From 74651831ef83cb6e372c1985357792f374e256c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibaut=20VAR=C3=88NE?= Date: Thu, 11 May 2023 11:08:42 +0200 Subject: [PATCH] uspot: configure devices ifnames in section uspot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current uspot config uses a single named section to assign ifnames to uspot interfaces like so: config devices 'devices' option wlanc0 'hotspot1' option wlanc1 'hotspot1' Where 'wlanc0' and 'wlanc1' are physical ifnames. Code in common.uc also hardcodes a check to match ifnames with 'wlanc*'. This comit gets rid of the "config device" sections and accepts in the "config uspot" sections e.g.: option ifname 'wlanc0' or list ifname 'wlanc0' list ifname 'wlanc1' The listed devices are then associated with the current uspot config exactly as they were with the previous configuration system. The hardcoded check in common.uc is also removed, allowing arbitrary ifnames to be used. Malformed sections are ignored with a warning. Subsequent duplicate entries for a given ifname are be ignored with a warning. Signed-off-by: Thibaut VARĂˆNE --- feeds/ucentral/uspot/files/etc/config/uspot | 1 - feeds/ucentral/uspot/files/usr/bin/captive | 8 ++--- .../uspot/files/usr/share/uspot/accounting.uc | 8 ++--- .../uspot/files/usr/share/uspot/common.uc | 30 +++++++++++++++++-- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/feeds/ucentral/uspot/files/etc/config/uspot b/feeds/ucentral/uspot/files/etc/config/uspot index e948e8f08..fb44014ae 100644 --- a/feeds/ucentral/uspot/files/etc/config/uspot +++ b/feeds/ucentral/uspot/files/etc/config/uspot @@ -1,2 +1 @@ -config devices devices config webroot def_captive diff --git a/feeds/ucentral/uspot/files/usr/bin/captive b/feeds/ucentral/uspot/files/usr/bin/captive index dbd52274b..32c7491e4 100755 --- a/feeds/ucentral/uspot/files/usr/bin/captive +++ b/feeds/ucentral/uspot/files/usr/bin/captive @@ -10,10 +10,10 @@ function restart() { function interfaces() { let interfaces = []; - let devices = uci.get_all('uspot', 'devices'); - for (let k, v in devices) - if (substr(k, 0, 1) != '.') - push(interfaces, v); + uci.foreach('uspot', 'uspot', (d) => { + if (!d[".anonymous"]) + push(interfaces, d[".name"]); + }); return uniq(interfaces); } diff --git a/feeds/ucentral/uspot/files/usr/share/uspot/accounting.uc b/feeds/ucentral/uspot/files/usr/share/uspot/accounting.uc index 9d5633408..ab943275c 100755 --- a/feeds/ucentral/uspot/files/usr/share/uspot/accounting.uc +++ b/feeds/ucentral/uspot/files/usr/share/uspot/accounting.uc @@ -21,10 +21,10 @@ function session_timeout(interface) { return config[interface].session_timeout || 0; } -let devices = uci.get_all('uspot', 'devices'); -for (let k, v in devices) - if (substr(k, 0, 1) != '.') - clients[v] = {};; +uci.foreach('uspot', 'uspot', (d) => { + if (!d[".anonymous"]) + clients[d[".name"]] = {}; +}); function syslog(interface, mac, msg) { let log = sprintf('uspot: %s %s %s', interface, mac, msg); diff --git a/feeds/ucentral/uspot/files/usr/share/uspot/common.uc b/feeds/ucentral/uspot/files/usr/share/uspot/common.uc index ed7a50035..dcb83ad11 100644 --- a/feeds/ucentral/uspot/files/usr/share/uspot/common.uc +++ b/feeds/ucentral/uspot/files/usr/share/uspot/common.uc @@ -29,12 +29,38 @@ if (file) { file.close(); } -let devices = uci.get_all('uspot', 'devices'); +let devices = {}; +uci.foreach('uspot', 'uspot', (d) => { + function adddev(ifname, sname) { + if (ifname in devices) + warn('uspot: ignoring duplicate entry for ifname: "' + ifname + '"\n'); + else + devices[ifname] = sname; + } + + if (d[".anonymous"]) { + warn('uspot: ignoring invalid anonymous section at index ' + d[".index"] + '\n'); + return; + } + + let spotname = d[".name"]; + if (!d.ifname) { + warn('uspot: missing ifname in section "' + spotname + '"\n'); + return; + } + + if (type(d.ifname) == "array") { + for (let n in d.ifname) + adddev(n, spotname); + } + else + adddev(d.ifname, spotname); +}); function lookup_station(mac) { let wifs = nl.request(nl.const.NL80211_CMD_GET_INTERFACE, nl.const.NLM_F_DUMP); for (let wif in wifs) { - if (substr(wif.ifname, 0, 5) != 'wlanc') + if (!(wif.ifname in devices)) continue; let res = nl.request(nl.const.NL80211_CMD_GET_STATION, nl.const.NLM_F_DUMP, { dev: wif.ifname }); for (let sta in res) {