Skip to content

Commit a161797

Browse files
vbnogueiraAvenger-285714
authored andcommitted
net: sched: Move drop_reason to struct tc_skb_cb
mainline inclusion from mainline-v6.8-rc1 category: feature 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> (cherry picked from commit fb27807) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 1e2d4d8 commit a161797

6 files changed

Lines changed: 25 additions & 22 deletions

File tree

include/net/pkt_cls.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,20 @@ __cls_set_class(unsigned long *clp, unsigned long cl)
154154
return xchg(clp, cl);
155155
}
156156

157-
static inline void tcf_set_drop_reason(struct tcf_result *res,
157+
struct tc_skb_cb;
158+
159+
static inline struct tc_skb_cb *tc_skb_cb(const struct sk_buff *skb);
160+
161+
static inline enum skb_drop_reason
162+
tcf_get_drop_reason(const struct sk_buff *skb)
163+
{
164+
return tc_skb_cb(skb)->drop_reason;
165+
}
166+
167+
static inline void tcf_set_drop_reason(const struct sk_buff *skb,
158168
enum skb_drop_reason reason)
159169
{
160-
res->drop_reason = reason;
170+
tc_skb_cb(skb)->drop_reason = reason;
161171
}
162172

163173
static inline void

include/net/pkt_sched.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,13 @@ static inline void skb_txtime_consumed(struct sk_buff *skb)
277277

278278
struct tc_skb_cb {
279279
struct qdisc_skb_cb qdisc_cb;
280+
u32 drop_reason;
280281

282+
u16 zone; /* Only valid if post_ct = true */
281283
u16 mru;
282284
u8 post_ct:1;
283285
u8 post_ct_snat:1;
284286
u8 post_ct_dnat:1;
285-
u16 zone; /* Only valid if post_ct = true */
286287
};
287288

288289
static inline struct tc_skb_cb *tc_skb_cb(const struct sk_buff *skb)

include/net/sch_generic.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ struct tcf_result {
342342
};
343343
const struct tcf_proto *goto_tp;
344344
};
345-
enum skb_drop_reason drop_reason;
346345
};
347346

348347
struct tcf_chain;

net/core/dev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3996,14 +3996,14 @@ static int tc_run(struct tcx_entry *entry, struct sk_buff *skb,
39963996

39973997
tc_skb_cb(skb)->mru = 0;
39983998
tc_skb_cb(skb)->post_ct = false;
3999-
res.drop_reason = *drop_reason;
3999+
tcf_set_drop_reason(skb, *drop_reason);
40004000

40014001
mini_qdisc_bstats_cpu_update(miniq, skb);
40024002
ret = tcf_classify(skb, miniq->block, miniq->filter_list, &res, false);
40034003
/* Only tcf related quirks below. */
40044004
switch (ret) {
40054005
case TC_ACT_SHOT:
4006-
*drop_reason = res.drop_reason;
4006+
*drop_reason = tcf_get_drop_reason(skb);
40074007
mini_qdisc_qstats_cpu_drop(miniq);
40084008
break;
40094009
case TC_ACT_OK:

net/sched/act_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ int tcf_action_exec(struct sk_buff *skb, struct tc_action **actions,
11181118
}
11191119
} else if (TC_ACT_EXT_CMP(ret, TC_ACT_GOTO_CHAIN)) {
11201120
if (unlikely(!rcu_access_pointer(a->goto_chain))) {
1121-
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
1121+
tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
11221122
return TC_ACT_SHOT;
11231123
}
11241124
tcf_action_goto_chain_exec(a, res);

net/sched/cls_api.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,6 @@ static inline int __tcf_classify(struct sk_buff *skb,
16641664
int act_index,
16651665
u32 *last_executed_chain)
16661666
{
1667-
u32 orig_reason = res->drop_reason;
16681667
#ifdef CONFIG_NET_CLS_ACT
16691668
const int max_reclassify_loop = 16;
16701669
const struct tcf_proto *first_tp;
@@ -1689,13 +1688,13 @@ static inline int __tcf_classify(struct sk_buff *skb,
16891688
*/
16901689
if (unlikely(n->tp != tp || n->tp->chain != n->chain ||
16911690
!tp->ops->get_exts)) {
1692-
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
1691+
tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
16931692
return TC_ACT_SHOT;
16941693
}
16951694

16961695
exts = tp->ops->get_exts(tp, n->handle);
16971696
if (unlikely(!exts || n->exts != exts)) {
1698-
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
1697+
tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
16991698
return TC_ACT_SHOT;
17001699
}
17011700

@@ -1719,18 +1718,12 @@ static inline int __tcf_classify(struct sk_buff *skb,
17191718
goto reset;
17201719
}
17211720
#endif
1722-
if (err >= 0) {
1723-
/* Policy drop or drop reason is over-written by
1724-
* classifiers with a bogus value(0) */
1725-
if (err == TC_ACT_SHOT &&
1726-
res->drop_reason == SKB_NOT_DROPPED_YET)
1727-
tcf_set_drop_reason(res, orig_reason);
1721+
if (err >= 0)
17281722
return err;
1729-
}
17301723
}
17311724

17321725
if (unlikely(n)) {
1733-
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
1726+
tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
17341727
return TC_ACT_SHOT;
17351728
}
17361729

@@ -1742,7 +1735,7 @@ static inline int __tcf_classify(struct sk_buff *skb,
17421735
tp->chain->block->index,
17431736
tp->prio & 0xffff,
17441737
ntohs(tp->protocol));
1745-
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
1738+
tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
17461739
return TC_ACT_SHOT;
17471740
}
17481741

@@ -1780,7 +1773,7 @@ int tcf_classify(struct sk_buff *skb,
17801773
n = tcf_exts_miss_cookie_lookup(ext->act_miss_cookie,
17811774
&act_index);
17821775
if (!n) {
1783-
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
1776+
tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
17841777
return TC_ACT_SHOT;
17851778
}
17861779

@@ -1791,7 +1784,7 @@ int tcf_classify(struct sk_buff *skb,
17911784

17921785
fchain = tcf_chain_lookup_rcu(block, chain);
17931786
if (!fchain) {
1794-
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
1787+
tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
17951788
return TC_ACT_SHOT;
17961789
}
17971790

@@ -1813,7 +1806,7 @@ int tcf_classify(struct sk_buff *skb,
18131806

18141807
ext = tc_skb_ext_alloc(skb);
18151808
if (WARN_ON_ONCE(!ext)) {
1816-
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
1809+
tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
18171810
return TC_ACT_SHOT;
18181811
}
18191812

0 commit comments

Comments
 (0)