arp: honour gratuitous ARP _replies_
Subsystems (3)
PATCH 1/1 arp: honour gratuitous ARP _replies_
When arp_accept is 1, gratuitous ARPs are supposed to override matching entries irrespective of whether they arrive during locktime. This was implemented in commit 56022a8fdd87 ("ipv4: arp: update neighbour address when a gratuitous arp is received and arp_accept is set")
There is a glitch in the patch though. RFC 2002, section 4.6, "ARP, Proxy ARP, and Gratuitous ARP", defines gratuitous ARPs so that they can be either of Request or Reply type. Those Reply gratuitous ARPs can be triggered with standard tooling, for example, arping -A option does just that.
This patch fixes the glitch, making both Request and Reply flavours of gratuitous ARPs to behave identically.
As per RFC, if gratuitous ARPs are of Reply type, their Target Hardware Address field should also be set to the link-layer address to which this cache entry should be updated. The field is present in ARP over Ethernet but not in IEEE 1394. In this patch, I don't consider any broadcasted ARP replies as gratuitous if the field is not present, to conform the standard. It's not clear whether there is such a thing for IEEE 1394 as a gratuitous ARP reply; until it's cleared up, we will ignore such broadcasts. Note that they will still update existing ARP cache entries, assuming they arrive out of locktime time interval.
--- net/ipv4/arp.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
net/ipv4/arp.c +16 -2
@@ -653,6 +653,7 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)unsigned char *arp_ptr;struct rtable *rt;unsigned char *sha; +unsigned char *tha =NULL ;__be32 sip, tip;u16 dev_type = dev->type;int addr_type;
@@ -724,6 +725,7 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)break ;#endif default : + tha = arp_ptr; arp_ptr += dev->addr_len; }memcpy (&tip, arp_ptr,4 );
@@ -842,8 +844,20 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)It is possible, that this option should be enabled for some devices (strip is candidate) */ - is_garp = arp->ar_op ==htons (ARPOP_REQUEST ) && tip == sip && - addr_type ==RTN_UNICAST ; + is_garp = tip == sip && addr_type ==RTN_UNICAST ; + +/* Unsolicited ARP _replies_ also require target hwaddr to be +* the same as source. +*/ +if (is_garp && arp->ar_op ==htons (ARPOP_REPLY )) + is_garp = +#if IS_ENABLED(CONFIG_FIREWIRE_NET) +/* IPv4 over IEEE 1394 doesn't provide target +* hardware address field in its ARP payload. +*/ + tha && +#endif + !memcmp (tha, sha, dev->addr_len); if (!n && ((arp->ar_op == htons(ARPOP_REPLY) &&
Signature · 1 line
2.9.3
David Miller
maintainerFrom: Ihar Hrachyshka <[email protected]>
Date: Tue, 9 May 2017 17:16:07 -0700
Quoted 11 lines
net/ipv4/arp.c +5
-2@@ -842,8 +844,20 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)It is possible, that this option should be enabled for some devices (strip is candidate) */ - is_garp = arp->ar_op ==htons (ARPOP_REQUEST ) && tip == sip && - addr_type ==RTN_UNICAST ; + is_garp = tip == sip && addr_type ==RTN_UNICAST ; + +/* Unsolicited ARP _replies_ also require target hwaddr to be +* the same as source. +*/
net/ipv4/arp.c static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb) · line 861
Quoted 10 lines
net/ipv4/arp.c +9
-0+if (is_garp && arp->ar_op ==htons (ARPOP_REPLY )) + is_garp = +#if IS_ENABLED(CONFIG_FIREWIRE_NET) +/* IPv4 over IEEE 1394 doesn't provide target +* hardware address field in its ARP payload. +*/ + tha && +#endif + !memcmp (tha, sha, dev->addr_len);
The ifdefs here make the test harder to understand.
I would suggest removing the ifdef and letting the compiler remove the 'tha' check if it can.
Thank you.
When arp_accept is 1, gratuitous ARPs are supposed to override matching entries irrespective of whether they arrive during locktime. This was implemented in commit 56022a8fdd87 ("ipv4: arp: update neighbour address when a gratuitous arp is received and arp_accept is set")
There is a glitch in the patch though. RFC 2002, section 4.6, "ARP, Proxy ARP, and Gratuitous ARP", defines gratuitous ARPs so that they can be either of Request or Reply type. Those Reply gratuitous ARPs can be triggered with standard tooling, for example, arping -A option does just that.
This patch fixes the glitch, making both Request and Reply flavours of gratuitous ARPs to behave identically.
As per RFC, if gratuitous ARPs are of Reply type, their Target Hardware Address field should also be set to the link-layer address to which this cache entry should be updated. The field is present in ARP over Ethernet but not in IEEE 1394. In this patch, I don't consider any broadcasted ARP replies as gratuitous if the field is not present, to conform the standard. It's not clear whether there is such a thing for IEEE 1394 as a gratuitous ARP reply; until it's cleared up, we will ignore such broadcasts. Note that they will still update existing ARP cache entries, assuming they arrive out of locktime time interval.
--- net/ipv4/arp.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
net/ipv4/arp.c +14 -2
@@ -653,6 +653,7 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)unsigned char *arp_ptr;struct rtable *rt;unsigned char *sha; +unsigned char *tha =NULL ;__be32 sip, tip;u16 dev_type = dev->type;int addr_type;
@@ -724,6 +725,7 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)break ;#endif default : + tha = arp_ptr; arp_ptr += dev->addr_len; }memcpy (&tip, arp_ptr,4 );
@@ -842,8 +844,18 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)It is possible, that this option should be enabled for some devices (strip is candidate) */ - is_garp = arp->ar_op ==htons (ARPOP_REQUEST ) && tip == sip && - addr_type ==RTN_UNICAST ; + is_garp = tip == sip && addr_type ==RTN_UNICAST ; + +/* Unsolicited ARP _replies_ also require target hwaddr to be +* the same as source. +*/ +if (is_garp && arp->ar_op ==htons (ARPOP_REPLY )) + is_garp = +/* IPv4 over IEEE 1394 doesn't provide target +* hardware address field in its ARP payload. +*/ + tha && + !memcmp (tha, sha, dev->addr_len); if (!n && ((arp->ar_op == htons(ARPOP_REPLY) &&
Signature · 1 line
2.9.3
Quoted 24 lines · Ihar Hrachyshka
When
arp_acceptis 1, gratuitous ARPs are supposed to override matching entries irrespective of whether they arrive during locktime. This was implemented in commit56022a8fdd87("ipv4: arp: update neighbour address when a gratuitous arp is received andarp_acceptis set")There is a glitch in the patch though. RFC 2002, section 4.6, "ARP, Proxy ARP, and Gratuitous ARP", defines gratuitous ARPs so that they can be either of Request or Reply type. Those Reply gratuitous ARPs can be triggered with standard tooling, for example, arping -A option does just that.
This patch fixes the glitch, making both Request and Reply flavours of gratuitous ARPs to behave identically.
As per RFC, if gratuitous ARPs are of Reply type, their Target Hardware Address field should also be set to the link-layer address to which this cache entry should be updated. The field is present in ARP over Ethernet but not in IEEE 1394. In this patch, I don't consider any broadcasted ARP replies as gratuitous if the field is not present, to conform the standard. It's not clear whether there is such a thing for IEEE 1394 as a gratuitous ARP reply; until it's cleared up, we will ignore such broadcasts. Note that they will still update existing ARP cache entries, assuming they arrive out of locktime time interval.
Quoted 1 line
Signed-off-by Ihar Hrachyshka <[email protected]>
Please disregard this email, I forgot to update the patch version to v2 and provide changelog. I posted (hopefully) correct version. Still learning the process...
Ihar
When arp_accept is 1, gratuitous ARPs are supposed to override matching entries irrespective of whether they arrive during locktime. This was implemented in commit 56022a8fdd87 ("ipv4: arp: update neighbour address when a gratuitous arp is received and arp_accept is set")
There is a glitch in the patch though. RFC 2002, section 4.6, "ARP, Proxy ARP, and Gratuitous ARP", defines gratuitous ARPs so that they can be either of Request or Reply type. Those Reply gratuitous ARPs can be triggered with standard tooling, for example, arping -A option does just that.
This patch fixes the glitch, making both Request and Reply flavours of gratuitous ARPs to behave identically.
As per RFC, if gratuitous ARPs are of Reply type, their Target Hardware Address field should also be set to the link-layer address to which this cache entry should be updated. The field is present in ARP over Ethernet but not in IEEE 1394. In this patch, I don't consider any broadcasted ARP replies as gratuitous if the field is not present, to conform the standard. It's not clear whether there is such a thing for IEEE 1394 as a gratuitous ARP reply; until it's cleared up, we will ignore such broadcasts. Note that they will still update existing ARP cache entries, assuming they arrive out of locktime time interval.
---
v2:
- removed #ifdef for CONFIG_FIREWIRE_NET
--- net/ipv4/arp.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
net/ipv4/arp.c +14 -2
@@ -653,6 +653,7 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)unsigned char *arp_ptr;struct rtable *rt;unsigned char *sha; +unsigned char *tha =NULL ;__be32 sip, tip;u16 dev_type = dev->type;int addr_type;
@@ -724,6 +725,7 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)break ;#endif default : + tha = arp_ptr; arp_ptr += dev->addr_len; }memcpy (&tip, arp_ptr,4 );
@@ -842,8 +844,18 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)It is possible, that this option should be enabled for some devices (strip is candidate) */ - is_garp = arp->ar_op ==htons (ARPOP_REQUEST ) && tip == sip && - addr_type ==RTN_UNICAST ; + is_garp = tip == sip && addr_type ==RTN_UNICAST ; + +/* Unsolicited ARP _replies_ also require target hwaddr to be +* the same as source. +*/ +if (is_garp && arp->ar_op ==htons (ARPOP_REPLY )) + is_garp = +/* IPv4 over IEEE 1394 doesn't provide target +* hardware address field in its ARP payload. +*/ + tha && + !memcmp (tha, sha, dev->addr_len); if (!n && ((arp->ar_op == htons(ARPOP_REPLY) &&
Signature · 1 line
2.9.3