Skip to content

Commit 98909f9

Browse files
committed
Merge branch 'net_sched-clean-up-filter-handle'
Cong Wang says: ==================== net_sched: clean up filter handle This patchset sits in my local branch for a long time, it is time to send it out. It cleans up the ambiguous use of 'unsigned long fh', please see each of them for details. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 08bd10f + 8113c09 commit 98909f9

File tree

14 files changed

+178
-154
lines changed

14 files changed

+178
-154
lines changed

include/net/pkt_cls.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct tcf_walker {
1111
int stop;
1212
int skip;
1313
int count;
14-
int (*fn)(struct tcf_proto *, unsigned long node, struct tcf_walker *);
14+
int (*fn)(struct tcf_proto *, void *node, struct tcf_walker *);
1515
};
1616

1717
int register_tcf_proto_ops(struct tcf_proto_ops *ops);

include/net/sch_generic.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,16 @@ struct tcf_proto_ops {
213213
int (*init)(struct tcf_proto*);
214214
void (*destroy)(struct tcf_proto*);
215215

216-
unsigned long (*get)(struct tcf_proto*, u32 handle);
216+
void* (*get)(struct tcf_proto*, u32 handle);
217217
int (*change)(struct net *net, struct sk_buff *,
218218
struct tcf_proto*, unsigned long,
219219
u32 handle, struct nlattr **,
220-
unsigned long *, bool);
221-
int (*delete)(struct tcf_proto*, unsigned long, bool*);
220+
void **, bool);
221+
int (*delete)(struct tcf_proto*, void *, bool*);
222222
void (*walk)(struct tcf_proto*, struct tcf_walker *arg);
223223

224224
/* rtnetlink specific */
225-
int (*dump)(struct net*, struct tcf_proto*, unsigned long,
225+
int (*dump)(struct net*, struct tcf_proto*, void *,
226226
struct sk_buff *skb, struct tcmsg*);
227227

228228
struct module *owner;

net/sched/cls_api.c

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ EXPORT_SYMBOL(unregister_tcf_proto_ops);
102102

103103
static int tfilter_notify(struct net *net, struct sk_buff *oskb,
104104
struct nlmsghdr *n, struct tcf_proto *tp,
105-
unsigned long fh, int event, bool unicast);
105+
void *fh, int event, bool unicast);
106+
107+
static int tfilter_del_notify(struct net *net, struct sk_buff *oskb,
108+
struct nlmsghdr *n, struct tcf_proto *tp,
109+
void *fh, bool unicast, bool *last);
106110

107111
static void tfilter_notify_chain(struct net *net, struct sk_buff *oskb,
108112
struct nlmsghdr *n,
@@ -428,7 +432,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
428432
struct tcf_proto *tp;
429433
const struct Qdisc_class_ops *cops;
430434
unsigned long cl;
431-
unsigned long fh;
435+
void *fh;
432436
int err;
433437
int tp_created;
434438

@@ -567,7 +571,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
567571

568572
fh = tp->ops->get(tp, t->tcm_handle);
569573

570-
if (fh == 0) {
574+
if (!fh) {
571575
if (n->nlmsg_type == RTM_DELTFILTER && t->tcm_handle == 0) {
572576
tcf_chain_tp_remove(chain, &chain_info, tp);
573577
tfilter_notify(net, skb, n, tp, fh,
@@ -595,11 +599,10 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
595599
}
596600
break;
597601
case RTM_DELTFILTER:
598-
err = tp->ops->delete(tp, fh, &last);
602+
err = tfilter_del_notify(net, skb, n, tp, fh, false,
603+
&last);
599604
if (err)
600605
goto errout;
601-
tfilter_notify(net, skb, n, tp, t->tcm_handle,
602-
RTM_DELTFILTER, false);
603606
if (last) {
604607
tcf_chain_tp_remove(chain, &chain_info, tp);
605608
tcf_proto_destroy(tp);
@@ -638,7 +641,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
638641
}
639642

640643
static int tcf_fill_node(struct net *net, struct sk_buff *skb,
641-
struct tcf_proto *tp, unsigned long fh, u32 portid,
644+
struct tcf_proto *tp, void *fh, u32 portid,
642645
u32 seq, u16 flags, int event)
643646
{
644647
struct tcmsg *tcm;
@@ -659,9 +662,9 @@ static int tcf_fill_node(struct net *net, struct sk_buff *skb,
659662
goto nla_put_failure;
660663
if (nla_put_u32(skb, TCA_CHAIN, tp->chain->index))
661664
goto nla_put_failure;
662-
tcm->tcm_handle = fh;
663-
if (RTM_DELTFILTER != event) {
665+
if (!fh) {
664666
tcm->tcm_handle = 0;
667+
} else {
665668
if (tp->ops->dump && tp->ops->dump(net, tp, fh, skb, tcm) < 0)
666669
goto nla_put_failure;
667670
}
@@ -676,7 +679,7 @@ static int tcf_fill_node(struct net *net, struct sk_buff *skb,
676679

677680
static int tfilter_notify(struct net *net, struct sk_buff *oskb,
678681
struct nlmsghdr *n, struct tcf_proto *tp,
679-
unsigned long fh, int event, bool unicast)
682+
void *fh, int event, bool unicast)
680683
{
681684
struct sk_buff *skb;
682685
u32 portid = oskb ? NETLINK_CB(oskb).portid : 0;
@@ -698,14 +701,44 @@ static int tfilter_notify(struct net *net, struct sk_buff *oskb,
698701
n->nlmsg_flags & NLM_F_ECHO);
699702
}
700703

704+
static int tfilter_del_notify(struct net *net, struct sk_buff *oskb,
705+
struct nlmsghdr *n, struct tcf_proto *tp,
706+
void *fh, bool unicast, bool *last)
707+
{
708+
struct sk_buff *skb;
709+
u32 portid = oskb ? NETLINK_CB(oskb).portid : 0;
710+
int err;
711+
712+
skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
713+
if (!skb)
714+
return -ENOBUFS;
715+
716+
if (tcf_fill_node(net, skb, tp, fh, portid, n->nlmsg_seq,
717+
n->nlmsg_flags, RTM_DELTFILTER) <= 0) {
718+
kfree_skb(skb);
719+
return -EINVAL;
720+
}
721+
722+
err = tp->ops->delete(tp, fh, last);
723+
if (err) {
724+
kfree_skb(skb);
725+
return err;
726+
}
727+
728+
if (unicast)
729+
return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
730+
731+
return rtnetlink_send(skb, net, portid, RTNLGRP_TC,
732+
n->nlmsg_flags & NLM_F_ECHO);
733+
}
734+
701735
struct tcf_dump_args {
702736
struct tcf_walker w;
703737
struct sk_buff *skb;
704738
struct netlink_callback *cb;
705739
};
706740

707-
static int tcf_node_dump(struct tcf_proto *tp, unsigned long n,
708-
struct tcf_walker *arg)
741+
static int tcf_node_dump(struct tcf_proto *tp, void *n, struct tcf_walker *arg)
709742
{
710743
struct tcf_dump_args *a = (void *)arg;
711744
struct net *net = sock_net(a->skb->sk);

net/sched/cls_basic.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,18 @@ static int basic_classify(struct sk_buff *skb, const struct tcf_proto *tp,
5656
return -1;
5757
}
5858

59-
static unsigned long basic_get(struct tcf_proto *tp, u32 handle)
59+
static void *basic_get(struct tcf_proto *tp, u32 handle)
6060
{
61-
unsigned long l = 0UL;
6261
struct basic_head *head = rtnl_dereference(tp->root);
6362
struct basic_filter *f;
6463

6564
list_for_each_entry(f, &head->flist, link) {
6665
if (f->handle == handle) {
67-
l = (unsigned long) f;
68-
break;
66+
return f;
6967
}
7068
}
7169

72-
return l;
70+
return NULL;
7371
}
7472

7573
static int basic_init(struct tcf_proto *tp)
@@ -106,10 +104,10 @@ static void basic_destroy(struct tcf_proto *tp)
106104
kfree_rcu(head, rcu);
107105
}
108106

109-
static int basic_delete(struct tcf_proto *tp, unsigned long arg, bool *last)
107+
static int basic_delete(struct tcf_proto *tp, void *arg, bool *last)
110108
{
111109
struct basic_head *head = rtnl_dereference(tp->root);
112-
struct basic_filter *f = (struct basic_filter *) arg;
110+
struct basic_filter *f = arg;
113111

114112
list_del_rcu(&f->link);
115113
tcf_unbind_filter(tp, &f->res);
@@ -149,7 +147,7 @@ static int basic_set_parms(struct net *net, struct tcf_proto *tp,
149147

150148
static int basic_change(struct net *net, struct sk_buff *in_skb,
151149
struct tcf_proto *tp, unsigned long base, u32 handle,
152-
struct nlattr **tca, unsigned long *arg, bool ovr)
150+
struct nlattr **tca, void **arg, bool ovr)
153151
{
154152
int err;
155153
struct basic_head *head = rtnl_dereference(tp->root);
@@ -202,7 +200,7 @@ static int basic_change(struct net *net, struct sk_buff *in_skb,
202200
if (err < 0)
203201
goto errout;
204202

205-
*arg = (unsigned long)fnew;
203+
*arg = fnew;
206204

207205
if (fold) {
208206
list_replace_rcu(&fold->link, &fnew->link);
@@ -228,7 +226,7 @@ static void basic_walk(struct tcf_proto *tp, struct tcf_walker *arg)
228226
if (arg->count < arg->skip)
229227
goto skip;
230228

231-
if (arg->fn(tp, (unsigned long) f, arg) < 0) {
229+
if (arg->fn(tp, f, arg) < 0) {
232230
arg->stop = 1;
233231
break;
234232
}
@@ -237,10 +235,10 @@ static void basic_walk(struct tcf_proto *tp, struct tcf_walker *arg)
237235
}
238236
}
239237

240-
static int basic_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
238+
static int basic_dump(struct net *net, struct tcf_proto *tp, void *fh,
241239
struct sk_buff *skb, struct tcmsg *t)
242240
{
243-
struct basic_filter *f = (struct basic_filter *) fh;
241+
struct basic_filter *f = fh;
244242
struct nlattr *nest;
245243

246244
if (f == NULL)

net/sched/cls_bpf.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,11 @@ static void __cls_bpf_delete(struct tcf_proto *tp, struct cls_bpf_prog *prog)
270270
call_rcu(&prog->rcu, cls_bpf_delete_prog_rcu);
271271
}
272272

273-
static int cls_bpf_delete(struct tcf_proto *tp, unsigned long arg, bool *last)
273+
static int cls_bpf_delete(struct tcf_proto *tp, void *arg, bool *last)
274274
{
275275
struct cls_bpf_head *head = rtnl_dereference(tp->root);
276276

277-
__cls_bpf_delete(tp, (struct cls_bpf_prog *) arg);
277+
__cls_bpf_delete(tp, arg);
278278
*last = list_empty(&head->plist);
279279
return 0;
280280
}
@@ -290,20 +290,17 @@ static void cls_bpf_destroy(struct tcf_proto *tp)
290290
kfree_rcu(head, rcu);
291291
}
292292

293-
static unsigned long cls_bpf_get(struct tcf_proto *tp, u32 handle)
293+
static void *cls_bpf_get(struct tcf_proto *tp, u32 handle)
294294
{
295295
struct cls_bpf_head *head = rtnl_dereference(tp->root);
296296
struct cls_bpf_prog *prog;
297-
unsigned long ret = 0UL;
298297

299298
list_for_each_entry(prog, &head->plist, link) {
300-
if (prog->handle == handle) {
301-
ret = (unsigned long) prog;
302-
break;
303-
}
299+
if (prog->handle == handle)
300+
return prog;
304301
}
305302

306-
return ret;
303+
return NULL;
307304
}
308305

309306
static int cls_bpf_prog_from_ops(struct nlattr **tb, struct cls_bpf_prog *prog)
@@ -448,10 +445,10 @@ static u32 cls_bpf_grab_new_handle(struct tcf_proto *tp,
448445
static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
449446
struct tcf_proto *tp, unsigned long base,
450447
u32 handle, struct nlattr **tca,
451-
unsigned long *arg, bool ovr)
448+
void **arg, bool ovr)
452449
{
453450
struct cls_bpf_head *head = rtnl_dereference(tp->root);
454-
struct cls_bpf_prog *oldprog = (struct cls_bpf_prog *) *arg;
451+
struct cls_bpf_prog *oldprog = *arg;
455452
struct nlattr *tb[TCA_BPF_MAX + 1];
456453
struct cls_bpf_prog *prog;
457454
int ret;
@@ -509,7 +506,7 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
509506
list_add_rcu(&prog->link, &head->plist);
510507
}
511508

512-
*arg = (unsigned long) prog;
509+
*arg = prog;
513510
return 0;
514511

515512
errout:
@@ -557,10 +554,10 @@ static int cls_bpf_dump_ebpf_info(const struct cls_bpf_prog *prog,
557554
return 0;
558555
}
559556

560-
static int cls_bpf_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
557+
static int cls_bpf_dump(struct net *net, struct tcf_proto *tp, void *fh,
561558
struct sk_buff *skb, struct tcmsg *tm)
562559
{
563-
struct cls_bpf_prog *prog = (struct cls_bpf_prog *) fh;
560+
struct cls_bpf_prog *prog = fh;
564561
struct nlattr *nest;
565562
u32 bpf_flags = 0;
566563
int ret;
@@ -618,7 +615,7 @@ static void cls_bpf_walk(struct tcf_proto *tp, struct tcf_walker *arg)
618615
list_for_each_entry(prog, &head->plist, link) {
619616
if (arg->count < arg->skip)
620617
goto skip;
621-
if (arg->fn(tp, (unsigned long) prog, arg) < 0) {
618+
if (arg->fn(tp, prog, arg) < 0) {
622619
arg->stop = 1;
623620
break;
624621
}

net/sched/cls_cgroup.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ static int cls_cgroup_classify(struct sk_buff *skb, const struct tcf_proto *tp,
4343
return tcf_exts_exec(skb, &head->exts, res);
4444
}
4545

46-
static unsigned long cls_cgroup_get(struct tcf_proto *tp, u32 handle)
46+
static void *cls_cgroup_get(struct tcf_proto *tp, u32 handle)
4747
{
48-
return 0UL;
48+
return NULL;
4949
}
5050

5151
static int cls_cgroup_init(struct tcf_proto *tp)
@@ -71,7 +71,7 @@ static void cls_cgroup_destroy_rcu(struct rcu_head *root)
7171
static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,
7272
struct tcf_proto *tp, unsigned long base,
7373
u32 handle, struct nlattr **tca,
74-
unsigned long *arg, bool ovr)
74+
void **arg, bool ovr)
7575
{
7676
struct nlattr *tb[TCA_CGROUP_MAX + 1];
7777
struct cls_cgroup_head *head = rtnl_dereference(tp->root);
@@ -128,7 +128,7 @@ static void cls_cgroup_destroy(struct tcf_proto *tp)
128128
call_rcu(&head->rcu, cls_cgroup_destroy_rcu);
129129
}
130130

131-
static int cls_cgroup_delete(struct tcf_proto *tp, unsigned long arg, bool *last)
131+
static int cls_cgroup_delete(struct tcf_proto *tp, void *arg, bool *last)
132132
{
133133
return -EOPNOTSUPP;
134134
}
@@ -140,15 +140,15 @@ static void cls_cgroup_walk(struct tcf_proto *tp, struct tcf_walker *arg)
140140
if (arg->count < arg->skip)
141141
goto skip;
142142

143-
if (arg->fn(tp, (unsigned long) head, arg) < 0) {
143+
if (arg->fn(tp, head, arg) < 0) {
144144
arg->stop = 1;
145145
return;
146146
}
147147
skip:
148148
arg->count++;
149149
}
150150

151-
static int cls_cgroup_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
151+
static int cls_cgroup_dump(struct net *net, struct tcf_proto *tp, void *fh,
152152
struct sk_buff *skb, struct tcmsg *t)
153153
{
154154
struct cls_cgroup_head *head = rtnl_dereference(tp->root);

0 commit comments

Comments
 (0)