summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-08-26 16:06:39 +0200
committerThomas Haller <thaller@redhat.com>2014-08-26 16:43:06 +0200
commitfb5a579756daefd2faebbf55febde34a204858d0 (patch)
tree0cdf556a27a9cc4cc6ddfa66b94ab9feaa0f92ec
parent259ee74c3e0a9583d54b6096a037d0b91b02fe71 (diff)
downloadNetworkManager-fb5a579756daefd2faebbf55febde34a204858d0.tar.gz
core: prefer connections with higher autoconnect-priority
https://bugzilla.gnome.org/show_bug.cgi?id=580018 Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r--src/nm-policy.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/nm-policy.c b/src/nm-policy.c
index 7964d1d3e7..8829191e0a 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -983,6 +983,30 @@ activate_data_free (ActivateData *data)
g_free (data);
}
+static int
+_sort_auto_connect_fcn (NMConnection **a, NMConnection **b)
+{
+ NMSettingConnection *a_s_con, *b_s_con;
+ gboolean a_ac, b_ac;
+ gint a_ap, b_ap;
+
+ a_s_con = nm_connection_get_setting_connection (*a);
+ b_s_con = nm_connection_get_setting_connection (*b);
+
+ a_ac = !!nm_setting_connection_get_autoconnect (a_s_con);
+ b_ac = !!nm_setting_connection_get_autoconnect (b_s_con);
+ if (a_ac != b_ac)
+ return ((int) b_ac) - ((int) a_ac);
+
+ a_ap = nm_setting_connection_get_autoconnect_priority (a_s_con);
+ b_ap = nm_setting_connection_get_autoconnect_priority (b_s_con);
+ if (a_ap == b_ap)
+ return 0;
+ if (a_ap > b_ap)
+ return 1;
+ return -1;
+}
+
static gboolean
auto_activate_device (gpointer user_data)
{
@@ -1015,6 +1039,9 @@ auto_activate_device (gpointer user_data)
connections = _nm_utils_slist_to_ptr_array (connection_list);
g_slist_free (connection_list);
+ /* sort is stable (which is important at this point) */
+ g_ptr_array_sort (connections, (GCompareFunc) _sort_auto_connect_fcn);
+
/* Find the first connection that should be auto-activated */
best_connection = NULL;
for (i = 0; i < connections->len; i++) {