Skip to content

Commit 21f678f

Browse files
idoschgregkh
authored andcommitted
ipv6: Start path selection from the first nexthop
[ Upstream commit 4d0ab3a6885e3e9040310a8d8f54503366083626 ] Cited commit transitioned IPv6 path selection to use hash-threshold instead of modulo-N. With hash-threshold, each nexthop is assigned a region boundary in the multipath hash function's output space and a nexthop is chosen if the calculated hash is smaller than the nexthop's region boundary. Hash-threshold does not work correctly if path selection does not start with the first nexthop. For example, if fib6_select_path() is always passed the last nexthop in the group, then it will always be chosen because its region boundary covers the entire hash function's output space. Fix this by starting the selection process from the first nexthop and do not consider nexthops for which rt6_score_route() provided a negative score. Fixes: 3d709f6 ("ipv6: Use hash-threshold instead of modulo-N") Reported-by: Stanislav Fomichev <stfomichev@gmail.com> Closes: https://lore.kernel.org/netdev/Z9RIyKZDNoka53EO@mini-arch/ Signed-off-by: Ido Schimmel <idosch@nvidia.com> Link: https://patch.msgid.link/20250402114224.293392-2-idosch@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 5a2976c commit 21f678f

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

net/ipv6/route.c

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,35 @@ static bool rt6_check_expired(const struct rt6_info *rt)
414414
return false;
415415
}
416416

417+
static struct fib6_info *
418+
rt6_multipath_first_sibling_rcu(const struct fib6_info *rt)
419+
{
420+
struct fib6_info *iter;
421+
struct fib6_node *fn;
422+
423+
fn = rcu_dereference(rt->fib6_node);
424+
if (!fn)
425+
goto out;
426+
iter = rcu_dereference(fn->leaf);
427+
if (!iter)
428+
goto out;
429+
430+
while (iter) {
431+
if (iter->fib6_metric == rt->fib6_metric &&
432+
rt6_qualify_for_ecmp(iter))
433+
return iter;
434+
iter = rcu_dereference(iter->fib6_next);
435+
}
436+
437+
out:
438+
return NULL;
439+
}
440+
417441
void fib6_select_path(const struct net *net, struct fib6_result *res,
418442
struct flowi6 *fl6, int oif, bool have_oif_match,
419443
const struct sk_buff *skb, int strict)
420444
{
421-
struct fib6_info *match = res->f6i;
445+
struct fib6_info *first, *match = res->f6i;
422446
struct fib6_info *sibling;
423447

424448
if (!match->nh && (!match->fib6_nsiblings || have_oif_match))
@@ -442,10 +466,18 @@ void fib6_select_path(const struct net *net, struct fib6_result *res,
442466
return;
443467
}
444468

445-
if (fl6->mp_hash <= atomic_read(&match->fib6_nh->fib_nh_upper_bound))
469+
first = rt6_multipath_first_sibling_rcu(match);
470+
if (!first)
446471
goto out;
447472

448-
list_for_each_entry_rcu(sibling, &match->fib6_siblings,
473+
if (fl6->mp_hash <= atomic_read(&first->fib6_nh->fib_nh_upper_bound) &&
474+
rt6_score_route(first->fib6_nh, first->fib6_flags, oif,
475+
strict) >= 0) {
476+
match = first;
477+
goto out;
478+
}
479+
480+
list_for_each_entry_rcu(sibling, &first->fib6_siblings,
449481
fib6_siblings) {
450482
const struct fib6_nh *nh = sibling->fib6_nh;
451483
int nh_upper_bound;

0 commit comments

Comments
 (0)