From d95a84e0a515c9d04efe0aae0da4f8f9c0d8defd Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Wed, 19 May 2021 18:24:20 +0300 Subject: [PATCH] bgpd: Show BGP community alias in JSON community list output Before: ``` "community":{ "string":"first 65001:2 65001:3", "list":[ "65001:1", "65001:2", "65001:3" ] }, ``` After: ``` "community":{ "string":"first 65001:2 65001:3", "list":[ "first", "65001:2", "65001:3" ] }, ``` Signed-off-by: Donatas Abraitis --- bgpd/bgp_community.c | 6 ++++-- bgpd/bgp_lcommunity.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/bgpd/bgp_community.c b/bgpd/bgp_community.c index b034ec9f7b..2aa6a56a5e 100644 --- a/bgpd/bgp_community.c +++ b/bgpd/bgp_community.c @@ -451,9 +451,11 @@ static void set_community_string(struct community *com, bool make_json) val = comval & 0xFFFF; char buf[32]; snprintf(buf, sizeof(buf), "%u:%d", as, val); - strlcat(str, bgp_community2alias(buf), len); + const char *com2alias = bgp_community2alias(buf); + + strlcat(str, com2alias, len); if (make_json) { - json_string = json_object_new_string(buf); + json_string = json_object_new_string(com2alias); json_object_array_add(json_community_list, json_string); } diff --git a/bgpd/bgp_lcommunity.c b/bgpd/bgp_lcommunity.c index ff34937efc..fa4d4aee28 100644 --- a/bgpd/bgp_lcommunity.c +++ b/bgpd/bgp_lcommunity.c @@ -232,11 +232,13 @@ static void set_lcommunity_string(struct lcommunity *lcom, bool make_json) snprintf(lcsb, sizeof(lcsb), "%u:%u:%u", global, local1, local2); - len = strlcat(str_buf, bgp_community2alias(lcsb), str_buf_sz); + const char *com2alias = bgp_community2alias(lcsb); + + len = strlcat(str_buf, com2alias, str_buf_sz); assert((unsigned int)len < str_buf_sz); if (make_json) { - json_string = json_object_new_string(lcsb); + json_string = json_object_new_string(com2alias); json_object_array_add(json_lcommunity_list, json_string); } -- 2.39.5