Skip to content

Commit

Permalink
Merge pull request #2808 from adharkar/frr-zebra_cli-5.0
Browse files Browse the repository at this point in the history
Zebra: Changes to "show ip route" json commands backport to stable/5.0
  • Loading branch information
donaldsharp committed Aug 14, 2018
2 parents 2ce8c82 + 730c60c commit ccd3a95
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions zebra/zebra_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,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);

if (uptime < ONE_DAY_SECOND)
sprintf(buf, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
tm->tm_sec);
Expand Down Expand Up @@ -1532,6 +1535,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,
Expand Down Expand Up @@ -1613,15 +1639,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);
}
}
Expand Down Expand Up @@ -1931,7 +1957,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"
Expand All @@ -1942,7 +1969,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;
Expand Down Expand Up @@ -1973,7 +2001,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);
}
Expand All @@ -1998,7 +2029,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);
}
Expand Down

0 comments on commit ccd3a95

Please sign in to comment.