From 89ca64c90acfc144d2f1802844abd7571a1e162c Mon Sep 17 00:00:00 2001 From: Stephen Worley Date: Mon, 13 Jan 2020 14:28:29 -0500 Subject: [PATCH] lib: assert if someone adds to nexthop list to nhg If someone tries to add a nexthop with a list of nexthops already attached to it, let's just assert. This standardizes the API to say we assume this is an individual nexthop you are appending to a group. Signed-off-by: Stephen Worley --- lib/nexthop_group.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/nexthop_group.c b/lib/nexthop_group.c index 0051cba625..d7aceb55b9 100644 --- a/lib/nexthop_group.c +++ b/lib/nexthop_group.c @@ -250,8 +250,7 @@ static void _nexthop_add_sorted(struct nexthop **head, { struct nexthop *position, *prev; - /* Ensure this gets set */ - nexthop->next = NULL; + assert(!nexthop->next); for (position = *head, prev = NULL; position; prev = position, position = position->next) { @@ -281,6 +280,8 @@ void nexthop_group_add_sorted(struct nexthop_group *nhg, { struct nexthop *tail; + assert(!nexthop->next); + /* Try to just append to the end first; * trust the list is already sorted */ -- 2.39.5