]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: Add sidStructure in SRv6 SIDs JSON output
authorCarmine Scarpitta <cscarpit@cisco.com>
Sat, 8 Feb 2025 21:17:09 +0000 (22:17 +0100)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Thu, 13 Feb 2025 18:38:17 +0000 (18:38 +0000)
The `show ipv6 route json` command displays the IPv6 routing table in
JSON format, including SRv6 SIDs. For each SRv6 SID, it provides
behavior and SID attributes. However, it does not include the SID
structure.

This commit adds the SID structure to the SRv6 SID JSON output.

Signed-off-by: Carmine Scarpitta <cscarpit@cisco.com>
(cherry picked from commit 312f7b3f8c7382afef6993aa2110326db2327c35)

lib/nexthop.c
lib/srv6.c
lib/srv6.h

index ee6c2b7ec04953248d06f4b6f403fd5049584b55..c377b9cb0067d303b9ce89ec6cc7fc1322934894 100644 (file)
@@ -1153,6 +1153,7 @@ void nexthop_json_helper(json_object *json_nexthop,
        json_object *json_backups = NULL;
        json_object *json_seg6local = NULL;
        json_object *json_seg6local_context = NULL;
+       json_object *json_srv6_sid_structure = NULL;
        json_object *json_seg6 = NULL;
        json_object *json_segs = NULL;
        int i;
@@ -1328,6 +1329,10 @@ void nexthop_json_helper(json_object *json_nexthop,
                json_object_object_add(json_nexthop, "seg6localContext",
                                       json_seg6local_context);
 
+               json_srv6_sid_structure = json_object_new_object();
+               srv6_sid_structure2json(&nexthop->nh_srv6->seg6local_ctx, json_srv6_sid_structure);
+               json_object_object_add(json_seg6local, "sidStructure", json_srv6_sid_structure);
+
                if (nexthop->nh_srv6->seg6_segs &&
                    nexthop->nh_srv6->seg6_segs->num_segs == 1) {
                        json_seg6 = json_object_new_object();
index e6fc375fbb1100dd12cd471f91872698b8d04832..c00aca3cab6971327fa2a8ea8c434f5d4c8c2ac8 100644 (file)
@@ -71,6 +71,14 @@ int snprintf_seg6_segs(char *str,
        return strlen(str);
 }
 
+void srv6_sid_structure2json(const struct seg6local_context *ctx, json_object *json)
+{
+       json_object_int_add(json, "blockLen", ctx->block_len);
+       json_object_int_add(json, "nodeLen", ctx->node_len);
+       json_object_int_add(json, "funcLen", ctx->function_len);
+       json_object_int_add(json, "argLen", ctx->argument_len);
+}
+
 void seg6local_context2json(const struct seg6local_context *ctx,
                            uint32_t action, json_object *json)
 {
index 7e4fb97ad11de2d3dbddee99a3cf6047eb6fd655..011705504e748ffa405c4fad0efbcd51370c5685 100644 (file)
@@ -363,6 +363,7 @@ const char *seg6local_context2str(char *str, size_t size,
                                  uint32_t action);
 void seg6local_context2json(const struct seg6local_context *ctx,
                            uint32_t action, json_object *json);
+void srv6_sid_structure2json(const struct seg6local_context *ctx, json_object *json);
 
 static inline const char *srv6_sid_ctx2str(char *str, size_t size,
                                           const struct srv6_sid_ctx *ctx)