hostapd: backport more hot-reload fixes

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin
2023-08-09 11:21:54 +02:00
parent 81f8a368d1
commit aeac214236
4 changed files with 41 additions and 40 deletions

View File

@@ -1,4 +1,4 @@
From 87450a717bf0e9e82566c89debb60e6ba7d4fe4a Mon Sep 17 00:00:00 2001
From 629630e0f11126913dd39e927af3f7d643a0c0f3 Mon Sep 17 00:00:00 2001
From: Felix Fietkau <nbd@nbd.name>
Date: Thu, 6 Jul 2023 08:33:25 +0000
Subject: [PATCH] backport hostapd ucode / wifi reload support
@@ -14,7 +14,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
.../hostapd/files/hostapd-basic.config | 2 +-
.../hostapd/files/hostapd-full.config | 6 +-
.../network/services/hostapd/files/hostapd.sh | 23 -
.../network/services/hostapd/files/hostapd.uc | 408 +
.../network/services/hostapd/files/hostapd.uc | 402 +
.../services/hostapd/files/radius.clients | 1 +
.../services/hostapd/files/radius.config | 9 +
.../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/ucode.c | 177 +
.../hostapd/src/wpa_supplicant/ucode.h | 38 +
98 files changed, 15515 insertions(+), 2535 deletions(-)
98 files changed, 15509 insertions(+), 2535 deletions(-)
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/hostapd.uc
@@ -2460,10 +2460,10 @@ index 68dbd374ff..62703dc2f4 100644
}
diff --git a/package/network/services/hostapd/files/hostapd.uc b/package/network/services/hostapd/files/hostapd.uc
new file mode 100644
index 0000000000..386ff72f7b
index 0000000000..b52732adcb
--- /dev/null
+++ b/package/network/services/hostapd/files/hostapd.uc
@@ -0,0 +1,408 @@
@@ -0,0 +1,402 @@
+let libubus = require("ubus");
+import { open, readfile } from "fs";
+import { wdev_create, wdev_remove, is_equal, vlist_new, phy_is_fullmac } from "common";
@@ -2497,35 +2497,24 @@ index 0000000000..386ff72f7b
+ wdev_remove(bss.ifname);
+}
+
+function write_lines(f, data)
+function iface_gen_config(phy, config)
+{
+ for (let line in data) {
+ f.write(line);
+ f.write("\n");
+ }
+}
+
+function iface_write_config(phy, config)
+{
+ config.file = `/var/run/ap-${phy}.conf`;
+
+ let f = open(config.file, "w");
+ if (!f) {
+ hostapd.printf(`Failed to open file ${config.file}`);
+ return;
+ }
+
+ write_lines(f, config.radio.data);
+ f.write(`channel=${config.radio.channel}\n`);
+ let str = `data:
+${join("\n", config.radio.data)}
+channel=${config.radio.channel}
+`;
+
+ for (let i = 0; i < length(config.bss); i++) {
+ let bss = config.bss[i];
+ let type = i > 0 ? "bss" : "interface";
+
+ f.write(`${type}=${bss.ifname}\n`);
+ write_lines(f, bss.data);
+ str += `
+${type}=${bss.ifname}
+${join("\n", bss.data)}
+`;
+ }
+ f.close();
+
+ return str;
+}
+
+function iface_restart(phy, config, old_config)
@@ -2542,7 +2531,8 @@ index 0000000000..386ff72f7b
+ let err = wdev_create(phy, bss.ifname, { mode: "ap" });
+ if (err)
+ hostapd.printf(`Failed to create ${bss.ifname} on phy ${phy}: ${err}`);
+ if (hostapd.add_iface(`bss_config=${bss.ifname}:${config.file}`) < 0) {
+ let config_inline = iface_gen_config(phy, config);
+ if (hostapd.add_iface(`bss_config=${bss.ifname}:${config_inline}`) < 0) {
+ hostapd.printf(`hostapd.add_iface failed for phy ${phy} ifname=${bss.ifname}`);
+ return;
+ }
@@ -2593,6 +2583,9 @@ index 0000000000..386ff72f7b
+ if (is_equal(old_config.bss, config.bss))
+ return true;
+
+ if (!old_config.bss || !old_config.bss[0])
+ return false;
+
+ if (config.bss[0].ifname != old_config.bss[0].ifname)
+ return false;
+
@@ -2600,13 +2593,15 @@ index 0000000000..386ff72f7b
+ if (!iface)
+ return false;
+
+ let config_inline = iface_gen_config(phy, config);
+
+ bss_reload_psk(iface.bss[0], 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}'`);
+ if (iface.bss[0].set_config(config.file, 0) < 0) {
+ if (iface.bss[0].set_config(config_inline, 0) < 0) {
+ hostapd.printf(`Failed to set config`);
+ return false;
+ }
@@ -2626,6 +2621,7 @@ index 0000000000..386ff72f7b
+ if (!new_cfg[name]) {
+ hostapd.printf(`Remove bss '${name}' on phy '${phy}'`);
+ bss.delete();
+ wdev_remove(name);
+ continue;
+ }
+
@@ -2642,7 +2638,7 @@ index 0000000000..386ff72f7b
+ return false;
+ }
+
+ if (bss.set_config(config.file, idx) < 0) {
+ if (bss.set_config(config_inline, idx) < 0) {
+ hostapd.printf(`Failed to set config`);
+ return false;
+ }
@@ -2657,7 +2653,7 @@ index 0000000000..386ff72f7b
+ return false;
+ }
+
+ if (iface.add_bss(config.file, idx) < 0) {
+ if (iface.add_bss(config_inline, idx) < 0) {
+ hostapd.printf(`Failed to add bss`);
+ return false;
+ }
@@ -2675,8 +2671,6 @@ index 0000000000..386ff72f7b
+ if (!config)
+ return iface_remove(old_config);
+
+ iface_write_config(phy, config);
+
+ let ret = iface_reload_config(phy, config, old_config);
+ if (ret) {
+ hostapd.printf(`Reloaded settings for phy ${phy}`);
@@ -2964,7 +2958,7 @@ index 0000000000..03e2fc8fae
+}
diff --git a/package/network/services/hostapd/files/wdev.uc b/package/network/services/hostapd/files/wdev.uc
new file mode 100644
index 0000000000..896f5261fb
index 0000000000..5b321423eb
--- /dev/null
+++ b/package/network/services/hostapd/files/wdev.uc
@@ -0,0 +1,156 @@
@@ -3016,7 +3010,7 @@ index 0000000000..896f5261fb
+ push(cmd, key, wdev[key]);
+ system(cmd);
+ } else if (wdev.mode == "mesh") {
+ let cmd = [ "iw", "dev", ifname, "mesh", "join", ssid, "freq", wdev.freq, wdev.htmode ];
+ let cmd = [ "iw", "dev", ifname, "mesh", "join", wdev.ssid, "freq", wdev.freq, wdev.htmode ];
+ for (let key in [ "beacon-interval", "mcast-rate" ])
+ if (wdev[key])
+ push(cmd, key, wdev[key]);