Skip to content

Commit fb27807

Browse files
vbnogueiradavem330
authored andcommitted
net: sched: Move drop_reason to struct tc_skb_cb
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 <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 18764b8 commit fb27807

File tree

6 files changed

+25
-22
lines changed

6 files changed

+25
-22
lines changed

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
@@ -332,7 +332,6 @@ struct tcf_result {
332332
};
333333
const struct tcf_proto *goto_tp;
334334
};
335-
enum skb_drop_reason drop_reason;
336335
};
337336

338337
struct tcf_chain;

net/core/dev.c

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

39243924
tc_skb_cb(skb)->mru = 0;
39253925
tc_skb_cb(skb)->post_ct = false;
3926-
res.drop_reason = *drop_reason;
3926+
tcf_set_drop_reason(skb, *drop_reason);
39273927

39283928
mini_qdisc_bstats_cpu_update(miniq, skb);
39293929
ret = tcf_classify(skb, miniq->block, miniq->filter_list, &res, false);
39303930
/* Only tcf related quirks below. */
39313931
switch (ret) {
39323932
case TC_ACT_SHOT:
3933-
*drop_reason = res.drop_reason;
3933+
*drop_reason = tcf_get_drop_reason(skb);
39343934
mini_qdisc_qstats_cpu_drop(miniq);
39353935
break;
39363936
case TC_ACT_OK:

net/sched/act_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ int tcf_action_exec(struct sk_buff *skb, struct tc_action **actions,
11191119
}
11201120
} else if (TC_ACT_EXT_CMP(ret, TC_ACT_GOTO_CHAIN)) {
11211121
if (unlikely(!rcu_access_pointer(a->goto_chain))) {
1122-
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
1122+
tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
11231123
return TC_ACT_SHOT;
11241124
}
11251125
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
@@ -1657,7 +1657,6 @@ static inline int __tcf_classify(struct sk_buff *skb,
16571657
int act_index,
16581658
u32 *last_executed_chain)
16591659
{
1660-
u32 orig_reason = res->drop_reason;
16611660
#ifdef CONFIG_NET_CLS_ACT
16621661
const int max_reclassify_loop = 16;
16631662
const struct tcf_proto *first_tp;
@@ -1682,13 +1681,13 @@ static inline int __tcf_classify(struct sk_buff *skb,
16821681
*/
16831682
if (unlikely(n->tp != tp || n->tp->chain != n->chain ||
16841683
!tp->ops->get_exts)) {
1685-
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
1684+
tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
16861685
return TC_ACT_SHOT;
16871686
}
16881687

16891688
exts = tp->ops->get_exts(tp, n->handle);
16901689
if (unlikely(!exts || n->exts != exts)) {
1691-
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
1690+
tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
16921691
return TC_ACT_SHOT;
16931692
}
16941693

@@ -1712,18 +1711,12 @@ static inline int __tcf_classify(struct sk_buff *skb,
17121711
goto reset;
17131712
}
17141713
#endif
1715-
if (err >= 0) {
1716-
/* Policy drop or drop reason is over-written by
1717-
* classifiers with a bogus value(0) */
1718-
if (err == TC_ACT_SHOT &&
1719-
res->drop_reason == SKB_NOT_DROPPED_YET)
1720-
tcf_set_drop_reason(res, orig_reason);
1714+
if (err >= 0)
17211715
return err;
1722-
}
17231716
}
17241717

17251718
if (unlikely(n)) {
1726-
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
1719+
tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
17271720
return TC_ACT_SHOT;
17281721
}
17291722

@@ -1735,7 +1728,7 @@ static inline int __tcf_classify(struct sk_buff *skb,
17351728
tp->chain->block->index,
17361729
tp->prio & 0xffff,
17371730
ntohs(tp->protocol));
1738-
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
1731+
tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
17391732
return TC_ACT_SHOT;
17401733
}
17411734

@@ -1773,7 +1766,7 @@ int tcf_classify(struct sk_buff *skb,
17731766
n = tcf_exts_miss_cookie_lookup(ext->act_miss_cookie,
17741767
&act_index);
17751768
if (!n) {
1776-
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
1769+
tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
17771770
return TC_ACT_SHOT;
17781771
}
17791772

@@ -1784,7 +1777,7 @@ int tcf_classify(struct sk_buff *skb,
17841777

17851778
fchain = tcf_chain_lookup_rcu(block, chain);
17861779
if (!fchain) {
1787-
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
1780+
tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
17881781
return TC_ACT_SHOT;
17891782
}
17901783

@@ -1806,7 +1799,7 @@ int tcf_classify(struct sk_buff *skb,
18061799

18071800
ext = tc_skb_ext_alloc(skb);
18081801
if (WARN_ON_ONCE(!ext)) {
1809-
tcf_set_drop_reason(res, SKB_DROP_REASON_TC_ERROR);
1802+
tcf_set_drop_reason(skb, SKB_DROP_REASON_TC_ERROR);
18101803
return TC_ACT_SHOT;
18111804
}
18121805

0 commit comments

Comments
 (0)