]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: Add a nexthop_dup() that allocates and copies
authorStephen Worley <sworley@cumulusnetworks.com>
Mon, 24 Jun 2019 15:37:49 +0000 (11:37 -0400)
committerStephen Worley <sworley@cumulusnetworks.com>
Wed, 26 Jun 2019 02:58:47 +0000 (22:58 -0400)
Add a nexthop_dup() api that both allocates and copies
a new nexthop from an old one. Still retain the old exposed
function nexthop_copy() so we can copy without allocation.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
lib/nexthop.c
lib/nexthop.h
lib/nexthop_group.c

index 405db6a5cb5a00f913c1d068044bd1067df9d77a..0984c1a168992fc29201fd664bedfde2e57709d1 100644 (file)
@@ -442,6 +442,15 @@ void nexthop_copy(struct nexthop *copy, const struct nexthop *nexthop,
                                   &nexthop->nh_label->label[0]);
 }
 
+struct nexthop *nexthop_dup(const struct nexthop *nexthop,
+                           struct nexthop *rparent)
+{
+       struct nexthop *new = nexthop_new();
+
+       nexthop_copy(new, nexthop, rparent);
+       return new;
+}
+
 /*
  * nexthop printing variants:
  *     %pNHvv
index ada7317a5899f0febce264741877ce68f451e136..20401cd5810b2188e195f6e6eeffb2edd15f5264 100644 (file)
@@ -152,8 +152,12 @@ extern const char *nexthop2str(const struct nexthop *nexthop,
                               char *str, int size);
 extern struct nexthop *nexthop_next(struct nexthop *nexthop);
 extern unsigned int nexthop_level(struct nexthop *nexthop);
+/* Copies to an already allocated nexthop struct */
 extern void nexthop_copy(struct nexthop *copy, const struct nexthop *nexthop,
                         struct nexthop *rparent);
+/* Duplicates a nexthop and returns the newly allocated nexthop */
+extern struct nexthop *nexthop_dup(const struct nexthop *nexthop,
+                                  struct nexthop *rparent);
 
 #ifdef __cplusplus
 }
index 4575ad6f70ec9b96b8c5407e2a44fa4437a6702b..7b3fb156255aa7044de8285722059d3078e48a8f 100644 (file)
@@ -185,9 +185,7 @@ void copy_nexthops(struct nexthop **tnh, const struct nexthop *nh,
        const struct nexthop *nh1;
 
        for (nh1 = nh; nh1; nh1 = nh1->next) {
-               nexthop = nexthop_new();
-               nexthop_copy(nexthop, nh1, rparent);
-
+               nexthop = nexthop_dup(nh1, rparent);
                nexthop_add(tnh, nexthop);
 
                if (CHECK_FLAG(nh1->flags, NEXTHOP_FLAG_RECURSIVE))