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

@@ -776,7 +776,7 @@ mac80211_prepare_iw_htmode() {
mac80211_add_mesh_params() { mac80211_add_mesh_params() {
for var in $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING; do for var in $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING; do
eval "mp_val=\"\$var\"" eval "mp_val=\"\$$var\""
[ -n "$mp_val" ] && json_add_string "$var" "$mp_val" [ -n "$mp_val" ] && json_add_string "$var" "$mp_val"
done done
} }
@@ -1102,14 +1102,18 @@ drv_mac80211_setup() {
json_get_values scan_list scan_list json_get_values scan_list scan_list
json_select .. json_select ..
json_select data && {
json_get_var prev_rxantenna rxantenna
json_get_var prev_txantenna txantenna
json_select ..
}
find_phy || { find_phy || {
echo "Could not find PHY for device '$1'" echo "Could not find PHY for device '$1'"
wireless_set_retry 0 wireless_set_retry 0
return 1 return 1
} }
wireless_set_data phy="$phy"
local wdev local wdev
local cwdev local cwdev
local found local found
@@ -1144,6 +1148,9 @@ drv_mac80211_setup() {
[ "$txantenna" = "all" ] && txantenna=0xffffffff [ "$txantenna" = "all" ] && txantenna=0xffffffff
[ "$rxantenna" = "all" ] && rxantenna=0xffffffff [ "$rxantenna" = "all" ] && rxantenna=0xffffffff
[ "$rxantenna" = "$prev_rxantenna" -a "$txantenna" = "$prev_txantenna" ] || mac80211_reset_config "$phy"
wireless_set_data phy="$phy" txantenna="$txantenna" rxantenna="$rxantenna"
iw phy "$phy" set antenna $txantenna $rxantenna >/dev/null 2>&1 iw phy "$phy" set antenna $txantenna $rxantenna >/dev/null 2>&1
iw phy "$phy" set antenna_gain $antenna_gain >/dev/null 2>&1 iw phy "$phy" set antenna_gain $antenna_gain >/dev/null 2>&1
iw phy "$phy" set distance "$distance" >/dev/null 2>&1 iw phy "$phy" set distance "$distance" >/dev/null 2>&1

View File

@@ -46,7 +46,7 @@ function iface_start(wdev)
push(cmd, key, wdev[key]); push(cmd, key, wdev[key]);
system(cmd); system(cmd);
} else if (wdev.mode == "mesh") { } 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" ]) for (let key in [ "beacon-interval", "mcast-rate" ])
if (wdev[key]) if (wdev[key])
push(cmd, key, wdev[key]); push(cmd, key, wdev[key]);

View File

@@ -705,7 +705,7 @@ mac80211_prepare_iw_htmode() {
mac80211_add_mesh_params() { mac80211_add_mesh_params() {
for var in $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING; do for var in $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING; do
eval "mp_val=\"\$var\"" eval "mp_val=\"\$$var\""
[ -n "$mp_val" ] && json_add_string "$var" "$mp_val" [ -n "$mp_val" ] && json_add_string "$var" "$mp_val"
done done
} }

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> 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
@@ -14,7 +14,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
.../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 | 408 + .../network/services/hostapd/files/hostapd.uc | 402 +
.../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, 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/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
@@ -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 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..386ff72f7b index 0000000000..b52732adcb
--- /dev/null --- /dev/null
+++ b/package/network/services/hostapd/files/hostapd.uc +++ b/package/network/services/hostapd/files/hostapd.uc
@@ -0,0 +1,408 @@ @@ -0,0 +1,402 @@
+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, phy_is_fullmac } from "common"; +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); + wdev_remove(bss.ifname);
+} +}
+ +
+function write_lines(f, data) +function iface_gen_config(phy, config)
+{ +{
+ for (let line in data) { + let str = `data:
+ f.write(line); +${join("\n", config.radio.data)}
+ f.write("\n"); +channel=${config.radio.channel}
+ } +`;
+}
+
+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`);
+ +
+ for (let i = 0; i < length(config.bss); i++) { + for (let i = 0; i < length(config.bss); i++) {
+ let bss = config.bss[i]; + let bss = config.bss[i];
+ let type = i > 0 ? "bss" : "interface"; + let type = i > 0 ? "bss" : "interface";
+ +
+ f.write(`${type}=${bss.ifname}\n`); + str += `
+ write_lines(f, bss.data); +${type}=${bss.ifname}
+${join("\n", bss.data)}
+`;
+ } + }
+ f.close(); +
+ return str;
+} +}
+ +
+function iface_restart(phy, config, old_config) +function iface_restart(phy, config, old_config)
@@ -2542,7 +2531,8 @@ index 0000000000..386ff72f7b
+ let err = wdev_create(phy, bss.ifname, { mode: "ap" }); + let err = wdev_create(phy, bss.ifname, { mode: "ap" });
+ if (err) + if (err)
+ hostapd.printf(`Failed to create ${bss.ifname} on phy ${phy}: ${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}`); + hostapd.printf(`hostapd.add_iface failed for phy ${phy} ifname=${bss.ifname}`);
+ return; + return;
+ } + }
@@ -2593,6 +2583,9 @@ index 0000000000..386ff72f7b
+ if (is_equal(old_config.bss, config.bss)) + if (is_equal(old_config.bss, config.bss))
+ return true; + return true;
+ +
+ if (!old_config.bss || !old_config.bss[0])
+ return false;
+
+ if (config.bss[0].ifname != old_config.bss[0].ifname) + if (config.bss[0].ifname != old_config.bss[0].ifname)
+ return false; + return false;
+ +
@@ -2600,13 +2593,15 @@ index 0000000000..386ff72f7b
+ if (!iface) + if (!iface)
+ return false; + return false;
+ +
+ let config_inline = iface_gen_config(phy, 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)) + if (phy_is_fullmac(phy))
+ return false; + 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_inline, 0) < 0) {
+ hostapd.printf(`Failed to set config`); + hostapd.printf(`Failed to set config`);
+ return false; + return false;
+ } + }
@@ -2626,6 +2621,7 @@ index 0000000000..386ff72f7b
+ if (!new_cfg[name]) { + if (!new_cfg[name]) {
+ hostapd.printf(`Remove bss '${name}' on phy '${phy}'`); + hostapd.printf(`Remove bss '${name}' on phy '${phy}'`);
+ bss.delete(); + bss.delete();
+ wdev_remove(name);
+ continue; + continue;
+ } + }
+ +
@@ -2642,7 +2638,7 @@ index 0000000000..386ff72f7b
+ return false; + return false;
+ } + }
+ +
+ if (bss.set_config(config.file, idx) < 0) { + if (bss.set_config(config_inline, idx) < 0) {
+ hostapd.printf(`Failed to set config`); + hostapd.printf(`Failed to set config`);
+ return false; + return false;
+ } + }
@@ -2657,7 +2653,7 @@ index 0000000000..386ff72f7b
+ return false; + return false;
+ } + }
+ +
+ if (iface.add_bss(config.file, idx) < 0) { + if (iface.add_bss(config_inline, idx) < 0) {
+ hostapd.printf(`Failed to add bss`); + hostapd.printf(`Failed to add bss`);
+ return false; + return false;
+ } + }
@@ -2675,8 +2671,6 @@ index 0000000000..386ff72f7b
+ if (!config) + if (!config)
+ return iface_remove(old_config); + return iface_remove(old_config);
+ +
+ iface_write_config(phy, config);
+
+ let ret = iface_reload_config(phy, config, old_config); + let ret = iface_reload_config(phy, config, old_config);
+ if (ret) { + if (ret) {
+ hostapd.printf(`Reloaded settings for phy ${phy}`); + 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 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..896f5261fb index 0000000000..5b321423eb
--- /dev/null --- /dev/null
+++ b/package/network/services/hostapd/files/wdev.uc +++ b/package/network/services/hostapd/files/wdev.uc
@@ -0,0 +1,156 @@ @@ -0,0 +1,156 @@
@@ -3016,7 +3010,7 @@ index 0000000000..896f5261fb
+ push(cmd, key, wdev[key]); + push(cmd, key, wdev[key]);
+ system(cmd); + system(cmd);
+ } else if (wdev.mode == "mesh") { + } 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" ]) + for (let key in [ "beacon-interval", "mcast-rate" ])
+ if (wdev[key]) + if (wdev[key])
+ push(cmd, key, wdev[key]); + push(cmd, key, wdev[key]);