Skip to content

Commit b409074

Browse files
w1ldptrdavem330
authored andcommitted
net: sched: add 'delete' function to action ops
Extend action ops with 'delete' function. Each action type to implements its own delete function that doesn't depend on rtnl lock. Implement delete function that is required to delete actions without holding rtnl lock. Use action API function that atomically deletes action only if it is still in action idr. This implementation prevents concurrent threads from deleting same action twice. Reviewed-by: Marcelo Ricardo Leitner <[email protected]> Signed-off-by: Vlad Buslov <[email protected]> Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2a2ea34 commit b409074

17 files changed

+137
-0
lines changed

include/net/act_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ struct tc_action_ops {
101101
void (*stats_update)(struct tc_action *, u64, u32, u64);
102102
size_t (*get_fill_size)(const struct tc_action *act);
103103
struct net_device *(*get_dev)(const struct tc_action *a);
104+
int (*delete)(struct net *net, u32 index);
104105
};
105106

106107
struct tc_action_net {

net/sched/act_bpf.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,13 @@ static int tcf_bpf_search(struct net *net, struct tc_action **a, u32 index,
388388
return tcf_idr_search(tn, a, index);
389389
}
390390

391+
static int tcf_bpf_delete(struct net *net, u32 index)
392+
{
393+
struct tc_action_net *tn = net_generic(net, bpf_net_id);
394+
395+
return tcf_idr_delete_index(tn, index);
396+
}
397+
391398
static struct tc_action_ops act_bpf_ops __read_mostly = {
392399
.kind = "bpf",
393400
.type = TCA_ACT_BPF,
@@ -398,6 +405,7 @@ static struct tc_action_ops act_bpf_ops __read_mostly = {
398405
.init = tcf_bpf_init,
399406
.walk = tcf_bpf_walker,
400407
.lookup = tcf_bpf_search,
408+
.delete = tcf_bpf_delete,
401409
.size = sizeof(struct tcf_bpf),
402410
};
403411

net/sched/act_connmark.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ static int tcf_connmark_search(struct net *net, struct tc_action **a, u32 index,
193193
return tcf_idr_search(tn, a, index);
194194
}
195195

196+
static int tcf_connmark_delete(struct net *net, u32 index)
197+
{
198+
struct tc_action_net *tn = net_generic(net, connmark_net_id);
199+
200+
return tcf_idr_delete_index(tn, index);
201+
}
202+
196203
static struct tc_action_ops act_connmark_ops = {
197204
.kind = "connmark",
198205
.type = TCA_ACT_CONNMARK,
@@ -202,6 +209,7 @@ static struct tc_action_ops act_connmark_ops = {
202209
.init = tcf_connmark_init,
203210
.walk = tcf_connmark_walker,
204211
.lookup = tcf_connmark_search,
212+
.delete = tcf_connmark_delete,
205213
.size = sizeof(struct tcf_connmark_info),
206214
};
207215

net/sched/act_csum.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,13 @@ static size_t tcf_csum_get_fill_size(const struct tc_action *act)
654654
return nla_total_size(sizeof(struct tc_csum));
655655
}
656656

657+
static int tcf_csum_delete(struct net *net, u32 index)
658+
{
659+
struct tc_action_net *tn = net_generic(net, csum_net_id);
660+
661+
return tcf_idr_delete_index(tn, index);
662+
}
663+
657664
static struct tc_action_ops act_csum_ops = {
658665
.kind = "csum",
659666
.type = TCA_ACT_CSUM,
@@ -665,6 +672,7 @@ static struct tc_action_ops act_csum_ops = {
665672
.walk = tcf_csum_walker,
666673
.lookup = tcf_csum_search,
667674
.get_fill_size = tcf_csum_get_fill_size,
675+
.delete = tcf_csum_delete,
668676
.size = sizeof(struct tcf_csum),
669677
};
670678

net/sched/act_gact.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@ static size_t tcf_gact_get_fill_size(const struct tc_action *act)
231231
return sz;
232232
}
233233

234+
static int tcf_gact_delete(struct net *net, u32 index)
235+
{
236+
struct tc_action_net *tn = net_generic(net, gact_net_id);
237+
238+
return tcf_idr_delete_index(tn, index);
239+
}
240+
234241
static struct tc_action_ops act_gact_ops = {
235242
.kind = "gact",
236243
.type = TCA_ACT_GACT,
@@ -242,6 +249,7 @@ static struct tc_action_ops act_gact_ops = {
242249
.walk = tcf_gact_walker,
243250
.lookup = tcf_gact_search,
244251
.get_fill_size = tcf_gact_get_fill_size,
252+
.delete = tcf_gact_delete,
245253
.size = sizeof(struct tcf_gact),
246254
};
247255

net/sched/act_ife.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,13 @@ static int tcf_ife_search(struct net *net, struct tc_action **a, u32 index,
844844
return tcf_idr_search(tn, a, index);
845845
}
846846

847+
static int tcf_ife_delete(struct net *net, u32 index)
848+
{
849+
struct tc_action_net *tn = net_generic(net, ife_net_id);
850+
851+
return tcf_idr_delete_index(tn, index);
852+
}
853+
847854
static struct tc_action_ops act_ife_ops = {
848855
.kind = "ife",
849856
.type = TCA_ACT_IFE,
@@ -854,6 +861,7 @@ static struct tc_action_ops act_ife_ops = {
854861
.init = tcf_ife_init,
855862
.walk = tcf_ife_walker,
856863
.lookup = tcf_ife_search,
864+
.delete = tcf_ife_delete,
857865
.size = sizeof(struct tcf_ife_info),
858866
};
859867

net/sched/act_ipt.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,13 @@ static int tcf_ipt_search(struct net *net, struct tc_action **a, u32 index,
324324
return tcf_idr_search(tn, a, index);
325325
}
326326

327+
static int tcf_ipt_delete(struct net *net, u32 index)
328+
{
329+
struct tc_action_net *tn = net_generic(net, ipt_net_id);
330+
331+
return tcf_idr_delete_index(tn, index);
332+
}
333+
327334
static struct tc_action_ops act_ipt_ops = {
328335
.kind = "ipt",
329336
.type = TCA_ACT_IPT,
@@ -334,6 +341,7 @@ static struct tc_action_ops act_ipt_ops = {
334341
.init = tcf_ipt_init,
335342
.walk = tcf_ipt_walker,
336343
.lookup = tcf_ipt_search,
344+
.delete = tcf_ipt_delete,
337345
.size = sizeof(struct tcf_ipt),
338346
};
339347

@@ -374,6 +382,13 @@ static int tcf_xt_search(struct net *net, struct tc_action **a, u32 index,
374382
return tcf_idr_search(tn, a, index);
375383
}
376384

385+
static int tcf_xt_delete(struct net *net, u32 index)
386+
{
387+
struct tc_action_net *tn = net_generic(net, xt_net_id);
388+
389+
return tcf_idr_delete_index(tn, index);
390+
}
391+
377392
static struct tc_action_ops act_xt_ops = {
378393
.kind = "xt",
379394
.type = TCA_ACT_XT,
@@ -384,6 +399,7 @@ static struct tc_action_ops act_xt_ops = {
384399
.init = tcf_xt_init,
385400
.walk = tcf_xt_walker,
386401
.lookup = tcf_xt_search,
402+
.delete = tcf_xt_delete,
387403
.size = sizeof(struct tcf_ipt),
388404
};
389405

net/sched/act_mirred.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,13 @@ static struct net_device *tcf_mirred_get_dev(const struct tc_action *a)
322322
return rtnl_dereference(m->tcfm_dev);
323323
}
324324

325+
static int tcf_mirred_delete(struct net *net, u32 index)
326+
{
327+
struct tc_action_net *tn = net_generic(net, mirred_net_id);
328+
329+
return tcf_idr_delete_index(tn, index);
330+
}
331+
325332
static struct tc_action_ops act_mirred_ops = {
326333
.kind = "mirred",
327334
.type = TCA_ACT_MIRRED,
@@ -335,6 +342,7 @@ static struct tc_action_ops act_mirred_ops = {
335342
.lookup = tcf_mirred_search,
336343
.size = sizeof(struct tcf_mirred),
337344
.get_dev = tcf_mirred_get_dev,
345+
.delete = tcf_mirred_delete,
338346
};
339347

340348
static __net_init int mirred_init_net(struct net *net)

net/sched/act_nat.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,13 @@ static int tcf_nat_search(struct net *net, struct tc_action **a, u32 index,
294294
return tcf_idr_search(tn, a, index);
295295
}
296296

297+
static int tcf_nat_delete(struct net *net, u32 index)
298+
{
299+
struct tc_action_net *tn = net_generic(net, nat_net_id);
300+
301+
return tcf_idr_delete_index(tn, index);
302+
}
303+
297304
static struct tc_action_ops act_nat_ops = {
298305
.kind = "nat",
299306
.type = TCA_ACT_NAT,
@@ -303,6 +310,7 @@ static struct tc_action_ops act_nat_ops = {
303310
.init = tcf_nat_init,
304311
.walk = tcf_nat_walker,
305312
.lookup = tcf_nat_search,
313+
.delete = tcf_nat_delete,
306314
.size = sizeof(struct tcf_nat),
307315
};
308316

net/sched/act_pedit.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,13 @@ static int tcf_pedit_search(struct net *net, struct tc_action **a, u32 index,
454454
return tcf_idr_search(tn, a, index);
455455
}
456456

457+
static int tcf_pedit_delete(struct net *net, u32 index)
458+
{
459+
struct tc_action_net *tn = net_generic(net, pedit_net_id);
460+
461+
return tcf_idr_delete_index(tn, index);
462+
}
463+
457464
static struct tc_action_ops act_pedit_ops = {
458465
.kind = "pedit",
459466
.type = TCA_ACT_PEDIT,
@@ -464,6 +471,7 @@ static struct tc_action_ops act_pedit_ops = {
464471
.init = tcf_pedit_init,
465472
.walk = tcf_pedit_walker,
466473
.lookup = tcf_pedit_search,
474+
.delete = tcf_pedit_delete,
467475
.size = sizeof(struct tcf_pedit),
468476
};
469477

net/sched/act_police.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,13 @@ static int tcf_police_search(struct net *net, struct tc_action **a, u32 index,
314314
return tcf_idr_search(tn, a, index);
315315
}
316316

317+
static int tcf_police_delete(struct net *net, u32 index)
318+
{
319+
struct tc_action_net *tn = net_generic(net, police_net_id);
320+
321+
return tcf_idr_delete_index(tn, index);
322+
}
323+
317324
MODULE_AUTHOR("Alexey Kuznetsov");
318325
MODULE_DESCRIPTION("Policing actions");
319326
MODULE_LICENSE("GPL");
@@ -327,6 +334,7 @@ static struct tc_action_ops act_police_ops = {
327334
.init = tcf_act_police_init,
328335
.walk = tcf_act_police_walker,
329336
.lookup = tcf_police_search,
337+
.delete = tcf_police_delete,
330338
.size = sizeof(struct tcf_police),
331339
};
332340

net/sched/act_sample.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ static int tcf_sample_search(struct net *net, struct tc_action **a, u32 index,
220220
return tcf_idr_search(tn, a, index);
221221
}
222222

223+
static int tcf_sample_delete(struct net *net, u32 index)
224+
{
225+
struct tc_action_net *tn = net_generic(net, sample_net_id);
226+
227+
return tcf_idr_delete_index(tn, index);
228+
}
229+
223230
static struct tc_action_ops act_sample_ops = {
224231
.kind = "sample",
225232
.type = TCA_ACT_SAMPLE,
@@ -230,6 +237,7 @@ static struct tc_action_ops act_sample_ops = {
230237
.cleanup = tcf_sample_cleanup,
231238
.walk = tcf_sample_walker,
232239
.lookup = tcf_sample_search,
240+
.delete = tcf_sample_delete,
233241
.size = sizeof(struct tcf_sample),
234242
};
235243

net/sched/act_simple.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ static int tcf_simp_search(struct net *net, struct tc_action **a, u32 index,
184184
return tcf_idr_search(tn, a, index);
185185
}
186186

187+
static int tcf_simp_delete(struct net *net, u32 index)
188+
{
189+
struct tc_action_net *tn = net_generic(net, simp_net_id);
190+
191+
return tcf_idr_delete_index(tn, index);
192+
}
193+
187194
static struct tc_action_ops act_simp_ops = {
188195
.kind = "simple",
189196
.type = TCA_ACT_SIMP,
@@ -194,6 +201,7 @@ static struct tc_action_ops act_simp_ops = {
194201
.init = tcf_simp_init,
195202
.walk = tcf_simp_walker,
196203
.lookup = tcf_simp_search,
204+
.delete = tcf_simp_delete,
197205
.size = sizeof(struct tcf_defact),
198206
};
199207

net/sched/act_skbedit.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,13 @@ static int tcf_skbedit_search(struct net *net, struct tc_action **a, u32 index,
267267
return tcf_idr_search(tn, a, index);
268268
}
269269

270+
static int tcf_skbedit_delete(struct net *net, u32 index)
271+
{
272+
struct tc_action_net *tn = net_generic(net, skbedit_net_id);
273+
274+
return tcf_idr_delete_index(tn, index);
275+
}
276+
270277
static struct tc_action_ops act_skbedit_ops = {
271278
.kind = "skbedit",
272279
.type = TCA_ACT_SKBEDIT,
@@ -276,6 +283,7 @@ static struct tc_action_ops act_skbedit_ops = {
276283
.init = tcf_skbedit_init,
277284
.walk = tcf_skbedit_walker,
278285
.lookup = tcf_skbedit_search,
286+
.delete = tcf_skbedit_delete,
279287
.size = sizeof(struct tcf_skbedit),
280288
};
281289

net/sched/act_skbmod.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ static int tcf_skbmod_search(struct net *net, struct tc_action **a, u32 index,
253253
return tcf_idr_search(tn, a, index);
254254
}
255255

256+
static int tcf_skbmod_delete(struct net *net, u32 index)
257+
{
258+
struct tc_action_net *tn = net_generic(net, skbmod_net_id);
259+
260+
return tcf_idr_delete_index(tn, index);
261+
}
262+
256263
static struct tc_action_ops act_skbmod_ops = {
257264
.kind = "skbmod",
258265
.type = TCA_ACT_SKBMOD,
@@ -263,6 +270,7 @@ static struct tc_action_ops act_skbmod_ops = {
263270
.cleanup = tcf_skbmod_cleanup,
264271
.walk = tcf_skbmod_walker,
265272
.lookup = tcf_skbmod_search,
273+
.delete = tcf_skbmod_delete,
266274
.size = sizeof(struct tcf_skbmod),
267275
};
268276

net/sched/act_tunnel_key.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,13 @@ static int tunnel_key_search(struct net *net, struct tc_action **a, u32 index,
534534
return tcf_idr_search(tn, a, index);
535535
}
536536

537+
static int tunnel_key_delete(struct net *net, u32 index)
538+
{
539+
struct tc_action_net *tn = net_generic(net, tunnel_key_net_id);
540+
541+
return tcf_idr_delete_index(tn, index);
542+
}
543+
537544
static struct tc_action_ops act_tunnel_key_ops = {
538545
.kind = "tunnel_key",
539546
.type = TCA_ACT_TUNNEL_KEY,
@@ -544,6 +551,7 @@ static struct tc_action_ops act_tunnel_key_ops = {
544551
.cleanup = tunnel_key_release,
545552
.walk = tunnel_key_walker,
546553
.lookup = tunnel_key_search,
554+
.delete = tunnel_key_delete,
547555
.size = sizeof(struct tcf_tunnel_key),
548556
};
549557

net/sched/act_vlan.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,13 @@ static int tcf_vlan_search(struct net *net, struct tc_action **a, u32 index,
287287
return tcf_idr_search(tn, a, index);
288288
}
289289

290+
static int tcf_vlan_delete(struct net *net, u32 index)
291+
{
292+
struct tc_action_net *tn = net_generic(net, vlan_net_id);
293+
294+
return tcf_idr_delete_index(tn, index);
295+
}
296+
290297
static struct tc_action_ops act_vlan_ops = {
291298
.kind = "vlan",
292299
.type = TCA_ACT_VLAN,
@@ -297,6 +304,7 @@ static struct tc_action_ops act_vlan_ops = {
297304
.cleanup = tcf_vlan_cleanup,
298305
.walk = tcf_vlan_walker,
299306
.lookup = tcf_vlan_search,
307+
.delete = tcf_vlan_delete,
300308
.size = sizeof(struct tcf_vlan),
301309
};
302310

0 commit comments

Comments
 (0)