From: Donald Sharp Date: Wed, 14 Feb 2018 03:38:47 +0000 (-0500) Subject: zebra: Add code to display interesting tables X-Git-Tag: frr-5.0-dev~212^2~4 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=ae825b8bf07764dc77248c83249c57a26ba2fd2b;p=mirror%2Ffrr.git zebra: Add code to display interesting tables With the ability of zebra to handle random tables, add code to display those tables via the show route table (1-...) [json] command. Signed-off-by: Donald Sharp --- diff --git a/zebra/zebra_ns.c b/zebra/zebra_ns.c index 91dbd34387..ac724a3299 100644 --- a/zebra/zebra_ns.c +++ b/zebra/zebra_ns.c @@ -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) diff --git a/zebra/zebra_ns.h b/zebra/zebra_ns.h index 29905ccad3..765f2c6893 100644 --- a/zebra/zebra_ns.h +++ b/zebra/zebra_ns.h @@ -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); diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 269244f768..d2248f4fbb 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -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 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);