Skip to content

Commit b6a3c60

Browse files
vbnogueiradavem330
authored andcommitted
net: sched: Make tc-related drop reason more flexible for remaining qdiscs
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/[email protected] Signed-off-by: Victor Nogueira <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent fb27807 commit b6a3c60

File tree

4 files changed

+36
-37
lines changed

4 files changed

+36
-37
lines changed

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
@@ -1036,6 +1036,37 @@ static inline struct sk_buff *qdisc_dequeue_head(struct Qdisc *sch)
10361036
return skb;
10371037
}
10381038

1039+
struct tc_skb_cb {
1040+
struct qdisc_skb_cb qdisc_cb;
1041+
u32 drop_reason;
1042+
1043+
u16 zone; /* Only valid if post_ct = true */
1044+
u16 mru;
1045+
u8 post_ct:1;
1046+
u8 post_ct_snat:1;
1047+
u8 post_ct_dnat:1;
1048+
};
1049+
1050+
static inline struct tc_skb_cb *tc_skb_cb(const struct sk_buff *skb)
1051+
{
1052+
struct tc_skb_cb *cb = (struct tc_skb_cb *)skb->cb;
1053+
1054+
BUILD_BUG_ON(sizeof(*cb) > sizeof_field(struct sk_buff, cb));
1055+
return cb;
1056+
}
1057+
1058+
static inline enum skb_drop_reason
1059+
tcf_get_drop_reason(const struct sk_buff *skb)
1060+
{
1061+
return tc_skb_cb(skb)->drop_reason;
1062+
}
1063+
1064+
static inline void tcf_set_drop_reason(const struct sk_buff *skb,
1065+
enum skb_drop_reason reason)
1066+
{
1067+
tc_skb_cb(skb)->drop_reason = reason;
1068+
}
1069+
10391070
/* Instead of calling kfree_skb() while root qdisc lock is held,
10401071
* queue the skb for future freeing at end of __dev_xmit_skb()
10411072
*/

net/core/dev.c

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

37543754
qdisc_calculate_pkt_len(skb, q);
37553755

3756+
tcf_set_drop_reason(skb, SKB_DROP_REASON_QDISC_DROP);
3757+
37563758
if (q->flags & TCQ_F_NOLOCK) {
37573759
if (q->flags & TCQ_F_CAN_BYPASS && nolock_qdisc_is_empty(q) &&
37583760
qdisc_run_begin(q)) {
@@ -3782,7 +3784,7 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
37823784
no_lock_out:
37833785
if (unlikely(to_free))
37843786
kfree_skb_list_reason(to_free,
3785-
SKB_DROP_REASON_QDISC_DROP);
3787+
tcf_get_drop_reason(to_free));
37863788
return rc;
37873789
}
37883790

@@ -3837,7 +3839,8 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
38373839
}
38383840
spin_unlock(root_lock);
38393841
if (unlikely(to_free))
3840-
kfree_skb_list_reason(to_free, SKB_DROP_REASON_QDISC_DROP);
3842+
kfree_skb_list_reason(to_free,
3843+
tcf_get_drop_reason(to_free));
38413844
if (unlikely(contended))
38423845
spin_unlock(&q->busylock);
38433846
return rc;

0 commit comments

Comments
 (0)