net: dropreason: add SKB_CONSUMED reason
authorEric Dumazet <edumazet@google.com>
Sat, 29 Oct 2022 15:45:16 +0000 (15:45 +0000)
committerJakub Kicinski <kuba@kernel.org>
Tue, 1 Nov 2022 03:14:26 +0000 (20:14 -0700)
This will allow to simply use in the future:

kfree_skb_reason(skb, reason);

Instead of repeating sequences like:

if (dropped)
    kfree_skb_reason(skb, reason);
else
    consume_skb(skb);

For instance, following patch in the series is adding
@reason to skb_release_data() and skb_release_all(),
so that we can propagate a meaningful @reason whenever
consume_skb()/kfree_skb() have to take care of a potential frag_list.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/dropreason.h
net/core/skbuff.c

index c1cbcdb..0bd18c1 100644 (file)
@@ -80,6 +80,8 @@ enum skb_drop_reason {
         * @SKB_NOT_DROPPED_YET: skb is not dropped yet (used for no-drop case)
         */
        SKB_NOT_DROPPED_YET = 0,
+       /** @SKB_CONSUMED: packet has been consumed */
+       SKB_CONSUMED,
        /** @SKB_DROP_REASON_NOT_SPECIFIED: drop reason is not specified */
        SKB_DROP_REASON_NOT_SPECIFIED,
        /** @SKB_DROP_REASON_NO_SOCKET: socket not found */
index 1d84a17..7ce797c 100644 (file)
@@ -94,6 +94,7 @@ EXPORT_SYMBOL(sysctl_max_skb_frags);
 #undef FN
 #define FN(reason) [SKB_DROP_REASON_##reason] = #reason,
 const char * const drop_reasons[] = {
+       [SKB_CONSUMED] = "CONSUMED",
        DEFINE_DROP_REASON(FN, FN)
 };
 EXPORT_SYMBOL(drop_reasons);
@@ -894,7 +895,10 @@ kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason)
 
        DEBUG_NET_WARN_ON_ONCE(reason <= 0 || reason >= SKB_DROP_REASON_MAX);
 
-       trace_kfree_skb(skb, __builtin_return_address(0), reason);
+       if (reason == SKB_CONSUMED)
+               trace_consume_skb(skb);
+       else
+               trace_kfree_skb(skb, __builtin_return_address(0), reason);
        __kfree_skb(skb);
 }
 EXPORT_SYMBOL(kfree_skb_reason);