diff options
author | Thomas Haller <thaller@redhat.com> | 2016-06-30 11:42:28 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-06-30 12:01:42 +0200 |
commit | c5c9f0aad7b788cf7901f889eec5f11e1505fda3 (patch) | |
tree | 2934e942bdd5ed62b8dea2688608e536ad67cf49 | |
parent | 5ce62dccc5d8edc77a71a00c6ec9436f23f42e0b (diff) | |
download | NetworkManager-c5c9f0aad7b788cf7901f889eec5f11e1505fda3.tar.gz |
device/wifi: properly reset the initial hardware address on shutdown
During shutdown, we unmanage Wi-Fi devices, and during NMDevice:deactivate()
we would reset to initial MAC address.
However, NMDeviceWifi:deactivate() would reset it again to the scanning one.
Fix that to properly restore the initial MAC address on the device
when NetworkManager exits.
Fixes: 4b2e375b3393ca4ebb1069279e919cd5fc9fd2ee
-rw-r--r-- | src/devices/nm-device.c | 24 | ||||
-rw-r--r-- | src/devices/nm-device.h | 2 | ||||
-rw-r--r-- | src/devices/wifi/nm-device-wifi.c | 10 |
3 files changed, 31 insertions, 5 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 76133bfb9e..2b3c3cfadd 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -10653,8 +10653,6 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason, CleanupType clean nm_device_ipv6_sysctl_set (self, "use_tempaddr", "0"); } - nm_device_hw_addr_reset (self, "deactivate"); - /* Call device type-specific deactivation */ if (NM_DEVICE_GET_CLASS (self)->deactivate) NM_DEVICE_GET_CLASS (self)->deactivate (self); @@ -10678,9 +10676,30 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason, CleanupType clean nm_lldp_listener_stop (priv->lldp_listener); nm_device_update_metered (self); + + + /* during device cleanup, we want to reset the MAC address of the device + * to the initial state. + * + * We certainly want to do that when reaching the UNMANAGED state... */ + if (nm_device_get_state (self) <= NM_DEVICE_STATE_UNMANAGED) + nm_device_hw_addr_reset (self, "unmanage"); + else { + /* for other device states (UNAVAILABLE, DISCONNECTED), allow the + * device to overwrite the reset behavior, so that Wi-Fi can set + * a randomized MAC address used during scanning. */ + NM_DEVICE_GET_CLASS (self)->deactivate_reset_hw_addr (self); + } + _cleanup_generic_post (self, cleanup_type); } +static void +deactivate_reset_hw_addr (NMDevice *self) +{ + nm_device_hw_addr_reset (self, "deactivate"); +} + static char * bin2hexstr (const char *bytes, gsize len) { @@ -12445,6 +12464,7 @@ nm_device_class_init (NMDeviceClass *klass) klass->carrier_changed = carrier_changed; klass->get_ip_iface_identifier = get_ip_iface_identifier; klass->unmanaged_on_quit = unmanaged_on_quit; + klass->deactivate_reset_hw_addr = deactivate_reset_hw_addr; /* Properties */ obj_properties[PROP_UDI] = diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 8383ea250d..6a4f22a5f4 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -279,6 +279,8 @@ typedef struct { GAsyncResult *res, GError **error); + void (* deactivate_reset_hw_addr) (NMDevice *self); + /* Sync deactivating (in the DISCONNECTED phase) */ void (* deactivate) (NMDevice *self); diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 5ddf5d84b7..bfd6d0217e 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -501,9 +501,6 @@ deactivate (NMDevice *device) /* Clear any critical protocol notification in the Wi-Fi stack */ 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, TRUE); - /* Ensure we're in infrastructure mode after deactivation; some devices * (usually older ones) don't scan well in adhoc mode. */ @@ -525,6 +522,12 @@ deactivate (NMDevice *device) } } +static void +deactivate_reset_hw_addr (NMDevice *device) +{ + _hw_addr_set_scanning ((NMDeviceWifi *) device, TRUE); +} + static gboolean is_adhoc_wpa (NMConnection *connection) { @@ -3117,6 +3120,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass) parent_class->act_stage4_ip4_config_timeout = act_stage4_ip4_config_timeout; parent_class->act_stage4_ip6_config_timeout = act_stage4_ip6_config_timeout; parent_class->deactivate = deactivate; + parent_class->deactivate_reset_hw_addr = deactivate_reset_hw_addr; parent_class->unmanaged_on_quit = unmanaged_on_quit; parent_class->state_changed = device_state_changed; |