xref: /freebsd/share/man/man4/tcp.4 (revision ae07a5805b1906f29e786f415d67bef334557bd3)
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 June 27, 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_cubic 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 msl_local
784The Maximum Segment Lifetime, in milliseconds, for a packet when both endpoints
785are local.
786.Va msl_local
787is only used if
788.Va nolocaltimewait ,
789which is deprecated, is zero.
790.It Va mssdflt
791The default value used for the TCP Maximum Segment Size
792.Pq Dq MSS
793for IPv4 when no advice to the contrary is received from MSS negotiation.
794.It Va newcwv
795Enable the New Congestion Window Validation mechanism as described in RFC 7661.
796This gently reduces the congestion window during periods, where TCP is
797application limited and the network bandwidth is not utilized completely.
798That prevents self-inflicted packet losses once the application starts to
799transmit data at a higher speed.
800.It Va nolocaltimewait
801Suppress the creation of TCP
802.Dv TIME_WAIT
803states for connections in
804which both endpoints are local.
805The default is 0.
806.Va nolocaltimewait
807is deprecated and will be removed in
808.Fx 16 .
809.Va msl_local
810can be used instead.
811.It Va path_mtu_discovery
812Enable Path MTU Discovery.
813.It Va pcbcount
814Number of active protocol control blocks
815(read-only).
816.It Va perconn_stats_enable
817Controls the default collection of statistics for all connections using the
818.Xr stats 3
819framework.
8200 disables, 1 enables, 2 enables random sampling across log id connection
821groups with all connections in a group receiving the same setting.
822.It Va perconn_stats_sample_rates
823A CSV list of template_spec=percent key-value pairs which controls the per
824template sampling rates when
825.Xr stats 3
826sampling is enabled.
827.It Va persmax
828Maximum persistence interval, msec.
829.It Va persmin
830Minimum persistence interval, msec.
831.It Va pmtud_blackhole_detection
832Enable automatic path MTU blackhole detection.
833In case of retransmits of MSS sized segments,
834the OS will lower the MSS to check if it's an MTU problem.
835If the current MSS is greater than the configured value to try
836.Po Va net.inet.tcp.pmtud_blackhole_mss
837and
838.Va net.inet.tcp.v6pmtud_blackhole_mss
839.Pc ,
840it will be set to this value, otherwise,
841the MSS will be set to the default values
842.Po Va net.inet.tcp.mssdflt
843and
844.Va net.inet.tcp.v6mssdflt
845.Pc .
846Settings:
847.Bl -tag -compact
848.It 0
849Disable path MTU blackhole detection.
850.It 1
851Enable path MTU blackhole detection for IPv4 and IPv6.
852.It 2
853Enable path MTU blackhole detection only for IPv4.
854.It 3
855Enable path MTU blackhole detection only for IPv6.
856.El
857.It Va pmtud_blackhole_mss
858MSS to try for IPv4 if PMTU blackhole detection is turned on.
859.It Va reass.cursegments
860The current total number of segments present in all reassembly queues.
861.It Va reass.maxqueuelen
862The maximum number of segments allowed in each reassembly queue.
863By default, the system chooses a limit based on each TCP connection's
864receive buffer size and maximum segment size (MSS).
865The actual limit applied to a session's reassembly queue will be the lower of
866the system-calculated automatic limit and the user-specified
867.Va reass.maxqueuelen
868limit.
869.It Va reass.maxsegments
870The maximum limit on the total number of segments across all reassembly
871queues.
872The limit can be adjusted as a tunable.
873.It Va recvbuf_auto
874Enable automatic receive buffer sizing as a connection progresses.
875.It Va recvbuf_max
876Maximum size of automatic receive buffer.
877.It Va recvspace
878Initial
879.Tn TCP
880receive window (buffer size).
881.It Va retries
882Maximum number of consecutive timer based retransmits sent after a data
883segment is lost (default and maximum is 12).
884.It Va rexmit_drop_options
885Drop TCP options from third and later retransmitted SYN segments
886of a connection.
887.It Va rexmit_initial , rexmit_min , rexmit_slop , rexmit_max
888Adjust the retransmit timer calculation for
889.Tn TCP .
890A new connection starts with timer set to
891.Va rexmit_initial .
892The
893.Va rexmit_slop
894typically added to the raw calculation to take into account
895occasional variances that the
896.Tn SRTT
897(smoothed round-trip time)
898is unable to accommodate, while the minimum specifies an
899absolute minimum.
900While a number of
901.Tn TCP
902RFCs suggest a 1
903second minimum, these RFCs tend to focus on streaming behavior,
904and fail to deal with the fact that a 1 second minimum has severe
905detrimental effects over lossy interactive connections, such
906as a 802.11b wireless link, and over very fast but lossy
907connections for those cases not covered by the fast retransmit
908code.
909For this reason, we use 200ms of slop and a near-0
910minimum, which gives us an effective minimum of 200ms (similar to
911.Tn Linux ) .
912The initial value is used before an RTT measurement has been performed.
913The
914.Va rexmit_min
915and
916.Va rexmit_max
917set minimum and maximum timer values that a connection may have.
918.It Va rfc1323
919Implement the window scaling and timestamp options of RFC 1323/RFC 7323
920(default is 1).
921Settings:
922.Bl -tag -compact
923.It 0
924Disable window scaling and timestamp option.
925.It 1
926Enable window scaling and timestamp option.
927.It 2
928Enable only window scaling.
929.It 3
930Enable only timestamp option.
931.El
932.It Va rfc3042
933Enable the Limited Transmit algorithm as described in RFC 3042.
934It helps avoid timeouts on lossy links and also when the congestion window
935is small, as happens on short transfers.
936.It Va rfc3390
937Enable support for RFC 3390, which allows for a variable-sized
938starting congestion window on new connections, depending on the
939maximum segment size.
940This helps throughput in general, but
941particularly affects short transfers and high-bandwidth large
942propagation-delay connections.
943.It Va rfc6675_pipe
944Deprecated and superseded by
945.Va sack.revised
946.It Va sack.enable
947Enable support for RFC 2018, TCP Selective Acknowledgment option,
948which allows the receiver to inform the sender about all successfully
949arrived segments, allowing the sender to retransmit the missing segments
950only.
951.It Va sack.globalholes
952Global number of TCP SACK holes currently allocated.
953.It Va sack.globalmaxholes
954Maximum number of SACK holes per system, across all connections.
955Defaults to 65536.
956.It Va sack.lrd
957Enable Lost Retransmission Detection for SACK-enabled sessions, enabled by
958default.
959Under severe congestion, a retransmission can be lost which then leads to a
960mandatory Retransmission Timeout (RTO), followed by slow-start.
961LRD will try to resend the repeatedly lost packet, preventing the time-consuming
962RTO and performance reducing slow-start or purge of the SACK scoreboard.
963.It Va sack.maxholes
964Maximum number of SACK holes per connection.
965Defaults to 128.
966.It Va sack.revised
967Enables three updated mechanisms from RFC6675 (default is true).
968Calculate the bytes in flight using the algorithm described in RFC 6675, and
969is also an improvement when Proportional Rate Reduction is enabled.
970Next, Rescue Retransmission helps timely loss recovery, when the trailing segments
971of a transmission are lost, while no additional data is ready to be sent.
972In case a partial ACK without a SACK block is received during SACK loss
973recovery, the trailing segment is immediately resent, rather than waiting
974for a Retransmission timeout.
975Finally, SACK loss recovery is also engaged, once two segments plus one byte are
976SACKed - even if no traditional duplicate ACKs were observed.
977.It Va sendbuf_auto
978Enable automatic send buffer sizing.
979.It Va sendbuf_auto_lowat
980Modify threshold for auto send buffer growth to account for
981.Dv SO_SNDLOWAT .
982.It Va sendbuf_inc
983Incrementor step size of automatic send buffer.
984.It Va sendbuf_max
985Maximum size of automatic send buffer.
986.It Va sendspace
987Initial
988.Tn TCP
989send window (buffer size).
990.It Va syncache
991Variables under the
992.Va net.inet.tcp.syncache
993node are documented in
994.Xr syncache 4 .
995.It Va syncookies
996Determines whether or not
997.Tn SYN
998cookies should be generated for outbound
999.Tn SYN-ACK
1000packets.
1001.Tn SYN
1002cookies are a great help during
1003.Tn SYN
1004flood attacks, and are enabled by default.
1005(See
1006.Xr syncookies 4 . )
1007.It Va syncookies_only
1008See
1009.Xr syncookies 4 .
1010.It Va tcbhashsize
1011Size of the
1012.Tn TCP
1013control-block hash table
1014(read-only).
1015This is tuned using the kernel option
1016.Dv TCBHASHSIZE
1017or by setting
1018.Va net.inet.tcp.tcbhashsize
1019in the
1020.Xr loader 8 .
1021.It Va tolerate_missing_ts
1022Tolerate the missing of timestamps (RFC 1323/RFC 7323) for
1023.Tn TCP
1024segments belonging to
1025.Tn TCP
1026connections for which support of
1027.Tn TCP
1028timestamps has been negotiated.
1029As of June 2021, several TCP stacks are known to violate RFC 7323, including
1030modern widely deployed ones.
1031Therefore the default is 1, i.e., the missing of timestamps is tolerated.
1032.It Va ts_offset_per_conn
1033When initializing the TCP timestamps, use a per connection offset instead of a
1034per host pair offset.
1035Default is to use per connection offsets as recommended in RFC 7323.
1036.It Va tso
1037Enable TCP Segmentation Offload.
1038.It Va udp_tunneling_overhead
1039The overhead taken into account when using UDP encapsulation.
1040Since MSS clamping by middleboxes will most likely not work, values larger than
10418 (the size of the UDP header) are also supported.
1042Supported values are between 8 and 1024.
1043The default is 8.
1044.It Va udp_tunneling_port
1045The local UDP encapsulation port.
1046A value of 0 indicates that UDP encapsulation is disabled.
1047The default is 0.
1048.It Va v6mssdflt
1049The default value used for the TCP Maximum Segment Size
1050.Pq Dq MSS
1051for IPv6 when no advice to the contrary is received from MSS negotiation.
1052.It Va v6pmtud_blackhole_mss
1053MSS to try for IPv6 if PMTU blackhole detection is turned on.
1054See
1055.Va pmtud_blackhole_detection .
1056.El
1057.Sh ERRORS
1058A socket operation may fail with one of the following errors returned:
1059.Bl -tag -width Er
1060.It Bq Er EISCONN
1061when trying to establish a connection on a socket which
1062already has one;
1063.It Bo Er ENOBUFS Bc or Bo Er ENOMEM Bc
1064when the system runs out of memory for
1065an internal data structure;
1066.It Bq Er ETIMEDOUT
1067when a connection was dropped
1068due to excessive retransmissions;
1069.It Bq Er ECONNRESET
1070when the remote peer
1071forces the connection to be closed;
1072.It Bq Er ECONNREFUSED
1073when the remote
1074peer actively refuses connection establishment (usually because
1075no process is listening to the port);
1076.It Bq Er EADDRINUSE
1077when an attempt
1078is made to create a socket with a port which has already been
1079allocated;
1080.It Bq Er EADDRNOTAVAIL
1081when an attempt is made to create a
1082socket with a network address for which no network interface
1083exists;
1084.It Bq Er EAFNOSUPPORT
1085when an attempt is made to bind or connect a socket to a multicast
1086address.
1087.It Bq Er EINVAL
1088when trying to change TCP function blocks at an invalid point in the session;
1089.It Bq Er ENOENT
1090when trying to use a TCP function block that is not available;
1091.El
1092.Sh SEE ALSO
1093.Xr getsockopt 2 ,
1094.Xr setfib 2 ,
1095.Xr socket 2 ,
1096.Xr stats 3 ,
1097.Xr sysctl 3 ,
1098.Xr blackhole 4 ,
1099.Xr inet 4 ,
1100.Xr intro 4 ,
1101.Xr ip 4 ,
1102.Xr ktls 4 ,
1103.Xr mod_cc 4 ,
1104.Xr siftr 4 ,
1105.Xr syncache 4 ,
1106.Xr tcp_bbr 4 ,
1107.Xr tcp_rack 4 ,
1108.Xr setkey 8 ,
1109.Xr sysctl 8 ,
1110.Xr tcp_functions 9
1111.Rs
1112.%A "V. Jacobson"
1113.%A "B. Braden"
1114.%A "D. Borman"
1115.%T "TCP Extensions for High Performance"
1116.%O "RFC 1323"
1117.Re
1118.Rs
1119.%A "D. Borman"
1120.%A "B. Braden"
1121.%A "V. Jacobson"
1122.%A "R. Scheffenegger"
1123.%T "TCP Extensions for High Performance"
1124.%O "RFC 7323"
1125.Re
1126.Rs
1127.%A "A. Heffernan"
1128.%T "Protection of BGP Sessions via the TCP MD5 Signature Option"
1129.%O "RFC 2385"
1130.Re
1131.Rs
1132.%A "K. Ramakrishnan"
1133.%A "S. Floyd"
1134.%A "D. Black"
1135.%T "The Addition of Explicit Congestion Notification (ECN) to IP"
1136.%O "RFC 3168"
1137.Re
1138.Rs
1139.%A "A. Ramaiah"
1140.%A "R. Stewart"
1141.%A "M. Dalal"
1142.%T "Improving TCP's Robustness to Blind In-Window Attacks"
1143.%O "RFC 5961"
1144.Re
1145.Sh HISTORY
1146The
1147.Tn TCP
1148protocol appeared in
1149.Bx 4.2 .
1150The RFC 1323 extensions for window scaling and timestamps were added
1151in
1152.Bx 4.4 .
1153The
1154.Dv TCP_INFO
1155option was introduced in
1156.Tn Linux 2.6
1157and is
1158.Em subject to change .
1159