From e5eee9afc3a4e09e7a5b19b03e1b335fcf9699ca Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 19 May 2015 18:03:55 -0700 Subject: [PATCH] The 'show ip bgp json' output is incorrect if the aspath is empty --- bgpd/bgp_route.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index fe39d47596..d9848fec0c 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -6737,7 +6737,10 @@ route_vty_out (struct vty *vty, struct prefix *p, { if (json_paths) { - json_string = json_object_new_string(attr->aspath); + if (!attr->aspath->str || aspath_count_hops (attr->aspath) == 0) + json_string = json_object_new_string("Local"); + else + json_string = json_object_new_string(attr->aspath->str); json_object_object_add(json_path, "aspath", json_string); } else @@ -8119,34 +8122,25 @@ bgp_show_route_in_table (struct vty *vty, struct bgp *bgp, } } - if (display) + if (use_json) { - if (use_json) - { - json_object_object_add(json, "paths", json_paths); - } + if (display) + json_object_object_add(json, "paths", json_paths); + + vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE); + + // Recursively free all json structures + json_object_put(json); } else { - if (use_json) - { - vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE); - } - else + if (!display) { vty_out (vty, "%% Network not in table%s", VTY_NEWLINE); return CMD_WARNING; } } - if (use_json) - { - vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE); - - // Recursively free all json structures - json_object_put(json); - } - return CMD_SUCCESS; } -- 2.39.5