From a48d6a204918c4a3665e104f4bd52c9feedf58a5 Mon Sep 17 00:00:00 2001 From: Carmine Scarpitta Date: Tue, 14 Feb 2023 12:34:47 +0100 Subject: [PATCH] isisd: Add format function for SRv6 Locator TLV Add a function to return information about an SRv6 Locator TLV and all its Sub-TLVs (RFC 9352 section #7.1). Examples: r1# show isis database detail Area 1: IS-IS Level-1 link-state database: LSP ID PduLen SeqNumber Chksum Holdtime ATT/P/OL r1.00-00 * 248 0x00000005 0xda6e 824 0/0/0 [...] SRv6 Locator: fc00:0:1::/48 (Metric: 0) standard Sub-TLVs: [...] r1# show isis database detail json [...] "srv6-locator":{ "mt-id":0, "prefix":"fc00:0:1::/48", "metric":0, "d-flag":"", "algorithm":0, "mt-name":"standard", "subtlvs":{ } } [...] Signed-off-by: Carmine Scarpitta --- isisd/isis_tlvs.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/isisd/isis_tlvs.c b/isisd/isis_tlvs.c index 6eb8fe0493..34da8aeb4e 100644 --- a/isisd/isis_tlvs.c +++ b/isisd/isis_tlvs.c @@ -5536,6 +5536,50 @@ static struct isis_item *copy_item_srv6_locator(struct isis_item *i) return (struct isis_item *)rv; } +static void format_item_srv6_locator(uint16_t mtid, struct isis_item *i, + struct sbuf *buf, struct json_object *json, + int indent) +{ + struct isis_srv6_locator_tlv *loc = (struct isis_srv6_locator_tlv *)i; + + if (json) { + struct json_object *loc_json; + loc_json = json_object_new_object(); + json_object_object_add(json, "srv6-locator", loc_json); + json_object_int_add(loc_json, "mt-id", mtid); + json_object_string_addf(loc_json, "prefix", "%pFX", + &loc->prefix); + json_object_int_add(loc_json, "metric", loc->metric); + json_object_string_add( + loc_json, "d-flag", + CHECK_FLAG(loc->flags, ISIS_TLV_SRV6_LOCATOR_FLAG_D) + ? "yes" + : ""); + json_object_int_add(loc_json, "algorithm", loc->algorithm); + json_object_string_add(loc_json, "mt-name", + isis_mtid2str(mtid)); + if (loc->subtlvs) { + struct json_object *subtlvs_json; + subtlvs_json = json_object_new_object(); + json_object_object_add(loc_json, "subtlvs", + subtlvs_json); + format_subtlvs(loc->subtlvs, NULL, subtlvs_json, 0); + } + } else { + sbuf_push(buf, indent, "SRv6 Locator: %pFX (Metric: %u)%s", + &loc->prefix, loc->metric, + CHECK_FLAG(loc->flags, ISIS_TLV_SRV6_LOCATOR_FLAG_D) + ? " D-flag" + : ""); + sbuf_push(buf, 0, " %s\n", isis_mtid2str(mtid)); + + if (loc->subtlvs) { + sbuf_push(buf, indent, " Sub-TLVs:\n"); + format_subtlvs(loc->subtlvs, buf, NULL, indent + 4); + } + } +} + /* Functions related to tlvs in general */ struct isis_tlvs *isis_alloc_tlvs(void) -- 2.39.5