From 225096bcd1946b8de211bd21122f417a5dca2886 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Tue, 10 Aug 2021 10:23:52 +0300 Subject: [PATCH 1/3] bgpd: Auto-complete for community lists Signed-off-by: Donatas Abraitis --- bgpd/bgp_clist.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ bgpd/bgp_clist.h | 2 ++ bgpd/bgp_vty.c | 2 ++ 3 files changed, 68 insertions(+) diff --git a/bgpd/bgp_clist.c b/bgpd/bgp_clist.c index 50122ad7da..1fb55ddf7d 100644 --- a/bgpd/bgp_clist.c +++ b/bgpd/bgp_clist.c @@ -1372,3 +1372,67 @@ void community_list_terminate(struct community_list_handler *ch) XFREE(MTYPE_COMMUNITY_LIST_HANDLER, ch); } + +static int bgp_community_list_vector_walker(struct hash_bucket *bucket, + void *data) +{ + vector *comps = data; + struct community_list *list = bucket->data; + + vector_set(*comps, XSTRDUP(MTYPE_COMPLETION, list->name)); + + return 1; +} + +static void bgp_community_list_cmd_completion(vector comps, + struct cmd_token *token) +{ + struct community_list_master *cm; + + cm = community_list_master_lookup(bgp_clist, COMMUNITY_LIST_MASTER); + + hash_walk(cm->hash, bgp_community_list_vector_walker, &comps); +} + +static void bgp_lcommunity_list_cmd_completion(vector comps, + struct cmd_token *token) +{ + struct community_list_master *cm; + + cm = community_list_master_lookup(bgp_clist, + LARGE_COMMUNITY_LIST_MASTER); + + hash_walk(cm->hash, bgp_community_list_vector_walker, &comps); +} + +static void bgp_extcommunity_list_cmd_completion(vector comps, + struct cmd_token *token) +{ + struct community_list_master *cm; + + cm = community_list_master_lookup(bgp_clist, EXTCOMMUNITY_LIST_MASTER); + + hash_walk(cm->hash, bgp_community_list_vector_walker, &comps); +} + +static const struct cmd_variable_handler community_list_handlers[] = { + {.tokenname = "COMMUNITY_LIST_NAME", + .completions = bgp_community_list_cmd_completion}, + {.completions = NULL}}; + +static const struct cmd_variable_handler lcommunity_list_handlers[] = { + {.tokenname = "LCOMMUNITY_LIST_NAME", + .completions = bgp_lcommunity_list_cmd_completion}, + {.completions = NULL}}; + +static const struct cmd_variable_handler extcommunity_list_handlers[] = { + {.tokenname = "EXTCOMMUNITY_LIST_NAME", + .completions = bgp_extcommunity_list_cmd_completion}, + {.completions = NULL}}; + +void bgp_community_list_command_completion_setup(void) +{ + cmd_variable_handler_register(community_list_handlers); + cmd_variable_handler_register(lcommunity_list_handlers); + cmd_variable_handler_register(extcommunity_list_handlers); +} diff --git a/bgpd/bgp_clist.h b/bgpd/bgp_clist.h index 632e1730cc..bb7c1363b2 100644 --- a/bgpd/bgp_clist.h +++ b/bgpd/bgp_clist.h @@ -184,4 +184,6 @@ static inline uint32_t bgp_clist_hash_key(char *name) return jhash(name, strlen(name), 0xdeadbeaf); } +extern void bgp_community_list_command_completion_setup(void); + #endif /* _QUAGGA_BGP_CLIST_H */ diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 63b2fbd4e6..a031b78971 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -19910,6 +19910,8 @@ static void community_list_vty(void) install_element(CONFIG_NODE, &no_bgp_lcommunity_list_name_expanded_cmd); install_element(VIEW_NODE, &show_bgp_lcommunity_list_cmd); install_element(VIEW_NODE, &show_bgp_lcommunity_list_arg_cmd); + + bgp_community_list_command_completion_setup(); } static struct cmd_node community_alias_node = { From 96870ecb059ab4cc2bd2b294c6cea97e5883ac9f Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Tue, 10 Aug 2021 11:02:50 +0300 Subject: [PATCH 2/3] bgpd: Auto-complete for `show bgp community-list` ``` exit1-debian-9# show ip bgp community-list ? (1-500) community-list number COMMUNITY_LIST_NAME community-list name testas ``` Signed-off-by: Donatas Abraitis --- bgpd/bgp_route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 6039a91f7d..65a1aa21a7 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -11948,7 +11948,7 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd, |route-map WORD\ |prefix-list WORD\ |filter-list WORD\ - |community-list <(1-500)|WORD> [exact-match]\ + |community-list <(1-500)|COMMUNITY_LIST_NAME> [exact-match]\ |A.B.C.D/M longer-prefixes\ |X:X::X:X/M longer-prefixes\ >", From 77a3a95eaa96e2f938825efeec2faf9de67c30b0 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Tue, 10 Aug 2021 11:04:57 +0300 Subject: [PATCH 3/3] bgpd: Auto-complete for `show bgp large-community-list` ``` exit1-debian-9# show ip bgp large-community-list (1-500) large-community-list number LCOMMUNITY_LIST_NAME large-community-list name large-testas ``` Signed-off-by: Donatas Abraitis --- bgpd/bgp_route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 65a1aa21a7..2b8a2eae3c 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -11715,7 +11715,7 @@ static int bgp_show_lcommunity_list(struct vty *vty, struct bgp *bgp, DEFUN (show_ip_bgp_large_community_list, show_ip_bgp_large_community_list_cmd, - "show [ip] bgp [ VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] large-community-list <(1-500)|WORD> [exact-match] [json]", + "show [ip] bgp [ VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> [exact-match] [json]", SHOW_STR IP_STR BGP_STR