aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/inet_timewait_sock.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@ghostprotocols.net>2005-08-09 23:09:46 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2005-08-29 18:42:18 -0400
commite48c414ee61f4ac8d5cff2973e66a7cbc8a93aa5 (patch)
treec4656efe48b75adf5742514c3e4286007f20bdca /net/ipv4/inet_timewait_sock.c
parent8feaf0c0a5488b3d898a9c207eb6678f44ba3f26 (diff)
[INET]: Generalise the TCP sock ID lookup routines
And also some TIME_WAIT functions. [acme@toy net-2.6.14]$ grep built-in /tmp/before.size /tmp/after.size /tmp/before.size: 282955 13122 9312 305389 4a8ed net/ipv4/built-in.o /tmp/after.size: 281566 13122 9312 304000 4a380 net/ipv4/built-in.o [acme@toy net-2.6.14]$ I kept them still inlined, will uninline at some point to see what would be the performance difference. Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/inet_timewait_sock.c')
-rw-r--r--net/ipv4/inet_timewait_sock.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c
new file mode 100644
index 000000000000..d38d160faeb7
--- /dev/null
+++ b/net/ipv4/inet_timewait_sock.c
@@ -0,0 +1,83 @@
1/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * Generic TIME_WAIT sockets functions
7 *
8 * From code orinally in TCP
9 */
10
11#include <linux/config.h>
12
13#include <net/inet_hashtables.h>
14#include <net/inet_timewait_sock.h>
15
16/* Must be called with locally disabled BHs. */
17void __inet_twsk_kill(struct inet_timewait_sock *tw, struct inet_hashinfo *hashinfo)
18{
19 struct inet_bind_hashbucket *bhead;
20 struct inet_bind_bucket *tb;
21 /* Unlink from established hashes. */
22 struct inet_ehash_bucket *ehead = &hashinfo->ehash[tw->tw_hashent];
23
24 write_lock(&ehead->lock);
25 if (hlist_unhashed(&tw->tw_node)) {
26 write_unlock(&ehead->lock);
27 return;
28 }
29 __hlist_del(&tw->tw_node);
30 sk_node_init(&tw->tw_node);
31 write_unlock(&ehead->lock);
32
33 /* Disassociate with bind bucket. */
34 bhead = &hashinfo->bhash[inet_bhashfn(tw->tw_num, hashinfo->bhash_size)];
35 spin_lock(&bhead->lock);
36 tb = tw->tw_tb;
37 __hlist_del(&tw->tw_bind_node);
38 tw->tw_tb = NULL;
39 inet_bind_bucket_destroy(hashinfo->bind_bucket_cachep, tb);
40 spin_unlock(&bhead->lock);
41#ifdef SOCK_REFCNT_DEBUG
42 if (atomic_read(&tw->tw_refcnt) != 1) {
43 printk(KERN_DEBUG "%s timewait_sock %p refcnt=%d\n",
44 tw->tw_prot->name, tw, atomic_read(&tw->tw_refcnt));
45 }
46#endif
47 inet_twsk_put(tw);
48}
49
50/*
51 * Enter the time wait state. This is called with locally disabled BH.
52 * Essentially we whip up a timewait bucket, copy the relevant info into it
53 * from the SK, and mess with hash chains and list linkage.
54 */
55void __inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk,
56 struct inet_hashinfo *hashinfo)
57{
58 const struct inet_sock *inet = inet_sk(sk);
59 struct inet_ehash_bucket *ehead = &hashinfo->ehash[sk->sk_hashent];
60 struct inet_bind_hashbucket *bhead;
61 /* Step 1: Put TW into bind hash. Original socket stays there too.
62 Note, that any socket with inet->num != 0 MUST be bound in
63 binding cache, even if it is closed.
64 */
65 bhead = &hashinfo->bhash[inet_bhashfn(inet->num, hashinfo->bhash_size)];
66 spin_lock(&bhead->lock);
67 tw->tw_tb = inet->bind_hash;
68 BUG_TRAP(inet->bind_hash);
69 inet_twsk_add_bind_node(tw, &tw->tw_tb->owners);
70 spin_unlock(&bhead->lock);
71
72 write_lock(&ehead->lock);
73
74 /* Step 2: Remove SK from established hash. */
75 if (__sk_del_node_init(sk))
76 sock_prot_dec_use(sk->sk_prot);
77
78 /* Step 3: Hash TW into TIMEWAIT half of established hash table. */
79 inet_twsk_add_node(tw, &(ehead + hashinfo->ehash_size)->chain);
80 atomic_inc(&tw->tw_refcnt);
81
82 write_unlock(&ehead->lock);
83}