DEFINE_MTYPE_STATIC(MVTYSH, VTYSH_CMD, "Vtysh cmd copy");
/* Struct VTY. */
-struct vty *vty;
+struct vty *gvty;
/* VTY shell pager name. */
char *vtysh_pager_name = NULL;
static void vclient_close(struct vtysh_client *vclient)
{
if (vclient->fd >= 0) {
- if (vty->of)
- vty_out(vty,
+ if (gvty->of)
+ vty_out(gvty,
"Warning: closing connection to %s because of an I/O error!\n",
vclient->name);
close(vclient->fd);
vclient, bufvalid, buf + bufsz - bufvalid - 1, pass_fd);
if (nread <= 0) {
- if (vty->of)
- vty_out(vty,
+ if (gvty->of)
+ vty_out(gvty,
"vtysh: error reading from %s: %s (%d)",
vclient->name, safe_strerror(errno),
errno);
/* eol is at line end now, either \n => \0 or \0\0\0 */
assert(eol && eol <= bufvalid);
- if (vty->of)
- vty_out(vty, "%s\n", buf);
+ if (gvty->of)
+ vty_out(gvty, "%s\n", buf);
callback(cbarg, buf);
/* else if no callback, dump raw */
if (!callback) {
- if (vty->of)
- vty_out(vty, "%s", buf);
+ if (gvty->of)
+ vty_out(gvty, "%s", buf);
memmove(buf, buf + textlen, bufvalid - buf - textlen);
bufvalid -= textlen;
if (end)
rc_all = rc;
}
}
- if (wrong_instance && !correct_instance && vty->of) {
- vty_out(vty,
+ if (wrong_instance && !correct_instance && gvty->of) {
+ vty_out(gvty,
"%% [%s]: command ignored as it targets an instance that is not running\n",
head_client->name);
rc_all = CMD_WARNING_CONFIG_FAILED;
if (idx_client != -1)
ret = vtysh_client_execute(&vtysh_client[idx_client], line);
else {
- vty_out(vty, "Client not found\n");
+ vty_out(gvty, "Client not found\n");
ret = CMD_WARNING;
}
return;
/* suppress output to user */
- vty->of_saved = vty->of;
- vty->of = NULL;
+ gvty->of_saved = gvty->of;
+ gvty->of = NULL;
vtysh_client_run_all(head_client, line, 1, vtysh_config_parse_line,
NULL);
- vty->of = vty->of_saved;
+ gvty->of = gvty->of_saved;
}
/* Command execution over the vty interface. */
char ts[48];
(void)frr_timestamp(3, ts, sizeof(ts));
- vty_out(vty, "%% %s\n\n", ts);
+ vty_out(gvty, "%% %s\n\n", ts);
}
- saved_ret = ret = cmd_execute(vty, line, &cmd, 1);
- saved_node = vty->node;
+ saved_ret = ret = cmd_execute(gvty, line, &cmd, 1);
+ saved_node = gvty->node;
/*
* If command doesn't succeeded in current node, try to walk up in node
while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON
&& ret != CMD_WARNING && ret != CMD_WARNING_CONFIG_FAILED
&& ret != CMD_ERR_AMBIGUOUS && ret != CMD_ERR_INCOMPLETE
- && vty->node > CONFIG_NODE) {
- vty->node = node_parent(vty->node);
- ret = cmd_execute(vty, line, &cmd, 1);
+ && gvty->node > CONFIG_NODE) {
+ gvty->node = node_parent(gvty->node);
+ ret = cmd_execute(gvty, line, &cmd, 1);
tried++;
}
- vty->node = saved_node;
+ gvty->node = saved_node;
/*
* If command succeeded in any other node than current (tried > 0) we
switch (ret) {
case CMD_WARNING:
case CMD_WARNING_CONFIG_FAILED:
- if (vty->type == VTY_FILE)
- vty_out(vty, "Warning...\n");
+ if (gvty->type == VTY_FILE)
+ vty_out(gvty, "Warning...\n");
break;
case CMD_ERR_AMBIGUOUS:
- vty_out(vty, "%% Ambiguous command: %s\n", line);
+ vty_out(gvty, "%% Ambiguous command: %s\n", line);
break;
case CMD_ERR_NO_MATCH:
- vty_out(vty, "%% Unknown command: %s\n", line);
+ vty_out(gvty, "%% Unknown command: %s\n", line);
break;
case CMD_ERR_INCOMPLETE:
- vty_out(vty, "%% Command incomplete: %s\n", line);
+ vty_out(gvty, "%% Command incomplete: %s\n", line);
break;
case CMD_SUCCESS_DAEMON: {
/*
* cause any problem but is really ugly.
*/
if (pager && strncmp(line, "exit", 4))
- vty_open_pager(vty);
+ vty_open_pager(gvty);
if (!strcmp(cmd->string, "configure")) {
for (i = 0; i < array_size(vtysh_client); i++) {
if (vline == NULL) {
- if (vty->is_paged)
- vty_close_pager(vty);
+ if (gvty->is_paged)
+ vty_close_pager(gvty);
return CMD_SUCCESS;
}
- ret = cmd_execute_command(vline, vty, &cmd, 1);
+ ret = cmd_execute_command(vline, gvty, &cmd, 1);
cmd_free_strvec(vline);
if (ret != CMD_SUCCESS_DAEMON)
break;
} else if (cmd->func) {
- (*cmd->func)(cmd, vty, 0, NULL);
+ (*cmd->func)(cmd, gvty, 0, NULL);
break;
}
}
break;
if (cmd->func)
- (*cmd->func)(cmd, vty, 0, NULL);
+ (*cmd->func)(cmd, gvty, 0, NULL);
}
}
- if (vty->is_paged)
- vty_close_pager(vty);
+ if (gvty->is_paged)
+ vty_close_pager(gvty);
return cmd_stat;
}
} else if (input_len && isspace((unsigned char)input[input_len - 1]))
vector_set(vline, NULL);
- describe = cmd_describe_command(vline, vty, &ret);
+ describe = cmd_describe_command(vline, gvty, &ret);
/* Ambiguous and no match error. */
switch (ret) {
case CMD_ERR_AMBIGUOUS:
cmd_free_strvec(vline);
vector_free(describe);
- vty_out(vty, "%% Ambiguous command.\n");
+ vty_out(gvty, "%% Ambiguous command.\n");
rl_on_new_line();
return 0;
case CMD_ERR_NO_MATCH:
cmd_free_strvec(vline);
if (describe)
vector_free(describe);
- vty_out(vty, "%% There is no matched command.\n");
+ vty_out(gvty, "%% There is no matched command.\n");
rl_on_new_line();
return 0;
}
for (i = 0; i < vector_active(describe); i++)
if ((token = vector_slot(describe, i)) != NULL) {
if (!token->desc)
- vty_out(vty, " %-s\n", token->text);
+ vty_out(gvty, " %-s\n", token->text);
else
- vty_out(vty, " %-*s %s\n", width, token->text,
+ vty_out(gvty, " %-*s %s\n", width, token->text,
token->desc);
if (IS_VARYING_TOKEN(token->type)) {
char *ac = cmd_variable_comp2str(
varcomps, cols);
- vty_out(vty, "%s\n", ac);
+ vty_out(gvty, "%s\n", ac);
XFREE(MTYPE_TMP, ac);
}
{
int ret;
- vty_out(vty, "\n");
+ vty_out(gvty, "\n");
ret = vtysh_process_questionmark(rl_line_buffer, rl_end);
rl_on_new_line();
if (!state) {
index = 0;
- if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
+ if (gvty->node == AUTH_NODE || gvty->node == AUTH_ENABLE_NODE)
return NULL;
vline = cmd_make_strvec(rl_line_buffer);
isspace((unsigned char)rl_line_buffer[rl_end - 1]))
vector_set(vline, NULL);
- matched = cmd_complete_command(vline, vty, &complete_status);
+ matched = cmd_complete_command(vline, gvty, &complete_status);
cmd_free_strvec(vline);
}
/* When '^Z' is received from vty, move down to the enable mode. */
static int vtysh_end(void)
{
- switch (vty->node) {
+ switch (gvty->node) {
case VIEW_NODE:
case ENABLE_NODE:
/* Nothing to do. */
break;
default:
- vty->node = ENABLE_NODE;
+ gvty->node = ENABLE_NODE;
break;
}
return CMD_SUCCESS;
strlcat(command_line, " json", sizeof(command_line));
if (json)
- vty_out(vty, "{");
+ vty_out(gvty, "{");
for (i = 0; i < array_size(vtysh_client); i++) {
const struct vtysh_client *client = &vtysh_client[i];
continue;
if (json && !first)
- vty_out(vty, ",");
+ vty_out(gvty, ",");
else
first = false;
if (json)
- vty_out(vty, "\"%s\":", vtysh_client[i].name);
+ vty_out(gvty, "\"%s\":", vtysh_client[i].name);
vtysh_client_execute_name(vtysh_client[i].name, command_line);
}
if (json)
- vty_out(vty, "}\n");
+ vty_out(gvty, "}\n");
}
DEFPY (show_route_map,
strlcat(command_line, " json", sizeof(command_line));
if (json)
- vty_out(vty, "{");
+ vty_out(gvty, "{");
for (i = 0; i < array_size(vtysh_client); i++) {
const struct vtysh_client *client = &vtysh_client[i];
continue;
if (json && !first)
- vty_out(vty, ",");
+ vty_out(gvty, ",");
else
first = false;
if (json)
- vty_out(vty, "\"%s\":", vtysh_client[i].name);
+ vty_out(gvty, "\"%s\":", vtysh_client[i].name);
vtysh_client_execute_name(vtysh_client[i].name, command_line);
}
if (json)
- vty_out(vty, "}\n");
+ vty_out(gvty, "}\n");
}
DEFPY (show_ip_prefix_list,
strlcat(command_line, access_list, sizeof(command_line));
if (json) {
strlcat(command_line, " json", sizeof(command_line));
- vty_out(vty, "{");
+ vty_out(gvty, "{");
}
for (i = 0; i < array_size(vtysh_client); i++) {
continue;
if (json && !first)
- vty_out(vty, ",");
+ vty_out(gvty, ",");
else
first = false;
if (json)
- vty_out(vty, "\"%s\":", vtysh_client[i].name);
+ vty_out(gvty, "\"%s\":", vtysh_client[i].name);
vtysh_client_execute_name(vtysh_client[i].name, command_line);
}
if (json)
- vty_out(vty, "}\n");
+ vty_out(gvty, "}\n");
}
DEFPY (show_ip_access_list,
/* Move current configuration file to backup config file. */
if (unlink(integrate_sav) != 0 && errno != ENOENT)
- vty_out(vty, "Unlink failed for %s: %s\n", integrate_sav,
+ vty_out(gvty, "Unlink failed for %s: %s\n", integrate_sav,
strerror(errno));
if (rename(fbackup, integrate_sav) != 0 && errno != ENOENT)
- vty_out(vty, "Error renaming %s to %s: %s\n", fbackup,
+ vty_out(gvty, "Error renaming %s to %s: %s\n", fbackup,
integrate_sav, strerror(errno));
free(integrate_sav);
}
struct stat st;
int err = 0;
- vty_out(vty, "Building Configuration...\n");
+ vty_out(gvty, "Building Configuration...\n");
backup_config_file(frr_config);
fp = fopen(frr_config, "w");
if (fp == NULL) {
- vty_out(vty,
+ vty_out(gvty,
"%% Error: failed to open configuration file %s: %s\n",
frr_config, safe_strerror(errno));
return CMD_WARNING_CONFIG_FAILED;
vtysh_client_config(&vtysh_client[i], line);
vtysh_config_write();
- vty->of_saved = vty->of;
- vty->of = fp;
+ gvty->of_saved = gvty->of;
+ gvty->of = fp;
vtysh_config_dump();
- vty->of = vty->of_saved;
+ gvty->of = gvty->of_saved;
if (fchmod(fd, CONFIGFILE_MASK) != 0) {
printf("%% Warning: can't chmod configuration file %s: %s\n",
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
/* prompt formatting has a %s in the cmd_node prompt string. */
- snprintf(buf, sizeof(buf), cmd_prompt(vty->node), cmd_hostname_get());
+ snprintf(buf, sizeof(buf), cmd_prompt(gvty->node), cmd_hostname_get());
#pragma GCC diagnostic pop
return buf;
}
snprintf(accmd, sizeof(accmd), "autocomplete %d %s %s", token->type,
token->text, token->varname ? token->varname : "-");
- vty->of_saved = vty->of;
- vty->of = NULL;
+ gvty->of_saved = gvty->of;
+ gvty->of = NULL;
for (i = 0; i < array_size(vtysh_client); i++)
vtysh_client_run_all(&vtysh_client[i], accmd, 1, vtysh_ac_line,
comps);
- vty->of = vty->of_saved;
+ gvty->of = gvty->of_saved;
}
static const struct cmd_variable_handler vtysh_var_handler[] = {
void vtysh_uninit(void)
{
- if (vty->of != stdout)
- fclose(vty->of);
+ if (gvty->of != stdout)
+ fclose(gvty->of);
}
void vtysh_init_vty(void)
stderr_stdout_same = true;
/* Make vty structure. */
- vty = vty_new();
- vty->type = VTY_SHELL;
- vty->node = VIEW_NODE;
+ gvty = vty_new();
+ gvty->type = VTY_SHELL;
+ gvty->node = VIEW_NODE;
/* set default output */
- vty->of = stdout;
+ gvty->of = stdout;
vtysh_pager_envdef(false);
/* Initialize commands. */