]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - share/man/man4/tcp.4
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / share / man / man4 / tcp.4
1 .\" Copyright (c) 1983, 1991, 1993
2 .\"     The Regents of the University of California.
3 .\" Copyright (c) 2010-2011 The FreeBSD Foundation
4 .\" All rights reserved.
5 .\"
6 .\" Portions of this documentation were written at the Centre for Advanced
7 .\" Internet Architectures, Swinburne University of Technology, Melbourne,
8 .\" Australia by David Hayes under sponsorship from the FreeBSD Foundation.
9 .\"
10 .\" Redistribution and use in source and binary forms, with or without
11 .\" modification, are permitted provided that the following conditions
12 .\" are met:
13 .\" 1. Redistributions of source code must retain the above copyright
14 .\"    notice, this list of conditions and the following disclaimer.
15 .\" 2. Redistributions in binary form must reproduce the above copyright
16 .\"    notice, this list of conditions and the following disclaimer in the
17 .\"    documentation and/or other materials provided with the distribution.
18 .\" 3. All advertising materials mentioning features or use of this software
19 .\"    must display the following acknowledgement:
20 .\"     This product includes software developed by the University of
21 .\"     California, Berkeley and its contributors.
22 .\" 4. Neither the name of the University nor the names of its contributors
23 .\"    may be used to endorse or promote products derived from this software
24 .\"    without specific prior written permission.
25 .\"
26 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 .\" SUCH DAMAGE.
37 .\"
38 .\"     From: @(#)tcp.4 8.1 (Berkeley) 6/5/93
39 .\" $FreeBSD$
40 .\"
41 .Dd November 19, 2012
42 .Dt TCP 4
43 .Os
44 .Sh NAME
45 .Nm tcp
46 .Nd Internet Transmission Control Protocol
47 .Sh SYNOPSIS
48 .In sys/types.h
49 .In sys/socket.h
50 .In netinet/in.h
51 .Ft int
52 .Fn socket AF_INET SOCK_STREAM 0
53 .Sh DESCRIPTION
54 The
55 .Tn TCP
56 protocol provides reliable, flow-controlled, two-way
57 transmission of data.
58 It is a byte-stream protocol used to
59 support the
60 .Dv SOCK_STREAM
61 abstraction.
62 .Tn TCP
63 uses the standard
64 Internet address format and, in addition, provides a per-host
65 collection of
66 .Dq "port addresses" .
67 Thus, each address is composed
68 of an Internet address specifying the host and network,
69 with a specific
70 .Tn TCP
71 port on the host identifying the peer entity.
72 .Pp
73 Sockets utilizing the
74 .Tn TCP
75 protocol are either
76 .Dq active
77 or
78 .Dq passive .
79 Active sockets initiate connections to passive
80 sockets.
81 By default,
82 .Tn TCP
83 sockets are created active; to create a
84 passive socket, the
85 .Xr listen 2
86 system call must be used
87 after binding the socket with the
88 .Xr bind 2
89 system call.
90 Only passive sockets may use the
91 .Xr accept 2
92 call to accept incoming connections.
93 Only active sockets may use the
94 .Xr connect 2
95 call to initiate connections.
96 .Pp
97 Passive sockets may
98 .Dq underspecify
99 their location to match
100 incoming connection requests from multiple networks.
101 This technique, termed
102 .Dq "wildcard addressing" ,
103 allows a single
104 server to provide service to clients on multiple networks.
105 To create a socket which listens on all networks, the Internet
106 address
107 .Dv INADDR_ANY
108 must be bound.
109 The
110 .Tn TCP
111 port may still be specified
112 at this time; if the port is not specified, the system will assign one.
113 Once a connection has been established, the socket's address is
114 fixed by the peer entity's location.
115 The address assigned to the
116 socket is the address associated with the network interface
117 through which packets are being transmitted and received.
118 Normally, this address corresponds to the peer entity's network.
119 .Pp
120 .Tn TCP
121 supports a number of socket options which can be set with
122 .Xr setsockopt 2
123 and tested with
124 .Xr getsockopt 2 :
125 .Bl -tag -width ".Dv TCP_CONGESTION"
126 .It Dv TCP_INFO
127 Information about a socket's underlying TCP session may be retrieved
128 by passing the read-only option
129 .Dv TCP_INFO
130 to
131 .Xr getsockopt 2 .
132 It accepts a single argument: a pointer to an instance of
133 .Vt "struct tcp_info" .
134 .Pp
135 This API is subject to change; consult the source to determine
136 which fields are currently filled out by this option.
137 .Fx
138 specific additions include
139 send window size,
140 receive window size,
141 and
142 bandwidth-controlled window space.
143 .It Dv TCP_CONGESTION
144 Select or query the congestion control algorithm that TCP will use for the
145 connection.
146 See
147 .Xr mod_cc 4
148 for details.
149 .It Dv TCP_KEEPINIT
150 This write-only 
151 .Xr setsockopt 2
152 option accepts a per-socket timeout argument of
153 .Vt "u_int"
154 in seconds, for new, non-established
155 .Tn TCP
156 connections.
157 For the global default in milliseconds see
158 .Va keepinit
159 in the
160 .Sx MIB Variables
161 section further down.
162 .It Dv TCP_KEEPIDLE
163 This write-only 
164 .Xr setsockopt 2
165 option accepts an argument of
166 .Vt "u_int"
167 for the amount of time, in seconds, that the connection must be idle
168 before keepalive probes (if enabled) are sent for the connection of this
169 socket.
170 If set on a listening socket, the value is inherited by the newly created
171 socket upon
172 .Xr accept 2 .
173 For the global default in milliseconds see
174 .Va keepidle
175 in the
176 .Sx MIB Variables
177 section further down.
178 .It Dv TCP_KEEPINTVL
179 This write-only 
180 .Xr setsockopt 2
181 option accepts an argument of
182 .Vt "u_int"
183 to set the per-socket interval, in seconds, between keepalive probes sent
184 to a peer.
185 If set on a listening socket, the value is inherited by the newly created
186 socket upon
187 .Xr accept 2 .
188 For the global default in milliseconds see
189 .Va keepintvl
190 in the
191 .Sx MIB Variables
192 section further down.
193 .It Dv TCP_KEEPCNT
194 This write-only 
195 .Xr setsockopt 2
196 option accepts an argument of
197 .Vt "u_int"
198 and allows a per-socket tuning of the number of probes sent, with no response,
199 before the connection will be dropped.
200 If set on a listening socket, the value is inherited by the newly created
201 socket upon
202 .Xr accept 2 .
203 For the global default see the
204 .Va keepcnt
205 in the
206 .Sx MIB Variables
207 section further down.
208 .It Dv TCP_NODELAY
209 Under most circumstances,
210 .Tn TCP
211 sends data when it is presented;
212 when outstanding data has not yet been acknowledged, it gathers
213 small amounts of output to be sent in a single packet once
214 an acknowledgement is received.
215 For a small number of clients, such as window systems
216 that send a stream of mouse events which receive no replies,
217 this packetization may cause significant delays.
218 The boolean option
219 .Dv TCP_NODELAY
220 defeats this algorithm.
221 .It Dv TCP_MAXSEG
222 By default, a sender- and
223 .No receiver- Ns Tn TCP
224 will negotiate among themselves to determine the maximum segment size
225 to be used for each connection.
226 The
227 .Dv TCP_MAXSEG
228 option allows the user to determine the result of this negotiation,
229 and to reduce it if desired.
230 .It Dv TCP_NOOPT
231 .Tn TCP
232 usually sends a number of options in each packet, corresponding to
233 various
234 .Tn TCP
235 extensions which are provided in this implementation.
236 The boolean option
237 .Dv TCP_NOOPT
238 is provided to disable
239 .Tn TCP
240 option use on a per-connection basis.
241 .It Dv TCP_NOPUSH
242 By convention, the
243 .No sender- Ns Tn TCP
244 will set the
245 .Dq push
246 bit, and begin transmission immediately (if permitted) at the end of
247 every user call to
248 .Xr write 2
249 or
250 .Xr writev 2 .
251 When this option is set to a non-zero value,
252 .Tn TCP
253 will delay sending any data at all until either the socket is closed,
254 or the internal send buffer is filled.
255 .It Dv TCP_MD5SIG
256 This option enables the use of MD5 digests (also known as TCP-MD5)
257 on writes to the specified socket.
258 Outgoing traffic is digested;
259 digests on incoming traffic are verified if the
260 .Va net.inet.tcp.signature_verify_input
261 sysctl is nonzero.
262 The current default behavior for the system is to respond to a system
263 advertising this option with TCP-MD5; this may change.
264 .Pp
265 One common use for this in a
266 .Fx
267 router deployment is to enable
268 based routers to interwork with Cisco equipment at peering points.
269 Support for this feature conforms to RFC 2385.
270 Only IPv4
271 .Pq Dv AF_INET
272 sessions are supported.
273 .Pp
274 In order for this option to function correctly, it is necessary for the
275 administrator to add a tcp-md5 key entry to the system's security
276 associations database (SADB) using the
277 .Xr setkey 8
278 utility.
279 This entry must have an SPI of 0x1000 and can therefore only be specified
280 on a per-host basis at this time.
281 .Pp
282 If an SADB entry cannot be found for the destination, the outgoing traffic
283 will have an invalid digest option prepended, and the following error message
284 will be visible on the system console:
285 .Em "tcp_signature_compute: SADB lookup failed for %d.%d.%d.%d" .
286 .El
287 .Pp
288 The option level for the
289 .Xr setsockopt 2
290 call is the protocol number for
291 .Tn TCP ,
292 available from
293 .Xr getprotobyname 3 ,
294 or
295 .Dv IPPROTO_TCP .
296 All options are declared in
297 .In netinet/tcp.h .
298 .Pp
299 Options at the
300 .Tn IP
301 transport level may be used with
302 .Tn TCP ;
303 see
304 .Xr ip 4 .
305 Incoming connection requests that are source-routed are noted,
306 and the reverse source route is used in responding.
307 .Pp
308 The default congestion control algorithm for
309 .Tn TCP
310 is
311 .Xr cc_newreno 4 .
312 Other congestion control algorithms can be made available using the
313 .Xr mod_cc 4
314 framework.
315 .Ss MIB Variables
316 The
317 .Tn TCP
318 protocol implements a number of variables in the
319 .Va net.inet.tcp
320 branch of the
321 .Xr sysctl 3
322 MIB.
323 .Bl -tag -width ".Va TCPCTL_DO_RFC1323"
324 .It Dv TCPCTL_DO_RFC1323
325 .Pq Va rfc1323
326 Implement the window scaling and timestamp options of RFC 1323
327 (default is true).
328 .It Dv TCPCTL_MSSDFLT
329 .Pq Va mssdflt
330 The default value used for the maximum segment size
331 .Pq Dq MSS
332 when no advice to the contrary is received from MSS negotiation.
333 .It Dv TCPCTL_SENDSPACE
334 .Pq Va sendspace
335 Maximum
336 .Tn TCP
337 send window.
338 .It Dv TCPCTL_RECVSPACE
339 .Pq Va recvspace
340 Maximum
341 .Tn TCP
342 receive window.
343 .It Va log_in_vain
344 Log any connection attempts to ports where there is not a socket
345 accepting connections.
346 The value of 1 limits the logging to
347 .Tn SYN
348 (connection establishment) packets only.
349 That of 2 results in any
350 .Tn TCP
351 packets to closed ports being logged.
352 Any value unlisted above disables the logging
353 (default is 0, i.e., the logging is disabled).
354 .It Va slowstart_flightsize
355 The number of packets allowed to be in-flight during the
356 .Tn TCP
357 slow-start phase on a non-local network.
358 .It Va local_slowstart_flightsize
359 The number of packets allowed to be in-flight during the
360 .Tn TCP
361 slow-start phase to local machines in the same subnet.
362 .It Va msl
363 The Maximum Segment Lifetime, in milliseconds, for a packet.
364 .It Va keepinit
365 Timeout, in milliseconds, for new, non-established
366 .Tn TCP
367 connections.
368 The default is 75000 msec.
369 .It Va keepidle
370 Amount of time, in milliseconds, that the connection must be idle
371 before keepalive probes (if enabled) are sent.
372 The default is 7200000 msec (2 hours).
373 .It Va keepintvl
374 The interval, in milliseconds, between keepalive probes sent to remote
375 machines, when no response is received on a
376 .Va keepidle
377 probe.
378 The default is 75000 msec.
379 .It Va keepcnt
380 Number of probes sent, with no response, before a connection
381 is dropped.
382 The default is 8 packets.
383 .It Va always_keepalive
384 Assume that
385 .Dv SO_KEEPALIVE
386 is set on all
387 .Tn TCP
388 connections, the kernel will
389 periodically send a packet to the remote host to verify the connection
390 is still up.
391 .It Va icmp_may_rst
392 Certain
393 .Tn ICMP
394 unreachable messages may abort connections in
395 .Tn SYN-SENT
396 state.
397 .It Va do_tcpdrain
398 Flush packets in the
399 .Tn TCP
400 reassembly queue if the system is low on mbufs.
401 .It Va blackhole
402 If enabled, disable sending of RST when a connection is attempted
403 to a port where there is not a socket accepting connections.
404 See
405 .Xr blackhole 4 .
406 .It Va delayed_ack
407 Delay ACK to try and piggyback it onto a data packet.
408 .It Va delacktime
409 Maximum amount of time, in milliseconds, before a delayed ACK is sent.
410 .It Va path_mtu_discovery
411 Enable Path MTU Discovery.
412 .It Va tcbhashsize
413 Size of the
414 .Tn TCP
415 control-block hash table
416 (read-only).
417 This may be tuned using the kernel option
418 .Dv TCBHASHSIZE
419 or by setting
420 .Va net.inet.tcp.tcbhashsize
421 in the
422 .Xr loader 8 .
423 .It Va pcbcount
424 Number of active process control blocks
425 (read-only).
426 .It Va syncookies
427 Determines whether or not
428 .Tn SYN
429 cookies should be generated for outbound
430 .Tn SYN-ACK
431 packets.
432 .Tn SYN
433 cookies are a great help during
434 .Tn SYN
435 flood attacks, and are enabled by default.
436 (See
437 .Xr syncookies 4 . )
438 .It Va isn_reseed_interval
439 The interval (in seconds) specifying how often the secret data used in
440 RFC 1948 initial sequence number calculations should be reseeded.
441 By default, this variable is set to zero, indicating that
442 no reseeding will occur.
443 Reseeding should not be necessary, and will break
444 .Dv TIME_WAIT
445 recycling for a few minutes.
446 .It Va rexmit_min , rexmit_slop
447 Adjust the retransmit timer calculation for
448 .Tn TCP .
449 The slop is
450 typically added to the raw calculation to take into account
451 occasional variances that the
452 .Tn SRTT
453 (smoothed round-trip time)
454 is unable to accommodate, while the minimum specifies an
455 absolute minimum.
456 While a number of
457 .Tn TCP
458 RFCs suggest a 1
459 second minimum, these RFCs tend to focus on streaming behavior,
460 and fail to deal with the fact that a 1 second minimum has severe
461 detrimental effects over lossy interactive connections, such
462 as a 802.11b wireless link, and over very fast but lossy
463 connections for those cases not covered by the fast retransmit
464 code.
465 For this reason, we use 200ms of slop and a near-0
466 minimum, which gives us an effective minimum of 200ms (similar to
467 .Tn Linux ) .
468 .It Va rfc3042
469 Enable the Limited Transmit algorithm as described in RFC 3042.
470 It helps avoid timeouts on lossy links and also when the congestion window
471 is small, as happens on short transfers.
472 .It Va rfc3390
473 Enable support for RFC 3390, which allows for a variable-sized
474 starting congestion window on new connections, depending on the
475 maximum segment size.
476 This helps throughput in general, but
477 particularly affects short transfers and high-bandwidth large
478 propagation-delay connections.
479 .Pp
480 When this feature is enabled, the
481 .Va slowstart_flightsize
482 and
483 .Va local_slowstart_flightsize
484 settings are not observed for new
485 connection slow starts, but they are still used for slow starts
486 that occur when the connection has been idle and starts sending
487 again.
488 .It Va sack.enable
489 Enable support for RFC 2018, TCP Selective Acknowledgment option,
490 which allows the receiver to inform the sender about all successfully
491 arrived segments, allowing the sender to retransmit the missing segments
492 only.
493 .It Va sack.maxholes
494 Maximum number of SACK holes per connection.
495 Defaults to 128.
496 .It Va sack.globalmaxholes
497 Maximum number of SACK holes per system, across all connections.
498 Defaults to 65536.
499 .It Va maxtcptw
500 When a TCP connection enters the
501 .Dv TIME_WAIT
502 state, its associated socket structure is freed, since it is of
503 negligible size and use, and a new structure is allocated to contain a
504 minimal amount of information necessary for sustaining a connection in
505 this state, called the compressed TCP TIME_WAIT state.
506 Since this structure is smaller than a socket structure, it can save
507 a significant amount of system memory.
508 The
509 .Va net.inet.tcp.maxtcptw
510 MIB variable controls the maximum number of these structures allocated.
511 By default, it is initialized to
512 .Va kern.ipc.maxsockets
513 / 5.
514 .It Va nolocaltimewait
515 Suppress creating of compressed TCP TIME_WAIT states for connections in
516 which both endpoints are local.
517 .It Va fast_finwait2_recycle
518 Recycle
519 .Tn TCP
520 .Dv FIN_WAIT_2
521 connections faster when the socket is marked as
522 .Dv SBS_CANTRCVMORE
523 (no user process has the socket open, data received on
524 the socket cannot be read).
525 The timeout used here is
526 .Va finwait2_timeout .
527 .It Va finwait2_timeout
528 Timeout to use for fast recycling of
529 .Tn TCP
530 .Dv FIN_WAIT_2
531 connections.
532 Defaults to 60 seconds.
533 .It Va ecn.enable
534 Enable support for TCP Explicit Congestion Notification (ECN).
535 ECN allows a TCP sender to reduce the transmission rate in order to
536 avoid packet drops.
537 .It Va ecn.maxretries
538 Number of retries (SYN or SYN/ACK retransmits) before disabling ECN on a
539 specific connection. This is needed to help with connection establishment
540 when a broken firewall is in the network path.
541 .El
542 .Sh ERRORS
543 A socket operation may fail with one of the following errors returned:
544 .Bl -tag -width Er
545 .It Bq Er EISCONN
546 when trying to establish a connection on a socket which
547 already has one;
548 .It Bq Er ENOBUFS
549 when the system runs out of memory for
550 an internal data structure;
551 .It Bq Er ETIMEDOUT
552 when a connection was dropped
553 due to excessive retransmissions;
554 .It Bq Er ECONNRESET
555 when the remote peer
556 forces the connection to be closed;
557 .It Bq Er ECONNREFUSED
558 when the remote
559 peer actively refuses connection establishment (usually because
560 no process is listening to the port);
561 .It Bq Er EADDRINUSE
562 when an attempt
563 is made to create a socket with a port which has already been
564 allocated;
565 .It Bq Er EADDRNOTAVAIL
566 when an attempt is made to create a
567 socket with a network address for which no network interface
568 exists;
569 .It Bq Er EAFNOSUPPORT
570 when an attempt is made to bind or connect a socket to a multicast
571 address.
572 .El
573 .Sh SEE ALSO
574 .Xr getsockopt 2 ,
575 .Xr socket 2 ,
576 .Xr sysctl 3 ,
577 .Xr blackhole 4 ,
578 .Xr inet 4 ,
579 .Xr intro 4 ,
580 .Xr ip 4 ,
581 .Xr mod_cc 4 ,
582 .Xr syncache 4 ,
583 .Xr setkey 8
584 .Rs
585 .%A "V. Jacobson"
586 .%A "R. Braden"
587 .%A "D. Borman"
588 .%T "TCP Extensions for High Performance"
589 .%O "RFC 1323"
590 .Re
591 .Rs
592 .%A "A. Heffernan"
593 .%T "Protection of BGP Sessions via the TCP MD5 Signature Option"
594 .%O "RFC 2385"
595 .Re
596 .Rs
597 .%A "K. Ramakrishnan"
598 .%A "S. Floyd"
599 .%A "D. Black"
600 .%T "The Addition of Explicit Congestion Notification (ECN) to IP"
601 .%O "RFC 3168"
602 .Re
603 .Sh HISTORY
604 The
605 .Tn TCP
606 protocol appeared in
607 .Bx 4.2 .
608 The RFC 1323 extensions for window scaling and timestamps were added
609 in
610 .Bx 4.4 .
611 The
612 .Dv TCP_INFO
613 option was introduced in
614 .Tn Linux 2.6
615 and is
616 .Em subject to change .