Commit 4bb5239b authored by Benjamin Poirier's avatar Benjamin Poirier Committed by Jakub Kicinski

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: default avatarIdo Schimmel <idosch@nvidia.com>
Signed-off-by: default avatarBenjamin Poirier <bpoirier@nvidia.com>
Reviewed-by: default avatarDavid Ahern <dsahern@kernel.org>
Link: https://lore.kernel.org/r/20230719-nh_select-v2-2-04383e89f868@nvidia.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent eedd47a6
...@@ -1152,6 +1152,20 @@ static bool ipv4_good_nh(const struct fib_nh *nh) ...@@ -1152,6 +1152,20 @@ static bool ipv4_good_nh(const struct fib_nh *nh)
return !!(state & NUD_VALID); return !!(state & NUD_VALID);
} }
static bool nexthop_is_good_nh(const struct nexthop *nh)
{
struct nh_info *nhi = rcu_dereference(nh->nh_info);
switch (nhi->family) {
case AF_INET:
return ipv4_good_nh(&nhi->fib_nh);
case AF_INET6:
return ipv6_good_nh(&nhi->fib6_nh);
}
return false;
}
static struct nexthop *nexthop_select_path_fdb(struct nh_group *nhg, int hash) static struct nexthop *nexthop_select_path_fdb(struct nh_group *nhg, int hash)
{ {
int i; int i;
...@@ -1179,26 +1193,15 @@ static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash) ...@@ -1179,26 +1193,15 @@ static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash)
for (i = 0; i < nhg->num_nh; ++i) { for (i = 0; i < nhg->num_nh; ++i) {
struct nh_grp_entry *nhge = &nhg->nh_entries[i]; struct nh_grp_entry *nhge = &nhg->nh_entries[i];
struct nh_info *nhi;
if (hash > atomic_read(&nhge->hthr.upper_bound)) if (hash > atomic_read(&nhge->hthr.upper_bound))
continue; continue;
nhi = rcu_dereference(nhge->nh->nh_info);
/* nexthops always check if it is good and does /* nexthops always check if it is good and does
* not rely on a sysctl for this behavior * not rely on a sysctl for this behavior
*/ */
switch (nhi->family) { if (nexthop_is_good_nh(nhge->nh))
case AF_INET: return nhge->nh;
if (ipv4_good_nh(&nhi->fib_nh))
return nhge->nh;
break;
case AF_INET6:
if (ipv6_good_nh(&nhi->fib6_nh))
return nhge->nh;
break;
}
if (!rc) if (!rc)
rc = nhge->nh; rc = nhge->nh;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment