diff options
Diffstat (limited to 'vtysh')
-rw-r--r-- | vtysh/Makefile.am | 4 | ||||
-rw-r--r-- | vtysh/vtysh.c | 48 | ||||
-rw-r--r-- | vtysh/vtysh.h | 4 | ||||
-rw-r--r-- | vtysh/vtysh_main.c | 59 | ||||
-rw-r--r-- | vtysh/vtysh_user.c | 5 |
5 files changed, 86 insertions, 34 deletions
diff --git a/vtysh/Makefile.am b/vtysh/Makefile.am index 791d95dd..e4d7d885 100644 --- a/vtysh/Makefile.am +++ b/vtysh/Makefile.am @@ -21,7 +21,9 @@ dist_examples_DATA = vtysh.conf.sample EXTRA_DIST = extract.pl -vtysh_cmd_FILES = $(top_srcdir)/bgpd/*.c $(top_srcdir)/isisd/*.c \ +vtysh_cmd_FILES = $(top_srcdir)/bgpd/*.c \ + $(top_srcdir)/isisd/isisd.c $(top_srcdir)/isisd/isis_spf.c \ + $(top_srcdir)/isisd/isis_circuit.c \ $(top_srcdir)/ospfd/*.c $(top_srcdir)/ospf6d/*.c \ $(top_srcdir)/ripd/*.c $(top_srcdir)/ripngd/*.c \ $(top_srcdir)/lib/keychain.c $(top_srcdir)/lib/routemap.c \ diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index bad05d98..bff06323 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -272,7 +272,7 @@ vtysh_pager_init (void) } /* Command execution over the vty interface. */ -static void +static int vtysh_execute_func (const char *line, int pager) { int ret, cmd_stat; @@ -288,7 +288,7 @@ vtysh_execute_func (const char *line, int pager) vline = cmd_make_strvec (line); if (vline == NULL) - return; + return CMD_SUCCESS; saved_ret = ret = cmd_execute_command (vline, vty, &cmd, 1); saved_node = vty->node; @@ -336,6 +336,7 @@ vtysh_execute_func (const char *line, int pager) cmd_free_strvec (vline); + cmd_stat = ret; switch (ret) { case CMD_WARNING: @@ -394,7 +395,7 @@ vtysh_execute_func (const char *line, int pager) } fp = NULL; } - return; + return CMD_SUCCESS; } ret = cmd_execute_command (vline, vty, &cmd, 1); @@ -435,18 +436,19 @@ vtysh_execute_func (const char *line, int pager) } fp = NULL; } + return cmd_stat; } -void +int vtysh_execute_no_pager (const char *line) { - vtysh_execute_func (line, 0); + return vtysh_execute_func (line, 0); } -void +int vtysh_execute (const char *line) { - vtysh_execute_func (line, 1); + return vtysh_execute_func (line, 1); } /* Configration make from file. */ @@ -711,97 +713,97 @@ vtysh_completion (char *text, int start, int end) #endif /* Vty node structures. */ -struct cmd_node bgp_node = +static struct cmd_node bgp_node = { BGP_NODE, "%s(config-router)# ", }; -struct cmd_node rip_node = +static struct cmd_node rip_node = { RIP_NODE, "%s(config-router)# ", }; -struct cmd_node isis_node = +static struct cmd_node isis_node = { ISIS_NODE, "%s(config-router)# ", }; -struct cmd_node interface_node = +static struct cmd_node interface_node = { INTERFACE_NODE, "%s(config-if)# ", }; -struct cmd_node rmap_node = +static struct cmd_node rmap_node = { RMAP_NODE, "%s(config-route-map)# " }; -struct cmd_node zebra_node = +static struct cmd_node zebra_node = { ZEBRA_NODE, "%s(config-router)# " }; -struct cmd_node bgp_vpnv4_node = +static struct cmd_node bgp_vpnv4_node = { BGP_VPNV4_NODE, "%s(config-router-af)# " }; -struct cmd_node bgp_ipv4_node = +static struct cmd_node bgp_ipv4_node = { BGP_IPV4_NODE, "%s(config-router-af)# " }; -struct cmd_node bgp_ipv4m_node = +static struct cmd_node bgp_ipv4m_node = { BGP_IPV4M_NODE, "%s(config-router-af)# " }; -struct cmd_node bgp_ipv6_node = +static struct cmd_node bgp_ipv6_node = { BGP_IPV6_NODE, "%s(config-router-af)# " }; -struct cmd_node bgp_ipv6m_node = +static struct cmd_node bgp_ipv6m_node = { BGP_IPV6M_NODE, "%s(config-router-af)# " }; -struct cmd_node ospf_node = +static struct cmd_node ospf_node = { OSPF_NODE, "%s(config-router)# " }; -struct cmd_node ripng_node = +static struct cmd_node ripng_node = { RIPNG_NODE, "%s(config-router)# " }; -struct cmd_node ospf6_node = +static struct cmd_node ospf6_node = { OSPF6_NODE, "%s(config-ospf6)# " }; -struct cmd_node keychain_node = +static struct cmd_node keychain_node = { KEYCHAIN_NODE, "%s(config-keychain)# " }; -struct cmd_node keychain_key_node = +static struct cmd_node keychain_key_node = { KEYCHAIN_KEY_NODE, "%s(config-keychain-key)# " diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h index 3ed0dd32..e711d593 100644 --- a/vtysh/vtysh.h +++ b/vtysh/vtysh.h @@ -42,8 +42,8 @@ extern int vtysh_connect_all (const char *optional_daemon_name); void vtysh_readline_init (void); void vtysh_user_init (void); -void vtysh_execute (const char *); -void vtysh_execute_no_pager (const char *); +int vtysh_execute (const char *); +int vtysh_execute_no_pager (const char *); char *vtysh_prompt (void); diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index 51f376c7..23ff64f7 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -58,6 +58,9 @@ static char *line_read; /* Master of threads. */ struct thread_master *master; +/* Command logging */ +FILE *logfile; + /* SIGTSTP handler. This function care user's ^Z input. */ void sigtstp (int sig) @@ -159,6 +162,7 @@ struct option longopts[] = { "echo", no_argument, NULL, 'E'}, { "dryrun", no_argument, NULL, 'C'}, { "help", no_argument, NULL, 'h'}, + { "noerror", no_argument, NULL, 'n'}, { 0 } }; @@ -191,6 +195,18 @@ vtysh_rl_gets () return (line_read); } +static void log_it(const char *line) +{ + time_t t = time(NULL); + struct tm *tmp = localtime(&t); + char *user = getenv("USER") ? : "boot"; + char tod[64]; + + strftime(tod, sizeof tod, "%Y%m%d-%H:%M.%S", tmp); + + fprintf(logfile, "%s:%s %s\n", tod, user, line); +} + /* VTY shell main routine. */ int main (int argc, char **argv, char **env) @@ -206,14 +222,19 @@ main (int argc, char **argv, char **env) } *cmd = NULL; struct cmd_rec *tail = NULL; int echo_command = 0; + int no_error = 0; /* Preserve name of myself. */ progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); + /* if logging open now */ + if ((p = getenv("VTYSH_LOG")) != NULL) + logfile = fopen(p, "a"); + /* Option handling. */ while (1) { - opt = getopt_long (argc, argv, "be:c:d:EhC", longopts, 0); + opt = getopt_long (argc, argv, "be:c:d:nEhC", longopts, 0); if (opt == EOF) break; @@ -242,6 +263,9 @@ main (int argc, char **argv, char **env) case 'd': daemon_name = optarg; break; + case 'n': + no_error = 1; + break; case 'E': echo_command = 1; break; @@ -259,6 +283,7 @@ main (int argc, char **argv, char **env) /* Initialize user input buffer. */ line_read = NULL; + setlinebuf(stdout); /* Signal and others. */ vtysh_signal_init (); @@ -280,6 +305,10 @@ main (int argc, char **argv, char **env) if(dryrun) return(0); + /* Ignore error messages */ + if (no_error) + freopen("/dev/null", "w", stdout); + /* Make sure we pass authentication before proceeding. */ vtysh_auth (); @@ -298,19 +327,41 @@ main (int argc, char **argv, char **env) while (cmd != NULL) { + int ret; char *eol; while ((eol = strchr(cmd->line, '\n')) != NULL) { *eol = '\0'; + if (echo_command) - printf("%s%s\n", vtysh_prompt(), cmd->line); - vtysh_execute_no_pager(cmd->line); + printf("%s%s\n", vtysh_prompt(), cmd->line); + + if (logfile) + log_it(cmd->line); + + ret = vtysh_execute_no_pager(cmd->line); + if (!no_error && + ! (ret == CMD_SUCCESS || + ret == CMD_SUCCESS_DAEMON || + ret == CMD_WARNING)) + exit(1); + cmd->line = eol+1; } + if (echo_command) printf("%s%s\n", vtysh_prompt(), cmd->line); - vtysh_execute_no_pager (cmd->line); + + if (logfile) + log_it(cmd->line); + + ret = vtysh_execute_no_pager(cmd->line); + if (!no_error && + ! (ret == CMD_SUCCESS || + ret == CMD_SUCCESS_DAEMON || + ret == CMD_WARNING)) + exit(1); { struct cmd_rec *cr; diff --git a/vtysh/vtysh_user.c b/vtysh/vtysh_user.c index e3015056..58676c10 100644 --- a/vtysh/vtysh_user.c +++ b/vtysh/vtysh_user.c @@ -101,10 +101,7 @@ struct list *userlist; struct vtysh_user * user_new () { - struct vtysh_user *user; - user = XMALLOC (0, sizeof (struct vtysh_user)); - memset (user, 0, sizeof (struct vtysh_user)); - return user; + return XCALLOC (0, sizeof (struct vtysh_user)); } void |