cmm put a next hop's MAC into CDX when it programmed the route and then only watched the next hop's address and interface. A next hop that changed its MAC (a new ISP modem, an IP reused by another LAN host) kept receiving its flows at the old MAC, possibly another host's, and new flows reused the stale route until cmm was restarted. Neighbors no route used also stayed cached as resolved, so a later route to the same IP got the old MAC without asking the kernel. cmm_neigh_check() now re-reads the ARP and NDP tables (one dump per family) and marks every cached neighbor whose MAC changed or is gone; cmm_route_check_neighbors() deregisters the routes using it and their offloaded flows, which re-offload once the next hop resolves again. It runs every maintenance cycle (30 s) and after route-socket changes, and cmm_route_handle_change() also treats a different MAC as a change. The last reference to a neighbor frees it. The link-layer table parser is shared by both lookups and bounds-checks each entry's length. pf_notify vetoes af-to (NAT64) states: their two keys are in different address families, which cmm cannot program. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
272 lines
11 KiB
Markdown
272 lines
11 KiB
Markdown
# Mono Gateway custom components for OPNsense
|
|
|
|
> This is the Karst Tech fork of
|
|
> [we-are-mono/opnsense-deps](https://github.com/we-are-mono/opnsense-deps).
|
|
> The vendor no longer maintains OPNsense for the gateway and its update
|
|
> mirror opnsense.mono.si is gone. This fork builds, signs and publishes the
|
|
> complete aarch64 OPNsense release (base, kernel, packages, image) at
|
|
> **https://opnsense.karsttech.com**. How that works, and how to build,
|
|
> publish and migrate a gateway, is in [RELEASE.md](RELEASE.md).
|
|
|
|
Out-of-tree kernel modules, userspace daemons, and build tooling for the Mono
|
|
Gateway OPNsense image. Contains the DPAA1 fast-path stack (CDX flow offload,
|
|
FCI, CMM connection manager, PF notifier, auto-bridge), board-support drivers
|
|
(LP5812 LED, EMC2302 fan, INA2xx power, SFP LED, PCF2131 RTC, TMP431 thermal,
|
|
CAAM crypto), WiFi support (NXP 88W9098 PCIe driver + DPAA OH port bridge),
|
|
FMan toolchain (fmlib, fmc, dpa_app), and helper scripts for kernel image
|
|
creation and deployment.
|
|
|
|
## Repository layout
|
|
|
|
```
|
|
opnsense-deps/
|
|
├── drivers/ # out-of-tree kernel modules
|
|
│ ├── caam/ # NXP CAAM crypto accelerator (JR + QI)
|
|
│ ├── dpaa_wifi/ # WiFi ↔ FMan OH port data plane bridge
|
|
│ ├── emc2302/ # SMSC EMC2302 fan controller
|
|
│ ├── fand/ # Fan control daemon (userspace)
|
|
│ ├── ina2xx/ # TI INA2xx power monitor
|
|
│ ├── lp5812/ # TI LP5812 LED controller
|
|
│ ├── mwifiex/ # NXP 88W9098 PCIe WiFi driver + firmware
|
|
│ ├── pcf2131/ # NXP PCF2131 RTC
|
|
│ ├── sfp-led/ # SFP+ link status LED
|
|
│ └── tmp431/ # TI TMP431 thermal sensor
|
|
├── fastpath/ # DPAA1 fast-path modules + userspace
|
|
│ ├── cdx/ # CDX flow offload kernel module
|
|
│ ├── fci/ # Fast-path Control Interface module
|
|
│ ├── auto_bridge/ # Auto-bridge kernel module
|
|
│ ├── pf_notify/ # PF state change notifier module
|
|
│ ├── fmlib/ # FMan userspace library
|
|
│ ├── fmc/ # FMan Configuration tool
|
|
│ ├── dpa_app/ # DPAA application (PCD setup)
|
|
│ ├── cmm/ # Connection Manager daemon
|
|
│ └── cmmctl/ # CMM control utility
|
|
├── config/ # FMC/CDX XML configuration files, GATEWAY device config
|
|
├── rc.d/ # rc.d service scripts and syshook scripts
|
|
├── pkg/ # FreeBSD package metadata
|
|
├── patches/<series>/ # opnsense/core patches (mirror, signing key, CMM restart)
|
|
├── keys/ # mirror public key and trusted/revoked fingerprints
|
|
├── release/ # build VM, release build, device migration (+ tests)
|
|
├── mirror/ # gwmirror.py stage/verify/publish, nginx container (+ tests)
|
|
├── mk-image.sh, tools/ # ZFS eMMC image builder used by the release build
|
|
├── _vendor/ # NXP vendor repos (cloned at build time, gitignored)
|
|
└── Makefile # top-level build (modules + userspace + package)
|
|
```
|
|
|
|
## Network interface mapping
|
|
|
|
The FMan MAC numbering in the device tree does not match the physical port order
|
|
on the board. This is a cosmetic mismatch in the PCB routing — it has no effect
|
|
on performance or functionality.
|
|
|
|
| Physical position (left → right) | Interface | Speed |
|
|
|----------------------------------|-----------|-------|
|
|
| Port 1 | dtsec1 | 1 GbE |
|
|
| Port 2 | dtsec2 | 1 GbE |
|
|
| Port 3 | dtsec0 | 1 GbE |
|
|
| Port 4 | dtsec3 | 10 GbE SFP+ |
|
|
| Port 5 | dtsec4 | 10 GbE SFP+ |
|
|
|
|
## Hardware flow offload (off by default)
|
|
|
|
The fast-path stack can forward established connections in FMan hardware
|
|
instead of through pf. It is only worth turning on for throughput pf cannot
|
|
reach in software, i.e. multi-gigabit traffic on the 10 GbE ports. Images
|
|
ship with it off (`cmm_enable="NO"` in `/etc/rc.conf.local`); the board
|
|
modules load either way.
|
|
|
|
Turn it on (the setting belongs in `/etc/rc.conf.local`, which overrides
|
|
`/etc/rc.conf`):
|
|
|
|
```sh
|
|
sh
|
|
sysrc -f /etc/rc.conf.local cmm_enable=YES
|
|
service cmm start
|
|
```
|
|
|
|
Turn it off:
|
|
|
|
```sh
|
|
sh
|
|
sysrc -f /etc/rc.conf.local cmm_enable=NO
|
|
service cmm onestop
|
|
```
|
|
|
|
pf still decides every connection: filtering, NAT, port forwards and routing
|
|
stay pf's, and killing a state removes its hardware flow. Flows whose rules
|
|
need pf for every packet (shaper, policy routing to another gateway, scrub,
|
|
MSS clamping, `log (all)`) stay in software. Caveats for offloaded flows:
|
|
|
|
- pf no longer checks their TCP sequence numbers (their states are sloppy).
|
|
- Suricata, Zenarmor, Insight/NetFlow and tcpdump see only their first
|
|
packets. Leave offload off if you rely on them.
|
|
- VLAN interface counters and per-rule counters miss hardware traffic
|
|
(physical port counters and per-state counters include it). Captive
|
|
portal accounting probably does too.
|
|
- When a next hop's MAC address changes (a new ISP modem, a LAN host with a
|
|
new NIC but the same IP), its offloaded flows can go to the old MAC for
|
|
up to 30 seconds, until cmm's next check of the ARP/NDP table.
|
|
- Not tested: IPv6, links with different MTUs (PPPoE, VPN), CARP/pfsync.
|
|
- After updating `mono-gateway`, reboot so the loaded `pf_notify.ko`
|
|
matches the new cmm; until then nothing is offloaded.
|
|
|
|
How cmm decides what to offload: [RELEASE.md](RELEASE.md), "Hardware flow
|
|
offload".
|
|
|
|
## Build instructions
|
|
|
|
The whole release, not just this package, has to be built for aarch64:
|
|
upstream OPNsense publishes no aarch64 packages at all. `release/build.sh`
|
|
drives [opnsense/tools](https://github.com/opnsense/tools) through base,
|
|
kernel, ports, plugins and core, builds the `mono-gateway` package from this
|
|
repository against the new kernel, signs everything and builds the eMMC image.
|
|
It runs on an aarch64 FreeBSD host of the series' release (15.1 for 26.7):
|
|
the emulated arm64 VM that `release/vm.sh` runs on a Linux
|
|
build host, or a native aarch64 machine. See [RELEASE.md](RELEASE.md).
|
|
|
|
To build only the board package on such a host after a release build:
|
|
|
|
```
|
|
sudo make -C /usr/deps -j$(sysctl -n hw.ncpu) package OPS_SETTINGS=26.7 OPS_VERSION=26.7.9
|
|
```
|
|
|
|
The first build clones the NXP vendor repositories (mwifiex driver source and
|
|
imx-firmware, mirrored on code.karsttech.com) into `_vendor/` at pinned
|
|
commits. Subsequent builds reuse the cached clones; remove `_vendor/` to
|
|
force a fresh clone.
|
|
|
|
## Development workflow
|
|
|
|
### Kernel source
|
|
|
|
The kernel source (`opnsense-src`) is a fork of OPNsense/FreeBSD at
|
|
[claude/opnsense-src](https://code.karsttech.com/claude/opnsense-src) (forked
|
|
from [we-are-mono/opnsense-src](https://github.com/we-are-mono/opnsense-src)).
|
|
Each `stable/<series>` branch is the upstream release tag plus the Mono
|
|
Gateway commits.
|
|
|
|
**Making a change:**
|
|
|
|
```bash
|
|
cd /usr/src
|
|
|
|
# See Mono Gateway commits on top of upstream (in a clone with the release tags)
|
|
git log --oneline 26.7.9..origin/stable/26.7
|
|
|
|
# 1. Edit the file
|
|
vim sys/contrib/device-tree/src/arm64/freescale/mono-gateway-dk.dts
|
|
|
|
# 2. Stage and commit
|
|
git add sys/contrib/device-tree/src/arm64/freescale/mono-gateway-dk.dts
|
|
git commit -m "dts: add PCIe WiFi reset GPIO"
|
|
|
|
# 3. Push
|
|
git push
|
|
```
|
|
|
|
To rebase on a newer upstream OPNsense release (here 26.7.9):
|
|
|
|
```bash
|
|
git remote add upstream https://github.com/opnsense/src.git
|
|
git fetch upstream tag 26.7.9
|
|
git rebase --onto 26.7.9 $(git merge-base HEAD upstream/stable/26.7) stable/26.7
|
|
git push --force-with-lease
|
|
```
|
|
|
|
### Out-of-tree modules
|
|
|
|
Drivers in `drivers/` build against kernel headers without modifying the kernel
|
|
source. To iterate on one:
|
|
|
|
```bash
|
|
# Rebuild just caam
|
|
sudo make -C /usr/deps build-caam
|
|
|
|
# Or rebuild all modules
|
|
sudo make -C /usr/deps -j24 modules
|
|
```
|
|
|
|
Output `.ko` files land in the driver directory and are collected into `dist/`
|
|
by `make all`.
|
|
|
|
## Local / Test Deployment
|
|
|
|
Flashing writes the image directly to the gateway's eMMC. The gateway must be
|
|
booted into Recovery Linux (initramfs) so the eMMC is not in use.
|
|
|
|
**Warning:** This overwrites the entire eMMC, including any existing OPNsense
|
|
installation and its configuration.
|
|
|
|
### 1. Boot into Recovery Linux
|
|
|
|
Power on the gateway and let U-Boot autoboot into Recovery Linux (or interrupt
|
|
U-Boot and run `run recovery`).
|
|
|
|
### 2. Configure networking on the gateway
|
|
|
|
Recovery Linux has no DHCP client. Assign a static IP on the uplink port
|
|
(adjust addresses to match your network):
|
|
|
|
```
|
|
ip link set eth3 up
|
|
ip addr add 10.0.0.69/24 dev eth3
|
|
ip route add default via 10.0.0.1 dev eth3
|
|
```
|
|
|
|
### 3. Serve the image from the build server
|
|
|
|
Signed images are published at
|
|
https://opnsense.karsttech.com/releases/<series>/ (check the `.sha256` file).
|
|
Recovery Linux is easiest served over plain HTTP from a machine on the same
|
|
network, e.g. in the directory holding the downloaded image:
|
|
|
|
```
|
|
python3 -m http.server 8000
|
|
```
|
|
|
|
### 4. Flash the eMMC
|
|
|
|
On the gateway, stream the compressed image directly to the eMMC. This
|
|
downloads, decompresses, and writes in a single pipeline — no local storage
|
|
needed (works even on devices with limited RAM):
|
|
|
|
```
|
|
curl http://[build-server]:8000/OPNsense-*-GATEWAY.img.gz | gunzip | dd of=/dev/mmcblk0 bs=1M
|
|
```
|
|
|
|
For an uncompressed image (slower transfer, no gunzip needed):
|
|
|
|
```
|
|
curl http://[build-server]:8000/OPNsense-*-GATEWAY.img | dd of=/dev/mmcblk0 bs=1M
|
|
```
|
|
|
|
### 5. Reboot
|
|
|
|
```
|
|
reboot
|
|
```
|
|
|
|
U-Boot will load `kernel.img` and the device tree from the FAT partition and
|
|
boot into OPNsense.
|
|
|
|
## Booting into OPNsense
|
|
|
|
The board's default boot command loads OpenWRT. To boot OPNsense instead,
|
|
interrupt U-Boot's autoboot (press any key during the countdown) and configure
|
|
a persistent `opnsense` boot environment:
|
|
|
|
```
|
|
=> setenv opnsense "load mmc 0:1 ${kernel_addr_r} kernel.img; load mmc 0:1 ${fdt_addr_r} dtb/mono-gateway-dk.dtb; booti 0x82000000 - 0x88000000"
|
|
=> setenv bootcmd_bak ${bootcmd}
|
|
=> setenv bootcmd "run opnsense || run recovery"
|
|
=> saveenv
|
|
=> reset
|
|
```
|
|
|
|
This saves the original boot command as `bootcmd_bak`, then sets `bootcmd` to
|
|
try OPNsense first and fall back to Recovery Linux if the kernel image is missing.
|
|
After `saveenv` and `reset`, the board will automatically boot into OPNsense on
|
|
every subsequent power-on.
|
|
|
|
> ## Disclaimer
|
|
> Many of the files in this repository, and in the [kernel fork](https://github.com/we-are-mono/opnsense-src), were ported from Linux sources provided by NXP (originally targeting Linux kernel 5.4). Due to the sheer scope of the porting effort, Claude Opus 4.6 was used to assist with the adaptation of this code to FreeBSD. As such, this project should be considered **highly experimental** and is **not fit for production use** until thorough reviews and testing have been performed by the wider community.
|