From fcfc12d50fb566bfa46abc64788aaecf3ce464f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alfonso=20S=C3=A1nchez-Beato?= Date: Fri, 15 May 2020 12:38:40 +0200 Subject: [PATCH 1/2] settings: move up autoconnect initialization functions Move autoconnect initialization functions up so we can use them from update_auth_cb. --- src/settings/nm-settings-connection.c | 96 +++++++++++++-------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index c6348cb492..37a4025863 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -1409,6 +1409,54 @@ update_complete (NMSettingsConnection *self, g_slice_free (UpdateInfo, info); } +static int +_autoconnect_retries_initial (NMSettingsConnection *self) +{ + NMSettingConnection *s_con; + int retries = -1; + + s_con = nm_connection_get_setting_connection (nm_settings_connection_get_connection (self)); + if (s_con) + retries = nm_setting_connection_get_autoconnect_retries (s_con); + + /* -1 means 'default' */ + if (retries == -1) + retries = nm_config_data_get_autoconnect_retries_default (NM_CONFIG_GET_DATA); + + /* 0 means 'forever', which is translated to a retry count of -1 */ + if (retries == 0) + retries = AUTOCONNECT_RETRIES_FOREVER; + + nm_assert (retries == AUTOCONNECT_RETRIES_FOREVER || retries >= 0); + return retries; +} + +static void +_autoconnect_retries_set (NMSettingsConnection *self, + int retries, + gboolean is_reset) +{ + NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); + + g_return_if_fail (retries == AUTOCONNECT_RETRIES_FOREVER || retries >= 0); + + if (priv->autoconnect_retries != retries) { + _LOGT ("autoconnect: retries set %d%s", retries, + is_reset ? " (reset)" : ""); + priv->autoconnect_retries = retries; + } + + if (retries) + priv->autoconnect_retries_blocked_until = 0; + else { + /* NOTE: the blocked time must be identical for all connections, otherwise + * the tracking of resetting the retry count in NMPolicy needs adjustment + * in _connection_autoconnect_retries_set() (as it would need to re-evaluate + * the next-timeout every time a connection gets blocked). */ + priv->autoconnect_retries_blocked_until = nm_utils_get_monotonic_timestamp_sec () + AUTOCONNECT_RESET_RETRIES_TIMER; + } +} + static void update_auth_cb (NMSettingsConnection *self, GDBusMethodInvocation *context, @@ -2328,54 +2376,6 @@ nm_settings_connection_add_seen_bssid (NMSettingsConnection *self, /*****************************************************************************/ -static int -_autoconnect_retries_initial (NMSettingsConnection *self) -{ - NMSettingConnection *s_con; - int retries = -1; - - s_con = nm_connection_get_setting_connection (nm_settings_connection_get_connection (self)); - if (s_con) - retries = nm_setting_connection_get_autoconnect_retries (s_con); - - /* -1 means 'default' */ - if (retries == -1) - retries = nm_config_data_get_autoconnect_retries_default (NM_CONFIG_GET_DATA); - - /* 0 means 'forever', which is translated to a retry count of -1 */ - if (retries == 0) - retries = AUTOCONNECT_RETRIES_FOREVER; - - nm_assert (retries == AUTOCONNECT_RETRIES_FOREVER || retries >= 0); - return retries; -} - -static void -_autoconnect_retries_set (NMSettingsConnection *self, - int retries, - gboolean is_reset) -{ - NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self); - - g_return_if_fail (retries == AUTOCONNECT_RETRIES_FOREVER || retries >= 0); - - if (priv->autoconnect_retries != retries) { - _LOGT ("autoconnect: retries set %d%s", retries, - is_reset ? " (reset)" : ""); - priv->autoconnect_retries = retries; - } - - if (retries) - priv->autoconnect_retries_blocked_until = 0; - else { - /* NOTE: the blocked time must be identical for all connections, otherwise - * the tracking of resetting the retry count in NMPolicy needs adjustment - * in _connection_autoconnect_retries_set() (as it would need to re-evaluate - * the next-timeout every time a connection gets blocked). */ - priv->autoconnect_retries_blocked_until = nm_utils_get_monotonic_timestamp_sec () + AUTOCONNECT_RESET_RETRIES_TIMER; - } -} - /** * nm_settings_connection_autoconnect_retries_get: * @self: the settings connection From 440a5c03b37557c9708dcafc62e846b37c8e3a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alfonso=20S=C3=A1nchez-Beato?= Date: Fri, 15 May 2020 12:40:39 +0200 Subject: [PATCH 2/2] settings: unblock autoconnect on new secrets When the secrets for a connection are updated, unblock autoconnection in case it had been blocked previously due to bad or no secrets. Otherwise we would need to manually activate the connection or restart NM to get another try with the new secrets. --- src/settings/nm-settings-connection.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 37a4025863..653a80c992 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -1492,6 +1492,12 @@ update_auth_cb (NMSettingsConnection *self, * they're in the main connection. */ update_agent_secrets_cache (self, info->new_settings); + + /* New secrets, allow autoconnection again */ + if ( nm_settings_connection_autoconnect_blocked_reason_set (self, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS, FALSE) + && !nm_settings_connection_autoconnect_blocked_reason_get (self, 0)) { + nm_settings_connection_autoconnect_retries_reset (self); + } } }