]> git.puffer.fish Git - matthieu/frr.git/commitdiff
Zebra: Changes to "show ip route" json commands backport to stable/4.0
authorAmeya Dharkar <adharkar@vmware.com>
Tue, 14 Aug 2018 18:43:17 +0000 (11:43 -0700)
committerAmeya Dharkar <adharkar@vmware.com>
Tue, 14 Aug 2018 18:43:17 +0000 (11:43 -0700)
1. Added json output to "show ip route " command
2. Added tag O/P to "show ip route json" command

Signed-off-by: Ameya Dharkar adharkar@vmware.com
zebra/zebra_vty.c

index 4ab835cc3e8acad1f9860e0adefa1fc8b1174261..c4a99734cb545a7cc4ef77664651c0b7a6442985 100644 (file)
@@ -881,6 +881,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);
@@ -1192,6 +1195,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 int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi,
                            safi_t safi, bool use_fib, u_char use_json,
                            route_tag_t tag,
@@ -1555,7 +1581,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"
@@ -1566,7 +1593,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;
@@ -1597,7 +1625,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);
                }
@@ -1622,7 +1653,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);
        }