]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: fix show route vrf all memory consumption
authorLouis Scalbert <louis.scalbert@6wind.com>
Fri, 24 May 2024 15:06:59 +0000 (17:06 +0200)
committerLouis Scalbert <louis.scalbert@6wind.com>
Fri, 7 Jun 2024 08:13:32 +0000 (10:13 +0200)
0e2fc3d67f ("vtysh, zebra: Fix malformed json output for multiple vrfs
in command 'show ip route vrf all json'") has been reverted in the
previous commit. Although the fix was correct, it was consuming too muca
memory when displaying large route tables.

A root JSON object was storing all the JSON objects containing the route
tables, each containing their respective prefixes in JSON objects. This
resulted in excessive memory allocation for JSON objects, potentially
leading to an out-of-memory error on the machine.

To Fix the memory consumption issue for the "show ip[v6] route vrf all
json" command, display the tables 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>
zebra/zebra_vty.c

index cc2d9b2164a876275a7b9c039a9824c5437324f9..97245d55b9eb8e101bb40ddf79a88bcf83dafb3b 100644 (file)
@@ -1739,6 +1739,7 @@ DEFPY (show_route,
        "Nexthop Group Information\n")
 {
        afi_t afi = ipv4 ? AFI_IP : AFI_IP6;
+       bool first_vrf_json = true;
        struct vrf *vrf;
        int type = 0;
        struct zebra_vrf *zvrf;
@@ -1770,7 +1771,9 @@ DEFPY (show_route,
                        if ((zvrf = vrf->info) == NULL
                            || (zvrf->table[afi][SAFI_UNICAST] == NULL))
                                continue;
-
+                       if (json)
+                               vty_json_key(vty, zvrf_name(zvrf),
+                                            &first_vrf_json);
                        if (table_all)
                                do_show_ip_route_all(vty, zvrf, afi, !!fib,
                                                     !!json, tag,
@@ -1786,6 +1789,8 @@ DEFPY (show_route,
                                                 ospf_instance_id, table, !!ng,
                                                 &ctx);
                }
+               if (json)
+                       vty_json_close(vty, first_vrf_json);
        } else {
                vrf_id_t vrf_id = VRF_DEFAULT;