From e240b0635b4e01396628ae51501cdfb8d807c300 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Tue, 9 Aug 2005 20:08:50 -0700 Subject: [PATCH] --- yaml --- r: 6272 b: refs/heads/master c: 81849d106b1fb97f8e2d311c0c4d36347def55b8 h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/include/net/inet_hashtables.h | 34 +++++++++++++++++++++++++++++ trunk/net/ipv4/tcp_ipv4.c | 29 ++---------------------- 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/[refs] b/[refs] index fde3c0821d61..193d9396fb27 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: c752f0739f09b803aed191c4765a3b6650a08653 +refs/heads/master: 81849d106b1fb97f8e2d311c0c4d36347def55b8 diff --git a/trunk/include/net/inet_hashtables.h b/trunk/include/net/inet_hashtables.h index c816708fa556..6731df2cea67 100644 --- a/trunk/include/net/inet_hashtables.h +++ b/trunk/include/net/inet_hashtables.h @@ -240,4 +240,38 @@ static inline void __inet_hash(struct inet_hashinfo *hashinfo, if (listen_possible && sk->sk_state == TCP_LISTEN) wake_up(&hashinfo->lhash_wait); } + +static inline void inet_hash(struct inet_hashinfo *hashinfo, struct sock *sk) +{ + if (sk->sk_state != TCP_CLOSE) { + local_bh_disable(); + __inet_hash(hashinfo, sk, 1); + local_bh_enable(); + } +} + +static inline void inet_unhash(struct inet_hashinfo *hashinfo, struct sock *sk) +{ + rwlock_t *lock; + + if (sk_unhashed(sk)) + goto out; + + if (sk->sk_state == TCP_LISTEN) { + local_bh_disable(); + inet_listen_wlock(hashinfo); + lock = &hashinfo->lhash_lock; + } else { + struct inet_ehash_bucket *head = &hashinfo->ehash[sk->sk_hashent]; + lock = &head->lock; + write_lock_bh(&head->lock); + } + + if (__sk_del_node_init(sk)) + sock_prot_dec_use(sk->sk_prot); + write_unlock_bh(lock); +out: + if (sk->sk_state == TCP_LISTEN) + wake_up(&hashinfo->lhash_wait); +} #endif /* _INET_HASHTABLES_H */ diff --git a/trunk/net/ipv4/tcp_ipv4.c b/trunk/net/ipv4/tcp_ipv4.c index 5f9ad95304ca..dca1be67164b 100644 --- a/trunk/net/ipv4/tcp_ipv4.c +++ b/trunk/net/ipv4/tcp_ipv4.c @@ -230,37 +230,12 @@ static int tcp_v4_get_port(struct sock *sk, unsigned short snum) static void tcp_v4_hash(struct sock *sk) { - if (sk->sk_state != TCP_CLOSE) { - local_bh_disable(); - __inet_hash(&tcp_hashinfo, sk, 1); - local_bh_enable(); - } + inet_hash(&tcp_hashinfo, sk); } void tcp_unhash(struct sock *sk) { - rwlock_t *lock; - - if (sk_unhashed(sk)) - goto ende; - - if (sk->sk_state == TCP_LISTEN) { - local_bh_disable(); - inet_listen_wlock(&tcp_hashinfo); - lock = &tcp_hashinfo.lhash_lock; - } else { - struct inet_ehash_bucket *head = &tcp_hashinfo.ehash[sk->sk_hashent]; - lock = &head->lock; - write_lock_bh(&head->lock); - } - - if (__sk_del_node_init(sk)) - sock_prot_dec_use(sk->sk_prot); - write_unlock_bh(lock); - - ende: - if (sk->sk_state == TCP_LISTEN) - wake_up(&tcp_hashinfo.lhash_wait); + inet_unhash(&tcp_hashinfo, sk); } /* Don't inline this cruft. Here are some nice properties to