summaryrefslogtreecommitdiff
path: root/lib/srv6.c
diff options
context:
space:
mode:
authorPhilippe Guibert <philippe.guibert@6wind.com>2024-08-08 10:05:45 +0200
committerPhilippe Guibert <philippe.guibert@6wind.com>2024-08-08 11:36:01 +0200
commit5d027fc79194870d26d14373d5c15f2ea4d58bd5 (patch)
treea616ccd29f8ca6f60d0fac293ac010987f924dbb /lib/srv6.c
parentd3047146975475aaeaf81804571afdb2d08e6e20 (diff)
lib: add seg6localContext json attribute in nexthop information
Some srv6 behaviors have a context attached that is visible if no json is requested: > # show ipv6 route > [..] > B>* 2001:db8:1:1:100::/128 [20/0] is directly connected, vrf10, seg6local End.DT6 table 10, weight 1, 00:00:14 > B>* 2001:db8:1:1:200::/128 [20/0] is directly connected, vrf20, seg6local End.DT6 table 20, weight 1, 00:00:14 > The json does not dump this attribute: > # show ipv6 route 2001:db8:1:1:100::/128 json > [..] > "nexthops":[ > { > "flags":3, > "fib":true, > "directlyConnected":true, > "interfaceIndex":6, > "interfaceName":"vrf10", > "active":true, > "weight":1, > "seg6local":{ > "action":"End.DT6" > }, > } > Add the json support for this. > "nexthops":[ > { > "flags":3, > "fib":true, > "directlyConnected":true, > "interfaceIndex":6, > "interfaceName":"vrf10", > "active":true, > "weight":1, > "seg6local":{ > "action":"End.DT6" > }, > "seg6localContext":{ > "table":10 > } > } > Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Diffstat (limited to 'lib/srv6.c')
-rw-r--r--lib/srv6.c38
1 files changed, 38 insertions, 0 deletions
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)