feat(access-point): SSID settings, radio channels, VLAN names, the AP configuration and DHCP leases through declared methods (NetOrk/netork#695)

push_ssid_config, set_radio_channels and set_vlan_name run as checked
uci steps (#35): a refused step raises naming itself and reverts what
was staged. set_radio_channels replaces the undeclared push_radio_channel.

apply_ap_config takes napalm-device-types' ApConfigDict and the parts
the caller found different and writes them as one detached script: the
builder netOrk had in _uci_builders.py, moved here. It answers which
parts it wrote and which it could not, whether the AP restarts, and the
script with every passphrase masked. A passphrase part now writes the
key.

get_dhcp_leases reads dnsmasq's lease file.

Needs napalm-device-types 4.54.0; CI pre-installs it from its branch
until it is on PyPI.
This commit is contained in:
Christian Manivong committed 2026-11-29 20:51:27 +01:00
1 parent dd3e3f1543
commit 634bc9c793
18 files changed
+2108 -40

No files matched your search

+38 -7
View File
@@ -72,6 +72,7 @@ device.close()
| `get_ntp_servers` / `get_ntp_peers` | ✅ | `system.ntp.server` in UCI, every server of the list; none while `system.ntp.enabled` is off -- the same list as `get_time_sync()` |
| `get_time_sync()` | ✅ | napalm-device-types `TimeSyncMixin`: the servers as above, the zone from `zonename` where the rule in `timezone` is that zone's (else the one zone with that rule, or none); `synchronized` is not readable (None) |
| `get_firmware_offer()` | ✅ | napalm-device-types `FirmwareOfferMixin`: the newest release of the device's own line on the attended sysupgrade server (see *Firmware upgrade*) |
| `get_dhcp_leases()` | ✅ | napalm-device-types `DhcpLeasesMixin`: dnsmasq's lease file (`dhcp.@dnsmasq[0].leasefile`, else `/tmp/dhcp.leases`), DHCPv4 leases only, state `active`; `[]` where dnsmasq never ran; raises when the file cannot be read. odhcpd's DHCPv4 leases are not read |
| `get_services_need_restart()` | ❌ | deliberately not offered (NetOrk/netork#2750): an upgrade writes the new files to the overlay while the old ones stay in the read-only image, and `/proc/<pid>/maps` can name those by their `/rom` or `/overlay/upper` path rather than as deleted (Linux before 6.8 shows an overlay file's real path). napalm-device-types' `/proc` scan could then read clean exactly after an upgrade; without the method the caller shows the reading as not made. A reading of OpenWrt's own is #51 |
## Configuration management
@@ -153,13 +154,43 @@ image.
## Wireless writes
`push_mac_acl(ssid_name, mode, macs)` (napalm-device-types `MacAclMixin`) rewrites the
MAC filter of every wifi-iface carrying the SSID and reloads wifi;
`push_radio_channel(radio, channel)` sets a radio's channel (`0` is `auto`) and restarts
wifi in full. Each `uci` step runs on an SSH exec channel of its own, as root, with its
exit status checked: a refused step raises `CommandErrorException` naming it, what was
staged is reverted, and nothing is committed or restarted. An SSID no wifi-iface
carries raises too.
Each `uci` step runs on an SSH exec channel of its own, as root, with its exit status
checked: a refused step raises `CommandErrorException` naming it, what was staged is
reverted, and nothing is committed or restarted.
- `push_mac_acl(ssid_name, mode, macs)` (napalm-device-types `MacAclMixin`) rewrites the
MAC filter of every wifi-iface carrying the SSID and reloads wifi. An SSID no wifi-iface
carries raises.
- `push_ssid_config(ssid, config)` (`WirelessWritesMixin`) writes the settings it is given
-- `encryption`, `key`, `hidden`, `enabled` (as UCI's `disabled`), `disassoc_low_ack`,
`max_inactivity` -- to every wifi-iface carrying the SSID, then `wifi reload`. A key it
is not given is left alone; an SSID no wifi-iface carries raises. Which mode may be
written without its key is the caller's to decide.
- `set_radio_channels({radio: channel})` (`WirelessWritesMixin`) sets every radio's channel
(`0` is `auto`) in one commit and restarts wifi in full once (`wifi`: `wifi reload` does
not change a radio's channel). A radio name that is no UCI section name, or a channel that
is no whole number, raises `ValueError` before anything is sent.
- `set_vlan_name(vlan_id, name)` names every `bridge-vlan` section of the VLAN and commits
`network`; nothing restarts for a label. False where no `bridge-vlan` carries the VLAN.
## AP configuration
`apply_ap_config(config, parts)` (napalm-device-types `ApConfigMixin`) writes the parts of
an `ApConfigDict` the caller names as one shell script: the radios (country, 5 and 2.4
GHz `htmode`), remote syslog, LuCI (`uhttpd` enabled or stopped), dropbear's port and
password logins, the `br-ap` bridge with VLAN filtering on `eth0` (every VLAN tagged, the
management VLAN untagged where asked), one VLAN of it, its spanning tree, and per SSID its
VLAN (`ap_vlan<vid>`), bands, presence, encryption and key, flags, limits, MAC filter and
802.11r. The radios are found by their `band` in `uci show wireless`. A keyed mode is never
written without its key, a whitelist without MACs is written as no filter, and a part the
driver does not know or whose values are missing comes back in `skipped`.
The script is written as root from stdin into a fresh `mktemp -d` directory
(`/tmp/openwrt-apply.XXXXXX`) and run detached, since it may cut the session; its output
stays in `apply.log` there. Rebuilding the bridge restarts the AP (`restarts`); otherwise
the configs are committed and network, wifi, system, dropbear and the firewall reloaded as
needed. The result carries the script with every passphrase masked. A step that fails
inside the script is in the log, not raised: the script has left the session by then.
## Time sync