summaryrefslogtreecommitdiff
path: root/src/core/settings/nm-settings-connection.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/settings/nm-settings-connection.c')
-rw-r--r--src/core/settings/nm-settings-connection.c160
1 files changed, 39 insertions, 121 deletions
diff --git a/src/core/settings/nm-settings-connection.c b/src/core/settings/nm-settings-connection.c
index 1638efcd7e..b80af551ce 100644
--- a/src/core/settings/nm-settings-connection.c
+++ b/src/core/settings/nm-settings-connection.c
@@ -24,13 +24,10 @@
#include "libnm-core-intern/nm-core-internal.h"
#include "nm-audit-manager.h"
#include "nm-settings.h"
+#include "nm-manager.h"
#include "nm-dbus-manager.h"
#include "settings/plugins/keyfile/nms-keyfile-storage.h"
-#define AUTOCONNECT_RETRIES_UNSET -2
-#define AUTOCONNECT_RETRIES_FOREVER -1
-#define AUTOCONNECT_RESET_RETRIES_TIMER 300
-
#define SEEN_BSSIDS_MAX 30
#define _NM_SETTINGS_UPDATE2_FLAG_ALL_PERSIST_MODES \
@@ -159,10 +156,6 @@ typedef struct _NMSettingsConnectionPrivate {
guint64 last_secret_agent_version_id;
- int autoconnect_retries;
-
- gint32 autoconnect_retries_blocked_until;
-
bool timestamp_set : 1;
NMSettingsAutoconnectBlockedReason autoconnect_blocked_reason : 4;
@@ -227,6 +220,22 @@ static guint _get_seen_bssids(NMSettingsConnection *self,
/*****************************************************************************/
+NMSettings *
+nm_settings_connection_get_settings(NMSettingsConnection *self)
+{
+ g_return_val_if_fail(NM_IS_SETTINGS_CONNECTION(self), NULL);
+
+ return NM_SETTINGS_CONNECTION_GET_PRIVATE(self)->settings;
+}
+
+NMManager *
+nm_settings_connection_get_manager(NMSettingsConnection *self)
+{
+ return nm_settings_get_manager(nm_settings_connection_get_settings(self));
+}
+
+/*****************************************************************************/
+
NMDevice *
nm_settings_connection_default_wired_get_device(NMSettingsConnection *self)
{
@@ -1445,52 +1454,6 @@ update_complete(NMSettingsConnection *self, UpdateInfo *info, GError *error)
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,
@@ -1539,10 +1502,13 @@ update_auth_cb(NMSettingsConnection *self,
/* New secrets, allow autoconnection again */
if (nm_settings_connection_autoconnect_blocked_reason_set(
self,
- NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS,
+ NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_NO_SECRETS,
FALSE)
&& !nm_settings_connection_autoconnect_blocked_reason_get(self))
- nm_settings_connection_autoconnect_retries_reset(self);
+ nm_manager_devcon_autoconnect_retries_reset(
+ nm_settings_connection_get_manager(self),
+ NULL,
+ self);
}
}
@@ -1615,7 +1581,9 @@ update_auth_cb(NMSettingsConnection *self,
}
/* Reset auto retries back to default since connection was updated */
- nm_settings_connection_autoconnect_retries_reset(self);
+ nm_manager_devcon_autoconnect_retries_reset(nm_settings_connection_get_manager(self),
+ NULL,
+ self);
update_complete(self, info, local);
}
@@ -2534,56 +2502,6 @@ nm_settings_connection_add_seen_bssid(NMSettingsConnection *self, const char *se
/*****************************************************************************/
-/**
- * nm_settings_connection_autoconnect_retries_get:
- * @self: the settings connection
- *
- * Returns the number of autoconnect retries left. If the value is
- * not yet set, initialize it with the value from the connection or
- * with the global default.
- */
-int
-nm_settings_connection_autoconnect_retries_get(NMSettingsConnection *self)
-{
- NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self);
-
- if (G_UNLIKELY(priv->autoconnect_retries == AUTOCONNECT_RETRIES_UNSET)) {
- _autoconnect_retries_set(self, _autoconnect_retries_initial(self), TRUE);
- }
- return priv->autoconnect_retries;
-}
-
-void
-nm_settings_connection_autoconnect_retries_set(NMSettingsConnection *self, int retries)
-{
- g_return_if_fail(NM_IS_SETTINGS_CONNECTION(self));
- g_return_if_fail(retries >= 0);
-
- _autoconnect_retries_set(self, retries, FALSE);
-}
-
-void
-nm_settings_connection_autoconnect_retries_reset(NMSettingsConnection *self)
-{
- g_return_if_fail(NM_IS_SETTINGS_CONNECTION(self));
-
- _autoconnect_retries_set(self, _autoconnect_retries_initial(self), TRUE);
-}
-
-gint32
-nm_settings_connection_autoconnect_retries_blocked_until(NMSettingsConnection *self)
-{
- return NM_SETTINGS_CONNECTION_GET_PRIVATE(self)->autoconnect_retries_blocked_until;
-}
-
-static NM_UTILS_FLAGS2STR_DEFINE(
- _autoconnect_blocked_reason_to_string,
- NMSettingsAutoconnectBlockedReason,
- NM_UTILS_FLAGS2STR(NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NONE, "none"),
- NM_UTILS_FLAGS2STR(NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_USER_REQUEST, "user-request"),
- NM_UTILS_FLAGS2STR(NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED, "failed"),
- NM_UTILS_FLAGS2STR(NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS, "no-secrets"), );
-
NMSettingsAutoconnectBlockedReason
nm_settings_connection_autoconnect_blocked_reason_get(NMSettingsConnection *self)
{
@@ -2591,25 +2509,27 @@ nm_settings_connection_autoconnect_blocked_reason_get(NMSettingsConnection *self
}
gboolean
-nm_settings_connection_autoconnect_blocked_reason_set_full(NMSettingsConnection *self,
- NMSettingsAutoconnectBlockedReason mask,
- NMSettingsAutoconnectBlockedReason value)
+nm_settings_connection_autoconnect_blocked_reason_set(NMSettingsConnection *self,
+ NMSettingsAutoconnectBlockedReason reason,
+ gboolean set)
{
NMSettingsAutoconnectBlockedReason v;
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self);
- char buf[100];
+ char buf1[100];
+ char buf2[100];
- nm_assert(mask);
- nm_assert(!NM_FLAGS_ANY(value, ~mask));
+ nm_assert(reason);
v = priv->autoconnect_blocked_reason;
- v = (v & ~mask) | (value & mask);
+ v = NM_FLAGS_ASSIGN(v, reason, set);
if (priv->autoconnect_blocked_reason == v)
return FALSE;
- _LOGT("autoconnect: blocked reason: %s",
- _autoconnect_blocked_reason_to_string(v, buf, sizeof(buf)));
+ _LOGD("autoconnect: %s blocked reason: %s (now %s)",
+ set ? "set" : "unset",
+ nm_settings_autoconnect_blocked_reason_to_string(reason, buf1, sizeof(buf1)),
+ nm_settings_autoconnect_blocked_reason_to_string(v, buf2, sizeof(buf2)));
priv->autoconnect_blocked_reason = v;
return TRUE;
}
@@ -2624,9 +2544,7 @@ nm_settings_connection_autoconnect_is_blocked(NMSettingsConnection *self)
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)
+ if (priv->autoconnect_blocked_reason != NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_NONE)
return TRUE;
flags = priv->flags;
@@ -2740,14 +2658,13 @@ nm_settings_connection_init(NMSettingsConnection *self)
self->_priv = priv;
c_list_init(&self->_connections_lst);
+ c_list_init(&self->devcon_con_lst_head);
c_list_init(&priv->seen_bssids_lst_head);
c_list_init(&priv->call_ids_lst_head);
c_list_init(&priv->auth_lst_head);
priv->agent_mgr = g_object_ref(nm_agent_manager_get());
priv->settings = g_object_ref(nm_settings_get());
-
- priv->autoconnect_retries = AUTOCONNECT_RETRIES_UNSET;
}
NMSettingsConnection *
@@ -2768,6 +2685,7 @@ dispose(GObject *object)
nm_assert(!priv->default_wired_device);
nm_assert(c_list_is_empty(&self->_connections_lst));
+ nm_assert(c_list_is_empty(&self->devcon_con_lst_head));
nm_assert(c_list_is_empty(&priv->auth_lst_head));
/* Cancel in-progress secrets requests */