diff options
author | David Lamparter <equinox@diac24.net> | 2018-08-08 20:27:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-08 20:27:49 +0200 |
commit | 6de00b4e95f6dafb1d754d4c30039e0af7d78765 (patch) | |
tree | 39d98554e3c397c3cdb3724150aca73883fa81a0 /zebra | |
parent | Merge pull request #2122 from donaldsharp/zebra_nhs (diff) | |
parent | 1. Added json output to "show ip route <prefix>" command (diff) | |
download | frr-6de00b4e95f6dafb1d754d4c30039e0af7d78765.tar.xz frr-6de00b4e95f6dafb1d754d4c30039e0af7d78765.zip |
Merge pull request #2799 from adharkar/frr-zebra_cli
Zebra: Changes to "show ip route" json commands
Diffstat (limited to 'zebra')
-rw-r--r-- | zebra/zebra_vty.c | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 7eb6fe828..4f1d5cf6d 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -404,6 +404,9 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, json_object_int_add(json_route, "metric", re->metric); } + if (re->tag) + json_object_int_add(json_route, "tag", re->tag); + json_object_int_add(json_route, "internalStatus", re->status); json_object_int_add(json_route, "internalFlags", @@ -729,6 +732,29 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, } } +static void vty_show_ip_route_detail_json(struct vty *vty, + struct route_node *rn) +{ + json_object *json = NULL; + json_object *json_prefix = NULL; + struct route_entry *re; + char buf[BUFSIZ]; + + json = json_object_new_object(); + + RNODE_FOREACH_RE (rn, re) { + json_prefix = json_object_new_array(); + vty_show_ip_route(vty, rn, re, json_prefix); + prefix2str(&rn->p, buf, sizeof buf); + json_object_object_add(json, buf, json_prefix); + json_prefix = NULL; + } + + vty_out(vty, "%s\n", json_object_to_json_string_ext( + json, JSON_C_TO_STRING_PRETTY)); + json_object_free(json); +} + static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf, struct route_table *table, afi_t afi, bool use_fib, route_tag_t tag, @@ -810,15 +836,15 @@ static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf, } if (json_prefix) { - prefix2str(&rn->p, buf, sizeof buf); + prefix2str(&rn->p, buf, sizeof(buf)); json_object_object_add(json, buf, json_prefix); json_prefix = NULL; } } if (use_json) { - vty_out(vty, "%s\n", json_object_to_json_string_ext( - json, JSON_C_TO_STRING_PRETTY)); + vty_out(vty, "%s\n", json_object_to_json_string_ext(json, + JSON_C_TO_STRING_PRETTY)); json_object_free(json); } } @@ -1157,7 +1183,8 @@ DEFPY (show_route_detail, X:X::X:X$address\ |X:X::X:X/M$prefix\ >\ - >", + >\ + [json$json]", SHOW_STR IP_STR "IP routing table\n" @@ -1168,7 +1195,8 @@ DEFPY (show_route_detail, "IP routing table\n" VRF_FULL_CMD_HELP_STR "IPv6 Address\n" - "IPv6 prefix\n") + "IPv6 prefix\n" + JSON_STR) { afi_t afi = ipv4 ? AFI_IP : AFI_IP6; struct route_table *table; @@ -1199,7 +1227,10 @@ DEFPY (show_route_detail, continue; } - vty_show_ip_route_detail(vty, rn, 0); + if (json) + vty_show_ip_route_detail_json(vty, rn); + else + vty_show_ip_route_detail(vty, rn, 0); route_unlock_node(rn); } @@ -1224,7 +1255,10 @@ DEFPY (show_route_detail, return CMD_WARNING; } - vty_show_ip_route_detail(vty, rn, 0); + if (json) + vty_show_ip_route_detail_json(vty, rn); + else + vty_show_ip_route_detail(vty, rn, 0); route_unlock_node(rn); } |