net: sched: Add initial TC error skb drop reasons
authorVictor Nogueira <victor@mojatatu.com>
Sat, 16 Dec 2023 20:44:36 +0000 (17:44 -0300)
committerDavid S. Miller <davem@davemloft.net>
Wed, 20 Dec 2023 11:50:13 +0000 (11:50 +0000)
Continue expanding Daniel's patch by adding new skb drop reasons that
are idiosyncratic to TC.

More specifically:

- SKB_DROP_REASON_TC_COOKIE_ERROR: An error occurred whilst
  processing a tc ext cookie.

- SKB_DROP_REASON_TC_CHAIN_NOTFOUND: tc chain lookup failed.

- SKB_DROP_REASON_TC_RECLASSIFY_LOOP: tc exceeded max reclassify loop
  iterations

Signed-off-by: Victor Nogueira <victor@mojatatu.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/dropreason-core.h
net/sched/act_api.c
net/sched/cls_api.c

index 278e4c7d465c193a05fc98fc8649c7db12bcb1f3..6d3a20163260ad4e84af368eb83441221ea44c65 100644 (file)
        FN(IPV6_NDISC_BAD_OPTIONS)      \
        FN(IPV6_NDISC_NS_OTHERHOST)     \
        FN(QUEUE_PURGE)                 \
-       FN(TC_ERROR)                    \
+       FN(TC_COOKIE_ERROR)             \
        FN(PACKET_SOCK_ERROR)           \
+       FN(TC_CHAIN_NOTFOUND)           \
+       FN(TC_RECLASSIFY_LOOP)          \
        FNe(MAX)
 
 /**
@@ -377,13 +379,23 @@ enum skb_drop_reason {
        SKB_DROP_REASON_IPV6_NDISC_NS_OTHERHOST,
        /** @SKB_DROP_REASON_QUEUE_PURGE: bulk free. */
        SKB_DROP_REASON_QUEUE_PURGE,
-       /** @SKB_DROP_REASON_TC_ERROR: generic internal tc error. */
-       SKB_DROP_REASON_TC_ERROR,
+       /**
+        * @SKB_DROP_REASON_TC_COOKIE_ERROR: An error occurred whilst
+        * processing a tc ext cookie.
+        */
+       SKB_DROP_REASON_TC_COOKIE_ERROR,
        /**
         * @SKB_DROP_REASON_PACKET_SOCK_ERROR: generic packet socket errors
         * after its filter matches an incoming packet.
         */
        SKB_DROP_REASON_PACKET_SOCK_ERROR,
+       /** @SKB_DROP_REASON_TC_CHAIN_NOTFOUND: tc chain lookup failed. */
+       SKB_DROP_REASON_TC_CHAIN_NOTFOUND,
+       /**
+        * @SKB_DROP_REASON_TC_RECLASSIFY_LOOP: tc exceeded max reclassify loop
+        * iterations.
+        */
+       SKB_DROP_REASON_TC_RECLASSIFY_LOOP,
        /**
         * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which
         * shouldn't be used as a real 'reason' - only for tracing code gen
index db500aa9f84190fcc65c6d853e52ecf9aa80e6d3..a44c097a880d3f4d47ef1939427da590d3176f84 100644 (file)
@@ -1119,7 +1119,8 @@ repeat:
                        }
                } else if (TC_ACT_EXT_CMP(ret, TC_ACT_GOTO_CHAIN)) {
                        if (unlikely(!rcu_access_pointer(a->goto_chain))) {
-                               tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
+                               tcf_set_drop_reason(skb,
+                                                   SKB_DROP_REASON_TC_CHAIN_NOTFOUND);
                                return TC_ACT_SHOT;
                        }
                        tcf_action_goto_chain_exec(a, res);
index 199406e4bcdd99126503e89f53fc49242ceb75e7..8978cf5531d074b657b004e25f7e6d2b025c7a08 100644 (file)
@@ -1681,13 +1681,15 @@ reclassify:
                         */
                        if (unlikely(n->tp != tp || n->tp->chain != n->chain ||
                                     !tp->ops->get_exts)) {
-                               tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
+                               tcf_set_drop_reason(skb,
+                                                   SKB_DROP_REASON_TC_COOKIE_ERROR);
                                return TC_ACT_SHOT;
                        }
 
                        exts = tp->ops->get_exts(tp, n->handle);
                        if (unlikely(!exts || n->exts != exts)) {
-                               tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
+                               tcf_set_drop_reason(skb,
+                                                   SKB_DROP_REASON_TC_COOKIE_ERROR);
                                return TC_ACT_SHOT;
                        }
 
@@ -1716,7 +1718,8 @@ reclassify:
        }
 
        if (unlikely(n)) {
-               tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
+               tcf_set_drop_reason(skb,
+                                   SKB_DROP_REASON_TC_COOKIE_ERROR);
                return TC_ACT_SHOT;
        }
 
@@ -1728,7 +1731,8 @@ reset:
                                       tp->chain->block->index,
                                       tp->prio & 0xffff,
                                       ntohs(tp->protocol));
-               tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
+               tcf_set_drop_reason(skb,
+                                   SKB_DROP_REASON_TC_RECLASSIFY_LOOP);
                return TC_ACT_SHOT;
        }
 
@@ -1766,7 +1770,8 @@ int tcf_classify(struct sk_buff *skb,
                                n = tcf_exts_miss_cookie_lookup(ext->act_miss_cookie,
                                                                &act_index);
                                if (!n) {
-                                       tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
+                                       tcf_set_drop_reason(skb,
+                                                           SKB_DROP_REASON_TC_COOKIE_ERROR);
                                        return TC_ACT_SHOT;
                                }
 
@@ -1777,7 +1782,9 @@ int tcf_classify(struct sk_buff *skb,
 
                        fchain = tcf_chain_lookup_rcu(block, chain);
                        if (!fchain) {
-                               tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
+                               tcf_set_drop_reason(skb,
+                                                   SKB_DROP_REASON_TC_CHAIN_NOTFOUND);
+
                                return TC_ACT_SHOT;
                        }
 
@@ -1799,10 +1806,9 @@ int tcf_classify(struct sk_buff *skb,
 
                        ext = tc_skb_ext_alloc(skb);
                        if (WARN_ON_ONCE(!ext)) {
-                               tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
+                               tcf_set_drop_reason(skb, SKB_DROP_REASON_NOMEM);
                                return TC_ACT_SHOT;
                        }
-
                        ext->chain = last_executed_chain;
                        ext->mru = cb->mru;
                        ext->post_ct = cb->post_ct;