]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man7/tcp.7
s/the the/the/
[thirdparty/man-pages.git] / man7 / tcp.7
CommitLineData
fea681da
MK
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>.
8dd9ef47
MK
8.\" Modified, 2004-11-11, Michael Kerrisk and Andries Brouwer
9.\" Updated details of interaction of TCP_CORK and TCP_NODELAY.
fea681da 10.\"
5c45d5f5 11.TH TCP 7 2005-06-15 "Linux Man Page" "Linux Programmer's Manual"
fea681da
MK
12.SH NAME
13tcp \- TCP protocol
14.SH SYNOPSIS
15.B #include <sys/socket.h>
16.br
17.B #include <netinet/in.h>
18.br
19.B #include <netinet/tcp.h>
20.br
21.B tcp_socket = socket(PF_INET, SOCK_STREAM, 0);
22.SH DESCRIPTION
23This is an implementation of the TCP protocol defined in
ccca85be 24RFC\ 793, RFC\ 1122 and RFC\ 2001 with the NewReno and SACK
fd1835be
MK
25extensions. It provides a reliable, stream-oriented,
26full-duplex connection between two sockets on top of
fea681da
MK
27.BR ip (7),
28for both v4 and v6 versions.
29TCP guarantees that the data arrives in order and
fd1835be
MK
30retransmits lost packets.
31It generates and checks a per-packet checksum to catch transmission errors.
32TCP does not preserve record boundaries.
fea681da 33
fd1835be 34A newly created TCP socket has no remote or local address and is not
fea681da
MK
35fully specified. To create an outgoing TCP connection use
36.BR connect (2)
37to establish a connection to another TCP socket.
fd1835be 38To receive new incoming connections, first
fea681da 39.BR bind (2)
fd1835be 40the socket to a local address and port and then call
fea681da 41.BR listen (2)
fd1835be 42to put the socket into the listening state. After that a new
fea681da
MK
43socket for each incoming connection can be accepted
44using
45.BR accept (2).
46A socket which has had
fd1835be 47.B accept()
fea681da 48or
fd1835be 49.B connect()
fea681da
MK
50successfully called on it is fully specified and may
51transmit data. Data cannot be transmitted on listening or
52not yet connected sockets.
53
ccca85be 54Linux supports RFC\ 1323 TCP high performance
fea681da
MK
55extensions. These include Protection Against Wrapped
56Sequence Numbers (PAWS), Window Scaling and
57Timestamps. Window scaling allows the use
58of large (> 64K) TCP windows in order to support links with high
59latency or bandwidth. To make use of them, the send and
60receive buffer sizes must be increased.
61They can be set globally with the
62.B net.ipv4.tcp_wmem
63and
64.B net.ipv4.tcp_rmem
65sysctl variables, or on individual sockets by using the
66.B SO_SNDBUF
67and
68.B SO_RCVBUF
69socket options with the
70.BR setsockopt (2)
71call.
72
73The maximum sizes for socket buffers declared via the
74.B SO_SNDBUF
75and
76.B SO_RCVBUF
77mechanisms are limited by the global
78.B net.core.rmem_max
79and
80.B net.core.wmem_max
81sysctls. Note that TCP actually allocates twice the size of
82the buffer requested in the
83.BR setsockopt (2)
84call, and so a succeeding
85.BR getsockopt (2)
86call will not return the same size of buffer as requested
87in the
88.BR setsockopt (2)
fd1835be 89call. TCP uses the extra space for administrative purposes and internal
fea681da
MK
90kernel structures, and the sysctl variables reflect the
91larger sizes compared to the actual TCP windows.
92On individual connections, the socket buffer size must be
93set prior to the
94.B listen()
95or
96.B connect()
97calls in order to have it take effect. See
98.BR socket (7)
99for more information.
100.PP
101TCP supports urgent data. Urgent data is used to signal the
102receiver that some important message is part of the data
103stream and that it should be processed as soon as possible.
104To send urgent data specify the
105.B MSG_OOB
106option to
107.BR send (2).
108When urgent data is received, the kernel sends a
109.B SIGURG
61f4934a 110signal to the process or process group that has been set as the
ccca85be 111socket "owner" using the
fea681da
MK
112.B SIOCSPGRP
113or
114.B FIOSETOWN
ccca85be
MK
115ioctls (or the SUSv3-specified
116.BR fcntl (2)
117.B F_SETOWN
118operation).
119When the
fea681da
MK
120.B SO_OOBINLINE
121socket option is enabled, urgent data is put into the normal
fd1835be 122data stream (a program can test for its location using the
fea681da 123.B SIOCATMARK
ccca85be 124ioctl described below),
fea681da
MK
125otherwise it can be only received when the
126.B MSG_OOB
127flag is set for
95d29ab2
MK
128.BR recv (2)
129or
130.BR recvmsg (2).
fea681da
MK
131
132Linux 2.4 introduced a number of changes for improved
133throughput and scaling, as well as enhanced functionality.
fd1835be 134Some of these features include support for zero-copy
fea681da
MK
135.BR sendfile (2),
136Explicit Congestion Notification, new
137management of TIME_WAIT sockets, keep-alive socket options
138and support for Duplicate SACK extensions.
139.SH "ADDRESS FORMATS"
140TCP is built on top of IP (see
141.BR ip (7)).
142The address formats defined by
143.BR ip (7)
144apply to TCP. TCP only supports point-to-point
145communication; broadcasting and multicasting are not
146supported.
147.SH SYSCTLS
148These variables can be accessed by the
149.B /proc/sys/net/ipv4/*
150files or with the
151.BR sysctl (2)
152interface. In addition, most IP sysctls also apply to TCP; see
153.BR ip (7).
ccca85be
MK
154Variables described as
155.I Boolean
156take an integer value, with a non-zero value ("true") meaning that
157the corresponding option is enabled, and a zero value ("false")
158meaning that the option is disabled.
5c45d5f5
MK
159.\" FIXME: As at 14 Jun 2005, kernel 2.6.12, the following are
160.\" not yet documented (shown with default values):
161.\"
162.\" /proc/sys/net/ipv4/tcp_bic_beta
163.\" 819
164.\" /proc/sys/net/ipv4/tcp_moderate_rcvbuf
165.\" 1
166.\" /proc/sys/net/ipv4/tcp_no_metrics_save
167.\" 0
168.\" /proc/sys/net/ipv4/tcp_vegas_alpha
169.\" 2
170.\" /proc/sys/net/ipv4/tcp_vegas_beta
171.\" 6
172.\" /proc/sys/net/ipv4/tcp_vegas_gamma
173.\" 2
fea681da 174.TP
5c45d5f5 175.BR tcp_abort_on_overflow " (Boolean; default: disabled)"
fea681da 176Enable resetting connections if the listening service is too
5c45d5f5
MK
177slow and unable to keep up and accept them.
178It means that if overflow occurred due
fea681da 179to a burst, the connection will recover. Enable this option
fd1835be
MK
180.I only
181if you are really sure that the listening daemon
fea681da
MK
182cannot be tuned to accept connections faster. Enabling this
183option can harm the clients of your server.
184.TP
5c45d5f5 185.BR tcp_adv_win_scale " (integer; default: 2)"
fea681da
MK
186Count buffering overhead as bytes/2^tcp_adv_win_scale
187(if tcp_adv_win_scale > 0) or bytes-bytes/2^(-tcp_adv_win_scale),
5c45d5f5 188if it is <= 0.
fea681da
MK
189
190The socket receive buffer space is shared between the
191application and kernel. TCP maintains part of the buffer as
192the TCP window, this is the size of the receive window
193advertised to the other end. The rest of the space is used
194as the "application" buffer, used to isolate the network
195from scheduling and application latencies. The
5c45d5f5 196.BR tcp_adv_win_scale
fea681da
MK
197default value of 2 implies that the space
198used for the application buffer is one fourth that of the
199total.
200.TP
5c45d5f5 201.BR tcp_app_win " (integer; default: 31)"
fea681da
MK
202This variable defines how many
203bytes of the TCP window are reserved for buffering
204overhead.
205
206A maximum of (window/2^tcp_app_win, mss) bytes in the window
207are reserved for the application buffer. A value of 0
5c45d5f5
MK
208implies that no amount is reserved.
209.\"
6f802359 210.\" The following is from 2.6.12: Documentation/networking/ip-sysctl.txt
fea681da 211.TP
5c45d5f5
MK
212.BR tcp_bic " (Boolean; default: disabled)"
213Enable BIC TCP congestion control algorithm.
214BIC-TCP is a sender-side only change that ensures a linear RTT
215fairness under large windows while offering both scalability and
216bounded TCP-friendliness. The protocol combines two schemes
217called additive increase and binary search increase. When the
218congestion window is large, additive increase with a large
219increment ensures linear RTT fairness as well as good
220scalability. Under small congestion windows, binary search
221increase provides TCP friendliness.
222.\"
6f802359 223.\" The following is from 2.6.12: Documentation/networking/ip-sysctl.txt
5c45d5f5
MK
224.TP
225.BR tcp_bic_low_window " (integer; default: 14)"
226Sets the threshold window (in packets) where BIC TCP starts to
227adjust the congestion window. Below this threshold BIC TCP behaves
228the same as the default TCP Reno.
229.\"
6f802359 230.\" The following is from 2.6.12: Documentation/networking/ip-sysctl.txt
5c45d5f5
MK
231.TP
232.BR tcp_bic_fast_convergence " (Boolean; default: enabled)"
233Forces BIC TCP to more quickly respond to changes in congestion
234window. Allows two flows sharing the same connection to converge
235more rapidly.
236.TP
237.BR tcp_dsack " (Boolean; default: enabled)"
ccca85be 238Enable RFC\ 2883 TCP Duplicate SACK support.
fea681da 239.TP
5c45d5f5 240.BR tcp_ecn " (Boolean; default: disabled)"
ccca85be 241Enable RFC\ 2884 Explicit Congestion Notification.
5c45d5f5 242When enabled, connectivity to some
fea681da
MK
243destinations could be affected due to older, misbehaving
244routers along the path causing connections to be dropped.
245.TP
5c45d5f5
MK
246.BR tcp_fack " (Boolean; default: enabled)"
247Enable TCP Forward Acknowledgement support.
fea681da 248.TP
5c45d5f5 249.BR tcp_fin_timeout " (integer; default: 60)"
fd1835be 250This specifies how many seconds to wait for a final FIN packet before the
fea681da
MK
251socket is forcibly closed. This is strictly a violation of
252the TCP specification, but required to prevent
5c45d5f5
MK
253denial-of-service attacks.
254In Linux 2.2, the default value was 180.
255.\"
6f802359 256.\" The following is from 2.6.12: Documentation/networking/ip-sysctl.txt
5c45d5f5
MK
257.TP
258.BR tcp_frto " (Boolean; default: disabled)"
259Enables F-RTO, an enhanced recovery algorithm for TCP retransmission
260timeouts. It is particularly beneficial in wireless environments
261where packet loss is typically due to random radio interference
262rather than intermediate router congestion.
fea681da 263.TP
5c45d5f5 264.BR tcp_keepalive_intvl " (integer; default: 75)"
fea681da 265The number of seconds between TCP keep-alive probes.
fea681da 266.TP
5c45d5f5 267.BR tcp_keepalive_probes " (integer; default: 9)"
fea681da
MK
268The maximum number of TCP keep-alive probes to send
269before giving up and killing the connection if
270no response is obtained from the other end.
fea681da 271.TP
5c45d5f5 272.BR tcp_keepalive_time " (integer; default: 7200)"
fea681da
MK
273The number of seconds a connection needs to be idle
274before TCP begins sending out keep-alive probes.
275Keep-alives are only sent when the
276.B SO_KEEPALIVE
277socket option is enabled. The default value is 7200 seconds
278(2 hours). An idle connection is terminated after
279approximately an additional 11 minutes (9 probes an interval
280of 75 seconds apart) when keep-alive is enabled.
281
282Note that underlying connection tracking mechanisms and
283application timeouts may be much shorter.
5c45d5f5 284.\"
6f802359 285.\" The following is from 2.6.12: Documentation/networking/ip-sysctl.txt
5c45d5f5
MK
286.TP
287.BR tcp_low_latency " (Boolean; default: disabled)"
288If enabled, the TCP stack makes decisions that prefer lower
289latency as opposed to higher throughput.
290It this option is disabled, then higher throughput is preferred.
291An example of an application where this default should be
292changed would be a Beowulf compute cluster.
fea681da 293.TP
5c45d5f5 294.BR tcp_max_orphans " (integer; default: see below)"
fea681da
MK
295The maximum number of orphaned (not attached to any user file
296handle) TCP sockets allowed in the system. When this number
297is exceeded, the orphaned connection is reset and a warning
fd1835be 298is printed. This limit exists only to prevent simple denial-of-service
fea681da
MK
299attacks. Lowering this limit is not recommended. Network
300conditions might require you to increase the number of
301orphans allowed, but note that each orphan can eat up to ~64K
302of unswappable memory. The default initial value is set
303equal to the kernel parameter NR_FILE. This initial default
304is adjusted depending on the memory in the system.
305.TP
5c45d5f5 306.BR tcp_max_syn_backlog " (integer; default: see below)"
fea681da
MK
307The maximum number of queued connection requests which have
308still not received an acknowledgement from the connecting
309client. If this number is exceeded, the kernel will begin
310dropping requests. The default value of 256 is increased to
3111024 when the memory present in the system is adequate or
312greater (>= 128Mb), and reduced to 128 for those systems with
313very low memory (<= 32Mb). It is recommended that if this
314needs to be increased above 1024, TCP_SYNQ_HSIZE in
315include/net/tcp.h be modified to keep
316TCP_SYNQ_HSIZE*16<=tcp_max_syn_backlog, and the kernel be
317recompiled.
318.TP
5c45d5f5 319.BR tcp_max_tw_buckets " (integer; default: see below)"
fea681da 320The maximum number of sockets in TIME_WAIT state allowed in
fd1835be 321the system. This limit exists only to prevent simple denial-of-service
fea681da
MK
322attacks. The default value of NR_FILE*2 is adjusted
323depending on the memory in the system. If this number is
324exceeded, the socket is closed and a warning is printed.
325.TP
5c45d5f5 326.BR tcp_mem
fea681da
MK
327This is a vector of 3 integers: [low, pressure, high]. These
328bounds are used by TCP to track its memory usage. The
329defaults are calculated at boot time from the amount of
330available memory.
331
332.I low
333- TCP doesn't regulate its memory allocation when the number
334of pages it has allocated globally is below this number.
335
336.I pressure
337- when the amount of memory allocated by TCP
338exceeds this number of pages, TCP moderates its memory
339consumption. This memory pressure state is exited
340once the number of pages allocated falls below
341the
342.B low
343mark.
344
345.I high
346- the maximum number of pages, globally, that TCP
347will allocate. This value overrides any other limits
348imposed by the kernel.
349.TP
5c45d5f5 350.BR tcp_orphan_retries " (integer; default: 8)"
fea681da
MK
351The maximum number of attempts made to probe the other
352end of a connection which has been closed by our end.
fea681da 353.TP
5c45d5f5 354.BR tcp_reordering " (integer; default: 3)"
fea681da
MK
355The maximum a packet can be reordered in a TCP packet stream
356without TCP assuming packet loss and going into slow start.
5c45d5f5 357It is not advisable to change this number.
fea681da
MK
358This is a packet reordering detection metric designed to
359minimize unnecessary back off and retransmits provoked by
360reordering of packets on a connection.
361.TP
5c45d5f5 362.BR tcp_retrans_collapse " (Boolean; default: enabled)"
fea681da 363Try to send full-sized packets during retransmit.
fea681da 364.TP
5c45d5f5 365.BR tcp_retries1 " (integer; default: 3)"
fea681da
MK
366The number of times TCP will attempt to retransmit a
367packet on an established connection normally,
368without the extra effort of getting the network
369layers involved. Once we exceed this number of
370retransmits, we first have the network layer
371update the route if possible before each new retransmit.
372The default is the RFC specified minimum of 3.
373.TP
5c45d5f5 374.BR tcp_retries2 " (integer; default: 15)"
fea681da
MK
375The maximum number of times a TCP packet is retransmitted
376in established state before giving up. The default
377value is 15, which corresponds to a duration of
378approximately between 13 to 30 minutes, depending
ccca85be 379on the retransmission timeout. The RFC\ 1122 specified
fea681da
MK
380minimum limit of 100 seconds is typically deemed too
381short.
382.TP
5c45d5f5 383.BR tcp_rfc1337 " (Boolean; default: disabled)"
fea681da 384Enable TCP behaviour conformant with RFC 1337.
5c45d5f5 385When disabled,
fea681da
MK
386if a RST is received in TIME_WAIT state, we close
387the socket immediately without waiting for the end
388of the TIME_WAIT period.
389.TP
5c45d5f5 390.BR tcp_rmem
fea681da
MK
391This is a vector of 3 integers: [min, default,
392max]. These parameters are used by TCP to regulate receive
393buffer sizes. TCP dynamically adjusts the size of the
394receive buffer from the defaults listed below, in the range
395of these sysctl variables, depending on memory available
396in the system.
397
398.I min
399- minimum size of the receive buffer used by each TCP
400socket. The default value is 4K, and is lowered to
fd1835be 401PAGE_SIZE bytes in low-memory systems. This value
fea681da
MK
402is used to ensure that in memory pressure mode,
403allocations below this size will still succeed. This is not
404used to bound the size of the receive buffer declared
405using
406.B SO_RCVBUF
407on a socket.
408
409.I default
410- the default size of the receive buffer for a TCP socket.
411This value overwrites the initial default buffer size from
412the generic global
413.B net.core.rmem_default
414defined for all protocols. The default value is 87380
fd1835be 415bytes, and is lowered to 43689 in low-memory systems. If
fea681da
MK
416larger receive buffer sizes are desired, this value should
417be increased (to affect all sockets). To employ large TCP
418windows, the
419.B net.ipv4.tcp_window_scaling
420must be enabled (default).
421
422.I max
423- the maximum size of the receive buffer used by
424each TCP socket. This value does not override the global
425.BR net.core.rmem_max .
426This is not used to limit the size of the receive buffer
427declared using
428.B SO_RCVBUF
429on a socket.
430The default value of 87380*2 bytes is lowered to 87380
fd1835be 431in low-memory systems.
fea681da 432.TP
5c45d5f5 433.BR tcp_sack " (Boolean; default: enabled)"
ccca85be 434Enable RFC\ 2018 TCP Selective Acknowledgements.
fea681da 435.TP
5c45d5f5 436.BR tcp_stdurg " (Boolean; default: disabled)"
ccca85be 437If this option is enabled, then use the RFC\ 1122 interpretation
6f802359 438of the TCP urgent-pointer field.
ccca85be
MK
439.\" RFC 793 was ambiguous in its specification of the meaning of the
440.\" urgent pointer. RFC 1122 (and RFC 961) fixed on a particular
441.\" resolution of this ambiguity (unfortunately the "wrong" one).
6f802359
MK
442According to this interpretation, the urgent pointer points
443to the last byte of urgent data.
444If this option is disabled, then use the BSD-compatible interpretation of
ccca85be 445the urgent pointer:
6f802359
MK
446the urgent pointer points to the first byte after the urgent data.
447Enabling this option may lead to interoperability problems.
fea681da 448.TP
5c45d5f5 449.BR tcp_synack_retries " (integer; default: 5)"
fea681da
MK
450The maximum number of times a SYN/ACK segment
451for a passive TCP connection will be retransmitted.
5c45d5f5 452This number should not be higher than 255.
fea681da 453.TP
5c45d5f5 454.BR tcp_syncookies " (Boolean)"
fea681da
MK
455Enable TCP syncookies. The kernel must be compiled with
456.BR CONFIG_SYN_COOKIES .
457Send out syncookies when the syn backlog queue of a socket
458overflows. The syncookies feature attempts to protect a
459socket from a SYN flood attack. This should be used as a
460last resort, if at all. This is a violation of the TCP
461protocol, and conflicts with other areas of TCP such as TCP
462extensions. It can cause problems for clients and relays.
463It is not recommended as a tuning mechanism for heavily
464loaded servers to help with overloaded or misconfigured
465conditions. For recommended alternatives see
466.BR tcp_max_syn_backlog ,
467.BR tcp_synack_retries ,
5c45d5f5 468and
fea681da
MK
469.BR tcp_abort_on_overflow .
470.TP
5c45d5f5 471.BR tcp_syn_retries " (integer; default: 5)"
fea681da
MK
472The maximum number of times initial SYNs for an active TCP
473connection attempt will be retransmitted. This value should
474not be higher than 255. The default value is 5, which
475corresponds to approximately 180 seconds.
476.TP
5c45d5f5 477.BR tcp_timestamps " (Boolean; default: enabled)"
ccca85be 478Enable RFC\ 1323 TCP timestamps.
fea681da 479.TP
5c45d5f5
MK
480.BR tcp_tw_recycle " (Boolean; default: disabled)"
481Enable fast recycling of TIME-WAIT sockets.
482Enabling this option is not
fea681da
MK
483recommended since this causes problems when working
484with NAT (Network Address Translation).
5c45d5f5 485.\"
6f802359 486.\" The following is from 2.6.12: Documentation/networking/ip-sysctl.txt
5c45d5f5
MK
487.TP
488.BR tcp_tw_reuse " (Boolean; default: disabled)"
489Allow to reuse TIME-WAIT sockets for new connections when it is
490safe from protocol viewpoint.
491It should not be changed without advice/request of technical
492experts.
fea681da 493.TP
5c45d5f5 494.BR tcp_window_scaling " (Boolean; default: disabled)"
ccca85be 495Enable RFC\ 1323 TCP window scaling.
5c45d5f5 496This feature allows the use of a large window
fea681da
MK
497(> 64K) on a TCP connection, should the other end support it.
498Normally, the 16 bit window length field in the TCP header
499limits the window size to less than 64K bytes. If larger
500windows are desired, applications can increase the size of
501their socket buffers and the window scaling option will be
502employed. If
5c45d5f5 503.BR tcp_window_scaling
fea681da
MK
504is disabled, TCP will not negotiate the use of window
505scaling with the other end during connection setup.
5c45d5f5 506.\"
6f802359 507.\" The following is from 2.6.12: Documentation/networking/ip-sysctl.txt
5c45d5f5
MK
508.TP
509.BR tcp_vegas_cong_avoid " (Boolean; default: disabled)"
510Enable TCP Vegas congestion avoidance algorithm.
511TCP Vegas is a sender-side only change to TCP that anticipates
512the onset of congestion by estimating the bandwidth. TCP Vegas
513adjusts the sending rate by modifying the congestion
514window. TCP Vegas should provide less packet loss, but it is
515not as aggressive as TCP Reno.
516.\"
6f802359 517.\" The following is from 2.6.12: Documentation/networking/ip-sysctl.txt
5c45d5f5
MK
518.TP
519.BR tcp_westwood " (Boolean; default: disabled)"
520Enable TCP Westwood+ congestion control algorithm.
521TCP Westwood+ is a sender-side only modification of the TCP Reno
522protocol stack that optimizes the performance of TCP congestion
523control. It is based on end-to-end bandwidth estimation to set
524congestion window and slow start threshold after a congestion
525episode. Using this estimation, TCP Westwood+ adaptively sets a
526slow start threshold and a congestion window which takes into
527account the bandwidth used at the time congestion is experienced.
ccca85be
MK
528TCP Westwood+ significantly increases fairness with respect to
529TCP Reno in wired networks and throughput over wireless links.
fea681da 530.TP
5c45d5f5 531.BR tcp_wmem
fea681da
MK
532This is a vector of 3 integers: [min, default, max]. These
533parameters are used by TCP to regulate send buffer sizes.
534TCP dynamically adjusts the size of the send buffer from the
535default values listed below, in the range of these sysctl
536variables, depending on memory available.
537
538.I min
539- minimum size of the send buffer used by each TCP socket.
540The default value is 4K bytes.
541This value is used to ensure that in memory pressure mode,
542allocations below this size will still succeed. This is not
543used to bound the size of the send buffer declared
544using
545.B SO_SNDBUF
546on a socket.
547
548.I default
549- the default size of the send buffer for a TCP socket.
550This value overwrites the initial default buffer size from
551the generic global
552.B net.core.wmem_default
553defined for all protocols. The default value is 16K bytes.
554If larger send buffer sizes are desired, this value
555should be increased (to affect all sockets). To employ
556large TCP windows, the sysctl variable
557.B net.ipv4.tcp_window_scaling
558must be enabled (default).
559
560.I max
561- the maximum size of the send buffer used by
562each TCP socket. This value does not override the global
563.BR net.core.wmem_max .
564This is not used to limit the size of the send buffer
565declared using
566.B SO_SNDBUF
567on a socket.
568The default value is 128K bytes. It is lowered to 64K
569depending on the memory available in the system.
570.SH "SOCKET OPTIONS"
571To set or get a TCP socket option, call
572.BR getsockopt (2)
573to read or
574.BR setsockopt (2)
575to write the option with the option level argument set to
576.BR SOL_TCP.
577In addition,
578most
579.B SOL_IP
580socket options are valid on TCP sockets. For more
581information see
582.BR ip (7).
583.TP
584.B TCP_CORK
585If set, don't send out partial frames. All queued
586partial frames are sent when the option is cleared again.
587This is useful for prepending headers before calling
588.BR sendfile (2),
8dd9ef47
MK
589or for throughput optimization.
590This option can be
fea681da 591combined with
8dd9ef47
MK
592.BR TCP_NODELAY
593only since Linux 2.5.71.
fea681da
MK
594This option should not be used in code intended to be
595portable.
596.TP
597.B TCP_DEFER_ACCEPT
598Allows a listener to be awakened only when data arrives on
599the socket. Takes an integer value (seconds), this can
600bound the maximum number of attempts TCP will make to
601complete the connection. This option should not be used in
602code intended to be portable.
603.TP
604.B TCP_INFO
605Used to collect information about this socket. The kernel
fd1835be 606returns a \fIstruct tcp_info\fP as defined in the file
fea681da
MK
607/usr/include/linux/tcp.h. This option should not be used in
608code intended to be portable.
609.TP
610.B TCP_KEEPCNT
611The maximum number of keepalive probes TCP should send
612before dropping the connection. This option should not be
613used in code intended to be portable.
614.TP
615.B TCP_KEEPIDLE
616The time (in seconds) the connection needs to remain idle
617before TCP starts sending keepalive probes, if the socket
618option SO_KEEPALIVE has been set on this socket. This
619option should not be used in code intended to be portable.
620.TP
621.B TCP_KEEPINTVL
622The time (in seconds) between individual keepalive probes.
623This option should not be used in code intended to be
624portable.
625.TP
626.B TCP_LINGER2
627The lifetime of orphaned FIN_WAIT2 state sockets. This
628option can be used to override the system wide sysctl
629.B tcp_fin_timeout
630on this socket. This is not to be confused with the
631.BR socket (7)
632level option
633.BR SO_LINGER .
634This option should not be used in code intended to be
635portable.
636.TP
637.B TCP_MAXSEG
638The maximum segment size for outgoing TCP packets. If this
639option is set before connection establishment, it also
640changes the MSS value announced to the other end in the
641initial packet. Values greater than the (eventual)
642interface MTU have no effect. TCP will also impose
643its minimum and maximum bounds over the value provided.
644.TP
645.B TCP_NODELAY
646If set, disable the Nagle algorithm. This means that segments
647are always sent as soon as possible, even if there is only a
648small amount of data. When not set, data is buffered until there
649is a sufficient amount to send out, thereby avoiding the
650frequent sending of small packets, which results in poor
8dd9ef47 651utilization of the network.
704a18f0 652This option is overridden by
925d4d6a
MK
653.BR TCP_CORK ;
654however, setting this option forces an explicit flush of
655pending output, even if
656.B TCP_CORK
657is currently set.
fea681da
MK
658.TP
659.B TCP_QUICKACK
660Enable quickack mode if set or disable quickack
661mode if cleared. In quickack mode, acks are sent
662immediately, rather than delayed if needed in accordance
663to normal TCP operation. This flag is not permanent,
664it only enables a switch to or from quickack mode.
665Subsequent operation of the TCP protocol will
666once again enter/leave quickack mode depending on
667internal protocol processing and factors such as
668delayed ack timeouts occurring and data transfer.
669This option should not be used in code intended to be
670portable.
671.TP
672.B TCP_SYNCNT
673Set the number of SYN retransmits that TCP should send before
674aborting the attempt to connect. It cannot exceed 255.
675This option should not be used in code intended to be
676portable.
677.TP
678.B TCP_WINDOW_CLAMP
679Bound the size of the advertised window to this value. The
680kernel imposes a minimum size of SOCK_MIN_RCVBUF/2.
681This option should not be used in code intended to be
682portable.
683.SH IOCTLS
fd1835be
MK
684These following
685.BR ioctl (2)
686calls return information in
687.IR value .
fea681da
MK
688The correct syntax is:
689.PP
690.RS
691.nf
692.BI int " value";
693.IB error " = ioctl(" tcp_socket ", " ioctl_type ", &" value ");"
694.fi
695.RE
fd1835be
MK
696.PP
697.I ioctl_type
698is one of the following:
fea681da
MK
699.TP
700.BR SIOCINQ
fd1835be
MK
701Returns the amount of queued unread data in the receive buffer.
702The socket must not be in LISTEN state, otherwise an error (EINVAL)
fea681da
MK
703is returned.
704.TP
705.B SIOCATMARK
fd1835be
MK
706Returns true (i.e.,
707.I value
708is non-zero) if the inbound data stream is at the urgent mark.
95d29ab2
MK
709.sp
710If the
711.BR SO_OOBINLINE
712socket option is set, and
fd1835be 713.B SIOCATMARK
95d29ab2 714returns true, then the
fd1835be 715next read from the socket will return the urgent data.
95d29ab2
MK
716If the
717.BR SO_OOBINLINE
718socket option is not set, and
719.B SIOCATMARK
720returns true, then the
721next read from the socket will return the bytes following
722the urgent data (to actually read the urgent data requires the
723.B recv(MSG_OOB)
724flag).
725.sp
726Note that a read never reads across the urgent mark.
ccca85be
MK
727If an application is informed of the presence of urgent data via
728.BR select (2)
729(using the
730.I exceptfds
731argument) or through delivery of a
732.B SIGURG
733signal,
734then it can advance up to the mark using a loop which repeatedly tests
735.B SIOCATMARK
736and performs a read (requesting any number of bytes) as long as
fd1835be 737.B SIOCATMARK
ccca85be 738returns false.
fea681da
MK
739.TP
740.B SIOCOUTQ
fd1835be
MK
741Returns the amount of unsent data in the socket send queue.
742The socket must not be in LISTEN state, otherwise an error (EINVAL)
fea681da
MK
743is returned.
744.SH "ERROR HANDLING"
745When a network error occurs, TCP tries to resend the
746packet. If it doesn't succeed after some time, either
747.B ETIMEDOUT
748or the last received error on this connection is reported.
749.PP
750Some applications require a quicker error notification.
751This can be enabled with the
752.B SOL_IP
753level
754.B IP_RECVERR
755socket option. When this option is enabled, all incoming
756errors are immediately passed to the user program. Use this
757option with care \- it makes TCP less tolerant to routing
758changes and other normal network conditions.
759.SH NOTES
760When an error occurs doing a connection setup occurring in a
761socket write
762.B SIGPIPE
763is only raised when the
764.B SO_KEEPALIVE
765socket option is set.
766.PP
767TCP has no real out-of-band data; it has urgent data. In
768Linux this means if the other end sends newer out-of-band
769data the older urgent data is inserted as normal data into
770the stream (even when
771.B SO_OOBINLINE
ccca85be 772is not set). This differs from BSD-based stacks.
fea681da
MK
773.PP
774Linux uses the BSD compatible interpretation of the urgent
ccca85be 775pointer field by default. This violates RFC\ 1122, but is
fea681da
MK
776required for interoperability with other stacks. It can be
777changed by the
778.B tcp_stdurg
779sysctl.
780.SH ERRORS
781.TP
782.B EPIPE
783The other end closed the socket unexpectedly or a read is
784executed on a shut down socket.
785.TP
786.B ETIMEDOUT
787The other end didn't acknowledge retransmitted data after
788some time.
789.TP
790.B EAFNOTSUPPORT
791Passed socket address type in
792.I sin_family
793was not
794.BR AF_INET .
795.PP
796Any errors defined for
797.BR ip (7)
798or the generic socket layer may also be returned for TCP.
799.SH BUGS
800Not all errors are documented.
801.br
802IPv6 is not described.
803.\" Only a single Linux kernel version is described
804.\" Info for 2.2 was lost. Should be added again,
805.\" or put into a separate page.
806.SH VERSIONS
fd1835be 807Support for Explicit Congestion Notification, zero-copy
fea681da
MK
808sendfile, reordering support and some SACK extensions
809(DSACK) were introduced in 2.4.
810Support for forward acknowledgement (FACK), TIME_WAIT recycling,
811per connection keepalive socket options and sysctls
812were introduced in 2.3.
813
814The default values and descriptions for the sysctl variables
815given above are applicable for the 2.4 kernel.
816.SH AUTHORS
817This man page was originally written by Andi Kleen.
818It was updated for 2.4 by Nivedita Singhvi with input from
819Alexey Kuznetsov's Documentation/networking/ip-sysctls.txt
820document.
821.SH "SEE ALSO"
822.BR accept (2),
823.BR bind (2),
824.BR connect (2),
825.BR getsockopt (2),
826.BR listen (2),
827.BR recvmsg (2),
828.BR sendfile (2),
829.BR sendmsg (2),
830.BR socket (2),
831.BR sysctl (2),
832.BR ip (7),
833.BR socket (7)
834.sp
ccca85be 835RFC\ 793 for the TCP specification.
fea681da 836.br
ccca85be 837RFC\ 1122 for the TCP requirements and a description
fea681da
MK
838of the Nagle algorithm.
839.br
ccca85be 840RFC\ 1323 for TCP timestamp and window scaling options.
fea681da 841.br
ccca85be 842RFC\ 1644 for a description of TIME_WAIT assassination
fea681da
MK
843hazards.
844.br
ccca85be 845RFC\ 2481 for a description of Explicit Congestion
fea681da
MK
846Notification.
847.br
ccca85be 848RFC\ 2581 for TCP congestion control algorithms.
fea681da 849.br
ccca85be 850RFC\ 2018 and RFC\ 2883 for SACK and extensions to SACK.