Skip to content

Commit 8dfd329

Browse files
Zhang Shengjudavem330
authored andcommitted
arp: correct return value of arp_rcv
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8303394 commit 8dfd329

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

net/ipv4/arp.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -665,15 +665,15 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)
665665
*/
666666

667667
if (!in_dev)
668-
goto out;
668+
goto out_free_skb;
669669

670670
arp = arp_hdr(skb);
671671

672672
switch (dev_type) {
673673
default:
674674
if (arp->ar_pro != htons(ETH_P_IP) ||
675675
htons(dev_type) != arp->ar_hrd)
676-
goto out;
676+
goto out_free_skb;
677677
break;
678678
case ARPHRD_ETHER:
679679
case ARPHRD_FDDI:
@@ -690,25 +690,25 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)
690690
if ((arp->ar_hrd != htons(ARPHRD_ETHER) &&
691691
arp->ar_hrd != htons(ARPHRD_IEEE802)) ||
692692
arp->ar_pro != htons(ETH_P_IP))
693-
goto out;
693+
goto out_free_skb;
694694
break;
695695
case ARPHRD_AX25:
696696
if (arp->ar_pro != htons(AX25_P_IP) ||
697697
arp->ar_hrd != htons(ARPHRD_AX25))
698-
goto out;
698+
goto out_free_skb;
699699
break;
700700
case ARPHRD_NETROM:
701701
if (arp->ar_pro != htons(AX25_P_IP) ||
702702
arp->ar_hrd != htons(ARPHRD_NETROM))
703-
goto out;
703+
goto out_free_skb;
704704
break;
705705
}
706706

707707
/* Understand only these message types */
708708

709709
if (arp->ar_op != htons(ARPOP_REPLY) &&
710710
arp->ar_op != htons(ARPOP_REQUEST))
711-
goto out;
711+
goto out_free_skb;
712712

713713
/*
714714
* Extract fields
@@ -733,15 +733,15 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)
733733
*/
734734
if (ipv4_is_multicast(tip) ||
735735
(!IN_DEV_ROUTE_LOCALNET(in_dev) && ipv4_is_loopback(tip)))
736-
goto out;
736+
goto out_free_skb;
737737

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

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

784784
if (arp->ar_op == htons(ARPOP_REQUEST) &&
@@ -803,7 +803,7 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)
803803
neigh_release(n);
804804
}
805805
}
806-
goto out;
806+
goto out_consume_skb;
807807
} else if (IN_DEV_FORWARD(in_dev)) {
808808
if (addr_type == RTN_UNICAST &&
809809
(arp_fwd_proxy(in_dev, dev, rt) ||
@@ -826,7 +826,7 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)
826826
in_dev->arp_parms, skb);
827827
goto out_free_dst;
828828
}
829-
goto out;
829+
goto out_consume_skb;
830830
}
831831
}
832832
}
@@ -876,11 +876,16 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)
876876
neigh_release(n);
877877
}
878878

879-
out:
879+
out_consume_skb:
880880
consume_skb(skb);
881+
881882
out_free_dst:
882883
dst_release(reply_dst);
883-
return 0;
884+
return NET_RX_SUCCESS;
885+
886+
out_free_skb:
887+
kfree_skb(skb);
888+
return NET_RX_DROP;
884889
}
885890

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

925930
consumeskb:
926931
consume_skb(skb);
927-
return 0;
932+
return NET_RX_SUCCESS;
928933
freeskb:
929934
kfree_skb(skb);
930935
out_of_mem:
931-
return 0;
936+
return NET_RX_DROP;
932937
}
933938

934939
/*

0 commit comments

Comments
 (0)