]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: Put single nexthop copy into its own function
authorStephen Worley <sworley@cumulusnetworks.com>
Tue, 14 May 2019 22:40:27 +0000 (15:40 -0700)
committerStephen Worley <sworley@cumulusnetworks.com>
Wed, 26 Jun 2019 02:58:47 +0000 (22:58 -0400)
Put the code to copy a single nexthop into a function
of its own.

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

index 4cea14955abdcbe873997a0f29a57a7cb06ba50f..405db6a5cb5a00f913c1d068044bd1067df9d77a 100644 (file)
@@ -425,6 +425,23 @@ uint32_t nexthop_hash(const struct nexthop *nexthop)
        return key;
 }
 
+void nexthop_copy(struct nexthop *copy, const struct nexthop *nexthop,
+                 struct nexthop *rparent)
+{
+       copy->vrf_id = nexthop->vrf_id;
+       copy->ifindex = nexthop->ifindex;
+       copy->type = nexthop->type;
+       copy->flags = nexthop->flags;
+       memcpy(&copy->gate, &nexthop->gate, sizeof(nexthop->gate));
+       memcpy(&copy->src, &nexthop->src, sizeof(nexthop->src));
+       memcpy(&copy->rmap_src, &nexthop->rmap_src, sizeof(nexthop->rmap_src));
+       copy->rparent = rparent;
+       if (nexthop->nh_label)
+               nexthop_add_labels(copy, nexthop->nh_label_type,
+                                  nexthop->nh_label->num_labels,
+                                  &nexthop->nh_label->label[0]);
+}
+
 /*
  * nexthop printing variants:
  *     %pNHvv
index 5b6c12d4ef504005341f45c9c886c8c5f2a7f87f..ada7317a5899f0febce264741877ce68f451e136 100644 (file)
@@ -152,6 +152,8 @@ 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);
+extern void nexthop_copy(struct nexthop *copy, const struct nexthop *nexthop,
+                        struct nexthop *rparent);
 
 #ifdef __cplusplus
 }
index d250e0e9b660272ca84e285b734eb49b6c274eef..4575ad6f70ec9b96b8c5407e2a44fa4437a6702b 100644 (file)
@@ -186,19 +186,8 @@ void copy_nexthops(struct nexthop **tnh, const struct nexthop *nh,
 
        for (nh1 = nh; nh1; nh1 = nh1->next) {
                nexthop = nexthop_new();
-               nexthop->vrf_id = nh1->vrf_id;
-               nexthop->ifindex = nh1->ifindex;
-               nexthop->type = nh1->type;
-               nexthop->flags = nh1->flags;
-               memcpy(&nexthop->gate, &nh1->gate, sizeof(nh1->gate));
-               memcpy(&nexthop->src, &nh1->src, sizeof(nh1->src));
-               memcpy(&nexthop->rmap_src, &nh1->rmap_src,
-                      sizeof(nh1->rmap_src));
-               nexthop->rparent = rparent;
-               if (nh1->nh_label)
-                       nexthop_add_labels(nexthop, nh1->nh_label_type,
-                                          nh1->nh_label->num_labels,
-                                          &nh1->nh_label->label[0]);
+               nexthop_copy(nexthop, nh1, rparent);
+
                nexthop_add(tnh, nexthop);
 
                if (CHECK_FLAG(nh1->flags, NEXTHOP_FLAG_RECURSIVE))