summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Stapp <mjs.ietf@gmail.com>2021-08-11 13:58:13 -0400
committerMark Stapp <mjs.ietf@gmail.com>2021-08-12 08:53:53 -0400
commita44e3106314342abd18d16a7ae4b44bd822591d7 (patch)
treecbc8f7ebd9d901391279b192b82d9d780ce9d316
parentc123e9df54e55c61b1666ec3b55b267c86865d49 (diff)
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 <mjs.ietf@gmail.com>
-rw-r--r--zebra/zebra_mpls.c46
-rw-r--r--zebra/zebra_mpls_vty.c30
2 files changed, 58 insertions, 18 deletions
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;