From 8ed85db65cab700aaa80d0b01e977b1a40fd5d44 Mon Sep 17 00:00:00 2001 From: Trey Aspelund Date: Fri, 31 Mar 2023 22:34:48 +0000 Subject: [PATCH] bgpd: add comments for 'json detail' show cmd code The json structure changes used for 'json detail' show commands are not very straightforward and might require code analysis to understand. This addscommentary to the flow to explain the change in structure. Signed-off-by: Trey Aspelund --- bgpd/bgp_route.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 4813874748..a23bffd4ae 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -11603,9 +11603,28 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, vty_out(vty, ",\"%pFX\": ", dest_p); } + /* This is used for 'json detail' vty keywords. + * + * In plain 'json' the per-prefix header is encoded + * as a standalone dictionary in the first json_paths + * array element: + * "": [{header}, {path-1}, {path-N}] + * (which is confusing and borderline broken) + * + * For 'json detail' this changes the value + * of each prefix-key to be a dictionary where each + * header item has its own key, and json_paths is + * tucked under the "paths" key: + * "": { + * "": , + * "": , + * "paths": [{path-1}, {path-N}] + * } + */ if (json_detail_header && json_paths != NULL) { const struct prefix_rd *prd; + /* Start per-prefix dictionary */ vty_out(vty, "{\n"); prd = bgp_rd_from_dest(dest, safi); @@ -11630,6 +11649,7 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, */ vty_json_no_pretty(vty, json_paths); + /* End per-prefix dictionary */ if (json_detail_header_used) vty_out(vty, "} "); -- 2.39.5