OpenWrt Router Deployment

MiBee Steward can run directly on an OpenWrt router, in two forms: a router-agent (a light agent on the router reporting upstream to a remote center, repo naming Form B) and a router-center (the full center runs ON the router, repo naming Form C; Form A means a center on a generic host, see Standalone Deployment).

Verified in the field on a GL.iNet MT2500 (Brume 2, mt7981): form C ran end-to-end on the stock firmware, all 4 Tier-1 sources produced live data, and a full-subnet scan self-identified the router as a GL.iNet device (#288). Read the known-limitation entry about v4 listeners on this firmware (troubleshooting table below) before deploying.

Why Run on a Router

The router is the network's choke point, it sees DHCP leases, NAT flows, WiFi associations, and DNS queries that a regular LAN host cannot. These four Tier-1 router-only discovery sources are only available on the gateway:

Source What it gives Router daemon it reads No-op when absent
dhcp_leases Authoritative hostname↔MAC↔IP map dnsmasq /tmp/dhcp.leases ✅ clean no-op (non-DHCP host)
conntrack "Who is talking RIGHT NOW" (liveness + discovery) /proc/net/nf_conntrack ✅ clean no-op (module not loaded)
hostapd WiFi STA associations (signal dBm / SSID / connect time) hostapd ctrl socket → iw station dump fallback ✅ clean no-op (no WiFi / no hostapd)
dns_log Passive DNS fingerprint (devices that block probes still do DNS) dnsmasq --log-queries log file ✅ clean no-op (no query logging configured)

On a host that lacks the backing file/socket, the sources degrade to a clean no-op (debug log + skip), no errors, no crashes. Configuration lives under scanner.discovery.* (see Discovery and Configuration Reference).

One-click enablement (#360): the config generated by install.sh on first install turns the three zero-cost router-resident sources ON by default (dhcp_leases + conntrack + hostapd, free when the host IS the gateway), and LuCI's Services → MiBee Steward → Settings page offers all four as checkboxes (save = restart + health check). dns_log stays off by default, it additionally requires dnsmasq query logging (uci set dhcp.@dnsmasq[0].logqueries=1 && uci commit dhcp && /etc/init.d/dnsmasq restart, shown on the page); the LuCI toggle notes this. Manual deployments and config-preserving upgrades are unaffected (existing settings kept, installer prints a hint).

Form Selection

Form Binary Role When to use
Form B, router-agent → remote center agent-rs (Rust, binary mibee-agent) Pure sensor: scans the router's LAN, reports upstream over HTTPS to a center elsewhere Multi-site / multi-LAN: one remote center + one agent per router. The agent is very light (~4.8MB static binary, ~12MB RAM).
Form C, router-center cmd/server The full center (API + SPA + asset registry + discovery) running ON the router Single-network (home / small office): one router does everything, gets the choke-point signals AND serves the management UI. No separate agent process needed.

Form B pairs with Distributed Deployment; Form C is a self-contained single-network option (compare with Standalone Deployment).

flowchart LR
    subgraph R["OpenWrt router"]
        S["cmd/server (Form C center)"] --> C["Local Tier-1 discovery sources"]
        B["agent-rs mibee-agent (Form B agent)"] --> C
    end
    C -->|"Form C: consumed locally"| D["Center API + embedded SPA"]
    C -->|"Form B: reported upstream"| E["Remote center over HTTPS"]

Installation

Hardware Requirements

Resource Minimum Comfortable Notes
Architecture ARM or ARM64 ARM64 (GL.iNet MT3000, ipq807x, mt798x; NanoPi R5S-class iStoreOS boxes) MIPS is NOT supported, modernc.org/libc (the pure-Go SQLite backend's transitive dep) has no working mips/mipsle port and a broken mips64le one. This excludes older ath79/ramips routers (TP-Link Archer C7, Netgear R7000, etc.).
RAM 128 MB 256 MB+ modernc SQLite is memory-heavier than C-SQLite; the center is heavier than the agent.
Flash 32 MB 128 MB+ Binary 5MB (agent) / 24MB (center) + OUI (~5MB full / 1.2KB curated) + fingerprint corpus (~1.2MB) + DB. The DB should live on /tmp (tmpfs), see Resource Usage below.

Cross-Compile

Both forms build CGO-free/static, no OpenWrt SDK needed:

# Form B: agent — the Rust agent (agent-rs/), static musl binaries.
# Requires cargo-zigbuild + the ziglang pip package (see agent-rs/README.md).
make build-agent-rs
# → agent-rs/target/aarch64-unknown-linux-musl/release/mibee-agent      (~4.8MB)
# → agent-rs/target/armv7-unknown-linux-musleabihf/release/mibee-agent  (~4.8MB)

# Form C: center (Go, embeds the SvelteKit SPA — `make build-linux-arm64`
# is the same thing with the sync+frontend steps wired in):
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build \
  -trimpath -ldflags="-s -w" -o mibee-steward ./cmd/server/
# → ~24MB

The center supports GOARCH=arm (32-bit, GOARM=7) for older ARM boards; GOARCH=mips* does not (modernc/libc). The Rust agent builds for aarch64 and armv7 out of the box (mipsel exists for the test oracles but is unsupported/unvalidated). The agent binary already embeds the fingerprint corpus + curated OUI via its own asset-sync step (make build-agent-rs runs it).

procd Init Scripts & Config Files

The repo ships the center's procd init script (deploy/openwrt/mibee-steward.init), and the agent's (agent-rs/deploy/openwrt/mibee-agent.init). Both are installed to /etc/init.d/ and managed with enable (start at boot) and start/stop/restart. Config files live under /etc/mibee/.

Install Form B (Rust agent → remote center):

# On your build host:
make build-agent-rs
scp agent-rs/target/aarch64-unknown-linux-musl/release/mibee-agent root@router:/usr/bin/mibee-agent
scp agent-rs/deploy/openwrt/mibee-agent.init root@router:/etc/init.d/mibee-agent
ssh root@router 'mkdir -p /etc/mibee'
scp <your-agent.yaml> root@router:/etc/mibee/agent.yaml   # write it from configs/agent.example.yaml / the minimal sample in [Distributed Deployment](distributed.md), then edit on the router

# On the router, edit /etc/mibee/agent.yaml:
#   center.url:         http://<your-center-ip>:<port>
#   center.auth_token:  <minted on the center via POST /api/v1/agents/tokens>
#   network.name/cidr:  this router's LAN (e.g. lan-1 / 192.168.1.0/24)
#   scanner.discovery.*: enable the router-only sources you want
#     (dhcp_leases, conntrack, hostapd, dns_log, all default false)

ssh root@router '/etc/init.d/mibee-agent enable && /etc/init.d/mibee-agent start'
ssh root@router 'logread -e mibee-agent | tail -20'   # expect "mibee-agent x.y.z starting"

Install Form C (center on the router):

scp mibee-steward root@router:/usr/bin/mibee-steward
scp deploy/openwrt/mibee-steward.init root@router:/etc/init.d/mibee-steward
ssh root@router 'mkdir -p /etc/mibee'
scp configs/config.yaml root@router:/etc/mibee/config.yaml   # then edit on the router

# On the router, edit /etc/mibee/config.yaml:
#   server.port:                   e.g. 8080
#   auth.jwt_secret:               a ≥32-char random string (required)
#   auth.initial_admin_password:   empty = create the admin password in the browser on first run (recommended)
#   network.name/cidr:             this router's LAN
#   database.sqlite.path:          /tmp/mibee/mibee.db  (tmpfs, see below)
#   scanner.discovery.*:           enable the router-only sources

ssh root@router '/etc/init.d/mibee-steward enable && /etc/init.d/mibee-steward start'
# Browse to http://<router-ip>:8080, the first run walks you through CREATING the admin password

iStoreOS / NanoPi R5S: one-command install (no Docker)

iStoreOS is an OpenWrt-based community firmware, everything on this page applies. A NanoPi R5S (RK3568, arm64, 1-4GB RAM + 8-32GB eMMC) is far above the minimums above and comfortably runs Form C (the full center); iStoreOS's bundled Docker is NOT needed.

A common concern, "where does the frontend render?", is a non-issue: the SPA is compiled into the Go binary and the router only serves HTTP. Browse to http://<router-ip>:8080 from any device on the LAN; the router itself needs no display or frontend runtime. The MT2500 "v4 listeners never handshake" row in the troubleshooting table is a GL.iNet vendor-kernel bug, unrelated to iStoreOS.

# On your build host (GOARCH defaults to arm64; add GOARCH=arm for ARMv7 boards):
make package-openwrt
#    → bin/mibee-steward-openwrt-arm64-<version>.tar.gz

scp bin/mibee-steward-openwrt-arm64-*.tar.gz root@<router-ip>:/tmp/
ssh root@<router-ip> 'cd /tmp && tar -xzf mibee-steward-openwrt-arm64-*.tar.gz && ./install.sh'

On the router, install.sh verifies the architecture (rejects MIPS, smoke-executes the binary), installs the binary to /usr/bin and the procd script to /etc/init.d,, on first install only, generates /etc/mibee/config.yaml (random jwt_secret, cookie_secure forced to false (plain-HTTP LAN), EMPTY initial admin password, network.name/cidr derived from uci, DB at the absolute path /etc/mibee/data/mibee.db), opens + persists ping_group_range, then enables, starts, and health-checks the service. An existing config.yaml is left untouched except for additive migrations (migrate-config.sh, #727: a feature-default block the config predates — e.g. probe.quality — is added so an upgraded install reaches fresh-install parity; anything you set explicitly, including enabled: false, is never touched; re-runs are no-ops) — re-running with a fresh tarball is the upgrade path. Open the printed URL in a browser, the first-run screen asks you to create the admin password (nothing to copy from the install output, no SSH needed). Afterwards:

  • If the password is ever lost: /usr/bin/mibee-steward reset-admin-password -config /etc/mibee/config.yaml;
  • Enable the router-only discovery sources you want (scanner.discovery.*; the R5S has no onboard WiFi, so hostapd no-ops by design);
  • With roomy eMMC the DB defaults to flash (the portrait survives reboots); write-sensitive setups can point it at /tmp/mibee/mibee.db (tmpfs, rebuilt after reboot, see "Flash-Wear Mitigation" above).

iStoreOS notes: LuCI/the iStore admin UI hold ports 80/443, MiBee's default 8080 doesn't conflict; the default LAN is usually 192.168.100.1/24 (check uci get network.lan.ipaddr); dhcp_leases / conntrack / dns_log read the same standard OpenWrt paths, no extra adaptation needed.

System package (.ipk / .apk)

If you prefer the system package manager (install/upgrade/remove via the package manager, auto-generated config, data dir survives removal), deliver a package instead of the tarball. OpenWrt 24.10 replaced opkg with apk, and the package format went from .ipk to .apk, iStoreOS builds exist on both bases, so check which one your firmware uses first:

ssh root@<router-ip> 'command -v opkg apk; grep DISTRIB_RELEASE /etc/openwrt_release'
# opkg (OpenWrt 22.03/23.05 base, most current iStoreOS builds):
make package-openwrt-ipk     # → bin/mibee-steward_<version>_arm64.ipk
scp bin/mibee-steward_*_arm64.ipk root@<router-ip>:/tmp/
ssh root@<router-ip> 'opkg install /tmp/mibee-steward_*_arm64.ipk'

# apk (OpenWrt 24.10+ base):
make package-openwrt-apk     # → bin/mibee-steward_<version>_arm64.apk
scp bin/mibee-steward_*_arm64.apk root@<router-ip>:/tmp/
ssh root@<router-ip> 'apk add --allow-untrusted /tmp/mibee-steward_*_arm64.apk'

The two packages' lifecycle scripts are equivalent: pre-install/preinst gates on uname (a mismatched box is refused before anything is laid down); post-install/postinst runs the exact same configure logic as the tarball installer (generates /etc/mibee/config.yaml, opens ping_group_range, enables + starts + health-checks, no admin password is pre-generated; it is created in the browser on first run); upgrade = install the new package (opkg install the new .ipk / apk add the new .apk, config kept — including the same additive migrate-config.sh migrations as the tarball installer, service restarted); remove = opkg remove mibee-steward / apk del mibee-steward (/etc/mibee config + database are deliberately kept, delete manually for a full wipe).

Why Architecture: all: the payload is a CGO-free static binary, so instead of chasing OpenWrt's per-target arch-name zoo (aarch64_generic, aarch64_cortex-a53, arm_cortex-a7_neon-vfpv4, …), the real gates are the pre-script uname check + the post-script -version smoke run. Exact arch naming and feed publishing remain the buildroot follow-up (see "Not Covered Here" below). The tarball path stays available for package-manager-less environments.

Agent packages (form B): the Rust agent ships the same three forms — make package-openwrt-agent-rs (tarball, the manual flow above), package-openwrt-agent-rs-ipk, package-openwrt-agent-rs-apk — and release tags attach them to the GitHub Release (mibee-agent_*_arm64.*). The lifecycle matches the center packages: preinst gates on uname + smoke-runs -version; postinst runs the same agent-install.sh --from-ipk configure logic (first install generates /etc/mibee/agent.yaml from uci-derived LAN facts; the center url/token stay empty placeholders and the service stays down until you fill them — upgrades keep the config untouched). No LuCI files: the agent is headless. On the router: opkg install mibee-agent_*_arm64.ipk / apk add --allow-untrusted mibee-agent_*_arm64.apk, then edit /etc/mibee/agent.yaml (center.url + auth_token) and /etc/init.d/mibee-agent start.

eBPF-enabled router package (#499)

The stock router packages ship the default unprivileged build. For a kernel >= 6.6 (the TCX attach era) router you can package the eBPF-enabled center — the passive observer then sees wire-level ARP/ND presence and protocol signatures from the gateway vantage, silently, with zero probe packets:

# One-time: generate the BPF object (clang >= 14 needed on the build host):
go generate -tags WITH_EBPF ./internal/service/scannerv2/ebpf/

# Then package with the tag; the kmod deps are written into the package metadata:
make package-openwrt-ipk PKG_TAGS=WITH_EBPF      PKG_DEPS="+kmod-sched-bpf"
# (or package-openwrt-apk with the same variables)

Notes:

  • libbpf, tc and the clsact qdisc are NOT needed — the Go binary carries its own loader, the BPF object is CO-RE free (loads even on BTF-less kernels), and the loader attaches via TCX (kernel ≥ 6.6), which needs no classic qdisc or userland (#535 matrix correction: earlier docs recommended +kmod-sched-cls-act +tc; the center loader has no classic-TC fallback — older kernels degrade instead). kmod-sched-bpf provides the kernel-side BPF scheduler hooks the attach rides on.
  • procd runs the service as root, which satisfies the capability requirement without any extra wiring.
  • On a bridged router, attach the observer to the physical ports (eth0, eth1, ...), not br-lan: frames forwarded between bridge ports do not traverse the bridge device's own TC ingress hook. scanner.ebpf.interfaces in /etc/mibee/config.yaml takes the list.
  • On a kernel older than 6.6 the observer reports unsupported at startup and the server runs exactly like the default build (#493 degradation).
  • Same variables work for the LLDP/CDP/ARP-sweep variant: PKG_TAGS=WITH_LLDP,WITH_CDP,WITH_ARPSCAN (procd's root already provides CAP_NET_RAW, no deps needed).

LuCI native entry (iStoreOS / OpenWrt web admin)

The package also lays down a LuCI integration (classic Lua controller + templates; no luci-compat/CBI dependency, the files are inert on builds without LuCI). After install, the router's admin UI (MiBee Steward under System → Services) offers two pages:

  • Status: service state, health, autostart, version, listening port, database size, and an "Open UI" button straight into the full web UI (http://<lan-ip>:<port>).
  • Settings:
    • Web UI port: rewrites server.port, restarts, and health-checks the new port (80/443 are refused, LuCI owns them);
    • Admin password: sets the admin login directly (via reset-admin-password, validated against the effective password policy, min 8 + upper + lower + digit; handed over through a 0600 temp file, never a command line);
    • Autostart toggle and Restart.

Every privileged operation funnels through the single audited script /usr/lib/mibee/luci-helper.sh (the LuCI pages only validate input and delegate); it is callable standalone: luci-helper.sh status | set-port <N> | set-password <file> | set-enabled <0|1> | restart. Asset-level configuration (discovery sources, scanner tuning, notifications) stays in MiBee's own web UI, the LuCI entry covers router-level concerns only.

UCI Configuration (for the dns_log source)

dns_log requires dnsmasq query logging:

uci set dhcp.@dnsmasq[0].logqueries=1 && uci commit && /etc/init.d/dnsmasq restart

Then point scanner.discovery.dns_log.path at the resulting log (or leave it empty to probe the conventional paths).

Self-Hosted opkg Feed

make package-openwrt-ipk package-openwrt-agent-rs-ipk feed-index builds the packages and turns them into a self-contained feed directory dist/feed/arm64/ (Packages + Packages.gz + the .ipk files). Host that directory on any static file server inside your network:

python3 -m http.server 8093 --directory /opt/mibee-feed   # or nginx et al.

On each router, subscribe once and updates become plain opkg operations:

echo "src/gz mibee http://<feed-host>:8093/arm64/" >> /etc/opkg/customfeeds.conf
opkg update
opkg list | grep mibee          # versions from the feed
opkg upgrade mibee-steward      # or install/upgrade via the LuCI package page

Every index stanza carries a SHA256sum, so opkg verifies each downloaded package against the index it fetched over the same channel. The index itself is unsigned (usign/ed25519 signing is a follow-up): serve it from a host you control - the same trust you already place in the release artifacts.

Permissions (CAP_NET_RAW)

Some of MiBee Steward's probes rely on raw sockets and need CAP_NET_RAW:

  • ARP probing (arp_scan etc.) sends/receives raw ARP frames
  • ICMP active probing depends on raw sockets
  • If you bake in the raw-frame LLDP listeners or the eBPF passive observer, matching runtime caps are needed too (eBPF needs CAP_BPF + CAP_NET_ADMIN, kernel ≥5.8 + BTF)

The procd init scripts run as root by default (standard OpenWrt practice), so these capabilities are naturally available. If you run under a restricted account or a seccomp/apparmor policy that drops CAP_NET_RAW, ARP probing (arp_scan etc.) degrades or fails, and MAC discovery plus ICMP liveness checks become unavailable.

Resource Usage

Resource Form B (Rust agent) Form C (center)
Binary size ~4.8MB (static musl) ~24MB (includes SPA)
RAM ~12MB steady Heavier (modernc SQLite + asset registry)

Measured on the field rigs (NanoPi NEO armv7 / FastRhino R68S arm64); the full Go-vs-Rust comparison lives in agent-rs.md. The agent fits even 128MB routers; the center is best on 256MB+.

Flash-Wear Mitigation (DB on tmpfs)

Both binaries write a SQLite DB (WAL mode). On a router's NAND flash under overlayfs this causes write-wear. Point the DB at /tmp (tmpfs, RAM-backed):

  • Form B (agent): the local DB is explicitly a shadow (the center is the writer of record), so cold-start loss is fine. Note the agent's DB path currently has no dedicated config key, it is fixed to agent.db next to the config file (e.g. /etc/mibee/agent.db). Its write volume is tiny (scan-result staging only), so flash is usually fine; if you truly need it on tmpfs, move the whole config dir to /tmp/mibee-agent/ and point the init script there (the config file must be recreated after each reboot). The in-memory pending-queue (100 batches) handles disconnection during a reboot.
  • Form C (center): the DB is the authoritative portrait. Pointing database.sqlite.path at /tmp means cold-start loss (rebuilt on the next scan; acceptable for a single-router deployment). For deployments that need persistence across reboots, leave that key on flash and accept the wear, consumer routers live 5-10 years and scan write volume is modest.

Verification & Troubleshooting

Health Check

# Form C (center): health endpoint
curl -s http://localhost:8080/api/v1/health

# View logs
logread -e mibee-steward   # Form C
logread -e mibee-agent     # Form B, expect "mibee-agent x.y.z starting"

Common Issues

Symptom Cause / fix
bind: address already in use on start Another process holds the port (often the router's own LuCI on 80/443). Set server.port to a free port (e.g. 8080).
database is locked (SQLITE_BUSY) WAL-mode write contention under heavy concurrent probing. The pool ceiling (16) is currently fixed at compile time; the practical knob is reducing scanner.max_concurrent_hosts.
mmap: access denied at startup Kernel disallows the mmap SQLite wants, run as root (the procd script does) or check seccomp/apparmor.
Discovery sources all no-op Expected on a non-router host. On a router, check each source's prereq (dnsmasq running, nf_conntrack loaded, hostapd ctrl_interface enabled).
ICMP probes all permission denied OpenWrt's default net.ipv4.ping_group_range = 1 0 disables the unprivileged datagram ping sockets MiBee's ICMP probes use. Fix once: echo 'net.ipv4.ping_group_range = 0 2147483647' > /etc/sysctl.d/99-mibee.conf && /etc/init.d/sysctl restart, mibee-steward doctor checks this.
Intermittent silent connection drops to the router's own ports fw3 SYN-flood protection (default on GL.iNet) is a global 25/s burst-50 token bucket; MiBee's heartbeat port checks + probe fan-out can exhaust it and new TCP connections to ANY local port are silently dropped. Disable SYN-flood protection in LuCI or via fw3 config.
New v4 TCP listeners never complete handshakes on GL.iNet MT2500 (mt7981, kernel 5.4.211 SDK) Vendor-kernel bug: SYNs arrive but SYN-ACKs leave with an unfilled 0.0.0.0 address and get RST'd by peers, affects any new listener in any language, while IPv6 works. Known limitation on this specific firmware: bind v6 (server.host: "::") or run the center elsewhere and put an agent on the router (form B).
scp to the router fails with sh: /usr/libexec/sftp-server: not found Vendor firmwares (GL.iNet included) ship no sftp-server, so modern scp falls back to SFTP and dies. Force the legacy protocol: scp -O ….
dns_log discovery source stays empty on GL.iNet GL's dnsmasq build logs queries via the custom logfacility uci key (not the standard logfile): uci set dhcp.@dnsmasq[0].logqueries=1 && uci set dhcp.@dnsmasq[0].logfacility=/tmp/dnsmasq.log && uci commit dhcp, then point discovery.dns_log.path at that file and restart dnsmasq.
build constraints exclude all Go files … modernc.org/libc… at build The typical error shape for unsupported MIPS (modernc/libc limitation). Use an ARM/ARM64 router.

Not Covered Here

  • Official .ipk/.apk packaging (OpenWrt build feed): this repo now ships hand-rolled binary packages (make package-openwrt-ipk / make package-openwrt-apk, Architecture: all + pre-script arch gate, installed locally via opkg install <file> / apk add --allow-untrusted <file>). What's still missing is the official packaging via the OpenWrt buildroot's golang-package macros, exact per-target arch naming, signing, and feed publishing so users can subscribe. Not required for correctness.
  • MIPS support: structural limitation of modernc/libc; would require swapping the SQLite backend to bbolt/goleveldb (deferred until a MIPS customer need exists).