opnsense-deps/RELEASE.md
Jeremy Karst ae932c9c46 Offload: follow next-hop MAC changes; veto af-to
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>
2026-11-28 04:22:57 -05:00

767 lines
39 KiB
Markdown

# OPNsense releases and update mirror for the Mono Gateway
The Mono Gateway (NXP LS1046A) runs an OPNsense build by its vendor. Mono
stopped maintaining it, and its update mirror `opnsense.mono.si` went dark in
October 2026: the server still answers, but holds no TLS certificate, so every
update check fails with "SSL alert number 80". Upstream OPNsense publishes no
aarch64 builds at all, so nothing can be mirrored. Every release is therefore
built from source here, signed with our own key, and served from
**https://opnsense.karsttech.com**.
## Overview
```
code.karsttech.com/claude/{opnsense-src,opnsense-deps} github.com/opnsense/{tools,core,ports,plugins}
\ / (release tags)
release/build.sh in the build VM (FreeBSD arm64, emulated on the build host)
| unsigned sets -> sign (key in VM memory only) -> image
release/vm.sh pull-out -> /scratch/mono-opnsense/out/<series>/
|
mirror/gwmirror.py stage -> verify -> publish (rsync onto the SMB share)
|
nginx container (Portainer stack, share mounted read-only) <- Traefik/NPM (TLS) <- gateway
```
| Piece | Where |
|---|---|
| Kernel/base sources: upstream OPNsense src plus the vendor's 27 DPAA/LS1046A commits | `claude/opnsense-src`, branch `stable/<series>` |
| Board package, core patches, keys, all release tooling (this repository) | `claude/opnsense-deps` |
| NXP sources the board package builds from | `claude/mwifiex`, `claude/imx-firmware` (daily pull mirrors) |
| Build framework, core, ports, plugins | upstream GitHub, checked out at the release tag |
The build VM and Portainer clone every repository anonymously, so the four
`claude/` repositories must be public. That requires the `claude` account
itself to be public: Forgejo makes every repository of a limited or private
account "internal", readable by signed-in users only, whatever the
repository's own setting.
## What a gateway fetches
These are the paths opnsense-update and core's firmware scripts request,
under the URL in `/usr/local/etc/pkg/repos/OPNsense.conf`:
```
/FreeBSD:14:aarch64/26.1/latest/ pkg repository (meta.conf, packagesite.*, data.*, All/, Latest/)
/FreeBSD:14:aarch64/26.1/aux/ build-only packages (repository disabled by default)
/FreeBSD:14:aarch64/26.1/MINT/<ver>/latest/ snapshot per release, for opnsense-revert -r
/FreeBSD:14:aarch64/26.1/sets/
base-<ver>-aarch64.txz(.sig) no device suffix: clients fetch it without
kernel-<ver>-aarch64-GATEWAY.txz(.sig) suffix from kern.ident "MONO-GATEWAY"
changelog.txz(.sig), bogons.txz(.sig) proxied by nginx from pkg.opnsense.org (see below)
{packages,base,kernel}-<next>-aarch64* major upgrade sets for the next series
/FreeBSD:15:aarch64/26.7/... the same for 26.7 (FreeBSD 15)
/releases/<series>/OPNsense-<ver>-arm-aarch64-GATEWAY.img.gz(.sig,.sha256) eMMC image
/healthz
```
- The base/kernel release a gateway wants is the version of the
`opnsense-update` package in the repository, so the sets are built with
`VERSION=<release>` and named exactly after it.
- Core reads the changelog and bogons URL from `OPNsense.conf.sample` (the
build-time package site), not from the live file.
- changelog.txz and bogons.txz don't depend on the architecture. Upstream
signs them with the key core already trusts (pkg.opnsense.org.20260120
for 26.1, .20260608 for 26.7). The container therefore proxies them live
from upstream's amd64 tree of the same FreeBSD major and series, which
keeps the bogons current with no scheduled job.
- The board package `mono-gateway` lives in the main OPNsense repository
(the vendor had a separate `MonoGateway` one). During a major upgrade,
`opnsense-update -P` upgrades only the OPNsense repository. The board's
kernel modules must cross the ABI change with it.
### Names on disk
The mirror is stored on an SMB share, which keeps names the Windows way. On
ours (checked 2026-11-18):
- `:` is refused (`NT_STATUS_OBJECT_NAME_INVALID`);
- names are case-insensitive (`case.txt` replaces `Case.txt`);
- device names such as `aux` and `con` are stored but listed under a mangled
8.3 name (`AHY9U3~9`), so rsync would copy them again and then delete the
"unknown" mangled entry, which is the real directory. A file stored that way
cannot even be deleted over SMB.
So two components of the paths above have other names on disk, in the staged
tree and on the share alike:
| URL path | On disk |
|---|---|
| `/FreeBSD:<N>:aarch64/` | `FreeBSD_<N>_aarch64/` |
| `/FreeBSD:<N>:aarch64/<series>/aux/` | `FreeBSD_<N>_aarch64/<series>/aux-repo/` |
The nginx container rewrites the URLs onto them; `gwmirror.py` reads and
writes through the same mapping (`disk_rel`). Every other name is stored as
it is, and `verify --root` (so also `publish`) fails on any name the share
cannot hold: reserved characters, device names, a trailing dot or space, or
two names in a directory that differ only in case.
## Signing keys and trust
- **Private key:** `~/.config/gwmirror/repo.key` on the workstation (RSA
4096, mode 0600). It is never stored in git, in `/scratch`, on the share or
on a VM disk. `vm.sh sign` copies it over ssh, through the build host, into
a memory file system in the build VM and removes it when signing ends.
**Keep an offline backup:** anyone holding it can install code as root on
the gateway.
- **Public key:** `keys/opnsense.karsttech.com.20261117.pub`.
- **Fingerprint:** `sha256(repo.pub)` =
`5fc1e2bf74e0386a2ea1ee60d085d683735a9d7cd8090647be0f476c779c0dc3`, shipped
by our core package as
`/usr/local/etc/pkg/fingerprints/OPNsense/trusted/opnsense.karsttech.com.20261117`.
- **Vendor keys:** `opnsense.mono.si.20260305` and `.20260716` are revoked
by our core.
- **What gets signed:** every `.sig` holds the RSA-SHA256 signature over the
hex sha256 of its file, plus the public key (`SIGNATURE`/`CERT`/`END`). This
covers sets, `Latest/*.pkg` and the image. The repository catalogues carry
the same signature inside `packagesite.pkg` and `data.pkg`.
- **Where trust is configured:** `keys/fingerprints/` (ours: trusted and
revoked) and `keys/upstream/` (for changelog/bogons). `gwmirror.py` and
`build.sh finish` both use them. finish refuses any key that is not trusted
there.
- **Rotating the key:**
1. Add the new fingerprint to `trusted/` in the core patch and in
`keys/fingerprints/`.
2. Publish one release signed with the old key that ships the new
fingerprint.
3. Then switch keys and move the old fingerprint to `revoked/`.
## Building a release
### Build host
Builds run natively in a FreeBSD arm64 VM that QEMU emulates (TCG) inside a
rootless podman container on a build host, named by `GW_VMHOST` (ours: a
16-core Ryzen AI Max+ 395 running Bazzite). The build host needs podman, curl,
sha256sum and xz, and no root. `release/vm.sh` runs `release/vmhost.sh`
there over ssh; that script builds the container image (QEMU and the arm64
UEFI firmware, from Debian) on first use and keeps the VM's files in
`~/gwbuild-vm/<osrel>`. The VM's ssh port listens on the build host's
loopback only, and vm.sh reaches it through the build host (ProxyJump).
Why emulated, not cross-built: on 2026-11-18 an amd64 VM cross-built base,
kernel and xtools in 64 minutes, but tools builds ports in an aarch64 chroot
under qemu's user-mode emulation, and no qemu-user-static available for
FreeBSD 14 can run cargo there (3.1.0 jumps into unmapped memory; 6.2.50
cannot start FreeBSD 14 programs at all). Every Rust port, py-cryptography
included, failed. Full-system emulation runs a real FreeBSD kernel: slow
(roughly a tenth of native speed), but faithful.
The VM's FreeBSD release must match the series: 15.1 for 26.7 (`OS` in
tools' `config/<series>/build.conf`). A native aarch64 FreeBSD
machine works with the same `build.sh` and no changes.
```sh
# ~/.config/gwmirror/vm.conf, sourced by vm.sh
GW_VMHOST=buildhost # ~/.ssh/config alias of the build host
GW_VM_CPUS=24
GW_VM_MEM=12G # the HTPC's other work needs most of its memory; see Memory below
release/vm.sh create 15.1 # on the build host: official image, checksum verified, grown to 100G
release/vm.sh start 15.1 # first boot applies freebsd-update patches: an hour or more emulated
release/vm.sh setup 15.1 # build.sh setup: host packages, ZFS settings, swap
release/vm.sh sync 15.1 # this repository (with .git) -> /usr/deps
```
- **Image:** the checksums come from download.freebsd.org or, for an old
release, archive.freebsd.org; the image itself from the first of those or
a mirror that has it (archive.freebsd.org at times stops sending).
Stalled transfers are resumed.
- **Disk:** ZFS with zstd compression and autotrim, in a qcow2 file with
copy-on-write disabled (the HTPC's home is btrfs).
- **Setup:** `setup` installs git, python3 and rsync from the frozen package
set of exactly that FreeBSD release.
- **Memory:** the build host backs every page of the VM's memory. On
2026-11-20 a 16 GB VM (18 GB in qemu, 7 GB of it ZFS cache) and the
HTPC's other work ran it out of memory, and it had to be rebooted. So
`setup` caps the VM's ZFS cache at 2 GB, and the VM swaps to a disk of
its own (`swap.qcow2`, `GW_VM_SWAP`, default 16G, serial `gwswap`):
not on ZFS, where swap can deadlock when memory runs out, and past the
host's page cache (`cache=none`). Builds that need more than the VM has
(Rust, LLVM) swap inside the VM instead of pressing on the host.
FreeBSD kills a process that has waited 30 seconds for a free page, and
the emulated VM's pageout can take that long: later that day the Rust
build lost two `llvm-tblgen` that way, 2.8 hours in, with the swap
unused. `setup` turns those kills off (`vm.pfault_oom_attempts=-1`).
On every build host, `build` caps `lang/rust`, which builds its own LLVM
with a job per CPU, at one job per 768 MB of memory (15 in the 12 GB VM,
where 24 did not fit), through tools' `make.conf`.
- **Restarts:** the VM does not start with the build host. After a reboot,
`vm.sh start` it and run `build` again: finished sets are reused. The
ports step writes its set only when it ends (below); `build` first adds
the packages an interrupted step had finished.
### Build, sign, collect
Commit your changes first: `build` refuses a dirty `/usr/deps` unless
`ALLOW_DIRTY=1`.
```sh
release/vm.sh sync 15.1
release/vm.sh run 15.1 build 26.7 26.7.9 # detached; vm.sh log 15.1 to follow
release/vm.sh sign 15.1 26.7 26.7.9 # key into a tmpfs in the VM, finish, key unmounted
release/vm.sh pull-out 15.1 26.7 # -> /scratch/mono-opnsense/out/26.7/{sets,images}
```
**`build`:**
1. Checks out each repository at the release tag, on the branch names tools
insists on. Override per repository with `TOOLS_REF`, `CORE_REF`,
`PORTS_REF`, `PLUGINS_REF` or `SRC_REF` when upstream skipped a tag.
Src is fetched shallow (its single commit, no tags): the build never needs
its history, which is most of its 2 GB. Git never prompts for credentials,
and a transfer that moves nothing for 10 minutes fails the build instead
of hanging. Each checkout must then be at the commit
`config/lock-<version>` gives it (`tools`, `src`, `ports`, `plugins`,
`core`, before our patches): a tag that moved upstream, or a src branch
that moved on, stops the build. Tags are fetched without `--force`, so a
moved tag already fails the fetch. `build.sh lock SERIES VERSION`
resolves the refs and writes the commits to `/root/gwlock-<version>` in
the VM; check them against the upstream tags (`git ls-remote`), then
commit them as `config/lock-<version>`.
2. Applies `patches/<series>/*.patch` to core with `git am`. Core's version
becomes `<release>_<patches>`.
3. Builds base and kernel, then this repository's kernel modules, as an
early check against the new kernel. The kernel set must contain
`boot/kernel/kernel.bin`, the image U-Boot boots: the eMMC image needs
it, and on the gateway `20-kernel-update` skips a kernel set without
one, so the old kernel would go on booting.
4. Builds the ports in one tools ports step over the whole list, tools'
`ports.conf`. Tools caches the build-only dependencies it builds (cmake,
autoconf, the Rust and Go compilers) for the rest of a step only, and the
packages set keeps just the listed ports and their runtime dependencies.
Splitting the list into several steps would rebuild those dependencies in
each one. That cost was measured: a second chunk of 20 started by
rebuilding the autotools the first chunk had already built. The set is
written when the step ends. A reboot of the build host during it leaves
the finished packages only in tools' stage, which the next step clears,
so `build` first adds them to the set: the runtime packages tools had
copied to the stage's packages directory, if the stage belongs to the
same build (series, version and ports commit, kept in
`/var/tmp/gwbuild-ports.run`) and each is a whole package archive. The
build-only dependencies are not kept and get rebuilt. A port that
fails is recorded and the step goes on with the others, then fails at the
end. Tools stops at the first failure only when its step is given an
argument, and `build` gives none. Once the failures are fixed, run `build`
again. Finished sets are reused, and the ports step skips every package
it has built. It does rebuild the build-only dependencies of the ports it
still has to build.
- After each port, tools ran `make clean` to remove its work directories
and its dependencies'. That clean runs each dependency's clean with the
port's own flavor, so a dependency with another flavor, or with none,
looks for the wrong `work-<flavor>` and keeps its work directory.
After a failure, tools removes the dependencies it built. A stale
directory then claims they are installed, so every later port that
needs them fails at once. On 2026-11-20 that happened to Rust ("Couldn't
find required command: cmake") and to libxslt ("libxslt.so - not
found").
- So `build` changes tools' `ports.sh` at checkout: after each port it
removes every work directory (`rm -rf /usr/obj/usr/ports`) instead of
cleaning. The build stops if tools' `ports.sh` no longer has the two
cleans it replaces.
- `config/make-<series>.conf` is added to tools' `make.conf`. Some ports
still download code while they build, at its newest version, and
upstream built them when the release was tagged. It pins
`www/caddy-custom`'s plugins, which xcaddy fetches, at their versions
of the release's tag date: on 2026-11-22 the newest `caddy-l4` needed
a newer Caddy than 26.1's ports tree had, and the port failed. For a
new series or release, pin them
at the release's tag date (`proxy.golang.org/<module>/@v/list` and
`.info`; a module without tags takes the pseudo-version of its last
commit before then).
5. The ports fetch their distfiles as they build. Some no longer download as
recorded in the ports tree's distinfo, chiefly patches GitHub generates
on the fly (`github.com/<owner>/<repo>/commit/<hash>.patch`): GitHub
abbreviates the object names on their `index` lines with more digits as
a repository grows, so an old patch now differs by a few bytes. Codeberg
tag archives (`codeberg.org/<owner>/<repo>/archive/<tag>.tar.gz`) changed
too: Codeberg now compresses them with GNU gzip instead of git's own, and
the same tar comes out smaller. FreeBSD's distfile cache does not help
here. It keeps the originals only of FreeBSD's own ports, so it has
nothing for OPNsense's (e.g. the patches of `opnsense/pkg`). For
`sysutils/sysinfo` it served the new archive as well (2026-11-22).
- Such ports are fetched on the build host with
`release/fetch-distfile.sh`. For a GitHub patch, it shortens the
abbreviations until the size matches distinfo. GitHub turns automated
requests away now and then ("Service Unavailable"), so the current
patch is tried three times, a minute apart. For a Codeberg archive, it
clones the tag and makes the archive with `git archive --format=tar.gz
-6`. Either way, the port's `checksum` target then verifies the
SHA256, so only the original bytes are accepted. The results are
appended to the distfiles set, which
tools extracts into every ports step's chroot. A port whose distfiles
the set has already is skipped, so a rerun downloads nothing for it.
- `opnsense/pkg` (tools' `PKG_ORIGIN`, not `ports-mgmt/pkg`) is fetched
this way first: the ports step's chroot builds pkg before anything
else, and tools needs the same pkg version on the build host
(`pkg -v`), so `build` builds it there too when the version differs
(`vm.sh setup` installs FreeBSD's). Both take its
distfiles from the set, not from GitHub, which turned its patches
away for minutes at a time on 2026-11-20.
- Any other port whose distfiles fail to fetch ("Couldn't fetch it" in
the step's output, `/var/tmp/gwbuild-ports.log`) is fetched this way
and the ports step runs once more. It skips the packages it has
already built, but rebuilds the build-only dependencies of the ports
it still has to build. A distfile that still cannot be fetched
stops the build with the port's name.
- Tools' own `distfiles` step, which would fetch every distfile up front
for offline rebuilds, is not run. It walks the whole dependency tree of
every port again, one `make` at a time: 70 of 266 ports in 9 hours
under emulation. For flavored ports it walks the default flavor's tree
(QEMU's desktop dependencies for `qemu@guestagent`) and fails on a port
the build never needs. Also, its fetch loop records failures at a path
outside its chroot, so the first failure ends the loop.
6. Builds plugins, core and the packages set.
7. Builds the board package against the base set's headers and our libxml2,
and puts it into the packages set.
**`finish`:**
1. Checks the key against `keys/fingerprints/trusted`.
2. Signs base, kernel, packages and aux. Signing the packages set regenerates
the catalogue, so it includes `mono-gateway`. Tools does not do the same
for the aux set: it signs the aux catalogue only in a packages step run
with the key. So `finish` first unpacks the aux set, signs its catalogue
with `pkg repo` and repacks it. `gwmirror verify` found the aux catalogue
unsigned on 2026-11-22.
3. Builds the 5 GB ZFS eMMC image (`mk-image.sh`).
4. Imports the image's pool read-only, without mounting it, and mounts each
dataset read-only by itself. Mounting them all at import does not work:
the pool's own dataset needs a mountpoint inside the read-only root, and
the import then leaves nothing mounted (2026-11-22). Fails if any
non-aarch64 ELF file is found (firmware blobs aside), if a dataset cannot
be mounted, or if the root dataset has no `/bin/sh`, so an empty scan
cannot pass.
5. Compresses and signs the image.
### Board package version
`mono-gateway` is versioned `<release>_<commit count of this repository>`,
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 by default)
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. It is only needed for
multi-gigabit throughput on the 10 GbE ports, so images set
`cmm_enable="NO"` (`rc.d/rc.conf.local`): the board modules load, but
nothing is offloaded until cmm is turned on. Turning it on and off, and its
caveats for users, are in README.md ("Hardware flow offload").
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, af-to
(NAT64);
- 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 software that watches
interfaces (Suricata, Zenarmor, Insight/NetFlow, tcpdump) misses them, and
so do counters kept in software (VLAN interfaces, pf rules); physical ports
count in hardware, and cmm copies the hardware's counts into pf's states.
IPsec is not offloaded (the vendor's IPsec offload was removed); it runs in
FreeBSD's stack, with CAAM through crypto(9).
A next hop's MAC address goes into CDX when its route is programmed. Every
30 seconds, and after route-socket changes, cmm re-reads the ARP and NDP
tables and tears down routes whose next hop moved to another MAC or left
the table (`cmm_neigh_check()`, `cmm_route_check_neighbors()`): its IP may
belong to another host by then. Neighbors no route uses are not cached.
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
```sh
M=/scratch/mono-opnsense/mirror
python3 mirror/gwmirror.py stage --sets /scratch/mono-opnsense/out/26.7 --mirror $M --series 26.7 --version 26.7.9 --upgrade-from 26.1
python3 mirror/gwmirror.py verify --root $M # deep: hashes, signatures, ELF architecture
python3 mirror/gwmirror.py publish --mirror $M --dest /mnt/opnsense-mirror # re-verifies first
python3 mirror/gwmirror.py verify --url https://opnsense.karsttech.com --series FreeBSD:14:aarch64/26.1 --series FreeBSD:15:aarch64/26.7
```
**`stage`** lays one build into the tree above:
- renames the base set;
- extracts the packages and aux sets, skipping tools' dotfile build markers;
- hard-links a MINT snapshot;
- copies the image;
- with `--upgrade-from <series>`, also places this build's sets in that
series' `sets/` as its major upgrade.
**`verify --root`** checks, for each `<ABI>/<series>`:
- the catalogue signatures, and that both catalogues agree;
- every package's path, ABI, size and checksum, and in the main repository
its `Latest/` signature (tools makes `Latest/` for the main repository
only; upstream's aux repository has none either). The catalogue's
checksum is the file's SHA-256 in hex up to pkg 2.3 (26.1), and from
pkg 2.8 (26.7) `2$` and its BLAKE2b-512 in pkg's own base32.
`Latest/` signatures are over the SHA-256 either way, so with a BLAKE2b
catalogue a shallow verify (`--url` without `--deep`) checks only that
they come from a trusted key, as it does for the sets;
- the major upgrade's packages set in the previous series' `sets/`, read
in place as the repository `opnsense-update -P` installs from;
- the set and image signatures against `keys/fingerprints`;
- that every ELF inside every package and set is aarch64. Firmware
directories are excepted, and so is the Go toolchain's source tree
(`/usr/local/go<N>/src/`, in the aux repository), which ships test data
and race-detector objects for every platform.
- that every name can be stored on the SMB share (see "Names on disk");
- that no symlink leads outside the tree or nowhere: `publish` copies with
`rsync -L`, which would publish a link's target.
Nothing is extracted to disk while verifying.
**`verify --url`** also checks:
- the TLS certificate (it must have 21+ days left);
- `/healthz`;
- Content-Length on the sets;
- that no redirect leads elsewhere;
- the proxied changelog/bogons signatures against `keys/upstream`.
`--url` is shallow by default (sizes and signatures, no downloads beyond the
catalogues). `--deep` downloads and hashes everything.
**`publish`** first refuses to delete a series. If the destination has a
directory in its top two levels (`FreeBSD_14_aarch64`,
`FreeBSD_14_aarch64/26.1`, `releases/26.1`) that the staged tree lacks, it
stops before verifying. A series is retired by deleting it from the share by
hand. `publish` then refuses to copy a tree that fails verification, and runs
`rsync -rtL --delay-updates --delete-after`: symlinks become plain files
(SMB keeps none), and clients never see a half-written repository.
The share is mounted on the workstation with the kernel CIFS client (as
root, once; `cifs-utils` installed), owned by the workstation user so rsync
needs no privileges:
```
# /etc/fstab
//<server>/<share>/<folder> /mnt/opnsense-mirror cifs credentials=/home/<user>/.config/gwmirror/smb-credentials,uid=<user>,gid=<user>,vers=3.0,nofail,_netdev 0 0
```
`~/.config/gwmirror/smb-credentials` (mode 0600) holds `username=` and
`password=` lines. The tree goes into a folder of the share (ours: `mirror/`),
and nothing else may live in that folder: `--delete-after` removes it. The
container's `SMB_SHARE` names the same folder (`<share>/mirror`).
### Restoring the staged mirror
The staged tree in `/scratch` is a working copy, and the share holds the
only copy of series that are no longer built (26.1 since 2026-11-28). If
`/scratch` is lost, copy the share back, then re-stage the current build so
its symlinks and hard links return (the rest stays as plain copies, which
verify the same way):
```sh
M=/scratch/mono-opnsense/mirror
mkdir -p $M && rsync -rt /mnt/opnsense-mirror/ $M/
release/vm.sh pull-out 15.1 26.7
python3 mirror/gwmirror.py stage --sets /scratch/mono-opnsense/out/26.7 --mirror $M --series 26.7 --version 26.7.9 --upgrade-from 26.1
python3 mirror/gwmirror.py verify --root $M
rsync -rL -n -i -c --delete-after --exclude='.*' $M/ /mnt/opnsense-mirror/ # prints nothing: publish would change no content
```
## Serving the mirror
`mirror/server/` holds the stack:
- an unprivileged nginx on a read-only root;
- the URL-to-disk name rewrites (see "Names on disk");
- GET/HEAD only, dotfiles hidden, autoindex on;
- the changelog/bogons proxy;
- `/healthz`.
Deploy it as a Portainer stack from this repository (compose path
`mirror/server/docker-compose.yml`), with the SMB share settings as stack
variables. The header of the compose file lists the variables, the
reverse-proxy requirements and the DOCKER-USER rule.
The gateway itself must reach the proxy. If `opnsense.karsttech.com`
resolves to the gateway's own WAN address, add an Unbound host override that
points it at the proxy's LAN IP.
To test locally with podman, serving a staged tree:
```sh
podman build -t opnsense-mirror:local mirror/server
podman run -d --rm --name gwmirror -p 127.0.0.1:18080:8080 -v $M:/srv/mirror:ro \
--read-only --tmpfs /tmp --cap-drop ALL --security-opt no-new-privileges opnsense-mirror:local
python3 mirror/gwmirror.py verify --url http://127.0.0.1:18080 --allow-http --series FreeBSD:14:aarch64/26.1
```
## Migrating a gateway from opnsense.mono.si
Shell commands, run on the gateway over ssh as root. Root's shell there is
csh, which does not take `#` comments typed at the prompt: start `sh` first.
ApolloGuardian was migrated this way on 2026-11-23.
**Before you start:**
- Download a configuration backup (System > Configuration > Backups).
- Have the serial console (115200 baud), or Recovery Linux and the image in
`releases/26.1/`, at hand for the first kernel update.
- `opnsense.karsttech.com` resolves to the public address, which is the
gateway's own WAN address: without an Unbound host override to the
proxy's LAN IP, the gateway connects to its own web GUI. With the
override, the URL depends on the proxy's LAN port (step 4).
**1. Checks.** `opnsense-verify -a` must print `FreeBSD:14:aarch64`,
`opnsense-version -a` `26.1`, and the fetches `ok` and `repo-ok` (add the
proxy's port to the URLs if it is not 443 inside the LAN):
```sh
sh
opnsense-verify -a
opnsense-version -a
fetch -qo - https://opnsense.karsttech.com/healthz
fetch -qo /dev/null https://opnsense.karsttech.com/FreeBSD:14:aarch64/26.1/latest/meta.conf && echo repo-ok
```
**2. Backup and boot environment:**
```sh
B=/root/gwmirror-backup-$(date +%Y%m%d%H%M%S)
mkdir -p $B
cp -p /usr/local/etc/pkg/repos/* $B/
bectl create pre-gwmirror
```
**3. Trust the signing key** (keys/fingerprints/trusted):
```sh
printf 'function: "sha256"\nfingerprint: "5fc1e2bf74e0386a2ea1ee60d085d683735a9d7cd8090647be0f476c779c0dc3"\n' > /usr/local/etc/pkg/fingerprints/OPNsense/trusted/opnsense.karsttech.com.20261117
```
**4. Point the repositories at the mirror.** If the proxy answers on 443
inside the LAN, rewrite the URLs in the repository files and their
`.sample` files (`${ABI}` stays literal):
```sh
cd /usr/local/etc/pkg/repos
for f in OPNsense.conf.sample OPNsense-aux.conf.sample OPNsense.conf OPNsense-aux.conf; do
[ -f $f ] && sed -i '' 's|^\([[:space:]]*url:[[:space:]]*"\)[^"]*\(/${ABI}/\)|\1https://opnsense.karsttech.com\2|' $f
done
cd
```
If the gateway reaches the proxy only on another port (at home Traefik
listens on 444 and the router forwards WAN 443 to it; pf cannot redirect
connections the firewall makes itself), set a custom mirror instead. It is
kept in `config.xml`, and core applies it at every firmware reload
(`opnsense-update -sd -m`), so it survives core updates. The GUI (System >
Firmware > Settings, Mirror "(custom)") did not store it on the vendor's
26.1.9; this did, keeping the previous version in System > Configuration >
History:
```sh
/usr/local/bin/php -r 'require_once("config.inc"); require_once("util.inc"); global $config; $config["system"]["firmware"]["mirror"] = "https://opnsense.karsttech.com:444"; write_config("custom mirror opnsense.karsttech.com:444");'
pluginctl -g system.firmware.mirror
```
The changelog and bogons downloads do not follow a custom mirror:
`opnsense-update -X` reads core's `OPNsense.conf.sample`, which names the
mirror without a port. On such a gateway the GUI changelog does not load
and the bogons list keeps the version it has. Serving the proxy on 443
inside the LAN avoids both.
**5. Drop the vendor's MonoGateway repository** and move `mono-gateway` to
the OPNsense repository (`opnsense-update -P` of a major upgrade only
upgrades that one):
```sh
rm -f /usr/local/etc/pkg/repos/MonoGateway.conf
pkg info -e mono-gateway && pkg annotate -qyM mono-gateway repository OPNsense
```
**6. Reload and check.** `opnsense-update -M` must name the new mirror, and
`pkg update -f` must accept the catalogue ("804 packages processed"; it
fails on a key that is not trusted):
```sh
configctl firmware reload
opnsense-update -M
grep -H url: /usr/local/etc/pkg/repos/OPNsense*.conf
pkg update -f
```
To undo before step 7: `cp -p $B/* /usr/local/etc/pkg/repos/`, remove the
fingerprint file (and the custom mirror, in System > Configuration >
History), `configctl firmware reload`. After step 7: `bectl activate
pre-gwmirror` and reboot.
**7. Update** in System > Firmware > Updates: Check for updates, then
update. This installs our core `26.1.11_2`, then the packages, base and
kernel, and reboots. That core names only our mirror and revokes the
vendor's keys. Besides ours it still trusts upstream's key
(`pkg.opnsense.org.20260120`; `.20260608` in 26.7), which signs the
changelog and bogons sets the mirror passes through from upstream.
**8. Reinstall everything once**, so no vendor-built binary remains, then
reboot:
```sh
sh
opnsense-update -pf
opnsense-update -bkf
reboot
```
**9. Check:**
- `opnsense-version` shows the release, `uname -v` our src fork's commit and
`MONO-GATEWAY`;
- `kldstat` lists cdx, fci and the other board modules (`ina2xx` is built
into the kernel: `kldstat -v | grep ina`), and mwifiex and dpaa_wifi when
the Wi-Fi card is fitted;
- System > Firmware > Status > Audit > Health is clean.
**10. Turn off hardware flow offload** (see "Hardware flow offload (off by
default)"; README.md has how to turn it on later). The vendor image's `/etc/rc.conf.local`
enables cmm and no package manages that file:
```sh
sh
sysrc -f /etc/rc.conf.local cmm_enable=NO
service cmm onestop
pgrep -l cmm || echo cmm-stopped
```
## Major upgrade (26.1 to 26.7)
1. **Kernel fork:** rebase `stable/26.7` of the src fork onto the 26.7.x tag
(see README.md). For 26.7.9 (2026-11-23), Mono's 27 commits on 26.7
rebased onto the tag without conflicts; Mono's tip is tagged
`mono/stable/26.7`. One of them was broken on Mono's 26.7 branch:
"pf: add state creation/destruction notification hooks" also replaced
parts of `pf.c` with older 14.x code (`s->rule.ptr`, the former SCTP and
ICMP cases), which does not compile. It was rebuilt from its 26.1
version: the hook call after each pfsync insert, update and delete call
(five in 26.7's single `pf_test`) and the declarations. To spot such a
commit, compare each commit's insertions and deletions with its 26.1
counterpart (`git show --numstat`); the others matched. FreeBSD 15 also
removed `GEOM_BDE`, so a commit on top drops it from the `GATEWAY` kernel
config. Before building, check the config's options against the new tree:
`config -d /tmp/x GATEWAY` in `sys/arm64/conf` stops at the first unknown
one. A second commit fixes three FreeBSD 15 compile errors in Mono's
code: two `machdep.c` lines that 26.7 no longer needs (upstream defines
`socdev_va` itself and dropped `hcr_el2`), the moved `dev/clk/clk.h`, and
`cpu_dcache_wbinv_range()` now taking a pointer. To find every compile
error in one pass rather than one per build, run tools' `buildkernel`
by hand in the VM with `make -k ... KERNFAST=1` after a failure. A third
commit sets `makeoptions WITH_KERNEL_BIN=t`: FreeBSD 15 builds
`kernel.bin` only when asked, and the 26.7.9 image build was the first
to notice. To rebuild just the kernel set after such a change, remove
it from the VM's `sets/` and run tools' `kernel` step, then `sign`
again.
2. **Core patches:** write `patches/26.7/` against core 26.7.x. For 26.7.9:
- the CMM restart moved from `interfaces_assign.php`, which 26.7 no
longer has, to the MVC assignment API
(`Interfaces/Api/AssignmentController::reconfigureAction`, after its
filter reload);
- the mirror patch applied as is, except for the `plist` lines, where
upstream's trusted key changed (`pkg.opnsense.org.20260608`).
- Also pin `www/caddy-custom`'s plugins at the release's tag date in
`config/make-26.7.conf` (build step 4).
3. **Board package:** fix this repository's drivers for the FreeBSD 15 kernel
interfaces. `build` compiles the modules right after the kernel, so this
fails early. For 26.7: caam's bus resource methods lost their `type`
and `rid` arguments, and `sys/cdefs.h` now defines `__maybe_unused`,
which cdx's `linux_compat.h` also did. The repository then stopped
building 26.1 (its patches and `make-26.1.conf` are gone); the 26.1
tree on the mirror stays, for gateways that still have to upgrade.
4. **Build:** run `vm.sh create 15.1`, then `build 26.7 26.7.x`, `sign` and
`pull-out`.
5. **Stage, verify, publish:**
`gwmirror.py stage ... --series 26.7 --version 26.7.x --upgrade-from 26.1`,
then verify and publish.
6. **Back up:** full eMMC backup from Recovery Linux, or at least a
configuration backup, with the 26.1 image at hand.
7. **Offer the upgrade** on the gateway. Core only offers it once
`packages-26.7.x` is on the mirror (checked in core 26.1.11's check.sh);
`opnsense-update -SRp` prints its size once it is:
```sh
sh
sed -i '' '/^UPGRADE_RELEASE=/d' /usr/local/etc/opnsense-update.conf
echo 'UPGRADE_RELEASE="26.7.x"' >> /usr/local/etc/opnsense-update.conf
opnsense-update -SRp
```
8. **Upgrade in the GUI.** It reboots three times: kernel, then base, then
packages.
- Until the packages stage, the 26.1 board modules don't load under the
26.7 kernel. `01-mono-modules` logs them and carries on, and the
in-kernel DPAA driver keeps the network up.
- At that last stage, the FreeBSD 15 `mono-gateway` package arrives.
## Ongoing releases
- **Point release** (e.g. 26.7.10):
1. Rebase the src fork onto the new tag.
2. Run `build.sh lock` in the VM, check the commits and commit
`config/lock-<version>` (build step 1).
3. Run `build` / `sign` / `pull-out`; tools skips unchanged ports.
4. Run `stage`, `verify`, `publish`.
- **Major release** (27.1 is due January 2027): the procedure above.
- **Board fix between releases:** commit here, then rebuild. The package
version rises with the commit count.
- **Kernel-only fix between releases:** push it to the src fork, update `src`
in `config/lock-<version>`, delete the kernel set in the VM and rebuild,
then republish the same-version kernel set; gateways pick it up with
`opnsense-update -fk`.
## Monitoring
`mirror/monitor/` has a systemd user timer that runs
`gwmirror.py verify --url` daily (install steps in the unit file). Its
failures land in the journal. That is the failure that killed the vendor's
mirror: the certificate is due to be renewed by the proxy, and the timer
complains 21 days before expiry if it isn't.
## Recovery
The kernel is booted by U-Boot from the FAT partition, not from
`/boot/kernel`. After a kernel set update, `rc.syshook.d/stop/20-kernel-update`
installs the new kernel there at shutdown. It keeps the previous one as
`kernel.old`, never leaves `kernel.img` missing, and retries at the next
shutdown if it can't finish. `/boot/kernel/kernel.bin` stays where the kernel
set put it, so the health audit finds the set complete; a shutdown whose
kernel and device tree are on the FAT partition already does nothing. (Up to
`mono-gateway` 26.7.9_116 the hook deleted it, and the audit reported it
missing; `opnsense-update -fk` puts it back.)
If a new kernel doesn't boot, interrupt U-Boot on the serial console:
```
=> load mmc 0:1 ${kernel_addr_r} kernel.old; load mmc 0:1 ${fdt_addr_r} dtb/mono-gateway-dk.old; booti 0x82000000 - 0x88000000
```
Then roll back the boot environment (`bectl activate pre-gwmirror-...`), or
reflash from Recovery Linux with the signed image from `/releases/` (README.md,
"Local / Test Deployment") and restore the configuration backup.
## Tests
```sh
python3 -m unittest discover -s mirror/tests # gwmirror stage/verify/publish, incl. HTTPS
python3 -m unittest discover -s release/tests # build.sh, 20-kernel-update, fetch-distfile.sh
release/vm.sh ssh 15.1 'cd /usr/deps && python3 -m unittest discover -s release/tests'
```
Run `release/tests` on the build VM as well (after `vm.sh sync`): those
scripts run on FreeBSD, whose `grep`, `sed` and `sh` reject things the GNU
tools accept (an empty alternative in a `grep -E` pattern, for one).