From 2d96ff08dd5151fc091db7c6fa9196ac8ae769f8 Mon Sep 17 00:00:00 2001 From: Stephen Worley Date: Thu, 13 Jun 2019 17:29:33 -0400 Subject: [PATCH] vtysh: Execute command on client by name only Add static function path for exectuting a command on a client daemon via a string of its name only. Signed-off-by: Stephen Worley --- vtysh/vtysh.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 1d5fa8cbc..2160e4054 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -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. -- 2.39.5