net/ipv6: compute anycast address hash only if dev is null
authorLi RongQing <lirongqing@baidu.com>
Thu, 8 Nov 2018 06:58:07 +0000 (14:58 +0800)
committerDavid S. Miller <davem@davemloft.net>
Fri, 9 Nov 2018 01:04:43 +0000 (17:04 -0800)
avoid to compute the hash value if dev is not null, since
hash value is not used

Signed-off-by: Li RongQing <lirongqing@baidu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv6/anycast.c

index 9499905..cca3b36 100644 (file)
@@ -433,7 +433,6 @@ static bool ipv6_chk_acast_dev(struct net_device *dev, const struct in6_addr *ad
 bool ipv6_chk_acast_addr(struct net *net, struct net_device *dev,
                         const struct in6_addr *addr)
 {
-       unsigned int hash = inet6_acaddr_hash(net, addr);
        struct net_device *nh_dev;
        struct ifacaddr6 *aca;
        bool found = false;
@@ -441,7 +440,9 @@ bool ipv6_chk_acast_addr(struct net *net, struct net_device *dev,
        rcu_read_lock();
        if (dev)
                found = ipv6_chk_acast_dev(dev, addr);
-       else
+       else {
+               unsigned int hash = inet6_acaddr_hash(net, addr);
+
                hlist_for_each_entry_rcu(aca, &inet6_acaddr_lst[hash],
                                         aca_addr_lst) {
                        nh_dev = fib6_info_nh_dev(aca->aca_rt);
@@ -452,6 +453,7 @@ bool ipv6_chk_acast_addr(struct net *net, struct net_device *dev,
                                break;
                        }
                }
+       }
        rcu_read_unlock();
        return found;
 }