]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: autocomplete neighbor names
authorDavid Lamparter <equinox@opensourcerouting.org>
Wed, 10 May 2017 14:55:42 +0000 (16:55 +0200)
committerQuentin Young <qlyoung@users.noreply.github.com>
Mon, 15 May 2017 14:27:43 +0000 (10:27 -0400)
Add autocompletion for neighbor IP/IPv6/peer-group names.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
bgpd/bgp_vty.c

index f2fa8a06433a6ebbe81d5e09f171356ba22b8c5a..0a8bef061b733c6014e8a50f4e8e0e6b022b2c9f 100644 (file)
@@ -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);