Debian Codegraph @

upstream/opensuse-tumbleweed/man7/tcp.7

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