From 51cec67253a014569f7807b5df56a58a7d4f30ae Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 11 Feb 2022 18:48:26 +0100 Subject: [PATCH] dns/resolved: sort dirty interfaces to prune in "nm-dns-systemd-resolved.c" When we do something where the order makes a visible difference, we should do it in a consistent way, that does not depend on arbitray things. Sort the ifindexes from dirty_interfaces hash table. --- src/core/dns/nm-dns-systemd-resolved.c | 28 ++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/core/dns/nm-dns-systemd-resolved.c b/src/core/dns/nm-dns-systemd-resolved.c index 9ac549d4ef..00928504be 100644 --- a/src/core/dns/nm-dns-systemd-resolved.c +++ b/src/core/dns/nm-dns-systemd-resolved.c @@ -569,6 +569,7 @@ update(NMDnsPlugin *plugin, gpointer pointer; NMDnsConfigIPData *ip_data; GHashTableIter iter; + gs_unref_array GArray *dirty_array = NULL; guint i; /* Group configs by ifindex/interfaces. */ @@ -611,22 +612,33 @@ update(NMDnsPlugin *plugin, * reset the resolved configuration for that ifindex. */ g_hash_table_iter_init(&iter, priv->dirty_interfaces); while (g_hash_table_iter_next(&iter, &pointer, NULL)) { - int ifindex = GPOINTER_TO_INT(pointer); - InterfaceConfig ic; + int ifindex = GPOINTER_TO_INT(pointer); if (g_hash_table_contains(interfaces, GINT_TO_POINTER(ifindex))) { /* the interface is still tracked and still dirty. Keep. */ continue; } - _LOGT("clear previously configured ifindex %d", ifindex); - ic = (InterfaceConfig){ - .ifindex = ifindex, - .configs_lst_head = C_LIST_INIT(ic.configs_lst_head), - }; - prepare_one_interface(self, &ic); + if (!dirty_array) + dirty_array = g_array_new(FALSE, FALSE, sizeof(int)); + g_array_append_val(dirty_array, ifindex); + g_hash_table_iter_remove(&iter); } + if (dirty_array) { + g_array_sort_with_data(dirty_array, nm_cmp_int2ptr_p_with_data, NULL); + for (i = 0; i < dirty_array->len; i++) { + int ifindex = g_array_index(dirty_array, int, i); + InterfaceConfig ic; + + _LOGT("clear previously configured ifindex %d", ifindex); + ic = (InterfaceConfig){ + .ifindex = ifindex, + .configs_lst_head = C_LIST_INIT(ic.configs_lst_head), + }; + prepare_one_interface(self, &ic); + } + } priv->send_updates_waiting = TRUE; send_updates(self);