summaryrefslogtreecommitdiff
path: root/zebra/zebra_vty.c
diff options
context:
space:
mode:
authorLouis Scalbert <louis.scalbert@6wind.com>2024-05-24 16:34:23 +0200
committerLouis Scalbert <louis.scalbert@6wind.com>2024-06-07 10:13:32 +0200
commit85eb60ffd6ce40428c3a99aeddf46b1b60d2e0a5 (patch)
tree4f6baa4821eb9e7e4d9e469a99e8811c13a2d8c0 /zebra/zebra_vty.c
parentcb440058f2d85d1408f932ad820c38e8e1b17191 (diff)
zebra: fix show route memory consumption
When displaying a route table in JSON, a table JSON object is storing all the prefix JSON objects containing the prefix information. This results in excessive memory allocation for JSON objects, potentially leading to an out-of-memory error on the machine with large routing tables. To Fix the memory consumption issue for the "show ip[v6] route [vrf XX] json" command, display the prefixes one by one and free the memory of each JSON object after it has been displayed. Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
Diffstat (limited to 'zebra/zebra_vty.c')
-rw-r--r--zebra/zebra_vty.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c
index 97245d55b9..c31218a7c3 100644
--- a/zebra/zebra_vty.c
+++ b/zebra/zebra_vty.c
@@ -869,9 +869,9 @@ static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf,
{
struct route_node *rn;
struct route_entry *re;
+ bool first_json = true;
int first = 1;
rib_dest_t *dest;
- json_object *json = NULL;
json_object *json_prefix = NULL;
uint32_t addr;
char buf[BUFSIZ];
@@ -887,9 +887,6 @@ static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf,
* => display the VRF and table if specific
*/
- if (use_json)
- json = json_object_new_object();
-
/* Show all routes. */
for (rn = route_top(table); rn; rn = srcdest_route_next(rn)) {
dest = rib_dest_from_rnode(rn);
@@ -962,17 +959,15 @@ static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf,
if (json_prefix) {
prefix2str(&rn->p, buf, sizeof(buf));
- json_object_object_add(json, buf, json_prefix);
+ vty_json_key(vty, buf, &first_json);
+ vty_json_no_pretty(vty, json_prefix);
+
json_prefix = NULL;
}
}
- /*
- * This is an extremely expensive operation at scale
- * and non-pretty reduces memory footprint significantly.
- */
if (use_json)
- vty_json_no_pretty(vty, json);
+ vty_json_close(vty, first_json);
}
static void do_show_ip_route_all(struct vty *vty, struct zebra_vrf *zvrf,