share/mk/: Fix includes
[man-pages.git] / man7 / tcp.7
blobc7b393c1059ca414c05942007118952abcb7fec2
1 .\" SPDX-License-Identifier: Linux-man-pages-1-para
2 .\"
3 .\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
4 .\" and Copyright (C) 2008 Michael Kerrisk <mtk.manpages@gmail.com>
5 .\" Note also that many pieces are drawn from the kernel source file
6 .\" Documentation/networking/ip-sysctl.txt.
7 .\"
8 .\" 2.4 Updates by Nivedita Singhvi 4/20/02 <nivedita@us.ibm.com>.
9 .\" Modified, 2004-11-11, Michael Kerrisk and Andries Brouwer
10 .\"     Updated details of interaction of TCP_CORK and TCP_NODELAY.
11 .\"
12 .\" 2008-11-21, mtk, many, many updates.
13 .\"     The descriptions of /proc files and socket options should now
14 .\"     be more or less up to date and complete as at Linux 2.6.27
15 .\"     (other than the remaining FIXMEs in the page source below).
16 .\"
17 .\" FIXME The following need to be documented
18 .\"     TCP_MD5SIG (2.6.20)
19 .\"         commit cfb6eeb4c860592edd123fdea908d23c6ad1c7dc
20 .\"         Author was yoshfuji@linux-ipv6.org
21 .\"         Needs CONFIG_TCP_MD5SIG
22 .\" From net/inet/Kconfig:
23 .\" bool "TCP: MD5 Signature Option support (RFC2385) (EXPERIMENTAL)"
24 .\" RFC2385 specifies a method of giving MD5 protection to TCP sessions.
25 .\" Its main (only?) use is to protect BGP sessions between core routers
26 .\" on the Internet.
27 .\"
28 .\" There is a TCP_MD5SIG option documented in FreeBSD's tcp(4),
29 .\" but probably many details are different on Linux
30 .\"         http://thread.gmane.org/gmane.linux.network/47490
31 .\"         http://www.daemon-systems.org/man/tcp.4.html
32 .\"         http://article.gmane.org/gmane.os.netbsd.devel.network/3767/match=tcp_md5sig+freebsd
33 .\"
34 .\"     TCP_COOKIE_TRANSACTIONS (2.6.33)
35 .\"         commit 519855c508b9a17878c0977a3cdefc09b59b30df
36 .\"         Author: William Allen Simpson <william.allen.simpson@gmail.com>
37 .\"         commit e56fb50f2b7958b931c8a2fc0966061b3f3c8f3a
38 .\"         Author: William Allen Simpson <william.allen.simpson@gmail.com>
39 .\"
40 .\"         REMOVED in Linux 3.10
41 .\"             commit 1a2c6181c4a1922021b4d7df373bba612c3e5f04
42 .\"             Author: Christoph Paasch <christoph.paasch@uclouvain.be>
43 .\"
44 .\"     TCP_THIN_LINEAR_TIMEOUTS (2.6.34)
45 .\"         commit 36e31b0af58728071e8023cf8e20c5166b700717
46 .\"         Author: Andreas Petlund <apetlund@simula.no>
47 .\"
48 .\"     TCP_THIN_DUPACK (2.6.34)
49 .\"         commit 7e38017557bc0b87434d184f8804cadb102bb903
50 .\"         Author: Andreas Petlund <apetlund@simula.no>
51 .\"
52 .\"     TCP_REPAIR (3.5)
53 .\"         commit ee9952831cfd0bbe834f4a26489d7dce74582e37
54 .\"         Author: Pavel Emelyanov <xemul@parallels.com>
55 .\"         See also
56 .\"             http://criu.org/TCP_connection
57 .\"             https://lwn.net/Articles/495304/
58 .\"
59 .\"     TCP_REPAIR_QUEUE (3.5)
60 .\"         commit ee9952831cfd0bbe834f4a26489d7dce74582e37
61 .\"         Author: Pavel Emelyanov <xemul@parallels.com>
62 .\"
63 .\"     TCP_QUEUE_SEQ (3.5)
64 .\"         commit ee9952831cfd0bbe834f4a26489d7dce74582e37
65 .\"         Author: Pavel Emelyanov <xemul@parallels.com>
66 .\"
67 .\"     TCP_REPAIR_OPTIONS (3.5)
68 .\"         commit b139ba4e90dccbf4cd4efb112af96a5c9e0b098c
69 .\"         Author: Pavel Emelyanov <xemul@parallels.com>
70 .\"
71 .\"     TCP_FASTOPEN (3.6)
72 .\"         (Fast Open server side implementation completed in Linux 3.7)
73 .\"         http://lwn.net/Articles/508865/
74 .\"
75 .\"     TCP_TIMESTAMP (3.9)
76 .\"        commit 93be6ce0e91b6a94783e012b1857a347a5e6e9f2
77 .\"        Author: Andrey Vagin <avagin@openvz.org>
78 .\"
79 .\"     TCP_NOTSENT_LOWAT (3.12)
80 .\"        commit c9bee3b7fdecb0c1d070c7b54113b3bdfb9a3d36
81 .\"        Author: Eric Dumazet <edumazet@google.com>
82 .\"
83 .\"     TCP_CC_INFO (4.1)
84 .\"        commit 6e9250f59ef9efb932c84850cd221f22c2a03c4a
85 .\"        Author: Eric Dumazet <edumazet@google.com>
86 .\"
87 .\"     TCP_SAVE_SYN, TCP_SAVED_SYN (4.2)
88 .\"         commit cd8ae85299d54155702a56811b2e035e63064d3d
89 .\"         Author: Eric Dumazet <edumazet@google.com>
90 .\"
91 .TH tcp 7 (date) "Linux man-pages (unreleased)"
92 .SH NAME
93 tcp \- TCP protocol
94 .SH SYNOPSIS
95 .nf
96 .B #include <sys/socket.h>
97 .B #include <netinet/in.h>
98 .B #include <netinet/tcp.h>
100 .IB tcp_socket " = socket(AF_INET, SOCK_STREAM, 0);"
102 .SH DESCRIPTION
103 This is an implementation of the TCP protocol defined in
104 RFC\ 793, RFC\ 1122 and RFC\ 2001 with the NewReno and SACK
105 extensions.
106 It provides a reliable, stream-oriented,
107 full-duplex connection between two sockets on top of
108 .BR ip (7),
109 for both v4 and v6 versions.
110 TCP guarantees that the data arrives in order and
111 retransmits lost packets.
112 It generates and checks a per-packet checksum to catch
113 transmission errors.
114 TCP does not preserve record boundaries.
116 A newly created TCP socket has no remote or local address and is not
117 fully specified.
118 To create an outgoing TCP connection use
119 .BR connect (2)
120 to establish a connection to another TCP socket.
121 To receive new incoming connections, first
122 .BR bind (2)
123 the socket to a local address and port and then call
124 .BR listen (2)
125 to put the socket into the listening state.
126 After that a new socket for each incoming connection can be accepted using
127 .BR accept (2).
128 A socket which has had
129 .BR accept (2)
131 .BR connect (2)
132 successfully called on it is fully specified and may transmit data.
133 Data cannot be transmitted on listening or not yet connected sockets.
135 Linux supports RFC\ 1323 TCP high performance
136 extensions.
137 These include Protection Against Wrapped
138 Sequence Numbers (PAWS), Window Scaling and Timestamps.
139 Window scaling allows the use
140 of large (> 64\ kB) TCP windows in order to support links with high
141 latency or bandwidth.
142 To make use of them, the send and receive buffer sizes must be increased.
143 They can be set globally with the
144 .I /proc/sys/net/ipv4/tcp_wmem
146 .I /proc/sys/net/ipv4/tcp_rmem
147 files, or on individual sockets by using the
148 .B SO_SNDBUF
150 .B SO_RCVBUF
151 socket options with the
152 .BR setsockopt (2)
153 call.
155 The maximum sizes for socket buffers declared via the
156 .B SO_SNDBUF
158 .B SO_RCVBUF
159 mechanisms are limited by the values in the
160 .I /proc/sys/net/core/rmem_max
162 .I /proc/sys/net/core/wmem_max
163 files.
164 Note that TCP actually allocates twice the size of
165 the buffer requested in the
166 .BR setsockopt (2)
167 call, and so a succeeding
168 .BR getsockopt (2)
169 call will not return the same size of buffer as requested in the
170 .BR setsockopt (2)
171 call.
172 TCP uses the extra space for administrative purposes and internal
173 kernel structures, and the
174 .I /proc
175 file values reflect the
176 larger sizes compared to the actual TCP windows.
177 On individual connections, the socket buffer size must be set prior to the
178 .BR listen (2)
180 .BR connect (2)
181 calls in order to have it take effect.
183 .BR socket (7)
184 for more information.
186 TCP supports urgent data.
187 Urgent data is used to signal the
188 receiver that some important message is part of the data
189 stream and that it should be processed as soon as possible.
190 To send urgent data specify the
191 .B MSG_OOB
192 option to
193 .BR send (2).
194 When urgent data is received, the kernel sends a
195 .B SIGURG
196 signal to the process or process group that has been set as the
197 socket "owner" using the
198 .B SIOCSPGRP
200 .B FIOSETOWN
201 ioctls (or the POSIX.1-specified
202 .BR fcntl (2)
203 .B F_SETOWN
204 operation).
205 When the
206 .B SO_OOBINLINE
207 socket option is enabled, urgent data is put into the normal
208 data stream (a program can test for its location using the
209 .B SIOCATMARK
210 ioctl described below),
211 otherwise it can be received only when the
212 .B MSG_OOB
213 flag is set for
214 .BR recv (2)
216 .BR recvmsg (2).
218 When out-of-band data is present,
219 .BR select (2)
220 indicates the file descriptor as having an exceptional condition and
221 .I poll (2)
222 indicates a
223 .B POLLPRI
224 event.
226 Linux 2.4 introduced a number of changes for improved
227 throughput and scaling, as well as enhanced functionality.
228 Some of these features include support for zero-copy
229 .BR sendfile (2),
230 Explicit Congestion Notification, new
231 management of TIME_WAIT sockets, keep-alive socket options
232 and support for Duplicate SACK extensions.
233 .SS Address formats
234 TCP is built on top of IP (see
235 .BR ip (7)).
236 The address formats defined by
237 .BR ip (7)
238 apply to TCP.
239 TCP supports point-to-point communication only;
240 broadcasting and multicasting are not
241 supported.
242 .SS /proc interfaces
243 System-wide TCP parameter settings can be accessed by files in the directory
244 .IR /proc/sys/net/ipv4/ .
245 In addition, most IP
246 .I /proc
247 interfaces also apply to TCP; see
248 .BR ip (7).
249 Variables described as
250 .I Boolean
251 take an integer value, with a nonzero value ("true") meaning that
252 the corresponding option is enabled, and a zero value ("false")
253 meaning that the option is disabled.
255 .IR tcp_abc " (Integer; default: 0; Linux 2.6.15 to Linux 3.8)"
256 .\" Since Linux 2.6.15; removed in Linux 3.9
257 .\" commit ca2eb5679f8ddffff60156af42595df44a315ef0
258 .\" The following is from Linux 2.6.28-rc4: Documentation/networking/ip-sysctl.txt
259 Control the Appropriate Byte Count (ABC), defined in RFC 3465.
260 ABC is a way of increasing the congestion window
261 .RI ( cwnd )
262 more slowly in response to partial acknowledgements.
263 Possible values are:
266 .B 0
267 increase
268 .I cwnd
269 once per acknowledgement (no ABC)
271 .B 1
272 increase
273 .I cwnd
274 once per acknowledgement of full sized segment
276 .B 2
277 allow increase
278 .I cwnd
279 by two if acknowledgement is
280 of two segments to compensate for delayed acknowledgements.
283 .IR tcp_abort_on_overflow " (Boolean; default: disabled; since Linux 2.4)"
284 .\" Since Linux 2.3.41
285 Enable resetting connections if the listening service is too
286 slow and unable to keep up and accept them.
287 It means that if overflow occurred due
288 to a burst, the connection will recover.
289 Enable this option
290 .I only
291 if you are really sure that the listening daemon
292 cannot be tuned to accept connections faster.
293 Enabling this option can harm the clients of your server.
295 .IR tcp_adv_win_scale " (integer; default: 2; since Linux 2.4)"
296 .\" Since Linux 2.4.0-test7
297 Count buffering overhead as
298 .IR "bytes/2\[ha]tcp_adv_win_scale" ,
300 .I tcp_adv_win_scale
301 is greater than 0; or
302 .IR "bytes\-bytes/2\[ha](\-tcp_adv_win_scale)" ,
304 .I tcp_adv_win_scale
305 is less than or equal to zero.
307 The socket receive buffer space is shared between the
308 application and kernel.
309 TCP maintains part of the buffer as
310 the TCP window, this is the size of the receive window
311 advertised to the other end.
312 The rest of the space is used
313 as the "application" buffer, used to isolate the network
314 from scheduling and application latencies.
316 .I tcp_adv_win_scale
317 default value of 2 implies that the space
318 used for the application buffer is one fourth that of the total.
320 .IR tcp_allowed_congestion_control " (String; default: see text; since Linux 2.4.20)"
321 .\" The following is from Linux 2.6.28-rc4: Documentation/networking/ip-sysctl.txt
322 Show/set the congestion control algorithm choices available to unprivileged
323 processes (see the description of the
324 .B TCP_CONGESTION
325 socket option).
326 The items in the list are separated by white space and
327 terminated by a newline character.
328 The list is a subset of those listed in
329 .IR tcp_available_congestion_control .
330 The default value for this list is "reno" plus the default setting of
331 .IR tcp_congestion_control .
333 .IR tcp_autocorking " (Boolean; default: enabled; since Linux 3.14)"
334 .\" commit f54b311142a92ea2e42598e347b84e1655caf8e3
335 .\" Text heavily based on Documentation/networking/ip-sysctl.txt
336 If this option is enabled, the kernel tries to coalesce small writes
337 (from consecutive
338 .BR write (2)
340 .BR sendmsg (2)
341 calls) as much as possible,
342 in order to decrease the total number of sent packets.
343 Coalescing is done if at least one prior packet for the flow
344 is waiting in Qdisc queues or device transmit queue.
345 Applications can still use the
346 .B TCP_CORK
347 socket option to obtain optimal behavior
348 when they know how/when to uncork their sockets.
350 .IR tcp_available_congestion_control " (String; read-only; since Linux 2.4.20)"
351 .\" The following is from Linux 2.6.28-rc4: Documentation/networking/ip-sysctl.txt
352 Show a list of the congestion-control algorithms
353 that are registered.
354 The items in the list are separated by white space and
355 terminated by a newline character.
356 This list is a limiting set for the list in
357 .IR tcp_allowed_congestion_control .
358 More congestion-control algorithms may be available as modules,
359 but not loaded.
361 .IR tcp_app_win  " (integer; default: 31; since Linux 2.4)"
362 .\" Since Linux 2.4.0-test7
363 This variable defines how many
364 bytes of the TCP window are reserved for buffering overhead.
366 A maximum of (\fIwindow/2\[ha]tcp_app_win\fP, mss) bytes in the window
367 are reserved for the application buffer.
368 A value of 0 implies that no amount is reserved.
370 .\" The following is from Linux 2.6.28-rc4: Documentation/networking/ip-sysctl.txt
372 .IR tcp_base_mss " (Integer; default: 512; since Linux 2.6.17)"
373 The initial value of
374 .I search_low
375 to be used by the packetization layer Path MTU discovery (MTU probing).
376 If MTU probing is enabled,
377 this is the initial MSS used by the connection.
379 .\" The following is from Linux 2.6.12: Documentation/networking/ip-sysctl.txt
381 .IR tcp_bic " (Boolean; default: disabled; Linux 2.4.27/2.6.6 to Linux 2.6.13)"
382 Enable BIC TCP congestion control algorithm.
383 BIC-TCP is a sender-side-only change that ensures a linear RTT
384 fairness under large windows while offering both scalability and
385 bounded TCP-friendliness.
386 The protocol combines two schemes
387 called additive increase and binary search increase.
388 When the congestion window is large, additive increase with a large
389 increment ensures linear RTT fairness as well as good scalability.
390 Under small congestion windows, binary search
391 increase provides TCP friendliness.
393 .\" The following is from Linux 2.6.12: Documentation/networking/ip-sysctl.txt
395 .IR tcp_bic_low_window " (integer; default: 14; Linux 2.4.27/2.6.6 to Linux 2.6.13)"
396 Set the threshold window (in packets) where BIC TCP starts to
397 adjust the congestion window.
398 Below this threshold BIC TCP behaves the same as the default TCP Reno.
400 .\" The following is from Linux 2.6.12: Documentation/networking/ip-sysctl.txt
402 .IR tcp_bic_fast_convergence " (Boolean; default: enabled; Linux 2.4.27/2.6.6 to Linux 2.6.13)"
403 Force BIC TCP to more quickly respond to changes in congestion window.
404 Allows two flows sharing the same connection to converge more rapidly.
406 .IR tcp_congestion_control " (String; default: see text; since Linux 2.4.13)"
407 .\" The following is from Linux 2.6.28-rc4: Documentation/networking/ip-sysctl.txt
408 Set the default congestion-control algorithm to be used for new connections.
409 The algorithm "reno" is always available,
410 but additional choices may be available depending on kernel configuration.
411 The default value for this file is set as part of kernel configuration.
413 .IR tcp_dma_copybreak " (integer; default: 4096; since Linux 2.6.24)"
414 Lower limit, in bytes, of the size of socket reads that will be
415 offloaded to a DMA copy engine, if one is present in the system
416 and the kernel was configured with the
417 .B CONFIG_NET_DMA
418 option.
420 .IR tcp_dsack " (Boolean; default: enabled; since Linux 2.4)"
421 .\" Since Linux 2.4.0-test7
422 Enable RFC\ 2883 TCP Duplicate SACK support.
424 .IR tcp_fastopen " (Bitmask; default: 0x1; since Linux 3.7)"
425 Enables RFC\~7413 Fast Open support.
426 The flag is used as a bitmap with the following values:
429 .B 0x1
430 Enables client side Fast Open support
432 .B 0x2
433 Enables server side Fast Open support
435 .B 0x4
436 Allows client side to transmit data in SYN without Fast Open option
438 .B 0x200
439 Allows server side to accept SYN data without Fast Open option
441 .B 0x400
442 Enables Fast Open on all listeners without
443 .B TCP_FASTOPEN
444 socket option
447 .IR tcp_fastopen_key " (since Linux 3.7)"
448 Set server side RFC\~7413 Fast Open key to generate Fast Open cookie
449 when server side Fast Open support is enabled.
451 .IR tcp_ecn " (Integer; default: see below; since Linux 2.4)"
452 .\" Since Linux 2.4.0-test7
453 Enable RFC\ 3168 Explicit Congestion Notification.
455 This file can have one of the following values:
458 .B 0
459 Disable ECN.
460 Neither initiate nor accept ECN.
461 This was the default up to and including Linux 2.6.30.
463 .B 1
464 Enable ECN when requested by incoming connections and also
465 request ECN on outgoing connection attempts.
467 .B 2
468 .\" commit 255cac91c3c9ce7dca7713b93ab03c75b7902e0e
469 Enable ECN when requested by incoming connections,
470 but do not request ECN on outgoing connections.
471 This value is supported, and is the default, since Linux 2.6.31.
474 When enabled, connectivity to some destinations could be affected
475 due to older, misbehaving middle boxes along the path, causing
476 connections to be dropped.
477 However, to facilitate and encourage deployment with option 1, and
478 to work around such buggy equipment, the
479 .B tcp_ecn_fallback
480 option has been introduced.
482 .IR tcp_ecn_fallback " (Boolean; default: enabled; since Linux 4.1)"
483 .\" commit 492135557dc090a1abb2cfbe1a412757e3ed68ab
484 Enable RFC\ 3168, Section 6.1.1.1. fallback.
485 When enabled, outgoing ECN-setup SYNs that time out within the
486 normal SYN retransmission timeout will be resent with CWR and
487 ECE cleared.
489 .IR tcp_fack " (Boolean; default: enabled; since Linux 2.2)"
490 .\" Since Linux 2.1.92
491 Enable TCP Forward Acknowledgement support.
493 .IR tcp_fin_timeout " (integer; default: 60; since Linux 2.2)"
494 .\" Since Linux 2.1.53
495 This specifies how many seconds to wait for a final FIN packet before the
496 socket is forcibly closed.
497 This is strictly a violation of the TCP specification,
498 but required to prevent denial-of-service attacks.
499 In Linux 2.2, the default value was 180.
501 .\" The following is from Linux 2.6.12: Documentation/networking/ip-sysctl.txt
503 .IR tcp_frto " (integer; default: see below; since Linux 2.4.21/2.6)"
504 .\" Since Linux 2.4.21/2.5.43
505 Enable F-RTO, an enhanced recovery algorithm for TCP retransmission
506 timeouts (RTOs).
507 It is particularly beneficial in wireless environments
508 where packet loss is typically due to random radio interference
509 rather than intermediate router congestion.
510 See RFC 4138 for more details.
512 This file can have one of the following values:
515 .B 0
516 Disabled.
517 This was the default up to and including Linux 2.6.23.
519 .B 1
520 The basic version F-RTO algorithm is enabled.
522 .B 2
523 .\" commit c96fd3d461fa495400df24be3b3b66f0e0b152f9
524 Enable SACK-enhanced F-RTO if flow uses SACK.
525 The basic version can be used also when
526 SACK is in use though in that case scenario(s) exists where F-RTO
527 interacts badly with the packet counting of the SACK-enabled TCP flow.
528 This value is the default since Linux 2.6.24.
531 Before Linux 2.6.22, this parameter was a Boolean value,
532 supporting just values 0 and 1 above.
534 .IR tcp_frto_response " (integer; default: 0; since Linux 2.6.22)"
535 When F-RTO has detected that a TCP retransmission timeout was spurious
536 (i.e., the timeout would have been avoided had TCP set a
537 longer retransmission timeout),
538 TCP has several options concerning what to do next.
539 Possible values are:
542 .B 0
543 Rate halving based; a smooth and conservative response,
544 results in halved congestion window
545 .RI ( cwnd )
546 and slow-start threshold
547 .RI ( ssthresh )
548 after one RTT.
550 .B 1
551 Very conservative response; not recommended because even
552 though being valid, it interacts poorly with the rest of Linux TCP; halves
553 .I cwnd
555 .I ssthresh
556 immediately.
558 .B 2
559 Aggressive response; undoes congestion-control measures
560 that are now known to be unnecessary
561 (ignoring the possibility of a lost retransmission that would require
562 TCP to be more cautious);
563 .I cwnd
565 .I ssthresh
566 are restored to the values prior to timeout.
569 .IR tcp_keepalive_intvl " (integer; default: 75; since Linux 2.4)"
570 .\" Since Linux 2.3.18
571 The number of seconds between TCP keep-alive probes.
573 .IR tcp_keepalive_probes " (integer; default: 9; since Linux 2.2)"
574 .\" Since Linux 2.1.43
575 The maximum number of TCP keep-alive probes to send
576 before giving up and killing the connection if
577 no response is obtained from the other end.
579 .IR tcp_keepalive_time " (integer; default: 7200; since Linux 2.2)"
580 .\" Since Linux 2.1.43
581 The number of seconds a connection needs to be idle
582 before TCP begins sending out keep-alive probes.
583 Keep-alives are sent only when the
584 .B SO_KEEPALIVE
585 socket option is enabled.
586 The default value is 7200 seconds (2 hours).
587 An idle connection is terminated after
588 approximately an additional 11 minutes (9 probes an interval
589 of 75 seconds apart) when keep-alive is enabled.
591 Note that underlying connection tracking mechanisms and
592 application timeouts may be much shorter.
594 .\" The following is from Linux 2.6.12: Documentation/networking/ip-sysctl.txt
596 .IR tcp_low_latency  " (Boolean; default: disabled; since Linux 2.4.21/2.6; \
597 obsolete since Linux 4.14)"
598 .\" Since Linux 2.4.21/2.5.60
599 If enabled, the TCP stack makes decisions that prefer lower
600 latency as opposed to higher throughput.
601 It this option is disabled, then higher throughput is preferred.
602 An example of an application where this default should be
603 changed would be a Beowulf compute cluster.
604 Since Linux 4.14,
605 .\" commit b6690b14386698ce2c19309abad3f17656bdfaea
606 this file still exists, but its value is ignored.
608 .IR tcp_max_orphans  " (integer; default: see below; since Linux 2.4)"
609 .\" Since Linux 2.3.41
610 The maximum number of orphaned (not attached to any user file
611 handle) TCP sockets allowed in the system.
612 When this number is exceeded,
613 the orphaned connection is reset and a warning is printed.
614 This limit exists only to prevent simple denial-of-service attacks.
615 Lowering this limit is not recommended.
616 Network conditions might require you to increase the number of
617 orphans allowed, but note that each orphan can eat up to \[ti]64\ kB
618 of unswappable memory.
619 The default initial value is set equal to the kernel parameter NR_FILE.
620 This initial default is adjusted depending on the memory in the system.
622 .IR tcp_max_syn_backlog " (integer; default: see below; since Linux 2.2)"
623 .\" Since Linux 2.1.53
624 The maximum number of queued connection requests which have
625 still not received an acknowledgement from the connecting client.
626 If this number is exceeded, the kernel will begin
627 dropping requests.
628 The default value of 256 is increased to
629 1024 when the memory present in the system is adequate or
630 greater (>= 128\ MB), and reduced to 128 for those systems with
631 very low memory (<= 32\ MB).
633 Before Linux 2.6.20,
634 .\" commit 72a3effaf633bcae9034b7e176bdbd78d64a71db
635 it was recommended that if this needed to be increased above 1024,
636 the size of the SYNACK hash table
637 .RB ( TCP_SYNQ_HSIZE )
639 .I include/net/tcp.h
640 should be modified to keep
642 .in +4n
644 TCP_SYNQ_HSIZE * 16 <= tcp_max_syn_backlog
648 and the kernel should be
649 recompiled.
650 In Linux 2.6.20, the fixed sized
651 .B TCP_SYNQ_HSIZE
652 was removed in favor of dynamic sizing.
654 .IR tcp_max_tw_buckets " (integer; default: see below; since Linux 2.4)"
655 .\" Since Linux 2.3.41
656 The maximum number of sockets in TIME_WAIT state allowed in
657 the system.
658 This limit exists only to prevent simple denial-of-service attacks.
659 The default value of NR_FILE*2 is adjusted
660 depending on the memory in the system.
661 If this number is
662 exceeded, the socket is closed and a warning is printed.
664 .IR tcp_moderate_rcvbuf " (Boolean; default: enabled; since Linux 2.4.17/2.6.7)"
665 .\" The following is from Linux 2.6.28-rc4: Documentation/networking/ip-sysctl.txt
666 If enabled, TCP performs receive buffer auto-tuning,
667 attempting to automatically size the buffer (no greater than
668 .IR tcp_rmem[2] )
669 to match the size required by the path for full throughput.
671 .IR tcp_mem " (since Linux 2.4)"
672 .\" Since Linux 2.4.0-test7
673 This is a vector of 3 integers: [low, pressure, high].
674 These bounds, measured in units of the system page size,
675 are used by TCP to track its memory usage.
676 The defaults are calculated at boot time from the amount of
677 available memory.
678 (TCP can only use
679 .I "low memory"
680 for this, which is limited to around 900 megabytes on 32-bit systems.
681 64-bit systems do not suffer this limitation.)
684 .I low
685 TCP doesn't regulate its memory allocation when the number
686 of pages it has allocated globally is below this number.
688 .I pressure
689 When the amount of memory allocated by TCP
690 exceeds this number of pages, TCP moderates its memory consumption.
691 This memory pressure state is exited
692 once the number of pages allocated falls below
694 .I low
695 mark.
697 .I high
698 The maximum number of pages, globally, that TCP will allocate.
699 This value overrides any other limits imposed by the kernel.
702 .IR tcp_mtu_probing " (integer; default: 0; since Linux 2.6.17)"
703 .\" The following is from Linux 2.6.28-rc4: Documentation/networking/ip-sysctl.txt
704 This parameter controls TCP Packetization-Layer Path MTU Discovery.
705 The following values may be assigned to the file:
708 .B 0
709 Disabled
711 .B 1
712 Disabled by default, enabled when an ICMP black hole detected
714 .B 2
715 Always enabled, use initial MSS of
716 .IR tcp_base_mss .
719 .IR tcp_no_metrics_save " (Boolean; default: disabled; since Linux 2.6.6)"
720 .\" The following is from Linux 2.6.28-rc4: Documentation/networking/ip-sysctl.txt
721 By default, TCP saves various connection metrics in the route cache
722 when the connection closes, so that connections established in the
723 near future can use these to set initial conditions.
724 Usually, this increases overall performance,
725 but it may sometimes cause performance degradation.
727 .I tcp_no_metrics_save
728 is enabled, TCP will not cache metrics on closing connections.
730 .IR tcp_orphan_retries " (integer; default: 8; since Linux 2.4)"
731 .\" Since Linux 2.3.41
732 The maximum number of attempts made to probe the other
733 end of a connection which has been closed by our end.
735 .IR tcp_reordering " (integer; default: 3; since Linux 2.4)"
736 .\" Since Linux 2.4.0-test7
737 The maximum a packet can be reordered in a TCP packet stream
738 without TCP assuming packet loss and going into slow start.
739 It is not advisable to change this number.
740 This is a packet reordering detection metric designed to
741 minimize unnecessary back off and retransmits provoked by
742 reordering of packets on a connection.
744 .IR tcp_retrans_collapse " (Boolean; default: enabled; since Linux 2.2)"
745 .\" Since Linux 2.1.96
746 Try to send full-sized packets during retransmit.
748 .IR tcp_retries1 " (integer; default: 3; since Linux 2.2)"
749 .\" Since Linux 2.1.43
750 The number of times TCP will attempt to retransmit a
751 packet on an established connection normally,
752 without the extra effort of getting the network layers involved.
753 Once we exceed this number of
754 retransmits, we first have the network layer
755 update the route if possible before each new retransmit.
756 The default is the RFC specified minimum of 3.
758 .IR tcp_retries2 " (integer; default: 15; since Linux 2.2)"
759 .\" Since Linux 2.1.43
760 The maximum number of times a TCP packet is retransmitted
761 in established state before giving up.
762 The default value is 15, which corresponds to a duration of
763 approximately between 13 to 30 minutes, depending
764 on the retransmission timeout.
765 The RFC\ 1122 specified
766 minimum limit of 100 seconds is typically deemed too short.
768 .IR tcp_rfc1337 " (Boolean; default: disabled; since Linux 2.2)"
769 .\" Since Linux 2.1.90
770 Enable TCP behavior conformant with RFC\ 1337.
771 When disabled,
772 if a RST is received in TIME_WAIT state, we close
773 the socket immediately without waiting for the end
774 of the TIME_WAIT period.
776 .IR tcp_rmem " (since Linux 2.4)"
777 .\" Since Linux 2.4.0-test7
778 This is a vector of 3 integers: [min, default, max].
779 These parameters are used by TCP to regulate receive buffer sizes.
780 TCP dynamically adjusts the size of the
781 receive buffer from the defaults listed below, in the range
782 of these values, depending on memory available in the system.
785 .I min
786 minimum size of the receive buffer used by each TCP socket.
787 The default value is the system page size.
788 (On Linux 2.4, the default value is 4\ kB, lowered to
789 .B PAGE_SIZE
790 bytes in low-memory systems.)
791 This value
792 is used to ensure that in memory pressure mode,
793 allocations below this size will still succeed.
794 This is not
795 used to bound the size of the receive buffer declared
796 using
797 .B SO_RCVBUF
798 on a socket.
800 .I default
801 the default size of the receive buffer for a TCP socket.
802 This value overwrites the initial default buffer size from
803 the generic global
804 .I net.core.rmem_default
805 defined for all protocols.
806 The default value is 87380 bytes.
807 (On Linux 2.4, this will be lowered to 43689 in low-memory systems.)
808 If larger receive buffer sizes are desired, this value should
809 be increased (to affect all sockets).
810 To employ large TCP windows, the
811 .I net.ipv4.tcp_window_scaling
812 must be enabled (default).
814 .I max
815 the maximum size of the receive buffer used by each TCP socket.
816 This value does not override the global
817 .IR net.core.rmem_max .
818 This is not used to limit the size of the receive buffer declared using
819 .B SO_RCVBUF
820 on a socket.
821 The default value is calculated using the formula
823 .in +4n
825 max(87380, min(4\ MB, \fItcp_mem\fP[1]*PAGE_SIZE/128))
829 (On Linux 2.4, the default is 87380*2 bytes,
830 lowered to 87380 in low-memory systems).
833 .IR tcp_sack " (Boolean; default: enabled; since Linux 2.2)"
834 .\" Since Linux 2.1.36
835 Enable RFC\ 2018 TCP Selective Acknowledgements.
837 .IR tcp_slow_start_after_idle " (Boolean; default: enabled; since Linux 2.6.18)"
838 .\" The following is from Linux 2.6.28-rc4: Documentation/networking/ip-sysctl.txt
839 If enabled, provide RFC 2861 behavior and time out the congestion
840 window after an idle period.
841 An idle period is defined as the current RTO (retransmission timeout).
842 If disabled, the congestion window will not
843 be timed out after an idle period.
845 .IR tcp_stdurg " (Boolean; default: disabled; since Linux 2.2)"
846 .\" Since Linux 2.1.44
847 If this option is enabled, then use the RFC\ 1122 interpretation
848 of the TCP urgent-pointer field.
849 .\" RFC 793 was ambiguous in its specification of the meaning of the
850 .\" urgent pointer.  RFC 1122 (and RFC 961) fixed on a particular
851 .\" resolution of this ambiguity (unfortunately the "wrong" one).
852 According to this interpretation, the urgent pointer points
853 to the last byte of urgent data.
854 If this option is disabled, then use the BSD-compatible interpretation of
855 the urgent pointer:
856 the urgent pointer points to the first byte after the urgent data.
857 Enabling this option may lead to interoperability problems.
859 .IR tcp_syn_retries  " (integer; default: 6; since Linux 2.2)"
860 .\" Since Linux 2.1.38
861 The maximum number of times initial SYNs for an active TCP
862 connection attempt will be retransmitted.
863 This value should not be higher than 255.
864 The default value is 6, which corresponds to retrying for up to
865 approximately 127 seconds.
866 Before Linux 3.7,
867 .\" commit 6c9ff979d1921e9fd05d89e1383121c2503759b9
868 the default value was 5, which
869 (in conjunction with calculation based on other kernel parameters)
870 corresponded to approximately 180 seconds.
872 .IR tcp_synack_retries " (integer; default: 5; since Linux 2.2)"
873 .\" Since Linux 2.1.38
874 The maximum number of times a SYN/ACK segment
875 for a passive TCP connection will be retransmitted.
876 This number should not be higher than 255.
878 .IR tcp_syncookies " (integer; default: 1; since Linux 2.2)"
879 .\" Since Linux 2.1.43
880 Enable TCP syncookies.
881 The kernel must be compiled with
882 .BR CONFIG_SYN_COOKIES .
883 The syncookies feature attempts to protect a
884 socket from a SYN flood attack.
885 This should be used as a last resort, if at all.
886 This is a violation of the TCP protocol,
887 and conflicts with other areas of TCP such as TCP extensions.
888 It can cause problems for clients and relays.
889 It is not recommended as a tuning mechanism for heavily
890 loaded servers to help with overloaded or misconfigured conditions.
891 For recommended alternatives see
892 .IR tcp_max_syn_backlog ,
893 .IR tcp_synack_retries ,
895 .IR tcp_abort_on_overflow .
896 Set to one of the following values:
899 .B 0
900 Disable TCP syncookies.
902 .B 1
903 Send out syncookies when the syn backlog queue of a socket overflows.
905 .B 2
906 (since Linux 3.12)
907 .\" commit 5ad37d5deee1ff7150a2d0602370101de158ad86
908 Send out syncookies unconditionally.
909 This can be useful for network testing.
912 .IR tcp_timestamps " (integer; default: 1; since Linux 2.2)"
913 .\" Since Linux 2.1.36
914 Set to one of the following values to enable or disable RFC\ 1323
915 TCP timestamps:
918 .B 0
919 Disable timestamps.
921 .B 1
922 Enable timestamps as defined in RFC1323 and use random offset for
923 each connection rather than only using the current time.
925 .B 2
926 As for the value 1, but without random offsets.
927 .\" commit 25429d7b7dca01dc4f17205de023a30ca09390d0
928 Setting
929 .I tcp_timestamps
930 to this value is meaningful since Linux 4.10.
933 .IR tcp_tso_win_divisor " (integer; default: 3; since Linux 2.6.9)"
934 This parameter controls what percentage of the congestion window
935 can be consumed by a single TCP Segmentation Offload (TSO) frame.
936 The setting of this parameter is a tradeoff between burstiness and
937 building larger TSO frames.
939 .IR tcp_tw_recycle " (Boolean; default: disabled; Linux 2.4 to Linux 4.11)"
940 .\" Since Linux 2.3.15
941 .\" removed in Linux 4.12; commit 4396e46187ca5070219b81773c4e65088dac50cc
942 Enable fast recycling of TIME_WAIT sockets.
943 Enabling this option is
944 not recommended as the remote IP may not use monotonically increasing
945 timestamps (devices behind NAT, devices with per-connection timestamp
946 offsets).
947 See RFC 1323 (PAWS) and RFC 6191.
949 .\" The following is from Linux 2.6.12: Documentation/networking/ip-sysctl.txt
951 .IR tcp_tw_reuse " (Boolean; default: disabled; since Linux 2.4.19/2.6)"
952 .\" Since Linux 2.4.19/2.5.43
953 Allow to reuse TIME_WAIT sockets for new connections when it is
954 safe from protocol viewpoint.
955 It should not be changed without advice/request of technical experts.
957 .\" The following is from Linux 2.6.12: Documentation/networking/ip-sysctl.txt
959 .IR tcp_vegas_cong_avoid  " (Boolean; default: disabled; Linux 2.2 to Linux 2.6.13)"
960 .\" Since Linux 2.1.8; removed in Linux 2.6.13
961 Enable TCP Vegas congestion avoidance algorithm.
962 TCP Vegas is a sender-side-only change to TCP that anticipates
963 the onset of congestion by estimating the bandwidth.
964 TCP Vegas adjusts the sending rate by modifying the congestion window.
965 TCP Vegas should provide less packet loss, but it is
966 not as aggressive as TCP Reno.
968 .\" The following is from Linux 2.6.12: Documentation/networking/ip-sysctl.txt
970 .IR tcp_westwood " (Boolean; default: disabled; Linux 2.4.26/2.6.3 to Linux 2.6.13)"
971 Enable TCP Westwood+ congestion control algorithm.
972 TCP Westwood+ is a sender-side-only modification of the TCP Reno
973 protocol stack that optimizes the performance of TCP congestion control.
974 It is based on end-to-end bandwidth estimation to set
975 congestion window and slow start threshold after a congestion episode.
976 Using this estimation, TCP Westwood+ adaptively sets a
977 slow start threshold and a congestion window which takes into
978 account the bandwidth used at the time congestion is experienced.
979 TCP Westwood+ significantly increases fairness with respect to
980 TCP Reno in wired networks and throughput over wireless links.
982 .IR tcp_window_scaling " (Boolean; default: enabled; since Linux 2.2)"
983 .\" Since Linux 2.1.36
984 Enable RFC\ 1323 TCP window scaling.
985 This feature allows the use of a large window
986 (> 64\ kB) on a TCP connection, should the other end support it.
987 Normally, the 16 bit window length field in the TCP header
988 limits the window size to less than 64\ kB.
989 If larger windows are desired, applications can increase the size of
990 their socket buffers and the window scaling option will be employed.
992 .I tcp_window_scaling
993 is disabled, TCP will not negotiate the use of window
994 scaling with the other end during connection setup.
996 .IR tcp_wmem " (since Linux 2.4)"
997 .\" Since Linux 2.4.0-test7
998 This is a vector of 3 integers: [min, default, max].
999 These parameters are used by TCP to regulate send buffer sizes.
1000 TCP dynamically adjusts the size of the send buffer from the
1001 default values listed below, in the range of these values,
1002 depending on memory available.
1005 .I min
1006 Minimum size of the send buffer used by each TCP socket.
1007 The default value is the system page size.
1008 (On Linux 2.4, the default value is 4\ kB.)
1009 This value is used to ensure that in memory pressure mode,
1010 allocations below this size will still succeed.
1011 This is not used to bound the size of the send buffer declared using
1012 .B SO_SNDBUF
1013 on a socket.
1015 .I default
1016 The default size of the send buffer for a TCP socket.
1017 This value overwrites the initial default buffer size from
1018 the generic global
1019 .I /proc/sys/net/core/wmem_default
1020 defined for all protocols.
1021 The default value is 16\ kB.
1022 .\" True in Linux 2.4 and 2.6
1023 If larger send buffer sizes are desired, this value
1024 should be increased (to affect all sockets).
1025 To employ large TCP windows, the
1026 .I /proc/sys/net/ipv4/tcp_window_scaling
1027 must be set to a nonzero value (default).
1029 .I max
1030 The maximum size of the send buffer used by each TCP socket.
1031 This value does not override the value in
1032 .IR /proc/sys/net/core/wmem_max .
1033 This is not used to limit the size of the send buffer declared using
1034 .B SO_SNDBUF
1035 on a socket.
1036 The default value is calculated using the formula
1038 .in +4n
1040 max(65536, min(4\ MB, \fItcp_mem\fP[1]*PAGE_SIZE/128))
1044 (On Linux 2.4, the default value is 128\ kB,
1045 lowered 64\ kB depending on low-memory systems.)
1048 .IR tcp_workaround_signed_windows " (Boolean; default: disabled; since Linux 2.6.26)"
1049 If enabled, assume that no receipt of a window-scaling option means that the
1050 remote TCP is broken and treats the window as a signed quantity.
1051 If disabled, assume that the remote TCP is not broken even if we do
1052 not receive a window scaling option from it.
1053 .SS Socket options
1054 To set or get a TCP socket option, call
1055 .BR getsockopt (2)
1056 to read or
1057 .BR setsockopt (2)
1058 to write the option with the option level argument set to
1059 .BR IPPROTO_TCP .
1060 Unless otherwise noted,
1061 .I optval
1062 is a pointer to an
1063 .IR int .
1064 .\" or SOL_TCP on Linux
1065 In addition,
1066 most
1067 .B IPPROTO_IP
1068 socket options are valid on TCP sockets.
1069 For more information see
1070 .BR ip (7).
1072 Following is a list of TCP-specific socket options.
1073 For details of some other socket options that are also applicable
1074 for TCP sockets, see
1075 .BR socket (7).
1077 .BR TCP_CONGESTION " (since Linux 2.6.13)"
1078 .\"         commit 5f8ef48d240963093451bcf83df89f1a1364f51d
1079 .\"         Author: Stephen Hemminger <shemminger@osdl.org>
1080 The argument for this option is a string.
1081 This option allows the caller to set the TCP congestion control
1082 algorithm to be used, on a per-socket basis.
1083 Unprivileged processes are restricted to choosing one of the algorithms in
1084 .I tcp_allowed_congestion_control
1085 (described above).
1086 Privileged processes
1087 .RB ( CAP_NET_ADMIN )
1088 can choose from any of the available congestion-control algorithms
1089 (see the description of
1090 .I tcp_available_congestion_control
1091 above).
1093 .BR TCP_CORK " (since Linux 2.2)"
1094 .\" precisely: since Linux 2.1.127
1095 If set, don't send out partial frames.
1096 All queued partial frames are sent when the option is cleared again.
1097 This is useful for prepending headers before calling
1098 .BR sendfile (2),
1099 or for throughput optimization.
1100 As currently implemented, there is a 200 millisecond ceiling on the time
1101 for which output is corked by
1102 .BR TCP_CORK .
1103 If this ceiling is reached, then queued data is automatically transmitted.
1104 This option can be combined with
1105 .B TCP_NODELAY
1106 only since Linux 2.5.71.
1107 This option should not be used in code intended to be portable.
1109 .BR TCP_DEFER_ACCEPT " (since Linux 2.4)"
1110 .\" Precisely: since Linux 2.3.38
1111 .\" Useful references:
1112 .\" http://www.techrepublic.com/article/take-advantage-of-tcp-ip-options-to-optimize-data-transmission/
1113 .\" http://unix.stackexchange.com/questions/94104/real-world-use-of-tcp-defer-accept
1114 Allow a listener to be awakened only when data arrives on the socket.
1115 Takes an integer value (seconds), this can
1116 bound the maximum number of attempts TCP will make to
1117 complete the connection.
1118 This option should not be used in code intended to be portable.
1120 .BR TCP_INFO " (since Linux 2.4)"
1121 Used to collect information about this socket.
1122 The kernel returns a \fIstruct tcp_info\fP as defined in the file
1123 .IR /usr/include/linux/tcp.h .
1124 This option should not be used in code intended to be portable.
1126 .BR TCP_KEEPCNT " (since Linux 2.4)"
1127 .\" Precisely: since Linux 2.3.18
1128 The maximum number of keepalive probes TCP should send
1129 before dropping the connection.
1130 This option should not be
1131 used in code intended to be portable.
1133 .BR TCP_KEEPIDLE " (since Linux 2.4)"
1134 .\" Precisely: since Linux 2.3.18
1135 The time (in seconds) the connection needs to remain idle
1136 before TCP starts sending keepalive probes, if the socket
1137 option
1138 .B SO_KEEPALIVE
1139 has been set on this socket.
1140 This option should not be used in code intended to be portable.
1142 .BR TCP_KEEPINTVL " (since Linux 2.4)"
1143 .\" Precisely: since Linux 2.3.18
1144 The time (in seconds) between individual keepalive probes.
1145 This option should not be used in code intended to be portable.
1147 .BR TCP_LINGER2 " (since Linux 2.4)"
1148 .\" Precisely: since Linux 2.3.41
1149 The lifetime of orphaned FIN_WAIT2 state sockets.
1150 This option can be used to override the system-wide setting in the file
1151 .I /proc/sys/net/ipv4/tcp_fin_timeout
1152 for this socket.
1153 This is not to be confused with the
1154 .BR socket (7)
1155 level option
1156 .BR SO_LINGER .
1157 This option should not be used in code intended to be portable.
1159 .B TCP_MAXSEG
1160 .\" Present in Linux 1.0
1161 The maximum segment size for outgoing TCP packets.
1162 In Linux 2.2 and earlier, and in Linux 2.6.28 and later,
1163 if this option is set before connection establishment, it also
1164 changes the MSS value announced to the other end in the initial packet.
1165 Values greater than the (eventual) interface MTU have no effect.
1166 TCP will also impose
1167 its minimum and maximum bounds over the value provided.
1169 .B TCP_NODELAY
1170 .\" Present in Linux 1.0
1171 If set, disable the Nagle algorithm.
1172 This means that segments
1173 are always sent as soon as possible, even if there is only a
1174 small amount of data.
1175 When not set, data is buffered until there
1176 is a sufficient amount to send out, thereby avoiding the
1177 frequent sending of small packets, which results in poor
1178 utilization of the network.
1179 This option is overridden by
1180 .BR TCP_CORK ;
1181 however, setting this option forces an explicit flush of
1182 pending output, even if
1183 .B TCP_CORK
1184 is currently set.
1186 .BR TCP_QUICKACK " (since Linux 2.4.4)"
1187 Enable quickack mode if set or disable quickack
1188 mode if cleared.
1189 In quickack mode, acks are sent
1190 immediately, rather than delayed if needed in accordance
1191 to normal TCP operation.
1192 This flag is not permanent,
1193 it only enables a switch to or from quickack mode.
1194 Subsequent operation of the TCP protocol will
1195 once again enter/leave quickack mode depending on
1196 internal protocol processing and factors such as
1197 delayed ack timeouts occurring and data transfer.
1198 This option should not be used in code intended to be
1199 portable.
1201 .BR TCP_SYNCNT " (since Linux 2.4)"
1202 .\" Precisely: since Linux 2.3.18
1203 Set the number of SYN retransmits that TCP should send before
1204 aborting the attempt to connect.
1205 It cannot exceed 255.
1206 This option should not be used in code intended to be portable.
1208 .BR TCP_USER_TIMEOUT " (since Linux 2.6.37)"
1209 .\"         commit dca43c75e7e545694a9dd6288553f55c53e2a3a3
1210 .\"         Author: Jerry Chu <hkchu@google.com>
1211 .\" The following text taken nearly verbatim from Jerry Chu's (excellent)
1212 .\" commit message.
1214 This option takes an
1215 .I unsigned int
1216 as an argument.
1217 When the value is greater than 0,
1218 it specifies the maximum amount of time in milliseconds that transmitted
1219 data may remain unacknowledged, or buffered data may remain untransmitted
1220 (due to zero window size) before TCP will forcibly close the
1221 corresponding connection and return
1222 .B ETIMEDOUT
1223 to the application.
1224 If the option value is specified as 0,
1225 TCP will use the system default.
1227 Increasing user timeouts allows a TCP connection to survive extended
1228 periods without end-to-end connectivity.
1229 Decreasing user timeouts
1230 allows applications to "fail fast", if so desired.
1231 Otherwise, failure may take up to 20 minutes with
1232 the current system defaults in a normal WAN environment.
1234 This option can be set during any state of a TCP connection,
1235 but is effective only during the synchronized states of a connection
1236 (ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, and LAST-ACK).
1237 Moreover, when used with the TCP keepalive
1238 .RB ( SO_KEEPALIVE )
1239 option,
1240 .B TCP_USER_TIMEOUT
1241 will override keepalive to determine when to close a
1242 connection due to keepalive failure.
1244 The option has no effect on when TCP retransmits a packet,
1245 nor when a keepalive probe is sent.
1247 This option, like many others, will be inherited by the socket returned by
1248 .BR accept (2),
1249 if it was set on the listening socket.
1251 Further details on the user timeout feature can be found in
1252 RFC\ 793 and RFC\ 5482 ("TCP User Timeout Option").
1254 .BR TCP_WINDOW_CLAMP " (since Linux 2.4)"
1255 .\" Precisely: since Linux 2.3.41
1256 Bound the size of the advertised window to this value.
1257 The kernel imposes a minimum size of SOCK_MIN_RCVBUF/2.
1258 This option should not be used in code intended to be
1259 portable.
1261 .BR TCP_FASTOPEN " (since Linux 3.6)"
1262 This option enables Fast Open (RFC\~7413) on the listener socket.
1263 The value specifies the maximum length of pending SYNs
1264 (similar to the backlog argument in
1265 .BR listen (2)).
1266 Once enabled,
1267 the listener socket grants the TCP Fast Open cookie
1268 on incoming SYN with TCP Fast Open option.
1270 More importantly it accepts the data in SYN with a valid Fast Open cookie
1271 and responds SYN-ACK acknowledging both the data and the SYN sequence.
1272 .BR accept (2)
1273 returns a socket that is available for read and write
1274 when the handshake has not completed yet.
1275 Thus the data exchange can commence before the handshake completes.
1276 This option requires enabling the server-side support on sysctl
1277 .I net.ipv4.tcp_fastopen
1278 (see above).
1279 For TCP Fast Open client-side support,
1281 .BR send (2)
1282 .B MSG_FASTOPEN
1284 .B TCP_FASTOPEN_CONNECT
1285 below.
1287 .BR TCP_FASTOPEN_CONNECT " (since Linux 4.11)"
1288 This option enables an alternative way to perform Fast Open
1289 on the active side (client).
1290 When this option is enabled,
1291 .BR connect (2)
1292 would behave differently depending on
1293 if a Fast Open cookie is available for the destination.
1295 If a cookie is not available (i.e. first contact to the destination),
1296 .BR connect (2)
1297 behaves as usual by sending a SYN immediately,
1298 except the SYN would include an empty Fast Open cookie option
1299 to solicit a cookie.
1301 If a cookie is available,
1302 .BR connect (2)
1303 would return 0 immediately but the SYN transmission is deferred.
1304 A subsequent
1305 .BR write (2)
1307 .BR sendmsg (2)
1308 would trigger a SYN with data plus cookie in the Fast Open option.
1309 In other words,
1310 the actual connect operation is deferred until data is supplied.
1312 .B Note:
1313 While this option is designed for convenience,
1314 enabling it does change the behaviors and certain system calls might set
1315 different
1316 .I errno
1317 values.
1318 With cookie present,
1319 .BR write (2)
1321 .BR sendmsg (2)
1322 must be called right after
1323 .BR connect (2)
1324 in order to send out SYN+data to complete 3WHS and establish connection.
1325 Calling
1326 .BR read (2)
1327 right after
1328 .BR connect (2)
1329 without
1330 .BR write (2)
1331 will cause the blocking socket to be blocked forever.
1333 The application should either set
1334 .B TCP_FASTOPEN_CONNECT
1335 socket option before
1336 .BR write (2)
1338 .BR sendmsg (2),
1339 or call
1340 .BR write (2)
1342 .BR sendmsg (2)
1343 with
1344 .B MSG_FASTOPEN
1345 flag directly,
1346 instead of both on the same connection.
1348 Here is the typical call flow with this new option:
1350 .in +4n
1352 s = socket();
1353 setsockopt(s, IPPROTO_TCP, TCP_FASTOPEN_CONNECT, 1, ...);
1354 connect(s);
1355 write(s); /* write() should always follow connect()
1356            * in order to trigger SYN to go out. */
1357 read(s)/write(s);
1358 /* ... */
1359 close(s);
1362 .SS Sockets API
1363 TCP provides limited support for out-of-band data,
1364 in the form of (a single byte of) urgent data.
1365 In Linux this means if the other end sends newer out-of-band
1366 data the older urgent data is inserted as normal data into
1367 the stream (even when
1368 .B SO_OOBINLINE
1369 is not set).
1370 This differs from BSD-based stacks.
1372 Linux uses the BSD compatible interpretation of the urgent
1373 pointer field by default.
1374 This violates RFC\ 1122, but is
1375 required for interoperability with other stacks.
1376 It can be changed via
1377 .IR /proc/sys/net/ipv4/tcp_stdurg .
1379 It is possible to peek at out-of-band data using the
1380 .BR recv (2)
1381 .B MSG_PEEK
1382 flag.
1384 Since Linux 2.4, Linux supports the use of
1385 .B MSG_TRUNC
1386 in the
1387 .I flags
1388 argument of
1389 .BR recv (2)
1390 (and
1391 .BR recvmsg (2)).
1392 This flag causes the received bytes of data to be discarded,
1393 rather than passed back in a caller-supplied buffer.
1394 Since Linux 2.4.4,
1395 .B MSG_TRUNC
1396 also has this effect when used in conjunction with
1397 .B MSG_OOB
1398 to receive out-of-band data.
1399 .SS Ioctls
1400 The following
1401 .BR ioctl (2)
1402 calls return information in
1403 .IR value .
1404 The correct syntax is:
1408 .BI int " value";
1409 .IB error " = ioctl(" tcp_socket ", " ioctl_type ", &" value ");"
1413 .I ioctl_type
1414 is one of the following:
1416 .B SIOCINQ
1417 Returns the amount of queued unread data in the receive buffer.
1418 The socket must not be in LISTEN state, otherwise an error
1419 .RB ( EINVAL )
1420 is returned.
1421 .B SIOCINQ
1422 is defined in
1423 .IR <linux/sockios.h> .
1424 .\" FIXME https://www.sourceware.org/bugzilla/show_bug.cgi?id=12002,
1425 .\" filed 2010-09-10, may cause SIOCINQ to be defined in glibc headers
1426 Alternatively,
1427 you can use the synonymous
1428 .BR FIONREAD ,
1429 defined in
1430 .IR <sys/ioctl.h> .
1432 .B SIOCATMARK
1433 Returns true (i.e.,
1434 .I value
1435 is nonzero) if the inbound data stream is at the urgent mark.
1437 If the
1438 .B SO_OOBINLINE
1439 socket option is set, and
1440 .B SIOCATMARK
1441 returns true, then the
1442 next read from the socket will return the urgent data.
1443 If the
1444 .B SO_OOBINLINE
1445 socket option is not set, and
1446 .B SIOCATMARK
1447 returns true, then the
1448 next read from the socket will return the bytes following
1449 the urgent data (to actually read the urgent data requires the
1450 .B recv(MSG_OOB)
1451 flag).
1453 Note that a read never reads across the urgent mark.
1454 If an application is informed of the presence of urgent data via
1455 .BR select (2)
1456 (using the
1457 .I exceptfds
1458 argument) or through delivery of a
1459 .B SIGURG
1460 signal,
1461 then it can advance up to the mark using a loop which repeatedly tests
1462 .B SIOCATMARK
1463 and performs a read (requesting any number of bytes) as long as
1464 .B SIOCATMARK
1465 returns false.
1467 .B SIOCOUTQ
1468 Returns the amount of unsent data in the socket send queue.
1469 The socket must not be in LISTEN state, otherwise an error
1470 .RB ( EINVAL )
1471 is returned.
1472 .B SIOCOUTQ
1473 is defined in
1474 .IR <linux/sockios.h> .
1475 .\" FIXME . https://www.sourceware.org/bugzilla/show_bug.cgi?id=12002,
1476 .\" filed 2010-09-10, may cause SIOCOUTQ to be defined in glibc headers
1477 Alternatively,
1478 you can use the synonymous
1479 .BR TIOCOUTQ ,
1480 defined in
1481 .IR <sys/ioctl.h> .
1482 .SS Error handling
1483 When a network error occurs, TCP tries to resend the packet.
1484 If it doesn't succeed after some time, either
1485 .B ETIMEDOUT
1486 or the last received error on this connection is reported.
1488 Some applications require a quicker error notification.
1489 This can be enabled with the
1490 .B IPPROTO_IP
1491 level
1492 .B IP_RECVERR
1493 socket option.
1494 When this option is enabled, all incoming
1495 errors are immediately passed to the user program.
1496 Use this option with care \[em] it makes TCP less tolerant to routing
1497 changes and other normal network conditions.
1498 .SH ERRORS
1500 .B EAFNOTSUPPORT
1501 Passed socket address type in
1502 .I sin_family
1503 was not
1504 .BR AF_INET .
1506 .B EPIPE
1507 The other end closed the socket unexpectedly or a read is
1508 executed on a shut down socket.
1510 .B ETIMEDOUT
1511 The other end didn't acknowledge retransmitted data after some time.
1513 Any errors defined for
1514 .BR ip (7)
1515 or the generic socket layer may also be returned for TCP.
1516 .SH VERSIONS
1517 Support for Explicit Congestion Notification, zero-copy
1518 .BR sendfile (2),
1519 reordering support and some SACK extensions
1520 (DSACK) were introduced in Linux 2.4.
1521 Support for forward acknowledgement (FACK), TIME_WAIT recycling,
1522 and per-connection keepalive socket options were introduced in Linux 2.3.
1523 .SH BUGS
1524 Not all errors are documented.
1526 IPv6 is not described.
1527 .\" Only a single Linux kernel version is described
1528 .\" Info for 2.2 was lost. Should be added again,
1529 .\" or put into a separate page.
1530 .\" .SH AUTHORS
1531 .\" This man page was originally written by Andi Kleen.
1532 .\" It was updated for 2.4 by Nivedita Singhvi with input from
1533 .\" Alexey Kuznetsov's Documentation/networking/ip-sysctl.txt
1534 .\" document.
1535 .SH SEE ALSO
1536 .BR accept (2),
1537 .BR bind (2),
1538 .BR connect (2),
1539 .BR getsockopt (2),
1540 .BR listen (2),
1541 .BR recvmsg (2),
1542 .BR sendfile (2),
1543 .BR sendmsg (2),
1544 .BR socket (2),
1545 .BR ip (7),
1546 .BR socket (7)
1548 The kernel source file
1549 .IR Documentation/networking/ip\-sysctl.txt .
1551 RFC\ 793 for the TCP specification.
1553 RFC\ 1122 for the TCP requirements and a description of the Nagle algorithm.
1555 RFC\ 1323 for TCP timestamp and window scaling options.
1557 RFC\ 1337 for a description of TIME_WAIT assassination hazards.
1559 RFC\ 3168 for a description of Explicit Congestion Notification.
1561 RFC\ 2581 for TCP congestion control algorithms.
1563 RFC\ 2018 and RFC\ 2883 for SACK and extensions to SACK.