xref: /freebsd/share/man/man4/tcp.4 (revision 42c159fe388a3765f69860c84183700af37aca8a)
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$
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
48The
49.Tn TCP
50protocol provides reliable, flow-controlled, two-way
51transmission of data.  It is a byte-stream protocol used to
52support the
53.Dv SOCK_STREAM
54abstraction.  TCP uses the standard
55Internet address format and, in addition, provides a per-host
56collection of
57.Dq port addresses .
58Thus, each address is composed
59of an Internet address specifying the host and network, with
60a specific
61.Tn TCP
62port on the host identifying the peer entity.
63.Pp
64Sockets utilizing the tcp protocol are either
65.Dq active
66or
67.Dq passive .
68Active sockets initiate connections to passive
69sockets.  By default
70.Tn TCP
71sockets are created active; to create a
72passive socket the
73.Xr listen 2
74system call must be used
75after binding the socket with the
76.Xr bind 2
77system call.  Only
78passive sockets may use the
79.Xr accept 2
80call to accept incoming connections.  Only active sockets may
81use the
82.Xr connect 2
83call to initiate connections.
84.Tn TCP
85also supports a more datagram-like mode, called Transaction
86.Tn TCP ,
87which is described in
88.Xr ttcp 4 .
89.Pp
90Passive sockets may
91.Dq underspecify
92their location to match
93incoming connection requests from multiple networks.  This
94technique, termed
95.Dq wildcard addressing ,
96allows a single
97server to provide service to clients on multiple networks.
98To create a socket which listens on all networks, the Internet
99address
100.Dv INADDR_ANY
101must be bound.  The
102.Tn TCP
103port may still be specified
104at this time; if the port is not specified the system will assign one.
105Once a connection has been established the socket's address is
106fixed by the peer entity's location.   The address assigned the
107socket is the address associated with the network interface
108through which packets are being transmitted and received.  Normally
109this address corresponds to the peer entity's network.
110.Pp
111.Tn TCP
112supports a number of socket options which can be set with
113.Xr setsockopt 2
114and tested with
115.Xr getsockopt 2 :
116.Bl -tag -width TCP_NODELAYx
117.It Dv TCP_NODELAY
118Under most circumstances,
119.Tn TCP
120sends data when it is presented;
121when outstanding data has not yet been acknowledged, it gathers
122small amounts of output to be sent in a single packet once
123an acknowledgement is received.
124For a small number of clients, such as window systems
125that send a stream of mouse events which receive no replies,
126this packetization may cause significant delays.
127The boolean option
128.Dv TCP_NODELAY
129defeats this algorithm.
130.It Dv TCP_MAXSEG
131By default, a sender\- and receiver-TCP
132will negotiate among themselves to determine the maximum segment size
133to be used for each connection.  The
134.Dv TCP_MAXSEG
135option allows the user to determine the result of this negotiation,
136and to reduce it if desired.
137.It Dv TCP_NOOPT
138.Tn TCP
139usually sends a number of options in each packet, corresponding to
140various
141.Tn TCP
142extensions which are provided in this implementation.  The boolean
143option
144.Dv TCP_NOOPT
145is provided to disable
146.Tn TCP
147option use on a per-connection basis.
148.It Dv TCP_NOPUSH
149By convention, the sender-TCP
150will set the
151.Dq push
152bit and begin transmission immediately (if permitted) at the end of
153every user call to
154.Xr write 2
155or
156.Xr writev 2 .
157The
158.Dv TCP_NOPUSH
159option is provided to allow servers to easily make use of Transaction
160TCP (see
161.Xr ttcp 4 ) .
162When the option is set to a non-zero value,
163.Tn TCP
164will delay sending any data at all until either the socket is closed,
165or the internal send buffer is filled.
166.El
167.Pp
168The option level for the
169.Xr setsockopt 2
170call is the protocol number for
171.Tn TCP ,
172available from
173.Xr getprotobyname 3 ,
174or
175.Dv IPPROTO_TCP .
176All options are declared in
177.Aq Pa netinet/tcp.h .
178.Pp
179Options at the
180.Tn IP
181transport level may be used with
182.Tn TCP ;
183see
184.Xr ip 4 .
185Incoming connection requests that are source-routed are noted,
186and the reverse source route is used in responding.
187.Sh MIB VARIABLES
188The
189.Nm
190protocol implements a number of variables in the
191.Li net.inet
192branch of the
193.Xr sysctl 3
194MIB.
195.Bl -tag -width TCPCTL_DO_RFC1644
196.It Dv TCPCTL_DO_RFC1323
197.Pq tcp.rfc1323
198Implement the window scaling and timestamp options of RFC 1323
199(default true).
200.It Dv TCPCTL_DO_RFC1644
201.Pq tcp.rfc1644
202Implement Transaction
203.Tn TCP ,
204as described in RFC 1644.
205.It Dv TCPCTL_MSSDFLT
206.Pq tcp.mssdflt
207The default value used for the maximum segment size
208.Pq Dq MSS
209when no advice to the contrary is received from MSS negotiation.
210.It Dv TCPCTL_SENDSPACE
211.Pq tcp.sendspace
212Maximum TCP send window.
213.It Dv TCPCTL_RECVSPACE
214.Pq tcp.recvspace
215Maximum TCP receive window.
216.It tcp.log_in_vain
217Log any connection attempts to ports where there is not a socket
218accepting connections.
219.It tcp.slowstart_flightsize
220The number of packets allowed to be in-flight during the
221.Tn TCP
222slow-start phase on a non-local network.
223.It tcp.local_slowstart_flightsize
224The number of packets allowed to be in-flight during the
225.Tn TCP
226slow-start phase to local machines in the same subnet.
227.It tcp.msl
228The Maximum Segment Lifetime, in milliseconds, for a packet.
229.It tcp.keepinit
230Timeout, in milliseconds, for new, non-established TCP connections.
231.It tcp.keepidle
232Amount of time, in milliseconds, that the connection must be idle
233before keepalive probes (if enabled) are sent.
234.It tcp.keepintvl
235The interval, in milliseconds, between keepalive probes sent to remote
236machines.
237After
238.Dv TCPTV_KEEPCNT
239(default 8) probes are sent, with no response, the connection is dropped.
240.It tcp.always_keepalive
241Assume that
242.Dv SO_KEEPALIVE
243is set on all
244.Tn TCP
245connections, the kernel will
246periodically send a packet to the remote host to verify the connection
247is still up.
248.It tcp.icmp_may_rst
249Certain
250.Tn ICMP
251unreachable messages may abort connections in
252.Tn SYN-SENT
253state.
254.It tcp.do_tcpdrain
255Flush packets in the
256.Tn TCP
257reassembly queue if the system is low on mbufs.
258.\"
259.\" This option should go away and become the default.
260.\"
261.It tcp.tcp_lq_overflow
262If a connection is dropped due to a listen queue overflow, delete the
263cloned route associated with the connection if it does not have any
264prior information.
265.It tcp.blackhole
266If enabled, disable sending of RST when a connection is attempted
267to a port where there is not a socket accepting connections.
268See
269.Xr blackhole 4 .
270.It tcp.delayed_ack
271Delay ACK to try and piggyback it onto a data packet.
272.It tcp.delacktime
273Maximum amount of time, in milliseconds, before a delayed ACK is sent.
274.It tcp.newreno
275Enable TCP NewReno Fast Recovery algorithm,
276as described in RFC 2582.
277.It tcp.path_mtu_discovery
278Enable Path MTU Discovery
279.It tcp.tcbhashsize
280Size of the
281.Tn TCP
282control-block hashtable
283(read-only).
284This may be tuned using the kernel option
285.Dv TCBHASHSIZE
286or by setting
287.Va net.inet.tcp.tcbhashsize
288in the
289.Xr loader 8 .
290.It tcp.pcbcount
291Number of active process control blocks
292(read-only).
293.It tcp.strict_rfc1948
294Enable strict RFC 1948 (Defending Against Sequence Number Attacks)
295compliance.
296Setting this variable to a non-zero value will disable reseeding and
297will disable the use of randomized initial sequence numbers in favor
298of MD5-generated initial sequence numbers.
299.It tcp.isn_reseed_interval
300The interval (in seconds) specifying how often the secret data used in
301RFC 1948 initial sequence number calculations should be reseeded.
302By default, this variable is set to zero, indicating that
303no reseeding will occur.
304Reseeding should not be necessary, and will break
305.Dv TIME_WAIT
306recycling for a few minutes.
307.El
308.Sh ERRORS
309A socket operation may fail with one of the following errors returned:
310.Bl -tag -width Er
311.It Bq Er EISCONN
312when trying to establish a connection on a socket which
313already has one;
314.It Bq Er ENOBUFS
315when the system runs out of memory for
316an internal data structure;
317.It Bq Er ETIMEDOUT
318when a connection was dropped
319due to excessive retransmissions;
320.It Bq Er ECONNRESET
321when the remote peer
322forces the connection to be closed;
323.It Bq Er ECONNREFUSED
324when the remote
325peer actively refuses connection establishment (usually because
326no process is listening to the port);
327.It Bq Er EADDRINUSE
328when an attempt
329is made to create a socket with a port which has already been
330allocated;
331.It Bq Er EADDRNOTAVAIL
332when an attempt is made to create a
333socket with a network address for which no network interface
334exists.
335.It Bq Er EAFNOSUPPORT
336when an attempt is made to bind or connect a socket to a multicast
337address.
338.El
339.Sh SEE ALSO
340.Xr getsockopt 2 ,
341.Xr socket 2 ,
342.Xr sysctl 3 ,
343.Xr blackhole 4 ,
344.Xr inet 4 ,
345.Xr intro 4 ,
346.Xr ip 4 ,
347.Xr ttcp 4
348.Rs
349.%A V. Jacobson
350.%A R. Braden
351.%A D. Borman
352.%T "TCP Extensions for High Performance"
353.%O RFC 1323
354.Re
355.Rs
356.%A R. Braden
357.%T "T/TCP \- TCP Extensions for Transactions"
358.%O RFC 1644
359.Re
360.Sh HISTORY
361The
362.Nm
363protocol appeared in
364.Bx 4.2 .
365The RFC 1323 extensions for window scaling and timestamps were added
366in
367.Bx 4.4 .
368