aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4
diff options
context:
space:
mode:
authorNeal Cardwell <ncardwell@google.com>2012-04-19 05:55:21 -0400
committerDavid S. Miller <davem@davemloft.net>2012-04-21 16:36:42 -0400
commit900f65d361d333c949ef76a828343075f4fdf523 (patch)
tree8b4474c6c9df1fcad4d946c64bcc1535450d0927 /net/ipv4
parente66e9a31474dcce5be6f1186dc933d8a991c707b (diff)
tcp: move duplicate code from tcp_v4_init_sock()/tcp_v6_init_sock()
This commit moves the (substantial) common code shared between tcp_v4_init_sock() and tcp_v6_init_sock() to a new address-family independent function, tcp_init_sock(). Centralizing this functionality should help avoid drift issues, e.g. where the IPv4 side is updated without a corresponding update to IPv6. There was already some drift: IPv4 initialized snd_cwnd to TCP_INIT_CWND, while the IPv6 side was still initializing snd_cwnd to 2 (in this case it should not matter, since snd_cwnd is also initialized in tcp_init_metrics(), but the general risks and maintenance overhead remain). When diffing the old and new code, note that new tcp_init_sock() function uses the order of steps from the tcp_v4_init_sock() implementation (the order is slightly different in tcp_v6_init_sock()). Signed-off-by: Neal Cardwell <ncardwell@google.com> Acked-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r--net/ipv4/tcp.c64
-rw-r--r--net/ipv4/tcp_ipv4.c52
2 files changed, 66 insertions, 50 deletions
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 3ce3bd031f3..bcc4eab5f25 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -363,6 +363,70 @@ static int retrans_to_secs(u8 retrans, int timeout, int rto_max)
363 return period; 363 return period;
364} 364}
365 365
366/* Address-family independent initialization for a tcp_sock.
367 *
368 * NOTE: A lot of things set to zero explicitly by call to
369 * sk_alloc() so need not be done here.
370 */
371void tcp_init_sock(struct sock *sk)
372{
373 struct inet_connection_sock *icsk = inet_csk(sk);
374 struct tcp_sock *tp = tcp_sk(sk);
375
376 skb_queue_head_init(&tp->out_of_order_queue);
377 tcp_init_xmit_timers(sk);
378 tcp_prequeue_init(tp);
379
380 icsk->icsk_rto = TCP_TIMEOUT_INIT;
381 tp->mdev = TCP_TIMEOUT_INIT;
382
383 /* So many TCP implementations out there (incorrectly) count the
384 * initial SYN frame in their delayed-ACK and congestion control
385 * algorithms that we must have the following bandaid to talk
386 * efficiently to them. -DaveM
387 */
388 tp->snd_cwnd = TCP_INIT_CWND;
389
390 /* See draft-stevens-tcpca-spec-01 for discussion of the
391 * initialization of these values.
392 */
393 tp->snd_ssthresh = TCP_INFINITE_SSTHRESH;
394 tp->snd_cwnd_clamp = ~0;
395 tp->mss_cache = TCP_MSS_DEFAULT;
396
397 tp->reordering = sysctl_tcp_reordering;
398 icsk->icsk_ca_ops = &tcp_init_congestion_ops;
399
400 sk->sk_state = TCP_CLOSE;
401
402 sk->sk_write_space = sk_stream_write_space;
403 sock_set_flag(sk, SOCK_USE_WRITE_QUEUE);
404
405 icsk->icsk_sync_mss = tcp_sync_mss;
406
407 /* TCP Cookie Transactions */
408 if (sysctl_tcp_cookie_size > 0) {
409 /* Default, cookies without s_data_payload. */
410 tp->cookie_values =
411 kzalloc(sizeof(*tp->cookie_values),
412 sk->sk_allocation);
413 if (tp->cookie_values != NULL)
414 kref_init(&tp->cookie_values->kref);
415 }
416 /* Presumed zeroed, in order of appearance:
417 * cookie_in_always, cookie_out_never,
418 * s_data_constant, s_data_in, s_data_out
419 */
420 sk->sk_sndbuf = sysctl_tcp_wmem[1];
421 sk->sk_rcvbuf = sysctl_tcp_rmem[1];
422
423 local_bh_disable();
424 sock_update_memcg(sk);
425 sk_sockets_allocated_inc(sk);
426 local_bh_enable();
427}
428EXPORT_SYMBOL(tcp_init_sock);
429
366/* 430/*
367 * Wait for a TCP event. 431 * Wait for a TCP event.
368 * 432 *
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index ba6dad81908..5b07ea10930 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1890,62 +1890,14 @@ static int tcp_v4_init_sock(struct sock *sk)
1890 struct inet_connection_sock *icsk = inet_csk(sk); 1890 struct inet_connection_sock *icsk = inet_csk(sk);
1891 struct tcp_sock *tp = tcp_sk(sk); 1891 struct tcp_sock *tp = tcp_sk(sk);
1892 1892
1893 skb_queue_head_init(&tp->out_of_order_queue); 1893 tcp_init_sock(sk);
1894 tcp_init_xmit_timers(sk);
1895 tcp_prequeue_init(tp);
1896
1897 icsk->icsk_rto = TCP_TIMEOUT_INIT;
1898 tp->mdev = TCP_TIMEOUT_INIT;
1899
1900 /* So many TCP implementations out there (incorrectly) count the
1901 * initial SYN frame in their delayed-ACK and congestion control
1902 * algorithms that we must have the following bandaid to talk
1903 * efficiently to them. -DaveM
1904 */
1905 tp->snd_cwnd = TCP_INIT_CWND;
1906
1907 /* See draft-stevens-tcpca-spec-01 for discussion of the
1908 * initialization of these values.
1909 */
1910 tp->snd_ssthresh = TCP_INFINITE_SSTHRESH;
1911 tp->snd_cwnd_clamp = ~0;
1912 tp->mss_cache = TCP_MSS_DEFAULT;
1913
1914 tp->reordering = sysctl_tcp_reordering;
1915 icsk->icsk_ca_ops = &tcp_init_congestion_ops;
1916
1917 sk->sk_state = TCP_CLOSE;
1918
1919 sk->sk_write_space = sk_stream_write_space;
1920 sock_set_flag(sk, SOCK_USE_WRITE_QUEUE);
1921 1894
1922 icsk->icsk_af_ops = &ipv4_specific; 1895 icsk->icsk_af_ops = &ipv4_specific;
1923 icsk->icsk_sync_mss = tcp_sync_mss; 1896
1924#ifdef CONFIG_TCP_MD5SIG 1897#ifdef CONFIG_TCP_MD5SIG
1925 tp->af_specific = &tcp_sock_ipv4_specific; 1898 tp->af_specific = &tcp_sock_ipv4_specific;
1926#endif 1899#endif
1927 1900
1928 /* TCP Cookie Transactions */
1929 if (sysctl_tcp_cookie_size > 0) {
1930 /* Default, cookies without s_data_payload. */
1931 tp->cookie_values =
1932 kzalloc(sizeof(*tp->cookie_values),
1933 sk->sk_allocation);
1934 if (tp->cookie_values != NULL)
1935 kref_init(&tp->cookie_values->kref);
1936 }
1937 /* Presumed zeroed, in order of appearance:
1938 * cookie_in_always, cookie_out_never,
1939 * s_data_constant, s_data_in, s_data_out
1940 */
1941 sk->sk_sndbuf = sysctl_tcp_wmem[1];
1942 sk->sk_rcvbuf = sysctl_tcp_rmem[1];
1943
1944 local_bh_disable();
1945 sock_update_memcg(sk);
1946 sk_sockets_allocated_inc(sk);
1947 local_bh_enable();
1948
1949 return 0; 1901 return 0;
1950} 1902}
1951 1903