xref: /freebsd/share/man/man4/tcp.4 (revision 357378bbdedf24ce2b90e9bd831af4a9db3ec70a)
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 July 28, 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 functions_inherit_listen_socket_stack
626Determines whether to inherit listen socket's TCP stack or use the current
627system default TCP stack, as defined by
628.Va functions_default .
629Default is true.
630.It Va hostcache
631The TCP host cache is used to cache connection details and metrics to
632improve future performance of connections between the same hosts.
633At the completion of a TCP connection, a host will cache information
634for the connection for some defined period of time.
635There are a number of
636.Va hostcache
637variables under this node.
638See
639.Va hostcache.enable .
640.It Va hostcache.bucketlimit
641The maximum number of entries for the same hash.
642Defaults to 30.
643.It Va hostcache.cachelimit
644Overall entry limit for hostcache.
645Defaults to
646.Va hashsize
647*
648.Va bucketlimit .
649.It Va hostcache.count
650The current number of entries in the host cache.
651.It Va hostcache.enable
652Enable/disable the host cache:
653.Bl -tag -compact
654.It 0
655Disable the host cache.
656.It 1
657Enable the host cache. (default)
658.El
659.It Va hostcache.expire
660Time in seconds, how long a entry should be kept in the
661host cache since last accessed.
662Defaults to 3600 (1 hour).
663.It Va hostcache.hashsize
664Size of TCP hostcache hashtable.
665This number has to be a power of two, or will be rejected.
666Defaults to 512.
667.It Va hostcache.histo
668Provide a Histogram of the hostcache hash utilization.
669.It Va hostcache.list
670Provide a complete list of all current entries in the host
671cache.
672.It Va hostcache.prune
673Time in seconds between pruning expired host cache entries.
674Defaults to 300 (5 minutes).
675.It Va hostcache.purge
676Expire all entries on next pruning of host cache entries.
677Any non-zero setting will be reset to zero, once the purge
678is running.
679.Bl -tag -compact
680.It 0
681Do not purge all entries when pruning the host cache (default).
682.It 1
683Purge all entries when doing the next pruning.
684.It 2
685Purge all entries and also reseed the hash salt.
686.El
687.It Va hostcache.purgenow
688Immediately purge all entries once set to any value.
689Setting this to 2 will also reseed the hash salt.
690.It Va icmp_may_rst
691Certain
692.Tn ICMP
693unreachable messages may abort connections in
694.Tn SYN-SENT
695state.
696.It Va initcwnd_segments
697Enable the ability to specify initial congestion window in number of segments.
698The default value is 10 as suggested by RFC 6928.
699Changing the value on the fly would not affect connections
700using congestion window from the hostcache.
701Caution:
702This regulates the burst of packets allowed to be sent in the first RTT.
703The value should be relative to the link capacity.
704Start with small values for lower-capacity links.
705Large bursts can cause buffer overruns and packet drops if routers have small
706buffers or the link is experiencing congestion.
707.It Va insecure_rst
708Use criteria defined in RFC793 instead of RFC5961 for accepting RST segments.
709Default is false.
710.It Va insecure_syn
711Use criteria defined in RFC793 instead of RFC5961 for accepting SYN segments.
712Default is false.
713.It Va insecure_ack
714Use criteria defined in RFC793 for validating SEG.ACK.
715Default is false.
716.It Va isn_reseed_interval
717The interval (in seconds) specifying how often the secret data used in
718RFC 1948 initial sequence number calculations should be reseeded.
719By default, this variable is set to zero, indicating that
720no reseeding will occur.
721Reseeding should not be necessary, and will break
722.Dv TIME_WAIT
723recycling for a few minutes.
724.It Va keepcnt
725Number of keepalive probes sent, with no response, before a connection
726is dropped.
727The default is 8 packets.
728.It Va keepidle
729Amount of time, in milliseconds, that the connection must be idle
730before sending keepalive probes (if enabled).
731The default is 7200000 msec (7.2M msec, 2 hours).
732.It Va keepinit
733Timeout, in milliseconds, for new, non-established
734.Tn TCP
735connections.
736The default is 75000 msec (75K msec, 75 sec).
737.It Va keepintvl
738The interval, in milliseconds, between keepalive probes sent to remote
739machines, when no response is received on a
740.Va keepidle
741probe.
742The default is 75000 msec (75K msec, 75 sec).
743.It Va log_in_vain
744Log any connection attempts to ports where there is no socket
745accepting connections.
746The value of 1 limits the logging to
747.Tn SYN
748(connection establishment) packets only.
749A value of 2 results in any
750.Tn TCP
751packets to closed ports being logged.
752Any value not listed above disables the logging
753(default is 0, i.e., the logging is disabled).
754.It Va minmss
755Minimum TCP Maximum Segment Size; used to prevent a denial of service attack
756from an unreasonably low MSS.
757.It Va msl
758The Maximum Segment Lifetime, in milliseconds, for a packet.
759.It Va mssdflt
760The default value used for the TCP Maximum Segment Size
761.Pq Dq MSS
762for IPv4 when no advice to the contrary is received from MSS negotiation.
763.It Va newcwd
764Enable the New Congestion Window Validation mechanism as described in RFC 7661.
765This gently reduces the congestion window during periods, where TCP is
766application limited and the network bandwidth is not utilized completely.
767That prevents self-inflicted packet losses once the application starts to
768transmit data at a higher speed.
769.It Va nolocaltimewait
770Suppress creation of TCP
771.Dv TIME_WAIT
772states for connections in
773which both endpoints are local.
774.It Va path_mtu_discovery
775Enable Path MTU Discovery.
776.It Va pcbcount
777Number of active protocol control blocks
778(read-only).
779.It Va perconn_stats_enable
780Controls the default collection of statistics for all connections using the
781.Xr stats 3
782framework.
7830 disables, 1 enables, 2 enables random sampling across log id connection
784groups with all connections in a group receiving the same setting.
785.It Va perconn_stats_sample_rates
786A CSV list of template_spec=percent key-value pairs which controls the per
787template sampling rates when
788.Xr stats 3
789sampling is enabled.
790.It Va persmax
791Maximum persistence interval, msec.
792.It Va persmin
793Minimum persistence interval, msec.
794.It Va pmtud_blackhole_detection
795Enable automatic path MTU blackhole detection.
796In case of retransmits of MSS sized segments,
797the OS will lower the MSS to check if it's an MTU problem.
798If the current MSS is greater than the configured value to try
799.Po Va net.inet.tcp.pmtud_blackhole_mss
800and
801.Va net.inet.tcp.v6pmtud_blackhole_mss
802.Pc ,
803it will be set to this value, otherwise,
804the MSS will be set to the default values
805.Po Va net.inet.tcp.mssdflt
806and
807.Va net.inet.tcp.v6mssdflt
808.Pc .
809Settings:
810.Bl -tag -compact
811.It 0
812Disable path MTU blackhole detection.
813.It 1
814Enable path MTU blackhole detection for IPv4 and IPv6.
815.It 2
816Enable path MTU blackhole detection only for IPv4.
817.It 3
818Enable path MTU blackhole detection only for IPv6.
819.El
820.It Va pmtud_blackhole_mss
821MSS to try for IPv4 if PMTU blackhole detection is turned on.
822.It Va reass.cursegments
823The current total number of segments present in all reassembly queues.
824.It Va reass.maxqueuelen
825The maximum number of segments allowed in each reassembly queue.
826By default, the system chooses a limit based on each TCP connection's
827receive buffer size and maximum segment size (MSS).
828The actual limit applied to a session's reassembly queue will be the lower of
829the system-calculated automatic limit and the user-specified
830.Va reass.maxqueuelen
831limit.
832.It Va reass.maxsegments
833The maximum limit on the total number of segments across all reassembly
834queues.
835The limit can be adjusted as a tunable.
836.It Va recvbuf_auto
837Enable automatic receive buffer sizing as a connection progresses.
838.It Va recvbuf_max
839Maximum size of automatic receive buffer.
840.It Va recvspace
841Initial
842.Tn TCP
843receive window (buffer size).
844.It Va retries
845Maximum number of consecutive timer based retransmits sent after a data
846segment is lost (default and maximum is 12).
847.It Va rexmit_drop_options
848Drop TCP options from third and later retransmitted SYN segments
849of a connection.
850.It Va rexmit_initial , rexmit_min , rexmit_slop
851Adjust the retransmit timer calculation for
852.Tn TCP .
853The slop is
854typically added to the raw calculation to take into account
855occasional variances that the
856.Tn SRTT
857(smoothed round-trip time)
858is unable to accommodate, while the minimum specifies an
859absolute minimum.
860While a number of
861.Tn TCP
862RFCs suggest a 1
863second minimum, these RFCs tend to focus on streaming behavior,
864and fail to deal with the fact that a 1 second minimum has severe
865detrimental effects over lossy interactive connections, such
866as a 802.11b wireless link, and over very fast but lossy
867connections for those cases not covered by the fast retransmit
868code.
869For this reason, we use 200ms of slop and a near-0
870minimum, which gives us an effective minimum of 200ms (similar to
871.Tn Linux ) .
872The initial value is used before an RTT measurement has been performed.
873.It Va rfc1323
874Implement the window scaling and timestamp options of RFC 1323/RFC 7323
875(default is 1).
876Settings:
877.Bl -tag -compact
878.It 0
879Disable window scaling and timestamp option.
880.It 1
881Enable window scaling and timestamp option.
882.It 2
883Enable only window scaling.
884.It 3
885Enable only timestamp option.
886.El
887.It Va rfc3042
888Enable the Limited Transmit algorithm as described in RFC 3042.
889It helps avoid timeouts on lossy links and also when the congestion window
890is small, as happens on short transfers.
891.It Va rfc3390
892Enable support for RFC 3390, which allows for a variable-sized
893starting congestion window on new connections, depending on the
894maximum segment size.
895This helps throughput in general, but
896particularly affects short transfers and high-bandwidth large
897propagation-delay connections.
898.It Va rfc6675_pipe
899Deprecated and superseded by
900.Va sack.revised
901.It Va sack.enable
902Enable support for RFC 2018, TCP Selective Acknowledgment option,
903which allows the receiver to inform the sender about all successfully
904arrived segments, allowing the sender to retransmit the missing segments
905only.
906.It Va sack.globalholes
907Global number of TCP SACK holes currently allocated.
908.It Va sack.globalmaxholes
909Maximum number of SACK holes per system, across all connections.
910Defaults to 65536.
911.It Va sack.lrd
912Enable Lost Retransmission Detection for SACK-enabled sessions, enabled by
913default.
914Under severe congestion, a retransmission can be lost which then leads to a
915mandatory Retransmission Timeout (RTO), followed by slow-start.
916LRD will try to resend the repeatedly lost packet, preventing the time-consuming
917RTO and performance reducing slow-start or purge of the SACK scoreboard.
918.It Va sack.maxholes
919Maximum number of SACK holes per connection.
920Defaults to 128.
921.It Va sack.revised
922Enables three updated mechanisms from RFC6675 (default is true).
923Calculate the bytes in flight using the algorithm described in RFC 6675, and
924is also an improvement when Proportional Rate Reduction is enabled.
925Next, Rescue Retransmission helps timely loss recovery, when the trailing segments
926of a transmission are lost, while no additional data is ready to be sent.
927In case a partial ACK without a SACK block is received during SACK loss
928recovery, the trailing segment is immediately resent, rather than waiting
929for a Retransmission timeout.
930Finally, SACK loss recovery is also engaged, once two segments plus one byte are
931SACKed - even if no traditional duplicate ACKs were observed.
932.It Va sendbuf_auto
933Enable automatic send buffer sizing.
934.It Va sendbuf_auto_lowat
935Modify threshold for auto send buffer growth to account for
936.Dv SO_SNDLOWAT .
937.It Va sendbuf_inc
938Incrementor step size of automatic send buffer.
939.It Va sendbuf_max
940Maximum size of automatic send buffer.
941.It Va sendspace
942Initial
943.Tn TCP
944send window (buffer size).
945.It Va syncache
946Variables under the
947.Va net.inet.tcp.syncache
948node are documented in
949.Xr syncache 4 .
950.It Va syncookies
951Determines whether or not
952.Tn SYN
953cookies should be generated for outbound
954.Tn SYN-ACK
955packets.
956.Tn SYN
957cookies are a great help during
958.Tn SYN
959flood attacks, and are enabled by default.
960(See
961.Xr syncookies 4 . )
962.It Va syncookies_only
963See
964.Xr syncookies 4 .
965.It Va tcbhashsize
966Size of the
967.Tn TCP
968control-block hash table
969(read-only).
970This is tuned using the kernel option
971.Dv TCBHASHSIZE
972or by setting
973.Va net.inet.tcp.tcbhashsize
974in the
975.Xr loader 8 .
976.It Va tolerate_missing_ts
977Tolerate the missing of timestamps (RFC 1323/RFC 7323) for
978.Tn TCP
979segments belonging to
980.Tn TCP
981connections for which support of
982.Tn TCP
983timestamps has been negotiated.
984As of June 2021, several TCP stacks are known to violate RFC 7323, including
985modern widely deployed ones.
986Therefore the default is 1, i.e., the missing of timestamps is tolerated.
987.It Va ts_offset_per_conn
988When initializing the TCP timestamps, use a per connection offset instead of a
989per host pair offset.
990Default is to use per connection offsets as recommended in RFC 7323.
991.It Va tso
992Enable TCP Segmentation Offload.
993.It Va udp_tunneling_overhead
994The overhead taken into account when using UDP encapsulation.
995Since MSS clamping by middleboxes will most likely not work, values larger than
9968 (the size of the UDP header) are also supported.
997Supported values are between 8 and 1024.
998The default is 8.
999.It Va udp_tunneling_port
1000The local UDP encapsulation port.
1001A value of 0 indicates that UDP encapsulation is disabled.
1002The default is 0.
1003.It Va v6mssdflt
1004The default value used for the TCP Maximum Segment Size
1005.Pq Dq MSS
1006for IPv6 when no advice to the contrary is received from MSS negotiation.
1007.It Va v6pmtud_blackhole_mss
1008MSS to try for IPv6 if PMTU blackhole detection is turned on.
1009See
1010.Va pmtud_blackhole_detection .
1011.El
1012.Sh ERRORS
1013A socket operation may fail with one of the following errors returned:
1014.Bl -tag -width Er
1015.It Bq Er EISCONN
1016when trying to establish a connection on a socket which
1017already has one;
1018.It Bo Er ENOBUFS Bc or Bo Er ENOMEM Bc
1019when the system runs out of memory for
1020an internal data structure;
1021.It Bq Er ETIMEDOUT
1022when a connection was dropped
1023due to excessive retransmissions;
1024.It Bq Er ECONNRESET
1025when the remote peer
1026forces the connection to be closed;
1027.It Bq Er ECONNREFUSED
1028when the remote
1029peer actively refuses connection establishment (usually because
1030no process is listening to the port);
1031.It Bq Er EADDRINUSE
1032when an attempt
1033is made to create a socket with a port which has already been
1034allocated;
1035.It Bq Er EADDRNOTAVAIL
1036when an attempt is made to create a
1037socket with a network address for which no network interface
1038exists;
1039.It Bq Er EAFNOSUPPORT
1040when an attempt is made to bind or connect a socket to a multicast
1041address.
1042.It Bq Er EINVAL
1043when trying to change TCP function blocks at an invalid point in the session;
1044.It Bq Er ENOENT
1045when trying to use a TCP function block that is not available;
1046.El
1047.Sh SEE ALSO
1048.Xr getsockopt 2 ,
1049.Xr socket 2 ,
1050.Xr stats 3 ,
1051.Xr sysctl 3 ,
1052.Xr blackhole 4 ,
1053.Xr inet 4 ,
1054.Xr intro 4 ,
1055.Xr ip 4 ,
1056.Xr ktls 4 ,
1057.Xr mod_cc 4 ,
1058.Xr siftr 4 ,
1059.Xr syncache 4 ,
1060.Xr tcp_bbr 4 ,
1061.Xr tcp_rack 4 ,
1062.Xr setkey 8 ,
1063.Xr sysctl 8 ,
1064.Xr tcp_functions 9
1065.Rs
1066.%A "V. Jacobson"
1067.%A "B. Braden"
1068.%A "D. Borman"
1069.%T "TCP Extensions for High Performance"
1070.%O "RFC 1323"
1071.Re
1072.Rs
1073.%A "D. Borman"
1074.%A "B. Braden"
1075.%A "V. Jacobson"
1076.%A "R. Scheffenegger"
1077.%T "TCP Extensions for High Performance"
1078.%O "RFC 7323"
1079.Re
1080.Rs
1081.%A "A. Heffernan"
1082.%T "Protection of BGP Sessions via the TCP MD5 Signature Option"
1083.%O "RFC 2385"
1084.Re
1085.Rs
1086.%A "K. Ramakrishnan"
1087.%A "S. Floyd"
1088.%A "D. Black"
1089.%T "The Addition of Explicit Congestion Notification (ECN) to IP"
1090.%O "RFC 3168"
1091.Re
1092.Rs
1093.%A "A. Ramaiah"
1094.%A "R. Stewart"
1095.%A "M. Dalal"
1096.%T "Improving TCP's Robustness to Blind In-Window Attacks"
1097.%O "RFC 5961"
1098.Re
1099.Sh HISTORY
1100The
1101.Tn TCP
1102protocol appeared in
1103.Bx 4.2 .
1104The RFC 1323 extensions for window scaling and timestamps were added
1105in
1106.Bx 4.4 .
1107The
1108.Dv TCP_INFO
1109option was introduced in
1110.Tn Linux 2.6
1111and is
1112.Em subject to change .
1113