]> git.proxmox.com Git - mirror_frr.git/commitdiff
ospfd: Fix usage of JSON_C_TO_STRING_NOSLASHESCAPE
authorDonald Sharp <sharpd@nvidia.com>
Tue, 7 Sep 2021 13:36:39 +0000 (09:36 -0400)
committerDonald Sharp <sharpd@nvidia.com>
Tue, 7 Sep 2021 13:36:39 +0000 (09:36 -0400)
The usage of json_object_to_json_string_ext is meant for
generation of output string and returns a `char *` pointer
to the `formatted` output.  Just calling it does nothing
and it's expensive to boot.

Modify the code in ospfd to just output with the NOSLASHESCAPE
when outputting.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
ospfd/ospf_vty.c

index 1d4aa65355650c9d8ddb442e600907175fd39c86..8af44943356f128d11ae234a0c0dcc8a9492491e 100644 (file)
@@ -10608,11 +10608,8 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
                prefix2str(&rn->p, buf1, sizeof(buf1));
 
                json_route = json_object_new_object();
-               if (json) {
+               if (json)
                        json_object_object_add(json, buf1, json_route);
-                       json_object_to_json_string_ext(
-                               json, JSON_C_TO_STRING_NOSLASHESCAPE);
-               }
 
                switch (or->path_type) {
                case OSPF_PATH_INTER_AREA:
@@ -10909,11 +10906,8 @@ static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
 
                snprintfrr(buf1, sizeof(buf1), "%pFX", &rn->p);
                json_route = json_object_new_object();
-               if (json) {
+               if (json)
                        json_object_object_add(json, buf1, json_route);
-                       json_object_to_json_string_ext(
-                               json, JSON_C_TO_STRING_NOSLASHESCAPE);
-               }
 
                switch (er->path_type) {
                case OSPF_PATH_TYPE1_EXTERNAL:
@@ -11224,7 +11218,9 @@ DEFUN (show_ip_ospf_route,
                        if (uj) {
                                /* Keep Non-pretty format */
                                vty_out(vty, "%s\n",
-                                       json_object_to_json_string(json));
+                                       json_object_to_json_string_ext(
+                                               json,
+                                               JSON_C_TO_STRING_NOSLASHESCAPE));
                                json_object_free(json);
                        } else if (!ospf_output)
                                vty_out(vty, "%% OSPF instance not found\n");
@@ -11236,7 +11232,9 @@ DEFUN (show_ip_ospf_route,
                        if (uj) {
                                vty_out(vty, "%s\n",
                                        json_object_to_json_string_ext(
-                                               json, JSON_C_TO_STRING_PRETTY));
+                                               json,
+                                               JSON_C_TO_STRING_PRETTY
+                                                       | JSON_C_TO_STRING_NOSLASHESCAPE));
                                json_object_free(json);
                        } else
                                vty_out(vty, "%% OSPF instance not found\n");
@@ -11250,7 +11248,9 @@ DEFUN (show_ip_ospf_route,
                        if (uj) {
                                vty_out(vty, "%s\n",
                                        json_object_to_json_string_ext(
-                                               json, JSON_C_TO_STRING_PRETTY));
+                                               json,
+                                               JSON_C_TO_STRING_PRETTY
+                                                       | JSON_C_TO_STRING_NOSLASHESCAPE));
                                json_object_free(json);
                        } else
                                vty_out(vty, "%% OSPF instance not found\n");
@@ -11263,7 +11263,9 @@ DEFUN (show_ip_ospf_route,
                ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf);
                /* Keep Non-pretty format */
                if (uj)
-                       vty_out(vty, "%s\n", json_object_to_json_string(json));
+                       vty_out(vty, "%s\n",
+                               json_object_to_json_string_ext(
+                                       json, JSON_C_TO_STRING_NOSLASHESCAPE));
        }
 
        if (uj)