From 7b585bcc932bc3b41d564ee8018ddc6cfaec7d5e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 22 Jun 2016 14:42:20 +0200 Subject: [PATCH] wifi: make MAC address randomization during scanning configurable This allows the user to disable MAC address randomization during scanning for Wi-Fi networks, which is done by default. For one, this allows the user to disable the randomization for whatever reason. Also, together with configuring the per-connection setting wifi.cloned-mac-address=preserve, this allows to disable NetworkManager to modify the MAC address of the interface. This may allow the user to set the MAC address outside of NetworkManager without NetworkManager interfering. --- man/NetworkManager.conf.xml | 14 ++++++++++++++ src/devices/wifi/nm-device-wifi.c | 22 ++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/man/NetworkManager.conf.xml b/man/NetworkManager.conf.xml index a766bf90f9..344aa9585c 100644 --- a/man/NetworkManager.conf.xml +++ b/man/NetworkManager.conf.xml @@ -737,6 +737,20 @@ unmanaged=1 + + wifi.scan-rand-mac-address + + + Configures the MAC address of a Wi-Fi device during scanning. + This defaults to yes in which case a random, + locally-administered MAC address will be confiugred. + Otherwise, the MAC address is left unchanged to whatever was + configured. + For the MAC address used while the device is connected, see instead + the per-connection setting wifi.cloned-mac-address. + + + diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 39ca8c46be..60f6f99f27 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -174,7 +174,7 @@ static void ap_add_remove (NMDeviceWifi *self, static void remove_supplicant_interface_error_handler (NMDeviceWifi *self); -static void _hw_addr_set_scanning (NMDeviceWifi *self); +static void _hw_addr_set_scanning (NMDeviceWifi *self, gboolean do_reset); /*****************************************************************/ @@ -490,7 +490,7 @@ deactivate (NMDevice *device) nm_platform_wifi_indicate_addressing_running (NM_PLATFORM_GET, ifindex, FALSE); g_clear_pointer (&priv->hw_addr_scan, g_free); - _hw_addr_set_scanning (self); + _hw_addr_set_scanning (self, TRUE); /* Ensure we're in infrastructure mode after deactivation; some devices * (usually older ones) don't scan well in adhoc mode. @@ -1021,11 +1021,12 @@ impl_device_wifi_get_all_access_points (NMDeviceWifi *self, } static void -_hw_addr_set_scanning (NMDeviceWifi *self) +_hw_addr_set_scanning (NMDeviceWifi *self, gboolean do_reset) { NMDevice *device = (NMDevice *) self; NMDeviceWifiPrivate *priv; guint32 now; + gboolean randomize; g_return_if_fail (NM_IS_DEVICE_WIFI (self)); @@ -1035,7 +1036,20 @@ _hw_addr_set_scanning (NMDeviceWifi *self) priv = NM_DEVICE_WIFI_GET_PRIVATE (self); + randomize = nm_config_data_get_device_config_boolean (NM_CONFIG_GET_DATA, + "wifi.scan-rand-mac-address", + device, + TRUE, TRUE); + + if (!randomize) { + g_clear_pointer (&priv->hw_addr_scan, g_free); + if (do_reset) + nm_device_hw_addr_reset (device); + return; + } + now = nm_utils_get_monotonic_timestamp_s (); + if ( !priv->hw_addr_scan || now >= priv->hw_addr_scan_expire) { /* the random MAC address for scanning expires after a while. @@ -1361,7 +1375,7 @@ request_wireless_scan (NMDeviceWifi *self, GVariant *scan_options) _LOGD (LOGD_WIFI_SCAN, "no SSIDs to probe scan"); } - _hw_addr_set_scanning (self); + _hw_addr_set_scanning (self, FALSE); if (nm_supplicant_interface_request_scan (priv->sup_iface, ssids)) { /* success */