From d0d95f4098655e0518b4e9235751008397715330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Sun, 28 Jun 2026 21:01:42 +0200 Subject: [PATCH] confd: wifi: Fix issue with reconfigure modes on a wifi radio The previous mode was not teardowned correctly --- src/confd/src/hardware.c | 26 ++++++++++++++++++++++++-- src/confd/src/if-wifi.c | 19 +++++-------------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/confd/src/hardware.c b/src/confd/src/hardware.c index 816396bd..f2dbb338 100644 --- a/src/confd/src/hardware.c +++ b/src/confd/src/hardware.c @@ -1379,8 +1379,32 @@ int hardware_change(sr_session_ctx_t *session, struct lyd_node *config, struct l * all radio configs, so band edits and radio add/remove both apply. */ if (wifi_changed && event == SR_EV_DONE) { + struct lyd_node *cifs; glob_t gl = { 0 }; + size_t i; + /* Need to remove old hostapd config files, for radios not used anymore */ + cifs = lydx_get_descendant(config, "interfaces", "interface", NULL); + if (glob("/etc/hostapd-*.conf", 0, NULL, &gl) == 0) { + for (i = 0; i < gl.gl_pathc; i++) { + char radio[64], **aps = NULL; + int n = 0, j; + + if (sscanf(gl.gl_pathv[i], "/etc/hostapd-%63[^.].conf", radio) != 1) + continue; + wifi_find_radio_aps(cifs, radio, &aps, &n); + for (j = 0; j < n; j++) + free(aps[j]); + free(aps); + if (!n) { + unlink(gl.gl_pathv[i]); + erasef(HOSTAPD_CONF_NEXT, radio); + } + } + globfree(&gl); + } + + gl = (glob_t){ 0 }; if (glob("/etc/hostapd-*.conf", 0, NULL, &gl) == 0 && gl.gl_pathc > 0) { FILE *fp; @@ -1389,8 +1413,6 @@ int hardware_change(sr_session_ctx_t *session, struct lyd_node *config, struct l ERRNO("Could not open " HOSTAPD_SERVICE); rc = SR_ERR_INTERNAL; } else { - size_t i; - fprintf(fp, "# Generated by confd, do not edit.\n"); fprintf(fp, "service name:hostapd \\\n"); fprintf(fp, "\t[2345] hostapd -P /run/hostapd.pid"); diff --git a/src/confd/src/if-wifi.c b/src/confd/src/if-wifi.c index 21baf77c..84653dfa 100644 --- a/src/confd/src/if-wifi.c +++ b/src/confd/src/if-wifi.c @@ -540,7 +540,6 @@ out: */ int wifi_del_iface(struct lyd_node *dif, struct dagger *net) { - struct lyd_node *wifi; const char *ifname; FILE *iw; @@ -553,22 +552,14 @@ int wifi_del_iface(struct lyd_node *dif, struct dagger *net) } fprintf(iw, "# Generated by Infix confd - WiFi Interface Deletion\n"); + + erasef(WPA_SUPPLICANT_CONF, ifname); + fprintf(iw, "initctl -bfq disable mesh@%s\n", ifname); + fprintf(iw, "initctl -bfq disable wifi@%s\n", ifname); + fprintf(iw, "ip link set %s down\n", ifname); fprintf(iw, "iw dev %s disconnect 2>/dev/null\n", ifname); fprintf(iw, "iw dev %s del 2>/dev/null || ip link del %s 2>/dev/null || true\n", ifname, ifname); - - wifi = lydx_get_child(dif, "wifi"); - if (wifi) { - int mode = wifi_get_mode(wifi); - - if (mode == wifi_mesh) { - erasef(WPA_SUPPLICANT_CONF, ifname); - fprintf(iw, "initctl -bfq disable mesh@%s\n", ifname); - } else if (mode != wifi_ap) { - erasef(WPA_SUPPLICANT_CONF, ifname); - fprintf(iw, "initctl -bfq disable wifi@%s\n", ifname); - } - } fclose(iw); return SR_ERR_OK;