Skip to content

Commit

Permalink
net_sched: use void pointer for filter handle
Browse files Browse the repository at this point in the history
Now we use 'unsigned long fh' as a pointer in every place,
it is safe to convert it to a void pointer now. This gets
rid of many casts to pointer.

Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
WANG Cong authored and David S. Miller committed Aug 7, 2017
1 parent 54df2cf commit 8113c09
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 151 deletions.
2 changes: 1 addition & 1 deletion include/net/pkt_cls.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct tcf_walker {
int stop;
int skip;
int count;
int (*fn)(struct tcf_proto *, unsigned long node, struct tcf_walker *);
int (*fn)(struct tcf_proto *, void *node, struct tcf_walker *);
};

int register_tcf_proto_ops(struct tcf_proto_ops *ops);
Expand Down
8 changes: 4 additions & 4 deletions include/net/sch_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,16 @@ struct tcf_proto_ops {
int (*init)(struct tcf_proto*);
void (*destroy)(struct tcf_proto*);

unsigned long (*get)(struct tcf_proto*, u32 handle);
void* (*get)(struct tcf_proto*, u32 handle);
int (*change)(struct net *net, struct sk_buff *,
struct tcf_proto*, unsigned long,
u32 handle, struct nlattr **,
unsigned long *, bool);
int (*delete)(struct tcf_proto*, unsigned long, bool*);
void **, bool);
int (*delete)(struct tcf_proto*, void *, bool*);
void (*walk)(struct tcf_proto*, struct tcf_walker *arg);

/* rtnetlink specific */
int (*dump)(struct net*, struct tcf_proto*, unsigned long,
int (*dump)(struct net*, struct tcf_proto*, void *,
struct sk_buff *skb, struct tcmsg*);

struct module *owner;
Expand Down
17 changes: 8 additions & 9 deletions net/sched/cls_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ EXPORT_SYMBOL(unregister_tcf_proto_ops);

static int tfilter_notify(struct net *net, struct sk_buff *oskb,
struct nlmsghdr *n, struct tcf_proto *tp,
unsigned long fh, int event, bool unicast);
void *fh, int event, bool unicast);

static int tfilter_del_notify(struct net *net, struct sk_buff *oskb,
struct nlmsghdr *n, struct tcf_proto *tp,
unsigned long fh, bool unicast, bool *last);
void *fh, bool unicast, bool *last);

static void tfilter_notify_chain(struct net *net, struct sk_buff *oskb,
struct nlmsghdr *n,
Expand Down Expand Up @@ -432,7 +432,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
struct tcf_proto *tp;
const struct Qdisc_class_ops *cops;
unsigned long cl;
unsigned long fh;
void *fh;
int err;
int tp_created;

Expand Down Expand Up @@ -571,7 +571,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,

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

if (fh == 0) {
if (!fh) {
if (n->nlmsg_type == RTM_DELTFILTER && t->tcm_handle == 0) {
tcf_chain_tp_remove(chain, &chain_info, tp);
tfilter_notify(net, skb, n, tp, fh,
Expand Down Expand Up @@ -641,7 +641,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
}

static int tcf_fill_node(struct net *net, struct sk_buff *skb,
struct tcf_proto *tp, unsigned long fh, u32 portid,
struct tcf_proto *tp, void *fh, u32 portid,
u32 seq, u16 flags, int event)
{
struct tcmsg *tcm;
Expand Down Expand Up @@ -679,7 +679,7 @@ static int tcf_fill_node(struct net *net, struct sk_buff *skb,

static int tfilter_notify(struct net *net, struct sk_buff *oskb,
struct nlmsghdr *n, struct tcf_proto *tp,
unsigned long fh, int event, bool unicast)
void *fh, int event, bool unicast)
{
struct sk_buff *skb;
u32 portid = oskb ? NETLINK_CB(oskb).portid : 0;
Expand All @@ -703,7 +703,7 @@ static int tfilter_notify(struct net *net, struct sk_buff *oskb,

static int tfilter_del_notify(struct net *net, struct sk_buff *oskb,
struct nlmsghdr *n, struct tcf_proto *tp,
unsigned long fh, bool unicast, bool *last)
void *fh, bool unicast, bool *last)
{
struct sk_buff *skb;
u32 portid = oskb ? NETLINK_CB(oskb).portid : 0;
Expand Down Expand Up @@ -738,8 +738,7 @@ struct tcf_dump_args {
struct netlink_callback *cb;
};

static int tcf_node_dump(struct tcf_proto *tp, unsigned long n,
struct tcf_walker *arg)
static int tcf_node_dump(struct tcf_proto *tp, void *n, struct tcf_walker *arg)
{
struct tcf_dump_args *a = (void *)arg;
struct net *net = sock_net(a->skb->sk);
Expand Down
22 changes: 10 additions & 12 deletions net/sched/cls_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,18 @@ static int basic_classify(struct sk_buff *skb, const struct tcf_proto *tp,
return -1;
}

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

list_for_each_entry(f, &head->flist, link) {
if (f->handle == handle) {
l = (unsigned long) f;
break;
return f;
}
}

return l;
return NULL;
}

static int basic_init(struct tcf_proto *tp)
Expand Down Expand Up @@ -106,10 +104,10 @@ static void basic_destroy(struct tcf_proto *tp)
kfree_rcu(head, rcu);
}

static int basic_delete(struct tcf_proto *tp, unsigned long arg, bool *last)
static int basic_delete(struct tcf_proto *tp, void *arg, bool *last)
{
struct basic_head *head = rtnl_dereference(tp->root);
struct basic_filter *f = (struct basic_filter *) arg;
struct basic_filter *f = arg;

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

static int basic_change(struct net *net, struct sk_buff *in_skb,
struct tcf_proto *tp, unsigned long base, u32 handle,
struct nlattr **tca, unsigned long *arg, bool ovr)
struct nlattr **tca, void **arg, bool ovr)
{
int err;
struct basic_head *head = rtnl_dereference(tp->root);
Expand Down Expand Up @@ -202,7 +200,7 @@ static int basic_change(struct net *net, struct sk_buff *in_skb,
if (err < 0)
goto errout;

*arg = (unsigned long)fnew;
*arg = fnew;

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

if (arg->fn(tp, (unsigned long) f, arg) < 0) {
if (arg->fn(tp, f, arg) < 0) {
arg->stop = 1;
break;
}
Expand All @@ -237,10 +235,10 @@ static void basic_walk(struct tcf_proto *tp, struct tcf_walker *arg)
}
}

static int basic_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
static int basic_dump(struct net *net, struct tcf_proto *tp, void *fh,
struct sk_buff *skb, struct tcmsg *t)
{
struct basic_filter *f = (struct basic_filter *) fh;
struct basic_filter *f = fh;
struct nlattr *nest;

if (f == NULL)
Expand Down
27 changes: 12 additions & 15 deletions net/sched/cls_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,11 @@ static void __cls_bpf_delete(struct tcf_proto *tp, struct cls_bpf_prog *prog)
call_rcu(&prog->rcu, cls_bpf_delete_prog_rcu);
}

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

__cls_bpf_delete(tp, (struct cls_bpf_prog *) arg);
__cls_bpf_delete(tp, arg);
*last = list_empty(&head->plist);
return 0;
}
Expand All @@ -290,20 +290,17 @@ static void cls_bpf_destroy(struct tcf_proto *tp)
kfree_rcu(head, rcu);
}

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

list_for_each_entry(prog, &head->plist, link) {
if (prog->handle == handle) {
ret = (unsigned long) prog;
break;
}
if (prog->handle == handle)
return prog;
}

return ret;
return NULL;
}

static int cls_bpf_prog_from_ops(struct nlattr **tb, struct cls_bpf_prog *prog)
Expand Down Expand Up @@ -448,10 +445,10 @@ static u32 cls_bpf_grab_new_handle(struct tcf_proto *tp,
static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
struct tcf_proto *tp, unsigned long base,
u32 handle, struct nlattr **tca,
unsigned long *arg, bool ovr)
void **arg, bool ovr)
{
struct cls_bpf_head *head = rtnl_dereference(tp->root);
struct cls_bpf_prog *oldprog = (struct cls_bpf_prog *) *arg;
struct cls_bpf_prog *oldprog = *arg;
struct nlattr *tb[TCA_BPF_MAX + 1];
struct cls_bpf_prog *prog;
int ret;
Expand Down Expand Up @@ -509,7 +506,7 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
list_add_rcu(&prog->link, &head->plist);
}

*arg = (unsigned long) prog;
*arg = prog;
return 0;

errout:
Expand Down Expand Up @@ -557,10 +554,10 @@ static int cls_bpf_dump_ebpf_info(const struct cls_bpf_prog *prog,
return 0;
}

static int cls_bpf_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
static int cls_bpf_dump(struct net *net, struct tcf_proto *tp, void *fh,
struct sk_buff *skb, struct tcmsg *tm)
{
struct cls_bpf_prog *prog = (struct cls_bpf_prog *) fh;
struct cls_bpf_prog *prog = fh;
struct nlattr *nest;
u32 bpf_flags = 0;
int ret;
Expand Down Expand Up @@ -618,7 +615,7 @@ static void cls_bpf_walk(struct tcf_proto *tp, struct tcf_walker *arg)
list_for_each_entry(prog, &head->plist, link) {
if (arg->count < arg->skip)
goto skip;
if (arg->fn(tp, (unsigned long) prog, arg) < 0) {
if (arg->fn(tp, prog, arg) < 0) {
arg->stop = 1;
break;
}
Expand Down
12 changes: 6 additions & 6 deletions net/sched/cls_cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ static int cls_cgroup_classify(struct sk_buff *skb, const struct tcf_proto *tp,
return tcf_exts_exec(skb, &head->exts, res);
}

static unsigned long cls_cgroup_get(struct tcf_proto *tp, u32 handle)
static void *cls_cgroup_get(struct tcf_proto *tp, u32 handle)
{
return 0UL;
return NULL;
}

static int cls_cgroup_init(struct tcf_proto *tp)
Expand All @@ -71,7 +71,7 @@ static void cls_cgroup_destroy_rcu(struct rcu_head *root)
static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,
struct tcf_proto *tp, unsigned long base,
u32 handle, struct nlattr **tca,
unsigned long *arg, bool ovr)
void **arg, bool ovr)
{
struct nlattr *tb[TCA_CGROUP_MAX + 1];
struct cls_cgroup_head *head = rtnl_dereference(tp->root);
Expand Down Expand Up @@ -128,7 +128,7 @@ static void cls_cgroup_destroy(struct tcf_proto *tp)
call_rcu(&head->rcu, cls_cgroup_destroy_rcu);
}

static int cls_cgroup_delete(struct tcf_proto *tp, unsigned long arg, bool *last)
static int cls_cgroup_delete(struct tcf_proto *tp, void *arg, bool *last)
{
return -EOPNOTSUPP;
}
Expand All @@ -140,15 +140,15 @@ static void cls_cgroup_walk(struct tcf_proto *tp, struct tcf_walker *arg)
if (arg->count < arg->skip)
goto skip;

if (arg->fn(tp, (unsigned long) head, arg) < 0) {
if (arg->fn(tp, head, arg) < 0) {
arg->stop = 1;
return;
}
skip:
arg->count++;
}

static int cls_cgroup_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
static int cls_cgroup_dump(struct net *net, struct tcf_proto *tp, void *fh,
struct sk_buff *skb, struct tcmsg *t)
{
struct cls_cgroup_head *head = rtnl_dereference(tp->root);
Expand Down
24 changes: 12 additions & 12 deletions net/sched/cls_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ static void flow_destroy_filter(struct rcu_head *head)
static int flow_change(struct net *net, struct sk_buff *in_skb,
struct tcf_proto *tp, unsigned long base,
u32 handle, struct nlattr **tca,
unsigned long *arg, bool ovr)
void **arg, bool ovr)
{
struct flow_head *head = rtnl_dereference(tp->root);
struct flow_filter *fold, *fnew;
Expand Down Expand Up @@ -439,7 +439,7 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,
if (err < 0)
goto err2;

fold = (struct flow_filter *)*arg;
fold = *arg;
if (fold) {
err = -EINVAL;
if (fold->handle != handle && handle)
Expand Down Expand Up @@ -532,12 +532,12 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,
if (perturb_period)
mod_timer(&fnew->perturb_timer, jiffies + perturb_period);

if (*arg == 0)
if (!*arg)
list_add_tail_rcu(&fnew->list, &head->filters);
else
list_replace_rcu(&fold->list, &fnew->list);

*arg = (unsigned long)fnew;
*arg = fnew;

if (fold)
call_rcu(&fold->rcu, flow_destroy_filter);
Expand All @@ -551,10 +551,10 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,
return err;
}

static int flow_delete(struct tcf_proto *tp, unsigned long arg, bool *last)
static int flow_delete(struct tcf_proto *tp, void *arg, bool *last)
{
struct flow_head *head = rtnl_dereference(tp->root);
struct flow_filter *f = (struct flow_filter *)arg;
struct flow_filter *f = arg;

list_del_rcu(&f->list);
call_rcu(&f->rcu, flow_destroy_filter);
Expand Down Expand Up @@ -586,21 +586,21 @@ static void flow_destroy(struct tcf_proto *tp)
kfree_rcu(head, rcu);
}

static unsigned long flow_get(struct tcf_proto *tp, u32 handle)
static void *flow_get(struct tcf_proto *tp, u32 handle)
{
struct flow_head *head = rtnl_dereference(tp->root);
struct flow_filter *f;

list_for_each_entry(f, &head->filters, list)
if (f->handle == handle)
return (unsigned long)f;
return 0;
return f;
return NULL;
}

static int flow_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
static int flow_dump(struct net *net, struct tcf_proto *tp, void *fh,
struct sk_buff *skb, struct tcmsg *t)
{
struct flow_filter *f = (struct flow_filter *)fh;
struct flow_filter *f = fh;
struct nlattr *nest;

if (f == NULL)
Expand Down Expand Up @@ -666,7 +666,7 @@ static void flow_walk(struct tcf_proto *tp, struct tcf_walker *arg)
list_for_each_entry(f, &head->filters, list) {
if (arg->count < arg->skip)
goto skip;
if (arg->fn(tp, (unsigned long)f, arg) < 0) {
if (arg->fn(tp, f, arg) < 0) {
arg->stop = 1;
break;
}
Expand Down
Loading

0 comments on commit 8113c09

Please sign in to comment.