inet: add struct net argument to inet_bhashfn
authorPavel Emelyanov <xemul@openvz.org>
Tue, 17 Jun 2008 00:12:49 +0000 (17:12 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 17 Jun 2008 00:12:49 +0000 (17:12 -0700)
Binding to some port in many namespaces may create too long
chains in bhash-es, so prepare the hashfn to take struct net
into account.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/inet_hashtables.h
net/ipv4/inet_connection_sock.c
net/ipv4/inet_hashtables.c
net/ipv4/inet_timewait_sock.c

index 735b926a3497a874eebbba280ab0b5769638ab7d..61dd3317089ce0a572ae8689a4e8f28e63cf3700 100644 (file)
@@ -201,7 +201,8 @@ extern struct inet_bind_bucket *
 extern void inet_bind_bucket_destroy(struct kmem_cache *cachep,
                                     struct inet_bind_bucket *tb);
 
-static inline int inet_bhashfn(const __u16 lport, const int bhash_size)
+static inline int inet_bhashfn(struct net *net,
+               const __u16 lport, const int bhash_size)
 {
        return lport & (bhash_size - 1);
 }
index 045e799d3e1db4e5cc58f72c8a35fc3f05d2eb87..4c804b3c287b59254cd0fb1e58b89052bb20fb09 100644 (file)
@@ -103,7 +103,8 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum)
                rover = net_random() % remaining + low;
 
                do {
-                       head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];
+                       head = &hashinfo->bhash[inet_bhashfn(net, rover,
+                                       hashinfo->bhash_size)];
                        spin_lock(&head->lock);
                        inet_bind_bucket_for_each(tb, node, &head->chain)
                                if (tb->ib_net == net && tb->port == rover)
@@ -130,7 +131,8 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum)
                 */
                snum = rover;
        } else {
-               head = &hashinfo->bhash[inet_bhashfn(snum, hashinfo->bhash_size)];
+               head = &hashinfo->bhash[inet_bhashfn(net, snum,
+                               hashinfo->bhash_size)];
                spin_lock(&head->lock);
                inet_bind_bucket_for_each(tb, node, &head->chain)
                        if (tb->ib_net == net && tb->port == snum)
index 2023d37b2708ea12ea5e5a4cb6ae010697b8d386..dc1b78de89903b32e09440af798b20fa65b3b863 100644 (file)
@@ -70,7 +70,8 @@ void inet_bind_hash(struct sock *sk, struct inet_bind_bucket *tb,
 static void __inet_put_port(struct sock *sk)
 {
        struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo;
-       const int bhash = inet_bhashfn(inet_sk(sk)->num, hashinfo->bhash_size);
+       const int bhash = inet_bhashfn(sock_net(sk), inet_sk(sk)->num,
+                       hashinfo->bhash_size);
        struct inet_bind_hashbucket *head = &hashinfo->bhash[bhash];
        struct inet_bind_bucket *tb;
 
@@ -95,7 +96,8 @@ EXPORT_SYMBOL(inet_put_port);
 void __inet_inherit_port(struct sock *sk, struct sock *child)
 {
        struct inet_hashinfo *table = sk->sk_prot->h.hashinfo;
-       const int bhash = inet_bhashfn(inet_sk(child)->num, table->bhash_size);
+       const int bhash = inet_bhashfn(sock_net(sk), inet_sk(child)->num,
+                       table->bhash_size);
        struct inet_bind_hashbucket *head = &table->bhash[bhash];
        struct inet_bind_bucket *tb;
 
@@ -438,7 +440,8 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row,
                local_bh_disable();
                for (i = 1; i <= remaining; i++) {
                        port = low + (i + offset) % remaining;
-                       head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];
+                       head = &hinfo->bhash[inet_bhashfn(net, port,
+                                       hinfo->bhash_size)];
                        spin_lock(&head->lock);
 
                        /* Does not bother with rcv_saddr checks,
@@ -493,7 +496,7 @@ ok:
                goto out;
        }
 
-       head = &hinfo->bhash[inet_bhashfn(snum, hinfo->bhash_size)];
+       head = &hinfo->bhash[inet_bhashfn(net, snum, hinfo->bhash_size)];
        tb  = inet_csk(sk)->icsk_bind_hash;
        spin_lock_bh(&head->lock);
        if (sk_head(&tb->owners) == sk && !sk->sk_bind_node.next) {
index ce16e9ac24c15841c8cf729634fcd739147b352f..06006a5ac8b9e465c65f8c2e431fec2f5059f50f 100644 (file)
@@ -32,7 +32,8 @@ static void __inet_twsk_kill(struct inet_timewait_sock *tw,
        write_unlock(lock);
 
        /* Disassociate with bind bucket. */
-       bhead = &hashinfo->bhash[inet_bhashfn(tw->tw_num, hashinfo->bhash_size)];
+       bhead = &hashinfo->bhash[inet_bhashfn(twsk_net(tw), tw->tw_num,
+                       hashinfo->bhash_size)];
        spin_lock(&bhead->lock);
        tb = tw->tw_tb;
        __hlist_del(&tw->tw_bind_node);
@@ -81,7 +82,8 @@ void __inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk,
           Note, that any socket with inet->num != 0 MUST be bound in
           binding cache, even if it is closed.
         */
-       bhead = &hashinfo->bhash[inet_bhashfn(inet->num, hashinfo->bhash_size)];
+       bhead = &hashinfo->bhash[inet_bhashfn(twsk_net(tw), inet->num,
+                       hashinfo->bhash_size)];
        spin_lock(&bhead->lock);
        tw->tw_tb = icsk->icsk_bind_hash;
        BUG_TRAP(icsk->icsk_bind_hash);