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