When there were multiple routes with the same target but different
metrics, __find_ip_route_target was returning the first one,
independently of the metric.
Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
if (route->flags & DEVROUTE_TABLE)
continue;
- if (!*res || route->mask > (*res)->mask)
+ if (!*res || route->mask > (*res)->mask ||
+ ((route->mask == (*res)->mask) && (route->flags & DEVROUTE_METRIC)
+ && (route->metric < (*res)->metric)))
*res = route;
}
}