OSDN Git Service

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