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: 695ce608ba ('l3cfg: add nm_l3_config_data_add_dependent_routes()')
This commit is contained in:
Beniamino Galvani 2026-05-30 17:11:46 +02:00
parent 63173a4e33
commit bc67b0211a

View file

@ -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;