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