diff --git a/man/NetworkManager.conf.xml b/man/NetworkManager.conf.xml
index e3b90d541c..99cb279613 100644
--- a/man/NetworkManager.conf.xml
+++ b/man/NetworkManager.conf.xml
@@ -356,6 +356,21 @@ no-auto-default=*
+
+ autoconnect-retries-default
+
+
+ The number of times a connection activation should be
+ automatically tried before switching to another one. This
+ value applies only to connections that can auto-connect
+ and have a
+ connection.autoconnect-retries property
+ set to -1. If not specified, connections will be retried 4
+ times.
+
+
+
+
diff --git a/src/nm-policy.c b/src/nm-policy.c
index ffe9203e7b..6993438cf0 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -1201,17 +1201,18 @@ device_state_changed (NMDevice *device,
if ( connection
&& old_state >= NM_DEVICE_STATE_PREPARE
&& old_state <= NM_DEVICE_STATE_ACTIVATED) {
- guint32 tries = nm_settings_connection_get_autoconnect_retries (connection);
+ int tries = nm_settings_connection_get_autoconnect_retries (connection);
if (reason == NM_DEVICE_STATE_REASON_NO_SECRETS) {
_LOGD (LOGD_DEVICE, "connection '%s' now blocked from autoconnect due to no secrets",
nm_settings_connection_get_id (connection));
nm_settings_connection_set_autoconnect_blocked_reason (connection, NM_DEVICE_STATE_REASON_NO_SECRETS);
- } else if (tries > 0) {
+ } else if (tries != 0) {
_LOGD (LOGD_DEVICE, "connection '%s' failed to autoconnect; %d tries left",
nm_settings_connection_get_id (connection), tries);
- nm_settings_connection_set_autoconnect_retries (connection, tries - 1);
+ if (tries > 0)
+ nm_settings_connection_set_autoconnect_retries (connection, tries - 1);
}
if (nm_settings_connection_get_autoconnect_retries (connection) == 0) {
diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c
index d373cb3ce1..220f25cbe4 100644
--- a/src/settings/nm-settings-connection.c
+++ b/src/settings/nm-settings-connection.c
@@ -26,6 +26,8 @@
#include
#include "nm-common-macros.h"
+#include "nm-config.h"
+#include "nm-config-data.h"
#include "nm-dbus-interface.h"
#include "nm-session-monitor.h"
#include "nm-auth-utils.h"
@@ -40,6 +42,11 @@
#define SETTINGS_TIMESTAMPS_FILE NMSTATEDIR "/timestamps"
#define SETTINGS_SEEN_BSSIDS_FILE NMSTATEDIR "/seen-bssids"
+#define AUTOCONNECT_RETRIES_UNSET -2
+#define AUTOCONNECT_RETRIES_FOREVER -1
+#define AUTOCONNECT_RETRIES_DEFAULT 4
+#define AUTOCONNECT_RESET_RETRIES_TIMER 300
+
/*****************************************************************************/
static void nm_settings_connection_connection_interface_init (NMConnectionInterface *iface);
@@ -2433,12 +2440,47 @@ nm_settings_connection_read_and_fill_seen_bssids (NMSettingsConnection *self)
}
}
-#define AUTOCONNECT_RETRIES_DEFAULT 4
-#define AUTOCONNECT_RESET_RETRIES_TIMER 300
-
+/**
+ * nm_settings_connection_get_autoconnect_retries:
+ * @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_get_autoconnect_retries (NMSettingsConnection *self)
{
+ NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
+
+ if (priv->autoconnect_retries == AUTOCONNECT_RETRIES_UNSET) {
+ NMSettingConnection *s_con;
+ int retries = -1;
+ const char *value;
+
+ s_con = nm_connection_get_setting_connection ((NMConnection *) self);
+ if (s_con)
+ retries = nm_setting_connection_get_autoconnect_retries (s_con);
+
+ /* -1 means 'default' */
+ if (retries == -1) {
+ value = nm_config_data_get_value_cached (NM_CONFIG_GET_DATA,
+ NM_CONFIG_KEYFILE_GROUP_MAIN,
+ "autoconnect-retries-default",
+ NM_CONFIG_GET_VALUE_STRIP);
+
+ retries = _nm_utils_ascii_str_to_int64 (value,
+ 10, 0, G_MAXINT32,
+ AUTOCONNECT_RETRIES_DEFAULT);
+ }
+
+ /* 0 means 'forever', which is translated to a retry count of -1 */
+ if (retries == 0)
+ retries = AUTOCONNECT_RETRIES_FOREVER;
+
+ priv->autoconnect_retries = retries;
+ }
+
return NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->autoconnect_retries;
}
@@ -2458,7 +2500,7 @@ nm_settings_connection_set_autoconnect_retries (NMSettingsConnection *self,
void
nm_settings_connection_reset_autoconnect_retries (NMSettingsConnection *self)
{
- nm_settings_connection_set_autoconnect_retries (self, AUTOCONNECT_RETRIES_DEFAULT);
+ nm_settings_connection_set_autoconnect_retries (self, AUTOCONNECT_RETRIES_UNSET);
}
gint32
@@ -2628,7 +2670,7 @@ nm_settings_connection_init (NMSettingsConnection *self)
priv->seen_bssids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
- priv->autoconnect_retries = AUTOCONNECT_RETRIES_DEFAULT;
+ priv->autoconnect_retries = AUTOCONNECT_RETRIES_UNSET;
priv->autoconnect_blocked_reason = NM_DEVICE_STATE_REASON_NONE;
g_signal_connect (self, NM_CONNECTION_SECRETS_CLEARED, G_CALLBACK (secrets_cleared_cb), NULL);