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