summaryrefslogtreecommitdiffstats
path: root/vtysh
diff options
context:
space:
mode:
Diffstat (limited to 'vtysh')
-rw-r--r--vtysh/ChangeLog10
-rwxr-xr-xvtysh/extract.pl.in4
-rw-r--r--vtysh/vtysh.c62
-rw-r--r--vtysh/vtysh.h4
-rw-r--r--vtysh/vtysh_main.c58
-rw-r--r--vtysh/vtysh_user.c5
6 files changed, 107 insertions, 36 deletions
diff --git a/vtysh/ChangeLog b/vtysh/ChangeLog
index de62763c..af55c6f2 100644
--- a/vtysh/ChangeLog
+++ b/vtysh/ChangeLog
@@ -1,3 +1,13 @@
+2008-07-03 MIYAJIMA Mitsuharu <miyajima.mitsuharu@anchor.jp>
+
+ * extract.pl.in: Fix as-range to match CPP output.
+ * vtysh.c: Add missing router_bgp_view_cmd alias.
+
+2008-07-02 MIYAJIMA Mitsuharu <miyajima.mitsuharu@anchor.jp>
+
+ * CMD_AS_RANGE was being used inside command strings, and thus
+ not being expanded, fix by dequoting.
+
2007-06-20 Nicolas Deffayet <nicolas@deffayet.com>
* vtysh.c: (vtysh_write_terminal) Write 'end' when done,
diff --git a/vtysh/extract.pl.in b/vtysh/extract.pl.in
index 789819c6..0b9ee516 100755
--- a/vtysh/extract.pl.in
+++ b/vtysh/extract.pl.in
@@ -37,8 +37,8 @@ $ignore{'"router ripng"'} = "ignore";
$ignore{'"router ospf"'} = "ignore";
$ignore{'"router ospf <0-65535>"'} = "ignore";
$ignore{'"router ospf6"'} = "ignore";
-$ignore{'"router bgp CMD_AS_RANGE"'} = "ignore";
-$ignore{'"router bgp CMD_AS_RANGE view WORD"'} = "ignore";
+$ignore{'"router bgp " "<1-4294967295>"'} = "ignore";
+$ignore{'"router bgp " "<1-4294967295>" " view WORD"'} = "ignore";
$ignore{'"router isis WORD"'} = "ignore";
$ignore{'"router zebra"'} = "ignore";
$ignore{'"address-family ipv4"'} = "ignore";
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c
index 9f47515d..bff06323 100644
--- a/vtysh/vtysh.c
+++ b/vtysh/vtysh.c
@@ -34,6 +34,7 @@
#include "memory.h"
#include "vtysh/vtysh.h"
#include "log.h"
+#include "bgpd/bgp_vty.h"
/* Struct VTY. */
struct vty *vty;
@@ -271,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;
@@ -287,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;
@@ -335,6 +336,7 @@ vtysh_execute_func (const char *line, int pager)
cmd_free_strvec (vline);
+ cmd_stat = ret;
switch (ret)
{
case CMD_WARNING:
@@ -393,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);
@@ -434,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. */
@@ -710,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)# "
@@ -838,7 +841,7 @@ DEFUNSH (VTYSH_ALL,
DEFUNSH (VTYSH_BGPD,
router_bgp,
router_bgp_cmd,
- "router bgp CMD_AS_RANGE",
+ "router bgp " CMD_AS_RANGE,
ROUTER_STR
BGP_STR
AS_STR)
@@ -847,6 +850,16 @@ DEFUNSH (VTYSH_BGPD,
return CMD_SUCCESS;
}
+ALIAS_SH (VTYSH_BGPD,
+ router_bgp,
+ router_bgp_view_cmd,
+ "router bgp " CMD_AS_RANGE " view WORD",
+ ROUTER_STR
+ BGP_STR
+ AS_STR
+ "BGP view\n"
+ "view name\n")
+
DEFUNSH (VTYSH_BGPD,
address_family_vpnv4,
address_family_vpnv4_cmd,
@@ -2341,6 +2354,7 @@ vtysh_init_vty (void)
#endif
install_element (CONFIG_NODE, &router_isis_cmd);
install_element (CONFIG_NODE, &router_bgp_cmd);
+ install_element (CONFIG_NODE, &router_bgp_view_cmd);
install_element (BGP_NODE, &address_family_vpnv4_cmd);
install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
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 d655e073..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;
@@ -281,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 ();
@@ -299,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