From 7004c67b352d75afacebb9e02df60c4e542b03a2 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 21 Jan 2019 12:47:10 -0200 Subject: [PATCH] zebra: merge four "show ip nht" commands into a single DEFPY This is mostly to be consistent with the "show ip import-check" command, which is very similar. Signed-off-by: Renato Westphal --- zebra/zebra_vty.c | 92 +++++++++++------------------------------------ 1 file changed, 21 insertions(+), 71 deletions(-) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 83c12e2bd..87b279b1e 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -930,21 +930,35 @@ DEFPY (show_route_table_vrf, return CMD_SUCCESS; } -DEFUN (show_ip_nht, +DEFPY (show_ip_nht, show_ip_nht_cmd, - "show ip nht [vrf NAME]", + "show nht [vrf NAME$vrf_name|vrf all$vrf_all]", SHOW_STR IP_STR + IP6_STR "IP nexthop tracking table\n" - VRF_CMD_HELP_STR) + VRF_CMD_HELP_STR + VRF_ALL_CMD_HELP_STR) { - int idx_vrf = 4; + afi_t afi = ipv4 ? AFI_IP : AFI_IP6; vrf_id_t vrf_id = VRF_DEFAULT; - if (argc == 5) - VRF_GET_ID(vrf_id, argv[idx_vrf]->arg, false); + if (vrf_all) { + struct vrf *vrf; + struct zebra_vrf *zvrf; + + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) + if ((zvrf = vrf->info) != NULL) { + vty_out(vty, "\nVRF %s:\n", zvrf_name(zvrf)); + zebra_print_rnh_table(zvrf_id(zvrf), afi, vty, + RNH_NEXTHOP_TYPE); + } + return CMD_SUCCESS; + } + if (vrf_name) + VRF_GET_ID(vrf_id, vrf_name, false); - zebra_print_rnh_table(vrf_id, AFI_IP, vty, RNH_NEXTHOP_TYPE); + zebra_print_rnh_table(vrf_id, afi, vty, RNH_NEXTHOP_TYPE); return CMD_SUCCESS; } @@ -981,67 +995,6 @@ DEFPY (show_ip_import_check, return CMD_SUCCESS; } -DEFUN (show_ip_nht_vrf_all, - show_ip_nht_vrf_all_cmd, - "show ip nht vrf all", - SHOW_STR - IP_STR - "IP nexthop tracking table\n" - VRF_ALL_CMD_HELP_STR) -{ - struct vrf *vrf; - struct zebra_vrf *zvrf; - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) - if ((zvrf = vrf->info) != NULL) { - vty_out(vty, "\nVRF %s:\n", zvrf_name(zvrf)); - zebra_print_rnh_table(zvrf_id(zvrf), AFI_IP, vty, - RNH_NEXTHOP_TYPE); - } - - return CMD_SUCCESS; -} - -DEFUN (show_ipv6_nht, - show_ipv6_nht_cmd, - "show ipv6 nht [vrf NAME]", - SHOW_STR - IPV6_STR - "IPv6 nexthop tracking table\n" - VRF_CMD_HELP_STR) -{ - int idx_vrf = 4; - vrf_id_t vrf_id = VRF_DEFAULT; - - if (argc == 5) - VRF_GET_ID(vrf_id, argv[idx_vrf]->arg, false); - - zebra_print_rnh_table(vrf_id, AFI_IP6, vty, RNH_NEXTHOP_TYPE); - return CMD_SUCCESS; -} - - -DEFUN (show_ipv6_nht_vrf_all, - show_ipv6_nht_vrf_all_cmd, - "show ipv6 nht vrf all", - SHOW_STR - IP_STR - "IPv6 nexthop tracking table\n" - VRF_ALL_CMD_HELP_STR) -{ - struct vrf *vrf; - struct zebra_vrf *zvrf; - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) - if ((zvrf = vrf->info) != NULL) { - vty_out(vty, "\nVRF %s:\n", zvrf_name(zvrf)); - zebra_print_rnh_table(zvrf_id(zvrf), AFI_IP6, vty, - RNH_NEXTHOP_TYPE); - } - - return CMD_SUCCESS; -} - DEFUN (ip_nht_default_route, ip_nht_default_route_cmd, "ip nht resolve-via-default", @@ -2954,9 +2907,6 @@ void zebra_vty_init(void) install_element(VIEW_NODE, &show_route_summary_cmd); install_element(VIEW_NODE, &show_ip_nht_cmd); install_element(VIEW_NODE, &show_ip_import_check_cmd); - install_element(VIEW_NODE, &show_ip_nht_vrf_all_cmd); - install_element(VIEW_NODE, &show_ipv6_nht_cmd); - install_element(VIEW_NODE, &show_ipv6_nht_vrf_all_cmd); install_element(VIEW_NODE, &show_ip_rpf_cmd); install_element(VIEW_NODE, &show_ip_rpf_addr_cmd); -- 2.39.2