3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-26 02:19:26 +01:00

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.
This commit is contained in:
Denis Kenzior 2021-07-16 18:22:28 -05:00
parent bedf2b0596
commit 8cfe038d67
3 changed files with 33 additions and 28 deletions

View File

@ -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,

View File

@ -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 {

View File

@ -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);
}