From: Philippe Guibert Date: Fri, 11 Apr 2025 19:41:54 +0000 (+0200) Subject: lib: add flavors display in json attributes X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=a078e2e52e98da9362fc7fa267a7e8933139f8f8;p=mirror%2Ffrr.git lib: add flavors display in json attributes Add flavors display in json nexthop attributes. > # ip -6 route add 2007::1 encap seg6local action End flavors psp dev dum1 > # vtysh -c "show ipv6 route json" > [..] > ,"2007::1/128":[{"prefix":"2007::1/128","prefixLen":128,"protocol":"kernel","vrfId":0, > "vrfName":"default","selected":true,"destSelected":true,"distance":0,"metric":1024, > "installed":true,"table":254,"internalStatus":16,"internalFlags":8,"internalNextHopNum":1, > "internalNextHopActiveNum":1,"nexthopGroupId":28,"installedNexthopGroupId":28,"uptime":"00:04:20", > "nexthops":[{"flags":3,"fib":true,"directlyConnected":true,"interfaceIndex":19,"interfaceName":"dum1", > "active":true,"weight":1,"seg6local":{"action":"End","sidStructure":{"blockLen":0,"nodeLen":0,"funcLen":0,"argLen":0}}, > "seg6localContext":{"flavors":["psp"]}}]}] > [..] Signed-off-by: Philippe Guibert --- diff --git a/lib/srv6.c b/lib/srv6.c index e8a0d505df..4e973e3642 100644 --- a/lib/srv6.c +++ b/lib/srv6.c @@ -71,6 +71,21 @@ int snprintf_seg6_segs(char *str, return strlen(str); } +static void seg6local_flavors2json(json_object *json, const struct seg6local_flavors_info *flv_info) +{ + json_object *json_flavors; + + json_flavors = json_object_new_array(); + json_object_object_add(json, "flavors", json_flavors); + + if (CHECK_SRV6_FLV_OP(flv_info->flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_PSP)) + json_array_string_add(json_flavors, "psp"); + if (CHECK_SRV6_FLV_OP(flv_info->flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_USP)) + json_array_string_add(json_flavors, "usp"); + if (CHECK_SRV6_FLV_OP(flv_info->flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_USD)) + json_array_string_add(json_flavors, "usd"); +} + void srv6_sid_structure2json(const struct seg6local_context *ctx, json_object *json) { json_object_int_add(json, "blockLen", ctx->block_len); @@ -82,6 +97,7 @@ void srv6_sid_structure2json(const struct seg6local_context *ctx, json_object *j void seg6local_context2json(const struct seg6local_context *ctx, uint32_t action, json_object *json) { + seg6local_flavors2json(json, &ctx->flv); switch (action) { case ZEBRA_SEG6_LOCAL_ACTION_END: return;