Skip to content

Commit d2310ff

Browse files
idoschjfvogel
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 <[email protected]> Closes: https://lore.kernel.org/netdev/Z9RIyKZDNoka53EO@mini-arch/ Signed-off-by: Ido Schimmel <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 1eb36a2cdf639483d414d193ad31ff476a8fb2a9) Signed-off-by: Jack Vogel <[email protected]>
1 parent 65c5e04 commit d2310ff

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
@@ -412,11 +412,35 @@ static bool rt6_check_expired(const struct rt6_info *rt)
412412
return false;
413413
}
414414

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

422446
if (!match->nh && (!match->fib6_nsiblings || have_oif_match))
@@ -440,10 +464,18 @@ void fib6_select_path(const struct net *net, struct fib6_result *res,
440464
return;
441465
}
442466

443-
if (fl6->mp_hash <= atomic_read(&match->fib6_nh->fib_nh_upper_bound))
467+
first = rt6_multipath_first_sibling_rcu(match);
468+
if (!first)
444469
goto out;
445470

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

0 commit comments

Comments
 (0)