Skip to content

Commit 4bb5239

Browse files
gobenjikuba-moo
authored andcommitted
nexthop: Factor out neighbor validity check
For legacy nexthops, there is fib_good_nh() to check the neighbor validity. In order to make the nexthop object code more similar to the legacy nexthop code, factor out the nexthop object neighbor validity check into 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-2-04383e89f868@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent eedd47a commit 4bb5239

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

net/ipv4/nexthop.c

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

1155+
static bool nexthop_is_good_nh(const struct nexthop *nh)
1156+
{
1157+
struct nh_info *nhi = rcu_dereference(nh->nh_info);
1158+
1159+
switch (nhi->family) {
1160+
case AF_INET:
1161+
return ipv4_good_nh(&nhi->fib_nh);
1162+
case AF_INET6:
1163+
return ipv6_good_nh(&nhi->fib6_nh);
1164+
}
1165+
1166+
return false;
1167+
}
1168+
11551169
static struct nexthop *nexthop_select_path_fdb(struct nh_group *nhg, int hash)
11561170
{
11571171
int i;
@@ -1179,26 +1193,15 @@ static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash)
11791193

11801194
for (i = 0; i < nhg->num_nh; ++i) {
11811195
struct nh_grp_entry *nhge = &nhg->nh_entries[i];
1182-
struct nh_info *nhi;
11831196

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

1187-
nhi = rcu_dereference(nhge->nh->nh_info);
1188-
11891200
/* nexthops always check if it is good and does
11901201
* not rely on a sysctl for this behavior
11911202
*/
1192-
switch (nhi->family) {
1193-
case AF_INET:
1194-
if (ipv4_good_nh(&nhi->fib_nh))
1195-
return nhge->nh;
1196-
break;
1197-
case AF_INET6:
1198-
if (ipv6_good_nh(&nhi->fib6_nh))
1199-
return nhge->nh;
1200-
break;
1201-
}
1203+
if (nexthop_is_good_nh(nhge->nh))
1204+
return nhge->nh;
12021205

12031206
if (!rc)
12041207
rc = nhge->nh;

0 commit comments

Comments
 (0)