fix(wireless): refuse an unknown MAC ACL mode before sending anything
driver / standard (pull_request) Successful in 17s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m0s
driver / test (3.12) (pull_request) Successful in 1m0s
driver / test (3.13) (pull_request) Successful in 55s
driver / lowest (pull_request) Successful in 30s
driver / build (pull_request) Successful in 32s
driver / security (pull_request) Successful in 1m9s
CI / driver (pull_request) Successful in 2m41s
driver / publish (pull_request) Skipped

push_mac_acl wrote macfilter='allow' for "whitelist" and 'deny' for any
other mode but "off", so a mode the driver does not know -- a typo, or a
new mode from the caller -- became a deny list. It now raises ValueError
naming the mode before the first command is sent.

Closes #39
This commit is contained in:
Christian Manivong committed 2026-11-12 19:19:41 +01:00
1 parent 780b635174
commit 17d9bead50
3 files changed
+20 -1

No files matched your search

+7 -1
View File
@@ -29,6 +29,8 @@ _WIFI_RELOAD = "wifi reload"
#: A full down/up of every radio; a channel needs it (see ``push_radio_channel``).
_WIFI_RESTART = "wifi"
_ACL_OPTIONS = ("macfilter", "maclist")
#: The modes ``push_mac_acl`` takes, and the ``macfilter`` each writes ("off" writes none).
_MACFILTER_BY_MODE = {"whitelist": "allow", "blacklist": "deny", "off": None}
def _mac_acl_changes(sec: UciSection, mode: str, macs: list[str]) -> list[str]:
@@ -40,7 +42,7 @@ def _mac_acl_changes(sec: UciSection, mode: str, macs: list[str]) -> list[str]:
present = [opt for opt in _ACL_OPTIONS if opt in sec.options]
if mode == "off":
return [uci("delete", f"{sec.ref}.{opt}") for opt in present]
changes = [uci("set", f"{sec.ref}.macfilter={'allow' if mode == 'whitelist' else 'deny'}")]
changes = [uci("set", f"{sec.ref}.macfilter={_MACFILTER_BY_MODE[mode]}")]
if "maclist" in present:
changes.append(uci("delete", f"{sec.ref}.maclist"))
changes += [uci("add_list", f"{sec.ref}.maclist={mac}") for mac in macs]
@@ -634,9 +636,13 @@ class OpenWrtWirelessMixin(UciStepsMixin):
:param macs: MAC addresses to set as the maclist. Only the entries for the
active mode's list are ever passed in — the caller resolves whitelist
vs. blacklist before calling.
:raises ValueError: for a mode other than the three, before anything is sent.
:raises CommandErrorException: when no wifi-iface carries *ssid_name*, or
when a step is refused.
"""
if mode not in _MACFILTER_BY_MODE:
known = ", ".join(map(repr, _MACFILTER_BY_MODE))
raise ValueError(f"unknown MAC ACL mode {mode!r}; expected one of {known}")
effective_mode = "off" if (mode == "whitelist" and not macs) else mode
sections = [
sec