Commit 14215108 authored by Cong Wang's avatar Cong Wang Committed by David S. Miller

net_sched: initialize net pointer inside tcf_exts_init()

For tcindex filter, it is too late to initialize the
net pointer in tcf_exts_validate(), as tcf_exts_get_net()
requires a non-NULL net pointer. We can just move its
initialization into tcf_exts_init(), which just requires
an additional parameter.

This makes the code in tcindex_alloc_perfect_hash()
prettier.

Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1a256608
...@@ -289,12 +289,13 @@ struct tcf_exts { ...@@ -289,12 +289,13 @@ struct tcf_exts {
int police; int police;
}; };
static inline int tcf_exts_init(struct tcf_exts *exts, int action, int police) static inline int tcf_exts_init(struct tcf_exts *exts, struct net *net,
int action, int police)
{ {
#ifdef CONFIG_NET_CLS_ACT #ifdef CONFIG_NET_CLS_ACT
exts->type = 0; exts->type = 0;
exts->nr_actions = 0; exts->nr_actions = 0;
exts->net = NULL; exts->net = net;
exts->actions = kcalloc(TCA_ACT_MAX_PRIO, sizeof(struct tc_action *), exts->actions = kcalloc(TCA_ACT_MAX_PRIO, sizeof(struct tc_action *),
GFP_KERNEL); GFP_KERNEL);
if (!exts->actions) if (!exts->actions)
......
...@@ -3051,7 +3051,6 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb, ...@@ -3051,7 +3051,6 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
return err; return err;
exts->nr_actions = err; exts->nr_actions = err;
} }
exts->net = net;
} }
#else #else
if ((exts->action && tb[exts->action]) || if ((exts->action && tb[exts->action]) ||
......
...@@ -199,7 +199,7 @@ static int basic_change(struct net *net, struct sk_buff *in_skb, ...@@ -199,7 +199,7 @@ static int basic_change(struct net *net, struct sk_buff *in_skb,
if (!fnew) if (!fnew)
return -ENOBUFS; return -ENOBUFS;
err = tcf_exts_init(&fnew->exts, TCA_BASIC_ACT, TCA_BASIC_POLICE); err = tcf_exts_init(&fnew->exts, net, TCA_BASIC_ACT, TCA_BASIC_POLICE);
if (err < 0) if (err < 0)
goto errout; goto errout;
......
...@@ -477,7 +477,7 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb, ...@@ -477,7 +477,7 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
if (!prog) if (!prog)
return -ENOBUFS; return -ENOBUFS;
ret = tcf_exts_init(&prog->exts, TCA_BPF_ACT, TCA_BPF_POLICE); ret = tcf_exts_init(&prog->exts, net, TCA_BPF_ACT, TCA_BPF_POLICE);
if (ret < 0) if (ret < 0)
goto errout; goto errout;
......
...@@ -99,7 +99,7 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb, ...@@ -99,7 +99,7 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,
if (!new) if (!new)
return -ENOBUFS; return -ENOBUFS;
err = tcf_exts_init(&new->exts, TCA_CGROUP_ACT, TCA_CGROUP_POLICE); err = tcf_exts_init(&new->exts, net, TCA_CGROUP_ACT, TCA_CGROUP_POLICE);
if (err < 0) if (err < 0)
goto errout; goto errout;
new->handle = handle; new->handle = handle;
......
...@@ -441,7 +441,7 @@ static int flow_change(struct net *net, struct sk_buff *in_skb, ...@@ -441,7 +441,7 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,
if (err < 0) if (err < 0)
goto err1; goto err1;
err = tcf_exts_init(&fnew->exts, TCA_FLOW_ACT, TCA_FLOW_POLICE); err = tcf_exts_init(&fnew->exts, net, TCA_FLOW_ACT, TCA_FLOW_POLICE);
if (err < 0) if (err < 0)
goto err2; goto err2;
......
...@@ -1344,7 +1344,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, ...@@ -1344,7 +1344,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
goto errout_tb; goto errout_tb;
} }
err = tcf_exts_init(&fnew->exts, TCA_FLOWER_ACT, 0); err = tcf_exts_init(&fnew->exts, net, TCA_FLOWER_ACT, 0);
if (err < 0) if (err < 0)
goto errout; goto errout;
......
...@@ -285,7 +285,8 @@ static int fw_change(struct net *net, struct sk_buff *in_skb, ...@@ -285,7 +285,8 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
#endif /* CONFIG_NET_CLS_IND */ #endif /* CONFIG_NET_CLS_IND */
fnew->tp = f->tp; fnew->tp = f->tp;
err = tcf_exts_init(&fnew->exts, TCA_FW_ACT, TCA_FW_POLICE); err = tcf_exts_init(&fnew->exts, net, TCA_FW_ACT,
TCA_FW_POLICE);
if (err < 0) { if (err < 0) {
kfree(fnew); kfree(fnew);
return err; return err;
...@@ -334,7 +335,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb, ...@@ -334,7 +335,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
if (f == NULL) if (f == NULL)
return -ENOBUFS; return -ENOBUFS;
err = tcf_exts_init(&f->exts, TCA_FW_ACT, TCA_FW_POLICE); err = tcf_exts_init(&f->exts, net, TCA_FW_ACT, TCA_FW_POLICE);
if (err < 0) if (err < 0)
goto errout; goto errout;
f->id = handle; f->id = handle;
......
...@@ -191,7 +191,7 @@ static int mall_change(struct net *net, struct sk_buff *in_skb, ...@@ -191,7 +191,7 @@ static int mall_change(struct net *net, struct sk_buff *in_skb,
if (!new) if (!new)
return -ENOBUFS; return -ENOBUFS;
err = tcf_exts_init(&new->exts, TCA_MATCHALL_ACT, 0); err = tcf_exts_init(&new->exts, net, TCA_MATCHALL_ACT, 0);
if (err) if (err)
goto err_exts_init; goto err_exts_init;
......
...@@ -497,7 +497,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb, ...@@ -497,7 +497,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,
if (!f) if (!f)
goto errout; goto errout;
err = tcf_exts_init(&f->exts, TCA_ROUTE4_ACT, TCA_ROUTE4_POLICE); err = tcf_exts_init(&f->exts, net, TCA_ROUTE4_ACT, TCA_ROUTE4_POLICE);
if (err < 0) if (err < 0)
goto errout; goto errout;
......
...@@ -501,7 +501,7 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb, ...@@ -501,7 +501,7 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb,
if (err < 0) if (err < 0)
return err; return err;
err = tcf_exts_init(&e, TCA_RSVP_ACT, TCA_RSVP_POLICE); err = tcf_exts_init(&e, net, TCA_RSVP_ACT, TCA_RSVP_POLICE);
if (err < 0) if (err < 0)
return err; return err;
err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &e, ovr, true, err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &e, ovr, true,
...@@ -523,7 +523,8 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb, ...@@ -523,7 +523,8 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb,
goto errout2; goto errout2;
} }
err = tcf_exts_init(&n->exts, TCA_RSVP_ACT, TCA_RSVP_POLICE); err = tcf_exts_init(&n->exts, net, TCA_RSVP_ACT,
TCA_RSVP_POLICE);
if (err < 0) { if (err < 0) {
kfree(n); kfree(n);
goto errout2; goto errout2;
...@@ -551,7 +552,7 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb, ...@@ -551,7 +552,7 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb,
if (f == NULL) if (f == NULL)
goto errout2; goto errout2;
err = tcf_exts_init(&f->exts, TCA_RSVP_ACT, TCA_RSVP_POLICE); err = tcf_exts_init(&f->exts, net, TCA_RSVP_ACT, TCA_RSVP_POLICE);
if (err < 0) if (err < 0)
goto errout; goto errout;
h2 = 16; h2 = 16;
......
...@@ -246,10 +246,12 @@ static const struct nla_policy tcindex_policy[TCA_TCINDEX_MAX + 1] = { ...@@ -246,10 +246,12 @@ static const struct nla_policy tcindex_policy[TCA_TCINDEX_MAX + 1] = {
[TCA_TCINDEX_CLASSID] = { .type = NLA_U32 }, [TCA_TCINDEX_CLASSID] = { .type = NLA_U32 },
}; };
static int tcindex_filter_result_init(struct tcindex_filter_result *r) static int tcindex_filter_result_init(struct tcindex_filter_result *r,
struct net *net)
{ {
memset(r, 0, sizeof(*r)); memset(r, 0, sizeof(*r));
return tcf_exts_init(&r->exts, TCA_TCINDEX_ACT, TCA_TCINDEX_POLICE); return tcf_exts_init(&r->exts, net, TCA_TCINDEX_ACT,
TCA_TCINDEX_POLICE);
} }
static void tcindex_partial_destroy_work(struct work_struct *work) static void tcindex_partial_destroy_work(struct work_struct *work)
...@@ -281,13 +283,10 @@ static int tcindex_alloc_perfect_hash(struct net *net, struct tcindex_data *cp) ...@@ -281,13 +283,10 @@ static int tcindex_alloc_perfect_hash(struct net *net, struct tcindex_data *cp)
return -ENOMEM; return -ENOMEM;
for (i = 0; i < cp->hash; i++) { for (i = 0; i < cp->hash; i++) {
err = tcf_exts_init(&cp->perfect[i].exts, err = tcf_exts_init(&cp->perfect[i].exts, net,
TCA_TCINDEX_ACT, TCA_TCINDEX_POLICE); TCA_TCINDEX_ACT, TCA_TCINDEX_POLICE);
if (err < 0) if (err < 0)
goto errout; goto errout;
#ifdef CONFIG_NET_CLS_ACT
cp->perfect[i].exts.net = net;
#endif
} }
return 0; return 0;
...@@ -310,7 +309,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, ...@@ -310,7 +309,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
int err, balloc = 0; int err, balloc = 0;
struct tcf_exts e; struct tcf_exts e;
err = tcf_exts_init(&e, TCA_TCINDEX_ACT, TCA_TCINDEX_POLICE); err = tcf_exts_init(&e, net, TCA_TCINDEX_ACT, TCA_TCINDEX_POLICE);
if (err < 0) if (err < 0)
return err; return err;
err = tcf_exts_validate(net, tp, tb, est, &e, ovr, true, extack); err = tcf_exts_validate(net, tp, tb, est, &e, ovr, true, extack);
...@@ -344,7 +343,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, ...@@ -344,7 +343,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
} }
cp->h = p->h; cp->h = p->h;
err = tcindex_filter_result_init(&new_filter_result); err = tcindex_filter_result_init(&new_filter_result, net);
if (err < 0) if (err < 0)
goto errout1; goto errout1;
if (old_r) if (old_r)
...@@ -431,7 +430,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, ...@@ -431,7 +430,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
goto errout_alloc; goto errout_alloc;
f->key = handle; f->key = handle;
f->next = NULL; f->next = NULL;
err = tcindex_filter_result_init(&f->result); err = tcindex_filter_result_init(&f->result, net);
if (err < 0) { if (err < 0) {
kfree(f); kfree(f);
goto errout_alloc; goto errout_alloc;
...@@ -444,7 +443,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, ...@@ -444,7 +443,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
} }
if (old_r && old_r != r) { if (old_r && old_r != r) {
err = tcindex_filter_result_init(old_r); err = tcindex_filter_result_init(old_r, net);
if (err < 0) { if (err < 0) {
kfree(f); kfree(f);
goto errout_alloc; goto errout_alloc;
......
...@@ -804,7 +804,7 @@ static void u32_replace_knode(struct tcf_proto *tp, struct tc_u_common *tp_c, ...@@ -804,7 +804,7 @@ static void u32_replace_knode(struct tcf_proto *tp, struct tc_u_common *tp_c,
rcu_assign_pointer(*ins, n); rcu_assign_pointer(*ins, n);
} }
static struct tc_u_knode *u32_init_knode(struct tcf_proto *tp, static struct tc_u_knode *u32_init_knode(struct net *net, struct tcf_proto *tp,
struct tc_u_knode *n) struct tc_u_knode *n)
{ {
struct tc_u_hnode *ht = rtnl_dereference(n->ht_down); struct tc_u_hnode *ht = rtnl_dereference(n->ht_down);
...@@ -849,7 +849,7 @@ static struct tc_u_knode *u32_init_knode(struct tcf_proto *tp, ...@@ -849,7 +849,7 @@ static struct tc_u_knode *u32_init_knode(struct tcf_proto *tp,
#endif #endif
memcpy(&new->sel, s, sizeof(*s) + s->nkeys*sizeof(struct tc_u32_key)); memcpy(&new->sel, s, sizeof(*s) + s->nkeys*sizeof(struct tc_u32_key));
if (tcf_exts_init(&new->exts, TCA_U32_ACT, TCA_U32_POLICE)) { if (tcf_exts_init(&new->exts, net, TCA_U32_ACT, TCA_U32_POLICE)) {
kfree(new); kfree(new);
return NULL; return NULL;
} }
...@@ -911,7 +911,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, ...@@ -911,7 +911,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
return -EINVAL; return -EINVAL;
} }
new = u32_init_knode(tp, n); new = u32_init_knode(net, tp, n);
if (!new) if (!new)
return -ENOMEM; return -ENOMEM;
...@@ -1061,7 +1061,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, ...@@ -1061,7 +1061,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
n->fshift = s->hmask ? ffs(ntohl(s->hmask)) - 1 : 0; n->fshift = s->hmask ? ffs(ntohl(s->hmask)) - 1 : 0;
n->flags = flags; n->flags = flags;
err = tcf_exts_init(&n->exts, TCA_U32_ACT, TCA_U32_POLICE); err = tcf_exts_init(&n->exts, net, TCA_U32_ACT, TCA_U32_POLICE);
if (err < 0) if (err < 0)
goto errout; goto errout;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment