Skip to content

Commit c7eb7d7

Browse files
jpirkodavem330
authored andcommitted
net: sched: introduce chain_head_change callback
Add a callback that is to be called whenever head of the chain changes. Also provide a callback for the default case when the caller gets a block using non-extended getter. Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent aa5fbf0 commit c7eb7d7

File tree

4 files changed

+62
-47
lines changed

4 files changed

+62
-47
lines changed

include/net/pkt_cls.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ enum tcf_block_binder_type {
2626

2727
struct tcf_block_ext_info {
2828
enum tcf_block_binder_type binder_type;
29+
tcf_chain_head_change_t *chain_head_change;
30+
void *chain_head_change_priv;
2931
};
3032

3133
struct tcf_block_cb;
@@ -37,12 +39,10 @@ struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index,
3739
void tcf_chain_put(struct tcf_chain *chain);
3840
int tcf_block_get(struct tcf_block **p_block,
3941
struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q);
40-
int tcf_block_get_ext(struct tcf_block **p_block,
41-
struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q,
42+
int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q,
4243
struct tcf_block_ext_info *ei);
4344
void tcf_block_put(struct tcf_block *block);
44-
void tcf_block_put_ext(struct tcf_block *block,
45-
struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q,
45+
void tcf_block_put_ext(struct tcf_block *block, struct Qdisc *q,
4646
struct tcf_block_ext_info *ei);
4747

4848
static inline struct Qdisc *tcf_block_q(struct tcf_block *block)
@@ -82,8 +82,7 @@ int tcf_block_get(struct tcf_block **p_block,
8282
}
8383

8484
static inline
85-
int tcf_block_get_ext(struct tcf_block **p_block,
86-
struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q,
85+
int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q,
8786
struct tcf_block_ext_info *ei)
8887
{
8988
return 0;
@@ -94,8 +93,7 @@ static inline void tcf_block_put(struct tcf_block *block)
9493
}
9594

9695
static inline
97-
void tcf_block_put_ext(struct tcf_block *block,
98-
struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q,
96+
void tcf_block_put_ext(struct tcf_block *block, struct Qdisc *q,
9997
struct tcf_block_ext_info *ei)
10098
{
10199
}

include/net/sch_generic.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,12 @@ struct qdisc_skb_cb {
260260
unsigned char data[QDISC_CB_PRIV_LEN];
261261
};
262262

263+
typedef void tcf_chain_head_change_t(struct tcf_proto *tp_head, void *priv);
264+
263265
struct tcf_chain {
264266
struct tcf_proto __rcu *filter_chain;
265-
struct tcf_proto __rcu **p_filter_chain;
267+
tcf_chain_head_change_t *chain_head_change;
268+
void *chain_head_change_priv;
266269
struct list_head list;
267270
struct tcf_block *block;
268271
u32 index; /* chain index */

net/sched/cls_api.c

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,19 @@ static struct tcf_chain *tcf_chain_create(struct tcf_block *block,
195195
return chain;
196196
}
197197

198+
static void tcf_chain_head_change(struct tcf_chain *chain,
199+
struct tcf_proto *tp_head)
200+
{
201+
if (chain->chain_head_change)
202+
chain->chain_head_change(tp_head,
203+
chain->chain_head_change_priv);
204+
}
205+
198206
static void tcf_chain_flush(struct tcf_chain *chain)
199207
{
200208
struct tcf_proto *tp;
201209

202-
if (chain->p_filter_chain)
203-
RCU_INIT_POINTER(*chain->p_filter_chain, NULL);
210+
tcf_chain_head_change(chain, NULL);
204211
while ((tp = rtnl_dereference(chain->filter_chain)) != NULL) {
205212
RCU_INIT_POINTER(chain->filter_chain, tp->next);
206213
tcf_chain_put(chain);
@@ -242,13 +249,6 @@ void tcf_chain_put(struct tcf_chain *chain)
242249
}
243250
EXPORT_SYMBOL(tcf_chain_put);
244251

245-
static void
246-
tcf_chain_filter_chain_ptr_set(struct tcf_chain *chain,
247-
struct tcf_proto __rcu **p_filter_chain)
248-
{
249-
chain->p_filter_chain = p_filter_chain;
250-
}
251-
252252
static void tcf_block_offload_cmd(struct tcf_block *block, struct Qdisc *q,
253253
struct tcf_block_ext_info *ei,
254254
enum tc_block_command command)
@@ -276,8 +276,7 @@ static void tcf_block_offload_unbind(struct tcf_block *block, struct Qdisc *q,
276276
tcf_block_offload_cmd(block, q, ei, TC_BLOCK_UNBIND);
277277
}
278278

279-
int tcf_block_get_ext(struct tcf_block **p_block,
280-
struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q,
279+
int tcf_block_get_ext(struct tcf_block **p_block, struct Qdisc *q,
281280
struct tcf_block_ext_info *ei)
282281
{
283282
struct tcf_block *block = kzalloc(sizeof(*block), GFP_KERNEL);
@@ -295,7 +294,9 @@ int tcf_block_get_ext(struct tcf_block **p_block,
295294
err = -ENOMEM;
296295
goto err_chain_create;
297296
}
298-
tcf_chain_filter_chain_ptr_set(chain, p_filter_chain);
297+
WARN_ON(!ei->chain_head_change);
298+
chain->chain_head_change = ei->chain_head_change;
299+
chain->chain_head_change_priv = ei->chain_head_change_priv;
299300
block->net = qdisc_net(q);
300301
block->q = q;
301302
tcf_block_offload_bind(block, q, ei);
@@ -308,12 +309,23 @@ int tcf_block_get_ext(struct tcf_block **p_block,
308309
}
309310
EXPORT_SYMBOL(tcf_block_get_ext);
310311

312+
static void tcf_chain_head_change_dflt(struct tcf_proto *tp_head, void *priv)
313+
{
314+
struct tcf_proto __rcu **p_filter_chain = priv;
315+
316+
rcu_assign_pointer(*p_filter_chain, tp_head);
317+
}
318+
311319
int tcf_block_get(struct tcf_block **p_block,
312320
struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q)
313321
{
314-
struct tcf_block_ext_info ei = {0, };
322+
struct tcf_block_ext_info ei = {
323+
.chain_head_change = tcf_chain_head_change_dflt,
324+
.chain_head_change_priv = p_filter_chain,
325+
};
315326

316-
return tcf_block_get_ext(p_block, p_filter_chain, q, &ei);
327+
WARN_ON(!p_filter_chain);
328+
return tcf_block_get_ext(p_block, q, &ei);
317329
}
318330
EXPORT_SYMBOL(tcf_block_get);
319331

@@ -334,8 +346,7 @@ static void tcf_block_put_final(struct work_struct *work)
334346
* actions should be all removed after flushing. However, filters are now
335347
* destroyed in tc filter workqueue with RTNL lock, they can not race here.
336348
*/
337-
void tcf_block_put_ext(struct tcf_block *block,
338-
struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q,
349+
void tcf_block_put_ext(struct tcf_block *block, struct Qdisc *q,
339350
struct tcf_block_ext_info *ei)
340351
{
341352
struct tcf_chain *chain, *tmp;
@@ -361,7 +372,7 @@ void tcf_block_put(struct tcf_block *block)
361372

362373
if (!block)
363374
return;
364-
tcf_block_put_ext(block, NULL, block->q, &ei);
375+
tcf_block_put_ext(block, block->q, &ei);
365376
}
366377

367378
EXPORT_SYMBOL(tcf_block_put);
@@ -537,9 +548,8 @@ static void tcf_chain_tp_insert(struct tcf_chain *chain,
537548
struct tcf_chain_info *chain_info,
538549
struct tcf_proto *tp)
539550
{
540-
if (chain->p_filter_chain &&
541-
*chain_info->pprev == chain->filter_chain)
542-
rcu_assign_pointer(*chain->p_filter_chain, tp);
551+
if (*chain_info->pprev == chain->filter_chain)
552+
tcf_chain_head_change(chain, tp);
543553
RCU_INIT_POINTER(tp->next, tcf_chain_tp_prev(chain_info));
544554
rcu_assign_pointer(*chain_info->pprev, tp);
545555
tcf_chain_hold(chain);
@@ -551,8 +561,8 @@ static void tcf_chain_tp_remove(struct tcf_chain *chain,
551561
{
552562
struct tcf_proto *next = rtnl_dereference(chain_info->next);
553563

554-
if (chain->p_filter_chain && tp == chain->filter_chain)
555-
RCU_INIT_POINTER(*chain->p_filter_chain, next);
564+
if (tp == chain->filter_chain)
565+
tcf_chain_head_change(chain, next);
556566
RCU_INIT_POINTER(*chain_info->pprev, next);
557567
tcf_chain_put(chain);
558568
}

net/sched/sch_ingress.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,24 @@ static struct tcf_block *ingress_tcf_block(struct Qdisc *sch, unsigned long cl)
5454
return q->block;
5555
}
5656

57+
static void clsact_chain_head_change(struct tcf_proto *tp_head, void *priv)
58+
{
59+
struct tcf_proto __rcu **p_filter_chain = priv;
60+
61+
rcu_assign_pointer(*p_filter_chain, tp_head);
62+
}
63+
5764
static int ingress_init(struct Qdisc *sch, struct nlattr *opt)
5865
{
5966
struct ingress_sched_data *q = qdisc_priv(sch);
6067
struct net_device *dev = qdisc_dev(sch);
6168
int err;
6269

6370
q->block_info.binder_type = TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS;
71+
q->block_info.chain_head_change = clsact_chain_head_change;
72+
q->block_info.chain_head_change_priv = &dev->ingress_cl_list;
6473

65-
err = tcf_block_get_ext(&q->block, &dev->ingress_cl_list,
66-
sch, &q->block_info);
74+
err = tcf_block_get_ext(&q->block, sch, &q->block_info);
6775
if (err)
6876
return err;
6977

@@ -76,10 +84,8 @@ static int ingress_init(struct Qdisc *sch, struct nlattr *opt)
7684
static void ingress_destroy(struct Qdisc *sch)
7785
{
7886
struct ingress_sched_data *q = qdisc_priv(sch);
79-
struct net_device *dev = qdisc_dev(sch);
8087

81-
tcf_block_put_ext(q->block, &dev->ingress_cl_list,
82-
sch, &q->block_info);
88+
tcf_block_put_ext(q->block, sch, &q->block_info);
8389
net_dec_ingress_queue();
8490
}
8591

@@ -162,16 +168,18 @@ static int clsact_init(struct Qdisc *sch, struct nlattr *opt)
162168
int err;
163169

164170
q->ingress_block_info.binder_type = TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS;
171+
q->ingress_block_info.chain_head_change = clsact_chain_head_change;
172+
q->ingress_block_info.chain_head_change_priv = &dev->ingress_cl_list;
165173

166-
err = tcf_block_get_ext(&q->ingress_block, &dev->ingress_cl_list,
167-
sch, &q->ingress_block_info);
174+
err = tcf_block_get_ext(&q->ingress_block, sch, &q->ingress_block_info);
168175
if (err)
169176
return err;
170177

171178
q->egress_block_info.binder_type = TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS;
179+
q->egress_block_info.chain_head_change = clsact_chain_head_change;
180+
q->egress_block_info.chain_head_change_priv = &dev->egress_cl_list;
172181

173-
err = tcf_block_get_ext(&q->egress_block, &dev->egress_cl_list,
174-
sch, &q->egress_block_info);
182+
err = tcf_block_get_ext(&q->egress_block, sch, &q->egress_block_info);
175183
if (err)
176184
goto err_egress_block_get;
177185

@@ -183,20 +191,16 @@ static int clsact_init(struct Qdisc *sch, struct nlattr *opt)
183191
return 0;
184192

185193
err_egress_block_get:
186-
tcf_block_put_ext(q->ingress_block, &dev->ingress_cl_list,
187-
sch, &q->ingress_block_info);
194+
tcf_block_put_ext(q->ingress_block, sch, &q->ingress_block_info);
188195
return err;
189196
}
190197

191198
static void clsact_destroy(struct Qdisc *sch)
192199
{
193200
struct clsact_sched_data *q = qdisc_priv(sch);
194-
struct net_device *dev = qdisc_dev(sch);
195201

196-
tcf_block_put_ext(q->egress_block, &dev->egress_cl_list,
197-
sch, &q->egress_block_info);
198-
tcf_block_put_ext(q->ingress_block, &dev->ingress_cl_list,
199-
sch, &q->ingress_block_info);
202+
tcf_block_put_ext(q->egress_block, sch, &q->egress_block_info);
203+
tcf_block_put_ext(q->ingress_block, sch, &q->ingress_block_info);
200204

201205
net_dec_ingress_queue();
202206
net_dec_egress_queue();

0 commit comments

Comments
 (0)