summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ldpd/ldp_zebra.c23
-rw-r--r--lib/log.c1
-rw-r--r--lib/zclient.c76
-rw-r--r--lib/zclient.h18
-rw-r--r--ospfd/ospf_sr.c13
-rw-r--r--zebra/zapi_msg.c141
-rw-r--r--zebra/zebra_mpls.c57
-rw-r--r--zebra/zebra_mpls.h13
8 files changed, 273 insertions, 69 deletions
diff --git a/ldpd/ldp_zebra.c b/ldpd/ldp_zebra.c
index 5582b95c83..884ae159be 100644
--- a/ldpd/ldp_zebra.c
+++ b/ldpd/ldp_zebra.c
@@ -109,6 +109,7 @@ static int
ldp_zebra_send_mpls_labels(int cmd, struct kroute *kr)
{
struct zapi_labels zl = {};
+ struct zapi_nexthop_label *znh;
if (kr->local_label < MPLS_LABEL_RESERVED_MAX ||
kr->remote_label == NO_LABEL)
@@ -141,28 +142,30 @@ ldp_zebra_send_mpls_labels(int cmd, struct kroute *kr)
zl.route.instance = kr->route_instance;
/* Set nexthop. */
+ zl.nexthop_num = 1;
+ znh = &zl.nexthops[0];
switch (kr->af) {
case AF_INET:
- zl.nexthop.family = AF_INET;
- zl.nexthop.address.ipv4 = kr->nexthop.v4;
+ znh->family = AF_INET;
+ znh->address.ipv4 = kr->nexthop.v4;
if (kr->ifindex)
- zl.nexthop.type = NEXTHOP_TYPE_IPV4_IFINDEX;
+ znh->type = NEXTHOP_TYPE_IPV4_IFINDEX;
else
- zl.nexthop.type = NEXTHOP_TYPE_IPV4;
+ znh->type = NEXTHOP_TYPE_IPV4;
break;
case AF_INET6:
- zl.nexthop.family = AF_INET6;
- zl.nexthop.address.ipv6 = kr->nexthop.v6;
+ znh->family = AF_INET6;
+ znh->address.ipv6 = kr->nexthop.v6;
if (kr->ifindex)
- zl.nexthop.type = NEXTHOP_TYPE_IPV6_IFINDEX;
+ znh->type = NEXTHOP_TYPE_IPV6_IFINDEX;
else
- zl.nexthop.type = NEXTHOP_TYPE_IPV6;
+ znh->type = NEXTHOP_TYPE_IPV6;
break;
default:
break;
}
- zl.nexthop.ifindex = kr->ifindex;
- zl.nexthop.label = kr->remote_label;
+ znh->ifindex = kr->ifindex;
+ znh->label = kr->remote_label;
return zebra_send_mpls_labels(zclient, cmd, &zl);
}
diff --git a/lib/log.c b/lib/log.c
index f1c0fabfba..c777868736 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -1041,6 +1041,7 @@ static const struct zebra_desc_table command_types[] = {
DESC_ENTRY(ZEBRA_INTERFACE_LINK_PARAMS),
DESC_ENTRY(ZEBRA_MPLS_LABELS_ADD),
DESC_ENTRY(ZEBRA_MPLS_LABELS_DELETE),
+ DESC_ENTRY(ZEBRA_MPLS_LABELS_REPLACE),
DESC_ENTRY(ZEBRA_IPMR_ROUTE_STATS),
DESC_ENTRY(ZEBRA_LABEL_MANAGER_CONNECT),
DESC_ENTRY(ZEBRA_LABEL_MANAGER_CONNECT_ASYNC),
diff --git a/lib/zclient.c b/lib/zclient.c
index a82484e42d..92a495ac61 100644
--- a/lib/zclient.c
+++ b/lib/zclient.c
@@ -2461,6 +2461,8 @@ int zebra_send_mpls_labels(struct zclient *zclient, int cmd,
int zapi_labels_encode(struct stream *s, int cmd, struct zapi_labels *zl)
{
+ struct zapi_nexthop_label *znh;
+
stream_reset(s);
zclient_create_header(s, cmd, VRF_DEFAULT);
@@ -2475,20 +2477,34 @@ int zapi_labels_encode(struct stream *s, int cmd, struct zapi_labels *zl)
stream_putw(s, zl->route.instance);
}
- stream_putc(s, zl->nexthop.type);
- stream_putw(s, zl->nexthop.family);
- switch (zl->nexthop.family) {
- case AF_INET:
- stream_put_in_addr(s, &zl->nexthop.address.ipv4);
- break;
- case AF_INET6:
- stream_write(s, (uint8_t *)&zl->nexthop.address.ipv6, 16);
- break;
- default:
- break;
+ if (zl->nexthop_num > MULTIPATH_NUM) {
+ flog_err(
+ EC_LIB_ZAPI_ENCODE,
+ "%s: label %u: can't encode %u nexthops (maximum is %u)",
+ __func__, zl->local_label, zl->nexthop_num,
+ MULTIPATH_NUM);
+ return -1;
+ }
+ stream_putw(s, zl->nexthop_num);
+
+ for (int i = 0; i < zl->nexthop_num; i++) {
+ znh = &zl->nexthops[i];
+
+ stream_putc(s, znh->type);
+ stream_putw(s, znh->family);
+ switch (znh->family) {
+ case AF_INET:
+ stream_put_in_addr(s, &znh->address.ipv4);
+ break;
+ case AF_INET6:
+ stream_write(s, (uint8_t *)&znh->address.ipv6, 16);
+ break;
+ default:
+ break;
+ }
+ stream_putl(s, znh->ifindex);
+ stream_putl(s, znh->label);
}
- stream_putl(s, zl->nexthop.ifindex);
- stream_putl(s, zl->nexthop.label);
/* Put length at the first point of the stream. */
stream_putw_at(s, 0, stream_get_endp(s));
@@ -2498,6 +2514,8 @@ int zapi_labels_encode(struct stream *s, int cmd, struct zapi_labels *zl)
int zapi_labels_decode(struct stream *s, struct zapi_labels *zl)
{
+ struct zapi_nexthop_label *znh;
+
memset(zl, 0, sizeof(*zl));
/* Get data. */
@@ -2545,20 +2563,26 @@ int zapi_labels_decode(struct stream *s, struct zapi_labels *zl)
STREAM_GETW(s, zl->route.instance);
}
- STREAM_GETC(s, zl->nexthop.type);
- STREAM_GETW(s, zl->nexthop.family);
- switch (zl->nexthop.family) {
- case AF_INET:
- STREAM_GET(&zl->nexthop.address.ipv4.s_addr, s, IPV4_MAX_BYTELEN);
- break;
- case AF_INET6:
- STREAM_GET(&zl->nexthop.address.ipv6, s, 16);
- break;
- default:
- break;
+ STREAM_GETW(s, zl->nexthop_num);
+ for (int i = 0; i < zl->nexthop_num; i++) {
+ znh = &zl->nexthops[i];
+
+ STREAM_GETC(s, znh->type);
+ STREAM_GETW(s, znh->family);
+ switch (znh->family) {
+ case AF_INET:
+ STREAM_GET(&znh->address.ipv4.s_addr, s,
+ IPV4_MAX_BYTELEN);
+ break;
+ case AF_INET6:
+ STREAM_GET(&znh->address.ipv6, s, 16);
+ break;
+ default:
+ break;
+ }
+ STREAM_GETL(s, znh->ifindex);
+ STREAM_GETL(s, znh->label);
}
- STREAM_GETL(s, zl->nexthop.ifindex);
- STREAM_GETL(s, zl->nexthop.label);
return 0;
stream_failure:
diff --git a/lib/zclient.h b/lib/zclient.h
index e0da1cbe32..eb3c97b111 100644
--- a/lib/zclient.h
+++ b/lib/zclient.h
@@ -126,6 +126,7 @@ typedef enum {
ZEBRA_INTERFACE_LINK_PARAMS,
ZEBRA_MPLS_LABELS_ADD,
ZEBRA_MPLS_LABELS_DELETE,
+ ZEBRA_MPLS_LABELS_REPLACE,
ZEBRA_IPMR_ROUTE_STATS,
ZEBRA_LABEL_MANAGER_CONNECT,
ZEBRA_LABEL_MANAGER_CONNECT_ASYNC,
@@ -395,6 +396,14 @@ struct zapi_route {
uint32_t tableid;
};
+struct zapi_nexthop_label {
+ enum nexthop_types_t type;
+ int family;
+ union g_addr address;
+ ifindex_t ifindex;
+ mpls_label_t label;
+};
+
struct zapi_labels {
uint8_t message;
#define ZAPI_LABELS_FTN 0x01
@@ -405,13 +414,8 @@ struct zapi_labels {
uint8_t type;
unsigned short instance;
} route;
- struct {
- enum nexthop_types_t type;
- int family;
- union g_addr address;
- ifindex_t ifindex;
- mpls_label_t label;
- } nexthop;
+ uint16_t nexthop_num;
+ struct zapi_nexthop_label nexthops[MULTIPATH_NUM];
};
struct zapi_pw {
diff --git a/ospfd/ospf_sr.c b/ospfd/ospf_sr.c
index 2d06ae77fc..91737085bd 100644
--- a/ospfd/ospf_sr.c
+++ b/ospfd/ospf_sr.c
@@ -609,6 +609,7 @@ static int compute_prefix_nhlfe(struct sr_prefix *srp)
static int ospf_zebra_send_mpls_labels(int cmd, struct sr_nhlfe nhlfe)
{
struct zapi_labels zl = {};
+ struct zapi_nexthop_label *znh;
if (IS_DEBUG_OSPF_SR)
zlog_debug(" |- %s LSP %u/%u for %s/%u via %u",
@@ -627,11 +628,13 @@ static int ospf_zebra_send_mpls_labels(int cmd, struct sr_nhlfe nhlfe)
zl.route.type = ZEBRA_ROUTE_OSPF;
zl.route.instance = 0;
- zl.nexthop.type = NEXTHOP_TYPE_IPV4_IFINDEX;
- zl.nexthop.family = AF_INET;
- zl.nexthop.address.ipv4 = nhlfe.nexthop;
- zl.nexthop.ifindex = nhlfe.ifindex;
- zl.nexthop.label = nhlfe.label_out;
+ zl.nexthop_num = 1;
+ znh = &zl.nexthops[0];
+ znh->type = NEXTHOP_TYPE_IPV4_IFINDEX;
+ znh->family = AF_INET;
+ znh->address.ipv4 = nhlfe.nexthop;
+ znh->ifindex = nhlfe.ifindex;
+ znh->label = nhlfe.label_out;
return zebra_send_mpls_labels(zclient, cmd, &zl);
}
diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c
index fa2ce019c5..826d31ef37 100644
--- a/zebra/zapi_msg.c
+++ b/zebra/zapi_msg.c
@@ -1749,7 +1749,15 @@ static void zread_vrf_unregister(ZAPI_HANDLER_ARGS)
vrf_bitmap_unset(client->ridinfo, zvrf_id(zvrf));
}
-static void zread_mpls_labels(ZAPI_HANDLER_ARGS)
+/*
+ * Handle request to create an MPLS LSP.
+ *
+ * A single message can fully specify an LSP with multiple nexthops.
+ *
+ * When the optional ZAPI_LABELS_FTN flag is set, the specified FEC (route) is
+ * updated to use the received label(s).
+ */
+static void zread_mpls_labels_add(ZAPI_HANDLER_ARGS)
{
struct stream *s;
struct zapi_labels zl;
@@ -1766,24 +1774,120 @@ static void zread_mpls_labels(ZAPI_HANDLER_ARGS)
if (!mpls_enabled)
return;
- if (hdr->command == ZEBRA_MPLS_LABELS_ADD) {
- mpls_lsp_install(zvrf, zl.type, zl.local_label,
- zl.nexthop.label, zl.nexthop.type,
- &zl.nexthop.address, zl.nexthop.ifindex);
+ for (int i = 0; i < zl.nexthop_num; i++) {
+ struct zapi_nexthop_label *znh;
+
+ znh = &zl.nexthops[i];
+ mpls_lsp_install(zvrf, zl.type, zl.local_label, znh->label,
+ znh->type, &znh->address, znh->ifindex);
+
if (CHECK_FLAG(zl.message, ZAPI_LABELS_FTN))
mpls_ftn_update(1, zvrf, zl.type, &zl.route.prefix,
- zl.nexthop.type, &zl.nexthop.address,
- zl.nexthop.ifindex, zl.route.type,
- zl.route.instance, zl.nexthop.label);
- } else if (hdr->command == ZEBRA_MPLS_LABELS_DELETE) {
- mpls_lsp_uninstall(zvrf, zl.type, zl.local_label,
- zl.nexthop.type, &zl.nexthop.address,
- zl.nexthop.ifindex);
+ znh->type, &znh->address, znh->ifindex,
+ zl.route.type, zl.route.instance,
+ znh->label);
+ }
+}
+
+/*
+ * Handle request to delete an MPLS LSP.
+ *
+ * An LSP is identified by its type and local label. When the received message
+ * doesn't contain any nexthop, the whole LSP is deleted. Otherwise, only the
+ * listed LSP nexthops (aka NHLFEs) are deleted.
+ *
+ * When the optional ZAPI_LABELS_FTN flag is set, the labels of the specified
+ * FEC (route) nexthops are deleted.
+ */
+static void zread_mpls_labels_delete(ZAPI_HANDLER_ARGS)
+{
+ struct stream *s;
+ struct zapi_labels zl;
+
+ /* Get input stream. */
+ s = msg;
+ if (zapi_labels_decode(s, &zl) < 0) {
+ if (IS_ZEBRA_DEBUG_RECV)
+ zlog_debug("%s: Unable to decode zapi_labels sent",
+ __PRETTY_FUNCTION__);
+ return;
+ }
+
+ if (!mpls_enabled)
+ return;
+
+ if (zl.nexthop_num > 0) {
+ for (int i = 0; i < zl.nexthop_num; i++) {
+ struct zapi_nexthop_label *znh;
+
+ znh = &zl.nexthops[i];
+ mpls_lsp_uninstall(zvrf, zl.type, zl.local_label,
+ znh->type, &znh->address,
+ znh->ifindex);
+
+ if (CHECK_FLAG(zl.message, ZAPI_LABELS_FTN))
+ mpls_ftn_update(0, zvrf, zl.type,
+ &zl.route.prefix, znh->type,
+ &znh->address, znh->ifindex,
+ zl.route.type,
+ zl.route.instance, znh->label);
+ }
+ } else {
+ mpls_lsp_uninstall_all_vrf(zvrf, zl.type, zl.local_label);
+
if (CHECK_FLAG(zl.message, ZAPI_LABELS_FTN))
- mpls_ftn_update(0, zvrf, zl.type, &zl.route.prefix,
- zl.nexthop.type, &zl.nexthop.address,
- zl.nexthop.ifindex, zl.route.type,
- zl.route.instance, zl.nexthop.label);
+ mpls_ftn_uninstall(zvrf, zl.type, &zl.route.prefix,
+ zl.route.type, zl.route.instance);
+ }
+}
+
+/*
+ * Handle request to add an MPLS LSP or change an existing one.
+ *
+ * A single message can fully specify an LSP with multiple nexthops.
+ *
+ * When the optional ZAPI_LABELS_FTN flag is set, the specified FEC (route) is
+ * updated to use the received label(s).
+ *
+ * NOTE: zebra will use route replace semantics (make-before-break) to update
+ * the LSP in the forwarding plane if that's supported by the underlying
+ * platform.
+ */
+static void zread_mpls_labels_replace(ZAPI_HANDLER_ARGS)
+{
+ struct stream *s;
+ struct zapi_labels zl;
+
+ /* Get input stream. */
+ s = msg;
+ if (zapi_labels_decode(s, &zl) < 0) {
+ if (IS_ZEBRA_DEBUG_RECV)
+ zlog_debug("%s: Unable to decode zapi_labels sent",
+ __PRETTY_FUNCTION__);
+ return;
+ }
+
+ if (!mpls_enabled)
+ return;
+
+ mpls_lsp_uninstall_all_vrf(zvrf, zl.type, zl.local_label);
+ if (CHECK_FLAG(zl.message, ZAPI_LABELS_FTN))
+ mpls_ftn_uninstall(zvrf, zl.type, &zl.route.prefix,
+ zl.route.type, zl.route.instance);
+
+ for (int i = 0; i < zl.nexthop_num; i++) {
+ struct zapi_nexthop_label *znh;
+
+ znh = &zl.nexthops[i];
+ mpls_lsp_install(zvrf, zl.type, zl.local_label, znh->label,
+ znh->type, &znh->address, znh->ifindex);
+
+ if (CHECK_FLAG(zl.message, ZAPI_LABELS_FTN)) {
+ mpls_ftn_update(1, zvrf, zl.type, &zl.route.prefix,
+ znh->type, &znh->address, znh->ifindex,
+ zl.route.type, zl.route.instance,
+ znh->label);
+ }
}
}
@@ -2409,8 +2513,9 @@ void (*zserv_handlers[])(ZAPI_HANDLER_ARGS) = {
[ZEBRA_INTERFACE_ENABLE_RADV] = NULL,
[ZEBRA_INTERFACE_DISABLE_RADV] = NULL,
#endif
- [ZEBRA_MPLS_LABELS_ADD] = zread_mpls_labels,
- [ZEBRA_MPLS_LABELS_DELETE] = zread_mpls_labels,
+ [ZEBRA_MPLS_LABELS_ADD] = zread_mpls_labels_add,
+ [ZEBRA_MPLS_LABELS_DELETE] = zread_mpls_labels_delete,
+ [ZEBRA_MPLS_LABELS_REPLACE] = zread_mpls_labels_replace,
[ZEBRA_IPMR_ROUTE_STATS] = zebra_ipmr_route_stats,
[ZEBRA_LABEL_MANAGER_CONNECT] = zread_label_manager_request,
[ZEBRA_LABEL_MANAGER_CONNECT_ASYNC] = zread_label_manager_request,
diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c
index bbf4af93ee..74eaa582c9 100644
--- a/zebra/zebra_mpls.c
+++ b/zebra/zebra_mpls.c
@@ -2654,6 +2654,42 @@ int mpls_ftn_update(int add, struct zebra_vrf *zvrf, enum lsp_types_t type,
return 0;
}
+int mpls_ftn_uninstall(struct zebra_vrf *zvrf, enum lsp_types_t type,
+ struct prefix *prefix, uint8_t route_type,
+ unsigned short route_instance)
+{
+ struct route_table *table;
+ struct route_node *rn;
+ struct route_entry *re;
+ struct nexthop *nexthop;
+
+ /* Lookup table. */
+ table = zebra_vrf_table(family2afi(prefix->family), SAFI_UNICAST,
+ zvrf_id(zvrf));
+ if (!table)
+ return -1;
+
+ /* Lookup existing route */
+ rn = route_node_get(table, prefix);
+ RNODE_FOREACH_RE (rn, re) {
+ if (CHECK_FLAG(re->status, ROUTE_ENTRY_REMOVED))
+ continue;
+ if (re->type == route_type && re->instance == route_instance)
+ break;
+ }
+ if (re == NULL)
+ return -1;
+
+ for (nexthop = re->ng.nexthop; nexthop; nexthop = nexthop->next)
+ nexthop_del_labels(nexthop);
+
+ SET_FLAG(re->status, ROUTE_ENTRY_CHANGED);
+ SET_FLAG(re->status, ROUTE_ENTRY_LABELS_CHANGED);
+ rib_queue_add(rn);
+
+ return 0;
+}
+
/*
* Install/update a NHLFE for an LSP in the forwarding table. This may be
* a new LSP entry or a new NHLFE for an existing in-label or an update of
@@ -2786,6 +2822,27 @@ int mpls_lsp_uninstall(struct zebra_vrf *zvrf, enum lsp_types_t type,
return 0;
}
+int mpls_lsp_uninstall_all_vrf(struct zebra_vrf *zvrf, enum lsp_types_t type,
+ mpls_label_t in_label)
+{
+ struct hash *lsp_table;
+ zebra_ile_t tmp_ile;
+ zebra_lsp_t *lsp;
+
+ /* Lookup table. */
+ lsp_table = zvrf->lsp_table;
+ if (!lsp_table)
+ return -1;
+
+ /* If entry is not present, exit. */
+ tmp_ile.in_label = in_label;
+ lsp = hash_lookup(lsp_table, &tmp_ile);
+ if (!lsp)
+ return 0;
+
+ return mpls_lsp_uninstall_all(lsp_table, lsp, type);
+}
+
/*
* Uninstall all NHLFEs for a particular LSP forwarding entry.
* If no other NHLFEs exist, the entry would be deleted.
diff --git a/zebra/zebra_mpls.h b/zebra/zebra_mpls.h
index e8ab46a8d8..157f43ca98 100644
--- a/zebra/zebra_mpls.h
+++ b/zebra/zebra_mpls.h
@@ -273,6 +273,13 @@ int mpls_ftn_update(int add, struct zebra_vrf *zvrf, enum lsp_types_t type,
unsigned short route_instance, mpls_label_t out_label);
/*
+ * Uninstall all NHLFEs bound to a single FEC.
+ */
+int mpls_ftn_uninstall(struct zebra_vrf *zvrf, enum lsp_types_t type,
+ struct prefix *prefix, uint8_t route_type,
+ unsigned short route_instance);
+
+/*
* Install/update a NHLFE for an LSP in the forwarding table. This may be
* a new LSP entry or a new NHLFE for an existing in-label or an update of
* the out-label for an existing NHLFE (update case).
@@ -291,10 +298,10 @@ int mpls_lsp_uninstall(struct zebra_vrf *zvrf, enum lsp_types_t type,
union g_addr *gate, ifindex_t ifindex);
/*
- * Uninstall all LDP NHLFEs for a particular LSP forwarding entry.
- * If no other NHLFEs exist, the entry would be deleted.
+ * Uninstall all NHLFEs for a particular LSP forwarding entry.
*/
-void mpls_ldp_lsp_uninstall_all(struct hash_bucket *bucket, void *ctxt);
+int mpls_lsp_uninstall_all_vrf(struct zebra_vrf *zvrf, enum lsp_types_t type,
+ mpls_label_t in_label);
/*
* Uninstall all Segment Routing NHLFEs for a particular LSP forwarding entry.