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.
This commit is contained in:
Lubomir Rintel
2015-03-16 18:19:05 +01:00
parent d05bedbc0d
commit f85513b8e4

View File

@@ -7475,7 +7475,7 @@ _cleanup_generic_post (NMDevice *self, gboolean deconfigure)
* *
*/ */
static void static void
nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason) nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason, gboolean deconfigure)
{ {
NMDevicePrivate *priv; NMDevicePrivate *priv;
int ifindex; int ifindex;
@@ -7490,12 +7490,14 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason)
/* Save whether or not we tried IPv6 for later */ /* Save whether or not we tried IPv6 for later */
priv = NM_DEVICE_GET_PRIVATE (self); priv = NM_DEVICE_GET_PRIVATE (self);
_cleanup_generic_pre (self, TRUE); _cleanup_generic_pre (self, deconfigure);
/* Turn off kernel IPv6 */ /* Turn off kernel IPv6 */
set_disable_ipv6 (self, "1"); if (deconfigure) {
nm_device_ipv6_sysctl_set (self, "accept_ra", "0"); set_disable_ipv6 (self, "1");
nm_device_ipv6_sysctl_set (self, "use_tempaddr", "0"); nm_device_ipv6_sysctl_set (self, "accept_ra", "0");
nm_device_ipv6_sysctl_set (self, "use_tempaddr", "0");
}
/* Call device type-specific deactivation */ /* Call device type-specific deactivation */
if (NM_DEVICE_GET_CLASS (self)->deactivate) if (NM_DEVICE_GET_CLASS (self)->deactivate)
@@ -7516,7 +7518,7 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason)
nm_platform_address_flush (ifindex); nm_platform_address_flush (ifindex);
} }
_cleanup_generic_post (self, TRUE); _cleanup_generic_post (self, deconfigure);
} }
static char * static char *
@@ -7844,12 +7846,16 @@ _set_state_full (NMDevice *self,
case NM_DEVICE_STATE_UNMANAGED: case NM_DEVICE_STATE_UNMANAGED:
nm_device_set_firmware_missing (self, FALSE); nm_device_set_firmware_missing (self, FALSE);
if (old_state > NM_DEVICE_STATE_UNMANAGED) { if (old_state > NM_DEVICE_STATE_UNMANAGED) {
/* Clean up if the device is now unmanaged but was activated */ if (reason == NM_DEVICE_STATE_REASON_REMOVED) {
if (nm_device_get_act_request (self)) nm_device_cleanup (self, reason, FALSE);
nm_device_cleanup (self, reason); } else {
nm_device_take_down (self, TRUE); /* Clean up if the device is now unmanaged but was activated */
set_nm_ipv6ll (self, FALSE); if (nm_device_get_act_request (self))
restore_ip6_properties (self); nm_device_cleanup (self, reason, TRUE);
nm_device_take_down (self, TRUE);
set_nm_ipv6ll (self, FALSE);
restore_ip6_properties (self);
}
} }
break; break;
case NM_DEVICE_STATE_UNAVAILABLE: case NM_DEVICE_STATE_UNAVAILABLE:
@@ -7874,7 +7880,7 @@ _set_state_full (NMDevice *self,
* Note that we "deactivate" the device even when coming from * Note that we "deactivate" the device even when coming from
* UNMANAGED, to ensure that it's in a clean state. * UNMANAGED, to ensure that it's in a clean state.
*/ */
nm_device_cleanup (self, reason); nm_device_cleanup (self, reason, TRUE);
} }
break; break;
case NM_DEVICE_STATE_DISCONNECTED: case NM_DEVICE_STATE_DISCONNECTED:
@@ -7884,7 +7890,7 @@ _set_state_full (NMDevice *self,
*/ */
set_nm_ipv6ll (self, TRUE); set_nm_ipv6ll (self, TRUE);
nm_device_cleanup (self, reason); nm_device_cleanup (self, reason, TRUE);
} else if (old_state < NM_DEVICE_STATE_DISCONNECTED) { } else if (old_state < NM_DEVICE_STATE_DISCONNECTED) {
if (reason != NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED) { if (reason != NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED) {
/* Ensure IPv6 is set up as it may not have been done when /* Ensure IPv6 is set up as it may not have been done when