From 1d049aba721bb05ecf2f8b5978d96863330093b6 Mon Sep 17 00:00:00 2001 From: Stephen Worley Date: Fri, 3 Jan 2020 12:35:15 -0500 Subject: [PATCH 1/2] zebra: just set nexthop member in handle_recursive_depend() With recent changes to the lib nexthop_group APIs (e1f3a8eb193267da195088cc515b598ae5a92a12), we are making new assumptions that this should be adding a single nexthop to a group, not a list of nexthops. This broke the case of a recursive nexthop resolving to a group: ``` D> 2.2.2.1/32 [150/0] via 1.1.1.1 (recursive), 00:00:09 * via 1.1.1.1, dummy1 onlink, 00:00:09 via 1.1.1.2 (recursive), 00:00:09 * via 1.1.1.2, dummy2 onlink, 00:00:09 D> 3.3.3.1/32 [150/0] via 2.2.2.1 (recursive), 00:00:04 * via 1.1.1.1, dummy1 onlink, 00:00:04 K * 10.0.0.0/8 [0/1] via 172.27.227.148, tun0, 00:00:21 ``` This group can instead just directly point to the nh that was passed. Its only being used for a lookup (the memory gets copied and used elsewhere if the nexthop is not found). Signed-off-by: Stephen Worley --- zebra/zebra_nhg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index 4f41406a5c..2eb3cd9b42 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -478,7 +478,7 @@ static void handle_recursive_depend(struct nhg_connected_tree_head *nhg_depends, struct nhg_hash_entry *depend = NULL; struct nexthop_group resolved_ng = {}; - nexthop_group_add_sorted(&resolved_ng, nh); + resolved_ng.nexthop = nh; depend = zebra_nhg_rib_find(0, &resolved_ng, afi); depends_add(nhg_depends, depend); From 89ca64c90acfc144d2f1802844abd7571a1e162c Mon Sep 17 00:00:00 2001 From: Stephen Worley Date: Mon, 13 Jan 2020 14:28:29 -0500 Subject: [PATCH 2/2] 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 */