From: Mark Stapp Date: Wed, 11 Aug 2021 17:58:13 +0000 (-0400) Subject: zebra: mpls validation and static lsp fixes X-Git-Tag: base_8.1~193^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=refs%2Fpull%2F9380%2Fhead;p=mirror%2Ffrr.git zebra: mpls validation and static lsp fixes Handle TYPE_IFINDEX nexthops more consistently in a few places; be more specific about a few integer return values that were being treated as booleans. Signed-off-by: Mark Stapp --- diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c index 2f83fe4e28..c9450541e8 100644 --- a/zebra/zebra_mpls.c +++ b/zebra/zebra_mpls.c @@ -1295,6 +1295,9 @@ static zebra_nhlfe_t *nhlfe_alloc(zebra_lsp_t *lsp, enum lsp_types_t lsp_type, nexthop->ifindex = ifindex; break; case NEXTHOP_TYPE_BLACKHOLE: + if (IS_ZEBRA_DEBUG_MPLS) + zlog_debug("%s: invalid: blackhole nexthop", __func__); + nexthop_free(nexthop); XFREE(MTYPE_NHLFE, nhlfe); return NULL; @@ -1319,6 +1322,14 @@ static zebra_nhlfe_t *nhlfe_add(zebra_lsp_t *lsp, enum lsp_types_t lsp_type, if (!lsp) return NULL; + /* Must have labels */ + if (num_labels == 0 || labels == NULL) { + if (IS_ZEBRA_DEBUG_MPLS) + zlog_debug("%s: invalid nexthop: no labels", __func__); + + return NULL; + } + /* Allocate new object */ nhlfe = nhlfe_alloc(lsp, lsp_type, gtype, gate, ifindex, num_labels, labels); @@ -1530,8 +1541,13 @@ static json_object *nhlfe_json(zebra_nhlfe_t *nhlfe) ifindex2ifname(nexthop->ifindex, nexthop->vrf_id)); break; - case NEXTHOP_TYPE_BLACKHOLE: case NEXTHOP_TYPE_IFINDEX: + if (nexthop->ifindex) + json_object_string_add(json_nhlfe, "interface", + ifindex2ifname(nexthop->ifindex, + nexthop->vrf_id)); + break; + case NEXTHOP_TYPE_BLACKHOLE: break; } @@ -1592,8 +1608,13 @@ static void nhlfe_print(zebra_nhlfe_t *nhlfe, struct vty *vty, ifindex2ifname(nexthop->ifindex, nexthop->vrf_id)); break; - case NEXTHOP_TYPE_BLACKHOLE: case NEXTHOP_TYPE_IFINDEX: + if (nexthop->ifindex) + vty_out(vty, " dev %s", + ifindex2ifname(nexthop->ifindex, + nexthop->vrf_id)); + break; + case NEXTHOP_TYPE_BLACKHOLE: break; } vty_out(vty, "%s", @@ -2835,9 +2856,21 @@ static bool ftn_update_znh(bool add_p, enum lsp_types_t type, break; success = true; break; - case NEXTHOP_TYPE_BLACKHOLE: case NEXTHOP_TYPE_IFINDEX: + if (znh->type != NEXTHOP_TYPE_IFINDEX) + continue; + if (nexthop->ifindex != znh->ifindex) + continue; + + found = true; + + if (!ftn_update_nexthop(add_p, nexthop, type, znh)) + break; + success = true; break; + case NEXTHOP_TYPE_BLACKHOLE: + /* Not valid */ + continue; } if (found) @@ -3815,8 +3848,13 @@ static char *nhlfe_config_str(const zebra_nhlfe_t *nhlfe, char *buf, int size) ifindex2ifname(nh->ifindex, VRF_DEFAULT), size); break; - case NEXTHOP_TYPE_BLACKHOLE: case NEXTHOP_TYPE_IFINDEX: + if (nh->ifindex) + strlcat(buf, + ifindex2ifname(nh->ifindex, VRF_DEFAULT), + size); + break; + case NEXTHOP_TYPE_BLACKHOLE: break; } diff --git a/zebra/zebra_mpls_vty.c b/zebra/zebra_mpls_vty.c index d789f20071..1ef70270f8 100644 --- a/zebra/zebra_mpls_vty.c +++ b/zebra/zebra_mpls_vty.c @@ -67,6 +67,11 @@ static int zebra_mpls_transit_lsp(struct vty *vty, int add_cmd, return CMD_WARNING_CONFIG_FAILED; } + if (gate_str == NULL) { + vty_out(vty, "%% No Nexthop Information\n"); + return CMD_WARNING_CONFIG_FAILED; + } + out_label = MPLS_LABEL_IMPLICIT_NULL; /* as initialization */ label = atoi(inlabel_str); if (!IS_MPLS_UNRESERVED_LABEL(label)) { @@ -86,21 +91,18 @@ static int zebra_mpls_transit_lsp(struct vty *vty, int add_cmd, } in_label = label; - gtype = NEXTHOP_TYPE_BLACKHOLE; /* as initialization */ - if (gate_str) { - /* Gateway is a IPv4 or IPv6 nexthop. */ - ret = inet_pton(AF_INET6, gate_str, &gate.ipv6); - if (ret) - gtype = NEXTHOP_TYPE_IPV6; + /* Gateway is a IPv4 or IPv6 nexthop. */ + ret = inet_pton(AF_INET6, gate_str, &gate.ipv6); + if (ret == 1) + gtype = NEXTHOP_TYPE_IPV6; + else { + ret = inet_pton(AF_INET, gate_str, &gate.ipv4); + if (ret == 1) + gtype = NEXTHOP_TYPE_IPV4; else { - ret = inet_pton(AF_INET, gate_str, &gate.ipv4); - if (ret) - gtype = NEXTHOP_TYPE_IPV4; - else { - vty_out(vty, "%% Invalid nexthop\n"); - return CMD_WARNING_CONFIG_FAILED; - } + vty_out(vty, "%% Invalid nexthop\n"); + return CMD_WARNING_CONFIG_FAILED; } } @@ -131,7 +133,7 @@ static int zebra_mpls_transit_lsp(struct vty *vty, int add_cmd, ret = zebra_mpls_static_lsp_del(zvrf, in_label, gtype, &gate, 0); - if (ret) { + if (ret != 0) { vty_out(vty, "%% LSP cannot be %s\n", add_cmd ? "added" : "deleted"); return CMD_WARNING_CONFIG_FAILED;