aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/tcp.h
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@ghostprotocols.net>2005-08-09 23:00:51 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2005-08-29 18:38:39 -0400
commit77d8bf9c6208eb535f05718168ffcc476be0ca8c (patch)
tree255d84f4f222161235d54f82793667cccc509229 /include/net/tcp.h
parent0f7ff9274e72fd254fbd1ab117bbc1db6e7cdb34 (diff)
[INET]: Move the TCP hashtable functions/structs to inet_hashtables.[ch]
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/tcp.h')
-rw-r--r--include/net/tcp.h120
1 files changed, 2 insertions, 118 deletions
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 6c9f6f7cab5c..ff5d30ac2b06 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -30,6 +30,7 @@
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/cache.h> 31#include <linux/cache.h>
32#include <linux/percpu.h> 32#include <linux/percpu.h>
33#include <net/inet_hashtables.h>
33#include <net/checksum.h> 34#include <net/checksum.h>
34#include <net/request_sock.h> 35#include <net/request_sock.h>
35#include <net/sock.h> 36#include <net/sock.h>
@@ -40,101 +41,6 @@
40#endif 41#endif
41#include <linux/seq_file.h> 42#include <linux/seq_file.h>
42 43
43/* This is for all connections with a full identity, no wildcards.
44 * New scheme, half the table is for TIME_WAIT, the other half is
45 * for the rest. I'll experiment with dynamic table growth later.
46 */
47struct inet_ehash_bucket {
48 rwlock_t lock;
49 struct hlist_head chain;
50} __attribute__((__aligned__(8)));
51
52/* This is for listening sockets, thus all sockets which possess wildcards. */
53#define INET_LHTABLE_SIZE 32 /* Yes, really, this is all you need. */
54
55/* There are a few simple rules, which allow for local port reuse by
56 * an application. In essence:
57 *
58 * 1) Sockets bound to different interfaces may share a local port.
59 * Failing that, goto test 2.
60 * 2) If all sockets have sk->sk_reuse set, and none of them are in
61 * TCP_LISTEN state, the port may be shared.
62 * Failing that, goto test 3.
63 * 3) If all sockets are bound to a specific inet_sk(sk)->rcv_saddr local
64 * address, and none of them are the same, the port may be
65 * shared.
66 * Failing this, the port cannot be shared.
67 *
68 * The interesting point, is test #2. This is what an FTP server does
69 * all day. To optimize this case we use a specific flag bit defined
70 * below. As we add sockets to a bind bucket list, we perform a
71 * check of: (newsk->sk_reuse && (newsk->sk_state != TCP_LISTEN))
72 * As long as all sockets added to a bind bucket pass this test,
73 * the flag bit will be set.
74 * The resulting situation is that tcp_v[46]_verify_bind() can just check
75 * for this flag bit, if it is set and the socket trying to bind has
76 * sk->sk_reuse set, we don't even have to walk the owners list at all,
77 * we return that it is ok to bind this socket to the requested local port.
78 *
79 * Sounds like a lot of work, but it is worth it. In a more naive
80 * implementation (ie. current FreeBSD etc.) the entire list of ports
81 * must be walked for each data port opened by an ftp server. Needless
82 * to say, this does not scale at all. With a couple thousand FTP
83 * users logged onto your box, isn't it nice to know that new data
84 * ports are created in O(1) time? I thought so. ;-) -DaveM
85 */
86struct inet_bind_bucket {
87 unsigned short port;
88 signed short fastreuse;
89 struct hlist_node node;
90 struct hlist_head owners;
91};
92
93#define inet_bind_bucket_for_each(tb, node, head) \
94 hlist_for_each_entry(tb, node, head, node)
95
96struct inet_bind_hashbucket {
97 spinlock_t lock;
98 struct hlist_head chain;
99};
100
101struct inet_hashinfo {
102 /* This is for sockets with full identity only. Sockets here will
103 * always be without wildcards and will have the following invariant:
104 *
105 * TCP_ESTABLISHED <= sk->sk_state < TCP_CLOSE
106 *
107 * First half of the table is for sockets not in TIME_WAIT, second half
108 * is for TIME_WAIT sockets only.
109 */
110 struct inet_ehash_bucket *ehash;
111
112 /* Ok, let's try this, I give up, we do need a local binding
113 * TCP hash as well as the others for fast bind/connect.
114 */
115 struct inet_bind_hashbucket *bhash;
116
117 int bhash_size;
118 int ehash_size;
119
120 /* All sockets in TCP_LISTEN state will be in here. This is the only
121 * table where wildcard'd TCP sockets can exist. Hash function here
122 * is just local port number.
123 */
124 struct hlist_head listening_hash[INET_LHTABLE_SIZE];
125
126 /* All the above members are written once at bootup and
127 * never written again _or_ are predominantly read-access.
128 *
129 * Now align to a new cache line as all the following members
130 * are often dirty.
131 */
132 rwlock_t lhash_lock ____cacheline_aligned;
133 atomic_t lhash_users;
134 wait_queue_head_t lhash_wait;
135 spinlock_t portalloc_lock;
136};
137
138extern struct inet_hashinfo tcp_hashinfo; 44extern struct inet_hashinfo tcp_hashinfo;
139#define tcp_ehash (tcp_hashinfo.ehash) 45#define tcp_ehash (tcp_hashinfo.ehash)
140#define tcp_bhash (tcp_hashinfo.bhash) 46#define tcp_bhash (tcp_hashinfo.bhash)
@@ -147,19 +53,8 @@ extern struct inet_hashinfo tcp_hashinfo;
147#define tcp_portalloc_lock (tcp_hashinfo.portalloc_lock) 53#define tcp_portalloc_lock (tcp_hashinfo.portalloc_lock)
148 54
149extern kmem_cache_t *tcp_bucket_cachep; 55extern kmem_cache_t *tcp_bucket_cachep;
150extern struct inet_bind_bucket *
151 inet_bind_bucket_create(kmem_cache_t *cachep,
152 struct inet_bind_hashbucket *head,
153 const unsigned short snum);
154extern void inet_bind_bucket_destroy(kmem_cache_t *cachep,
155 struct inet_bind_bucket *tb);
156extern int tcp_port_rover;
157 56
158/* These are AF independent. */ 57extern int tcp_port_rover;
159static inline int inet_bhashfn(const __u16 lport, const int bhash_size)
160{
161 return lport & (bhash_size - 1);
162}
163 58
164extern void tcp_bind_hash(struct sock *sk, struct inet_bind_bucket *tb, 59extern void tcp_bind_hash(struct sock *sk, struct inet_bind_bucket *tb,
165 unsigned short snum); 60 unsigned short snum);
@@ -359,17 +254,6 @@ extern void tcp_tw_deschedule(struct tcp_tw_bucket *tw);
359 ipv6_addr_equal(&inet6_sk(__sk)->rcv_saddr, (__daddr)) && \ 254 ipv6_addr_equal(&inet6_sk(__sk)->rcv_saddr, (__daddr)) && \
360 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) 255 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
361 256
362/* These can have wildcards, don't try too hard. */
363static inline int inet_lhashfn(const unsigned short num)
364{
365 return num & (INET_LHTABLE_SIZE - 1);
366}
367
368static inline int inet_sk_listen_hashfn(const struct sock *sk)
369{
370 return inet_lhashfn(inet_sk(sk)->num);
371}
372
373#define MAX_TCP_HEADER (128 + MAX_HEADER) 257#define MAX_TCP_HEADER (128 + MAX_HEADER)
374 258
375/* 259/*