Skip to content

Commit 3f27fb2

Browse files
edumazetdavem330
authored andcommitted
ipv6: addrconf: add per netns perturbation in inet6_addr_hash()
Bring IPv6 in par with IPv4 : - Use net_hash_mix() to spread addresses a bit more. - Use 256 slots hash table instead of 16 Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 752a929 commit 3f27fb2

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

include/net/addrconf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct in6_validator_info {
5858
struct netlink_ext_ack *extack;
5959
};
6060

61-
#define IN6_ADDR_HSIZE_SHIFT 4
61+
#define IN6_ADDR_HSIZE_SHIFT 8
6262
#define IN6_ADDR_HSIZE (1 << IN6_ADDR_HSIZE_SHIFT)
6363

6464
int addrconf_init(void);

net/ipv6/addrconf.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -950,9 +950,11 @@ ipv6_link_dev_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp)
950950
list_add_tail_rcu(&ifp->if_list, p);
951951
}
952952

953-
static u32 inet6_addr_hash(const struct in6_addr *addr)
953+
static u32 inet6_addr_hash(const struct net *net, const struct in6_addr *addr)
954954
{
955-
return hash_32(ipv6_addr_hash(addr), IN6_ADDR_HSIZE_SHIFT);
955+
u32 val = ipv6_addr_hash(addr) ^ net_hash_mix(net);
956+
957+
return hash_32(val, IN6_ADDR_HSIZE_SHIFT);
956958
}
957959

958960
static bool ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr,
@@ -973,7 +975,7 @@ static bool ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr,
973975

974976
static int ipv6_add_addr_hash(struct net_device *dev, struct inet6_ifaddr *ifa)
975977
{
976-
unsigned int hash = inet6_addr_hash(&ifa->addr);
978+
unsigned int hash = inet6_addr_hash(dev_net(dev), &ifa->addr);
977979
int err = 0;
978980

979981
spin_lock(&addrconf_hash_lock);
@@ -1838,8 +1840,8 @@ int ipv6_chk_addr_and_flags(struct net *net, const struct in6_addr *addr,
18381840
const struct net_device *dev, int strict,
18391841
u32 banned_flags)
18401842
{
1843+
unsigned int hash = inet6_addr_hash(net, addr);
18411844
struct inet6_ifaddr *ifp;
1842-
unsigned int hash = inet6_addr_hash(addr);
18431845
u32 ifp_flags;
18441846

18451847
rcu_read_lock_bh();
@@ -1917,8 +1919,8 @@ EXPORT_SYMBOL(ipv6_chk_prefix);
19171919
struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, const struct in6_addr *addr,
19181920
struct net_device *dev, int strict)
19191921
{
1922+
unsigned int hash = inet6_addr_hash(net, addr);
19201923
struct inet6_ifaddr *ifp, *result = NULL;
1921-
unsigned int hash = inet6_addr_hash(addr);
19221924

19231925
rcu_read_lock_bh();
19241926
hlist_for_each_entry_rcu_bh(ifp, &inet6_addr_lst[hash], addr_lst) {
@@ -4242,9 +4244,9 @@ void if6_proc_exit(void)
42424244
/* Check if address is a home address configured on any interface. */
42434245
int ipv6_chk_home_addr(struct net *net, const struct in6_addr *addr)
42444246
{
4245-
int ret = 0;
4247+
unsigned int hash = inet6_addr_hash(net, addr);
42464248
struct inet6_ifaddr *ifp = NULL;
4247-
unsigned int hash = inet6_addr_hash(addr);
4249+
int ret = 0;
42484250

42494251
rcu_read_lock_bh();
42504252
hlist_for_each_entry_rcu_bh(ifp, &inet6_addr_lst[hash], addr_lst) {

0 commit comments

Comments
 (0)