Skip to content

Commit 80bec12

Browse files
vbnogueiraAvenger-285714
authored andcommitted
net: sched: Make tc-related drop reason more flexible for remaining qdiscs
mainline inclusion from mainline-v6.8-rc1 category: feature Incrementing on Daniel's patch[1], make tc-related drop reason more flexible for remaining qdiscs - that is, all qdiscs aside from clsact. In essence, the drop reason will be set by cls_api and act_api in case any error occurred in the data path. With that, we can give the user more detailed information so that they can distinguish between a policy drop or an error drop. [1] https://lore.kernel.org/all/20231009092655.22025-1-daniel@iogearbox.net 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 b6a3c60) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent a161797 commit 80bec12

4 files changed

Lines changed: 36 additions & 37 deletions

File tree

include/net/pkt_cls.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -154,22 +154,6 @@ __cls_set_class(unsigned long *clp, unsigned long cl)
154154
return xchg(clp, cl);
155155
}
156156

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,
168-
enum skb_drop_reason reason)
169-
{
170-
tc_skb_cb(skb)->drop_reason = reason;
171-
}
172-
173157
static inline void
174158
__tcf_bind_filter(struct Qdisc *q, struct tcf_result *r, unsigned long base)
175159
{

include/net/pkt_sched.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -275,25 +275,6 @@ static inline void skb_txtime_consumed(struct sk_buff *skb)
275275
skb->tstamp = ktime_set(0, 0);
276276
}
277277

278-
struct tc_skb_cb {
279-
struct qdisc_skb_cb qdisc_cb;
280-
u32 drop_reason;
281-
282-
u16 zone; /* Only valid if post_ct = true */
283-
u16 mru;
284-
u8 post_ct:1;
285-
u8 post_ct_snat:1;
286-
u8 post_ct_dnat:1;
287-
};
288-
289-
static inline struct tc_skb_cb *tc_skb_cb(const struct sk_buff *skb)
290-
{
291-
struct tc_skb_cb *cb = (struct tc_skb_cb *)skb->cb;
292-
293-
BUILD_BUG_ON(sizeof(*cb) > sizeof_field(struct sk_buff, cb));
294-
return cb;
295-
}
296-
297278
static inline bool tc_qdisc_stats_dump(struct Qdisc *sch,
298279
unsigned long cl,
299280
struct qdisc_walker *arg)

include/net/sch_generic.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,37 @@ static inline struct sk_buff *qdisc_dequeue_head(struct Qdisc *sch)
10631063
return skb;
10641064
}
10651065

1066+
struct tc_skb_cb {
1067+
struct qdisc_skb_cb qdisc_cb;
1068+
u32 drop_reason;
1069+
1070+
u16 zone; /* Only valid if post_ct = true */
1071+
u16 mru;
1072+
u8 post_ct:1;
1073+
u8 post_ct_snat:1;
1074+
u8 post_ct_dnat:1;
1075+
};
1076+
1077+
static inline struct tc_skb_cb *tc_skb_cb(const struct sk_buff *skb)
1078+
{
1079+
struct tc_skb_cb *cb = (struct tc_skb_cb *)skb->cb;
1080+
1081+
BUILD_BUG_ON(sizeof(*cb) > sizeof_field(struct sk_buff, cb));
1082+
return cb;
1083+
}
1084+
1085+
static inline enum skb_drop_reason
1086+
tcf_get_drop_reason(const struct sk_buff *skb)
1087+
{
1088+
return tc_skb_cb(skb)->drop_reason;
1089+
}
1090+
1091+
static inline void tcf_set_drop_reason(const struct sk_buff *skb,
1092+
enum skb_drop_reason reason)
1093+
{
1094+
tc_skb_cb(skb)->drop_reason = reason;
1095+
}
1096+
10661097
/* Instead of calling kfree_skb() while root qdisc lock is held,
10671098
* queue the skb for future freeing at end of __dev_xmit_skb()
10681099
*/

net/core/dev.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3826,6 +3826,8 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
38263826

38273827
qdisc_calculate_pkt_len(skb, q);
38283828

3829+
tcf_set_drop_reason(skb, SKB_DROP_REASON_QDISC_DROP);
3830+
38293831
if (q->flags & TCQ_F_NOLOCK) {
38303832
if (q->flags & TCQ_F_CAN_BYPASS && nolock_qdisc_is_empty(q) &&
38313833
qdisc_run_begin(q)) {
@@ -3855,7 +3857,7 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
38553857
no_lock_out:
38563858
if (unlikely(to_free))
38573859
kfree_skb_list_reason(to_free,
3858-
SKB_DROP_REASON_QDISC_DROP);
3860+
tcf_get_drop_reason(to_free));
38593861
return rc;
38603862
}
38613863

@@ -3910,7 +3912,8 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
39103912
}
39113913
spin_unlock(root_lock);
39123914
if (unlikely(to_free))
3913-
kfree_skb_list_reason(to_free, SKB_DROP_REASON_QDISC_DROP);
3915+
kfree_skb_list_reason(to_free,
3916+
tcf_get_drop_reason(to_free));
39143917
if (unlikely(contended))
39153918
spin_unlock(&q->busylock);
39163919
return rc;

0 commit comments

Comments
 (0)