From ecffa493c0c2a3ac9fe96a5ac202f48da9b44d21 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 13 Sep 2017 15:16:12 -0300 Subject: [PATCH 1/4] zebra: unify the ipv4/ipv6 'show ip route' commands - part 1/2 Note: I had to remove one assert in clidef.py in order to fix a build error when using a preprocessor string (FRR_IP_REDIST_STR_ZEBRA) inside a DEFPY command. This should be revisited later. Signed-off-by: Renato Westphal --- lib/vrf.h | 1 + python/clidef.py | 2 - zebra/zebra_vty.c | 236 +++++++++++----------------------------------- 3 files changed, 54 insertions(+), 185 deletions(-) diff --git a/lib/vrf.h b/lib/vrf.h index 8bfdc87689..e93e993776 100644 --- a/lib/vrf.h +++ b/lib/vrf.h @@ -51,6 +51,7 @@ enum { IFLA_VRF_UNSPEC, IFLA_VRF_TABLE, __IFLA_VRF_MAX }; */ #define VRF_CMD_HELP_STR "Specify the VRF\nThe VRF name\n" #define VRF_ALL_CMD_HELP_STR "Specify the VRF\nAll VRFs\n" +#define VRF_FULL_CMD_HELP_STR "Specify the VRF\nThe VRF name\nAll VRFs\n" /* * Pass some OS specific data up through diff --git a/python/clidef.py b/python/clidef.py index 6a69986323..fe01a89162 100644 --- a/python/clidef.py +++ b/python/clidef.py @@ -188,8 +188,6 @@ def process_file(fn, ofd, dumpfd, all_defun): for entry in filedata['data']: if entry['type'] == 'DEFPY' or (all_defun and entry['type'].startswith('DEFUN')): cmddef = entry['args'][2] - for i in cmddef: - assert i.startswith('"') and i.endswith('"') cmddef = ''.join([i[1:-1] for i in cmddef]) graph = clippy.Graph(cmddef) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index d86cc88b42..dbfb491db1 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -49,7 +49,8 @@ extern int allow_delete; 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, struct prefix *longer_prefix_p, + route_tag_t tag, + const struct prefix *longer_prefix_p, bool supernets_only, int type, u_short ospf_instance_id); static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, @@ -935,14 +936,10 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, } } -static bool use_fib(struct cmd_token *token) -{ - return strncmp(token->arg, "route", strlen(token->arg)); -} - 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, struct prefix *longer_prefix_p, + route_tag_t tag, + const struct prefix *longer_prefix_p, bool supernets_only, int type, u_short ospf_instance_id) { @@ -1200,14 +1197,31 @@ DEFUN (no_ipv6_nht_default_route, return CMD_SUCCESS; } -DEFUN (show_ip_route, - show_ip_route_cmd, - "show ip [vrf NAME] [tag (1-4294967295)|A.B.C.D/M longer-prefixes|supernets-only|" FRR_IP_REDIST_STR_ZEBRA "|ospf (1-65535)] [json]", +DEFPY (show_route, + show_route_cmd, + "show\ + <\ + ip$ipv4 [vrf ]\ + [\ + tag (1-4294967295)\ + |A.B.C.D/M$prefix longer-prefixes\ + |supernets-only$supernets_only\ + |" FRR_IP_REDIST_STR_ZEBRA "$type_str\ + |ospf$type_str (1-65535)$ospf_instance_id\ + ]\ + |ipv6$ipv6 [vrf ]\ + [\ + tag (1-4294967295)\ + |X:X::X:X/M$prefix longer-prefixes\ + |" FRR_IP6_REDIST_STR_ZEBRA "$type_str\ + ]\ + >\ + [json$json]", SHOW_STR IP_STR "IP forwarding table\n" "IP routing table\n" - VRF_CMD_HELP_STR + VRF_FULL_CMD_HELP_STR "Show only routes with tag\n" "Tag value\n" "IP prefix /, e.g., 35.0.0.0/8\n" @@ -1216,75 +1230,23 @@ DEFUN (show_ip_route, FRR_IP_REDIST_HELP_STR_ZEBRA "Open Shortest Path First (OSPFv2)\n" "Instance ID\n" + IPV6_STR + "IP forwarding table\n" + "IP routing table\n" + VRF_FULL_CMD_HELP_STR + "Show only routes with tag\n" + "Tag value\n" + "IPv6 prefix\n" + "Show route matching the specified Network/Mask pair only\n" + FRR_IP6_REDIST_HELP_STR_ZEBRA JSON_STR) { - bool uf = use_fib(argv[2]); - struct route_table *table; - int vrf_all = 0; - route_tag_t tag = 0; - vrf_id_t vrf_id = VRF_DEFAULT; + afi_t afi = ipv4 ? AFI_IP : AFI_IP6; struct vrf *vrf; - struct zebra_vrf *zvrf; - int uj = use_json(argc, argv); - int idx = 0; - struct prefix p; - bool longer_prefixes = false; - bool supernets_only = false; int type = 0; - u_short ospf_instance_id = 0; - - if (argv_find(argv, argc, "vrf", &idx)) { - if (strmatch(argv[idx + 1]->arg, "all")) - vrf_all = 1; - else - VRF_GET_ID(vrf_id, argv[idx + 1]->arg); - } - - if (argv_find(argv, argc, "tag", &idx)) - tag = strtoul(argv[idx + 1]->arg, NULL, 10); - - else if (argv_find(argv, argc, "A.B.C.D/M", &idx)) { - if (str2prefix(argv[idx]->arg, &p) <= 0) { - vty_out(vty, "%% Malformed prefix\n"); - return CMD_WARNING; - } - longer_prefixes = true; - } - - else if (argv_find(argv, argc, "supernets_only", &idx)) - supernets_only = true; - - else { - if (argv_find(argv, argc, "kernel", &idx)) - type = proto_redistnum(AFI_IP, argv[idx]->text); - else if (argv_find(argv, argc, "babel", &idx)) - type = proto_redistnum(AFI_IP, argv[idx]->text); - else if (argv_find(argv, argc, "connected", &idx)) - type = proto_redistnum(AFI_IP, argv[idx]->text); - else if (argv_find(argv, argc, "static", &idx)) - type = proto_redistnum(AFI_IP, argv[idx]->text); - else if (argv_find(argv, argc, "rip", &idx)) - type = proto_redistnum(AFI_IP, argv[idx]->text); - else if (argv_find(argv, argc, "ospf", &idx)) - type = proto_redistnum(AFI_IP, argv[idx]->text); - else if (argv_find(argv, argc, "isis", &idx)) - type = proto_redistnum(AFI_IP, argv[idx]->text); - else if (argv_find(argv, argc, "bgp", &idx)) - type = proto_redistnum(AFI_IP, argv[idx]->text); - else if (argv_find(argv, argc, "pim", &idx)) - type = proto_redistnum(AFI_IP, argv[idx]->text); - else if (argv_find(argv, argc, "eigrp", &idx)) - type = proto_redistnum(AFI_IP, argv[idx]->text); - else if (argv_find(argv, argc, "nhrp", &idx)) - type = proto_redistnum(AFI_IP, argv[idx]->text); - else if (argv_find(argv, argc, "table", &idx)) - type = proto_redistnum(AFI_IP, argv[idx]->text); - else if (argv_find(argv, argc, "vnc", &idx)) - type = proto_redistnum(AFI_IP, argv[idx]->text); - - if (argv_find(argv, argc, "(1-65535)", &idx)) - ospf_instance_id = strtoul(argv[idx]->arg, NULL, 10); + if (type_str) { + type = proto_redistnum(afi, type_str); if (type < 0) { vty_out(vty, "Unknown route type\n"); return CMD_WARNING; @@ -1293,22 +1255,29 @@ DEFUN (show_ip_route, if (vrf_all) { RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { + struct zebra_vrf *zvrf; + struct route_table *table; + if ((zvrf = vrf->info) == NULL - || (table = zvrf->table[AFI_IP][SAFI_UNICAST]) - == NULL) + || (table = zvrf->table[afi][SAFI_UNICAST]) == NULL) continue; do_show_ip_route( - vty, zvrf_name(zvrf), AFI_IP, SAFI_UNICAST, uf, - uj, tag, longer_prefixes ? &p : NULL, - supernets_only, type, ospf_instance_id); + vty, zvrf_name(zvrf), afi, SAFI_UNICAST, !!fib, + !!json, tag, prefix_str ? prefix : NULL, + !!supernets_only, type, ospf_instance_id); } } else { + vrf_id_t vrf_id = VRF_DEFAULT; + + if (vrf_name) + VRF_GET_ID(vrf_id, vrf_name); vrf = vrf_lookup_by_id(vrf_id); - do_show_ip_route(vty, vrf->name, AFI_IP, SAFI_UNICAST, uf, uj, - tag, longer_prefixes ? &p : NULL, - supernets_only, type, ospf_instance_id); + do_show_ip_route(vty, vrf->name, afi, SAFI_UNICAST, !!fib, + !!json, tag, prefix_str ? prefix : NULL, + !!supernets_only, type, ospf_instance_id); } + return CMD_SUCCESS; } @@ -1900,104 +1869,6 @@ DEFPY(ipv6_route, tag_str, distance_str, vrf, label); } -DEFUN (show_ipv6_route, - show_ipv6_route_cmd, - "show ipv6 [vrf NAME] [tag (1-4294967295)|X:X::X:X/M longer-prefixes|" FRR_IP6_REDIST_STR_ZEBRA "] [json]", - SHOW_STR - IP_STR - "IP forwarding table\n" - "IP routing table\n" - VRF_CMD_HELP_STR - "Show only routes with tag\n" - "Tag value\n" - "IPv6 prefix\n" - "Show route matching the specified Network/Mask pair only\n" - FRR_IP6_REDIST_HELP_STR_ZEBRA - JSON_STR) -{ - bool uf = use_fib(argv[2]); - struct route_table *table; - int vrf_all = 0; - route_tag_t tag = 0; - vrf_id_t vrf_id = VRF_DEFAULT; - struct vrf *vrf; - struct zebra_vrf *zvrf; - int uj = use_json(argc, argv); - int idx = 0; - struct prefix p; - bool longer_prefixes = false; - bool supernets_only = false; - int type = 0; - - if (argv_find(argv, argc, "vrf", &idx)) { - if (strmatch(argv[idx + 1]->arg, "all")) - vrf_all = 1; - else - VRF_GET_ID(vrf_id, argv[idx + 1]->arg); - } - - if (argv_find(argv, argc, "tag", &idx)) - tag = strtoul(argv[idx + 1]->arg, NULL, 10); - - else if (argv_find(argv, argc, "X:X::X:X/M", &idx)) { - if (str2prefix(argv[idx]->arg, &p) <= 0) { - vty_out(vty, "%% Malformed prefix\n"); - return CMD_WARNING; - } - longer_prefixes = true; - } - - else { - if (argv_find(argv, argc, "kernel", &idx)) - type = proto_redistnum(AFI_IP6, argv[idx]->text); - else if (argv_find(argv, argc, "babel", &idx)) - type = proto_redistnum(AFI_IP6, argv[idx]->text); - else if (argv_find(argv, argc, "connected", &idx)) - type = proto_redistnum(AFI_IP6, argv[idx]->text); - else if (argv_find(argv, argc, "static", &idx)) - type = proto_redistnum(AFI_IP6, argv[idx]->text); - else if (argv_find(argv, argc, "ripng", &idx)) - type = proto_redistnum(AFI_IP6, argv[idx]->text); - else if (argv_find(argv, argc, "ospf6", &idx)) - type = proto_redistnum(AFI_IP6, argv[idx]->text); - else if (argv_find(argv, argc, "isis", &idx)) - type = proto_redistnum(AFI_IP6, argv[idx]->text); - else if (argv_find(argv, argc, "bgp", &idx)) - type = proto_redistnum(AFI_IP6, argv[idx]->text); - else if (argv_find(argv, argc, "nhrp", &idx)) - type = proto_redistnum(AFI_IP6, argv[idx]->text); - else if (argv_find(argv, argc, "table", &idx)) - type = proto_redistnum(AFI_IP6, argv[idx]->text); - else if (argv_find(argv, argc, "vnc", &idx)) - type = proto_redistnum(AFI_IP6, argv[idx]->text); - - if (type < 0) { - vty_out(vty, "Unknown route type\n"); - return CMD_WARNING; - } - } - - if (vrf_all) { - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if ((zvrf = vrf->info) == NULL - || (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) - == NULL) - continue; - - do_show_ip_route(vty, zvrf_name(zvrf), AFI_IP6, - SAFI_UNICAST, uf, uj, tag, - longer_prefixes ? &p : NULL, - supernets_only, type, 0); - } - } else { - vrf = vrf_lookup_by_id(vrf_id); - do_show_ip_route(vty, vrf->name, AFI_IP6, SAFI_UNICAST, uf, uj, - tag, longer_prefixes ? &p : NULL, - supernets_only, type, 0); - } - return CMD_SUCCESS; -} - DEFUN (show_ipv6_route_addr, show_ipv6_route_addr_cmd, "show ipv6 route [vrf NAME] X:X::X:X", @@ -2783,7 +2654,7 @@ void zebra_vty_init(void) install_element(CONFIG_NODE, &no_ip_zebra_import_table_cmd); install_element(VIEW_NODE, &show_vrf_cmd); - install_element(VIEW_NODE, &show_ip_route_cmd); + install_element(VIEW_NODE, &show_route_cmd); install_element(VIEW_NODE, &show_ip_nht_cmd); install_element(VIEW_NODE, &show_ip_nht_vrf_all_cmd); install_element(VIEW_NODE, &show_ipv6_nht_cmd); @@ -2808,7 +2679,6 @@ void zebra_vty_init(void) install_element(CONFIG_NODE, &no_ip_nht_default_route_cmd); install_element(CONFIG_NODE, &ipv6_nht_default_route_cmd); install_element(CONFIG_NODE, &no_ipv6_nht_default_route_cmd); - install_element(VIEW_NODE, &show_ipv6_route_cmd); install_element(VIEW_NODE, &show_ipv6_route_summary_cmd); install_element(VIEW_NODE, &show_ipv6_route_summary_prefix_cmd); install_element(VIEW_NODE, &show_ipv6_route_addr_cmd); From a3e13ef37f188386c2bda3e311f98b52ef651764 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 13 Sep 2017 15:25:39 -0300 Subject: [PATCH 2/4] zebra: 'show ip route' with multiple options at the same time Now it's possible to specify multiple options when viewing the RIB or FIB. Example: 'show ip route 192.168.0.0/16 longer-prefixes tag 10 ospf' Signed-off-by: Renato Westphal --- zebra/zebra_vty.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index dbfb491db1..889cdcfa99 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -1202,19 +1202,21 @@ DEFPY (show_route, "show\ <\ ip$ipv4 [vrf ]\ - [\ + [{\ tag (1-4294967295)\ |A.B.C.D/M$prefix longer-prefixes\ |supernets-only$supernets_only\ - |" FRR_IP_REDIST_STR_ZEBRA "$type_str\ + }]\ + [<\ + " FRR_IP_REDIST_STR_ZEBRA "$type_str\ |ospf$type_str (1-65535)$ospf_instance_id\ - ]\ + >]\ |ipv6$ipv6 [vrf ]\ - [\ + [{\ tag (1-4294967295)\ |X:X::X:X/M$prefix longer-prefixes\ - |" FRR_IP6_REDIST_STR_ZEBRA "$type_str\ - ]\ + }]\ + [" FRR_IP6_REDIST_STR_ZEBRA "$type_str]\ >\ [json$json]", SHOW_STR From ce0ff16bd900edb89d8b066d5d42b3486fe04313 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 13 Sep 2017 17:45:16 -0300 Subject: [PATCH 3/4] zebra: fix route node leak on error path Signed-off-by: Renato Westphal --- zebra/zebra_vty.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 889cdcfa99..95c35e62ea 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -1360,6 +1360,8 @@ DEFUN (show_ip_route_prefix, rn = route_node_match(table, (struct prefix *)&p); if (!rn || rn->p.prefixlen != p.prefixlen) { + if (rn) + route_unlock_node(rn); vty_out(vty, "%% Network not in table\n"); return CMD_WARNING; } @@ -1947,6 +1949,8 @@ DEFUN (show_ipv6_route_prefix, rn = route_node_match(table, (struct prefix *)&p); if (!rn || rn->p.prefixlen != p.prefixlen) { + if (rn) + route_unlock_node(rn); vty_out(vty, "%% Network not in table\n"); return CMD_WARNING; } From 5ce91022c1eecb07273b6e30a1df7c55ece4894d Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 13 Sep 2017 17:40:19 -0300 Subject: [PATCH 4/4] zebra: unify the ipv4/ipv6 'show ip route' commands - part 2/2 Signed-off-by: Renato Westphal --- zebra/zebra_vty.c | 668 +++++++++------------------------------------- 1 file changed, 133 insertions(+), 535 deletions(-) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 95c35e62ea..008afdfa4f 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -55,6 +55,10 @@ static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, u_short ospf_instance_id); static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, int mcast); +static void vty_show_ip_route_summary(struct vty *vty, + struct route_table *table); +static void vty_show_ip_route_summary_prefix(struct vty *vty, + struct route_table *table); /* VNI range as per RFC 7432 */ #define CMD_VNI_RANGE "(1-16777215)" @@ -1283,96 +1287,151 @@ DEFPY (show_route, return CMD_SUCCESS; } -DEFUN (show_ip_route_addr, - show_ip_route_addr_cmd, - "show ip route [vrf NAME] A.B.C.D", +DEFPY (show_route_detail, + show_route_detail_cmd, + "show\ + <\ + ip$ipv4 route [vrf ]\ + <\ + A.B.C.D$address\ + |A.B.C.D/M$prefix\ + >\ + |ipv6$ipv6 route [vrf ]\ + <\ + X:X::X:X$address\ + |X:X::X:X/M$prefix\ + >\ + >", SHOW_STR IP_STR "IP routing table\n" - VRF_CMD_HELP_STR - "Network in the IP routing table to display\n") -{ - int ret; - struct prefix_ipv4 p; - struct route_table *table; - struct route_node *rn; - vrf_id_t vrf_id = VRF_DEFAULT; - - if (strmatch(argv[3]->text, "vrf")) { - VRF_GET_ID(vrf_id, argv[4]->arg); - ret = str2prefix_ipv4(argv[5]->arg, &p); - } else { - ret = str2prefix_ipv4(argv[3]->arg, &p); - } - - if (ret <= 0) { - vty_out(vty, "%% Malformed IPv4 address\n"); - return CMD_WARNING; - } - - table = zebra_vrf_table(AFI_IP, SAFI_UNICAST, vrf_id); - if (!table) - return CMD_SUCCESS; - - rn = route_node_match(table, (struct prefix *)&p); - if (!rn) { - vty_out(vty, "%% Network not in table\n"); - return CMD_WARNING; - } - - vty_show_ip_route_detail(vty, rn, 0); - - route_unlock_node(rn); - - return CMD_SUCCESS; -} - -DEFUN (show_ip_route_prefix, - show_ip_route_prefix_cmd, - "show ip route [vrf NAME] A.B.C.D/M", - SHOW_STR - IP_STR + VRF_FULL_CMD_HELP_STR + "Network in the IP routing table to display\n" + "IP prefix /, e.g., 35.0.0.0/8\n" + IP6_STR "IP routing table\n" - VRF_CMD_HELP_STR - "IP prefix /, e.g., 35.0.0.0/8\n") + VRF_FULL_CMD_HELP_STR + "IPv6 Address\n" + "IPv6 prefix\n") { - int ret; - struct prefix_ipv4 p; + afi_t afi = ipv4 ? AFI_IP : AFI_IP6; struct route_table *table; + struct prefix p; struct route_node *rn; - vrf_id_t vrf_id = VRF_DEFAULT; - if (strmatch(argv[3]->text, "vrf")) { - VRF_GET_ID(vrf_id, argv[4]->arg); - ret = str2prefix_ipv4(argv[5]->arg, &p); - } else { - ret = str2prefix_ipv4(argv[3]->arg, &p); - } - - if (ret <= 0) { - vty_out(vty, "%% Malformed IPv4 address\n"); + if (address_str) + prefix_str = address_str; + if (str2prefix(prefix_str, &p) < 0) { + vty_out(vty, "%% Malformed address\n"); return CMD_WARNING; } - table = zebra_vrf_table(AFI_IP, SAFI_UNICAST, vrf_id); - if (!table) - return CMD_SUCCESS; + if (vrf_all) { + struct vrf *vrf; + struct zebra_vrf *zvrf; + + RB_FOREACH(vrf, vrf_name_head, &vrfs_by_name) { + if ((zvrf = vrf->info) == NULL + || (table = zvrf->table[afi][SAFI_UNICAST]) == NULL) + continue; + + rn = route_node_match(table, &p); + if (!rn) + continue; + if (!address_str && rn->p.prefixlen != p.prefixlen) { + route_unlock_node(rn); + continue; + } + + vty_show_ip_route_detail(vty, rn, 0); - rn = route_node_match(table, (struct prefix *)&p); - if (!rn || rn->p.prefixlen != p.prefixlen) { - if (rn) route_unlock_node(rn); - vty_out(vty, "%% Network not in table\n"); - return CMD_WARNING; + } + } else { + vrf_id_t vrf_id = VRF_DEFAULT; + + if (vrf_name) + VRF_GET_ID(vrf_id, vrf_name); + + table = zebra_vrf_table(afi, SAFI_UNICAST, vrf_id); + if (!table) + return CMD_SUCCESS; + + rn = route_node_match(table, &p); + if (!rn) { + vty_out(vty, "%% Network not in table\n"); + return CMD_WARNING; + } + if (!address_str && rn->p.prefixlen != p.prefixlen) { + vty_out(vty, "%% Network not in table\n"); + route_unlock_node(rn); + return CMD_WARNING; + } + + vty_show_ip_route_detail(vty, rn, 0); + + route_unlock_node(rn); } - vty_show_ip_route_detail(vty, rn, 0); - - route_unlock_node(rn); - return CMD_SUCCESS; } +DEFPY (show_route_summary, + show_route_summary_cmd, + "show\ + <\ + ip$ipv4 route [vrf ]\ + summary [prefix$prefix]\ + |ipv6$ipv6 route [vrf ]\ + summary [prefix$prefix]\ + >", + SHOW_STR + IP_STR + "IP routing table\n" + VRF_FULL_CMD_HELP_STR + "Summary of all routes\n" + "Prefix routes\n" + IP6_STR + "IP routing table\n" + VRF_FULL_CMD_HELP_STR + "Summary of all routes\n" + "Prefix routes\n") +{ + afi_t afi = ipv4 ? AFI_IP : AFI_IP6; + struct route_table *table; + + if (vrf_all) { + struct vrf *vrf; + struct zebra_vrf *zvrf; + + RB_FOREACH(vrf, vrf_name_head, &vrfs_by_name) { + if ((zvrf = vrf->info) == NULL + || (table = zvrf->table[afi][SAFI_UNICAST]) == NULL) + continue; + + if (prefix) + vty_show_ip_route_summary_prefix(vty, table); + else + vty_show_ip_route_summary(vty, table); + } + } else { + vrf_id_t vrf_id = VRF_DEFAULT; + + if (vrf_name) + VRF_GET_ID(vrf_id, vrf_name); + + table = zebra_vrf_table(afi, SAFI_UNICAST, vrf_id); + if (!table) + return CMD_SUCCESS; + + if (prefix) + vty_show_ip_route_summary_prefix(vty, table); + else + vty_show_ip_route_summary(vty, table); + } + + return CMD_SUCCESS; +} static void vty_show_ip_route_summary(struct vty *vty, struct route_table *table) @@ -1512,183 +1571,6 @@ static void vty_show_ip_route_summary_prefix(struct vty *vty, vty_out(vty, "\n"); } -/* Show route summary. */ -DEFUN (show_ip_route_summary, - show_ip_route_summary_cmd, - "show ip route [vrf NAME] summary", - SHOW_STR - IP_STR - "IP routing table\n" - VRF_CMD_HELP_STR - "Summary of all routes\n") -{ - struct route_table *table; - vrf_id_t vrf_id = VRF_DEFAULT; - - if (strmatch(argv[3]->text, "vrf")) - VRF_GET_ID(vrf_id, argv[4]->arg); - - table = zebra_vrf_table(AFI_IP, SAFI_UNICAST, vrf_id); - if (!table) - return CMD_SUCCESS; - - vty_show_ip_route_summary(vty, table); - - return CMD_SUCCESS; -} - -/* Show route summary prefix. */ -DEFUN (show_ip_route_summary_prefix, - show_ip_route_summary_prefix_cmd, - "show ip route [vrf NAME] summary prefix", - SHOW_STR - IP_STR - "IP routing table\n" - VRF_CMD_HELP_STR - "Summary of all routes\n" - "Prefix routes\n") -{ - struct route_table *table; - vrf_id_t vrf_id = VRF_DEFAULT; - - if (strmatch(argv[3]->text, "vrf")) - VRF_GET_ID(vrf_id, argv[4]->arg); - - table = zebra_vrf_table(AFI_IP, SAFI_UNICAST, vrf_id); - if (!table) - return CMD_SUCCESS; - - vty_show_ip_route_summary_prefix(vty, table); - - return CMD_SUCCESS; -} - - -DEFUN (show_ip_route_vrf_all_addr, - show_ip_route_vrf_all_addr_cmd, - "show ip route vrf all A.B.C.D", - SHOW_STR - IP_STR - "IP routing table\n" - VRF_ALL_CMD_HELP_STR - "Network in the IP routing table to display\n") -{ - int idx_ipv4 = 5; - int ret; - struct prefix_ipv4 p; - struct route_table *table; - struct route_node *rn; - struct vrf *vrf; - struct zebra_vrf *zvrf; - - ret = str2prefix_ipv4(argv[idx_ipv4]->arg, &p); - if (ret <= 0) { - vty_out(vty, "%% Malformed IPv4 address\n"); - return CMD_WARNING; - } - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if ((zvrf = vrf->info) == NULL - || (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL) - continue; - - rn = route_node_match(table, (struct prefix *)&p); - if (!rn) - continue; - - vty_show_ip_route_detail(vty, rn, 0); - - route_unlock_node(rn); - } - - return CMD_SUCCESS; -} - -DEFUN (show_ip_route_vrf_all_prefix, - show_ip_route_vrf_all_prefix_cmd, - "show ip route vrf all A.B.C.D/M", - SHOW_STR - IP_STR - "IP routing table\n" - VRF_ALL_CMD_HELP_STR - "IP prefix /, e.g., 35.0.0.0/8\n") -{ - int idx_ipv4_prefixlen = 5; - int ret; - struct prefix_ipv4 p; - struct route_table *table; - struct route_node *rn; - struct vrf *vrf; - struct zebra_vrf *zvrf; - - ret = str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); - if (ret <= 0) { - vty_out(vty, "%% Malformed IPv4 address\n"); - return CMD_WARNING; - } - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if ((zvrf = vrf->info) == NULL - || (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL) - continue; - - rn = route_node_match(table, (struct prefix *)&p); - if (!rn) - continue; - if (rn->p.prefixlen != p.prefixlen) { - route_unlock_node(rn); - continue; - } - - vty_show_ip_route_detail(vty, rn, 0); - - route_unlock_node(rn); - } - - return CMD_SUCCESS; -} - -DEFUN (show_ip_route_vrf_all_summary, - show_ip_route_vrf_all_summary_cmd, - "show ip route vrf all summary ", - SHOW_STR - IP_STR - "IP routing table\n" - VRF_ALL_CMD_HELP_STR - "Summary of all routes\n") -{ - struct vrf *vrf; - struct zebra_vrf *zvrf; - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) - if ((zvrf = vrf->info) != NULL) - vty_show_ip_route_summary( - vty, zvrf->table[AFI_IP][SAFI_UNICAST]); - - return CMD_SUCCESS; -} - -DEFUN (show_ip_route_vrf_all_summary_prefix, - show_ip_route_vrf_all_summary_prefix_cmd, - "show ip route vrf all summary prefix", - SHOW_STR - IP_STR - "IP routing table\n" - VRF_ALL_CMD_HELP_STR - "Summary of all routes\n" - "Prefix routes\n") -{ - struct vrf *vrf; - struct zebra_vrf *zvrf; - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) - if ((zvrf = vrf->info) != NULL) - vty_show_ip_route_summary_prefix( - vty, zvrf->table[AFI_IP][SAFI_UNICAST]); - - return CMD_SUCCESS; -} - /* Write static route configuration. */ static int static_config(struct vty *vty, afi_t afi, safi_t safi, const char *cmd) @@ -1873,149 +1755,6 @@ DEFPY(ipv6_route, tag_str, distance_str, vrf, label); } -DEFUN (show_ipv6_route_addr, - show_ipv6_route_addr_cmd, - "show ipv6 route [vrf NAME] X:X::X:X", - SHOW_STR - IP_STR - "IPv6 routing table\n" - VRF_CMD_HELP_STR - "IPv6 Address\n") -{ - int ret; - struct prefix_ipv6 p; - struct route_table *table; - struct route_node *rn; - vrf_id_t vrf_id = VRF_DEFAULT; - - if (strmatch(argv[3]->text, "vrf")) { - VRF_GET_ID(vrf_id, argv[4]->arg); - ret = str2prefix_ipv6(argv[5]->arg, &p); - } else { - ret = str2prefix_ipv6(argv[3]->arg, &p); - } - - if (ret <= 0) { - vty_out(vty, "Malformed IPv6 address\n"); - return CMD_WARNING; - } - - table = zebra_vrf_table(AFI_IP6, SAFI_UNICAST, vrf_id); - if (!table) - return CMD_SUCCESS; - - rn = route_node_match(table, (struct prefix *)&p); - if (!rn) { - vty_out(vty, "%% Network not in table\n"); - return CMD_WARNING; - } - - vty_show_ip_route_detail(vty, rn, 0); - - route_unlock_node(rn); - - return CMD_SUCCESS; -} - -DEFUN (show_ipv6_route_prefix, - show_ipv6_route_prefix_cmd, - "show ipv6 route [vrf NAME] X:X::X:X/M", - SHOW_STR - IP_STR - "IPv6 routing table\n" - VRF_CMD_HELP_STR - "IPv6 prefix\n") -{ - int ret; - struct prefix_ipv6 p; - struct route_table *table; - struct route_node *rn; - vrf_id_t vrf_id = VRF_DEFAULT; - - if (strmatch(argv[3]->text, "vrf")) { - VRF_GET_ID(vrf_id, argv[4]->arg); - ret = str2prefix_ipv6(argv[5]->arg, &p); - } else - ret = str2prefix_ipv6(argv[3]->arg, &p); - - if (ret <= 0) { - vty_out(vty, "Malformed IPv6 prefix\n"); - return CMD_WARNING; - } - - table = zebra_vrf_table(AFI_IP6, SAFI_UNICAST, vrf_id); - if (!table) - return CMD_SUCCESS; - - rn = route_node_match(table, (struct prefix *)&p); - if (!rn || rn->p.prefixlen != p.prefixlen) { - if (rn) - route_unlock_node(rn); - vty_out(vty, "%% Network not in table\n"); - return CMD_WARNING; - } - - vty_show_ip_route_detail(vty, rn, 0); - - route_unlock_node(rn); - - return CMD_SUCCESS; -} - - -/* Show route summary. */ -DEFUN (show_ipv6_route_summary, - show_ipv6_route_summary_cmd, - "show ipv6 route [vrf NAME] summary", - SHOW_STR - IP_STR - "IPv6 routing table\n" - VRF_CMD_HELP_STR - "Summary of all IPv6 routes\n") -{ - struct route_table *table; - vrf_id_t vrf_id = VRF_DEFAULT; - - if (strmatch(argv[3]->text, "vrf")) - VRF_GET_ID(vrf_id, argv[4]->arg); - - table = zebra_vrf_table(AFI_IP6, SAFI_UNICAST, vrf_id); - if (!table) - return CMD_SUCCESS; - - vty_show_ip_route_summary(vty, table); - - return CMD_SUCCESS; -} - - -/* Show ipv6 route summary prefix. */ -DEFUN (show_ipv6_route_summary_prefix, - show_ipv6_route_summary_prefix_cmd, - "show ipv6 route [vrf NAME] summary prefix", - SHOW_STR - IP_STR - "IPv6 routing table\n" - VRF_CMD_HELP_STR - "Summary of all IPv6 routes\n" - "Prefix routes\n") -{ - struct route_table *table; - vrf_id_t vrf_id = VRF_DEFAULT; - - if (strmatch(argv[3]->text, "vrf")) - VRF_GET_ID(vrf_id, argv[4]->arg); - - table = zebra_vrf_table(AFI_IP6, SAFI_UNICAST, vrf_id); - if (!table) - return CMD_SUCCESS; - - vty_show_ip_route_summary_prefix(vty, table); - - return CMD_SUCCESS; -} - - /* * Show IPv6 mroute command.Used to dump * the Multicast routing table. @@ -2053,110 +1792,6 @@ DEFUN (show_ipv6_mroute, return CMD_SUCCESS; } -DEFUN (show_ipv6_route_vrf_all_addr, - show_ipv6_route_vrf_all_addr_cmd, - "show ipv6 route vrf all X:X::X:X", - SHOW_STR - IP_STR - "IPv6 routing table\n" - VRF_ALL_CMD_HELP_STR - "IPv6 Address\n") -{ - int idx_ipv6 = 5; - int ret; - struct prefix_ipv6 p; - struct route_table *table; - struct route_node *rn; - struct vrf *vrf; - struct zebra_vrf *zvrf; - - ret = str2prefix_ipv6(argv[idx_ipv6]->arg, &p); - if (ret <= 0) { - vty_out(vty, "Malformed IPv6 address\n"); - return CMD_WARNING; - } - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if ((zvrf = vrf->info) == NULL - || (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL) - continue; - - rn = route_node_match(table, (struct prefix *)&p); - if (!rn) - continue; - - vty_show_ip_route_detail(vty, rn, 0); - - route_unlock_node(rn); - } - - return CMD_SUCCESS; -} - -DEFUN (show_ipv6_route_vrf_all_prefix, - show_ipv6_route_vrf_all_prefix_cmd, - "show ipv6 route vrf all X:X::X:X/M", - SHOW_STR - IP_STR - "IPv6 routing table\n" - VRF_ALL_CMD_HELP_STR - "IPv6 prefix\n") -{ - int idx_ipv6_prefixlen = 5; - int ret; - struct prefix_ipv6 p; - struct route_table *table; - struct route_node *rn; - struct vrf *vrf; - struct zebra_vrf *zvrf; - - ret = str2prefix_ipv6(argv[idx_ipv6_prefixlen]->arg, &p); - if (ret <= 0) { - vty_out(vty, "Malformed IPv6 prefix\n"); - return CMD_WARNING; - } - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if ((zvrf = vrf->info) == NULL - || (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL) - continue; - - rn = route_node_match(table, (struct prefix *)&p); - if (!rn) - continue; - if (rn->p.prefixlen != p.prefixlen) { - route_unlock_node(rn); - continue; - } - - vty_show_ip_route_detail(vty, rn, 0); - - route_unlock_node(rn); - } - - return CMD_SUCCESS; -} - -DEFUN (show_ipv6_route_vrf_all_summary, - show_ipv6_route_vrf_all_summary_cmd, - "show ipv6 route vrf all summary", - SHOW_STR - IP_STR - "IPv6 routing table\n" - VRF_ALL_CMD_HELP_STR - "Summary of all IPv6 routes\n") -{ - struct vrf *vrf; - struct zebra_vrf *zvrf; - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) - if ((zvrf = vrf->info) != NULL) - vty_show_ip_route_summary( - vty, zvrf->table[AFI_IP6][SAFI_UNICAST]); - - return CMD_SUCCESS; -} - DEFUN (show_ipv6_mroute_vrf_all, show_ipv6_mroute_vrf_all_cmd, "show ipv6 mroute vrf all", @@ -2190,27 +1825,6 @@ DEFUN (show_ipv6_mroute_vrf_all, return CMD_SUCCESS; } -DEFUN (show_ipv6_route_vrf_all_summary_prefix, - show_ipv6_route_vrf_all_summary_prefix_cmd, - "show ipv6 route vrf all summary prefix", - SHOW_STR - IP_STR - "IPv6 routing table\n" - VRF_ALL_CMD_HELP_STR - "Summary of all IPv6 routes\n" - "Prefix routes\n") -{ - struct vrf *vrf; - struct zebra_vrf *zvrf; - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) - if ((zvrf = vrf->info) != NULL) - vty_show_ip_route_summary_prefix( - vty, zvrf->table[AFI_IP6][SAFI_UNICAST]); - - return CMD_SUCCESS; -} - DEFUN (allow_external_route_update, allow_external_route_update_cmd, "allow-external-route-update", @@ -2661,23 +2275,16 @@ void zebra_vty_init(void) install_element(VIEW_NODE, &show_vrf_cmd); install_element(VIEW_NODE, &show_route_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); 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_route_addr_cmd); - install_element(VIEW_NODE, &show_ip_route_prefix_cmd); - install_element(VIEW_NODE, &show_ip_route_summary_cmd); - install_element(VIEW_NODE, &show_ip_route_summary_prefix_cmd); install_element(VIEW_NODE, &show_ip_rpf_cmd); install_element(VIEW_NODE, &show_ip_rpf_addr_cmd); - install_element(VIEW_NODE, &show_ip_route_vrf_all_addr_cmd); - install_element(VIEW_NODE, &show_ip_route_vrf_all_prefix_cmd); - install_element(VIEW_NODE, &show_ip_route_vrf_all_summary_cmd); - install_element(VIEW_NODE, &show_ip_route_vrf_all_summary_prefix_cmd); - install_element(CONFIG_NODE, &ipv6_route_blackhole_cmd); install_element(CONFIG_NODE, &ipv6_route_address_interface_cmd); install_element(CONFIG_NODE, &ipv6_route_cmd); @@ -2685,18 +2292,9 @@ void zebra_vty_init(void) install_element(CONFIG_NODE, &no_ip_nht_default_route_cmd); install_element(CONFIG_NODE, &ipv6_nht_default_route_cmd); install_element(CONFIG_NODE, &no_ipv6_nht_default_route_cmd); - install_element(VIEW_NODE, &show_ipv6_route_summary_cmd); - install_element(VIEW_NODE, &show_ipv6_route_summary_prefix_cmd); - install_element(VIEW_NODE, &show_ipv6_route_addr_cmd); - install_element(VIEW_NODE, &show_ipv6_route_prefix_cmd); install_element(VIEW_NODE, &show_ipv6_mroute_cmd); /* Commands for VRF */ - install_element(VIEW_NODE, &show_ipv6_route_vrf_all_summary_cmd); - install_element(VIEW_NODE, &show_ipv6_route_vrf_all_summary_prefix_cmd); - install_element(VIEW_NODE, &show_ipv6_route_vrf_all_addr_cmd); - install_element(VIEW_NODE, &show_ipv6_route_vrf_all_prefix_cmd); - install_element(VIEW_NODE, &show_ipv6_mroute_vrf_all_cmd); install_element(VIEW_NODE, &show_evpn_vni_cmd);