From bc67b0211abde1fb9aefafd2a6a1899e8130299e Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Sat, 30 May 2026 17:11:46 +0200 Subject: [PATCH] l3-config-data: fix direct route selection preferring metric over prefix length In nm_l3_config_data_get_direct_route_for_host(), after the first check filters out routes with a shorter prefix than the current best, the remaining candidates have plen >= best_route->plen. The metric comparison must only apply when the prefix lengths are equal; otherwise a more specific route (longer prefix) is incorrectly skipped if it has a higher metric than the current best. Fixes: 695ce608bafb ('l3cfg: add nm_l3_config_data_add_dependent_routes()') --- src/core/nm-l3-config-data.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/nm-l3-config-data.c b/src/core/nm-l3-config-data.c index 496e9401bd..397b9ee422 100644 --- a/src/core/nm-l3-config-data.c +++ b/src/core/nm-l3-config-data.c @@ -2773,7 +2773,8 @@ nm_l3_config_data_get_direct_route_for_host(const NML3ConfigData *self, if (!nm_ip_addr_same_prefix(addr_family, host, item->rx.network_ptr, item->rx.plen)) continue; - if (best_route && best_route->rx.metric <= item->rx.metric) + if (best_route && best_route->rx.plen == item->rx.plen + && best_route->rx.metric <= item->rx.metric) continue; best_route_obj = item_obj;