@@ -490,28 +490,33 @@ struct nexthop *nexthop_select_path(struct nexthop *nh, int hash)
nhg = rcu_dereference(nh->nh_grp);
for (i = 0; i < nhg->num_nh; ++i) {
struct nh_grp_entry *nhge = &nhg->nh_entries[i];
+ struct nexthop *nhge_nh;
struct nh_info *nhi;
if (hash > atomic_read(&nhge->upper_bound))
continue;
+ nhge_nh = READ_ONCE(nhge->nh);
+ if (unlikely(!nhge_nh))
+ continue;
+
/* nexthops always check if it is good and does
* not rely on a sysctl for this behavior
*/
- nhi = rcu_dereference(nhge->nh->nh_info);
+ nhi = rcu_dereference(nhge_nh->nh_info);
switch (nhi->family) {
case AF_INET:
if (ipv4_good_nh(&nhi->fib_nh))
- return nhge->nh;
+ return nhge_nh;
break;
case AF_INET6:
if (ipv6_good_nh(&nhi->fib6_nh))
- return nhge->nh;
+ return nhge_nh;
break;
}
if (!rc)
- rc = nhge->nh;
+ rc = nhge_nh;
}
return rc;