aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@ghostprotocols.net>2005-08-09 23:08:50 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2005-08-29 18:42:02 -0400
commit81849d106b1fb97f8e2d311c0c4d36347def55b8 (patch)
treeba1188f1b38f5b608756d94395c919ab5f7b8b3c
parentc752f0739f09b803aed191c4765a3b6650a08653 (diff)
[INET]: Generalise tcp_v4_hash & tcp_unhash
It really just makes the existing code be a helper function that tcp_v4_hash and tcp_unhash uses, specifying the right inet_hashinfo, tcp_hashinfo. One thing I'll investigate at some point is to have the inet_hashinfo pointer in sk_prot, so that we get all the hashtable information from the sk pointer, this can lead to some extra indirections that may well hurt performance/code size, we'll see. Ultimate idea would be that sk_prot would provide _all_ the information about a protocol implementation. Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/inet_hashtables.h34
-rw-r--r--net/ipv4/tcp_ipv4.c29
2 files changed, 36 insertions, 27 deletions
diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h
index c816708fa556..6731df2cea67 100644
--- a/include/net/inet_hashtables.h
+++ b/include/net/inet_hashtables.h
@@ -240,4 +240,38 @@ static inline void __inet_hash(struct inet_hashinfo *hashinfo,
240 if (listen_possible && sk->sk_state == TCP_LISTEN) 240 if (listen_possible && sk->sk_state == TCP_LISTEN)
241 wake_up(&hashinfo->lhash_wait); 241 wake_up(&hashinfo->lhash_wait);
242} 242}
243
244static inline void inet_hash(struct inet_hashinfo *hashinfo, struct sock *sk)
245{
246 if (sk->sk_state != TCP_CLOSE) {
247 local_bh_disable();
248 __inet_hash(hashinfo, sk, 1);
249 local_bh_enable();
250 }
251}
252
253static inline void inet_unhash(struct inet_hashinfo *hashinfo, struct sock *sk)
254{
255 rwlock_t *lock;
256
257 if (sk_unhashed(sk))
258 goto out;
259
260 if (sk->sk_state == TCP_LISTEN) {
261 local_bh_disable();
262 inet_listen_wlock(hashinfo);
263 lock = &hashinfo->lhash_lock;
264 } else {
265 struct inet_ehash_bucket *head = &hashinfo->ehash[sk->sk_hashent];
266 lock = &head->lock;
267 write_lock_bh(&head->lock);
268 }
269
270 if (__sk_del_node_init(sk))
271 sock_prot_dec_use(sk->sk_prot);
272 write_unlock_bh(lock);
273out:
274 if (sk->sk_state == TCP_LISTEN)
275 wake_up(&hashinfo->lhash_wait);
276}
243#endif /* _INET_HASHTABLES_H */ 277#endif /* _INET_HASHTABLES_H */
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 5f9ad95304ca..dca1be67164b 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -230,37 +230,12 @@ fail:
230 230
231static void tcp_v4_hash(struct sock *sk) 231static void tcp_v4_hash(struct sock *sk)
232{ 232{
233 if (sk->sk_state != TCP_CLOSE) { 233 inet_hash(&tcp_hashinfo, sk);
234 local_bh_disable();
235 __inet_hash(&tcp_hashinfo, sk, 1);
236 local_bh_enable();
237 }
238} 234}
239 235
240void tcp_unhash(struct sock *sk) 236void tcp_unhash(struct sock *sk)
241{ 237{
242 rwlock_t *lock; 238 inet_unhash(&tcp_hashinfo, sk);
243
244 if (sk_unhashed(sk))
245 goto ende;
246
247 if (sk->sk_state == TCP_LISTEN) {
248 local_bh_disable();
249 inet_listen_wlock(&tcp_hashinfo);
250 lock = &tcp_hashinfo.lhash_lock;
251 } else {
252 struct inet_ehash_bucket *head = &tcp_hashinfo.ehash[sk->sk_hashent];
253 lock = &head->lock;
254 write_lock_bh(&head->lock);
255 }
256
257 if (__sk_del_node_init(sk))
258 sock_prot_dec_use(sk->sk_prot);
259 write_unlock_bh(lock);
260
261 ende:
262 if (sk->sk_state == TCP_LISTEN)
263 wake_up(&tcp_hashinfo.lhash_wait);
264} 239}
265 240
266/* Don't inline this cruft. Here are some nice properties to 241/* Don't inline this cruft. Here are some nice properties to