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

net_sched: only create filter chains for new filters/actions

tcf_chain_get() always creates a new filter chain if not found
in existing ones. This is totally unnecessary when we get or
delete filters, new chain should be only created for new filters
(or new actions).

Fixes: 5bc17018 ("net: sched: introduce multichain support for filters")
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ee538dce
...@@ -18,7 +18,8 @@ int register_tcf_proto_ops(struct tcf_proto_ops *ops); ...@@ -18,7 +18,8 @@ int register_tcf_proto_ops(struct tcf_proto_ops *ops);
int unregister_tcf_proto_ops(struct tcf_proto_ops *ops); int unregister_tcf_proto_ops(struct tcf_proto_ops *ops);
#ifdef CONFIG_NET_CLS #ifdef CONFIG_NET_CLS
struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index); struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index,
bool create);
void tcf_chain_put(struct tcf_chain *chain); void tcf_chain_put(struct tcf_chain *chain);
int tcf_block_get(struct tcf_block **p_block, int tcf_block_get(struct tcf_block **p_block,
struct tcf_proto __rcu **p_filter_chain); struct tcf_proto __rcu **p_filter_chain);
......
...@@ -34,7 +34,7 @@ static int tcf_action_goto_chain_init(struct tc_action *a, struct tcf_proto *tp) ...@@ -34,7 +34,7 @@ static int tcf_action_goto_chain_init(struct tc_action *a, struct tcf_proto *tp)
if (!tp) if (!tp)
return -EINVAL; return -EINVAL;
a->goto_chain = tcf_chain_get(tp->chain->block, chain_index); a->goto_chain = tcf_chain_get(tp->chain->block, chain_index, true);
if (!a->goto_chain) if (!a->goto_chain)
return -ENOMEM; return -ENOMEM;
return 0; return 0;
......
...@@ -220,7 +220,8 @@ static void tcf_chain_destroy(struct tcf_chain *chain) ...@@ -220,7 +220,8 @@ static void tcf_chain_destroy(struct tcf_chain *chain)
kfree(chain); kfree(chain);
} }
struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index) struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index,
bool create)
{ {
struct tcf_chain *chain; struct tcf_chain *chain;
...@@ -230,7 +231,10 @@ struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index) ...@@ -230,7 +231,10 @@ struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index)
return chain; return chain;
} }
} }
if (create)
return tcf_chain_create(block, chain_index); return tcf_chain_create(block, chain_index);
else
return NULL;
} }
EXPORT_SYMBOL(tcf_chain_get); EXPORT_SYMBOL(tcf_chain_get);
...@@ -511,9 +515,10 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, ...@@ -511,9 +515,10 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
err = -EINVAL; err = -EINVAL;
goto errout; goto errout;
} }
chain = tcf_chain_get(block, chain_index); chain = tcf_chain_get(block, chain_index,
n->nlmsg_type == RTM_NEWTFILTER);
if (!chain) { if (!chain) {
err = -ENOMEM; err = n->nlmsg_type == RTM_NEWTFILTER ? -ENOMEM : -EINVAL;
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