From 7e6750b3eab476397efd95316a7cf6b43ef9e274 Mon Sep 17 00:00:00 2001 From: Vlad Yasevich Date: Mon, 21 May 2007 10:15:05 -0400 Subject: [PATCH 2/4] [INET] Make struct inet_sock bind hash aware Move the icsk_bind_hash from the inet_connection_sock to struct inet_sock so that other sockets derived from inet_sock can use it. Signed-off-by: Vlad Yasevich --- include/net/inet_connection_sock.h | 1 - include/net/inet_hashtables.h | 4 ++-- include/net/inet_sock.h | 1 + include/net/tcp.h | 2 +- net/dccp/proto.c | 6 +++--- net/ipv4/inet_connection_sock.c | 7 +++---- net/ipv4/inet_hashtables.c | 8 ++++---- net/ipv4/inet_timewait_sock.c | 5 ++--- net/ipv4/tcp.c | 2 +- net/ipv4/tcp_ipv4.c | 2 +- net/ipv6/inet6_hashtables.c | 2 +- 11 files changed, 19 insertions(+), 21 deletions(-) diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h index 133cf30..f8a7d7c 100644 --- a/include/net/inet_connection_sock.h +++ b/include/net/inet_connection_sock.h @@ -85,7 +85,6 @@ struct inet_connection_sock { /* inet_sock has to be the first member! */ struct inet_sock icsk_inet; struct request_sock_queue icsk_accept_queue; - struct inet_bind_bucket *icsk_bind_hash; unsigned long icsk_timeout; struct timer_list icsk_retransmit_timer; struct timer_list icsk_delack_timer; diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h index d27ee8c..56fd7c8 100644 --- a/include/net/inet_hashtables.h +++ b/include/net/inet_hashtables.h @@ -170,9 +170,9 @@ static inline void __inet_inherit_port(struct inet_hashinfo *table, struct inet_bind_bucket *tb; spin_lock(&head->lock); - tb = inet_csk(sk)->icsk_bind_hash; + tb = inet_sk(sk)->sk_bind_hash; sk_add_bind_node(child, &tb->owners); - inet_csk(child)->icsk_bind_hash = tb; + inet_sk(child)->sk_bind_hash = tb; spin_unlock(&head->lock); } diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h index 62daf21..9b1dec5 100644 --- a/include/net/inet_sock.h +++ b/include/net/inet_sock.h @@ -110,6 +110,7 @@ struct inet_sock { #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) struct ipv6_pinfo *pinet6; #endif + struct inet_bind_bucket *sk_bind_hash; /* Socket demultiplex comparisons on incoming packets. */ __be32 daddr; __be32 rcv_saddr; diff --git a/include/net/tcp.h b/include/net/tcp.h index e22b4f0..d003c59 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -907,7 +907,7 @@ static inline void tcp_set_state(struct sock *sk, int state) TCP_INC_STATS(TCP_MIB_ESTABRESETS); sk->sk_prot->unhash(sk); - if (inet_csk(sk)->icsk_bind_hash && + if (inet_sk(sk)->sk_bind_hash && !(sk->sk_userlocks & SOCK_BINDPORT_LOCK)) inet_put_port(&tcp_hashinfo, sk); /* fall through */ diff --git a/net/dccp/proto.c b/net/dccp/proto.c index 6607b7b..2121ce4 100644 --- a/net/dccp/proto.c +++ b/net/dccp/proto.c @@ -75,7 +75,7 @@ void dccp_set_state(struct sock *sk, const int state) DCCP_INC_STATS(DCCP_MIB_ESTABRESETS); sk->sk_prot->unhash(sk); - if (inet_csk(sk)->icsk_bind_hash != NULL && + if (inet_sk(sk)->sk_bind_hash != NULL && !(sk->sk_userlocks & SOCK_BINDPORT_LOCK)) inet_put_port(&dccp_hashinfo, sk); /* fall through */ @@ -244,7 +244,7 @@ int dccp_destroy_sock(struct sock *sk) } /* Clean up a referenced DCCP bind bucket. */ - if (inet_csk(sk)->icsk_bind_hash != NULL) + if (inet_sk(sk)->sk_bind_hash != NULL) inet_put_port(&dccp_hashinfo, sk); kfree(dp->dccps_service_list); @@ -310,7 +310,7 @@ int dccp_disconnect(struct sock *sk, int flags) inet_csk_delack_init(sk); __sk_dst_reset(sk); - BUG_TRAP(!inet->num || icsk->icsk_bind_hash); + BUG_TRAP(!inet->num || inet->sk_bind_hash); sk->sk_error_report(sk); return err; diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index 43fb160..0e40c6d 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -146,9 +146,9 @@ tb_not_found: (!sk->sk_reuse || sk->sk_state == TCP_LISTEN)) tb->fastreuse = 0; success: - if (!inet_csk(sk)->icsk_bind_hash) + if (!inet_sk(sk)->sk_bind_hash) inet_bind_hash(sk, tb, snum); - BUG_TRAP(inet_csk(sk)->icsk_bind_hash == tb); + BUG_TRAP(inet_sk(sk)->sk_bind_hash == tb); ret = 0; fail_unlock: @@ -499,7 +499,6 @@ struct sock *inet_csk_clone(struct sock *sk, const struct request_sock *req, struct inet_connection_sock *newicsk = inet_csk(newsk); newsk->sk_state = TCP_SYN_RECV; - newicsk->icsk_bind_hash = NULL; inet_sk(newsk)->dport = inet_rsk(req)->rmt_port; newsk->sk_write_space = sk_stream_write_space; @@ -533,7 +532,7 @@ void inet_csk_destroy_sock(struct sock *sk) BUG_TRAP(sk_unhashed(sk)); /* If it has not 0 inet_sk(sk)->num, it must be bound */ - BUG_TRAP(!inet_sk(sk)->num || inet_csk(sk)->icsk_bind_hash); + BUG_TRAP(!inet_sk(sk)->num || inet_sk(sk)->sk_bind_hash); sk->sk_prot->destroy(sk); diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c index fb66262..ff250de 100644 --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c @@ -58,7 +58,7 @@ void inet_bind_hash(struct sock *sk, struct inet_bind_bucket *tb, { inet_sk(sk)->num = snum; sk_add_bind_node(sk, &tb->owners); - inet_csk(sk)->icsk_bind_hash = tb; + inet_sk(sk)->sk_bind_hash = tb; } /* @@ -71,9 +71,9 @@ static void __inet_put_port(struct inet_hashinfo *hashinfo, struct sock *sk) struct inet_bind_bucket *tb; spin_lock(&head->lock); - tb = inet_csk(sk)->icsk_bind_hash; + tb = inet_sk(sk)->sk_bind_hash; __sk_del_bind_node(sk); - inet_csk(sk)->icsk_bind_hash = NULL; + inet_sk(sk)->sk_bind_hash = NULL; inet_sk(sk)->num = 0; inet_bind_bucket_destroy(hashinfo->bind_bucket_cachep, tb); spin_unlock(&head->lock); @@ -348,7 +348,7 @@ ok: } head = &hinfo->bhash[inet_bhashfn(snum, hinfo->bhash_size)]; - tb = inet_csk(sk)->icsk_bind_hash; + tb = inet_sk(sk)->sk_bind_hash; spin_lock_bh(&head->lock); if (sk_head(&tb->owners) == sk && !sk->sk_bind_node.next) { __inet_hash(hinfo, sk, 0); diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c index a73cf93..3f8ce82 100644 --- a/net/ipv4/inet_timewait_sock.c +++ b/net/ipv4/inet_timewait_sock.c @@ -58,7 +58,6 @@ void __inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk, struct inet_hashinfo *hashinfo) { const struct inet_sock *inet = inet_sk(sk); - const struct inet_connection_sock *icsk = inet_csk(sk); struct inet_ehash_bucket *ehead = inet_ehash_bucket(hashinfo, sk->sk_hash); struct inet_bind_hashbucket *bhead; /* Step 1: Put TW into bind hash. Original socket stays there too. @@ -67,8 +66,8 @@ void __inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk, */ bhead = &hashinfo->bhash[inet_bhashfn(inet->num, hashinfo->bhash_size)]; spin_lock(&bhead->lock); - tw->tw_tb = icsk->icsk_bind_hash; - BUG_TRAP(icsk->icsk_bind_hash); + tw->tw_tb = inet->sk_bind_hash; + BUG_TRAP(inet->sk_bind_hash); inet_twsk_add_bind_node(tw, &tw->tw_tb->owners); spin_unlock(&bhead->lock); diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index bd4c295..6d312ea 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1762,7 +1762,7 @@ int tcp_disconnect(struct sock *sk, int flags) memset(&tp->rx_opt, 0, sizeof(tp->rx_opt)); __sk_dst_reset(sk); - BUG_TRAP(!inet->num || icsk->icsk_bind_hash); + BUG_TRAP(!inet->num || inet->sk_bind_hash); sk->sk_error_report(sk); return err; diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 5a3e7f8..5427823 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1914,7 +1914,7 @@ int tcp_v4_destroy_sock(struct sock *sk) __skb_queue_purge(&tp->ucopy.prequeue); /* Clean up a referenced TCP bind bucket. */ - if (inet_csk(sk)->icsk_bind_hash) + if (inet_sk(sk)->sk_bind_hash) inet_put_port(&tcp_hashinfo, sk); /* diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c index ae6b0e7..6933a1f 100644 --- a/net/ipv6/inet6_hashtables.c +++ b/net/ipv6/inet6_hashtables.c @@ -323,7 +323,7 @@ ok: } head = &hinfo->bhash[inet_bhashfn(snum, hinfo->bhash_size)]; - tb = inet_csk(sk)->icsk_bind_hash; + tb = inet_sk(sk)->sk_bind_hash; spin_lock_bh(&head->lock); if (sk_head(&tb->owners) == sk && sk->sk_bind_node.next == NULL) { -- 1.5.2.4