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