Docs: hardware flow offload is opt-in and keeps pf's decisions

RELEASE.md: the "offload: off" section becomes "opt-in": how to turn cmm
on (in /etc/rc.conf.local, which overrides rc.conf), which flows go into
hardware and which stay in pf, what offloaded packets still skip
(Suricata, Insight/NetFlow, tcpdump), the reboot after an update, and
what was wrong with the vendor's offload.

ARCHITECTURE.md: pf_notify's RESYNC event, vetoes, route-to target and
orig_kif, the DELETE reserve, sloppy only for offloaded states, and the
flow lifecycle with the offload conditions; the PF_KEY socket is gone
with the IPsec code; cmm only starts with cmm_enable="YES".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jeremy Karst 2026-11-28 02:08:48 -05:00
parent e78dba3348
commit 64240400dc
2 changed files with 87 additions and 27 deletions

View file

@ -51,7 +51,8 @@ bypassing the FreeBSD networking stack.
kernel boot
└─► kldload cdx fci pf_notify auto_bridge
└─► dpa_app /etc/cdx_pcd.xml /etc/cdx_cfg.xml /etc/cdx_sp.xml
└─► service cmm start
└─► service cmm start (only with cmm_enable="YES"; images
ship "NO", see RELEASE.md)
```
## Fastpath Modules
@ -86,11 +87,28 @@ Hooks into the PF firewall to push state change events to userspace:
- `PFN_EVENT_INSERT` — new state created
- `PFN_EVENT_READY` — state became offload-eligible (TCP ESTABLISHED)
- `PFN_EVENT_DELETE` — state removed by PF
- `PFN_EVENT_RESYNC` — DELETE events were lost: CMM drops every hardware
flow and starts over (`net.pfnotify.resyncs`)
Each event carries the state's keys, the interface it was created on
(`orig_kif`; a floating state's own interface is `all`), its route-to or
reply-to target, and a veto mask (`PFN_VETO_*`) for rule actions only
pf_test() can carry out per packet: dup-to, another FIB, a dummynet pipe
or queue, ALTQ, `log (all)` or pflow, scrub options, set-tos, max-mss,
min-ttl, max-pkt-size. CMM never offloads a vetoed flow.
Exposes `/dev/pfnotify` (read-write, non-blocking). Required by CMM —
CMM will not start without this module loaded. Uses a 128K-entry ring
buffer with one-shot READY semantics: dropped events re-fire on the
next packet, eliminating the need for polling fallback.
buffer, of which 4096 entries are kept for DELETEs, with one-shot READY
semantics: dropped events re-fire on the next packet, eliminating the
need for polling fallback. CMM reports the states it put into hardware
(`PFN_IOC_OFFLOADED`); only those are made sloppy, as their TCP windows
stop being tracked. `PFN_IOC_UPDATE_COUNTERS` adds the hardware's packet
counts to the states, which keeps them from expiring while FMan forwards.
The event layout is shared with CMM (`pf_notify.h`). A CMM and a
pf_notify.ko from different builds get only short reads and offload
nothing, so reboot after updating `mono-gateway`.
Source: `fastpath/pf_notify/`
@ -111,18 +129,29 @@ next-hop neighbors, and programs CDX with offload entries.
/dev/pfnotify │ │ FCI commands
PF state poll │ CMM ├──────────────► cdx.ko
route socket │ │
PF_KEY socket │ event loop │◄────────────── FCI events
│ event loop │◄────────────── FCI events
/dev/autobridge│ (kqueue) │ (flow timeout)
ctrl socket │ │
└──────────────┘
```
**Flow lifecycle**:
1. PF creates state → pfnotify READY → CMM resolves route + neighbor
2. CMM sends route + conntrack to CDX via FCI → flow in hardware
3. Packets forwarded at line rate by FMan, bypassing stack
4. CDX timer expires or TCP FIN → FCI event → CMM clears offload flag
5. If PF state still alive → maintenance timer (30s) re-offloads
1. PF creates the flow's states (in on the ingress interface, out on the
egress one) → pfnotify READY for each → CMM pairs them and resolves
route + neighbor
2. CMM offloads only if neither state is vetoed, both were seen, each
direction's route leaves by the interface PF's state for it is on,
and a route-to (original direction) or reply-to (reply) names the
same interface and next hop as that route
3. CMM sends route + conntrack to CDX via FCI → flow in hardware, and
reports the two states to pf_notify (sloppy from then on)
4. Packets forwarded at line rate by FMan, bypassing stack; their
counters are synced back into PF's states
5. PF deletes a state (close, timeout, `pfctl -k`) → DELETE → CMM removes
the flow from hardware
6. CDX timer expires or TCP FIN → FCI event → CMM clears offload flag
7. A route change tears down the flows using it; while PF's states are
alive, the maintenance timer (30s) re-runs step 2 and re-offloads
Source: `fastpath/cmm/`

View file

@ -336,24 +336,55 @@ release/vm.sh pull-out 15.1 26.7 # -> /scratch/mono-opnsense/out/26.7
e.g. `26.1.11_74`. That always upgrades the previous build, and also the
vendor's `26.1.5_N` packages.
### Hardware flow offload: off
### Hardware flow offload (opt-in)
New images set `cmm_enable="NO"` (`rc.d/rc.conf.local`); the board modules
still load, but without cmm nothing is offloaded and pf handles every packet.
The vendor's offload is not safe yet (security audit, 2026-11-22):
With cmm running, FMan forwards established flows in hardware: pf decides a
flow's first packets, then the hardware forwards the rest with pf's
translation, and pf's states and counters follow it. Images set
`cmm_enable="NO"` (`rc.d/rc.conf.local`): the board modules load, but
nothing is offloaded until cmm is turned on. `/etc/rc.conf.local` overrides
`/etc/rc.conf`, so set it there:
- offloaded flows take the main routing table's route, so pf `route-to`,
`reply-to` and gateway rules (a VPN as gateway, multi-WAN) are ignored and
such traffic can leave on WAN outside the tunnel (`fastpath/cmm/cmm_conn.c`);
- while cmm runs, pf_notify marks every pf state sloppy, which turns off TCP
sequence checks (`fastpath/pf_notify/pf_notify.c`);
- bridged MAC pairs are offloaded without pf (`fastpath/auto_bridge`), and
hardware flows can outlive a pf state whose deletion event was dropped;
- the IPsec exception path panics on most decrypted packet sizes
(`fastpath/cdx/dpa_ipsec_freebsd.c`).
```sh
sh
sysrc -f /etc/rc.conf.local cmm_enable=YES
service cmm start
```
Offloaded traffic also skipped Suricata, the shaper, the captive portal and
pflog. Re-enable cmm only once these are fixed.
A flow goes into hardware only where that does what pf would have done
(`fastpath/pf_notify/`, `fastpath/cmm/cmm_conn.c`, ARCHITECTURE.md):
- pf passed it in and out, and none of its rules asks for something only pf
does per packet: dup-to, another FIB, a shaper pipe or queue, ALTQ,
`log (all)` or pflow, scrub options, set-tos, max-mss, min-ttl;
- the routing table sends each direction out of the interface pf's state for
it is on. A route-to or reply-to counts only while it names the same
interface and next hop as the routing table, as OPNsense's automatic
force-gateway and WAN reply-to rules do on a single WAN. Policy routing to
another gateway (a VPN, a second WAN) stays in pf, and a route change
tears down the flows that use the route;
- bridged traffic is offloaded only while pf filters neither the members nor
the bridge (`net.link.bridge.pfil_member` and `pfil_bridge` both 0);
- only offloaded states are made sloppy (no TCP window tracking). A state pf
deletes (close, timeout, `pfctl -k`) takes its hardware flow with it, and
if deletion events are ever lost, cmm drops every hardware flow
(`net.pfnotify.resyncs`).
Offloaded packets never reach the host, so whatever watches interfaces in
software misses them: Suricata (IDS and IPS), Insight/NetFlow, tcpdump.
Leave cmm off if forwarded traffic must pass through those. IPsec is not
offloaded (the vendor's IPsec offload was removed); it runs in FreeBSD's
stack, with CAAM through crypto(9).
After updating `mono-gateway` with cmm on, reboot: until then the new cmm
and the loaded `pf_notify.ko` differ, and cmm offloads nothing (it logs
"short pfnotify read").
The vendor's offload, which the security audit of 2026-11-22 found unsafe,
ignored route-to and reply-to, made every pf state sloppy, offloaded bridged
traffic past pf, could keep a hardware flow after its pf state was gone, and
panicked on decrypted IPsec packets. The rework was tested on a gateway on
2026-11-28; the results are in the merge commit (`git log --merges`).
## Stage, verify, publish
@ -596,9 +627,9 @@ reboot
the Wi-Fi card is fitted;
- System > Firmware > Status > Audit > Health is clean.
**10. Turn off hardware flow offload** (see "Hardware flow offload: off").
The vendor image's `/etc/rc.conf.local` enables cmm and no package manages
that file:
**10. Turn off hardware flow offload** for now (see "Hardware flow offload
(opt-in)" for turning it on later). The vendor image's `/etc/rc.conf.local`
enables cmm and no package manages that file:
```sh
sh