summaryrefslogtreecommitdiff
path: root/isisd/isis_zebra.c
diff options
context:
space:
mode:
Diffstat (limited to 'isisd/isis_zebra.c')
-rw-r--r--isisd/isis_zebra.c428
1 files changed, 320 insertions, 108 deletions
diff --git a/isisd/isis_zebra.c b/isisd/isis_zebra.c
index 2412ec5e84..ce4eb74ec6 100644
--- a/isisd/isis_zebra.c
+++ b/isisd/isis_zebra.c
@@ -645,6 +645,70 @@ int isis_zebra_request_label_range(uint32_t base, uint32_t chunk_size)
}
/**
+ * Request an End.X SID for an IS-IS adjacency.
+ *
+ * @param adj IS-IS Adjacency
+ */
+void isis_zebra_request_srv6_sid_endx(struct isis_adjacency *adj)
+{
+ struct isis_circuit *circuit = adj->circuit;
+ struct isis_area *area = circuit->area;
+ struct in6_addr nexthop;
+ struct srv6_sid_ctx ctx = {};
+ struct in6_addr sid_value = {};
+ bool ret;
+
+ if (!area || !area->srv6db.srv6_locator)
+ return;
+
+ /* Determine nexthop IP address */
+ if (!circuit->ipv6_router || !adj->ll_ipv6_count)
+ return;
+
+ nexthop = adj->ll_ipv6_addrs[0];
+
+ ctx.behavior = ZEBRA_SEG6_LOCAL_ACTION_END_X;
+ ctx.nh6 = nexthop;
+ ret = isis_zebra_request_srv6_sid(&ctx, &sid_value,
+ area->srv6db.config.srv6_locator_name);
+ if (!ret) {
+ zlog_err("%s: not allocated new End.X SID for IS-IS area %s",
+ __func__, area->area_tag);
+ return;
+ }
+}
+
+static void request_srv6_sids(struct isis_area *area)
+{
+ struct srv6_sid_ctx ctx = {};
+ struct in6_addr sid_value = {};
+ struct listnode *node;
+ struct isis_adjacency *adj;
+ bool ret;
+
+ if (!area || !area->srv6db.config.enabled || !area->srv6db.srv6_locator)
+ return;
+
+ sr_debug("Requesting SRv6 SIDs for IS-IS area %s", area->area_tag);
+
+ /* Request new SRv6 End SID */
+ ctx.behavior = ZEBRA_SEG6_LOCAL_ACTION_END;
+ ret = isis_zebra_request_srv6_sid(&ctx, &sid_value,
+ area->srv6db.config.srv6_locator_name);
+ if (!ret) {
+ zlog_err("%s: not allocated new End SID for IS-IS area %s",
+ __func__, area->area_tag);
+ return;
+ }
+
+ /* Create SRv6 End.X SIDs from existing IS-IS Adjacencies */
+ for (ALL_LIST_ELEMENTS_RO(area->adjacency_list, node, adj)) {
+ if (adj->ll_ipv6_count > 0)
+ isis_zebra_request_srv6_sid_endx(adj);
+ }
+}
+
+/**
* Release Label Range to the Label Manager.
*
* @param start start of label range to release
@@ -1119,99 +1183,47 @@ void isis_zebra_srv6_adj_sid_uninstall(struct srv6_adjacency *sra)
}
/**
- * Callback to process an SRv6 locator chunk received from SRv6 Manager (zebra).
+ * Internal function to process an SRv6 locator
*
- * @result 0 on success, -1 otherwise
+ * @param locator The locator to be processed
*/
-static int isis_zebra_process_srv6_locator_chunk(ZAPI_CALLBACK_ARGS)
+static int isis_zebra_process_srv6_locator_internal(struct srv6_locator *locator)
{
struct isis *isis = isis_lookup_by_vrfid(VRF_DEFAULT);
- struct stream *s = NULL;
- struct listnode *node;
struct isis_area *area;
- struct srv6_locator_chunk *c;
- struct srv6_locator_chunk *chunk = srv6_locator_chunk_alloc();
- struct isis_srv6_sid *sid;
- struct isis_adjacency *adj;
- enum srv6_endpoint_behavior_codepoint behavior;
- bool allocated = false;
-
- if (!isis) {
- srv6_locator_chunk_free(&chunk);
- return -1;
- }
+ struct listnode *node;
- /* Decode the received zebra message */
- s = zclient->ibuf;
- if (zapi_srv6_locator_chunk_decode(s, chunk) < 0) {
- srv6_locator_chunk_free(&chunk);
+ if (!isis || !locator)
return -1;
- }
- sr_debug(
- "Received SRv6 locator chunk from zebra: name %s, "
- "prefix %pFX, block_len %u, node_len %u, func_len %u, arg_len %u",
- chunk->locator_name, &chunk->prefix, chunk->block_bits_length,
- chunk->node_bits_length, chunk->function_bits_length,
- chunk->argument_bits_length);
+ zlog_info("%s: Received SRv6 locator %s %pFX, loc-block-len=%u, loc-node-len=%u func-len=%u, arg-len=%u",
+ __func__, locator->name, &locator->prefix,
+ locator->block_bits_length, locator->node_bits_length,
+ locator->function_bits_length, locator->argument_bits_length);
/* Walk through all areas of the ISIS instance */
for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
- if (strncmp(area->srv6db.config.srv6_locator_name,
- chunk->locator_name,
- sizeof(area->srv6db.config.srv6_locator_name)) != 0)
+ /*
+ * Check if the IS-IS area is configured to use the received
+ * locator
+ */
+ if (strncmp(area->srv6db.config.srv6_locator_name, locator->name,
+ sizeof(area->srv6db.config.srv6_locator_name)) != 0) {
+ zlog_err("%s: SRv6 Locator name unmatch %s:%s",
+ __func__, area->srv6db.config.srv6_locator_name,
+ locator->name);
continue;
-
- for (ALL_LIST_ELEMENTS_RO(area->srv6db.srv6_locator_chunks,
- node, c)) {
- if (!prefix_cmp(&c->prefix, &chunk->prefix)) {
- srv6_locator_chunk_free(&chunk);
- return 0;
- }
- }
-
- sr_debug(
- "SRv6 locator chunk (locator %s, prefix %pFX) assigned to IS-IS area %s",
- chunk->locator_name, &chunk->prefix, area->area_tag);
-
- /* Add the SRv6 Locator chunk to the per-area chunks list */
- listnode_add(area->srv6db.srv6_locator_chunks, chunk);
-
- /* Decide which behavior to use,depending on the locator type
- * (i.e. uSID vs classic locator) */
- behavior = (CHECK_FLAG(chunk->flags, SRV6_LOCATOR_USID))
- ? SRV6_ENDPOINT_BEHAVIOR_END_NEXT_CSID
- : SRV6_ENDPOINT_BEHAVIOR_END;
-
- /* Allocate new SRv6 End SID */
- sid = isis_srv6_sid_alloc(area, chunk, behavior, 0);
- if (!sid)
- return -1;
-
- /* Install the new SRv6 End SID in the forwarding plane through
- * Zebra */
- isis_zebra_srv6_sid_install(area, sid);
-
- /* Store the SID */
- listnode_add(area->srv6db.srv6_sids, sid);
-
- /* Create SRv6 End.X SIDs from existing IS-IS Adjacencies */
- for (ALL_LIST_ELEMENTS_RO(area->adjacency_list, node, adj)) {
- if (adj->ll_ipv6_count > 0)
- srv6_endx_sid_add(adj);
}
- /* Regenerate LSPs to advertise the new locator and the SID */
- lsp_regenerate_schedule(area, area->is_type, 0);
+ sr_debug("SRv6 locator (locator %s, prefix %pFX) set for IS-IS area %s",
+ locator->name, &locator->prefix, area->area_tag);
- allocated = true;
- break;
- }
+ /* Store the locator in the IS-IS area */
+ area->srv6db.srv6_locator = srv6_locator_alloc(locator->name);
+ srv6_locator_copy(area->srv6db.srv6_locator, locator);
- if (!allocated) {
- sr_debug("No IS-IS area configured for the locator %s",
- chunk->locator_name);
- srv6_locator_chunk_free(&chunk);
+ /* Request SIDs from the locator */
+ request_srv6_sids(area);
}
return 0;
@@ -1226,8 +1238,6 @@ static int isis_zebra_process_srv6_locator_add(ZAPI_CALLBACK_ARGS)
{
struct isis *isis = isis_lookup_by_vrfid(VRF_DEFAULT);
struct srv6_locator loc = {};
- struct listnode *node;
- struct isis_area *area;
if (!isis)
return -1;
@@ -1236,33 +1246,7 @@ static int isis_zebra_process_srv6_locator_add(ZAPI_CALLBACK_ARGS)
if (zapi_srv6_locator_decode(zclient->ibuf, &loc) < 0)
return -1;
- sr_debug(
- "New SRv6 locator allocated in zebra: name %s, "
- "prefix %pFX, block_len %u, node_len %u, func_len %u, arg_len %u",
- loc.name, &loc.prefix, loc.block_bits_length,
- loc.node_bits_length, loc.function_bits_length,
- loc.argument_bits_length);
-
- /* Lookup on the IS-IS areas */
- for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
- /* If SRv6 is enabled on this area and the configured locator
- * corresponds to the new locator, then request a chunk from the
- * locator */
- if (area->srv6db.config.enabled &&
- strncmp(area->srv6db.config.srv6_locator_name, loc.name,
- sizeof(area->srv6db.config.srv6_locator_name)) == 0) {
- sr_debug(
- "Sending a request to get a chunk from the SRv6 locator %s (%pFX) "
- "for IS-IS area %s",
- loc.name, &loc.prefix, area->area_tag);
-
- if (isis_zebra_srv6_manager_get_locator_chunk(
- loc.name) < 0)
- return -1;
- }
- }
-
- return 0;
+ return isis_zebra_process_srv6_locator_internal(&loc);
}
/**
@@ -1335,6 +1319,9 @@ static int isis_zebra_process_srv6_locator_delete(ZAPI_CALLBACK_ARGS)
}
}
+ srv6_locator_free(area->srv6db.srv6_locator);
+ area->srv6db.srv6_locator = NULL;
+
/* Regenerate LSPs to advertise that the locator no longer
* exists */
lsp_regenerate_schedule(area, area->is_type, 0);
@@ -1368,6 +1355,232 @@ int isis_zebra_srv6_manager_release_locator_chunk(const char *name)
return srv6_manager_release_locator_chunk(zclient, name);
}
+/**
+ * Ask the SRv6 Manager (zebra) about a specific locator
+ *
+ * @param name Locator name
+ * @return 0 on success, -1 otherwise
+ */
+int isis_zebra_srv6_manager_get_locator(const char *name)
+{
+ if (!name)
+ return -1;
+
+ /*
+ * Send the Get Locator request to the SRv6 Manager and return the
+ * result
+ */
+ return srv6_manager_get_locator(zclient, name);
+}
+
+/**
+ * Ask the SRv6 Manager (zebra) to allocate a SID.
+ *
+ * Optionally, it is possible to provide an IPv6 address (sid_value parameter).
+ *
+ * When sid_value is provided, the SRv6 Manager allocates the requested SID
+ * address, if the request can be satisfied (explicit allocation).
+ *
+ * When sid_value is not provided, the SRv6 Manager allocates any available SID
+ * from the provided locator (dynamic allocation).
+ *
+ * @param ctx Context to be associated with the request SID
+ * @param sid_value IPv6 address to be associated with the requested SID (optional)
+ * @param locator_name Name of the locator from which the SID must be allocated
+ */
+bool isis_zebra_request_srv6_sid(const struct srv6_sid_ctx *ctx,
+ struct in6_addr *sid_value,
+ const char *locator_name)
+{
+ int ret;
+
+ if (!ctx || !locator_name)
+ return false;
+
+ /*
+ * Send the Get SRv6 SID request to the SRv6 Manager and check the
+ * result
+ */
+ ret = srv6_manager_get_sid(zclient, ctx, sid_value, locator_name, NULL);
+ if (ret < 0) {
+ zlog_warn("%s: error getting SRv6 SID!", __func__);
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * Ask the SRv6 Manager (zebra) to release a previously allocated SID.
+ *
+ * This function is used to tell the SRv6 Manager that IS-IS no longer intends
+ * to use the SID.
+ *
+ * @param ctx Context to be associated with the SID to be released
+ */
+void isis_zebra_release_srv6_sid(const struct srv6_sid_ctx *ctx)
+{
+ int ret;
+
+ if (!ctx)
+ return;
+
+ /*
+ * Send the Release SRv6 SID request to the SRv6 Manager and check the
+ * result
+ */
+ ret = srv6_manager_release_sid(zclient, ctx);
+ if (ret < 0) {
+ zlog_warn("%s: error releasing SRv6 SID!", __func__);
+ return;
+ }
+}
+
+static int isis_zebra_srv6_sid_notify(ZAPI_CALLBACK_ARGS)
+{
+ struct isis *isis = isis_lookup_by_vrfid(VRF_DEFAULT);
+ struct srv6_sid_ctx ctx;
+ struct in6_addr sid_addr;
+ enum zapi_srv6_sid_notify note;
+ uint32_t sid_func;
+ struct isis_area *area;
+ struct listnode *node, *nnode, *n;
+ char buf[256];
+ struct srv6_locator *locator;
+ struct prefix_ipv6 tmp_prefix;
+ struct srv6_adjacency *sra;
+ enum srv6_endpoint_behavior_codepoint behavior;
+ struct isis_srv6_sid *sid;
+ struct isis_adjacency *adj;
+
+ if (!isis)
+ return -1;
+
+ /* Decode the received notification message */
+ if (!zapi_srv6_sid_notify_decode(zclient->ibuf, &ctx, &sid_addr,
+ &sid_func, NULL, &note, NULL)) {
+ zlog_err("%s : error in msg decode", __func__);
+ return -1;
+ }
+
+ sr_debug("%s: received SRv6 SID notify: ctx %s sid_value %pI6 sid_func %u note %s",
+ __func__, srv6_sid_ctx2str(buf, sizeof(buf), &ctx), &sid_addr,
+ sid_func, zapi_srv6_sid_notify2str(note));
+
+ for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) {
+ if (!area->srv6db.config.enabled || !area->srv6db.srv6_locator)
+ continue;
+
+ locator = area->srv6db.srv6_locator;
+
+ /* Verify that the received SID belongs to the configured locator */
+ if (note == ZAPI_SRV6_SID_ALLOCATED) {
+ tmp_prefix.family = AF_INET6;
+ tmp_prefix.prefixlen = IPV6_MAX_BITLEN;
+ tmp_prefix.prefix = sid_addr;
+
+ if (!prefix_match((struct prefix *)&locator->prefix,
+ (struct prefix *)&tmp_prefix)) {
+ sr_debug("%s : ignoring SRv6 SID notify: locator (area %s) does not match",
+ __func__, area->area_tag);
+ continue;
+ }
+ }
+
+ /* Handle notification */
+ switch (note) {
+ case ZAPI_SRV6_SID_ALLOCATED:
+ sr_debug("SRv6 SID %pI6 %s ALLOCATED", &sid_addr,
+ srv6_sid_ctx2str(buf, sizeof(buf), &ctx));
+
+ if (ctx.behavior == ZEBRA_SEG6_LOCAL_ACTION_END) {
+ /* Remove old End SIDs, if any */
+ for (ALL_LIST_ELEMENTS(area->srv6db.srv6_sids,
+ node, nnode, sid)) {
+ isis_zebra_srv6_sid_uninstall(area, sid);
+ listnode_delete(area->srv6db.srv6_sids,
+ sid);
+ }
+
+ /* Allocate new SRv6 End SID */
+ behavior =
+ (CHECK_FLAG(locator->flags,
+ SRV6_LOCATOR_USID))
+ ? SRV6_ENDPOINT_BEHAVIOR_END_NEXT_CSID
+ : SRV6_ENDPOINT_BEHAVIOR_END;
+ sid = isis_srv6_sid_alloc(area,
+ area->srv6db
+ .srv6_locator,
+ behavior, &sid_addr);
+ if (!sid) {
+ zlog_warn("%s: isis_srv6_sid_alloc failed",
+ __func__);
+ return -1;
+ }
+
+ /*
+ * Install the new SRv6 End SID in the forwarding plane through
+ * Zebra
+ */
+ isis_zebra_srv6_sid_install(area, sid);
+
+ /* Store the SID */
+ listnode_add(area->srv6db.srv6_sids, sid);
+
+ } else if (ctx.behavior ==
+ ZEBRA_SEG6_LOCAL_ACTION_END_X) {
+ for (ALL_LIST_ELEMENTS_RO(area->adjacency_list,
+ n, adj)) {
+ /* Check if the End.X SID is for this adjacecny */
+ if (adj->ll_ipv6_count == 0 ||
+ memcmp(&adj->ll_ipv6_addrs[0],
+ &ctx.nh6,
+ sizeof(struct in6_addr)) != 0)
+ continue;
+
+ /* Remove old End.X SIDs, if any */
+ for (ALL_LIST_ELEMENTS(adj->srv6_endx_sids,
+ node, nnode, sra))
+ srv6_endx_sid_del(sra);
+
+ /* Allocate new End.X SID for the adjacency */
+ srv6_endx_sid_add_single(adj, false,
+ NULL,
+ &sid_addr);
+ }
+ } else {
+ zlog_warn("%s: unsupported behavior %u",
+ __func__, ctx.behavior);
+ return -1;
+ }
+ break;
+ case ZAPI_SRV6_SID_RELEASED:
+ sr_debug("SRv6 SID %pI6 %s: RELEASED", &sid_addr,
+ srv6_sid_ctx2str(buf, sizeof(buf), &ctx));
+ break;
+ case ZAPI_SRV6_SID_FAIL_ALLOC:
+ sr_debug("SRv6 SID %pI6 %s: Failed to allocate",
+ &sid_addr,
+ srv6_sid_ctx2str(buf, sizeof(buf), &ctx));
+
+ /* Error will be logged by zebra module */
+ break;
+ case ZAPI_SRV6_SID_FAIL_RELEASE:
+ zlog_warn("%s: SRv6 SID %pI6 %s failure to release",
+ __func__, &sid_addr,
+ srv6_sid_ctx2str(buf, sizeof(buf), &ctx));
+
+ /* Error will be logged by zebra module */
+ break;
+ }
+
+ /* Regenerate LSPs to advertise the new locator and the SID */
+ lsp_regenerate_schedule(area, area->is_type, 0);
+ }
+
+ return 0;
+}
+
static zclient_handler *const isis_handlers[] = {
[ZEBRA_ROUTER_ID_UPDATE] = isis_router_id_update_zebra,
[ZEBRA_INTERFACE_ADDRESS_ADD] = isis_zebra_if_address_add,
@@ -1380,10 +1593,9 @@ static zclient_handler *const isis_handlers[] = {
[ZEBRA_CLIENT_CLOSE_NOTIFY] = isis_zebra_client_close_notify,
- [ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK] =
- isis_zebra_process_srv6_locator_chunk,
[ZEBRA_SRV6_LOCATOR_ADD] = isis_zebra_process_srv6_locator_add,
[ZEBRA_SRV6_LOCATOR_DELETE] = isis_zebra_process_srv6_locator_delete,
+ [ZEBRA_SRV6_SID_NOTIFY] = isis_zebra_srv6_sid_notify,
};
void isis_zebra_init(struct event_loop *master, int instance)