summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorIhar Hrachyshka <ihrachys@redhat.com>2017-05-18 12:41:19 -0700
committerDavid S. Miller <davem@davemloft.net>2017-05-21 13:26:45 -0400
commit6fd05633bdafc0ae6ec0d55e61af10780d4d3530 (patch)
tree831a02bc8d919ba4db70d0f5a35179dadddcf0f6 /net
parent34eb5fe07831458cf8238d54c1fc847dedeaf68c (diff)
arp: decompose is_garp logic into a separate function
The code is quite involving already to earn a separate function for itself. If anything, it helps arp_process readability. Signed-off-by: Ihar Hrachyshka <ihrachys@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/ipv4/arp.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c
index 053492af8a6e..ca6e1e6c1496 100644
--- a/net/ipv4/arp.c
+++ b/net/ipv4/arp.c
@@ -641,6 +641,27 @@ void arp_xmit(struct sk_buff *skb)
}
EXPORT_SYMBOL(arp_xmit);
+static bool arp_is_garp(struct net_device *dev, int addr_type,
+ __be16 ar_op,
+ __be32 sip, __be32 tip,
+ unsigned char *sha, unsigned char *tha)
+{
+ bool is_garp = tip == sip && addr_type == RTN_UNICAST;
+
+ /* Gratuitous ARP _replies_ also require target hwaddr to be
+ * the same as source.
+ */
+ if (is_garp && 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);
+
+ return is_garp;
+}
+
/*
* Process an arp request.
*/
@@ -844,18 +865,8 @@ 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 = tip == sip && addr_type == RTN_UNICAST;
-
- /* Gratuitous 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);
+ is_garp = arp_is_garp(dev, addr_type, arp->ar_op,
+ sip, tip, sha, tha);
if (!n &&
((arp->ar_op == htons(ARPOP_REPLY) &&