From: David Lamparter Date: Wed, 10 May 2017 14:55:42 +0000 (+0200) Subject: bgpd: autocomplete neighbor names X-Git-Tag: reindent-master-before~163 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=b8a815e5e464257e0eeca49128475c3a5eb1253f;p=matthieu%2Ffrr.git bgpd: autocomplete neighbor names Add autocompletion for neighbor IP/IPv6/peer-group names. Signed-off-by: David Lamparter --- diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index f2fa8a0643..0a8bef061b 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -10912,9 +10912,51 @@ static struct cmd_node bgp_evpn_node = static void community_list_vty (void); +static void +bgp_ac_neighbor (vector comps, struct cmd_token *token) +{ + struct bgp *bgp; + struct peer *peer; + 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 + { + bool is_v6 = !!strchr(peer->host, ':'); + if (is_v6 != ipv6 || name) + continue; + vector_set(comps, XSTRDUP(MTYPE_COMPLETION, peer->host)); + } +} + +static const struct cmd_variable_handler bgp_var_neighbor[] = { + { + .varname = "neighbor", + .completions = bgp_ac_neighbor + }, { + .varname = "neighbors", + .completions = bgp_ac_neighbor + }, { + .completions = NULL + } +}; + void bgp_vty_init (void) { + cmd_variable_handler_register(bgp_var_neighbor); + /* Install bgp top node. */ install_node (&bgp_node, bgp_config_write); install_node (&bgp_ipv4_unicast_node, NULL);