hostapd: fix stray unused interfaces in the hot reload code

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin
2023-07-26 14:29:33 +02:00
parent 693e147cd9
commit 7bf62b76bd
4 changed files with 55 additions and 25 deletions

View File

@@ -15,11 +15,23 @@ function wdev_remove(name)
nl80211.request(nl80211.const.NL80211_CMD_DEL_INTERFACE, 0, { dev: name }); nl80211.request(nl80211.const.NL80211_CMD_DEL_INTERFACE, 0, { dev: name });
} }
function __phy_is_fullmac(phyidx)
{
let data = nl80211.request(nl80211.const.NL80211_CMD_GET_WIPHY, 0, { wiphy: phyidx });
return !data.software_iftypes.ap_vlan;
}
function phy_is_fullmac(phy)
{
let phyidx = int(trim(readfile(`/sys/class/ieee80211/${phy}/index`)));
return __phy_is_fullmac(phyidx);
}
function find_reusable_wdev(phyidx) function find_reusable_wdev(phyidx)
{ {
let data = nl80211.request(nl80211.const.NL80211_CMD_GET_WIPHY, 0, { wiphy: phyidx }); if (!__phy_is_fullmac(phyidx))
if (data.software_iftypes.ap_vlan)
return null; return null;
data = nl80211.request( data = nl80211.request(
@@ -153,4 +165,4 @@ function vlist_new(cb) {
}, vlist_proto); }, vlist_proto);
} }
export { wdev_remove, wdev_create, is_equal, vlist_new }; export { wdev_remove, wdev_create, is_equal, vlist_new, phy_is_fullmac };

View File

@@ -1,6 +1,6 @@
let libubus = require("ubus"); let libubus = require("ubus");
import { open, readfile } from "fs"; import { open, readfile } from "fs";
import { wdev_create, wdev_remove, is_equal, vlist_new } from "common"; import { wdev_create, wdev_remove, is_equal, vlist_new, phy_is_fullmac } from "common";
let ubus = libubus.connect(); let ubus = libubus.connect();
@@ -128,6 +128,9 @@ function iface_reload_config(phy, config, old_config)
bss_reload_psk(iface.bss[0], config.bss[0], old_config.bss[0]); bss_reload_psk(iface.bss[0], config.bss[0], old_config.bss[0]);
if (!is_equal(config.bss[0], old_config.bss[0])) { if (!is_equal(config.bss[0], old_config.bss[0])) {
if (phy_is_fullmac(phy))
return false;
hostapd.printf(`Reload config for bss '${config.bss[0].ifname}' on phy '${phy}'`); hostapd.printf(`Reload config for bss '${config.bss[0].ifname}' on phy '${phy}'`);
if (iface.bss[0].set_config(config_inline, 0) < 0) { if (iface.bss[0].set_config(config_inline, 0) < 0) {
hostapd.printf(`Failed to set config`); hostapd.printf(`Failed to set config`);

View File

@@ -89,24 +89,24 @@ function drop_inactive(config)
function add_ifname(config) function add_ifname(config)
{ {
for (let key in config) for (let key in config)
config.ifname = key; config[key].ifname = key;
} }
function delete_ifname(config) function delete_ifname(config)
{ {
for (let key in config) for (let key in config)
delete config.ifname; delete config[key].ifname;
} }
function add_existing(phy, config) function add_existing(phy, config)
{ {
let wdevs = glob(`/sys/class/ieee80211/${phy}/device/net/*`); let wdevs = glob(`/sys/class/ieee80211/${phy}/device/net/*`);
wdevs = map(wdevs, function(arg) { basename(arg) }); wdevs = map(wdevs, (arg) => basename(arg));
for (let wdev in wdevs) { for (let wdev in wdevs) {
if (config[wdev]) if (config[wdev])
continue; continue;
if (readfile(`/sys/class/net/${wdev}/operstate`) == "down") if (trim(readfile(`/sys/class/net/${wdev}/operstate`)) == "down")
config[wdev] = {}; config[wdev] = {};
} }
} }

View File

@@ -1,4 +1,4 @@
From 28baa7ac0c159be2d29431aca5c6aca2494b1e65 Mon Sep 17 00:00:00 2001 From 4f17c6e2ca90130f86783e87927019525af719ba Mon Sep 17 00:00:00 2001
From: Felix Fietkau <nbd@nbd.name> From: Felix Fietkau <nbd@nbd.name>
Date: Thu, 6 Jul 2023 08:33:25 +0000 Date: Thu, 6 Jul 2023 08:33:25 +0000
Subject: [PATCH] backport hostapd ucode / wifi reload support Subject: [PATCH] backport hostapd ucode / wifi reload support
@@ -10,11 +10,11 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
package/network/services/hostapd/Config.in | 39 +- package/network/services/hostapd/Config.in | 39 +-
package/network/services/hostapd/Makefile | 231 +- package/network/services/hostapd/Makefile | 231 +-
package/network/services/hostapd/README.md | 419 + package/network/services/hostapd/README.md | 419 +
.../network/services/hostapd/files/common.uc | 156 + .../network/services/hostapd/files/common.uc | 168 +
.../hostapd/files/hostapd-basic.config | 2 +- .../hostapd/files/hostapd-basic.config | 2 +-
.../hostapd/files/hostapd-full.config | 6 +- .../hostapd/files/hostapd-full.config | 6 +-
.../network/services/hostapd/files/hostapd.sh | 23 - .../network/services/hostapd/files/hostapd.sh | 23 -
.../network/services/hostapd/files/hostapd.uc | 405 + .../network/services/hostapd/files/hostapd.uc | 408 +
.../services/hostapd/files/radius.clients | 1 + .../services/hostapd/files/radius.clients | 1 +
.../services/hostapd/files/radius.config | 9 + .../services/hostapd/files/radius.config | 9 +
.../services/hostapd/files/radius.init | 42 + .../services/hostapd/files/radius.init | 42 +
@@ -103,7 +103,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
.../hostapd/src/wpa_supplicant/ubus.h | 11 - .../hostapd/src/wpa_supplicant/ubus.h | 11 -
.../hostapd/src/wpa_supplicant/ucode.c | 177 + .../hostapd/src/wpa_supplicant/ucode.c | 177 +
.../hostapd/src/wpa_supplicant/ucode.h | 38 + .../hostapd/src/wpa_supplicant/ucode.h | 38 +
98 files changed, 15497 insertions(+), 2535 deletions(-) 98 files changed, 15512 insertions(+), 2535 deletions(-)
create mode 100644 package/network/services/hostapd/README.md create mode 100644 package/network/services/hostapd/README.md
create mode 100644 package/network/services/hostapd/files/common.uc create mode 100644 package/network/services/hostapd/files/common.uc
create mode 100644 package/network/services/hostapd/files/hostapd.uc create mode 100644 package/network/services/hostapd/files/hostapd.uc
@@ -2208,10 +2208,10 @@ index 0000000000..2150863306
+`ubus call hostapd.wl5-fb wps_start` +`ubus call hostapd.wl5-fb wps_start`
diff --git a/package/network/services/hostapd/files/common.uc b/package/network/services/hostapd/files/common.uc diff --git a/package/network/services/hostapd/files/common.uc b/package/network/services/hostapd/files/common.uc
new file mode 100644 new file mode 100644
index 0000000000..5c358b1902 index 0000000000..2002572cf1
--- /dev/null --- /dev/null
+++ b/package/network/services/hostapd/files/common.uc +++ b/package/network/services/hostapd/files/common.uc
@@ -0,0 +1,156 @@ @@ -0,0 +1,168 @@
+import * as nl80211 from "nl80211"; +import * as nl80211 from "nl80211";
+import * as rtnl from "rtnl"; +import * as rtnl from "rtnl";
+import { readfile } from "fs"; +import { readfile } from "fs";
@@ -2229,11 +2229,23 @@ index 0000000000..5c358b1902
+ nl80211.request(nl80211.const.NL80211_CMD_DEL_INTERFACE, 0, { dev: name }); + nl80211.request(nl80211.const.NL80211_CMD_DEL_INTERFACE, 0, { dev: name });
+} +}
+ +
+function __phy_is_fullmac(phyidx)
+{
+ let data = nl80211.request(nl80211.const.NL80211_CMD_GET_WIPHY, 0, { wiphy: phyidx });
+
+ return !data.software_iftypes.ap_vlan;
+}
+
+function phy_is_fullmac(phy)
+{
+ let phyidx = int(trim(readfile(`/sys/class/ieee80211/${phy}/index`)));
+
+ return __phy_is_fullmac(phyidx);
+}
+ +
+function find_reusable_wdev(phyidx) +function find_reusable_wdev(phyidx)
+{ +{
+ let data = nl80211.request(nl80211.const.NL80211_CMD_GET_WIPHY, 0, { wiphy: phyidx }); + if (!__phy_is_fullmac(phyidx))
+ if (data.software_iftypes.ap_vlan)
+ return null; + return null;
+ +
+ data = nl80211.request( + data = nl80211.request(
@@ -2367,7 +2379,7 @@ index 0000000000..5c358b1902
+ }, vlist_proto); + }, vlist_proto);
+} +}
+ +
+export { wdev_remove, wdev_create, is_equal, vlist_new }; +export { wdev_remove, wdev_create, is_equal, vlist_new, phy_is_fullmac };
diff --git a/package/network/services/hostapd/files/hostapd-basic.config b/package/network/services/hostapd/files/hostapd-basic.config diff --git a/package/network/services/hostapd/files/hostapd-basic.config b/package/network/services/hostapd/files/hostapd-basic.config
index 1f52546d57..3d19d8f902 100644 index 1f52546d57..3d19d8f902 100644
--- a/package/network/services/hostapd/files/hostapd-basic.config --- a/package/network/services/hostapd/files/hostapd-basic.config
@@ -2448,13 +2460,13 @@ index 68dbd374ff..62703dc2f4 100644
} }
diff --git a/package/network/services/hostapd/files/hostapd.uc b/package/network/services/hostapd/files/hostapd.uc diff --git a/package/network/services/hostapd/files/hostapd.uc b/package/network/services/hostapd/files/hostapd.uc
new file mode 100644 new file mode 100644
index 0000000000..2cd9339e77 index 0000000000..386ff72f7b
--- /dev/null --- /dev/null
+++ b/package/network/services/hostapd/files/hostapd.uc +++ b/package/network/services/hostapd/files/hostapd.uc
@@ -0,0 +1,405 @@ @@ -0,0 +1,408 @@
+let libubus = require("ubus"); +let libubus = require("ubus");
+import { open, readfile } from "fs"; +import { open, readfile } from "fs";
+import { wdev_create, wdev_remove, is_equal, vlist_new } from "common"; +import { wdev_create, wdev_remove, is_equal, vlist_new, phy_is_fullmac } from "common";
+ +
+let ubus = libubus.connect(); +let ubus = libubus.connect();
+ +
@@ -2590,6 +2602,9 @@ index 0000000000..2cd9339e77
+ +
+ bss_reload_psk(iface.bss[0], config.bss[0], old_config.bss[0]); + bss_reload_psk(iface.bss[0], config.bss[0], old_config.bss[0]);
+ if (!is_equal(config.bss[0], old_config.bss[0])) { + if (!is_equal(config.bss[0], old_config.bss[0])) {
+ if (phy_is_fullmac(phy))
+ return false;
+
+ hostapd.printf(`Reload config for bss '${config.bss[0].ifname}' on phy '${phy}'`); + hostapd.printf(`Reload config for bss '${config.bss[0].ifname}' on phy '${phy}'`);
+ if (iface.bss[0].set_config(config.file, 0) < 0) { + if (iface.bss[0].set_config(config.file, 0) < 0) {
+ hostapd.printf(`Failed to set config`); + hostapd.printf(`Failed to set config`);
@@ -2949,7 +2964,7 @@ index 0000000000..03e2fc8fae
+} +}
diff --git a/package/network/services/hostapd/files/wdev.uc b/package/network/services/hostapd/files/wdev.uc diff --git a/package/network/services/hostapd/files/wdev.uc b/package/network/services/hostapd/files/wdev.uc
new file mode 100644 new file mode 100644
index 0000000000..e7f5dcc527 index 0000000000..9701af125a
--- /dev/null --- /dev/null
+++ b/package/network/services/hostapd/files/wdev.uc +++ b/package/network/services/hostapd/files/wdev.uc
@@ -0,0 +1,153 @@ @@ -0,0 +1,153 @@
@@ -3044,24 +3059,24 @@ index 0000000000..e7f5dcc527
+function add_ifname(config) +function add_ifname(config)
+{ +{
+ for (let key in config) + for (let key in config)
+ config.ifname = key; + config[key].ifname = key;
+} +}
+ +
+function delete_ifname(config) +function delete_ifname(config)
+{ +{
+ for (let key in config) + for (let key in config)
+ delete config.ifname; + delete config[key].ifname;
+} +}
+ +
+function add_existing(phy, config) +function add_existing(phy, config)
+{ +{
+ let wdevs = glob(`/sys/class/ieee80211/${phy}/device/net/*`); + let wdevs = glob(`/sys/class/ieee80211/${phy}/device/net/*`);
+ wdevs = map(wdevs, function(arg) { basename(arg) }); + wdevs = map(wdevs, (arg) => basename(arg));
+ for (let wdev in wdevs) { + for (let wdev in wdevs) {
+ if (config[wdev]) + if (config[wdev])
+ continue; + continue;
+ +
+ if (readfile(`/sys/class/net/${wdev}/operstate`) == "down") + if (trim(readfile(`/sys/class/net/${wdev}/operstate`)) == "down")
+ config[wdev] = {}; + config[wdev] = {};
+ } + }
+} +}