mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 02:32:09 -04:00
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 <[email protected]> Cc: David S. Miller <[email protected]> Signed-off-by: Cong Wang <[email protected]> Signed-off-by: Jamal Hadi Salim <[email protected]> Signed-off-by: David S. Miller <[email protected]>
This commit is contained in:
parent
832d1d5bfa
commit
2519a602c2
3 changed files with 39 additions and 29 deletions
|
|
@ -338,27 +338,27 @@ static inline int tcf_valid_offset(const struct sk_buff *skb,
|
|||
#include <net/net_namespace.h>
|
||||
|
||||
static inline int
|
||||
tcf_change_indev(struct tcf_proto *tp, char *indev, struct nlattr *indev_tlv)
|
||||
{
|
||||
if (nla_strlcpy(indev, indev_tlv, IFNAMSIZ) >= IFNAMSIZ)
|
||||
return -EINVAL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
tcf_match_indev(struct sk_buff *skb, char *indev)
|
||||
tcf_change_indev(struct net *net, struct nlattr *indev_tlv)
|
||||
{
|
||||
char indev[IFNAMSIZ];
|
||||
struct net_device *dev;
|
||||
|
||||
if (indev[0]) {
|
||||
if (!skb->skb_iif)
|
||||
return 0;
|
||||
dev = __dev_get_by_index(dev_net(skb->dev), skb->skb_iif);
|
||||
if (!dev || strcmp(indev, dev->name))
|
||||
return 0;
|
||||
}
|
||||
if (nla_strlcpy(indev, indev_tlv, IFNAMSIZ) >= IFNAMSIZ)
|
||||
return -EINVAL;
|
||||
dev = __dev_get_by_name(net, indev);
|
||||
if (!dev)
|
||||
return -ENODEV;
|
||||
return dev->ifindex;
|
||||
}
|
||||
|
||||
return 1;
|
||||
static inline bool
|
||||
tcf_match_indev(struct sk_buff *skb, int ifindex)
|
||||
{
|
||||
if (!ifindex)
|
||||
return true;
|
||||
if (!skb->skb_iif)
|
||||
return false;
|
||||
return ifindex == skb->skb_iif;
|
||||
}
|
||||
#endif /* CONFIG_NET_CLS_IND */
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue