mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-05 13:30:28 +01:00
libnm: sort INGRESS_PRIORITY_MAP, EGRESS_PRIORITY_MAP properties
This fixes comparing the properties.
Priority map { 1:2, 2:5 } is actually the same as { 2:5, 1:2 }.
This commit is contained in:
parent
704930a045
commit
93b8871f56
2 changed files with 22 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue