]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
hostapd: Make hostapd_config::bss array of pointers
authorJouni Malinen <jouni@qca.qualcomm.com>
Tue, 29 Oct 2013 14:23:23 +0000 (16:23 +0200)
committerJouni Malinen <j@w1.fi>
Tue, 29 Oct 2013 14:58:21 +0000 (16:58 +0200)
This makes it more convenient to move BSS configuration entries between
struct hostapd_config instances to clean up per-BSS configuration file
design.

Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>

hostapd/config_file.c
hostapd/main.c
src/ap/ap_config.c
src/ap/ap_config.h
src/ap/hostapd.c
wpa_supplicant/ap.c

index dc676ed46e483462a3cb89084fcca16eb44d0caf..1d785507c252f637d27e0140c09304cd2480ea48 100644 (file)
@@ -748,21 +748,21 @@ static int hostapd_parse_intlist(int **int_list, char *val)
 
 static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
 {
-       struct hostapd_bss_config *bss;
+       struct hostapd_bss_config **all, *bss;
 
        if (*ifname == '\0')
                return -1;
 
-       bss = os_realloc_array(conf->bss, conf->num_bss + 1,
-                              sizeof(struct hostapd_bss_config));
-       if (bss == NULL) {
+       all = os_realloc_array(conf->bss, conf->num_bss + 1,
+                              sizeof(struct hostapd_bss_config *));
+       if (all == NULL) {
                wpa_printf(MSG_ERROR, "Failed to allocate memory for "
                           "multi-BSS entry");
                return -1;
        }
-       conf->bss = bss;
+       conf->bss = all;
 
-       bss = &(conf->bss[conf->num_bss]);
+       bss = conf->bss[conf->num_bss];
        os_memset(bss, 0, sizeof(*bss));
        bss->radius = os_zalloc(sizeof(*bss->radius));
        if (bss->radius == NULL) {
@@ -1143,13 +1143,13 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
                size_t i;
 
                for (i = 0; i < conf->num_bss; i++) {
-                       if ((&conf->bss[i] != bss) &&
-                           (hostapd_mac_comp(conf->bss[i].bssid,
+                       if (conf->bss[i] != bss &&
+                           (hostapd_mac_comp(conf->bss[i]->bssid,
                                              bss->bssid) == 0)) {
                                wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
                                           " on interface '%s' and '%s'.",
                                           MAC2STR(bss->bssid),
-                                          conf->bss[i].iface, bss->iface);
+                                          conf->bss[i]->iface, bss->iface);
                                return -1;
                        }
                }
@@ -1245,7 +1245,7 @@ static int hostapd_config_check(struct hostapd_config *conf)
        }
 
        for (i = 0; i < conf->num_bss; i++) {
-               if (hostapd_config_check_bss(&conf->bss[i], conf))
+               if (hostapd_config_check_bss(conf->bss[i], conf))
                        return -1;
        }
 
@@ -1752,8 +1752,8 @@ static int hostapd_config_fill(struct hostapd_config *conf,
 
        {
                if (os_strcmp(buf, "interface") == 0) {
-                       os_strlcpy(conf->bss[0].iface, pos,
-                                  sizeof(conf->bss[0].iface));
+                       os_strlcpy(conf->bss[0]->iface, pos,
+                                  sizeof(conf->bss[0]->iface));
                } else if (os_strcmp(buf, "bridge") == 0) {
                        os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
                } else if (os_strcmp(buf, "vlan_bridge") == 0) {
@@ -3157,7 +3157,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
                return NULL;
        }
 
-       bss = conf->last_bss = conf->bss;
+       bss = conf->last_bss = conf->bss[0];
 
        while (fgets(buf, sizeof(buf), f)) {
                bss = conf->last_bss;
@@ -3191,7 +3191,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
        fclose(f);
 
        for (i = 0; i < conf->num_bss; i++)
-               hostapd_set_security_params(&conf->bss[i]);
+               hostapd_set_security_params(conf->bss[i]);
 
        if (hostapd_config_check(conf))
                errors++;
@@ -3223,7 +3223,7 @@ int hostapd_set_iface(struct hostapd_config *conf,
        }
 
        for (i = 0; i < conf->num_bss; i++)
-               hostapd_set_security_params(&conf->bss[i]);
+               hostapd_set_security_params(conf->bss[i]);
 
        if (hostapd_config_check(conf)) {
                wpa_printf(MSG_ERROR, "Configuration check failed");
index 6a673479542bbc39b96729f010d0b18928d6a667..ab75b5fe6d9b8d8ea190c24a68c02ae3fb5c6d49 100644 (file)
@@ -185,7 +185,7 @@ static struct hostapd_iface * hostapd_init(const char *config_file)
        for (i = 0; i < conf->num_bss; i++) {
                hapd = hapd_iface->bss[i] =
                        hostapd_alloc_bss_data(hapd_iface, conf,
-                                              &conf->bss[i]);
+                                              conf->bss[i]);
                if (hapd == NULL)
                        goto fail;
                hapd->msg_ctx = hapd;
@@ -313,7 +313,7 @@ hostapd_interface_init(struct hapd_interfaces *interfaces,
                        iface->bss[0]->conf->logger_stdout_level--;
        }
 
-       if (iface->conf->bss[0].iface[0] == '\0' &&
+       if (iface->conf->bss[0]->iface[0] == '\0' &&
            !hostapd_drv_none(iface->bss[0])) {
                wpa_printf(MSG_ERROR, "Interface name not specified in %s",
                           config_fname);
@@ -526,8 +526,9 @@ static void usage(void)
 static const char * hostapd_msg_ifname_cb(void *ctx)
 {
        struct hostapd_data *hapd = ctx;
-       if (hapd && hapd->iconf && hapd->iconf->bss)
-               return hapd->iconf->bss->iface;
+       if (hapd && hapd->iconf && hapd->iconf->bss &&
+           hapd->iconf->num_bss > 0 && hapd->iconf->bss[0])
+               return hapd->iconf->bss[0]->iface;
        return NULL;
 }
 
index caf75c4d59c15d16a4d4f6bcbe0b0b51487aefe3..7295bedb6761414c3362fab66767bce9d19282f9 100644 (file)
@@ -130,6 +130,13 @@ struct hostapd_config * hostapd_config_defaults(void)
                os_free(bss);
                return NULL;
        }
+       conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *));
+       if (conf->bss == NULL) {
+               os_free(conf);
+               os_free(bss);
+               return NULL;
+       }
+       conf->bss[0] = bss;
 
        bss->radius = os_zalloc(sizeof(*bss->radius));
        if (bss->radius == NULL) {
@@ -141,7 +148,6 @@ struct hostapd_config * hostapd_config_defaults(void)
        hostapd_config_defaults_bss(bss);
 
        conf->num_bss = 1;
-       conf->bss = bss;
 
        conf->beacon_int = 100;
        conf->rts_threshold = -1; /* use driver default: 2347 */
@@ -525,6 +531,8 @@ static void hostapd_config_free_bss(struct hostapd_bss_config *conf)
        os_free(conf->sae_groups);
 
        os_free(conf->server_id);
+
+       os_free(conf);
 }
 
 
@@ -540,7 +548,7 @@ void hostapd_config_free(struct hostapd_config *conf)
                return;
 
        for (i = 0; i < conf->num_bss; i++)
-               hostapd_config_free_bss(&conf->bss[i]);
+               hostapd_config_free_bss(conf->bss[i]);
        os_free(conf->bss);
        os_free(conf->supported_rates);
        os_free(conf->basic_rates);
index a9fc15a009bc761432f7a87d9f304e786c14cfcf..8f536ea3f434ced74fb3375976365a18c2fa4d4e 100644 (file)
@@ -481,7 +481,7 @@ struct hostapd_bss_config {
  * struct hostapd_config - Per-radio interface configuration
  */
 struct hostapd_config {
-       struct hostapd_bss_config *bss, *last_bss;
+       struct hostapd_bss_config **bss, *last_bss;
        size_t num_bss;
 
        u16 beacon_int;
index 6e7b37f9abe202ffe203fee774be5a6d2e1792b9..8f91bf8d538dc9e926aba9a004540d31225ec831 100644 (file)
@@ -172,7 +172,7 @@ int hostapd_reload_config(struct hostapd_iface *iface)
        for (j = 0; j < iface->num_bss; j++) {
                hapd = iface->bss[j];
                hapd->iconf = newconf;
-               hapd->conf = &newconf->bss[j];
+               hapd->conf = newconf->bss[j];
                hostapd_reload_bss(hapd);
        }
 
@@ -442,7 +442,7 @@ static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface)
        /* Determine the bits necessary to any configured BSSIDs,
           if they are higher than the number of BSSIDs. */
        for (j = 0; j < iface->conf->num_bss; j++) {
-               if (hostapd_mac_comp_empty(iface->conf->bss[j].bssid) == 0) {
+               if (hostapd_mac_comp_empty(iface->conf->bss[j]->bssid) == 0) {
                        if (j)
                                auto_addr++;
                        continue;
@@ -450,7 +450,7 @@ static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface)
 
                for (i = 0; i < ETH_ALEN; i++) {
                        mask[i] |=
-                               iface->conf->bss[j].bssid[i] ^
+                               iface->conf->bss[j]->bssid[i] ^
                                hapd->own_addr[i];
                }
        }
@@ -515,7 +515,7 @@ static int mac_in_conf(struct hostapd_config *conf, const void *a)
        size_t i;
 
        for (i = 0; i < conf->num_bss; i++) {
-               if (hostapd_mac_comp(conf->bss[i].bssid, a) == 0) {
+               if (hostapd_mac_comp(conf->bss[i]->bssid, a) == 0) {
                        return 1;
                }
        }
@@ -862,14 +862,15 @@ static void hostapd_set_acl(struct hostapd_data *hapd)
 
        if (hapd->iface->drv_max_acl_mac_addrs == 0)
                return;
-       if (!(conf->bss->num_accept_mac || conf->bss->num_deny_mac))
+       if (!(conf->bss[0]->num_accept_mac || conf->bss[0]->num_deny_mac))
                return;
 
-       if (conf->bss->macaddr_acl == DENY_UNLESS_ACCEPTED) {
-               if (conf->bss->num_accept_mac) {
+       if (conf->bss[0]->macaddr_acl == DENY_UNLESS_ACCEPTED) {
+               if (conf->bss[0]->num_accept_mac) {
                        accept_acl = 1;
-                       err = hostapd_set_acl_list(hapd, conf->bss->accept_mac,
-                                                  conf->bss->num_accept_mac,
+                       err = hostapd_set_acl_list(hapd,
+                                                  conf->bss[0]->accept_mac,
+                                                  conf->bss[0]->num_accept_mac,
                                                   accept_acl);
                        if (err) {
                                wpa_printf(MSG_DEBUG, "Failed to set accept acl");
@@ -878,11 +879,11 @@ static void hostapd_set_acl(struct hostapd_data *hapd)
                } else {
                        wpa_printf(MSG_DEBUG, "Mismatch between ACL Policy & Accept/deny lists file");
                }
-       } else if (conf->bss->macaddr_acl == ACCEPT_UNLESS_DENIED) {
-               if (conf->bss->num_deny_mac) {
+       } else if (conf->bss[0]->macaddr_acl == ACCEPT_UNLESS_DENIED) {
+               if (conf->bss[0]->num_deny_mac) {
                        accept_acl = 0;
-                       err = hostapd_set_acl_list(hapd, conf->bss->deny_mac,
-                                                  conf->bss->num_deny_mac,
+                       err = hostapd_set_acl_list(hapd, conf->bss[0]->deny_mac,
+                                                  conf->bss[0]->num_deny_mac,
                                                   accept_acl);
                        if (err) {
                                wpa_printf(MSG_DEBUG, "Failed to set deny acl");
@@ -1173,12 +1174,12 @@ int hostapd_enable_iface(struct hostapd_iface *hapd_iface)
 {
        if (hapd_iface->bss[0]->drv_priv != NULL) {
                wpa_printf(MSG_ERROR, "Interface %s already enabled",
-                          hapd_iface->conf->bss[0].iface);
+                          hapd_iface->conf->bss[0]->iface);
                return -1;
        }
 
        wpa_printf(MSG_DEBUG, "Enable interface %s",
-                  hapd_iface->conf->bss[0].iface);
+                  hapd_iface->conf->bss[0]->iface);
 
        if (hapd_iface->interfaces == NULL ||
            hapd_iface->interfaces->driver_init == NULL ||
@@ -1196,7 +1197,7 @@ int hostapd_reload_iface(struct hostapd_iface *hapd_iface)
        size_t j;
 
        wpa_printf(MSG_DEBUG, "Reload interface %s",
-                  hapd_iface->conf->bss[0].iface);
+                  hapd_iface->conf->bss[0]->iface);
        hostapd_clear_old(hapd_iface);
        for (j = 0; j < hapd_iface->num_bss; j++)
                hostapd_reload_bss(hapd_iface->bss[j]);
@@ -1287,7 +1288,7 @@ hostapd_config_alloc(struct hapd_interfaces *interfaces, const char *ifname,
                return NULL;
        }
 
-       bss = conf->last_bss = conf->bss;
+       bss = conf->last_bss = conf->bss[0];
 
        os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
        bss->ctrl_interface = os_strdup(ctrl_iface);
@@ -1322,8 +1323,7 @@ static struct hostapd_iface * hostapd_data_alloc(
 
        for (i = 0; i < conf->num_bss; i++) {
                hapd = hapd_iface->bss[i] =
-                       hostapd_alloc_bss_data(hapd_iface, conf,
-                                              &conf->bss[i]);
+                       hostapd_alloc_bss_data(hapd_iface, conf, conf->bss[i]);
                if (hapd == NULL)
                        return NULL;
                hapd->msg_ctx = hapd;
@@ -1352,7 +1352,7 @@ int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf)
                conf_file = ptr + 7;
 
        for (i = 0; i < interfaces->count; i++) {
-               if (!os_strcmp(interfaces->iface[i]->conf->bss[0].iface,
+               if (!os_strcmp(interfaces->iface[i]->conf->bss[0]->iface,
                               buf)) {
                        wpa_printf(MSG_INFO, "Cannot add interface - it "
                                   "already exists");
@@ -1370,8 +1370,8 @@ int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf)
        if (conf_file && interfaces->config_read_cb) {
                conf = interfaces->config_read_cb(conf_file);
                if (conf && conf->bss)
-                       os_strlcpy(conf->bss->iface, buf,
-                                  sizeof(conf->bss->iface));
+                       os_strlcpy(conf->bss[0]->iface, buf,
+                                  sizeof(conf->bss[0]->iface));
        } else
                conf = hostapd_config_alloc(interfaces, buf, ptr);
        if (conf == NULL || conf->bss == NULL) {
@@ -1394,7 +1394,7 @@ int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf)
                           "interface", __func__);
                goto fail;
        }
-       wpa_printf(MSG_INFO, "Add interface '%s'", conf->bss[0].iface);
+       wpa_printf(MSG_INFO, "Add interface '%s'", conf->bss[0]->iface);
 
        return 0;
 
@@ -1418,7 +1418,7 @@ int hostapd_remove_iface(struct hapd_interfaces *interfaces, char *buf)
                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->conf->bss[0]->iface, buf)) {
                        wpa_printf(MSG_INFO, "Remove interface '%s'", buf);
                        hostapd_interface_deinit_free(hapd_iface);
                        k = i;
index b7b58cdb34bae460df4a0582340105d97384f3d2..688746937f7de8b172d69e61f669f75a5c02e652 100644 (file)
@@ -73,7 +73,7 @@ static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
                                  struct wpa_ssid *ssid,
                                  struct hostapd_config *conf)
 {
-       struct hostapd_bss_config *bss = &conf->bss[0];
+       struct hostapd_bss_config *bss = conf->bss[0];
 
        conf->driver = wpa_s->driver;
 
@@ -561,8 +561,8 @@ int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
                  sizeof(wpa_s->conf->wmm_ac_params));
 
        if (params.uapsd > 0) {
-               conf->bss->wmm_enabled = 1;
-               conf->bss->wmm_uapsd = 1;
+               conf->bss[0]->wmm_enabled = 1;
+               conf->bss[0]->wmm_uapsd = 1;
        }
 
        if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
@@ -573,9 +573,9 @@ int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
 
 #ifdef CONFIG_P2P
        if (ssid->mode == WPAS_MODE_P2P_GO)
-               conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
+               conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
        else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
-               conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
+               conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
                        P2P_GROUP_FORMATION;
 #endif /* CONFIG_P2P */
 
@@ -590,7 +590,7 @@ int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
        for (i = 0; i < conf->num_bss; i++) {
                hapd_iface->bss[i] =
                        hostapd_alloc_bss_data(hapd_iface, conf,
-                                              &conf->bss[i]);
+                                              conf->bss[i]);
                if (hapd_iface->bss[i] == NULL) {
                        wpa_supplicant_ap_deinit(wpa_s);
                        return -1;
@@ -1042,9 +1042,9 @@ int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
 
 #ifdef CONFIG_P2P
        if (ssid->mode == WPAS_MODE_P2P_GO)
-               iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
+               iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
        else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
-               iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
+               iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
                        P2P_GROUP_FORMATION;
 #endif /* CONFIG_P2P */