Commit c1f166d1 authored by Menglong Dong's avatar Menglong Dong Committed by David S. Miller

net: ipv4: use kfree_skb_reason() in ip_rcv_finish_core()

Replace kfree_skb() with kfree_skb_reason() in ip_rcv_finish_core(),
following drop reasons are introduced:

SKB_DROP_REASON_IP_RPFILTER
SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST
Signed-off-by: default avatarMenglong Dong <imagedong@tencent.com>
Reviewed-by: default avatarDavid Ahern <dsahern@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 33cba429
...@@ -330,6 +330,15 @@ enum skb_drop_reason { ...@@ -330,6 +330,15 @@ enum skb_drop_reason {
* IP header (see * IP header (see
* IPSTATS_MIB_INHDRERRORS) * IPSTATS_MIB_INHDRERRORS)
*/ */
SKB_DROP_REASON_IP_RPFILTER, /* IP rpfilter validate failed.
* see the document for rp_filter
* in ip-sysctl.rst for more
* information
*/
SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST, /* destination address of L2
* is multicast, but L3 is
* unicast.
*/
SKB_DROP_REASON_MAX, SKB_DROP_REASON_MAX,
}; };
......
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
EM(SKB_DROP_REASON_OTHERHOST, OTHERHOST) \ EM(SKB_DROP_REASON_OTHERHOST, OTHERHOST) \
EM(SKB_DROP_REASON_IP_CSUM, IP_CSUM) \ EM(SKB_DROP_REASON_IP_CSUM, IP_CSUM) \
EM(SKB_DROP_REASON_IP_INHDR, IP_INHDR) \ EM(SKB_DROP_REASON_IP_INHDR, IP_INHDR) \
EM(SKB_DROP_REASON_IP_RPFILTER, IP_RPFILTER) \
EM(SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST, \
UNICAST_IN_L2_MULTICAST) \
EMe(SKB_DROP_REASON_MAX, MAX) EMe(SKB_DROP_REASON_MAX, MAX)
#undef EM #undef EM
......
...@@ -318,8 +318,10 @@ static int ip_rcv_finish_core(struct net *net, struct sock *sk, ...@@ -318,8 +318,10 @@ static int ip_rcv_finish_core(struct net *net, struct sock *sk,
{ {
const struct iphdr *iph = ip_hdr(skb); const struct iphdr *iph = ip_hdr(skb);
int (*edemux)(struct sk_buff *skb); int (*edemux)(struct sk_buff *skb);
int err, drop_reason;
struct rtable *rt; struct rtable *rt;
int err;
drop_reason = SKB_DROP_REASON_NOT_SPECIFIED;
if (ip_can_use_hint(skb, iph, hint)) { if (ip_can_use_hint(skb, iph, hint)) {
err = ip_route_use_hint(skb, iph->daddr, iph->saddr, iph->tos, err = ip_route_use_hint(skb, iph->daddr, iph->saddr, iph->tos,
...@@ -396,19 +398,23 @@ static int ip_rcv_finish_core(struct net *net, struct sock *sk, ...@@ -396,19 +398,23 @@ static int ip_rcv_finish_core(struct net *net, struct sock *sk,
* so-called "hole-196" attack) so do it for both. * so-called "hole-196" attack) so do it for both.
*/ */
if (in_dev && if (in_dev &&
IN_DEV_ORCONF(in_dev, DROP_UNICAST_IN_L2_MULTICAST)) IN_DEV_ORCONF(in_dev, DROP_UNICAST_IN_L2_MULTICAST)) {
drop_reason = SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST;
goto drop; goto drop;
} }
}
return NET_RX_SUCCESS; return NET_RX_SUCCESS;
drop: drop:
kfree_skb(skb); kfree_skb_reason(skb, drop_reason);
return NET_RX_DROP; return NET_RX_DROP;
drop_error: drop_error:
if (err == -EXDEV) if (err == -EXDEV) {
drop_reason = SKB_DROP_REASON_IP_RPFILTER;
__NET_INC_STATS(net, LINUX_MIB_IPRPFILTER); __NET_INC_STATS(net, LINUX_MIB_IPRPFILTER);
}
goto drop; goto drop;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment