From c64d2fdbd24795567ffe2bb0cebfe35eadf263ce Mon Sep 17 00:00:00 2001 From: Jakob Olsson <jakob.olsson@iopsys.eu> Date: Fri, 14 Feb 2025 16:29:09 +0000 Subject: [PATCH] remove torn-down APs from configs After receiving and applying WSC M2, remove any torn-down APs from wireless and map-agent UCI configurations. --- src/agent.c | 34 ++++++++++++++++++++++++++++++---- src/agent.h | 3 +++ src/agent_map.c | 34 ++++++++++------------------------ src/script/multiap | 26 ++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 28 deletions(-) diff --git a/src/agent.c b/src/agent.c index 506905819..0ea4df791 100644 --- a/src/agent.c +++ b/src/agent.c @@ -5645,8 +5645,7 @@ struct netif_ap *netif_alloc_ap(const char *ifname) INIT_LIST_HEAD(&n->stalist); INIT_LIST_HEAD(&n->nbrlist); INIT_LIST_HEAD(&n->restrict_stalist); - - snprintf(n->ifname, 15, "%s", ifname); + snprintf(n->ifname, sizeof(n->ifname), "%s", ifname); timer_init(&n->nbr_timer, refresh_neighbor_list); timer_init(&n->bss_timer, refresh_bssinfo); @@ -7140,6 +7139,35 @@ refresh_interval: cfg->pcfg->report_interval * 1000); } +/* remove passed interface from mapagent and wireless config, if present */ +static int wifi_clean_iface(const char *ifname) +{ + char fmt[128] = {0}; + + snprintf(fmt, sizeof(fmt), "clean_stale_ifaces %s", ifname); + agent_exec_platform_scripts(fmt); + + dbg("|%s:%d| Cleaned interface %s\n", __func__, __LINE__, ifname); + return 0; +} + +/* remove all torndown interfaces on radio from config/memory */ +int wifi_clean_torndown_ifaces(struct agent *a, struct wifi_radio_element *re) +{ + struct netif_ap *ap = NULL, *ap_tmp; + + list_for_each_entry_safe(ap, ap_tmp, &re->aplist, list) { + if (!ap->torndown) + continue; + + wifi_clean_iface(ap->ifname); + clean_ap(ap->cfg); + netif_free(ap); + } + + return 0; +} + void clear_sta(struct sta *s) { dbg("Delete STA " MACFMT "\n", MAC2STR(s->macaddr)); @@ -7192,8 +7220,6 @@ void clear_restrict_stalist(struct netif_ap *p) } } - - static void netif_reset(struct netif_ap *ap) { /* clear stalist */ diff --git a/src/agent.h b/src/agent.h index e2760b461..0f30be066 100644 --- a/src/agent.h +++ b/src/agent.h @@ -1095,6 +1095,9 @@ void reschedule_nbrlist_update(struct netif_ap *ap); void agent_disable_local_cntlr(struct agent *a); void agent_schedule_fh_disable(struct agent *a); void wifiagent_log_cntlrinfo(struct agent *a); + +int wifi_clean_torndown_ifaces(struct agent *a, struct wifi_radio_element *re); + void agent_free_radios(struct agent *a); void agent_free_cntlr_sync(struct agent *a); void clear_sta(struct sta *s); diff --git a/src/agent_map.c b/src/agent_map.c index 322665a89..578911ee3 100644 --- a/src/agent_map.c +++ b/src/agent_map.c @@ -1717,34 +1717,19 @@ int wifi_teardown_map_bsta_mld(struct agent *a, uint32_t band) int wifi_teardown_map_ifaces_by_radio(struct agent *a, char *device) { - struct netif_apcfg *ap; + struct netif_apcfg *apcfg; - list_for_each_entry(ap, &a->cfg.aplist, list) { - struct netif_ap *f; - - if (strncmp(ap->device, device, sizeof(ap->device) - 1)) - continue; - - wifi_teardown_iface(ap->name); - f = agent_get_ap_by_ifname(a, ap->name); - if (f) - f->torndown = true; - } - - agent_config_reload(a); - return 0; -} - -int wifi_teardown_map_ifaces_by_band(struct agent *a, enum wifi_band band) -{ - struct netif_apcfg *ap = NULL, *ap_tmp; + /* teardown configs */ + list_for_each_entry(apcfg, &a->cfg.aplist, list) { + struct netif_ap *ap; - list_for_each_entry_safe(ap, ap_tmp, &a->cfg.aplist, list) { - if (ap->band != band) + if (strncmp(apcfg->device, device, sizeof(apcfg->device) - 1)) continue; - wifi_teardown_iface(ap->name); - clean_ap(ap); + wifi_teardown_iface(apcfg->name); + ap = agent_get_ap_by_ifname(a, apcfg->name); + if (ap) + ap->torndown = true; } agent_config_reload(a); @@ -2788,6 +2773,7 @@ int handle_ap_autoconfig_wsc(void *agent, struct cmdu_buff *rx_cmdu, } else a->reconfig_reason |= AGENT_RECONFIG_REASON_VLAN_TEARDOWN; + wifi_clean_torndown_ifaces(a, radio); agent_exec_platform_scripts("write_credentials"); agent_config_reload(a); radio->state = AUTOCFG_HEARTBEAT; diff --git a/src/script/multiap b/src/script/multiap index fbf51fa19..16819d8ef 100755 --- a/src/script/multiap +++ b/src/script/multiap @@ -756,6 +756,31 @@ teardown_iface() { uci commit mapagent } +clean_stale_ifaces() { + local iface=$1 + + clean_ap() { + local section=$1 + local config=$2 + local iface=$3 + + config_get ifname $section ifname + + [ "$iface" != "$ifname" ] && return + + uci -q delete ${config}.${section} + } + + config_load wireless + config_foreach clean_ap wifi-iface wireless $iface + uci commit wireless + + config_load mapagent + config_foreach clean_ap ap mapagent $iface + uci commit mapagent + +} + bsta_to_wireless() { config_load mapagent @@ -1489,6 +1514,7 @@ case "$func" in write_bsta_config) write_bsta_config $@;; teardown_bsta_mld) teardown_bsta_mld $@;; teardown_iface) teardown_iface $@;; + clean_stale_ifaces) clean_stale_ifaces $@;; bsta_to_wireless) bsta_to_wireless $@;; sync_mapcontroller_from_wireless) sync_mapcontroller_from_wireless $@;; ts) ts_sub $@;; -- GitLab