hostapd: Make hostapd_config::bss array of pointers

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>
This commit is contained in:
Jouni Malinen 2013-10-29 16:23:23 +02:00 committed by Jouni Malinen
parent a781e211f9
commit ebd79f07c4
6 changed files with 63 additions and 54 deletions

View 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) 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') if (*ifname == '\0')
return -1; return -1;
bss = os_realloc_array(conf->bss, conf->num_bss + 1, all = os_realloc_array(conf->bss, conf->num_bss + 1,
sizeof(struct hostapd_bss_config)); sizeof(struct hostapd_bss_config *));
if (bss == NULL) { if (all == NULL) {
wpa_printf(MSG_ERROR, "Failed to allocate memory for " wpa_printf(MSG_ERROR, "Failed to allocate memory for "
"multi-BSS entry"); "multi-BSS entry");
return -1; 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)); os_memset(bss, 0, sizeof(*bss));
bss->radius = os_zalloc(sizeof(*bss->radius)); bss->radius = os_zalloc(sizeof(*bss->radius));
if (bss->radius == NULL) { if (bss->radius == NULL) {
@ -1143,13 +1143,13 @@ static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
size_t i; size_t i;
for (i = 0; i < conf->num_bss; i++) { for (i = 0; i < conf->num_bss; i++) {
if ((&conf->bss[i] != bss) && if (conf->bss[i] != bss &&
(hostapd_mac_comp(conf->bss[i].bssid, (hostapd_mac_comp(conf->bss[i]->bssid,
bss->bssid) == 0)) { bss->bssid) == 0)) {
wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
" on interface '%s' and '%s'.", " on interface '%s' and '%s'.",
MAC2STR(bss->bssid), MAC2STR(bss->bssid),
conf->bss[i].iface, bss->iface); conf->bss[i]->iface, bss->iface);
return -1; return -1;
} }
} }
@ -1245,7 +1245,7 @@ static int hostapd_config_check(struct hostapd_config *conf)
} }
for (i = 0; i < conf->num_bss; i++) { 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; return -1;
} }
@ -1752,8 +1752,8 @@ static int hostapd_config_fill(struct hostapd_config *conf,
{ {
if (os_strcmp(buf, "interface") == 0) { if (os_strcmp(buf, "interface") == 0) {
os_strlcpy(conf->bss[0].iface, pos, os_strlcpy(conf->bss[0]->iface, pos,
sizeof(conf->bss[0].iface)); sizeof(conf->bss[0]->iface));
} else if (os_strcmp(buf, "bridge") == 0) { } else if (os_strcmp(buf, "bridge") == 0) {
os_strlcpy(bss->bridge, pos, sizeof(bss->bridge)); os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
} else if (os_strcmp(buf, "vlan_bridge") == 0) { } else if (os_strcmp(buf, "vlan_bridge") == 0) {
@ -3157,7 +3157,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
return NULL; return NULL;
} }
bss = conf->last_bss = conf->bss; bss = conf->last_bss = conf->bss[0];
while (fgets(buf, sizeof(buf), f)) { while (fgets(buf, sizeof(buf), f)) {
bss = conf->last_bss; bss = conf->last_bss;
@ -3191,7 +3191,7 @@ struct hostapd_config * hostapd_config_read(const char *fname)
fclose(f); fclose(f);
for (i = 0; i < conf->num_bss; i++) 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)) if (hostapd_config_check(conf))
errors++; errors++;
@ -3223,7 +3223,7 @@ int hostapd_set_iface(struct hostapd_config *conf,
} }
for (i = 0; i < conf->num_bss; i++) 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)) { if (hostapd_config_check(conf)) {
wpa_printf(MSG_ERROR, "Configuration check failed"); wpa_printf(MSG_ERROR, "Configuration check failed");

View file

@ -185,7 +185,7 @@ static struct hostapd_iface * hostapd_init(const char *config_file)
for (i = 0; i < conf->num_bss; i++) { for (i = 0; i < conf->num_bss; i++) {
hapd = hapd_iface->bss[i] = hapd = hapd_iface->bss[i] =
hostapd_alloc_bss_data(hapd_iface, conf, hostapd_alloc_bss_data(hapd_iface, conf,
&conf->bss[i]); conf->bss[i]);
if (hapd == NULL) if (hapd == NULL)
goto fail; goto fail;
hapd->msg_ctx = hapd; hapd->msg_ctx = hapd;
@ -313,7 +313,7 @@ hostapd_interface_init(struct hapd_interfaces *interfaces,
iface->bss[0]->conf->logger_stdout_level--; 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])) { !hostapd_drv_none(iface->bss[0])) {
wpa_printf(MSG_ERROR, "Interface name not specified in %s", wpa_printf(MSG_ERROR, "Interface name not specified in %s",
config_fname); config_fname);
@ -526,8 +526,9 @@ static void usage(void)
static const char * hostapd_msg_ifname_cb(void *ctx) static const char * hostapd_msg_ifname_cb(void *ctx)
{ {
struct hostapd_data *hapd = ctx; struct hostapd_data *hapd = ctx;
if (hapd && hapd->iconf && hapd->iconf->bss) if (hapd && hapd->iconf && hapd->iconf->bss &&
return hapd->iconf->bss->iface; hapd->iconf->num_bss > 0 && hapd->iconf->bss[0])
return hapd->iconf->bss[0]->iface;
return NULL; return NULL;
} }

View file

@ -130,6 +130,13 @@ struct hostapd_config * hostapd_config_defaults(void)
os_free(bss); os_free(bss);
return NULL; 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)); bss->radius = os_zalloc(sizeof(*bss->radius));
if (bss->radius == NULL) { if (bss->radius == NULL) {
@ -141,7 +148,6 @@ struct hostapd_config * hostapd_config_defaults(void)
hostapd_config_defaults_bss(bss); hostapd_config_defaults_bss(bss);
conf->num_bss = 1; conf->num_bss = 1;
conf->bss = bss;
conf->beacon_int = 100; conf->beacon_int = 100;
conf->rts_threshold = -1; /* use driver default: 2347 */ 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->sae_groups);
os_free(conf->server_id); os_free(conf->server_id);
os_free(conf);
} }
@ -540,7 +548,7 @@ void hostapd_config_free(struct hostapd_config *conf)
return; return;
for (i = 0; i < conf->num_bss; i++) 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->bss);
os_free(conf->supported_rates); os_free(conf->supported_rates);
os_free(conf->basic_rates); os_free(conf->basic_rates);

View file

@ -481,7 +481,7 @@ struct hostapd_bss_config {
* struct hostapd_config - Per-radio interface configuration * struct hostapd_config - Per-radio interface configuration
*/ */
struct hostapd_config { struct hostapd_config {
struct hostapd_bss_config *bss, *last_bss; struct hostapd_bss_config **bss, *last_bss;
size_t num_bss; size_t num_bss;
u16 beacon_int; u16 beacon_int;

View file

@ -172,7 +172,7 @@ int hostapd_reload_config(struct hostapd_iface *iface)
for (j = 0; j < iface->num_bss; j++) { for (j = 0; j < iface->num_bss; j++) {
hapd = iface->bss[j]; hapd = iface->bss[j];
hapd->iconf = newconf; hapd->iconf = newconf;
hapd->conf = &newconf->bss[j]; hapd->conf = newconf->bss[j];
hostapd_reload_bss(hapd); 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, /* Determine the bits necessary to any configured BSSIDs,
if they are higher than the number of BSSIDs. */ if they are higher than the number of BSSIDs. */
for (j = 0; j < iface->conf->num_bss; j++) { 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) if (j)
auto_addr++; auto_addr++;
continue; continue;
@ -450,7 +450,7 @@ static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface)
for (i = 0; i < ETH_ALEN; i++) { for (i = 0; i < ETH_ALEN; i++) {
mask[i] |= mask[i] |=
iface->conf->bss[j].bssid[i] ^ iface->conf->bss[j]->bssid[i] ^
hapd->own_addr[i]; hapd->own_addr[i];
} }
} }
@ -515,7 +515,7 @@ static int mac_in_conf(struct hostapd_config *conf, const void *a)
size_t i; size_t i;
for (i = 0; i < conf->num_bss; 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; return 1;
} }
} }
@ -862,14 +862,15 @@ static void hostapd_set_acl(struct hostapd_data *hapd)
if (hapd->iface->drv_max_acl_mac_addrs == 0) if (hapd->iface->drv_max_acl_mac_addrs == 0)
return; 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; return;
if (conf->bss->macaddr_acl == DENY_UNLESS_ACCEPTED) { if (conf->bss[0]->macaddr_acl == DENY_UNLESS_ACCEPTED) {
if (conf->bss->num_accept_mac) { if (conf->bss[0]->num_accept_mac) {
accept_acl = 1; accept_acl = 1;
err = hostapd_set_acl_list(hapd, conf->bss->accept_mac, err = hostapd_set_acl_list(hapd,
conf->bss->num_accept_mac, conf->bss[0]->accept_mac,
conf->bss[0]->num_accept_mac,
accept_acl); accept_acl);
if (err) { if (err) {
wpa_printf(MSG_DEBUG, "Failed to set accept acl"); wpa_printf(MSG_DEBUG, "Failed to set accept acl");
@ -878,11 +879,11 @@ static void hostapd_set_acl(struct hostapd_data *hapd)
} else { } else {
wpa_printf(MSG_DEBUG, "Mismatch between ACL Policy & Accept/deny lists file"); wpa_printf(MSG_DEBUG, "Mismatch between ACL Policy & Accept/deny lists file");
} }
} else if (conf->bss->macaddr_acl == ACCEPT_UNLESS_DENIED) { } else if (conf->bss[0]->macaddr_acl == ACCEPT_UNLESS_DENIED) {
if (conf->bss->num_deny_mac) { if (conf->bss[0]->num_deny_mac) {
accept_acl = 0; accept_acl = 0;
err = hostapd_set_acl_list(hapd, conf->bss->deny_mac, err = hostapd_set_acl_list(hapd, conf->bss[0]->deny_mac,
conf->bss->num_deny_mac, conf->bss[0]->num_deny_mac,
accept_acl); accept_acl);
if (err) { if (err) {
wpa_printf(MSG_DEBUG, "Failed to set deny acl"); 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) { if (hapd_iface->bss[0]->drv_priv != NULL) {
wpa_printf(MSG_ERROR, "Interface %s already enabled", wpa_printf(MSG_ERROR, "Interface %s already enabled",
hapd_iface->conf->bss[0].iface); hapd_iface->conf->bss[0]->iface);
return -1; return -1;
} }
wpa_printf(MSG_DEBUG, "Enable interface %s", wpa_printf(MSG_DEBUG, "Enable interface %s",
hapd_iface->conf->bss[0].iface); hapd_iface->conf->bss[0]->iface);
if (hapd_iface->interfaces == NULL || if (hapd_iface->interfaces == NULL ||
hapd_iface->interfaces->driver_init == NULL || hapd_iface->interfaces->driver_init == NULL ||
@ -1196,7 +1197,7 @@ int hostapd_reload_iface(struct hostapd_iface *hapd_iface)
size_t j; size_t j;
wpa_printf(MSG_DEBUG, "Reload interface %s", wpa_printf(MSG_DEBUG, "Reload interface %s",
hapd_iface->conf->bss[0].iface); hapd_iface->conf->bss[0]->iface);
hostapd_clear_old(hapd_iface); hostapd_clear_old(hapd_iface);
for (j = 0; j < hapd_iface->num_bss; j++) for (j = 0; j < hapd_iface->num_bss; j++)
hostapd_reload_bss(hapd_iface->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; return NULL;
} }
bss = conf->last_bss = conf->bss; bss = conf->last_bss = conf->bss[0];
os_strlcpy(bss->iface, ifname, sizeof(bss->iface)); os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
bss->ctrl_interface = os_strdup(ctrl_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++) { for (i = 0; i < conf->num_bss; i++) {
hapd = hapd_iface->bss[i] = hapd = hapd_iface->bss[i] =
hostapd_alloc_bss_data(hapd_iface, conf, hostapd_alloc_bss_data(hapd_iface, conf, conf->bss[i]);
&conf->bss[i]);
if (hapd == NULL) if (hapd == NULL)
return NULL; return NULL;
hapd->msg_ctx = hapd; hapd->msg_ctx = hapd;
@ -1352,7 +1352,7 @@ int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf)
conf_file = ptr + 7; conf_file = ptr + 7;
for (i = 0; i < interfaces->count; i++) { 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)) { buf)) {
wpa_printf(MSG_INFO, "Cannot add interface - it " wpa_printf(MSG_INFO, "Cannot add interface - it "
"already exists"); "already exists");
@ -1370,8 +1370,8 @@ int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf)
if (conf_file && interfaces->config_read_cb) { if (conf_file && interfaces->config_read_cb) {
conf = interfaces->config_read_cb(conf_file); conf = interfaces->config_read_cb(conf_file);
if (conf && conf->bss) if (conf && conf->bss)
os_strlcpy(conf->bss->iface, buf, os_strlcpy(conf->bss[0]->iface, buf,
sizeof(conf->bss->iface)); sizeof(conf->bss[0]->iface));
} else } else
conf = hostapd_config_alloc(interfaces, buf, ptr); conf = hostapd_config_alloc(interfaces, buf, ptr);
if (conf == NULL || conf->bss == NULL) { if (conf == NULL || conf->bss == NULL) {
@ -1394,7 +1394,7 @@ int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf)
"interface", __func__); "interface", __func__);
goto fail; 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; return 0;
@ -1418,7 +1418,7 @@ int hostapd_remove_iface(struct hapd_interfaces *interfaces, char *buf)
hapd_iface = interfaces->iface[i]; hapd_iface = interfaces->iface[i];
if (hapd_iface == NULL) if (hapd_iface == NULL)
return -1; 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); wpa_printf(MSG_INFO, "Remove interface '%s'", buf);
hostapd_interface_deinit_free(hapd_iface); hostapd_interface_deinit_free(hapd_iface);
k = i; k = i;

View file

@ -73,7 +73,7 @@ static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
struct wpa_ssid *ssid, struct wpa_ssid *ssid,
struct hostapd_config *conf) 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; 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)); sizeof(wpa_s->conf->wmm_ac_params));
if (params.uapsd > 0) { if (params.uapsd > 0) {
conf->bss->wmm_enabled = 1; conf->bss[0]->wmm_enabled = 1;
conf->bss->wmm_uapsd = 1; conf->bss[0]->wmm_uapsd = 1;
} }
if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) { 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 #ifdef CONFIG_P2P
if (ssid->mode == WPAS_MODE_P2P_GO) 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) 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; P2P_GROUP_FORMATION;
#endif /* CONFIG_P2P */ #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++) { for (i = 0; i < conf->num_bss; i++) {
hapd_iface->bss[i] = hapd_iface->bss[i] =
hostapd_alloc_bss_data(hapd_iface, conf, hostapd_alloc_bss_data(hapd_iface, conf,
&conf->bss[i]); conf->bss[i]);
if (hapd_iface->bss[i] == NULL) { if (hapd_iface->bss[i] == NULL) {
wpa_supplicant_ap_deinit(wpa_s); wpa_supplicant_ap_deinit(wpa_s);
return -1; return -1;
@ -1042,9 +1042,9 @@ int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
#ifdef CONFIG_P2P #ifdef CONFIG_P2P
if (ssid->mode == WPAS_MODE_P2P_GO) 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) 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; P2P_GROUP_FORMATION;
#endif /* CONFIG_P2P */ #endif /* CONFIG_P2P */