From b7d76b2277113316879d9d2a9348dac5d2358f0c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 19 Jun 2016 13:01:57 +0200 Subject: libnm: deprecated wireless.mac-address-randomization property for wireless.cloned-mac-address --- libnm-core/nm-connection.c | 47 ++++++++++++++++++++++++++++++++++++++++ libnm-core/nm-setting-wireless.c | 34 +++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index a823af9bea..7695518115 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -847,6 +847,52 @@ _normalize_bond_mode (NMConnection *self, GHashTable *parameters) return FALSE; } +static gboolean +_normalize_wireless_mac_address_randomization (NMConnection *self, GHashTable *parameters) +{ + NMSettingWireless *s_wifi = nm_connection_get_setting_wireless (self); + const char *cloned_mac_address; + NMSettingMacRandomization mac_address_randomization; + + if (!s_wifi) + return FALSE; + + mac_address_randomization = nm_setting_wireless_get_mac_address_randomization (s_wifi); + if (!NM_IN_SET (mac_address_randomization, + NM_SETTING_MAC_RANDOMIZATION_DEFAULT, + NM_SETTING_MAC_RANDOMIZATION_NEVER, + NM_SETTING_MAC_RANDOMIZATION_ALWAYS)) + return FALSE; + + cloned_mac_address = nm_setting_wireless_get_cloned_mac_address (s_wifi); + if (cloned_mac_address) { + if (nm_streq (cloned_mac_address, "random")) { + if (mac_address_randomization == NM_SETTING_MAC_RANDOMIZATION_ALWAYS) + return FALSE; + mac_address_randomization = NM_SETTING_MAC_RANDOMIZATION_ALWAYS; + } else if (nm_streq (cloned_mac_address, "permanent")) { + if (mac_address_randomization == NM_SETTING_MAC_RANDOMIZATION_NEVER) + return FALSE; + mac_address_randomization = NM_SETTING_MAC_RANDOMIZATION_NEVER; + } else { + if (mac_address_randomization == NM_SETTING_MAC_RANDOMIZATION_DEFAULT) + return FALSE; + mac_address_randomization = NM_SETTING_MAC_RANDOMIZATION_DEFAULT; + } + g_object_set (s_wifi, NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION, mac_address_randomization, NULL); + return TRUE; + } + if (mac_address_randomization != NM_SETTING_MAC_RANDOMIZATION_DEFAULT) { + g_object_set (s_wifi, + NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, + mac_address_randomization == NM_SETTING_MAC_RANDOMIZATION_ALWAYS + ? "random" : "permanent", + NULL); + return TRUE; + } + return FALSE; +} + /** * nm_connection_verify: * @connection: the #NMConnection to verify @@ -1089,6 +1135,7 @@ nm_connection_normalize (NMConnection *connection, was_modified |= _normalize_ip_config (connection, parameters); was_modified |= _normalize_infiniband_mtu (connection, parameters); was_modified |= _normalize_bond_mode (connection, parameters); + was_modified |= _normalize_wireless_mac_address_randomization (connection, parameters); /* Verify anew. */ success = _nm_connection_verify (connection, error); diff --git a/libnm-core/nm-setting-wireless.c b/libnm-core/nm-setting-wireless.c index 78824887cd..15ba71b7f8 100644 --- a/libnm-core/nm-setting-wireless.c +++ b/libnm-core/nm-setting-wireless.c @@ -840,6 +840,39 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) } } + if (!NM_IN_SET (priv->mac_address_randomization, + NM_SETTING_MAC_RANDOMIZATION_DEFAULT, + NM_SETTING_MAC_RANDOMIZATION_NEVER, + NM_SETTING_MAC_RANDOMIZATION_ALWAYS)) { + g_set_error (error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("invalid value")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION); + return FALSE; + } + + /* from here on, check for NM_SETTING_VERIFY_NORMALIZABLE conditions. */ + + if (priv->cloned_mac_address) { + if ( priv->mac_address_randomization == NM_SETTING_MAC_RANDOMIZATION_ALWAYS + && nm_streq (priv->cloned_mac_address, "random")) + goto mac_addr_rand_ok; + if ( priv->mac_address_randomization == NM_SETTING_MAC_RANDOMIZATION_NEVER + && nm_streq (priv->cloned_mac_address, "permanent")) + goto mac_addr_rand_ok; + if (priv->mac_address_randomization == NM_SETTING_MAC_RANDOMIZATION_DEFAULT) + goto mac_addr_rand_ok; + } else if (priv->mac_address_randomization == NM_SETTING_MAC_RANDOMIZATION_DEFAULT) + goto mac_addr_rand_ok; + g_set_error (error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("conflicting value of mac-address-randomization and cloned-mac-address")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS); + return NM_SETTING_VERIFY_NORMALIZABLE; +mac_addr_rand_ok: + return TRUE; } @@ -1460,6 +1493,7 @@ nm_setting_wireless_class_init (NMSettingWirelessClass *setting_wireless_class) * (always randomize the MAC address). * * Since: 1.2 + * Deprecated: 1.4: Deprecated by NMSettingWireless:cloned-mac-address property **/ /* ---ifcfg-rh--- * property: mac-address-randomization -- cgit v1.2.1