100 Commits
Author SHA1 Message Date
Michael Tuexen ff066579fd TCP RACK: fix RSM computation for TCP fast open
When spitting an RSM containing the SYN and data, honor the
sequence number used by the SYN flag when computing the offset
in the socket buffer.

PR:			297006
Reviewed by:		rrs, Peter Lei
MFC after:		3 days
MFC to:			stable/15
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D61149
2026-11-07 14:33:45 +01:00
Michael Tuexen 9a406a9ec3 tcp/rack: Fix a potential overflow in rack_update_pcm_ack()
The RACK stack's path capacity measurement module maintains an array of
samples, updated when the stack receives an ACK.  The array grows as
needed, but code which handles the expansion is susceptible to remotely
triggerable overflow.  This could lead to underallocation and a ~512KB
out-of-bounds write.

Fix this by bounding the sample array size.

Approved by:	so
Security:	FreeBSD-SA-26:70.tcp
Security:	CVE-2026-101307
Reviewed by:	glebius, markj
Reported by:	Nozomi Networks Security Research
2026-10-14 16:00:47 +00:00
Michael Tuexen d39b12e903 sysctl: don't loop when EAGAIN is returned
When userland_sysctl() experiences EAGAIN, don't loop internally but
leave retrying to the caller.
Looping was a problem in case of using tcpsso(8) to switch a TCP stack
where the acceptance check of the new TCP stack results in EAGAIN.

Reviewed by:		kib, glebius
MFC after:		1 week
MFC to:			stable/15
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D60444
2026-10-08 15:05:11 +02:00
Michael Tuexen e2279d5ba9 tcpdrop: improve handling of -C and -S
Handle empty strings for -Cand -S correctly.

Reported by:		maxim
Reviewed by:		maxim
MFC after:		1 week
MFC to:			stable/14
MFC to:			stable/15
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D60210
2026-10-01 21:14:11 +02:00
Michael Tuexen 6d3e3afbf9 tcp: remove redundant assignments
Since the struct inpcb in embedded in the struct tcpcb, the
relationship can't change. So there is no need to reassign the tp
anymore.
No functional change intended.

Reported by:		Hannes Elfert
Reviewed by:		glebius
MFC after:		1 week
MFC to:			stable/15
Differential Revision:	https://reviews.freebsd.org/D59384
2026-09-06 16:05:40 +02:00
Michael Tuexen 74d330943b tcp md5: improve consistency
All other usages of SCF_SIGNATURE are protected by IPSEC_SUPPORT
or TCP_SIGNATURE.
No functional change intended.

Reported by:	Hannes Elfert
MFC after:	1 week
MFC to:		stable/14
MFC to:		stable/15
2026-09-04 09:37:45 +02:00
Michael Tuexen 2fb53436cd tcp md5: fix accounting of ACK with bad signatures
When processing the ACK of the initial TCP handshake using the
SYN cookie, don't increment the counter for unexpected
signatures (tcps_sig_err_sigopt). The correct
counter (tcps_sig_rcvbadsig) for bad signatures is already
incremented in TCPMD5_INPUT().

Reported by:		Hannes Elfert
Reviewed by:		rscheff
MFC after:		1 week
MFC to:			stable/14
MFC to:			stable/15
Differential Revision:	https://reviews.freebsd.org/D59302
2026-09-04 09:28:35 +02:00
Michael Tuexen 5d3e31df7c tcp md5: fix accounting for SYN segments with unexpected signature
When receiving a SYN segment with an MD5 option on a listening socket,
which has not enabled TCP MD5 support, increment the counter for
unexpected signatures (tcps_sig_err_sigopt).

Reviewed by:		rscheff
MFC after:		1 week
MFC to:			stable/14
MFC to:			stable/15
Differential Revision:	https://reviews.freebsd.org/D59303
2026-09-04 09:18:10 +02:00
Michael Tuexen c6ae11c1b0 tcp md5: improve handling of tcps_sig_err_sigopt counter
For non listening TCP endpoints, increment the tcps_sig_err_sigopt
counter when TCP MD5 is not enabled in the TCP connection, but a
segment containing a TCP MD5 option is received.
Also increment the counter when using the RACK or BBR stack.

Reported by:		Hannes Elfert
Reviewed by:		rrs
MFC after:		1 week
MFC to:			stable/14
MFC to:			stable/15
Differential Revision:	https://reviews.freebsd.org/D59249
2026-08-31 15:12:54 +02:00
Michael Tuexen 209668726c sockstat: provide more BBLog information
When using -b, provide in addition to the BBLog state also the number
of entries stored at the endpoint, the corresponding upper limit and
the next sequence number to be assigned.

Reviewed by:		rrs
MFC after:		1 week
MFC to:			stable/15
MFC to:			stable/14
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D59131
2026-08-26 20:36:26 +02:00
Michael Tuexen 191dad334c tcp: minor cleanup
Several cleanups in tcp_input_with_port():
* Don't assign m twice.
* Don't reassign pointers without having done pullup().
* While there, change the type of isipv6 to bool, since it is used
  that way.
No functional change intended.

Reported by:		Hannes Elfert
Reviewed by:		pouria, Timo Völker, Nick Banks
MFC after:		1 week
MFC to:			stable/15
Differential Revision:	https://reviews.freebsd.org/D59142
2026-08-24 21:05:56 +02:00
Michael Tuexen 74019bc3ea tcp: cleanup whitespaces
Use tabs consistently in #defines
No functional change intended.

Reported by:	Hannes Elfert
MFC after:	1 week
MFC to:		stable/15
2026-08-24 09:50:23 +02:00
Michael Tuexen 732c8d2a1a sockstat: improve consistency
Include the entries of the BBLOG STATE column in the computation
of the column width as done also for other columns.
Also set first to falso only when needed.

MFC after:	3 days
MFC to:		stable/15
MFC to:		stable/14
Sponsored by:	Netflix, Inc.
2026-08-23 22:11:24 +02:00
Michael Tuexen 8bea280f43 Revert "vtnet: move offload functions to virtio_net.h to share them"
This reverts commit 44cddaa99d.
It breaks the LINT-NOIP config.
2026-08-21 22:16:05 +02:00
Michael Tuexen 0053a4b9cc tcp: fix TF_BITS
Add missing TF_DISCONNECTED bit.

Reported by:	Hannes Elfert
Fixes:		40dbb06fa7 ("inpcb: retire INP_DROPPED and in_pcbdrop()")
2026-08-10 21:16:37 +02:00
Michael Tuexen c9df1a6cf9 tcp: improve SEG.SEQ validation for RST segments
A RST segment can be sent in response to
(a) received segment or
(b) by the upper layer protocol.

The SEG.SEQ validation consists of two checks:
(1) the in-window check of SEG.SEQ and
(2) the exact match check of SEG.SEQ.

For the in-window check (1), the left edge of the window needs to be
based on tp->last_ack_sent to cover the delayed ACK case, whereas the
right edge needs to be based on tp->rcv_nxt + tp->rcv_wnd. This both
assumes that tp->rcv_wnd is not zero. For the special case of
tp->rcv_wnd being zero, add checks against tp->last_ack_sent for (a)
and on tp->rcv_nxt for (b). This applies to all TCP stacks.

When the exact match (2) of SEG.SEQ is performed, it should be based
on tp->last_ack_sent for (a) and on tp->rcv_nxt for (b). To cover both,
check for both. Add this only to the base stack, since the RACK and
BBR stacks already do this.

PR:			296594
Reviewed by:		rscheff
MFC after:		3 days
MFC to:			stable/14
MFC to:			stable/15
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D58594
2026-08-03 13:07:32 +02:00
Michael Tuexen 52b7cbcb78 tcp: improve handling of stopped timers
When a TCP timer is stopped, t_timers[] is set to SBT_MAX. Adding the
corresponding t_precisions[], if it is not zero, would result in
overflows in tcp_timer_next(). To avoid this, skip stopped timers.

The problem was identified while debugging uperf by Lukas Book and
an initial patch was provided by him. The committed patch was
suggested by glebius.

The problem can be observed by running netstat -nxptcp and looking for
negative timer values and by observing very long running timers in
some cases.

Reported by:		Lukas Book <[email protected]>
Reviewed by:		glebius
Differential Revision:	https://reviews.freebsd.org/D58484
2026-07-28 22:15:22 +02:00
Michael Tuexen fa2ad70a45 tcp: make ghost ACK handling more conformant
The latest version of draft-ietf-tcpm-tcp-ghost-acks changed
a condition. This should make no substantial difference, but makei
it compliant to the latest version of the specification.

Reviewed by:		rscheff, Peter Lei
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D58411
2026-07-23 18:03:39 +02:00
Michael Tuexen f2f50c80ae sockstat: fix SCTP support
Provide a name for SCTP sockets.

Fixes:		8b2b62b49d ("sockstat: consolidate unix(4) protocols in the array of protocols")
2026-07-13 11:13:04 +02:00
Michael Tuexen fbc039e512 tests: fix checksum computation
This fixes an endianness bug in sys/netinet/ip_reass_test.
Just use the code from RFC 1071.

Reported by:		glebius
Reviewed by:		glebius, Timo Völker
MFC after:		1 week
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D57988
2026-07-01 18:07:04 +02:00
Michael Tuexen 1ed2bf1e00 tcp: cleanup resource handling in SYN handling
Handle cred, ipopts, and maclabel using the same pattern:
allocate at the beginning and set to NULL when the object is
transferred to a struct syncache. When exiting the function, free
these objects if not transferred or when transferred to the on-stack
struct syncache. This makes use of a new function syncache_release().

This fixes a use after free problem: ipopts should only be freed,
if the on-stack struct syncache is used and the pointer in this
structure still points to the allocated ipopts. If the ipopts
are moved from the struct syncache to the struct inpcb in
syncache_socket(), which is called by syncache_tfo_expand(),
the pointer in the struct syncache is set to NULL.

In a FreeBSD default setup this problem is mitigated by
1. TCP fast open support on the server side not being enabled
   (the sysctl-variable net.inet.tcp.fastopen.server_enable is 0).
2. Incoming IP packet with source routing options are not being
    processed by the host stack
    (the sysctl-variable net.inet.ip.accept_sourceroute is 0).

Only if these two sysctl-variables are changed, a FreeBSD system
is affected, if a server actually using TCP fast open is running.

Reported by:		Yuxiang Yang, Yizhou Zhao, Xuewei Feng, Qi Li, and Ke Xu from Tsinghua University using GLM5.1 from Z.ai
Reviewed by:		markj, rscheff
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D57374
2026-06-17 15:46:56 +02:00
Michael Tuexen cf678e30ca devfs: add bpf example
Add an example for allowing members of the network group to read from
bpf devices. In particular, this allows members of the network group
to monitor traffic without running with root privileges.

Reviewed by:		markj, glebius
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D56742
2026-04-30 22:35:07 +02:00
Michael Tuexen cca22c36c3 iflib: fix book keeping
iflib_txq_drain() returns the number of consumed entries. In the case
of TSO, a single entry can contain multiple TCP packets.

Reported by:		Ricardo Branco, David Wolfskill
Reviewed by:		gallatin
Fixes:			3fade68cfd ("iflib: accurately count bytes/segments for TSO")
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D56509
2026-04-18 21:57:40 +02:00
Michael Tuexen 3a54aa3b09 tcp: use RFC 6191 for connection recycling in TIME-WAIT
Implement the criteria specified in RFC 6191 for recycling TCP
connections in TIME-WAIT.

Reviewed by:		rscheff, Marius Halden
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D56321
2026-04-17 09:11:41 +02:00
Michael Tuexen 2d13620c6e tcp lro: fix vnet handling
Reported by:		Shawn Webb
Reviewed by:		glebius, rrs
Fixes:			f707cc00ed ("lro: move pkt rejection checks to leafs to avoid queueing")
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D56420
2026-04-15 22:31:48 +02:00
Michael Tuexen 04b994d19e bpf: fix handling the read timeout on ppc64
On platforms other than amd64, BIOCSRTIMEOUT is equal to
BIOCSRTIMEOUT32. Therefore, running the COMPAT_FREEBSD32 code
basically clears tv_usec on big endian platforms. When tcpdump is
used, the timeout requested is 100ms, which gets cleared to 0 on
ppc64 platforms. This results in tcpdump showing the packets only
when the read buffer is full.
Thanks to kib for guiding me to the correct fix.

Reported by:		ivy
Reviewed by:		adrian, kib
MFC after:		3 days
Differential Revision:	https://reviews.freebsd.org/D56399
2026-04-15 21:24:05 +02:00
Michael Tuexen 32cc4beb0a tcp: retire TF_SENTSYN
This TF_-flag is only used in the RACK stack and not really needed.
So replace it, since glebius@ needs a TF_ flag and right now all
of them are taken.
No functional change intended.

Reviewed by:		rrs, glebius, rscheff, Nick Banks
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D56025
2026-04-03 21:22:11 +02:00
Michael Tuexen 6b2d6ccad2 tcp: plug an mbuf leak
When a challenge ACK should be sent via tcp_send_challenge_ack(),
but the rate limiter suppresses the sending, free the mbuf chain.
The caller of tcp_send_challenge_ack() expects this similar to the
callers of tcp_respond().

Approved by:	so
Security:	FreeBSD-SA-26:06.tcp
Security:	CVE-2026-4247
Reviewed by:	lstewart
Tested by:	lstewart
Sponsored by:	Netflix, Inc.
2026-03-25 18:11:54 -07:00
Michael Tuexen 3d69387ece tcp: improve NOINET builds
Reported by:	bz
MFC after:	1 week
Sponsored by:	Netflix, Inc.
2026-03-04 15:18:58 +01:00
Michael Tuexen 6bd97e9e01 sctp: fix NOINET build
Reported by:		ngie
Fixes:			454212b971 ("sctp: fix so_proto when peeling off a socket")
MFC after:		3 days
2026-02-27 08:56:01 +01:00
Michael Tuexen f3364d3c8c tcp: improve handling of segments in TIME WAIT
The check for excluding duplicate ACKs needs to consider only TH_SYN
and TH_FIN. We know that TH_ACK is set and TH_RST is cleared. All
other flags, in particular TH_ECE, TH_CWR, and TH_AE needs to be
ignored for the check.

PR:			292293
Reviewed by:		rrs
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D55489
2026-02-25 14:06:15 +01:00
Michael Tuexen 8d2f910ceb tcp: BBLog incoming packets in TCPS_TIME_WAIT
PR:			292293
Reviewed by:		rrs, rscheff, pouria, Nick Banks, Peter Lei
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D5546
2026-02-25 14:04:37 +01:00
Michael Tuexen 454212b971 sctp: fix so_proto when peeling off a socket
Reported by:		glebius
Reviewed by:		rrs
Fixes:			d195b3783f ("sctp: fix socket type created by sctp_peeloff()")
Differential Revision:	https://reviews.freebsd.org/D55454
2026-02-25 13:55:54 +01:00
Michael Tuexen c984c7593e tcp: cleanup
No functional change intended.

Reviewed by:		pouria, rrs, Timo Völker
MFC after:		1 week
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D55415
2026-02-22 18:44:10 +01:00
Michael Tuexen e1886559ea tcp: improve validation of received TCP over UDP packets
Reviewed by:		glebius, pouria
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D55410
2026-02-20 22:21:37 +01:00
Michael Tuexen 378577393e ure: improve receive checksum offloading
Let the receive checksum offload for TCP/IPv6 and UDP/IPv6 be
controlled by ifconfig rxcsum6 and not by ifconfig rxcsum.
While there, make the code more compact and improve stlye.9
conformity.

Reviewed by:		Timo Völker
MFC after:		1 week
Differential Revision:	https://reviews.freebsd.org/D55188
2026-02-10 18:13:48 +01:00
Michael Tuexen 7266121ce9 ure: improve transmit checksum offloading
Apparently, the name of the variable l4off was correct. Providing the
offset to the TCP or UDP header allows the transmit checksum offload to
work for TCP/IPv4, TCP/IPv6, UDP/IPv4, and UDP/IPv6.

Reported by:		vishwin
Reviewed by:		vishwin
MFC after:		1 week
Differential Revision:	https://reviews.freebsd.org/D55187
2026-02-08 21:16:20 +01:00
Michael Tuexen d195b3783f sctp: fix socket type created by sctp_peeloff()
When calling sctp_peeloff() on a SOCK_SEQPACKET socket, the created
and returned socket has the type SOCK_STREAM.
This is specified in section 9.2 of RFC 6458.

Reported by:	Xin Long
MFC after:	3 days
2026-01-31 19:11:08 +01:00
Michael Tuexen 7b6e84c9ac ure: improve checksum offloading
This patch fixes three issues:
(1) Initially, set the hwassist flags correctly when enabling
    transmit checksum offload for TCP/IPv6 and UDP/IPv6.
(2) Keep the hwassist flags in sync with the capabilities when
    changing txcsum.
(3) Keep the hwasssit flags in sync with the capabilities when
    changing txcsum6.
Without this patch, transmit checksum offloading for TCP/IPv6 and
UDP/IPv6 is never used and transmit checksum offloading for IPv4,
TCP/IPv4 and UDP/IPv4 is always used, even if disabled via
ifconfig ue? -txcsum.

Reviewed by:		Timo Völker
MFC after:		3 days
Differential Revision:	https://reviews.freebsd.org/D54974
2026-01-31 11:42:10 +01:00
Michael Tuexen 33596d9255 dpaa2: add support for several interface counters
Add support for IFCOUNTER_IPACKETS, IFCOUNTER_OPACKETS,
IFCOUNTER_OBYTES, IFCOUNTER_OMCASTS, IFCOUNTER_OERRORS, and
IFCOUNTER_OQDROPS.
This allows tools like systat to report the incoming and outgoing
bandwidth.

Reviewed by:		dsl, Timo Völker
MFC after:		1 week
Differential Revision:	https://reviews.freebsd.org/D54893
2026-01-30 10:58:57 +01:00
Michael Tuexen f31336b3e3 dpnaa2: announce transmit checksum support
Let the network stack know that the NIC supports checksum offloading
for the IPv4 header checksum and the TCP and UDP transport checksum.
This avoids the computation in software and therefore provides the
expected performance gain.

PR:			292006
Reviewed by:		dsl, Timo Völker
MFC after:		3 days
Differential Revision:	https://reviews.freebsd.org/D54809
2026-01-23 08:59:57 +01:00
Michael Tuexen d8b8dc776b dpaa2: cleanup
No functional change intended.

Reviewed by:		bz, dsl
MFC after:		3 days
Differential Revision:	https://reviews.freebsd.org/D54805
2026-01-21 08:16:46 +01:00
Michael Tuexen 8d82dafa56 sctp: support bridge interfaces
Reported by:	Timo Völker
Tested by:	Timo Völker
MFC after:	3 days
2026-01-20 18:06:17 +01:00
Michael Tuexen 3d771e0db6 dwc: cleanup
No functional change intended.

Reviewed by:		Timo Völker
MFC after:		3 days
Differential Revision:	https://reviews.freebsd.org/D54788
2026-01-20 11:25:31 +01:00
Michael Tuexen 68a449f09e sctp: improve compilation as module
When compiling SCTP as a module, don't compile sctp_crc32.c into
the module. This avoids code and variable duplication since
sctp_crc32.c is compiled into the kernel. In particular, the variable
system_base_info is not duplicated. This fixes the handling of the
statistic counters sctps_sendhwcrc and sctps_sendswcrc when using
sctp_delayed_cksum.

MFC after:	3 days
2026-01-19 21:38:37 +01:00
Michael Tuexen 0ef8f7133d netstat: fix typo
MFC after:	3 days
2026-01-18 13:26:52 +01:00
Michael Tuexen 5d8777f3a7 dwc: add receive checksum offload for IPv6
This patch adds support for receive checksum offload for TCP/IPv6
and UDP/IPv6. Since receive checksum offload can't be configured
separately for IPv4 and IPv6, IFCAP_RXCSUM and IFCAP_RXCSUM_IPV6
can't be changed independently.

Reviewed by:		Timo Völker
MFC after:		3 days
Differential Revision:	https://reviews.freebsd.org/D54756
2026-01-17 21:06:28 +01:00
Michael Tuexen aca67c37a5 dwc: add transmit checksum offload for IPv6
This patch adds support for transmit checksum offload for TCP/IPv6
and UDP/IPv6.

Reviewed by:		Timo Völker
MFC after:		3 days
Differential Revision:	https://reviews.freebsd.org/D54754
2026-01-17 21:01:54 +01:00
Michael Tuexen 97b177f51f dwc: prepare for IPv6 transmit checksum offloading
No functional change intended.

MFC after:	3 days
2026-01-16 18:28:01 +01:00
Michael Tuexen bbd30927b1 bge: disable TXCSUM if UDP transmit checksum offloading is disabled
The bge interface is special with respect to transmit checksumi
offloading. In the default settings, an bge interface announces TXCSUM
capabilities, but only supports TCP/IPv4 and not UDP/IPv4 due to
limitations of some of the NICs. This results in problems when the bge
interface becomes a member of a bridge. Since currently only the
TXCSUM capabilities are synced when a member is added to a bridge and
not the protocol specific capabilities, this can result in a situation
where UDP packets are sent out using a bge interface without having a
correct checksum.
To mitigate this problem, initially don't announce TXCSUM capabilities,
when UDP transmit checksum is disabled. It is still possible to enable
TXCSUM capabilities via ifconfig.

PR:			291420
Reviewed by:		Timo Voelker
MFC after:		3 days
Differential Revision:	https://reviews.freebsd.org/D54486
2026-01-16 13:36:53 +01:00
Michael Tuexen 1f5b1de1fd ipv6: account for jumbo payload option
If a jumbo payload option is added, the length of the mbuf chain is
increased by 8 but the actual hop-by-hop extension header with the
jumbo playload option is only inserted in the packet if there are
other options. Therefore, adjust optlen to reflect the actual size
of IPv6 extension headers including the hop-by-hop extension header
containing the jumbo payload option.

Reported by:		[email protected]
Reviewed by:		markj, Timo Voelker
MFC after:		3 days
Differential Revision:	https://reviews.freebsd.org/D54394
2026-01-16 12:49:40 +01:00
Michael Tuexen f8ddf74175 dwc: improve IPv4 transmit checksum offloading
This patch provides two improvements for TCP/IPv4 and UDP/IPv4
transmit checksum offloading:
(1) Use *CIC_SEG instead of *CIC_FULL, since FreeBSD always provides
    a pseudo header checksum.
(2) Don't make transmit IPv4 header checksum offloading a prerequisite
    for TCP/IPv4 or UDP/IPv4 transmit checksum offloading.
This is the root cause of PR 291696, since right now the epair
interface does not support transmit IPv4 header checksum offloading,
but TCP/IPv4 and UDP/IPv4 transmit checksum offloading.

PR:			291696
Reviewed by:		Timo Voelker
Tested by:		Marek Benc
MFC after:		3 days
Differential Revision:	https://reviews.freebsd.org/D54395
2026-01-16 12:02:53 +01:00
Michael Tuexen 8da838ac31 vtnet: improve consistency
Use sbuf_new_for_sysctl() instead of sbuf_new_auto() when exposing
the flags via sysctl.

MFC after:		1 week
2025-12-19 17:44:20 +01:00
Michael Tuexen 634d9c0d11 vtnet: expose features via sysctl tree
Right now the 64-bit flags field needs to be casted to a 32-bit field,
because clang warns if more than 32-bits are used.
Once clang is fixed, this restriction will be removed and more bits
will be added.

Reviewed by:		markj, Timo Völker
MFC after:		1 week
Differential Revision:	https://reviews.freebsd.org/D54288
2025-12-19 17:38:35 +01:00
Michael Tuexen d2cb9cab84 printf.9: Support more than 32 bits in %b
This will be usable after clang has been extended to accept length
modifiers for %b when compiling kernel code.
But we need FreeBSD to support it first...

Reviewed by:		markj, Timo Völker
MFC after:		1 week
Differential Revision:	https://reviews.freebsd.org/D54286
2025-12-19 17:26:37 +01:00
Michael Tuexen 391e870931 printf.9: fix style
Follow the style described by style.9.

Reported by:	markj
MFC after:	1 week
2025-12-18 23:49:51 +01:00
Michael Tuexen f6e1833018 vtnet.4: put each sentence on its own line
Reported by:	ziaee
Fixes:		e3a0571ad7 ("vtnet: expose flags via sysctl tree")
MFC after:	1 week
2025-12-18 15:57:46 +01:00
Michael Tuexen e3a0571ad7 vtnet: expose flags via sysctl tree
Provide the flags used for a vtnet interface via the sysctl tree.
This is mostly used for debugging purposes.

Reviewed by:		Timo Völker
MFC after:		1 week
Differential Revision:	https://reviews.freebsd.org/D54283
2025-12-18 15:42:13 +01:00
Michael Tuexen e0c6c4ecfc vtnet: define flags in a consistent way
This allows adding flags in the upper 32 bits in a consistent way.
No functional change intended.

MFC after:	1 week
2025-12-18 13:41:29 +01:00
Michael Tuexen 4c50ac6816 vtnet: fix enabling/disabling tso
Transmit segment offloading depends on transmit checksum offloading.
Enforce that constraint. This also fixes a bug, since if_hwassist bits
are from the CSUM_ space, not from the IFCAP_ space.

PR:			290773
Reviewed by:		Timo Völker
Tested by:		[email protected]
MFC after:		3 days
Differential Revision:	https://reviews.freebsd.org/D53629
2025-11-10 16:34:53 +01:00
Michael Tuexen 836b3cd9d7 vtnet: don't provide VIRTIO_NET_HDR_F_DATA_VALID
According to section 5.1.6.2.1 of version 1.3 of the virtio
specification, the driver MUST NOT set VIRTIO_NET_HDR_F_DATA_VALID in
the flags. So don't do that.

Reviewed by: 		Timo Völker
MFC after:		3 days
Differential Revision:	https://reviews.freebsd.org/D53650
2025-11-10 16:28:04 +01:00
Michael Tuexen 17fb082104 tcp: improve comments in the syncache code
Add a comment explaining why syncache entries are dropped and fix a
typo in a comment.

Reviewed by:		rrs, glebius
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D53564
2025-11-07 10:27:56 -05:00
Michael Tuexen 5f43b0cb7c ddb: provide inp_flags2 when printing inpcbs
Reviewed by:		markj, Peter Lei
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D53542
2025-11-03 06:17:29 -05:00
Michael Tuexen 239464e993 tcp: drop SYN ACK segment for listening sockets
When a SYN ACK is received for a listening socket, just drop it
instead of killing the SYN-cache entry and send a RST.
This closes the possibility to kill a TCP connection during its
handling in the SYN-cache.

Reviewed by:		Nick Banks, Peter Lei
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D53540
2025-11-03 05:50:49 -05:00
Michael Tuexen 25aed6401b ddb: improve printing of inpcbs
* shuffle around the inp_label to give inp_flags more space since it
  can become long.
* fix the indentation of in6p_icmp6filt, in6p_cksum, and in6p_hops.

Reviewed by:		Peter Lei
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D53541
2025-11-02 12:21:01 -05:00
Michael Tuexen 8e8956f7f9 ddb: use %b when showing flags for a tcpcb
This is much more compact. Thanks to markj@ for suggesting the change.

Reviewed by:		markj, Peter Lei, imp, Nick Banks
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D53510
2025-11-02 11:15:47 -05:00
Michael Tuexen e8c50058e8 ddb: use %b when showing flags for an inp
This is much more compact. Thanks to markj@ for suggesting the change.

Reviewed by:		markj
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D53507
2025-11-02 11:14:57 -05:00
Michael Tuexen 259b69ad3d ddb: fix compilation
Fixes:		9aa5a79e2a ("ddb: optionally print inp when printing tcpcb")
Sponsored by:	Netflix, Inc.
2025-10-31 15:20:01 -04:00
Michael Tuexen 9aa5a79e2a ddb: optionally print inp when printing tcpcb
Add /i option to the ddb commands show tcpcb and show all tcpcbs,
which enables the printing of the t_inpcb.

Reviewed by:		markj
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D53497
2025-10-31 14:05:02 -04:00
Michael Tuexen 3adaacad11 ddb: whitespace change
No functional change intended.

MFC after:	3 days
Sponsored by:	Netflix, Inc.
2025-10-31 14:03:35 -04:00
Michael Tuexen fee2e6b9fa ddb: improve printing of inp_flags
Add four missing flags (INP_BINDANY, INP_INHASHLIST, INP_RESERVED_0,
INP_BOUNDFIB) used in inp_flags and remove one flag (INP_ORIGDSTADDR),
which is actually a flag used in inp_flags2 and not in inp_flags.

Reviewed by:		markj
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D53498
2025-10-31 13:58:46 -04:00
Michael Tuexen 44cb1e857f tcp: improve credential handling in syncache
When adding a syncache entry, take a reference count of the
credentials while the inp is still locked.
Thanks to markj@ for providing a hint regarding the root cause.

Reported by:		David Marker
Reviewed by:		glebius
Tested by:		David Marker
Fixes:			cbc9438f05 ("tcp: improve ref count handling when processing SYN")
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D53380
2025-10-27 23:28:59 +01:00
Michael Tuexen d3a3854fdc udp: honor IPV6_TCLASS cmsg for UDP/IPv4 packets
Honor the IPPROTO_IPV6-level cmsg of type IPV6_TCLASS when sending
an UDP/IPv4 packet on an AF_INET6 socket.

Reviewed by:		bz
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D53347
2025-10-26 18:58:15 +01:00
Michael Tuexen 3535546a86 udp: honor IPV6_TCLASS socket option for UDP/IPv4 packets
Honor the IPPROTO_IPV6-level socket option IPV6_TCLASS when sending
an UDP/IPv4 packet on an AF_INET6 socket.

Reviewed by:		bz, glebius
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D53346
2025-10-26 18:52:33 +01:00
Michael Tuexen bfda98a420 tcp over udp: don't copy more bytes than avaiable
When copying the data in the first mbuf to get rid of the UDP
header, use the correct length. It was copying too much (8 bytes,
the length of the UDP header).
This only applies to handling TCP over UDP packets. The support for
TCP over UDP is disabled by default.

Reported by:		jtl
Reviewed by:		Peter Lei
MFC after:		3 days
Sponsored by:		Netflix, Inc.
2025-10-23 09:24:09 +02:00
Michael Tuexen c2b08c13c2 netstat: add support for UDP-Lite endpoints
With this patch UDP-Lite endpoints are also shown per default.

Reviewed by:		Nick Banks
MFC after:		3 days
Differential Revision:	https://reviews.freebsd.org/D53252
2025-10-23 09:15:22 +02:00
Michael Tuexen f48c6390dd sockstat: add support for UDP-Lite endpoints
With this patch UDP-Lite endpoints are also show per default.

Reviewed by:		Peter Lei, Nick Banks
MFC after:		3 days
Relnotes:		yes
Differential Revision:	https://reviews.freebsd.org/D53230
2025-10-23 09:12:32 +02:00
Michael Tuexen be93b27483 UDP-Lite: export pcblist via sysctl interface
Export the list of pcbs for UDP-Lite to be consumed by sockstat and
netstat.

Reviewed by:		Peter Lei, Nick Banks
MFC after:		3 days
Differential Revision:	https://reviews.freebsd.org/D53229
2025-10-23 09:10:03 +02:00
Michael Tuexen be3c59ff50 UDP: let udp_pcblist() support UDP and UDP-Lite
Provide the IPPROTO_UDP in the arg2 parameter of udp_pcblist() and use
this to determine the inpcbinfo. This allows the same function to be
used in an upcoming commit to provide the list of pcbs for UDP-Lite
just by providing IPPROTO_UDPLITE in the arg2 parameter.

Reviewed by:		rrs
MFC after:		3 days
Differential Revision:	https://reviews.freebsd.org/D53218
2025-10-20 23:21:47 +02:00
Michael Tuexen 7294d2601f Revert "UDP: let udp_pcblist() support UDP and UDP-Lite"
This reverts commit 5f6f2c3fa2.
Missing link to review.
2025-10-20 23:19:29 +02:00
Michael Tuexen 5f6f2c3fa2 UDP: let udp_pcblist() support UDP and UDP-Lite
Provide the IPPROTO_UDP in the arg2 parameter of udp_pcblist() and use
this to determine the inpcbinfo. This allows the same function to be
used in an upcoming commit to provide the list of pcbs for UDP-Lite
just by providing IPPROTO_UDPLITE in the arg2 parameter.

Reviewed by:		rrs
MFC after:		3 days
Pull Request:		https://reviews.freebsd.org/D53218
2025-10-20 23:10:34 +02:00
Michael Tuexen 4ee0ddae1d sockstat: fix column length for PROTO
The computation of the length was not taking into account that IPv6
endpoints, which are not IPv6 only, have a suffix of 46.
For UDP and TCP this bug was not relevant, since tcp46 and udp46
has the same length as PROTO, but sctp46 is longer. Upcoming
udplite support will also be affected.

Reviewed by:		asomers
MFC after:		3 days
Differential Revision:	https://reviews.freebsd.org/D53212
2025-10-20 16:26:52 +02:00
Michael Tuexen aafdbf83b9 tcp: cleanup of syncache_expand()
* Consistently free the string after unlocking the sch, if possible.
* Remove the failure handling in case of sc != NULL, since this is
  not possible anymore.
* Remove the use of goto and instead return 0 in the three cases.
The only change in behavior is that in three out of the four cases,
where 0 is returned, *lsop is not set to NULL anymore. So the behavior
is now consistent and also documented in a comment. The current in
tree callers only look at *lsop, if and only if syncache_expand()
returns 1.

Reviewed by:		Peter Lei
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D52948
2025-10-17 07:40:02 +02:00
Michael Tuexen baeff75122 tcp: bump max rcv buffer size for autoscaling
This allows in higher throughput values with default settings.
In the review I was proposing using 16 MB, but in the transport
call today we settled on a more conservative value of 8.
Bumping it further will be done in combination with mitigations
for mbuf exhaustion attacks.

Reviewed by:		rscheff, Peter Lei, jtl, thj
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D52871
2025-10-15 22:24:51 +02:00
Michael Tuexen 9dd4742ee5 tcp: bump max snd buffer size for autoscaling
This allows in higher throughput values with default settings.
In the review I was proposing using 16 MB, but in the transport
call today we settled on a more conservative value of 8.
Bumping it further will be done in combination with mitigations
for mbuf exhaustion attacks.

Reviewed by:		rscheff, cc, glebius, Nick Banks, Peter Lei, jtl, thj, rrs
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D52872
2025-10-15 22:19:14 +02:00
Michael Tuexen 1fe6497b48 socket: bump socket buffer limit to 8MB
Bump the socket buffer limit from 2 MB to 8MB.
In particular, this allows to use larger values for TCP sockets,
which may result in higher throughput values with default settings.
In the review I was proposing using 16 MB, but in the transport
call today we settled on a more conservative value of 8.
Bumping it further will be done in combination with mitigations
for mbuf exhaustion attacks.

Reviewed by:		rscheff, Peter Lei, jtl, thj
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D52873
2025-10-15 22:14:53 +02:00
Michael Tuexen 1985940204 conf: enable TCP_HPTS_KTEST on debug builds
Enable the kernel build option TCP_HPTS_KTEST on debug builds and
disable it on non-debug builds.

PR:			290234
Reviewed by:		Nick Banks, glebius
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D53108
2025-10-15 01:36:54 +02:00
Michael Tuexen 97e858f5b3 sockstat: improve handling of path state
Only suppress the path state column when producing traditional text
output. When generating html output, always include the column.
Please note that when generating json or xml output, optional fields
like the path state are only generated if they is applicable. This
has not been changed.
The changes in this patch were suggested by asomers.

Reviewed by:		asomers
Fixes:			746eadecaa ("sockstat: show path state column only when useful")
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D53005
2025-10-14 08:48:43 +02:00
Michael Tuexen 746eadecaa sockstat: show path state column only when useful
Showing the path state column is only useful, if there is at least one
SCTP endpoint shown, which is not in the state CLOSED or LISTEN.
Don't show it when it is not useful.

Reviewed by:		rrs
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D52986
2025-10-09 21:16:38 +02:00
Michael Tuexen 98b2a2265f sockstat: improve output formatting
Fix the format when the output for a socket spans multiple lines.

Reviewed by:		rrs
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D52984
2025-10-09 21:13:56 +02:00
Michael Tuexen 73f56fa542 tcp lro: use theflowid only when it has hash properties
When a packet is provided to LRO using tcp_lro_queue_mbuf(), a
sequence number is computed based on the m_pkthdr.flowid provided
by he driver. The implicit assumption is that the m_pkthdr.flowid
has hash properties.
The recent use of tcp_lro_queue_mbuf() in iflib exposed a bug in at
least one driver (igc) , which
* reports always that is uses M_HASHTYPE_OPAQUE.
* sets in some cases m_pkthdr.flowid not consistently for packets
  belonging to the same TCP connection.
This results in severe performance problems for the base TCP stack,
since it handles the packets in the wrong sequence, although they were
received in the correct sequence.
To protect against such misbehaving drivers, just take the
m_pkthdr.flowid only into account, if it has hash properties.
The performance problems were observed by gallatin@ and analyzed
together with rrs@.

Reviewed by:		gallatin
Tested by:		gallatin
MFC after:		5 Minutes
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D52989
2025-10-09 14:37:11 +02:00
Michael Tuexen ab837a2eed sockstat: improve indentation
No functional changes intended.

MFC after:	3 days
Sponsored by:	Netflix, Inc.
2025-10-07 04:06:24 +02:00
Michael Tuexen d801cc2d85 sockstat: support reporting of BBLog state
Add a -b option to print the BBLog state for TCP sockets.

Reviewed by:		jtl, rrs
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D52944
2025-10-07 01:24:43 +02:00
Michael Tuexen 0faa9ca827 tcp: remove stray ;
MFC after:	3 days
Sponsored by:	Netflix, Inc.
2025-10-06 23:35:57 +02:00
Michael Tuexen 8af2f06a99 tcp: improve SEG.ACK validation in SYN-RECEIVED
According to the fifth step in SEGMENT ARRIVES, send a RST segment in
response to an ACK segment which fails the SEG.ACK check, but leave
the endpoint state unchanged.
FreeBSD handles this correctly when entering the SYN-RECEIVED state via
the SYN-SENT state, but not in the SYN-cache code, which handles the
SYN-RECEIVED state via the LISTEN state.

This also fixes a panic reported by Alexander Leidinger.

Reviewed by:		jtl, glebius
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D52934
2025-10-06 22:43:11 +02:00
Michael Tuexen 941b8ecdc0 tcp: remove stray ;
No functional change intended.

MFC after:		3 days
Sponsored by:		Netflix, Inc.
2025-10-06 16:32:08 +02:00
Michael Tuexen b7118461f9 tcp: improve segment validation in SYN-RECEIVED
The validation of SEG.SEQ (first step in SEGMENT ARRIVES of RFC 9293)
should be done before the validation of SEG.ACK (fifth step in
SEGMENT ARRIVES in RFC 9293).
Furthermore, when the SEG.SEQ validation fails, a challenge ACK
should be sent instead of sending a RST-segment and moving the
endpoint to CLOSED.

Reported by:		Tilnel on freebsd-net
Reviewed by:		Nick Banks
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D52849
2025-10-02 16:51:09 +02:00
Michael Tuexen 7841b44f84 tcp: keep SYN-cache entry when sending of challenge ACK fails
Don't drop a SYN-cache entry just because a challenge ACK couldn't
be sent. This might only be a temporary failure.

Reviewed by:		Nick Banks, glebius, jtl
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D52840
2025-10-02 08:57:14 +02:00
Michael Tuexen 3034fa3d43 tcp: cleanup syncache_expand()
Only validate SEG.SEQ and SEG.ACK when processing a real SYN-cache
entry. In the SYN-cookie case, these conditions are always true, since
the SYN-cache entry on the stack is constructed from the incoming
TCP segment.
While there, fix the logging messages.

Reviewed by:		Nick Banks
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D52816
2025-10-01 21:14:23 +02:00
Michael Tuexen c2900b6e82 tcp: apply rate limits to challenge ACKs
When sending challenge ACKs from the SYN-cache, apply the same rate
limiting as in other states.

Reviewed by:		cc, rrs
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D52754
2025-09-30 22:06:33 +02:00