Initial import from FreeBSD RELENG_4:
[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 .\"
35 .Dd February 14, 1995
36 .Dt TCP 4
37 .Os
38 .Sh NAME
39 .Nm tcp
40 .Nd Internet Transmission Control Protocol
41 .Sh SYNOPSIS
42 .In sys/types.h
43 .In sys/socket.h
44 .In netinet/in.h
45 .Ft int
46 .Fn socket AF_INET SOCK_STREAM 0
47 .Sh DESCRIPTION
48 The
49 .Tn TCP
50 protocol provides reliable, flow-controlled, two-way
51 transmission of data.  It is a byte-stream protocol used to
52 support the
53 .Dv SOCK_STREAM
54 abstraction.  TCP uses the standard
55 Internet address format and, in addition, provides a per-host
56 collection of
57 .Dq port addresses .
58 Thus, each address is composed
59 of an Internet address specifying the host and network, with
60 a specific
61 .Tn TCP
62 port on the host identifying the peer entity.
63 .Pp
64 Sockets utilizing the tcp protocol are either
65 .Dq active
66 or
67 .Dq passive .
68 Active sockets initiate connections to passive
69 sockets.  By default
70 .Tn TCP
71 sockets are created active; to create a
72 passive socket the
73 .Xr listen 2
74 system call must be used
75 after binding the socket with the
76 .Xr bind 2
77 system call.  Only
78 passive sockets may use the
79 .Xr accept 2
80 call to accept incoming connections.  Only active sockets may
81 use the
82 .Xr connect 2
83 call to initiate connections.
84 .Tn TCP
85 also supports a more datagram-like mode, called Transaction
86 .Tn TCP ,
87 which is described in
88 .Xr ttcp 4 .
89 .Pp
90 Passive sockets may
91 .Dq underspecify
92 their location to match
93 incoming connection requests from multiple networks.  This
94 technique, termed
95 .Dq wildcard addressing ,
96 allows a single
97 server to provide service to clients on multiple networks.
98 To create a socket which listens on all networks, the Internet
99 address
100 .Dv INADDR_ANY
101 must be bound.  The
102 .Tn TCP
103 port may still be specified
104 at this time; if the port is not specified the system will assign one.
105 Once a connection has been established the socket's address is
106 fixed by the peer entity's location.   The address assigned the
107 socket is the address associated with the network interface
108 through which packets are being transmitted and received.  Normally
109 this address corresponds to the peer entity's network.
110 .Pp
111 .Tn TCP
112 supports a number of socket options which can be set with
113 .Xr setsockopt 2
114 and tested with
115 .Xr getsockopt 2 :
116 .Bl -tag -width TCP_NODELAYx
117 .It Dv TCP_NODELAY
118 Under most circumstances,
119 .Tn TCP
120 sends data when it is presented;
121 when outstanding data has not yet been acknowledged, it gathers
122 small amounts of output to be sent in a single packet once
123 an acknowledgement is received.
124 For a small number of clients, such as window systems
125 that send a stream of mouse events which receive no replies,
126 this packetization may cause significant delays.
127 The boolean option
128 .Dv TCP_NODELAY
129 defeats this algorithm.
130 .It Dv TCP_MAXSEG
131 By default, a sender\- and receiver-TCP
132 will negotiate among themselves to determine the maximum segment size
133 to be used for each connection.  The
134 .Dv TCP_MAXSEG
135 option allows the user to determine the result of this negotiation,
136 and to reduce it if desired.
137 .It Dv TCP_NOOPT
138 .Tn TCP
139 usually sends a number of options in each packet, corresponding to
140 various
141 .Tn TCP
142 extensions which are provided in this implementation.  The boolean
143 option
144 .Dv TCP_NOOPT
145 is provided to disable
146 .Tn TCP
147 option use on a per-connection basis.
148 .It Dv TCP_NOPUSH
149 By convention, the sender-TCP
150 will set the
151 .Dq push
152 bit and begin transmission immediately (if permitted) at the end of
153 every user call to
154 .Xr write 2
155 or
156 .Xr writev 2 .
157 The
158 .Dv TCP_NOPUSH
159 option is provided to allow servers to easily make use of Transaction
160 TCP (see
161 .Xr ttcp 4 ) .
162 When the option is set to a non-zero value,
163 .Tn TCP
164 will delay sending any data at all until either the socket is closed,
165 or the internal send buffer is filled.
166 .El
167 .Pp
168 The option level for the
169 .Xr setsockopt 2
170 call is the protocol number for
171 .Tn TCP ,
172 available from
173 .Xr getprotobyname 3 ,
174 or
175 .Dv IPPROTO_TCP .
176 All options are declared in
177 .Aq Pa netinet/tcp.h .
178 .Pp
179 Options at the
180 .Tn IP
181 transport level may be used with
182 .Tn TCP ;
183 see
184 .Xr ip 4 .
185 Incoming connection requests that are source-routed are noted,
186 and the reverse source route is used in responding.
187 .Sh MIB VARIABLES
188 The
189 .Nm
190 protocol implements a number of variables in the
191 .Li net.inet
192 branch of the
193 .Xr sysctl 3
194 MIB.
195 .Bl -tag -width TCPCTL_DO_RFC1644
196 .It Dv TCPCTL_DO_RFC1323
197 .Pq tcp.rfc1323
198 Implement the window scaling and timestamp options of RFC 1323
199 (default true).
200 .It Dv TCPCTL_DO_RFC1644
201 .Pq tcp.rfc1644
202 Implement Transaction
203 .Tn TCP ,
204 as described in RFC 1644.
205 .It Dv TCPCTL_MSSDFLT
206 .Pq tcp.mssdflt
207 The default value used for the maximum segment size
208 .Pq Dq MSS
209 when no advice to the contrary is received from MSS negotiation.
210 .It Dv TCPCTL_SENDSPACE
211 .Pq tcp.sendspace
212 Maximum TCP send window.
213 .It Dv TCPCTL_RECVSPACE
214 .Pq tcp.recvspace
215 Maximum TCP receive window.
216 .It tcp.log_in_vain
217 Log any connection attempts to ports where there is not a socket
218 accepting connections.
219 The value of 1 limits the logging to SYN (connection establishment)
220 packets only.
221 That of 2 results in any TCP packets to closed ports being logged.
222 Any value unlisted above disables the logging
223 (default is 0, i.e., the logging is disabled).
224 .It tcp.slowstart_flightsize
225 The number of packets allowed to be in-flight during the
226 .Tn TCP
227 slow-start phase on a non-local network.
228 .It tcp.local_slowstart_flightsize
229 The number of packets allowed to be in-flight during the
230 .Tn TCP
231 slow-start phase to local machines in the same subnet.
232 .It tcp.msl
233 The Maximum Segment Lifetime for a packet.
234 .It tcp.keepinit
235 Timeout for new, non-established TCP connections.
236 .It tcp.keepidle
237 Amount of time the connection should be idle before keepalive
238 probes (if enabled) are sent.
239 .It tcp.keepintvl
240 The interval between keepalive probes sent to remote machines.
241 After
242 .Dv TCPTV_KEEPCNT
243 (default 8) probes are sent, with no response, the connection is dropped.
244 .It tcp.always_keepalive
245 Assume that
246 .Dv SO_KEEPALIVE
247 is set on all
248 .Tn TCP
249 connections, the kernel will
250 periodically send a packet to the remote host to verify the connection
251 is still up.
252 .It tcp.icmp_may_rst
253 Certain
254 .Tn ICMP
255 unreachable messages may abort connections in
256 .Tn SYN-SENT
257 state.
258 .It tcp.do_tcpdrain
259 Flush packets in the
260 .Tn TCP
261 reassembly queue if the system is low on mbufs.
262 .It tcp.blackhole
263 If enabled, disable sending of RST when a connection is attempted
264 to a port where there is not a socket accepting connections.
265 See
266 .Xr blackhole 4 .
267 .It tcp.delayed_ack
268 Delay ACK to try and piggyback it onto a data packet.
269 .It tcp.delacktime
270 Maximum amount of time before a delayed ACK is sent.
271 .It tcp.newreno
272 Enable TCP NewReno Fast Recovery algorithm,
273 as described in RFC 2582.
274 .It tcp.path_mtu_discovery
275 Enable Path MTU Discovery
276 .It tcp.tcbhashsize
277 Size of the
278 .Tn TCP
279 control-block hashtable
280 (read-only).
281 This may be tuned using the kernel option
282 .Dv TCBHASHSIZE
283 or by setting
284 .Va net.inet.tcp.tcbhashsize
285 in the
286 .Xr loader 8 .
287 .It tcp.pcbcount
288 Number of active process control blocks
289 (read-only).
290 .It tcp.syncookies
291 Determines whether or not syn cookies should be generated for
292 outbound syn-ack packets.  Syn cookies are a great help during
293 syn flood attacks, and are enabled by default.
294 .It tcp.isn_reseed_interval
295 The interval (in seconds) specifying how often the secret data used in
296 RFC 1948 initial sequence number calculations should be reseeded.
297 By default, this variable is set to zero, indicating that
298 no reseeding will occur.
299 Reseeding should not be necessary, and will break
300 .Dv TIME_WAIT
301 recycling for a few minutes.
302 .It tcp.inet.tcp.rexmit_{min,slop}
303 Adjust the retransmit timer calculation for TCP.  The slop is
304 typically added to the raw calculation to take into account
305 occasional variances that the SRTT (smoothed round trip time)
306 is unable to accomodate, while the minimum specifies an
307 absolute minimum.  While a number of TCP RFCs suggest a 1
308 second minimum these RFCs tend to focus on streaming behavior
309 and fail to deal with the fact that a 1 second minimum has severe
310 detrimental effects over lossy interactive connections, such
311 as a 802.11b wireless link, and over very fast but lossy
312 connections for those cases not covered by the fast retransmit
313 code.  For this reason we suggest changing the slop to 200ms and
314 setting the minimum to something out of the way, like 20ms,
315 which gives you an effective minimum of 200ms (similar to Linux).
316 .It tcp.inflight_enable
317 Enable
318 .Tn TCP
319 bandwidth delay product limiting.  An attempt will be made to calculate
320 the bandwidth delay product for each individual TCP connection and limit
321 the amount of inflight data being transmitted to avoid building up 
322 unnecessary packets in the network.  This option is recommended if you
323 are serving a lot of data over connections with high bandwidth-delay
324 products, such as modems, GigE links, and fast long-haul WANs, and/or
325 you have configured your machine to accomodate large TCP windows.  In such
326 situations, without this option, you may experience high interactive
327 latencies or packet loss due to the overloading of intermediate routers
328 and switches.  Note that bandwidth delay product limiting only effects
329 the transmit side of a TCP connection.
330 .It tcp.inflight_debug
331 Enable debugging for the bandwidth delay product algorithm.  This may
332 default to on (1) so if you enable the algorithm you should probably also
333 disable debugging by setting this variable to 0.
334 .It tcp.inflight_min
335 This puts an lower bound on the bandwidth delay product window, in bytes.
336 A value of 1024 is typically used for debugging.  6000-16000 is more typical
337 in a production installation.  Setting this value too low may result in
338 slow ramp-up times for bursty connections.  Setting this value too high
339 effectively disables the algorithm.
340 .It tcp.inflight_max
341 This puts an upper bound on the bandwidth delay product window, in bytes.
342 This value should not generally be modified but may be used to set a
343 global per-connection limit on queued data, potentially allowing you to
344 intentionally set a less then optimum limit to smooth data flow over a
345 network while still being able to specify huge internal TCP buffers.
346 .It tcp.inflight_stab
347 The bandwidth delay product algorithm requires a slightly larger window
348 then it otherwise calculates for stability.  This parameter determines the
349 extra window in maximal packets / 10.  The default value of 20 represents 
350 2 maximal packets.  Reducing this value is not recommended but you may
351 come across a situation with very slow links where the ping time
352 reduction of the default inflight code is not sufficient.  If this case
353 occurs you should first try reducing tcp.inflight_min and, if that does not
354 work, reduce both tcp.inflight_min and tcp.inflight_stab, trying values of
355 15, 10, or 5 for the latter.  Never use a value less then 5.  Reducing
356 tcp.inflight_stab can lead to upwards of a 20% underutilization of the link
357 as well as reducing the algorithm's ability to adapt to changing
358 situations and should only be done as a last resort.
359 .El
360 .Sh ERRORS
361 A socket operation may fail with one of the following errors returned:
362 .Bl -tag -width Er
363 .It Bq Er EISCONN
364 when trying to establish a connection on a socket which
365 already has one;
366 .It Bq Er ENOBUFS
367 when the system runs out of memory for
368 an internal data structure;
369 .It Bq Er ETIMEDOUT
370 when a connection was dropped
371 due to excessive retransmissions;
372 .It Bq Er ECONNRESET
373 when the remote peer
374 forces the connection to be closed;
375 .It Bq Er ECONNREFUSED
376 when the remote
377 peer actively refuses connection establishment (usually because
378 no process is listening to the port);
379 .It Bq Er EADDRINUSE
380 when an attempt
381 is made to create a socket with a port which has already been
382 allocated;
383 .It Bq Er EADDRNOTAVAIL
384 when an attempt is made to create a
385 socket with a network address for which no network interface
386 exists.
387 .It Bq Er EAFNOSUPPORT
388 when an attempt is made to bind or connect a socket to a multicast
389 address.
390 .El
391 .Sh SEE ALSO
392 .Xr getsockopt 2 ,
393 .Xr socket 2 ,
394 .Xr sysctl 3 ,
395 .Xr blackhole 4 ,
396 .Xr inet 4 ,
397 .Xr intro 4 ,
398 .Xr ip 4 ,
399 .Xr ttcp 4
400 .Rs
401 .%A V. Jacobson
402 .%A R. Braden
403 .%A D. Borman
404 .%T "TCP Extensions for High Performance"
405 .%O RFC 1323
406 .Re
407 .Rs
408 .%A R. Braden
409 .%T "T/TCP \- TCP Extensions for Transactions"
410 .%O RFC 1644
411 .Re
412 .Sh HISTORY
413 The
414 .Nm
415 protocol appeared in
416 .Bx 4.2 .
417 The RFC 1323 extensions for window scaling and timestamps were added
418 in
419 .Bx 4.4 .