diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index ae0f0ab1dc..6575189ab1 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -566,6 +566,7 @@ DEFUN (no_vpnv6_network, return bgp_static_unset_safi (SAFI_MPLS_VPN, vty, argv[idx_ipv6_prefix]->arg, argv[idx_ext_community]->arg, argv[idx_word]->arg); } +#if defined(KEEP_OLD_VPN_COMMANDS) static int show_adj_route_vpn (struct vty *vty, struct peer *peer, struct prefix_rd *prd, u_char use_json, afi_t afi) { @@ -732,6 +733,7 @@ show_adj_route_vpn (struct vty *vty, struct peer *peer, struct prefix_rd *prd, u } return CMD_SUCCESS; } +#endif enum bgp_show_type { diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 0a9747b526..0cf96101c2 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -492,7 +492,7 @@ bgp_show_all_instances_nexthops_vty (struct vty *vty) DEFUN (show_ip_bgp_nexthop, show_ip_bgp_nexthop_cmd, - "show [ip] bgp [ VRFNAME] nexthop [detail]", + "show [ip] bgp [ WORD] nexthop [detail]", SHOW_STR IP_STR BGP_STR @@ -501,7 +501,7 @@ DEFUN (show_ip_bgp_nexthop, "Show detailed information\n") { int idx = 0; - char *vrf = argv_find (argv, argc, "VRFNAME", &idx) ? argv[idx]->arg : NULL; + char *vrf = argv_find (argv, argc, "WORD", &idx) ? argv[idx]->arg : NULL; int detail = argv_find (argv, argc, "detail", &idx) ? 1 : 0; return show_ip_bgp_nexthop_table (vty, vrf, detail); } diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 84759ca04f..ca96bae020 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -7245,30 +7245,30 @@ enum bgp_show_type }; static int -bgp_show_prefix_list (struct vty *vty, const char *name, +bgp_show_prefix_list (struct vty *vty, struct bgp *bgp, const char *prefix_list_str, afi_t afi, safi_t safi, enum bgp_show_type type); static int -bgp_show_filter_list (struct vty *vty, const char *name, +bgp_show_filter_list (struct vty *vty, struct bgp *bgp, const char *filter, afi_t afi, safi_t safi, enum bgp_show_type type); static int -bgp_show_route_map (struct vty *vty, const char *name, +bgp_show_route_map (struct vty *vty, struct bgp *bgp, const char *rmap_str, afi_t afi, safi_t safi, enum bgp_show_type type); static int -bgp_show_community_list (struct vty *vty, const char *name, +bgp_show_community_list (struct vty *vty, struct bgp *bgp, const char *com, int exact, afi_t afi, safi_t safi); static int -bgp_show_prefix_longer (struct vty *vty, const char *name, +bgp_show_prefix_longer (struct vty *vty, struct bgp *bgp, const char *prefix, afi_t afi, safi_t safi, enum bgp_show_type type); static int bgp_show_regexp (struct vty *vty, const char *regstr, afi_t afi, safi_t safi, enum bgp_show_type type); static int -bgp_show_community (struct vty *vty, const char *view_name, int argc, +bgp_show_community (struct vty *vty, struct bgp *bgp, int argc, struct cmd_token **argv, int exact, afi_t afi, safi_t safi); static int @@ -7832,33 +7832,11 @@ bgp_show_route_in_table (struct vty *vty, struct bgp *bgp, /* Display specified route of Main RIB */ static int -bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str, +bgp_show_route (struct vty *vty, struct bgp *bgp, const char *ip_str, afi_t afi, safi_t safi, struct prefix_rd *prd, int prefix_check, enum bgp_path_type pathtype, u_char use_json) { - struct bgp *bgp; - - /* BGP structure lookup. */ - if (view_name) - { - bgp = bgp_lookup_by_name (view_name); - if (bgp == NULL) - { - vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE); - return CMD_WARNING; - } - } - else - { - bgp = bgp_get_default (); - if (bgp == NULL) - { - vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); - return CMD_WARNING; - } - } - return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str, afi, safi, prd, prefix_check, pathtype, use_json); @@ -8016,9 +7994,11 @@ DEFUN (show_ip_bgp_large_community, return bgp_show (vty, bgp, afi, safi, bgp_show_type_lcommunity_all, NULL, uj); } +static int bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi); + /* BGP route print out function. */ -DEFUN (show_ip_bgp_ipv4, - show_ip_bgp_ipv4_cmd, +DEFUN (show_ip_bgp, + show_ip_bgp_cmd, "show [ip] bgp [ WORD] [ []]\ [<\ cidr-only\ @@ -8026,6 +8006,7 @@ DEFUN (show_ip_bgp_ipv4, |route-map WORD\ |prefix-list WORD\ |filter-list WORD\ + |statistics\ |community [ [exact-match]]\ |community-list <(1-500)|WORD> [exact-match]\ |A.B.C.D/M longer-prefixes\ @@ -8045,13 +8026,14 @@ DEFUN (show_ip_bgp_ipv4, "Display detailed information about dampening\n" "Display flap statistics of routes\n" "Display paths suppressed due to dampening\n" - "Display dampening parameters\n" + "Display detail of configured dampening parameters\n" "Display routes matching the route-map\n" "A route-map to match on\n" "Display routes conforming to the prefix-list\n" "Prefix-list name\n" "Display routes conforming to the filter-list\n" "Regular expression access list name\n" + "BGP RIB advertisement statistics\n" "Display routes matching the communities\n" COMMUNITY_AANN_STR "Do not send outside local AS (well-known community)\n" @@ -8068,93 +8050,78 @@ DEFUN (show_ip_bgp_ipv4, "Display route and more specific routes\n" JSON_STR) { - char *vrf = NULL; + vrf_id_t vrf = VRF_DEFAULT; afi_t afi = AFI_IP6; safi_t safi = SAFI_UNICAST; int exact_match = 0; enum bgp_show_type sh_type = bgp_show_type_normal; - + struct bgp *bgp = NULL; int idx = 0; - if (argv_find (argv, argc, "ip", &idx)) - afi = AFI_IP; - if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx)) - vrf = argv[++idx]->arg; - if (argv_find (argv, argc, "ipv4", &idx) || argv_find (argv, argc, "ipv6", &idx)) - { - afi = strmatch(argv[idx]->text, "ipv6") ? AFI_IP6 : AFI_IP; - if (argv_find (argv, argc, "unicast", &idx) || argv_find (argv, argc, "multicast", &idx)) - safi = bgp_vty_safi_from_arg (argv[idx]->text); - } - else if (argv_find (argv, argc, "encap", &idx) || argv_find (argv, argc, "vpnv4", &idx)) - { - afi = AFI_IP; - safi = strmatch (argv[idx]->text, "encap") ? SAFI_ENCAP : SAFI_MPLS_VPN; - // advance idx if necessary - argv_find (argv, argc, "unicast", &idx); - } + bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf); + if (!idx) + return CMD_WARNING; int uj = use_json (argc, argv); if (uj) argc--; - struct bgp *bgp = bgp_lookup_by_name (vrf); + bgp = bgp_lookup_by_vrf_id (vrf); if (bgp == NULL) - { - vty_out (vty, "Can't find BGP instance %s%s", vrf, VTY_NEWLINE); - return CMD_WARNING; - } + { + vty_out (vty, "Can't find BGP instance %s%s", argv[5]->arg, VTY_NEWLINE); + return CMD_WARNING; + } - if (++idx < argc) - { - if (strmatch(argv[idx]->text, "cidr-only")) - return bgp_show (vty, bgp, afi, safi, bgp_show_type_cidr_only, NULL, uj); + if (argv_find(argv, argc, "cidr-only", &idx)) + return bgp_show (vty, bgp, afi, safi, bgp_show_type_cidr_only, NULL, uj); - else if (strmatch(argv[idx]->text, "dampening")) + if (argv_find(argv, argc, "dampening", &idx)) { if (argv_find (argv, argc, "dampened-paths", &idx)) return bgp_show (vty, bgp, afi, safi, bgp_show_type_dampend_paths, NULL, uj); else if (argv_find (argv, argc, "flap-statistics", &idx)) return bgp_show (vty, bgp, afi, safi, bgp_show_type_flap_statistics, NULL, uj); else if (argv_find (argv, argc, "parameters", &idx)) - return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST); + return bgp_show_dampening_parameters (vty, afi, safi); } - else if (strmatch(argv[idx]->text, "prefix-list")) - return bgp_show_prefix_list (vty, vrf, argv[idx + 1]->arg, afi, safi, bgp_show_type_prefix_list); + if (argv_find(argv, argc, "prefix-list", &idx)) + return bgp_show_prefix_list (vty, bgp, argv[idx + 1]->arg, afi, safi, bgp_show_type_prefix_list); - else if (strmatch(argv[idx]->text, "filter-list")) - return bgp_show_filter_list (vty, vrf, argv[idx + 1]->arg, afi, safi, bgp_show_type_filter_list); + if (argv_find(argv, argc, "filter-list", &idx)) + return bgp_show_filter_list (vty, bgp, argv[idx + 1]->arg, afi, safi, bgp_show_type_filter_list); - else if (strmatch(argv[idx]->text, "route-map")) - return bgp_show_route_map (vty, vrf, argv[idx + 1]->arg, afi, safi, bgp_show_type_route_map); + if (argv_find(argv, argc, "statistics", &idx)) + return bgp_table_stats (vty, bgp, afi, safi); - else if (strmatch(argv[idx]->text, "community")) + if (argv_find(argv, argc, "route-map", &idx)) + return bgp_show_route_map (vty, bgp, argv[idx + 1]->arg, afi, safi, bgp_show_type_route_map); + + if (argv_find(argv, argc, "community", &idx)) { /* show a specific community */ - if (argv[idx + 1]->type == VARIABLE_TKN || - strmatch(argv[idx + 1]->text, "local-AS") || - strmatch(argv[idx + 1]->text, "no-advertise") || - strmatch(argv[idx + 1]->text, "no-export")) + if (argv_find (argv, argc, "local-AS", &idx) || + argv_find (argv, argc, "no-advertise", &idx) || + argv_find (argv, argc, "no-export", &idx)) { - if (strmatch(argv[idx + 2]->text, "exact_match")) + if (argv_find (argv, argc, "exact_match", &idx)) exact_match = 1; - return bgp_show_community (vty, vrf, argc, argv, exact_match, afi, safi); + return bgp_show_community (vty, bgp, argc, argv, exact_match, afi, safi); } /* show all communities */ else return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, uj); } - else if (strmatch(argv[idx]->text, "community-list")) - { - const char *clist_number_or_name = argv[++idx]->arg; - if (++idx < argc && strmatch (argv[idx]->arg, "exact-match")) - exact_match = 1; - return bgp_show_community_list (vty, vrf, clist_number_or_name, exact_match, afi, safi); - } - /* prefix-longer */ - else if (argv[idx]->type == IPV4_TKN || argv[idx]->type == IPV6_TKN) - return bgp_show_prefix_longer (vty, vrf, argv[idx + 1]->arg, afi, safi, bgp_show_type_prefix_longer); - } + if (argv_find(argv, argc, "community-list", &idx)) + { + const char *clist_number_or_name = argv[++idx]->arg; + if (++idx < argc && strmatch (argv[idx]->text, "exact-match")) + exact_match = 1; + return bgp_show_community_list (vty, bgp, clist_number_or_name, exact_match, afi, safi); + } + /* prefix-longer */ + if (argv_find(argv, argc, "A.B.C.D/M", &idx) || argv_find(argv, argc, "X:X::X:X/M", &idx)) + return bgp_show_prefix_longer (vty, bgp, argv[idx + 1]->arg, afi, safi, bgp_show_type_prefix_longer); return bgp_show (vty, bgp, afi, safi, sh_type, NULL, uj); } @@ -8185,34 +8152,32 @@ DEFUN (show_ip_bgp_route, afi_t afi = AFI_IP6; safi_t safi = SAFI_UNICAST; - char *vrf = NULL; + vrf_id_t vrf = VRF_DEFAULT;; char *prefix = NULL; - + struct bgp *bgp = NULL; enum bgp_path_type path_type; u_char uj = use_json(argc, argv); int idx = 0; - /* show [ip] bgp */ - if (argv_find (argv, argc, "ip", &idx)) - afi = AFI_IP; - /* [ WORD] */ - if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx)) - vrf = argv[++idx]->arg; - /* []|ipv6 []|encap [unicast]|vpnv4 [unicast]>] */ - if (argv_find (argv, argc, "ipv4", &idx) || argv_find (argv, argc, "ipv6", &idx)) - { - afi = strmatch(argv[idx]->text, "ipv6") ? AFI_IP6 : AFI_IP; - if (argv_find (argv, argc, "unicast", &idx) || argv_find (argv, argc, "multicast", &idx)) - safi = strmatch (argv[idx]->text, "unicast") ? SAFI_UNICAST : SAFI_MULTICAST; - } - else if (argv_find (argv, argc, "encap", &idx) || argv_find (argv, argc, "vpnv4", &idx)) - { - afi = AFI_IP; - safi = strmatch (argv[idx]->text, "encap") ? SAFI_ENCAP : SAFI_MPLS_VPN; - // advance idx if necessary - argv_find (argv, argc, "unicast", &idx); - } + bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf); + if (!idx) + return CMD_WARNING; + + if (vrf != VRF_ALL) + { + bgp = bgp_lookup_by_vrf_id (vrf); + if (bgp == NULL) + { + vty_out (vty, "Can't find BGP instance %s%s", argv[5]->arg, VTY_NEWLINE); + return CMD_WARNING; + } + } + else + { + vty_out (vty, "Specified 'all' vrf's but this command currently only works per view/vrf%s", VTY_NEWLINE); + return CMD_WARNING; + } /* */ if (argv_find (argv, argc, "A.B.C.D", &idx) || argv_find (argv, argc, "X:X::X:X", &idx)) @@ -8241,51 +8206,33 @@ DEFUN (show_ip_bgp_route, else path_type = BGP_PATH_ALL; - return bgp_show_route (vty, vrf, prefix, afi, safi, NULL, prefix_check, path_type, uj); + return bgp_show_route (vty, bgp, prefix, afi, safi, NULL, prefix_check, path_type, uj); } DEFUN (show_ip_bgp_regexp, show_ip_bgp_regexp_cmd, - "show [ip] bgp []|ipv6 []|encap [unicast]|vpnv4 [unicast]>] regexp REGEX...", + "show [ip] bgp [ WORD] [ []] regexp REGEX...", SHOW_STR IP_STR BGP_STR + BGP_INSTANCE_HELP_STR + "Address Family\n" "Address Family\n" "Address Family modifier\n" "Address Family modifier\n" "Address Family modifier\n" "Address Family modifier\n" - "Address Family\n" - "Address Family modifier\n" - "Address Family modifier\n" - "Address Family modifier\n" - "Address Family modifier\n" - "Address Family\n" - "Address Family modifier\n" - "Address Family\n" - "Address Family modifier\n" "Display routes matching the AS path regular expression\n" "A regular-expression to match the BGP AS paths\n") { + vrf_id_t vrf = VRF_DEFAULT; afi_t afi = AFI_IP6; safi_t safi = SAFI_UNICAST; int idx = 0; - - /* []|ipv6 []|encap [unicast]|vpnv4 [unicast]>] */ - if (argv_find (argv, argc, "ipv4", &idx) || argv_find (argv, argc, "ipv6", &idx)) - { - afi = strmatch(argv[idx]->text, "ipv6") ? AFI_IP6 : AFI_IP; - if (argv_find (argv, argc, "unicast", &idx) || argv_find (argv, argc, "multicast", &idx)) - safi = strmatch (argv[idx]->text, "unicast") ? SAFI_UNICAST : SAFI_MULTICAST; - } - else if (argv_find (argv, argc, "encap", &idx) || argv_find (argv, argc, "vpnv4", &idx)) - { - afi = AFI_IP; - safi = strmatch (argv[idx]->text, "encap") ? SAFI_ENCAP : SAFI_MPLS_VPN; - // advance idx if necessary - argv_find (argv, argc, "unicast", &idx); - } + bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf); + if (!idx) + return CMD_WARNING; // get index of regex argv_find (argv, argc, "regexp", &idx); @@ -8299,53 +8246,35 @@ DEFUN (show_ip_bgp_regexp, DEFUN (show_ip_bgp_instance_all, show_ip_bgp_instance_all_cmd, - "show [ip] bgp all []|ipv6 []|encap [unicast]|vpnv4 [unicast]>] [json]", + "show [ip] bgp all [ []] [json]", SHOW_STR IP_STR BGP_STR BGP_INSTANCE_ALL_HELP_STR "Address Family\n" - "Address Family modifier\n" - "Address Family modifier\n" "Address Family\n" "Address Family modifier\n" "Address Family modifier\n" - "Address Family\n" "Address Family modifier\n" - "Address Family\n" "Address Family modifier\n" JSON_STR) { + vrf_id_t vrf = VRF_DEFAULT; afi_t afi = AFI_IP; safi_t safi = SAFI_UNICAST; int idx = 0; + bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf); + if (!idx) + return CMD_WARNING; - /* show [ip] bgp */ - if (argv_find (argv, argc, "ip", &idx)) - afi = AFI_IP; - /* []|ipv6 []|encap [unicast]|vpnv4 [unicast]>] */ - if (argv_find (argv, argc, "ipv4", &idx) || argv_find (argv, argc, "ipv6", &idx)) - { - afi = strmatch(argv[idx]->text, "ipv6") ? AFI_IP6 : AFI_IP; - if (argv_find (argv, argc, "unicast", &idx) || argv_find (argv, argc, "multicast", &idx)) - safi = strmatch (argv[idx]->text, "unicast") ? SAFI_UNICAST : SAFI_MULTICAST; - } - else if (argv_find (argv, argc, "encap", &idx) || argv_find (argv, argc, "vpnv4", &idx)) - { - afi = AFI_IP; - safi = strmatch (argv[idx]->text, "encap") ? SAFI_ENCAP : SAFI_MPLS_VPN; - // advance idx if necessary - argv_find (argv, argc, "unicast", &idx); - } - - u_char uj = use_json(argc, argv); + int uj = use_json (argc, argv); + if (uj) argc--; bgp_show_all_instances_routes_vty (vty, afi, safi, uj); return CMD_SUCCESS; } - static int bgp_show_regexp (struct vty *vty, const char *regstr, afi_t afi, safi_t safi, enum bgp_show_type type) @@ -8368,18 +8297,11 @@ bgp_show_regexp (struct vty *vty, const char *regstr, afi_t afi, } static int -bgp_show_prefix_list (struct vty *vty, const char *name, +bgp_show_prefix_list (struct vty *vty, struct bgp *bgp, const char *prefix_list_str, afi_t afi, safi_t safi, enum bgp_show_type type) { struct prefix_list *plist; - struct bgp *bgp = NULL; - - if (name && !(bgp = bgp_lookup_by_name(name))) - { - vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE); - return CMD_WARNING; - } plist = prefix_list_lookup (afi, prefix_list_str); if (plist == NULL) @@ -8393,18 +8315,11 @@ bgp_show_prefix_list (struct vty *vty, const char *name, } static int -bgp_show_filter_list (struct vty *vty, const char *name, +bgp_show_filter_list (struct vty *vty, struct bgp *bgp, const char *filter, afi_t afi, safi_t safi, enum bgp_show_type type) { struct as_list *as_list; - struct bgp *bgp = NULL; - - if (name && !(bgp = bgp_lookup_by_name(name))) - { - vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE); - return CMD_WARNING; - } as_list = as_list_lookup (filter); if (as_list == NULL) @@ -8416,53 +8331,12 @@ bgp_show_filter_list (struct vty *vty, const char *name, return bgp_show (vty, bgp, afi, safi, type, as_list, 0); } -DEFUN (show_ip_bgp_dampening_info, - show_ip_bgp_dampening_params_cmd, - "show [ip] bgp dampening parameters", - SHOW_STR - IP_STR - BGP_STR - "Display detailed information about dampening\n" - "Display detail of configured dampening parameters\n") -{ - return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST); -} - - -DEFUN (show_ip_bgp_ipv4_dampening_parameters, - show_ip_bgp_ipv4_dampening_parameters_cmd, - "show [ip] bgp ipv4 dampening parameters", - SHOW_STR - IP_STR - BGP_STR - "Address Family\n" - "Address Family modifier\n" - "Address Family modifier\n" - "Display detailed information about dampening\n" - "Display detail of configured dampening parameters\n") -{ - int idx_safi = 4; - if (strncmp(argv[idx_safi]->arg, "m", 1) == 0) - return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_MULTICAST); - - return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST); -} - static int -bgp_show_route_map (struct vty *vty, const char *name, +bgp_show_route_map (struct vty *vty, struct bgp *bgp, const char *rmap_str, afi_t afi, safi_t safi, enum bgp_show_type type) { struct route_map *rmap; - struct bgp *bgp = NULL; - - if (name && !(bgp = bgp_lookup_by_name(name))) - { - - - vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE); - return CMD_WARNING; - } rmap = route_map_lookup_by_name (rmap_str); if (! rmap) @@ -8476,36 +8350,15 @@ bgp_show_route_map (struct vty *vty, const char *name, } static int -bgp_show_community (struct vty *vty, const char *view_name, int argc, +bgp_show_community (struct vty *vty, struct bgp *bgp, int argc, struct cmd_token **argv, int exact, afi_t afi, safi_t safi) { struct community *com; struct buffer *b; - struct bgp *bgp; int i; char *str; int first = 0; - /* BGP structure lookup */ - if (view_name) - { - bgp = bgp_lookup_by_name (view_name); - if (bgp == NULL) - { - vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE); - return CMD_WARNING; - } - } - else - { - bgp = bgp_get_default (); - if (bgp == NULL) - { - vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); - return CMD_WARNING; - } - } - b = buffer_new (1024); for (i = 0; i < argc; i++) { @@ -8539,18 +8392,11 @@ bgp_show_community (struct vty *vty, const char *view_name, int argc, } static int -bgp_show_community_list (struct vty *vty, const char *name, +bgp_show_community_list (struct vty *vty, struct bgp *bgp, const char *com, int exact, afi_t afi, safi_t safi) { struct community_list *list; - struct bgp *bgp = NULL; - - if (name && !(bgp = bgp_lookup_by_name(name))) - { - vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE); - return CMD_WARNING; - } list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER); if (list == NULL) @@ -8566,19 +8412,12 @@ bgp_show_community_list (struct vty *vty, const char *name, } static int -bgp_show_prefix_longer (struct vty *vty, const char *name, +bgp_show_prefix_longer (struct vty *vty, struct bgp *bgp, const char *prefix, afi_t afi, safi_t safi, enum bgp_show_type type) { int ret; struct prefix *p; - struct bgp *bgp = NULL; - - if (name && !(bgp = bgp_lookup_by_name(name))) - { - vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE); - return CMD_WARNING; - } p = prefix_new(); @@ -8595,52 +8434,13 @@ bgp_show_prefix_longer (struct vty *vty, const char *name, } static struct peer * -peer_lookup_in_view (struct vty *vty, const char *view_name, +peer_lookup_in_view (struct vty *vty, struct bgp *bgp, const char *ip_str, u_char use_json) { int ret; - struct bgp *bgp; struct peer *peer; union sockunion su; - /* BGP structure lookup. */ - if (view_name) - { - bgp = bgp_lookup_by_name (view_name); - if (! bgp) - { - if (use_json) - { - json_object *json_no = NULL; - json_no = json_object_new_object(); - json_object_string_add(json_no, "warning", "Can't find BGP view"); - vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); - json_object_free(json_no); - } - else - vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE); - return NULL; - } - } - else - { - bgp = bgp_get_default (); - if (! bgp) - { - if (use_json) - { - json_object *json_no = NULL; - json_no = json_object_new_object(); - json_object_string_add(json_no, "warning", "No BGP process configured"); - vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); - json_object_free(json_no); - } - else - vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); - return NULL; - } - } - /* Get peer sockunion. */ ret = str2sockunion (ip_str, &su); if (ret < 0) @@ -8936,81 +8736,6 @@ bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi) return CMD_SUCCESS; } -static int -bgp_table_stats_vty (struct vty *vty, const char *name, - const char *afi_str, const char *safi_str) -{ - struct bgp *bgp; - afi_t afi; - safi_t safi; - - if (name) - bgp = bgp_lookup_by_name (name); - else - bgp = bgp_get_default (); - - if (!bgp) - { - vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE); - return CMD_WARNING; - } - afi = bgp_vty_afi_from_arg(afi_str); - if (afi == AFI_MAX) - { - vty_out (vty, "%% Invalid address family \"%s\"%s", - afi_str, VTY_NEWLINE); - return CMD_WARNING; - } - safi = bgp_vty_safi_from_arg(safi_str); - if (safi == SAFI_MAX) - { - vty_out (vty, "%% Invalid subsequent address family %s%s", - safi_str, VTY_NEWLINE); - return CMD_WARNING; - } - - return bgp_table_stats (vty, bgp, afi, safi); -} - -DEFUN (show_bgp_statistics, - show_bgp_statistics_cmd, - "show [ip] bgp statistics", - SHOW_STR - IP_STR - BGP_STR - "Address Family\n" - "Address Family\n" - "Address Family modifier\n" - "Address Family modifier\n" - "Address Family modifier\n" - "Address Family modifier\n" - "BGP RIB advertisement statistics\n") -{ - int idx_afi = 2; - int idx_safi = 3; - return bgp_table_stats_vty (vty, NULL, argv[idx_afi]->arg, argv[idx_safi]->arg); -} - -DEFUN (show_bgp_statistics_view, - show_bgp_statistics_view_cmd, - "show [ip] bgp WORD statistics", - SHOW_STR - IP_STR - BGP_STR - BGP_INSTANCE_HELP_STR - "Address Family\n" - "Address Family\n" - "Address Family modifier\n" - "Address Family modifier\n" - "Address Family modifier\n" - "Address Family modifier\n" - "BGP RIB advertisement statistics\n") -{ - int idx_word = 3; - int idx_afi = 4; - return bgp_table_stats_vty (vty, NULL, argv[idx_word]->arg, argv[idx_afi]->arg); -} - enum bgp_pcounts { PCOUNT_ADJ_IN = 0, @@ -9202,117 +8927,20 @@ bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_c return CMD_SUCCESS; } -DEFUN (show_ip_bgp_neighbor_prefix_counts, - show_ip_bgp_neighbor_prefix_counts_cmd, - "show [ip] bgp neighbors prefix-counts [json]", - SHOW_STR - IP_STR - BGP_STR - "Detailed information on TCP and BGP neighbor connections\n" - "Neighbor to display information about\n" - "Neighbor to display information about\n" - "Neighbor on BGP configured interface\n" - "Display detailed prefix count information\n" - JSON_STR) -{ - int idx_peer = 4; - struct peer *peer; - u_char uj = use_json(argc, argv); - - peer = peer_lookup_in_view (vty, NULL, argv[idx_peer]->arg, uj); - if (! peer) - return CMD_WARNING; - - return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj); -} - DEFUN (show_ip_bgp_instance_neighbor_prefix_counts, show_ip_bgp_instance_neighbor_prefix_counts_cmd, - "show [ip] bgp WORD neighbors prefix-counts [json]", - SHOW_STR - IP_STR - BGP_STR - BGP_INSTANCE_HELP_STR - "Detailed information on TCP and BGP neighbor connections\n" - "Neighbor to display information about\n" - "Neighbor to display information about\n" - "Neighbor on BGP configured interface\n" - "Display detailed prefix count information\n" - JSON_STR) -{ - int idx_word = 4; - int idx_peer = 6; - struct peer *peer; - u_char uj = use_json(argc, argv); - - peer = peer_lookup_in_view (vty, argv[idx_word]->arg, argv[idx_peer]->arg, uj); - if (! peer) - return CMD_WARNING; - - return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj); -} - -DEFUN (show_bgp_ipv6_neighbor_prefix_counts, - show_bgp_ipv6_neighbor_prefix_counts_cmd, - "show [ip] bgp ipv6 neighbors prefix-counts [json]", - SHOW_STR - IP_STR - BGP_STR - "Address Family\n" - "Detailed information on TCP and BGP neighbor connections\n" - "Neighbor to display information about\n" - "Neighbor to display information about\n" - "Neighbor on BGP configured interface\n" - "Display detailed prefix count information\n" - JSON_STR) -{ - int idx_peer = 4; - struct peer *peer; - u_char uj = use_json(argc, argv); - - peer = peer_lookup_in_view (vty, NULL, argv[idx_peer]->arg, uj); - if (! peer) - return CMD_WARNING; - - return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj); -} - -DEFUN (show_bgp_instance_ipv6_neighbor_prefix_counts, - show_bgp_instance_ipv6_neighbor_prefix_counts_cmd, - "show [ip] bgp WORD ipv6 neighbors prefix-counts [json]", + "show [ip] bgp [ WORD] [ []] " + "neighbors prefix-counts [json]", SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Address Family\n" - "Detailed information on TCP and BGP neighbor connections\n" - "Neighbor to display information about\n" - "Neighbor to display information about\n" - "Neighbor on BGP configured interface\n" - "Display detailed prefix count information\n" - JSON_STR) -{ - int idx_word = 3; - int idx_peer = 6; - struct peer *peer; - u_char uj = use_json(argc, argv); - - peer = peer_lookup_in_view (vty, argv[idx_word]->arg, argv[idx_peer]->arg, uj); - if (! peer) - return CMD_WARNING; - - return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST, uj); -} - -DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts, - show_ip_bgp_ipv4_neighbor_prefix_counts_cmd, - "show [ip] bgp ipv4 neighbors prefix-counts [json]", - SHOW_STR - IP_STR - BGP_STR "Address Family\n" "Address Family modifier\n" "Address Family modifier\n" + "Address Family modifier\n" + "Address Family modifier\n" "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" "Neighbor to display information about\n" @@ -9320,17 +8948,45 @@ DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts, "Display detailed prefix count information\n" JSON_STR) { - int idx_safi = 4; - int idx_peer = 6; + vrf_id_t vrf = VRF_DEFAULT; + afi_t afi = AFI_IP6; + safi_t safi = SAFI_UNICAST; struct peer *peer; - u_char uj = use_json(argc, argv); + int idx = 0; + struct bgp *bgp = NULL; - peer = peer_lookup_in_view (vty, NULL, argv[idx_peer]->arg, uj); - if (! peer) + bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf); + if (!idx) return CMD_WARNING; - if (strncmp (argv[idx_safi]->arg, "m", 1) == 0) - return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST, uj); + int uj = use_json (argc, argv); + if (uj) argc--; + + if (vrf != VRF_ALL) + { + bgp = bgp_lookup_by_vrf_id (vrf); + if (bgp == NULL) + { + if (uj) + { + json_object *json_no = NULL; + json_no = json_object_new_object(); + json_object_string_add(json_no, "warning", "Can't find BGP view"); + vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); + json_object_free(json_no); + } + else + vty_out (vty, "Can't find BGP instance %s%s", argv[5]->arg, VTY_NEWLINE); + return CMD_WARNING; + } + } + else + bgp = NULL; + + argv_find (argv, argc, "neighbors", &idx); + peer = peer_lookup_in_view (vty, bgp, argv[idx+1]->arg, uj); + if (! peer) + return CMD_WARNING; return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST, uj); } @@ -9376,9 +9032,15 @@ DEFUN (show_ip_bgp_vpn_all_route_prefix, { int idx = 0; char *network = NULL; + struct bgp *bgp = bgp_get_default(); + if (!bgp) + { + vty_out (vty, "Can't find default instance%s", VTY_NEWLINE); + return CMD_WARNING; + } network = argv_find (argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; network = argv_find (argv, argc, "A.B.C.D/M", &idx) ? argv[idx]->arg : NULL; - return bgp_show_route (vty, NULL, network, AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); + return bgp_show_route (vty, bgp, network, AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); } #endif /* KEEP_OLD_VPN_COMMANDS */ @@ -9624,20 +9286,17 @@ peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, DEFUN (show_ip_bgp_instance_neighbor_advertised_route, show_ip_bgp_instance_neighbor_advertised_route_cmd, - "show [ip] bgp [ WORD] []|ipv6 []|encap [unicast]|vpnv4 [unicast]>] neighbors [route-map WORD] [json]", + "show [ip] bgp [ WORD] [ []] " + "neighbors [ [route-map WORD]] [json]", SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Address Family\n" - "Address Family modifier\n" - "Address Family modifier\n" "Address Family\n" "Address Family modifier\n" "Address Family modifier\n" - "Address Family\n" "Address Family modifier\n" - "Address Family\n" "Address Family modifier\n" "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" @@ -9649,51 +9308,47 @@ DEFUN (show_ip_bgp_instance_neighbor_advertised_route, "Name of the route map\n" JSON_STR) { + vrf_id_t vrf = VRF_DEFAULT; afi_t afi = AFI_IP6; safi_t safi = SAFI_UNICAST; - char *vrf = NULL; char *rmap_name = NULL; char *peerstr = NULL; int rcvd = 0; - + struct bgp *bgp = NULL; struct peer *peer; int idx = 0; - /* show [ip] bgp */ - if (argv_find (argv, argc, "ip", &idx)) - afi = AFI_IP; - /* [ WORD] */ - if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx)) - vrf = argv[++idx]->arg; - /* []|ipv6 []|encap [unicast]|vpnv4 [unicast]>] */ - if (argv_find (argv, argc, "ipv4", &idx) || argv_find (argv, argc, "ipv6", &idx)) - { - afi = strmatch(argv[idx]->text, "ipv6") ? AFI_IP6 : AFI_IP; - if (argv_find (argv, argc, "unicast", &idx) || argv_find (argv, argc, "multicast", &idx)) - safi = strmatch (argv[idx]->text, "unicast") ? SAFI_UNICAST : SAFI_MULTICAST; - } - else if (argv_find (argv, argc, "encap", &idx) || argv_find (argv, argc, "vpnv4", &idx)) - { - afi = AFI_IP; - safi = strmatch (argv[idx]->text, "encap") ? SAFI_ENCAP : SAFI_MPLS_VPN; - // advance idx if necessary - argv_find (argv, argc, "unicast", &idx); - } + bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf); + if (!idx) + return CMD_WARNING; + + int uj = use_json (argc, argv); + if (uj) argc--; + + bgp = bgp_lookup_by_vrf_id (vrf); + if (bgp == NULL) + { + if (uj) + { + json_object *json_no = NULL; + json_no = json_object_new_object(); + json_object_string_add(json_no, "warning", "Can't find BGP view"); + vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); + json_object_free(json_no); + } + else + vty_out (vty, "Can't find BGP instance %s%s", argv[5]->arg, VTY_NEWLINE); + return CMD_WARNING; + } /* neighbors */ argv_find (argv, argc, "neighbors", &idx); peerstr = argv[++idx]->arg; - u_char uj = use_json(argc, argv); - - peer = peer_lookup_in_view (vty, vrf, peerstr, uj); - + peer = peer_lookup_in_view (vty, bgp, peerstr, uj); if (! peer) - { - vty_out (vty, "No such neighbor%s", VTY_NEWLINE); - return CMD_WARNING; - } + return CMD_WARNING; if (argv_find (argv, argc, "received-routes", &idx)) rcvd = 1; @@ -9816,20 +9471,17 @@ bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi, DEFUN (show_ip_bgp_neighbor_routes, show_ip_bgp_neighbor_routes_cmd, - "show [ip] bgp [ WORD] []|ipv6 []|encap [unicast]|vpnv4 [unicast]>] neighbors [json]", + "show [ip] bgp [ WORD] [ []] " + "neighbors [json]", SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR "Address Family\n" - "Address Family modifier\n" - "Address Family modifier\n" "Address Family\n" "Address Family modifier\n" "Address Family modifier\n" - "Address Family\n" "Address Family modifier\n" - "Address Family\n" "Address Family modifier\n" "Detailed information on TCP and BGP neighbor connections\n" "Neighbor to display information about\n" @@ -9840,9 +9492,9 @@ DEFUN (show_ip_bgp_neighbor_routes, "Display routes learned from neighbor\n" JSON_STR) { - char *vrf = NULL; + vrf_id_t vrf = VRF_DEFAULT; char *peerstr = NULL; - + struct bgp *bgp = NULL; afi_t afi = AFI_IP6; safi_t safi = SAFI_UNICAST; struct peer *peer; @@ -9850,33 +9502,39 @@ DEFUN (show_ip_bgp_neighbor_routes, int idx = 0; - /* show [ip] bgp */ - if (argv_find (argv, argc, "ip", &idx)) - afi = AFI_IP; - /* [ WORD] */ - if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx)) - vrf = argv[++idx]->arg; - /* []|ipv6 []|encap [unicast]|vpnv4 [unicast]>] */ - if (argv_find (argv, argc, "ipv4", &idx) || argv_find (argv, argc, "ipv6", &idx)) - { - afi = strmatch(argv[idx]->text, "ipv6") ? AFI_IP6 : AFI_IP; - if (argv_find (argv, argc, "unicast", &idx) || argv_find (argv, argc, "multicast", &idx)) - safi = strmatch (argv[idx]->text, "unicast") ? SAFI_UNICAST : SAFI_MULTICAST; - } - else if (argv_find (argv, argc, "encap", &idx) || argv_find (argv, argc, "vpnv4", &idx)) - { - afi = AFI_IP; - safi = strmatch (argv[idx]->text, "encap") ? SAFI_ENCAP : SAFI_MPLS_VPN; - // advance idx if necessary - argv_find (argv, argc, "unicast", &idx); - } + bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf); + if (!idx) + return CMD_WARNING; + + int uj = use_json (argc, argv); + if (uj) argc--; + + if (vrf != VRF_ALL) + { + bgp = bgp_lookup_by_vrf_id (vrf); + if (bgp == NULL) + { + if (uj) + { + json_object *json_no = NULL; + json_no = json_object_new_object(); + json_object_string_add(json_no, "warning", "Can't find BGP view"); + vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); + json_object_free(json_no); + } + else + vty_out (vty, "Can't find BGP instance %s%s", argv[5]->arg, VTY_NEWLINE); + return CMD_WARNING; + } + } + else + bgp = NULL; + /* neighbors */ argv_find (argv, argc, "neighbors", &idx); peerstr = argv[++idx]->arg; - u_char uj = use_json(argc, argv); - - peer = peer_lookup_in_view (vty, vrf, peerstr, uj); + peer = peer_lookup_in_view (vty, bgp, peerstr, uj); if (! peer) { vty_out (vty, "No such neighbor%s", VTY_NEWLINE); @@ -10710,15 +10368,13 @@ bgp_route_init (void) install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd); install_element (VIEW_NODE, &show_ip_bgp_instance_all_cmd); - install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd); + install_element (VIEW_NODE, &show_ip_bgp_cmd); install_element (VIEW_NODE, &show_ip_bgp_route_cmd); install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd); install_element (VIEW_NODE, &show_ip_bgp_instance_neighbor_advertised_route_cmd); install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd); install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd); - install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd); - install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd); #ifdef KEEP_OLD_VPN_COMMANDS install_element (VIEW_NODE, &show_ip_bgp_vpn_all_route_prefix_cmd); #endif /* KEEP_OLD_VPN_COMMANDS */ @@ -10731,14 +10387,10 @@ bgp_route_init (void) install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd); /* prefix count */ - install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd); install_element (ENABLE_NODE, &show_ip_bgp_instance_neighbor_prefix_counts_cmd); - install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd); #ifdef KEEP_OLD_VPN_COMMANDS install_element (ENABLE_NODE, &show_ip_bgp_vpn_neighbor_prefix_counts_cmd); #endif /* KEEP_OLD_VPN_COMMANDS */ - install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd); - install_element (ENABLE_NODE, &show_bgp_instance_ipv6_neighbor_prefix_counts_cmd); /* New config IPv6 BGP commands. */ install_element (BGP_IPV6_NODE, &bgp_table_map_cmd); @@ -10753,10 +10405,6 @@ bgp_route_init (void) install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd); install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd); - /* Statistics */ - install_element (ENABLE_NODE, &show_bgp_statistics_cmd); - install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd); - install_element (BGP_NODE, &bgp_distance_cmd); install_element (BGP_NODE, &no_bgp_distance_cmd); install_element (BGP_NODE, &bgp_distance_source_cmd); diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index 58788d2041..8f2486314a 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -4399,7 +4399,7 @@ DEFUN (no_set_vpn_nexthop, DEFUN (set_ipx_vpn_nexthop, set_ipx_vpn_nexthop_cmd, - "set vpn next-hop [A.B.C.D|X:X::X:X]", + "set vpn next-hop []", SET_STR "IPv4 information\n" "IPv6 information\n" @@ -4426,7 +4426,7 @@ DEFUN (set_ipx_vpn_nexthop, DEFUN (no_set_ipx_vpn_nexthop, no_set_ipx_vpn_nexthop_cmd, - "no set vpn next-hop [A.B.C.D|X:X::X:X]", + "no set vpn next-hop []", NO_STR SET_STR "IPv4 information\n" diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 17b8485237..d9043e520d 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -168,17 +168,7 @@ bgp_vty_safi_from_arg(const char *safi_str) } int -bgp_parse_safi(const char *str, safi_t *safi) -{ - *safi = bgp_vty_safi_from_arg(str); - if (*safi != SAFI_MAX) - return 0; - else - return -1; -} - -int -argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index, safi_t *safi) +argv_find_and_parse_safi (struct cmd_token **argv, int argc, int *index, safi_t *safi) { int ret = 0; if (argv_find (argv, argc, "unicast", index)) @@ -208,6 +198,80 @@ argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index, safi_t * return ret; } +/* + * bgp_vty_find_and_parse_afi_safi_vrf + * + * For a given 'show ...' command, correctly parse the afi/safi/vrf out from it + * This function *assumes* that the calling function pre-sets the afi/safi/vrf + * to appropriate values for the calling function. This is to allow the + * calling function to make decisions appropriate for the show command + * that is being parsed. + * + * The show commands are generally of the form: + * "show [ip] bgp [ WORD] [ []] ..." + * + * Since we use argv_find if the show command in particular doesn't have: + * [ip] + * [ WORD] + * [ []] + * The command parsing should still be ok. + * + * vty -> The vty for the command so we can output some useful data in + * the event of a parse error in the vrf. + * argv -> The command tokens + * argc -> How many command tokens we have + * idx -> The current place in the command, generally should be 0 for this function + * afi -> The parsed afi if it was included in the show command, returned here + * safi -> The parsed safi if it was included in the show command, returned here + * vrf -> The parsed vrf id if it was included in the show command, returned here + * + * The function returns the correct location in the parse tree for the + * last token found. + * + * Returns 0 for failure to parse correctly, else the idx position of where + * it found the last token. + */ +int +bgp_vty_find_and_parse_afi_safi_vrf (struct vty *vty, struct cmd_token **argv, int argc, int *idx, + afi_t *afi, safi_t *safi, vrf_id_t *vrf) +{ + char *vrf_name = NULL; + + assert (afi); + assert (safi); + assert (vrf && *vrf != VRF_UNKNOWN); + + if (argv_find (argv, argc, "ip", idx)) + *afi = AFI_IP; + + if (argv_find (argv, argc, "view", idx) || argv_find (argv, argc, "vrf", idx)) + { + vrf_name = argv[*idx + 1]->arg; + *idx += 2; + } + + if (argv_find_and_parse_afi (argv, argc, idx, afi)) + argv_find_and_parse_safi (argv, argc, idx, safi); + + if (vrf_name) + { + if (strmatch(vrf_name, "all")) + *vrf = VRF_ALL; + else + *vrf = vrf_name_to_id (vrf_name); + } + + if (*vrf == VRF_UNKNOWN) + { + vty_out (vty, "View/Vrf specified is unknown: %s", vrf_name); + *idx = 0; + return 0; + } + + *idx += 1; + return *idx; +} + static int peer_address_self_check (struct bgp *bgp, union sockunion *su) { @@ -8614,7 +8678,7 @@ DEFUN (show_ip_bgp_neighbors, SHOW_STR IP_STR BGP_STR - BGP_INSTANCE_ALL_HELP_STR + BGP_INSTANCE_HELP_STR "Address Family\n" "Address Family\n" "Address Family\n" @@ -9280,7 +9344,7 @@ bgp_show_peer_group_vty (struct vty *vty, const char *name, DEFUN (show_ip_bgp_peer_groups, show_ip_bgp_peer_groups_cmd, - "show [ip] bgp [ VRFNAME] peer-group [PGNAME]", + "show [ip] bgp [ WORD] peer-group [PGNAME]", SHOW_STR IP_STR BGP_STR @@ -9292,7 +9356,7 @@ DEFUN (show_ip_bgp_peer_groups, vrf = pg = NULL; int idx = 0; - vrf = argv_find (argv, argc, "VRFNAME", &idx) ? argv[idx]->arg : NULL; + vrf = argv_find (argv, argc, "WORD", &idx) ? argv[idx]->arg : NULL; pg = argv_find (argv, argc, "PGNAME", &idx) ? argv[idx]->arg : NULL; return bgp_show_peer_group_vty (vty, vrf, show_all_groups, pg); diff --git a/bgpd/bgp_vty.h b/bgpd/bgp_vty.h index 40c1723218..13e67d112e 100644 --- a/bgpd/bgp_vty.h +++ b/bgpd/bgp_vty.h @@ -51,9 +51,6 @@ peer_and_group_lookup_vty (struct vty *vty, const char *peer_str); extern int bgp_parse_afi(const char *str, afi_t *afi); -extern int -bgp_parse_safi(const char *str, safi_t *safi); - extern afi_t bgp_vty_afi_from_arg(const char *afi_str); @@ -66,4 +63,7 @@ argv_find_and_parse_afi(struct cmd_token **argv, int argc, int *index, afi_t *af extern int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index, safi_t *safi); +extern int +bgp_vty_find_and_parse_afi_safi_vrf (struct vty *vty, struct cmd_token **argv, int argc, int *idx, + afi_t *afi, safi_t *safi, vrf_id_t *vrf); #endif /* _QUAGGA_BGP_VTY_H */ diff --git a/lib/vrf.h b/lib/vrf.h index 96c716a7b8..f8bb07ef48 100644 --- a/lib/vrf.h +++ b/lib/vrf.h @@ -34,6 +34,7 @@ /* The default VRF ID */ #define VRF_DEFAULT 0 #define VRF_UNKNOWN UINT16_MAX +#define VRF_ALL UINT16_MAX - 1 /* Pending: May need to refine this. */ #ifndef IFLA_VRF_MAX