diff options
| author | Donatas Abraitis <donatas@opensourcerouting.org> | 2024-08-08 22:39:34 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-08 22:39:34 +0300 |
| commit | 536d478049b4ae7c3d60676a75a56115491d9b6f (patch) | |
| tree | 9f043e62b3f9c8678349377e08a28398b6f3b8c9 /lib | |
| parent | 7b8ca3e2ed6e7f98a63633c7dc91a9f0d12c576a (diff) | |
| parent | 5d027fc79194870d26d14373d5c15f2ea4d58bd5 (diff) | |
Merge pull request #16535 from pguibert6WIND/srv6_nexthop_context
lib: add seg6localContext json attribute in nexthop information
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/nexthop.c | 9 | ||||
| -rw-r--r-- | lib/srv6.c | 38 | ||||
| -rw-r--r-- | lib/srv6.h | 2 |
3 files changed, 49 insertions, 0 deletions
diff --git a/lib/nexthop.c b/lib/nexthop.c index 26c338256f..65c12c1e69 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -1166,6 +1166,7 @@ void nexthop_json_helper(json_object *json_nexthop, json_object *json_labels = NULL; json_object *json_backups = NULL; json_object *json_seg6local = NULL; + json_object *json_seg6local_context = NULL; json_object *json_seg6 = NULL; json_object *json_segs = NULL; int i; @@ -1331,8 +1332,16 @@ void nexthop_json_helper(json_object *json_nexthop, seg6local_action2str( nexthop->nh_srv6 ->seg6local_action)); + json_seg6local_context = json_object_new_object(); json_object_object_add(json_nexthop, "seg6local", json_seg6local); + + seg6local_context2json(&nexthop->nh_srv6->seg6local_ctx, + nexthop->nh_srv6->seg6local_action, + json_seg6local_context); + json_object_object_add(json_nexthop, "seg6localContext", + json_seg6local_context); + if (nexthop->nh_srv6->seg6_segs && nexthop->nh_srv6->seg6_segs->num_segs == 1) { json_seg6 = json_object_new_object(); diff --git a/lib/srv6.c b/lib/srv6.c index 883d429b62..e6fc375fbb 100644 --- a/lib/srv6.c +++ b/lib/srv6.c @@ -71,6 +71,44 @@ int snprintf_seg6_segs(char *str, return strlen(str); } +void seg6local_context2json(const struct seg6local_context *ctx, + uint32_t action, json_object *json) +{ + switch (action) { + case ZEBRA_SEG6_LOCAL_ACTION_END: + json_object_boolean_add(json, "USP", true); + return; + case ZEBRA_SEG6_LOCAL_ACTION_END_X: + case ZEBRA_SEG6_LOCAL_ACTION_END_DX6: + json_object_string_addf(json, "nh6", "%pI6", &ctx->nh6); + return; + case ZEBRA_SEG6_LOCAL_ACTION_END_DX4: + json_object_string_addf(json, "nh4", "%pI4", &ctx->nh4); + return; + case ZEBRA_SEG6_LOCAL_ACTION_END_T: + case ZEBRA_SEG6_LOCAL_ACTION_END_DT6: + case ZEBRA_SEG6_LOCAL_ACTION_END_DT4: + case ZEBRA_SEG6_LOCAL_ACTION_END_DT46: + json_object_int_add(json, "table", ctx->table); + return; + case ZEBRA_SEG6_LOCAL_ACTION_END_DX2: + json_object_boolean_add(json, "none", true); + return; + case ZEBRA_SEG6_LOCAL_ACTION_END_B6: + case ZEBRA_SEG6_LOCAL_ACTION_END_B6_ENCAP: + json_object_string_addf(json, "nh6", "%pI6", &ctx->nh6); + return; + case ZEBRA_SEG6_LOCAL_ACTION_END_BM: + case ZEBRA_SEG6_LOCAL_ACTION_END_S: + case ZEBRA_SEG6_LOCAL_ACTION_END_AS: + case ZEBRA_SEG6_LOCAL_ACTION_END_AM: + case ZEBRA_SEG6_LOCAL_ACTION_UNSPEC: + default: + json_object_boolean_add(json, "unknown", true); + return; + } +} + const char *seg6local_context2str(char *str, size_t size, const struct seg6local_context *ctx, uint32_t action) diff --git a/lib/srv6.h b/lib/srv6.h index 01b0820133..03ada7fcfc 100644 --- a/lib/srv6.h +++ b/lib/srv6.h @@ -319,6 +319,8 @@ seg6local_action2str(uint32_t action); const char *seg6local_context2str(char *str, size_t size, const struct seg6local_context *ctx, uint32_t action); +void seg6local_context2json(const struct seg6local_context *ctx, + uint32_t action, json_object *json); static inline const char *srv6_sid_ctx2str(char *str, size_t size, const struct srv6_sid_ctx *ctx) |
