]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/bridge/netfilter/ebt_arp.c
[NETFILTER]: ebt_arp: add gratuitous arp filtering
[linux-2.6-omap-h63xx.git] / net / bridge / netfilter / ebt_arp.c
index a6c81d9f73b85c07445d0e2e5ceb96a43f3ad88f..1a46952a56d9f197077e97e9cddf9814f24544b6 100644 (file)
@@ -35,40 +35,36 @@ static int ebt_filter_arp(const struct sk_buff *skb, const struct net_device *in
                return EBT_NOMATCH;
 
        if (info->bitmask & (EBT_ARP_SRC_IP | EBT_ARP_DST_IP)) {
-               uint32_t _addr, *ap;
+               __be32 saddr, daddr, *sap, *dap;
 
-               /* IPv4 addresses are always 4 bytes */
-               if (ah->ar_pln != sizeof(uint32_t))
+               if (ah->ar_pln != sizeof(__be32) || ah->ar_pro != htons(ETH_P_IP))
+                       return EBT_NOMATCH;
+               sap = skb_header_pointer(skb, sizeof(struct arphdr) +
+                                       ah->ar_hln, sizeof(saddr),
+                                       &saddr);
+               if (sap == NULL)
+                       return EBT_NOMATCH;
+               dap = skb_header_pointer(skb, sizeof(struct arphdr) +
+                                       2*ah->ar_hln+sizeof(saddr),
+                                       sizeof(daddr), &daddr);
+               if (dap == NULL)
+                       return EBT_NOMATCH;
+               if (info->bitmask & EBT_ARP_SRC_IP &&
+                   FWINV(info->saddr != (*sap & info->smsk), EBT_ARP_SRC_IP))
+                       return EBT_NOMATCH;
+               if (info->bitmask & EBT_ARP_DST_IP &&
+                   FWINV(info->daddr != (*dap & info->dmsk), EBT_ARP_DST_IP))
+                       return EBT_NOMATCH;
+               if (info->bitmask & EBT_ARP_GRAT &&
+                   FWINV(*dap != *sap, EBT_ARP_GRAT))
                        return EBT_NOMATCH;
-               if (info->bitmask & EBT_ARP_SRC_IP) {
-                       ap = skb_header_pointer(skb, sizeof(struct arphdr) +
-                                               ah->ar_hln, sizeof(_addr),
-                                               &_addr);
-                       if (ap == NULL)
-                               return EBT_NOMATCH;
-                       if (FWINV(info->saddr != (*ap & info->smsk),
-                          EBT_ARP_SRC_IP))
-                               return EBT_NOMATCH;
-               }
-
-               if (info->bitmask & EBT_ARP_DST_IP) {
-                       ap = skb_header_pointer(skb, sizeof(struct arphdr) +
-                                               2*ah->ar_hln+sizeof(uint32_t),
-                                               sizeof(_addr), &_addr);
-                       if (ap == NULL)
-                               return EBT_NOMATCH;
-                       if (FWINV(info->daddr != (*ap & info->dmsk),
-                          EBT_ARP_DST_IP))
-                               return EBT_NOMATCH;
-               }
        }
 
        if (info->bitmask & (EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC)) {
                unsigned char _mac[ETH_ALEN], *mp;
                uint8_t verdict, i;
 
-               /* MAC addresses are 6 bytes */
-               if (ah->ar_hln != ETH_ALEN)
+               if (ah->ar_hln != ETH_ALEN || ah->ar_hrd != htons(ARPHRD_ETHER))
                        return EBT_NOMATCH;
                if (info->bitmask & EBT_ARP_SRC_MAC) {
                        mp = skb_header_pointer(skb, sizeof(struct arphdr),