From: Eric Dumazet <edumazet@google.com>
To: "David S . Miller" <davem@davemloft.net>
Cc: netdev <netdev@vger.kernel.org>,
Eric Dumazet <edumazet@google.com>,
Eric Dumazet <eric.dumazet@gmail.com>
Subject: [PATCH net-next 2/7] ipv6: addrconf: factorize inet6_addr_hash() call
Date: Mon, 23 Oct 2017 16:17:46 -0700 [thread overview]
Message-ID: <20171023231751.29530-3-edumazet@google.com> (raw)
In-Reply-To: <20171023231751.29530-1-edumazet@google.com>
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>
---
net/ipv6/addrconf.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 9228030e34970c1d6380e95e8c193496448ea8ac..c1a5028f394c75d347fe703573548fd617b5c142 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)
}
static bool ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr,
- struct net_device *dev)
+ struct net_device *dev, unsigned int hash)
{
- unsigned int hash = inet6_addr_hash(addr);
struct inet6_ifaddr *ifp;
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,
static int ipv6_add_addr_hash(struct net_device *dev, struct inet6_ifaddr *ifa)
{
- unsigned int hash;
+ unsigned int hash = inet6_addr_hash(&ifa->addr);
int err = 0;
spin_lock(&addrconf_hash_lock);
/* Ignore adding duplicate addresses on an interface */
- if (ipv6_chk_same_addr(dev_net(dev), &ifa->addr, dev)) {
+ if (ipv6_chk_same_addr(dev_net(dev), &ifa->addr, dev, hash)) {
ADBG("ipv6_add_addr: already assigned\n");
err = -EEXIST;
- goto out;
+ } else {
+ hlist_add_head_rcu(&ifa->addr_lst, &inet6_addr_lst[hash]);
}
- /* Add to big hash table */
- hash = inet6_addr_hash(&ifa->addr);
- hlist_add_head_rcu(&ifa->addr_lst, &inet6_addr_lst[hash]);
-
-out:
spin_unlock(&addrconf_hash_lock);
return err;
--
2.15.0.rc0.271.g36b669edcc-goog
next prev parent reply other threads:[~2017-10-23 23:18 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-23 23:17 [PATCH net-next 0/7] ipv6: addrconf: hash improvements and cleanups Eric Dumazet
2017-10-23 23:17 ` [PATCH net-next 1/7] ipv6: addrconf: move ipv6_chk_same_addr() to avoid forward declaration Eric Dumazet
2017-10-23 23:17 ` Eric Dumazet [this message]
2017-10-23 23:17 ` [PATCH net-next 3/7] ipv6: addrconf: add per netns perturbation in inet6_addr_hash() Eric Dumazet
2017-10-23 23:17 ` [PATCH net-next 4/7] ipv6: addrconf: do not block BH in ipv6_chk_addr_and_flags() Eric Dumazet
2017-10-23 23:17 ` [PATCH net-next 5/7] ipv6: addrconf: do not block BH in ipv6_get_ifaddr() Eric Dumazet
2017-10-23 23:17 ` [PATCH net-next 6/7] ipv6: addrconf: do not block BH in /proc/net/if_inet6 handling Eric Dumazet
2017-10-23 23:17 ` [PATCH net-next 7/7] ipv6: addrconf: do not block BH in ipv6_chk_home_addr() Eric Dumazet
2017-10-24 8:54 ` [PATCH net-next 0/7] ipv6: addrconf: hash improvements and cleanups David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171023231751.29530-3-edumazet@google.com \
--to=edumazet@google.com \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox