]> git.proxmox.com Git - mirror_frr.git/commitdiff
zebra: mpls validation and static lsp fixes
authorMark Stapp <mjs.ietf@gmail.com>
Wed, 11 Aug 2021 17:58:13 +0000 (13:58 -0400)
committerMark Stapp <mjs.ietf@gmail.com>
Thu, 12 Aug 2021 12:53:53 +0000 (08:53 -0400)
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>
zebra/zebra_mpls.c
zebra/zebra_mpls_vty.c

index 2f83fe4e2844aafbd64f0aafd51a21c7e93ed3af..c9450541e84f21f7e1a800aa24ace3118e054c0d 100644 (file)
@@ -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;
        }
 
index d789f200715462412b11a25050672092b6705dc1..1ef70270f82c94caa22e514d5eb11b6f43a377c4 100644 (file)
@@ -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;