100 Commits
Author SHA1 Message Date
Gleb Smirnoff f2d4370fbb ipfw: declare the ipfw_nat module
The module declaration is necessary for 'kldstat -m' to see it,
and the rc(8) uses that to detect presence of ipfw_nat.

NB: the module(9) KPI lacks a way to declare a module without
providing an empty handler and no SYSINITs.

Reported by:	ambrisko
Fixes:		9bcc1e97dd
2026-10-27 13:53:26 -07:00
Gleb Smirnoff 91bff7d7ed Revert "inpcb: add single peer local port caching"
This reverts commit 289082428c.

Requested by:	markj
2026-10-23 11:56:06 -07:00
Gleb Smirnoff 289082428c inpcb: add single peer local port caching
A typical caching proxy problem is port allocation to backends.  We
usually have a few of them, with thousands connections to each.  Upon
creation of a new connection we need to find a new unique local port for
the peer:port.  This is achieved by linear search in in_pcb_lport_dest().
The closer we get to the port exhaustion the more expensive this loop is.
It needs to be executed tens thousands of times to find a port or fail.

Address the problem by adding advisory negative cache that is lazily
allocated upon first conflict.  Once the cache is in action we skip trying
those ports that are already marked in the cache.  During the search we
may encounter a cache allocated by other lookup.  In this case the caches
are merged into one.  The expectation is that under a stable heavy load we
are going to stabilize at a very low number of allocated caches, ideally
one per peer:port. The cache is a bitset of IPPORT_MAX, which makes it 8k.
Unfortunately metadata pushes allocation size to 16k UMA bucket.  However,
the expectation is that we are going to have a very few allocated, thus
current decision is to not create a separate UMA zone.

Differential Revision:	https://reviews.freebsd.org/D58290
2026-10-23 10:33:04 -07:00
Gleb Smirnoff 9c67d6ed96 inpcb: inp_next() never returns a freed inpcb 2026-10-21 20:29:46 -07:00
Gleb Smirnoff 49548ea75c udp: in_pcblookup() never returns a freed inpcb 2026-10-21 20:29:41 -07:00
Gleb Smirnoff abb8b02550 icmp6: make icmp6_notify_error() more readable
Remove a level of indentation, improve line breaks, remove single use
variables.  No functional change.
2026-10-21 20:29:37 -07:00
Gleb Smirnoff 331333ba01 ipfw: hold sleepable "upper half lock" for periodic state expiry
The state expiration may lead to freeing rules, which requires this lock.
Since the lock is sleepable, move the expiry routine from callout context
to a taskqueue.  This also should have a positive effect of not running
expensive function as a callout.

Fixes:	e3caa360d5

Reviewed by:		pouria
Differential Revision:	https://reviews.freebsd.org/D60869
2026-10-21 20:28:57 -07:00
Gleb Smirnoff 7146ad04f1 tcp: refactor tcp_autosndbuf() and associated sysctls
Rename tcp_sndbuf_autoscale() to tcp_autosndbuf().  This matches
complementary tcp_autorcvbuf() that was factored out as a separate
function a few months before tcp_sndbuf_autoscale() was.  Move the large
comment to the header of the function.  Use unsigned types for all sizing
sysctls and variables and use bool for the switching sysctl.  Add a
comment above net.inet.tcp.sendbuf_auto_lowat (default to off) providing a
reference to its origins.  Add DTrace probe tcp::send-autoresize,
complementary to the existing tcp::receive-autoresize.

Rack has its own function, just enable the DTrace probe there.

Reviewed by:		tuexen
Differential Revision:	https://reviews.freebsd.org/D60732
2026-10-21 20:27:47 -07:00
Gleb Smirnoff 04cd9bca4d tcp: refactor tcp_autorcvbuf() and associated sysctls
Run the entire function under the socket buffer lock.  Make it responsible
to set the new limit or clear SB_AUTOSIZE in case of a failure.  Use
unsigned type for newsize, that matches both the sb_hiwat type and min()
argument types.  Make byte counter in the tcpcb unsigned, too.  Make the
sizing tunables unsigned, and make the switching tunable a boolean.  Don't
execute Dtrace probe in case of a failure.  Simplify the Dtrace probe to
report only relevant information, the previous probe looked more like a
leftover from a debugging session.

Reviewed by:		tuexen
Differential Revision:	https://reviews.freebsd.org/D60731
2026-10-21 20:27:36 -07:00
Gleb Smirnoff 4488a4f048 inpcb: make ipport_randomized static 2026-10-19 12:42:15 -07:00
Gleb Smirnoff f2bba01921 ipfw: keep flag(s) definition next to member that holds them 2026-10-19 10:32:21 -07:00
Gleb Smirnoff bc9e66886a ipfw: gc disabled old hashing code
This code was disabled for 8 years already.  It used to produce very
predictable hash without a salt, and that made the dynamic state engine an
easy DoS attack vector.  No chance we will ever use it again.
2026-10-19 10:32:15 -07:00
Gleb Smirnoff 41356c8017 net*: use inlined m_pullup()
Leverage the fact that m_pullup() in an inline function in mbuf.h and let
compiler to do all optimizations.

Mostly mechanical changes, but in few cases surrounding lines are brought
to style(9).  In netinet6, a few input functions changed to set the
input/output `struct mbuf **` pointer to NULL at a single place.

Reviewed by:		pouria, zlei, gallatin
Differential Revision:	https://reviews.freebsd.org/D60689
2026-10-19 10:32:00 -07:00
Gleb Smirnoff 671babc794 mbuf: make m_pullup() an inline over most expected case
Implement a most typical use of m_pullup() as an inline and leave only the
heavy part as a function.  A sweeping change to make benefit of the new
version follows.

Reviewed by:		pouria, zlei, gallatin
Differential Revision:	https://reviews.freebsd.org/D60688
2026-10-19 10:31:50 -07:00
Gleb Smirnoff 4c72b1c36d ng_pppoe: fix m_pullup() logic
The clear intent here is to do m_pullup() if we _don't_ have two bytes.
Before the fix: a) m_pullup() was always called and did nothing; b) if a
node was ever supplied with a fragmented but otherwise correct mbuf, then
it would not handle PROT_LCP as intended.

Noticed by:		zlei
Reviewed by:		zlei, eugen_grosbein.net
Differential Revision:	https://reviews.freebsd.org/D60788
Fixes:			28903f396a
2026-10-19 10:30:43 -07:00
Gleb Smirnoff d7cf2e714e net*: remove remnants of caddr_t
caddr_t is a typedef for a character pointer (char *) that originated in
Version 7 Unix, released by AT&T in 1979.  It became obsolete in 1989,
when ANSI C introduced void *.

What's left:

* ioctl(9) KPI still uses caddr_t, thus network related ioctl method
  still use it.
* if_clone KPI, to be done separately.
* bpf(4), to be done separately.
* SCTP, let maintainers decide.
* iflib(4), let maintainers decide.

Reviewed by:		zlei
Differential Revision:	https://reviews.freebsd.org/D60738
2026-10-16 14:16:59 -07:00
Gleb Smirnoff 690c3fbbe1 mbuf: remove remnants of caddr_t
caddr_t is a typedef for a character pointer (char *) that originated in
Version 7 Unix, released by AT&T in 1979.  It became obsolete in 1989,
when ANSI C introduced void *.

There is a lot of code that uses m->m_data for arithmetics, thus we can't
switch it to void * easily.  Let's at least stop proliferation of caddr_t.
We have developers that are twice younger than obsoletion of this type.

Reviewed by:		zlei, tuexen, adrian
Differential Revision:	https://reviews.freebsd.org/D60736
2026-10-16 14:09:19 -07:00
Gleb Smirnoff 9bcc1e97dd ipfw: cleanup SYSINIT(9)s
Make them all belong to SI_SUB_PROTO_FIREWALL and explicitly specify
order.  Prefer SYSINIT() over modevent, for those subsystems that don't
have dependencies.  All subsystems just depend on the main module and they
don't depend on each other, except dummynet which also has submodules.
Thus, keep DECLARE_MODULE() only for the main module and dummynet.

Differential Revision:	https://reviews.freebsd.org/D60685
2026-10-16 14:09:05 -07:00
Gleb Smirnoff a44c11974c loopback: set MTU to IF_MAXMTU
It was temporarily reduced in af78195e00 in 1994 to hide some bugs with
signed short overflow.  We believe all these bugs were sorted out by
today. :)

Note that earlier ba582a82b0 reduced the MTU be rounded to a longword
with a reference "NFS likes it to be rounded".  We have had several
refactors of the NFS code since that.

Reviewed by:		pouria, zlei, tuexen
Differential Revision:	https://reviews.freebsd.org/D59450
2026-10-16 14:08:36 -07:00
Gleb Smirnoff f84cdc2584 pfsync: use result of m_pullup() 2026-10-14 21:50:41 -07:00
Gleb Smirnoff 1da1ad38d0 tests/netpfil: reference manual pages in atf_skip statements
For those modules that don't have a manual page spell out full name of a
loadable module.
2026-10-14 12:35:07 -07:00
Gleb Smirnoff 90c8c8e451 netinet: garbage collect __IPPROTO_DIVERT 2026-10-13 12:51:53 -07:00
Gleb Smirnoff a20bbabe34 ipfw: re-arrange declarations so that they match comments
No functional change.
2026-10-13 12:51:53 -07:00
Gleb Smirnoff 6948f4d5e2 sendfile: keep the lowat hack more conservative
First, record the original lowat value and later in the wait/EAGAIN loop
look at the original value, rather than on the value that we just faked.
This eliminates some blank syscalls, where socket was reported as writable
and immediate write instantly fails.  In my testing the ratio of such
syscalls was really small, under 2%, however in a different scenario this
negative effect can be more profound.

Second, cap the lowat growth to 1/2 of original socket buffer size, rather
than to current size.  The problem was there before, but it became more
profound after 587c6c1215.

Note: we are considering to evaluate if the lowat hack is needed at all.

Reviewed by:		tuexen
Differential Revision:	https://reviews.freebsd.org/D60106
2026-10-01 19:53:40 -07:00
Gleb Smirnoff e65b7079db tcp: use SB_AUTOSIZE flag to tell if socket buffer was set
The check against V_tcp_sendspace is not a correct one, as a buffer may
grow larger than the initial value.  The conjunction was always false up
until 587c6c1215, and only after it the bug surfaced.

If we already grow our buffer past the value stored in the hostcache,
prefer our value.

Reviewed by:		tuexen
Differential Revision:	https://reviews.freebsd.org/D60105
2026-10-01 19:53:31 -07:00
Gleb Smirnoff 58031cbd54 ipfw: cleanup !FreeBSD and !_KERNEL code
These are leftovers from last import from Luigi Rizzo in 2013, that were
never compiled checked since and lots of changes have had happened since
and more changes to come.  Let's not pretend ipfw is buildable on
something else than FreeBSD nor it can be compiled for userland.

Reviewed by:		lytboris_gmail.com
Differential Revision:	https://reviews.freebsd.org/D59427
2026-09-18 15:50:23 -07:00
Gleb Smirnoff 08f0a1bdc0 ipfw: use typed pointers to access network protocols headers where possible
The 'void *ulp' is still in action, but where possible prefer a typed
pointer.  Get rid of associated pre-processor macros.

Differential Revision:	https://reviews.freebsd.org/D59435
2026-09-18 15:50:23 -07:00
Gleb Smirnoff 5f81426831 ipfw: refactor macros around m_pullup()
In the prologue, where we check if the argument is a memory or an mbuf
chain, do not set 'struct ip *ip' pointer.  However, set the 'struct
ether_header *eh' pointer there and set Etherner header length in 'ehlen'.
Side effect of this refactor is that now Layer 2 hooks may send mbufs with
ETHERTYPE_VLAN frames.  However, current network stack doesn't do that.

Write a new PULLUP() macro that would take type of the argument to
determine how much to pull.  Unlike PULLUP_TO() this macro can take typed
pointer.  This will allow to get rid of 'void *ulp' and bunch of casting
macros in the next change.  Use local bool variable to see if we need to
unlock upon jump to pullup_failed.  Embed pointer update into the branch
of the macro, where pointers indeed need an update.

Use new PULLUP() macro to pullup initial 'struct ip *ip' and 'struct
ip6_hdr *ip6'.  This removes max_protohdr sized pullup, that previously
tried to pull more than an unmapped mbuf could yield, fixing a bug covered
by the testcase sys/netpfil/ipfw/unmapped.

Reviewed by:		gallatin
Differential Revision:	https://reviews.freebsd.org/D59426
2026-09-18 15:50:23 -07:00
Gleb Smirnoff 8aab44ce3b netinet6?: move struct ip6?_moptions definition to in6?_var.h
Rest of multicast related kernel structures live in in6?_var.h and this
piece of ip6?_var.h was anyway requiring in6?_var.h to be included before.

Differential Revision:	https://reviews.freebsd.org/D55963
2026-09-18 15:42:41 -07:00
Gleb Smirnoff 597798a0e5 tcp: use sparse initializer for host cache metrics
Reviewed by:		tuexen
Differential Revision:	https://reviews.freebsd.org/D59453
2026-09-18 14:58:39 -07:00
Gleb Smirnoff 587c6c1215 tcp: turn on TCP hostcache for socket buffer sizes
The code has been there since introduction of the TCP hostcache
in 97d8d152c2 in 2003, but was turned off.

Reviewed by:		tuexen, cc
Differential Revision:	https://reviews.freebsd.org/D59452
2026-09-18 14:57:52 -07:00
Gleb Smirnoff f8f05fe48d tcp: collect and report more statistics on the TCP host cache
Reviewed by:		tuexen
Differential Revision:	https://reviews.freebsd.org/D59451
2026-09-18 14:56:54 -07:00
Gleb Smirnoff 8a37f8c325 buf_ring: use counter(9) for drops
If a buffer ring experiences drops, then system is definitely starving in
CPU resources.  Having an extra cache miss on a racy shared variable
increment doesn't help.

Reviewed by:		gallatin
Differential Revision:	https://reviews.freebsd.org/D59495
2026-09-18 14:53:39 -07:00
Gleb Smirnoff 3b498d515f buf_ring: support different lock classes
And enable locking assertions for INVARIANTS kernel.

Reviewed by:		gallatin, kib, markj
Differential Revision:	https://reviews.freebsd.org/D59457
2026-09-18 14:20:25 -07:00
Gleb Smirnoff 11d26e3c7e callout: provide callout_init_lock()
This is type agnostic locked callout initializer.  The callout_init_mtx()
and etc remain for compatibility.

Reviewed by:		kib, markj
Differential Revision:	https://reviews.freebsd.org/D59456
2026-09-18 14:17:02 -07:00
Gleb Smirnoff 0e7c7cfd11 locks: provide a macro to extract lock_object from various lock types
To be used in _Generic() KPIs that accept different lock types.

Reviewed by:		kib
Differential Revision:	https://reviews.freebsd.org/D59455
2026-09-18 14:14:28 -07:00
Gleb Smirnoff 465942e8cc raw ip: clear sin_port on bind(2)
Application may set sin_port to some value.  Although this value is not
used by SOCK_RAW, it breaks a check that the address is available.  A
perfect fix would be not use sockaddrs for ifaddrs, but that would be a
bigger change.

PR:			298366
Reviewed by:		pouria, bnovkov, adrian
Differential Revision:	https://reviews.freebsd.org/D59570
Fixes:			948ad32ae1
2026-09-12 05:12:36 -07:00
Gleb Smirnoff b712bb84a7 tcp: fix TCPS_CLOSED state underleak in syncache_socket()
The syncache entry holds one TCPS_SYN_RECEIVED count that normally is
transferred to the the newborn tp.  Upon failure syncache_socket() shall
not use TCPSTATES_INC/TCPSTATES_DEC (see 5050df3f4a why).  But when
syncache_socket() fails in_pcbconnect(), it calls tcp_discardcb() to free
resources that were just allocated by tcp_newtcpcb() and this
tcp_discardcb() would do TCPSTATES_DEC(tp->t_state).  The t_state is
TCPS_CLOSED at this point.

Make tcp_discardcb() symmetrical to tcp_newtcpcb() - not responsible for
the TCPSTATES.  Make the caller responsible for state count book keeping.

Reviewed by:		tuexen
Fixes:			3703e1a73e
Differential Revision:	https://reviews.freebsd.org/D59325
2026-09-07 12:09:40 -07:00
Gleb Smirnoff 2e16d37e27 tests/netinet: test case for a jail with 2 addresses
Check that wildcard bind(2) doesn't yet select a local address, and later
connect(2) succeeds.
2026-09-07 11:51:22 -07:00
Gleb Smirnoff 08cf9598bd inpcb: use new local address in in_pcbconnect()
when collecting necessary locks for the operation.  The IPv6 version
is already correct.

Submitted by:	Nick Price <nick spun.io>
Fixes:		1dda8ba77a
2026-09-07 11:51:22 -07:00
Gleb Smirnoff 4e45f4c767 buf_ring: tiny style(9) fixup 2026-09-07 09:59:05 -07:00
Gleb Smirnoff e5bcf98839 recv(2): update description of MSG_WAITALL
Remove a note about "data of a different type".  This was a bug that was
fixed in FreeBSD 15.  Instead put an exact quote from SUS that lists
allowed cases of a short read with MSG_WAITALL.  See discussion in D57511.
2026-09-06 09:03:45 -07:00
Gleb Smirnoff f1fa2f7db1 amd64: initialize IPI scoreboard earlier
The initializer just needs working malloc(9) and two constants that
are set at hammer_time().

Fixes:	648fa3558c

Reviewed by:		avg, markj
Differential Revision:	https://reviews.freebsd.org/D58714
2026-09-05 11:11:00 -07:00
Gleb Smirnoff d13ee10b77 random: don't collect entropy when scheduling software interrupt handlers
The entropy will be collected in intr_event_schedule_thread() for event
handlers that are marked as entropy sources.  The quality of entropy
provided by SWI wasn't great anyway.

Reviewed by:		cem, ngie
Differential Revision:	https://reviews.freebsd.org/D58829
2026-09-05 11:03:40 -07:00
Gleb Smirnoff 241df6af17 unix: fix comment
Noticed by:	mckusick
Fixes:		6563dcb6b1
2026-08-19 15:53:53 -07:00
Gleb Smirnoff 5e0e6a9e2f unix: wrap comments to fit in 80 char line
Fixes:	6563dcb6b1
2026-08-18 10:44:33 -07:00
Gleb Smirnoff a77edeb0e5 SYSINIT: add SI_SUB_KENV
Since the kernel environment has its own dependencies, lurking at the end
of the SI_SUB_KMEM sequence appeared to be fragile.  Provide own subsystem
for it.  The init_dynamic_kenv() goes SI_ORDER_FIRST, and two modules that
depend on it go SI_ORDER_ANY.

PR:			297492
Reviewed by:		imp, markj, emaste
Differential Revision:	https://reviews.freebsd.org/D58836
2026-08-17 12:40:49 -07:00
Gleb Smirnoff 87b21f30d3 SYSINIT: add SI_SUB_NUMA
This allows to parse ACPI tables and initialize VM domains before
SI_SUB_VM w/o a hack.

Reviewed by:		markj
Differential Revision:	https://reviews.freebsd.org/D58713
2026-08-11 07:40:46 -07:00
Gleb Smirnoff 4f2465260f SYSINIT: add SI_SUB_FIRST
This allows to initialize mp_maxid, mp_ncpus and register APICs at the
most early stage, guaranteeing that those values will already be available
at SI_SUB_TUNABLES.

Reviewed by:		markj
Differential Revision:	https://reviews.freebsd.org/D58712
2026-08-11 07:40:06 -07:00
Gleb Smirnoff 662497d5a7 SYSINIT: add explicit SI_ORDER_LAST
Working on cleansing use of (SI_SUB_FOO + 1) construct through the kernel
I found a repeating pattern.  Often a developer adds a module that depends
on certain subsystem to be fully instantiated and they want to put their
module SYSINIT right at the end of the SI_SUB_FOO.  Such module usually
expects that nothing else within this subsystem shall depend on the
module.

The problem with SI_ORDER_ANY which practically was "the last" until this
change is that it is used very widely and people treat it literally as
"any", well, because this is what the name says.  This lead to many parts
that could have dependencies later to be added as SI_ORDER_ANY.

So, our developer with the new subsystem that depends on SI_SUB_FOO has
three options:

1) Use SI_ORDER_ANY, but grep around ther kernel for other SI_SUB_FOO
entries to make sure that no dependencies are set to SI_ORDER_ANY.  And in
case they are, shift them up and recheck if dependencies of those
dependencies are met.

2) Take next subsystem in sysinit list.  However, the next one can be
SI_SUB_BAR, that is completely irrelevant from SI_SUB_FOO, and our
developer doesn't want to put his module's SYSINIT into SI_SUB_BAR, cause
it is ugly.

3) Use the (SI_SUB_FOO + 1) construct that violates -Werror=assign-enum.

The SI_ORDER_LAST solves this hard choice.  If you know that nothing is
going to depend on your module within SI_SUB_FOO, but you depend on
SI_SUB_FOO, just use SI_ORDER_LAST.

Reviewed by:		markj, emaste
Differential Revision:	https://reviews.freebsd.org/D58709
2026-08-11 07:39:30 -07:00
Gleb Smirnoff d1eeae7506 linker: rely on kick_init running at SI_ORDER_MIDDLE
Reviewed by:		markj
Differential Revision:	https://reviews.freebsd.org/D58711
2026-08-10 13:52:56 -07:00
Gleb Smirnoff 413346fddb usb: use SYSINIT(9) order instead of using non-existing subsystem
Found with:		clang -Werror=assign-enum
Reviewed by:		markj
Differential Revision:	https://reviews.freebsd.org/D58710
2026-08-10 13:52:25 -07:00
Gleb Smirnoff 1dda8ba77a inpcb: take a pcbinfo database out from single lock
Initialize all three hashes (exact, wild, load balance group) with a per-
bucket lock.  Nothing changes for the packet lookup KPI - it still uses
SMR section for thread safety.  But connect(2) and bind(2) operations gain
parallelism now.

The main concept is that as we lookup inpcb database for editing, we are
accumulating bucket locks necessary to accomplish the operation.  Once all
lookups are complete and we are good to go, the inpcb is inserted (or
moved) and accumulated lock context is released.

Reviewed by:		markj
Differential Revision:	https://reviews.freebsd.org/D58131
2026-08-10 13:50:22 -07:00
Gleb Smirnoff 618dc484b5 tests/netinet/socket_afinet: add more tests to multibind
Add tests where first socket and second socket are bound to different
addresses, e.g. first specific and second wildcard and vice versa.

Mark success with SO_REUSEPORT on the second socket as a bug suspect.

Mark failure to bind to INADDR_ANY in presence of other UID's specific
bound socket to the same port as probably too strict.

Differential Revision:	https://reviews.freebsd.org/D58088
2026-08-10 13:50:22 -07:00
Gleb Smirnoff e70e25761f tests/netinet/socket_afinet: multibind second socket can be different
Allows to add tests to the table where the second socket doesn't take
address from the first.  No functional change yet, all tests test the same
conditions.

Differential Revision:	https://reviews.freebsd.org/D58087
2026-08-10 13:50:22 -07:00
Gleb Smirnoff 8f6d8a9016 tests/netinet/socket_afinet: unroll multibind test into a table
The test has 6 dimensions: address family, socket type, socket option on
the first socket, socket option on the second socket, is first socket
bound to specific address or wildcard and is the second socket priveleged
or not.  Before the change 3 dimensions are implemented as 3 nested for()
loops, 2 dimensions are implemented as repetitions in the test body and
one dimension as two actions in the innermost loop.

I'm about to add one more dimension: whether the second socket is bound to
a specific address or wildcard instead of using first socket's
getsockopt(2) result.  Also, there is a change under discussion that would
make SOCK_STREAM sockets behave different to SOCK_DGRAM.  That would break
result consistency in the dimensions of socket type.

We expect that consistency in the dimension of address families shall
never break, thus this one remains a for() loop.  The priveleged & non-
privileged bind(2) attempts also remain as two actions, but expected
results are in the table.  The rest of dimensions are unrolled into a
table, which at the moment has quite a lot of lines with identical
results. However, as more tests are added and SOCK_STREAM behavior
changes, the table will get more mixed results.  Also, reading a test that
is written in a declarative manner a table is much easier and modifying it
is more resistent to accidential breakage.

Differential Revision:	https://reviews.freebsd.org/D58085
2026-08-10 13:50:22 -07:00
Gleb Smirnoff c8f38634ed tests/netinet6: remove test that uses Jumbo Payload Option
This test was already marked as always skipped.

Fixes:	069a67374e
Reviewed by:		pouria
Differential Revision:	https://reviews.freebsd.org/D58114
2026-08-10 13:41:37 -07:00
Gleb Smirnoff e79f6aa3e5 ath: return error code of HAL_STATUS type
Found with:	clang -Werror=assign-enum
2026-08-07 15:16:04 -07:00
Gleb Smirnoff 2ae8976a3f ocs_fc: return correct error code from ocs_hw_set_persistent_topology()
No functional change, as current callers either don't check the return
value or check it against OCS_HW_RTN_SUCCESS only.

Found with:	clang -Werror=assign-enum
2026-08-07 15:14:53 -07:00
Gleb Smirnoff 9d765453b0 urtw: return error of usb_error_t
Found with:	clang -Werror=assign-enum
2026-08-07 14:13:26 -07:00
Gleb Smirnoff 6a15fd9239 linuxkpi: add WLAN_EID_HT_OPERATION to ieee80211_eid
It matches our IEEE80211_ELEMID_HTINFO, that is already in use.

Found with:	clang -Werror=assign-enum
2026-08-07 14:12:57 -07:00
Gleb Smirnoff d2a9eef321 mpt: mpt_map_physdisk() is internal and shall not return cam_status
Found with:	clang -Werror=assign-enum
2026-08-07 14:12:17 -07:00
Gleb Smirnoff d3a0bf0a79 ng_ipfw: provide a tree for faster hook lookup
This should assist setups that connect a lot of nodes to ipfw: and then
distribute traffic with ipfw(4) tablearg feature.

Reviewed by:		pouria
Differential Revision:	https://reviews.freebsd.org/D58547
2026-08-03 14:55:14 -07:00
Gleb Smirnoff 76363a7970 Revert "tests/ktls: merge two sysctl checking helpers into one"
With certain sysctl configuration the test will fail.

This reverts commit 801c0f383c.
2026-07-27 19:16:39 -07:00
Gleb Smirnoff 698402f4f9 inpcb: declare struct in_conninfo as a single declaration
This removes just one level of #define mess that is needed to reach into
an inpcbs IPv4 address.  And makes the declaration easier to read.  No
functional change.

Reviewed by:		markj
Differential Revision:	https://reviews.freebsd.org/D58273
2026-07-27 12:28:08 -07:00
Gleb Smirnoff 801c0f383c tests/ktls: merge two sysctl checking helpers into one
No functional change.
2026-07-27 10:31:24 -07:00
Gleb Smirnoff aa588213d8 ministat: revert "parse comma used as decimal delimiter"
This partially reverts commit 77a201b170.

Requested by:	des, fuz
2026-07-20 11:40:28 -07:00
Gleb Smirnoff 77a201b170 ministat: parse comma used as decimal delimiter
This allows to use output of '/usr/bin/time -ao foo' as direct input to
ministat(1).

While here make diagnostic message more verbose.
2026-07-16 18:40:03 -07:00
Gleb Smirnoff 56ac3351c6 witness: fix operation without WITNESS_SKIPSPIN
Since malloc(9) even with M_NOWAIT is forbidden when we hold a spinlock,
we can't print detailed lock tree as the operation tries to allocate
memory.

Fixes:	fb4b0c9119
2026-07-16 18:37:03 -07:00
Gleb Smirnoff 3abd3d3cf3 inpcb: return ENOMEM if bind(2) fails to allocate lbgroup
This is exactly the same as the second part of IPv4's change
136c5e17b61a1/D49153.
2026-07-15 12:07:53 -07:00
Gleb Smirnoff ca4eb3f398 inpcb: do not set INP_ANONPORT until successful operation 2026-07-15 12:07:48 -07:00
Gleb Smirnoff 3ff24c76c1 inpcb: remove unneeded #ifdef INET || INET6
Per sys/conf/files this unit is not compiled for a NOIP kernel.
2026-07-14 19:13:25 -07:00
Gleb Smirnoff 11bd6ade5d linux: switch off interface name translation and schedule its removal
Modern Linuxes don't use ethX for almost 15 years already, see [1] and
[2].  The translation logic has always been a source of bugs and PITA.
Switch default to not translate (long due!) and schedule removal of the
code for FreeBSD 17.

[1] https://systemd.io/PREDICTABLE_INTERFACE_NAMES/
[2] https://www.freedesktop.org/software/systemd/man/latest/systemd.net-naming-scheme.html

Reviewed by:		iwtcex_gmail.com, vvd, melifaro, dchagin
Differential Revision:	https://reviews.freebsd.org/D57852
2026-07-07 14:19:17 -07:00
Gleb Smirnoff 6cfc526e7f acpi: fix instant panic in hest_attach()
Since now there is a pseudo-bus between our device and acpi0, we need to
go deeper.

Fixes:	9313f6b014
2026-07-07 14:14:43 -07:00
Gleb Smirnoff 1ea204b919 inpcb: make net.inet.ip.portrange port number limiting sysctls unsigned
And make net.inet.ip.portrange.randomized boolean.

Reviewed by:		pouria, tuexen, markj
Differential Revision:	https://reviews.freebsd.org/D57291
2026-07-07 09:28:48 -07:00
Gleb Smirnoff 3fdb1b6f10 netinet6: further refactor in6_pcbconnect()
A mistake from 90ea8e89d9 is that in6_pcblookup_internal() was skipped
for an inpcb that had unspecified local address.  This is incorrect, as
such inpcb could have already have a port set, and in_pcb_lport_dest()
shall not be called on such inpcb.  That could lead to creation of an
alised connection in the database.

This makes the function almost identical to in_pcbconnect().  While here,
fix minor bug of missing INP_ANONPORT.  This flag has no use in kernel,
but affects netstat(1) output in certain mode.

Fixes:	90ea8e89d9
Reviewed by:		pouria
Differential Revision:	https://reviews.freebsd.org/D57987
2026-07-07 09:27:57 -07:00
Gleb Smirnoff ee5d87a3e2 raw ip: fix race of two connect(2)
The historical design of sockets is that on a re-connect the disconnect is
performed at the socket layer in soconnectat().  Since SMP times this is
known to be racy and the function has appopriate comment.  I missed that
in the recent change.  The pr_connect method should normally expect the
socket to be already disconnected, however should be able to handle a race
where socket is actually connected.  Convert the check that incorrectly
tried to handle normal path of re-connect into check that handles the
race.

Reported by:	markj
Fixes:	ece716c5d3
2026-07-06 14:30:41 -07:00
Gleb Smirnoff f01c509568 pf: revert netlink commands back to enum
Revert pf_nl.h part of 017690e509 and use new libsysdecode build glue
that parses enums.

Reviewed by:	kp, glebius
Differential Revision:	https://reviews.freebsd.org/D57866
2026-07-06 21:41:25 +02:00
Gleb Smirnoff 07db030937 tests/socket_afinet: make multibind test more verbose on failure 2026-06-30 22:48:23 -07:00
Gleb Smirnoff 51eb574064 tests/netinet/socket_afinet: reduce tautology in test cases names
Just avoid repeating the test program name in every test case name.
No functional change.

Reviewed by:		markj
Differential Revision:	https://reviews.freebsd.org/D56727
2026-06-30 22:48:16 -07:00
Gleb Smirnoff 0bc0b0c3f7 tests/socket_afinet: extend bind_connected_port_test to cover more cases
- Test SOCK_DGRAM (UDP) sockets.
- Test binding to 0:port and to a addr:port in presence of connected socket
  using the port.

Differential Revision:	https://reviews.freebsd.org/D56707
2026-06-30 22:48:06 -07:00
Gleb Smirnoff 57cc01057b tests/socket_afinet: make child_bind() return a full spectre of results
There is no functional change for existing tests, but allows to write a test
that would expect an immediate success of bind(2).
2026-06-30 22:47:47 -07:00
Gleb Smirnoff 6b75f8ff5e inpcb: use correct mask in in6_pcblookup_lbgroup()
There is no visible bug fixed as in current tree masks are the same.

Fixes:	6883b120c5
2026-06-30 22:46:30 -07:00
Gleb Smirnoff bdd0c4d0a7 netinet6: cleanse safeguards against IFT_PFLOG
This "interface" type is no more.  Leave the constant in if_types.h, we
probably need an exp-run before removing it.
2026-06-29 13:20:02 -07:00
Gleb Smirnoff f9a0147ee5 protocols: remove IPPROTO_DIVERT 2026-06-29 13:20:02 -07:00
Gleb Smirnoff 4d3cbeb7b4 ng_socket: plug node reference leak
There is no need to reference node in its constructor, the framework
already granted us a reference.  This extraneous reference was later given
back on socket detach.  However, if node is destroyed before the socket,
the node was leaked.  This leak was harmless until VIMAGE, where
vnet_netgraph_uninit() would cycle through all nodes and shut them down
expecting them to not exist after the shutdown.

Fixes: 1928437497
2026-06-26 16:35:36 -07:00
Gleb Smirnoff 41bc52c893 ng_socket: simplify protosw(9) methods
- so_pcb can't be non-NULL in pr_attach.
- so_pcb can't be NULL in all other methods.
- Short circuit data socket attach down to the common attach.
- Short circuit both detach methods down to common one.
- Inline control socket attach.
- Inline control pr_bind.
- Inline data pr_connect.
- Rely on pr_connect_notsupp() for control connect(2).
- Don't use cast on so_pcb, it is void *.

Should be no functional change.
2026-06-26 16:35:32 -07:00
Gleb Smirnoff 90ea8e89d9 netinet6: refactor in6_pcbconnect()
If the inpcb is already bound to a local address, there is no reason to
call in6_pcbladdr().  If the inpcb is already bound to a local port, there
is no reason to call in_pcb_lport_dest().  In the opposite case, if the
inpcb is not bound, and we are about to choose a non-conflicting local
addr:port, then there is no reason to call in6_pcblookup_internal().

This change makes in6_pcbconnect() to look much more alike the IPv4
in_pcbconnect().  I tracked this strange logic all the way down to initial
KAME import and failed to find any reasoning for it.

Reviewed by:		pouria
Differential Revision:	https://reviews.freebsd.org/D57534
2026-06-25 14:34:38 -07:00
Gleb Smirnoff 8b2b62b49d sockstat: consolidate unix(4) protocols in the array of protocols
This makes it possible to list unix(4) protocols in -P, which was not
possible before.  Update the manual page and provide an example.

In 'struct sock' make member proto a pointer into the protocols table
instead of a number.  This removes namespace collision that mixed
IPPROTO_TCP and etc with SOCK_STREAM and etc.  There were no known bugs
due to this collision, though.

Preserve all current UI bugs for possible combinations of protocol
selection options.  Should be no UI changes outside the improved -P.

Reviewed by:		pouria, tuexen
Differential Revision:	https://reviews.freebsd.org/D57508
2026-06-16 09:59:01 -07:00
Gleb Smirnoff 3a58a50dd4 sockstat: don't use getprotoent(3)
This removes requirement for existence of obsolete IPPROTO_DIVERT in
<netinet/in.h> and the 'divert' entry in /etc/protocols.

Also, this avoids running through the nsdispatch(3) machinery on startup,
cutting down about 20 syscalls, three of which are open(2).  The code of
sockstat(1) itself is also reduced.

The only UI change for a normal execution is that now the divert(4)
sockets are reported as "divert4" instead of "div4".  The prefix "4"
itself is also incorrect, as divert(4) is not a part of IPv4.  This will
be addressed in a separate change.

There is small UI change for incorrect runs.  Previously protocols listed
in /etc/protocols, but not supported, would err out like this:

  # sockstat -P ggp
  sockstat: protocol 3 not supported

And non-existent protocols would err out like this:

  # sockstat -P foo
  sockstat: cap_getprotobyname: No error: 0 USER COMMAND
  PID FD PROTO LOCAL ADDRESS         FOREIGN ADDRESS

Now both cases will consistently err:

  sockstat: protocol foo not supported

Reviewed by:		pouria, tuexen
Differential Revision:	https://reviews.freebsd.org/D57507
2026-06-16 09:58:13 -07:00
Gleb Smirnoff 256fa87c9f netgraph: remove remnants of IPPROTO_DIVERT
Fixes:	8624f4347e
2026-06-08 09:35:07 -07:00
Gleb Smirnoff d62e8c5c6f inpcb: update inpcb multipath routing information only on success
This is very similar to IPv4 change 24e5c2ee2a.  Don't modify inpcb
until we are sure connect(2) will be successful.

Fixes:	0c325f53f1
2026-05-27 21:46:38 -07:00
Gleb Smirnoff ca91300c07 inpcb: a pcb may travel only from the wild hash to exact, not vice versa
The only possible way to exercise in_pcbrehash() is to bind(2) and then
connect(2).  The second branch was a dead code since fdb987bebd.

Reviewed by:		markj
Differential Revision:	https://reviews.freebsd.org/D57241
2026-05-27 21:46:27 -07:00
Gleb Smirnoff 2750d95787 tcp: fix TCP_ACCOUNTING build
The uninitialized timeval was discovered by the new clang.
2026-05-26 10:23:32 -07:00
Gleb Smirnoff e924a2c80b netlink: fix unsigned overflow on a truncated message
PR:			295106
Submitted by:		Robert Morris <[email protected]>
Reviewed by:		pouria, melifaro
Differential Revision:	https://reviews.freebsd.org/D56916
2026-05-20 07:27:52 -07:00
Gleb Smirnoff e145afc9eb netlink: factor out compatibility code from inlined function
This is a refactor of 228c632ab3.  First, move compatibility one level
up, where we yet work with the full header.  Second, move this rarely
executed code outside of the inline function.  Should be no functional
change.

Reviewed by:		pouria, melifaro
Differential Revision:	https://reviews.freebsd.org/D56915
2026-05-20 07:27:39 -07:00
Gleb Smirnoff 6883b120c5 inpcb: allow to specify different sizes for port and load balance hashes
Understand zero size as instruction to not allocate the hash.  Do not
allocate both hashes for rawip(4).  There are no functional changes to TCP
or UDP.

Reviewed by:		markj
Differential Revision:	https://reviews.freebsd.org/D56705
2026-04-29 09:19:14 -07:00
Gleb Smirnoff 9b8eb70ca9 inpcb: improve some internal function names
The 'hash' subword doesn't bring any additional information.  All inpcb
lookup functions operate on hashes.

For lookup functions that work on either exact hash or wild hash just
perform s/hash_//.  Rename in_pcblookup_hash() into
in_pcblookup_with_lock(), emphasizing its difference to
in_pcblookup_smr().  Rename in_pcblookup_hash_locked() to
in_pcblookup_internal(), as it doesn't return a locked inpcb and is used
only for internal purposes.  Note that the IPv6 sibling of this function
already lives by name in6_pcblookup_internal().  Some future changes will
make such naming more justified.

No functional change.

Reviewed by:		pouria, markj
Differential Revision:	https://reviews.freebsd.org/D56482
2026-04-29 09:19:03 -07:00
Gleb Smirnoff 4602d45eb3 kgss: de-virtualize kgss_gssd_handle
The RPC client is more of a class rather than an instance.  RPCs from
different VNETs are served by the same client.  This makes the kgss layer
fully transparent to VIMAGE and not even required to be aware of it.

It is responsibility of the rpcsec_gss module to have curvnet set on the
calling thread when doing RPC calls via kgssapi.

This change should enable proper operation of an NFS server with gssd(8)
in a VIMAGE jail.

PR:			294501
Reviewed by:		rmacklem
Differential Revision:	https://reviews.freebsd.org/D56562
2026-04-24 19:55:55 -07:00
Gleb Smirnoff 2bd2f267f3 kgss: remove unnecessary CURVNET_SET() and kgss_gssd_handle checks
These RPC methods correctly acquire the kgss_gssd_handle later with call
to kgss_gssd_client().

Reviewed by:		rmacklem
Differential Revision:	https://reviews.freebsd.org/D56561
2026-04-24 19:55:50 -07:00