Skip to content

Commit

Permalink
nexthop: Factor out hash threshold fdb nexthop selection
Browse files Browse the repository at this point in the history
The loop in nexthop_select_path_hthr() includes code to check for neighbor
validity. Since this does not apply to fdb nexthops, simplify the loop by
moving the fdb nexthop selection to its own function.

Signed-off-by: Ido Schimmel <[email protected]>
Signed-off-by: Benjamin Poirier <[email protected]>
Reviewed-by: David Ahern <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
gobenji authored and kuba-moo committed Jul 21, 2023
1 parent 022add1 commit eedd47a
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions net/ipv4/nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1152,11 +1152,31 @@ static bool ipv4_good_nh(const struct fib_nh *nh)
return !!(state & NUD_VALID);
}

static struct nexthop *nexthop_select_path_fdb(struct nh_group *nhg, int hash)
{
int i;

for (i = 0; i < nhg->num_nh; i++) {
struct nh_grp_entry *nhge = &nhg->nh_entries[i];

if (hash > atomic_read(&nhge->hthr.upper_bound))
continue;

return nhge->nh;
}

WARN_ON_ONCE(1);
return NULL;
}

static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash)
{
struct nexthop *rc = NULL;
int i;

if (nhg->fdb_nh)
return nexthop_select_path_fdb(nhg, hash);

for (i = 0; i < nhg->num_nh; ++i) {
struct nh_grp_entry *nhge = &nhg->nh_entries[i];
struct nh_info *nhi;
Expand All @@ -1165,8 +1185,6 @@ static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash)
continue;

nhi = rcu_dereference(nhge->nh->nh_info);
if (nhi->fdb_nh)
return nhge->nh;

/* nexthops always check if it is good and does
* not rely on a sysctl for this behavior
Expand Down

0 comments on commit eedd47a

Please sign in to comment.