diff options
author | Jiří Klimeš <jklimes@redhat.com> | 2010-10-19 19:32:01 +0200 |
---|---|---|
committer | Jiří Klimeš <jklimes@redhat.com> | 2010-11-03 16:24:58 +0100 |
commit | 8c08ff5460af3c7369613a8412b2451f248783bb (patch) | |
tree | bf28e4c7af0e7b895b318b248edfc3e2afae1983 /src | |
parent | 5e54122f4c243a4df64c9d3804d0a08f5a1e3a8e (diff) |
core: add configurable auto connection retries (bgo #628825)
Presently, when automatic connecting fails, the connection is marked
as invalid and is not retried again. This commit adds a configuration
parameter to specify how many times the connection should be re-tried.
Diffstat (limited to 'src')
-rw-r--r-- | src/nm-policy.c | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/src/nm-policy.c b/src/nm-policy.c index e8a18d0262..d9be65c8a5 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -66,6 +66,7 @@ struct NMPolicy { }; #define INVALID_TAG "invalid" +#define RETRIES_TAG "autoconnect-retries" static const char * get_connection_id (NMConnection *connection) @@ -714,6 +715,19 @@ update_routing_and_dns (NMPolicy *policy, gboolean force_update) update_system_hostname (policy, policy->default_device4, policy->default_device6); } +static void +reset_auto_connection_retries (NMConnection *connection) +{ + NMSettingConnection *s_con; + int retries; + + s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION)); + g_assert (s_con); + + retries = nm_setting_connection_get_autoconnect_retries (s_con); + g_object_set_data (G_OBJECT (connection), RETRIES_TAG, GINT_TO_POINTER (retries)); +} + typedef struct { NMPolicy *policy; NMDevice *device; @@ -744,17 +758,26 @@ auto_activate_device (gpointer user_data) if (nm_manager_auto_user_connections_allowed (policy->manager)) connections = g_slist_concat (connections, nm_manager_get_connections (policy->manager, NM_CONNECTION_SCOPE_USER)); - /* Remove connections that are in the invalid list. */ + /* Remove connections that have INVALID_TAG and shouldn't be retried any more. */ iter = connections; while (iter) { NMConnection *iter_connection = NM_CONNECTION (iter->data); GSList *next = g_slist_next (iter); if (g_object_get_data (G_OBJECT (iter_connection), INVALID_TAG)) { - connections = g_slist_remove_link (connections, iter); - g_object_unref (iter_connection); - g_slist_free (iter); + int retries = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (iter_connection), RETRIES_TAG)); + if (retries == 0) { + connections = g_slist_remove_link (connections, iter); + g_object_unref (iter_connection); + g_slist_free (iter); + } else if (retries > 0) { + g_object_set_data (G_OBJECT (iter_connection), RETRIES_TAG, GINT_TO_POINTER (retries-1)); + } + } else { + /* Set the initial # of retries for auto-connection */ + reset_auto_connection_retries (iter_connection); } + iter = next; } @@ -902,7 +925,8 @@ device_state_changed (NMDevice *device, */ if (connection && IS_ACTIVATING_STATE (old_state)) { g_object_set_data (G_OBJECT (connection), INVALID_TAG, GUINT_TO_POINTER (TRUE)); - nm_log_info (LOGD_DEVICE, "Marking connection '%s' invalid.", get_connection_id (connection)); + if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (connection), RETRIES_TAG)) == 0) + nm_log_info (LOGD_DEVICE, "Marking connection '%s' invalid.", get_connection_id (connection)); nm_connection_clear_secrets (connection); } schedule_activate_check (policy, device, 3); @@ -912,6 +936,9 @@ device_state_changed (NMDevice *device, /* Clear the invalid tag on the connection */ g_object_set_data (G_OBJECT (connection), INVALID_TAG, NULL); + /* Reset RETRIES_TAG to number from the setting */ + reset_auto_connection_retries (connection); + /* And clear secrets so they will always be requested from the * settings service when the next connection is made. */ |