aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@ghostprotocols.net>2005-08-09 23:09:59 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2005-08-29 18:42:26 -0400
commitc676270bcd25015b978722ec0352c330dcc87883 (patch)
tree098cc52c71d68465e7ee5fbae462d58126b68885
parente48c414ee61f4ac8d5cff2973e66a7cbc8a93aa5 (diff)
[INET_TWSK]: Introduce inet_twsk_alloc
With the parts of tcp_time_wait that are not TCP specific, tcp_time_wait uses it and so will dccp_time_wait. Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/inet_timewait_sock.h3
-rw-r--r--net/ipv4/inet_timewait_sock.c28
-rw-r--r--net/ipv4/tcp_minisocks.c24
3 files changed, 33 insertions, 22 deletions
diff --git a/include/net/inet_timewait_sock.h b/include/net/inet_timewait_sock.h
index 020f28058fd4..e00861b16696 100644
--- a/include/net/inet_timewait_sock.h
+++ b/include/net/inet_timewait_sock.h
@@ -142,6 +142,9 @@ static inline void inet_twsk_put(struct inet_timewait_sock *tw)
142 } 142 }
143} 143}
144 144
145extern struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk,
146 const int state);
147
145extern void __inet_twsk_kill(struct inet_timewait_sock *tw, 148extern void __inet_twsk_kill(struct inet_timewait_sock *tw,
146 struct inet_hashinfo *hashinfo); 149 struct inet_hashinfo *hashinfo);
147 150
diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c
index d38d160faeb7..ceb577c74237 100644
--- a/net/ipv4/inet_timewait_sock.c
+++ b/net/ipv4/inet_timewait_sock.c
@@ -81,3 +81,31 @@ void __inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk,
81 81
82 write_unlock(&ehead->lock); 82 write_unlock(&ehead->lock);
83} 83}
84
85struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk, const int state)
86{
87 struct inet_timewait_sock *tw = kmem_cache_alloc(sk->sk_prot_creator->twsk_slab,
88 SLAB_ATOMIC);
89 if (tw != NULL) {
90 const struct inet_sock *inet = inet_sk(sk);
91
92 /* Give us an identity. */
93 tw->tw_daddr = inet->daddr;
94 tw->tw_rcv_saddr = inet->rcv_saddr;
95 tw->tw_bound_dev_if = sk->sk_bound_dev_if;
96 tw->tw_num = inet->num;
97 tw->tw_state = TCP_TIME_WAIT;
98 tw->tw_substate = state;
99 tw->tw_sport = inet->sport;
100 tw->tw_dport = inet->dport;
101 tw->tw_family = sk->sk_family;
102 tw->tw_reuse = sk->sk_reuse;
103 tw->tw_hashent = sk->sk_hashent;
104 tw->tw_ipv6only = 0;
105 tw->tw_prot = sk->sk_prot_creator;
106 atomic_set(&tw->tw_refcnt, 1);
107 inet_twsk_dead_node_init(tw);
108 }
109
110 return tw;
111}
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 4112f7a6d108..66ce1790a94f 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -267,37 +267,18 @@ void tcp_time_wait(struct sock *sk, int state, int timeo)
267 recycle_ok = tp->af_specific->remember_stamp(sk); 267 recycle_ok = tp->af_specific->remember_stamp(sk);
268 268
269 if (tcp_tw_count < sysctl_tcp_max_tw_buckets) 269 if (tcp_tw_count < sysctl_tcp_max_tw_buckets)
270 tw = kmem_cache_alloc(sk->sk_prot_creator->twsk_slab, SLAB_ATOMIC); 270 tw = inet_twsk_alloc(sk, state);
271 271
272 if (tw != NULL) { 272 if (tw != NULL) {
273 struct tcp_timewait_sock *tcptw = tcp_twsk((struct sock *)tw); 273 struct tcp_timewait_sock *tcptw = tcp_twsk((struct sock *)tw);
274 const struct inet_sock *inet = inet_sk(sk);
275 const int rto = (tp->rto << 2) - (tp->rto >> 1); 274 const int rto = (tp->rto << 2) - (tp->rto >> 1);
276 275
277 /* Remember our protocol */
278 tw->tw_prot = sk->sk_prot_creator;
279
280 /* Give us an identity. */
281 tw->tw_daddr = inet->daddr;
282 tw->tw_rcv_saddr = inet->rcv_saddr;
283 tw->tw_bound_dev_if = sk->sk_bound_dev_if;
284 tw->tw_num = inet->num;
285 tw->tw_state = TCP_TIME_WAIT;
286 tw->tw_substate = state;
287 tw->tw_sport = inet->sport;
288 tw->tw_dport = inet->dport;
289 tw->tw_family = sk->sk_family;
290 tw->tw_reuse = sk->sk_reuse;
291 tw->tw_rcv_wscale = tp->rx_opt.rcv_wscale; 276 tw->tw_rcv_wscale = tp->rx_opt.rcv_wscale;
292 atomic_set(&tw->tw_refcnt, 1);
293
294 tw->tw_hashent = sk->sk_hashent;
295 tcptw->tw_rcv_nxt = tp->rcv_nxt; 277 tcptw->tw_rcv_nxt = tp->rcv_nxt;
296 tcptw->tw_snd_nxt = tp->snd_nxt; 278 tcptw->tw_snd_nxt = tp->snd_nxt;
297 tcptw->tw_rcv_wnd = tcp_receive_window(tp); 279 tcptw->tw_rcv_wnd = tcp_receive_window(tp);
298 tcptw->tw_ts_recent = tp->rx_opt.ts_recent; 280 tcptw->tw_ts_recent = tp->rx_opt.ts_recent;
299 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp; 281 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
300 inet_twsk_dead_node_init(tw);
301 282
302#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 283#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
303 if (tw->tw_family == PF_INET6) { 284 if (tw->tw_family == PF_INET6) {
@@ -307,8 +288,7 @@ void tcp_time_wait(struct sock *sk, int state, int timeo)
307 ipv6_addr_copy(&tcp6tw->tw_v6_daddr, &np->daddr); 288 ipv6_addr_copy(&tcp6tw->tw_v6_daddr, &np->daddr);
308 ipv6_addr_copy(&tcp6tw->tw_v6_rcv_saddr, &np->rcv_saddr); 289 ipv6_addr_copy(&tcp6tw->tw_v6_rcv_saddr, &np->rcv_saddr);
309 tw->tw_ipv6only = np->ipv6only; 290 tw->tw_ipv6only = np->ipv6only;
310 } else 291 }
311 tw->tw_ipv6only = 0;
312#endif 292#endif
313 /* Linkage updates. */ 293 /* Linkage updates. */
314 __inet_twsk_hashdance(tw, sk, &tcp_hashinfo); 294 __inet_twsk_hashdance(tw, sk, &tcp_hashinfo);