Merge pull request #725 from donaldsharp/vrf_completion

Vrf completion
This commit is contained in:
David Lamparter 2017-06-16 21:59:23 +02:00 committed by GitHub
commit 2dc1ef552b
5 changed files with 87 additions and 29 deletions

View File

@ -492,7 +492,7 @@ bgp_show_all_instances_nexthops_vty (struct vty *vty)
DEFUN (show_ip_bgp_nexthop, DEFUN (show_ip_bgp_nexthop,
show_ip_bgp_nexthop_cmd, show_ip_bgp_nexthop_cmd,
"show [ip] bgp [<view|vrf> WORD] nexthop [detail]", "show [ip] bgp [<view|vrf> VIEWVRFNAME] nexthop [detail]",
SHOW_STR SHOW_STR
IP_STR IP_STR
BGP_STR BGP_STR

View File

@ -8438,7 +8438,7 @@ bgp_show_lcommunity_list (struct vty *vty, struct bgp *bgp, const char *lcom,
DEFUN (show_ip_bgp_large_community_list, DEFUN (show_ip_bgp_large_community_list,
show_ip_bgp_large_community_list_cmd, show_ip_bgp_large_community_list_cmd,
"show [ip] bgp [<view|vrf> WORD] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]] large-community-list <(1-500)|WORD> [json]", "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]] large-community-list <(1-500)|WORD> [json]",
SHOW_STR SHOW_STR
IP_STR IP_STR
BGP_STR BGP_STR
@ -8484,7 +8484,7 @@ DEFUN (show_ip_bgp_large_community_list,
} }
DEFUN (show_ip_bgp_large_community, DEFUN (show_ip_bgp_large_community,
show_ip_bgp_large_community_cmd, show_ip_bgp_large_community_cmd,
"show [ip] bgp [<view|vrf> WORD] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]] large-community [AA:BB:CC] [json]", "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]] large-community [AA:BB:CC] [json]",
SHOW_STR SHOW_STR
IP_STR IP_STR
BGP_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. */ /* BGP route print out function. */
DEFUN (show_ip_bgp, DEFUN (show_ip_bgp,
show_ip_bgp_cmd, show_ip_bgp_cmd,
"show [ip] bgp [<view|vrf> WORD] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]]\ "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]]\
[<\ [<\
cidr-only\ cidr-only\
|dampening <flap-statistics|dampened-paths|parameters>\ |dampening <flap-statistics|dampened-paths|parameters>\
@ -8656,7 +8656,7 @@ DEFUN (show_ip_bgp,
DEFUN (show_ip_bgp_route, DEFUN (show_ip_bgp_route,
show_ip_bgp_route_cmd, show_ip_bgp_route_cmd,
"show [ip] bgp [<view|vrf> WORD] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]]" "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]]"
"<A.B.C.D|A.B.C.D/M|X:X::X:X|X:X::X:X/M> [<bestpath|multipath>] [json]", "<A.B.C.D|A.B.C.D/M|X:X::X:X|X:X::X:X/M> [<bestpath|multipath>] [json]",
SHOW_STR SHOW_STR
IP_STR IP_STR
@ -8725,7 +8725,7 @@ DEFUN (show_ip_bgp_route,
DEFUN (show_ip_bgp_regexp, DEFUN (show_ip_bgp_regexp,
show_ip_bgp_regexp_cmd, show_ip_bgp_regexp_cmd,
"show [ip] bgp [<view|vrf> WORD] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] regexp REGEX...", "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] regexp REGEX...",
SHOW_STR SHOW_STR
IP_STR IP_STR
BGP_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, DEFUN (show_ip_bgp_instance_neighbor_prefix_counts,
show_ip_bgp_instance_neighbor_prefix_counts_cmd, show_ip_bgp_instance_neighbor_prefix_counts_cmd,
"show [ip] bgp [<view|vrf> WORD] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]] " "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]] "
"neighbors <A.B.C.D|X:X::X:X|WORD> prefix-counts [json]", "neighbors <A.B.C.D|X:X::X:X|WORD> prefix-counts [json]",
SHOW_STR SHOW_STR
IP_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, DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
show_ip_bgp_instance_neighbor_advertised_route_cmd, show_ip_bgp_instance_neighbor_advertised_route_cmd,
"show [ip] bgp [<view|vrf> WORD] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] " "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] "
"neighbors <A.B.C.D|X:X::X:X|WORD> <received-routes|advertised-routes> [route-map WORD] [json]", "neighbors <A.B.C.D|X:X::X:X|WORD> <received-routes|advertised-routes> [route-map WORD] [json]",
SHOW_STR SHOW_STR
IP_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, DEFUN (show_ip_bgp_neighbor_routes,
show_ip_bgp_neighbor_routes_cmd, show_ip_bgp_neighbor_routes_cmd,
"show [ip] bgp [<view|vrf> WORD] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] " "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] "
"neighbors <A.B.C.D|X:X::X:X|WORD> <flap-statistics|dampened-routes|routes> [json]", "neighbors <A.B.C.D|X:X::X:X|WORD> <flap-statistics|dampened-routes|routes> [json]",
SHOW_STR SHOW_STR
IP_STR IP_STR

View File

@ -275,11 +275,11 @@ argv_find_and_parse_safi (struct cmd_token **argv, int argc, int *index, safi_t
* that is being parsed. * that is being parsed.
* *
* The show commands are generally of the form: * The show commands are generally of the form:
* "show [ip] bgp [<view|vrf> WORD] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]] ..." * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]] ..."
* *
* Since we use argv_find if the show command in particular doesn't have: * Since we use argv_find if the show command in particular doesn't have:
* [ip] * [ip]
* [<view|vrf> WORD] * [<view|vrf> VIEWVRFNAME]
* [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]] * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
* The command parsing should still be ok. * The command parsing should still be ok.
* *
@ -859,7 +859,7 @@ DEFUN (no_auto_summary,
/* "router bgp" commands. */ /* "router bgp" commands. */
DEFUN_NOSH (router_bgp, DEFUN_NOSH (router_bgp,
router_bgp_cmd, router_bgp_cmd,
"router bgp [(1-4294967295) [<view|vrf> WORD]]", "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
ROUTER_STR ROUTER_STR
BGP_STR BGP_STR
AS_STR AS_STR
@ -937,7 +937,7 @@ DEFUN_NOSH (router_bgp,
/* "no router bgp" commands. */ /* "no router bgp" commands. */
DEFUN (no_router_bgp, DEFUN (no_router_bgp,
no_router_bgp_cmd, no_router_bgp_cmd,
"no router bgp [(1-4294967295) [<view|vrf> WORD]]", "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
NO_STR NO_STR
ROUTER_STR ROUTER_STR
BGP_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 */ /* one clear bgp command to rule them all */
DEFUN (clear_ip_bgp_all, DEFUN (clear_ip_bgp_all,
clear_ip_bgp_all_cmd, clear_ip_bgp_all_cmd,
"clear [ip] bgp [<view|vrf> WORD] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> [<soft [<in|out>]|in [prefix-filter]|out>]", "clear [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> [<soft [<in|out>]|in [prefix-filter]|out>]",
CLEAR_STR CLEAR_STR
IP_STR IP_STR
BGP_STR BGP_STR
@ -6534,7 +6534,7 @@ DEFUN (clear_ip_bgp_all,
/* clear [ip] bgp */ /* clear [ip] bgp */
if (argv_find (argv, argc, "ip", &idx)) if (argv_find (argv, argc, "ip", &idx))
afi = AFI_IP; afi = AFI_IP;
/* [<view|vrf> WORD] */ /* [<view|vrf> VIEWVRFNAME] */
if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx)) if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx))
{ {
vrf = argv[idx + 1]->arg; vrf = argv[idx + 1]->arg;
@ -6604,7 +6604,7 @@ DEFUN (clear_ip_bgp_all,
DEFUN (clear_ip_bgp_prefix, DEFUN (clear_ip_bgp_prefix,
clear_ip_bgp_prefix_cmd, clear_ip_bgp_prefix_cmd,
"clear [ip] bgp [<view|vrf> WORD] prefix A.B.C.D/M", "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
CLEAR_STR CLEAR_STR
IP_STR IP_STR
BGP_STR BGP_STR
@ -6617,7 +6617,7 @@ DEFUN (clear_ip_bgp_prefix,
int idx = 0; int idx = 0;
/* [<view|vrf> WORD] */ /* [<view|vrf> VIEWVRFNAME] */
if (argv_find (argv, argc, "WORD", &idx)) if (argv_find (argv, argc, "WORD", &idx))
vrf = argv[idx]->arg; vrf = argv[idx]->arg;
@ -6645,7 +6645,7 @@ DEFUN (clear_bgp_ipv6_safi_prefix,
DEFUN (clear_bgp_instance_ipv6_safi_prefix, DEFUN (clear_bgp_instance_ipv6_safi_prefix,
clear_bgp_instance_ipv6_safi_prefix_cmd, clear_bgp_instance_ipv6_safi_prefix_cmd,
"clear [ip] bgp <view|vrf> WORD ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M", "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
CLEAR_STR CLEAR_STR
IP_STR IP_STR
BGP_STR BGP_STR
@ -7474,7 +7474,7 @@ bgp_show_summary_vty (struct vty *vty, const char *name,
/* `show [ip] bgp summary' commands. */ /* `show [ip] bgp summary' commands. */
DEFUN (show_ip_bgp_summary, DEFUN (show_ip_bgp_summary,
show_ip_bgp_summary_cmd, show_ip_bgp_summary_cmd,
"show [ip] bgp [<view|vrf> WORD] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] summary [json]", "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] summary [json]",
SHOW_STR SHOW_STR
IP_STR IP_STR
BGP_STR BGP_STR
@ -7493,7 +7493,7 @@ DEFUN (show_ip_bgp_summary,
/* show [ip] bgp */ /* show [ip] bgp */
if (argv_find (argv, argc, "ip", &idx)) if (argv_find (argv, argc, "ip", &idx))
afi = AFI_IP; afi = AFI_IP;
/* [<view|vrf> WORD] */ /* [<view|vrf> VIEWVRFNAME] */
if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx)) if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx))
vrf = argv[++idx]->arg; vrf = argv[++idx]->arg;
/* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */ /* ["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. */ /* "show [ip] bgp neighbors" commands. */
DEFUN (show_ip_bgp_neighbors, DEFUN (show_ip_bgp_neighbors,
show_ip_bgp_neighbors_cmd, show_ip_bgp_neighbors_cmd,
"show [ip] bgp [<view|vrf> WORD] [<ipv4|ipv6|vpnv4 <all|rd ASN:nn_or_IP-address:nn>>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]", "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|vpnv4 <all|rd ASN:nn_or_IP-address:nn>>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
SHOW_STR SHOW_STR
IP_STR IP_STR
BGP_STR BGP_STR
@ -9610,7 +9610,7 @@ bgp_show_update_groups(struct vty *vty, const char *name,
DEFUN (show_ip_bgp_updgrps, DEFUN (show_ip_bgp_updgrps,
show_ip_bgp_updgrps_cmd, show_ip_bgp_updgrps_cmd,
"show [ip] bgp [<view|vrf> WORD] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] update-groups [SUBGROUP-ID]", "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] update-groups [SUBGROUP-ID]",
SHOW_STR SHOW_STR
IP_STR IP_STR
BGP_STR BGP_STR
@ -9630,7 +9630,7 @@ DEFUN (show_ip_bgp_updgrps,
/* show [ip] bgp */ /* show [ip] bgp */
if (argv_find (argv, argc, "ip", &idx)) if (argv_find (argv, argc, "ip", &idx))
afi = AFI_IP; afi = AFI_IP;
/* [<view|vrf> WORD] */ /* [<view|vrf> VIEWVRFNAME] */
if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx)) if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx))
vrf = argv[++idx]->arg; vrf = argv[++idx]->arg;
/* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */ /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
@ -9680,7 +9680,7 @@ DEFUN (show_bgp_updgrps_stats,
DEFUN (show_bgp_instance_updgrps_stats, DEFUN (show_bgp_instance_updgrps_stats,
show_bgp_instance_updgrps_stats_cmd, show_bgp_instance_updgrps_stats_cmd,
"show [ip] bgp <view|vrf> WORD update-groups statistics", "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
SHOW_STR SHOW_STR
IP_STR IP_STR
BGP_STR BGP_STR
@ -9740,7 +9740,7 @@ DEFUN (show_ip_bgp_updgrps_adj,
DEFUN (show_ip_bgp_instance_updgrps_adj, DEFUN (show_ip_bgp_instance_updgrps_adj,
show_ip_bgp_instance_updgrps_adj_cmd, show_ip_bgp_instance_updgrps_adj_cmd,
"show [ip] bgp <view|vrf> WORD update-groups <advertise-queue|advertised-routes|packet-queue>", "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
SHOW_STR SHOW_STR
IP_STR IP_STR
BGP_STR BGP_STR
@ -9798,7 +9798,7 @@ DEFUN (show_bgp_updgrps_adj,
DEFUN (show_bgp_instance_updgrps_adj, DEFUN (show_bgp_instance_updgrps_adj,
show_bgp_instance_updgrps_adj_cmd, show_bgp_instance_updgrps_adj_cmd,
"show [ip] bgp <view|vrf> WORD update-groups <advertise-queue|advertised-routes|packet-queue>", "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
SHOW_STR SHOW_STR
IP_STR IP_STR
BGP_STR BGP_STR
@ -9839,7 +9839,7 @@ DEFUN (show_ip_bgp_updgrps_adj_s,
DEFUN (show_ip_bgp_instance_updgrps_adj_s, DEFUN (show_ip_bgp_instance_updgrps_adj_s,
show_ip_bgp_instance_updgrps_adj_s_cmd, show_ip_bgp_instance_updgrps_adj_s_cmd,
"show [ip] bgp <view|vrf> WORD update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>", "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
SHOW_STR SHOW_STR
IP_STR IP_STR
BGP_STR BGP_STR
@ -9915,7 +9915,7 @@ DEFUN (show_bgp_updgrps_adj_s,
DEFUN (show_bgp_instance_updgrps_adj_s, DEFUN (show_bgp_instance_updgrps_adj_s,
show_bgp_instance_updgrps_adj_s_cmd, show_bgp_instance_updgrps_adj_s_cmd,
"show [ip] bgp <view|vrf> WORD update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>", "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
SHOW_STR SHOW_STR
IP_STR IP_STR
BGP_STR BGP_STR
@ -10102,7 +10102,7 @@ bgp_show_peer_group_vty (struct vty *vty, const char *name,
DEFUN (show_ip_bgp_peer_groups, DEFUN (show_ip_bgp_peer_groups,
show_ip_bgp_peer_groups_cmd, show_ip_bgp_peer_groups_cmd,
"show [ip] bgp [<view|vrf> WORD] peer-group [PGNAME]", "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
SHOW_STR SHOW_STR
IP_STR IP_STR
BGP_STR BGP_STR

View File

@ -7681,6 +7681,38 @@ bgp_if_finish (struct bgp *bgp)
extern void bgp_snmp_init (void); 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 void
bgp_init (void) bgp_init (void)
{ {
@ -7730,6 +7762,8 @@ bgp_init (void)
/* BFD init */ /* BFD init */
bgp_bfd_init(); bgp_bfd_init();
cmd_variable_handler_register (bgp_viewvrf_var_handlers);
} }
void void

View File

@ -377,6 +377,28 @@ vrf_bitmap_check (vrf_bitmap_t bmap, vrf_id_t vrf_id)
VRF_BITMAP_FLAG (offset)) ? 1 : 0; 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. */ /* Initialize VRF module. */
void void
vrf_init (int (*create)(struct vrf *), 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!"); zlog_err ("vrf_init: failed to enable the default VRF!");
exit (1); exit (1);
} }
cmd_variable_handler_register (vrf_var_handlers);
} }
/* Terminate VRF module. */ /* Terminate VRF module. */