diff options
-rw-r--r-- | include/net/tcp.h | 1 | ||||
-rw-r--r-- | net/ipv4/tcp.c | 64 | ||||
-rw-r--r-- | net/ipv4/tcp_ipv4.c | 52 | ||||
-rw-r--r-- | net/ipv6/tcp_ipv6.c | 50 |
4 files changed, 68 insertions, 99 deletions
diff --git a/include/net/tcp.h b/include/net/tcp.h index b4ccb8a6c9c1..fc880e92164a 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h | |||
@@ -395,6 +395,7 @@ extern void tcp_enter_loss(struct sock *sk, int how); | |||
395 | extern void tcp_clear_retrans(struct tcp_sock *tp); | 395 | extern void tcp_clear_retrans(struct tcp_sock *tp); |
396 | extern void tcp_update_metrics(struct sock *sk); | 396 | extern void tcp_update_metrics(struct sock *sk); |
397 | extern void tcp_close(struct sock *sk, long timeout); | 397 | extern void tcp_close(struct sock *sk, long timeout); |
398 | extern void tcp_init_sock(struct sock *sk); | ||
398 | extern unsigned int tcp_poll(struct file * file, struct socket *sock, | 399 | extern unsigned int tcp_poll(struct file * file, struct socket *sock, |
399 | struct poll_table_struct *wait); | 400 | struct poll_table_struct *wait); |
400 | extern int tcp_getsockopt(struct sock *sk, int level, int optname, | 401 | extern int tcp_getsockopt(struct sock *sk, int level, int optname, |
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 3ce3bd031f33..bcc4eab5f251 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 | */ | ||
371 | void 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 | } | ||
428 | EXPORT_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 ba6dad81908e..5b07ea109300 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 | ||
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 050c55186bc4..24dac6b83fb9 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c | |||
@@ -1831,62 +1831,14 @@ static int tcp_v6_init_sock(struct sock *sk) | |||
1831 | struct inet_connection_sock *icsk = inet_csk(sk); | 1831 | struct inet_connection_sock *icsk = inet_csk(sk); |
1832 | struct tcp_sock *tp = tcp_sk(sk); | 1832 | struct tcp_sock *tp = tcp_sk(sk); |
1833 | 1833 | ||
1834 | skb_queue_head_init(&tp->out_of_order_queue); | 1834 | tcp_init_sock(sk); |
1835 | tcp_init_xmit_timers(sk); | ||
1836 | tcp_prequeue_init(tp); | ||
1837 | |||
1838 | icsk->icsk_rto = TCP_TIMEOUT_INIT; | ||
1839 | tp->mdev = TCP_TIMEOUT_INIT; | ||
1840 | |||
1841 | /* So many TCP implementations out there (incorrectly) count the | ||
1842 | * initial SYN frame in their delayed-ACK and congestion control | ||
1843 | * algorithms that we must have the following bandaid to talk | ||
1844 | * efficiently to them. -DaveM | ||
1845 | */ | ||
1846 | tp->snd_cwnd = 2; | ||
1847 | |||
1848 | /* See draft-stevens-tcpca-spec-01 for discussion of the | ||
1849 | * initialization of these values. | ||
1850 | */ | ||
1851 | tp->snd_ssthresh = TCP_INFINITE_SSTHRESH; | ||
1852 | tp->snd_cwnd_clamp = ~0; | ||
1853 | tp->mss_cache = TCP_MSS_DEFAULT; | ||
1854 | |||
1855 | tp->reordering = sysctl_tcp_reordering; | ||
1856 | |||
1857 | sk->sk_state = TCP_CLOSE; | ||
1858 | 1835 | ||
1859 | icsk->icsk_af_ops = &ipv6_specific; | 1836 | icsk->icsk_af_ops = &ipv6_specific; |
1860 | icsk->icsk_ca_ops = &tcp_init_congestion_ops; | ||
1861 | icsk->icsk_sync_mss = tcp_sync_mss; | ||
1862 | sk->sk_write_space = sk_stream_write_space; | ||
1863 | sock_set_flag(sk, SOCK_USE_WRITE_QUEUE); | ||
1864 | 1837 | ||
1865 | #ifdef CONFIG_TCP_MD5SIG | 1838 | #ifdef CONFIG_TCP_MD5SIG |
1866 | tp->af_specific = &tcp_sock_ipv6_specific; | 1839 | tp->af_specific = &tcp_sock_ipv6_specific; |
1867 | #endif | 1840 | #endif |
1868 | 1841 | ||
1869 | /* TCP Cookie Transactions */ | ||
1870 | if (sysctl_tcp_cookie_size > 0) { | ||
1871 | /* Default, cookies without s_data_payload. */ | ||
1872 | tp->cookie_values = | ||
1873 | kzalloc(sizeof(*tp->cookie_values), | ||
1874 | sk->sk_allocation); | ||
1875 | if (tp->cookie_values != NULL) | ||
1876 | kref_init(&tp->cookie_values->kref); | ||
1877 | } | ||
1878 | /* Presumed zeroed, in order of appearance: | ||
1879 | * cookie_in_always, cookie_out_never, | ||
1880 | * s_data_constant, s_data_in, s_data_out | ||
1881 | */ | ||
1882 | sk->sk_sndbuf = sysctl_tcp_wmem[1]; | ||
1883 | sk->sk_rcvbuf = sysctl_tcp_rmem[1]; | ||
1884 | |||
1885 | local_bh_disable(); | ||
1886 | sock_update_memcg(sk); | ||
1887 | sk_sockets_allocated_inc(sk); | ||
1888 | local_bh_enable(); | ||
1889 | |||
1890 | return 0; | 1842 | return 0; |
1891 | } | 1843 | } |
1892 | 1844 | ||