]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: Do not delete nhg's when retain_mode is engaged
authorDonald Sharp <sharpd@nvidia.com>
Thu, 22 Oct 2020 12:02:33 +0000 (08:02 -0400)
committerDonald Sharp <sharpd@nvidia.com>
Thu, 22 Oct 2020 12:02:33 +0000 (08:02 -0400)
When `-r` is specified to zebra, on shutdown we should
not remove any routes from the fib.  This was a problem
with nhg's on shutdown due to their ref-count behavior.

Introduce a methodology where on shutdown we don't mess
with the nexthop groups in the kernel.  That way on
next startup things will be ok.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
zebra/main.c
zebra/zebra_nhg.c
zebra/zebra_nhg.h

index 6b6409f8455ab506837d74ea53043f340ec8fe13..ced29e1a25fc1550d8c0292b0ecdaab1ea4b6474 100644 (file)
@@ -170,12 +170,14 @@ static void sigint(void)
 
        zebra_ptm_finish();
 
-       if (retain_mode)
+       if (retain_mode) {
+               zebra_nhg_mark_keep();
                RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
                        zvrf = vrf->info;
                        if (zvrf)
                                SET_FLAG(zvrf->flags, ZEBRA_VRF_RETAIN);
                }
+       }
        if (zrouter.lsp_process_q)
                work_queue_free_and_null(&zrouter.lsp_process_q);
 
index f1f6e7e2bf882d5439855ca3e136e8e12ac6c002..fa7bab9d2cada58b55459fba9073794f7d02bd5b 100644 (file)
@@ -2711,6 +2711,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
index 052fa65d064014ffb1a3d32a230ae9d5ccb44cea..b2ef88bb61a0d4006adcbd96db26685d2fef720d 100644 (file)
@@ -324,9 +324,16 @@ struct zebra_dplane_ctx;
 extern void zebra_nhg_dplane_result(struct zebra_dplane_ctx *ctx);
 
 
-/* Sweet the nhg hash tables for old entries on restart */
+/* Sweep the nhg hash tables for old entries on restart */
 extern void zebra_nhg_sweep_table(struct hash *hash);
 
+/*
+ * We are shutting down but the nexthops should be kept
+ * as that -r has been specified and we don't want to delete
+ * the routes unintentionally
+ */
+extern void zebra_nhg_mark_keep(void);
+
 /* Nexthop resolution processing */
 struct route_entry; /* Forward ref to avoid circular includes */
 extern int nexthop_active_update(struct route_node *rn, struct route_entry *re);