]> git.proxmox.com Git - mirror_frr.git/commitdiff
vtysh: Execute command on client by name only
authorStephen Worley <sworley@cumulusnetworks.com>
Thu, 13 Jun 2019 21:29:33 +0000 (17:29 -0400)
committerStephen Worley <sworley@cumulusnetworks.com>
Wed, 19 Jun 2019 21:20:24 +0000 (17:20 -0400)
Add static function path for exectuting a command
on a client daemon via a string of its name only.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
vtysh/vtysh.c

index 1d5fa8cbc8f58abf0b2aa77fdd18956ab5b7fd1e..2160e4054e3129b10fd15d3f144de688aaf47cad 100644 (file)
@@ -140,6 +140,21 @@ struct vtysh_client vtysh_client[] = {
        {.fd = -1, .name = "vrrpd", .flag = VTYSH_VRRPD, .next = NULL},
 };
 
+/* Searches for client by name, returns index */
+static int vtysh_client_lookup(const char *name)
+{
+       int idx = -1;
+
+       for (unsigned int i = 0; i < array_size(vtysh_client); i++) {
+               if (strmatch(vtysh_client[i].name, name)) {
+                       idx = i;
+                       break;
+               }
+       }
+
+       return idx;
+}
+
 enum vtysh_write_integrated vtysh_write_integrated =
        WRITE_INTEGRATED_UNSPECIFIED;
 
@@ -394,6 +409,23 @@ static int vtysh_client_execute(struct vtysh_client *head_client,
        return vtysh_client_run_all(head_client, line, 0, NULL, NULL);
 }
 
+/* Execute by name */
+static int vtysh_client_execute_name(const char *name, const char *line)
+{
+       int ret = CMD_SUCCESS;
+       int idx_client = -1;
+
+       idx_client = vtysh_client_lookup(name);
+       if (idx_client != -1)
+               ret = vtysh_client_execute(&vtysh_client[idx_client], line);
+       else {
+               vty_out(vty, "Client not found\n");
+               ret = CMD_WARNING;
+       }
+
+       return ret;
+}
+
 /*
  * Retrieve all running config from daemons and parse it with the vtysh config
  * parser. Returned output is not displayed to the user.