diff mbox series

[net-next,04/12] nexthop: Assert the invariant that a NH group is of only one type

Message ID e73db0a825d62df59f2ba11f5582e5e21711102b.1611836479.git.petrm@nvidia.com
State New
Headers show
Series nexthop: Preparations for resilient next-hop groups | expand

Commit Message

Petr Machata Jan. 28, 2021, 12:49 p.m. UTC
Most of the code that deals with nexthop groups relies on the fact that the
group is of exactly one well-known type. Currently there is only one type,
"mpath", but as more next-hop group types come, it becomes desirable to
have a central place where the setting is validated. Introduce such place
into nexthop_create_group(), such that the check is done before the code
that relies on that invariant is invoked.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
---
 net/ipv4/nexthop.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

David Ahern Jan. 29, 2021, 3:10 a.m. UTC | #1
On 1/28/21 5:49 AM, Petr Machata wrote:
> Most of the code that deals with nexthop groups relies on the fact that the

> group is of exactly one well-known type. Currently there is only one type,

> "mpath", but as more next-hop group types come, it becomes desirable to

> have a central place where the setting is validated. Introduce such place

> into nexthop_create_group(), such that the check is done before the code

> that relies on that invariant is invoked.

> 

> Signed-off-by: Petr Machata <petrm@nvidia.com>

> Reviewed-by: Ido Schimmel <idosch@nvidia.com>

> ---

>  net/ipv4/nexthop.c | 7 +++++--

>  1 file changed, 5 insertions(+), 2 deletions(-)

> 


Reviewed-by: David Ahern <dsahern@kernel.org>
diff mbox series

Patch

diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index 7a30df5aea75..c09b8231f56a 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -1466,10 +1466,13 @@  static struct nexthop *nexthop_create_group(struct net *net,
 		nhg->nh_entries[i].nh_parent = nh;
 	}
 
-	if (cfg->nh_grp_type == NEXTHOP_GRP_TYPE_MPATH) {
+	if (cfg->nh_grp_type == NEXTHOP_GRP_TYPE_MPATH)
 		nhg->mpath = 1;
+
+	WARN_ON_ONCE(nhg->mpath != 1);
+
+	if (nhg->mpath)
 		nh_group_rebalance(nhg);
-	}
 
 	if (cfg->nh_fdb)
 		nhg->fdb_nh = 1;