nexthop: Introduce to struct nh_grp_entry a per-type union
authorPetr Machata <petrm@nvidia.com>
Thu, 28 Jan 2021 12:49:15 +0000 (13:49 +0100)
committerJakub Kicinski <kuba@kernel.org>
Fri, 29 Jan 2021 04:49:51 +0000 (20:49 -0800)
The values that a next-hop group needs to keep track of depend on the group
type. Introduce a union to separate fields specific to the mpath groups
from fields specific to other group types.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/nexthop.h
net/ipv4/nexthop.c

index 226930d66b637d1ed2e30bc765d5c69d8f8b398b..d0e245b0635d92f43efa7e8a8db248fb9a3cfcef 100644 (file)
@@ -66,7 +66,12 @@ struct nh_info {
 struct nh_grp_entry {
        struct nexthop  *nh;
        u8              weight;
-       atomic_t        upper_bound;
+
+       union {
+               struct {
+                       atomic_t        upper_bound;
+               } mpath;
+       };
 
        struct list_head nh_list;
        struct nexthop  *nh_parent;  /* nexthop of group with this entry */
index 43bb5f4513436145cafe9491ce1bb60e2d5efec0..7a30df5aea75544823cff516ff35b966245b3277 100644 (file)
@@ -689,7 +689,7 @@ static struct nexthop *nexthop_select_path_mp(struct nh_group *nhg, int hash)
                struct nh_grp_entry *nhge = &nhg->nh_entries[i];
                struct nh_info *nhi;
 
-               if (hash > atomic_read(&nhge->upper_bound))
+               if (hash > atomic_read(&nhge->mpath.upper_bound))
                        continue;
 
                nhi = rcu_dereference(nhge->nh->nh_info);
@@ -924,7 +924,7 @@ static void nh_group_rebalance(struct nh_group *nhg)
 
                w += nhge->weight;
                upper_bound = DIV_ROUND_CLOSEST_ULL((u64)w << 31, total) - 1;
-               atomic_set(&nhge->upper_bound, upper_bound);
+               atomic_set(&nhge->mpath.upper_bound, upper_bound);
        }
 }