forked from Mirror/frr
lib: Add a couple functions to nexthop_group.c
Add nexthop_group_copy and nexthop_group_add_sorted functions. nexthop_group_copy -> Copy src nexthop_group into dst nexthop_group nexthop_group_add_sorted -> Adds a new nexthop to the nexthop group in a sorted manner. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
parent
f3afd0a4e1
commit
6c8b51e172
|
@ -100,6 +100,12 @@ struct nexthop_group *nexthop_group_new(void)
|
|||
return XCALLOC(MTYPE_NEXTHOP_GROUP, sizeof(struct nexthop_group));
|
||||
}
|
||||
|
||||
void nexthop_group_copy(struct nexthop_group *to, struct nexthop_group *from)
|
||||
{
|
||||
/* Copy everything, including recursive info */
|
||||
copy_nexthops(&to->nexthop, from->nexthop, NULL);
|
||||
}
|
||||
|
||||
void nexthop_group_delete(struct nexthop_group **nhg)
|
||||
{
|
||||
XFREE(MTYPE_NEXTHOP_GROUP, *nhg);
|
||||
|
@ -119,6 +125,35 @@ void nexthop_add(struct nexthop **target, struct nexthop *nexthop)
|
|||
nexthop->prev = last;
|
||||
}
|
||||
|
||||
void nexthop_group_add_sorted(struct nexthop_group *nhg,
|
||||
struct nexthop *nexthop)
|
||||
{
|
||||
struct nexthop *position, *prev;
|
||||
|
||||
for (position = nhg->nexthop, prev = NULL; position;
|
||||
prev = position, position = position->next) {
|
||||
if (nexthop_cmp(position, nexthop) > 0) {
|
||||
nexthop->next = position;
|
||||
nexthop->prev = prev;
|
||||
|
||||
if (nexthop->prev)
|
||||
nexthop->prev->next = nexthop;
|
||||
else
|
||||
nhg->nexthop = nexthop;
|
||||
|
||||
position->prev = nexthop;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
nexthop->prev = prev;
|
||||
if (prev)
|
||||
prev->next = nexthop;
|
||||
else
|
||||
nhg->nexthop = nexthop;
|
||||
|
||||
}
|
||||
|
||||
/* Delete nexthop from a nexthop list. */
|
||||
void nexthop_del(struct nexthop_group *nhg, struct nexthop *nh)
|
||||
{
|
||||
|
|
|
@ -43,6 +43,10 @@ struct nexthop_group *nexthop_group_new(void);
|
|||
void nexthop_group_delete(struct nexthop_group **nhg);
|
||||
|
||||
void nexthop_add(struct nexthop **target, struct nexthop *nexthop);
|
||||
void nexthop_group_add_sorted(struct nexthop_group *nhg,
|
||||
struct nexthop *nexthop);
|
||||
void nexthop_group_copy(struct nexthop_group *to,
|
||||
struct nexthop_group *from);
|
||||
void nexthop_del(struct nexthop_group *nhg, struct nexthop *nexthop);
|
||||
void copy_nexthops(struct nexthop **tnh, const struct nexthop *nh,
|
||||
struct nexthop *rparent);
|
||||
|
|
Loading…
Reference in a new issue