]> git.proxmox.com Git - mirror_frr.git/commitdiff
zebra: Add helper functions for freeing the members of nexthop group hash entries
authorStephen Worley <sworley@cumulusnetworks.com>
Fri, 22 Mar 2019 17:07:22 +0000 (13:07 -0400)
committerStephen Worley <sworley@cumulusnetworks.com>
Fri, 25 Oct 2019 15:13:38 +0000 (11:13 -0400)
Add some functions that can be called to free everything that should
have been allocated in a nexthop group hash entry.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
zebra/zebra_nhg.c
zebra/zebra_nhg.h

index 82bbef3911669f3ad826d91eac5ae288d6c92a09..789e371da52aad445facf2e4ae6a2a241c796b21 100644 (file)
@@ -328,38 +328,54 @@ struct nhg_hash_entry *zebra_nhg_find(struct nexthop_group *nhg,
        lookup.id = id;
        lookup.vrf_id = vrf_id;
        lookup.afi = afi;
-       lookup.nhg = *nhg;
-       lookup.nhg_depends = NULL;
+       lookup.nhg = nhg;
+       lookup.nhg_depends = nhg_depends;
 
-       if (dep_count)
-               lookup.nhg_depends = nhg_depends;
-
-       nhe = hash_lookup(zrouter.nhgs, &lookup);
+       if (id)
+               nhe = zebra_nhg_lookup_id(id);
+       else
+               nhe = hash_lookup(zrouter.nhgs, &lookup);
 
        if (!nhe) {
                nhe = hash_get(zrouter.nhgs, &lookup, zebra_nhg_alloc);
        } else {
-               if (id) {
-                       /* Duplicate but with different ID from the kernel */
-
-                       /* The kernel allows duplicate nexthops as long as they
-                        * have different IDs. We are ignoring those to prevent
-                        * syncing problems with the kernel changes.
-                        */
-                       flog_warn(
-                               EC_ZEBRA_DUPLICATE_NHG_MESSAGE,
-                               "Nexthop Group from with ID (%d) is a duplicate, ignoring",
-                               id);
-                       if (lookup.nhg_depends)
-                               list_delete(&lookup.nhg_depends);
-
-                       return NULL;
-               }
+               zebra_nhg_free_group_depends(nhg, nhg_depends);
        }
 
        return nhe;
 }
 
+/**
+ * zebra_nhg_free_group_depends() - Helper function for freeing nexthop_group
+ *                                 struct and depends
+ *
+ * @nhg:               Nexthop group
+ * @nhg_depends:       Nexthop group hash entry dependency list
+ */
+void zebra_nhg_free_group_depends(struct nexthop_group *nhg,
+                                 struct list *nhg_depends)
+{
+       if (nhg_depends)
+               list_delete(&nhg_depends);
+       if (nhg) {
+               if (nhg->nexthop)
+                       nexthops_free(nhg->nexthop);
+               nexthop_group_delete(&nhg);
+       }
+}
+
+/**
+ * zebra_nhg_free_members() - Free all members in the hash entry struct
+ *
+ * @nhe: Nexthop group hash entry
+ *
+ * Just use this to free everything but the entry itself.
+ */
+void zebra_nhg_free_members(struct nhg_hash_entry *nhe)
+{
+       zebra_nhg_free_group_depends(nhe->nhg, nhe->nhg_depends);
+}
+
 /**
  * zebra_nhg_free() - Free the nexthop group hash entry
  *
index e741cc0cfc1d91df858e80416701f23028469466..287aaf275f7964c74185f6a732d553b4e5ef8948 100644 (file)
@@ -104,6 +104,9 @@ extern struct nhg_hash_entry *
 zebra_nhg_find(struct nexthop_group *nhg, vrf_id_t vrf_id, afi_t afi,
               uint32_t id, struct list *nhg_depends, int dep_count);
 
+void zebra_nhg_free_group_depends(struct nexthop_group *nhg,
+                                 struct list *nhg_depends);
+void zebra_nhg_free_members(struct nhg_hash_entry *nhe);
 void zebra_nhg_free(void *arg);
 void zebra_nhg_release(struct nhg_hash_entry *nhe);
 void zebra_nhg_decrement_ref(struct nhg_hash_entry *nhe);