tcp(7) Miscellaneous Information Manual tcp(7) tcp - TCP #include #include #include tcp_socket = socket(AF_INET, SOCK_STREAM, 0); TCP, RFC 793, RFC 1122 RFC 2001 NewReno SACK. ip(7) v4 v6. TCP . . TCP . TCP . TCP TCP connect(2). bind(2), listen(2) . accept(2). , accept(2) connect(2), . . Linux TCP RFC 1323. : (PAWS), . (> 64 ) TCP . . /proc/sys/net/ipv4/tcp_wmem /proc/sys/net/ipv4/tcp_rmem, , SO_SNDBUF SO_RCVBUF setsockopt(2). , SO_SNDBUF SO_RCVBUF /proc/sys/net/core/rmem_max /proc/sys/net/core/wmem_max. , TCP , , setsockopt(2), getsockopt(2) , setsockopt(2). TCP , /proc , TCP. listen(2) connect(2). socket(7). TCP . , , . MSG_OOB send(2). SIGURG , <<>> ioctl- SIOCSPGRP FIOSETOWN ( POSIX.1 F_SETOWN fcntl(2)). SO_OOBINLINE, ( ioctl- SIOCATMARK, ), , recv(2) recvmsg(2) MSG_OOB. select(2) , poll (2) POLLPRI. Linux 2.4 , : <<>> (zero-copy) sendfile(2), , TIME_WAIT, Duplicate SACK. TCP IP ( ip(7)). , ip(7), TCP. TCP - (point-to-point); . /proc TCP /proc/sys/net/ipv4/. , /proc IP TCP ( ip(7)). , Boolean, , (<<, true>>) , , (<<, false>>) , . tcp_abc (Integer; : 0; Linux 2.6.15 Linux 3.8) Control the Appropriate Byte Count (ABC), defined in RFC 3465. ABC is a way of increasing the congestion window (cwnd) more slowly in response to partial acknowledgements. Possible values are: 0 increase cwnd once per acknowledgement (no ABC) 1 increase cwnd once per acknowledgement of full sized segment 2 allow increase cwnd by two if acknowledgement is of two segments to compensate for delayed acknowledgements. tcp_abort_on_overflow (Boolean; : ; Linux 2.4) (resetting) , . , - (burst), . , , . . tcp_adv_win_scale (integer; : 2; Linux 2.4) Count buffering overhead as bytes/2^tcp_adv_win_scale, if tcp_adv_win_scale is greater than 0; or bytes-bytes/2^(-tcp_adv_win_scale), if tcp_adv_win_scale is less than or equal to zero. . TCP TCP, . << >>, . tcp_adv_win_scale -- 2 -- , . tcp_allowed_congestion_control (String; : ; Linux 2.4.20) / ( TCP_CONGESTION). . tcp_available_congestion_control. <> tcp_congestion_control. tcp_autocorking (Boolean; : ; Linux 3.14) , ( write(2) sendmsg(2)), . (coalescing) , , , Qdisc . - TCP_CORK , / (uncork) . tcp_available_congestion_control (String; ; Linux 2.4.20) . . tcp_allowed_congestion_control. , . tcp_app_win (integer; : 31; Linux 2.4) , TCP (overhead). A maximum of (window/2^tcp_app_win, mss) bytes in the window are reserved for the application buffer. A value of 0 implies that no amount is reserved. tcp_base_mss (Integer; : 512; Linux 2.6.17) search_low, Path MTU ( MTU). (probing) MTU , MSS. tcp_bic (Boolean; default: disabled; Linux 2.4.27/2.6.6 to Linux 2.6.13) BIC TCP. BIC-TCP , RTT TCP. , (additive increase) (binary search increase). , RTT, . , TCP. tcp_bic_low_window (integer; default: 14; Linux 2.4.27/2.6.6 to Linux 2.6.13) ( ) BIC TCP . BIC TCP -- TCP Reno. tcp_bic_fast_convergence (Boolean; default: enabled; Linux 2.4.27/2.6.6 to Linux 2.6.13) BIC TCP . . tcp_congestion_control (String; : ; Linux 2.4.13) . <> , . . tcp_dma_copybreak (integer; : 4096; Linux 2.6.24) ( ) , DMA, CONFIG_NET_DMA. tcp_dsack (Boolean; : ; Linux 2.4) RFC 2883 TCP Duplicate SACK. tcp_fastopen (Bitmask; default: 0x1; since Linux 3.7) Enables RFC 7413 Fast Open support. The flag is used as a bitmap with the following values: 0x1 Enables client side Fast Open support 0x2 Enables server side Fast Open support 0x4 Allows client side to transmit data in SYN without Fast Open option 0x200 Allows server side to accept SYN data without Fast Open option 0x400 Enables Fast Open on all listeners without TCP_FASTOPEN socket option tcp_fastopen_key (since Linux 3.7) Set server side RFC 7413 Fast Open key to generate Fast Open cookie when server side Fast Open support is enabled. tcp_ecn (Integer; : ; Linux 2.4) RFC 3168 -- (Explicit Congestion Notification). : 0 ECN. ECN. Linux 2.6.30 . 1 ECN , ECN . 2 ECN , ECN . Linux 2.6.31. - , (dropped) . 1 tcp_ecn_fallback. tcp_ecn_fallback (Boolean; : ; Linux 4.1) RFC 3168, Section 6.1.1.1. ECN SYN, SYN, CWR ECE. tcp_fack (Boolean; : ; Linux 2.2) TCP Forward Acknowledgement ( ). tcp_fin_timeout (integer; : 60; Linux 2.2) , FIN . , TCP, (DoS). 2.2 180. tcp_frto (integer; : ; Linux 2.4.21/2.6) F-RTO -- TCP (RTO). , , - , - . RFC 4138. : 0 . Linux 2.6.23 . 1 F-RTO. 2 SACK F-RTO, SACK. SACK, , , F-RTO TCP SACK. Linux 2.6.24. Linux 2.6.22 Boolean, 0 1. tcp_frto_response (integer; : 0; Linux 2.6.22) F-RTO , TCP (.., , TCP ), TCP , . : 0 (rate) ; , (cwnd) (ssthresh) RTT. 1 ; , , Linux TCP; cwnd ssthresh . 2 ; , ( , TCP ); cwnd ssthresh . tcp_keepalive_intvl (integer; : 75; Linux 2.4) <<>> (keep-alive) . tcp_keepalive_probes (integer; : 9; Linux 2.2) <<>> (keep-alive) TCP , . tcp_keepalive_time (integer; : 7200; Linux 2.2) <<>> . , SO_KEEPALIVE. 7200 (2 ). 11 (9 , 75 ) keep-alive. , . tcp_low_latency (Boolean; default: disabled; since Linux 2.4.21/2.6; obsolete since Linux 4.14) If enabled, the TCP stack makes decisions that prefer lower latency as opposed to higher throughput. It this option is disabled, then higher throughput is preferred. An example of an application where this default should be changed would be a Beowulf compute cluster. Since Linux 4.14, this file still exists, but its value is ignored. tcp_max_orphans (integer; : ; Linux 2.4) The maximum number of orphaned (not attached to any user file handle) TCP sockets allowed in the system. When this number is exceeded, the orphaned connection is reset and a warning is printed. This limit exists only to prevent simple denial-of-service attacks. Lowering this limit is not recommended. Network conditions might require you to increase the number of orphans allowed, but note that each orphan can eat up to ~64 kB of unswappable memory. The default initial value is set equal to the kernel parameter NR_FILE. This initial default is adjusted depending on the memory in the system. tcp_max_syn_backlog (integer; : ; Linux 2.2) , . , . (256) 1024, (>= 128 ) 128, (<= 32 ). Before Linux 2.6.20, it was recommended that if this needed to be increased above 1024, the size of the SYNACK hash table (TCP_SYNQ_HSIZE) in include/net/tcp.h should be modified to keep TCP_SYNQ_HSIZE * 16 <= tcp_max_syn_backlog . Linux 2.6.20 TCP_SYNQ_HSIZE . tcp_max_tw_buckets (integer; : ; Linux 2.4) TIME_WAIT, . DoS. NR_FILE*2 . , . tcp_moderate_rcvbuf (Boolean; : ; Linux 2.4.17/2.6.7) , TCP ; ( tcp_rmem[2]) , , . tcp_mem ( Linux 2.4) 3 : [low, pressure, high]. , , TCP . , ( TCP (low memory), 32- 900- . 64- ). low TCP , , , . pressure , TCP, , TCP . low. high () , TCP. , . tcp_mtu_probing (integer; : 0; Linux 2.6.17) TCP Packetization-Layer Path MTU Discovery. : 0 1 (black hole) ICMP 2 , MSS tcp_base_mss. tcp_no_metrics_save (Boolean; : ; Linux 2.6.6) , TCP , , , . , , . tcp_no_metrics_save , TCP . tcp_orphan_retries (integer; : 8; Linux 2.4) . tcp_reordering (integer; : 3; Linux 2.4) , TCP, TCP (slow start). . , . tcp_retrans_collapse (Boolean; : ; Linux 2.2) . tcp_retries1 (integer; : 3; Linux 2.2) . , ( ). RFC : 3. tcp_retries2 (integer; : 15; Linux 2.2) TCP , . 15, 13 30 , . RFC 1122 100 , . tcp_rfc1337 (Boolean; : ; Linux 2.2) TCP, RFC 1337. , : TIME_WAIT RST, , TIME_WAIT. tcp_rmem ( Linux 2.4) 3 : [min, default, max]. TCP . TCP , , . min , TCP. ( Linux 2.4 4 PAGE_SIZE ). , (pressure) . , SO_RCVBUF. default TCP. , net.core.rmem_default, . 87380 ( Linux 2.4 43689 ). , ( ). TCP net.ipv4.tcp_window_scaling ( ). max , TCP. net.core.rmem_max. , SO_RCVBUF. max(87380, min(4 MB, tcp_mem[1]*PAGE_SIZE/128)) ( Linux 2.4 87380*2 , 87380 ). tcp_sack (Boolean; : ; Linux 2.2) TCP (TCP Selective Acknowledgements), RFC 2018. tcp_slow_start_after_idle (Boolean; : ; Linux 2.6.18) , RFC 2861 . RTO ( ). , . tcp_stdurg (Boolean; : ; Linux 2.2) , TCP RFC 1122. . , , BSD: . . tcp_syn_retries (integer; default: 6; since Linux 2.2) The maximum number of times initial SYNs for an active TCP connection attempt will be retransmitted. This value should not be higher than 255. The default value is 6, which corresponds to retrying for up to approximately 127 seconds. Before Linux 3.7, the default value was 5, which (in conjunction with calculation based on other kernel parameters) corresponded to approximately 180 seconds. tcp_synack_retries (integer; : 5; Linux 2.2) SYN/ACK TCP. 255. tcp_syncookies (integer; default: 1; since Linux 2.2) Enable TCP syncookies. The kernel must be compiled with CONFIG_SYN_COOKIES. The syncookies feature attempts to protect a socket from a SYN flood attack. This should be used as a last resort, if at all. This is a violation of the TCP protocol, and conflicts with other areas of TCP such as TCP extensions. It can cause problems for clients and relays. It is not recommended as a tuning mechanism for heavily loaded servers to help with overloaded or misconfigured conditions. For recommended alternatives see tcp_max_syn_backlog, tcp_synack_retries, and tcp_abort_on_overflow. Set to one of the following values: 0 Disable TCP syncookies. 1 Send out syncookies when the syn backlog queue of a socket overflows. 2 (since Linux 3.12) Send out syncookies unconditionally. This can be useful for network testing. tcp_timestamps (integer; : 1; Linux 2.2) RFC 1323 TCP: 0 . 1 , RFC1323, , . 2 1, . tcp_timestamps Linux 4.10. tcp_tso_win_divisor (integer; : 3; Linux 2.6.9) , TCP Segmentation Offload (TSO). -- (burstiness) TSO. tcp_tw_recycle (Boolean; default: disabled; Linux 2.4 to Linux 4.11) TIME_WAIT. , IP ( NAT, ). RFC 1323 (PAWS) RFC 6191. tcp_tw_reuse (Boolean; : ; Linux 2.4.19/2.6) TIME_WAIT , . / . tcp_vegas_cong_avoid (Boolean; default: disabled; Linux 2.2 to Linux 2.6.13) TCP Vegas. TCP Vegas ; , . TCP Vegas , . TCP Vegas , TCP Reno. tcp_westwood (Boolean; default: disabled; Linux 2.4.26/2.6.3 to Linux 2.6.13) TCP Westwood+. TCP Westwood+ TCP Reno, TCP. . TCP Westwood+ , , . TCP Westwood+ (fairness), TCP Reno, . tcp_window_scaling (Boolean; : ; Linux 2.2) TCP, RFC 1323 (> 64 ) TCP, . , 16- TCP 64 . , . tcp_window_scaling , TCP . tcp_wmem ( Linux 2.4) 3 : [min, default, max]. TCP . TCP , , . min , TCP ( Linux 2.4 4 ). , (pressure) . , SO_SNDBUF. default TCP , /proc/sys/net/core/wmem_default, . 16 . , ( ). TCP /proc/sys/net/ipv4/tcp_window_scaling ( ). max , TCP. /proc/sys/net/core/wmem_max. , SO_SNDBUF. max(65536, min(4 MB, tcp_mem[1]*PAGE_SIZE/128)) ( Linux 2.4 128 , 64 ). tcp_workaround_signed_windows (Boolean; : ; Linux 2.6.26) , , , TCP . , , TCP , . TCP getsockopt(2) setsockopt(2), . IPPROTO_TCP. , optval -- int. , TCP IPPROTO_IP. ip(7). TCP. , TCP, socket(7). TCP_CONGESTION ( Linux 2.6.13) . TCP, . tcp_allowed_congestion_control ( ). (CAP_NET_ADMIN) ( tcp_available_congestion_control ). TCP_CORK ( Linux 2.2) , . , . sendfile(2) . (ceiling) 200 , (corked) - TCP_CORK. , . TCP_NODELAY Linux 2.5.71. , . TCP_DEFER_ACCEPT ( Linux 2.4) . (), TCP . , . TCP_INFO ( Linux 2.4) . struct tcp_info, /usr/include/linux/tcp.h. , . TCP_KEEPCNT ( Linux 2.4) (keepalive probes) TCP, . , . TCP_KEEPIDLE ( Linux 2.4) ( ) (idle) , TCP (keepalive probes), SO_KEEPALIVE. , . TCP_KEEPINTVL ( Linux 2.4) (keepalive probes). , . TCP_LINGER2 ( Linux 2.4) (orphaned) FIN_WAIT2. /proc/sys/net/ipv4/tcp_fin_timeout . SO_LINGER socket(7). , . TCP_MAXSEG TCP. Linux 2.2 , Linux 2.6.28 , , MSS, . , MTU , . TCP . TCP_NODELAY , Nagle. , , . , , . TCP_CORK; , , TCP_CORK. TCP_QUICKACK ( Linux 2.4.4) quickack . , TCP. , quickack. TCP / , . , . TCP_SYNCNT ( Linux 2.4) SYN, TCP . 255. , . TCP_USER_TIMEOUT ( Linux 2.6.37) This option takes an unsigned int as an argument. When the value is greater than 0, it specifies the maximum amount of time in milliseconds that transmitted data may remain unacknowledged, or buffered data may remain untransmitted (due to zero window size) before TCP will forcibly close the corresponding connection and return ETIMEDOUT to the application. If the option value is specified as 0, TCP will use the system default. TCP . << >>, . 20 WAN. TCP, (ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING LAST-ACK). , TCP (SO_KEEPALIVE), TCP_USER_TIMEOUT - . , TCP , . , , , accept(2), . RFC 793 RFC 5482 (<>). TCP_WINDOW_CLAMP ( Linux 2.4) . SOCK_MIN_RCVBUF/2. , . TCP_FASTOPEN (since Linux 3.6) This option enables Fast Open (RFC 7413) on the listener socket. The value specifies the maximum length of pending SYNs (similar to the backlog argument in listen(2)). Once enabled, the listener socket grants the TCP Fast Open cookie on incoming SYN with TCP Fast Open option. More importantly it accepts the data in SYN with a valid Fast Open cookie and responds SYN-ACK acknowledging both the data and the SYN sequence. accept(2) returns a socket that is available for read and write when the handshake has not completed yet. Thus the data exchange can commence before the handshake completes. This option requires enabling the server-side support on sysctl net.ipv4.tcp_fastopen (see above). For TCP Fast Open client-side support, see send(2) MSG_FASTOPEN or TCP_FASTOPEN_CONNECT below. TCP_FASTOPEN_CONNECT (since Linux 4.11) This option enables an alternative way to perform Fast Open on the active side (client). When this option is enabled, connect(2) would behave differently depending on if a Fast Open cookie is available for the destination. If a cookie is not available (i.e. first contact to the destination), connect(2) behaves as usual by sending a SYN immediately, except the SYN would include an empty Fast Open cookie option to solicit a cookie. If a cookie is available, connect(2) would return 0 immediately but the SYN transmission is deferred. A subsequent write(2) or sendmsg(2) would trigger a SYN with data plus cookie in the Fast Open option. In other words, the actual connect operation is deferred until data is supplied. Note: While this option is designed for convenience, enabling it does change the behaviors and certain system calls might set different errno values. With cookie present, write(2) or sendmsg(2) must be called right after connect(2) in order to send out SYN+data to complete 3WHS and establish connection. Calling read(2) right after connect(2) without write(2) will cause the blocking socket to be blocked forever. The application should either set TCP_FASTOPEN_CONNECT socket option before write(2) or sendmsg(2), or call write(2) or sendmsg(2) with MSG_FASTOPEN flag directly, instead of both on the same connection. Here is the typical call flow with this new option: s = socket(); setsockopt(s, IPPROTO_TCP, TCP_FASTOPEN_CONNECT, 1, ...); connect(s); write(s); /* write() should always follow connect() * in order to trigger SYN to go out. */ read(s)/write(s); /* ... */ close(s); TCP ( ) . Linux , , ( SO_OOBINLINE ). BSD. Linux BSD . RFC 1122, . /proc/sys/net/ipv4/tcp_stdurg. recv(2) MSG_PEEK. Since Linux 2.4, Linux supports the use of MSG_TRUNC in the flags argument of recv(2) (and recvmsg(2)). This flag causes the received bytes of data to be discarded, rather than passed back in a caller-supplied buffer. Since Linux 2.4.4, MSG_TRUNC also has this effect when used in conjunction with MSG_OOB to receive out-of-band data. ioctl ioctl(2) value. : int value; error = ioctl(tcp_socket, ioctl_type, &value); ioctl_type : SIOCINQ . LISTEN, (EINVAL). SIOCINQ . FIONREAD, . SIOCATMARK (.., value ), . SO_OOBINLINE SIOCATMARK , . SO_OOBINLINE SIOCATMARK , , ( recv(MSG_OOB)). , . select(2) ( exceptfds) SIGURG, , SIOCATMARK, ( ) SIOCATMARK . SIOCOUTQ . LISTEN, (EINVAL). SIOCOUTQ . TIOCOUTQ, . TCP . , ETIMEDOUT, , . Some applications require a quicker error notification. This can be enabled with the IPPROTO_IP level IP_RECVERR socket option. When this option is enabled, all incoming errors are immediately passed to the user program. Use this option with care -- it makes TCP less tolerant to routing changes and other normal network conditions. EAFNOTSUPPORT sin_family AF_INET. EPIPE , . ETIMEDOUT . , ip(7) , TCP. Support for Explicit Congestion Notification, zero-copy sendfile(2), reordering support and some SACK extensions (DSACK) were introduced in Linux 2.4. Support for forward acknowledgement (FACK), TIME_WAIT recycling, and per-connection keepalive socket options were introduced in Linux 2.3. . IPv6 . accept(2), bind(2), connect(2), getsockopt(2), listen(2), recvmsg(2), sendfile(2), sendmsg(2), socket(2), ip(7), socket(7) The kernel source file Documentation/networking/ip-sysctl.txt. RFC 793 TCP. RFC 1122 TCP (Nagle). RFC 1323 TCP . RFC 1337 TIME_WAIT. RFC 3168 (Explicit Congestion Notification). RFC 2581 TCP. RFC 2018 RFC 2883 SACK SACK. Azamat Hackimov , Dmitry Bolkhovskikh , Yuri Kozlov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , <>. Linux man-pages 6.8 2 2024 . tcp(7)