summaryrefslogtreecommitdiff
path: root/zebra/zebra_nhg.c
diff options
context:
space:
mode:
Diffstat (limited to 'zebra/zebra_nhg.c')
-rw-r--r--zebra/zebra_nhg.c52
1 files changed, 41 insertions, 11 deletions
diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c
index f1f6e7e2bf..ebefa020c8 100644
--- a/zebra/zebra_nhg.c
+++ b/zebra/zebra_nhg.c
@@ -442,11 +442,8 @@ static void *zebra_nhg_hash_alloc(void *arg)
/* Mark duplicate nexthops in a group at creation time. */
nexthop_group_mark_duplicates(&(nhe->nhg));
- zebra_nhg_connect_depends(nhe, &(copy->nhg_depends));
-
/* Add the ifp now if it's not a group or recursive and has ifindex */
- if (zebra_nhg_depends_is_empty(nhe) && nhe->nhg.nexthop
- && nhe->nhg.nexthop->ifindex) {
+ if (nhe->nhg.nexthop && nhe->nhg.nexthop->ifindex) {
struct interface *ifp = NULL;
ifp = if_lookup_by_index(nhe->nhg.nexthop->ifindex,
@@ -461,7 +458,6 @@ static void *zebra_nhg_hash_alloc(void *arg)
nhe->nhg.nexthop->vrf_id, nhe->id);
}
-
return nhe;
}
@@ -754,7 +750,7 @@ static bool zebra_nhe_find(struct nhg_hash_entry **nhe, /* return value */
* resolving nexthop; or a group of nexthops, where we need
* relationships with the corresponding singletons.
*/
- zebra_nhg_depends_init(lookup);
+ zebra_nhg_depends_init(newnhe);
nh = newnhe->nhg.nexthop;
@@ -786,7 +782,14 @@ static bool zebra_nhe_find(struct nhg_hash_entry **nhe, /* return value */
}
if (recursive)
- SET_FLAG((*nhe)->flags, NEXTHOP_GROUP_RECURSIVE);
+ SET_FLAG(newnhe->flags, NEXTHOP_GROUP_RECURSIVE);
+
+ /* Attach dependent backpointers to singletons */
+ zebra_nhg_connect_depends(newnhe, &newnhe->nhg_depends);
+
+ /**
+ * Backup Nexthops
+ */
if (zebra_nhg_get_backup_nhg(newnhe) == NULL ||
zebra_nhg_get_backup_nhg(newnhe)->nexthop == NULL)
@@ -1588,6 +1591,7 @@ void zebra_nhg_free(struct nhg_hash_entry *nhe)
void zebra_nhg_hash_free(void *p)
{
+ zebra_nhg_release_all_deps((struct nhg_hash_entry *)p);
zebra_nhg_free((struct nhg_hash_entry *)p);
}
@@ -2711,6 +2715,30 @@ void zebra_nhg_sweep_table(struct hash *hash)
hash_iterate(hash, zebra_nhg_sweep_entry, NULL);
}
+static void zebra_nhg_mark_keep_entry(struct hash_bucket *bucket, void *arg)
+{
+ struct nhg_hash_entry *nhe = bucket->data;
+
+ UNSET_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED);
+}
+
+/*
+ * When we are shutting down and we have retain mode enabled
+ * in zebra the process is to mark each vrf that it's
+ * routes should not be deleted. The problem with that
+ * is that shutdown actually free's up memory which
+ * causes the nexthop group's ref counts to go to zero
+ * we need a way to subtly tell the system to not remove
+ * the nexthop groups from the kernel at the same time.
+ * The easiest just looks like that we should not mark
+ * the nhg's as installed any more and when the ref count
+ * goes to zero we'll attempt to delete and do nothing
+ */
+void zebra_nhg_mark_keep(void)
+{
+ hash_iterate(zrouter.nhgs_id, zebra_nhg_mark_keep_entry, NULL);
+}
+
/* Global control to disable use of kernel nexthops, if available. We can't
* force the kernel to support nexthop ids, of course, but we can disable
* zebra's use of them, for testing e.g. By default, if the kernel supports
@@ -2814,10 +2842,15 @@ struct nhg_hash_entry *zebra_nhg_proto_add(uint32_t id, int type,
if (old) {
/*
* This is a replace, just release NHE from ID for now, The
- * depends/dependents may still be used in the replacement.
+ * depends/dependents may still be used in the replacement so
+ * we don't touch them other than to remove their refs to their
+ * old parent.
*/
replace = true;
hash_release(zrouter.nhgs_id, old);
+
+ /* Free all the things */
+ zebra_nhg_release_all_deps(old);
}
new = zebra_nhg_rib_find_nhe(&lookup, afi);
@@ -2854,9 +2887,6 @@ struct nhg_hash_entry *zebra_nhg_proto_add(uint32_t id, int type,
zebra_nhg_decrement_ref(rb_node_dep->nhe);
}
- /* Free all the things */
- zebra_nhg_release_all_deps(old);
-
/* Dont call the dec API, we dont want to uninstall the ID */
old->refcnt = 0;
zebra_nhg_free(old);