aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@ghostprotocols.net>2005-08-09 23:07:13 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2005-08-29 18:40:29 -0400
commit2d8c4ce51903636ce0f60addc8134aa50ab8fa76 (patch)
tree1ea4d4faf831b832489b30b13d8910777020feed /include
parentff21d5774b4a186c98be6398eacde75d896db804 (diff)
[INET]: Generalise tcp_bind_hash & tcp_inherit_port
This required moving tcp_bucket_cachep to inet_hashinfo. Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include')
-rw-r--r--include/net/inet_hashtables.h32
-rw-r--r--include/net/tcp.h11
2 files changed, 34 insertions, 9 deletions
diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h
index 3a6c11ca421d..da9705525f15 100644
--- a/include/net/inet_hashtables.h
+++ b/include/net/inet_hashtables.h
@@ -14,12 +14,15 @@
14#ifndef _INET_HASHTABLES_H 14#ifndef _INET_HASHTABLES_H
15#define _INET_HASHTABLES_H 15#define _INET_HASHTABLES_H
16 16
17#include <linux/interrupt.h>
17#include <linux/ip.h> 18#include <linux/ip.h>
18#include <linux/list.h> 19#include <linux/list.h>
19#include <linux/slab.h> 20#include <linux/slab.h>
20#include <linux/spinlock.h> 21#include <linux/spinlock.h>
21#include <linux/types.h> 22#include <linux/types.h>
22 23
24#include <net/sock.h>
25
23/* This is for all connections with a full identity, no wildcards. 26/* This is for all connections with a full identity, no wildcards.
24 * New scheme, half the table is for TIME_WAIT, the other half is 27 * New scheme, half the table is for TIME_WAIT, the other half is
25 * for the rest. I'll experiment with dynamic table growth later. 28 * for the rest. I'll experiment with dynamic table growth later.
@@ -113,6 +116,7 @@ struct inet_hashinfo {
113 atomic_t lhash_users; 116 atomic_t lhash_users;
114 wait_queue_head_t lhash_wait; 117 wait_queue_head_t lhash_wait;
115 spinlock_t portalloc_lock; 118 spinlock_t portalloc_lock;
119 kmem_cache_t *bind_bucket_cachep;
116}; 120};
117 121
118static inline int inet_ehashfn(const __u32 laddr, const __u16 lport, 122static inline int inet_ehashfn(const __u32 laddr, const __u16 lport,
@@ -148,6 +152,9 @@ static inline int inet_bhashfn(const __u16 lport, const int bhash_size)
148 return lport & (bhash_size - 1); 152 return lport & (bhash_size - 1);
149} 153}
150 154
155extern void inet_bind_hash(struct sock *sk, struct inet_bind_bucket *tb,
156 const unsigned short snum);
157
151/* These can have wildcards, don't try too hard. */ 158/* These can have wildcards, don't try too hard. */
152static inline int inet_lhashfn(const unsigned short num) 159static inline int inet_lhashfn(const unsigned short num)
153{ 160{
@@ -159,4 +166,29 @@ static inline int inet_sk_listen_hashfn(const struct sock *sk)
159 return inet_lhashfn(inet_sk(sk)->num); 166 return inet_lhashfn(inet_sk(sk)->num);
160} 167}
161 168
169/* Caller must disable local BH processing. */
170static inline void __inet_inherit_port(struct inet_hashinfo *table,
171 struct sock *sk, struct sock *child)
172{
173 const int bhash = inet_bhashfn(inet_sk(child)->num, table->bhash_size);
174 struct inet_bind_hashbucket *head = &table->bhash[bhash];
175 struct inet_bind_bucket *tb;
176
177 spin_lock(&head->lock);
178 tb = inet_sk(sk)->bind_hash;
179 sk_add_bind_node(child, &tb->owners);
180 inet_sk(child)->bind_hash = tb;
181 spin_unlock(&head->lock);
182}
183
184static inline void inet_inherit_port(struct inet_hashinfo *table,
185 struct sock *sk, struct sock *child)
186{
187 local_bh_disable();
188 __inet_inherit_port(table, sk, child);
189 local_bh_enable();
190}
191
192extern void inet_put_port(struct inet_hashinfo *table, struct sock *sk);
193
162#endif /* _INET_HASHTABLES_H */ 194#endif /* _INET_HASHTABLES_H */
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 6c6c879e7e87..9eb8ff7c911e 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -51,14 +51,10 @@ extern struct inet_hashinfo tcp_hashinfo;
51#define tcp_lhash_users (tcp_hashinfo.lhash_users) 51#define tcp_lhash_users (tcp_hashinfo.lhash_users)
52#define tcp_lhash_wait (tcp_hashinfo.lhash_wait) 52#define tcp_lhash_wait (tcp_hashinfo.lhash_wait)
53#define tcp_portalloc_lock (tcp_hashinfo.portalloc_lock) 53#define tcp_portalloc_lock (tcp_hashinfo.portalloc_lock)
54 54#define tcp_bucket_cachep (tcp_hashinfo.bind_bucket_cachep)
55extern kmem_cache_t *tcp_bucket_cachep;
56 55
57extern int tcp_port_rover; 56extern int tcp_port_rover;
58 57
59extern void tcp_bind_hash(struct sock *sk, struct inet_bind_bucket *tb,
60 unsigned short snum);
61
62#if (BITS_PER_LONG == 64) 58#if (BITS_PER_LONG == 64)
63#define TCP_ADDRCMP_ALIGN_BYTES 8 59#define TCP_ADDRCMP_ALIGN_BYTES 8
64#else 60#else
@@ -549,9 +545,6 @@ DECLARE_SNMP_STAT(struct tcp_mib, tcp_statistics);
549#define TCP_ADD_STATS_BH(field, val) SNMP_ADD_STATS_BH(tcp_statistics, field, val) 545#define TCP_ADD_STATS_BH(field, val) SNMP_ADD_STATS_BH(tcp_statistics, field, val)
550#define TCP_ADD_STATS_USER(field, val) SNMP_ADD_STATS_USER(tcp_statistics, field, val) 546#define TCP_ADD_STATS_USER(field, val) SNMP_ADD_STATS_USER(tcp_statistics, field, val)
551 547
552extern void tcp_put_port(struct sock *sk);
553extern void tcp_inherit_port(struct sock *sk, struct sock *child);
554
555extern void tcp_v4_err(struct sk_buff *skb, u32); 548extern void tcp_v4_err(struct sk_buff *skb, u32);
556 549
557extern void tcp_shutdown (struct sock *sk, int how); 550extern void tcp_shutdown (struct sock *sk, int how);
@@ -1268,7 +1261,7 @@ static __inline__ void tcp_set_state(struct sock *sk, int state)
1268 sk->sk_prot->unhash(sk); 1261 sk->sk_prot->unhash(sk);
1269 if (inet_sk(sk)->bind_hash && 1262 if (inet_sk(sk)->bind_hash &&
1270 !(sk->sk_userlocks & SOCK_BINDPORT_LOCK)) 1263 !(sk->sk_userlocks & SOCK_BINDPORT_LOCK))
1271 tcp_put_port(sk); 1264 inet_put_port(&tcp_hashinfo, sk);
1272 /* fall through */ 1265 /* fall through */
1273 default: 1266 default:
1274 if (oldstate==TCP_ESTABLISHED) 1267 if (oldstate==TCP_ESTABLISHED)