]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: Always copy nhg and depends on nhe alloc
authorStephen Worley <sworley@cumulusnetworks.com>
Tue, 26 Mar 2019 23:40:23 +0000 (19:40 -0400)
committerStephen Worley <sworley@cumulusnetworks.com>
Fri, 25 Oct 2019 15:13:38 +0000 (11:13 -0400)
Changed our alloc function to just copy the nhg and
nhg_depends. This makes the zebra_nhg_find code a
little bit cleaner, hopefully preventing bugs.

The only issue with this is that it makes us have to loop
over the nexthops in a group an extra time for the copies.

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

index 42daefeea9efbe7690e5248fd4c3169059493563..ea81d180db52f3a923ad59445231d49710becc80 100644 (file)
@@ -2399,12 +2399,13 @@ int netlink_nexthop_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
                        /* This is a new nexthop group */
                        nhe = zebra_nhg_find(nhg, vrf_id, afi, id, nhg_depends,
                                             dep_count);
+                       zebra_nhg_free_group_depends(nhg, nhg_depends);
+
                        if (!nhe) {
                                flog_err(
                                        EC_ZEBRA_TABLE_LOOKUP_FAILED,
                                        "Zebra failed to find or create a nexthop hash entry for ID (%u) from the kernel",
                                        id);
-                               zebra_nhg_free_group_depends(nhg, nhg_depends);
                                return -1;
                        }
 
index 140e6a9abf92b7874dbbb8806db744d8d12ee582..3c78ce525310fe78bb3f053f790a03169923b970 100644 (file)
@@ -185,9 +185,10 @@ static void *zebra_nhg_alloc(void *arg)
        nhe->nhg_depends = NULL;
 
        if (copy->nhg_depends)
-               nhe->nhg_depends = copy->nhg_depends;
+               nhe->nhg_depends = nhg_depend_dup_list(copy->nhg_depends);
 
-       nhe->nhg = copy->nhg;
+       nhe->nhg = nexthop_group_new();
+       nexthop_group_copy(nhe->nhg, copy->nhg);
 
        nhe->vrf_id = copy->vrf_id;
        nhe->afi = copy->afi;
@@ -352,11 +353,8 @@ struct nhg_hash_entry *zebra_nhg_find(struct nexthop_group *nhg,
        else
                nhe = hash_lookup(zrouter.nhgs, &lookup);
 
-       if (!nhe) {
+       if (!nhe)
                nhe = hash_get(zrouter.nhgs, &lookup, zebra_nhg_alloc);
-       } else {
-               zebra_nhg_free_group_depends(nhg, nhg_depends);
-       }
 
        return nhe;
 }
index e882c9d6944129942e329409de6f5284a417eaec..a5b939baa9a6a4d222f2fe51df77d1a9025ef882 100644 (file)
@@ -2662,6 +2662,7 @@ int rib_add_multipath(afi_t afi, safi_t safi, struct prefix *p,
 
        if (nhe) {
                // TODO: Add interface pointer
+               zebra_nhg_free_group_depends(re->ng, NULL);
                re->ng = nhe->nhg;
                re->nhe_id = nhe->id;
                nhe->refcnt++;