ospfd: enhance TI-LFA memory management

Signed-off-by: GalaxyGorilla <sascha@netdef.org>
This commit is contained in:
GalaxyGorilla 2020-11-18 13:18:21 +00:00
parent 66dc21bb23
commit 669247b868
2 changed files with 40 additions and 7 deletions

View File

@ -71,15 +71,31 @@ struct ospf_path *ospf_path_new(void)
static struct ospf_path *ospf_path_dup(struct ospf_path *path)
{
struct ospf_path *new;
int memsize;
new = ospf_path_new();
memcpy(new, path, sizeof(struct ospf_path));
/* optional TI-LFA backup paths */
if (path->srni.backup_label_stack) {
memsize = sizeof(struct mpls_label_stack)
+ (sizeof(mpls_label_t)
* path->srni.backup_label_stack->num_labels);
new->srni.backup_label_stack =
XCALLOC(MTYPE_OSPF_PATH, memsize);
memcpy(new->srni.backup_label_stack,
path->srni.backup_label_stack, memsize);
}
return new;
}
void ospf_path_free(struct ospf_path *op)
{
/* optional TI-LFA backup paths */
if (op->srni.backup_label_stack)
XFREE(MTYPE_OSPF_PATH, op->srni.backup_label_stack);
XFREE(MTYPE_OSPF_PATH, op);
}

View File

@ -634,8 +634,28 @@ void ospf_ti_lfa_insert_backup_paths(struct ospf_area *area,
continue;
}
path->srni.backup_label_stack = q_space->label_stack;
path->srni.backup_nexthop = q_space->nexthop;
/* If there's a backup label stack, insert it*/
if (q_space->label_stack) {
/* Init the backup path data in path */
path->srni.backup_label_stack = XCALLOC(
MTYPE_OSPF_PATH,
sizeof(struct mpls_label_stack)
+ sizeof(mpls_label_t)
* q_space->label_stack
->num_labels);
/* Copy over the label stack */
path->srni.backup_label_stack->num_labels =
q_space->label_stack->num_labels;
memcpy(path->srni.backup_label_stack->label,
q_space->label_stack->label,
sizeof(mpls_label_t)
* q_space->label_stack
->num_labels);
/* Set the backup nexthop too */
path->srni.backup_nexthop = q_space->nexthop;
}
if (path->srni.backup_label_stack) {
mpls_label2str(q_space->label_stack->num_labels,
@ -665,13 +685,10 @@ void ospf_ti_lfa_free_p_spaces(struct ospf_area *area)
while ((q_space = q_spaces_pop(p_space->q_spaces))) {
ospf_spf_cleanup(q_space->root, q_space->vertex_list);
/*
* TODO: label stack is used for route installation
* XFREE(MTYPE_OSPF_Q_SPACE, q_space->label_stack);
*/
XFREE(MTYPE_OSPF_Q_SPACE, q_space->label_stack);
XFREE(MTYPE_OSPF_Q_SPACE, q_space);
}
ospf_spf_cleanup(p_space->root, p_space->vertex_list);
ospf_spf_cleanup(p_space->pc_spf, p_space->pc_vertex_list);
XFREE(MTYPE_OSPF_P_SPACE, p_space->protected_resource);