diff options
Diffstat (limited to 'vtysh')
-rw-r--r-- | vtysh/vtysh.c | 82 | ||||
-rw-r--r-- | vtysh/vtysh.h | 4 | ||||
-rw-r--r-- | vtysh/vtysh_config.c | 43 | ||||
-rw-r--r-- | vtysh/vtysh_main.c | 15 | ||||
-rw-r--r-- | vtysh/vtysh_user.c | 25 | ||||
-rw-r--r-- | vtysh/vtysh_user.h | 3 |
6 files changed, 93 insertions, 79 deletions
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 64c1b549..a1f65190 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -30,6 +30,7 @@ #include <readline/readline.h> #include <readline/history.h> +#include "command_execute.h" #include "command.h" #include "memory.h" #include "vtysh/vtysh.h" @@ -37,7 +38,7 @@ #include "bgpd/bgp_vty.h" /* Struct VTY. */ -struct vty *vty; +static struct vty* vtysh_vty; /* VTY shell pager name. */ char *vtysh_pager_name = NULL; @@ -51,13 +52,13 @@ struct vtysh_client const char *path; } vtysh_client[] = { - { .fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA, .path = ZEBRA_VTYSH_PATH}, - { .fd = -1, .name = "ripd", .flag = VTYSH_RIPD, .path = RIP_VTYSH_PATH}, + { .fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA, .path = ZEBRA_VTYSH_PATH}, + { .fd = -1, .name = "ripd", .flag = VTYSH_RIPD, .path = RIP_VTYSH_PATH}, { .fd = -1, .name = "ripngd", .flag = VTYSH_RIPNGD, .path = RIPNG_VTYSH_PATH}, - { .fd = -1, .name = "ospfd", .flag = VTYSH_OSPFD, .path = OSPF_VTYSH_PATH}, + { .fd = -1, .name = "ospfd", .flag = VTYSH_OSPFD, .path = OSPF_VTYSH_PATH}, { .fd = -1, .name = "ospf6d", .flag = VTYSH_OSPF6D, .path = OSPF6_VTYSH_PATH}, - { .fd = -1, .name = "bgpd", .flag = VTYSH_BGPD, .path = BGP_VTYSH_PATH}, - { .fd = -1, .name = "isisd", .flag = VTYSH_ISISD, .path = ISIS_VTYSH_PATH}, + { .fd = -1, .name = "bgpd", .flag = VTYSH_BGPD, .path = BGP_VTYSH_PATH}, + { .fd = -1, .name = "isisd", .flag = VTYSH_ISISD, .path = ISIS_VTYSH_PATH}, }; #define VTYSH_INDEX_MAX (sizeof(vtysh_client)/sizeof(vtysh_client[0])) @@ -250,7 +251,7 @@ vtysh_client_execute (struct vtysh_client *vclient, const char *line, FILE *fp) } } -void +static void vtysh_exit_ripd_only (void) { if (ripd_client) @@ -277,34 +278,34 @@ vtysh_execute_func (const char *line, int pager) { int ret, cmd_stat; u_int i; - struct cmd_element *cmd; + struct cmd_command *cmd; FILE *fp = NULL; int closepager = 0; int tried = 0; int saved_ret, saved_node; /* TODO: how well does vtysh_execute_func work ?? -- esp. qpthreads_enabled */ - vty->buf = line ; + vtysh_vty->buf = line ; - saved_ret = ret = cmd_execute_command (vty, cmd_parse_completion, &cmd); + saved_ret = ret = cmd_execute_command (vtysh_vty, cmd_parse_standard, &cmd); if ((ret == CMD_SUCCESS) && (cmd == NULL)) return ret ; /* quit if nothing to do ??? */ - saved_node = vty->node; + saved_node = vtysh_vty->node; /* If command doesn't succeeded in current node, try to walk up in node tree. - * Changing vty->node is enough to try it just out without actual walkup in - * the vtysh. */ + * Changing vtysh_vty->node is enough to try it just out without actual + * walkup in the vtysh. */ while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING - && vty->node > CONFIG_NODE) + && vtysh_vty->node > CONFIG_NODE) { - vty->node = node_parent(vty->node); - ret = cmd_execute_command (vty, cmd_parse_completion, &cmd); + vtysh_vty->node = cmd_node_parent(vtysh_vty->node); + ret = cmd_execute_command (vtysh_vty, cmd_parse_standard, &cmd); tried++; } - vty->node = saved_node; + vtysh_vty->node = saved_node; /* If command succeeded in any other node than current (tried > 0) we have * to move into node in the vtysh where it succeeded. */ @@ -338,7 +339,7 @@ vtysh_execute_func (const char *line, int pager) switch (ret) { case CMD_WARNING: - if (vty->type == VTY_FILE) + if (vtysh_vty->type == VTY_FILE) fprintf (stdout,"Warning...\n"); break; case CMD_ERR_AMBIGUOUS: @@ -382,16 +383,16 @@ vtysh_execute_func (const char *line, int pager) { line = "end"; - vty->buf = line ; + vtysh_vty->buf = line ; - ret = cmd_execute_command (vty, cmd_parse_completion, &cmd); + ret = cmd_execute_command (vtysh_vty, cmd_parse_standard, &cmd); if (ret != CMD_SUCCESS_DAEMON) break; } else if (cmd->func) { - (*cmd->func) (cmd, vty, 0, NULL); + (*cmd->func) (cmd, vtysh_vty, 0, NULL); break; } } @@ -410,7 +411,7 @@ vtysh_execute_func (const char *line, int pager) break; if (cmd->func) - (*cmd->func) (cmd, vty, 0, NULL); + (*cmd->func) (cmd, vtysh_vty, 0, NULL); } } if (pager && vtysh_pager_name && fp && closepager) @@ -441,12 +442,12 @@ int vtysh_config_from_file (struct vty *vty, FILE *fp) { int ret; - struct cmd_element *cmd; + struct cmd_command *cmd; /* TODO: (1) allocate buffer for vty->buf (2) what about CMD_QUEUED ?? */ - while (fgets (vty->buf, VTY_BUFSIZ, fp)) + while (fgets (vty->buf, 2000, fp)) { /* Execute configuration command : this is strict match. */ ret = cmd_execute_command(vty, cmd_parse_strict, &cmd); @@ -524,7 +525,7 @@ vtysh_config_from_file (struct vty *vty, FILE *fp) } /* We don't care about the point of the cursor when '?' is typed. */ -int +static int vtysh_rl_describe (void) { int ret; @@ -546,7 +547,7 @@ vtysh_rl_describe (void) if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1])) vector_set (vline, '\0'); - describe = cmd_describe_command (vline, vty->node, &ret); + describe = cmd_describe_command (vline, vtysh_vty->node, &ret); fprintf (stdout,"\n"); @@ -591,14 +592,14 @@ vtysh_rl_describe (void) if (desc->cmd[0] == '\0') continue; - if (! desc->str) + if (! desc->doc) fprintf (stdout," %-s\n", desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd); else fprintf (stdout," %-*s %s\n", width, desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd, - desc->str); + desc->doc); } cmd_free_strvec (vline); @@ -626,7 +627,7 @@ command_generator (const char *text, int state) { index = 0; - if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE) + if (vtysh_vty->node == AUTH_NODE || vtysh_vty->node == AUTH_ENABLE_NODE) return NULL; vline = cmd_make_strvec (rl_line_buffer); @@ -636,7 +637,7 @@ command_generator (const char *text, int state) if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1])) vector_set (vline, '\0'); - matched = cmd_complete_command (vline, vty->node, &complete_status); + matched = cmd_complete_command (vline, vtysh_vty->node, &complete_status); } if (matched && matched[index]) @@ -671,7 +672,7 @@ vtysh_completion (char *text, int start, int end) vector vline; char **matched = NULL; - if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE) + if (vtysh_vty->node == AUTH_NODE || vtysh_vty->node == AUTH_ENABLE_NODE) return NULL; vline = cmd_make_strvec (rl_line_buffer); @@ -682,7 +683,7 @@ vtysh_completion (char *text, int start, int end) if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1])) vector_set (vline, '\0'); - matched = cmd_complete_command (vline, vty, &ret); + matched = cmd_complete_command (vline, vtysh_vty, &ret); cmd_free_strvec (vline); @@ -791,17 +792,17 @@ static struct cmd_node keychain_key_node = extern struct cmd_node vty_node; /* When '^Z' is received from vty, move down to the enable mode. */ -int +static int vtysh_end (void) { - switch (vty->node) + switch (vtysh_vty->node) { case VIEW_NODE: case ENABLE_NODE: /* Nothing to do. */ break; default: - vty->node = ENABLE_NODE; + vtysh_vty->node = ENABLE_NODE; break; } return CMD_SUCCESS; @@ -2196,17 +2197,17 @@ vtysh_prompt (void) hostname = names.nodename; } - snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname); + snprintf (buf, sizeof buf, cmd_prompt (vtysh_vty->node), hostname); return buf; } -void +struct vty* vtysh_init_vty (void) { - /* Make vty structure. */ - vty = vty_open(VTY_SHELL); - vty->node = VIEW_NODE; + /* Make vtysh_vty structure. */ + vtysh_vty = vty_open(VTY_SHELL); + vtysh_vty->node = VIEW_NODE; /* Initialize commands. */ cmd_init (0); @@ -2437,4 +2438,5 @@ vtysh_init_vty (void) install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd); install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd); + return vtysh_vty ; } diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h index e711d593..820e5506 100644 --- a/vtysh/vtysh.h +++ b/vtysh/vtysh.h @@ -36,7 +36,7 @@ /* vtysh local configuration file. */ #define VTYSH_DEFAULT_CONFIG "vtysh.conf" -void vtysh_init_vty (void); +struct vty* vtysh_init_vty (void); void vtysh_init_cmd (void); extern int vtysh_connect_all (const char *optional_daemon_name); void vtysh_readline_init (void); @@ -64,6 +64,4 @@ void vtysh_pager_init (void); /* Child process execution flag. */ extern int execute_flag; -extern struct vty *vty; - #endif /* VTYSH_H */ diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c index 15938f43..aed3a91c 100644 --- a/vtysh/vtysh_config.c +++ b/vtysh/vtysh_config.c @@ -47,19 +47,19 @@ struct config struct list *config_top; -int -line_cmp (char *c1, char *c2) +static int +line_cmp (const char *c1, const char *c2) { return strcmp (c1, c2); } -void +static void line_del (char *line) { XFREE (MTYPE_VTYSH_CONFIG_LINE, line); } -struct config * +static struct config * config_new () { struct config *config; @@ -67,13 +67,13 @@ config_new () return config; } -int +static int config_cmp (struct config *c1, struct config *c2) { return strcmp (c1->name, c2->name); } -void +static void config_del (struct config* config) { list_delete (config->line); @@ -82,7 +82,7 @@ config_del (struct config* config) XFREE (MTYPE_VTYSH_CONFIG, config); } -struct config * +static struct config * config_get (int index, const char *line) { struct config *config; @@ -121,13 +121,13 @@ config_get (int index, const char *line) return config; } -void +static void config_add_line (struct list *config, const char *line) { listnode_add (config, XSTRDUP (MTYPE_VTYSH_CONFIG_LINE, line)); } -void +static void config_add_line_uniq (struct list *config, const char *line) { struct listnode *node, *nnode; @@ -141,7 +141,7 @@ config_add_line_uniq (struct list *config, const char *line) listnode_add_sort (config, XSTRDUP (MTYPE_VTYSH_CONFIG_LINE, line)); } -void +static void vtysh_config_parse_line (const char *line) { char c; @@ -285,12 +285,19 @@ vtysh_config_parse (char *line) /* Macro to check delimiter is needed between each configuration line * or not. */ -#define NO_DELIMITER(I) \ - ((I) == ACCESS_NODE || (I) == PREFIX_NODE || (I) == IP_NODE \ - || (I) == AS_LIST_NODE || (I) == COMMUNITY_LIST_NODE || \ - (I) == ACCESS_IPV6_NODE || (I) == PREFIX_IPV6_NODE \ - || (I) == SERVICE_NODE || (I) == FORWARDING_NODE || (I) == DEBUG_NODE \ - || (I) == AAA_NODE) +#define NO_DELIMITER(I) ( \ + (I) == ACCESS_NODE || \ + (I) == PREFIX_NODE || \ + (I) == IP_NODE || \ + (I) == AS_LIST_NODE || \ + (I) == COMMUNITY_LIST_NODE || \ + (I) == ACCESS_IPV6_NODE || \ + (I) == PREFIX_IPV6_NODE || \ + (I) == SERVICE_NODE || \ + (I) == FORWARDING_NODE || \ + (I) == DEBUG_NODE || \ + (I) == AAA_NODE || \ + 0 ) /* Display configuration to file pointer. */ void @@ -365,7 +372,7 @@ vtysh_read_file (FILE *confp) vtysh_execute_no_pager ("end"); vtysh_execute_no_pager ("disable"); - vty_close (vty); + vty_close_final(vty); if (ret != CMD_SUCCESS) { @@ -396,7 +403,7 @@ vtysh_read_config (char *config_default_dir) vtysh_read_file (confp); fclose (confp); - host_config_set (config_default_dir); + cmd_host_config_set (config_default_dir); return (0); } diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index 4a315a5c..c576d3e0 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -63,7 +63,7 @@ struct thread_master *master; FILE *logfile; /* SIGTSTP handler. This function care user's ^Z input. */ -void +static void sigtstp (int sig) { /* Execute "end" command. */ @@ -84,7 +84,7 @@ sigtstp (int sig) } /* SIGINT handler. This function care user's ^Z input. */ -void +static void sigint (int sig) { /* Check this process is not child process. */ @@ -98,7 +98,7 @@ sigint (int sig) /* Signale wrapper for vtysh. We don't use sigevent because * vtysh doesn't use threads. TODO */ -RETSIGTYPE * +static RETSIGTYPE * vtysh_signal_set (int signo, void (*func)(int)) { int ret; @@ -121,7 +121,7 @@ vtysh_signal_set (int signo, void (*func)(int)) } /* Initialization of signal handles. */ -void +static void vtysh_signal_init () { vtysh_signal_set (SIGINT, sigint); @@ -168,7 +168,7 @@ struct option longopts[] = }; /* Read a string, and return a pointer to it. Returns NULL on EOF. */ -char * +static char * vtysh_rl_gets () { HIST_ENTRY *last; @@ -202,7 +202,7 @@ static void log_it(const char *line) { time_t t = time(NULL); struct tm *tmp = localtime(&t); - char *user = getenv("USER") ? : "boot"; + const char *user = getenv("USER") ? : "boot"; char tod[64]; strftime(tod, sizeof tod, "%Y%m%d-%H:%M.%S", tmp); @@ -214,6 +214,7 @@ static void log_it(const char *line) int main (int argc, char **argv, char **env) { + struct vty* vty ; char *p; int opt; int dryrun = 0; @@ -292,7 +293,7 @@ main (int argc, char **argv, char **env) vtysh_signal_init (); /* Make vty structure and register commands. */ - vtysh_init_vty (); + vty = vtysh_init_vty (); vtysh_init_cmd (); vtysh_user_init (); vtysh_config_init (); diff --git a/vtysh/vtysh_user.c b/vtysh/vtysh_user.c index 58676c10..5dd50bb7 100644 --- a/vtysh/vtysh_user.c +++ b/vtysh/vtysh_user.c @@ -21,6 +21,7 @@ #include <zebra.h> #include <lib/version.h> +#include <vtysh_user.h> #include <pwd.h> @@ -98,19 +99,21 @@ struct vtysh_user struct list *userlist; -struct vtysh_user * +static struct vtysh_user * user_new () { return XCALLOC (0, sizeof (struct vtysh_user)); } -void +static void user_free (struct vtysh_user *user) __attribute__((unused)) ; + +static void user_free (struct vtysh_user *user) { XFREE (0, user); } -struct vtysh_user * +static struct vtysh_user * user_lookup (const char *name) { struct listnode *node, *nnode; @@ -124,8 +127,10 @@ user_lookup (const char *name) return NULL; } -void -user_config_write () +static void user_config_write (void) __attribute__((unused)) ; + +static void +user_config_write (void) { struct listnode *node, *nnode; struct vtysh_user *user; @@ -137,7 +142,7 @@ user_config_write () } } -struct vtysh_user * +static struct vtysh_user * user_get (const char *name) { struct vtysh_user *user; @@ -165,8 +170,8 @@ DEFUN (username_nopassword, return CMD_SUCCESS; } -int -vtysh_auth () +extern int +vtysh_auth(void) { struct vtysh_user *user; struct passwd *passwd; @@ -186,8 +191,8 @@ vtysh_auth () return 0; } -void -vtysh_user_init () +extern void +vtysh_user_init(void) { userlist = list_new (); install_element (CONFIG_NODE, &username_nopassword_cmd); diff --git a/vtysh/vtysh_user.h b/vtysh/vtysh_user.h index 8d0a4cf6..c02cfede 100644 --- a/vtysh/vtysh_user.h +++ b/vtysh/vtysh_user.h @@ -22,6 +22,7 @@ #ifndef _VTYSH_USER_H #define _VTYSH_USER_H -int vtysh_auth (); +extern int vtysh_auth(void) ; +extern void vtysh_user_init(void) ; #endif /* _VTYSH_USER_H */ |