291170 Commits

Author SHA1 Message Date
Mark Johnston
f8f116ac6a inpcb: Add FIB-aware inpcb lookup
Allow protocol layers to look up an inpcb belonging to a particular FIB.
This is indicated by setting INPLOOKUP_FIB; if it is set, the FIB to be
used is obtained from the specificed mbuf or ifnet.

No functional change intended.

Reviewed by:	glebius, melifaro
MFC after:	2 weeks
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D48662

(cherry picked from commit da806e8db685eead02bc67888b16ebac6badb6b6)
2025-03-21 09:28:54 +01:00
Mark Johnston
b37c9c8fb1 inpcb: Add a flags parameter to in_pcbbind()
Add a flag, INPBIND_FIB, which means that the inpcb is local to its FIB
number.  When this flag is specified, duplicate bindings are permitted,
so long as each FIB contains at most one inpcb bound to the same
address/port.  If an inpcb is bound with this flag, it'll have the
INP_BOUNDFIB flag set.

No functional change intended.

Reviewed by:	glebius
MFC after:	2 weeks
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D48661

(cherry picked from commit bbd0084baf7539c7042ce94f8c6770210f83f765)
2025-03-21 09:28:39 +01:00
Mark Johnston
992d19dc2d inpcb: Imbue in(6)_pcblookup_local() with a FIB parameter
This is to enable a mode where duplicate inpcb bindings are permitted,
and we want to look up an inpcb with a particular FIB.  Thus, add a
"fib" parameter to in_pcblookup() and related functions, and plumb it
through.

A fib value of RT_ALL_FIBS indicates that the lookup should ignore FIB
numbers when searching.  Otherwise, it should refer to a valid FIB
number, and the returned inpcb should belong to the specific FIB.  For
now, just add the fib parameter where needed, as there are several
layers to plumb through.

No functional change intended.

Reviewed by:	glebius
MFC after:	2 weeks
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D48660

(cherry picked from commit 9a4131629bb3083ddc02a32950e4eb4806a07710)
2025-03-21 09:28:21 +01:00
Mark Johnston
3b1330920d inpcb: Constify address parameters to in6 pcb lookup routines
No functional change intended.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield

(cherry picked from commit 52ef944b0f6f1df8eebe1cb877c6aadb1c247da0)
2025-03-21 09:25:30 +01:00
Mark Johnston
580dfe1398 in6: Constify some sockaddr conversion functions
No functional change intended.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield

(cherry picked from commit 3bb15ffc4ab4bfcd4c1bd700a64b3b5ed95389c3)
2025-03-21 09:20:06 +01:00
Mark Johnston
a71853600c inpcb: Further restrict binding to a port owned by a different UID
See commit 4f02a7d739b3 for more background.

I cannot see a good reason to continue ignoring mismatching UIDs when
binding to INADDR_ANY.  Looking at the sdr.V2.4a7n sources (mentioned in
bugzilla PR 7713), there is a CANT_MCAST_BIND hack wherein the
application binds to INADDR_ANY instead of a multicast address, but
CANT_MCAST_BIND isn't defined for FreeBSD builds.

It seems unlikely that we still have a use-case for allowing sockets
from different UIDs to bind to the same port when binding to the
unspecified address.  And, as noted in D47832, applications like sdr
would have been broken by the inverted SO_REUSEPORT check removed in
that revision, apparently without any bug reports.  Let's break
compatibility and simply disallow this case outright.

Also, add some comments, remove a hack in a regression test which tests
this funtionality, and add a new regression test to exercise the
remaining checks that were added in commit 4658dc8325e03.

MFC after:	1 month
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D47870

(cherry picked from commit c9756953bded0d8428027fa3e812c9bdac069252)
2025-03-21 09:17:52 +01:00
Mark Johnston
707000f30f inpcb: Close some SO_REUSEPORT_LB races
For a long time, the inpcb lookup path has been lockless in the common
case: we use net_epoch to synchronize lookups.  However, the routines
which update lbgroups were not careful to synchronize with unlocked
lookups.  I believe that in the worst case this can result in spurious
connection aborts (I have a regression test case to exercise this), but
it's hard to be certain.

Modify in_pcblbgroup* routines to synchronize with unlocked lookup:
- When removing inpcbs from an lbgroup, do not shrink the array.
  The maximum number of lbgroup entries is INPCBLBGROUP_SIZMAX (256),
  and it doesn't seem worth the complexity to shrink the array when a
  socket is removed.
- When resizing an lbgroup, do not insert it into the hash table until
  it is fully initialized; otherwise lookups may observe a partially
  constructed lbgroup.
- When adding an inpcb to the group, increment the counter after adding
  the array entry, using a release store.  Otherwise it's possible for
  lookups to observe a null array slot.
- When looking up an entry, use a corresponding acquire load.

Reviewed by:	ae, glebius
MFC after:	1 month
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D48020

(cherry picked from commit a600aabe9b04f0906069a8fb1f8d696ad186080f)
2025-03-21 09:17:39 +01:00
Mark Johnston
74986b481c inpcb: Remove bogus SO_REUSEPORT(_LB) checks in in_pcbbind()
This check for SO_REUSEPORT was added way back in commit 52b65dbe85faf.
Per the commit log, this commit restricted this port-stealing check to
unicast addresses, and then only if the existing socket does not have
SO_REUSEPORT set.  In other words, if there exists a socket bound to
INADDR_ANY, and we bind a socket to INADDR_ANY with the same port, then
the two sockets need not be owned by the same user if the existing
socket has SO_REUSEPORT set.

This is a surprising semantic; bugzilla PR 7713 gives some additional
context.  That PR makes a case for the behaviour described above when
binding to a multicast address.  But, the SO_REUSEPORT check is only
applied when binding to a non-multicast address, so it doesn't really
make sense.  In the PR the committer notes that "unicast applications
don't set SO_REUSEPORT", which makes some sense, but also refers to
"multicast applications that bind to INADDR_ANY", which sounds a bit
suspicious.

OpenBSD performs the multicast check, but not the SO_REUSEPORT check.
DragonflyBSD removed the SO_REUSEPORT (and INADDR_ANY) checks back in
2014 (commit 0323d5fde12a4).  NetBSD explicitly copied our logic and
still has it.

The plot thickens: 20 years later, SO_REUSEPORT_LB was ported from
DragonflyBSD: this option provides similar semantics to SO_REUSEPORT,
but for unicast addresses it causes incoming connections/datagrams to be
distributed among all sockets in the group.  This commit (1a43cff92a20d)
inverted the check for SO_REUSEPORT while adding one for
SO_REUSEPORT_LB; this appears to have been inadvertent.  However:
- apparently no one has noticed that the semantics were changed;
- sockets belonging to different users can now be bound to the same port
  so long as they belong to a single lbgroup bound to INADDR_ANY, which
  is not correct.

Simply remove the SO_REUSEPORT(_LB) checks, as their original
justification was dubious and their current implementation is wrong; add
some tests.

Reviewed by:	glebius
MFC after:	1 month
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D47832

(cherry picked from commit 4f02a7d739b354eef38e19b25866f64842d69414)
2025-03-21 09:17:24 +01:00
Mark Johnston
619cb9c48d inpcb: Fix the GENERIC-NODEBUG build
Fixes:	01f8ce83242d ("inpcb: Factor out parts of in6_pcbbind() and in_pcbbind_setup()")
(cherry picked from commit ffb3d384fc1d550a764def2c0cd034ac3a4f0b86)
2025-03-21 09:17:10 +01:00
Mark Johnston
4388cf9814 inpcb: Factor out parts of in6_pcbbind() and in_pcbbind_setup()
A large portion of these functions just determines whether the inpcb can
bind to the address/port.  This portion has no side effects, so is a
good candidate to move into its own helper function.  This patch does
so, making the callers less complicated and reducing indentation.

While moving this code, also make some changes:
- Load socket options (SO_REUSEADDR etc.) only once.  There is nothing
  preventing another thread from toggling the socket options, so make
  this function easier to reason about by avoiding races.
- When checking whether the bind address is an interface address, make a
  separate sockaddr rather than temporarily modifying the one passed to
  in_pcbbind().

Reviewed by:	ae, glebius
MFC after:	1 month
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D47590

(cherry picked from commit 01f8ce83242d7a8e599cf6a78b6277161d79edd4)
2025-03-21 09:16:43 +01:00
Zhenlei Huang
ee086b194d inpcb: Use NULL for VNET_SYSINIT's last arg, which is a pointer type
MFC after:	3 days

(cherry picked from commit ec6e7677a0dbfbcdb4b740b28a1105256f1fc93e)
2025-03-21 09:16:34 +01:00
Mark Johnston
93844e2506 inpcb: Make some cosmetic improvements to in_pcbbind()
- Use the local var "laddr" instead of sin->sin_addr in one block.
- Use in_nullhost() instead of explicit comparisons with INADDR_ANY.
- Combine multiple socket options checks into one.
- Fix indentation.
- Remove some unhelpful comments.

This is in preparation for some simplification and bug-fixing.

No functional change intended.

Reviewed by:	glebius
MFC after:	2 weeks
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D47451

(cherry picked from commit 45a77bf23fa2f36bf2169f7ba2a33b31f4c35adb)
2025-03-21 09:16:11 +01:00
Mark Johnston
7e198d2852 inpcb: Remove some unused parameters in internal hash lookup functions
in_pcblookup_hash_wild_* looks up unconnected inpcbs, so there is no
point in passing the foreign address and port, and indeed those
parameters are not used.  So, remove them.

No functional change intended.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Differential Revision:	https://reviews.freebsd.org/D47385

(cherry picked from commit 21d7ac8c79a34cf3b7205d0c32014ee39f1f28ab)
2025-03-21 09:13:32 +01:00
Zhenlei Huang
42b36112c0 netinet: Update a comment for in_localip()
The function in_localip() was changed to return bool but the comment was
left unchanged.

Fixes:	c8ee75f2315e Use network epoch to protect local IPv4 addresses hash
MFC after:	3 days

(cherry picked from commit a5e380e51cdba64a392846a4eeda000f948f42ce)
2025-03-21 09:11:06 +01:00
Zhenlei Huang
2eeb55649e lagg: Use static initializers
MFC after:	1 week

(cherry picked from commit 36ebdd0155d07fc53375fb212d9ca80158dde350)
2025-03-21 09:08:47 +01:00
Bjoern A. Zeeb
3e10fbcb7b iwlwifi: adjust a debug comment referring to a PR
A FreeBSD specific comment asked people to report to a PR if they see
this.  By now we got enough feedback and also left this in a release.
Simply point to the PR so people can check the status but not longer
ask to submit a report to the PR.

Sponsored by:	The FreeBSD Foundation
PR:		274382

(cherry picked from commit 4a4eee553307a2e02c6ed4796d575bfce2857049)
2025-03-21 09:07:56 +01:00
Andrew Gallatin
2d3b2ee939 ifconfig: fix reporting optics on most 100g interfaces
This fixes a bug where optics on 100G and faster NICs
were not properly reported.

(cherry picked from commit 709348c21351a783ff0025519d1f7cf884771077)
2025-03-21 09:06:58 +01:00
Konstantin Belousov
8fd42f3649 ip6_cksum.c: generalize in6_cksum_partial() to allow L2 headers in passed mbuf
(cherry picked from commit fcf81de12f27d34a5c18168fd0c756c371a62076)
2025-03-21 09:06:57 +01:00
Mateusz Guzik
f13a5e03b6 inet6: add the missing lock acquire to nd6_get_llentry
Reported by:	Lexi Winter
PR:		282378
Sponsored by:	Rubicon Communications, LLC ("Netgate")

(cherry picked from commit d6138a65405f697715189363b2b18581e7abd982)
2025-03-21 09:06:22 +01:00
Zhenlei Huang
ba418a9ea6 vnet: Use static initializers
MFC after:	1 week

(cherry picked from commit 23f453ae34c29b99f892da18db44ce4292ccb7c3)
2025-03-18 11:55:11 +01:00
Zhenlei Huang
f944a04125 tcp_ratelimit: Use static initializers
MFC after:	1 week

(cherry picked from commit 09de37310313d87942fc5349914be46b9cb8c808)
2025-03-18 11:54:47 +01:00
Zhenlei Huang
90a8aa5134 if_bridge: Use static initializers
MFC after:	1 week

(cherry picked from commit 59dbc829cf077ae0b07577f374ffc536d5acbc6a)
2025-03-18 11:54:34 +01:00
Zhenlei Huang
749c0c3701 bridgestp: Use static initializers
MFC after:	1 week

(cherry picked from commit fd0020f81a60f7c4a1401de56761cbfb2d745ca7)
2025-03-18 11:54:23 +01:00
Zhenlei Huang
6a7a20684a carp: Use static initializers
MFC after:	1 week

(cherry picked from commit b7d5bda6f109e09d8999283a9b4e4a9668df9de9)
2025-03-18 11:53:48 +01:00
Andrey V. Elsukov
7ff16c1a2e routing: do not allow PINNED routes to be overriden
First configured PINNED routes should have higher priority.

Fixes:		1da4954c92ea
Differential Revision:	https://reviews.freebsd.org/D48650

(cherry picked from commit 361a8395f0b0e6f254fd138798232529679d99f6)
2025-03-18 11:51:02 +01:00
Konstantin Belousov
7116d18ec9 ip_output(): style
(cherry picked from commit 394605c057ade77775e1f9975e278dbb7693f44f)
2025-03-18 11:50:53 +01:00
Konstantin Belousov
2b4429a2b1 ip_output(): if mb_unmapped_to_ext() failed, return directly
(cherry picked from commit edc1fba05e055a1943efd969d77c0acf0fbff587)
2025-03-18 11:50:44 +01:00
Igor Ostapenko
a4b3ec1e3f kyua: Pass unprivileged user config prop to ATF using all known names
Kyua and ATF speak different naming styles. In this case, the
unprivileged user property can be named with underscore on the Kyua
side, and with a hyphen on the ATF side. Sometimes it is not obvious
which style should be used in which situation. For instance, a test case
may require this configuration property being set using require.config.
Also, a test case may want to read the property using something like
atf_tc_get_config_var(). Which names should be used in these cases?
From the perspective of the original code, it is expected to be this:
    require.config unprivileged-user
    atf_tc_get_config_var(tc, "unprivileged-user")

But, as long as Kyua is the main interface, its users expect to work
with kyua.conf(5), which says that it must be named as unprivileged_user
(with underscore). As a result, test authors tend to do this instead:
    require.config unprivileged_user
    atf_tc_get_config_var(tc, "unprivileged_user")

Kyua already has hacks to understand both unprivileged_user and
unprivileged-user coming from require.config. And this patch covers the
missing second part -- make Kyua pass both names back to ATF as two
identical configuration properties named different ways.

Reviewed by:	ngie, asomers
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D49039

(cherry picked from commit 51a8eb6410461c94c8e0f2b59e3417cfb5d7da75)
2025-03-18 11:50:33 +01:00
Kyle Evans
c78b0e3436 kern: wg: remove overly-restrictive address family check
IPv4 packets can be routed via an IPv6 nexthop, so the handling of the
parsed address family is more strict than it needs to be.  If we have a
valid header that matches a known peer, then we have no reason to
decline the packet.

Convert it to an assertion that it matches the destination as viewed by
the stack below it, instead.  `dst` may be the gateway instead of the
destination in the case of a nexthop, so the `af` assignment must be
switched to use the destination in all cases.

Add a test case that approximates a setup like in the PR and
demonstrates the issue.

PR:		284857
Reviewed by:	markj (earlier version), zlei

(cherry picked from commit 2bef0d54f74dad6962ef7d1dfa407e95cb4fb4ad)
2025-03-18 11:50:18 +01:00
Zhenlei Huang
ef741cec70 if_clone: Use static initializers
While here, remove vnet_if_clone_init() which is therefore an empty function.

MFC after:	1 week

(cherry picked from commit 1ba655149ed0447f93e997a60330d9b962d061f2)
2025-03-14 11:02:20 +01:00
Kevin Bowling
16c9e5f5f8 ixgbe: x550 support for 1000BASE-BX SFP modules
Add support for 1Gbit BiDi modules to x550 derivatives

(cherry picked from commit 183621655613bcc97e4ec7d22adbc829347ed426)
2025-03-14 11:00:24 +01:00
Tore Amundsen
c324c90cae ixgbe: Add support for 1000BASE-BX SFP modules
Add support for 1Gbit BiDi modules

Signed-off-by:	Tore Amundsen <tore@amundsen.org>
Relnotes:	yes
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1518

(cherry picked from commit 89d4096950c4db748e39758c941cfb708c2ff808)
2025-03-14 11:00:24 +01:00
Andrey V. Elsukov
5d333f6446 pfkey2: use correct value for a key length
The length of key data is specified via sadb_key_bits field.
Use specified size for buffer allocation and key copying.
Also add a check that the value of sadb_key_bits is not zero,
as explicitly required in RFC 2367.

PR:		241010
Submitted by:	jean-francois.hren at stormshield eu

(cherry picked from commit 04207850a9b988d3c04e904cb5783f33da7fe184)
2025-03-14 10:59:06 +01:00
Andrey V. Elsukov
47129fdb74 ipfw: fix dump_soptcodes() handler
Use correct indent number to dump registered socket options.
It is not currently in use but can be used for debugging.

PR:		283970

(cherry picked from commit b405250c77e6841a8159a4081d4e0f61e49dfbf8)
2025-03-14 10:58:57 +01:00
Zhenlei Huang
19b6924cdc bpf: Use static initializers
MFC after:	1 week

(cherry picked from commit c7f8ffc70afa00ae863fe9f122c5a7eb7b56f4f5)
2025-03-14 10:58:31 +01:00
Zhenlei Huang
9e57b6b4f5 udp: Do not recursively enter net epoch
The only caller udp_send() has already entered net epoch before invoking
udp_v4mapped_pktinfo().

No functional change intended.

This partially reverts commit d74b7baeb0d4 (ifnet_byindex() actually
requires network epoch).

Reviewed by:	ae, glebius
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D49227

(cherry picked from commit 2472f4dbe93049d70afe0897f66f9651b67672e9)
2025-03-14 10:58:08 +01:00
Zhenlei Huang
02a79c4a32 netlink: Fix getting route scope of interface's IPv4 addresses
sin_addr of a `struct sockaddr_in` is stored in network byte order, but
IN_LOOPBACK() and IN_LINKLOCAL() want the host order.

Reviewed by:	melifaro, #network
Fixes:	7e5bf68495cc netlink: add netlink support
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D49226

(cherry picked from commit 0e096bb3fcaaf663df372aa4abb986e8d63c6e68)
2025-03-14 10:57:33 +01:00
Franco Fichtner
2a564b0b65 pf: only force state failure logging if logging was requested
PR: https://forum.opnsense.org/index.php?topic=45801.0
Fixes: 1a2a481
25.1.4
2025-03-12 14:51:52 +01:00
Zhenlei Huang
7c59d89f8c netinet: Make in_canforward() return bool
No functional change intended.

MFC after:	5 days

(cherry picked from commit 3ae7c763540afc0bc5320eb45f2661d315370eb8)
25.1.3
2025-03-10 08:25:25 +01:00
Andrey V. Elsukov
5fd8e8b505 routing: set net.route.multipath=0 when kernel doesn't have ROUTE_MPATH
(cherry picked from commit f2644d64b40f611fd4d4f66069ad8d6cf33f69df)
2025-03-10 08:23:45 +01:00
Zhenlei Huang
aba17792cc netinet: Make in_ifhasaddr() return bool
No functional change intended.

MFC after:	1 week

(cherry picked from commit 97309cec6f31f1f4f7a76f9ec5c7dd359c56de02)
2025-03-10 08:21:21 +01:00
Zhenlei Huang
dacf15eb76 netinet: Make in_localaddr() return bool
It is used as a boolean function everywhere.

No functional change intended.

MFC after:	1 week

(cherry picked from commit 69beb162848b15c967d3b45ac56501dbd8b94e91)
2025-03-10 08:21:09 +01:00
Zhenlei Huang
f4138e6c1e carp: Explicitly mark tunnable net.inet.carp.allow with CTLFLAG_NOFETCH
With recent change 110113bc086f, a vnet tunable can be initialized when
there is a corresponding kernel environment variable unless it is marked
with the flag CTLFLAG_NOFETCH.

The initialization may happen during early boot(linker preload), at that
time vnet0 has not been created. The hander carp_allow_sysctl() for the
tunable net.inet.carp.allow requires vnet, thus invoking it during early
boot will cause kernel panic.

The tunnable is initialized by vnet sysinit routine ipcarp_sysinit() so
let's just mark it with flag CTLFLAG_NOFETCH.

No functional change intended.

Fixes:		110113bc086f sysctl(9): Enable vnet sysctl variables to be loader tunable
MFC after:	2 week
Differential Revision:	https://reviews.freebsd.org/D41525

(cherry picked from commit 242fa308f3c3def32b2e61e0b78c11b3697e4492)
2025-03-07 09:37:05 +01:00
Zhenlei Huang
b425fdbd66 MAC: mac_biba, mac_lomac: Fix setting loader tunables
A string loader tunable requires setting the len parameter to a nonzero
value, typically the size of the string, to have the flag CTLFLAG_TUN
work correctly [1] [2].

Without this fix security.mac.{biba,lomac}.trusted_interfaces would
have no effect at all.

[1] 3da1cf1e88f8 Extend the meaning of the CTLFLAG_TUN flag to automatically ...
[2] 6a3287f889b0 Fix regression issue after r267961. Handle special string case ...

Reviewed by:	olce, kib
Fixes:		af3b2549c4ba Pull in r267961 and r267973 again ...
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D48898

(cherry picked from commit 7d4c0fac8c7db9c5741ba98a8b3ce3c43feb1cf4)
2025-03-07 09:34:36 +01:00
Zhenlei Huang
52acf9788a powerpc: Remove flag CTLFLAG_TUN from sysctl knob hw.platform
Prior to change [1] this flag is useless but harmless. After the change
plat_name[] will be fetched from kernel environment after invoking the
platform probe function `platform_probe_and_attach()`. The probe function
runs at early boot stage prior to `mi_startup()` thus it is too late and
pointless to set plat_name[] after the probe.

Nathan mentioned that the logic to specify the platform pre-dates the
powerpc64 work, and is from the original pre-FDT Book-E bringup from
like 2008, so it's irrelevant these days. Instead of fixing setting the
sysctl knob hw.platform, let's clean it up now.

[1] 3da1cf1e88f8 Extend the meaning of the CTLFLAG_TUN flag to ...

Discussed with:	nwhitehorn
Reviewed by:	olce (previous version), jhibbits, #powerpc
MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D48897

(cherry picked from commit b61fbbed73ea3bf0c84589b56cca160c46a3739d)
2025-03-07 09:34:12 +01:00
Zhenlei Huang
ea694ddbeb sysctl(9): Enable vnet sysctl variables to be loader tunable
Complete phase two of 3da1cf1e88f8.

In 3da1cf1e88f8, the meaning of the flag CTLFLAG_TUN is extended to
automatically check if there is a kernel environment variable which
shall initialize the SYSCTL during early boot. It works for all SYSCTL
types both statically and dynamically created ones, except for the
SYSCTLs which belong to VNETs.

This change extends the meaning further, to allow it also works for
the SYSCTLs which belong to VNETs. A typical usage is
```
VNET_DEFINE_STATIC(int, foo) = 0;
SYSCTL_INT(_net, OID_AUTO, foo, CTLFLAG_RWTUN | CTLFLAG_VNET,
    &VNET_NAME(foo), 0, "Description of the foo loader tunable");
```

Note that the implementation has a limitation. It behaves the same way
as that of non-vnet loader tunables. That is, after the kernel or modules
being initialized, any changes (e.g. via kenv) to kernel environment
variable will not affect the corresponding vnet variable of subsequently
created VNETs. To overcome it, we can use TUNABLE_XXX_FETCH to fetch
the kernel environment variable into those vnet variables during vnet
constructing.

This change will fix the following SYSCTLs those belong to VNETs and
have CTLFLAG_TUN flag:
```
net.add_addr_allfibs
net.bpf.optimize_writers
net.inet.tcp.fastopen.ccache_buckets
net.link.bridge.inherit_mac
net.link.bridge.ipfw_arp
net.link.bridge.log_stp
net.link.bridge.pfil_bridge
net.link.bridge.pfil_local_phys
net.link.bridge.pfil_member
net.link.bridge.pfil_onlyip
net.link.lagg.default_use_flowid
net.link.lagg.default_use_numa
net.link.lagg.default_flowid_shift
net.link.lagg.lacp.debug
net.link.lagg.lacp.default_strict_mode
```

Although the following vnet SYSCTLs have CTLFLAG_TUN flag, theirs
values are re-fetched via TUNABLE_XXX_FETCH, thus are not affected
by this change.
```
net.inet.ip.reass_hashsize
net.inet.tcp.hostcache.cachelimit
net.inet.tcp.hostcache.hashsize
net.inet.tcp.hostcache.bucketlimit
net.inet.tcp.syncache.bucketlimit
net.inet.tcp.syncache.cachelimit
net.inet.tcp.syncache.hashsize
net.key.spdcache.maxentries
net.key.spdcache.threshold
```

In memoriam:	hselasky
Discussed with:	hselasky, glebius
Fixes:		3da1cf1e88f8 Extend the meaning of the CTLFLAG_TUN flag ...
MFC after:	2 weeks
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D39638

(cherry picked from commit 110113bc086f5df1a9b6547edb1ab0cec698c55c)
2025-03-07 09:33:33 +01:00
Zhenlei Huang
0af904c415 netinet: Use NULL for VNET_SYSINIT's last arg, which is a pointer type
MFC after:	3 days

(cherry picked from commit ac51711cab6e55a99ee0a565fe0ae30c0305c854)
2025-03-07 09:12:39 +01:00
Franco Fichtner
da1ef9f513 netinet6: do not forward to the unspecified address
This mimics 316a0990f0b74 in IPv6.  While this condition is already
checked in some of the ICMP code make it explicit while processing
the packet in icmp6_reflect().
2025-03-07 08:51:43 +01:00
Konstantin Belousov
33a19b8045 mb_unmapped_to_ext(): return error code on error
(cherry picked from commit cf322978d73a3ed4958cb64cc4f1b47ceb53a03e)
2025-03-07 08:51:43 +01:00
Zhenlei Huang
316a0990f0 netinet: Do not forward or ICMP response to INADDR_ANY
The section 4 in the draft proposal [1] explicitly states that 0.0.0.0,
aka INADDR_ANY, retains its existing special meanings.

[1] https://datatracker.ietf.org/doc/draft-schoen-intarea-unicast-0

Reviewed by:	glebius
Fixes:	efe58855f3ea IPv4: experimental changes to allow net 0/8, 240/4, part of 127/8
MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D49157

(cherry picked from commit f7174eb2b4c45573bb9e836edad2b179a445a88f)
2025-03-07 08:18:35 +01:00