]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zapi: add support for routes with multiple labels
authorRenato Westphal <renato@opensourcerouting.org>
Sun, 20 Aug 2017 22:57:36 +0000 (19:57 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Wed, 23 Aug 2017 21:58:35 +0000 (18:58 -0300)
This will be necessary for the Segment Routing feature.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
lib/mpls.h
lib/zclient.c
lib/zclient.h
zebra/zebra_mpls.h
zebra/zserv.c

index 025770d479645bebc23d826cd96ba15d63dbbecd..bf98eecd81615adafe8b22f4002579a3610ba18a 100644 (file)
@@ -44,6 +44,9 @@
 #define MPLS_DEFAULT_MIN_SRGB_LABEL        16000
 #define MPLS_DEFAULT_MAX_SRGB_LABEL        23999
 
+/* Maximum # labels that can be pushed. */
+#define MPLS_MAX_LABELS                    16
+
 #define IS_MPLS_RESERVED_LABEL(label)                                          \
        (label >= MPLS_MIN_RESERVED_LABEL && label <= MPLS_MAX_RESERVED_LABEL)
 
index 3f5c7a0f6f5afeb923addf9695e248e0cc6a0abd..e063c7151f8252ae95d549955c4d8a8118e9cf4b 100644 (file)
@@ -970,10 +970,26 @@ int zapi_route_encode(u_char cmd, struct stream *s, struct zapi_route *api)
                                break;
                        }
 
-                       /* For labeled-unicast, each nexthop is followed
-                        * by label. */
-                       if (CHECK_FLAG(api->message, ZAPI_MESSAGE_LABEL))
-                               stream_putl(s, api_nh->label);
+                       /* MPLS labels for BGP-LU or Segment Routing */
+                       if (CHECK_FLAG(api->message, ZAPI_MESSAGE_LABEL)) {
+                               if (api_nh->label_num > MPLS_MAX_LABELS) {
+                                       char buf[PREFIX2STR_BUFFER];
+                                       prefix2str(&api->prefix, buf,
+                                                  sizeof(buf));
+                                       zlog_err(
+                                               "%s: prefix %s: can't encode "
+                                               "%u labels (maximum is %u)",
+                                               __func__, buf,
+                                               api_nh->label_num,
+                                               MPLS_MAX_LABELS);
+                                       return -1;
+                               }
+
+                               stream_putc(s, api_nh->label_num);
+                               stream_put(s, &api_nh->labels[0],
+                                          api_nh->label_num
+                                                  * sizeof(mpls_label_t));
+                       }
                }
        }
 
@@ -1064,11 +1080,21 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api)
                                break;
                        }
 
-                       /* For labeled-unicast, each nexthop is followed
-                        * by label. */
+                       /* MPLS labels for BGP-LU or Segment Routing */
                        if (CHECK_FLAG(api->message, ZAPI_MESSAGE_LABEL)) {
-                               stream_get(&api_nh->label, s,
-                                          sizeof(api_nh->label));
+                               api_nh->label_num = stream_getc(s);
+
+                               if (api_nh->label_num > MPLS_MAX_LABELS) {
+                                       zlog_warn(
+                                               "%s: invalid number of MPLS "
+                                               "labels (%u)",
+                                               __func__, api_nh->label_num);
+                                       return -1;
+                               }
+
+                               stream_get(&api_nh->labels[0], s,
+                                          api_nh->label_num
+                                                  * sizeof(mpls_label_t));
                        }
                }
        }
index 2e450ed398f212caac8e56556d9b280d5161c63f..40ddbf62df2d121337fe05b39840db37fcd0b780 100644 (file)
@@ -230,7 +230,10 @@ struct zapi_nexthop {
        enum nexthop_types_t type;
        ifindex_t ifindex;
        union g_addr gate;
-       mpls_label_t label;
+
+       /* MPLS labels for BGP-LU or Segment Routing */
+       uint8_t label_num;
+       mpls_label_t labels[MPLS_MAX_LABELS];
 };
 
 struct zapi_route {
index 6bddc4d00f15178622032b58545e097235ff8a88..c8df8670f4a5d7f5231196124696afa3ce8c3426 100644 (file)
@@ -37,8 +37,6 @@
 
 /* Definitions and macros. */
 
-#define MPLS_MAX_LABELS 16  /* Maximum # labels that can be pushed. */
-
 #define NHLFE_FAMILY(nhlfe)                                                    \
        (((nhlfe)->nexthop->type == NEXTHOP_TYPE_IPV6                          \
          || (nhlfe)->nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX)              \
index 94e34865b5c23fda03b31a4cc1cfc889d3bce6e9..de475dccfdd2cf824908af5d780c95c9760cd1df 100644 (file)
@@ -1222,8 +1222,9 @@ static int zread_route_add(struct zserv *client, u_short length,
 
                                label_type =
                                        lsp_type_from_re_type(client->proto);
-                               nexthop_add_labels(nexthop, label_type, 1,
-                                                  &api_nh->label);
+                               nexthop_add_labels(nexthop, label_type,
+                                                  api_nh->label_num,
+                                                  &api_nh->labels[0]);
                        }
                }
        }