diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 132b754104..e35f9752f1 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 [ WORD] nexthop [detail]", + "show [ip] bgp [ VIEWVRFNAME] nexthop [detail]", SHOW_STR IP_STR BGP_STR diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 31c1dd8c10..979e7bda35 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -8438,7 +8438,7 @@ bgp_show_lcommunity_list (struct vty *vty, struct bgp *bgp, const char *lcom, DEFUN (show_ip_bgp_large_community_list, show_ip_bgp_large_community_list_cmd, - "show [ip] bgp [ WORD] [ []] large-community-list <(1-500)|WORD> [json]", + "show [ip] bgp [ VIEWVRFNAME] [ []] large-community-list <(1-500)|WORD> [json]", SHOW_STR IP_STR BGP_STR @@ -8484,7 +8484,7 @@ DEFUN (show_ip_bgp_large_community_list, } DEFUN (show_ip_bgp_large_community, show_ip_bgp_large_community_cmd, - "show [ip] bgp [ WORD] [ []] large-community [AA:BB:CC] [json]", + "show [ip] bgp [ VIEWVRFNAME] [ []] large-community [AA:BB:CC] [json]", SHOW_STR IP_STR BGP_STR @@ -8535,7 +8535,7 @@ static int bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t /* BGP route print out function. */ DEFUN (show_ip_bgp, show_ip_bgp_cmd, - "show [ip] bgp [ WORD] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]]\ + "show [ip] bgp [ VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]]\ [<\ cidr-only\ |dampening \ @@ -8656,7 +8656,7 @@ DEFUN (show_ip_bgp, DEFUN (show_ip_bgp_route, show_ip_bgp_route_cmd, - "show [ip] bgp [ WORD] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]]" + "show [ip] bgp [ VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]]" " [] [json]", SHOW_STR IP_STR @@ -8725,7 +8725,7 @@ DEFUN (show_ip_bgp_route, DEFUN (show_ip_bgp_regexp, show_ip_bgp_regexp_cmd, - "show [ip] bgp [ WORD] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] regexp REGEX...", + "show [ip] bgp [ VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] regexp REGEX...", SHOW_STR IP_STR BGP_STR @@ -9437,7 +9437,7 @@ bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_c DEFUN (show_ip_bgp_instance_neighbor_prefix_counts, show_ip_bgp_instance_neighbor_prefix_counts_cmd, - "show [ip] bgp [ WORD] [ []] " + "show [ip] bgp [ VIEWVRFNAME] [ []] " "neighbors prefix-counts [json]", SHOW_STR IP_STR @@ -9810,7 +9810,7 @@ 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] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] " + "show [ip] bgp [ VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] " "neighbors [route-map WORD] [json]", SHOW_STR IP_STR @@ -9974,7 +9974,7 @@ 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] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] " + "show [ip] bgp [ VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] " "neighbors [json]", SHOW_STR IP_STR diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index f5f538de95..702427a9c4 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -275,11 +275,11 @@ argv_find_and_parse_safi (struct cmd_token **argv, int argc, int *index, safi_t * that is being parsed. * * The show commands are generally of the form: - * "show [ip] bgp [ WORD] [ []] ..." + * "show [ip] bgp [ VIEWVRFNAME] [ []] ..." * * Since we use argv_find if the show command in particular doesn't have: * [ip] - * [ WORD] + * [ VIEWVRFNAME] * [ []] * The command parsing should still be ok. * @@ -859,7 +859,7 @@ DEFUN (no_auto_summary, /* "router bgp" commands. */ DEFUN_NOSH (router_bgp, router_bgp_cmd, - "router bgp [(1-4294967295) [ WORD]]", + "router bgp [(1-4294967295) [ VIEWVRFNAME]]", ROUTER_STR BGP_STR AS_STR @@ -937,7 +937,7 @@ DEFUN_NOSH (router_bgp, /* "no router bgp" commands. */ DEFUN (no_router_bgp, no_router_bgp_cmd, - "no router bgp [(1-4294967295) [ WORD]]", + "no router bgp [(1-4294967295) [ VIEWVRFNAME]]", NO_STR ROUTER_STR BGP_STR @@ -6499,7 +6499,7 @@ bgp_clear_prefix (struct vty *vty, const char *view_name, const char *ip_str, /* one clear bgp command to rule them all */ DEFUN (clear_ip_bgp_all, clear_ip_bgp_all_cmd, - "clear [ip] bgp [ WORD] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> []|in [prefix-filter]|out>]", + "clear [ip] bgp [ VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> []|in [prefix-filter]|out>]", CLEAR_STR IP_STR BGP_STR @@ -6534,7 +6534,7 @@ DEFUN (clear_ip_bgp_all, /* clear [ip] bgp */ if (argv_find (argv, argc, "ip", &idx)) afi = AFI_IP; - /* [ WORD] */ + /* [ VIEWVRFNAME] */ if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx)) { vrf = argv[idx + 1]->arg; @@ -6604,7 +6604,7 @@ DEFUN (clear_ip_bgp_all, DEFUN (clear_ip_bgp_prefix, clear_ip_bgp_prefix_cmd, - "clear [ip] bgp [ WORD] prefix A.B.C.D/M", + "clear [ip] bgp [ VIEWVRFNAME] prefix A.B.C.D/M", CLEAR_STR IP_STR BGP_STR @@ -6617,7 +6617,7 @@ DEFUN (clear_ip_bgp_prefix, int idx = 0; - /* [ WORD] */ + /* [ VIEWVRFNAME] */ if (argv_find (argv, argc, "WORD", &idx)) vrf = argv[idx]->arg; @@ -6645,7 +6645,7 @@ DEFUN (clear_bgp_ipv6_safi_prefix, DEFUN (clear_bgp_instance_ipv6_safi_prefix, clear_bgp_instance_ipv6_safi_prefix_cmd, - "clear [ip] bgp WORD ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M", + "clear [ip] bgp VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M", CLEAR_STR IP_STR BGP_STR @@ -7474,7 +7474,7 @@ bgp_show_summary_vty (struct vty *vty, const char *name, /* `show [ip] bgp summary' commands. */ DEFUN (show_ip_bgp_summary, show_ip_bgp_summary_cmd, - "show [ip] bgp [ WORD] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] summary [json]", + "show [ip] bgp [ VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] summary [json]", SHOW_STR IP_STR BGP_STR @@ -7493,7 +7493,7 @@ DEFUN (show_ip_bgp_summary, /* show [ip] bgp */ if (argv_find (argv, argc, "ip", &idx)) afi = AFI_IP; - /* [ WORD] */ + /* [ VIEWVRFNAME] */ if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx)) vrf = argv[++idx]->arg; /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */ @@ -9430,7 +9430,7 @@ bgp_show_neighbor_vty (struct vty *vty, const char *name, /* "show [ip] bgp neighbors" commands. */ DEFUN (show_ip_bgp_neighbors, show_ip_bgp_neighbors_cmd, - "show [ip] bgp [ WORD] [>] neighbors [] [json]", + "show [ip] bgp [ VIEWVRFNAME] [>] neighbors [] [json]", SHOW_STR IP_STR BGP_STR @@ -9610,7 +9610,7 @@ bgp_show_update_groups(struct vty *vty, const char *name, DEFUN (show_ip_bgp_updgrps, show_ip_bgp_updgrps_cmd, - "show [ip] bgp [ WORD] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] update-groups [SUBGROUP-ID]", + "show [ip] bgp [ VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] update-groups [SUBGROUP-ID]", SHOW_STR IP_STR BGP_STR @@ -9630,7 +9630,7 @@ DEFUN (show_ip_bgp_updgrps, /* show [ip] bgp */ if (argv_find (argv, argc, "ip", &idx)) afi = AFI_IP; - /* [ WORD] */ + /* [ VIEWVRFNAME] */ if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx)) vrf = argv[++idx]->arg; /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */ @@ -9680,7 +9680,7 @@ DEFUN (show_bgp_updgrps_stats, DEFUN (show_bgp_instance_updgrps_stats, show_bgp_instance_updgrps_stats_cmd, - "show [ip] bgp WORD update-groups statistics", + "show [ip] bgp VIEWVRFNAME update-groups statistics", SHOW_STR IP_STR BGP_STR @@ -9740,7 +9740,7 @@ DEFUN (show_ip_bgp_updgrps_adj, DEFUN (show_ip_bgp_instance_updgrps_adj, show_ip_bgp_instance_updgrps_adj_cmd, - "show [ip] bgp WORD update-groups ", + "show [ip] bgp VIEWVRFNAME update-groups ", SHOW_STR IP_STR BGP_STR @@ -9798,7 +9798,7 @@ DEFUN (show_bgp_updgrps_adj, DEFUN (show_bgp_instance_updgrps_adj, show_bgp_instance_updgrps_adj_cmd, - "show [ip] bgp WORD update-groups ", + "show [ip] bgp VIEWVRFNAME update-groups ", SHOW_STR IP_STR BGP_STR @@ -9839,7 +9839,7 @@ DEFUN (show_ip_bgp_updgrps_adj_s, DEFUN (show_ip_bgp_instance_updgrps_adj_s, show_ip_bgp_instance_updgrps_adj_s_cmd, - "show [ip] bgp WORD update-groups SUBGROUP-ID ", + "show [ip] bgp VIEWVRFNAME update-groups SUBGROUP-ID ", SHOW_STR IP_STR BGP_STR @@ -9915,7 +9915,7 @@ DEFUN (show_bgp_updgrps_adj_s, DEFUN (show_bgp_instance_updgrps_adj_s, show_bgp_instance_updgrps_adj_s_cmd, - "show [ip] bgp WORD update-groups SUBGROUP-ID ", + "show [ip] bgp VIEWVRFNAME update-groups SUBGROUP-ID ", SHOW_STR IP_STR BGP_STR @@ -10102,7 +10102,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 [ WORD] peer-group [PGNAME]", + "show [ip] bgp [ VIEWVRFNAME] peer-group [PGNAME]", SHOW_STR IP_STR BGP_STR diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index cf6c00ae52..99db69b7c5 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -7681,6 +7681,38 @@ bgp_if_finish (struct bgp *bgp) extern void bgp_snmp_init (void); +static void +bgp_viewvrf_autocomplete (vector comps, struct cmd_token *token) +{ + struct vrf *vrf = NULL; + struct listnode *next; + struct bgp *bgp; + + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) + { + if (vrf->vrf_id != VRF_DEFAULT) + vector_set (comps, XSTRDUP (MTYPE_COMPLETION, vrf->name)); + } + + for (ALL_LIST_ELEMENTS_RO (bm->bgp, next, bgp)) + { + if (bgp->inst_type != BGP_INSTANCE_TYPE_VIEW) + continue; + + vector_set (comps, XSTRDUP (MTYPE_COMPLETION, bgp->name)); + } +} + +static const struct cmd_variable_handler bgp_viewvrf_var_handlers[] = { + { + .tokenname = "VIEWVRFNAME", + .completions = bgp_viewvrf_autocomplete + }, + { + .completions = NULL + }, +}; + void bgp_init (void) { @@ -7730,6 +7762,8 @@ bgp_init (void) /* BFD init */ bgp_bfd_init(); + + cmd_variable_handler_register (bgp_viewvrf_var_handlers); } void diff --git a/lib/vrf.c b/lib/vrf.c index c4e527db5b..5199795fdf 100644 --- a/lib/vrf.c +++ b/lib/vrf.c @@ -377,6 +377,28 @@ vrf_bitmap_check (vrf_bitmap_t bmap, vrf_id_t vrf_id) VRF_BITMAP_FLAG (offset)) ? 1 : 0; } +static void +vrf_autocomplete (vector comps, struct cmd_token *token) +{ + struct vrf *vrf = NULL; + + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) + { + if (vrf->vrf_id != 0) + vector_set (comps, XSTRDUP (MTYPE_COMPLETION, vrf->name)); + } +} + +static const struct cmd_variable_handler vrf_var_handlers[] = { + { + .varname = "vrf", + .completions = vrf_autocomplete, + }, + { + .completions = NULL + }, +}; + /* Initialize VRF module. */ void vrf_init (int (*create)(struct vrf *), @@ -408,6 +430,8 @@ vrf_init (int (*create)(struct vrf *), zlog_err ("vrf_init: failed to enable the default VRF!"); exit (1); } + + cmd_variable_handler_register (vrf_var_handlers); } /* Terminate VRF module. */