confd: wifi: Fix issue with reconfigure modes on a wifi radio

The previous mode was not teardowned correctly
This commit is contained in:
Mattias Walström
2026-06-30 09:18:52 +02:00
parent 84dfaf7c03
commit d0d95f4098
2 changed files with 29 additions and 16 deletions
+24 -2
View File
@@ -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");
+5 -14
View File
@@ -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;