f133b6c119660bb31c27fdbc9d8f32af31a8a646
[dragonfly.git] / share / man / man4 / tcp.4
1 .\" Copyright (c) 1983, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     From: @(#)tcp.4 8.1 (Berkeley) 6/5/93
33 .\" $FreeBSD: src/share/man/man4/tcp.4,v 1.11.2.14 2002/12/29 16:35:38 schweikh Exp $
34 .\" $DragonFly: src/share/man/man4/tcp.4,v 1.9 2008/10/17 11:30:24 swildner Exp $
35 .\"
36 .Dd February 14, 1995
37 .Dt TCP 4
38 .Os
39 .Sh NAME
40 .Nm tcp
41 .Nd Internet Transmission Control Protocol
42 .Sh SYNOPSIS
43 .In sys/types.h
44 .In sys/socket.h
45 .In netinet/in.h
46 .Ft int
47 .Fn socket AF_INET SOCK_STREAM 0
48 .Sh DESCRIPTION
49 The
50 .Tn TCP
51 protocol provides reliable, flow-controlled, two-way
52 transmission of data.  It is a byte-stream protocol used to
53 support the
54 .Dv SOCK_STREAM
55 abstraction.  TCP uses the standard
56 Internet address format and, in addition, provides a per-host
57 collection of
58 .Dq port addresses .
59 Thus, each address is composed
60 of an Internet address specifying the host and network, with
61 a specific
62 .Tn TCP
63 port on the host identifying the peer entity.
64 .Pp
65 Sockets utilizing the tcp protocol are either
66 .Dq active
67 or
68 .Dq passive .
69 Active sockets initiate connections to passive
70 sockets.  By default
71 .Tn TCP
72 sockets are created active; to create a
73 passive socket the
74 .Xr listen 2
75 system call must be used
76 after binding the socket with the
77 .Xr bind 2
78 system call.  Only
79 passive sockets may use the
80 .Xr accept 2
81 call to accept incoming connections.  Only active sockets may
82 use the
83 .Xr connect 2
84 call to initiate connections.
85 .Pp
86 Passive sockets may
87 .Dq underspecify
88 their location to match
89 incoming connection requests from multiple networks.  This
90 technique, termed
91 .Dq wildcard addressing ,
92 allows a single
93 server to provide service to clients on multiple networks.
94 To create a socket which listens on all networks, the Internet
95 address
96 .Dv INADDR_ANY
97 must be bound.  The
98 .Tn TCP
99 port may still be specified
100 at this time; if the port is not specified the system will assign one.
101 Once a connection has been established the socket's address is
102 fixed by the peer entity's location.   The address assigned the
103 socket is the address associated with the network interface
104 through which packets are being transmitted and received.  Normally
105 this address corresponds to the peer entity's network.
106 .Pp
107 .Tn TCP
108 supports a number of socket options which can be set with
109 .Xr setsockopt 2
110 and tested with
111 .Xr getsockopt 2 :
112 .Bl -tag -width TCP_NODELAYx
113 .It Dv TCP_NODELAY
114 Under most circumstances,
115 .Tn TCP
116 sends data when it is presented;
117 when outstanding data has not yet been acknowledged, it gathers
118 small amounts of output to be sent in a single packet once
119 an acknowledgement is received.
120 For a small number of clients, such as window systems
121 that send a stream of mouse events which receive no replies,
122 this packetization may cause significant delays.
123 The boolean option
124 .Dv TCP_NODELAY
125 defeats this algorithm.
126 .It Dv TCP_MAXSEG
127 By default, a sender\- and receiver-TCP
128 will negotiate among themselves to determine the maximum segment size
129 to be used for each connection.  The
130 .Dv TCP_MAXSEG
131 option allows the user to determine the result of this negotiation,
132 and to reduce it if desired.
133 .It Dv TCP_NOOPT
134 .Tn TCP
135 usually sends a number of options in each packet, corresponding to
136 various
137 .Tn TCP
138 extensions which are provided in this implementation.  The boolean
139 option
140 .Dv TCP_NOOPT
141 is provided to disable
142 .Tn TCP
143 option use on a per-connection basis.
144 .It Dv TCP_NOPUSH
145 By convention, the sender-TCP
146 will set the
147 .Dq push
148 bit and begin transmission immediately (if permitted) at the end of
149 every user call to
150 .Xr write 2
151 or
152 .Xr writev 2 .
153 When the
154 .Dv TCP_NOPUSH
155 option is set to a non-zero value,
156 .Tn TCP
157 will delay sending any data at all until either the socket is closed,
158 or the internal send buffer is filled.
159 .It Dv TCP_SIGNATURE_ENABLE
160 This option enables the use of MD5 digests (also known as TCP-MD5)
161 on writes to the specified socket.
162 In the current release, only outgoing traffic is digested;
163 digests on incoming traffic are not verified.
164 The current default behavior for the system is to respond to a system
165 advertising this option with TCP-MD5; this may change.
166 .Pp
167 One common use for this in a DragonFlyBSD router deployment is to enable
168 based routers to interwork with Cisco equipment at peering points.
169 Support for this feature conforms to RFC 2385.
170 Only IPv4 (AF_INET) sessions are supported.
171 .Pp
172 In order for this option to function correctly, it is necessary for the
173 administrator to add a tcp-md5 key entry to the system's security
174 associations database (SADB) using the
175 .Xr setkey 8
176 utility.
177 This entry must have an SPI of 0x1000 and can therefore only be specified
178 on a per-host basis at this time.
179 .Pp
180 If an SADB entry cannot be found for the destination, the outgoing traffic
181 will have an invalid digest option prepended, and the following error message
182 will be visible on the system console:
183 .Em "tcpsignature_compute: SADB lookup failed for %d.%d.%d.%d" .
184 .El
185 .Pp
186 The option level for the
187 .Xr setsockopt 2
188 call is the protocol number for
189 .Tn TCP ,
190 available from
191 .Xr getprotobyname 3 ,
192 or
193 .Dv IPPROTO_TCP .
194 All options are declared in
195 .In netinet/tcp.h .
196 .Pp
197 Options at the
198 .Tn IP
199 transport level may be used with
200 .Tn TCP ;
201 see
202 .Xr ip 4 .
203 Incoming connection requests that are source-routed are noted,
204 and the reverse source route is used in responding.
205 .Sh MIB VARIABLES
206 The
207 .Nm
208 protocol implements a number of variables in the
209 .Li net.inet
210 branch of the
211 .Xr sysctl 3
212 MIB.
213 .Bl -tag -width TCPCTL_DO_RFC1644
214 .It Dv TCPCTL_DO_RFC1323
215 .Pq tcp.rfc1323
216 Implement the window scaling and timestamp options of RFC 1323
217 (default true).
218 .It Dv TCPCTL_MSSDFLT
219 .Pq tcp.mssdflt
220 The default value used for the maximum segment size
221 .Pq Dq MSS
222 when no advice to the contrary is received from MSS negotiation.
223 .It Dv TCPCTL_SENDSPACE
224 .Pq tcp.sendspace
225 Maximum TCP send window.
226 .It Dv TCPCTL_RECVSPACE
227 .Pq tcp.recvspace
228 Maximum TCP receive window.
229 .It tcp.log_in_vain
230 Log any connection attempts to ports where there is not a socket
231 accepting connections.
232 The value of 1 limits the logging to SYN (connection establishment)
233 packets only.
234 That of 2 results in any TCP packets to closed ports being logged.
235 Any value unlisted above disables the logging
236 (default is 0, i.e., the logging is disabled).
237 .It tcp.msl
238 The Maximum Segment Lifetime for a packet.
239 .It tcp.keepinit
240 Timeout for new, non-established TCP connections.
241 .It tcp.keepidle
242 Amount of time the connection should be idle before keepalive
243 probes (if enabled) are sent.
244 .It tcp.keepintvl
245 The interval between keepalive probes sent to remote machines.
246 After
247 tcp.keepcnt
248 (default 8) probes are sent, with no response, the connection is dropped.
249 .It tcp.keepcnt
250 The maximum number of keepalive probes to be sent
251 before dropping the connection.
252 .It tcp.always_keepalive
253 Assume that
254 .Dv SO_KEEPALIVE
255 is set on all
256 .Tn TCP
257 connections, the kernel will
258 periodically send a packet to the remote host to verify the connection
259 is still up.
260 .It tcp.icmp_may_rst
261 Certain
262 .Tn ICMP
263 unreachable messages may abort connections in
264 .Tn SYN-SENT
265 state.
266 .It tcp.do_tcpdrain
267 Flush packets in the
268 .Tn TCP
269 reassembly queue if the system is low on mbufs.
270 .It tcp.blackhole
271 If enabled, disable sending of RST when a connection is attempted
272 to a port where there is not a socket accepting connections.
273 See
274 .Xr blackhole 4 .
275 .It tcp.delayed_ack
276 Delay ACK to try and piggyback it onto a data packet.
277 .It tcp.delacktime
278 Maximum amount of time before a delayed ACK is sent.
279 .It tcp.newreno
280 Enable TCP NewReno Fast Recovery algorithm,
281 as described in RFC 2582.
282 .It tcp.path_mtu_discovery
283 Enables Path MTU Discovery.  PMTU Discovery is helpful for avoiding
284 IP fragmentation when tranferring lots of data to the same client.
285 For web servers, where most of the connections are short and to
286 different clients, PMTU Discovery actually hurts performance due
287 to unnecessary retransmissions.  Turn this on only if most of your
288 TCP connections are long transfers or are repeatedly to the same
289 set of clients.
290 .It tcp.tcbhashsize
291 Size of the
292 .Tn TCP
293 control-block hashtable
294 (read-only).
295 This may be tuned using the kernel option
296 .Dv TCBHASHSIZE
297 or by setting
298 .Va net.inet.tcp.tcbhashsize
299 in the
300 .Xr loader 8 .
301 .It tcp.pcbcount
302 Number of active process control blocks
303 (read-only).
304 .It tcp.syncookies
305 Determines whether or not syn cookies should be generated for
306 outbound syn-ack packets.  Syn cookies are a great help during
307 syn flood attacks, and are enabled by default.
308 .It tcp.isn_reseed_interval
309 The interval (in seconds) specifying how often the secret data used in
310 RFC 1948 initial sequence number calculations should be reseeded.
311 By default, this variable is set to zero, indicating that
312 no reseeding will occur.
313 Reseeding should not be necessary, and will break
314 .Dv TIME_WAIT
315 recycling for a few minutes.
316 .It tcp.inet.tcp.rexmit_{min,slop}
317 Adjust the retransmit timer calculation for TCP.  The slop is
318 typically added to the raw calculation to take into account
319 occasional variances that the SRTT (smoothed round trip time)
320 is unable to accommodate, while the minimum specifies an
321 absolute minimum.  While a number of TCP RFCs suggest a 1
322 second minimum these RFCs tend to focus on streaming behavior
323 and fail to deal with the fact that a 1 second minimum has severe
324 detrimental effects over lossy interactive connections, such
325 as a 802.11b wireless link, and over very fast but lossy
326 connections for those cases not covered by the fast retransmit
327 code.  For this reason we suggest changing the slop to 200ms and
328 setting the minimum to something out of the way, like 20ms,
329 which gives you an effective minimum of 200ms (similar to Linux).
330 .It tcp.inflight_enable
331 Enable
332 .Tn TCP
333 bandwidth delay product limiting.  An attempt will be made to calculate
334 the bandwidth delay product for each individual TCP connection and limit
335 the amount of inflight data being transmitted to avoid building up
336 unnecessary packets in the network.  This option is recommended if you
337 are serving a lot of data over connections with high bandwidth-delay
338 products, such as modems, GigE links, and fast long-haul WANs, and/or
339 you have configured your machine to accommodate large TCP windows.  In such
340 situations, without this option, you may experience high interactive
341 latencies or packet loss due to the overloading of intermediate routers
342 and switches.  Note that bandwidth delay product limiting only affects
343 the transmit side of a TCP connection.
344 .It tcp.inflight_debug
345 Enable debugging for the bandwidth delay product algorithm.  This may
346 default to on (1) so if you enable the algorithm you should probably also
347 disable debugging by setting this variable to 0.
348 .It tcp.inflight_min
349 This puts an lower bound on the bandwidth delay product window, in bytes.
350 A value of 1024 is typically used for debugging.  6000-16000 is more typical
351 in a production installation.  Setting this value too low may result in
352 slow ramp-up times for bursty connections.  Setting this value too high
353 effectively disables the algorithm.
354 .It tcp.inflight_max
355 This puts an upper bound on the bandwidth delay product window, in bytes.
356 This value should not generally be modified but may be used to set a
357 global per-connection limit on queued data, potentially allowing you to
358 intentionally set a less than optimum limit to smooth data flow over a
359 network while still being able to specify huge internal TCP buffers.
360 .It tcp.inflight_stab
361 The bandwidth delay product algorithm requires a slightly larger window
362 than it otherwise calculates for stability.  This parameter determines the
363 extra window in maximal packets / 10.  The default value of 20 represents
364 2 maximal packets.  Reducing this value is not recommended but you may
365 come across a situation with very slow links where the ping time
366 reduction of the default inflight code is not sufficient.  If this case
367 occurs you should first try reducing tcp.inflight_min and, if that does not
368 work, reduce both tcp.inflight_min and tcp.inflight_stab, trying values of
369 15, 10, or 5 for the latter.  Never use a value less than 5.  Reducing
370 tcp.inflight_stab can lead to upwards of a 20% underutilization of the link
371 as well as reducing the algorithm's ability to adapt to changing
372 situations and should only be done as a last resort.
373 .El
374 .Sh ERRORS
375 A socket operation may fail with one of the following errors returned:
376 .Bl -tag -width Er
377 .It Bq Er EISCONN
378 when trying to establish a connection on a socket which
379 already has one;
380 .It Bq Er ENOBUFS
381 when the system runs out of memory for
382 an internal data structure;
383 .It Bq Er ETIMEDOUT
384 when a connection was dropped
385 due to excessive retransmissions;
386 .It Bq Er ECONNRESET
387 when the remote peer
388 forces the connection to be closed;
389 .It Bq Er ECONNREFUSED
390 when the remote
391 peer actively refuses connection establishment (usually because
392 no process is listening to the port);
393 .It Bq Er EADDRINUSE
394 when an attempt
395 is made to create a socket with a port which has already been
396 allocated;
397 .It Bq Er EADDRNOTAVAIL
398 when an attempt is made to create a
399 socket with a network address for which no network interface
400 exists.
401 .It Bq Er EAFNOSUPPORT
402 when an attempt is made to bind or connect a socket to a multicast
403 address.
404 .El
405 .Sh SEE ALSO
406 .Xr getsockopt 2 ,
407 .Xr socket 2 ,
408 .Xr sysctl 3 ,
409 .Xr blackhole 4 ,
410 .Xr inet 4 ,
411 .Xr intro 4 ,
412 .Xr ip 4 ,
413 .Xr setkey 8
414 .Rs
415 .%A V. Jacobson
416 .%A R. Braden
417 .%A D. Borman
418 .%T "TCP Extensions for High Performance"
419 .%O RFC 1323
420 .Re
421 .Rs
422 .%A "A. Heffernan"
423 .%T "Protection of BGP Sessions via the TCP MD5 Signature Option"
424 .%O "RFC 2385"
425 .Re
426 .Sh HISTORY
427 The
428 .Nm
429 protocol appeared in
430 .Bx 4.2 .
431 The RFC 1323 extensions for window scaling and timestamps were added
432 in
433 .Bx 4.4 .