forked from Mirror/frr
lib: Add a nexthop_dup() that allocates and copies
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>
This commit is contained in:
parent
e7addf02a1
commit
504d0a4096
|
@ -442,6 +442,15 @@ void nexthop_copy(struct nexthop *copy, const struct nexthop *nexthop,
|
||||||
&nexthop->nh_label->label[0]);
|
&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:
|
* nexthop printing variants:
|
||||||
* %pNHvv
|
* %pNHvv
|
||||||
|
|
|
@ -152,8 +152,12 @@ extern const char *nexthop2str(const struct nexthop *nexthop,
|
||||||
char *str, int size);
|
char *str, int size);
|
||||||
extern struct nexthop *nexthop_next(struct nexthop *nexthop);
|
extern struct nexthop *nexthop_next(struct nexthop *nexthop);
|
||||||
extern unsigned int nexthop_level(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,
|
extern void nexthop_copy(struct nexthop *copy, const struct nexthop *nexthop,
|
||||||
struct nexthop *rparent);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,9 +185,7 @@ void copy_nexthops(struct nexthop **tnh, const struct nexthop *nh,
|
||||||
const struct nexthop *nh1;
|
const struct nexthop *nh1;
|
||||||
|
|
||||||
for (nh1 = nh; nh1; nh1 = nh1->next) {
|
for (nh1 = nh; nh1; nh1 = nh1->next) {
|
||||||
nexthop = nexthop_new();
|
nexthop = nexthop_dup(nh1, rparent);
|
||||||
nexthop_copy(nexthop, nh1, rparent);
|
|
||||||
|
|
||||||
nexthop_add(tnh, nexthop);
|
nexthop_add(tnh, nexthop);
|
||||||
|
|
||||||
if (CHECK_FLAG(nh1->flags, NEXTHOP_FLAG_RECURSIVE))
|
if (CHECK_FLAG(nh1->flags, NEXTHOP_FLAG_RECURSIVE))
|
||||||
|
|
Loading…
Reference in a new issue