Skip to content

Commit 8beecd4

Browse files
borkmannopsiff
authored andcommitted
net, sched: Add tcf_set_drop_reason for {__,}tcf_classify
mainline inclusion from mainline-v6.7-rc1 category: feature Add an initial user for the newly added tcf_set_drop_reason() helper to set the drop reason for internal errors leading to TC_ACT_SHOT inside {__,}tcf_classify(). Right now this only adds a very basic SKB_DROP_REASON_TC_ERROR as a generic fallback indicator to mark drop locations. Where needed, such locations can be converted to more specific codes, for example, when hitting the reclassification limit, etc. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Cc: Jamal Hadi Salim <jhs@mojatatu.com> Cc: Victor Nogueira <victor@mojatatu.com> Link: https://lore.kernel.org/r/20231009092655.22025-2-daniel@iogearbox.net Signed-off-by: Jakub Kicinski <kuba@kernel.org> (cherry picked from commit 39d08b9) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent bd303e1 commit 8beecd4

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

include/net/dropreason-core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
FN(IPV6_NDISC_BAD_OPTIONS) \
8181
FN(IPV6_NDISC_NS_OTHERHOST) \
8282
FN(QUEUE_PURGE) \
83+
FN(TC_ERROR) \
8384
FNe(MAX)
8485

8586
/**
@@ -345,6 +346,8 @@ enum skb_drop_reason {
345346
SKB_DROP_REASON_IPV6_NDISC_NS_OTHERHOST,
346347
/** @SKB_DROP_REASON_QUEUE_PURGE: bulk free. */
347348
SKB_DROP_REASON_QUEUE_PURGE,
349+
/** @SKB_DROP_REASON_TC_ERROR: generic internal tc error. */
350+
SKB_DROP_REASON_TC_ERROR,
348351
/**
349352
* @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which
350353
* shouldn't be used as a real 'reason' - only for tracing code gen

net/sched/cls_api.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,12 +1687,16 @@ static inline int __tcf_classify(struct sk_buff *skb,
16871687
* time we got here with a cookie from hardware.
16881688
*/
16891689
if (unlikely(n->tp != tp || n->tp->chain != n->chain ||
1690-
!tp->ops->get_exts))
1690+
!tp->ops->get_exts)) {
1691+
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
16911692
return TC_ACT_SHOT;
1693+
}
16921694

16931695
exts = tp->ops->get_exts(tp, n->handle);
1694-
if (unlikely(!exts || n->exts != exts))
1696+
if (unlikely(!exts || n->exts != exts)) {
1697+
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
16951698
return TC_ACT_SHOT;
1699+
}
16961700

16971701
n = NULL;
16981702
err = tcf_exts_exec_ex(skb, exts, act_index, res);
@@ -1718,8 +1722,10 @@ static inline int __tcf_classify(struct sk_buff *skb,
17181722
return err;
17191723
}
17201724

1721-
if (unlikely(n))
1725+
if (unlikely(n)) {
1726+
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
17221727
return TC_ACT_SHOT;
1728+
}
17231729

17241730
return TC_ACT_UNSPEC; /* signal: continue lookup */
17251731
#ifdef CONFIG_NET_CLS_ACT
@@ -1729,6 +1735,7 @@ static inline int __tcf_classify(struct sk_buff *skb,
17291735
tp->chain->block->index,
17301736
tp->prio & 0xffff,
17311737
ntohs(tp->protocol));
1738+
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
17321739
return TC_ACT_SHOT;
17331740
}
17341741

@@ -1765,17 +1772,21 @@ int tcf_classify(struct sk_buff *skb,
17651772
if (ext->act_miss) {
17661773
n = tcf_exts_miss_cookie_lookup(ext->act_miss_cookie,
17671774
&act_index);
1768-
if (!n)
1775+
if (!n) {
1776+
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
17691777
return TC_ACT_SHOT;
1778+
}
17701779

17711780
chain = n->chain_index;
17721781
} else {
17731782
chain = ext->chain;
17741783
}
17751784

17761785
fchain = tcf_chain_lookup_rcu(block, chain);
1777-
if (!fchain)
1786+
if (!fchain) {
1787+
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
17781788
return TC_ACT_SHOT;
1789+
}
17791790

17801791
/* Consume, so cloned/redirect skbs won't inherit ext */
17811792
skb_ext_del(skb, TC_SKB_EXT);
@@ -1794,8 +1805,11 @@ int tcf_classify(struct sk_buff *skb,
17941805
struct tc_skb_cb *cb = tc_skb_cb(skb);
17951806

17961807
ext = tc_skb_ext_alloc(skb);
1797-
if (WARN_ON_ONCE(!ext))
1808+
if (WARN_ON_ONCE(!ext)) {
1809+
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
17981810
return TC_ACT_SHOT;
1811+
}
1812+
17991813
ext->chain = last_executed_chain;
18001814
ext->mru = cb->mru;
18011815
ext->post_ct = cb->post_ct;

0 commit comments

Comments
 (0)