summaryrefslogtreecommitdiffstats
path: root/zebra/zebra_nhg.c
diff options
context:
space:
mode:
authorMark Stapp <mjs@voltanet.io>2020-01-15 22:31:55 +0100
committerGitHub <noreply@github.com>2020-01-15 22:31:55 +0100
commitd26e2d9be40f3a5279414f8aafdc574421e01dbc (patch)
tree85b62eb6a6e3d1d47f78dd85900a3b31940de26c /zebra/zebra_nhg.c
parentMerge pull request #5616 from sworleys/NHG-Fix-Recurse-to-Group (diff)
parentlib,zebra: tighten up the nexthop_copy/nexthop_dup APIs (diff)
downloadfrr-d26e2d9be40f3a5279414f8aafdc574421e01dbc.tar.xz
frr-d26e2d9be40f3a5279414f8aafdc574421e01dbc.zip
Merge pull request #5600 from sworleys/NHG-Depend-Crash
zebra: can't improve efficiency for recursive depends
Diffstat (limited to 'zebra/zebra_nhg.c')
-rw-r--r--zebra/zebra_nhg.c44
1 files changed, 37 insertions, 7 deletions
diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c
index 2a4c708b8..743030732 100644
--- a/zebra/zebra_nhg.c
+++ b/zebra/zebra_nhg.c
@@ -1048,25 +1048,55 @@ int zebra_nhg_kernel_del(uint32_t id)
}
/* Some dependency helper functions */
-static struct nhg_hash_entry *depends_find(const struct nexthop *nh, afi_t afi)
+static struct nhg_hash_entry *depends_find_recursive(const struct nexthop *nh,
+ afi_t afi)
{
- struct nexthop lookup;
- struct nhg_hash_entry *nhe = NULL;
+ struct nhg_hash_entry *nhe;
+ struct nexthop *lookup = NULL;
- if (!nh)
- goto done;
+ lookup = nexthop_dup(nh, NULL);
+
+ nhe = zebra_nhg_find_nexthop(0, lookup, afi, 0);
+
+ nexthops_free(lookup);
+
+ return nhe;
+}
+
+static struct nhg_hash_entry *depends_find_singleton(const struct nexthop *nh,
+ afi_t afi)
+{
+ struct nhg_hash_entry *nhe;
+ struct nexthop lookup = {};
/* Capture a snapshot of this single nh; it might be part of a list,
* so we need to make a standalone copy.
*/
- memset(&lookup, 0, sizeof(lookup));
- nexthop_copy(&lookup, nh, NULL);
+ nexthop_copy_no_recurse(&lookup, nh, NULL);
nhe = zebra_nhg_find_nexthop(0, &lookup, afi, 0);
/* The copy may have allocated labels; free them if necessary. */
nexthop_del_labels(&lookup);
+ return nhe;
+}
+
+static struct nhg_hash_entry *depends_find(const struct nexthop *nh, afi_t afi)
+{
+ struct nhg_hash_entry *nhe = NULL;
+
+ if (!nh)
+ goto done;
+
+ /* We are separating these functions out to increase handling speed
+ * in the non-recursive case (by not alloc/freeing)
+ */
+ if (CHECK_FLAG(nh->flags, NEXTHOP_FLAG_RECURSIVE))
+ nhe = depends_find_recursive(nh, afi);
+ else
+ nhe = depends_find_singleton(nh, afi);
+
done:
return nhe;
}