]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Add API to get/release SRv6 SIDs
authorCarmine Scarpitta <cscarpit@cisco.com>
Sat, 23 Mar 2024 18:17:48 +0000 (19:17 +0100)
committerCarmine Scarpitta <cscarpit@cisco.com>
Thu, 5 Sep 2024 08:59:59 +0000 (10:59 +0200)
Add an API to get/release SRv6 SIDs through the SRv6 SID Manager.

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

index 3d36e995401dac778a9960d964e17afb41d85bab..ecfcae1edbde02b40fbd2a90d6c3f5f1c917db50 100644 (file)
@@ -4156,6 +4156,71 @@ int bgp_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
+ * @param sid_func SID Function allocated by the SRv6 Manager.
+ */
+bool bgp_zebra_request_srv6_sid(const struct srv6_sid_ctx *ctx,
+                               struct in6_addr *sid_value,
+                               const char *locator_name, uint32_t *sid_func)
+{
+       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,
+                                  sid_func);
+       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 BGP no longer intends
+ * to use the SID.
+ *
+ * @param ctx Context to be associated with the SID to be released
+ */
+void bgp_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;
+       }
+}
+
 void bgp_zebra_send_nexthop_label(int cmd, mpls_label_t label,
                                  ifindex_t ifindex, vrf_id_t vrf_id,
                                  enum lsp_types_t ltype, struct prefix *p,
index 737ffb6b99f18e8168d0b1034a6135b849d82d5a..8deecba747b310ee6e2f7b1eb88242fe44d6a39c 100644 (file)
@@ -118,6 +118,11 @@ extern int bgp_zebra_stale_timer_update(struct bgp *bgp);
 extern int bgp_zebra_srv6_manager_get_locator_chunk(const char *name);
 extern int bgp_zebra_srv6_manager_release_locator_chunk(const char *name);
 extern int bgp_zebra_srv6_manager_get_locator(const char *name);
+extern bool bgp_zebra_request_srv6_sid(const struct srv6_sid_ctx *ctx,
+                                      struct in6_addr *sid_value,
+                                      const char *locator_name,
+                                      uint32_t *sid_func);
+extern void bgp_zebra_release_srv6_sid(const struct srv6_sid_ctx *ctx);
 
 extern void bgp_zebra_send_nexthop_label(int cmd, mpls_label_t label,
                                         ifindex_t index, vrf_id_t vrfid,