ApmonD 2.0: a shared access point monitoring library (libapmon) and the apmond daemon, written in C.
The 1.x shell version lives in openNDS/apmond.
Status: 2.0.1beta, development build after the 2.0.0 release. Protocol: docs/PROTOCOL.md.
| Path | What |
|---|---|
src/lib |
libapmon: PBKDF2/HKDF key derivation, AES-256-GCM envelope, replay cache, JSON writer, Wi-Fi chipset detection; crypto through crypto.h with an mbedtls or OpenSSL 3 backend (-DCRYPTO_BACKEND=mbedtls|openssl) |
src/apmond |
the daemon: uloop, uci, ubus, data collection, sender, collector (libmicrohttpd) |
tests |
host unit tests (make -C tests check, CRYPTO=openssl for the OpenSSL backend, check-all for both; add MBEDTLS_DIR=<mbedtls 3.6 tree> if the system has no mbedtls) and test vectors |
openwrt/apmond |
OpenWrt package (Makefile, files/apmond.config, files/apmond.init) |
On every node: same apmon_seed and port (default 2468) in /etc/config/apmond. The access points can be linked in any way (cabled, mesh, point-to-point, fibre); apmond only needs them on one LAN. With role auto, an access point with an upstream gateway on its WAN (netifd wan or wan6 up with a default route) is a collector candidate and the first to claim the collector ULA becomes the collector; the others are senders (or send to option collector).
A sender sends to the collector ULA <prefix>:<subnet>::1 (collector_via ula). At start it waits up to 30 s for its own node ULA to finish duplicate address detection before choosing (logged: waiting up to 30 s for node ULA ..., then node ULA ready after N ms); only if the ULA is still not ready, or two sends in a row to the ULA fail (logged: collector ULA not reachable 2 times in a row ...), does it use the lan's IPv4 gateway (collector_via ipv4), trying the ULA again after 10 IPv4 reports or after a failed IPv4 send (r32). Only the lan side gateway is used, never the WAN default route; with none the sender stays on the ULA. A collector candidate with a collector ULA never falls back to IPv4: it waits for its node ULA (r34), and still runs the role check once per interval, so it keeps trying to claim, re-adds a missing node ULA, and stops waiting as a candidate when its upstream goes (r35). A candidate with no collector ULA (ULA setup failed) becomes the local collector, and uses the lan IPv4 gateway only if that collector fails to start.
The node ULA, the collector listener and the reported ipv4_addresses use one network device: option netdev if set, else the l3_device of option interface (default lan). When neither is set, a sender uses the device that reaches the collector, checked every interval: the device on which the apmond ULA prefix is on-link (a route added by netifd or an RA, not the kernel's own address routes), else the device of the IPv4 default route, else the lan device. On most access points that is the lan device anyway; on a node whose uplink network is bridged into its WAN, such as a CPE with its own local LAN, it is the WAN device (eg br-wan), so the node ULA and addresses it reports are reachable from the collector. When the choice changes (eg the WAN comes up after apmond), the node ULA moves to the new device and one notice is logged. A collector candidate always uses the lan device. option device (node MAC, wired clients) is not affected.
On the collector:
ubus call apmond status
ubus call apmond nodes
ubus call apmond clients
ubus call apmond node '{"id":"<node mac>"}'
apmond bench prints how long key derivation takes on the device.
mesh11sd is optional. apmond 2.x does not conflict with mesh11sd. On mesh11sd nodes set uci set mesh11sd.setup.apmond_enable='0' so mesh11sd's built-in (1.x protocol) apmond is off. apmond 1.x conflicts with mesh11sd. With mesh11sd auto configuration, LuCI is disabled on a portal until mesh11sd commit_all commit is run there.
apmond is also a thin ubus client of the running daemon. Output is JSON, indented as jq and apmond 1.x print it (two spaces; ubus call apmond ... keeps libubox's own format); add -t or --table for aligned tables.
apmond -v | --version print the version line (eg apmond 2.0.1beta) and exit 0
apmond status this node: version and build identity, role and why, ULAs, collector, counters, debuglevel, blocks
apmond nodes collector: every node with its info, APs and clients (as 1.x show_ap_data)
apmond node <node_mac> collector: one node, same layout as nodes
apmond clients [node_mac] collector: flat client list, by node then MAC (stale ones marked stale*)
apmond forget <node_mac|client_mac> collector: drop a node with its clients, or one client
apmond block add <name> <json> [ttl]
apmond block remove <name>
apmond debuglevel [0|1|2|3] show, or set at once and save to uci
apmond wifidetect this node's Wi-Fi chipsets and capabilities, detected again (see below)
apmond read_log [-f] print the log; -f keeps following it
apmond bench key derivation time on this hardware
apmond run [-c confdir] the daemon itself (started by /etc/init.d/apmond)
On a sender, apmond status always ends with reports sent N failed N time sync failed N last HTTP status N last error E (zeros included; r33 added the time sync count and last error) and a reminder that lost reports are counted on the collector (apmond node <id>, lost_reports). With -t the line is on stdout; in JSON mode it is on stderr, so the JSON on stdout stays parseable (r31). Status JSON has time_sync_failed (time requests that got no valid reply, eg a wrong apmon_seed: the sender then never gets to send a report) and last_error: empty after a success, else no connection, key rejected, time or replay rejected, bad reply or HTTP NNN. The collector logs messages that fail authentication at notice level, at most once per report interval, with the count since the last notice and the source address (r33).
Example:
# apmond -t nodes
=== OpenWrt-6873 94:83:c4:52:68:73 collector ok last report 29s ago
model GL-MT300N-V2 release 25.12.5 apmond 2.0.0beta
uptime 5d 19h 12m load 1.10 0.83 0.63 free RAM 75532 KiB free flash 9016 KiB
ULA fd46:cfe5:34c5:6ddd:9683:c4ff:fe52:6873 IPv4 192.168.10.1/24
source local reports 2 lost 0 passphrase DEFAULT
Access points
PHY CHANNEL MHZ HTMODE AP SSID BSSID
phy0 1 2412 HT20 phy0-ap0 House-6873 96:83:C4:52:68:73
Clients (1)
MAC KIND STATE LAST_SEEN WHERE SIGNAL TX RX CONNECTED
1c:86:0b:36:3f:dd wired active 29s eth0.1 - 100 Mbit/s 100 Mbit/s -
=== OpenWrt-f9d1 94:83:c4:2e:f9:d1 peer ok last report 3s ago
...
A node is identified by its factory (label) MAC, node_mac. apmond takes it from the first of these that gives one, the same chain mesh11sd 8.0.0 will use in its own mesh11sd_factory_mac() (apmond's is apmon_factory_mac() in src/lib/factory_mac.c; mesh11sd does not depend on apmond), kept in agreement by shared test vectors, so both always agree on a node's id:
- the device tree:
aliases/label-mac-device, that node'smac-address, elselocal-mac-address. Newer ujail (OpenWrt master) hides/sys/firmwareinside the jail, so the init script copies just those files to/tmp/apmond/devicetreebefore starting the jailed daemon, which reads the copy when it cannot see the device tree itself /etc/board.jsonsystem.label_macaddruci system.@system[0].label_macaddr(set this to override the id on an odd board)- the permanent MAC of the WAN device (
ubus call network.interface.wan status,device, elsel3_device) - the first of
eth1,eth0,lan0,lan1with a universally administered permanent MAC - the lowest-ifindex ethernet device with a universally administered permanent MAC
A permanent MAC is what ethtool -P shows, else the current MAC when the kernel says it was never changed (addr_assign_type 0), so a MAC rewritten at runtime (eg by mesh11sd) is never used. All-zero MACs are ignored, and locally administered ones at steps 5 and 6. If nothing fits, apmond logs an error and does not start; there is no br-lan fallback. The source used is logged at start: node id ... (factory MAC from ...).
Upgrading from r28 or older: on boards where the old chain fell back to an interface MAC, the id can change, so the node shows up once as a new node (forget the old one with apmond forget <old node_mac>). Example: the GL-BE10000 on snapshot, where r28 used eth1 as rewritten by mesh11sd (96:83:c4:e7:b1:b1) and r29 reads the device tree label MAC (94:83:c4:dd:b1:b1).
Nodes are identified by node_mac and clients by client_mac, the first field of every client object. Clients nested under a node in apmond nodes / node are just client_mac, kind, state, last_seen, last_seen_date, last_seen_age_s, location (Wi-Fi ap_ssid, ap_ifname, ap_bssid; wired bridge/port), vlan, vxlan, then their stats (-t shows a Wi-Fi client's SSID under WHERE); the flat apmond clients list adds node_mac and node_hostname after client_mac.
In collector output (apmond nodes|node|clients and the ubus methods) client last_seen and node last_report are Unix seconds, each with a _date twin in apmond 1.x's date_time format (router local time, spaces as _, eg Thu_Oct_29_15:47:00_GMT_2026), plus last_seen_age_s / age_s. Reports on the wire keep milliseconds.
Every AP and client carries vlan: the access VLAN of its bridge port (PVID on a vlan_filtering bridge, so an AP on option network lan with lan on br-lan.10 shows 10; a Wi-Fi client has its AP's VLAN, a wired client its port's). null means untagged / no VLAN; tables show -. On mesh11sd nodes, where the trunk is a VXLAN (vxlan<tun_id> in br-tun<tun_id>), APs and clients on that bridge also carry "vxlan": {"vni": N, "device": "vxlan0"}, otherwise null. Both come from rtnetlink, no forks, cached 5 minutes.
apmond debuglevel prints the level; apmond debuglevel N (or ubus call apmond debuglevel '{"level":N}') applies it at once and commits option debuglevel to /etc/config/apmond, as 1.x did, so it persists. A change made with uci set apmond.setup.debuglevel=N; uci commit apmond is picked up on the next report cycle. Every change is logged at notice level.
As apmond 1.x: messages above debuglevel (0 errors, 1 notices (default), 2 info, 3 debug) are dropped and identical consecutive messages are written once. Errors and notices go to syslog and to the log file; info and debug go to the log file only. The log file is <log_mountpoint>/apmond/apmond_log.log (default /tmp/apmond/apmond_log.log), trimmed to max_log_entries lines (500), each line <date> daemon.<level> apmond: [<n>] <message> (r20+: no pid, as in a ujail it would read 1; apmond status (the CLI, as root) shows the daemon's host pid as pid, from procd and, when jailed, the ujail wrapper's child; ubus status has no pid (r22+)). A log_mountpoint that is not mounted disables the log file so it can't fill flash.
Any program on a node can attach a JSON object to that node's reports:
ubus call apmond add_block '{"name":"mesh","data":{"peers":2},"ttl":90}'
ubus call apmond remove_block '{"name":"mesh"}'
The collector shows it in apmond node <node_mac> under blocks.mesh (and in apmond nodes). Names: 1–32 of a-z 0-9 _ -; data up to 16 KiB; up to 16 blocks; RAM only; ttl (seconds) makes a block expire unless it is set again. This is how a rewritten mesh11sd can add its mesh data without its own reporting code. See docs/PROTOCOL.md section 9.
apmond wifidetect (or ubus call apmond wifidetect '{"refresh":true}') prints this node's
Wi-Fi chipsets and capabilities as JSON, with the key names and layout of mesh11sd v7
wifi_chipset_detect: System@<factory MAC> holds Distribution, Release, Revision, Target,
Architecture, Description and Device, and phy holds one object per phy with Chipset, Bands,
Standards, MeshPoint, Wi-FiGeneration, MIMO, MaxChannelWidth, ChannelWidthCap, Antennas,
TheoreticalMaxMbps (Aggregated_MLO_MaxMbps for Wi-Fi 7), TXQS, AIRTIME_FAIRNESS, AQL_Extended,
AQL_Runtime and Driver. The daemon detects once at startup and again only on request, keeps the
result in RAM (ubus call apmond wifidetect without refresh returns it) and writes it to
/tmp/apmond/wifidetect. It is not sent in reports. The data comes from /sys/class/ieee80211,
/etc/openwrt_release, /etc/board.json and iw phy <phy> info (iw is not a dependency:
without it Bands, Standards and the rest read unknown or false). AQL_Runtime needs debugfs, which
only root can read, so the daemon reports it false; if apmond is not running, apmond wifidetect
detects by itself as root.
Every node reports, right after apmond_version, package_version (eg 2.0.0_beta-r13),
build_commit, running_sha256 (the binary that is running, hashed at startup),
installed_sha256 (/usr/sbin/apmond on disk, re-hashed when it changes) and
restart_needed (true when they differ). apmond status, apmond nodes and apmond node <mac>
show them; apmond -t nodes has a line per node such as
build 2.0.0_beta-r13 3aa8f8d running 8a681eac installed 8a681eac
ending in RESTART NEEDED when the installed binary is not the one running. The package
restarts apmond itself on an apk upgrade, so this normally shows only after a manual copy.
Nodes running a 2.0 beta before r13 show these fields as null.
apmond does not run as root. The package creates user and group apmond (468), and
the init script starts it one of two ways:
- ujail (when
procd-ujailis installed and the kernel has PID, IPC and UTS namespaces): procd jails it as user apmond with onlyCAP_NET_ADMIN(/etc/capabilities/apmond.json), no_new_privs, and these mounts: ubus, log, /proc, /sys, read-only/etc/config,/etc/openwrt_release,/tmp/sysinfo,/usr/sbin(soinstalled_sha256sees a replaced binary),/overlay(free flash),/bin/shand/sbin/swconfig(wired speed fallback),/usr/sbin/iwwhen installed (wifidetect), and read-write/tmp/apmondpluslog_mountpointwhen it is not /tmp. - otherwise (no ujail, or a small target such as ramips/mt76x8 whose kernel has only
mount namespaces, where ujail cannot start):
apmond run -u apmondstarts as root and switches to user apmond itself, keeping onlyCAP_NET_ADMIN(bounding, permitted, effective, ambient) with no_new_privs, as dnsmasq does.
CAP_NET_ADMIN is needed to add and remove the ULA addresses over netlink; the collector
port (2468) needs no capability, and CAP_NET_RAW is not used. The listener is bound to the LAN
device with SO_BINDTODEVICE on a fresh socket, which an unprivileged process may do since
Linux 5.7 (the kernel only requires CAP_NET_RAW to change an existing binding), so a jailed
apmond needs kernel 5.7 or later (all 25.12 targets run 6.x). If user or group apmond is
missing at start (eg /etc/passwd restored from an old backup), the init script recreates
them (uid/gid 468, as the package does); if id apmond still fails, apmond is not started.
A collector candidate checks that it can open the listener before it claims ::1, and gives
::1 up if the listener fails later, so a node that cannot listen never holds ::1. ubus access for user
apmond is in /usr/share/acl.d/apmond.json: publish apmond and call network.interface.*
status and network.wireless status (AP/mesh encryption and SSID as netifd applied them). Wi-Fi state comes straight from the kernel over nl80211 generic netlink (no iwinfo,
rpcd-mod-iwinfo or libnl; dumps need no capability). The postinst reloads ubusd so the
ACL applies at once.
/etc/config/apmond is root:apmond 0640 (set at every start): the daemon reads it,
including debuglevel each cycle, but cannot write it. apmond debuglevel N (as root)
saves the level to uci itself and restores the group; ubus call apmond debuglevel '{"level":N}' changes it for the running daemon ("persisted": false when jailed). A
uci commit apmond by another tool keeps the mode but resets the group to root, so the
daemon keeps its current settings until the next restart or service apmond reload.
The CLI (apmond status, nodes, ...) runs as root outside the jail and talks over ubus.
build_commit comes from .build_commit, which holds $Format:%h$: git archive and
GitHub release tarballs fill in the short commit (.gitattributes export-subst). A build
from a plain checkout asks git, else shows "unknown".
One Makefile builds two variants that differ only in the crypto library: apmond
(mbedTLS, the default, what apk add apmond and luci-app-apmond get) and apmond-openssl
(OpenSSL 3 libcrypto, for images that already carry OpenSSL). They are wire compatible and
can be mixed freely on one network; both pass the same test vectors. They conflict with each
other (apmond-openssl provides apmond) and share the config, init script, ACL and
capabilities. To switch a node, keeping /etc/config/apmond:
apk del apmond && apk add apmond-openssl # or back: apk del apmond-openssl && apk add apmond
ubus call apmond status shows the backend in use as crypto.
mbedTLS (apmond) is the default and the recommended variant, especially on small or
legacy devices (16 MB flash, eg GL-MT300N-V2, GL-AR300M16): OpenWrt images already
carry libmbedtls, so apmond adds only itself (~50 KB package). apmond-openssl pulls in
libopenssl3 from the package feed, which costs about 2.4 MB of overlay flash (aarch64,
UBIFS-compressed; 4.9 MiB installed) unless the image already has it. It installs with
apk like any package, no custom image needed.