[PATCH net-next 7/7] net: dev: use kfree_skb_reason() for __netif_receive_skb_core()

From: menglong8 . dong
Date: Thu Mar 03 2022 - 12:49:20 EST


From: Menglong Dong <imagedong@xxxxxxxxxxx>

Add reason for skb drops to __netif_receive_skb_core() when packet_type
not found to handle the skb. For this purpose, the drop reason
SKB_DROP_REASON_PTYPE_ABSENT is introduced. Take ether packets for
example, this case mainly happens when L3 protocol is not supported.

Signed-off-by: Menglong Dong <imagedong@xxxxxxxxxxx>
---
include/linux/skbuff.h | 5 +++++
net/core/dev.c | 8 +++++---
2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 04508d15152e..f3945d21cecf 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -413,6 +413,11 @@ enum skb_drop_reason {
* failed (maybe an eBPF program
* is tricking?)
*/
+ SKB_DROP_REASON_PTYPE_ABSENT, /* not packet_type found to handle
+ * the skb. For an etner packet,
+ * this means that L3 protocol is
+ * not supported
+ */
SKB_DROP_REASON_MAX,
};

diff --git a/net/core/dev.c b/net/core/dev.c
index 429ad8265e8c..0bdea7d113f5 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -5330,11 +5330,13 @@ static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc,
*ppt_prev = pt_prev;
} else {
drop:
- if (!deliver_exact)
+ if (!deliver_exact) {
atomic_long_inc(&skb->dev->rx_dropped);
- else
+ kfree_skb_reason(skb, SKB_DROP_REASON_PTYPE_ABSENT);
+ } else {
atomic_long_inc(&skb->dev->rx_nohandler);
- kfree_skb(skb);
+ kfree_skb(skb);
+ }
/* Jamal, now you will not able to escape explaining
* me how you were going to use this. :-)
*/
--
2.35.1