From: Daniel Walton Date: Wed, 10 May 2017 13:42:00 +0000 (-0400) Subject: zebra: lsp_install() failed due to ZEBRA_FLAG_SELECTED check X-Git-Tag: reindent-master-before~176^2~2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=4caac24b23148a1ed37dd389b13e4475dc40bb64;p=mirror%2Ffrr.git zebra: lsp_install() failed due to ZEBRA_FLAG_SELECTED check ZEBRA_FLAG_SELECTED hasn't been set yet by the time lsp_install is called. The call path is: rib_process -> rib_process_add_fib -> zebra_mpls_lsp_install -> lsp_install but ZEBRA_FLAG_SELECTED is set in rib_process after it calls rib_process_add_fib. I can't think of anything that it would hurt to install the LSP regardless of whether ZEBRA_FLAG_SELECTED is set later. I also cleaned up some UI (json and display the pretty label names instead of their numeric values). Signed-off-by: Daniel Walton --- diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c index 76263024c5..bb9c913e3c 100644 --- a/zebra/zebra_mpls.c +++ b/zebra/zebra_mpls.c @@ -185,10 +185,6 @@ lsp_install (struct zebra_vrf *zvrf, mpls_label_t label, if (!lsp_table) return -1; - /* See if route entry is selected; we really expect only 1 entry here. */ - if (!CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)) - return 0; - lsp_type = lsp_type_from_rib_type (rib->type); added = changed = 0; @@ -1766,13 +1762,29 @@ mpls_str2label (const char *label_str, u_int8_t *num_labels, */ char * mpls_label2str (u_int8_t num_labels, mpls_label_t *labels, - char *buf, int len) + char *buf, int len, int pretty) { + char *buf_ptr = buf; buf[0] = '\0'; - if (num_labels == 1) - snprintf (buf, len, "%u", labels[0]); - else if (num_labels == 2) - snprintf (buf, len, "%u/%u", labels[0], labels[1]); + + if (pretty) { + if (num_labels == 1) { + label2str(labels[0], buf, len); + } else if (num_labels == 2) { + label2str(labels[0], buf, len); + buf_ptr += strlen(buf); + + snprintf (buf_ptr, len, "/"); + buf_ptr++; + + label2str(labels[1], buf_ptr, len); + } + } else { + if (num_labels == 1) + snprintf (buf, len, "%u", labels[0]); + else if (num_labels == 2) + snprintf (buf, len, "%u/%u", labels[0], labels[1]); + } return buf; } diff --git a/zebra/zebra_mpls.h b/zebra/zebra_mpls.h index e271edd2eb..b5a8f3173e 100644 --- a/zebra/zebra_mpls.h +++ b/zebra/zebra_mpls.h @@ -184,7 +184,7 @@ mpls_str2label (const char *label_str, u_int8_t *num_labels, */ char * mpls_label2str (u_int8_t num_labels, mpls_label_t *labels, - char *buf, int len); + char *buf, int len, int pretty); /* * Add/update global label block. diff --git a/zebra/zebra_mpls_null.c b/zebra/zebra_mpls_null.c index 168c8d003c..0333b6e6b4 100644 --- a/zebra/zebra_mpls_null.c +++ b/zebra/zebra_mpls_null.c @@ -32,7 +32,7 @@ int mpls_enabled; char * mpls_label2str (u_int8_t num_labels, mpls_label_t *labels, - char *buf, int len) + char *buf, int len, int pretty) { return NULL; } diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 1708138d83..186a2d022e 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -781,9 +781,9 @@ vty_show_ip_route_detail (struct vty *vty, struct route_node *rn, int mcast) /* Label information */ if (nexthop->nh_label && nexthop->nh_label->num_labels) { - vty_out (vty, " label %s", + vty_out (vty, ", label %s", mpls_label2str (nexthop->nh_label->num_labels, - nexthop->nh_label->label, buf, BUFSIZ)); + nexthop->nh_label->label, buf, BUFSIZ, 1)); } vty_out (vty, "%s", VTY_NEWLINE); @@ -803,6 +803,7 @@ vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib, json_object *json_nexthops = NULL; json_object *json_nexthop = NULL; json_object *json_route = NULL; + json_object *json_labels = NULL; if (json) { @@ -932,6 +933,16 @@ vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib, break; } + if (nexthop->nh_label && nexthop->nh_label->num_labels) + { + json_labels = json_object_new_array(); + + for (int label_index = 0; label_index < nexthop->nh_label->num_labels; label_index++) + json_object_array_add(json_labels, json_object_new_int(nexthop->nh_label->label[label_index])); + + json_object_object_add(json_nexthop, "labels", json_labels); + } + json_object_array_add(json_nexthops, json_nexthop); } @@ -1030,9 +1041,9 @@ vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib, /* Label information */ if (nexthop->nh_label && nexthop->nh_label->num_labels) { - vty_out (vty, " label %s", + vty_out (vty, ", label %s", mpls_label2str (nexthop->nh_label->num_labels, - nexthop->nh_label->label, buf, BUFSIZ)); + nexthop->nh_label->label, buf, BUFSIZ, 1)); } if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE)) @@ -2319,7 +2330,7 @@ static_config_ipv4 (struct vty *vty, safi_t safi, const char *cmd) if (si->snh_label.num_labels) vty_out (vty, " label %s", mpls_label2str (si->snh_label.num_labels, - si->snh_label.label, buf, sizeof buf)); + si->snh_label.label, buf, sizeof buf, 0)); vty_out (vty, "%s", VTY_NEWLINE); @@ -3812,7 +3823,7 @@ static_config_ipv6 (struct vty *vty) if (si->snh_label.num_labels) vty_out (vty, " label %s", mpls_label2str (si->snh_label.num_labels, - si->snh_label.label, buf, sizeof buf)); + si->snh_label.label, buf, sizeof buf, 0)); vty_out (vty, "%s", VTY_NEWLINE);