hostapd: update to latest hot reload

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin
2023-09-25 11:52:41 +02:00
parent 4f5a3b0c2b
commit d9f237b450
15 changed files with 140 additions and 42 deletions

View File

@@ -26,7 +26,6 @@ function iface_remove(cfg)
if (!cfg || !cfg.bss || !cfg.bss[0] || !cfg.bss[0].ifname)
return;
hostapd.remove_iface(cfg.bss[0].ifname);
for (let bss in cfg.bss)
wdev_remove(bss.ifname);
}
@@ -95,14 +94,14 @@ function iface_add(phy, config, phy_status)
let config_inline = iface_gen_config(phy, config, !!phy_status);
let bss = config.bss[0];
let ret = hostapd.add_iface(`bss_config=${bss.ifname}:${config_inline}`);
let ret = hostapd.add_iface(`bss_config=${phy}:${config_inline}`);
if (ret < 0)
return false;
if (!phy_status)
return true;
let iface = hostapd.interfaces[bss.ifname];
let iface = hostapd.interfaces[phy];
if (!iface)
return false;
@@ -127,6 +126,7 @@ function iface_restart(phydev, config, old_config)
{
let phy = phydev.name;
hostapd.remove_iface(phy);
iface_remove(old_config);
iface_remove(config);
@@ -267,13 +267,13 @@ function iface_reload_config(phydev, config, old_config)
if (!old_config.bss || !old_config.bss[0])
return false;
let iface_name = old_config.bss[0].ifname;
let iface = hostapd.interfaces[iface_name];
let iface = hostapd.interfaces[phy];
if (!iface) {
hostapd.printf(`Could not find previous interface ${iface_name}`);
return false;
}
let iface_name = old_config.bss[0].ifname;
let first_bss = hostapd.bss[iface_name];
if (!first_bss) {
hostapd.printf(`Could not find bss of previous interface ${iface_name}`);
@@ -512,8 +512,10 @@ function iface_set_config(phy, config)
hostapd.data.config[phy] = config;
if (!config)
if (!config) {
hostapd.remove_iface(phy);
return iface_remove(old_config);
}
let phydev = phy_open(phy);
if (!phydev) {
@@ -667,7 +669,7 @@ let main_obj = {
if (!config || !config.bss || !config.bss[0] || !config.bss[0].ifname)
return 0;
let iface = hostapd.interfaces[config.bss[0].ifname];
let iface = hostapd.interfaces[phy];
if (!iface)
return 0;

View File

@@ -13,6 +13,7 @@ start_service() {
procd_open_instance hostapd
procd_set_param command /usr/sbin/hostapd -s -g /var/run/hostapd/global
procd_set_param respawn 3600 1 0
procd_set_param limits core="unlimited"
[ -x /sbin/ujail -a -e /etc/capabilities/wpad.json ] && {
procd_add_jail hostapd
procd_set_param capabilities /etc/capabilities/wpad.json
@@ -29,6 +30,7 @@ start_service() {
procd_open_instance supplicant
procd_set_param command /usr/sbin/wpa_supplicant -n -s -g /var/run/wpa_supplicant/global
procd_set_param respawn 3600 1 0
procd_set_param limits core="unlimited"
[ -x /sbin/ujail -a -e /etc/capabilities/wpad.json ] && {
procd_add_jail wpa_supplicant
procd_set_param capabilities /etc/capabilities/wpad.json

View File

@@ -0,0 +1,28 @@
From: Felix Fietkau <nbd@nbd.name>
Date: Wed, 20 Sep 2023 13:41:10 +0200
Subject: [PATCH] hostapd: cancel channel_list_update_timeout in
hostapd_cleanup_iface_partial
Fixes a crash when disabling an interface during channel list update
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
--- a/src/ap/hostapd.c
+++ b/src/ap/hostapd.c
@@ -501,6 +501,7 @@ static void sta_track_deinit(struct host
void hostapd_cleanup_iface_partial(struct hostapd_iface *iface)
{
wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
+ eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
#ifdef NEED_AP_MLME
hostapd_stop_setup_timers(iface);
#endif /* NEED_AP_MLME */
@@ -529,7 +530,6 @@ void hostapd_cleanup_iface_partial(struc
static void hostapd_cleanup_iface(struct hostapd_iface *iface)
{
wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
- eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
eloop_cancel_timeout(hostapd_interface_setup_failure_handler, iface,
NULL);

View File

@@ -117,7 +117,7 @@ Index: hostapd-2021-02-20-59e9794c/src/ap/ieee802_11.c
goto fail;
}
+ ubus_resp = hostapd_ubus_handle_event(hapd, &req);
+ if (0 && ubus_resp) {
+ if (ubus_resp) {
+ wpa_printf(MSG_DEBUG, "Station " MACSTR " rejected by ubus handler.\n",
+ MAC2STR(mgmt->sa));
+ resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
@@ -152,7 +152,7 @@ Index: hostapd-2021-02-20-59e9794c/src/ap/ieee802_11.c
#endif /* CONFIG_FILS */
+ ubus_resp = hostapd_ubus_handle_event(hapd, &req);
+ if (0 && ubus_resp) {
+ if (ubus_resp) {
+ wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
+ MAC2STR(mgmt->sa));
+ resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;

View File

@@ -107,14 +107,14 @@
hostapd_ubus_free_bss(hapd);
accounting_deinit(hapd);
hostapd_deinit_wpa(hapd);
@@ -530,6 +533,7 @@ void hostapd_cleanup_iface_partial(struc
static void hostapd_cleanup_iface(struct hostapd_iface *iface)
@@ -502,6 +505,7 @@ static void sta_track_deinit(struct host
void hostapd_cleanup_iface_partial(struct hostapd_iface *iface)
{
wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
+ hostapd_ucode_free_iface(iface);
eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
eloop_cancel_timeout(hostapd_interface_setup_failure_handler, iface,
NULL);
#ifdef NEED_AP_MLME
hostapd_stop_setup_timers(iface);
@@ -1104,7 +1108,7 @@ static int db_table_create_radius_attrib
* initialized. Most of the modules that are initialized here will be
* deinitialized in hostapd_cleanup().
@@ -159,6 +159,16 @@
hostapd_cleanup(hapd);
hapd_iface->bss[hapd_iface->num_bss - 1] = NULL;
hapd_iface->conf->num_bss--;
@@ -3137,7 +3142,8 @@ int hostapd_remove_iface(struct hapd_int
hapd_iface = interfaces->iface[i];
if (hapd_iface == NULL)
return -1;
- if (!os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
+ if (!os_strcmp(hapd_iface->phy, buf) ||
+ !os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
wpa_printf(MSG_INFO, "Remove interface '%s'", buf);
hapd_iface->driver_ap_teardown =
!!(hapd_iface->drv_flags &
--- a/wpa_supplicant/Makefile
+++ b/wpa_supplicant/Makefile
@@ -172,8 +172,20 @@ endif
@@ -402,7 +412,7 @@
{
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -1222,7 +1222,7 @@ static void wpa_driver_nl80211_event_rtm
@@ -1224,7 +1224,7 @@ static void wpa_driver_nl80211_event_rtm
}
wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)",
namebuf, ifname);
@@ -411,7 +421,7 @@
wpa_printf(MSG_DEBUG,
"nl80211: Not the main interface (%s) - do not indicate interface down",
drv->first_bss->ifname);
@@ -1258,7 +1258,7 @@ static void wpa_driver_nl80211_event_rtm
@@ -1260,7 +1260,7 @@ static void wpa_driver_nl80211_event_rtm
}
wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)",
namebuf, ifname);
@@ -420,7 +430,7 @@
wpa_printf(MSG_DEBUG,
"nl80211: Not the main interface (%s) - do not indicate interface up",
drv->first_bss->ifname);
@@ -7609,6 +7609,7 @@ static void *i802_init(struct hostapd_da
@@ -7614,6 +7614,7 @@ static void *i802_init(struct hostapd_da
char master_ifname[IFNAMSIZ];
int ifindex, br_ifindex = 0;
int br_added = 0;
@@ -428,7 +438,7 @@
bss = wpa_driver_nl80211_drv_init(hapd, params->ifname,
params->global_priv, 1,
@@ -7668,21 +7669,17 @@ static void *i802_init(struct hostapd_da
@@ -7673,21 +7674,17 @@ static void *i802_init(struct hostapd_da
(params->num_bridge == 0 || !params->bridge[0]))
add_ifidx(drv, br_ifindex, drv->ifindex);
@@ -460,7 +470,7 @@
}
if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) {
@@ -8041,6 +8038,50 @@ static int wpa_driver_nl80211_if_remove(
@@ -8047,6 +8044,50 @@ static int wpa_driver_nl80211_if_remove(
return 0;
}
@@ -511,7 +521,7 @@
static int cookie_handler(struct nl_msg *msg, void *arg)
{
@@ -9385,6 +9426,37 @@ static int driver_nl80211_if_remove(void
@@ -9391,6 +9432,37 @@ static int driver_nl80211_if_remove(void
}
@@ -549,7 +559,7 @@
static int driver_nl80211_send_mlme(void *priv, const u8 *data,
size_t data_len, int noack,
unsigned int freq,
@@ -11967,6 +12039,8 @@ const struct wpa_driver_ops wpa_driver_n
@@ -11973,6 +12045,8 @@ const struct wpa_driver_ops wpa_driver_n
.set_acl = wpa_driver_nl80211_set_acl,
.if_add = wpa_driver_nl80211_if_add,
.if_remove = driver_nl80211_if_remove,

View File

@@ -1,6 +1,6 @@
--- a/src/ap/ieee802_11.c
+++ b/src/ap/ieee802_11.c
@@ -57,6 +57,15 @@
@@ -57,6 +57,17 @@
#include "gas_query_ap.h"
@@ -8,6 +8,8 @@
+ewma(int new, int old)
+{
+ #define ALPHA 10
+ if (!old)
+ return new;
+ if (new >= 0)
+ return old;
+ return ((ALPHA * new) + ((100 - ALPHA) * old)) / 100;

View File

@@ -153,7 +153,7 @@ hostapd_bss_ban_client(struct hostapd_data *hapd, u8 *addr, int time)
}
}
eloop_register_timeout(0, time * 1000, hostapd_bss_del_ban, ban, hapd);
eloop_register_timeout(time, 0, hostapd_bss_del_ban, ban, hapd);
}
static int
@@ -305,6 +305,8 @@ hostapd_bss_get_clients(struct ubus_context *ctx, struct ubus_object *obj,
blobmsg_add_u32(&b, "rx", sta_driver_data.current_rx_rate * 100);
blobmsg_add_u32(&b, "tx", sta_driver_data.current_tx_rate * 100);
blobmsg_close_table(&b, r);
blobmsg_add_u32(&b, "retries", sta_driver_data.tx_retry_count);
blobmsg_add_u32(&b, "failed", sta_driver_data.tx_retry_failed);
blobmsg_add_u32(&b, "signal", sta_driver_data.signal);
r = blobmsg_open_table(&b, "mcs");

View File

@@ -471,6 +471,9 @@ uc_hostapd_iface_stop(uc_vm_t *vm, size_t nargs)
struct hostapd_iface *iface = uc_fn_thisval("hostapd.iface");
int i;
if (!iface)
return NULL;
switch (iface->state) {
case HAPD_IFACE_ENABLED:
case HAPD_IFACE_DISABLED:

View File

@@ -26,7 +26,6 @@ function iface_remove(cfg)
if (!cfg || !cfg.bss || !cfg.bss[0] || !cfg.bss[0].ifname)
return;
hostapd.remove_iface(cfg.bss[0].ifname);
for (let bss in cfg.bss)
wdev_remove(bss.ifname);
}
@@ -95,14 +94,14 @@ function iface_add(phy, config, phy_status)
let config_inline = iface_gen_config(phy, config, !!phy_status);
let bss = config.bss[0];
let ret = hostapd.add_iface(`bss_config=${bss.ifname}:${config_inline}`);
let ret = hostapd.add_iface(`bss_config=${phy}:${config_inline}`);
if (ret < 0)
return false;
if (!phy_status)
return true;
let iface = hostapd.interfaces[bss.ifname];
let iface = hostapd.interfaces[phy];
if (!iface)
return false;
@@ -127,6 +126,7 @@ function iface_restart(phydev, config, old_config)
{
let phy = phydev.name;
hostapd.remove_iface(phy);
iface_remove(old_config);
iface_remove(config);
@@ -267,13 +267,13 @@ function iface_reload_config(phydev, config, old_config)
if (!old_config.bss || !old_config.bss[0])
return false;
let iface_name = old_config.bss[0].ifname;
let iface = hostapd.interfaces[iface_name];
let iface = hostapd.interfaces[phy];
if (!iface) {
hostapd.printf(`Could not find previous interface ${iface_name}`);
return false;
}
let iface_name = old_config.bss[0].ifname;
let first_bss = hostapd.bss[iface_name];
if (!first_bss) {
hostapd.printf(`Could not find bss of previous interface ${iface_name}`);
@@ -512,8 +512,10 @@ function iface_set_config(phy, config)
hostapd.data.config[phy] = config;
if (!config)
if (!config) {
hostapd.remove_iface(phy);
return iface_remove(old_config);
}
let phydev = phy_open(phy);
if (!phydev) {
@@ -667,7 +669,7 @@ let main_obj = {
if (!config || !config.bss || !config.bss[0] || !config.bss[0].ifname)
return 0;
let iface = hostapd.interfaces[config.bss[0].ifname];
let iface = hostapd.interfaces[phy];
if (!iface)
return 0;

View File

@@ -13,6 +13,7 @@ start_service() {
procd_open_instance hostapd
procd_set_param command /usr/sbin/hostapd -s -g /var/run/hostapd/global
procd_set_param respawn 3600 1 0
procd_set_param limits core="unlimited"
[ -x /sbin/ujail -a -e /etc/capabilities/wpad.json ] && {
procd_add_jail hostapd
procd_set_param capabilities /etc/capabilities/wpad.json
@@ -29,6 +30,7 @@ start_service() {
procd_open_instance supplicant
procd_set_param command /usr/sbin/wpa_supplicant -n -s -g /var/run/wpa_supplicant/global
procd_set_param respawn 3600 1 0
procd_set_param limits core="unlimited"
[ -x /sbin/ujail -a -e /etc/capabilities/wpad.json ] && {
procd_add_jail wpa_supplicant
procd_set_param capabilities /etc/capabilities/wpad.json

View File

@@ -0,0 +1,28 @@
From: Felix Fietkau <nbd@nbd.name>
Date: Wed, 20 Sep 2023 13:41:10 +0200
Subject: [PATCH] hostapd: cancel channel_list_update_timeout in
hostapd_cleanup_iface_partial
Fixes a crash when disabling an interface during channel list update
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
--- a/src/ap/hostapd.c
+++ b/src/ap/hostapd.c
@@ -501,6 +501,7 @@ static void sta_track_deinit(struct host
void hostapd_cleanup_iface_partial(struct hostapd_iface *iface)
{
wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
+ eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
#ifdef NEED_AP_MLME
hostapd_stop_setup_timers(iface);
#endif /* NEED_AP_MLME */
@@ -529,7 +530,6 @@ void hostapd_cleanup_iface_partial(struc
static void hostapd_cleanup_iface(struct hostapd_iface *iface)
{
wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
- eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
eloop_cancel_timeout(hostapd_interface_setup_failure_handler, iface,
NULL);

View File

@@ -107,14 +107,14 @@
hostapd_ubus_free_bss(hapd);
accounting_deinit(hapd);
hostapd_deinit_wpa(hapd);
@@ -530,6 +533,7 @@ void hostapd_cleanup_iface_partial(struc
static void hostapd_cleanup_iface(struct hostapd_iface *iface)
@@ -502,6 +505,7 @@ static void sta_track_deinit(struct host
void hostapd_cleanup_iface_partial(struct hostapd_iface *iface)
{
wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
+ hostapd_ucode_free_iface(iface);
eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
eloop_cancel_timeout(hostapd_interface_setup_failure_handler, iface,
NULL);
#ifdef NEED_AP_MLME
hostapd_stop_setup_timers(iface);
@@ -1104,7 +1108,7 @@ static int db_table_create_radius_attrib
* initialized. Most of the modules that are initialized here will be
* deinitialized in hostapd_cleanup().
@@ -159,6 +159,16 @@
hostapd_cleanup(hapd);
hapd_iface->bss[hapd_iface->num_bss - 1] = NULL;
hapd_iface->conf->num_bss--;
@@ -3137,7 +3142,8 @@ int hostapd_remove_iface(struct hapd_int
hapd_iface = interfaces->iface[i];
if (hapd_iface == NULL)
return -1;
- if (!os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
+ if (!os_strcmp(hapd_iface->phy, buf) ||
+ !os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
wpa_printf(MSG_INFO, "Remove interface '%s'", buf);
hapd_iface->driver_ap_teardown =
!!(hapd_iface->drv_flags &
--- a/wpa_supplicant/Makefile
+++ b/wpa_supplicant/Makefile
@@ -172,8 +172,20 @@ endif
@@ -402,7 +412,7 @@
{
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -1222,7 +1222,7 @@ static void wpa_driver_nl80211_event_rtm
@@ -1224,7 +1224,7 @@ static void wpa_driver_nl80211_event_rtm
}
wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)",
namebuf, ifname);
@@ -411,7 +421,7 @@
wpa_printf(MSG_DEBUG,
"nl80211: Not the main interface (%s) - do not indicate interface down",
drv->first_bss->ifname);
@@ -1258,7 +1258,7 @@ static void wpa_driver_nl80211_event_rtm
@@ -1260,7 +1260,7 @@ static void wpa_driver_nl80211_event_rtm
}
wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)",
namebuf, ifname);
@@ -420,7 +430,7 @@
wpa_printf(MSG_DEBUG,
"nl80211: Not the main interface (%s) - do not indicate interface up",
drv->first_bss->ifname);
@@ -7609,6 +7609,7 @@ static void *i802_init(struct hostapd_da
@@ -7614,6 +7614,7 @@ static void *i802_init(struct hostapd_da
char master_ifname[IFNAMSIZ];
int ifindex, br_ifindex = 0;
int br_added = 0;
@@ -428,7 +438,7 @@
bss = wpa_driver_nl80211_drv_init(hapd, params->ifname,
params->global_priv, 1,
@@ -7668,21 +7669,17 @@ static void *i802_init(struct hostapd_da
@@ -7673,21 +7674,17 @@ static void *i802_init(struct hostapd_da
(params->num_bridge == 0 || !params->bridge[0]))
add_ifidx(drv, br_ifindex, drv->ifindex);
@@ -460,7 +470,7 @@
}
if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) {
@@ -8041,6 +8038,50 @@ static int wpa_driver_nl80211_if_remove(
@@ -8047,6 +8044,50 @@ static int wpa_driver_nl80211_if_remove(
return 0;
}
@@ -511,7 +521,7 @@
static int cookie_handler(struct nl_msg *msg, void *arg)
{
@@ -9385,6 +9426,37 @@ static int driver_nl80211_if_remove(void
@@ -9391,6 +9432,37 @@ static int driver_nl80211_if_remove(void
}
@@ -549,7 +559,7 @@
static int driver_nl80211_send_mlme(void *priv, const u8 *data,
size_t data_len, int noack,
unsigned int freq,
@@ -11967,6 +12039,8 @@ const struct wpa_driver_ops wpa_driver_n
@@ -11973,6 +12045,8 @@ const struct wpa_driver_ops wpa_driver_n
.set_acl = wpa_driver_nl80211_set_acl,
.if_add = wpa_driver_nl80211_if_add,
.if_remove = driver_nl80211_if_remove,

View File

@@ -1,6 +1,6 @@
--- a/src/ap/ieee802_11.c
+++ b/src/ap/ieee802_11.c
@@ -57,6 +57,15 @@
@@ -57,6 +57,17 @@
#include "gas_query_ap.h"
@@ -8,6 +8,8 @@
+ewma(int new, int old)
+{
+ #define ALPHA 10
+ if (!old)
+ return new;
+ if (new >= 0)
+ return old;
+ return ((ALPHA * new) + ((100 - ALPHA) * old)) / 100;

View File

@@ -153,7 +153,7 @@ hostapd_bss_ban_client(struct hostapd_data *hapd, u8 *addr, int time)
}
}
eloop_register_timeout(0, time * 1000, hostapd_bss_del_ban, ban, hapd);
eloop_register_timeout(time, 0, hostapd_bss_del_ban, ban, hapd);
}
static int
@@ -305,6 +305,8 @@ hostapd_bss_get_clients(struct ubus_context *ctx, struct ubus_object *obj,
blobmsg_add_u32(&b, "rx", sta_driver_data.current_rx_rate * 100);
blobmsg_add_u32(&b, "tx", sta_driver_data.current_tx_rate * 100);
blobmsg_close_table(&b, r);
blobmsg_add_u32(&b, "retries", sta_driver_data.tx_retry_count);
blobmsg_add_u32(&b, "failed", sta_driver_data.tx_retry_failed);
blobmsg_add_u32(&b, "signal", sta_driver_data.signal);
r = blobmsg_open_table(&b, "mcs");

View File

@@ -471,6 +471,9 @@ uc_hostapd_iface_stop(uc_vm_t *vm, size_t nargs)
struct hostapd_iface *iface = uc_fn_thisval("hostapd.iface");
int i;
if (!iface)
return NULL;
switch (iface->state) {
case HAPD_IFACE_ENABLED:
case HAPD_IFACE_DISABLED: