Commit d8aecb10 authored by WANG Cong's avatar WANG Cong Committed by David S. Miller

net: revert "net_sched: move tp->root allocation into fw_init()"

fw filter uses tp->root==NULL to check if it is the old method,
so it doesn't need allocation at all in this case. This patch
reverts the offending commit and adds some comments for old
method to make it obvious.

Fixes: 33f8b9ec ("net_sched: move tp->root allocation into fw_init()")
Reported-by: default avatarAkshat Kakkar <akshat.1984@gmail.com>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
Acked-by: default avatarJamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8fe79c60
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
struct fw_head { struct fw_head {
u32 mask; u32 mask;
bool mask_set;
struct fw_filter __rcu *ht[HTSIZE]; struct fw_filter __rcu *ht[HTSIZE];
struct rcu_head rcu; struct rcu_head rcu;
}; };
...@@ -84,7 +83,7 @@ static int fw_classify(struct sk_buff *skb, const struct tcf_proto *tp, ...@@ -84,7 +83,7 @@ static int fw_classify(struct sk_buff *skb, const struct tcf_proto *tp,
} }
} }
} else { } else {
/* old method */ /* Old method: classify the packet using its skb mark. */
if (id && (TC_H_MAJ(id) == 0 || if (id && (TC_H_MAJ(id) == 0 ||
!(TC_H_MAJ(id ^ tp->q->handle)))) { !(TC_H_MAJ(id ^ tp->q->handle)))) {
res->classid = id; res->classid = id;
...@@ -114,14 +113,9 @@ static unsigned long fw_get(struct tcf_proto *tp, u32 handle) ...@@ -114,14 +113,9 @@ static unsigned long fw_get(struct tcf_proto *tp, u32 handle)
static int fw_init(struct tcf_proto *tp) static int fw_init(struct tcf_proto *tp)
{ {
struct fw_head *head; /* We don't allocate fw_head here, because in the old method
* we don't need it at all.
head = kzalloc(sizeof(struct fw_head), GFP_KERNEL); */
if (head == NULL)
return -ENOBUFS;
head->mask_set = false;
rcu_assign_pointer(tp->root, head);
return 0; return 0;
} }
...@@ -252,7 +246,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb, ...@@ -252,7 +246,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
int err; int err;
if (!opt) if (!opt)
return handle ? -EINVAL : 0; return handle ? -EINVAL : 0; /* Succeed if it is old method. */
err = nla_parse_nested(tb, TCA_FW_MAX, opt, fw_policy); err = nla_parse_nested(tb, TCA_FW_MAX, opt, fw_policy);
if (err < 0) if (err < 0)
...@@ -302,11 +296,17 @@ static int fw_change(struct net *net, struct sk_buff *in_skb, ...@@ -302,11 +296,17 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
if (!handle) if (!handle)
return -EINVAL; return -EINVAL;
if (!head->mask_set) { if (!head) {
head->mask = 0xFFFFFFFF; u32 mask = 0xFFFFFFFF;
if (tb[TCA_FW_MASK]) if (tb[TCA_FW_MASK])
head->mask = nla_get_u32(tb[TCA_FW_MASK]); mask = nla_get_u32(tb[TCA_FW_MASK]);
head->mask_set = true;
head = kzalloc(sizeof(*head), GFP_KERNEL);
if (!head)
return -ENOBUFS;
head->mask = mask;
rcu_assign_pointer(tp->root, head);
} }
f = kzalloc(sizeof(struct fw_filter), GFP_KERNEL); f = kzalloc(sizeof(struct fw_filter), GFP_KERNEL);
......
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