Commit graph

307228 commits

Author SHA1 Message Date
fe7a7425d4 iicbus: ina2xx is GPL-2.0-only, ported from Linux hwmon/ina2xx.c
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 21:54:00 -05:00
81bd5b12ac dpaa: trust RX L4 checksums only when the parser validated them
The RX path marked TCP/UDP checksums hardware-verified unless
FM_FD_CMD_DCL4C was set, but that is a TX command bit: frames with bad
checksums could be accepted (IDS evasion). Claim CSUM_L4_VALID only with
FM_FD_STAT_L4CV in the frame status, as Linux's dpaa_eth does. Nothing
says the parser checked the IPv4 header checksum, so the stack verifies
it again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 21:54:00 -05:00
623bab2673 arm64: build kernel.bin for the GATEWAY kernel
FreeBSD 15 builds kernel.bin, the booti image U-Boot loads, only with
WITH_KERNEL_BIN (34632ed1a4); it was always built before. The image
and the gateway's FAT kernel update both need it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 15:19:11 -05:00
c32ae510d7 arm64, dpaa: build fixes for FreeBSD 15
- machdep.c: drop the socdev_va and hcr_el2 lines carried over from
  26.1. Upstream 26.7 defines socdev_va itself and no longer uses
  hcr_el2, which -Werror rejects as unused.
- fman_fdt.c: the clock header moved to dev/clk/clk.h.
- fm_ehash.c: cpu_dcache_wbinv_range() takes a pointer now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 19:25:04 -05:00
c52883ab3e arm64: drop GEOM_BDE from the GATEWAY kernel config
FreeBSD 15 removed GEOM_BDE (gbde), so config(8) stops on the unknown
option. Upstream OPNsense 26.7 no longer sets it either.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 16:50:40 -05:00
Maurice Walker
ba6d8a73da build U-Boot booti compatible kernel 2026-11-22 21:16:06 -05:00
Tomaz Zaman
979a18e50e kern: add colored timestamps to console output
Prefix every console line with a Linux-style [seconds.microseconds]
timestamp. Brackets in default white, number in green via ANSI escapes.
Uses microuptime() for the time source and emits directly to console
hardware to avoid cnputc recursion. Both EARLY_PRINTF and normal
console paths are covered.
2026-11-22 21:16:06 -05:00
Tomaz Zaman
cfc080ef72 zfs: switch root filesystem from UFS to ZFS, silence fmcd ioctl spam
Change GATEWAY kernel config from UFS root to ZFS root (pool0/ROOT/default).
ZFS is compiled into the kernel since booti direct boot has no FreeBSD loader
to load modules. Disable kern.geom.label.disk_ident.enable so GPT labels
work cleanly with ZFS.

Remove printf from fman chardev ioctl default cases. ZFS GEOM probes all
character devices with DIOCGMEDIASIZE (0x40086481) at boot, generating ~32
spurious "unknown ioctl" messages. ENOTTY is the correct response and the
printf serves no diagnostic purpose.
2026-11-22 21:16:06 -05:00
Tomaz Zaman
c6e1ba22d8 sff: move SFP module management into sfp_fdt state machine
Move ~900 lines of SFP management code (GPIO polling, EEPROM reading,
RollBall I2C-MDIO PHY probing, auto-negotiation, link monitoring) from
the dtsec MAC driver into the sfp_fdt framework driver.

sfp_fdt now implements a full state machine (EMPTY → PROBE → PRESENT →
PHY_PROBE/WAIT_LOS → PHY_AN/DDM_POLL → LINK_UP) that handles module
detection, identification, and link management for any MAC driver with
SFP+ cages. MAC drivers register a callback table (sfp_upstream_ops)
via SFF_REGISTER_UPSTREAM() and receive module_insert, module_remove,
link_up, and link_down events.

dtsec is reduced to ~50 lines of callback implementations that update
interface link state and store module info for sysctl reporting.

Tested on hardware with both fiber (FLEXOPTIX DAC) and copper (FS.com
10GBASE-T with AQR113C PHY via RollBall) modules at 10 Gbps.
2026-11-22 21:16:06 -05:00
Tomaz Zaman
b909c69491 dpaa: add 10GBASE-T copper SFP+ PHY driver via I2C-MDIO bridge
Add support for copper (RJ45) SFP+ modules with embedded PHYs.
These modules use Clause 45 MDIO registers accessed via an I2C-to-MDIO
bridge for PHY management, auto-negotiation, and link status polling.

Two bridge protocols are supported with automatic detection:
- RollBall (I2C addr 0x51, page 3, command-based)
- Standard I2C-MDIO (I2C addr 0x56, SFF-8472)

PHY probe runs on module insertion for RJ45 connectors, configures
auto-negotiation (10G/5G/2.5G/1G advertisement with Extended Next Page),
and polls PMA/PMD link status at 1Hz via taskqueue. Speed detection
uses AN 10GBT_STAT for multi-gig and PMA/PMD CTRL1 as fallback.

For copper modules without accessible PHY (autonomous operation),
falls back to DDM RX_LOS polling for link state detection.

Also fixes three GPIO issues that prevented copper modules from working:
- TX_DISABLE pin direction must be set to OUTPUT explicitly
- TX_DISABLE polarity inverted due to board hardware inverter
- Module PHY stays inactive until TX_DISABLE is properly deasserted

Verified at 10 Gbps (9.4 Gbps iperf3) with FS.com SFP-10G-T (AQR113C)
and Intel X550 link partner over Cat6e cable.
2026-11-22 21:16:06 -05:00
Tomaz Zaman
c561eda6c1 dpaa: fix SFP link state semantics and copper module handling
Use LINK_STATE_UNKNOWN for no-module state (instead of DOWN) so the
sfpled driver can distinguish "no module" from "module present, no
link".  For copper PHY modules (RJ45 connector type 0x22), ignore
LOS GPIO — these modules deassert LOS when powered up regardless
of copper link negotiation status.  Always report LINK_STATE_DOWN
for RJ45 modules until a PHY driver can negotiate.
2026-11-22 21:16:06 -05:00
Tomaz Zaman
2f5ece53b5 dpaa: add SFP module detection and link management for 10GbE ports
Wire SFP infrastructure into dtsec so 10GbE ports detect module
insertion/removal via mod-def0 GPIO polling, read the SFP EEPROM
for identification, control TX enable/disable, and report accurate
link status via LOS GPIO instead of hardcoding link as always up.

Module presence is polled at 1Hz in the existing tick callout.
EEPROM reads are deferred to taskqueue_thread since I2C can sleep.
Insert task re-checks module presence under DTSEC_LOCK to handle
races with hot-removal during EEPROM read.

Adds dev.dtsec.N.sfp_info sysctl for module vendor and part number.

No DTS changes needed — sfp phandle, GPIOs, and i2c-bus are already
defined in mono-gateway-dk.dts.
2026-11-22 21:16:05 -05:00
Tomaz Zaman
caad5d8702 dpaa: move fmlib ioctl headers into kernel tree
Move the 5 fmlib ioctl ABI headers (fm_pcd_ioctls.h, fm_ioctls.h,
net_ioctls.h, ioctls.h, integration_ioctls.h) from the external
opnsense-deps repo into sys/contrib/ncsw/inc/ioctls/.  This makes the
kernel buildable without depending on a sibling repository.

Merge FMCD_COMPILE_CMD into DPAA_COMPILE_CMD since it only added a
single -I path; fman_chardev.c now compiles with the same flags as all
other DPAA source files.
2026-11-22 21:16:05 -05:00
Tomaz Zaman
7e0b387d89 dpaa: use opnsense-deps for fmcd headers instead of ASK
Point FMCD_COMPILE_CMD include paths from $S/../../ASK/freebsd/fmlib/
to $S/../../opnsense-deps/fastpath/fmlib/. The headers are identical;
this removes the build dependency on the standalone ASK repository.
2026-11-22 21:16:05 -05:00
Tomaz Zaman
00b427c6bb ng_pppoe: add NGM_PPPOE_GET_SESSION_INFO for PPPoE offload
Add netgraph control message (cookie 20) that returns PPPoE session
parameters: session_id, peer MAC, state, and hook name.  Supports
both single-session query (by hook name) and list-all-sessions mode.

Used by CMM to detect active PPPoE sessions and extract the parameters
needed to program hardware flow offload (session ID for PPPoE header
insertion, peer MAC for L2 header construction).
2026-11-22 21:16:05 -05:00
Tomaz Zaman
dfe1215105 dpaa: start MII tick for LAGG member ports, reprogram MAC on enable
LAGG member ports are enabled via SIOCSIFFLAGS -> dtsec_if_enable_locked(),
not dtsec_if_init_locked(). The MII tick callout was only started in the
init path, so LAGG member ports never got periodic PHY polling. Without
the tick, link state changes (cable unplug/replug) were never detected
and RTM_IFINFO was never generated.

Start callout_reset in dtsec_if_enable_locked() so member ports get the
same periodic PHY polling as standalone ports. Also reprogram the hardware
MAC address via FM_MAC_ModifyMacAddr() since LAGG changes the stack MAC
via if_setlladdr() then cycles SIOCSIFFLAGS.
2026-11-22 21:16:05 -05:00
Tomaz Zaman
7f5479734b dpaa: per-VAP FQ registry, dist fallback, OH enqueue EBUSY, refill API
dpaa_oh: Add per-VAP distribution FQ registry so CDX can route WiFi
download frames to hash-distributed FQIDs. Add dist fallback callback
for frames with unrecognized BPIDs on OH dist FQs. Return EBUSY from
dpaa_oh_enqueue when EQCR ring is full so callers can retry. Free
dtsec buffers in error callback to prevent BMan pool drain.

if_dtsec: Export dtsec_rm_pool_rx_refill_bpid for external callers
(dpaa_wifi, dpaa_oh, CDX) that consume dtsec BMan pool buffers.
2026-11-22 21:16:05 -05:00
Tomaz Zaman
2fdd8cef4e dpaa: PLCR/KG miss fixup, portal quiesce, OH dist callbacks
fm_ehash: Rewrite ModifyMissNextEngine to match Linux SDK two-phase
pattern (DROP→update→real action). Support KG (with CC_EN), PLCR
(shared profile), and DONE engines. Remove verify-retry loop and CC
tree copy propagation — single WRITE_UINT32 per word suffices with
the two-phase approach.

qman_portals: Add qman_portal_quiesce() to drain all per-CPU portal
poll taskqueues. Called after FQR retire to ensure no in-flight
QM_PORTAL_Poll references a stale callback from an unloading module.

if_dtsec_rm: Add dtsec_rm_pool_rx_refill_bpid() for external callers
(CDX dist FQ callback) to trigger BMan pool refill by BPID.

dpaa_oh: Add distribution FQ callback registry (register/unregister/
lookup by BPID) for OH port consumers (WiFi, IPsec) to receive
frames from CDX distribution FQs. Add MODULE_VERSION.
2026-11-22 21:16:05 -05:00
Tomaz Zaman
5473dd8a44 dpaa: cross-module buffer free for WiFi offload
Add dtsec_rm_buf_free_external() for dpaa_wifi.ko to release BMan
buffers from dtsec RX pools back to the correct UMA zone. Route
M_PROTO1-tagged mbufs to if_transmit in QMan portal drain path.
2026-11-22 21:16:05 -05:00
Tomaz Zaman
b10a2eb875 gpio: add FDT gpio-hog processing for boot-time pin configuration
Process gpio-hog child nodes during gpiobus attach to configure pins
at boot. Used on Mono Gateway for WiFi module enable (2R-enable),
3R-disable, and UART mux routing.
2026-11-22 21:16:05 -05:00
Tomaz Zaman
a3dd8a80d2 pci: DesignWare PCIe big-endian CCSR and lane configuration for LS1046A
- qoriq_dw_pci: byte-swap CCSR register access for big-endian controller
- pci_dw: lane configuration support for proper link training
- DTS: enable PCIe3 for WiFi module (88W9098)
2026-11-22 21:16:05 -05:00
Tomaz Zaman
3671939045 pf: add state creation/destruction notification hooks
Add callback interface for PF state lifecycle events (create, destroy,
update). Used by CMM connection offload module to synchronize hardware
flow tables with PF firewall state.

[26.7.9: rebuilt from the 26.1 version of this commit. On stable/26.7 it also
replaced parts of pf.c with older 14.x code (s->rule.ptr, the former SCTP
and ICMP cases), which does not compile; only the hook calls are kept.]
2026-11-22 21:15:53 -05:00
Tomaz Zaman
a921690479 net: add bridge L2 offload notification hooks
Add callback hooks for bridge member add/remove and L2 address learning
events. Used by CDX flow offload module to maintain hardware L2
forwarding tables.
2026-11-22 20:41:57 -05:00
Tomaz Zaman
e94f183c19 dpaa: add CEETM egress QoS traffic management
Class-based Enqueue/Dequeue Traffic Management for DPAA1 QMan.
Provides hardware traffic shaping and scheduling via QMan CEETM
channels.
2026-11-22 20:41:57 -05:00
Tomaz Zaman
85b9f36f56 iicbus: add INA2xx power monitor driver
TI INA219/INA226/INA234 I2C power monitor with sysctl interface for
voltage, current, and power readings. Used on Mono Gateway for rail
monitoring.
2026-11-22 20:41:57 -05:00
Tomaz Zaman
5b6356018b arm64: peripheral driver fixes for LS1046A
- qoriq_gpio: QorIQ GPIO controller support
- gpiopower: GPIO-based power control fix
- iicmux/pca954x: I2C mux devclass fix (use "iicbus" not "ofw_iicbus")
- ofw_iicbus: FDT child enumeration fix
- random_harvestq: allow CAAM hardware RNG as entropy source
2026-11-22 20:41:57 -05:00
Tomaz Zaman
2d75c29355 mii: add MaxLinear GPY115/GPY2xx PHY driver
Firmware-based SGMII PHY used on the Mono Gateway (3x 1GbE ports).
Key differences from standard PHY drivers:
- No BMCR reset (kills firmware, darkens LEDs)
- SGMII auto-negotiation via MMD VEND1 register
- Status read from MIISTAT instead of BMSR
2026-11-22 20:41:57 -05:00
Tomaz Zaman
b2234cb747 dpaa: add offline/header manipulation (OH) port driver
OH ports provide hardware packet processing pipelines for IPsec and
WiFi offload via CDX. Port assignment matches Linux SDK: cell-index 3
(IPsec), cell-index 4 (WiFi). Cell-index 2 reserved for Host Command.
2026-11-22 20:41:57 -05:00
Tomaz Zaman
d94f482413 dpaa: dTSEC/mEMAC Ethernet driver with checksum offload and RSS
Add the main DPAA1 Ethernet driver using the NCSW FM_MAC API for
mEMAC (LS1046A FManv3). Implements TX/RX via QMan frame queues and
BMan buffer pools with scatter-gather support.

Features: TX checksum offload (RPD+DTC), RX checksum validation with
PCD parser, 128-FQID RSS via FMan KeyGen, deferred RX delivery via
mbufq to prevent SMP hard lockups from nested NCSW_PLOCK, per-port
BMan buffer pool with consumption model and in-flight cap.

Includes mEMAC external MDIO controller for PHY management.
2026-11-22 20:41:57 -05:00
Tomaz Zaman
0d5c7129e6 dpaa: BMan/QMan/FMan portal integration and bus drivers
Add the FreeBSD bus driver wrappers that bridge NCSW to the kernel
device tree. BMan and QMan portal drivers handle multi-CPU
initialization with explicit CPU binding (sched_bind unavailable
during attach). FMan driver configures the frame manager hardware,
reserved-memory regions (PFDR/FQD/FBPR via no-map DT nodes), and
MURAM allocation.

Portal common infrastructure provides shared init and cache-inhibited
mapping for both BMan and QMan portals.
2026-11-22 20:41:57 -05:00
Tomaz Zaman
9a8915a7a0 ncsw: port DPAA1 NCSW layer to ARM64
Port the NetCommSW (NCSW) library from PowerPC to ARM64 for the
NXP LS1046A. Adds ARM64 environment layer (xx_arm64.c, core_arm64.c,
dflags_arm64.h), fixes big-endian portal access, cache operations,
and integration headers for DPAA_VERSION 11 (FManv3/mEMAC).

Includes enhanced hash table support (fm_ehash.c) for CDX PCD,
MURAM batch-write fixes for ARM64 store behavior, QMan FQR RSS
expansion, and BMan/QMan portal initialization changes.

Enable device dpaa in GATEWAY config with NCSW file list.
2026-11-22 20:41:56 -05:00
Tomaz Zaman
227c532dce arm64: GATEWAY kernel config, device tree, and platform support
Add the MONO-GATEWAY kernel configuration for the NXP LS1046A-based
Mono Gateway Development Kit. Based on GENERIC with OPNsense standard
features, DPAA1 build infrastructure (empty file list for now), and
early printf via QorIQ ns16550.

Add the mono-gateway-dk.dts device tree covering the full SoC and board
peripherals (DPAA1 FMan/QMan/BMan, I2C mux tree, GPIO, UART, eMMC, QSPI,
SFP+ cages, and reserved memory regions).

Add ARM64 I/O stubs (pio.h) for NCSW compatibility, EARLY_PRINTF qoriq
type registration, CAAM RNG entropy source enum, and qoriq_therm build
fix (remove spurious pci dependency).
2026-11-22 20:41:56 -05:00
Franco Fichtner
1633399de9 Revert "ice(4): Fix link speed after changing cable type"
This reverts commit 27ffeba0e6.

PR: https://forum.opnsense.org/index.php?topic=52405.msg276938#msg276938
2026-11-10 13:56:13 +01:00
Andrew Gallatin
68b64bbc01 pfil: Avoid potential mbuf tag leak
In '398254f9999e mbuf: simplify m_free' we removed tag processing
on m_free() of M_NOFREE mbufs. It is possible that a packet filter
could attach a tag to this stack mbuf and call m_free()
on it, meaning that 398254f9999e may have introduced a tag leak.

However,if a tag is attached without anyone calling m_free(), then
this leak was pre-existing.

Reviewed by: glebius
Differential Revision: https://reviews.freebsd.org/D60686
Fixes: 398254f9999e
Sponsored by: Netflix

(cherry picked from commit f4ff995e361fa72cea240c4dbac2d0931965c80f)
2026-11-10 12:52:53 +01:00
Mark Johnston
717cbf3f0d igmp: Refresh the ip header pointer after m_pullup()
There is a chance that the m_pullup() call immediately above invalidated
the "ip" pointer, so refresh it as we do with the IGMP header.
Otherwise the test in igmp_input_v3_query() for whether the packet is an
IGMPv3 general query might use a pointer to a freed mbuf.

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit dc47a6940d60d393b3d36ba0fc5cb84d06fafaea)
2026-11-10 12:52:07 +01:00
Mark Johnston
6738896f59 igmp: Deindent some code
No functional change intended.

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 123342f3d2cccf432d3d0082097b6c97397ecc67)
2026-11-10 12:52:00 +01:00
Olivier Cochard
cf3f8e3dc6 carp: fix global demotion counter to VRRP advertisements
When net.inet.carp.preempt=1 and a physical interface goes down, the global
V_carp_demotion counter is incremented. For CARP this was already reflected in
outgoing advertisements via DEMOTE_ADVSKEW(), but VRRP sent the raw
sc_vrrp_prio unchanged, so demotion had no effect.

Add DEMOTE_VRRP_PRIO(), a macro analogous to DEMOTE_ADVSKEW():
It subtracts V_carp_demotion from the configured priority and clamps the result
to [0, 254]. Priority 0 is VRRPv3's "resign" signal and causes backups to
preempt immediately. Priority 255 (IP address owner) is never demoted.

Reviewed by:	kp
Approved by:	kp
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D55558

(cherry picked from commit 9f71153aec0cb455cd49af6d4ca7e4c16fd45d7a)
2026-11-10 12:51:01 +01:00
Bjoern A. Zeeb
54820bb93a sctp: initialize inp to avoid uninitialized use
If we take an early goto out_unlocked inp is uninitialized and then
may be used in SCTP_LTRACE_ERR_RET().  Initialize inp to NULL
to avoid warnings.

Found with:	gcc15 tinderbox build
Reviewed by:	tuexen, pouria
Differential Revision: https://reviews.freebsd.org/D56503

(cherry picked from commit 4cdbcc2b6a2e551529f7133665ef406869b48bf7)
2026-11-10 12:49:55 +01:00
Pouria Mousavizadeh Tehrani
989cc33561 netinet6: Fix check for pktinfo outgoing ifindex in route cache
lookup_route is only called for outgoing traffic, therefore
check nh_ifp index instead of nh_aifp as specified by RFC3542 sec 6.

Differential Revision: https://reviews.freebsd.org/D58544

(cherry picked from commit 7753a59fdf196fcbd8bb5706ad44bfc590bce0a9)
2026-11-10 12:48:11 +01:00
R. Christian McDonald
00c1838935 iflib: Do not ring the transmit doorbell when nothing is pending
For a lightly used ring iflib_txd_db_check() may defer zero descriptors,
so its "pending >= limit" test is true even when nothing has been queued
since the last doorbell.  iflib_txq_drain() calls it before, inside and
after its loop, so a sender that drains its own packet wrote the tail
register three times per packet, twice with the value the hardware
already had.

The log of 81be655266 ("iflib: ensure that tx interrupts enabled and
cleanups") calls skipping the doorbell when db_pending is zero "an
obvious missing optimization"; the comparison against a limit of zero
defeated it.  vmx(4) and mgb(4) have dropped such repeated requests in
the driver since 2019.  Return early when nothing is pending.

Reviewed by:		gallatin
MFC after:		2 weeks
Sponsored by:		Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D60290

(cherry picked from commit 4a0ec469934a5de60b9b540689703a698ac44105)
2026-11-10 12:47:27 +01:00
Gleb Smirnoff
f4fddfa875 netlink: fix unsigned overflow on a truncated message
PR:			295106
Submitted by:		Robert Morris <rtm@lcs.mit.edu>
Reviewed by:		pouria, melifaro
Differential Revision:	https://reviews.freebsd.org/D56916

(cherry picked from commit e924a2c80b9e1ace68d8ca0ffdacec65feec90a3)
2026-11-10 12:44:04 +01:00
Teddy Engel
8015491859 nat64lsn: Fix type confusion panic when using wrong NAT64 instance type
When an ipfw rule references a NAT64 instance by name using
'nat64lsn', the kernel looks up the instance in the shared
srvstate[] array without verifying the instance type.
If the named instance is actually a nat64clat or nat64stl
instance (created with 'nat64clat' or 'nat64stl'), the code
incorrectly casts the instance to nat64lsn_instance and
dereferences the ->cfg pointer, which causes a kernel panic.

The root cause is that all NAT64 instance types share the same
srvstate[] array but have different struct layouts.
For nat64lsn_instance, the field after 'no' is a pointer to nat64lsn_cfg.
For nat64clat_cfg, the same offset contains an embedded nat64_config struct.

Fix by adding a type check after NAT64_LOOKUP() to verify that the
instance's etlv matches IPFW_TLV_NAT64LSN_NAME before proceeding.
If the type doesn't match, return IP_FW_DENY to reject the packet
safely rather than crashing.

Signed-off-by:	Teddy Engel <engel.teddy@gmail.com>
PR:		292023
Reported by:	pouria
Reviewed by:	ae
Pull-Request:	https://github.com/freebsd/freebsd-src/pull/2249

(cherry picked from commit ea4888e63f6ac89c38982ffee693f89a5927e9c9)
2026-11-10 12:43:13 +01:00
Teddy Engel
829ea4eefa ipfw/nat64: Fix type confusion panic when using wrong NAT64 instance type
Add etlv type validation to ipfw_nat64clat() and ipfw_nat64stl() to
verify that the retrieved instance is actually a nat64clat instance
before use.

All NAT64 instance types share the same srvstate[] array but have
different struct layouts.
Without type validation, using the wrong instance type with
a handler causes type confusion and kernel panic.

Signed-off-by:	Teddy Engel <engel.teddy@gmail.com>
PR:		292023
Reviewed by:	pouria
Pull Request:	https://github.com/freebsd/freebsd-src/pull/2259

(cherry picked from commit 2e6b22abf44d99b84abf17fe25ca2e8f89716c04)
2026-11-10 12:43:13 +01:00
R. Christian McDonald
2a3cdb77ed pf: leave the epoch to purge unlinked rules
pf_purge_thread() calls pf_purge_unlinked_rules() in the network
epoch, where sleeping is not allowed, and it takes pf_config_lock, an
sx lock. If a rule is being added at the time, the purge thread
can sleep on the lock, which panics with INVARIANTS.

Reviewed by:		kp
Approved by:		kp (mentor)
Fixes:			f92d9b1aad ("pflow: import from OpenBSD")
MFC after:		1 week
Sponsored by:		Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D60160

(cherry picked from commit 82ab4adec95578b196eaf431d6ca87dd209aca6b)
2026-11-10 12:34:15 +01:00
R. Christian McDonald
7da85a4ab4 pf: Drain the overload task before a vnet's rules are freed
pf_src_connlimit() queues an entry for pf_overload_task() when a
source exceeds max-src-conn or max-src-conn-rate and the rule has an
overload table.  The entry holds a pointer to the rule, and the task
runs from taskqueue_swi with the vnet of the queue.  Nothing drained
the task when the vnet went away: an entry queued just before could
be applied to a rule pf_unload_vnet_purge() had freed, or to a vnet
that was gone.

Drain the task at the start of pf_unload_vnet_purge(), before the
unlinked rules are freed.  No packet can queue another by then, as the
hooks are already removed.

Reviewed by:		kp
MFC after:		2 weeks
Sponsored by:		Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D60529

(cherry picked from commit 92d66a6b474fa6fe42fbe08002803d79a5af6594)
2026-11-10 12:33:41 +01:00
Kristof Provost
3eb67be8ed pf: check extension header length.
pf_walk_header6() advances the packet offset for each IPv6 extension
header.  It was not checked that this does not exceed the packet
length if no next header was processed.  When used with af-to rules,
this could trigger a panic: m_copydata: null mbuf.

from Acts1631; OK henning@ sashan@

MFC after:	1 week
Obtained from:	OpenBSD, bluhm <bluhm@openbsd.org>, 6d56112588
Sponsored by:	Rubicon Communications, LLC ("Netgate")

(cherry picked from commit ccb19b359aae4b7e7315ad61d33d9a35d85849d1)
2026-11-10 12:32:12 +01:00
Kristof Provost
1c205252a8 pf: check AH header length.
pf_walk_header() advances the packet offset for each AH extension
header.  It was not checked that this does not exceed the packet
length if no next header was processed.  Fix it like in IPv6.

OK henning@ sashan@

MFC after:	1 week
Obtained from:	OpenBSD, bluhm <bluhm@openbsd.org>, fcd4e5522e
Sponsored by:	Rubicon Communications, LLC ("Netgate")

(cherry picked from commit b4d2c9835c0edfddd1d6742afa86d4873ccfad16)
2026-11-10 12:32:12 +01:00
R. Christian McDonald
86a0697d6a pf: modify pfik_flags atomically
The purge thread sets PFI_IFLAG_REFS on the interfaces that states
refer to without the rules lock, under which the other flags are
changed. The updates can interleave, so that a "set skip on" is lost,
or outlives its removal, until the next ruleset load.

Use atomic operations to modify the flags. In the purge thread, only
write if the flag is not already set.

Reviewed by:		kp
Approved by:		kp (mentor)
MFC after:		1 week
Sponsored by:		Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D60107

(cherry picked from commit c1241c6e30c792fb514f4689d2ed92ee21d3cf39)
2026-11-10 12:29:23 +01:00
R. Christian McDonald
6658853902 pf: Set the reassembly flags under the rules lock
DIOCSETREASS stored V_pf_status.reass twice with no lock, first the
flags it was given and then, if reassembly was not among them, zero.
pf_normalize_ip() and pf_normalize_ip6() read the flags with the rules
lock held for reading, so a packet could see the intermediate value.
Compute the flags first and store them once, with the rules lock held
for writing, as DIOCSETDEBUG and DIOCSETHOSTID do.

Reviewed by:		kp
Fixes:			39282ef356 ("pf: backport OpenBSD syntax of "scrub" option for "match" and "pass" rules")
MFC after:		2 weeks
Sponsored by:		Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D60531

(cherry picked from commit b951994eddd4d274514df751da06680a32139037)
2026-11-10 12:28:45 +01:00
R. Christian McDonald
06566a325e pf: free the packet rate counter of a rule
pf_ioctl_addrule() allocates a counter_rate for every rule, whether it
has a max-pkt-rate or not, and pf_krule_free() never frees it.

Free it with the rest of the rule.

Reviewed by:		kp
Approved by:		kp (mentor)
Fixes:			ff11f1c8c7 ("pf: add a generic packet rate matching filter")
MFC after:		1 week
Sponsored by:		Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D60190

(cherry picked from commit 2fa4ef491608aad827f8ceef3eb389d8c07451fb)
2026-11-10 12:28:27 +01:00