diff options
| author | Louis Scalbert <louis.scalbert@6wind.com> | 2022-09-02 18:03:21 +0200 | 
|---|---|---|
| committer | Louis Scalbert <louis.scalbert@6wind.com> | 2024-05-23 14:43:21 +0200 | 
| commit | 9a83c6cf7217070d0a4885bfe82cb331b94f0b41 (patch) | |
| tree | 15a28c3429e2689d0f31e1bc403f747e723b6407 /isisd/isis_tlvs.c | |
| parent | 980d76c403de248139339bfea68946b50f0bb338 (diff) | |
isisd: fix multiple values display in show isis database detail json
Multiple occurrences of the same (sub-)TLVs are mixed into a single JSON
object. Last values replaces the previous.
Display all the occurrences in an array for the following (sub-)TLVs:
- is-reach
- ip-reach
- ext-reach
- ext-ip-reach
- ipv6-reach
- MT
- prefix-SID
Fixes: a2cac12a63 ("isisd: Add json to show isis database command.")
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
Diffstat (limited to 'isisd/isis_tlvs.c')
| -rw-r--r-- | isisd/isis_tlvs.c | 69 | 
1 files changed, 54 insertions, 15 deletions
diff --git a/isisd/isis_tlvs.c b/isisd/isis_tlvs.c index 93ae8c6cb2..2fd7e7e2b7 100644 --- a/isisd/isis_tlvs.c +++ b/isisd/isis_tlvs.c @@ -2127,9 +2127,14 @@ static void format_item_prefix_sid(uint16_t mtid, struct isis_item *i,  	struct isis_prefix_sid *sid = (struct isis_prefix_sid *)i;  	if (json) { -		struct json_object *sr_json; +		struct json_object *sr_json, *array_json;  		sr_json = json_object_new_object(); -		json_object_object_add(json, "sr", sr_json); +		json_object_object_get_ex(json, "sr", &array_json); +		if (!array_json) { +			array_json = json_object_new_array(); +			json_object_object_add(json, "sr", array_json); +		} +		json_object_array_add(array_json, sr_json);  		if (sid->flags & ISIS_PREFIX_SID_VALUE) {  			json_object_int_add(sr_json, "label", sid->value);  		} else { @@ -2929,9 +2934,15 @@ static void format_item_oldstyle_reach(uint16_t mtid, struct isis_item *i,  	snprintfrr(sys_id, ISO_SYSID_STRLEN, "%pPN", r->id);  	if (json) { -		struct json_object *old_json; +		struct json_object *old_json, *array_json;  		old_json = json_object_new_object(); -		json_object_object_add(json, "old-reach-style", old_json); +		json_object_object_get_ex(json, "old-reach-style", &array_json); +		if (!array_json) { +			array_json = json_object_new_array(); +			json_object_object_add(json, "old-reach-style", +					       array_json); +		} +		json_object_array_add(array_json, old_json);  		json_object_string_add(old_json, "is-reach", sys_id);  		json_object_int_add(old_json, "metric", r->metric);  	} else @@ -3173,9 +3184,14 @@ static void format_item_extended_reach(uint16_t mtid, struct isis_item *i,  	snprintfrr(sys_id, ISO_SYSID_STRLEN, "%pPN", r->id);  	if (json) { -		struct json_object *reach_json; +		struct json_object *reach_json, *array_json;  		reach_json = json_object_new_object(); -		json_object_object_add(json, "ext-reach", reach_json); +		json_object_object_get_ex(json, "ext-reach", &array_json); +		if (!array_json) { +			array_json = json_object_new_array(); +			json_object_object_add(json, "ext-reach", array_json); +		} +		json_object_array_add(array_json, reach_json);  		json_object_string_add(  			reach_json, "mt-id",  			(mtid == ISIS_MT_IPV4_UNICAST) ? "Extended" : "MT"); @@ -3314,13 +3330,21 @@ static void format_item_oldstyle_ip_reach(uint16_t mtid, struct isis_item *i,  	char prefixbuf[PREFIX2STR_BUFFER];  	if (json) { -		struct json_object *old_json; +		struct json_object *old_json, *array_json;  		old_json = json_object_new_object(); -		json_object_object_add(json, "old-ip-reach-style", old_json); +		json_object_object_get_ex(json, "old-ip-reach-style", +					  &array_json); +		if (!array_json) { +			array_json = json_object_new_array(); +			json_object_object_add(json, "old-ip-reach-style", +					       old_json); +		} +		json_object_array_add(array_json, old_json);  		json_object_string_add(old_json, "prefix",  				       prefix2str(&r->prefix, prefixbuf, sizeof(prefixbuf)));  		json_object_int_add(old_json, "metric", r->metric); -	} else +		return; +	}  	sbuf_push(buf, indent, "IP Reachability: %s (Metric: %hhu)\n",  		  prefix2str(&r->prefix, prefixbuf, sizeof(prefixbuf)),  		  r->metric); @@ -3705,9 +3729,14 @@ static void format_item_mt_router_info(uint16_t mtid, struct isis_item *i,  	struct isis_mt_router_info *info = (struct isis_mt_router_info *)i;  	if (json) { -		struct json_object *mt_json; +		struct json_object *mt_json, *array_json;  		mt_json = json_object_new_object(); -		json_object_object_add(json, "mt", mt_json); +		json_object_object_get_ex(json, "mt", &array_json); +		if (!array_json) { +			array_json = json_object_new_array(); +			json_object_object_add(json, "mt", array_json); +		} +		json_object_array_add(array_json, mt_json);  		json_object_int_add(mt_json, "mtid", info->mtid);  		json_object_string_add(mt_json, "overload", info->overload?"true":"false");  		json_object_string_add(mt_json, "attached", info->attached?"true":"false"); @@ -3866,12 +3895,17 @@ static void format_item_extended_ip_reach(uint16_t mtid, struct isis_item *i,  					  struct json_object *json, int indent)  {  	struct isis_extended_ip_reach *r = (struct isis_extended_ip_reach *)i; +	struct json_object *ext_json, *array_json;  	char prefixbuf[PREFIX2STR_BUFFER];  	if (json) { -		struct json_object *ext_json;  		ext_json = json_object_new_object(); -		json_object_object_add(json, "ext-ip-reach", ext_json); +		json_object_object_get_ex(json, "ext-ip-reach", &array_json); +		if (!array_json) { +			array_json = json_object_new_array(); +			json_object_object_add(json, "ext-ip-reach", array_json); +		} +		json_object_array_add(array_json, ext_json);  		json_object_string_add(  			json, "mt-id",  			(mtid == ISIS_MT_IPV4_UNICAST) ? "Extended" : "MT"); @@ -4500,9 +4534,14 @@ static void format_item_ipv6_reach(uint16_t mtid, struct isis_item *i,  	char prefixbuf[PREFIX2STR_BUFFER];  	if (json) { -		struct json_object *reach_json; +		struct json_object *reach_json, *array_json;  		reach_json = json_object_new_object(); -		json_object_object_add(json, "ipv6-reach", reach_json); +		json_object_object_get_ex(json, "ipv6-reach", &array_json); +		if (!array_json) { +			array_json = json_object_new_array(); +			json_object_object_add(json, "ipv6-reach", array_json); +		} +		json_object_array_add(array_json, reach_json);  		json_object_string_add(reach_json, "mt-id",  				       (mtid == ISIS_MT_IPV4_UNICAST) ? ""  								      : "mt");  | 
