OSDN Git Service

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