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: Append labels on nexthop resolve #4808

Closed
wants to merge 2 commits into from
Closed
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
30 changes: 30 additions & 0 deletions lib/nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,36 @@ void nexthop_add_labels(struct nexthop *nexthop, enum lsp_types_t type,
nexthop->nh_label = nh_label;
}

void nexthop_append_labels(struct nexthop *nexthop, enum lsp_types_t type,
uint8_t num_labels, mpls_label_t *label)
{
struct mpls_label_stack *nh_label;
int i, j;
uint8_t old_num_labels =
(nexthop->nh_label ? nexthop->nh_label->num_labels : 0);

nh_label =
XCALLOC(MTYPE_NH_LABEL, sizeof(struct mpls_label_stack)
+ ((old_num_labels + num_labels)
* sizeof(mpls_label_t)));
nh_label->num_labels = old_num_labels + num_labels;

for (i = 0; i < old_num_labels; i++)
nh_label->label[i] = nexthop->nh_label->label[i];

for (i = old_num_labels, j = 0; i < nh_label->num_labels; i++, j++)
nh_label->label[i] = *(label + j);

/* Free up old stack */
nexthop_del_labels(nexthop);

/*
* Yes, we are overwriting the type already there with the new one.
*/
nexthop->nh_label_type = type;
nexthop->nh_label = nh_label;
}

/* Free label information of nexthop, if present. */
void nexthop_del_labels(struct nexthop *nexthop)
{
Expand Down
2 changes: 2 additions & 0 deletions lib/nexthop.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ void nexthops_free(struct nexthop *nexthop);

void nexthop_add_labels(struct nexthop *, enum lsp_types_t, uint8_t,
mpls_label_t *);
void nexthop_append_labels(struct nexthop *, enum lsp_types_t, uint8_t,
mpls_label_t *);
void nexthop_del_labels(struct nexthop *);

/*
Expand Down
78 changes: 34 additions & 44 deletions zebra/rt_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1019,33 +1019,28 @@ static void _netlink_route_build_singlepath(const char *routedesc, int bytelen,
label_buf[0] = '\0';

assert(nexthop);
for (const struct nexthop *nh = nexthop; nh; nh = nh->rparent) {
char label_buf1[20];
char label_buf1[20];

nh_label = nh->nh_label;
if (!nh_label || !nh_label->num_labels)
continue;
nh_label = nexthop->nh_label;

for (int i = 0; i < nh_label->num_labels; i++) {
if (nh_label->label[i] == MPLS_LABEL_IMPLICIT_NULL)
continue;
for (int i = 0; nh_label && i < nh_label->num_labels; i++) {
if (nh_label->label[i] == MPLS_LABEL_IMPLICIT_NULL)
continue;

if (IS_ZEBRA_DEBUG_KERNEL) {
if (!num_labels)
sprintf(label_buf, "label %u",
nh_label->label[i]);
else {
sprintf(label_buf1, "/%u",
nh_label->label[i]);
strlcat(label_buf, label_buf1,
sizeof(label_buf));
}
if (IS_ZEBRA_DEBUG_KERNEL) {
if (!num_labels)
sprintf(label_buf, "label %u",
nh_label->label[i]);
else {
sprintf(label_buf1, "/%u", nh_label->label[i]);
strlcat(label_buf, label_buf1,
sizeof(label_buf));
}

out_lse[num_labels] =
mpls_lse_encode(nh_label->label[i], 0, 0, 0);
num_labels++;
}

out_lse[num_labels] =
mpls_lse_encode(nh_label->label[i], 0, 0, 0);
num_labels++;
}

if (num_labels) {
Expand Down Expand Up @@ -1210,33 +1205,28 @@ static void _netlink_route_build_multipath(const char *routedesc, int bytelen,
label_buf[0] = '\0';

assert(nexthop);
for (const struct nexthop *nh = nexthop; nh; nh = nh->rparent) {
char label_buf1[20];
char label_buf1[20];

nh_label = nh->nh_label;
if (!nh_label || !nh_label->num_labels)
continue;
nh_label = nexthop->nh_label;

for (int i = 0; i < nh_label->num_labels; i++) {
if (nh_label->label[i] == MPLS_LABEL_IMPLICIT_NULL)
continue;
for (int i = 0; nh_label && i < nh_label->num_labels; i++) {
if (nh_label->label[i] == MPLS_LABEL_IMPLICIT_NULL)
continue;

if (IS_ZEBRA_DEBUG_KERNEL) {
if (!num_labels)
sprintf(label_buf, "label %u",
nh_label->label[i]);
else {
sprintf(label_buf1, "/%u",
nh_label->label[i]);
strlcat(label_buf, label_buf1,
sizeof(label_buf));
}
if (IS_ZEBRA_DEBUG_KERNEL) {
if (!num_labels)
sprintf(label_buf, "label %u",
nh_label->label[i]);
else {
sprintf(label_buf1, "/%u", nh_label->label[i]);
strlcat(label_buf, label_buf1,
sizeof(label_buf));
}

out_lse[num_labels] =
mpls_lse_encode(nh_label->label[i], 0, 0, 0);
num_labels++;
}

out_lse[num_labels] =
mpls_lse_encode(nh_label->label[i], 0, 0, 0);
num_labels++;
}

if (num_labels) {
Expand Down
10 changes: 10 additions & 0 deletions zebra/zebra_nhg.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ static void nexthop_set_resolved(afi_t afi, const struct nexthop *newhop,
newhop->nh_label->num_labels,
&newhop->nh_label->label[0]);

/* Append labels of parent as well.
* We have to do this since nexthop objects being
* installed need all of them. We can't iterate up the tree
* when we install the route like we used to.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I'm still missing something - maybe this comment is throwing me off - why can't we iterate as we ... always have done? We have the recursive nexthop that is being resolved, and we have the resolving nexthops - what is it that we can't iterate over?

if (nexthop->nh_label)
nexthop_append_labels(resolved_hop, nexthop->nh_label_type,
nexthop->nh_label->num_labels,
&nexthop->nh_label->label[0]);

resolved_hop->rparent = nexthop;
_nexthop_add(&nexthop->resolved, resolved_hop);
}
Expand Down