Skip to content

Commit c15bf6e

Browse files
Bart De SchuymerDavid S. Miller
authored andcommitted
[NETFILTER]: ebt_arp: add gratuitous arp filtering
The attached patch adds gratuitous arp filtering, more precisely: it allows checking that the IPv4 source address matches the IPv4 destination address inside the ARP header. It also adds a check for the hardware address type when matching MAC addresses (nothing critical, just for better consistency). Signed-off-by: Bart De Schuymer <[email protected]> Acked-by: Carl-Daniel Hailfinger <[email protected]> Signed-off-by: Patrick McHardy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 516299d commit c15bf6e

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

include/linux/netfilter_bridge/ebt_arp.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
#define EBT_ARP_DST_IP 0x10
99
#define EBT_ARP_SRC_MAC 0x20
1010
#define EBT_ARP_DST_MAC 0x40
11+
#define EBT_ARP_GRAT 0x80
1112
#define EBT_ARP_MASK (EBT_ARP_OPCODE | EBT_ARP_HTYPE | EBT_ARP_PTYPE | \
12-
EBT_ARP_SRC_IP | EBT_ARP_DST_IP | EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC)
13+
EBT_ARP_SRC_IP | EBT_ARP_DST_IP | EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC | \
14+
EBT_ARP_GRAT)
1315
#define EBT_ARP_MATCH "arp"
1416

1517
struct ebt_arp_info

net/bridge/netfilter/ebt_arp.c

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,40 +35,36 @@ static int ebt_filter_arp(const struct sk_buff *skb, const struct net_device *in
3535
return EBT_NOMATCH;
3636

3737
if (info->bitmask & (EBT_ARP_SRC_IP | EBT_ARP_DST_IP)) {
38-
__be32 _addr, *ap;
38+
__be32 saddr, daddr, *sap, *dap;
3939

40-
/* IPv4 addresses are always 4 bytes */
41-
if (ah->ar_pln != sizeof(__be32))
40+
if (ah->ar_pln != sizeof(__be32) || ah->ar_pro != htons(ETH_P_IP))
41+
return EBT_NOMATCH;
42+
sap = skb_header_pointer(skb, sizeof(struct arphdr) +
43+
ah->ar_hln, sizeof(saddr),
44+
&saddr);
45+
if (sap == NULL)
46+
return EBT_NOMATCH;
47+
dap = skb_header_pointer(skb, sizeof(struct arphdr) +
48+
2*ah->ar_hln+sizeof(saddr),
49+
sizeof(daddr), &daddr);
50+
if (dap == NULL)
51+
return EBT_NOMATCH;
52+
if (info->bitmask & EBT_ARP_SRC_IP &&
53+
FWINV(info->saddr != (*sap & info->smsk), EBT_ARP_SRC_IP))
54+
return EBT_NOMATCH;
55+
if (info->bitmask & EBT_ARP_DST_IP &&
56+
FWINV(info->daddr != (*dap & info->dmsk), EBT_ARP_DST_IP))
57+
return EBT_NOMATCH;
58+
if (info->bitmask & EBT_ARP_GRAT &&
59+
FWINV(*dap != *sap, EBT_ARP_GRAT))
4260
return EBT_NOMATCH;
43-
if (info->bitmask & EBT_ARP_SRC_IP) {
44-
ap = skb_header_pointer(skb, sizeof(struct arphdr) +
45-
ah->ar_hln, sizeof(_addr),
46-
&_addr);
47-
if (ap == NULL)
48-
return EBT_NOMATCH;
49-
if (FWINV(info->saddr != (*ap & info->smsk),
50-
EBT_ARP_SRC_IP))
51-
return EBT_NOMATCH;
52-
}
53-
54-
if (info->bitmask & EBT_ARP_DST_IP) {
55-
ap = skb_header_pointer(skb, sizeof(struct arphdr) +
56-
2*ah->ar_hln+sizeof(__be32),
57-
sizeof(_addr), &_addr);
58-
if (ap == NULL)
59-
return EBT_NOMATCH;
60-
if (FWINV(info->daddr != (*ap & info->dmsk),
61-
EBT_ARP_DST_IP))
62-
return EBT_NOMATCH;
63-
}
6461
}
6562

6663
if (info->bitmask & (EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC)) {
6764
unsigned char _mac[ETH_ALEN], *mp;
6865
uint8_t verdict, i;
6966

70-
/* MAC addresses are 6 bytes */
71-
if (ah->ar_hln != ETH_ALEN)
67+
if (ah->ar_hln != ETH_ALEN || ah->ar_hrd != htons(ARPHRD_ETHER))
7268
return EBT_NOMATCH;
7369
if (info->bitmask & EBT_ARP_SRC_MAC) {
7470
mp = skb_header_pointer(skb, sizeof(struct arphdr),

0 commit comments

Comments
 (0)