From 146fbfab33c109026be82bc76c2bc8a9dcd1717d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 7 Nov 2017 13:04:32 +0100 Subject: [PATCH] policy: don't block autoconnect for connections when disconnecting software devices This was added by commit 979b8920b465867ea248dee23a8a290da28f75e5 (core: move virtual device autoconnect tracking bits out of NMManager) to avoid autoconnecting software devices repeatedly. That was done, because disconnecting a software device would delete the NMDevice instance, and there is no property on a device to prevent autoconnect. In the meantime, we only unrealize software devices and don't delete them entirely. Also, the autoconnect-blocked flags of the device are preserved when the device unrealized. It was anyway odd, that deactivating one software-device would block autoconnection for all matching connections. --- src/nm-policy.c | 45 ++++++--------------------------------------- 1 file changed, 6 insertions(+), 39 deletions(-) diff --git a/src/nm-policy.c b/src/nm-policy.c index 488d7deac3..e56fce0b26 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -1466,34 +1466,6 @@ reset_autoconnect_for_failed_secrets (NMPolicy *self) } } -static void -block_autoconnect_for_device (NMPolicy *self, NMDevice *device) -{ - NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self); - gs_free NMSettingsConnection **connections = NULL; - guint i; - - _LOGD (LOGD_DEVICE, "blocking autoconnect for all connections on %s", - nm_device_get_iface (device)); - - /* NMDevice keeps its own autoconnect-able-ness state; we only need to - * explicitly block connections for software devices, where the NMDevice - * might be destroyed and recreated later. - */ - if (!nm_device_is_software (device)) - return; - - connections = nm_settings_get_connections_sorted (priv->settings, NULL); - for (i = 0; connections[i]; i++) { - NMSettingsConnection *connection = connections[i]; - - if (nm_device_check_connection_compatible (device, NM_CONNECTION (connection))) { - nm_settings_connection_autoconnect_blocked_reason_set (connection, - NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_USER_REQUEST); - } - } -} - static void sleeping_changed (NMManager *manager, GParamSpec *pspec, gpointer user_data) { @@ -1844,17 +1816,12 @@ device_state_changed (NMDevice *device, break; case NM_DEVICE_STATE_DEACTIVATING: if (nm_device_state_reason_check (reason) == NM_DEVICE_STATE_REASON_USER_REQUESTED) { - if (nm_device_autoconnect_blocked_get (device, NM_DEVICE_AUTOCONNECT_BLOCKED_ALL)) { - /* The device was disconnected; block all connections on it */ - block_autoconnect_for_device (self, device); - } else { - if (connection) { - /* The connection was deactivated, so block just this connection */ - _LOGD (LOGD_DEVICE, "blocking autoconnect of connection '%s' by user request", - nm_settings_connection_get_id (connection)); - nm_settings_connection_autoconnect_blocked_reason_set (connection, - NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_USER_REQUEST); - } + if (connection) { + /* The connection was deactivated, so block just this connection */ + _LOGD (LOGD_DEVICE, "blocking autoconnect of connection '%s' by user request", + nm_settings_connection_get_id (connection)); + nm_settings_connection_autoconnect_blocked_reason_set (connection, + NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_USER_REQUEST); } } ip6_remove_device_prefix_delegations (self, device);