diff options
| author | Eric Dumazet <edumazet@google.com> | 2017-10-23 19:17:46 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2017-10-24 04:54:19 -0400 |
| commit | 752a92927e97e88096394dac3f10d12a58555254 (patch) | |
| tree | 7cd95fcbbd7b56d7e99f10070460e3782dd86e81 /net/ipv6/addrconf.c | |
| parent | 56fc709b7a9fe191173dc772a881e180458db517 (diff) | |
ipv6: addrconf: factorize inet6_addr_hash() call
ipv6_add_addr_hash() can compute the hash value outside of
locked section and pass it to ipv6_chk_same_addr().
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6/addrconf.c')
| -rw-r--r-- | net/ipv6/addrconf.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 9228030e3497..c1a5028f394c 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c | |||
| @@ -956,9 +956,8 @@ static u32 inet6_addr_hash(const struct in6_addr *addr) | |||
| 956 | } | 956 | } |
| 957 | 957 | ||
| 958 | static bool ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr, | 958 | static bool ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr, |
| 959 | struct net_device *dev) | 959 | struct net_device *dev, unsigned int hash) |
| 960 | { | 960 | { |
| 961 | unsigned int hash = inet6_addr_hash(addr); | ||
| 962 | struct inet6_ifaddr *ifp; | 961 | struct inet6_ifaddr *ifp; |
| 963 | 962 | ||
| 964 | hlist_for_each_entry(ifp, &inet6_addr_lst[hash], addr_lst) { | 963 | hlist_for_each_entry(ifp, &inet6_addr_lst[hash], addr_lst) { |
| @@ -974,23 +973,19 @@ static bool ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr, | |||
| 974 | 973 | ||
| 975 | static int ipv6_add_addr_hash(struct net_device *dev, struct inet6_ifaddr *ifa) | 974 | static int ipv6_add_addr_hash(struct net_device *dev, struct inet6_ifaddr *ifa) |
| 976 | { | 975 | { |
| 977 | unsigned int hash; | 976 | unsigned int hash = inet6_addr_hash(&ifa->addr); |
| 978 | int err = 0; | 977 | int err = 0; |
| 979 | 978 | ||
| 980 | spin_lock(&addrconf_hash_lock); | 979 | spin_lock(&addrconf_hash_lock); |
| 981 | 980 | ||
| 982 | /* Ignore adding duplicate addresses on an interface */ | 981 | /* Ignore adding duplicate addresses on an interface */ |
| 983 | if (ipv6_chk_same_addr(dev_net(dev), &ifa->addr, dev)) { | 982 | if (ipv6_chk_same_addr(dev_net(dev), &ifa->addr, dev, hash)) { |
| 984 | ADBG("ipv6_add_addr: already assigned\n"); | 983 | ADBG("ipv6_add_addr: already assigned\n"); |
| 985 | err = -EEXIST; | 984 | err = -EEXIST; |
| 986 | goto out; | 985 | } else { |
| 986 | hlist_add_head_rcu(&ifa->addr_lst, &inet6_addr_lst[hash]); | ||
| 987 | } | 987 | } |
| 988 | 988 | ||
| 989 | /* Add to big hash table */ | ||
| 990 | hash = inet6_addr_hash(&ifa->addr); | ||
| 991 | hlist_add_head_rcu(&ifa->addr_lst, &inet6_addr_lst[hash]); | ||
| 992 | |||
| 993 | out: | ||
| 994 | spin_unlock(&addrconf_hash_lock); | 989 | spin_unlock(&addrconf_hash_lock); |
| 995 | 990 | ||
| 996 | return err; | 991 | return err; |
