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.
This commit is contained in:
Íñigo Huguet
2024-12-10 10:15:52 +01:00
committed by Íñigo Huguet
parent e330eb9c4a
commit c06d130c38

View File

@@ -5172,15 +5172,17 @@ _l3_commit_one(NML3Cfg *self,
nm_g_array_len(ipv6_temp_addrs_keep)); nm_g_array_len(ipv6_temp_addrs_keep));
if (route_table_sync == NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN_AND_NM_ROUTES) { if (route_table_sync == NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN_AND_NM_ROUTES) {
NMDedupMultiIter iter; GHashTableIter h_iter;
const NMPObject *rt_obj; ObjStateData *obj_state;
routes_old = g_ptr_array_new(); /* Get list of all the routes that were configured by us */
nm_l3_config_data_iter_obj_for_each (&iter, routes_old = g_ptr_array_new_with_free_func((GDestroyNotify) nmp_object_unref);
l3cd_old, g_hash_table_iter_init(&h_iter, self->priv.p->obj_state_hash);
&rt_obj, while (g_hash_table_iter_next(&h_iter, (gpointer *) &obj_state, NULL)) {
NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4)) if (NMP_OBJECT_GET_TYPE(obj_state->obj) == NMP_OBJECT_TYPE_IP_ROUTE(IS_IPv4)
g_ptr_array_add(routes_old, (gpointer) rt_obj); && 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); nm_platform_route_objs_sort(routes_old, NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY);
} }