diff options
author | WANG Cong <xiyou.wangcong@gmail.com> | 2014-01-09 19:14:02 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-01-13 14:50:15 -0500 |
commit | 2519a602c273c5254781bc55b6e678a17e469a12 (patch) | |
tree | fcfbf3b98b6e186ea042d8167ddbde5b4fff63f2 /net/sched | |
parent | 832d1d5bfaefafa5aa40282f6765c6d996fe384e (diff) |
net_sched: optimize tcf_match_indev()
tcf_match_indev() is called in fast path, it is not wise to
search for a netdev by ifindex and then compare by its name,
just compare the ifindex.
Also, dev->name could be changed by user-space, therefore
the match would be always fail, but dev->ifindex could
be consistent.
BTW, this will also save some bytes from the core struct of u32.
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/sched')
-rw-r--r-- | net/sched/cls_fw.c | 19 | ||||
-rw-r--r-- | net/sched/cls_u32.c | 19 |
2 files changed, 24 insertions, 14 deletions
diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c index d605285af5bf..ca662aaa5eb4 100644 --- a/net/sched/cls_fw.c +++ b/net/sched/cls_fw.c | |||
@@ -41,7 +41,7 @@ struct fw_filter { | |||
41 | u32 id; | 41 | u32 id; |
42 | struct tcf_result res; | 42 | struct tcf_result res; |
43 | #ifdef CONFIG_NET_CLS_IND | 43 | #ifdef CONFIG_NET_CLS_IND |
44 | char indev[IFNAMSIZ]; | 44 | int ifindex; |
45 | #endif /* CONFIG_NET_CLS_IND */ | 45 | #endif /* CONFIG_NET_CLS_IND */ |
46 | struct tcf_exts exts; | 46 | struct tcf_exts exts; |
47 | }; | 47 | }; |
@@ -86,7 +86,7 @@ static int fw_classify(struct sk_buff *skb, const struct tcf_proto *tp, | |||
86 | if (f->id == id) { | 86 | if (f->id == id) { |
87 | *res = f->res; | 87 | *res = f->res; |
88 | #ifdef CONFIG_NET_CLS_IND | 88 | #ifdef CONFIG_NET_CLS_IND |
89 | if (!tcf_match_indev(skb, f->indev)) | 89 | if (!tcf_match_indev(skb, f->ifindex)) |
90 | continue; | 90 | continue; |
91 | #endif /* CONFIG_NET_CLS_IND */ | 91 | #endif /* CONFIG_NET_CLS_IND */ |
92 | r = tcf_exts_exec(skb, &f->exts, res); | 92 | r = tcf_exts_exec(skb, &f->exts, res); |
@@ -207,9 +207,11 @@ fw_change_attrs(struct net *net, struct tcf_proto *tp, struct fw_filter *f, | |||
207 | 207 | ||
208 | #ifdef CONFIG_NET_CLS_IND | 208 | #ifdef CONFIG_NET_CLS_IND |
209 | if (tb[TCA_FW_INDEV]) { | 209 | if (tb[TCA_FW_INDEV]) { |
210 | err = tcf_change_indev(tp, f->indev, tb[TCA_FW_INDEV]); | 210 | int ret; |
211 | if (err < 0) | 211 | ret = tcf_change_indev(net, tb[TCA_FW_INDEV]); |
212 | if (ret < 0) | ||
212 | goto errout; | 213 | goto errout; |
214 | f->ifindex = ret; | ||
213 | } | 215 | } |
214 | #endif /* CONFIG_NET_CLS_IND */ | 216 | #endif /* CONFIG_NET_CLS_IND */ |
215 | 217 | ||
@@ -348,9 +350,12 @@ static int fw_dump(struct net *net, struct tcf_proto *tp, unsigned long fh, | |||
348 | nla_put_u32(skb, TCA_FW_CLASSID, f->res.classid)) | 350 | nla_put_u32(skb, TCA_FW_CLASSID, f->res.classid)) |
349 | goto nla_put_failure; | 351 | goto nla_put_failure; |
350 | #ifdef CONFIG_NET_CLS_IND | 352 | #ifdef CONFIG_NET_CLS_IND |
351 | if (strlen(f->indev) && | 353 | if (f->ifindex) { |
352 | nla_put_string(skb, TCA_FW_INDEV, f->indev)) | 354 | struct net_device *dev; |
353 | goto nla_put_failure; | 355 | dev = __dev_get_by_index(net, f->ifindex); |
356 | if (dev && nla_put_string(skb, TCA_FW_INDEV, dev->name)) | ||
357 | goto nla_put_failure; | ||
358 | } | ||
354 | #endif /* CONFIG_NET_CLS_IND */ | 359 | #endif /* CONFIG_NET_CLS_IND */ |
355 | if (head->mask != 0xFFFFFFFF && | 360 | if (head->mask != 0xFFFFFFFF && |
356 | nla_put_u32(skb, TCA_FW_MASK, head->mask)) | 361 | nla_put_u32(skb, TCA_FW_MASK, head->mask)) |
diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index e25411a80f9b..f509b7907f8d 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c | |||
@@ -48,7 +48,7 @@ struct tc_u_knode { | |||
48 | struct tc_u_hnode *ht_up; | 48 | struct tc_u_hnode *ht_up; |
49 | struct tcf_exts exts; | 49 | struct tcf_exts exts; |
50 | #ifdef CONFIG_NET_CLS_IND | 50 | #ifdef CONFIG_NET_CLS_IND |
51 | char indev[IFNAMSIZ]; | 51 | int ifindex; |
52 | #endif | 52 | #endif |
53 | u8 fshift; | 53 | u8 fshift; |
54 | struct tcf_result res; | 54 | struct tcf_result res; |
@@ -152,7 +152,7 @@ check_terminal: | |||
152 | 152 | ||
153 | *res = n->res; | 153 | *res = n->res; |
154 | #ifdef CONFIG_NET_CLS_IND | 154 | #ifdef CONFIG_NET_CLS_IND |
155 | if (!tcf_match_indev(skb, n->indev)) { | 155 | if (!tcf_match_indev(skb, n->ifindex)) { |
156 | n = n->next; | 156 | n = n->next; |
157 | goto next_knode; | 157 | goto next_knode; |
158 | } | 158 | } |
@@ -527,9 +527,11 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp, | |||
527 | 527 | ||
528 | #ifdef CONFIG_NET_CLS_IND | 528 | #ifdef CONFIG_NET_CLS_IND |
529 | if (tb[TCA_U32_INDEV]) { | 529 | if (tb[TCA_U32_INDEV]) { |
530 | err = tcf_change_indev(tp, n->indev, tb[TCA_U32_INDEV]); | 530 | int ret; |
531 | if (err < 0) | 531 | ret = tcf_change_indev(net, tb[TCA_U32_INDEV]); |
532 | if (ret < 0) | ||
532 | goto errout; | 533 | goto errout; |
534 | n->ifindex = ret; | ||
533 | } | 535 | } |
534 | #endif | 536 | #endif |
535 | tcf_exts_change(tp, &n->exts, &e); | 537 | tcf_exts_change(tp, &n->exts, &e); |
@@ -760,9 +762,12 @@ static int u32_dump(struct net *net, struct tcf_proto *tp, unsigned long fh, | |||
760 | goto nla_put_failure; | 762 | goto nla_put_failure; |
761 | 763 | ||
762 | #ifdef CONFIG_NET_CLS_IND | 764 | #ifdef CONFIG_NET_CLS_IND |
763 | if (strlen(n->indev) && | 765 | if (n->ifindex) { |
764 | nla_put_string(skb, TCA_U32_INDEV, n->indev)) | 766 | struct net_device *dev; |
765 | goto nla_put_failure; | 767 | dev = __dev_get_by_index(net, n->ifindex); |
768 | if (dev && nla_put_string(skb, TCA_U32_INDEV, dev->name)) | ||
769 | goto nla_put_failure; | ||
770 | } | ||
766 | #endif | 771 | #endif |
767 | #ifdef CONFIG_CLS_U32_PERF | 772 | #ifdef CONFIG_CLS_U32_PERF |
768 | if (nla_put(skb, TCA_U32_PCNT, | 773 | if (nla_put(skb, TCA_U32_PCNT, |