Skip to content

Commit

Permalink
arp: correct return value of arp_rcv
Browse files Browse the repository at this point in the history
Currently, arp_rcv() always return zero on a packet delivery upcall.

To make its behavior more compliant with the way this API should be
used, this patch changes this to let it return NET_RX_SUCCESS when the
packet is proper handled, and NET_RX_DROP otherwise.

v1->v2:
If sanity check is failed, call kfree_skb() instead of consume_skb(), then
return the correct return value.

Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Zhang Shengju authored and David S. Miller committed Mar 7, 2016
1 parent 8303394 commit 8dfd329
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions net/ipv4/arp.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,15 +665,15 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)
*/

if (!in_dev)
goto out;
goto out_free_skb;

arp = arp_hdr(skb);

switch (dev_type) {
default:
if (arp->ar_pro != htons(ETH_P_IP) ||
htons(dev_type) != arp->ar_hrd)
goto out;
goto out_free_skb;
break;
case ARPHRD_ETHER:
case ARPHRD_FDDI:
Expand All @@ -690,25 +690,25 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)
if ((arp->ar_hrd != htons(ARPHRD_ETHER) &&
arp->ar_hrd != htons(ARPHRD_IEEE802)) ||
arp->ar_pro != htons(ETH_P_IP))
goto out;
goto out_free_skb;
break;
case ARPHRD_AX25:
if (arp->ar_pro != htons(AX25_P_IP) ||
arp->ar_hrd != htons(ARPHRD_AX25))
goto out;
goto out_free_skb;
break;
case ARPHRD_NETROM:
if (arp->ar_pro != htons(AX25_P_IP) ||
arp->ar_hrd != htons(ARPHRD_NETROM))
goto out;
goto out_free_skb;
break;
}

/* Understand only these message types */

if (arp->ar_op != htons(ARPOP_REPLY) &&
arp->ar_op != htons(ARPOP_REQUEST))
goto out;
goto out_free_skb;

/*
* Extract fields
Expand All @@ -733,15 +733,15 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)
*/
if (ipv4_is_multicast(tip) ||
(!IN_DEV_ROUTE_LOCALNET(in_dev) && ipv4_is_loopback(tip)))
goto out;
goto out_free_skb;

/*
* For some 802.11 wireless deployments (and possibly other networks),
* there will be an ARP proxy and gratuitous ARP frames are attacks
* and thus should not be accepted.
*/
if (sip == tip && IN_DEV_ORCONF(in_dev, DROP_GRATUITOUS_ARP))
goto out;
goto out_free_skb;

/*
* Special case: We must set Frame Relay source Q.922 address
Expand Down Expand Up @@ -778,7 +778,7 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)
!arp_ignore(in_dev, sip, tip))
arp_send_dst(ARPOP_REPLY, ETH_P_ARP, sip, dev, tip,
sha, dev->dev_addr, sha, reply_dst);
goto out;
goto out_consume_skb;
}

if (arp->ar_op == htons(ARPOP_REQUEST) &&
Expand All @@ -803,7 +803,7 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)
neigh_release(n);
}
}
goto out;
goto out_consume_skb;
} else if (IN_DEV_FORWARD(in_dev)) {
if (addr_type == RTN_UNICAST &&
(arp_fwd_proxy(in_dev, dev, rt) ||
Expand All @@ -826,7 +826,7 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)
in_dev->arp_parms, skb);
goto out_free_dst;
}
goto out;
goto out_consume_skb;
}
}
}
Expand Down Expand Up @@ -876,11 +876,16 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)
neigh_release(n);
}

out:
out_consume_skb:
consume_skb(skb);

out_free_dst:
dst_release(reply_dst);
return 0;
return NET_RX_SUCCESS;

out_free_skb:
kfree_skb(skb);
return NET_RX_DROP;
}

static void parp_redo(struct sk_buff *skb)
Expand Down Expand Up @@ -924,11 +929,11 @@ static int arp_rcv(struct sk_buff *skb, struct net_device *dev,

consumeskb:
consume_skb(skb);
return 0;
return NET_RX_SUCCESS;
freeskb:
kfree_skb(skb);
out_of_mem:
return 0;
return NET_RX_DROP;
}

/*
Expand Down

0 comments on commit 8dfd329

Please sign in to comment.