]> git.puffer.fish Git - mirror/frr.git/commitdiff
isisd: Add API to get/release SRv6 SIDs
authorCarmine Scarpitta <cscarpit@cisco.com>
Thu, 9 May 2024 09:23:53 +0000 (11:23 +0200)
committerCarmine Scarpitta <cscarpit@cisco.com>
Tue, 18 Jun 2024 16:33:29 +0000 (18:33 +0200)
Add an API to get/release SRv6 SIDs through the SRv6 SID Manager.

Signed-off-by: Carmine Scarpitta <cscarpit@cisco.com>
isisd/isis_zebra.c
isisd/isis_zebra.h

index f5b3f712be4e3e12a39e1d4f9a593d1458b3ea8f..226ee567967552090c3dd422d866994f5aef92cc 100644 (file)
@@ -644,6 +644,40 @@ int isis_zebra_request_label_range(uint32_t base, uint32_t chunk_size)
        return 0;
 }
 
+/**
+ * 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;
+       }
+}
+
 /**
  * Release Label Range to the Label Manager.
  *
@@ -1386,6 +1420,69 @@ int isis_zebra_srv6_manager_get_locator(const char *name)
        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 zclient_handler *const isis_handlers[] = {
        [ZEBRA_ROUTER_ID_UPDATE] = isis_router_id_update_zebra,
        [ZEBRA_INTERFACE_ADDRESS_ADD] = isis_zebra_if_address_add,
index bfd23f69f4955a6ac62d543cd61299be05b1c8af..79da16efac4952b638d3e3d92dcc5a6e920947bc 100644 (file)
@@ -69,5 +69,10 @@ extern int isis_zebra_srv6_manager_get_locator_chunk(const char *name);
 extern int isis_zebra_srv6_manager_release_locator_chunk(const char *name);
 
 extern int isis_zebra_srv6_manager_get_locator(const char *name);
+extern void isis_zebra_request_srv6_sid_endx(struct isis_adjacency *adj);
+extern bool isis_zebra_request_srv6_sid(const struct srv6_sid_ctx *ctx,
+                                       struct in6_addr *sid_value,
+                                       const char *locator_name);
+extern void isis_zebra_release_srv6_sid(const struct srv6_sid_ctx *ctx);
 
 #endif /* _ZEBRA_ISIS_ZEBRA_H */