xref: /freebsd/share/man/man4/tcp.4 (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
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. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd August 3, 2024
35.Dt TCP 4
36.Os
37.Sh NAME
38.Nm tcp
39.Nd Internet Transmission Control Protocol
40.Sh SYNOPSIS
41.In sys/types.h
42.In sys/socket.h
43.In netinet/in.h
44.In netinet/tcp.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.
52It is a byte-stream protocol used to
53support the
54.Dv SOCK_STREAM
55abstraction.
56.Tn TCP
57uses the standard
58Internet address format and, in addition, provides a per-host
59collection of
60.Dq "port addresses" .
61Thus, each address is composed
62of an Internet address specifying the host and network,
63with a specific
64.Tn TCP
65port on the host identifying the peer entity.
66.Pp
67Sockets utilizing the
68.Tn TCP
69protocol are either
70.Dq active
71or
72.Dq passive .
73Active sockets initiate connections to passive
74sockets.
75By default,
76.Tn TCP
77sockets are created active; to create a
78passive socket, the
79.Xr listen 2
80system call must be used
81after binding the socket with the
82.Xr bind 2
83system call.
84Only passive sockets may use the
85.Xr accept 2
86call to accept incoming connections.
87Only active sockets may use the
88.Xr connect 2
89call to initiate connections.
90.Pp
91Passive sockets may
92.Dq underspecify
93their location to match
94incoming connection requests from multiple networks.
95This technique, termed
96.Dq "wildcard addressing" ,
97allows a single
98server to provide service to clients on multiple networks.
99To create a socket which listens on all networks, the Internet
100address
101.Dv INADDR_ANY
102must be bound.
103The
104.Tn TCP
105port may still be specified
106at this time; if the port is not specified, the system will assign one.
107Once a connection has been established, the socket's address is
108fixed by the peer entity's location.
109The address assigned to the
110socket is the address associated with the network interface
111through which packets are being transmitted and received.
112Normally, this address corresponds to the peer entity's network.
113.Pp
114.Tn TCP
115supports a number of socket options which can be set with
116.Xr setsockopt 2
117and tested with
118.Xr getsockopt 2 :
119.Bl -tag -width ".Dv TCP_FUNCTION_BLK"
120.It Dv TCP_INFO
121Information about a socket's underlying TCP session may be retrieved
122by passing the read-only option
123.Dv TCP_INFO
124to
125.Xr getsockopt 2 .
126It accepts a single argument: a pointer to an instance of
127.Vt "struct tcp_info" .
128.Pp
129This API is subject to change; consult the source to determine
130which fields are currently filled out by this option.
131.Fx
132specific additions include
133send window size,
134receive window size,
135and
136bandwidth-controlled window space.
137.It Dv TCP_CCALGOOPT
138Set or query congestion control algorithm specific parameters.
139See
140.Xr mod_cc 4
141for details.
142.It Dv TCP_CONGESTION
143Select or query the congestion control algorithm that TCP will use for the
144connection.
145See
146.Xr mod_cc 4
147for details.
148.It Dv TCP_FASTOPEN
149Enable or disable TCP Fast Open (TFO).
150To use this option, the kernel must be built with the
151.Dv TCP_RFC7413
152option.
153.Pp
154This option can be set on the socket either before or after the
155.Xr listen 2
156is invoked.
157Clearing this option on a listen socket after it has been set has no effect on
158existing TFO connections or TFO connections in progress; it only prevents new
159TFO connections from being established.
160.Pp
161For passively-created sockets, the
162.Dv TCP_FASTOPEN
163socket option can be queried to determine whether the connection was established
164using TFO.
165Note that connections that are established via a TFO
166.Tn SYN ,
167but that fall back to using a non-TFO
168.Tn SYN|ACK
169will have the
170.Dv TCP_FASTOPEN
171socket option set.
172.Pp
173In addition to the facilities defined in RFC7413, this implementation supports a
174pre-shared key (PSK) mode of operation in which the TFO server requires the
175client to be in possession of a shared secret in order for the client to be able
176to successfully open TFO connections with the server.
177This is useful, for example, in environments where TFO servers are exposed to
178both internal and external clients and only wish to allow TFO connections from
179internal clients.
180.Pp
181In the PSK mode of operation, the server generates and sends TFO cookies to
182requesting clients as usual.
183However, when validating cookies received in TFO SYNs from clients, the server
184requires the client-supplied cookie to equal
185.Bd -literal -offset left
186SipHash24(key=\fI16-byte-psk\fP, msg=\fIcookie-sent-to-client\fP)
187.Ed
188.Pp
189Multiple concurrent valid pre-shared keys are supported so that time-based
190rolling PSK invalidation policies can be implemented in the system.
191The default number of concurrent pre-shared keys is 2.
192.Pp
193This can be adjusted with the
194.Dv TCP_RFC7413_MAX_PSKS
195kernel option.
196.It Dv TCP_FUNCTION_BLK
197Select or query the set of functions that TCP will use for this connection.
198This allows a user to select an alternate TCP stack.
199The alternate TCP stack must already be loaded in the kernel.
200To list the available TCP stacks, see
201.Va functions_available
202in the
203.Sx MIB (sysctl) Variables
204section further down.
205To list the default TCP stack, see
206.Va functions_default
207in the
208.Sx MIB (sysctl) Variables
209section.
210.It Dv TCP_KEEPINIT
211This
212.Xr setsockopt 2
213option accepts a per-socket timeout argument of
214.Vt "u_int"
215in seconds, for new, non-established
216.Tn TCP
217connections.
218For the global default in milliseconds see
219.Va keepinit
220in the
221.Sx MIB (sysctl) Variables
222section further down.
223.It Dv TCP_KEEPIDLE
224This
225.Xr setsockopt 2
226option accepts an argument of
227.Vt "u_int"
228for the amount of time, in seconds, that the connection must be idle
229before keepalive probes (if enabled) are sent for the connection of this
230socket.
231If set on a listening socket, the value is inherited by the newly created
232socket upon
233.Xr accept 2 .
234For the global default in milliseconds see
235.Va keepidle
236in the
237.Sx MIB (sysctl) Variables
238section further down.
239.It Dv TCP_KEEPINTVL
240This
241.Xr setsockopt 2
242option accepts an argument of
243.Vt "u_int"
244to set the per-socket interval, in seconds, between keepalive probes sent
245to a peer.
246If set on a listening socket, the value is inherited by the newly created
247socket upon
248.Xr accept 2 .
249For the global default in milliseconds see
250.Va keepintvl
251in the
252.Sx MIB (sysctl) Variables
253section further down.
254.It Dv TCP_KEEPCNT
255This
256.Xr setsockopt 2
257option accepts an argument of
258.Vt "u_int"
259and allows a per-socket tuning of the number of probes sent, with no response,
260before the connection will be dropped.
261If set on a listening socket, the value is inherited by the newly created
262socket upon
263.Xr accept 2 .
264For the global default see the
265.Va keepcnt
266in the
267.Sx MIB (sysctl) Variables
268section further down.
269.It Dv TCP_NODELAY
270Under most circumstances,
271.Tn TCP
272sends data when it is presented;
273when outstanding data has not yet been acknowledged, it gathers
274small amounts of output to be sent in a single packet once
275an acknowledgement is received.
276For a small number of clients, such as window systems
277that send a stream of mouse events which receive no replies,
278this packetization may cause significant delays.
279The boolean option
280.Dv TCP_NODELAY
281defeats this algorithm.
282
283.It Dv TCP_MAXSEG
284By default, a sender- and
285.No receiver- Ns Tn TCP
286will negotiate among themselves to determine the maximum segment size
287to be used for each connection.
288The
289.Dv TCP_MAXSEG
290option allows the user to determine the result of this negotiation,
291and to reduce it if desired.
292.It Dv TCP_MAXUNACKTIME
293This
294.Xr setsockopt 2
295option accepts an argument of
296.Vt "u_int"
297to set the per-socket interval, in seconds, in which the connection must
298make progress. Progress is defined by at least 1 byte being acknowledged within
299the set time period. If a connection fails to make progress, then the
300.Tn TCP
301stack will terminate the connection with a reset. Note that the default
302value for this is zero which indicates no progress checks should be made.
303.It Dv TCP_NOOPT
304.Tn TCP
305usually sends a number of options in each packet, corresponding to
306various
307.Tn TCP
308extensions which are provided in this implementation.
309The boolean option
310.Dv TCP_NOOPT
311is provided to disable
312.Tn TCP
313option use on a per-connection basis.
314.It Dv TCP_NOPUSH
315By convention, the
316.No sender- Ns Tn TCP
317will set the
318.Dq push
319bit, and begin transmission immediately (if permitted) at the end of
320every user call to
321.Xr write 2
322or
323.Xr writev 2 .
324When this option is set to a non-zero value,
325.Tn TCP
326will delay sending any data at all until either the socket is closed,
327or the internal send buffer is filled.
328.It Dv TCP_MD5SIG
329This option enables the use of MD5 digests (also known as TCP-MD5)
330on writes to the specified socket.
331Outgoing traffic is digested;
332digests on incoming traffic are verified.
333When this option is enabled on a socket, all inbound and outgoing
334TCP segments must be signed with MD5 digests.
335.Pp
336One common use for this in a
337.Fx
338router deployment is to enable
339based routers to interwork with Cisco equipment at peering points.
340Support for this feature conforms to RFC 2385.
341.Pp
342In order for this option to function correctly, it is necessary for the
343administrator to add a tcp-md5 key entry to the system's security
344associations database (SADB) using the
345.Xr setkey 8
346utility.
347This entry can only be specified on a per-host basis at this time.
348.Pp
349If an SADB entry cannot be found for the destination,
350the system does not send any outgoing segments and drops any inbound segments.
351However, during connection negotiation, a non-signed segment will be accepted if
352an SADB entry does not exist between hosts.
353When a non-signed segment is accepted, the established connection is not
354protected with MD5 digests.
355.It Dv TCP_STATS
356Manage collection of connection level statistics using the
357.Xr stats 3
358framework.
359.Pp
360Each dropped segment is taken into account in the TCP protocol statistics.
361.It Dv TCP_TXTLS_ENABLE
362Enable in-kernel Transport Layer Security (TLS) for data written to this
363socket.
364See
365.Xr ktls 4
366for more details.
367.It Dv TCP_TXTLS_MODE
368The integer argument can be used to get or set the current TLS transmit mode
369of a socket.
370See
371.Xr ktls 4
372for more details.
373.It Dv TCP_RXTLS_ENABLE
374Enable in-kernel TLS for data read from this socket.
375See
376.Xr ktls 4
377for more details.
378.It Dv TCP_REUSPORT_LB_NUMA
379Changes NUMA affinity filtering for an established TCP listen
380socket.
381This option takes a single integer argument which specifies
382the NUMA domain to filter on for this listen socket.
383The argument can also have the following special values:
384.Bl -tag -width "Dv TCP_REUSPORT_LB_NUMA"
385.It Dv TCP_REUSPORT_LB_NUMA_NODOM
386Remove NUMA filtering for this listen socket.
387.It Dv TCP_REUSPORT_LB_NUMA_CURDOM
388Filter traffic associated with the domain where the calling thread is
389currently executing.
390This is typically used after a process or thread inherits a listen
391socket from its parent, and sets its CPU affinity to a particular core.
392.El
393.It Dv TCP_REMOTE_UDP_ENCAPS_PORT
394Set and get the remote UDP encapsulation port.
395It can only be set on a closed TCP socket.
396.El
397.Pp
398The option level for the
399.Xr setsockopt 2
400call is the protocol number for
401.Tn TCP ,
402available from
403.Xr getprotobyname 3 ,
404or
405.Dv IPPROTO_TCP .
406All options are declared in
407.In netinet/tcp.h .
408.Pp
409Options at the
410.Tn IP
411transport level may be used with
412.Tn TCP ;
413see
414.Xr ip 4 .
415Incoming connection requests that are source-routed are noted,
416and the reverse source route is used in responding.
417.Pp
418The default congestion control algorithm for
419.Tn TCP
420is
421.Xr cc_newreno 4 .
422Other congestion control algorithms can be made available using the
423.Xr mod_cc 4
424framework.
425.Ss MIB (sysctl) Variables
426The
427.Tn TCP
428protocol implements a number of variables in the
429.Va net.inet.tcp
430branch of the
431.Xr sysctl 3
432MIB, which can also be read or modified with
433.Xr sysctl 8 .
434.Bl -tag -width ".Va v6pmtud_blackhole_mss"
435.It Va ack_war_timewindow , ack_war_cnt
436The challenge ACK throttling algorithm defined in RFC 5961 limits
437the number of challenge ACKs sent per TCP connection to
438.Va ack_war_cnt
439during the time interval specified in milliseconds by
440.Va ack_war_timewindow .
441Setting
442.Va ack_war_timewindow
443or
444.Va ack_war_cnt
445to zero disables challenge ACK throttling.
446.It Va always_keepalive
447Assume that
448.Dv SO_KEEPALIVE
449is set on all
450.Tn TCP
451connections, the kernel will
452periodically send a packet to the remote host to verify the connection
453is still up.
454.It Va blackhole
455If enabled, disable sending of RST when a connection is attempted
456to a port where there is no socket accepting connections.
457See
458.Xr blackhole 4 .
459.It Va blackhole_local
460See
461.Xr blackhole 4 .
462.It Va cc
463A number of variables for congestion control are under the
464.Va net.inet.tcp.cc
465node.
466See
467.Xr mod_cc 4 .
468.It Va cc.newreno
469Variables for NewReno congestion control are under the
470.Va net.inet.tcp.cc.newreno
471node.
472See
473.Xr cc_newreno 4 .
474.It Va delacktime
475Maximum amount of time, in milliseconds, before a delayed ACK is sent.
476.It Va delayed_ack
477Delay ACK to try and piggyback it onto a data packet or another ACK.
478.It Va do_prr
479Perform SACK loss recovery using the Proportional Rate Reduction (PRR) algorithm
480described in RFC6937.
481This improves the effectiveness of retransmissions particular in environments
482with ACK thinning or burst loss events, as chances to run out of the ACK clock
483are reduced, preventing lengthy and performance reducing RTO based loss recovery
484(default is true).
485.It Va do_tcpdrain
486Flush packets in the
487.Tn TCP
488reassembly queue if the system is low on mbufs.
489.It Va drop_synfin
490Drop TCP packets with both SYN and FIN set.
491.It Va ecn.enable
492Enable support for TCP Explicit Congestion Notification (ECN).
493ECN allows a TCP sender to reduce the transmission rate in order to
494avoid packet drops.
495.Bl -tag -compact
496.It 0
497Disable ECN.
498.It 1
499Allow incoming connections to request ECN.
500Outgoing connections will request ECN.
501.It 2
502Allow incoming connections to request ECN.
503Outgoing connections will not request ECN.
504(default)
505.It 3
506Negotiate on incoming connection for Accurate ECN, ECN, or no ECN.
507Outgoing connections will request Accurate ECN and fall back to
508ECN depending on the capabilities of the server.
509.It 4
510Negotiate on incoming connection for Accurate ECN, ECN, or no ECN.
511Outgoing connections will not request ECN.
512.El
513.It Va ecn.maxretries
514Number of retries (SYN or SYN/ACK retransmits) before disabling ECN on a
515specific connection.
516This is needed to help with connection establishment
517when a broken firewall is in the network path.
518.It Va fast_finwait2_recycle
519Recycle
520.Tn TCP
521.Dv FIN_WAIT_2
522connections faster when the socket is marked as
523.Dv SBS_CANTRCVMORE
524(no user process has the socket open, data received on
525the socket cannot be read).
526The timeout used here is
527.Va finwait2_timeout .
528.It Va fastopen.acceptany
529When non-zero, all client-supplied TFO cookies will be considered to be valid.
530The default is 0.
531.It Va fastopen.autokey
532When this and
533.Va net.inet.tcp.fastopen.server_enable
534are non-zero, a new key will be automatically generated after this specified
535seconds.
536The default is 120.
537.It Va fastopen.ccache_bucket_limit
538The maximum number of entries in a client cookie cache bucket.
539The default value can be tuned with the
540.Dv TCP_FASTOPEN_CCACHE_BUCKET_LIMIT_DEFAULT
541kernel option or by setting
542.Va net.inet.tcp.fastopen_ccache_bucket_limit
543in the
544.Xr loader 8 .
545.It Va fastopen.ccache_buckets
546The number of client cookie cache buckets.
547Read-only.
548The value can be tuned with the
549.Dv TCP_FASTOPEN_CCACHE_BUCKETS_DEFAULT
550kernel option or by setting
551.Va fastopen.ccache_buckets
552in the
553.Xr loader 8 .
554.It Va fastopen.ccache_list
555Print the client cookie cache.
556Read-only.
557.It Va fastopen.client_enable
558When zero, no new active (i.e., client) TFO connections can be created.
559On the transition from enabled to disabled, the client cookie cache is cleared
560and disabled.
561The transition from enabled to disabled does not affect any active TFO
562connections in progress; it only prevents new ones from being established.
563The default is 0.
564.It Va fastopen.keylen
565The key length in bytes.
566Read-only.
567.It Va fastopen.maxkeys
568The maximum number of keys supported.
569Read-only,
570.It Va fastopen.maxpsks
571The maximum number of pre-shared keys supported.
572Read-only.
573.It Va fastopen.numkeys
574The current number of keys installed.
575Read-only.
576.It Va fastopen.numpsks
577The current number of pre-shared keys installed.
578Read-only.
579.It Va fastopen.path_disable_time
580When a failure occurs while trying to create a new active (i.e., client) TFO
581connection, new active connections on the same path, as determined by the tuple
582.Brq client_ip, server_ip, server_port ,
583will be forced to be non-TFO for this many seconds.
584Note that the path disable mechanism relies on state stored in client cookie
585cache entries, so it is possible for the disable time for a given path to be
586reduced if the corresponding client cookie cache entry is reused due to resource
587pressure before the disable period has elapsed.
588The default is
589.Dv TCP_FASTOPEN_PATH_DISABLE_TIME_DEFAULT .
590.It Va fastopen.psk_enable
591When non-zero, pre-shared key (PSK) mode is enabled for all TFO servers.
592On the transition from enabled to disabled, all installed pre-shared keys are
593removed.
594The default is 0.
595.It Va fastopen.server_enable
596When zero, no new passive (i.e., server) TFO connections can be created.
597On the transition from enabled to disabled, all installed keys and pre-shared
598keys are removed.
599On the transition from disabled to enabled, if
600.Va fastopen.autokey
601is non-zero and there are no keys installed, a new key will be generated
602immediately.
603The transition from enabled to disabled does not affect any passive TFO
604connections in progress; it only prevents new ones from being established.
605The default is 0.
606.It Va fastopen.setkey
607Install a new key by writing
608.Va net.inet.tcp.fastopen.keylen
609bytes to this sysctl.
610.It Va fastopen.setpsk
611Install a new pre-shared key by writing
612.Va net.inet.tcp.fastopen.keylen
613bytes to this sysctl.
614.It Va finwait2_timeout
615Timeout to use for fast recycling of
616.Tn TCP
617.Dv FIN_WAIT_2
618connections
619.Pq Va fast_finwait2_recycle .
620Defaults to 60 seconds.
621.It Va functions_available
622List of available TCP function blocks (TCP stacks).
623.It Va functions_default
624The default TCP function block (TCP stack).
625.It Va hostcache
626The TCP host cache is used to cache connection details and metrics to
627improve future performance of connections between the same hosts.
628At the completion of a TCP connection, a host will cache information
629for the connection for some defined period of time.
630There are a number of
631.Va hostcache
632variables under this node.
633See
634.Va hostcache.enable .
635.It Va hostcache.bucketlimit
636The maximum number of entries for the same hash.
637Defaults to 30.
638.It Va hostcache.cachelimit
639Overall entry limit for hostcache.
640Defaults to
641.Va hashsize
642*
643.Va bucketlimit .
644.It Va hostcache.count
645The current number of entries in the host cache.
646.It Va hostcache.enable
647Enable/disable the host cache:
648.Bl -tag -compact
649.It 0
650Disable the host cache.
651.It 1
652Enable the host cache. (default)
653.El
654.It Va hostcache.expire
655Time in seconds, how long a entry should be kept in the
656host cache since last accessed.
657Defaults to 3600 (1 hour).
658.It Va hostcache.hashsize
659Size of TCP hostcache hashtable.
660This number has to be a power of two, or will be rejected.
661Defaults to 512.
662.It Va hostcache.histo
663Provide a Histogram of the hostcache hash utilization.
664.It Va hostcache.list
665Provide a complete list of all current entries in the host
666cache.
667.It Va hostcache.prune
668Time in seconds between pruning expired host cache entries.
669Defaults to 300 (5 minutes).
670.It Va hostcache.purge
671Expire all entries on next pruning of host cache entries.
672Any non-zero setting will be reset to zero, once the purge
673is running.
674.Bl -tag -compact
675.It 0
676Do not purge all entries when pruning the host cache (default).
677.It 1
678Purge all entries when doing the next pruning.
679.It 2
680Purge all entries and also reseed the hash salt.
681.El
682.It Va hostcache.purgenow
683Immediately purge all entries once set to any value.
684Setting this to 2 will also reseed the hash salt.
685.It Va icmp_may_rst
686Certain
687.Tn ICMP
688unreachable messages may abort connections in
689.Tn SYN-SENT
690state.
691.It Va initcwnd_segments
692Enable the ability to specify initial congestion window in number of segments.
693The default value is 10 as suggested by RFC 6928.
694Changing the value on the fly would not affect connections
695using congestion window from the hostcache.
696Caution:
697This regulates the burst of packets allowed to be sent in the first RTT.
698The value should be relative to the link capacity.
699Start with small values for lower-capacity links.
700Large bursts can cause buffer overruns and packet drops if routers have small
701buffers or the link is experiencing congestion.
702.It Va insecure_rst
703Use criteria defined in RFC793 instead of RFC5961 for accepting RST segments.
704Default is false.
705.It Va insecure_syn
706Use criteria defined in RFC793 instead of RFC5961 for accepting SYN segments.
707Default is false.
708.It Va insecure_ack
709Use criteria defined in RFC793 for validating SEG.ACK.
710Default is false.
711.It Va isn_reseed_interval
712The interval (in seconds) specifying how often the secret data used in
713RFC 1948 initial sequence number calculations should be reseeded.
714By default, this variable is set to zero, indicating that
715no reseeding will occur.
716Reseeding should not be necessary, and will break
717.Dv TIME_WAIT
718recycling for a few minutes.
719.It Va keepcnt
720Number of keepalive probes sent, with no response, before a connection
721is dropped.
722The default is 8 packets.
723.It Va keepidle
724Amount of time, in milliseconds, that the connection must be idle
725before sending keepalive probes (if enabled).
726The default is 7200000 msec (7.2M msec, 2 hours).
727.It Va keepinit
728Timeout, in milliseconds, for new, non-established
729.Tn TCP
730connections.
731The default is 75000 msec (75K msec, 75 sec).
732.It Va keepintvl
733The interval, in milliseconds, between keepalive probes sent to remote
734machines, when no response is received on a
735.Va keepidle
736probe.
737The default is 75000 msec (75K msec, 75 sec).
738.It Va log_in_vain
739Log any connection attempts to ports where there is no socket
740accepting connections.
741The value of 1 limits the logging to
742.Tn SYN
743(connection establishment) packets only.
744A value of 2 results in any
745.Tn TCP
746packets to closed ports being logged.
747Any value not listed above disables the logging
748(default is 0, i.e., the logging is disabled).
749.It Va minmss
750Minimum TCP Maximum Segment Size; used to prevent a denial of service attack
751from an unreasonably low MSS.
752.It Va msl
753The Maximum Segment Lifetime, in milliseconds, for a packet.
754.It Va mssdflt
755The default value used for the TCP Maximum Segment Size
756.Pq Dq MSS
757for IPv4 when no advice to the contrary is received from MSS negotiation.
758.It Va newcwd
759Enable the New Congestion Window Validation mechanism as described in RFC 7661.
760This gently reduces the congestion window during periods, where TCP is
761application limited and the network bandwidth is not utilized completely.
762That prevents self-inflicted packet losses once the application starts to
763transmit data at a higher speed.
764.It Va nolocaltimewait
765Suppress creation of TCP
766.Dv TIME_WAIT
767states for connections in
768which both endpoints are local.
769.It Va path_mtu_discovery
770Enable Path MTU Discovery.
771.It Va pcbcount
772Number of active protocol control blocks
773(read-only).
774.It Va perconn_stats_enable
775Controls the default collection of statistics for all connections using the
776.Xr stats 3
777framework.
7780 disables, 1 enables, 2 enables random sampling across log id connection
779groups with all connections in a group receiving the same setting.
780.It Va perconn_stats_sample_rates
781A CSV list of template_spec=percent key-value pairs which controls the per
782template sampling rates when
783.Xr stats 3
784sampling is enabled.
785.It Va persmax
786Maximum persistence interval, msec.
787.It Va persmin
788Minimum persistence interval, msec.
789.It Va pmtud_blackhole_detection
790Enable automatic path MTU blackhole detection.
791In case of retransmits of MSS sized segments,
792the OS will lower the MSS to check if it's an MTU problem.
793If the current MSS is greater than the configured value to try
794.Po Va net.inet.tcp.pmtud_blackhole_mss
795and
796.Va net.inet.tcp.v6pmtud_blackhole_mss
797.Pc ,
798it will be set to this value, otherwise,
799the MSS will be set to the default values
800.Po Va net.inet.tcp.mssdflt
801and
802.Va net.inet.tcp.v6mssdflt
803.Pc .
804Settings:
805.Bl -tag -compact
806.It 0
807Disable path MTU blackhole detection.
808.It 1
809Enable path MTU blackhole detection for IPv4 and IPv6.
810.It 2
811Enable path MTU blackhole detection only for IPv4.
812.It 3
813Enable path MTU blackhole detection only for IPv6.
814.El
815.It Va pmtud_blackhole_mss
816MSS to try for IPv4 if PMTU blackhole detection is turned on.
817.It Va reass.cursegments
818The current total number of segments present in all reassembly queues.
819.It Va reass.maxqueuelen
820The maximum number of segments allowed in each reassembly queue.
821By default, the system chooses a limit based on each TCP connection's
822receive buffer size and maximum segment size (MSS).
823The actual limit applied to a session's reassembly queue will be the lower of
824the system-calculated automatic limit and the user-specified
825.Va reass.maxqueuelen
826limit.
827.It Va reass.maxsegments
828The maximum limit on the total number of segments across all reassembly
829queues.
830The limit can be adjusted as a tunable.
831.It Va recvbuf_auto
832Enable automatic receive buffer sizing as a connection progresses.
833.It Va recvbuf_max
834Maximum size of automatic receive buffer.
835.It Va recvspace
836Initial
837.Tn TCP
838receive window (buffer size).
839.It Va retries
840Maximum number of consecutive timer based retransmits sent after a data
841segment is lost (default and maximum is 12).
842.It Va rexmit_drop_options
843Drop TCP options from third and later retransmitted SYN segments
844of a connection.
845.It Va rexmit_initial , rexmit_min , rexmit_slop
846Adjust the retransmit timer calculation for
847.Tn TCP .
848The slop is
849typically added to the raw calculation to take into account
850occasional variances that the
851.Tn SRTT
852(smoothed round-trip time)
853is unable to accommodate, while the minimum specifies an
854absolute minimum.
855While a number of
856.Tn TCP
857RFCs suggest a 1
858second minimum, these RFCs tend to focus on streaming behavior,
859and fail to deal with the fact that a 1 second minimum has severe
860detrimental effects over lossy interactive connections, such
861as a 802.11b wireless link, and over very fast but lossy
862connections for those cases not covered by the fast retransmit
863code.
864For this reason, we use 200ms of slop and a near-0
865minimum, which gives us an effective minimum of 200ms (similar to
866.Tn Linux ) .
867The initial value is used before an RTT measurement has been performed.
868.It Va rfc1323
869Implement the window scaling and timestamp options of RFC 1323/RFC 7323
870(default is 1).
871Settings:
872.Bl -tag -compact
873.It 0
874Disable window scaling and timestamp option.
875.It 1
876Enable window scaling and timestamp option.
877.It 2
878Enable only window scaling.
879.It 3
880Enable only timestamp option.
881.El
882.It Va rfc3042
883Enable the Limited Transmit algorithm as described in RFC 3042.
884It helps avoid timeouts on lossy links and also when the congestion window
885is small, as happens on short transfers.
886.It Va rfc3390
887Enable support for RFC 3390, which allows for a variable-sized
888starting congestion window on new connections, depending on the
889maximum segment size.
890This helps throughput in general, but
891particularly affects short transfers and high-bandwidth large
892propagation-delay connections.
893.It Va rfc6675_pipe
894Deprecated and superseded by
895.Va sack.revised
896.It Va sack.enable
897Enable support for RFC 2018, TCP Selective Acknowledgment option,
898which allows the receiver to inform the sender about all successfully
899arrived segments, allowing the sender to retransmit the missing segments
900only.
901.It Va sack.globalholes
902Global number of TCP SACK holes currently allocated.
903.It Va sack.globalmaxholes
904Maximum number of SACK holes per system, across all connections.
905Defaults to 65536.
906.It Va sack.lrd
907Enable Lost Retransmission Detection for SACK-enabled sessions, enabled by
908default.
909Under severe congestion, a retransmission can be lost which then leads to a
910mandatory Retransmission Timeout (RTO), followed by slow-start.
911LRD will try to resend the repeatedly lost packet, preventing the time-consuming
912RTO and performance reducing slow-start or purge of the SACK scoreboard.
913.It Va sack.maxholes
914Maximum number of SACK holes per connection.
915Defaults to 128.
916.It Va sack.revised
917Enables three updated mechanisms from RFC6675 (default is true).
918Calculate the bytes in flight using the algorithm described in RFC 6675, and
919is also an improvement when Proportional Rate Reduction is enabled.
920Next, Rescue Retransmission helps timely loss recovery, when the trailing segments
921of a transmission are lost, while no additional data is ready to be sent.
922In case a partial ACK without a SACK block is received during SACK loss
923recovery, the trailing segment is immediately resent, rather than waiting
924for a Retransmission timeout.
925Finally, SACK loss recovery is also engaged, once two segments plus one byte are
926SACKed - even if no traditional duplicate ACKs were observed.
927.It Va sendbuf_auto
928Enable automatic send buffer sizing.
929.It Va sendbuf_auto_lowat
930Modify threshold for auto send buffer growth to account for
931.Dv SO_SNDLOWAT .
932.It Va sendbuf_inc
933Incrementor step size of automatic send buffer.
934.It Va sendbuf_max
935Maximum size of automatic send buffer.
936.It Va sendspace
937Initial
938.Tn TCP
939send window (buffer size).
940.It Va syncache
941Variables under the
942.Va net.inet.tcp.syncache
943node are documented in
944.Xr syncache 4 .
945.It Va syncookies
946Determines whether or not
947.Tn SYN
948cookies should be generated for outbound
949.Tn SYN-ACK
950packets.
951.Tn SYN
952cookies are a great help during
953.Tn SYN
954flood attacks, and are enabled by default.
955(See
956.Xr syncookies 4 . )
957.It Va syncookies_only
958See
959.Xr syncookies 4 .
960.It Va tcbhashsize
961Size of the
962.Tn TCP
963control-block hash table
964(read-only).
965This is tuned using the kernel option
966.Dv TCBHASHSIZE
967or by setting
968.Va net.inet.tcp.tcbhashsize
969in the
970.Xr loader 8 .
971.It Va tolerate_missing_ts
972Tolerate the missing of timestamps (RFC 1323/RFC 7323) for
973.Tn TCP
974segments belonging to
975.Tn TCP
976connections for which support of
977.Tn TCP
978timestamps has been negotiated.
979As of June 2021, several TCP stacks are known to violate RFC 7323, including
980modern widely deployed ones.
981Therefore the default is 1, i.e., the missing of timestamps is tolerated.
982.It Va ts_offset_per_conn
983When initializing the TCP timestamps, use a per connection offset instead of a
984per host pair offset.
985Default is to use per connection offsets as recommended in RFC 7323.
986.It Va tso
987Enable TCP Segmentation Offload.
988.It Va udp_tunneling_overhead
989The overhead taken into account when using UDP encapsulation.
990Since MSS clamping by middleboxes will most likely not work, values larger than
9918 (the size of the UDP header) are also supported.
992Supported values are between 8 and 1024.
993The default is 8.
994.It Va udp_tunneling_port
995The local UDP encapsulation port.
996A value of 0 indicates that UDP encapsulation is disabled.
997The default is 0.
998.It Va v6mssdflt
999The default value used for the TCP Maximum Segment Size
1000.Pq Dq MSS
1001for IPv6 when no advice to the contrary is received from MSS negotiation.
1002.It Va v6pmtud_blackhole_mss
1003MSS to try for IPv6 if PMTU blackhole detection is turned on.
1004See
1005.Va pmtud_blackhole_detection .
1006.El
1007.Sh ERRORS
1008A socket operation may fail with one of the following errors returned:
1009.Bl -tag -width Er
1010.It Bq Er EISCONN
1011when trying to establish a connection on a socket which
1012already has one;
1013.It Bo Er ENOBUFS Bc or Bo Er ENOMEM Bc
1014when the system runs out of memory for
1015an internal data structure;
1016.It Bq Er ETIMEDOUT
1017when a connection was dropped
1018due to excessive retransmissions;
1019.It Bq Er ECONNRESET
1020when the remote peer
1021forces the connection to be closed;
1022.It Bq Er ECONNREFUSED
1023when the remote
1024peer actively refuses connection establishment (usually because
1025no process is listening to the port);
1026.It Bq Er EADDRINUSE
1027when an attempt
1028is made to create a socket with a port which has already been
1029allocated;
1030.It Bq Er EADDRNOTAVAIL
1031when an attempt is made to create a
1032socket with a network address for which no network interface
1033exists;
1034.It Bq Er EAFNOSUPPORT
1035when an attempt is made to bind or connect a socket to a multicast
1036address.
1037.It Bq Er EINVAL
1038when trying to change TCP function blocks at an invalid point in the session;
1039.It Bq Er ENOENT
1040when trying to use a TCP function block that is not available;
1041.El
1042.Sh SEE ALSO
1043.Xr getsockopt 2 ,
1044.Xr socket 2 ,
1045.Xr stats 3 ,
1046.Xr sysctl 3 ,
1047.Xr blackhole 4 ,
1048.Xr inet 4 ,
1049.Xr intro 4 ,
1050.Xr ip 4 ,
1051.Xr ktls 4 ,
1052.Xr mod_cc 4 ,
1053.Xr siftr 4 ,
1054.Xr syncache 4 ,
1055.Xr tcp_bbr 4 ,
1056.Xr tcp_rack 4 ,
1057.Xr setkey 8 ,
1058.Xr sysctl 8 ,
1059.Xr tcp_functions 9
1060.Rs
1061.%A "V. Jacobson"
1062.%A "B. Braden"
1063.%A "D. Borman"
1064.%T "TCP Extensions for High Performance"
1065.%O "RFC 1323"
1066.Re
1067.Rs
1068.%A "D. Borman"
1069.%A "B. Braden"
1070.%A "V. Jacobson"
1071.%A "R. Scheffenegger"
1072.%T "TCP Extensions for High Performance"
1073.%O "RFC 7323"
1074.Re
1075.Rs
1076.%A "A. Heffernan"
1077.%T "Protection of BGP Sessions via the TCP MD5 Signature Option"
1078.%O "RFC 2385"
1079.Re
1080.Rs
1081.%A "K. Ramakrishnan"
1082.%A "S. Floyd"
1083.%A "D. Black"
1084.%T "The Addition of Explicit Congestion Notification (ECN) to IP"
1085.%O "RFC 3168"
1086.Re
1087.Rs
1088.%A "A. Ramaiah"
1089.%A "R. Stewart"
1090.%A "M. Dalal"
1091.%T "Improving TCP's Robustness to Blind In-Window Attacks"
1092.%O "RFC 5961"
1093.Re
1094.Sh HISTORY
1095The
1096.Tn TCP
1097protocol appeared in
1098.Bx 4.2 .
1099The RFC 1323 extensions for window scaling and timestamps were added
1100in
1101.Bx 4.4 .
1102The
1103.Dv TCP_INFO
1104option was introduced in
1105.Tn Linux 2.6
1106and is
1107.Em subject to change .
1108