Skip to content

Commit 367a8ce

Browse files
congwangdavem330
authored andcommitted
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: 5bc1701 ("net: sched: introduce multichain support for filters") Cc: Jamal Hadi Salim <[email protected]> Cc: Jiri Pirko <[email protected]> Signed-off-by: Cong Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ee538dc commit 367a8ce

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

include/net/pkt_cls.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ int register_tcf_proto_ops(struct tcf_proto_ops *ops);
1818
int unregister_tcf_proto_ops(struct tcf_proto_ops *ops);
1919

2020
#ifdef CONFIG_NET_CLS
21-
struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index);
21+
struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index,
22+
bool create);
2223
void tcf_chain_put(struct tcf_chain *chain);
2324
int tcf_block_get(struct tcf_block **p_block,
2425
struct tcf_proto __rcu **p_filter_chain);

net/sched/act_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static int tcf_action_goto_chain_init(struct tc_action *a, struct tcf_proto *tp)
3434

3535
if (!tp)
3636
return -EINVAL;
37-
a->goto_chain = tcf_chain_get(tp->chain->block, chain_index);
37+
a->goto_chain = tcf_chain_get(tp->chain->block, chain_index, true);
3838
if (!a->goto_chain)
3939
return -ENOMEM;
4040
return 0;

net/sched/cls_api.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ static void tcf_chain_destroy(struct tcf_chain *chain)
220220
kfree(chain);
221221
}
222222

223-
struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index)
223+
struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index,
224+
bool create)
224225
{
225226
struct tcf_chain *chain;
226227

@@ -230,7 +231,10 @@ struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index)
230231
return chain;
231232
}
232233
}
233-
return tcf_chain_create(block, chain_index);
234+
if (create)
235+
return tcf_chain_create(block, chain_index);
236+
else
237+
return NULL;
234238
}
235239
EXPORT_SYMBOL(tcf_chain_get);
236240

@@ -511,9 +515,10 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
511515
err = -EINVAL;
512516
goto errout;
513517
}
514-
chain = tcf_chain_get(block, chain_index);
518+
chain = tcf_chain_get(block, chain_index,
519+
n->nlmsg_type == RTM_NEWTFILTER);
515520
if (!chain) {
516-
err = -ENOMEM;
521+
err = n->nlmsg_type == RTM_NEWTFILTER ? -ENOMEM : -EINVAL;
517522
goto errout;
518523
}
519524

0 commit comments

Comments
 (0)