From c06d130c38a4d4238e18c06f0152f8f1a6bafa7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8D=C3=B1igo=20Huguet?= Date: Tue, 10 Dec 2024 10:15:52 +0100 Subject: [PATCH] l3cfg: get routes to prune from the list of routes configured by NM We always sync routes in the main table, but routes in tables other than main are only pruned if were added by NM, by default. Get the list of routes to prune from other tables using obj_state->os_nm_configured, as this tracks what routes were effectively added by NM. The list should be the same that the one obtained from l3cfg_old. It could be different if we commited the l3cfg with an NMIPRouteTableSyncMode of NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN, thus not deleting some routes at commit time. However, since the previous commit, we never do it. What all this shows is that starting to use different NMIPRouteTableSyncModes is probably a bad idea: it will be a source of bugs of routes not being always synced as users expect, and the use case for them is still to be known. --- src/core/nm-l3cfg.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/core/nm-l3cfg.c b/src/core/nm-l3cfg.c index 0b3ddcb98..94d79da86 100644 --- a/src/core/nm-l3cfg.c +++ b/src/core/nm-l3cfg.c @@ -5172,15 +5172,17 @@ _l3_commit_one(NML3Cfg *self, nm_g_array_len(ipv6_temp_addrs_keep)); if (route_table_sync == NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN_AND_NM_ROUTES) { - NMDedupMultiIter iter; - const NMPObject *rt_obj; + GHashTableIter h_iter; + ObjStateData *obj_state; - routes_old = g_ptr_array_new(); - nm_l3_config_data_iter_obj_for_each (&iter, - l3cd_old, - &rt_obj, - NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4)) - g_ptr_array_add(routes_old, (gpointer) rt_obj); + /* Get list of all the routes that were configured by us */ + routes_old = g_ptr_array_new_with_free_func((GDestroyNotify) nmp_object_unref); + g_hash_table_iter_init(&h_iter, self->priv.p->obj_state_hash); + while (g_hash_table_iter_next(&h_iter, (gpointer *) &obj_state, NULL)) { + if (NMP_OBJECT_GET_TYPE(obj_state->obj) == NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4) + && obj_state->os_nm_configured) + g_ptr_array_add(routes_old, (gpointer) nmp_object_ref(obj_state->obj)); + } nm_platform_route_objs_sort(routes_old, NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY); }