]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
net_sched: initialize net pointer inside tcf_exts_init()
authorCong Wang <xiyou.wangcong@gmail.com>
Wed, 15 May 2019 13:02:00 +0000 (15:02 +0200)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Tue, 2 Jul 2019 12:12:44 +0000 (14:12 +0200)
BugLink: https://bugs.launchpad.net/bugs/1825942
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: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit 14215108a1fd7e002c0a1f9faf8fbaf41fdda50d)
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
Acked-by: Connor Kuehl <connor.kuehl@canonical.com>
Acked-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
13 files changed:
include/net/pkt_cls.h
net/sched/cls_api.c
net/sched/cls_basic.c
net/sched/cls_bpf.c
net/sched/cls_cgroup.c
net/sched/cls_flow.c
net/sched/cls_flower.c
net/sched/cls_fw.c
net/sched/cls_matchall.c
net/sched/cls_route.c
net/sched/cls_rsvp.h
net/sched/cls_tcindex.c
net/sched/cls_u32.c

index 9206a1b2d6c3ee8f0b2fc568e69652b030d2a648..d076a0b7af8f77402d99f45924b103111ddbdd4b 100644 (file)
@@ -240,12 +240,13 @@ struct tcf_exts {
        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
        exts->type = 0;
        exts->nr_actions = 0;
-       exts->net = NULL;
+       exts->net = net;
        exts->actions = kcalloc(TCA_ACT_MAX_PRIO, sizeof(struct tc_action *),
                                GFP_KERNEL);
        if (!exts->actions)
index 115c89c9734e5e428ba5ee9d40bb71fe4ead26f5..ef7f2ab9c39cb0043cb5d237f2bd3b9ac7c3435b 100644 (file)
@@ -1114,7 +1114,6 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
                                exts->actions[i++] = act;
                        exts->nr_actions = i;
                }
-               exts->net = net;
        }
 #else
        if ((exts->action && tb[exts->action]) ||
index 0fb49c30cdbe1904b94361b24b8130f6507ee591..9afb739329830c7b970ecb51a95c42b7483be18a 100644 (file)
@@ -191,7 +191,7 @@ static int basic_change(struct net *net, struct sk_buff *in_skb,
        if (!fnew)
                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)
                goto errout;
 
index 91620bc441fcdea525f2d254cef526b79f45fdb1..d98f4e24f0df565b5ecf2b9edc2145199944b1f2 100644 (file)
@@ -467,7 +467,7 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
        if (!prog)
                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)
                goto errout;
 
index 1322fcac12e5704fb93d0809be62562d63db5eab..08a256d75b24d81bbbe8a3843366c63d3a831ef9 100644 (file)
@@ -98,7 +98,7 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,
        if (!new)
                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)
                goto errout;
        new->handle = handle;
index d9d3d525e20c1dc3ba545385fe635f9e8812a9b8..0fd14a381191c78c5cfd4c858808d7ce915d1309 100644 (file)
@@ -440,7 +440,7 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,
        if (err < 0)
                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)
                goto err2;
 
index 39dbaa41b4584f5cf811ad7ed3340a748d2f3de1..26c91780c46b2c372a8613db14e7191f2af340d9 100644 (file)
@@ -864,7 +864,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
                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)
                goto errout;
 
index 964f2e3ed64d443f13de032baf056960e2f378e3..e2d476cc24f75821abd6869841dcdec8d7180b91 100644 (file)
@@ -280,7 +280,8 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
 #endif /* CONFIG_NET_CLS_IND */
                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) {
                        kfree(fnew);
                        return err;
@@ -329,7 +330,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
        if (f == NULL)
                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)
                goto errout;
        f->id = handle;
index 550be06dc625c93b9afbf0ccf2137940598adff4..291ed212723d5138f9b80f6a8e2e3aed94661d02 100644 (file)
@@ -177,7 +177,7 @@ static int mall_change(struct net *net, struct sk_buff *in_skb,
        if (!new)
                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)
                goto err_exts_init;
 
index b9e3621d0775e8c12e7aead2ade0b77c1932e333..9b1eecd1137aed1ef5260fbad947197d1aead8f3 100644 (file)
@@ -494,7 +494,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,
        if (!f)
                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)
                goto errout;
 
index 4e1807b41028598f864d92dd045fce54cfd45036..1b6b39a44e81cce99a4bf1d778c63e5dbbf21064 100644 (file)
@@ -498,7 +498,7 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb,
        if (err < 0)
                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)
                return err;
        err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &e, ovr);
@@ -519,7 +519,8 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb,
                        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) {
                        kfree(n);
                        goto errout2;
@@ -547,7 +548,7 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb,
        if (f == NULL)
                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)
                goto errout;
        h2 = 16;
index 13164d8d055ae6c29ab6b552cf32a59de1251496..204e11feabba6448a8ed22c4f231c8c4f87f8155 100644 (file)
@@ -245,10 +245,12 @@ static const struct nla_policy tcindex_policy[TCA_TCINDEX_MAX + 1] = {
        [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));
-       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)
@@ -280,13 +282,10 @@ static int tcindex_alloc_perfect_hash(struct net *net, struct tcindex_data *cp)
                return -ENOMEM;
 
        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);
                if (err < 0)
                        goto errout;
-#ifdef CONFIG_NET_CLS_ACT
-               cp->perfect[i].exts.net = net;
-#endif
        }
 
        return 0;
@@ -309,7 +308,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
        int err, balloc = 0;
        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)
                return err;
        err = tcf_exts_validate(net, tp, tb, est, &e, ovr);
@@ -343,7 +342,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
        }
        cp->h = p->h;
 
-       err = tcindex_filter_result_init(&new_filter_result);
+       err = tcindex_filter_result_init(&new_filter_result, net);
        if (err < 0)
                goto errout1;
        err = tcindex_filter_result_init(&cr);
@@ -433,7 +432,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
                        goto errout_alloc;
                f->key = handle;
                f->next = NULL;
-               err = tcindex_filter_result_init(&f->result);
+               err = tcindex_filter_result_init(&f->result, net);
                if (err < 0) {
                        kfree(f);
                        goto errout_alloc;
@@ -446,7 +445,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
        }
 
        if (old_r && old_r != r) {
-               err = tcindex_filter_result_init(old_r);
+               err = tcindex_filter_result_init(old_r, net);
                if (err < 0) {
                        kfree(f);
                        goto errout_alloc;
index 413a59a78d2ac576711af2edc50344fa58e76083..5c1b47b2498772555fef9418a5973eab340da165 100644 (file)
@@ -823,7 +823,7 @@ static void u32_replace_knode(struct tcf_proto *tp, struct tc_u_common *tp_c,
        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_hnode *ht = rtnl_dereference(n->ht_down);
@@ -869,7 +869,7 @@ static struct tc_u_knode *u32_init_knode(struct tcf_proto *tp,
        new->tp = tp;
        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);
                return NULL;
        }
@@ -917,7 +917,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
                    ~(TCA_CLS_FLAGS_IN_HW | TCA_CLS_FLAGS_NOT_IN_HW))
                        return -EINVAL;
 
-               new = u32_init_knode(tp, n);
+               new = u32_init_knode(net, tp, n);
                if (!new)
                        return -ENOMEM;
 
@@ -1050,7 +1050,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
        n->flags = flags;
        n->tp = tp;
 
-       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)
                goto errout;