malloc.3: Clarify that realloc() may move the memory block
[man-pages.git] / man7 / tcp.7
blob0a7c61a373c7d9ecb2f1fafed8b46ff156a25872
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 2021-03-22 "Linux" "Linux Programmer's Manual"
97 .SH NAME
98 tcp \- TCP protocol
99 .SH SYNOPSIS
101 .B #include <sys/socket.h>
102 .B #include <netinet/in.h>
103 .B #include <netinet/tcp.h>
105 .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.
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)
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.
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
151 .I /proc/sys/net/ipv4/tcp_rmem
152 files, or on individual sockets by using the
153 .B SO_SNDBUF
155 .B SO_RCVBUF
156 socket options with the
157 .BR setsockopt (2)
158 call.
160 The maximum sizes for socket buffers declared via the
161 .B SO_SNDBUF
163 .B SO_RCVBUF
164 mechanisms are limited by the values in the
165 .I /proc/sys/net/core/rmem_max
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)
185 .BR connect (2)
186 calls in order to have it take effect.
188 .BR socket (7)
189 for more information.
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
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)
221 .BR recvmsg (2).
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.
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.
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 acknowledgements.
268 Possible values are:
270 .IP 0 3
271 increase
272 .I cwnd
273 once per acknowledgement (no ABC)
274 .IP 1
275 increase
276 .I cwnd
277 once per acknowledgement of full sized segment
278 .IP 2
279 allow increase
280 .I cwnd
281 by two if acknowledgement is
282 of two segments to compensate for delayed acknowledgements.
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.
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" ,
302 .I tcp_adv_win_scale
303 is greater than 0; or
304 .IR "bytes\-bytes/2^(\-tcp_adv_win_scale)" ,
306 .I tcp_adv_win_scale
307 is less than or equal to zero.
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.
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.
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 .
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)
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.
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.
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.
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.
372 .\" The following is from 2.6.28-rc4: Documentation/networking/ip-sysctl.txt
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.
381 .\" The following is from 2.6.12: Documentation/networking/ip-sysctl.txt
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.
395 .\" The following is from 2.6.12: Documentation/networking/ip-sysctl.txt
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.
402 .\" The following is from 2.6.12: Documentation/networking/ip-sysctl.txt
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.
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.
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.
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.
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.
430 This file can have one of the following values:
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.
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.
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.
461 .IR tcp_fack " (Boolean; default: enabled; since Linux 2.2)"
462 .\" Since 2.1.92
463 Enable TCP Forward Acknowledgement support.
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.
473 .\" The following is from 2.6.12: Documentation/networking/ip-sysctl.txt
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.
484 This file can have one of the following values:
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.
500 Before Linux 2.6.22, this parameter was a Boolean value,
501 supporting just values 0 and 1 above.
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:
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
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
531 .I ssthresh
532 are restored to the values prior to timeout.
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.
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.
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.
557 Note that underlying connection tracking mechanisms and
558 application timeouts may be much shorter.
560 .\" The following is from 2.6.12: Documentation/networking/ip-sysctl.txt
562 .IR tcp_low_latency  " (Boolean; default: disabled; since Linux 2.4.21/2.6; \
563 obsolete since Linux 4.14)"
564 .\" Since 2.4.21/2.5.60
565 If enabled, the TCP stack makes decisions that prefer lower
566 latency as opposed to higher throughput.
567 It this option is disabled, then higher throughput is preferred.
568 An example of an application where this default should be
569 changed would be a Beowulf compute cluster.
570 Since Linux 4.14,
571 .\" commit b6690b14386698ce2c19309abad3f17656bdfaea
572 this file still exists, but its value is ignored.
574 .IR tcp_max_orphans  " (integer; default: see below; since Linux 2.4)"
575 .\" Since 2.3.41
576 The maximum number of orphaned (not attached to any user file
577 handle) TCP sockets allowed in the system.
578 When this number is exceeded,
579 the orphaned connection is reset and a warning is printed.
580 This limit exists only to prevent simple denial-of-service attacks.
581 Lowering this limit is not recommended.
582 Network conditions might require you to increase the number of
583 orphans allowed, but note that each orphan can eat up to \(ti64\ kB
584 of unswappable memory.
585 The default initial value is set equal to the kernel parameter NR_FILE.
586 This initial default is adjusted depending on the memory in the system.
588 .IR tcp_max_syn_backlog " (integer; default: see below; since Linux 2.2)"
589 .\" Since 2.1.53
590 The maximum number of queued connection requests which have
591 still not received an acknowledgement from the connecting client.
592 If this number is exceeded, the kernel will begin
593 dropping requests.
594 The default value of 256 is increased to
595 1024 when the memory present in the system is adequate or
596 greater (>= 128\ MB), and reduced to 128 for those systems with
597 very low memory (<= 32\ MB).
599 Prior to Linux 2.6.20,
600 .\" commit 72a3effaf633bcae9034b7e176bdbd78d64a71db
601 it was recommended that if this needed to be increased above 1024,
602 the size of the SYNACK hash table
603 .RB ( TCP_SYNQ_HSIZE )
605 .I include/net/tcp.h
606 should be modified to keep
608     TCP_SYNQ_HSIZE * 16 <= tcp_max_syn_backlog
610 and the kernel should be
611 recompiled.
612 In Linux 2.6.20, the fixed sized
613 .B TCP_SYNQ_HSIZE
614 was removed in favor of dynamic sizing.
616 .IR tcp_max_tw_buckets " (integer; default: see below; since Linux 2.4)"
617 .\" Since 2.3.41
618 The maximum number of sockets in TIME_WAIT state allowed in
619 the system.
620 This limit exists only to prevent simple denial-of-service attacks.
621 The default value of NR_FILE*2 is adjusted
622 depending on the memory in the system.
623 If this number is
624 exceeded, the socket is closed and a warning is printed.
626 .IR tcp_moderate_rcvbuf " (Boolean; default: enabled; since Linux 2.4.17/2.6.7)"
627 .\" The following is from 2.6.28-rc4: Documentation/networking/ip-sysctl.txt
628 If enabled, TCP performs receive buffer auto-tuning,
629 attempting to automatically size the buffer (no greater than
630 .IR tcp_rmem[2] )
631 to match the size required by the path for full throughput.
633 .IR tcp_mem " (since Linux 2.4)"
634 .\" Since 2.4.0-test7
635 This is a vector of 3 integers: [low, pressure, high].
636 These bounds, measured in units of the system page size,
637 are used by TCP to track its memory usage.
638 The defaults are calculated at boot time from the amount of
639 available memory.
640 (TCP can only use
641 .I "low memory"
642 for this, which is limited to around 900 megabytes on 32-bit systems.
643 64-bit systems do not suffer this limitation.)
646 .I low
647 TCP doesn't regulate its memory allocation when the number
648 of pages it has allocated globally is below this number.
650 .I pressure
651 When the amount of memory allocated by TCP
652 exceeds this number of pages, TCP moderates its memory consumption.
653 This memory pressure state is exited
654 once the number of pages allocated falls below
656 .I low
657 mark.
659 .I high
660 The maximum number of pages, globally, that TCP will allocate.
661 This value overrides any other limits imposed by the kernel.
664 .IR tcp_mtu_probing " (integer; default: 0; since Linux 2.6.17)"
665 .\" The following is from 2.6.28-rc4: Documentation/networking/ip-sysctl.txt
666 This parameter controls TCP Packetization-Layer Path MTU Discovery.
667 The following values may be assigned to the file:
669 .IP 0 3
670 Disabled
671 .IP 1
672 Disabled by default, enabled when an ICMP black hole detected
673 .IP 2
674 Always enabled, use initial MSS of
675 .IR tcp_base_mss .
678 .IR tcp_no_metrics_save " (Boolean; default: disabled; since Linux 2.6.6)"
679 .\" The following is from 2.6.28-rc4: Documentation/networking/ip-sysctl.txt
680 By default, TCP saves various connection metrics in the route cache
681 when the connection closes, so that connections established in the
682 near future can use these to set initial conditions.
683 Usually, this increases overall performance,
684 but it may sometimes cause performance degradation.
686 .I tcp_no_metrics_save
687 is enabled, TCP will not cache metrics on closing connections.
689 .IR tcp_orphan_retries " (integer; default: 8; since Linux 2.4)"
690 .\" Since 2.3.41
691 The maximum number of attempts made to probe the other
692 end of a connection which has been closed by our end.
694 .IR tcp_reordering " (integer; default: 3; since Linux 2.4)"
695 .\" Since 2.4.0-test7
696 The maximum a packet can be reordered in a TCP packet stream
697 without TCP assuming packet loss and going into slow start.
698 It is not advisable to change this number.
699 This is a packet reordering detection metric designed to
700 minimize unnecessary back off and retransmits provoked by
701 reordering of packets on a connection.
703 .IR tcp_retrans_collapse " (Boolean; default: enabled; since Linux 2.2)"
704 .\" Since 2.1.96
705 Try to send full-sized packets during retransmit.
707 .IR tcp_retries1 " (integer; default: 3; since Linux 2.2)"
708 .\" Since 2.1.43
709 The number of times TCP will attempt to retransmit a
710 packet on an established connection normally,
711 without the extra effort of getting the network layers involved.
712 Once we exceed this number of
713 retransmits, we first have the network layer
714 update the route if possible before each new retransmit.
715 The default is the RFC specified minimum of 3.
717 .IR tcp_retries2 " (integer; default: 15; since Linux 2.2)"
718 .\" Since 2.1.43
719 The maximum number of times a TCP packet is retransmitted
720 in established state before giving up.
721 The default value is 15, which corresponds to a duration of
722 approximately between 13 to 30 minutes, depending
723 on the retransmission timeout.
724 The RFC\ 1122 specified
725 minimum limit of 100 seconds is typically deemed too short.
727 .IR tcp_rfc1337 " (Boolean; default: disabled; since Linux 2.2)"
728 .\" Since 2.1.90
729 Enable TCP behavior conformant with RFC\ 1337.
730 When disabled,
731 if a RST is received in TIME_WAIT state, we close
732 the socket immediately without waiting for the end
733 of the TIME_WAIT period.
735 .IR tcp_rmem " (since Linux 2.4)"
736 .\" Since 2.4.0-test7
737 This is a vector of 3 integers: [min, default, max].
738 These parameters are used by TCP to regulate receive buffer sizes.
739 TCP dynamically adjusts the size of the
740 receive buffer from the defaults listed below, in the range
741 of these values, depending on memory available in the system.
744 .I min
745 minimum size of the receive buffer used by each TCP socket.
746 The default value is the system page size.
747 (On Linux 2.4, the default value is 4\ kB, lowered to
748 .B PAGE_SIZE
749 bytes in low-memory systems.)
750 This value
751 is used to ensure that in memory pressure mode,
752 allocations below this size will still succeed.
753 This is not
754 used to bound the size of the receive buffer declared
755 using
756 .B SO_RCVBUF
757 on a socket.
759 .I default
760 the default size of the receive buffer for a TCP socket.
761 This value overwrites the initial default buffer size from
762 the generic global
763 .I net.core.rmem_default
764 defined for all protocols.
765 The default value is 87380 bytes.
766 (On Linux 2.4, this will be lowered to 43689 in low-memory systems.)
767 If larger receive buffer sizes are desired, this value should
768 be increased (to affect all sockets).
769 To employ large TCP windows, the
770 .I net.ipv4.tcp_window_scaling
771 must be enabled (default).
773 .I max
774 the maximum size of the receive buffer used by each TCP socket.
775 This value does not override the global
776 .IR net.core.rmem_max .
777 This is not used to limit the size of the receive buffer declared using
778 .B SO_RCVBUF
779 on a socket.
780 The default value is calculated using the formula
782     max(87380, min(4\ MB, \fItcp_mem\fP[1]*PAGE_SIZE/128))
784 (On Linux 2.4, the default is 87380*2 bytes,
785 lowered to 87380 in low-memory systems).
788 .IR tcp_sack " (Boolean; default: enabled; since Linux 2.2)"
789 .\" Since 2.1.36
790 Enable RFC\ 2018 TCP Selective Acknowledgements.
792 .IR tcp_slow_start_after_idle " (Boolean; default: enabled; since Linux 2.6.18)"
793 .\" The following is from 2.6.28-rc4: Documentation/networking/ip-sysctl.txt
794 If enabled, provide RFC 2861 behavior and time out the congestion
795 window after an idle period.
796 An idle period is defined as the current RTO (retransmission timeout).
797 If disabled, the congestion window will not
798 be timed out after an idle period.
800 .IR tcp_stdurg " (Boolean; default: disabled; since Linux 2.2)"
801 .\" Since 2.1.44
802 If this option is enabled, then use the RFC\ 1122 interpretation
803 of the TCP urgent-pointer field.
804 .\" RFC 793 was ambiguous in its specification of the meaning of the
805 .\" urgent pointer.  RFC 1122 (and RFC 961) fixed on a particular
806 .\" resolution of this ambiguity (unfortunately the "wrong" one).
807 According to this interpretation, the urgent pointer points
808 to the last byte of urgent data.
809 If this option is disabled, then use the BSD-compatible interpretation of
810 the urgent pointer:
811 the urgent pointer points to the first byte after the urgent data.
812 Enabling this option may lead to interoperability problems.
814 .IR tcp_syn_retries  " (integer; default: 6; since Linux 2.2)"
815 .\" Since 2.1.38
816 The maximum number of times initial SYNs for an active TCP
817 connection attempt will be retransmitted.
818 This value should not be higher than 255.
819 The default value is 6, which corresponds to retrying for up to
820 approximately 127 seconds.
821 Before Linux 3.7,
822 .\" commit 6c9ff979d1921e9fd05d89e1383121c2503759b9
823 the default value was 5, which
824 (in conjunction with calculation based on other kernel parameters)
825 corresponded to approximately 180 seconds.
827 .IR tcp_synack_retries " (integer; default: 5; since Linux 2.2)"
828 .\" Since 2.1.38
829 The maximum number of times a SYN/ACK segment
830 for a passive TCP connection will be retransmitted.
831 This number should not be higher than 255.
833 .IR tcp_syncookies " (integer; default: 1; since Linux 2.2)"
834 .\" Since 2.1.43
835 Enable TCP syncookies.
836 The kernel must be compiled with
837 .BR CONFIG_SYN_COOKIES .
838 The syncookies feature attempts to protect a
839 socket from a SYN flood attack.
840 This should be used as a last resort, if at all.
841 This is a violation of the TCP protocol,
842 and conflicts with other areas of TCP such as TCP extensions.
843 It can cause problems for clients and relays.
844 It is not recommended as a tuning mechanism for heavily
845 loaded servers to help with overloaded or misconfigured conditions.
846 For recommended alternatives see
847 .IR tcp_max_syn_backlog ,
848 .IR tcp_synack_retries ,
850 .IR tcp_abort_on_overflow .
851 Set to one of the following values:
853 .IP 0 3
854 Disable TCP syncookies.
855 .IP 1
856 Send out syncookies when the syn backlog queue of a socket overflows.
857 .IP 2
858 (since Linux 3.12)
859 .\" commit 5ad37d5deee1ff7150a2d0602370101de158ad86
860 Send out syncookies unconditionally.
861 This can be useful for network testing.
864 .IR tcp_timestamps " (integer; default: 1; since Linux 2.2)"
865 .\" Since 2.1.36
866 Set to one of the following values to enable or disable RFC\ 1323
867 TCP timestamps:
869 .IP 0 3
870 Disable timestamps.
871 .IP 1
872 Enable timestamps as defined in RFC1323 and use random offset for
873 each connection rather than only using the current time.
874 .IP 2
875 As for the value 1, but without random offsets.
876 .\" commit 25429d7b7dca01dc4f17205de023a30ca09390d0
877 Setting
878 .I tcp_timestamps
879 to this value is meaningful since Linux 4.10.
882 .IR tcp_tso_win_divisor " (integer; default: 3; since Linux 2.6.9)"
883 This parameter controls what percentage of the congestion window
884 can be consumed by a single TCP Segmentation Offload (TSO) frame.
885 The setting of this parameter is a tradeoff between burstiness and
886 building larger TSO frames.
888 .IR tcp_tw_recycle " (Boolean; default: disabled; Linux 2.4 to 4.11)"
889 .\" Since 2.3.15
890 .\" removed in 4.12; commit 4396e46187ca5070219b81773c4e65088dac50cc
891 Enable fast recycling of TIME_WAIT sockets.
892 Enabling this option is
893 not recommended as the remote IP may not use monotonically increasing
894 timestamps (devices behind NAT, devices with per-connection timestamp
895 offsets).
896 See RFC 1323 (PAWS) and RFC 6191.
898 .\" The following is from 2.6.12: Documentation/networking/ip-sysctl.txt
900 .IR tcp_tw_reuse " (Boolean; default: disabled; since Linux 2.4.19/2.6)"
901 .\" Since 2.4.19/2.5.43
902 Allow to reuse TIME_WAIT sockets for new connections when it is
903 safe from protocol viewpoint.
904 It should not be changed without advice/request of technical experts.
906 .\" The following is from 2.6.12: Documentation/networking/ip-sysctl.txt
908 .IR tcp_vegas_cong_avoid  " (Boolean; default: disabled; Linux 2.2 to 2.6.13)"
909 .\" Since 2.1.8; removed in 2.6.13
910 Enable TCP Vegas congestion avoidance algorithm.
911 TCP Vegas is a sender-side-only change to TCP that anticipates
912 the onset of congestion by estimating the bandwidth.
913 TCP Vegas adjusts the sending rate by modifying the congestion window.
914 TCP Vegas should provide less packet loss, but it is
915 not as aggressive as TCP Reno.
917 .\" The following is from 2.6.12: Documentation/networking/ip-sysctl.txt
919 .IR tcp_westwood " (Boolean; default: disabled; Linux 2.4.26/2.6.3 to 2.6.13)"
920 Enable TCP Westwood+ congestion control algorithm.
921 TCP Westwood+ is a sender-side-only modification of the TCP Reno
922 protocol stack that optimizes the performance of TCP congestion control.
923 It is based on end-to-end bandwidth estimation to set
924 congestion window and slow start threshold after a congestion episode.
925 Using this estimation, TCP Westwood+ adaptively sets a
926 slow start threshold and a congestion window which takes into
927 account the bandwidth used at the time congestion is experienced.
928 TCP Westwood+ significantly increases fairness with respect to
929 TCP Reno in wired networks and throughput over wireless links.
931 .IR tcp_window_scaling " (Boolean; default: enabled; since Linux 2.2)"
932 .\" Since 2.1.36
933 Enable RFC\ 1323 TCP window scaling.
934 This feature allows the use of a large window
935 (> 64\ kB) on a TCP connection, should the other end support it.
936 Normally, the 16 bit window length field in the TCP header
937 limits the window size to less than 64\ kB.
938 If larger windows are desired, applications can increase the size of
939 their socket buffers and the window scaling option will be employed.
941 .I tcp_window_scaling
942 is disabled, TCP will not negotiate the use of window
943 scaling with the other end during connection setup.
945 .IR tcp_wmem " (since Linux 2.4)"
946 .\" Since 2.4.0-test7
947 This is a vector of 3 integers: [min, default, max].
948 These parameters are used by TCP to regulate send buffer sizes.
949 TCP dynamically adjusts the size of the send buffer from the
950 default values listed below, in the range of these values,
951 depending on memory available.
954 .I min
955 Minimum size of the send buffer used by each TCP socket.
956 The default value is the system page size.
957 (On Linux 2.4, the default value is 4\ kB.)
958 This value is used to ensure that in memory pressure mode,
959 allocations below this size will still succeed.
960 This is not used to bound the size of the send buffer declared using
961 .B SO_SNDBUF
962 on a socket.
964 .I default
965 The default size of the send buffer for a TCP socket.
966 This value overwrites the initial default buffer size from
967 the generic global
968 .I /proc/sys/net/core/wmem_default
969 defined for all protocols.
970 The default value is 16\ kB.
971 .\" True in Linux 2.4 and 2.6
972 If larger send buffer sizes are desired, this value
973 should be increased (to affect all sockets).
974 To employ large TCP windows, the
975 .I /proc/sys/net/ipv4/tcp_window_scaling
976 must be set to a nonzero value (default).
978 .I max
979 The maximum size of the send buffer used by each TCP socket.
980 This value does not override the value in
981 .IR /proc/sys/net/core/wmem_max .
982 This is not used to limit the size of the send buffer declared using
983 .B SO_SNDBUF
984 on a socket.
985 The default value is calculated using the formula
987     max(65536, min(4\ MB, \fItcp_mem\fP[1]*PAGE_SIZE/128))
989 (On Linux 2.4, the default value is 128\ kB,
990 lowered 64\ kB depending on low-memory systems.)
993 .IR tcp_workaround_signed_windows " (Boolean; default: disabled; since Linux 2.6.26)"
994 If enabled, assume that no receipt of a window-scaling option means that the
995 remote TCP is broken and treats the window as a signed quantity.
996 If disabled, assume that the remote TCP is not broken even if we do
997 not receive a window scaling option from it.
998 .SS Socket options
999 To set or get a TCP socket option, call
1000 .BR getsockopt (2)
1001 to read or
1002 .BR setsockopt (2)
1003 to write the option with the option level argument set to
1004 .BR IPPROTO_TCP .
1005 Unless otherwise noted,
1006 .I optval
1007 is a pointer to an
1008 .IR int .
1009 .\" or SOL_TCP on Linux
1010 In addition,
1011 most
1012 .B IPPROTO_IP
1013 socket options are valid on TCP sockets.
1014 For more information see
1015 .BR ip (7).
1017 Following is a list of TCP-specific socket options.
1018 For details of some other socket options that are also applicable
1019 for TCP sockets, see
1020 .BR socket (7).
1022 .BR TCP_CONGESTION " (since Linux 2.6.13)"
1023 .\"         commit 5f8ef48d240963093451bcf83df89f1a1364f51d
1024 .\"         Author: Stephen Hemminger <shemminger@osdl.org>
1025 The argument for this option is a string.
1026 This option allows the caller to set the TCP congestion control
1027 algorithm to be used, on a per-socket basis.
1028 Unprivileged processes are restricted to choosing one of the algorithms in
1029 .IR tcp_allowed_congestion_control
1030 (described above).
1031 Privileged processes
1032 .RB ( CAP_NET_ADMIN )
1033 can choose from any of the available congestion-control algorithms
1034 (see the description of
1035 .IR tcp_available_congestion_control
1036 above).
1038 .BR TCP_CORK " (since Linux 2.2)"
1039 .\" precisely: since 2.1.127
1040 If set, don't send out partial frames.
1041 All queued partial frames are sent when the option is cleared again.
1042 This is useful for prepending headers before calling
1043 .BR sendfile (2),
1044 or for throughput optimization.
1045 As currently implemented, there is a 200 millisecond ceiling on the time
1046 for which output is corked by
1047 .BR TCP_CORK .
1048 If this ceiling is reached, then queued data is automatically transmitted.
1049 This option can be combined with
1050 .B TCP_NODELAY
1051 only since Linux 2.5.71.
1052 This option should not be used in code intended to be portable.
1054 .BR TCP_DEFER_ACCEPT " (since Linux 2.4)"
1055 .\" Precisely: since 2.3.38
1056 .\" Useful references:
1057 .\" http://www.techrepublic.com/article/take-advantage-of-tcp-ip-options-to-optimize-data-transmission/
1058 .\" http://unix.stackexchange.com/questions/94104/real-world-use-of-tcp-defer-accept
1059 Allow a listener to be awakened only when data arrives on the socket.
1060 Takes an integer value (seconds), this can
1061 bound the maximum number of attempts TCP will make to
1062 complete the connection.
1063 This option should not be used in code intended to be portable.
1065 .BR TCP_INFO " (since Linux 2.4)"
1066 Used to collect information about this socket.
1067 The kernel returns a \fIstruct tcp_info\fP as defined in the file
1068 .IR /usr/include/linux/tcp.h .
1069 This option should not be used in code intended to be portable.
1071 .BR TCP_KEEPCNT " (since Linux 2.4)"
1072 .\" Precisely: since 2.3.18
1073 The maximum number of keepalive probes TCP should send
1074 before dropping the connection.
1075 This option should not be
1076 used in code intended to be portable.
1078 .BR TCP_KEEPIDLE " (since Linux 2.4)"
1079 .\" Precisely: since 2.3.18
1080 The time (in seconds) the connection needs to remain idle
1081 before TCP starts sending keepalive probes, if the socket
1082 option
1083 .B SO_KEEPALIVE
1084 has been set on this socket.
1085 This option should not be used in code intended to be portable.
1087 .BR TCP_KEEPINTVL " (since Linux 2.4)"
1088 .\" Precisely: since 2.3.18
1089 The time (in seconds) between individual keepalive probes.
1090 This option should not be used in code intended to be portable.
1092 .BR TCP_LINGER2 " (since Linux 2.4)"
1093 .\" Precisely: since 2.3.41
1094 The lifetime of orphaned FIN_WAIT2 state sockets.
1095 This option can be used to override the system-wide setting in the file
1096 .I /proc/sys/net/ipv4/tcp_fin_timeout
1097 for this socket.
1098 This is not to be confused with the
1099 .BR socket (7)
1100 level option
1101 .BR SO_LINGER .
1102 This option should not be used in code intended to be portable.
1104 .B TCP_MAXSEG
1105 .\" Present in Linux 1.0
1106 The maximum segment size for outgoing TCP packets.
1107 In Linux 2.2 and earlier, and in Linux 2.6.28 and later,
1108 if this option is set before connection establishment, it also
1109 changes the MSS value announced to the other end in the initial packet.
1110 Values greater than the (eventual) interface MTU have no effect.
1111 TCP will also impose
1112 its minimum and maximum bounds over the value provided.
1114 .B TCP_NODELAY
1115 .\" Present in Linux 1.0
1116 If set, disable the Nagle algorithm.
1117 This means that segments
1118 are always sent as soon as possible, even if there is only a
1119 small amount of data.
1120 When not set, data is buffered until there
1121 is a sufficient amount to send out, thereby avoiding the
1122 frequent sending of small packets, which results in poor
1123 utilization of the network.
1124 This option is overridden by
1125 .BR TCP_CORK ;
1126 however, setting this option forces an explicit flush of
1127 pending output, even if
1128 .B TCP_CORK
1129 is currently set.
1131 .BR TCP_QUICKACK " (since Linux 2.4.4)"
1132 Enable quickack mode if set or disable quickack
1133 mode if cleared.
1134 In quickack mode, acks are sent
1135 immediately, rather than delayed if needed in accordance
1136 to normal TCP operation.
1137 This flag is not permanent,
1138 it only enables a switch to or from quickack mode.
1139 Subsequent operation of the TCP protocol will
1140 once again enter/leave quickack mode depending on
1141 internal protocol processing and factors such as
1142 delayed ack timeouts occurring and data transfer.
1143 This option should not be used in code intended to be
1144 portable.
1146 .BR TCP_SYNCNT " (since Linux 2.4)"
1147 .\" Precisely: since 2.3.18
1148 Set the number of SYN retransmits that TCP should send before
1149 aborting the attempt to connect.
1150 It cannot exceed 255.
1151 This option should not be used in code intended to be portable.
1153 .BR TCP_USER_TIMEOUT " (since Linux 2.6.37)"
1154 .\"         commit dca43c75e7e545694a9dd6288553f55c53e2a3a3
1155 .\"         Author: Jerry Chu <hkchu@google.com>
1156 .\" The following text taken nearly verbatim from Jerry Chu's (excellent)
1157 .\" commit message.
1159 This option takes an
1160 .IR "unsigned int"
1161 as an argument.
1162 When the value is greater than 0,
1163 it specifies the maximum amount of time in milliseconds that transmitted
1164 data may remain unacknowledged, or bufferred data may remain untransmitted
1165 (due to zero window size) before TCP will forcibly close the
1166 corresponding connection and return
1167 .B ETIMEDOUT
1168 to the application.
1169 If the option value is specified as 0,
1170 TCP will use the system default.
1172 Increasing user timeouts allows a TCP connection to survive extended
1173 periods without end-to-end connectivity.
1174 Decreasing user timeouts
1175 allows applications to "fail fast", if so desired.
1176 Otherwise, failure may take up to 20 minutes with
1177 the current system defaults in a normal WAN environment.
1179 This option can be set during any state of a TCP connection,
1180 but is effective only during the synchronized states of a connection
1181 (ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, and LAST-ACK).
1182 Moreover, when used with the TCP keepalive
1183 .RB ( SO_KEEPALIVE )
1184 option,
1185 .B TCP_USER_TIMEOUT
1186 will override keepalive to determine when to close a
1187 connection due to keepalive failure.
1189 The option has no effect on when TCP retransmits a packet,
1190 nor when a keepalive probe is sent.
1192 This option, like many others, will be inherited by the socket returned by
1193 .BR accept (2),
1194 if it was set on the listening socket.
1196 Further details on the user timeout feature can be found in
1197 RFC\ 793 and RFC\ 5482 ("TCP User Timeout Option").
1199 .BR TCP_WINDOW_CLAMP " (since Linux 2.4)"
1200 .\" Precisely: since 2.3.41
1201 Bound the size of the advertised window to this value.
1202 The kernel imposes a minimum size of SOCK_MIN_RCVBUF/2.
1203 This option should not be used in code intended to be
1204 portable.
1205 .SS Sockets API
1206 TCP provides limited support for out-of-band data,
1207 in the form of (a single byte of) urgent data.
1208 In Linux this means if the other end sends newer out-of-band
1209 data the older urgent data is inserted as normal data into
1210 the stream (even when
1211 .B SO_OOBINLINE
1212 is not set).
1213 This differs from BSD-based stacks.
1215 Linux uses the BSD compatible interpretation of the urgent
1216 pointer field by default.
1217 This violates RFC\ 1122, but is
1218 required for interoperability with other stacks.
1219 It can be changed via
1220 .IR /proc/sys/net/ipv4/tcp_stdurg .
1222 It is possible to peek at out-of-band data using the
1223 .BR recv (2)
1224 .B MSG_PEEK
1225 flag.
1227 Since version 2.4, Linux supports the use of
1228 .B MSG_TRUNC
1229 in the
1230 .I flags
1231 argument of
1232 .BR recv (2)
1233 (and
1234 .BR recvmsg (2)).
1235 This flag causes the received bytes of data to be discarded,
1236 rather than passed back in a caller-supplied buffer.
1237 Since Linux 2.4.4,
1238 .BR MSG_TRUNC
1239 also has this effect when used in conjunction with
1240 .BR MSG_OOB
1241 to receive out-of-band data.
1242 .SS Ioctls
1243 The following
1244 .BR ioctl (2)
1245 calls return information in
1246 .IR value .
1247 The correct syntax is:
1251 .BI int " value";
1252 .IB error " = ioctl(" tcp_socket ", " ioctl_type ", &" value ");"
1256 .I ioctl_type
1257 is one of the following:
1259 .B SIOCINQ
1260 Returns the amount of queued unread data in the receive buffer.
1261 The socket must not be in LISTEN state, otherwise an error
1262 .RB ( EINVAL )
1263 is returned.
1264 .B SIOCINQ
1265 is defined in
1266 .IR <linux/sockios.h> .
1267 .\" FIXME http://sources.redhat.com/bugzilla/show_bug.cgi?id=12002,
1268 .\" filed 2010-09-10, may cause SIOCINQ to be defined in glibc headers
1269 Alternatively,
1270 you can use the synonymous
1271 .BR FIONREAD ,
1272 defined in
1273 .IR <sys/ioctl.h> .
1275 .B SIOCATMARK
1276 Returns true (i.e.,
1277 .I value
1278 is nonzero) if the inbound data stream is at the urgent mark.
1280 If the
1281 .B SO_OOBINLINE
1282 socket option is set, and
1283 .B SIOCATMARK
1284 returns true, then the
1285 next read from the socket will return the urgent data.
1286 If the
1287 .B SO_OOBINLINE
1288 socket option is not set, and
1289 .B SIOCATMARK
1290 returns true, then the
1291 next read from the socket will return the bytes following
1292 the urgent data (to actually read the urgent data requires the
1293 .B recv(MSG_OOB)
1294 flag).
1296 Note that a read never reads across the urgent mark.
1297 If an application is informed of the presence of urgent data via
1298 .BR select (2)
1299 (using the
1300 .I exceptfds
1301 argument) or through delivery of a
1302 .B SIGURG
1303 signal,
1304 then it can advance up to the mark using a loop which repeatedly tests
1305 .B SIOCATMARK
1306 and performs a read (requesting any number of bytes) as long as
1307 .B SIOCATMARK
1308 returns false.
1310 .B SIOCOUTQ
1311 Returns the amount of unsent data in the socket send queue.
1312 The socket must not be in LISTEN state, otherwise an error
1313 .RB ( EINVAL )
1314 is returned.
1315 .B SIOCOUTQ
1316 is defined in
1317 .IR <linux/sockios.h> .
1318 .\" FIXME . http://sources.redhat.com/bugzilla/show_bug.cgi?id=12002,
1319 .\" filed 2010-09-10, may cause SIOCOUTQ to be defined in glibc headers
1320 Alternatively,
1321 you can use the synonymous
1322 .BR TIOCOUTQ ,
1323 defined in
1324 .IR <sys/ioctl.h> .
1325 .SS Error handling
1326 When a network error occurs, TCP tries to resend the packet.
1327 If it doesn't succeed after some time, either
1328 .B ETIMEDOUT
1329 or the last received error on this connection is reported.
1331 Some applications require a quicker error notification.
1332 This can be enabled with the
1333 .B IPPROTO_IP
1334 level
1335 .B IP_RECVERR
1336 socket option.
1337 When this option is enabled, all incoming
1338 errors are immediately passed to the user program.
1339 Use this option with care \(em it makes TCP less tolerant to routing
1340 changes and other normal network conditions.
1341 .SH ERRORS
1343 .B EAFNOTSUPPORT
1344 Passed socket address type in
1345 .I sin_family
1346 was not
1347 .BR AF_INET .
1349 .B EPIPE
1350 The other end closed the socket unexpectedly or a read is
1351 executed on a shut down socket.
1353 .B ETIMEDOUT
1354 The other end didn't acknowledge retransmitted data after some time.
1356 Any errors defined for
1357 .BR ip (7)
1358 or the generic socket layer may also be returned for TCP.
1359 .SH VERSIONS
1360 Support for Explicit Congestion Notification, zero-copy
1361 .BR sendfile (2),
1362 reordering support and some SACK extensions
1363 (DSACK) were introduced in 2.4.
1364 Support for forward acknowledgement (FACK), TIME_WAIT recycling,
1365 and per-connection keepalive socket options were introduced in 2.3.
1366 .SH BUGS
1367 Not all errors are documented.
1369 IPv6 is not described.
1370 .\" Only a single Linux kernel version is described
1371 .\" Info for 2.2 was lost. Should be added again,
1372 .\" or put into a separate page.
1373 .\" .SH AUTHORS
1374 .\" This man page was originally written by Andi Kleen.
1375 .\" It was updated for 2.4 by Nivedita Singhvi with input from
1376 .\" Alexey Kuznetsov's Documentation/networking/ip-sysctl.txt
1377 .\" document.
1378 .SH SEE ALSO
1379 .BR accept (2),
1380 .BR bind (2),
1381 .BR connect (2),
1382 .BR getsockopt (2),
1383 .BR listen (2),
1384 .BR recvmsg (2),
1385 .BR sendfile (2),
1386 .BR sendmsg (2),
1387 .BR socket (2),
1388 .BR ip (7),
1389 .BR socket (7)
1391 The kernel source file
1392 .IR Documentation/networking/ip\-sysctl.txt .
1394 RFC\ 793 for the TCP specification.
1396 RFC\ 1122 for the TCP requirements and a description of the Nagle algorithm.
1398 RFC\ 1323 for TCP timestamp and window scaling options.
1400 RFC\ 1337 for a description of TIME_WAIT assassination hazards.
1402 RFC\ 3168 for a description of Explicit Congestion Notification.
1404 RFC\ 2581 for TCP congestion control algorithms.
1406 RFC\ 2018 and RFC\ 2883 for SACK and extensions to SACK.