From 639d8027f166f1853d7a22e162c15355b7beec1b Mon Sep 17 00:00:00 2001 From: anlan_cs Date: Tue, 7 May 2024 10:16:00 +0800 Subject: [PATCH] isisd: fix json display for database command The current json display lost a lot of LSPs, added them. Fixed the json format for two commands: "show isis database detail json" "show isis database json" Signed-off-by: anlan_cs --- isisd/isis_lsp.c | 13 +++++++++++-- isisd/isisd.c | 10 +++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/isisd/isis_lsp.c b/isisd/isis_lsp.c index 77573cdfacb4..9d671137e945 100644 --- a/isisd/isis_lsp.c +++ b/isisd/isis_lsp.c @@ -822,15 +822,24 @@ int lsp_print_all(struct vty *vty, struct json_object *json, { struct isis_lsp *lsp; int lsp_count = 0; + struct json_object *lsp_json = NULL; if (detail == ISIS_UI_LEVEL_BRIEF) { frr_each (lspdb, head, lsp) { - lsp_print_common(lsp, vty, json, dynhost, isis); + if (json) { + lsp_json = json_object_new_object(); + json_object_array_add(json, lsp_json); + } + lsp_print_common(lsp, vty, lsp_json, dynhost, isis); lsp_count++; } } else if (detail == ISIS_UI_LEVEL_DETAIL) { frr_each (lspdb, head, lsp) { - lsp_print_detail(lsp, vty, json, dynhost, isis); + if (json) { + lsp_json = json_object_new_object(); + json_object_array_add(json, lsp_json); + } + lsp_print_detail(lsp, vty, lsp_json, dynhost, isis); lsp_count++; } } diff --git a/isisd/isisd.c b/isisd/isisd.c index c1eda4822a43..6535b8fcc070 100644 --- a/isisd/isisd.c +++ b/isisd/isisd.c @@ -2681,6 +2681,7 @@ void show_isis_database_lspdb_json(struct json_object *json, { struct isis_lsp *lsp; int lsp_count; + struct json_object *lsp_arr_json; if (lspdb_count(lspdb) > 0) { lsp = lsp_for_sysid(lspdb, sysid_str, area->isis); @@ -2697,9 +2698,12 @@ void show_isis_database_lspdb_json(struct json_object *json, lsp_print_json(lsp, json, area->dynhostname, area->isis); } else if (sysid_str == NULL) { - lsp_count = - lsp_print_all(NULL, json, lspdb, ui_level, - area->dynhostname, area->isis); + lsp_arr_json = json_object_new_array(); + json_object_object_add(json, "lsps", lsp_arr_json); + + lsp_count = lsp_print_all(NULL, lsp_arr_json, lspdb, + ui_level, area->dynhostname, + area->isis); json_object_int_add(json, "count", lsp_count); }