]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: autocomplete peer-groups & interface peers
authorDavid Lamparter <equinox@opensourcerouting.org>
Fri, 12 May 2017 10:22:56 +0000 (12:22 +0200)
committerQuentin Young <qlyoung@users.noreply.github.com>
Mon, 15 May 2017 14:27:43 +0000 (10:27 -0400)
This wasn't quite correct in the previous patch, leading to peer-groups
& interface peers breaking in autocompletion.

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

index 0a8bef061b733c6014e8a50f4e8e0e6b022b2c9f..e5734bd76b286767da672fcb868600e019b9a927 100644 (file)
@@ -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[] = {