Skip to content

Commit

Permalink
arp: decompose is_garp logic into a separate function
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
booxter authored and davem330 committed May 21, 2017
1 parent 34eb5fe commit 6fd0563
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions net/ipv4/arp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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) &&
Expand Down

0 comments on commit 6fd0563

Please sign in to comment.