diff options
author | Stefan Tomanek <stefan.tomanek@wertarbyte.de> | 2015-01-05 20:10:16 (GMT) |
---|---|---|
committer | Jouni Malinen <j@w1.fi> | 2015-01-10 15:35:53 (GMT) |
commit | 79cd993a623e101952b81fa6a29c674cd858504f (patch) | |
tree | f1ff8efd459085ee332c411b8f87eb48bda96a4e /wpa_supplicant/config.c | |
parent | b83e455451a875ba233b3b8ac29aff8b62f064f2 (diff) | |
download | hostap-79cd993a623e101952b81fa6a29c674cd858504f.zip hostap-79cd993a623e101952b81fa6a29c674cd858504f.tar.gz hostap-79cd993a623e101952b81fa6a29c674cd858504f.tar.bz2 |
Add address masks to BSSID lists
In many applications it is useful not just to enumerate a group of well
known access points, but to use a address/mask notation to match an
entire set of addresses (ca:ff:ee:00:00:00/ff:ff:ff:00:00:00).
This change expands the data structures used by MAC lists to include a
mask indicating the significant (non-masked) portions of an address and
extends the list parser to recognize mask suffixes.
Signed-off-by: Stefan Tomanek <stefan.tomanek@wertarbyte.de>
Diffstat (limited to 'wpa_supplicant/config.c')
-rw-r--r-- | wpa_supplicant/config.c | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c index 8925705..a810632 100644 --- a/wpa_supplicant/config.c +++ b/wpa_supplicant/config.c @@ -238,10 +238,10 @@ static char * wpa_config_write_int(const struct parse_data *data, static int wpa_config_parse_addr_list(const struct parse_data *data, int line, const char *value, u8 **list, size_t *num, char *name, - u8 abort_on_error) + u8 abort_on_error, u8 masked) { const char *pos; - u8 *buf, *n, addr[ETH_ALEN]; + u8 *buf, *n, addr[2 * ETH_ALEN]; size_t count; buf = NULL; @@ -252,7 +252,7 @@ static int wpa_config_parse_addr_list(const struct parse_data *data, while (*pos == ' ') pos++; - if (hwaddr_aton(pos, addr)) { + if (hwaddr_masked_aton(pos, addr, &addr[ETH_ALEN], masked)) { if (abort_on_error || count == 0) { wpa_printf(MSG_ERROR, "Line %d: Invalid %s address '%s'", @@ -266,16 +266,20 @@ static int wpa_config_parse_addr_list(const struct parse_data *data, "Line %d: Ignore likely truncated %s address '%s'", line, name, pos); } else { - n = os_realloc_array(buf, count + 1, ETH_ALEN); + n = os_realloc_array(buf, count + 1, 2 * ETH_ALEN); if (n == NULL) { os_free(buf); return -1; } buf = n; - os_memmove(buf + ETH_ALEN, buf, count * ETH_ALEN); - os_memcpy(buf, addr, ETH_ALEN); + os_memmove(buf + 2 * ETH_ALEN, buf, + count * 2 * ETH_ALEN); + os_memcpy(buf, addr, 2 * ETH_ALEN); count++; - wpa_hexdump(MSG_MSGDUMP, name, addr, ETH_ALEN); + wpa_printf(MSG_MSGDUMP, + "%s: addr=" MACSTR " mask=" MACSTR, + name, MAC2STR(addr), + MAC2STR(&addr[ETH_ALEN])); } pos = os_strchr(pos, ' '); @@ -300,25 +304,26 @@ static char * wpa_config_write_addr_list(const struct parse_data *data, if (list == NULL || num == 0) return NULL; - value = os_malloc(20 * num); + value = os_malloc(2 * 20 * num); if (value == NULL) return NULL; pos = value; - end = value + 20 * num; + end = value + 2 * 20 * num; for (i = num; i > 0; i--) { - res = os_snprintf(pos, end - pos, MACSTR " ", - MAC2STR(list + (i - 1) * ETH_ALEN)); - if (os_snprintf_error(end - pos, res)) { + const u8 *a = list + (i - 1) * 2 * ETH_ALEN; + const u8 *m = a + ETH_ALEN; + + if (i < num) + *pos++ = ' '; + res = hwaddr_mask_txt(pos, end - pos, a, m); + if (res < 0) { os_free(value); return NULL; } pos += res; } - if (pos > value) - pos[-1] = '\0'; - return value; } #endif /* NO_CONFIG_WRITE */ @@ -375,7 +380,7 @@ static int wpa_config_parse_bssid_blacklist(const struct parse_data *data, return wpa_config_parse_addr_list(data, line, value, &ssid->bssid_blacklist, &ssid->num_bssid_blacklist, - "bssid_blacklist", 1); + "bssid_blacklist", 1, 1); } @@ -397,7 +402,7 @@ static int wpa_config_parse_bssid_whitelist(const struct parse_data *data, return wpa_config_parse_addr_list(data, line, value, &ssid->bssid_whitelist, &ssid->num_bssid_whitelist, - "bssid_whitelist", 1); + "bssid_whitelist", 1, 1); } @@ -1588,7 +1593,7 @@ static int wpa_config_parse_p2p_client_list(const struct parse_data *data, return wpa_config_parse_addr_list(data, line, value, &ssid->p2p_client_list, &ssid->num_p2p_clients, - "p2p_client_list", 0); + "p2p_client_list", 0, 0); } @@ -2101,6 +2106,8 @@ void wpa_config_free_ssid(struct wpa_ssid *ssid) os_free(ssid->freq_list); os_free(ssid->bgscan); os_free(ssid->p2p_client_list); + os_free(ssid->bssid_blacklist); + os_free(ssid->bssid_whitelist); #ifdef CONFIG_HT_OVERRIDES os_free(ssid->ht_mcs); #endif /* CONFIG_HT_OVERRIDES */ |