From: David Lamparter Date: Fri, 12 May 2017 10:22:56 +0000 (+0200) Subject: bgpd: autocomplete peer-groups & interface peers X-Git-Tag: reindent-master-before~160 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=d48ed3e09864f28bc57e64161e62872d9eab7d25;p=matthieu%2Ffrr.git bgpd: autocomplete peer-groups & interface peers This wasn't quite correct in the previous patch, leading to peer-groups & interface peers breaking in autocompletion. Signed-off-by: David Lamparter --- diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 0a8bef061b..e5734bd76b 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -10917,27 +10917,38 @@ bgp_ac_neighbor (vector comps, struct cmd_token *token) { struct bgp *bgp; struct peer *peer; + struct peer_group *group; struct listnode *lnbgp, *lnpeer; - bool ipv4 = !strcmp(token->text, "A.B.C.D"); - bool ipv6 = !strcmp(token->text, "X:X::X:X"); - bool name = !(ipv4 || ipv6); - for (ALL_LIST_ELEMENTS_RO (bm->bgp, lnbgp, bgp)) - for (ALL_LIST_ELEMENTS_RO (bgp->peer, lnpeer, peer)) - if (peer->group) - { - if (!name) - continue; - vector_set(comps, XSTRDUP(MTYPE_COMPLETION, peer->host)); - } - else + { + for (ALL_LIST_ELEMENTS_RO (bgp->peer, lnpeer, peer)) { - bool is_v6 = !!strchr(peer->host, ':'); - if (is_v6 != ipv6 || name) + /* only provide suggestions on the appropriate input token type, + * they'll otherwise show up multiple times */ + enum cmd_token_type match_type; + char *name = peer->host; + + if (peer->conf_if) + { + match_type = VARIABLE_TKN; + name = peer->conf_if; + } + else if (strchr(peer->host, ':')) + match_type = IPV6_TKN; + else + match_type = IPV4_TKN; + + if (token->type != match_type) continue; - vector_set(comps, XSTRDUP(MTYPE_COMPLETION, peer->host)); + + vector_set(comps, XSTRDUP(MTYPE_COMPLETION, name)); } + + if (token->type == VARIABLE_TKN) + for (ALL_LIST_ELEMENTS_RO (bgp->group, lnpeer, group)) + vector_set(comps, XSTRDUP(MTYPE_COMPLETION, group->name)); + } } static const struct cmd_variable_handler bgp_var_neighbor[] = {