aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2008-02-03 07:06:04 -0500
committerDavid S. Miller <davem@davemloft.net>2008-02-03 07:28:52 -0500
commitab1e0a13d70299e792fd0527cefd070c1405fa5b (patch)
treed470e7b94b0e33ea59b12713366f1bee0b94f78c /include
parent9dc7f30e3bac329998a2a9bb814bd0abc7cb58e2 (diff)
[SOCK] proto: Add hashinfo member to struct proto
This way we can remove TCP and DCCP specific versions of sk->sk_prot->get_port: both v4 and v6 use inet_csk_get_port sk->sk_prot->hash: inet_hash is directly used, only v6 need a specific version to deal with mapped sockets sk->sk_prot->unhash: both v4 and v6 use inet_hash directly struct inet_connection_sock_af_ops also gets a new member, bind_conflict, so that inet_csk_get_port can find the per family routine. Now only the lookup routines receive as a parameter a struct inet_hashtable. With this we further reuse code, reducing the difference among INET transport protocols. Eventually work has to be done on UDP and SCTP to make them share this infrastructure and get as a bonus inet_diag interfaces so that iproute can be used with these protocols. net-2.6/net/ipv4/inet_hashtables.c: struct proto | +8 struct inet_connection_sock_af_ops | +8 2 structs changed __inet_hash_nolisten | +18 __inet_hash | -210 inet_put_port | +8 inet_bind_bucket_create | +1 __inet_hash_connect | -8 5 functions changed, 27 bytes added, 218 bytes removed, diff: -191 net-2.6/net/core/sock.c: proto_seq_show | +3 1 function changed, 3 bytes added, diff: +3 net-2.6/net/ipv4/inet_connection_sock.c: inet_csk_get_port | +15 1 function changed, 15 bytes added, diff: +15 net-2.6/net/ipv4/tcp.c: tcp_set_state | -7 1 function changed, 7 bytes removed, diff: -7 net-2.6/net/ipv4/tcp_ipv4.c: tcp_v4_get_port | -31 tcp_v4_hash | -48 tcp_v4_destroy_sock | -7 tcp_v4_syn_recv_sock | -2 tcp_unhash | -179 5 functions changed, 267 bytes removed, diff: -267 net-2.6/net/ipv6/inet6_hashtables.c: __inet6_hash | +8 1 function changed, 8 bytes added, diff: +8 net-2.6/net/ipv4/inet_hashtables.c: inet_unhash | +190 inet_hash | +242 2 functions changed, 432 bytes added, diff: +432 vmlinux: 16 functions changed, 485 bytes added, 492 bytes removed, diff: -7 /home/acme/git/net-2.6/net/ipv6/tcp_ipv6.c: tcp_v6_get_port | -31 tcp_v6_hash | -7 tcp_v6_syn_recv_sock | -9 3 functions changed, 47 bytes removed, diff: -47 /home/acme/git/net-2.6/net/dccp/proto.c: dccp_destroy_sock | -7 dccp_unhash | -179 dccp_hash | -49 dccp_set_state | -7 dccp_done | +1 5 functions changed, 1 bytes added, 242 bytes removed, diff: -241 /home/acme/git/net-2.6/net/dccp/ipv4.c: dccp_v4_get_port | -31 dccp_v4_request_recv_sock | -2 2 functions changed, 33 bytes removed, diff: -33 /home/acme/git/net-2.6/net/dccp/ipv6.c: dccp_v6_get_port | -31 dccp_v6_hash | -7 dccp_v6_request_recv_sock | +5 3 functions changed, 5 bytes added, 38 bytes removed, diff: -33 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include')
-rw-r--r--include/net/inet6_hashtables.h2
-rw-r--r--include/net/inet_connection_sock.h8
-rw-r--r--include/net/inet_hashtables.h51
-rw-r--r--include/net/sock.h3
4 files changed, 16 insertions, 48 deletions
diff --git a/include/net/inet6_hashtables.h b/include/net/inet6_hashtables.h
index fdff630708ce..62a5b691858e 100644
--- a/include/net/inet6_hashtables.h
+++ b/include/net/inet6_hashtables.h
@@ -49,7 +49,7 @@ static inline int inet6_sk_ehashfn(const struct sock *sk)
49 return inet6_ehashfn(laddr, lport, faddr, fport); 49 return inet6_ehashfn(laddr, lport, faddr, fport);
50} 50}
51 51
52extern void __inet6_hash(struct inet_hashinfo *hashinfo, struct sock *sk); 52extern void __inet6_hash(struct sock *sk);
53 53
54/* 54/*
55 * Sockets in TCP_CLOSE state are _always_ taken out of the hash, so 55 * Sockets in TCP_CLOSE state are _always_ taken out of the hash, so
diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
index 133cf30d2d79..f00f0573627b 100644
--- a/include/net/inet_connection_sock.h
+++ b/include/net/inet_connection_sock.h
@@ -29,7 +29,6 @@
29#undef INET_CSK_CLEAR_TIMERS 29#undef INET_CSK_CLEAR_TIMERS
30 30
31struct inet_bind_bucket; 31struct inet_bind_bucket;
32struct inet_hashinfo;
33struct tcp_congestion_ops; 32struct tcp_congestion_ops;
34 33
35/* 34/*
@@ -59,6 +58,8 @@ struct inet_connection_sock_af_ops {
59 int level, int optname, 58 int level, int optname,
60 char __user *optval, int __user *optlen); 59 char __user *optval, int __user *optlen);
61 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *); 60 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
61 int (*bind_conflict)(const struct sock *sk,
62 const struct inet_bind_bucket *tb);
62}; 63};
63 64
64/** inet_connection_sock - INET connection oriented sock 65/** inet_connection_sock - INET connection oriented sock
@@ -244,10 +245,7 @@ extern struct request_sock *inet_csk_search_req(const struct sock *sk,
244 const __be32 laddr); 245 const __be32 laddr);
245extern int inet_csk_bind_conflict(const struct sock *sk, 246extern int inet_csk_bind_conflict(const struct sock *sk,
246 const struct inet_bind_bucket *tb); 247 const struct inet_bind_bucket *tb);
247extern int inet_csk_get_port(struct inet_hashinfo *hashinfo, 248extern int inet_csk_get_port(struct sock *sk, unsigned short snum);
248 struct sock *sk, unsigned short snum,
249 int (*bind_conflict)(const struct sock *sk,
250 const struct inet_bind_bucket *tb));
251 249
252extern struct dst_entry* inet_csk_route_req(struct sock *sk, 250extern struct dst_entry* inet_csk_route_req(struct sock *sk,
253 const struct request_sock *req); 251 const struct request_sock *req);
diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h
index c23c4ed30724..48ac620cb846 100644
--- a/include/net/inet_hashtables.h
+++ b/include/net/inet_hashtables.h
@@ -221,9 +221,9 @@ static inline int inet_sk_listen_hashfn(const struct sock *sk)
221} 221}
222 222
223/* Caller must disable local BH processing. */ 223/* Caller must disable local BH processing. */
224static inline void __inet_inherit_port(struct inet_hashinfo *table, 224static inline void __inet_inherit_port(struct sock *sk, struct sock *child)
225 struct sock *sk, struct sock *child)
226{ 225{
226 struct inet_hashinfo *table = sk->sk_prot->hashinfo;
227 const int bhash = inet_bhashfn(inet_sk(child)->num, table->bhash_size); 227 const int bhash = inet_bhashfn(inet_sk(child)->num, table->bhash_size);
228 struct inet_bind_hashbucket *head = &table->bhash[bhash]; 228 struct inet_bind_hashbucket *head = &table->bhash[bhash];
229 struct inet_bind_bucket *tb; 229 struct inet_bind_bucket *tb;
@@ -235,15 +235,14 @@ static inline void __inet_inherit_port(struct inet_hashinfo *table,
235 spin_unlock(&head->lock); 235 spin_unlock(&head->lock);
236} 236}
237 237
238static inline void inet_inherit_port(struct inet_hashinfo *table, 238static inline void inet_inherit_port(struct sock *sk, struct sock *child)
239 struct sock *sk, struct sock *child)
240{ 239{
241 local_bh_disable(); 240 local_bh_disable();
242 __inet_inherit_port(table, sk, child); 241 __inet_inherit_port(sk, child);
243 local_bh_enable(); 242 local_bh_enable();
244} 243}
245 244
246extern void inet_put_port(struct inet_hashinfo *table, struct sock *sk); 245extern void inet_put_port(struct sock *sk);
247 246
248extern void inet_listen_wlock(struct inet_hashinfo *hashinfo); 247extern void inet_listen_wlock(struct inet_hashinfo *hashinfo);
249 248
@@ -266,41 +265,9 @@ static inline void inet_listen_unlock(struct inet_hashinfo *hashinfo)
266 wake_up(&hashinfo->lhash_wait); 265 wake_up(&hashinfo->lhash_wait);
267} 266}
268 267
269extern void __inet_hash(struct inet_hashinfo *hashinfo, struct sock *sk); 268extern void __inet_hash_nolisten(struct sock *sk);
270extern void __inet_hash_nolisten(struct inet_hashinfo *hinfo, struct sock *sk); 269extern void inet_hash(struct sock *sk);
271 270extern void inet_unhash(struct sock *sk);
272static inline void inet_hash(struct inet_hashinfo *hashinfo, struct sock *sk)
273{
274 if (sk->sk_state != TCP_CLOSE) {
275 local_bh_disable();
276 __inet_hash(hashinfo, sk);
277 local_bh_enable();
278 }
279}
280
281static inline void inet_unhash(struct inet_hashinfo *hashinfo, struct sock *sk)
282{
283 rwlock_t *lock;
284
285 if (sk_unhashed(sk))
286 goto out;
287
288 if (sk->sk_state == TCP_LISTEN) {
289 local_bh_disable();
290 inet_listen_wlock(hashinfo);
291 lock = &hashinfo->lhash_lock;
292 } else {
293 lock = inet_ehash_lockp(hashinfo, sk->sk_hash);
294 write_lock_bh(lock);
295 }
296
297 if (__sk_del_node_init(sk))
298 sock_prot_inuse_add(sk->sk_prot, -1);
299 write_unlock_bh(lock);
300out:
301 if (sk->sk_state == TCP_LISTEN)
302 wake_up(&hashinfo->lhash_wait);
303}
304 271
305extern struct sock *__inet_lookup_listener(struct net *net, 272extern struct sock *__inet_lookup_listener(struct net *net,
306 struct inet_hashinfo *hashinfo, 273 struct inet_hashinfo *hashinfo,
@@ -425,7 +392,7 @@ extern int __inet_hash_connect(struct inet_timewait_death_row *death_row,
425 struct sock *sk, 392 struct sock *sk,
426 int (*check_established)(struct inet_timewait_death_row *, 393 int (*check_established)(struct inet_timewait_death_row *,
427 struct sock *, __u16, struct inet_timewait_sock **), 394 struct sock *, __u16, struct inet_timewait_sock **),
428 void (*hash)(struct inet_hashinfo *, struct sock *)); 395 void (*hash)(struct sock *sk));
429extern int inet_hash_connect(struct inet_timewait_death_row *death_row, 396extern int inet_hash_connect(struct inet_timewait_death_row *death_row,
430 struct sock *sk); 397 struct sock *sk);
431#endif /* _INET_HASHTABLES_H */ 398#endif /* _INET_HASHTABLES_H */
diff --git a/include/net/sock.h b/include/net/sock.h
index e3fb4c047f4c..8a7889b35810 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -496,6 +496,7 @@ extern int sk_wait_data(struct sock *sk, long *timeo);
496 496
497struct request_sock_ops; 497struct request_sock_ops;
498struct timewait_sock_ops; 498struct timewait_sock_ops;
499struct inet_hashinfo;
499 500
500/* Networking protocol blocks we attach to sockets. 501/* Networking protocol blocks we attach to sockets.
501 * socket layer -> transport layer interface 502 * socket layer -> transport layer interface
@@ -578,6 +579,8 @@ struct proto {
578 struct request_sock_ops *rsk_prot; 579 struct request_sock_ops *rsk_prot;
579 struct timewait_sock_ops *twsk_prot; 580 struct timewait_sock_ops *twsk_prot;
580 581
582 struct inet_hashinfo *hashinfo;
583
581 struct module *owner; 584 struct module *owner;
582 585
583 char name[32]; 586 char name[32];