[Devel] [PATCH RHEL9 COMMIT] net: ip: add skb drop reasons for ip egress path

Konstantin Khorenko khorenko at virtuozzo.com
Mon Jan 16 20:56:45 MSK 2023


The commit is pushed to "branch-rh9-5.14.0-162.6.1.vz9.18.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-162.6.1.vz9.18.2
------>
commit 58933fa1d540635a11192783c3cddf3da15a341c
Author: Menglong Dong <imagedong at tencent.com>
Date:   Tue Jan 3 17:39:14 2023 +0200

    net: ip: add skb drop reasons for ip egress path
    
    Replace kfree_skb() which is used in the packet egress path of IP layer
    with kfree_skb_reason(). Functions that are involved include:
    
    __ip_queue_xmit()
    ip_finish_output()
    ip_mc_finish_output()
    ip6_output()
    ip6_finish_output()
    ip6_finish_output2()
    
    Following new drop reasons are introduced:
    
    SKB_DROP_REASON_IP_OUTNOROUTES
    SKB_DROP_REASON_BPF_CGROUP_EGRESS
    SKB_DROP_REASON_IPV6DISABLED
    SKB_DROP_REASON_NEIGH_CREATEFAIL
    
    Reviewed-by: Mengen Sun <mengensun at tencent.com>
    Reviewed-by: Hao Peng <flyingpeng at tencent.com>
    Signed-off-by: Menglong Dong <imagedong at tencent.com>
    Reviewed-by: David Ahern <dsahern at kernel.org>
    Signed-off-by: David S. Miller <davem at davemloft.net>
    Acked-by: Nikolay Borisov <nborisov at suse.com>
    Signed-off-by: Nikolay Borisov <nikolay.borisov at virtuozzo.com>
    
    ======
    Patchset description:
    ms/net: Annotate skb free sites with reason
    
    This series backports most of the patches that add a reason to skb free sites.
    
    https://jira.sw.ru/browse/PSBM-143302
    
    Feature: net: improve verbosity of dropped packets reporting
---
 include/linux/skbuff.h     | 10 ++++++++++
 include/trace/events/skb.h |  6 +++++-
 net/ipv4/ip_output.c       |  8 ++++----
 net/ipv6/ip6_output.c      |  6 +++---
 4 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index d3f79982e3f4..4cfc9f359d7d 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -378,6 +378,16 @@ enum skb_drop_reason {
 					 * the ofo queue, corresponding to
 					 * LINUX_MIB_TCPOFOMERGE
 					 */
+	SKB_DROP_REASON_IP_OUTNOROUTES, /* route lookup failed */
+	SKB_DROP_REASON_BPF_CGROUP_EGRESS,      /* dropped by
+						 * BPF_PROG_TYPE_CGROUP_SKB
+						 * eBPF program
+						 */
+	SKB_DROP_REASON_IPV6DISABLED,   /* IPv6 is disabled on the device */
+	SKB_DROP_REASON_NEIGH_CREATEFAIL,       /* failed to create neigh
+						 * entry
+						 */
+
 
 
 
diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h
index c81b55e19d09..c28194e29b95 100644
--- a/include/trace/events/skb.h
+++ b/include/trace/events/skb.h
@@ -37,7 +37,11 @@
 	EM(SKB_DROP_REASON_TCP_OLD_DATA, TCP_OLD_DATA)          \
 	EM(SKB_DROP_REASON_TCP_OVERWINDOW, TCP_OVERWINDOW)      \
 	EM(SKB_DROP_REASON_TCP_OFOMERGE, TCP_OFOMERGE)          \
-
+	EM(SKB_DROP_REASON_IP_OUTNOROUTES, IP_OUTNOROUTES)      \
+	EM(SKB_DROP_REASON_BPF_CGROUP_EGRESS,                   \
+	   BPF_CGROUP_EGRESS)                                   \
+	EM(SKB_DROP_REASON_IPV6DISABLED, IPV6DISABLED)          \
+	EM(SKB_DROP_REASON_NEIGH_CREATEFAIL, NEIGH_CREATEFAIL)  \
 	EMe(SKB_DROP_REASON_MAX, MAX)
 
 #undef EM
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 845d01136579..e6c8142b10c7 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -233,7 +233,7 @@ static int ip_finish_output2(struct net *net, struct sock *sk, struct sk_buff *s
 
 	net_dbg_ratelimited("%s: No header cache and no neighbour!\n",
 			    __func__);
-	kfree_skb(skb);
+	kfree_skb_reason(skb, SKB_DROP_REASON_NEIGH_CREATEFAIL);
 	return -EINVAL;
 }
 
@@ -317,7 +317,7 @@ static int ip_finish_output(struct net *net, struct sock *sk, struct sk_buff *sk
 	case NET_XMIT_CN:
 		return __ip_finish_output(net, sk, skb) ? : ret;
 	default:
-		kfree_skb(skb);
+		kfree_skb_reason(skb, SKB_DROP_REASON_BPF_CGROUP_EGRESS);
 		return ret;
 	}
 }
@@ -337,7 +337,7 @@ static int ip_mc_finish_output(struct net *net, struct sock *sk,
 	case NET_XMIT_SUCCESS:
 		break;
 	default:
-		kfree_skb(skb);
+		kfree_skb_reason(skb, SKB_DROP_REASON_BPF_CGROUP_EGRESS);
 		return ret;
 	}
 
@@ -535,7 +535,7 @@ int __ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl,
 no_route:
 	rcu_read_unlock();
 	IP_INC_STATS(net, IPSTATS_MIB_OUTNOROUTES);
-	kfree_skb(skb);
+	kfree_skb_reason(skb, SKB_DROP_REASON_IP_OUTNOROUTES);
 	return -EHOSTUNREACH;
 }
 EXPORT_SYMBOL(__ip_queue_xmit);
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 81fc57dca755..6c84d66433be 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -130,7 +130,7 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff *
 	rcu_read_unlock_bh();
 
 	IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTNOROUTES);
-	kfree_skb(skb);
+	kfree_skb_reason(skb, SKB_DROP_REASON_NEIGH_CREATEFAIL);
 	return -EINVAL;
 }
 
@@ -202,7 +202,7 @@ static int ip6_finish_output(struct net *net, struct sock *sk, struct sk_buff *s
 	case NET_XMIT_CN:
 		return __ip6_finish_output(net, sk, skb) ? : ret;
 	default:
-		kfree_skb(skb);
+		kfree_skb_reason(skb, SKB_DROP_REASON_BPF_CGROUP_EGRESS);
 		return ret;
 	}
 }
@@ -217,7 +217,7 @@ int ip6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
 
 	if (unlikely(idev->cnf.disable_ipv6)) {
 		IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS);
-		kfree_skb(skb);
+		kfree_skb_reason(skb, SKB_DROP_REASON_IPV6DISABLED);
 		return 0;
 	}
 


More information about the Devel mailing list