diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2015-03-16 18:19:05 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2015-03-17 15:36:12 +0100 |
commit | f85513b8e4df8e88428506715ad4d0fc14e4d76a (patch) | |
tree | c2e437874d1853f2a3ce3e5fcef3a0671f528572 | |
parent | d05bedbc0d3e6e64c9f6e7ca1ede59ebb79b68b1 (diff) | |
download | NetworkManager-f85513b8e4df8e88428506715ad4d0fc14e4d76a.tar.gz |
device: do not touch sysctls after the device was removed
Paths to sysctls don't use ifindex and device names can be reused. If someone
removes a device and quickly creates a device with the same name, chances are
we're cleaning up the device that was just added.
Sadly, it seems there's no better API than sysctl-- neither netlink nor procfs
symlinks with ifindex or anything like that.
-rw-r--r-- | src/devices/nm-device.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index bb338e07a4..06106be712 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -7475,7 +7475,7 @@ _cleanup_generic_post (NMDevice *self, gboolean deconfigure) * */ static void -nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason) +nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason, gboolean deconfigure) { NMDevicePrivate *priv; int ifindex; @@ -7490,12 +7490,14 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason) /* Save whether or not we tried IPv6 for later */ priv = NM_DEVICE_GET_PRIVATE (self); - _cleanup_generic_pre (self, TRUE); + _cleanup_generic_pre (self, deconfigure); /* Turn off kernel IPv6 */ - set_disable_ipv6 (self, "1"); - nm_device_ipv6_sysctl_set (self, "accept_ra", "0"); - nm_device_ipv6_sysctl_set (self, "use_tempaddr", "0"); + if (deconfigure) { + set_disable_ipv6 (self, "1"); + nm_device_ipv6_sysctl_set (self, "accept_ra", "0"); + nm_device_ipv6_sysctl_set (self, "use_tempaddr", "0"); + } /* Call device type-specific deactivation */ if (NM_DEVICE_GET_CLASS (self)->deactivate) @@ -7516,7 +7518,7 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason) nm_platform_address_flush (ifindex); } - _cleanup_generic_post (self, TRUE); + _cleanup_generic_post (self, deconfigure); } static char * @@ -7844,12 +7846,16 @@ _set_state_full (NMDevice *self, case NM_DEVICE_STATE_UNMANAGED: nm_device_set_firmware_missing (self, FALSE); if (old_state > NM_DEVICE_STATE_UNMANAGED) { - /* Clean up if the device is now unmanaged but was activated */ - if (nm_device_get_act_request (self)) - nm_device_cleanup (self, reason); - nm_device_take_down (self, TRUE); - set_nm_ipv6ll (self, FALSE); - restore_ip6_properties (self); + if (reason == NM_DEVICE_STATE_REASON_REMOVED) { + nm_device_cleanup (self, reason, FALSE); + } else { + /* Clean up if the device is now unmanaged but was activated */ + if (nm_device_get_act_request (self)) + nm_device_cleanup (self, reason, TRUE); + nm_device_take_down (self, TRUE); + set_nm_ipv6ll (self, FALSE); + restore_ip6_properties (self); + } } break; case NM_DEVICE_STATE_UNAVAILABLE: @@ -7874,7 +7880,7 @@ _set_state_full (NMDevice *self, * Note that we "deactivate" the device even when coming from * UNMANAGED, to ensure that it's in a clean state. */ - nm_device_cleanup (self, reason); + nm_device_cleanup (self, reason, TRUE); } break; case NM_DEVICE_STATE_DISCONNECTED: @@ -7884,7 +7890,7 @@ _set_state_full (NMDevice *self, */ set_nm_ipv6ll (self, TRUE); - nm_device_cleanup (self, reason); + nm_device_cleanup (self, reason, TRUE); } else if (old_state < NM_DEVICE_STATE_DISCONNECTED) { if (reason != NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED) { /* Ensure IPv6 is set up as it may not have been done when |