ipv6: Do not consider link down nexthops in path selection

[ Upstream commit 8b8e0dd357165e0258d9f9cdab5366720ed2f619 ]

Nexthops whose link is down are not supposed to be considered during
path selection when the "ignore_routes_with_linkdown" sysctl is set.
This is done by assigning them a negative region boundary.

However, when comparing the computed hash (unsigned) with the region
boundary (signed), the negative region boundary is treated as unsigned,
resulting in incorrect nexthop selection.

Fix by treating the computed hash as signed. Note that the computed hash
is always in range of [0, 2^31 - 1].

Fixes: 3d709f69a3 ("ipv6: Use hash-threshold instead of modulo-N")
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/20250402114224.293392-3-idosch@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Ido Schimmel 2025-04-02 14:42:24 +03:00 committed by Greg Kroah-Hartman
parent 6d1e50a73d
commit d10bd910d3

View File

@ -446,6 +446,7 @@ void fib6_select_path(const struct net *net, struct fib6_result *res,
{ {
struct fib6_info *first, *match = res->f6i; struct fib6_info *first, *match = res->f6i;
struct fib6_info *sibling; struct fib6_info *sibling;
int hash;
if (!match->nh && (!match->fib6_nsiblings || have_oif_match)) if (!match->nh && (!match->fib6_nsiblings || have_oif_match))
goto out; goto out;
@ -472,7 +473,8 @@ void fib6_select_path(const struct net *net, struct fib6_result *res,
if (!first) if (!first)
goto out; goto out;
if (fl6->mp_hash <= atomic_read(&first->fib6_nh->fib_nh_upper_bound) && hash = fl6->mp_hash;
if (hash <= atomic_read(&first->fib6_nh->fib_nh_upper_bound) &&
rt6_score_route(first->fib6_nh, first->fib6_flags, oif, rt6_score_route(first->fib6_nh, first->fib6_flags, oif,
strict) >= 0) { strict) >= 0) {
match = first; match = first;
@ -485,7 +487,7 @@ void fib6_select_path(const struct net *net, struct fib6_result *res,
int nh_upper_bound; int nh_upper_bound;
nh_upper_bound = atomic_read(&nh->fib_nh_upper_bound); nh_upper_bound = atomic_read(&nh->fib_nh_upper_bound);
if (fl6->mp_hash > nh_upper_bound) if (hash > nh_upper_bound)
continue; continue;
if (rt6_score_route(nh, sibling->fib6_flags, oif, strict) < 0) if (rt6_score_route(nh, sibling->fib6_flags, oif, strict) < 0)
break; break;