]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: Add code to display interesting tables
authorDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 14 Feb 2018 03:38:47 +0000 (22:38 -0500)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 23 Feb 2018 12:08:36 +0000 (07:08 -0500)
With the ability of zebra to handle random tables,
add code to display those tables via the
show <ip|ipv6> route table (1-...) [json] command.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
zebra/zebra_ns.c
zebra/zebra_ns.h
zebra/zebra_vty.c

index 91dbd34387d023b2d88201f0b4865f73e554b902..ac724a3299bc715787ec6dd98be854b03976f6fe 100644 (file)
@@ -74,6 +74,23 @@ int zebra_ns_enable(ns_id_t ns_id, void **info)
        return 0;
 }
 
+struct route_table *zebra_ns_find_table(struct zebra_ns *zns,
+                                       uint32_t tableid, afi_t afi)
+{
+       struct zebra_ns_tables finder;
+       struct zebra_ns_tables *znst;
+
+       memset(&finder, 0, sizeof(finder));
+       finder.afi = afi;
+       finder.tableid = tableid;
+       znst = RB_FIND(zebra_ns_tables_head, &zns->ns_tables, &finder);
+
+       if (znst)
+               return znst->table;
+       else
+               return NULL;
+}
+
 struct route_table *zebra_ns_get_table(struct zebra_ns *zns,
                                       struct zebra_vrf *zvrf, uint32_t tableid,
                                       afi_t afi)
index 29905ccad38e1f321e6a7d6f396af77bc1ad9feb..765f2c6893d959b611df6c4c0236f08a31dbefca 100644 (file)
@@ -77,6 +77,8 @@ int zebra_ns_init(void);
 int zebra_ns_enable(ns_id_t ns_id, void **info);
 int zebra_ns_disable(ns_id_t ns_id, void **info);
 
+extern struct route_table *zebra_ns_find_table(struct zebra_ns *zns,
+                                              uint32_t tableid, afi_t afi);
 extern struct route_table *zebra_ns_get_table(struct zebra_ns *zns,
                                              struct zebra_vrf *zvrf,
                                              uint32_t tableid, afi_t afi);
index 269244f7688dec1f72bd89407b46503c1f8cc41a..d2248f4fbb6fabcc9c56b7d86b5f3aa5b64ea9eb 100644 (file)
@@ -1235,46 +1235,21 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn,
        }
 }
 
-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,
-                           const struct prefix *longer_prefix_p,
-                           bool supernets_only, int type,
-                           u_short ospf_instance_id)
+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,
+                                const struct prefix *longer_prefix_p,
+                                bool supernets_only, int type,
+                                u_short ospf_instance_id, u_char use_json)
 {
-       struct route_table *table;
-       rib_dest_t *dest;
        struct route_node *rn;
        struct route_entry *re;
        int first = 1;
-       struct zebra_vrf *zvrf = NULL;
-       char buf[BUFSIZ];
+       rib_dest_t *dest;
        json_object *json = NULL;
        json_object *json_prefix = NULL;
-       u_int32_t addr;
-
-       if (!(zvrf = zebra_vrf_lookup_by_name(vrf_name))) {
-               if (use_json)
-                       vty_out(vty, "{}\n");
-               else
-                       vty_out(vty, "vrf %s not defined\n", vrf_name);
-               return CMD_SUCCESS;
-       }
-
-       if (zvrf_id(zvrf) == VRF_UNKNOWN) {
-               if (use_json)
-                       vty_out(vty, "{}\n");
-               else
-                       vty_out(vty, "vrf %s inactive\n", vrf_name);
-               return CMD_SUCCESS;
-       }
-
-       table = zebra_vrf_table(afi, safi, zvrf_id(zvrf));
-       if (!table) {
-               if (use_json)
-                       vty_out(vty, "{}\n");
-               return CMD_SUCCESS;
-       }
+       uint32_t addr;
+       char buf[BUFSIZ];
 
        if (use_json)
                json = json_object_new_object();
@@ -1352,6 +1327,67 @@ static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi,
                                             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,
+                           const struct prefix *longer_prefix_p,
+                           bool supernets_only, int type,
+                           u_short ospf_instance_id)
+{
+       struct route_table *table;
+       struct zebra_vrf *zvrf = NULL;
+
+       if (!(zvrf = zebra_vrf_lookup_by_name(vrf_name))) {
+               if (use_json)
+                       vty_out(vty, "{}\n");
+               else
+                       vty_out(vty, "vrf %s not defined\n", vrf_name);
+               return CMD_SUCCESS;
+       }
+
+       if (zvrf_id(zvrf) == VRF_UNKNOWN) {
+               if (use_json)
+                       vty_out(vty, "{}\n");
+               else
+                       vty_out(vty, "vrf %s inactive\n", vrf_name);
+               return CMD_SUCCESS;
+       }
+
+       table = zebra_vrf_table(afi, safi, zvrf_id(zvrf));
+       if (!table) {
+               if (use_json)
+                       vty_out(vty, "{}\n");
+               return CMD_SUCCESS;
+       }
+
+       do_show_route_helper(vty, zvrf, table, afi, use_fib, tag,
+                            longer_prefix_p, supernets_only, type,
+                            ospf_instance_id, use_json);
+
+       return CMD_SUCCESS;
+}
+
+DEFPY (show_route_table,
+       show_route_table_cmd,
+       "show <ip$ipv4|ipv6$ipv6> route table (1-4294967295)$table [json$json]",
+       SHOW_STR
+       IP_STR
+       IP6_STR
+       "IP routing table\n"
+       "Table to display\n"
+       "The table number to display, if available\n"
+       JSON_STR)
+{
+       afi_t afi = ipv4 ? AFI_IP : AFI_IP6;
+       struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
+       struct route_table *t;
+
+       t = zebra_ns_find_table(zvrf->zns, table, afi);
+       if (t)
+               do_show_route_helper(vty, zvrf, t, afi, false, 0, false, false,
+                                    0, 0, !!json);
 
        return CMD_SUCCESS;
 }
@@ -3341,6 +3377,7 @@ void zebra_vty_init(void)
        install_element(VIEW_NODE, &show_vrf_cmd);
        install_element(VIEW_NODE, &show_vrf_vni_cmd);
        install_element(VIEW_NODE, &show_route_cmd);
+       install_element(VIEW_NODE, &show_route_table_cmd);
        install_element(VIEW_NODE, &show_route_detail_cmd);
        install_element(VIEW_NODE, &show_route_summary_cmd);
        install_element(VIEW_NODE, &show_ip_nht_cmd);