From 8cfe038d67f85cb912c825b459f2b1dd8f9773d8 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Fri, 16 Jul 2021 18:22:28 -0500 Subject: [PATCH] network: Move parsing of additional options Move parsing of AddressOverride and AlwaysRandomizeAddress settings to knownnetwork.c to be in the same place as other global network settings. --- src/knownnetworks.c | 25 +++++++++++++++++++++++++ src/knownnetworks.h | 3 +++ src/network.c | 33 +++++---------------------------- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/knownnetworks.c b/src/knownnetworks.c index c8387699..19234142 100644 --- a/src/knownnetworks.c +++ b/src/knownnetworks.c @@ -57,6 +57,8 @@ void __network_config_parse(const struct l_settings *settings, struct network_config *config) { bool b; + const char *value; + uint8_t new_addr[6]; memset(config, 0, sizeof(struct network_config)); @@ -72,6 +74,29 @@ void __network_config_parse(const struct l_settings *settings, b = false; config->is_hidden = b; + + if (!l_settings_get_bool(settings, NET_ALWAYS_RANDOMIZE_ADDRESS, &b)) + b = false; + + config->always_random_addr = b; + + value = l_settings_get_value(settings, NET_ADDRESS_OVERRIDE); + if (value) { + if (util_string_to_address(value, new_addr) && + util_is_valid_sta_address(new_addr)) { + config->override_addr = true; + memcpy(config->sta_addr, new_addr, sizeof(new_addr)); + } else + l_warn("[%s].%s is not a valid MAC address", + NET_ADDRESS_OVERRIDE); + } + + if (config->override_addr && config->always_random_addr) { + l_warn("Cannot use both [%s].%s and [%s].%s, using latter", + NET_ALWAYS_RANDOMIZE_ADDRESS, + NET_ADDRESS_OVERRIDE); + config->always_random_addr = false; + } } void __network_info_init(struct network_info *info, diff --git a/src/knownnetworks.h b/src/knownnetworks.h index 4c130dec..5d1698c2 100644 --- a/src/knownnetworks.h +++ b/src/knownnetworks.h @@ -64,6 +64,9 @@ struct network_config { uint64_t connected_time; /* Time last connected */ bool is_hidden:1; bool is_autoconnectable:1; + bool override_addr:1; + bool always_random_addr:1; + uint8_t sta_addr[6]; }; struct network_info { diff --git a/src/network.c b/src/network.c index 1de94ce1..6323cb28 100644 --- a/src/network.c +++ b/src/network.c @@ -446,10 +446,8 @@ int network_handshake_setup(struct network *network, struct station *station = network->station; struct wiphy *wiphy = station_get_wiphy(station); struct l_settings *settings = network->settings; + struct network_info *info = network->info; uint32_t eapol_proto_version; - const char *value; - bool full_random; - bool override = false; uint8_t new_addr[ETH_ALEN]; int r; @@ -493,31 +491,10 @@ int network_handshake_setup(struct network *network, * 2. per-network full MAC randomization * 3. per-network MAC override */ - - if (!l_settings_get_bool(settings, NET_ALWAYS_RANDOMIZE_ADDRESS, - &full_random)) - full_random = false; - - value = l_settings_get_value(settings, NET_ADDRESS_OVERRIDE); - if (value) { - if (util_string_to_address(value, new_addr) && - util_is_valid_sta_address(new_addr)) - override = true; - else - l_warn("[%s].%s is not a valid MAC address", - NET_ADDRESS_OVERRIDE); - } - - if (override && full_random) { - l_warn("Cannot use both [%s].%s and [%s].%s, using latter", - NET_ALWAYS_RANDOMIZE_ADDRESS, - NET_ADDRESS_OVERRIDE); - full_random = false; - } - - if (override) - handshake_state_set_supplicant_address(hs, new_addr); - else if (full_random) { + if (info && info->config.override_addr) + handshake_state_set_supplicant_address(hs, + info->config.sta_addr); + else if (info && info->config.always_random_addr) { wiphy_generate_random_address(wiphy, new_addr); handshake_state_set_supplicant_address(hs, new_addr); }