From: Stephen Worley Date: Tue, 14 May 2019 22:40:27 +0000 (-0700) Subject: lib: Put single nexthop copy into its own function X-Git-Tag: base_7.2~163^2~2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=e7addf02a1164499c515fdcfc8c8bb75c383ff90;p=matthieu%2Ffrr.git lib: Put single nexthop copy into its own function Put the code to copy a single nexthop into a function of its own. Signed-off-by: Stephen Worley --- diff --git a/lib/nexthop.c b/lib/nexthop.c index 4cea14955a..405db6a5cb 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -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(©->gate, &nexthop->gate, sizeof(nexthop->gate)); + memcpy(©->src, &nexthop->src, sizeof(nexthop->src)); + memcpy(©->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 diff --git a/lib/nexthop.h b/lib/nexthop.h index 5b6c12d4ef..ada7317a58 100644 --- a/lib/nexthop.h +++ b/lib/nexthop.h @@ -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 } diff --git a/lib/nexthop_group.c b/lib/nexthop_group.c index d250e0e9b6..4575ad6f70 100644 --- a/lib/nexthop_group.c +++ b/lib/nexthop_group.c @@ -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))