]> err.no Git - linux-2.6/blobdiff - net/ipv4/inet_hashtables.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-2.6
[linux-2.6] / net / ipv4 / inet_hashtables.c
index 8dfd5a691e5f2ae3ee85bf508f3a9692e6df10ce..619c63c6948aa1cac403c3a7e94a5dc550acba1b 100644 (file)
@@ -96,6 +96,7 @@ EXPORT_SYMBOL(inet_put_port);
  * exclusive lock release). It should be ifdefed really.
  */
 void inet_listen_wlock(struct inet_hashinfo *hashinfo)
+       __acquires(hashinfo->lhash_lock)
 {
        write_lock(&hashinfo->lhash_lock);
 
@@ -190,6 +191,44 @@ sherry_cache:
 }
 EXPORT_SYMBOL_GPL(__inet_lookup_listener);
 
+struct sock * __inet_lookup_established(struct inet_hashinfo *hashinfo,
+                                 const __be32 saddr, const __be16 sport,
+                                 const __be32 daddr, const u16 hnum,
+                                 const int dif)
+{
+       INET_ADDR_COOKIE(acookie, saddr, daddr)
+       const __portpair ports = INET_COMBINED_PORTS(sport, hnum);
+       struct sock *sk;
+       const struct hlist_node *node;
+       /* Optimize here for direct hit, only listening connections can
+        * have wildcards anyways.
+        */
+       unsigned int hash = inet_ehashfn(daddr, hnum, saddr, sport);
+       struct inet_ehash_bucket *head = inet_ehash_bucket(hashinfo, hash);
+       rwlock_t *lock = inet_ehash_lockp(hashinfo, hash);
+
+       prefetch(head->chain.first);
+       read_lock(lock);
+       sk_for_each(sk, node, &head->chain) {
+               if (INET_MATCH(sk, hash, acookie, saddr, daddr, ports, dif))
+                       goto hit; /* You sunk my battleship! */
+       }
+
+       /* Must check for a TIME_WAIT'er before going to listener hash. */
+       sk_for_each(sk, node, &head->twchain) {
+               if (INET_TW_MATCH(sk, hash, acookie, saddr, daddr, ports, dif))
+                       goto hit;
+       }
+       sk = NULL;
+out:
+       read_unlock(lock);
+       return sk;
+hit:
+       sock_hold(sk);
+       goto out;
+}
+EXPORT_SYMBOL_GPL(__inet_lookup_established);
+
 /* called with local bh disabled */
 static int __inet_check_established(struct inet_timewait_death_row *death_row,
                                    struct sock *sk, __u16 lport,
@@ -239,7 +278,7 @@ unique:
        sk->sk_hash = hash;
        BUG_TRAP(sk_unhashed(sk));
        __sk_add_node(sk, &head->chain);
-       sock_prot_inc_use(sk->sk_prot);
+       sock_prot_inuse_add(sk->sk_prot, 1);
        write_unlock(lock);
 
        if (twp) {
@@ -282,7 +321,7 @@ void __inet_hash_nolisten(struct inet_hashinfo *hashinfo, struct sock *sk)
 
        write_lock(lock);
        __sk_add_node(sk, list);
-       sock_prot_inc_use(sk->sk_prot);
+       sock_prot_inuse_add(sk->sk_prot, 1);
        write_unlock(lock);
 }
 EXPORT_SYMBOL_GPL(__inet_hash_nolisten);
@@ -303,7 +342,7 @@ void __inet_hash(struct inet_hashinfo *hashinfo, struct sock *sk)
 
        inet_listen_wlock(hashinfo);
        __sk_add_node(sk, list);
-       sock_prot_inc_use(sk->sk_prot);
+       sock_prot_inuse_add(sk->sk_prot, 1);
        write_unlock(lock);
        wake_up(&hashinfo->lhash_wait);
 }