]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
[ARP]: Introduce the arp_hdr_len helper.
authorPavel Emelyanov <xemul@openvz.org>
Mon, 3 Mar 2008 20:20:57 +0000 (12:20 -0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 3 Mar 2008 20:20:57 +0000 (12:20 -0800)
There are some place, that calculate the ARP header length. These
calculations are correct, but
 a) some operate with "magic" constants,
 b) enlarge the code length (sometimes at the cost of coding style),
 c) are not informative from the first glance.

The proposal is to introduce a helper, that includes all the good
sides of these calculations.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/bonding/bond_main.c
include/linux/if_arp.h
net/core/netpoll.c
net/ipv4/arp.c
net/ipv4/ipconfig.c
net/ipv4/netfilter/arp_tables.c

index 966643473da7175fa7d0ef25dc35f38d7f8c1dc5..5fc9d8d58ecef06e25c0cfc99444e8d298f65c48 100644 (file)
@@ -2646,10 +2646,7 @@ static int bond_arp_rcv(struct sk_buff *skb, struct net_device *dev, struct pack
        if (!slave || !slave_do_arp_validate(bond, slave))
                goto out_unlock;
 
-       /* ARP header, plus 2 device addresses, plus 2 IP addresses.  */
-       if (!pskb_may_pull(skb, (sizeof(struct arphdr) +
-                                (2 * dev->addr_len) +
-                                (2 * sizeof(u32)))))
+       if (!pskb_may_pull(skb, arp_hdr_len(dev)))
                goto out_unlock;
 
        arp = arp_hdr(skb);
index 296e8e86e91d1c33052ea2b27ad3b1d8f86895db..4d3401812e6cbfe237902c51a00e7123a96fc4cb 100644 (file)
@@ -156,6 +156,12 @@ static inline struct arphdr *arp_hdr(const struct sk_buff *skb)
 {
        return (struct arphdr *)skb_network_header(skb);
 }
+
+static inline int arp_hdr_len(struct net_device *dev)
+{
+       /* ARP header, plus 2 device addresses, plus 2 IP addresses. */
+       return sizeof(struct arphdr) + (dev->addr_len + sizeof(u32)) * 2;
+}
 #endif
 
 #endif /* _LINUX_IF_ARP_H */
index 6faa128a4c8ef22d110c22b2add2dc8a4ffbbfd3..7ae98659d79d727e1a860d7ec3b6d25adaadbadb 100644 (file)
@@ -384,9 +384,7 @@ static void arp_reply(struct sk_buff *skb)
        if (skb->dev->flags & IFF_NOARP)
                return;
 
-       if (!pskb_may_pull(skb, (sizeof(struct arphdr) +
-                                (2 * skb->dev->addr_len) +
-                                (2 * sizeof(u32)))))
+       if (!pskb_may_pull(skb, arp_hdr_len(skb->dev)))
                return;
 
        skb_reset_network_header(skb);
@@ -414,7 +412,7 @@ static void arp_reply(struct sk_buff *skb)
            ipv4_is_loopback(tip) || ipv4_is_multicast(tip))
                return;
 
-       size = sizeof(struct arphdr) + 2 * (skb->dev->addr_len + 4);
+       size = arp_hdr_len(skb->dev);
        send_skb = find_skb(np, size + LL_RESERVED_SPACE(np->dev),
                            LL_RESERVED_SPACE(np->dev));
 
index 8e17f65f400215a72c3ac3effb908071255d2747..69e80bd9774af9c8d9bf4115ee76e2fda36c8bdf 100644 (file)
@@ -570,14 +570,13 @@ struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
         *      Allocate a buffer
         */
 
-       skb = alloc_skb(sizeof(struct arphdr)+ 2*(dev->addr_len+4)
-                               + LL_RESERVED_SPACE(dev), GFP_ATOMIC);
+       skb = alloc_skb(arp_hdr_len(dev) + LL_RESERVED_SPACE(dev), GFP_ATOMIC);
        if (skb == NULL)
                return NULL;
 
        skb_reserve(skb, LL_RESERVED_SPACE(dev));
        skb_reset_network_header(skb);
-       arp = (struct arphdr *) skb_put(skb,sizeof(struct arphdr) + 2*(dev->addr_len+4));
+       arp = (struct arphdr *) skb_put(skb, arp_hdr_len(dev));
        skb->dev = dev;
        skb->protocol = htons(ETH_P_ARP);
        if (src_hw == NULL)
@@ -916,9 +915,7 @@ static int arp_rcv(struct sk_buff *skb, struct net_device *dev,
                goto freeskb;
 
        /* ARP header, plus 2 device addresses, plus 2 IP addresses.  */
-       if (!pskb_may_pull(skb, (sizeof(struct arphdr) +
-                                (2 * dev->addr_len) +
-                                (2 * sizeof(u32)))))
+       if (!pskb_may_pull(skb, arp_hdr_len(dev)))
                goto freeskb;
 
        arp = arp_hdr(skb);
index c90e75a66e812c902ab69f15a4547dd7979effcf..f84041d1f623df5b9c269a79df2c0162a9e21235 100644 (file)
@@ -459,10 +459,7 @@ ic_rarp_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
        if (rarp->ar_pro != htons(ETH_P_IP))
                goto drop;
 
-       if (!pskb_may_pull(skb,
-                          sizeof(struct arphdr) +
-                          (2 * dev->addr_len) +
-                          (2 * 4)))
+       if (!pskb_may_pull(skb, arp_hdr_len(dev)))
                goto drop;
 
        /* OK, it is all there and looks valid, process... */
index a7591ce344d2c18a747c717ded8fa96671e2dcc8..9b590448618470b9299bf85be12e5f0c2d07348c 100644 (file)
@@ -233,10 +233,7 @@ unsigned int arpt_do_table(struct sk_buff *skb,
        void *table_base;
        struct xt_table_info *private;
 
-       /* ARP header, plus 2 device addresses, plus 2 IP addresses.  */
-       if (!pskb_may_pull(skb, (sizeof(struct arphdr) +
-                                (2 * skb->dev->addr_len) +
-                                (2 * sizeof(u32)))))
+       if (!pskb_may_pull(skb, arp_hdr_len(skb->dev)))
                return NF_DROP;
 
        indev = in ? in->name : nulldevname;