Skip to content

Commit eedd47a

Browse files
gobenjikuba-moo
authored andcommitted
nexthop: Factor out hash threshold fdb nexthop selection
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 <idosch@nvidia.com> Signed-off-by: Benjamin Poirier <bpoirier@nvidia.com> Reviewed-by: David Ahern <dsahern@kernel.org> Link: https://lore.kernel.org/r/20230719-nh_select-v2-1-04383e89f868@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 022add1 commit eedd47a

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

net/ipv4/nexthop.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,11 +1152,31 @@ static bool ipv4_good_nh(const struct fib_nh *nh)
11521152
return !!(state & NUD_VALID);
11531153
}
11541154

1155+
static struct nexthop *nexthop_select_path_fdb(struct nh_group *nhg, int hash)
1156+
{
1157+
int i;
1158+
1159+
for (i = 0; i < nhg->num_nh; i++) {
1160+
struct nh_grp_entry *nhge = &nhg->nh_entries[i];
1161+
1162+
if (hash > atomic_read(&nhge->hthr.upper_bound))
1163+
continue;
1164+
1165+
return nhge->nh;
1166+
}
1167+
1168+
WARN_ON_ONCE(1);
1169+
return NULL;
1170+
}
1171+
11551172
static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash)
11561173
{
11571174
struct nexthop *rc = NULL;
11581175
int i;
11591176

1177+
if (nhg->fdb_nh)
1178+
return nexthop_select_path_fdb(nhg, hash);
1179+
11601180
for (i = 0; i < nhg->num_nh; ++i) {
11611181
struct nh_grp_entry *nhge = &nhg->nh_entries[i];
11621182
struct nh_info *nhi;
@@ -1165,8 +1185,6 @@ static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash)
11651185
continue;
11661186

11671187
nhi = rcu_dereference(nhge->nh->nh_info);
1168-
if (nhi->fdb_nh)
1169-
return nhge->nh;
11701188

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

0 commit comments

Comments
 (0)