Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib, zebra: Do not have duplicate memory type problems #17492

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,32 @@ void nexthop_del_labels(struct nexthop *nexthop)
nexthop->nh_label_type = ZEBRA_LSP_NONE;
}

void nexthop_change_labels(struct nexthop *nexthop, struct mpls_label_stack *new_stack)
{
struct mpls_label_stack *nh_label_tmp;
uint32_t i;

/* Enforce limit on label stack size */
if (new_stack->num_labels > MPLS_MAX_LABELS)
new_stack->num_labels = MPLS_MAX_LABELS;

/* Resize the array to accommodate the new label stack */
if (new_stack->num_labels > nexthop->nh_label->num_labels) {
nh_label_tmp = XREALLOC(MTYPE_NH_LABEL, nexthop->nh_label,
sizeof(struct mpls_label_stack) +
new_stack->num_labels * sizeof(mpls_label_t));
if (nh_label_tmp) {
nexthop->nh_label = nh_label_tmp;
nexthop->nh_label->num_labels = new_stack->num_labels;
} else
new_stack->num_labels = nexthop->nh_label->num_labels;
}

/* Copy the label stack into the array */
for (i = 0; i < new_stack->num_labels; i++)
nexthop->nh_label->label[i] = new_stack->label[i];
}

void nexthop_add_srv6_seg6local(struct nexthop *nexthop, uint32_t action,
const struct seg6local_context *ctx)
{
Expand Down
2 changes: 2 additions & 0 deletions lib/nexthop.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ void nexthops_free(struct nexthop *nexthop);
void nexthop_add_labels(struct nexthop *nexthop, enum lsp_types_t ltype,
uint8_t num_labels, const mpls_label_t *labels);
void nexthop_del_labels(struct nexthop *);
void nexthop_change_labels(struct nexthop *nexthop, struct mpls_label_stack *new_stack);

void nexthop_add_srv6_seg6local(struct nexthop *nexthop, uint32_t action,
const struct seg6local_context *ctx);
void nexthop_del_srv6_seg6local(struct nexthop *nexthop);
Expand Down
27 changes: 1 addition & 26 deletions zebra/zebra_mpls.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
DEFINE_MTYPE_STATIC(ZEBRA, LSP, "MPLS LSP object");
DEFINE_MTYPE_STATIC(ZEBRA, FEC, "MPLS FEC object");
DEFINE_MTYPE_STATIC(ZEBRA, NHLFE, "MPLS nexthop object");
DEFINE_MTYPE_STATIC(ZEBRA, NH_LABEL, "Nexthop label");

bool mpls_enabled;
bool mpls_pw_reach_strict; /* Strict reachability checking */
Expand Down Expand Up @@ -1453,31 +1452,7 @@ static int nhlfe_del(struct zebra_nhlfe *nhlfe)
static void nhlfe_out_label_update(struct zebra_nhlfe *nhlfe,
struct mpls_label_stack *nh_label)
{
struct mpls_label_stack *nh_label_tmp;
int i;

/* Enforce limit on label stack size */
if (nh_label->num_labels > MPLS_MAX_LABELS)
nh_label->num_labels = MPLS_MAX_LABELS;

/* Resize the array to accommodate the new label stack */
if (nh_label->num_labels > nhlfe->nexthop->nh_label->num_labels) {
nh_label_tmp = XREALLOC(MTYPE_NH_LABEL, nhlfe->nexthop->nh_label,
sizeof(struct mpls_label_stack) +
nh_label->num_labels *
sizeof(mpls_label_t));
if (nh_label_tmp) {
nhlfe->nexthop->nh_label = nh_label_tmp;
nhlfe->nexthop->nh_label->num_labels =
nh_label->num_labels;
} else
nh_label->num_labels =
nhlfe->nexthop->nh_label->num_labels;
}

/* Copy the label stack into the array */
for (i = 0; i < nh_label->num_labels; i++)
nhlfe->nexthop->nh_label->label[i] = nh_label->label[i];
nexthop_change_labels(nhlfe->nexthop, nh_label);
}

static int mpls_lsp_uninstall_all(struct hash *lsp_table, struct zebra_lsp *lsp,
Expand Down
Loading