diff options
author | Russ White <russ@riw.us> | 2019-07-30 17:18:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-30 17:18:10 +0200 |
commit | 0cd8c0ff11b5f55aa633624cf3fe0f42cf810c15 (patch) | |
tree | 695b732333db2e3f537b986d4d865b963a526b4c | |
parent | Merge pull request #4750 from dslicenc/bgp-remove-replace-as (diff) | |
parent | doc: add information about 'show ip route [vrf VRF] tables command (diff) | |
download | frr-0cd8c0ff11b5f55aa633624cf3fe0f42cf810c15.tar.xz frr-0cd8c0ff11b5f55aa633624cf3fe0f42cf810c15.zip |
Merge pull request #4650 from pguibert6WIND/show_ip_route_table_all
zebra: add show ip route all command to dump all unicast tables
-rw-r--r-- | doc/user/zebra.rst | 6 | ||||
-rw-r--r-- | zebra/zebra_vty.c | 55 |
2 files changed, 55 insertions, 6 deletions
diff --git a/doc/user/zebra.rst b/doc/user/zebra.rst index eefc5802a..2744cb66e 100644 --- a/doc/user/zebra.rst +++ b/doc/user/zebra.rst @@ -361,6 +361,12 @@ commands in relationship to VRF. Here is an extract of some of those commands: will dump the routing table ``TABLENO`` of the *Linux network namespace* ``VRF``. +.. index:: show ip route vrf VRF tables +.. clicmd:: show ip route vrf VRF tables + + This command will dump the routing tables within the vrf scope. If `vrf all` + is executed, all routing tables will be dumped. + By using the :option:`-n` option, the *Linux network namespace* will be mapped over the *Zebra* VRF. One nice feature that is possible by handling *Linux network namespace* is the ability to name default VRF. At startup, *Zebra* diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 4d18045fb..91edfab10 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -448,6 +448,9 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, if (re->tag) json_object_int_add(json_route, "tag", re->tag); + if (re->table) + json_object_int_add(json_route, "table", re->table); + json_object_int_add(json_route, "internalStatus", re->status); json_object_int_add(json_route, "internalFlags", @@ -804,7 +807,8 @@ static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf, bool use_fib, route_tag_t tag, const struct prefix *longer_prefix_p, bool supernets_only, int type, - unsigned short ospf_instance_id, bool use_json) + unsigned short ospf_instance_id, bool use_json, + uint32_t tableid) { struct route_node *rn; struct route_entry *re; @@ -867,10 +871,12 @@ static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf, vty_out(vty, SHOW_ROUTE_V6_HEADER); - if (zvrf_id(zvrf) != VRF_DEFAULT) + if (tableid && tableid != RT_TABLE_MAIN) + vty_out(vty, "\nVRF %s table %u:\n", + zvrf_name(zvrf), tableid); + else if (zvrf_id(zvrf) != VRF_DEFAULT) vty_out(vty, "\nVRF %s:\n", zvrf_name(zvrf)); - first = 0; } } @@ -927,7 +933,7 @@ static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, do_show_route_helper(vty, zvrf, table, afi, use_fib, tag, longer_prefix_p, supernets_only, type, - ospf_instance_id, use_json); + ospf_instance_id, use_json, 0); return CMD_SUCCESS; } @@ -950,7 +956,7 @@ DEFPY (show_route_table, t = zebra_router_find_table(zvrf, table, afi, SAFI_UNICAST); if (t) do_show_route_helper(vty, zvrf, t, afi, false, 0, false, false, - 0, 0, !!json); + 0, 0, !!json, table); return CMD_SUCCESS; } @@ -979,8 +985,44 @@ DEFPY (show_route_table_vrf, t = zebra_router_find_table(zvrf, table, afi, SAFI_UNICAST); if (t) do_show_route_helper(vty, zvrf, t, afi, false, 0, false, false, - 0, 0, !!json); + 0, 0, !!json, table); + + return CMD_SUCCESS; +} + +DEFPY (show_route_all_table_vrf, + show_route_all_table_vrf_cmd, + "show <ip$ipv4|ipv6$ipv6> route [vrf <NAME$vrf_name|all$vrf_all>] tables [json$json]", + SHOW_STR + IP_STR + IP6_STR + "IP routing table\n" + "Display all tables\n" + VRF_FULL_CMD_HELP_STR + JSON_STR) +{ + afi_t afi = ipv4 ? AFI_IP : AFI_IP6; + struct zebra_vrf *zvrf = NULL; + vrf_id_t vrf_id = VRF_UNKNOWN; + struct zebra_router_table *zrt; + if (vrf_name) { + VRF_GET_ID(vrf_id, vrf_name, !!json); + zvrf = zebra_vrf_lookup_by_id(vrf_id); + } + + RB_FOREACH (zrt, zebra_router_table_head, &zrouter.tables) { + rib_table_info_t *info = route_table_get_info(zrt->table); + + if (zvrf && zvrf != info->zvrf) + continue; + if (zrt->afi != afi || zrt->safi != SAFI_UNICAST) + continue; + if (zrt->table) + do_show_route_helper(vty, info->zvrf, zrt->table, afi, + false, 0, false, false, + 0, 0, !!json, zrt->tableid); + } return CMD_SUCCESS; } @@ -2989,6 +3031,7 @@ void zebra_vty_init(void) install_element(VIEW_NODE, &show_route_table_cmd); if (vrf_is_backend_netns()) install_element(VIEW_NODE, &show_route_table_vrf_cmd); + install_element(VIEW_NODE, &show_route_all_table_vrf_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); |