net: sched: Move drop_reason to struct tc_skb_cb
authorVictor Nogueira <victor@mojatatu.com>
Sat, 16 Dec 2023 20:44:34 +0000 (17:44 -0300)
committerDavid S. Miller <davem@davemloft.net>
Wed, 20 Dec 2023 11:50:13 +0000 (11:50 +0000)
Move drop_reason from struct tcf_result to skb cb - more specifically to
struct tc_skb_cb. With that, we'll be able to also set the drop reason for
the remaining qdiscs (aside from clsact) that do not have access to
tcf_result when time comes to set the skb drop reason.

Signed-off-by: Victor Nogueira <victor@mojatatu.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/pkt_cls.h
include/net/pkt_sched.h
include/net/sch_generic.h
net/core/dev.c
net/sched/act_api.c
net/sched/cls_api.c

index a76c9171db0eff21154f939f027dcfb38c0e3ee5..761e4500cca09ac2a5ab6a08056b9302a183741f 100644 (file)
@@ -154,10 +154,20 @@ __cls_set_class(unsigned long *clp, unsigned long cl)
        return xchg(clp, cl);
 }
 
-static inline void tcf_set_drop_reason(struct tcf_result *res,
+struct tc_skb_cb;
+
+static inline struct tc_skb_cb *tc_skb_cb(const struct sk_buff *skb);
+
+static inline enum skb_drop_reason
+tcf_get_drop_reason(const struct sk_buff *skb)
+{
+       return tc_skb_cb(skb)->drop_reason;
+}
+
+static inline void tcf_set_drop_reason(const struct sk_buff *skb,
                                       enum skb_drop_reason reason)
 {
-       res->drop_reason = reason;
+       tc_skb_cb(skb)->drop_reason = reason;
 }
 
 static inline void
index 9fa1d0794dfa5241705f9a39c896ed44519a9f13..9b559aa5c079be9d56f8bd9295fed81d68dce5cd 100644 (file)
@@ -277,12 +277,13 @@ static inline void skb_txtime_consumed(struct sk_buff *skb)
 
 struct tc_skb_cb {
        struct qdisc_skb_cb qdisc_cb;
+       u32 drop_reason;
 
+       u16 zone; /* Only valid if post_ct = true */
        u16 mru;
        u8 post_ct:1;
        u8 post_ct_snat:1;
        u8 post_ct_dnat:1;
-       u16 zone; /* Only valid if post_ct = true */
 };
 
 static inline struct tc_skb_cb *tc_skb_cb(const struct sk_buff *skb)
index dcb9160e6467147d7e4d381aa5c5c6689fe824d8..c499b56bb215ce2be999dddaf1e3c9b437a0341b 100644 (file)
@@ -332,7 +332,6 @@ struct tcf_result {
                };
                const struct tcf_proto *goto_tp;
        };
-       enum skb_drop_reason            drop_reason;
 };
 
 struct tcf_chain;
index 0432b04cf9b000628497345d9ec0e8a141a617a3..16af89a733e416118e3017634dcc6a5f058374f8 100644 (file)
@@ -3923,14 +3923,14 @@ static int tc_run(struct tcx_entry *entry, struct sk_buff *skb,
 
        tc_skb_cb(skb)->mru = 0;
        tc_skb_cb(skb)->post_ct = false;
-       res.drop_reason = *drop_reason;
+       tcf_set_drop_reason(skb, *drop_reason);
 
        mini_qdisc_bstats_cpu_update(miniq, skb);
        ret = tcf_classify(skb, miniq->block, miniq->filter_list, &res, false);
        /* Only tcf related quirks below. */
        switch (ret) {
        case TC_ACT_SHOT:
-               *drop_reason = res.drop_reason;
+               *drop_reason = tcf_get_drop_reason(skb);
                mini_qdisc_qstats_cpu_drop(miniq);
                break;
        case TC_ACT_OK:
index 3a7770eff52d232bc4406c79f61e77514c931b9f..db500aa9f84190fcc65c6d853e52ecf9aa80e6d3 100644 (file)
@@ -1119,7 +1119,7 @@ repeat:
                        }
                } else if (TC_ACT_EXT_CMP(ret, TC_ACT_GOTO_CHAIN)) {
                        if (unlikely(!rcu_access_pointer(a->goto_chain))) {
-                               tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
+                               tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
                                return TC_ACT_SHOT;
                        }
                        tcf_action_goto_chain_exec(a, res);
index dc1c19a25882b9d5c02b1ad778e75b5912baf5be..199406e4bcdd99126503e89f53fc49242ceb75e7 100644 (file)
@@ -1657,7 +1657,6 @@ static inline int __tcf_classify(struct sk_buff *skb,
                                 int act_index,
                                 u32 *last_executed_chain)
 {
-       u32 orig_reason = res->drop_reason;
 #ifdef CONFIG_NET_CLS_ACT
        const int max_reclassify_loop = 16;
        const struct tcf_proto *first_tp;
@@ -1682,13 +1681,13 @@ reclassify:
                         */
                        if (unlikely(n->tp != tp || n->tp->chain != n->chain ||
                                     !tp->ops->get_exts)) {
-                               tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
+                               tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
                                return TC_ACT_SHOT;
                        }
 
                        exts = tp->ops->get_exts(tp, n->handle);
                        if (unlikely(!exts || n->exts != exts)) {
-                               tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
+                               tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
                                return TC_ACT_SHOT;
                        }
 
@@ -1712,18 +1711,12 @@ reclassify:
                        goto reset;
                }
 #endif
-               if (err >= 0) {
-                       /* Policy drop or drop reason is over-written by
-                        * classifiers with a bogus value(0) */
-                       if (err == TC_ACT_SHOT &&
-                           res->drop_reason == SKB_NOT_DROPPED_YET)
-                               tcf_set_drop_reason(res, orig_reason);
+               if (err >= 0)
                        return err;
-               }
        }
 
        if (unlikely(n)) {
-               tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
+               tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
                return TC_ACT_SHOT;
        }
 
@@ -1735,7 +1728,7 @@ reset:
                                       tp->chain->block->index,
                                       tp->prio & 0xffff,
                                       ntohs(tp->protocol));
-               tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
+               tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
                return TC_ACT_SHOT;
        }
 
@@ -1773,7 +1766,7 @@ 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(res, SKB_DROP_REASON_TC_ERROR);
+                                       tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
                                        return TC_ACT_SHOT;
                                }
 
@@ -1784,7 +1777,7 @@ int tcf_classify(struct sk_buff *skb,
 
                        fchain = tcf_chain_lookup_rcu(block, chain);
                        if (!fchain) {
-                               tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
+                               tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
                                return TC_ACT_SHOT;
                        }
 
@@ -1806,7 +1799,7 @@ int tcf_classify(struct sk_buff *skb,
 
                        ext = tc_skb_ext_alloc(skb);
                        if (WARN_ON_ONCE(!ext)) {
-                               tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
+                               tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
                                return TC_ACT_SHOT;
                        }