Commit 39d08b91 authored by Daniel Borkmann's avatar Daniel Borkmann Committed by Jakub Kicinski

net, sched: Add tcf_set_drop_reason for {__,}tcf_classify

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: default avatarDaniel 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.netSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 54a59aed
...@@ -80,6 +80,7 @@ ...@@ -80,6 +80,7 @@
FN(IPV6_NDISC_BAD_OPTIONS) \ FN(IPV6_NDISC_BAD_OPTIONS) \
FN(IPV6_NDISC_NS_OTHERHOST) \ FN(IPV6_NDISC_NS_OTHERHOST) \
FN(QUEUE_PURGE) \ FN(QUEUE_PURGE) \
FN(TC_ERROR) \
FNe(MAX) FNe(MAX)
/** /**
...@@ -345,6 +346,8 @@ enum skb_drop_reason { ...@@ -345,6 +346,8 @@ enum skb_drop_reason {
SKB_DROP_REASON_IPV6_NDISC_NS_OTHERHOST, SKB_DROP_REASON_IPV6_NDISC_NS_OTHERHOST,
/** @SKB_DROP_REASON_QUEUE_PURGE: bulk free. */ /** @SKB_DROP_REASON_QUEUE_PURGE: bulk free. */
SKB_DROP_REASON_QUEUE_PURGE, SKB_DROP_REASON_QUEUE_PURGE,
/** @SKB_DROP_REASON_TC_ERROR: generic internal tc error. */
SKB_DROP_REASON_TC_ERROR,
/** /**
* @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which
* shouldn't be used as a real 'reason' - only for tracing code gen * shouldn't be used as a real 'reason' - only for tracing code gen
......
...@@ -1681,12 +1681,16 @@ static inline int __tcf_classify(struct sk_buff *skb, ...@@ -1681,12 +1681,16 @@ static inline int __tcf_classify(struct sk_buff *skb,
* time we got here with a cookie from hardware. * time we got here with a cookie from hardware.
*/ */
if (unlikely(n->tp != tp || n->tp->chain != n->chain || if (unlikely(n->tp != tp || n->tp->chain != n->chain ||
!tp->ops->get_exts)) !tp->ops->get_exts)) {
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
return TC_ACT_SHOT; return TC_ACT_SHOT;
}
exts = tp->ops->get_exts(tp, n->handle); exts = tp->ops->get_exts(tp, n->handle);
if (unlikely(!exts || n->exts != exts)) if (unlikely(!exts || n->exts != exts)) {
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
return TC_ACT_SHOT; return TC_ACT_SHOT;
}
n = NULL; n = NULL;
err = tcf_exts_exec_ex(skb, exts, act_index, res); err = tcf_exts_exec_ex(skb, exts, act_index, res);
...@@ -1712,8 +1716,10 @@ static inline int __tcf_classify(struct sk_buff *skb, ...@@ -1712,8 +1716,10 @@ static inline int __tcf_classify(struct sk_buff *skb,
return err; return err;
} }
if (unlikely(n)) if (unlikely(n)) {
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
return TC_ACT_SHOT; return TC_ACT_SHOT;
}
return TC_ACT_UNSPEC; /* signal: continue lookup */ return TC_ACT_UNSPEC; /* signal: continue lookup */
#ifdef CONFIG_NET_CLS_ACT #ifdef CONFIG_NET_CLS_ACT
...@@ -1723,6 +1729,7 @@ static inline int __tcf_classify(struct sk_buff *skb, ...@@ -1723,6 +1729,7 @@ static inline int __tcf_classify(struct sk_buff *skb,
tp->chain->block->index, tp->chain->block->index,
tp->prio & 0xffff, tp->prio & 0xffff,
ntohs(tp->protocol)); ntohs(tp->protocol));
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
return TC_ACT_SHOT; return TC_ACT_SHOT;
} }
...@@ -1759,8 +1766,10 @@ int tcf_classify(struct sk_buff *skb, ...@@ -1759,8 +1766,10 @@ int tcf_classify(struct sk_buff *skb,
if (ext->act_miss) { if (ext->act_miss) {
n = tcf_exts_miss_cookie_lookup(ext->act_miss_cookie, n = tcf_exts_miss_cookie_lookup(ext->act_miss_cookie,
&act_index); &act_index);
if (!n) if (!n) {
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
return TC_ACT_SHOT; return TC_ACT_SHOT;
}
chain = n->chain_index; chain = n->chain_index;
} else { } else {
...@@ -1768,8 +1777,10 @@ int tcf_classify(struct sk_buff *skb, ...@@ -1768,8 +1777,10 @@ int tcf_classify(struct sk_buff *skb,
} }
fchain = tcf_chain_lookup_rcu(block, chain); fchain = tcf_chain_lookup_rcu(block, chain);
if (!fchain) if (!fchain) {
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
return TC_ACT_SHOT; return TC_ACT_SHOT;
}
/* Consume, so cloned/redirect skbs won't inherit ext */ /* Consume, so cloned/redirect skbs won't inherit ext */
skb_ext_del(skb, TC_SKB_EXT); skb_ext_del(skb, TC_SKB_EXT);
...@@ -1788,8 +1799,11 @@ int tcf_classify(struct sk_buff *skb, ...@@ -1788,8 +1799,11 @@ int tcf_classify(struct sk_buff *skb,
struct tc_skb_cb *cb = tc_skb_cb(skb); struct tc_skb_cb *cb = tc_skb_cb(skb);
ext = tc_skb_ext_alloc(skb); ext = tc_skb_ext_alloc(skb);
if (WARN_ON_ONCE(!ext)) if (WARN_ON_ONCE(!ext)) {
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
return TC_ACT_SHOT; return TC_ACT_SHOT;
}
ext->chain = last_executed_chain; ext->chain = last_executed_chain;
ext->mru = cb->mru; ext->mru = cb->mru;
ext->post_ct = cb->post_ct; ext->post_ct = cb->post_ct;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment