@@ -192,8 +192,6 @@ static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifa);
192192
193193static void inet6_prefix_notify (int event , struct inet6_dev * idev ,
194194 struct prefix_info * pinfo );
195- static bool ipv6_chk_same_addr (struct net * net , const struct in6_addr * addr ,
196- struct net_device * dev );
197195
198196static struct ipv6_devconf ipv6_devconf __read_mostly = {
199197 .forwarding = 0 ,
@@ -952,30 +950,44 @@ ipv6_link_dev_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp)
952950 list_add_tail_rcu (& ifp -> if_list , p );
953951}
954952
955- 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 )
956954{
957- 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 );
958+ }
959+
960+ static bool ipv6_chk_same_addr (struct net * net , const struct in6_addr * addr ,
961+ struct net_device * dev , unsigned int hash )
962+ {
963+ struct inet6_ifaddr * ifp ;
964+
965+ hlist_for_each_entry (ifp , & inet6_addr_lst [hash ], addr_lst ) {
966+ if (!net_eq (dev_net (ifp -> idev -> dev ), net ))
967+ continue ;
968+ if (ipv6_addr_equal (& ifp -> addr , addr )) {
969+ if (!dev || ifp -> idev -> dev == dev )
970+ return true;
971+ }
972+ }
973+ return false;
958974}
959975
960976static int ipv6_add_addr_hash (struct net_device * dev , struct inet6_ifaddr * ifa )
961977{
962- unsigned int hash ;
978+ unsigned int hash = inet6_addr_hash ( dev_net ( dev ), & ifa -> addr ) ;
963979 int err = 0 ;
964980
965981 spin_lock (& addrconf_hash_lock );
966982
967983 /* Ignore adding duplicate addresses on an interface */
968- if (ipv6_chk_same_addr (dev_net (dev ), & ifa -> addr , dev )) {
984+ if (ipv6_chk_same_addr (dev_net (dev ), & ifa -> addr , dev , hash )) {
969985 ADBG ("ipv6_add_addr: already assigned\n" );
970986 err = - EEXIST ;
971- goto out ;
987+ } else {
988+ hlist_add_head_rcu (& ifa -> addr_lst , & inet6_addr_lst [hash ]);
972989 }
973990
974- /* Add to big hash table */
975- hash = inet6_addr_hash (& ifa -> addr );
976- hlist_add_head_rcu (& ifa -> addr_lst , & inet6_addr_lst [hash ]);
977-
978- out :
979991 spin_unlock (& addrconf_hash_lock );
980992
981993 return err ;
@@ -1828,11 +1840,11 @@ int ipv6_chk_addr_and_flags(struct net *net, const struct in6_addr *addr,
18281840 const struct net_device * dev , int strict ,
18291841 u32 banned_flags )
18301842{
1843+ unsigned int hash = inet6_addr_hash (net , addr );
18311844 struct inet6_ifaddr * ifp ;
1832- unsigned int hash = inet6_addr_hash (addr );
18331845 u32 ifp_flags ;
18341846
1835- rcu_read_lock_bh ();
1847+ rcu_read_lock ();
18361848 hlist_for_each_entry_rcu (ifp , & inet6_addr_lst [hash ], addr_lst ) {
18371849 if (!net_eq (dev_net (ifp -> idev -> dev ), net ))
18381850 continue ;
@@ -1846,32 +1858,16 @@ int ipv6_chk_addr_and_flags(struct net *net, const struct in6_addr *addr,
18461858 !(ifp_flags & banned_flags ) &&
18471859 (!dev || ifp -> idev -> dev == dev ||
18481860 !(ifp -> scope & (IFA_LINK |IFA_HOST ) || strict ))) {
1849- rcu_read_unlock_bh ();
1861+ rcu_read_unlock ();
18501862 return 1 ;
18511863 }
18521864 }
18531865
1854- rcu_read_unlock_bh ();
1866+ rcu_read_unlock ();
18551867 return 0 ;
18561868}
18571869EXPORT_SYMBOL (ipv6_chk_addr_and_flags );
18581870
1859- static bool ipv6_chk_same_addr (struct net * net , const struct in6_addr * addr ,
1860- struct net_device * dev )
1861- {
1862- unsigned int hash = inet6_addr_hash (addr );
1863- struct inet6_ifaddr * ifp ;
1864-
1865- hlist_for_each_entry (ifp , & inet6_addr_lst [hash ], addr_lst ) {
1866- if (!net_eq (dev_net (ifp -> idev -> dev ), net ))
1867- continue ;
1868- if (ipv6_addr_equal (& ifp -> addr , addr )) {
1869- if (!dev || ifp -> idev -> dev == dev )
1870- return true;
1871- }
1872- }
1873- return false;
1874- }
18751871
18761872/* Compares an address/prefix_len with addresses on device @dev.
18771873 * If one is found it returns true.
@@ -1923,11 +1919,11 @@ EXPORT_SYMBOL(ipv6_chk_prefix);
19231919struct inet6_ifaddr * ipv6_get_ifaddr (struct net * net , const struct in6_addr * addr ,
19241920 struct net_device * dev , int strict )
19251921{
1922+ unsigned int hash = inet6_addr_hash (net , addr );
19261923 struct inet6_ifaddr * ifp , * result = NULL ;
1927- unsigned int hash = inet6_addr_hash (addr );
19281924
1929- rcu_read_lock_bh ();
1930- hlist_for_each_entry_rcu_bh (ifp , & inet6_addr_lst [hash ], addr_lst ) {
1925+ rcu_read_lock ();
1926+ hlist_for_each_entry_rcu (ifp , & inet6_addr_lst [hash ], addr_lst ) {
19311927 if (!net_eq (dev_net (ifp -> idev -> dev ), net ))
19321928 continue ;
19331929 if (ipv6_addr_equal (& ifp -> addr , addr )) {
@@ -1939,7 +1935,7 @@ struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, const struct in6_addr *add
19391935 }
19401936 }
19411937 }
1942- rcu_read_unlock_bh ();
1938+ rcu_read_unlock ();
19431939
19441940 return result ;
19451941}
@@ -4101,9 +4097,9 @@ struct if6_iter_state {
41014097
41024098static struct inet6_ifaddr * if6_get_first (struct seq_file * seq , loff_t pos )
41034099{
4104- struct inet6_ifaddr * ifa = NULL ;
41054100 struct if6_iter_state * state = seq -> private ;
41064101 struct net * net = seq_file_net (seq );
4102+ struct inet6_ifaddr * ifa = NULL ;
41074103 int p = 0 ;
41084104
41094105 /* initial bucket if pos is 0 */
@@ -4113,7 +4109,7 @@ static struct inet6_ifaddr *if6_get_first(struct seq_file *seq, loff_t pos)
41134109 }
41144110
41154111 for (; state -> bucket < IN6_ADDR_HSIZE ; ++ state -> bucket ) {
4116- hlist_for_each_entry_rcu_bh (ifa , & inet6_addr_lst [state -> bucket ],
4112+ hlist_for_each_entry_rcu (ifa , & inet6_addr_lst [state -> bucket ],
41174113 addr_lst ) {
41184114 if (!net_eq (dev_net (ifa -> idev -> dev ), net ))
41194115 continue ;
@@ -4139,7 +4135,7 @@ static struct inet6_ifaddr *if6_get_next(struct seq_file *seq,
41394135 struct if6_iter_state * state = seq -> private ;
41404136 struct net * net = seq_file_net (seq );
41414137
4142- hlist_for_each_entry_continue_rcu_bh (ifa , addr_lst ) {
4138+ hlist_for_each_entry_continue_rcu (ifa , addr_lst ) {
41434139 if (!net_eq (dev_net (ifa -> idev -> dev ), net ))
41444140 continue ;
41454141 state -> offset ++ ;
@@ -4148,7 +4144,7 @@ static struct inet6_ifaddr *if6_get_next(struct seq_file *seq,
41484144
41494145 while (++ state -> bucket < IN6_ADDR_HSIZE ) {
41504146 state -> offset = 0 ;
4151- hlist_for_each_entry_rcu_bh (ifa ,
4147+ hlist_for_each_entry_rcu (ifa ,
41524148 & inet6_addr_lst [state -> bucket ], addr_lst ) {
41534149 if (!net_eq (dev_net (ifa -> idev -> dev ), net ))
41544150 continue ;
@@ -4161,9 +4157,9 @@ static struct inet6_ifaddr *if6_get_next(struct seq_file *seq,
41614157}
41624158
41634159static void * if6_seq_start (struct seq_file * seq , loff_t * pos )
4164- __acquires (rcu_bh )
4160+ __acquires (rcu )
41654161{
4166- rcu_read_lock_bh ();
4162+ rcu_read_lock ();
41674163 return if6_get_first (seq , * pos );
41684164}
41694165
@@ -4177,9 +4173,9 @@ static void *if6_seq_next(struct seq_file *seq, void *v, loff_t *pos)
41774173}
41784174
41794175static void if6_seq_stop (struct seq_file * seq , void * v )
4180- __releases (rcu_bh )
4176+ __releases (rcu )
41814177{
4182- rcu_read_unlock_bh ();
4178+ rcu_read_unlock ();
41834179}
41844180
41854181static int if6_seq_show (struct seq_file * seq , void * v )
@@ -4248,12 +4244,12 @@ void if6_proc_exit(void)
42484244/* Check if address is a home address configured on any interface. */
42494245int ipv6_chk_home_addr (struct net * net , const struct in6_addr * addr )
42504246{
4251- int ret = 0 ;
4247+ unsigned int hash = inet6_addr_hash ( net , addr ) ;
42524248 struct inet6_ifaddr * ifp = NULL ;
4253- unsigned int hash = inet6_addr_hash ( addr ) ;
4249+ int ret = 0 ;
42544250
4255- rcu_read_lock_bh ();
4256- hlist_for_each_entry_rcu_bh (ifp , & inet6_addr_lst [hash ], addr_lst ) {
4251+ rcu_read_lock ();
4252+ hlist_for_each_entry_rcu (ifp , & inet6_addr_lst [hash ], addr_lst ) {
42574253 if (!net_eq (dev_net (ifp -> idev -> dev ), net ))
42584254 continue ;
42594255 if (ipv6_addr_equal (& ifp -> addr , addr ) &&
@@ -4262,7 +4258,7 @@ int ipv6_chk_home_addr(struct net *net, const struct in6_addr *addr)
42624258 break ;
42634259 }
42644260 }
4265- rcu_read_unlock_bh ();
4261+ rcu_read_unlock ();
42664262 return ret ;
42674263}
42684264#endif
0 commit comments