]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/zebra_nhg.c
Merge pull request #11877 from sri-mohan1/sri-ldp-dbg1
[mirror_frr.git] / zebra / zebra_nhg.c
index 8a255981b77d4a70e23ee064ffd8ffe61d23f07e..1964c763c579ad6e51c3bceebc0e51239c6f52b7 100644 (file)
@@ -1058,7 +1058,7 @@ static void zebra_nhg_set_invalid(struct nhg_hash_entry *nhe)
        /* If we're in shutdown, this interface event needs to clean
         * up installed NHGs, so don't clear that flag directly.
         */
-       if (!zrouter.in_shutdown)
+       if (!zebra_router_in_shutdown())
                UNSET_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED);
 
        /* Update validity of nexthops depending on it */
@@ -1611,18 +1611,68 @@ void zebra_nhg_free(struct nhg_hash_entry *nhe)
                                   nhe->nhg.nexthop);
        }
 
-       if (nhe->refcnt)
-               zlog_debug("nhe_id=%pNG hash refcnt=%d", nhe, nhe->refcnt);
+       THREAD_OFF(nhe->timer);
 
        zebra_nhg_free_members(nhe);
 
        XFREE(MTYPE_NHG, nhe);
 }
 
+/*
+ * Let's just drop the memory associated with each item
+ */
 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);
+       struct nhg_hash_entry *nhe = p;
+
+       if (IS_ZEBRA_DEBUG_NHG_DETAIL) {
+               /* Group or singleton? */
+               if (nhe->nhg.nexthop && nhe->nhg.nexthop->next)
+                       zlog_debug("%s: nhe %p (%u), refcnt %d", __func__, nhe,
+                                  nhe->id, nhe->refcnt);
+               else
+                       zlog_debug("%s: nhe %p (%pNG), refcnt %d, NH %pNHv",
+                                  __func__, nhe, nhe, nhe->refcnt,
+                                  nhe->nhg.nexthop);
+       }
+
+       THREAD_OFF(nhe->timer);
+
+       nexthops_free(nhe->nhg.nexthop);
+
+       XFREE(MTYPE_NHG, nhe);
+}
+
+/*
+ * On cleanup there are nexthop groups that have not
+ * been resolved at all( a nhe->id of 0 ).  As such
+ * zebra needs to clean up the memory associated with
+ * those entries.
+ */
+void zebra_nhg_hash_free_zero_id(struct hash_bucket *b, void *arg)
+{
+       struct nhg_hash_entry *nhe = b->data;
+       struct nhg_connected *dep;
+
+       while ((dep = nhg_connected_tree_pop(&nhe->nhg_depends))) {
+               if (dep->nhe->id == 0)
+                       zebra_nhg_hash_free(dep->nhe);
+
+               nhg_connected_free(dep);
+       }
+
+       while ((dep = nhg_connected_tree_pop(&nhe->nhg_dependents)))
+               nhg_connected_free(dep);
+
+       if (nhe->backup_info && nhe->backup_info->nhe->id == 0) {
+               while ((dep = nhg_connected_tree_pop(
+                               &nhe->backup_info->nhe->nhg_depends)))
+                       nhg_connected_free(dep);
+
+               zebra_nhg_hash_free(nhe->backup_info->nhe);
+
+               XFREE(MTYPE_NHG, nhe->backup_info);
+       }
 }
 
 static void zebra_nhg_timer(struct thread *thread)
@@ -1644,13 +1694,14 @@ void zebra_nhg_decrement_ref(struct nhg_hash_entry *nhe)
 
        nhe->refcnt--;
 
-       if (!zrouter.in_shutdown && nhe->refcnt <= 0 &&
+       if (!zebra_router_in_shutdown() && nhe->refcnt <= 0 &&
            CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED) &&
            !CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_KEEP_AROUND)) {
                nhe->refcnt = 1;
                SET_FLAG(nhe->flags, NEXTHOP_GROUP_KEEP_AROUND);
                thread_add_timer(zrouter.master, zebra_nhg_timer, nhe,
                                 zrouter.nhg_keep, &nhe->timer);
+               return;
        }
 
        if (!zebra_nhg_depends_is_empty(nhe))
@@ -3074,6 +3125,9 @@ void zebra_nhg_dplane_result(struct zebra_dplane_ctx *ctx)
        case DPLANE_OP_INTF_INSTALL:
        case DPLANE_OP_INTF_UPDATE:
        case DPLANE_OP_INTF_DELETE:
+       case DPLANE_OP_TC_INSTALL:
+       case DPLANE_OP_TC_UPDATE:
+       case DPLANE_OP_TC_DELETE:
                break;
        }
 }