diff --git a/libnm-core/nm-setting-vlan.c b/libnm-core/nm-setting-vlan.c index 4f9d59d58d..a9b105e280 100644 --- a/libnm-core/nm-setting-vlan.c +++ b/libnm-core/nm-setting-vlan.c @@ -181,9 +181,25 @@ get_map (NMSettingVlan *self, NMVlanPriorityMap map) return NULL; } +static gint +prio_map_compare (PriorityMap *a, PriorityMap *b) +{ + return a->from < b->from + ? -1 + : (a->from > b->from + ? 1 + : (a->to < b->to ? -1 : (a->to > b->to ? 1 : 0))); +} + static void set_map (NMSettingVlan *self, NMVlanPriorityMap map, GSList *list) { + /* Sort the list. + * First, it looks better. Second, it assures that comparing lists works + * as expected. + */ + list = g_slist_sort (list, (GCompareFunc) prio_map_compare); + if (map == NM_VLAN_INGRESS_MAP) { NM_SETTING_VLAN_GET_PRIVATE (self)->ingress_priority_map = list; g_object_notify (G_OBJECT (self), NM_SETTING_VLAN_INGRESS_PRIORITY_MAP); @@ -598,7 +614,7 @@ priority_strv_to_maplist (NMVlanPriorityMap map, char **strv) list = g_slist_prepend (list, item); } } - return g_slist_reverse (list); + return g_slist_sort (list, (GCompareFunc) prio_map_compare); } static void diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 70a793c78f..2b317e8ee2 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -11004,17 +11004,17 @@ test_read_vlan_interface (void) g_assert_cmpint (nm_setting_vlan_get_num_priorities (s_vlan, NM_VLAN_EGRESS_MAP), ==, 3); g_assert (nm_setting_vlan_get_priority (s_vlan, NM_VLAN_EGRESS_MAP, 0, &from, &to)); + g_assert_cmpint (from, ==, 3); + g_assert_cmpint (to, ==, 1); + + g_assert (nm_setting_vlan_get_priority (s_vlan, NM_VLAN_EGRESS_MAP, 1, &from, &to)); g_assert_cmpint (from, ==, 12); g_assert_cmpint (to, ==, 3); - g_assert (nm_setting_vlan_get_priority (s_vlan, NM_VLAN_EGRESS_MAP, 1, &from, &to)); + g_assert (nm_setting_vlan_get_priority (s_vlan, NM_VLAN_EGRESS_MAP, 2, &from, &to)); g_assert_cmpint (from, ==, 14); g_assert_cmpint (to, ==, 7); - g_assert (nm_setting_vlan_get_priority (s_vlan, NM_VLAN_EGRESS_MAP, 2, &from, &to)); - g_assert_cmpint (from, ==, 3); - g_assert_cmpint (to, ==, 1); - g_object_unref (connection); }