From 446c86f4be1e5d164fd883d2c999aa53636c5984 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 5 Dec 2017 12:20:41 +0100 Subject: [PATCH] settings: let invisible connection not autoconnect according to is_blocked() function Previously, NMPolicy would explicitly check whether the connection is not visible, to skip autoconnect. We have nm_settings_connection_autoconnect_is_blocked() function, that can do that. The advantage is, that at various places we call nm_settings_connection_autoconnect_is_blocked() to determine whether autoconnect is blocked. By declaring invisible connections as blocked from autoconnect as well, we short-cut various autoconnection attempts, that previoulsy only failed later during auto_activate_device(). (cherry picked from commit ccc93639a0a94ba097dd0d08240801df0a16646f) --- src/nm-policy.c | 11 +++++------ src/settings/nm-settings-connection.c | 22 ++++++++++++++++++---- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/nm-policy.c b/src/nm-policy.c index 8b507a5808..8dfb0ab007 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -1224,9 +1224,7 @@ auto_activate_device (NMPolicy *self, NMSettingConnection *s_con; const char *permission; - if ( !NM_FLAGS_HAS (nm_settings_connection_get_flags (candidate), - NM_SETTINGS_CONNECTION_FLAGS_VISIBLE) - || nm_settings_connection_autoconnect_is_blocked (candidate)) + if (nm_settings_connection_autoconnect_is_blocked (candidate)) continue; s_con = nm_connection_get_setting_connection (NM_CONNECTION (candidate)); @@ -2384,9 +2382,10 @@ connection_flags_changed (NMSettings *settings, NMPolicy *self = _PRIV_TO_SELF (priv); if (NM_FLAGS_HAS (nm_settings_connection_get_flags (connection), - NM_SETTINGS_CONNECTION_FLAGS_VISIBLE)) - schedule_activate_all (self); - else + NM_SETTINGS_CONNECTION_FLAGS_VISIBLE)) { + if (!nm_settings_connection_autoconnect_is_blocked (connection)) + schedule_activate_all (self); + } else _deactivate_if_active (self, connection); } diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 80f7b290fb..cef26d6cb8 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -2734,11 +2734,25 @@ nm_settings_connection_autoconnect_blocked_reason_set_full (NMSettingsConnection gboolean nm_settings_connection_autoconnect_is_blocked (NMSettingsConnection *self) { - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); + NMSettingsConnectionPrivate *priv; + NMSettingsConnectionFlags flags; - return priv->autoconnect_blocked_reason != NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NONE - || priv->autoconnect_retries == 0 - || NM_FLAGS_HAS (nm_settings_connection_get_flags (self), NM_SETTINGS_CONNECTION_FLAGS_VOLATILE); + g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (self), TRUE); + + priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); + + if (priv->autoconnect_blocked_reason != NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NONE) + return TRUE; + if (priv->autoconnect_retries == 0) + return TRUE; + + flags = priv->flags; + if (NM_FLAGS_HAS (flags, NM_SETTINGS_CONNECTION_FLAGS_VOLATILE)) + return TRUE; + if (!NM_FLAGS_HAS (flags, NM_SETTINGS_CONNECTION_FLAGS_VISIBLE)) + return TRUE; + + return FALSE; } /*****************************************************************************/