hostapd: enhance wifi reload
authorJohn Crispin <john@phrozen.org>
Tue, 25 Feb 2020 16:01:55 +0000 (17:01 +0100)
committerJohn Crispin <john@phrozen.org>
Tue, 25 Feb 2020 16:01:55 +0000 (17:01 +0100)
Add a radio_config_id property. If the radio config changes return an error
upon receiving the reconf call.

Signed-off-by: John Crispin <john@phrozen.org>
package/network/services/hostapd/patches/700-wifi-reload.patch
package/network/services/hostapd/src/src/ap/ubus.c

index b21ae85..fa557b7 100644 (file)
@@ -1,5 +1,7 @@
---- a/hostapd/config_file.c
-+++ b/hostapd/config_file.c
+Index: hostapd-2019-08-08-ca8c2bd2/hostapd/config_file.c
+===================================================================
+--- hostapd-2019-08-08-ca8c2bd2.orig/hostapd/config_file.c
++++ hostapd-2019-08-08-ca8c2bd2/hostapd/config_file.c
 @@ -2470,6 +2470,8 @@ static int hostapd_config_fill(struct ho
                bss->isolate = atoi(pos);
        } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
@@ -9,8 +11,19 @@
        } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
                bss->skip_inactivity_poll = atoi(pos);
        } else if (os_strcmp(buf, "country_code") == 0) {
---- a/src/ap/ap_config.c
-+++ b/src/ap/ap_config.c
+@@ -3131,6 +3133,8 @@ static int hostapd_config_fill(struct ho
+               }
+       } else if (os_strcmp(buf, "acs_exclude_dfs") == 0) {
+               conf->acs_exclude_dfs = atoi(pos);
++      } else if (os_strcmp(buf, "radio_config_id") == 0) {
++                      conf->config_id = os_strdup(pos);
+       } else if (os_strcmp(buf, "channel") == 0) {
+               if (os_strcmp(pos, "acs_survey") == 0) {
+ #ifndef CONFIG_ACS
+Index: hostapd-2019-08-08-ca8c2bd2/src/ap/ap_config.c
+===================================================================
+--- hostapd-2019-08-08-ca8c2bd2.orig/src/ap/ap_config.c
++++ hostapd-2019-08-08-ca8c2bd2/src/ap/ap_config.c
 @@ -698,6 +698,7 @@ void hostapd_config_free_bss(struct host
        os_free(conf->radius_req_attr_sqlite);
        os_free(conf->rsn_preauth_interfaces);
        os_free(conf->ca_cert);
        os_free(conf->server_cert);
        os_free(conf->server_cert2);
---- a/src/ap/ap_config.h
-+++ b/src/ap/ap_config.h
+@@ -881,6 +882,7 @@ void hostapd_config_free(struct hostapd_
+       for (i = 0; i < conf->num_bss; i++)
+               hostapd_config_free_bss(conf->bss[i]);
++      os_free(conf->config_id);
+       os_free(conf->bss);
+       os_free(conf->supported_rates);
+       os_free(conf->basic_rates);
+Index: hostapd-2019-08-08-ca8c2bd2/src/ap/ap_config.h
+===================================================================
+--- hostapd-2019-08-08-ca8c2bd2.orig/src/ap/ap_config.h
++++ hostapd-2019-08-08-ca8c2bd2/src/ap/ap_config.h
 @@ -829,6 +829,7 @@ struct hostapd_bss_config {
         */
        u8 mka_psk_set;
  };
  
  /**
---- a/src/ap/hostapd.c
-+++ b/src/ap/hostapd.c
-@@ -242,13 +242,13 @@ int hostapd_reload_config(struct hostapd
+@@ -1012,6 +1013,7 @@ struct hostapd_config {
+       unsigned int airtime_update_interval;
+ #define AIRTIME_MODE_MAX (__AIRTIME_MODE_MAX - 1)
+ #endif /* CONFIG_AIRTIME_POLICY */
++      char *config_id;
+ };
+Index: hostapd-2019-08-08-ca8c2bd2/src/ap/hostapd.c
+===================================================================
+--- hostapd-2019-08-08-ca8c2bd2.orig/src/ap/hostapd.c
++++ hostapd-2019-08-08-ca8c2bd2/src/ap/hostapd.c
+@@ -206,6 +206,10 @@ static int hostapd_iface_conf_changed(st
+ {
+       size_t i;
++      if (newconf->config_id != oldconf->config_id)
++              if (strcmp(newconf->config_id, oldconf->config_id))
++                      return 1;
++
+       if (newconf->num_bss != oldconf->num_bss)
+               return 1;
+@@ -219,7 +223,7 @@ static int hostapd_iface_conf_changed(st
+ }
+-int hostapd_reload_config(struct hostapd_iface *iface)
++int hostapd_reload_config(struct hostapd_iface *iface, int reconf)
+ {
+       struct hapd_interfaces *interfaces = iface->interfaces;
+       struct hostapd_data *hapd = iface->bss[0];
+@@ -242,13 +246,16 @@ int hostapd_reload_config(struct hostapd
        if (newconf == NULL)
                return -1;
  
                char *fname;
                int res;
  
++              if (reconf)
++                      return -1;
++
 +              hostapd_clear_old(iface);
 +
                wpa_printf(MSG_DEBUG,
                           "Configuration changes include interface/BSS modification - force full disable+enable sequence");
                fname = os_strdup(iface->config_fname);
-@@ -273,6 +273,22 @@ int hostapd_reload_config(struct hostapd
+@@ -273,6 +280,22 @@ int hostapd_reload_config(struct hostapd
                        wpa_printf(MSG_ERROR,
                                   "Failed to enable interface on config reload");
                return res;
        }
        iface->conf = newconf;
  
-@@ -289,6 +305,12 @@ int hostapd_reload_config(struct hostapd
+@@ -289,6 +312,12 @@ int hostapd_reload_config(struct hostapd
  
        for (j = 0; j < iface->num_bss; j++) {
                hapd = iface->bss[j];
                hapd->iconf = newconf;
                hapd->conf = newconf->bss[j];
                hostapd_reload_bss(hapd);
-@@ -2257,6 +2279,10 @@ hostapd_alloc_bss_data(struct hostapd_if
+@@ -2257,6 +2286,10 @@ hostapd_alloc_bss_data(struct hostapd_if
        hapd->iconf = conf;
        hapd->conf = bss;
        hapd->iface = hapd_iface;
        if (conf)
                hapd->driver = conf->driver;
        hapd->ctrl_sock = -1;
---- a/src/ap/hostapd.h
-+++ b/src/ap/hostapd.h
+Index: hostapd-2019-08-08-ca8c2bd2/src/ap/hostapd.h
+===================================================================
+--- hostapd-2019-08-08-ca8c2bd2.orig/src/ap/hostapd.h
++++ hostapd-2019-08-08-ca8c2bd2/src/ap/hostapd.h
+@@ -42,7 +42,7 @@ struct mesh_conf;
+ struct hostapd_iface;
+ struct hapd_interfaces {
+-      int (*reload_config)(struct hostapd_iface *iface);
++      int (*reload_config)(struct hostapd_iface *iface, int reconf);
+       struct hostapd_config * (*config_read_cb)(const char *config_fname);
+       int (*ctrl_iface_init)(struct hostapd_data *hapd);
+       void (*ctrl_iface_deinit)(struct hostapd_data *hapd);
 @@ -149,6 +149,7 @@ struct hostapd_data {
        struct hostapd_config *iconf;
        struct hostapd_bss_config *conf;
        int interface_added; /* virtual interface added for this BSS */
        unsigned int started:1;
        unsigned int disabled:1;
---- a/src/drivers/driver_nl80211.c
-+++ b/src/drivers/driver_nl80211.c
+@@ -576,7 +577,7 @@ struct hostapd_iface {
+ int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
+                              int (*cb)(struct hostapd_iface *iface,
+                                        void *ctx), void *ctx);
+-int hostapd_reload_config(struct hostapd_iface *iface);
++int hostapd_reload_config(struct hostapd_iface *iface, int reconf);
+ void hostapd_reconfig_encryption(struct hostapd_data *hapd);
+ struct hostapd_data *
+ hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
+Index: hostapd-2019-08-08-ca8c2bd2/src/drivers/driver_nl80211.c
+===================================================================
+--- hostapd-2019-08-08-ca8c2bd2.orig/src/drivers/driver_nl80211.c
++++ hostapd-2019-08-08-ca8c2bd2/src/drivers/driver_nl80211.c
 @@ -4295,6 +4295,9 @@ static int wpa_driver_nl80211_set_ap(voi
        if (ret) {
                wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)",
        } else {
                bss->beacon_set = 1;
                nl80211_set_bss(bss, params->cts_protect, params->preamble,
+Index: hostapd-2019-08-08-ca8c2bd2/hostapd/ctrl_iface.c
+===================================================================
+--- hostapd-2019-08-08-ca8c2bd2.orig/hostapd/ctrl_iface.c
++++ hostapd-2019-08-08-ca8c2bd2/hostapd/ctrl_iface.c
+@@ -182,7 +182,7 @@ static int hostapd_ctrl_iface_update(str
+       iface->interfaces->config_read_cb = hostapd_ctrl_iface_config_read;
+       reload_opts = txt;
+-      hostapd_reload_config(iface);
++      hostapd_reload_config(iface, 0);
+       iface->interfaces->config_read_cb = config_read_cb;
+ }
+Index: hostapd-2019-08-08-ca8c2bd2/hostapd/main.c
+===================================================================
+--- hostapd-2019-08-08-ca8c2bd2.orig/hostapd/main.c
++++ hostapd-2019-08-08-ca8c2bd2/hostapd/main.c
+@@ -320,7 +320,7 @@ static void handle_term(int sig, void *s
+ static int handle_reload_iface(struct hostapd_iface *iface, void *ctx)
+ {
+-      if (hostapd_reload_config(iface) < 0) {
++      if (hostapd_reload_config(iface, 0) < 0) {
+               wpa_printf(MSG_WARNING, "Failed to read new configuration "
+                          "file - continuing with old.");
+       }
+Index: hostapd-2019-08-08-ca8c2bd2/src/ap/wps_hostapd.c
+===================================================================
+--- hostapd-2019-08-08-ca8c2bd2.orig/src/ap/wps_hostapd.c
++++ hostapd-2019-08-08-ca8c2bd2/src/ap/wps_hostapd.c
+@@ -275,7 +275,7 @@ static void wps_reload_config(void *eloo
+       wpa_printf(MSG_DEBUG, "WPS: Reload configuration data");
+       if (iface->interfaces == NULL ||
+-          iface->interfaces->reload_config(iface) < 0) {
++          iface->interfaces->reload_config(iface, 1) < 0) {
+               wpa_printf(MSG_WARNING, "WPS: Failed to reload the updated "
+                          "configuration");
+       }
index e25c329..5ed6e18 100644 (file)
@@ -152,8 +152,7 @@ hostapd_bss_reload(struct ubus_context *ctx, struct ubus_object *obj,
                   struct blob_attr *msg)
 {
        struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj);
-       hostapd_reload_config(hapd->iface);
-       hostapd_reload_iface(hapd->iface);
+       return hostapd_reload_config(hapd->iface, 1);
 }
 
 static int