frr/lib/command.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

2649 lines
65 KiB
C
Raw Permalink Normal View History

// SPDX-License-Identifier: GPL-2.0-or-later
2004-12-07 Andrew J. Schorr <ajschorr@alumni.princeton.edu> * bgp_main.c: (main) The 2nd argument to openzlog has been removed. * isis_main.c: (main) The 2nd argument to openzlog has been removed. * ospf6_main.c: (main) The 2nd argument to openzlog has been removed. Note that stdout logging will no longer be enabled by default when not running as a daemon. * ospf_main.c: (main) The 2nd argument to openzlog has been removed. * rip_main.c: (main) The 2nd argument to openzlog has been removed. * ripng_main.c: (main) The 2nd argument to openzlog has been removed. * main.c: (main) The 2nd argument to openzlog has been removed. So stdout logging will no longer be enabled by default. * irdp_main.c: (irdp_finish) Reduce severity of shutdown message from LOG_WARNING to LOG_INFO. * vtysh.c: Make several functions static instead of global. Added several commands to support destination-specific logging levels. (vtysh_completion) This function is unused, so comment it out. * basic.texi: Document new logging features. Separate basic config commands from basic VTY commands. * log.h: Replace struct zlog flags and maskpri fields with maxlvl array to support individual logging levels for each destination. Remove the 2nd argument to openzlog since the default logging config should be standardized inside the library. Replaced the zlog_set_flag and zlog_reset_flag functions with zlog_set_level. And zlog_set_file now requires an additional log_level argument. Declare zlog_proto_names for use inside command.c in the "show logging" command. Added defines useful for command construction. * log.c: (vzlog) Decide where to send the message based on the individual logging levels configured for each destination. Remove support for ZLOG_STDERR since it was never actually used. Support record-priority for terminal monitors. (zlog_signal,zlog_backtrace_sigsafe) Support destination-specific logging levels. Remove stderr support (was never used). Added support for terminal monitor logging. (_zlog_assert_failed) Increase message severity to LOG_EMERG. (openzlog) Remove 2nd argument since default config should be standardized in library. By default, terminal monitoring is set to debug, and all other logging is disabled. (zlog_set_flag,zlog_reset_flag) Removed. (zlog_set_level) New function to replace zlog_set_flag and zlog_reset_flag. Supports destination-specific logging levels. (zlog_set_file,zlog_reset_file) Support file-specific logging level. (zlog_rotate) Log an error message if fopen fails, and support new file-specific logging level. * command.h: Change DEFUN_CMD_FUNC_DECL and DEFUN_CMD_FUNC_TEXT so that command functions will be static instead of global. Remove declarations for config_exit and config_help. Define new macros DEFUNSH_ATTR, DEFUNSH_HIDDEN, and DEFUNSH_DEPRECATED so we can have deprecated commands in vtysh. Similarly, for completeness, define macros ALIAS_SH, ALIAS_SH_HIDDEN, and ALIAS_SH_DEPRECATED. Also, fix bug in ALIAS_ATTR macro (didn't matter because it was never used). * command.c: Make many functions static instead of global. (facility_name,facility_match,level_match) New functions to support enhanced destination-specific logging levels. (config_write_host) Support new destination-specific logging levels. (config_logmsg) Added new "logmsg" command to help test logging system. (show_logging) Added "show logging" command to show the current configuration of the logging system. (config_log_stdout_level) Support explicit stdout logging level. (no_config_log_stdout) Now takes optional LEVEL arg. (config_log_monitor,config_log_monitor_level,no_config_log_monitor) New commands creating new "log monitor" commands to set terminal monitoring log level. (config_log_file_level) Support explicit file logging level. (config_log_syslog_level) Support explicit syslog logging level. (config_log_facility,no_config_log_facility) Implement new "log facility" command. (cmd_init) Add hooks for new commands: "show logging", "logmsg", "log stdout <level>", "log monitor", "log monitor <level>", "no log monitor", "log file <filename> <level>", "no log file <filename> <level>", "log syslog <level>", "log facility", and "no log facility". * vty.h: Added a "level" argument to vty_log so it can support "log record-priority". Declare new function vty_log_fixed for use in signal handlers. * vty.c: (vty_log,vty_log_out) Added a "level" argument to support "log record-priority" for vty terminal monitors. (vty_down_level) Use config_exit_cmd.func instead of calling config_exit directly (since command functions will now be static instead of global). (vty_log_fixed) New function to send terminal monitor messages from inside a signal handler.
2004-12-07 16:39:31 +01:00
/*
* CLI backend interface.
*
* --
* Copyright (C) 2016 Cumulus Networks, Inc.
* Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
* Copyright (C) 2013 by Open Source Routing.
* Copyright (C) 2013 by Internet Systems Consortium, Inc. ("ISC")
*/
2002-12-13 21:15:29 +01:00
#include <zebra.h>
#include <sys/utsname.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <lib/version.h>
2002-12-13 21:15:29 +01:00
#include "command.h"
#include "debug.h"
#include "frrstr.h"
2002-12-13 21:15:29 +01:00
#include "memory.h"
#include "log.h"
#include "log_vty.h"
#include "frrevent.h"
#include "vector.h"
#include "linklist.h"
#include "vty.h"
#include "workqueue.h"
#include "vrf.h"
#include "command_match.h"
#include "command_graph.h"
#include "qobj.h"
#include "defaults.h"
#include "libfrr.h"
#include "jhash.h"
#include "hook.h"
#include "lib_errors.h"
#include "mgmt_be_client.h"
#include "mgmt_fe_client.h"
#include "northbound_cli.h"
#include "network.h"
#include "routemap.h"
#include "frrscript.h"
#include "lib/config_paths.h"
DEFINE_MTYPE_STATIC(LIB, HOST, "Host config");
DEFINE_MTYPE(LIB, COMPLETION, "Completion item");
#define item(x) \
{ \
x, #x \
}
/* clang-format off */
const struct message tokennames[] = {
item(WORD_TKN),
item(VARIABLE_TKN),
item(RANGE_TKN),
item(IPV4_TKN),
item(IPV4_PREFIX_TKN),
item(IPV6_TKN),
item(IPV6_PREFIX_TKN),
item(MAC_TKN),
item(MAC_PREFIX_TKN),
item(ASNUM_TKN),
item(FORK_TKN),
item(JOIN_TKN),
item(START_TKN),
item(END_TKN),
item(NEG_ONLY_TKN),
{0},
};
/* clang-format on */
2002-12-13 21:15:29 +01:00
/* Command vector which includes some level of command lists. Normally
each daemon maintains each own cmdvec. */
vector cmdvec = NULL;
2002-12-13 21:15:29 +01:00
/* Host information structure. */
struct host host;
/* for vtysh, put together CLI trees only when switching into node */
static bool defer_cli_tree;
/*
* Returns host.name if any, otherwise
* it returns the system hostname.
*/
const char *cmd_hostname_get(void)
{
return host.name;
}
/*
* Returns unix domainname
*/
const char *cmd_domainname_get(void)
{
return host.domainname;
}
const char *cmd_system_get(void)
{
return host.system;
}
const char *cmd_release_get(void)
{
return host.release;
}
const char *cmd_version_get(void)
{
return host.version;
}
bool cmd_allow_reserved_ranges_get(void)
{
return host.allow_reserved_ranges;
}
bgpd: Add BGP Software Version Capability Implement: https://datatracker.ietf.org/doc/html/draft-abraitis-bgp-version-capability Tested with GoBGP: ``` % ./gobgp neighbor 192.168.10.124 BGP neighbor is 192.168.10.124, remote AS 65001 BGP version 4, remote router ID 200.200.200.202 BGP state = ESTABLISHED, up for 00:01:49 BGP OutQ = 0, Flops = 0 Hold time is 3, keepalive interval is 1 seconds Configured hold time is 90, keepalive interval is 30 seconds Neighbor capabilities: multiprotocol: ipv4-unicast: advertised and received ipv6-unicast: advertised route-refresh: advertised and received extended-nexthop: advertised Local: nlri: ipv4-unicast, nexthop: ipv6 UnknownCapability(6): received UnknownCapability(9): received graceful-restart: advertised and received Local: restart time 10 sec ipv6-unicast ipv4-unicast Remote: restart time 120 sec, notification flag set ipv4-unicast, forward flag set 4-octet-as: advertised and received add-path: received Remote: ipv4-unicast: receive enhanced-route-refresh: received long-lived-graceful-restart: advertised and received Local: ipv6-unicast, restart time 10 sec ipv4-unicast, restart time 20 sec Remote: ipv4-unicast, restart time 0 sec, forward flag set fqdn: advertised and received Local: name: donatas-pc, domain: Remote: name: spine1-debian-11, domain: software-version: advertised and received Local: GoBGP/3.10.0 Remote: FRRouting/8.5-dev-MyOwnFRRVersion-gdc92f44a45-dirt cisco-route-refresh: received Message statistics: ``` FRR side: ``` root@spine1-debian-11:~# vtysh -c 'show bgp neighbor 192.168.10.17 json' | \ > jq '."192.168.10.17".neighborCapabilities.softwareVersion.receivedSoftwareVersion' "GoBGP/3.10.0" root@spine1-debian-11:~# ``` Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-02-25 08:00:23 +01:00
const char *cmd_software_version_get(void)
{
return FRR_FULL_NAME "/" FRR_VERSION;
}
static int root_on_exit(struct vty *vty);
2002-12-13 21:15:29 +01:00
/* Standard command node structures. */
static struct cmd_node auth_node = {
.name = "auth",
.node = AUTH_NODE,
.prompt = "Password: ",
2002-12-13 21:15:29 +01:00
};
static struct cmd_node view_node = {
.name = "view",
.node = VIEW_NODE,
.prompt = "%s> ",
.node_exit = root_on_exit,
2002-12-13 21:15:29 +01:00
};
static struct cmd_node auth_enable_node = {
.name = "auth enable",
.node = AUTH_ENABLE_NODE,
.prompt = "Password: ",
2002-12-13 21:15:29 +01:00
};
static struct cmd_node enable_node = {
.name = "enable",
.node = ENABLE_NODE,
.prompt = "%s# ",
.node_exit = root_on_exit,
2002-12-13 21:15:29 +01:00
};
static int config_write_host(struct vty *vty);
static struct cmd_node config_node = {
.name = "config",
.node = CONFIG_NODE,
.parent_node = ENABLE_NODE,
.prompt = "%s(config)# ",
.config_write = config_write_host,
.node_exit = vty_config_node_exit,
};
/* This is called from main when a daemon is invoked with -v or --version. */
void print_version(const char *progname)
{
printf("%s version %s\n", progname, FRR_VERSION);
printf("%s\n", FRR_COPYRIGHT);
#ifdef ENABLE_VERSION_BUILD_CONFIG
printf("configured with:\n\t%s\n", FRR_CONFIG_ARGS);
#endif
}
char *argv_concat(struct cmd_token **argv, int argc, int shift)
2002-12-13 21:15:29 +01:00
{
int cnt = MAX(argc - shift, 0);
const char *argstr[cnt + 1];
if (!cnt)
return NULL;
for (int i = 0; i < cnt; i++)
argstr[i] = argv[i + shift]->arg;
return frrstr_join(argstr, cnt, " ");
}
vector cmd_make_strvec(const char *string)
{
if (!string)
return NULL;
const char *copy = string;
/* skip leading whitespace */
while (isspace((unsigned char)*copy) && *copy != '\0')
copy++;
/* if the entire string was whitespace or a comment, return */
if (*copy == '\0' || *copy == '!' || *copy == '#')
return NULL;
vector result = frrstr_split_vec(copy, "\n\r\t ");
for (unsigned int i = 0; i < vector_active(result); i++) {
if (strlen(vector_slot(result, i)) == 0) {
XFREE(MTYPE_TMP, vector_slot(result, i));
vector_unset(result, i);
}
2002-12-13 21:15:29 +01:00
}
vector_compact(result);
return result;
}
void cmd_free_strvec(vector v)
{
frrstr_strvec_free(v);
2002-12-13 21:15:29 +01:00
}
/**
* Convenience function for accessing argv data.
*
* @param argc
* @param argv
* @param text definition snippet of the desired token
* @param index the starting index, and where to store the
* index of the found token if it exists
* @return 1 if found, 0 otherwise
*/
int argv_find(struct cmd_token **argv, int argc, const char *text, int *index)
{
int found = 0;
for (int i = *index; i < argc && found == 0; i++)
if ((found = strmatch(text, argv[i]->text)))
*index = i;
return found;
}
static unsigned int cmd_hash_key(const void *p)
{
int size = sizeof(p);
return jhash(p, size, 0);
}
static bool cmd_hash_cmp(const void *a, const void *b)
{
return a == b;
}
2002-12-13 21:15:29 +01:00
/* Install top node of command vector. */
void install_node(struct cmd_node *node)
2002-12-13 21:15:29 +01:00
{
#define CMD_HASH_STR_SIZE 256
char hash_name[CMD_HASH_STR_SIZE];
2002-12-13 21:15:29 +01:00
vector_set_index(cmdvec, node->node, node);
node->cmdgraph = graph_new();
node->cmd_vector = vector_init(VECTOR_MIN_SIZE);
// add start node
struct cmd_token *token = cmd_token_new(START_TKN, 0, NULL, NULL);
graph_new_node(node->cmdgraph, token,
(void (*)(void *)) & cmd_token_del);
snprintf(hash_name, sizeof(hash_name), "Command Hash: %s", node->name);
node->cmd_hash =
hash_create_size(16, cmd_hash_key, cmd_hash_cmp, hash_name);
2002-12-13 21:15:29 +01:00
}
/* Return prompt character of specified node. */
const char *cmd_prompt(enum node_type node)
{
struct cmd_node *cnode;
cnode = vector_slot(cmdvec, node);
return cnode->prompt;
}
void cmd_defer_tree(bool val)
{
defer_cli_tree = val;
}
2002-12-13 21:15:29 +01:00
/* Install a command into a node. */
void _install_element(enum node_type ntype, const struct cmd_element *cmd)
2002-12-13 21:15:29 +01:00
{
struct cmd_node *cnode;
/* cmd_init hasn't been called */
if (!cmdvec) {
fprintf(stderr, "%s called before cmd_init, breakage likely\n",
__func__);
return;
}
cnode = vector_lookup(cmdvec, ntype);
2002-12-13 21:15:29 +01:00
if (cnode == NULL) {
2002-12-13 21:15:29 +01:00
fprintf(stderr,
"%s[%s]:\n"
"\tnode %d does not exist.\n"
"\tplease call install_node() before install_element()\n",
cmd->name, cmd->string, ntype);
exit(EXIT_FAILURE);
2002-12-13 21:15:29 +01:00
}
if (hash_lookup(cnode->cmd_hash, (void *)cmd) != NULL) {
fprintf(stderr,
"%s[%s]:\n"
"\tnode %d (%s) already has this command installed.\n"
"\tduplicate install_element call?\n",
cmd->name, cmd->string, ntype, cnode->name);
return;
}
(void)hash_get(cnode->cmd_hash, (void *)cmd, hash_alloc_intern);
if (cnode->graph_built || !defer_cli_tree) {
struct graph *graph = graph_new();
struct cmd_token *token =
cmd_token_new(START_TKN, 0, NULL, NULL);
graph_new_node(graph, token,
(void (*)(void *)) & cmd_token_del);
cmd_graph_parse(graph, cmd);
cmd_graph_names(graph);
cmd_graph_merge(cnode->cmdgraph, graph, +1);
graph_delete_graph(graph);
cnode->graph_built = true;
}
vector_set(cnode->cmd_vector, (void *)cmd);
if (ntype == VIEW_NODE)
_install_element(ENABLE_NODE, cmd);
}
static void cmd_finalize_iter(struct hash_bucket *hb, void *arg)
{
struct cmd_node *cnode = arg;
const struct cmd_element *cmd = hb->data;
struct graph *graph = graph_new();
struct cmd_token *token = cmd_token_new(START_TKN, 0, NULL, NULL);
graph_new_node(graph, token, (void (*)(void *)) & cmd_token_del);
cmd_graph_parse(graph, cmd);
cmd_graph_names(graph);
cmd_graph_merge(cnode->cmdgraph, graph, +1);
graph_delete_graph(graph);
}
void cmd_finalize_node(struct cmd_node *cnode)
{
if (cnode->graph_built)
return;
hash_iterate(cnode->cmd_hash, cmd_finalize_iter, cnode);
cnode->graph_built = true;
2002-12-13 21:15:29 +01:00
}
void uninstall_element(enum node_type ntype, const struct cmd_element *cmd)
{
struct cmd_node *cnode;
/* cmd_init hasn't been called */
if (!cmdvec) {
fprintf(stderr, "%s called before cmd_init, breakage likely\n",
__func__);
return;
}
cnode = vector_lookup(cmdvec, ntype);
if (cnode == NULL) {
fprintf(stderr,
"%s[%s]:\n"
"\tnode %d does not exist.\n"
"\tplease call install_node() before uninstall_element()\n",
cmd->name, cmd->string, ntype);
exit(EXIT_FAILURE);
}
if (hash_release(cnode->cmd_hash, (void *)cmd) == NULL) {
fprintf(stderr,
"%s[%s]:\n"
"\tnode %d (%s) does not have this command installed.\n"
"\tduplicate uninstall_element call?\n",
cmd->name, cmd->string, ntype, cnode->name);
return;
}
vector_unset_value(cnode->cmd_vector, (void *)cmd);
if (cnode->graph_built) {
struct graph *graph = graph_new();
struct cmd_token *token =
cmd_token_new(START_TKN, 0, NULL, NULL);
graph_new_node(graph, token,
(void (*)(void *)) & cmd_token_del);
cmd_graph_parse(graph, cmd);
cmd_graph_names(graph);
cmd_graph_merge(cnode->cmdgraph, graph, -1);
graph_delete_graph(graph);
}
if (ntype == VIEW_NODE)
uninstall_element(ENABLE_NODE, cmd);
}
static const unsigned char itoa64[] =
2002-12-13 21:15:29 +01:00
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
static void to64(char *s, long v, int n)
{
while (--n >= 0) {
2002-12-13 21:15:29 +01:00
*s++ = itoa64[v & 0x3f];
v >>= 6;
}
}
2004-12-07 Andrew J. Schorr <ajschorr@alumni.princeton.edu> * bgp_main.c: (main) The 2nd argument to openzlog has been removed. * isis_main.c: (main) The 2nd argument to openzlog has been removed. * ospf6_main.c: (main) The 2nd argument to openzlog has been removed. Note that stdout logging will no longer be enabled by default when not running as a daemon. * ospf_main.c: (main) The 2nd argument to openzlog has been removed. * rip_main.c: (main) The 2nd argument to openzlog has been removed. * ripng_main.c: (main) The 2nd argument to openzlog has been removed. * main.c: (main) The 2nd argument to openzlog has been removed. So stdout logging will no longer be enabled by default. * irdp_main.c: (irdp_finish) Reduce severity of shutdown message from LOG_WARNING to LOG_INFO. * vtysh.c: Make several functions static instead of global. Added several commands to support destination-specific logging levels. (vtysh_completion) This function is unused, so comment it out. * basic.texi: Document new logging features. Separate basic config commands from basic VTY commands. * log.h: Replace struct zlog flags and maskpri fields with maxlvl array to support individual logging levels for each destination. Remove the 2nd argument to openzlog since the default logging config should be standardized inside the library. Replaced the zlog_set_flag and zlog_reset_flag functions with zlog_set_level. And zlog_set_file now requires an additional log_level argument. Declare zlog_proto_names for use inside command.c in the "show logging" command. Added defines useful for command construction. * log.c: (vzlog) Decide where to send the message based on the individual logging levels configured for each destination. Remove support for ZLOG_STDERR since it was never actually used. Support record-priority for terminal monitors. (zlog_signal,zlog_backtrace_sigsafe) Support destination-specific logging levels. Remove stderr support (was never used). Added support for terminal monitor logging. (_zlog_assert_failed) Increase message severity to LOG_EMERG. (openzlog) Remove 2nd argument since default config should be standardized in library. By default, terminal monitoring is set to debug, and all other logging is disabled. (zlog_set_flag,zlog_reset_flag) Removed. (zlog_set_level) New function to replace zlog_set_flag and zlog_reset_flag. Supports destination-specific logging levels. (zlog_set_file,zlog_reset_file) Support file-specific logging level. (zlog_rotate) Log an error message if fopen fails, and support new file-specific logging level. * command.h: Change DEFUN_CMD_FUNC_DECL and DEFUN_CMD_FUNC_TEXT so that command functions will be static instead of global. Remove declarations for config_exit and config_help. Define new macros DEFUNSH_ATTR, DEFUNSH_HIDDEN, and DEFUNSH_DEPRECATED so we can have deprecated commands in vtysh. Similarly, for completeness, define macros ALIAS_SH, ALIAS_SH_HIDDEN, and ALIAS_SH_DEPRECATED. Also, fix bug in ALIAS_ATTR macro (didn't matter because it was never used). * command.c: Make many functions static instead of global. (facility_name,facility_match,level_match) New functions to support enhanced destination-specific logging levels. (config_write_host) Support new destination-specific logging levels. (config_logmsg) Added new "logmsg" command to help test logging system. (show_logging) Added "show logging" command to show the current configuration of the logging system. (config_log_stdout_level) Support explicit stdout logging level. (no_config_log_stdout) Now takes optional LEVEL arg. (config_log_monitor,config_log_monitor_level,no_config_log_monitor) New commands creating new "log monitor" commands to set terminal monitoring log level. (config_log_file_level) Support explicit file logging level. (config_log_syslog_level) Support explicit syslog logging level. (config_log_facility,no_config_log_facility) Implement new "log facility" command. (cmd_init) Add hooks for new commands: "show logging", "logmsg", "log stdout <level>", "log monitor", "log monitor <level>", "no log monitor", "log file <filename> <level>", "no log file <filename> <level>", "log syslog <level>", "log facility", and "no log facility". * vty.h: Added a "level" argument to vty_log so it can support "log record-priority". Declare new function vty_log_fixed for use in signal handlers. * vty.c: (vty_log,vty_log_out) Added a "level" argument to support "log record-priority" for vty terminal monitors. (vty_down_level) Use config_exit_cmd.func instead of calling config_exit directly (since command functions will now be static instead of global). (vty_log_fixed) New function to send terminal monitor messages from inside a signal handler.
2004-12-07 16:39:31 +01:00
static char *zencrypt(const char *passwd)
2002-12-13 21:15:29 +01:00
{
char salt[6];
struct timeval tv;
gettimeofday(&tv, 0);
to64(&salt[0], frr_weak_random(), 3);
2002-12-13 21:15:29 +01:00
to64(&salt[3], tv.tv_usec, 3);
salt[5] = '\0';
return crypt(passwd, salt);
}
static bool full_cli;
2002-12-13 21:15:29 +01:00
/* This function write configuration of this host. */
static int config_write_host(struct vty *vty)
{
const char *name;
name = cmd_hostname_get();
if (name && name[0] != '\0')
vty_out(vty, "hostname %s\n", name);
name = cmd_domainname_get();
if (name && name[0] != '\0')
vty_out(vty, "domainname %s\n", name);
if (cmd_allow_reserved_ranges_get())
vty_out(vty, "allow-reserved-ranges\n");
/* The following are all configuration commands that are not sent to
* watchfrr. For instance watchfrr is hardcoded to log to syslog so
* we would always display 'log syslog informational' in the config
* which would cause other daemons to then switch to syslog when they
* parse frr.conf.
*/
if (full_cli) {
if (host.encrypt) {
if (host.password_encrypt)
vty_out(vty, "password 8 %s\n",
host.password_encrypt);
if (host.enable_encrypt)
vty_out(vty, "enable password 8 %s\n",
host.enable_encrypt);
} else {
if (host.password)
vty_out(vty, "password %s\n", host.password);
if (host.enable)
vty_out(vty, "enable password %s\n",
host.enable);
}
log_config_write(vty);
if (!cputime_enabled)
vty_out(vty, "no service cputime-stats\n");
if (!cputime_threshold)
vty_out(vty, "no service cputime-warning\n");
else if (cputime_threshold != CONSUMED_TIME_CHECK)
vty_out(vty, "service cputime-warning %lu\n",
cputime_threshold / 1000);
if (!walltime_threshold)
vty_out(vty, "no service walltime-warning\n");
else if (walltime_threshold != CONSUMED_TIME_CHECK)
vty_out(vty, "service walltime-warning %lu\n",
walltime_threshold / 1000);
if (host.advanced)
vty_out(vty, "service advanced-vty\n");
if (host.encrypt)
vty_out(vty, "service password-encryption\n");
if (host.lines >= 0)
vty_out(vty, "service terminal-length %d\n",
host.lines);
if (host.motdfile)
vty_out(vty, "banner motd file %s\n", host.motdfile);
else if (host.motd
&& strncmp(host.motd, FRR_DEFAULT_MOTD,
strlen(host.motd)))
vty_out(vty, "banner motd line %s\n", host.motd);
else if (!host.motd)
vty_out(vty, "no banner motd\n");
}
if (debug_memstats_at_exit)
vty_out(vty, "!\ndebug memstats-at-exit\n");
2002-12-13 21:15:29 +01:00
return 1;
}
/* Utility function for getting command graph. */
static struct graph *cmd_node_graph(vector v, enum node_type ntype)
2002-12-13 21:15:29 +01:00
{
struct cmd_node *cnode = vector_slot(v, ntype);
cmd_finalize_node(cnode);
return cnode->cmdgraph;
2002-12-13 21:15:29 +01:00
}
static int cmd_try_do_shortcut(enum node_type node, char *first_word)
{
if (first_word != NULL && node != AUTH_NODE && node != VIEW_NODE
&& node != AUTH_ENABLE_NODE && 0 == strcmp("do", first_word))
return 1;
return 0;
2002-12-13 21:15:29 +01:00
}
/**
* Compare function for cmd_token.
* Used with qsort to sort command completions.
*/
static int compare_completions(const void *fst, const void *snd)
2002-12-13 21:15:29 +01:00
{
const struct cmd_token *first = *(const struct cmd_token * const *)fst,
*secnd = *(const struct cmd_token * const *)snd;
return strcmp(first->text, secnd->text);
2002-12-13 21:15:29 +01:00
}
/**
* Takes a list of completions returned by command_complete,
* dedeuplicates them based on both text and description,
* sorts them, and returns them as a vector.
*
* @param completions linked list of cmd_token
* @return deduplicated and sorted vector with
*/
vector completions_to_vec(struct list *completions)
2002-12-13 21:15:29 +01:00
{
vector comps = vector_init(VECTOR_MIN_SIZE);
struct listnode *ln;
struct cmd_token *token, *cr = NULL;
unsigned int i, exists;
for (ALL_LIST_ELEMENTS_RO(completions, ln, token)) {
if (token->type == END_TKN && (cr = token))
continue;
// linear search for token in completions vector
exists = 0;
for (i = 0; i < vector_active(comps) && !exists; i++) {
struct cmd_token *curr = vector_slot(comps, i);
#ifdef VTYSH_DEBUG
exists = !strcmp(curr->text, token->text)
&& !strcmp(curr->desc, token->desc);
#else
exists = !strcmp(curr->text, token->text);
#endif /* VTYSH_DEBUG */
}
if (!exists)
vector_set(comps, token);
}
// sort completions
qsort(comps->index, vector_active(comps), sizeof(void *),
&compare_completions);
// make <cr> the first element, if it is present
if (cr) {
vector_set_index(comps, vector_active(comps), NULL);
memmove(comps->index + 1, comps->index,
(comps->alloced - 1) * sizeof(void *));
vector_set_index(comps, 0, cr);
}
return comps;
}
/**
* Generates a vector of cmd_token representing possible completions
* on the current input.
*
* @param vline the vectorized input line
* @param vty the vty with the node to match on
* @param status pointer to matcher status code
* @return vector of struct cmd_token * with possible completions
*/
static vector cmd_complete_command_real(vector vline, struct vty *vty,
int *status)
{
struct list *completions;
struct graph *cmdgraph = cmd_node_graph(cmdvec, vty->node);
enum matcher_rv rv = command_complete(cmdgraph, vline, &completions);
if (MATCHER_ERROR(rv)) {
*status = CMD_ERR_NO_MATCH;
return NULL;
}
vector comps = completions_to_vec(completions);
list_delete(&completions);
// set status code appropriately
switch (vector_active(comps)) {
case 0:
*status = CMD_ERR_NO_MATCH;
break;
case 1:
*status = CMD_COMPLETE_FULL_MATCH;
break;
default:
*status = CMD_COMPLETE_LIST_MATCH;
}
2002-12-13 21:15:29 +01:00
return comps;
}
2002-12-13 21:15:29 +01:00
vector cmd_describe_command(vector vline, struct vty *vty, int *status)
{
vector ret;
2002-12-13 21:15:29 +01:00
if (cmd_try_do_shortcut(vty->node, vector_slot(vline, 0))) {
enum node_type onode;
int orig_xpath_index;
vector shifted_vline;
unsigned int index;
2002-12-13 21:15:29 +01:00
onode = vty->node;
orig_xpath_index = vty->xpath_index;
vty->node = ENABLE_NODE;
vty->xpath_index = 0;
/* We can try it on enable node, cos' the vty is authenticated
*/
2002-12-13 21:15:29 +01:00
shifted_vline = vector_init(vector_count(vline));
/* use memcpy? */
for (index = 1; index < vector_active(vline); index++) {
vector_set_index(shifted_vline, index - 1,
vector_lookup(vline, index));
}
2002-12-13 21:15:29 +01:00
ret = cmd_complete_command_real(shifted_vline, vty, status);
vector_free(shifted_vline);
vty->node = onode;
vty->xpath_index = orig_xpath_index;
return ret;
}
2002-12-13 21:15:29 +01:00
return cmd_complete_command_real(vline, vty, status);
2002-12-13 21:15:29 +01:00
}
static struct list *varhandlers = NULL;
static int __add_key_comp(const struct lyd_node *dnode, void *arg)
{
const char *key_value = yang_dnode_get_string(dnode, NULL);
vector_set((vector)arg, XSTRDUP(MTYPE_COMPLETION, key_value));
return YANG_ITER_CONTINUE;
}
static void __get_list_keys(vector comps, const char *xpath)
{
yang_dnode_iterate(__add_key_comp, comps,
vty_shared_candidate_config->dnode, "%s", xpath);
}
void cmd_variable_complete(struct cmd_token *token, const char *arg,
vector comps)
{
struct listnode *ln;
const struct cmd_variable_handler *cvh;
size_t i, argsz;
vector tmpcomps;
tmpcomps = arg ? vector_init(VECTOR_MIN_SIZE) : comps;
for (ALL_LIST_ELEMENTS_RO(varhandlers, ln, cvh)) {
if (cvh->tokenname && strcmp(cvh->tokenname, token->text))
continue;
if (cvh->varname && (!token->varname
|| strcmp(cvh->varname, token->varname)))
continue;
if (cvh->xpath)
__get_list_keys(tmpcomps, cvh->xpath);
if (cvh->completions)
cvh->completions(tmpcomps, token);
break;
}
if (!arg)
return;
argsz = strlen(arg);
for (i = vector_active(tmpcomps); i; i--) {
char *item = vector_slot(tmpcomps, i - 1);
if (strlen(item) >= argsz && !strncmp(item, arg, argsz))
vector_set(comps, item);
else
XFREE(MTYPE_COMPLETION, item);
}
vector_free(tmpcomps);
}
#define AUTOCOMP_INDENT 5
char *cmd_variable_comp2str(vector comps, unsigned short cols)
{
size_t bsz = 16;
char *buf = XCALLOC(MTYPE_TMP, bsz);
int lc = AUTOCOMP_INDENT;
size_t cs = AUTOCOMP_INDENT;
size_t itemlen;
snprintf(buf, bsz, "%*s", AUTOCOMP_INDENT, "");
for (size_t j = 0; j < vector_active(comps); j++) {
char *item = vector_slot(comps, j);
itemlen = strlen(item);
size_t next_sz = cs + itemlen + AUTOCOMP_INDENT + 3;
if (next_sz > bsz) {
/* Make sure the buf size is large enough */
bsz = next_sz;
buf = XREALLOC(MTYPE_TMP, buf, bsz);
}
if (lc + itemlen + 1 >= cols) {
cs += snprintf(&buf[cs], bsz - cs, "\n%*s",
AUTOCOMP_INDENT, "");
lc = AUTOCOMP_INDENT;
}
size_t written = snprintf(&buf[cs], bsz - cs, "%s ", item);
lc += written;
cs += written;
XFREE(MTYPE_COMPLETION, item);
vector_set_index(comps, j, NULL);
}
return buf;
}
void cmd_variable_handler_register(const struct cmd_variable_handler *cvh)
{
if (!varhandlers)
return;
for (; cvh->completions || cvh->xpath; cvh++)
listnode_add(varhandlers, (void *)cvh);
}
DEFUN_HIDDEN (autocomplete,
autocomplete_cmd,
"autocomplete TYPE TEXT VARNAME",
"Autocompletion handler (internal, for vtysh)\n"
"cmd_token->type\n"
"cmd_token->text\n"
"cmd_token->varname\n")
{
struct cmd_token tok;
vector comps = vector_init(32);
size_t i;
memset(&tok, 0, sizeof(tok));
tok.type = atoi(argv[1]->arg);
tok.text = argv[2]->arg;
tok.varname = argv[3]->arg;
if (!strcmp(tok.varname, "-"))
tok.varname = NULL;
cmd_variable_complete(&tok, NULL, comps);
for (i = 0; i < vector_active(comps); i++) {
char *text = vector_slot(comps, i);
vty_out(vty, "%s\n", text);
XFREE(MTYPE_COMPLETION, text);
}
vector_free(comps);
return CMD_SUCCESS;
}
/**
* Generate possible tab-completions for the given input. This function only
* returns results that would result in a valid command if used as Readline
* completions (as is the case in vtysh). For instance, if the passed vline ends
* with '4.3.2', the strings 'A.B.C.D' and 'A.B.C.D/M' will _not_ be returned.
*
* @param vline vectorized input line
* @param vty the vty
* @param status location to store matcher status code in
* @return set of valid strings for use with Readline as tab-completions.
*/
char **cmd_complete_command(vector vline, struct vty *vty, int *status)
{
char **ret = NULL;
int original_node = vty->node;
vector input_line = vector_init(vector_count(vline));
// if the first token is 'do' we'll want to execute the command in the
// enable node
int do_shortcut = cmd_try_do_shortcut(vty->node, vector_slot(vline, 0));
vty->node = do_shortcut ? ENABLE_NODE : original_node;
// construct the input line we'll be matching on
unsigned int offset = (do_shortcut) ? 1 : 0;
for (unsigned index = 0; index + offset < vector_active(vline); index++)
vector_set_index(input_line, index,
vector_lookup(vline, index + offset));
// get token completions -- this is a copying operation
vector comps = NULL, initial_comps;
initial_comps = cmd_complete_command_real(input_line, vty, status);
if (!MATCHER_ERROR(*status)) {
assert(initial_comps);
// filter out everything that is not suitable for a
// tab-completion
comps = vector_init(VECTOR_MIN_SIZE);
for (unsigned int i = 0; i < vector_active(initial_comps);
i++) {
struct cmd_token *token = vector_slot(initial_comps, i);
if (token->type == WORD_TKN)
vector_set(comps, XSTRDUP(MTYPE_COMPLETION,
token->text));
else if (IS_VARYING_TOKEN(token->type)) {
const char *ref = vector_lookup(
vline, vector_active(vline) - 1);
cmd_variable_complete(token, ref, comps);
}
}
vector_free(initial_comps);
// since we filtered results, we need to re-set status code
switch (vector_active(comps)) {
case 0:
*status = CMD_ERR_NO_MATCH;
break;
case 1:
*status = CMD_COMPLETE_FULL_MATCH;
break;
default:
*status = CMD_COMPLETE_LIST_MATCH;
}
// copy completions text into an array of char*
ret = XMALLOC(MTYPE_TMP,
(vector_active(comps) + 1) * sizeof(char *));
unsigned int i;
for (i = 0; i < vector_active(comps); i++) {
ret[i] = vector_slot(comps, i);
}
// set the last element to NULL, because this array is used in
// a Readline completion_generator function which expects NULL
// as a sentinel value
ret[i] = NULL;
vector_free(comps);
comps = NULL;
} else if (initial_comps)
vector_free(initial_comps);
// comps should always be null here
assert(!comps);
// free the adjusted input line
vector_free(input_line);
// reset vty->node to its original value
vty->node = original_node;
return ret;
}
/* return parent node */
/* MUST eventually converge on CONFIG_NODE */
2004-12-07 Andrew J. Schorr <ajschorr@alumni.princeton.edu> * bgp_main.c: (main) The 2nd argument to openzlog has been removed. * isis_main.c: (main) The 2nd argument to openzlog has been removed. * ospf6_main.c: (main) The 2nd argument to openzlog has been removed. Note that stdout logging will no longer be enabled by default when not running as a daemon. * ospf_main.c: (main) The 2nd argument to openzlog has been removed. * rip_main.c: (main) The 2nd argument to openzlog has been removed. * ripng_main.c: (main) The 2nd argument to openzlog has been removed. * main.c: (main) The 2nd argument to openzlog has been removed. So stdout logging will no longer be enabled by default. * irdp_main.c: (irdp_finish) Reduce severity of shutdown message from LOG_WARNING to LOG_INFO. * vtysh.c: Make several functions static instead of global. Added several commands to support destination-specific logging levels. (vtysh_completion) This function is unused, so comment it out. * basic.texi: Document new logging features. Separate basic config commands from basic VTY commands. * log.h: Replace struct zlog flags and maskpri fields with maxlvl array to support individual logging levels for each destination. Remove the 2nd argument to openzlog since the default logging config should be standardized inside the library. Replaced the zlog_set_flag and zlog_reset_flag functions with zlog_set_level. And zlog_set_file now requires an additional log_level argument. Declare zlog_proto_names for use inside command.c in the "show logging" command. Added defines useful for command construction. * log.c: (vzlog) Decide where to send the message based on the individual logging levels configured for each destination. Remove support for ZLOG_STDERR since it was never actually used. Support record-priority for terminal monitors. (zlog_signal,zlog_backtrace_sigsafe) Support destination-specific logging levels. Remove stderr support (was never used). Added support for terminal monitor logging. (_zlog_assert_failed) Increase message severity to LOG_EMERG. (openzlog) Remove 2nd argument since default config should be standardized in library. By default, terminal monitoring is set to debug, and all other logging is disabled. (zlog_set_flag,zlog_reset_flag) Removed. (zlog_set_level) New function to replace zlog_set_flag and zlog_reset_flag. Supports destination-specific logging levels. (zlog_set_file,zlog_reset_file) Support file-specific logging level. (zlog_rotate) Log an error message if fopen fails, and support new file-specific logging level. * command.h: Change DEFUN_CMD_FUNC_DECL and DEFUN_CMD_FUNC_TEXT so that command functions will be static instead of global. Remove declarations for config_exit and config_help. Define new macros DEFUNSH_ATTR, DEFUNSH_HIDDEN, and DEFUNSH_DEPRECATED so we can have deprecated commands in vtysh. Similarly, for completeness, define macros ALIAS_SH, ALIAS_SH_HIDDEN, and ALIAS_SH_DEPRECATED. Also, fix bug in ALIAS_ATTR macro (didn't matter because it was never used). * command.c: Make many functions static instead of global. (facility_name,facility_match,level_match) New functions to support enhanced destination-specific logging levels. (config_write_host) Support new destination-specific logging levels. (config_logmsg) Added new "logmsg" command to help test logging system. (show_logging) Added "show logging" command to show the current configuration of the logging system. (config_log_stdout_level) Support explicit stdout logging level. (no_config_log_stdout) Now takes optional LEVEL arg. (config_log_monitor,config_log_monitor_level,no_config_log_monitor) New commands creating new "log monitor" commands to set terminal monitoring log level. (config_log_file_level) Support explicit file logging level. (config_log_syslog_level) Support explicit syslog logging level. (config_log_facility,no_config_log_facility) Implement new "log facility" command. (cmd_init) Add hooks for new commands: "show logging", "logmsg", "log stdout <level>", "log monitor", "log monitor <level>", "no log monitor", "log file <filename> <level>", "no log file <filename> <level>", "log syslog <level>", "log facility", and "no log facility". * vty.h: Added a "level" argument to vty_log so it can support "log record-priority". Declare new function vty_log_fixed for use in signal handlers. * vty.c: (vty_log,vty_log_out) Added a "level" argument to support "log record-priority" for vty terminal monitors. (vty_down_level) Use config_exit_cmd.func instead of calling config_exit directly (since command functions will now be static instead of global). (vty_log_fixed) New function to send terminal monitor messages from inside a signal handler.
2004-12-07 16:39:31 +01:00
enum node_type node_parent(enum node_type node)
{
struct cmd_node *cnode;
This patch adds Yon's CLI 'walk back up tree' patch. Following are email describing original patch and a shorter email describing changes to an updated patch, the one which is applied: From havanna_moon@gmx.net Sat Jan 18 00:37:13 2003 Date: Mon, 9 Dec 2002 05:32:58 +0100 (CET) From: Yon Uriarte <havanna_moon@gmx.net> To: "the list(tm) Zebra" <zebra@zebra.org> Subject: [zebra 16671] [PATCH] CLI extensions. Hi, this patch adds 2 improvements to the CLI (lib/command.c): #1) When in subconfig mode (router XXX, interface XXX, ...) commands that fail for that node are tried on the main CONFIG_NODE. This is great for configuring interfaces or changing the sub-config mode quickly, without the need to type 'exit' between commands: ospfd(config)# int eth1 ospfd(config-if)# ip ospf cost 9 ospfd(config-if)# ip ospf prio 101 ospfd(config-if)# router ospf ospfd(config-router)# network 1.1.1.0/24 area 51 ospfd(config-router)# int eth2 ospfd(config-if)# ip ospf authentication message-digest ospfd(config-if)# ^Z ospfd# Is this IOS-like or does IOS try to walk up the tree of config sub-modes instead of directly trying the command on CONFIG_NODE? CAVEATS: "?" and "TAB" don't work. IIRC IOS doesnt show that help neither. NON-CAVEATS: This wont break much, as config_from_file() already does try a failed command on the parent node of the actual vty->node. If changing the code to walk the node tree instead of directly trying the command on the ENABLE_NODE the same semantics would be in use and no future bugs could creep in. #2) When in config or subconfig mode use the "do " prefix to execute commans of the ENABLE_NODE. "?" and "TAB" work. The space after the "do" is needed: ospfd(config-router)# do<?> % There is no matched command. ospfd(config-router)# do <?> clear Reset functions configure Configuration from vty interface copy Copy configuration debug Debugging functions (see also 'undebug') disable Turn off privileged mode command end End current mode and change to enable mode. exit Exit current mode and down to previous mode help Description of the interactive help system list Print command list no Negate a command or set its defaults quit Exit current mode and down to previous mode show Show running system information terminal Set terminal line parameters who Display who is on vty write Write running configuration to memory, network, or terminal ospfd(config-router)# do sho<TAB> ospfd(config-router)# do show me<TAB> ospfd(config-router)# do show memory r<TAB> ospfd(config-router)# do show memory rip RIP structure : 0 RIP route info : 0 RIP interface : 0 RIP peer : 0 RIP offset list : 0 RIP distance : 0 ospfd(config-router)# ^Z ospfd# CAVEATS: I don't have access to an IOS with this feature, so I implemented it from the comments on this mailing list (in fact my personal motivation was to implement feature #1, which I missed on zebra. But #2 sounded like a nice one to have, and xemacs was already parked on command.c ...). Is this IOS-like or are there differences? I will happily change this patch to mimick IOS or the mailing-list consensus on CLI-usability. regards, yon From havanna_moon@gmx.net Sat Jan 18 01:13:11 2003 Date: Sat, 11 Jan 2003 23:36:51 +0100 (CET) From: Yon Uriarte <havanna_moon@gmx.net> To: zebra@zebra.org Subject: [zebra 17218] Re: [PATCH] CLI extensions. Hi, [redacted] > I prefer the IOS way for the node "up walking". This patch should walk the tree upwards: bgpd(config)# router bgp 1 bgpd(config-router)# address-family ipv4 multicast bgpd(config-router-af)# access-list 1 remark hola que tal bgpd(config)# I cant test all combinations, so I cant rule out some bugs. I'd love to get (long and explicit) bug reports. [redacted]
2003-01-18 02:16:20 +01:00
assert(node > CONFIG_NODE);
cnode = vector_lookup(cmdvec, node);
return cnode->parent_node;
}
2002-12-13 21:15:29 +01:00
/* Execute command by argument vline vector. */
static int cmd_execute_command_real(vector vline, struct vty *vty,
const struct cmd_element **cmd,
unsigned int up_level)
{
struct list *argv_list;
enum matcher_rv status;
const struct cmd_element *matched_element = NULL;
unsigned int i;
int xpath_index = vty->xpath_index;
int node = vty->node;
/* only happens for legacy split config file load; need to check for
* a match before calling node_exit handlers below
*/
for (i = 0; i < up_level; i++) {
struct cmd_node *cnode;
if (node <= CONFIG_NODE)
return CMD_NO_LEVEL_UP;
cnode = vector_slot(cmdvec, node);
node = node_parent(node);
if (xpath_index > 0 && !cnode->no_xpath)
xpath_index--;
}
struct graph *cmdgraph = cmd_node_graph(cmdvec, node);
status = command_match(cmdgraph, vline, &argv_list, &matched_element);
if (cmd)
*cmd = matched_element;
// if matcher error, return corresponding CMD_ERR
if (MATCHER_ERROR(status)) {
if (argv_list)
list_delete(&argv_list);
switch (status) {
case MATCHER_INCOMPLETE:
return CMD_ERR_INCOMPLETE;
case MATCHER_AMBIGUOUS:
return CMD_ERR_AMBIGUOUS;
case MATCHER_NO_MATCH:
case MATCHER_OK:
return CMD_ERR_NO_MATCH;
}
2002-12-13 21:15:29 +01:00
}
for (i = 0; i < up_level; i++)
cmd_exit(vty);
// build argv array from argv list
struct cmd_token **argv = XMALLOC(
MTYPE_TMP, argv_list->count * sizeof(struct cmd_token *));
struct listnode *ln;
struct cmd_token *token;
i = 0;
for (ALL_LIST_ELEMENTS_RO(argv_list, ln, token))
argv[i++] = token;
int argc = argv_list->count;
int ret;
if (matched_element->daemon)
ret = CMD_SUCCESS_DAEMON;
else {
if (vty->config) {
/* Clear array of enqueued configuration changes. */
vty->num_cfg_changes = 0;
memset(&vty->cfg_changes, 0, sizeof(vty->cfg_changes));
/* Regenerate candidate configuration if necessary. */
if (frr_get_cli_mode() == FRR_CLI_CLASSIC
&& running_config->version
> vty->candidate_config->version)
nb_config_replace(vty->candidate_config,
running_config, true);
lib: introduce configuration back-off timer for YANG-modeled commands When using the default CLI mode, the northbound layer needs to create a separate transaction to process each YANG-modeled command since they are supposed to be applied immediately (there's no candidate configuration nor the "commit" command like in the transactional CLI). The problem is that configuration transactions have an overhead associated to them, in big part because of the use of some heavy libyang functions like `lyd_validate()` and `lyd_diff()`. As of now this overhead is substantial and doesn't scale well when large numbers of transactions need to be performed in sequence. As an example, loading 50k prefix-lists using a single transaction takes about 2 seconds on a modern CPU. Loading the same 50k prefix-lists using 50k transactions can take more than an hour to complete (which is unacceptable by any standard). To fix this problem, some heavy optimization work needs to be done on libyang and on the FRR northbound itself too (e.g. perform partial configuration diffs whenever possible). This, however, should be a long term effort since these optimizations shouldn't be trivial to implement and we're far from having the performance numbers we need. In the meanwhile, this commit introduces a simple but efficient workaround to alleviate the issue. In short, a new back-off timer was introduced in the CLI to monitor and detect when too many YANG-modeled commands are being received at the same time. When a certain threshold is reached (100 YANG-modeled commands within one second), the northbound starts to group all subsequent commands into a single large transaction, which allows them to be processed much faster (e.g. seconds and not hours). It's essentially a protection mechanism that creates dynamically-sized transactions when necessary to prevent performance issues from happening. This mechanism is enabled both when parsing configuration files and when reading commands from a terminal. The downside of this optimization is that, if several YANG-modeled commands are grouped into the same transaction and at least one of them fails, the whole transaction is rejected. This is undesirable since users don't expect transactional behavior when that's not enabled explicitly. To minimize this issue, the CLI will log all commands that were rejected whenever that happens, to make the user aware of what happened and have enough information to fix the problem. Commands that fail due to parsing errors or CLI-level validations in general are rejected separately. Again, this proposed workaround is intended to be temporary. The goal is to provided a quick fix to issues like #6658 while we work on better long-term solutions. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-07-02 19:43:36 +02:00
/*
* Perform pending commit (if any) before executing
* non-YANG command.
*/
if (!(matched_element->attr & CMD_ATTR_YANG))
northbound: KISS always batch yang config (file read), it's faster The backoff code assumed that yang operations always completed quickly. It checked for > 100 YANG modeled commands happening in under 1 second to enable batching. If 100 yang modeled commands always take longer than 1 second batching is never enabled. This is the exact opposite of what we want to happen since batching speeds the operations up. Here are the results for libyang2 code without and with batching. | action | 1K rts | 2K rts | 1K rts | 2K rts | 20k rts | | | nobatch | nobatch | batch | batch | batch | | Add IPv4 | .881 | 1.28 | .703 | 1.04 | 8.16 | | Add Same IPv4 | 28.7 | 113 | .590 | .860 | 6.09 | | Rem 1/2 IPv4 | .376 | .442 | .379 | .435 | 1.44 | | Add Same IPv4 | 28.7 | 113 | .576 | .841 | 6.02 | | Rem All IPv4 | 17.4 | 71.8 | .559 | .813 | 5.57 | (IPv6 numbers are basically the same as iPv4, a couple percent slower) Clearly we need this. Please note the growth (1K to 2K) w/o batching is non-linear and 100 times slower than batched. Notes on code: The use of the new `nb_cli_apply_changes_clear_pending` is to commit any pending changes (including the current one). This is done when the code would not correctly handle a single diff that included the current changes with possible following changes. For example, a "no" command followed by a new value to replace it would be merged into a change, and the code would not deal well with that. A good example of this is BGP neighbor peer-group changing. The other use is after entering a router level (e.g., "router bgp") where the follow-on command handlers expect that router object to now exists. The code eventually needs to be cleaned up to not fail in these cases, but that is for future NB cleanup. Signed-off-by: Christian Hopps <chopps@labn.net>
2021-05-28 21:16:18 +02:00
(void)nb_cli_pending_commit_check(vty);
}
ret = matched_element->func(matched_element, vty, argc, argv);
}
// delete list and cmd_token's in it
list_delete(&argv_list);
XFREE(MTYPE_TMP, argv);
return ret;
2002-12-13 21:15:29 +01:00
}
/**
* Execute a given command, handling things like "do ..." and checking
* whether the given command might apply at a parent node if doesn't
* apply for the current node.
*
* @param vline Command line input, vector of char* where each element is
* one input token.
* @param vty The vty context in which the command should be executed.
* @param cmd Pointer where the struct cmd_element of the matched command
* will be stored, if any. May be set to NULL if this info is
* not needed.
* @param vtysh If set != 0, don't lookup the command at parent nodes.
* @return The status of the command that has been executed or an error code
* as to why no command could be executed.
*/
int cmd_execute_command(vector vline, struct vty *vty,
const struct cmd_element **cmd, int vtysh)
{
int ret, saved_ret = 0;
This patch adds Yon's CLI 'walk back up tree' patch. Following are email describing original patch and a shorter email describing changes to an updated patch, the one which is applied: From havanna_moon@gmx.net Sat Jan 18 00:37:13 2003 Date: Mon, 9 Dec 2002 05:32:58 +0100 (CET) From: Yon Uriarte <havanna_moon@gmx.net> To: "the list(tm) Zebra" <zebra@zebra.org> Subject: [zebra 16671] [PATCH] CLI extensions. Hi, this patch adds 2 improvements to the CLI (lib/command.c): #1) When in subconfig mode (router XXX, interface XXX, ...) commands that fail for that node are tried on the main CONFIG_NODE. This is great for configuring interfaces or changing the sub-config mode quickly, without the need to type 'exit' between commands: ospfd(config)# int eth1 ospfd(config-if)# ip ospf cost 9 ospfd(config-if)# ip ospf prio 101 ospfd(config-if)# router ospf ospfd(config-router)# network 1.1.1.0/24 area 51 ospfd(config-router)# int eth2 ospfd(config-if)# ip ospf authentication message-digest ospfd(config-if)# ^Z ospfd# Is this IOS-like or does IOS try to walk up the tree of config sub-modes instead of directly trying the command on CONFIG_NODE? CAVEATS: "?" and "TAB" don't work. IIRC IOS doesnt show that help neither. NON-CAVEATS: This wont break much, as config_from_file() already does try a failed command on the parent node of the actual vty->node. If changing the code to walk the node tree instead of directly trying the command on the ENABLE_NODE the same semantics would be in use and no future bugs could creep in. #2) When in config or subconfig mode use the "do " prefix to execute commans of the ENABLE_NODE. "?" and "TAB" work. The space after the "do" is needed: ospfd(config-router)# do<?> % There is no matched command. ospfd(config-router)# do <?> clear Reset functions configure Configuration from vty interface copy Copy configuration debug Debugging functions (see also 'undebug') disable Turn off privileged mode command end End current mode and change to enable mode. exit Exit current mode and down to previous mode help Description of the interactive help system list Print command list no Negate a command or set its defaults quit Exit current mode and down to previous mode show Show running system information terminal Set terminal line parameters who Display who is on vty write Write running configuration to memory, network, or terminal ospfd(config-router)# do sho<TAB> ospfd(config-router)# do show me<TAB> ospfd(config-router)# do show memory r<TAB> ospfd(config-router)# do show memory rip RIP structure : 0 RIP route info : 0 RIP interface : 0 RIP peer : 0 RIP offset list : 0 RIP distance : 0 ospfd(config-router)# ^Z ospfd# CAVEATS: I don't have access to an IOS with this feature, so I implemented it from the comments on this mailing list (in fact my personal motivation was to implement feature #1, which I missed on zebra. But #2 sounded like a nice one to have, and xemacs was already parked on command.c ...). Is this IOS-like or are there differences? I will happily change this patch to mimick IOS or the mailing-list consensus on CLI-usability. regards, yon From havanna_moon@gmx.net Sat Jan 18 01:13:11 2003 Date: Sat, 11 Jan 2003 23:36:51 +0100 (CET) From: Yon Uriarte <havanna_moon@gmx.net> To: zebra@zebra.org Subject: [zebra 17218] Re: [PATCH] CLI extensions. Hi, [redacted] > I prefer the IOS way for the node "up walking". This patch should walk the tree upwards: bgpd(config)# router bgp 1 bgpd(config-router)# address-family ipv4 multicast bgpd(config-router-af)# access-list 1 remark hola que tal bgpd(config)# I cant test all combinations, so I cant rule out some bugs. I'd love to get (long and explicit) bug reports. [redacted]
2003-01-18 02:16:20 +01:00
enum node_type onode, try_node;
int orig_xpath_index;
Finish off merge off CLI extensions, see below for description. Merge should be off: From havanna_moon@gmx.net Sat Jan 18 00:37:13 2003 Date: Mon, 9 Dec 2002 05:32:58 +0100 (CET) From: Yon Uriarte <havanna_moon@gmx.net> To: "the list(tm) Zebra" <zebra@zebra.org> Subject: [zebra 16671] [PATCH] CLI extensions. Hi, this patch adds 2 improvements to the CLI (lib/command.c): #1) When in subconfig mode (router XXX, interface XXX, ...) commands that fail for that node are tried on the main CONFIG_NODE. This is great for configuring interfaces or changing the sub-config mode quickly, without the need to type 'exit' between commands: ospfd(config)# int eth1 ospfd(config-if)# ip ospf cost 9 ospfd(config-if)# ip ospf prio 101 ospfd(config-if)# router ospf ospfd(config-router)# network 1.1.1.0/24 area 51 ospfd(config-router)# int eth2 ospfd(config-if)# ip ospf authentication message-digest ospfd(config-if)# ^Z ospfd# Is this IOS-like or does IOS try to walk up the tree of config sub-modes instead of directly trying the command on CONFIG_NODE? CAVEATS: "?" and "TAB" don't work. IIRC IOS doesnt show that help neither. NON-CAVEATS: This wont break much, as config_from_file() already does try a failed command on the parent node of the actual vty->node. If changing the code to walk the node tree instead of directly trying the command on the ENABLE_NODE the same semantics would be in use and no future bugs could creep in. #2) When in config or subconfig mode use the "do " prefix to execute commans of the ENABLE_NODE. "?" and "TAB" work. The space after the "do" is needed: ospfd(config-router)# do<?> % There is no matched command. ospfd(config-router)# do <?> clear Reset functions configure Configuration from vty interface copy Copy configuration debug Debugging functions (see also 'undebug') disable Turn off privileged mode command end End current mode and change to enable mode. exit Exit current mode and down to previous mode help Description of the interactive help system list Print command list no Negate a command or set its defaults quit Exit current mode and down to previous mode show Show running system information terminal Set terminal line parameters who Display who is on vty write Write running configuration to memory, network, or terminal ospfd(config-router)# do sho<TAB> ospfd(config-router)# do show me<TAB> ospfd(config-router)# do show memory r<TAB> ospfd(config-router)# do show memory rip RIP structure : 0 RIP route info : 0 RIP interface : 0 RIP peer : 0 RIP offset list : 0 RIP distance : 0 ospfd(config-router)# ^Z ospfd# CAVEATS: I don't have access to an IOS with this feature, so I implemented it from the comments on this mailing list (in fact my personal motivation was to implement feature #1, which I missed on zebra. But #2 sounded like a nice one to have, and xemacs was already parked on command.c ...). Is this IOS-like or are there differences? I will happily change this patch to mimick IOS or the mailing-list consensus on CLI-usability. regards, yon
2003-01-18 01:39:19 +01:00
This patch adds Yon's CLI 'walk back up tree' patch. Following are email describing original patch and a shorter email describing changes to an updated patch, the one which is applied: From havanna_moon@gmx.net Sat Jan 18 00:37:13 2003 Date: Mon, 9 Dec 2002 05:32:58 +0100 (CET) From: Yon Uriarte <havanna_moon@gmx.net> To: "the list(tm) Zebra" <zebra@zebra.org> Subject: [zebra 16671] [PATCH] CLI extensions. Hi, this patch adds 2 improvements to the CLI (lib/command.c): #1) When in subconfig mode (router XXX, interface XXX, ...) commands that fail for that node are tried on the main CONFIG_NODE. This is great for configuring interfaces or changing the sub-config mode quickly, without the need to type 'exit' between commands: ospfd(config)# int eth1 ospfd(config-if)# ip ospf cost 9 ospfd(config-if)# ip ospf prio 101 ospfd(config-if)# router ospf ospfd(config-router)# network 1.1.1.0/24 area 51 ospfd(config-router)# int eth2 ospfd(config-if)# ip ospf authentication message-digest ospfd(config-if)# ^Z ospfd# Is this IOS-like or does IOS try to walk up the tree of config sub-modes instead of directly trying the command on CONFIG_NODE? CAVEATS: "?" and "TAB" don't work. IIRC IOS doesnt show that help neither. NON-CAVEATS: This wont break much, as config_from_file() already does try a failed command on the parent node of the actual vty->node. If changing the code to walk the node tree instead of directly trying the command on the ENABLE_NODE the same semantics would be in use and no future bugs could creep in. #2) When in config or subconfig mode use the "do " prefix to execute commans of the ENABLE_NODE. "?" and "TAB" work. The space after the "do" is needed: ospfd(config-router)# do<?> % There is no matched command. ospfd(config-router)# do <?> clear Reset functions configure Configuration from vty interface copy Copy configuration debug Debugging functions (see also 'undebug') disable Turn off privileged mode command end End current mode and change to enable mode. exit Exit current mode and down to previous mode help Description of the interactive help system list Print command list no Negate a command or set its defaults quit Exit current mode and down to previous mode show Show running system information terminal Set terminal line parameters who Display who is on vty write Write running configuration to memory, network, or terminal ospfd(config-router)# do sho<TAB> ospfd(config-router)# do show me<TAB> ospfd(config-router)# do show memory r<TAB> ospfd(config-router)# do show memory rip RIP structure : 0 RIP route info : 0 RIP interface : 0 RIP peer : 0 RIP offset list : 0 RIP distance : 0 ospfd(config-router)# ^Z ospfd# CAVEATS: I don't have access to an IOS with this feature, so I implemented it from the comments on this mailing list (in fact my personal motivation was to implement feature #1, which I missed on zebra. But #2 sounded like a nice one to have, and xemacs was already parked on command.c ...). Is this IOS-like or are there differences? I will happily change this patch to mimick IOS or the mailing-list consensus on CLI-usability. regards, yon From havanna_moon@gmx.net Sat Jan 18 01:13:11 2003 Date: Sat, 11 Jan 2003 23:36:51 +0100 (CET) From: Yon Uriarte <havanna_moon@gmx.net> To: zebra@zebra.org Subject: [zebra 17218] Re: [PATCH] CLI extensions. Hi, [redacted] > I prefer the IOS way for the node "up walking". This patch should walk the tree upwards: bgpd(config)# router bgp 1 bgpd(config-router)# address-family ipv4 multicast bgpd(config-router-af)# access-list 1 remark hola que tal bgpd(config)# I cant test all combinations, so I cant rule out some bugs. I'd love to get (long and explicit) bug reports. [redacted]
2003-01-18 02:16:20 +01:00
onode = try_node = vty->node;
orig_xpath_index = vty->xpath_index;
if (cmd_try_do_shortcut(vty->node, vector_slot(vline, 0))) {
vector shifted_vline;
unsigned int index;
vty->node = ENABLE_NODE;
vty->xpath_index = 0;
/* We can try it on enable node, cos' the vty is authenticated
*/
shifted_vline = vector_init(vector_count(vline));
/* use memcpy? */
for (index = 1; index < vector_active(vline); index++)
vector_set_index(shifted_vline, index - 1,
vector_lookup(vline, index));
ret = cmd_execute_command_real(shifted_vline, vty, cmd, 0);
vector_free(shifted_vline);
vty->node = onode;
vty->xpath_index = orig_xpath_index;
return ret;
}
saved_ret = ret =
cmd_execute_command_real(vline, vty, cmd, 0);
if (vtysh)
return saved_ret;
if (ret != CMD_SUCCESS && ret != CMD_WARNING
&& ret != CMD_ERR_AMBIGUOUS && ret != CMD_ERR_INCOMPLETE
&& ret != CMD_NOT_MY_INSTANCE && ret != CMD_WARNING_CONFIG_FAILED) {
/* This assumes all nodes above CONFIG_NODE are childs of
* CONFIG_NODE */
while (vty->node > CONFIG_NODE) {
struct cmd_node *cnode = vector_slot(cmdvec, try_node);
try_node = node_parent(try_node);
vty->node = try_node;
if (vty->xpath_index > 0 && !cnode->no_xpath)
vty->xpath_index--;
ret = cmd_execute_command_real(vline, vty, cmd, 0);
if (ret == CMD_SUCCESS || ret == CMD_WARNING
|| ret == CMD_ERR_AMBIGUOUS || ret == CMD_ERR_INCOMPLETE
|| ret == CMD_NOT_MY_INSTANCE
|| ret == CMD_WARNING_CONFIG_FAILED)
return ret;
}
/* no command succeeded, reset the vty to the original node */
vty->node = onode;
vty->xpath_index = orig_xpath_index;
}
/* return command status for original node */
This patch adds Yon's CLI 'walk back up tree' patch. Following are email describing original patch and a shorter email describing changes to an updated patch, the one which is applied: From havanna_moon@gmx.net Sat Jan 18 00:37:13 2003 Date: Mon, 9 Dec 2002 05:32:58 +0100 (CET) From: Yon Uriarte <havanna_moon@gmx.net> To: "the list(tm) Zebra" <zebra@zebra.org> Subject: [zebra 16671] [PATCH] CLI extensions. Hi, this patch adds 2 improvements to the CLI (lib/command.c): #1) When in subconfig mode (router XXX, interface XXX, ...) commands that fail for that node are tried on the main CONFIG_NODE. This is great for configuring interfaces or changing the sub-config mode quickly, without the need to type 'exit' between commands: ospfd(config)# int eth1 ospfd(config-if)# ip ospf cost 9 ospfd(config-if)# ip ospf prio 101 ospfd(config-if)# router ospf ospfd(config-router)# network 1.1.1.0/24 area 51 ospfd(config-router)# int eth2 ospfd(config-if)# ip ospf authentication message-digest ospfd(config-if)# ^Z ospfd# Is this IOS-like or does IOS try to walk up the tree of config sub-modes instead of directly trying the command on CONFIG_NODE? CAVEATS: "?" and "TAB" don't work. IIRC IOS doesnt show that help neither. NON-CAVEATS: This wont break much, as config_from_file() already does try a failed command on the parent node of the actual vty->node. If changing the code to walk the node tree instead of directly trying the command on the ENABLE_NODE the same semantics would be in use and no future bugs could creep in. #2) When in config or subconfig mode use the "do " prefix to execute commans of the ENABLE_NODE. "?" and "TAB" work. The space after the "do" is needed: ospfd(config-router)# do<?> % There is no matched command. ospfd(config-router)# do <?> clear Reset functions configure Configuration from vty interface copy Copy configuration debug Debugging functions (see also 'undebug') disable Turn off privileged mode command end End current mode and change to enable mode. exit Exit current mode and down to previous mode help Description of the interactive help system list Print command list no Negate a command or set its defaults quit Exit current mode and down to previous mode show Show running system information terminal Set terminal line parameters who Display who is on vty write Write running configuration to memory, network, or terminal ospfd(config-router)# do sho<TAB> ospfd(config-router)# do show me<TAB> ospfd(config-router)# do show memory r<TAB> ospfd(config-router)# do show memory rip RIP structure : 0 RIP route info : 0 RIP interface : 0 RIP peer : 0 RIP offset list : 0 RIP distance : 0 ospfd(config-router)# ^Z ospfd# CAVEATS: I don't have access to an IOS with this feature, so I implemented it from the comments on this mailing list (in fact my personal motivation was to implement feature #1, which I missed on zebra. But #2 sounded like a nice one to have, and xemacs was already parked on command.c ...). Is this IOS-like or are there differences? I will happily change this patch to mimick IOS or the mailing-list consensus on CLI-usability. regards, yon From havanna_moon@gmx.net Sat Jan 18 01:13:11 2003 Date: Sat, 11 Jan 2003 23:36:51 +0100 (CET) From: Yon Uriarte <havanna_moon@gmx.net> To: zebra@zebra.org Subject: [zebra 17218] Re: [PATCH] CLI extensions. Hi, [redacted] > I prefer the IOS way for the node "up walking". This patch should walk the tree upwards: bgpd(config)# router bgp 1 bgpd(config-router)# address-family ipv4 multicast bgpd(config-router-af)# access-list 1 remark hola que tal bgpd(config)# I cant test all combinations, so I cant rule out some bugs. I'd love to get (long and explicit) bug reports. [redacted]
2003-01-18 02:16:20 +01:00
return saved_ret;
}
/**
* Execute a given command, matching it strictly against the current node.
* This mode is used when reading config files.
*
* @param vline Command line input, vector of char* where each element is
* one input token.
* @param vty The vty context in which the command should be executed.
* @param cmd Pointer where the struct cmd_element* of the matched command
* will be stored, if any. May be set to NULL if this info is
* not needed.
* @return The status of the command that has been executed or an error code
* as to why no command could be executed.
*/
int cmd_execute_command_strict(vector vline, struct vty *vty,
const struct cmd_element **cmd)
2002-12-13 21:15:29 +01:00
{
return cmd_execute_command_real(vline, vty, cmd, 0);
2002-12-13 21:15:29 +01:00
}
/*
* Hook for preprocessing command string before executing.
*
* All subscribers are called with the raw command string that is to be
* executed. If any changes are to be made, a new string should be allocated
* with MTYPE_TMP and *cmd_out updated to point to this new string. The caller
* is then responsible for freeing this string.
*
* All processing functions must be mutually exclusive in their action, i.e. if
* one subscriber decides to modify the command, all others must not modify it
* when called. Feeding the output of one processing command into a subsequent
* one is not supported.
*
* This hook is intentionally internal to the command processing system.
*
* cmd_in
* The raw command string.
*
* cmd_out
* The result of any processing.
*/
DECLARE_HOOK(cmd_execute,
(struct vty *vty, const char *cmd_in, char **cmd_out),
(vty, cmd_in, cmd_out));
DEFINE_HOOK(cmd_execute, (struct vty *vty, const char *cmd_in, char **cmd_out),
(vty, cmd_in, cmd_out));
/* Hook executed after a CLI command. */
DECLARE_KOOH(cmd_execute_done, (struct vty *vty, const char *cmd_exec),
(vty, cmd_exec));
DEFINE_KOOH(cmd_execute_done, (struct vty *vty, const char *cmd_exec),
(vty, cmd_exec));
/*
* cmd_execute hook subscriber to handle `|` actions.
*/
static int handle_pipe_action(struct vty *vty, const char *cmd_in,
char **cmd_out)
{
/* look for `|` */
char *orig, *working, *token, *u;
char *pipe = strstr(cmd_in, "| ");
int ret = 0;
if (!pipe)
return 0;
/* duplicate string for processing purposes, not including pipe */
orig = working = XSTRDUP(MTYPE_TMP, pipe + 2);
/* retrieve action */
token = strsep(&working, " ");
assert(token);
/* match result to known actions */
if (strmatch(token, "include")) {
/* the remaining text should be a regexp */
char *regexp = working;
if (!regexp) {
vty_out(vty, "%% Need a regexp to filter with\n");
ret = 1;
goto fail;
}
bool succ = vty_set_include(vty, regexp);
if (!succ) {
vty_out(vty, "%% Bad regexp '%s'\n", regexp);
ret = 1;
goto fail;
}
*cmd_out = XSTRDUP(MTYPE_TMP, cmd_in);
u = *cmd_out;
strsep(&u, "|");
} else {
vty_out(vty, "%% Unknown action '%s'\n", token);
ret = 1;
goto fail;
}
fail:
XFREE(MTYPE_TMP, orig);
return ret;
}
static int handle_pipe_action_done(struct vty *vty, const char *cmd_exec)
{
if (vty->filter)
vty_set_include(vty, NULL);
return 0;
}
int cmd_execute(struct vty *vty, const char *cmd,
const struct cmd_element **matched, int vtysh)
{
int ret;
char *cmd_out = NULL;
const char *cmd_exec = NULL;
vector vline;
ret = hook_call(cmd_execute, vty, cmd, &cmd_out);
if (ret) {
ret = CMD_WARNING;
goto free;
}
cmd_exec = cmd_out ? (const char *)cmd_out : cmd;
vline = cmd_make_strvec(cmd_exec);
if (vline) {
ret = cmd_execute_command(vline, vty, matched, vtysh);
cmd_free_strvec(vline);
} else {
ret = CMD_SUCCESS;
}
free:
hook_call(cmd_execute_done, vty, cmd_exec);
XFREE(MTYPE_TMP, cmd_out);
return ret;
}
/**
* Parse one line of config, walking up the parse tree attempting to find a
* match
*
* @param vty The vty context in which the command should be executed.
* @param cmd Pointer where the struct cmd_element* of the match command
* will be stored, if any. May be set to NULL if this info is
* not needed.
* @param use_daemon Boolean to control whether or not we match on
* CMD_SUCCESS_DAEMON
* or not.
* @return The status of the command that has been executed or an error code
* as to why no command could be executed.
*/
int command_config_read_one_line(struct vty *vty,
const struct cmd_element **cmd,
uint32_t line_num, int use_daemon)
{
vector vline;
int ret;
unsigned up_level = 0;
vline = cmd_make_strvec(vty->buf);
/* In case of comment line */
if (vline == NULL)
return CMD_SUCCESS;
/* Execute configuration command : this is strict match */
ret = cmd_execute_command_strict(vline, vty, cmd);
/* The logic for trying parent nodes is in cmd_execute_command_real()
* since calling ->node_exit() correctly is a bit involved. This is
* also the only reason CMD_NO_LEVEL_UP exists.
*/
while (!(use_daemon && ret == CMD_SUCCESS_DAEMON)
&& !(!use_daemon && ret == CMD_ERR_NOTHING_TODO)
&& ret != CMD_SUCCESS && ret != CMD_WARNING
&& ret != CMD_ERR_AMBIGUOUS && ret != CMD_ERR_INCOMPLETE
&& ret != CMD_NOT_MY_INSTANCE && ret != CMD_WARNING_CONFIG_FAILED
&& ret != CMD_NO_LEVEL_UP)
ret = cmd_execute_command_real(vline, vty, cmd, ++up_level);
if (ret == CMD_NO_LEVEL_UP)
ret = CMD_ERR_NO_MATCH;
if (ret != CMD_SUCCESS &&
ret != CMD_WARNING &&
ret != CMD_SUCCESS_DAEMON) {
struct vty_error *ve = XCALLOC(MTYPE_TMP, sizeof(*ve));
memcpy(ve->error_buf, vty->buf, VTY_BUFSIZ);
ve->line_num = line_num;
ve->cmd_ret = ret;
if (!vty->error)
vty->error = list_new();
listnode_add(vty->error, ve);
}
cmd_free_strvec(vline);
return ret;
}
/* Configuration make from file. */
int config_from_file(struct vty *vty, FILE *fp, unsigned int *line_num)
2002-12-13 21:15:29 +01:00
{
int ret, error_ret = 0;
*line_num = 0;
2002-12-13 21:15:29 +01:00
while (fgets(vty->buf, VTY_BUFSIZ, fp)) {
++(*line_num);
if (vty_log_commands) {
int len = strlen(vty->buf);
/* now log the command */
zlog_notice("config-from-file# %.*s", len ? len - 1 : 0,
vty->buf);
}
ret = command_config_read_one_line(vty, NULL, *line_num, 0);
2002-12-13 21:15:29 +01:00
if (ret != CMD_SUCCESS && ret != CMD_WARNING
&& ret != CMD_ERR_NOTHING_TODO)
error_ret = ret;
2002-12-13 21:15:29 +01:00
}
if (error_ret) {
return error_ret;
}
2002-12-13 21:15:29 +01:00
return CMD_SUCCESS;
}
/* Configuration from terminal */
2002-12-13 21:15:29 +01:00
DEFUN (config_terminal,
config_terminal_cmd,
"configure [terminal [file-lock]]",
2002-12-13 21:15:29 +01:00
"Configuration from vty interface\n"
"Configuration terminal\n"
"Configuration with locked datastores\n")
2002-12-13 21:15:29 +01:00
{
return vty_config_enter(vty, false, false, argc == 3);
2002-12-13 21:15:29 +01:00
}
/* Enable command */
DEFUN (enable,
2002-12-13 21:15:29 +01:00
config_enable_cmd,
"enable",
"Turn on privileged mode command\n")
{
/* If enable password is NULL, change to ENABLE_NODE */
if ((host.enable == NULL && host.enable_encrypt == NULL)
|| vty->type == VTY_SHELL_SERV)
vty->node = ENABLE_NODE;
else
vty->node = AUTH_ENABLE_NODE;
return CMD_SUCCESS;
}
/* Disable command */
DEFUN (disable,
2002-12-13 21:15:29 +01:00
config_disable_cmd,
"disable",
"Turn off privileged mode command\n")
{
if (vty->node == ENABLE_NODE)
vty->node = VIEW_NODE;
return CMD_SUCCESS;
}
/* Down vty node level. */
DEFUN_YANG (config_exit,
2002-12-13 21:15:29 +01:00
config_exit_cmd,
"exit",
"Exit current mode and down to previous mode\n")
{
cmd_exit(vty);
return CMD_SUCCESS;
}
static int root_on_exit(struct vty *vty)
{
if (vty_shell(vty))
exit(0);
else
vty->status = VTY_CLOSE;
return 0;
}
void cmd_exit(struct vty *vty)
2002-12-13 21:15:29 +01:00
{
struct cmd_node *cnode = vector_lookup(cmdvec, vty->node);
if (cnode->node_exit) {
if (!cnode->node_exit(vty))
return;
2002-12-13 21:15:29 +01:00
}
if (cnode->parent_node)
vty->node = cnode->parent_node;
if (vty->xpath_index > 0 && !cnode->no_xpath)
vty->xpath_index--;
2002-12-13 21:15:29 +01:00
}
/* ALIAS_FIXME */
DEFUN (config_quit,
config_quit_cmd,
"quit",
"Exit current mode and down to previous mode\n")
{
return config_exit(self, vty, argc, argv);
}
2002-12-13 21:15:29 +01:00
/* End of configuration. */
DEFUN (config_end,
config_end_cmd,
"end",
"End current mode and change to enable mode.\n")
2002-12-13 21:15:29 +01:00
{
if (vty->config) {
vty_config_exit(vty);
2002-12-13 21:15:29 +01:00
vty->node = ENABLE_NODE;
}
return CMD_SUCCESS;
}
/* Show version. */
DEFUN (show_version,
show_version_cmd,
"show version",
SHOW_STR
"Displays zebra version\n")
{
vty_out(vty, "%s %s (%s) on %s(%s).\n", FRR_FULL_NAME, FRR_VERSION,
cmd_hostname_get() ? cmd_hostname_get() : "", cmd_system_get(),
cmd_release_get());
vty_out(vty, "%s%s\n", FRR_COPYRIGHT, GIT_INFO);
#ifdef ENABLE_VERSION_BUILD_CONFIG
vty_out(vty, "configured with:\n %s\n", FRR_CONFIG_ARGS);
#endif
2002-12-13 21:15:29 +01:00
return CMD_SUCCESS;
}
/* Help display function for all node. */
DEFUN (config_help,
config_help_cmd,
"help",
"Description of the interactive help system\n")
{
vty_out(vty,
"FRR VTY provides advanced help feature. When you need help,\n\
anytime at the command line please press '?'.\n\
\n\
If nothing matches, the help list will be empty and you must backup\n\
until entering a '?' shows the available options.\n\
Two styles of help are provided:\n\
1. Full help is available when you are ready to enter a\n\
command argument (e.g. 'show ?') and describes each possible\n\
argument.\n\
2. Partial help is provided when an abbreviated argument is entered\n\
and you want to know what arguments match the input\n\
(e.g. 'show me?'.)\n\n");
2002-12-13 21:15:29 +01:00
return CMD_SUCCESS;
}
static void permute(struct graph_node *start, struct vty *vty)
{
static struct list *position = NULL;
if (!position)
position = list_new();
struct cmd_token *stok = start->data;
struct graph_node *gnn;
struct listnode *ln;
// recursive dfs
listnode_add(position, start);
for (unsigned int i = 0; i < vector_active(start->to); i++) {
struct graph_node *gn = vector_slot(start->to, i);
struct cmd_token *tok = gn->data;
if (tok->attr & CMD_ATTR_HIDDEN)
continue;
else if (tok->type == END_TKN || gn == start) {
vty_out(vty, " ");
for (ALL_LIST_ELEMENTS_RO(position, ln, gnn)) {
struct cmd_token *tt = gnn->data;
if (tt->type < SPECIAL_TKN)
vty_out(vty, " %s", tt->text);
}
if (gn == start)
vty_out(vty, "...");
vty_out(vty, "\n");
} else {
bool skip = false;
if (stok->type == FORK_TKN && tok->type != FORK_TKN)
for (ALL_LIST_ELEMENTS_RO(position, ln, gnn))
if (gnn == gn) {
skip = true;
break;
}
if (!skip)
permute(gn, vty);
}
}
list_delete_node(position, listtail(position));
}
static void print_cmd(struct vty *vty, const char *cmd)
{
int i, j, len = strlen(cmd);
char buf[len + 1];
bool skip = false;
j = 0;
for (i = 0; i < len; i++) {
/* skip varname */
if (cmd[i] == '$')
skip = true;
else if (strchr(" ()<>[]{}|", cmd[i]))
skip = false;
if (skip)
continue;
if (isspace(cmd[i])) {
/* skip leading whitespace */
if (i == 0)
continue;
/* skip trailing whitespace */
if (i == len - 1)
continue;
/* skip all whitespace after opening brackets or pipe */
if (strchr("(<[{|", cmd[i - 1])) {
while (isspace(cmd[i + 1]))
i++;
continue;
}
/* skip repeated whitespace */
if (isspace(cmd[i + 1]))
continue;
/* skip whitespace before closing brackets or pipe */
if (strchr(")>]}|", cmd[i + 1]))
continue;
/* convert tabs to spaces */
if (cmd[i] == '\t') {
buf[j++] = ' ';
continue;
}
}
buf[j++] = cmd[i];
}
buf[j] = 0;
vty_out(vty, "%s\n", buf);
}
int cmd_list_cmds(struct vty *vty, int do_permute)
2002-12-13 21:15:29 +01:00
{
struct cmd_node *node = vector_slot(cmdvec, vty->node);
if (do_permute) {
cmd_finalize_node(node);
permute(vector_slot(node->cmdgraph->nodes, 0), vty);
} else {
/* loop over all commands at this node */
const struct cmd_element *element = NULL;
for (unsigned int i = 0; i < vector_active(node->cmd_vector);
i++)
if ((element = vector_slot(node->cmd_vector, i)) &&
!(element->attr & CMD_ATTR_HIDDEN)) {
vty_out(vty, " ");
print_cmd(vty, element->string);
}
}
2002-12-13 21:15:29 +01:00
return CMD_SUCCESS;
}
/* Help display function for all node. */
DEFUN (config_list,
config_list_cmd,
"list [permutations]",
"Print command list\n"
"Print all possible command permutations\n")
{
return cmd_list_cmds(vty, argc == 2);
}
DEFUN (show_commandtree,
show_commandtree_cmd,
"show commandtree [permutations]",
SHOW_STR
"Show command tree\n"
"Permutations that we are interested in\n")
{
return cmd_list_cmds(vty, argc == 3);
}
DEFUN_HIDDEN(show_cli_graph,
show_cli_graph_cmd,
"show cli graph",
SHOW_STR
"CLI reflection\n"
"Dump current command space as DOT graph\n")
{
struct cmd_node *cn = vector_slot(cmdvec, vty->node);
char *dot;
cmd_finalize_node(cn);
dot = cmd_graph_dump_dot(cn->cmdgraph);
vty_out(vty, "%s\n", dot);
XFREE(MTYPE_TMP, dot);
return CMD_SUCCESS;
}
static int vty_write_config(struct vty *vty)
{
size_t i;
struct cmd_node *node;
if (host.noconfig)
return CMD_SUCCESS;
nb_cli_show_config_prepare(running_config, false);
if (vty->type == VTY_TERM) {
vty_out(vty, "\nCurrent configuration:\n");
vty_out(vty, "!\n");
}
if (strcmp(frr_defaults_version(), FRR_VER_SHORT))
vty_out(vty, "! loaded from %s\n", frr_defaults_version());
vty_out(vty, "frr version %s\n", FRR_VER_SHORT);
vty_out(vty, "frr defaults %s\n", frr_defaults_profile());
vty_out(vty, "!\n");
for (i = 0; i < vector_active(cmdvec); i++)
if ((node = vector_slot(cmdvec, i)) && node->config_write) {
if ((*node->config_write)(vty))
vty_out(vty, "!\n");
}
if (vty->type == VTY_TERM) {
vty_out(vty, "end\n");
}
return CMD_SUCCESS;
}
/* cross-reference frr_daemon_state_save in libfrr.c
* the code there is similar but not identical (state files always use the same
* name for the new write, and don't keep a backup of previous state.)
*/
static int file_write_config(struct vty *vty)
2002-12-13 21:15:29 +01:00
{
int fd, dirfd;
char *config_file, *slash;
2002-12-13 21:15:29 +01:00
char *config_file_tmp = NULL;
char *config_file_sav = NULL;
int ret = CMD_WARNING;
2002-12-13 21:15:29 +01:00
struct vty *file_vty;
struct stat conf_stat;
if (host.noconfig)
return CMD_SUCCESS;
2002-12-13 21:15:29 +01:00
/* Check and see if we are operating under vtysh configuration */
if (host.config == NULL) {
vty_out(vty,
"Can't save to configuration file, using vtysh.\n");
2002-12-13 21:15:29 +01:00
return CMD_WARNING;
}
2002-12-13 21:15:29 +01:00
/* Get filename. */
config_file = host.config;
#ifndef O_DIRECTORY
#define O_DIRECTORY 0
#endif
slash = strrchr(config_file, '/');
if (slash) {
char *config_dir = XSTRDUP(MTYPE_TMP, config_file);
config_dir[slash - config_file] = '\0';
dirfd = open(config_dir, O_DIRECTORY | O_RDONLY);
XFREE(MTYPE_TMP, config_dir);
} else
dirfd = open(".", O_DIRECTORY | O_RDONLY);
/* if dirfd is invalid, directory sync fails, but we're still OK */
size_t config_file_sav_sz = strlen(config_file) + strlen(CONF_BACKUP_EXT) + 1;
config_file_sav = XMALLOC(MTYPE_TMP, config_file_sav_sz);
strlcpy(config_file_sav, config_file, config_file_sav_sz);
strlcat(config_file_sav, CONF_BACKUP_EXT, config_file_sav_sz);
config_file_tmp = XMALLOC(MTYPE_TMP, strlen(config_file) + 8);
snprintf(config_file_tmp, strlen(config_file) + 8, "%s.XXXXXX",
config_file);
2002-12-13 21:15:29 +01:00
/* Open file to configuration write. */
fd = mkstemp(config_file_tmp);
if (fd < 0) {
vty_out(vty, "Can't open configuration file %s.\n",
config_file_tmp);
goto finished;
2002-12-13 21:15:29 +01:00
}
if (fchmod(fd, CONFIGFILE_MASK) != 0) {
vty_out(vty, "Can't chmod configuration file %s: %s (%d).\n",
config_file_tmp, safe_strerror(errno), errno);
goto finished;
}
2002-12-13 21:15:29 +01:00
/* Make vty for configuration file. */
file_vty = vty_new();
file_vty->wfd = fd;
2002-12-13 21:15:29 +01:00
file_vty->type = VTY_FILE;
2002-12-13 21:15:29 +01:00
/* Config file header print. */
vty_out(file_vty, "!\n! Zebra configuration saved from vty\n! ");
vty_time_print(file_vty, 1);
vty_out(file_vty, "!\n");
vty_write_config(file_vty);
2002-12-13 21:15:29 +01:00
vty_close(file_vty);
if (stat(config_file, &conf_stat) >= 0) {
if (unlink(config_file_sav) != 0)
if (errno != ENOENT) {
vty_out(vty,
"Can't unlink backup configuration file %s.\n",
config_file_sav);
goto finished;
}
if (link(config_file, config_file_sav) != 0) {
vty_out(vty,
"Can't backup old configuration file %s.\n",
config_file_sav);
goto finished;
}
if (dirfd >= 0)
fsync(dirfd);
2002-12-13 21:15:29 +01:00
}
if (rename(config_file_tmp, config_file) != 0) {
vty_out(vty, "Can't save configuration file %s.\n",
config_file);
goto finished;
2002-12-13 21:15:29 +01:00
}
if (dirfd >= 0)
fsync(dirfd);
vty_out(vty, "Configuration saved to %s\n", config_file);
ret = CMD_SUCCESS;
finished:
if (ret != CMD_SUCCESS)
unlink(config_file_tmp);
if (dirfd >= 0)
close(dirfd);
XFREE(MTYPE_TMP, config_file_tmp);
XFREE(MTYPE_TMP, config_file_sav);
return ret;
2002-12-13 21:15:29 +01:00
}
/* Write current configuration into file. */
DEFUN (config_write,
config_write_cmd,
"write [<file|memory|terminal>]",
"Write running configuration to memory, network, or terminal\n"
"Write to configuration file\n"
"Write configuration currently in memory\n"
"Write configuration to terminal\n")
{
const int idx_type = 1;
// if command was 'write terminal' or 'write memory'
if (argc == 2 && (!strcmp(argv[idx_type]->text, "terminal"))) {
return vty_write_config(vty);
}
return file_write_config(vty);
}
/* ALIAS_FIXME for 'write <terminal|memory>' */
DEFUN (show_running_config,
show_running_config_cmd,
"show running-config",
SHOW_STR
"running configuration (same as write terminal)\n")
{
return vty_write_config(vty);
}
2002-12-13 21:15:29 +01:00
/* ALIAS_FIXME for 'write file' */
DEFUN (copy_runningconf_startupconf,
copy_runningconf_startupconf_cmd,
"copy running-config startup-config",
"Copy configuration\n"
"Copy running config to... \n"
"Copy running config to startup config (same as write file/memory)\n")
{
return file_write_config(vty);
}
/** -- **/
2002-12-13 21:15:29 +01:00
/* Write startup configuration into the terminal. */
DEFUN (show_startup_config,
show_startup_config_cmd,
"show startup-config",
SHOW_STR
"Contents of startup configuration\n")
2002-12-13 21:15:29 +01:00
{
char buf[BUFSIZ];
FILE *confp;
if (host.noconfig)
return CMD_SUCCESS;
if (host.config == NULL)
return CMD_WARNING;
2002-12-13 21:15:29 +01:00
confp = fopen(host.config, "r");
if (confp == NULL) {
vty_out(vty, "Can't open configuration file [%s] due to '%s'\n",
host.config, safe_strerror(errno));
2002-12-13 21:15:29 +01:00
return CMD_WARNING;
}
while (fgets(buf, BUFSIZ, confp)) {
char *cp = buf;
while (*cp != '\r' && *cp != '\n' && *cp != '\0')
cp++;
2002-12-13 21:15:29 +01:00
*cp = '\0';
vty_out(vty, "%s\n", buf);
2002-12-13 21:15:29 +01:00
}
fclose(confp);
return CMD_SUCCESS;
}
int cmd_domainname_set(const char *domainname)
{
XFREE(MTYPE_HOST, host.domainname);
host.domainname = domainname ? XSTRDUP(MTYPE_HOST, domainname) : NULL;
return CMD_SUCCESS;
}
/* Hostname configuration */
DEFUN(config_domainname,
domainname_cmd,
"domainname WORD",
"Set system's domain name\n"
"This system's domain name\n")
{
struct cmd_token *word = argv[1];
if (!isalpha((unsigned char)word->arg[0])) {
vty_out(vty, "Please specify string starting with alphabet\n");
return CMD_WARNING_CONFIG_FAILED;
}
return cmd_domainname_set(word->arg);
}
DEFUN(config_no_domainname,
no_domainname_cmd,
"no domainname [DOMAINNAME]",
NO_STR
"Reset system's domain name\n"
"domain name of this router\n")
{
return cmd_domainname_set(NULL);
}
int cmd_hostname_set(const char *hostname)
{
XFREE(MTYPE_HOST, host.name);
host.name = hostname ? XSTRDUP(MTYPE_HOST, hostname) : NULL;
return CMD_SUCCESS;
}
2002-12-13 21:15:29 +01:00
/* Hostname configuration */
DEFUN (config_hostname,
2002-12-13 21:15:29 +01:00
hostname_cmd,
"hostname WORD",
"Set system's network name\n"
"This system's network name\n")
{
struct cmd_token *word = argv[1];
if (!isalnum((unsigned char)word->arg[0])) {
vty_out(vty,
"Please specify string starting with alphabet or number\n");
return CMD_WARNING_CONFIG_FAILED;
}
/* With reference to RFC 1123 Section 2.1 */
if (strlen(word->arg) > HOSTNAME_LEN) {
vty_out(vty, "Hostname length should be less than %d chars\n",
HOSTNAME_LEN);
return CMD_WARNING_CONFIG_FAILED;
2002-12-13 21:15:29 +01:00
}
return cmd_hostname_set(word->arg);
2002-12-13 21:15:29 +01:00
}
DEFUN (config_no_hostname,
2002-12-13 21:15:29 +01:00
no_hostname_cmd,
"no hostname [HOSTNAME]",
NO_STR
"Reset system's network name\n"
"Host name of this router\n")
{
return cmd_hostname_set(NULL);
2002-12-13 21:15:29 +01:00
}
/* VTY interface password set. */
DEFUN (config_password,
password_cmd,
"password [(8-8)] WORD",
"Modify the terminal connection password\n"
2002-12-13 21:15:29 +01:00
"Specifies a HIDDEN password will follow\n"
"The password string\n")
2002-12-13 21:15:29 +01:00
{
int idx_8 = 1;
int idx_word = 2;
if (argc == 3) // '8' was specified
{
if (host.password)
XFREE(MTYPE_HOST, host.password);
host.password = NULL;
if (host.password_encrypt)
XFREE(MTYPE_HOST, host.password_encrypt);
host.password_encrypt =
XSTRDUP(MTYPE_HOST, argv[idx_word]->arg);
return CMD_SUCCESS;
}
if (!isalnum((unsigned char)argv[idx_8]->arg[0])) {
vty_out(vty,
"Please specify string starting with alphanumeric\n");
return CMD_WARNING_CONFIG_FAILED;
2002-12-13 21:15:29 +01:00
}
2002-12-13 21:15:29 +01:00
if (host.password)
XFREE(MTYPE_HOST, host.password);
2002-12-13 21:15:29 +01:00
host.password = NULL;
2002-12-13 21:15:29 +01:00
if (host.encrypt) {
if (host.password_encrypt)
XFREE(MTYPE_HOST, host.password_encrypt);
host.password_encrypt =
XSTRDUP(MTYPE_HOST, zencrypt(argv[idx_8]->arg));
2002-12-13 21:15:29 +01:00
} else
host.password = XSTRDUP(MTYPE_HOST, argv[idx_8]->arg);
2002-12-13 21:15:29 +01:00
return CMD_SUCCESS;
}
/* VTY interface password delete. */
DEFUN (no_config_password,
no_password_cmd,
"no password",
NO_STR
"Modify the terminal connection password\n")
{
bool warned = false;
if (host.password) {
if (!vty_shell_serv(vty)) {
vty_out(vty, NO_PASSWD_CMD_WARNING);
warned = true;
}
XFREE(MTYPE_HOST, host.password);
}
host.password = NULL;
if (host.password_encrypt) {
if (!warned && !vty_shell_serv(vty))
vty_out(vty, NO_PASSWD_CMD_WARNING);
XFREE(MTYPE_HOST, host.password_encrypt);
}
host.password_encrypt = NULL;
return CMD_SUCCESS;
}
2002-12-13 21:15:29 +01:00
/* VTY enable password set. */
DEFUN (config_enable_password,
enable_password_cmd,
"enable password [(8-8)] WORD",
2002-12-13 21:15:29 +01:00
"Modify enable password parameters\n"
"Assign the privileged level password\n"
"Specifies a HIDDEN password will follow\n"
"The HIDDEN 'enable' password string\n")
{
int idx_8 = 2;
int idx_word = 3;
2002-12-13 21:15:29 +01:00
/* Crypt type is specified. */
if (argc == 4) {
if (argv[idx_8]->arg[0] == '8') {
if (host.enable)
XFREE(MTYPE_HOST, host.enable);
host.enable = NULL;
if (host.enable_encrypt)
XFREE(MTYPE_HOST, host.enable_encrypt);
host.enable_encrypt =
XSTRDUP(MTYPE_HOST, argv[idx_word]->arg);
return CMD_SUCCESS;
2002-12-13 21:15:29 +01:00
} else {
vty_out(vty, "Unknown encryption type.\n");
return CMD_WARNING_CONFIG_FAILED;
}
}
if (!isalnum((unsigned char)argv[idx_8]->arg[0])) {
vty_out(vty,
"Please specify string starting with alphanumeric\n");
return CMD_WARNING_CONFIG_FAILED;
2002-12-13 21:15:29 +01:00
}
2002-12-13 21:15:29 +01:00
if (host.enable)
XFREE(MTYPE_HOST, host.enable);
2002-12-13 21:15:29 +01:00
host.enable = NULL;
2002-12-13 21:15:29 +01:00
/* Plain password input. */
if (host.encrypt) {
if (host.enable_encrypt)
XFREE(MTYPE_HOST, host.enable_encrypt);
host.enable_encrypt =
XSTRDUP(MTYPE_HOST, zencrypt(argv[idx_8]->arg));
2002-12-13 21:15:29 +01:00
} else
host.enable = XSTRDUP(MTYPE_HOST, argv[idx_8]->arg);
2002-12-13 21:15:29 +01:00
return CMD_SUCCESS;
}
/* VTY enable password delete. */
DEFUN (no_config_enable_password,
no_enable_password_cmd,
2002-12-13 21:15:29 +01:00
"no enable password",
NO_STR
"Modify enable password parameters\n"
"Assign the privileged level password\n")
{
bool warned = false;
if (host.enable) {
if (!vty_shell_serv(vty)) {
vty_out(vty, NO_PASSWD_CMD_WARNING);
warned = true;
}
XFREE(MTYPE_HOST, host.enable);
}
2002-12-13 21:15:29 +01:00
host.enable = NULL;
if (host.enable_encrypt) {
if (!warned && !vty_shell_serv(vty))
vty_out(vty, NO_PASSWD_CMD_WARNING);
XFREE(MTYPE_HOST, host.enable_encrypt);
}
2002-12-13 21:15:29 +01:00
host.enable_encrypt = NULL;
return CMD_SUCCESS;
}
2002-12-13 21:15:29 +01:00
DEFUN (service_password_encrypt,
service_password_encrypt_cmd,
"service password-encryption",
"Set up miscellaneous service\n"
"Enable encrypted passwords\n")
{
if (host.encrypt)
return CMD_SUCCESS;
host.encrypt = 1;
if (host.password) {
if (host.password_encrypt)
XFREE(MTYPE_HOST, host.password_encrypt);
host.password_encrypt =
XSTRDUP(MTYPE_HOST, zencrypt(host.password));
2002-12-13 21:15:29 +01:00
}
if (host.enable) {
if (host.enable_encrypt)
XFREE(MTYPE_HOST, host.enable_encrypt);
host.enable_encrypt =
XSTRDUP(MTYPE_HOST, zencrypt(host.enable));
2002-12-13 21:15:29 +01:00
}
return CMD_SUCCESS;
}
DEFUN (no_service_password_encrypt,
no_service_password_encrypt_cmd,
"no service password-encryption",
NO_STR
"Set up miscellaneous service\n"
"Enable encrypted passwords\n")
{
if (!host.encrypt)
return CMD_SUCCESS;
host.encrypt = 0;
if (host.password_encrypt)
XFREE(MTYPE_HOST, host.password_encrypt);
2002-12-13 21:15:29 +01:00
host.password_encrypt = NULL;
if (host.enable_encrypt)
XFREE(MTYPE_HOST, host.enable_encrypt);
2002-12-13 21:15:29 +01:00
host.enable_encrypt = NULL;
return CMD_SUCCESS;
}
DEFUN (config_terminal_length,
config_terminal_length_cmd,
"terminal length (0-512)",
2002-12-13 21:15:29 +01:00
"Set terminal line parameters\n"
"Set number of lines on a screen\n"
"Number of lines on screen (0 for no pausing)\n")
{
int idx_number = 2;
2002-12-13 21:15:29 +01:00
vty->lines = atoi(argv[idx_number]->arg);
2002-12-13 21:15:29 +01:00
return CMD_SUCCESS;
}
DEFUN (config_terminal_no_length,
config_terminal_no_length_cmd,
2002-12-13 21:15:29 +01:00
"terminal no length",
"Set terminal line parameters\n"
NO_STR
"Set number of lines on a screen\n")
{
vty->lines = -1;
return CMD_SUCCESS;
}
DEFUN (service_terminal_length,
service_terminal_length_cmd,
"service terminal-length (0-512)",
2002-12-13 21:15:29 +01:00
"Set up miscellaneous service\n"
"System wide terminal length configuration\n"
"Number of lines of VTY (0 means no line control)\n")
{
int idx_number = 2;
2002-12-13 21:15:29 +01:00
host.lines = atoi(argv[idx_number]->arg);
2002-12-13 21:15:29 +01:00
return CMD_SUCCESS;
}
DEFUN (no_service_terminal_length,
no_service_terminal_length_cmd,
"no service terminal-length [(0-512)]",
2002-12-13 21:15:29 +01:00
NO_STR
"Set up miscellaneous service\n"
"System wide terminal length configuration\n"
"Number of lines of VTY (0 means no line control)\n")
{
host.lines = -1;
return CMD_SUCCESS;
}
DEFUN_HIDDEN (do_echo,
echo_cmd,
"echo MESSAGE...",
"Echo a message back to the vty\n"
"The message to echo\n")
{
char *message;
vty_out(vty, "%s\n",
((message = argv_concat(argv, argc, 1)) ? message : ""));
if (message)
XFREE(MTYPE_TMP, message);
return CMD_SUCCESS;
}
2004-12-07 Andrew J. Schorr <ajschorr@alumni.princeton.edu> * bgp_main.c: (main) The 2nd argument to openzlog has been removed. * isis_main.c: (main) The 2nd argument to openzlog has been removed. * ospf6_main.c: (main) The 2nd argument to openzlog has been removed. Note that stdout logging will no longer be enabled by default when not running as a daemon. * ospf_main.c: (main) The 2nd argument to openzlog has been removed. * rip_main.c: (main) The 2nd argument to openzlog has been removed. * ripng_main.c: (main) The 2nd argument to openzlog has been removed. * main.c: (main) The 2nd argument to openzlog has been removed. So stdout logging will no longer be enabled by default. * irdp_main.c: (irdp_finish) Reduce severity of shutdown message from LOG_WARNING to LOG_INFO. * vtysh.c: Make several functions static instead of global. Added several commands to support destination-specific logging levels. (vtysh_completion) This function is unused, so comment it out. * basic.texi: Document new logging features. Separate basic config commands from basic VTY commands. * log.h: Replace struct zlog flags and maskpri fields with maxlvl array to support individual logging levels for each destination. Remove the 2nd argument to openzlog since the default logging config should be standardized inside the library. Replaced the zlog_set_flag and zlog_reset_flag functions with zlog_set_level. And zlog_set_file now requires an additional log_level argument. Declare zlog_proto_names for use inside command.c in the "show logging" command. Added defines useful for command construction. * log.c: (vzlog) Decide where to send the message based on the individual logging levels configured for each destination. Remove support for ZLOG_STDERR since it was never actually used. Support record-priority for terminal monitors. (zlog_signal,zlog_backtrace_sigsafe) Support destination-specific logging levels. Remove stderr support (was never used). Added support for terminal monitor logging. (_zlog_assert_failed) Increase message severity to LOG_EMERG. (openzlog) Remove 2nd argument since default config should be standardized in library. By default, terminal monitoring is set to debug, and all other logging is disabled. (zlog_set_flag,zlog_reset_flag) Removed. (zlog_set_level) New function to replace zlog_set_flag and zlog_reset_flag. Supports destination-specific logging levels. (zlog_set_file,zlog_reset_file) Support file-specific logging level. (zlog_rotate) Log an error message if fopen fails, and support new file-specific logging level. * command.h: Change DEFUN_CMD_FUNC_DECL and DEFUN_CMD_FUNC_TEXT so that command functions will be static instead of global. Remove declarations for config_exit and config_help. Define new macros DEFUNSH_ATTR, DEFUNSH_HIDDEN, and DEFUNSH_DEPRECATED so we can have deprecated commands in vtysh. Similarly, for completeness, define macros ALIAS_SH, ALIAS_SH_HIDDEN, and ALIAS_SH_DEPRECATED. Also, fix bug in ALIAS_ATTR macro (didn't matter because it was never used). * command.c: Make many functions static instead of global. (facility_name,facility_match,level_match) New functions to support enhanced destination-specific logging levels. (config_write_host) Support new destination-specific logging levels. (config_logmsg) Added new "logmsg" command to help test logging system. (show_logging) Added "show logging" command to show the current configuration of the logging system. (config_log_stdout_level) Support explicit stdout logging level. (no_config_log_stdout) Now takes optional LEVEL arg. (config_log_monitor,config_log_monitor_level,no_config_log_monitor) New commands creating new "log monitor" commands to set terminal monitoring log level. (config_log_file_level) Support explicit file logging level. (config_log_syslog_level) Support explicit syslog logging level. (config_log_facility,no_config_log_facility) Implement new "log facility" command. (cmd_init) Add hooks for new commands: "show logging", "logmsg", "log stdout <level>", "log monitor", "log monitor <level>", "no log monitor", "log file <filename> <level>", "no log file <filename> <level>", "log syslog <level>", "log facility", and "no log facility". * vty.h: Added a "level" argument to vty_log so it can support "log record-priority". Declare new function vty_log_fixed for use in signal handlers. * vty.c: (vty_log,vty_log_out) Added a "level" argument to support "log record-priority" for vty terminal monitors. (vty_down_level) Use config_exit_cmd.func instead of calling config_exit directly (since command functions will now be static instead of global). (vty_log_fixed) New function to send terminal monitor messages from inside a signal handler.
2004-12-07 16:39:31 +01:00
DEFUN (config_logmsg,
config_logmsg_cmd,
"logmsg <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging> MESSAGE...",
2004-12-07 Andrew J. Schorr <ajschorr@alumni.princeton.edu> * bgp_main.c: (main) The 2nd argument to openzlog has been removed. * isis_main.c: (main) The 2nd argument to openzlog has been removed. * ospf6_main.c: (main) The 2nd argument to openzlog has been removed. Note that stdout logging will no longer be enabled by default when not running as a daemon. * ospf_main.c: (main) The 2nd argument to openzlog has been removed. * rip_main.c: (main) The 2nd argument to openzlog has been removed. * ripng_main.c: (main) The 2nd argument to openzlog has been removed. * main.c: (main) The 2nd argument to openzlog has been removed. So stdout logging will no longer be enabled by default. * irdp_main.c: (irdp_finish) Reduce severity of shutdown message from LOG_WARNING to LOG_INFO. * vtysh.c: Make several functions static instead of global. Added several commands to support destination-specific logging levels. (vtysh_completion) This function is unused, so comment it out. * basic.texi: Document new logging features. Separate basic config commands from basic VTY commands. * log.h: Replace struct zlog flags and maskpri fields with maxlvl array to support individual logging levels for each destination. Remove the 2nd argument to openzlog since the default logging config should be standardized inside the library. Replaced the zlog_set_flag and zlog_reset_flag functions with zlog_set_level. And zlog_set_file now requires an additional log_level argument. Declare zlog_proto_names for use inside command.c in the "show logging" command. Added defines useful for command construction. * log.c: (vzlog) Decide where to send the message based on the individual logging levels configured for each destination. Remove support for ZLOG_STDERR since it was never actually used. Support record-priority for terminal monitors. (zlog_signal,zlog_backtrace_sigsafe) Support destination-specific logging levels. Remove stderr support (was never used). Added support for terminal monitor logging. (_zlog_assert_failed) Increase message severity to LOG_EMERG. (openzlog) Remove 2nd argument since default config should be standardized in library. By default, terminal monitoring is set to debug, and all other logging is disabled. (zlog_set_flag,zlog_reset_flag) Removed. (zlog_set_level) New function to replace zlog_set_flag and zlog_reset_flag. Supports destination-specific logging levels. (zlog_set_file,zlog_reset_file) Support file-specific logging level. (zlog_rotate) Log an error message if fopen fails, and support new file-specific logging level. * command.h: Change DEFUN_CMD_FUNC_DECL and DEFUN_CMD_FUNC_TEXT so that command functions will be static instead of global. Remove declarations for config_exit and config_help. Define new macros DEFUNSH_ATTR, DEFUNSH_HIDDEN, and DEFUNSH_DEPRECATED so we can have deprecated commands in vtysh. Similarly, for completeness, define macros ALIAS_SH, ALIAS_SH_HIDDEN, and ALIAS_SH_DEPRECATED. Also, fix bug in ALIAS_ATTR macro (didn't matter because it was never used). * command.c: Make many functions static instead of global. (facility_name,facility_match,level_match) New functions to support enhanced destination-specific logging levels. (config_write_host) Support new destination-specific logging levels. (config_logmsg) Added new "logmsg" command to help test logging system. (show_logging) Added "show logging" command to show the current configuration of the logging system. (config_log_stdout_level) Support explicit stdout logging level. (no_config_log_stdout) Now takes optional LEVEL arg. (config_log_monitor,config_log_monitor_level,no_config_log_monitor) New commands creating new "log monitor" commands to set terminal monitoring log level. (config_log_file_level) Support explicit file logging level. (config_log_syslog_level) Support explicit syslog logging level. (config_log_facility,no_config_log_facility) Implement new "log facility" command. (cmd_init) Add hooks for new commands: "show logging", "logmsg", "log stdout <level>", "log monitor", "log monitor <level>", "no log monitor", "log file <filename> <level>", "no log file <filename> <level>", "log syslog <level>", "log facility", and "no log facility". * vty.h: Added a "level" argument to vty_log so it can support "log record-priority". Declare new function vty_log_fixed for use in signal handlers. * vty.c: (vty_log,vty_log_out) Added a "level" argument to support "log record-priority" for vty terminal monitors. (vty_down_level) Use config_exit_cmd.func instead of calling config_exit directly (since command functions will now be static instead of global). (vty_log_fixed) New function to send terminal monitor messages from inside a signal handler.
2004-12-07 16:39:31 +01:00
"Send a message to enabled logging destinations\n"
LOG_LEVEL_DESC
"The message to send\n")
{
int idx_log_level = 1;
int idx_message = 2;
2004-12-07 Andrew J. Schorr <ajschorr@alumni.princeton.edu> * bgp_main.c: (main) The 2nd argument to openzlog has been removed. * isis_main.c: (main) The 2nd argument to openzlog has been removed. * ospf6_main.c: (main) The 2nd argument to openzlog has been removed. Note that stdout logging will no longer be enabled by default when not running as a daemon. * ospf_main.c: (main) The 2nd argument to openzlog has been removed. * rip_main.c: (main) The 2nd argument to openzlog has been removed. * ripng_main.c: (main) The 2nd argument to openzlog has been removed. * main.c: (main) The 2nd argument to openzlog has been removed. So stdout logging will no longer be enabled by default. * irdp_main.c: (irdp_finish) Reduce severity of shutdown message from LOG_WARNING to LOG_INFO. * vtysh.c: Make several functions static instead of global. Added several commands to support destination-specific logging levels. (vtysh_completion) This function is unused, so comment it out. * basic.texi: Document new logging features. Separate basic config commands from basic VTY commands. * log.h: Replace struct zlog flags and maskpri fields with maxlvl array to support individual logging levels for each destination. Remove the 2nd argument to openzlog since the default logging config should be standardized inside the library. Replaced the zlog_set_flag and zlog_reset_flag functions with zlog_set_level. And zlog_set_file now requires an additional log_level argument. Declare zlog_proto_names for use inside command.c in the "show logging" command. Added defines useful for command construction. * log.c: (vzlog) Decide where to send the message based on the individual logging levels configured for each destination. Remove support for ZLOG_STDERR since it was never actually used. Support record-priority for terminal monitors. (zlog_signal,zlog_backtrace_sigsafe) Support destination-specific logging levels. Remove stderr support (was never used). Added support for terminal monitor logging. (_zlog_assert_failed) Increase message severity to LOG_EMERG. (openzlog) Remove 2nd argument since default config should be standardized in library. By default, terminal monitoring is set to debug, and all other logging is disabled. (zlog_set_flag,zlog_reset_flag) Removed. (zlog_set_level) New function to replace zlog_set_flag and zlog_reset_flag. Supports destination-specific logging levels. (zlog_set_file,zlog_reset_file) Support file-specific logging level. (zlog_rotate) Log an error message if fopen fails, and support new file-specific logging level. * command.h: Change DEFUN_CMD_FUNC_DECL and DEFUN_CMD_FUNC_TEXT so that command functions will be static instead of global. Remove declarations for config_exit and config_help. Define new macros DEFUNSH_ATTR, DEFUNSH_HIDDEN, and DEFUNSH_DEPRECATED so we can have deprecated commands in vtysh. Similarly, for completeness, define macros ALIAS_SH, ALIAS_SH_HIDDEN, and ALIAS_SH_DEPRECATED. Also, fix bug in ALIAS_ATTR macro (didn't matter because it was never used). * command.c: Make many functions static instead of global. (facility_name,facility_match,level_match) New functions to support enhanced destination-specific logging levels. (config_write_host) Support new destination-specific logging levels. (config_logmsg) Added new "logmsg" command to help test logging system. (show_logging) Added "show logging" command to show the current configuration of the logging system. (config_log_stdout_level) Support explicit stdout logging level. (no_config_log_stdout) Now takes optional LEVEL arg. (config_log_monitor,config_log_monitor_level,no_config_log_monitor) New commands creating new "log monitor" commands to set terminal monitoring log level. (config_log_file_level) Support explicit file logging level. (config_log_syslog_level) Support explicit syslog logging level. (config_log_facility,no_config_log_facility) Implement new "log facility" command. (cmd_init) Add hooks for new commands: "show logging", "logmsg", "log stdout <level>", "log monitor", "log monitor <level>", "no log monitor", "log file <filename> <level>", "no log file <filename> <level>", "log syslog <level>", "log facility", and "no log facility". * vty.h: Added a "level" argument to vty_log so it can support "log record-priority". Declare new function vty_log_fixed for use in signal handlers. * vty.c: (vty_log,vty_log_out) Added a "level" argument to support "log record-priority" for vty terminal monitors. (vty_down_level) Use config_exit_cmd.func instead of calling config_exit directly (since command functions will now be static instead of global). (vty_log_fixed) New function to send terminal monitor messages from inside a signal handler.
2004-12-07 16:39:31 +01:00
int level;
char *message;
level = log_level_match(argv[idx_log_level]->arg);
if (level == ZLOG_DISABLED)
2004-12-07 Andrew J. Schorr <ajschorr@alumni.princeton.edu> * bgp_main.c: (main) The 2nd argument to openzlog has been removed. * isis_main.c: (main) The 2nd argument to openzlog has been removed. * ospf6_main.c: (main) The 2nd argument to openzlog has been removed. Note that stdout logging will no longer be enabled by default when not running as a daemon. * ospf_main.c: (main) The 2nd argument to openzlog has been removed. * rip_main.c: (main) The 2nd argument to openzlog has been removed. * ripng_main.c: (main) The 2nd argument to openzlog has been removed. * main.c: (main) The 2nd argument to openzlog has been removed. So stdout logging will no longer be enabled by default. * irdp_main.c: (irdp_finish) Reduce severity of shutdown message from LOG_WARNING to LOG_INFO. * vtysh.c: Make several functions static instead of global. Added several commands to support destination-specific logging levels. (vtysh_completion) This function is unused, so comment it out. * basic.texi: Document new logging features. Separate basic config commands from basic VTY commands. * log.h: Replace struct zlog flags and maskpri fields with maxlvl array to support individual logging levels for each destination. Remove the 2nd argument to openzlog since the default logging config should be standardized inside the library. Replaced the zlog_set_flag and zlog_reset_flag functions with zlog_set_level. And zlog_set_file now requires an additional log_level argument. Declare zlog_proto_names for use inside command.c in the "show logging" command. Added defines useful for command construction. * log.c: (vzlog) Decide where to send the message based on the individual logging levels configured for each destination. Remove support for ZLOG_STDERR since it was never actually used. Support record-priority for terminal monitors. (zlog_signal,zlog_backtrace_sigsafe) Support destination-specific logging levels. Remove stderr support (was never used). Added support for terminal monitor logging. (_zlog_assert_failed) Increase message severity to LOG_EMERG. (openzlog) Remove 2nd argument since default config should be standardized in library. By default, terminal monitoring is set to debug, and all other logging is disabled. (zlog_set_flag,zlog_reset_flag) Removed. (zlog_set_level) New function to replace zlog_set_flag and zlog_reset_flag. Supports destination-specific logging levels. (zlog_set_file,zlog_reset_file) Support file-specific logging level. (zlog_rotate) Log an error message if fopen fails, and support new file-specific logging level. * command.h: Change DEFUN_CMD_FUNC_DECL and DEFUN_CMD_FUNC_TEXT so that command functions will be static instead of global. Remove declarations for config_exit and config_help. Define new macros DEFUNSH_ATTR, DEFUNSH_HIDDEN, and DEFUNSH_DEPRECATED so we can have deprecated commands in vtysh. Similarly, for completeness, define macros ALIAS_SH, ALIAS_SH_HIDDEN, and ALIAS_SH_DEPRECATED. Also, fix bug in ALIAS_ATTR macro (didn't matter because it was never used). * command.c: Make many functions static instead of global. (facility_name,facility_match,level_match) New functions to support enhanced destination-specific logging levels. (config_write_host) Support new destination-specific logging levels. (config_logmsg) Added new "logmsg" command to help test logging system. (show_logging) Added "show logging" command to show the current configuration of the logging system. (config_log_stdout_level) Support explicit stdout logging level. (no_config_log_stdout) Now takes optional LEVEL arg. (config_log_monitor,config_log_monitor_level,no_config_log_monitor) New commands creating new "log monitor" commands to set terminal monitoring log level. (config_log_file_level) Support explicit file logging level. (config_log_syslog_level) Support explicit syslog logging level. (config_log_facility,no_config_log_facility) Implement new "log facility" command. (cmd_init) Add hooks for new commands: "show logging", "logmsg", "log stdout <level>", "log monitor", "log monitor <level>", "no log monitor", "log file <filename> <level>", "no log file <filename> <level>", "log syslog <level>", "log facility", and "no log facility". * vty.h: Added a "level" argument to vty_log so it can support "log record-priority". Declare new function vty_log_fixed for use in signal handlers. * vty.c: (vty_log,vty_log_out) Added a "level" argument to support "log record-priority" for vty terminal monitors. (vty_down_level) Use config_exit_cmd.func instead of calling config_exit directly (since command functions will now be static instead of global). (vty_log_fixed) New function to send terminal monitor messages from inside a signal handler.
2004-12-07 16:39:31 +01:00
return CMD_ERR_NO_MATCH;
zlog(level, "%s",
((message = argv_concat(argv, argc, idx_message)) ? message : ""));
if (message)
XFREE(MTYPE_TMP, message);
bgpd: add L3/L2VPN Virtual Network Control feature This feature adds an L3 & L2 VPN application that makes use of the VPN and Encap SAFIs. This code is currently used to support IETF NVO3 style operation. In NVO3 terminology it provides the Network Virtualization Authority (NVA) and the ability to import/export IP prefixes and MAC addresses from Network Virtualization Edges (NVEs). The code supports per-NVE tables. The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2 (L2) forwarding information between NVAs and NVEs is referred to as the Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For general background on NVO3 and RFP concepts see [1]. For information on Openflow see [2]. RFPs are integrated with BGP via the RF API contained in the new "rfapi" BGP sub-directory. Currently, only a simple example RFP is included in Quagga. Developers may use this example as a starting point to integrate Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code also supports the ability import/export of routing information between VNC and customer edge routers (CEs) operating within a virtual network. Import/export may take place between BGP views or to the default zebera VRF. BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN information between NVAs. BGP based IP VPN support is defined in RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659, BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use of both the Encapsulation Subsequent Address Family Identifier (SAFI) and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation Subsequent Address Family Identifier (SAFI) and the BGP Tunnel Encapsulation Attribute, are supported. MAC address distribution does not follow any standard BGB encoding, although it was inspired by the early IETF EVPN concepts. The feature is conditionally compiled and disabled by default. Use the --enable-bgp-vnc configure option to enable. The majority of this code was authored by G. Paul Ziemba <paulz@labn.net>. [1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req [2] https://www.opennetworking.org/sdn-resources/technical-library Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
2004-12-07 Andrew J. Schorr <ajschorr@alumni.princeton.edu> * bgp_main.c: (main) The 2nd argument to openzlog has been removed. * isis_main.c: (main) The 2nd argument to openzlog has been removed. * ospf6_main.c: (main) The 2nd argument to openzlog has been removed. Note that stdout logging will no longer be enabled by default when not running as a daemon. * ospf_main.c: (main) The 2nd argument to openzlog has been removed. * rip_main.c: (main) The 2nd argument to openzlog has been removed. * ripng_main.c: (main) The 2nd argument to openzlog has been removed. * main.c: (main) The 2nd argument to openzlog has been removed. So stdout logging will no longer be enabled by default. * irdp_main.c: (irdp_finish) Reduce severity of shutdown message from LOG_WARNING to LOG_INFO. * vtysh.c: Make several functions static instead of global. Added several commands to support destination-specific logging levels. (vtysh_completion) This function is unused, so comment it out. * basic.texi: Document new logging features. Separate basic config commands from basic VTY commands. * log.h: Replace struct zlog flags and maskpri fields with maxlvl array to support individual logging levels for each destination. Remove the 2nd argument to openzlog since the default logging config should be standardized inside the library. Replaced the zlog_set_flag and zlog_reset_flag functions with zlog_set_level. And zlog_set_file now requires an additional log_level argument. Declare zlog_proto_names for use inside command.c in the "show logging" command. Added defines useful for command construction. * log.c: (vzlog) Decide where to send the message based on the individual logging levels configured for each destination. Remove support for ZLOG_STDERR since it was never actually used. Support record-priority for terminal monitors. (zlog_signal,zlog_backtrace_sigsafe) Support destination-specific logging levels. Remove stderr support (was never used). Added support for terminal monitor logging. (_zlog_assert_failed) Increase message severity to LOG_EMERG. (openzlog) Remove 2nd argument since default config should be standardized in library. By default, terminal monitoring is set to debug, and all other logging is disabled. (zlog_set_flag,zlog_reset_flag) Removed. (zlog_set_level) New function to replace zlog_set_flag and zlog_reset_flag. Supports destination-specific logging levels. (zlog_set_file,zlog_reset_file) Support file-specific logging level. (zlog_rotate) Log an error message if fopen fails, and support new file-specific logging level. * command.h: Change DEFUN_CMD_FUNC_DECL and DEFUN_CMD_FUNC_TEXT so that command functions will be static instead of global. Remove declarations for config_exit and config_help. Define new macros DEFUNSH_ATTR, DEFUNSH_HIDDEN, and DEFUNSH_DEPRECATED so we can have deprecated commands in vtysh. Similarly, for completeness, define macros ALIAS_SH, ALIAS_SH_HIDDEN, and ALIAS_SH_DEPRECATED. Also, fix bug in ALIAS_ATTR macro (didn't matter because it was never used). * command.c: Make many functions static instead of global. (facility_name,facility_match,level_match) New functions to support enhanced destination-specific logging levels. (config_write_host) Support new destination-specific logging levels. (config_logmsg) Added new "logmsg" command to help test logging system. (show_logging) Added "show logging" command to show the current configuration of the logging system. (config_log_stdout_level) Support explicit stdout logging level. (no_config_log_stdout) Now takes optional LEVEL arg. (config_log_monitor,config_log_monitor_level,no_config_log_monitor) New commands creating new "log monitor" commands to set terminal monitoring log level. (config_log_file_level) Support explicit file logging level. (config_log_syslog_level) Support explicit syslog logging level. (config_log_facility,no_config_log_facility) Implement new "log facility" command. (cmd_init) Add hooks for new commands: "show logging", "logmsg", "log stdout <level>", "log monitor", "log monitor <level>", "no log monitor", "log file <filename> <level>", "no log file <filename> <level>", "log syslog <level>", "log facility", and "no log facility". * vty.h: Added a "level" argument to vty_log so it can support "log record-priority". Declare new function vty_log_fixed for use in signal handlers. * vty.c: (vty_log,vty_log_out) Added a "level" argument to support "log record-priority" for vty terminal monitors. (vty_down_level) Use config_exit_cmd.func instead of calling config_exit directly (since command functions will now be static instead of global). (vty_log_fixed) New function to send terminal monitor messages from inside a signal handler.
2004-12-07 16:39:31 +01:00
return CMD_SUCCESS;
}
DEFUN (debug_memstats,
debug_memstats_cmd,
"[no] debug memstats-at-exit",
NO_STR
DEBUG_STR
"Print memory type statistics at exit\n")
{
debug_memstats_at_exit = !!strcmp(argv[0]->text, "no");
return CMD_SUCCESS;
}
int cmd_banner_motd_file(const char *file)
{
int success = CMD_SUCCESS;
char p[PATH_MAX];
char *rpath;
char *in;
rpath = realpath(file, p);
if (!rpath)
return CMD_ERR_NO_FILE;
in = strstr(rpath, SYSCONFDIR);
if (in == rpath) {
XFREE(MTYPE_HOST, host.motdfile);
host.motdfile = XSTRDUP(MTYPE_HOST, file);
} else
success = CMD_WARNING_CONFIG_FAILED;
return success;
}
void cmd_banner_motd_line(const char *line)
{
XFREE(MTYPE_HOST, host.motd);
host.motd = XSTRDUP(MTYPE_HOST, line);
}
DEFUN (banner_motd_file,
banner_motd_file_cmd,
"banner motd file FILE",
"Set banner\n"
"Banner for motd\n"
"Banner from a file\n"
"Filename\n")
{
int idx_file = 3;
const char *filename = argv[idx_file]->arg;
int cmd = cmd_banner_motd_file(filename);
if (cmd == CMD_ERR_NO_FILE)
vty_out(vty, "%s does not exist\n", filename);
else if (cmd == CMD_WARNING_CONFIG_FAILED)
vty_out(vty, "%s must be in %s\n", filename, SYSCONFDIR);
return cmd;
}
2002-12-13 21:15:29 +01:00
DEFUN (banner_motd_line,
banner_motd_line_cmd,
"banner motd line LINE...",
"Set banner\n"
"Banner for motd\n"
"Banner from an input\n"
"Text\n")
{
int idx = 0;
char *motd;
argv_find(argv, argc, "LINE", &idx);
motd = argv_concat(argv, argc, idx);
cmd_banner_motd_line(motd);
XFREE(MTYPE_TMP, motd);
return CMD_SUCCESS;
}
2002-12-13 21:15:29 +01:00
DEFUN (banner_motd_default,
banner_motd_default_cmd,
"banner motd default",
"Set banner string\n"
"Strings for motd\n"
"Default string\n")
{
cmd_banner_motd_line(FRR_DEFAULT_MOTD);
2002-12-13 21:15:29 +01:00
return CMD_SUCCESS;
}
DEFUN (no_banner_motd,
no_banner_motd_cmd,
"no banner motd",
NO_STR
"Set banner string\n"
"Strings for motd\n")
{
host.motd = NULL;
if (host.motdfile)
XFREE(MTYPE_HOST, host.motdfile);
host.motdfile = NULL;
2002-12-13 21:15:29 +01:00
return CMD_SUCCESS;
}
DEFUN(allow_reserved_ranges, allow_reserved_ranges_cmd, "allow-reserved-ranges",
"Allow using IPv4 (Class E) reserved IP space\n")
{
host.allow_reserved_ranges = true;
return CMD_SUCCESS;
}
DEFUN(no_allow_reserved_ranges, no_allow_reserved_ranges_cmd,
"no allow-reserved-ranges",
NO_STR "Allow using IPv4 (Class E) reserved IP space\n")
{
host.allow_reserved_ranges = false;
return CMD_SUCCESS;
}
int cmd_find_cmds(struct vty *vty, struct cmd_token **argv, int argc)
{
const struct cmd_node *node;
const struct cmd_element *cli;
vector clis;
regex_t exp = {};
char *pattern = argv_concat(argv, argc, 1);
int cr = regcomp(&exp, pattern, REG_NOSUB | REG_EXTENDED);
XFREE(MTYPE_TMP, pattern);
if (cr != 0) {
switch (cr) {
case REG_BADBR:
vty_out(vty, "%% Invalid {...} expression\n");
break;
case REG_BADRPT:
vty_out(vty, "%% Bad repetition operator\n");
break;
case REG_BADPAT:
vty_out(vty, "%% Regex syntax error\n");
break;
case REG_ECOLLATE:
vty_out(vty, "%% Invalid collating element\n");
break;
case REG_ECTYPE:
vty_out(vty, "%% Invalid character class name\n");
break;
case REG_EESCAPE:
vty_out(vty,
"%% Regex ended with escape character (\\)\n");
break;
case REG_ESUBREG:
vty_out(vty,
"%% Invalid number in \\digit construction\n");
break;
case REG_EBRACK:
vty_out(vty, "%% Unbalanced square brackets\n");
break;
case REG_EPAREN:
vty_out(vty, "%% Unbalanced parentheses\n");
break;
case REG_EBRACE:
vty_out(vty, "%% Unbalanced braces\n");
break;
case REG_ERANGE:
vty_out(vty,
"%% Invalid endpoint in range expression\n");
break;
case REG_ESPACE:
vty_out(vty, "%% Failed to compile (out of memory)\n");
break;
}
goto done;
}
for (unsigned int i = 0; i < vector_active(cmdvec); i++) {
node = vector_slot(cmdvec, i);
if (!node)
continue;
clis = node->cmd_vector;
for (unsigned int j = 0; j < vector_active(clis); j++) {
cli = vector_slot(clis, j);
if (regexec(&exp, cli->string, 0, NULL, 0) == 0) {
vty_out(vty, " (%s) ", node->name);
print_cmd(vty, cli->string);
}
}
}
done:
regfree(&exp);
return CMD_SUCCESS;
}
DEFUN(find,
find_cmd,
"find REGEX...",
"Find CLI command matching a regular expression\n"
"Search pattern (POSIX regex)\n")
{
return cmd_find_cmds(vty, argv, argc);
}
#if defined(DEV_BUILD) && defined(HAVE_SCRIPTING)
DEFUN(script, script_cmd, "script SCRIPT FUNCTION",
"Test command - execute a function in a script\n"
"Script name (same as filename in /etc/frr/scripts/)\n"
"Function name (in the script)\n")
lib: start adding generic scripting stuff Rather than let Luaisms propagate from the start, this is some generic wrapper stuff that defines some semantics for interacting with scripts that aren't specific to the underlying language. The concept I have in mind for FRR's idea of a script is: - has a name - has some inputs, which have types - has some outputs, which have types I don't want to even say they have to be files; maybe we can embed scripts in frr.conf, for example. Similarly the types of inputs and outputs are probably going to end up being some language-specific setup. For now, we will stick to this simple model, but the plan is to add full object support (ie calling back into C). This shouldn't be misconstrued as prepping for multilingual scripting support, which is a bad idea for the following reasons: - Each language would require different FFI methods, and specifically different object encoders; a lot of code - Languages have different capabilities that would have to be brought to parity with each other; a lot of work - Languages have *vastly* different performance characteristics; bad impressions, lots of issues we can't do anything about - Each language would need a dedicated maintainer for the above reasons; pragmatically difficult - Supporting multiple languages fractures the community and limits the audience with which a given script can be shared The only pro for multilingual support would be ease of use for users not familiar with Lua but familiar with one of the other supported languages. This is not enough to outweigh the cons. In order to get rich scripting capabilities, we need to be able to pass representations of internal objects to the scripts. For example, a script that performs some computation based on information about a peer needs access to some equivalent of `struct peer` for the peer in question. To transfer these objects from C-space into Lua-space we need to encode them onto the Lua stack. This patch adds a mapping from arbitrary type names to the functions that encode objects of that type. For example, the function that encodes `struct peer` into a Lua table could be registered with: bgp_peer_encoder_func(struct frrscript *fs, struct peer *peer) { // encode peer to Lua table, push to stack in fs->scriptinfo->L } frrscript_register_type_encoder("peer", bgp_peer_encoder_func); Later on when calling a script that wants a peer, the plan is to be able to specify the type name like so: frrscript_call(script, "peer", peer); Using C-style types for the type names would have been nice, it might be possible to do this with preprocessor magic or possibly python preprocessing later on. Signed-off-by: Quentin Young <qlyoung@nvidia.com> mergeme no stdlib Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-11-29 01:02:39 +01:00
{
struct prefix p;
(void)str2prefix("1.2.3.4/24", &p);
struct frrscript *fs = frrscript_new(argv[1]->arg);
lib: start adding generic scripting stuff Rather than let Luaisms propagate from the start, this is some generic wrapper stuff that defines some semantics for interacting with scripts that aren't specific to the underlying language. The concept I have in mind for FRR's idea of a script is: - has a name - has some inputs, which have types - has some outputs, which have types I don't want to even say they have to be files; maybe we can embed scripts in frr.conf, for example. Similarly the types of inputs and outputs are probably going to end up being some language-specific setup. For now, we will stick to this simple model, but the plan is to add full object support (ie calling back into C). This shouldn't be misconstrued as prepping for multilingual scripting support, which is a bad idea for the following reasons: - Each language would require different FFI methods, and specifically different object encoders; a lot of code - Languages have different capabilities that would have to be brought to parity with each other; a lot of work - Languages have *vastly* different performance characteristics; bad impressions, lots of issues we can't do anything about - Each language would need a dedicated maintainer for the above reasons; pragmatically difficult - Supporting multiple languages fractures the community and limits the audience with which a given script can be shared The only pro for multilingual support would be ease of use for users not familiar with Lua but familiar with one of the other supported languages. This is not enough to outweigh the cons. In order to get rich scripting capabilities, we need to be able to pass representations of internal objects to the scripts. For example, a script that performs some computation based on information about a peer needs access to some equivalent of `struct peer` for the peer in question. To transfer these objects from C-space into Lua-space we need to encode them onto the Lua stack. This patch adds a mapping from arbitrary type names to the functions that encode objects of that type. For example, the function that encodes `struct peer` into a Lua table could be registered with: bgp_peer_encoder_func(struct frrscript *fs, struct peer *peer) { // encode peer to Lua table, push to stack in fs->scriptinfo->L } frrscript_register_type_encoder("peer", bgp_peer_encoder_func); Later on when calling a script that wants a peer, the plan is to be able to specify the type name like so: frrscript_call(script, "peer", peer); Using C-style types for the type names would have been nice, it might be possible to do this with preprocessor magic or possibly python preprocessing later on. Signed-off-by: Quentin Young <qlyoung@nvidia.com> mergeme no stdlib Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-11-29 01:02:39 +01:00
if (frrscript_load(fs, argv[2]->arg, NULL)) {
vty_out(vty,
"/etc/frr/scripts/%s.lua or function '%s' not found\n",
argv[1]->arg, argv[2]->arg);
}
lib: start adding generic scripting stuff Rather than let Luaisms propagate from the start, this is some generic wrapper stuff that defines some semantics for interacting with scripts that aren't specific to the underlying language. The concept I have in mind for FRR's idea of a script is: - has a name - has some inputs, which have types - has some outputs, which have types I don't want to even say they have to be files; maybe we can embed scripts in frr.conf, for example. Similarly the types of inputs and outputs are probably going to end up being some language-specific setup. For now, we will stick to this simple model, but the plan is to add full object support (ie calling back into C). This shouldn't be misconstrued as prepping for multilingual scripting support, which is a bad idea for the following reasons: - Each language would require different FFI methods, and specifically different object encoders; a lot of code - Languages have different capabilities that would have to be brought to parity with each other; a lot of work - Languages have *vastly* different performance characteristics; bad impressions, lots of issues we can't do anything about - Each language would need a dedicated maintainer for the above reasons; pragmatically difficult - Supporting multiple languages fractures the community and limits the audience with which a given script can be shared The only pro for multilingual support would be ease of use for users not familiar with Lua but familiar with one of the other supported languages. This is not enough to outweigh the cons. In order to get rich scripting capabilities, we need to be able to pass representations of internal objects to the scripts. For example, a script that performs some computation based on information about a peer needs access to some equivalent of `struct peer` for the peer in question. To transfer these objects from C-space into Lua-space we need to encode them onto the Lua stack. This patch adds a mapping from arbitrary type names to the functions that encode objects of that type. For example, the function that encodes `struct peer` into a Lua table could be registered with: bgp_peer_encoder_func(struct frrscript *fs, struct peer *peer) { // encode peer to Lua table, push to stack in fs->scriptinfo->L } frrscript_register_type_encoder("peer", bgp_peer_encoder_func); Later on when calling a script that wants a peer, the plan is to be able to specify the type name like so: frrscript_call(script, "peer", peer); Using C-style types for the type names would have been nice, it might be possible to do this with preprocessor magic or possibly python preprocessing later on. Signed-off-by: Quentin Young <qlyoung@nvidia.com> mergeme no stdlib Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-11-29 01:02:39 +01:00
int ret = frrscript_call(fs, argv[2]->arg, ("p", &p));
char buf[40];
prefix2str(&p, buf, sizeof(buf));
vty_out(vty, "p: %s\n", buf);
vty_out(vty, "Script result: %d\n", ret);
lib: start adding generic scripting stuff Rather than let Luaisms propagate from the start, this is some generic wrapper stuff that defines some semantics for interacting with scripts that aren't specific to the underlying language. The concept I have in mind for FRR's idea of a script is: - has a name - has some inputs, which have types - has some outputs, which have types I don't want to even say they have to be files; maybe we can embed scripts in frr.conf, for example. Similarly the types of inputs and outputs are probably going to end up being some language-specific setup. For now, we will stick to this simple model, but the plan is to add full object support (ie calling back into C). This shouldn't be misconstrued as prepping for multilingual scripting support, which is a bad idea for the following reasons: - Each language would require different FFI methods, and specifically different object encoders; a lot of code - Languages have different capabilities that would have to be brought to parity with each other; a lot of work - Languages have *vastly* different performance characteristics; bad impressions, lots of issues we can't do anything about - Each language would need a dedicated maintainer for the above reasons; pragmatically difficult - Supporting multiple languages fractures the community and limits the audience with which a given script can be shared The only pro for multilingual support would be ease of use for users not familiar with Lua but familiar with one of the other supported languages. This is not enough to outweigh the cons. In order to get rich scripting capabilities, we need to be able to pass representations of internal objects to the scripts. For example, a script that performs some computation based on information about a peer needs access to some equivalent of `struct peer` for the peer in question. To transfer these objects from C-space into Lua-space we need to encode them onto the Lua stack. This patch adds a mapping from arbitrary type names to the functions that encode objects of that type. For example, the function that encodes `struct peer` into a Lua table could be registered with: bgp_peer_encoder_func(struct frrscript *fs, struct peer *peer) { // encode peer to Lua table, push to stack in fs->scriptinfo->L } frrscript_register_type_encoder("peer", bgp_peer_encoder_func); Later on when calling a script that wants a peer, the plan is to be able to specify the type name like so: frrscript_call(script, "peer", peer); Using C-style types for the type names would have been nice, it might be possible to do this with preprocessor magic or possibly python preprocessing later on. Signed-off-by: Quentin Young <qlyoung@nvidia.com> mergeme no stdlib Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-11-29 01:02:39 +01:00
frrscript_delete(fs);
lib: start adding generic scripting stuff Rather than let Luaisms propagate from the start, this is some generic wrapper stuff that defines some semantics for interacting with scripts that aren't specific to the underlying language. The concept I have in mind for FRR's idea of a script is: - has a name - has some inputs, which have types - has some outputs, which have types I don't want to even say they have to be files; maybe we can embed scripts in frr.conf, for example. Similarly the types of inputs and outputs are probably going to end up being some language-specific setup. For now, we will stick to this simple model, but the plan is to add full object support (ie calling back into C). This shouldn't be misconstrued as prepping for multilingual scripting support, which is a bad idea for the following reasons: - Each language would require different FFI methods, and specifically different object encoders; a lot of code - Languages have different capabilities that would have to be brought to parity with each other; a lot of work - Languages have *vastly* different performance characteristics; bad impressions, lots of issues we can't do anything about - Each language would need a dedicated maintainer for the above reasons; pragmatically difficult - Supporting multiple languages fractures the community and limits the audience with which a given script can be shared The only pro for multilingual support would be ease of use for users not familiar with Lua but familiar with one of the other supported languages. This is not enough to outweigh the cons. In order to get rich scripting capabilities, we need to be able to pass representations of internal objects to the scripts. For example, a script that performs some computation based on information about a peer needs access to some equivalent of `struct peer` for the peer in question. To transfer these objects from C-space into Lua-space we need to encode them onto the Lua stack. This patch adds a mapping from arbitrary type names to the functions that encode objects of that type. For example, the function that encodes `struct peer` into a Lua table could be registered with: bgp_peer_encoder_func(struct frrscript *fs, struct peer *peer) { // encode peer to Lua table, push to stack in fs->scriptinfo->L } frrscript_register_type_encoder("peer", bgp_peer_encoder_func); Later on when calling a script that wants a peer, the plan is to be able to specify the type name like so: frrscript_call(script, "peer", peer); Using C-style types for the type names would have been nice, it might be possible to do this with preprocessor magic or possibly python preprocessing later on. Signed-off-by: Quentin Young <qlyoung@nvidia.com> mergeme no stdlib Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-11-29 01:02:39 +01:00
return CMD_SUCCESS;
}
#endif
2002-12-13 21:15:29 +01:00
/* Set config filename. Called from vty.c */
void host_config_set(const char *filename)
2002-12-13 21:15:29 +01:00
{
XFREE(MTYPE_HOST, host.config);
host.config = XSTRDUP(MTYPE_HOST, filename);
2002-12-13 21:15:29 +01:00
}
const char *host_config_get(void)
{
return host.config;
}
void cmd_show_lib_debugs(struct vty *vty)
{
route_map_show_debug(vty);
debug_status_write(vty);
}
2002-12-13 21:15:29 +01:00
void install_default(enum node_type node)
{
_install_element(node, &config_exit_cmd);
_install_element(node, &config_quit_cmd);
_install_element(node, &config_end_cmd);
_install_element(node, &config_help_cmd);
_install_element(node, &config_list_cmd);
_install_element(node, &show_cli_graph_cmd);
_install_element(node, &find_cmd);
2002-12-13 21:15:29 +01:00
_install_element(node, &config_write_cmd);
_install_element(node, &show_running_config_cmd);
_install_element(node, &autocomplete_cmd);
nb_cli_install_default(node);
2002-12-13 21:15:29 +01:00
}
/* Initialize command interface. Install basic nodes and commands.
*
* terminal = 0 -- vtysh / no logging, no config control
* terminal = 1 -- normal daemon
* terminal = -1 -- watchfrr / no logging, but minimal config control */
2002-12-13 21:15:29 +01:00
void cmd_init(int terminal)
{
struct utsname names;
uname(&names);
qobj_init();
/* register command preprocessors */
hook_register(cmd_execute, handle_pipe_action);
hook_register(cmd_execute_done, handle_pipe_action_done);
varhandlers = list_new();
2002-12-13 21:15:29 +01:00
/* Allocate initial top vector of commands. */
cmdvec = vector_init(VECTOR_MIN_SIZE);
2002-12-13 21:15:29 +01:00
/* Default host value settings. */
host.name = XSTRDUP(MTYPE_HOST, names.nodename);
host.system = XSTRDUP(MTYPE_HOST, names.sysname);
host.release = XSTRDUP(MTYPE_HOST, names.release);
host.version = XSTRDUP(MTYPE_HOST, names.version);
#ifdef HAVE_STRUCT_UTSNAME_DOMAINNAME
if ((strcmp(names.domainname, "(none)") == 0))
host.domainname = NULL;
else
host.domainname = XSTRDUP(MTYPE_HOST, names.domainname);
#else
host.domainname = NULL;
#endif
2002-12-13 21:15:29 +01:00
host.password = NULL;
host.enable = NULL;
host.config = NULL;
host.noconfig = (terminal < 0);
2002-12-13 21:15:29 +01:00
host.lines = -1;
cmd_banner_motd_line(FRR_DEFAULT_MOTD);
host.motdfile = NULL;
host.allow_reserved_ranges = false;
2002-12-13 21:15:29 +01:00
/* Install top nodes. */
install_node(&view_node);
install_node(&enable_node);
install_node(&auth_node);
install_node(&auth_enable_node);
install_node(&config_node);
2002-12-13 21:15:29 +01:00
/* Each node's basic commands. */
install_element(VIEW_NODE, &show_version_cmd);
install_element(ENABLE_NODE, &show_startup_config_cmd);
2002-12-13 21:15:29 +01:00
if (terminal) {
install_element(ENABLE_NODE, &debug_memstats_cmd);
2002-12-13 21:15:29 +01:00
install_element(VIEW_NODE, &config_list_cmd);
install_element(VIEW_NODE, &config_exit_cmd);
install_element(VIEW_NODE, &config_quit_cmd);
2002-12-13 21:15:29 +01:00
install_element(VIEW_NODE, &config_help_cmd);
install_element(VIEW_NODE, &config_enable_cmd);
install_element(VIEW_NODE, &config_terminal_length_cmd);
install_element(VIEW_NODE, &config_terminal_no_length_cmd);
install_element(VIEW_NODE, &show_commandtree_cmd);
install_element(VIEW_NODE, &echo_cmd);
install_element(VIEW_NODE, &autocomplete_cmd);
install_element(VIEW_NODE, &find_cmd);
#if defined(DEV_BUILD) && defined(HAVE_SCRIPTING)
install_element(VIEW_NODE, &script_cmd);
#endif
install_element(ENABLE_NODE, &config_end_cmd);
2002-12-13 21:15:29 +01:00
install_element(ENABLE_NODE, &config_disable_cmd);
install_element(ENABLE_NODE, &config_terminal_cmd);
install_element(ENABLE_NODE, &copy_runningconf_startupconf_cmd);
install_element(ENABLE_NODE, &config_write_cmd);
install_element(ENABLE_NODE, &show_running_config_cmd);
2004-12-07 Andrew J. Schorr <ajschorr@alumni.princeton.edu> * bgp_main.c: (main) The 2nd argument to openzlog has been removed. * isis_main.c: (main) The 2nd argument to openzlog has been removed. * ospf6_main.c: (main) The 2nd argument to openzlog has been removed. Note that stdout logging will no longer be enabled by default when not running as a daemon. * ospf_main.c: (main) The 2nd argument to openzlog has been removed. * rip_main.c: (main) The 2nd argument to openzlog has been removed. * ripng_main.c: (main) The 2nd argument to openzlog has been removed. * main.c: (main) The 2nd argument to openzlog has been removed. So stdout logging will no longer be enabled by default. * irdp_main.c: (irdp_finish) Reduce severity of shutdown message from LOG_WARNING to LOG_INFO. * vtysh.c: Make several functions static instead of global. Added several commands to support destination-specific logging levels. (vtysh_completion) This function is unused, so comment it out. * basic.texi: Document new logging features. Separate basic config commands from basic VTY commands. * log.h: Replace struct zlog flags and maskpri fields with maxlvl array to support individual logging levels for each destination. Remove the 2nd argument to openzlog since the default logging config should be standardized inside the library. Replaced the zlog_set_flag and zlog_reset_flag functions with zlog_set_level. And zlog_set_file now requires an additional log_level argument. Declare zlog_proto_names for use inside command.c in the "show logging" command. Added defines useful for command construction. * log.c: (vzlog) Decide where to send the message based on the individual logging levels configured for each destination. Remove support for ZLOG_STDERR since it was never actually used. Support record-priority for terminal monitors. (zlog_signal,zlog_backtrace_sigsafe) Support destination-specific logging levels. Remove stderr support (was never used). Added support for terminal monitor logging. (_zlog_assert_failed) Increase message severity to LOG_EMERG. (openzlog) Remove 2nd argument since default config should be standardized in library. By default, terminal monitoring is set to debug, and all other logging is disabled. (zlog_set_flag,zlog_reset_flag) Removed. (zlog_set_level) New function to replace zlog_set_flag and zlog_reset_flag. Supports destination-specific logging levels. (zlog_set_file,zlog_reset_file) Support file-specific logging level. (zlog_rotate) Log an error message if fopen fails, and support new file-specific logging level. * command.h: Change DEFUN_CMD_FUNC_DECL and DEFUN_CMD_FUNC_TEXT so that command functions will be static instead of global. Remove declarations for config_exit and config_help. Define new macros DEFUNSH_ATTR, DEFUNSH_HIDDEN, and DEFUNSH_DEPRECATED so we can have deprecated commands in vtysh. Similarly, for completeness, define macros ALIAS_SH, ALIAS_SH_HIDDEN, and ALIAS_SH_DEPRECATED. Also, fix bug in ALIAS_ATTR macro (didn't matter because it was never used). * command.c: Make many functions static instead of global. (facility_name,facility_match,level_match) New functions to support enhanced destination-specific logging levels. (config_write_host) Support new destination-specific logging levels. (config_logmsg) Added new "logmsg" command to help test logging system. (show_logging) Added "show logging" command to show the current configuration of the logging system. (config_log_stdout_level) Support explicit stdout logging level. (no_config_log_stdout) Now takes optional LEVEL arg. (config_log_monitor,config_log_monitor_level,no_config_log_monitor) New commands creating new "log monitor" commands to set terminal monitoring log level. (config_log_file_level) Support explicit file logging level. (config_log_syslog_level) Support explicit syslog logging level. (config_log_facility,no_config_log_facility) Implement new "log facility" command. (cmd_init) Add hooks for new commands: "show logging", "logmsg", "log stdout <level>", "log monitor", "log monitor <level>", "no log monitor", "log file <filename> <level>", "no log file <filename> <level>", "log syslog <level>", "log facility", and "no log facility". * vty.h: Added a "level" argument to vty_log so it can support "log record-priority". Declare new function vty_log_fixed for use in signal handlers. * vty.c: (vty_log,vty_log_out) Added a "level" argument to support "log record-priority" for vty terminal monitors. (vty_down_level) Use config_exit_cmd.func instead of calling config_exit directly (since command functions will now be static instead of global). (vty_log_fixed) New function to send terminal monitor messages from inside a signal handler.
2004-12-07 16:39:31 +01:00
install_element(ENABLE_NODE, &config_logmsg_cmd);
install_default(CONFIG_NODE);
event_cmd_init();
workqueue_cmd_init();
hash_cmd_init();
}
install_element(CONFIG_NODE, &hostname_cmd);
install_element(CONFIG_NODE, &no_hostname_cmd);
install_element(CONFIG_NODE, &domainname_cmd);
install_element(CONFIG_NODE, &no_domainname_cmd);
if (terminal > 0) {
full_cli = true;
install_element(CONFIG_NODE, &debug_memstats_cmd);
install_element(CONFIG_NODE, &password_cmd);
install_element(CONFIG_NODE, &no_password_cmd);
install_element(CONFIG_NODE, &enable_password_cmd);
install_element(CONFIG_NODE, &no_enable_password_cmd);
2002-12-13 21:15:29 +01:00
install_element(CONFIG_NODE, &service_password_encrypt_cmd);
install_element(CONFIG_NODE, &no_service_password_encrypt_cmd);
install_element(CONFIG_NODE, &banner_motd_default_cmd);
install_element(CONFIG_NODE, &banner_motd_file_cmd);
install_element(CONFIG_NODE, &banner_motd_line_cmd);
2002-12-13 21:15:29 +01:00
install_element(CONFIG_NODE, &no_banner_motd_cmd);
install_element(CONFIG_NODE, &service_terminal_length_cmd);
install_element(CONFIG_NODE, &no_service_terminal_length_cmd);
install_element(CONFIG_NODE, &allow_reserved_ranges_cmd);
install_element(CONFIG_NODE, &no_allow_reserved_ranges_cmd);
log_cmd_init();
vrf_install_commands();
This patch adds Yon's CLI 'walk back up tree' patch. Following are email describing original patch and a shorter email describing changes to an updated patch, the one which is applied: From havanna_moon@gmx.net Sat Jan 18 00:37:13 2003 Date: Mon, 9 Dec 2002 05:32:58 +0100 (CET) From: Yon Uriarte <havanna_moon@gmx.net> To: "the list(tm) Zebra" <zebra@zebra.org> Subject: [zebra 16671] [PATCH] CLI extensions. Hi, this patch adds 2 improvements to the CLI (lib/command.c): #1) When in subconfig mode (router XXX, interface XXX, ...) commands that fail for that node are tried on the main CONFIG_NODE. This is great for configuring interfaces or changing the sub-config mode quickly, without the need to type 'exit' between commands: ospfd(config)# int eth1 ospfd(config-if)# ip ospf cost 9 ospfd(config-if)# ip ospf prio 101 ospfd(config-if)# router ospf ospfd(config-router)# network 1.1.1.0/24 area 51 ospfd(config-router)# int eth2 ospfd(config-if)# ip ospf authentication message-digest ospfd(config-if)# ^Z ospfd# Is this IOS-like or does IOS try to walk up the tree of config sub-modes instead of directly trying the command on CONFIG_NODE? CAVEATS: "?" and "TAB" don't work. IIRC IOS doesnt show that help neither. NON-CAVEATS: This wont break much, as config_from_file() already does try a failed command on the parent node of the actual vty->node. If changing the code to walk the node tree instead of directly trying the command on the ENABLE_NODE the same semantics would be in use and no future bugs could creep in. #2) When in config or subconfig mode use the "do " prefix to execute commans of the ENABLE_NODE. "?" and "TAB" work. The space after the "do" is needed: ospfd(config-router)# do<?> % There is no matched command. ospfd(config-router)# do <?> clear Reset functions configure Configuration from vty interface copy Copy configuration debug Debugging functions (see also 'undebug') disable Turn off privileged mode command end End current mode and change to enable mode. exit Exit current mode and down to previous mode help Description of the interactive help system list Print command list no Negate a command or set its defaults quit Exit current mode and down to previous mode show Show running system information terminal Set terminal line parameters who Display who is on vty write Write running configuration to memory, network, or terminal ospfd(config-router)# do sho<TAB> ospfd(config-router)# do show me<TAB> ospfd(config-router)# do show memory r<TAB> ospfd(config-router)# do show memory rip RIP structure : 0 RIP route info : 0 RIP interface : 0 RIP peer : 0 RIP offset list : 0 RIP distance : 0 ospfd(config-router)# ^Z ospfd# CAVEATS: I don't have access to an IOS with this feature, so I implemented it from the comments on this mailing list (in fact my personal motivation was to implement feature #1, which I missed on zebra. But #2 sounded like a nice one to have, and xemacs was already parked on command.c ...). Is this IOS-like or are there differences? I will happily change this patch to mimick IOS or the mailing-list consensus on CLI-usability. regards, yon From havanna_moon@gmx.net Sat Jan 18 01:13:11 2003 Date: Sat, 11 Jan 2003 23:36:51 +0100 (CET) From: Yon Uriarte <havanna_moon@gmx.net> To: zebra@zebra.org Subject: [zebra 17218] Re: [PATCH] CLI extensions. Hi, [redacted] > I prefer the IOS way for the node "up walking". This patch should walk the tree upwards: bgpd(config)# router bgp 1 bgpd(config-router)# address-family ipv4 multicast bgpd(config-router-af)# access-list 1 remark hola que tal bgpd(config)# I cant test all combinations, so I cant rule out some bugs. I'd love to get (long and explicit) bug reports. [redacted]
2003-01-18 02:16:20 +01:00
}
#ifdef DEV_BUILD
grammar_sandbox_init();
#endif
2002-12-13 21:15:29 +01:00
}
[bgpd] Stability fixes including bugs 397, 492 I've spent the last several weeks working on stability fixes to bgpd. These patches fix all of the numerous crashes, assertion failures, memory leaks and memory stomping I could find. Valgrind was used extensively. Added new function bgp_exit() to help catch problems. If "debug bgp" is configured and bgpd exits with status of 0, statistics on remaining lib/memory.c allocations are printed to stderr. It is my hope that other developers will use this to stay on top of memory issues. Example questionable exit: bgpd: memstats: Current memory utilization in module LIB: bgpd: memstats: Link List : 6 bgpd: memstats: Link Node : 5 bgpd: memstats: Hash : 8 bgpd: memstats: Hash Bucket : 2 bgpd: memstats: Hash Index : 8 bgpd: memstats: Work queue : 3 bgpd: memstats: Work queue item : 2 bgpd: memstats: Work queue name string : 3 bgpd: memstats: Current memory utilization in module BGP: bgpd: memstats: BGP instance : 1 bgpd: memstats: BGP peer : 1 bgpd: memstats: BGP peer hostname : 1 bgpd: memstats: BGP attribute : 1 bgpd: memstats: BGP extra attributes : 1 bgpd: memstats: BGP aspath : 1 bgpd: memstats: BGP aspath str : 1 bgpd: memstats: BGP table : 24 bgpd: memstats: BGP node : 1 bgpd: memstats: BGP route : 1 bgpd: memstats: BGP synchronise : 8 bgpd: memstats: BGP Process queue : 1 bgpd: memstats: BGP node clear queue : 1 bgpd: memstats: NOTE: If configuration exists, utilization may be expected. Example clean exit: bgpd: memstats: No remaining tracked memory utilization. This patch fixes bug #397: "Invalid free in bgp_announce_check()". This patch fixes bug #492: "SIGBUS in bgpd/bgp_route.c: bgp_clear_route_node()". My apologies for not separating out these changes into individual patches. The complexity of doing so boggled what is left of my brain. I hope this is all still useful to the community. This code has been production tested, in non-route-server-client mode, on a linux 32-bit box and a 64-bit box. Release/reset functions, used by bgp_exit(), added to: bgpd/bgp_attr.c,h bgpd/bgp_community.c,h bgpd/bgp_dump.c,h bgpd/bgp_ecommunity.c,h bgpd/bgp_filter.c,h bgpd/bgp_nexthop.c,h bgpd/bgp_route.c,h lib/routemap.c,h File by file analysis: * bgpd/bgp_aspath.c: Prevent re-use of ashash after it is released. * bgpd/bgp_attr.c: #if removed uncalled cluster_dup(). * bgpd/bgp_clist.c,h: Allow community_list_terminate() to be called from bgp_exit(). * bgpd/bgp_filter.c: Fix aslist->name use without allocation check, and also fix memory leak. * bgpd/bgp_main.c: Created bgp_exit() exit routine. This function frees allocations made as part of bgpd initialization and, to some extent, configuration. If "debug bgp" is configured, memory stats are printed as described above. * bgpd/bgp_nexthop.c: zclient_new() already allocates stream for ibuf/obuf, so bgp_scan_init() shouldn't do it too. Also, made it so zlookup is global so bgp_exit() can use it. * bgpd/bgp_packet.c: bgp_capability_msg_parse() call to bgp_clear_route() adjusted to use new BGP_CLEAR_ROUTE_NORMAL flag. * bgpd/bgp_route.h: Correct reference counter "lock" to be signed. bgp_clear_route() now accepts a bgp_clear_route_type of either BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT. * bgpd/bgp_route.c: - bgp_process_rsclient(): attr was being zero'ed and then bgp_attr_extra_free() was being called with it, even though it was never filled with valid data. - bgp_process_rsclient(): Make sure rsclient->group is not NULL before use. - bgp_processq_del(): Add call to bgp_table_unlock(). - bgp_process(): Add call to bgp_table_lock(). - bgp_update_rsclient(): memset clearing of new_attr not needed since declarationw with "= { 0 }" does it. memset was already commented out. - bgp_update_rsclient(): Fix screwed up misleading indentation. - bgp_withdraw_rsclient(): Fix screwed up misleading indentation. - bgp_clear_route_node(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. - bgp_clear_node_queue_del(): Add call to bgp_table_unlock() and also free struct bgp_clear_node_queue used for work item. - bgp_clear_node_complete(): Do peer_unlock() after BGP_EVENT_ADD() in case peer is released by peer_unlock() call. - bgp_clear_route_table(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. Use struct bgp_clear_node_queue to supply data to worker. Add call to bgp_table_lock(). - bgp_clear_route(): Add support for BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT. - bgp_clear_route_all(): Use BGP_CLEAR_ROUTE_NORMAL. Bug 397 fixes: - bgp_default_originate() - bgp_announce_table() * bgpd/bgp_table.h: - struct bgp_table: Added reference count. Changed type of owner to be "struct peer *" rather than "void *". - struct bgp_node: Correct reference counter "lock" to be signed. * bgpd/bgp_table.c: - Added bgp_table reference counting. - bgp_table_free(): Fixed cleanup code. Call peer_unlock() on owner if set. - bgp_unlock_node(): Added assertion. - bgp_node_get(): Added call to bgp_lock_node() to code path that it was missing from. * bgpd/bgp_vty.c: - peer_rsclient_set_vty(): Call peer_lock() as part of peer assignment to owner. Handle failure gracefully. - peer_rsclient_unset_vty(): Add call to bgp_clear_route() with BGP_CLEAR_ROUTE_MY_RSCLIENT purpose. * bgpd/bgp_zebra.c: Made it so zclient is global so bgp_exit() can use it. * bgpd/bgpd.c: - peer_lock(): Allow to be called when status is "Deleted". - peer_deactivate(): Supply BGP_CLEAR_ROUTE_NORMAL purpose to bgp_clear_route() call. - peer_delete(): Common variable listnode pn. Fix bug in which rsclient was only dealt with if not part of a peer group. Call bgp_clear_route() for rsclient, if appropriate, and do so with BGP_CLEAR_ROUTE_MY_RSCLIENT purpose. - peer_group_get(): Use XSTRDUP() instead of strdup() for conf->host. - peer_group_bind(): Call bgp_clear_route() for rsclient, and do so with BGP_CLEAR_ROUTE_MY_RSCLIENT purpose. - bgp_create(): Use XSTRDUP() instead of strdup() for peer_self->host. - bgp_delete(): Delete peers before groups, rather than after. And then rather than deleting rsclients, verify that there are none at this point. - bgp_unlock(): Add assertion. - bgp_free(): Call bgp_table_finish() rather than doing XFREE() itself. * lib/command.c,h: Compiler warning fixes. Add cmd_terminate(). Fixed massive leak in install_element() in which cmd_make_descvec() was being called more than once for the same cmd->strvec/string/doc. * lib/log.c: Make closezlog() check fp before calling fclose(). * lib/memory.c: Catch when alloc count goes negative by using signed counts. Correct #endif comment. Add log_memstats_stderr(). * lib/memory.h: Add log_memstats_stderr(). * lib/thread.c: thread->funcname was being accessed in thread_call() after it had been freed. Rearranged things so that thread_call() frees funcname. Also made it so thread_master_free() cleans up cpu_record. * lib/vty.c,h: Use global command_cr. Add vty_terminate(). * lib/zclient.c,h: Re-enable zclient_free().
2009-07-18 07:44:03 +02:00
void cmd_terminate(void)
[bgpd] Stability fixes including bugs 397, 492 I've spent the last several weeks working on stability fixes to bgpd. These patches fix all of the numerous crashes, assertion failures, memory leaks and memory stomping I could find. Valgrind was used extensively. Added new function bgp_exit() to help catch problems. If "debug bgp" is configured and bgpd exits with status of 0, statistics on remaining lib/memory.c allocations are printed to stderr. It is my hope that other developers will use this to stay on top of memory issues. Example questionable exit: bgpd: memstats: Current memory utilization in module LIB: bgpd: memstats: Link List : 6 bgpd: memstats: Link Node : 5 bgpd: memstats: Hash : 8 bgpd: memstats: Hash Bucket : 2 bgpd: memstats: Hash Index : 8 bgpd: memstats: Work queue : 3 bgpd: memstats: Work queue item : 2 bgpd: memstats: Work queue name string : 3 bgpd: memstats: Current memory utilization in module BGP: bgpd: memstats: BGP instance : 1 bgpd: memstats: BGP peer : 1 bgpd: memstats: BGP peer hostname : 1 bgpd: memstats: BGP attribute : 1 bgpd: memstats: BGP extra attributes : 1 bgpd: memstats: BGP aspath : 1 bgpd: memstats: BGP aspath str : 1 bgpd: memstats: BGP table : 24 bgpd: memstats: BGP node : 1 bgpd: memstats: BGP route : 1 bgpd: memstats: BGP synchronise : 8 bgpd: memstats: BGP Process queue : 1 bgpd: memstats: BGP node clear queue : 1 bgpd: memstats: NOTE: If configuration exists, utilization may be expected. Example clean exit: bgpd: memstats: No remaining tracked memory utilization. This patch fixes bug #397: "Invalid free in bgp_announce_check()". This patch fixes bug #492: "SIGBUS in bgpd/bgp_route.c: bgp_clear_route_node()". My apologies for not separating out these changes into individual patches. The complexity of doing so boggled what is left of my brain. I hope this is all still useful to the community. This code has been production tested, in non-route-server-client mode, on a linux 32-bit box and a 64-bit box. Release/reset functions, used by bgp_exit(), added to: bgpd/bgp_attr.c,h bgpd/bgp_community.c,h bgpd/bgp_dump.c,h bgpd/bgp_ecommunity.c,h bgpd/bgp_filter.c,h bgpd/bgp_nexthop.c,h bgpd/bgp_route.c,h lib/routemap.c,h File by file analysis: * bgpd/bgp_aspath.c: Prevent re-use of ashash after it is released. * bgpd/bgp_attr.c: #if removed uncalled cluster_dup(). * bgpd/bgp_clist.c,h: Allow community_list_terminate() to be called from bgp_exit(). * bgpd/bgp_filter.c: Fix aslist->name use without allocation check, and also fix memory leak. * bgpd/bgp_main.c: Created bgp_exit() exit routine. This function frees allocations made as part of bgpd initialization and, to some extent, configuration. If "debug bgp" is configured, memory stats are printed as described above. * bgpd/bgp_nexthop.c: zclient_new() already allocates stream for ibuf/obuf, so bgp_scan_init() shouldn't do it too. Also, made it so zlookup is global so bgp_exit() can use it. * bgpd/bgp_packet.c: bgp_capability_msg_parse() call to bgp_clear_route() adjusted to use new BGP_CLEAR_ROUTE_NORMAL flag. * bgpd/bgp_route.h: Correct reference counter "lock" to be signed. bgp_clear_route() now accepts a bgp_clear_route_type of either BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT. * bgpd/bgp_route.c: - bgp_process_rsclient(): attr was being zero'ed and then bgp_attr_extra_free() was being called with it, even though it was never filled with valid data. - bgp_process_rsclient(): Make sure rsclient->group is not NULL before use. - bgp_processq_del(): Add call to bgp_table_unlock(). - bgp_process(): Add call to bgp_table_lock(). - bgp_update_rsclient(): memset clearing of new_attr not needed since declarationw with "= { 0 }" does it. memset was already commented out. - bgp_update_rsclient(): Fix screwed up misleading indentation. - bgp_withdraw_rsclient(): Fix screwed up misleading indentation. - bgp_clear_route_node(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. - bgp_clear_node_queue_del(): Add call to bgp_table_unlock() and also free struct bgp_clear_node_queue used for work item. - bgp_clear_node_complete(): Do peer_unlock() after BGP_EVENT_ADD() in case peer is released by peer_unlock() call. - bgp_clear_route_table(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. Use struct bgp_clear_node_queue to supply data to worker. Add call to bgp_table_lock(). - bgp_clear_route(): Add support for BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT. - bgp_clear_route_all(): Use BGP_CLEAR_ROUTE_NORMAL. Bug 397 fixes: - bgp_default_originate() - bgp_announce_table() * bgpd/bgp_table.h: - struct bgp_table: Added reference count. Changed type of owner to be "struct peer *" rather than "void *". - struct bgp_node: Correct reference counter "lock" to be signed. * bgpd/bgp_table.c: - Added bgp_table reference counting. - bgp_table_free(): Fixed cleanup code. Call peer_unlock() on owner if set. - bgp_unlock_node(): Added assertion. - bgp_node_get(): Added call to bgp_lock_node() to code path that it was missing from. * bgpd/bgp_vty.c: - peer_rsclient_set_vty(): Call peer_lock() as part of peer assignment to owner. Handle failure gracefully. - peer_rsclient_unset_vty(): Add call to bgp_clear_route() with BGP_CLEAR_ROUTE_MY_RSCLIENT purpose. * bgpd/bgp_zebra.c: Made it so zclient is global so bgp_exit() can use it. * bgpd/bgpd.c: - peer_lock(): Allow to be called when status is "Deleted". - peer_deactivate(): Supply BGP_CLEAR_ROUTE_NORMAL purpose to bgp_clear_route() call. - peer_delete(): Common variable listnode pn. Fix bug in which rsclient was only dealt with if not part of a peer group. Call bgp_clear_route() for rsclient, if appropriate, and do so with BGP_CLEAR_ROUTE_MY_RSCLIENT purpose. - peer_group_get(): Use XSTRDUP() instead of strdup() for conf->host. - peer_group_bind(): Call bgp_clear_route() for rsclient, and do so with BGP_CLEAR_ROUTE_MY_RSCLIENT purpose. - bgp_create(): Use XSTRDUP() instead of strdup() for peer_self->host. - bgp_delete(): Delete peers before groups, rather than after. And then rather than deleting rsclients, verify that there are none at this point. - bgp_unlock(): Add assertion. - bgp_free(): Call bgp_table_finish() rather than doing XFREE() itself. * lib/command.c,h: Compiler warning fixes. Add cmd_terminate(). Fixed massive leak in install_element() in which cmd_make_descvec() was being called more than once for the same cmd->strvec/string/doc. * lib/log.c: Make closezlog() check fp before calling fclose(). * lib/memory.c: Catch when alloc count goes negative by using signed counts. Correct #endif comment. Add log_memstats_stderr(). * lib/memory.h: Add log_memstats_stderr(). * lib/thread.c: thread->funcname was being accessed in thread_call() after it had been freed. Rearranged things so that thread_call() frees funcname. Also made it so thread_master_free() cleans up cpu_record. * lib/vty.c,h: Use global command_cr. Add vty_terminate(). * lib/zclient.c,h: Re-enable zclient_free().
2009-07-18 07:44:03 +02:00
{
struct cmd_node *cmd_node;
hook_unregister(cmd_execute, handle_pipe_action);
hook_unregister(cmd_execute_done, handle_pipe_action_done);
[bgpd] Stability fixes including bugs 397, 492 I've spent the last several weeks working on stability fixes to bgpd. These patches fix all of the numerous crashes, assertion failures, memory leaks and memory stomping I could find. Valgrind was used extensively. Added new function bgp_exit() to help catch problems. If "debug bgp" is configured and bgpd exits with status of 0, statistics on remaining lib/memory.c allocations are printed to stderr. It is my hope that other developers will use this to stay on top of memory issues. Example questionable exit: bgpd: memstats: Current memory utilization in module LIB: bgpd: memstats: Link List : 6 bgpd: memstats: Link Node : 5 bgpd: memstats: Hash : 8 bgpd: memstats: Hash Bucket : 2 bgpd: memstats: Hash Index : 8 bgpd: memstats: Work queue : 3 bgpd: memstats: Work queue item : 2 bgpd: memstats: Work queue name string : 3 bgpd: memstats: Current memory utilization in module BGP: bgpd: memstats: BGP instance : 1 bgpd: memstats: BGP peer : 1 bgpd: memstats: BGP peer hostname : 1 bgpd: memstats: BGP attribute : 1 bgpd: memstats: BGP extra attributes : 1 bgpd: memstats: BGP aspath : 1 bgpd: memstats: BGP aspath str : 1 bgpd: memstats: BGP table : 24 bgpd: memstats: BGP node : 1 bgpd: memstats: BGP route : 1 bgpd: memstats: BGP synchronise : 8 bgpd: memstats: BGP Process queue : 1 bgpd: memstats: BGP node clear queue : 1 bgpd: memstats: NOTE: If configuration exists, utilization may be expected. Example clean exit: bgpd: memstats: No remaining tracked memory utilization. This patch fixes bug #397: "Invalid free in bgp_announce_check()". This patch fixes bug #492: "SIGBUS in bgpd/bgp_route.c: bgp_clear_route_node()". My apologies for not separating out these changes into individual patches. The complexity of doing so boggled what is left of my brain. I hope this is all still useful to the community. This code has been production tested, in non-route-server-client mode, on a linux 32-bit box and a 64-bit box. Release/reset functions, used by bgp_exit(), added to: bgpd/bgp_attr.c,h bgpd/bgp_community.c,h bgpd/bgp_dump.c,h bgpd/bgp_ecommunity.c,h bgpd/bgp_filter.c,h bgpd/bgp_nexthop.c,h bgpd/bgp_route.c,h lib/routemap.c,h File by file analysis: * bgpd/bgp_aspath.c: Prevent re-use of ashash after it is released. * bgpd/bgp_attr.c: #if removed uncalled cluster_dup(). * bgpd/bgp_clist.c,h: Allow community_list_terminate() to be called from bgp_exit(). * bgpd/bgp_filter.c: Fix aslist->name use without allocation check, and also fix memory leak. * bgpd/bgp_main.c: Created bgp_exit() exit routine. This function frees allocations made as part of bgpd initialization and, to some extent, configuration. If "debug bgp" is configured, memory stats are printed as described above. * bgpd/bgp_nexthop.c: zclient_new() already allocates stream for ibuf/obuf, so bgp_scan_init() shouldn't do it too. Also, made it so zlookup is global so bgp_exit() can use it. * bgpd/bgp_packet.c: bgp_capability_msg_parse() call to bgp_clear_route() adjusted to use new BGP_CLEAR_ROUTE_NORMAL flag. * bgpd/bgp_route.h: Correct reference counter "lock" to be signed. bgp_clear_route() now accepts a bgp_clear_route_type of either BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT. * bgpd/bgp_route.c: - bgp_process_rsclient(): attr was being zero'ed and then bgp_attr_extra_free() was being called with it, even though it was never filled with valid data. - bgp_process_rsclient(): Make sure rsclient->group is not NULL before use. - bgp_processq_del(): Add call to bgp_table_unlock(). - bgp_process(): Add call to bgp_table_lock(). - bgp_update_rsclient(): memset clearing of new_attr not needed since declarationw with "= { 0 }" does it. memset was already commented out. - bgp_update_rsclient(): Fix screwed up misleading indentation. - bgp_withdraw_rsclient(): Fix screwed up misleading indentation. - bgp_clear_route_node(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. - bgp_clear_node_queue_del(): Add call to bgp_table_unlock() and also free struct bgp_clear_node_queue used for work item. - bgp_clear_node_complete(): Do peer_unlock() after BGP_EVENT_ADD() in case peer is released by peer_unlock() call. - bgp_clear_route_table(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. Use struct bgp_clear_node_queue to supply data to worker. Add call to bgp_table_lock(). - bgp_clear_route(): Add support for BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT. - bgp_clear_route_all(): Use BGP_CLEAR_ROUTE_NORMAL. Bug 397 fixes: - bgp_default_originate() - bgp_announce_table() * bgpd/bgp_table.h: - struct bgp_table: Added reference count. Changed type of owner to be "struct peer *" rather than "void *". - struct bgp_node: Correct reference counter "lock" to be signed. * bgpd/bgp_table.c: - Added bgp_table reference counting. - bgp_table_free(): Fixed cleanup code. Call peer_unlock() on owner if set. - bgp_unlock_node(): Added assertion. - bgp_node_get(): Added call to bgp_lock_node() to code path that it was missing from. * bgpd/bgp_vty.c: - peer_rsclient_set_vty(): Call peer_lock() as part of peer assignment to owner. Handle failure gracefully. - peer_rsclient_unset_vty(): Add call to bgp_clear_route() with BGP_CLEAR_ROUTE_MY_RSCLIENT purpose. * bgpd/bgp_zebra.c: Made it so zclient is global so bgp_exit() can use it. * bgpd/bgpd.c: - peer_lock(): Allow to be called when status is "Deleted". - peer_deactivate(): Supply BGP_CLEAR_ROUTE_NORMAL purpose to bgp_clear_route() call. - peer_delete(): Common variable listnode pn. Fix bug in which rsclient was only dealt with if not part of a peer group. Call bgp_clear_route() for rsclient, if appropriate, and do so with BGP_CLEAR_ROUTE_MY_RSCLIENT purpose. - peer_group_get(): Use XSTRDUP() instead of strdup() for conf->host. - peer_group_bind(): Call bgp_clear_route() for rsclient, and do so with BGP_CLEAR_ROUTE_MY_RSCLIENT purpose. - bgp_create(): Use XSTRDUP() instead of strdup() for peer_self->host. - bgp_delete(): Delete peers before groups, rather than after. And then rather than deleting rsclients, verify that there are none at this point. - bgp_unlock(): Add assertion. - bgp_free(): Call bgp_table_finish() rather than doing XFREE() itself. * lib/command.c,h: Compiler warning fixes. Add cmd_terminate(). Fixed massive leak in install_element() in which cmd_make_descvec() was being called more than once for the same cmd->strvec/string/doc. * lib/log.c: Make closezlog() check fp before calling fclose(). * lib/memory.c: Catch when alloc count goes negative by using signed counts. Correct #endif comment. Add log_memstats_stderr(). * lib/memory.h: Add log_memstats_stderr(). * lib/thread.c: thread->funcname was being accessed in thread_call() after it had been freed. Rearranged things so that thread_call() frees funcname. Also made it so thread_master_free() cleans up cpu_record. * lib/vty.c,h: Use global command_cr. Add vty_terminate(). * lib/zclient.c,h: Re-enable zclient_free().
2009-07-18 07:44:03 +02:00
if (cmdvec) {
for (unsigned int i = 0; i < vector_active(cmdvec); i++)
[bgpd] Stability fixes including bugs 397, 492 I've spent the last several weeks working on stability fixes to bgpd. These patches fix all of the numerous crashes, assertion failures, memory leaks and memory stomping I could find. Valgrind was used extensively. Added new function bgp_exit() to help catch problems. If "debug bgp" is configured and bgpd exits with status of 0, statistics on remaining lib/memory.c allocations are printed to stderr. It is my hope that other developers will use this to stay on top of memory issues. Example questionable exit: bgpd: memstats: Current memory utilization in module LIB: bgpd: memstats: Link List : 6 bgpd: memstats: Link Node : 5 bgpd: memstats: Hash : 8 bgpd: memstats: Hash Bucket : 2 bgpd: memstats: Hash Index : 8 bgpd: memstats: Work queue : 3 bgpd: memstats: Work queue item : 2 bgpd: memstats: Work queue name string : 3 bgpd: memstats: Current memory utilization in module BGP: bgpd: memstats: BGP instance : 1 bgpd: memstats: BGP peer : 1 bgpd: memstats: BGP peer hostname : 1 bgpd: memstats: BGP attribute : 1 bgpd: memstats: BGP extra attributes : 1 bgpd: memstats: BGP aspath : 1 bgpd: memstats: BGP aspath str : 1 bgpd: memstats: BGP table : 24 bgpd: memstats: BGP node : 1 bgpd: memstats: BGP route : 1 bgpd: memstats: BGP synchronise : 8 bgpd: memstats: BGP Process queue : 1 bgpd: memstats: BGP node clear queue : 1 bgpd: memstats: NOTE: If configuration exists, utilization may be expected. Example clean exit: bgpd: memstats: No remaining tracked memory utilization. This patch fixes bug #397: "Invalid free in bgp_announce_check()". This patch fixes bug #492: "SIGBUS in bgpd/bgp_route.c: bgp_clear_route_node()". My apologies for not separating out these changes into individual patches. The complexity of doing so boggled what is left of my brain. I hope this is all still useful to the community. This code has been production tested, in non-route-server-client mode, on a linux 32-bit box and a 64-bit box. Release/reset functions, used by bgp_exit(), added to: bgpd/bgp_attr.c,h bgpd/bgp_community.c,h bgpd/bgp_dump.c,h bgpd/bgp_ecommunity.c,h bgpd/bgp_filter.c,h bgpd/bgp_nexthop.c,h bgpd/bgp_route.c,h lib/routemap.c,h File by file analysis: * bgpd/bgp_aspath.c: Prevent re-use of ashash after it is released. * bgpd/bgp_attr.c: #if removed uncalled cluster_dup(). * bgpd/bgp_clist.c,h: Allow community_list_terminate() to be called from bgp_exit(). * bgpd/bgp_filter.c: Fix aslist->name use without allocation check, and also fix memory leak. * bgpd/bgp_main.c: Created bgp_exit() exit routine. This function frees allocations made as part of bgpd initialization and, to some extent, configuration. If "debug bgp" is configured, memory stats are printed as described above. * bgpd/bgp_nexthop.c: zclient_new() already allocates stream for ibuf/obuf, so bgp_scan_init() shouldn't do it too. Also, made it so zlookup is global so bgp_exit() can use it. * bgpd/bgp_packet.c: bgp_capability_msg_parse() call to bgp_clear_route() adjusted to use new BGP_CLEAR_ROUTE_NORMAL flag. * bgpd/bgp_route.h: Correct reference counter "lock" to be signed. bgp_clear_route() now accepts a bgp_clear_route_type of either BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT. * bgpd/bgp_route.c: - bgp_process_rsclient(): attr was being zero'ed and then bgp_attr_extra_free() was being called with it, even though it was never filled with valid data. - bgp_process_rsclient(): Make sure rsclient->group is not NULL before use. - bgp_processq_del(): Add call to bgp_table_unlock(). - bgp_process(): Add call to bgp_table_lock(). - bgp_update_rsclient(): memset clearing of new_attr not needed since declarationw with "= { 0 }" does it. memset was already commented out. - bgp_update_rsclient(): Fix screwed up misleading indentation. - bgp_withdraw_rsclient(): Fix screwed up misleading indentation. - bgp_clear_route_node(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. - bgp_clear_node_queue_del(): Add call to bgp_table_unlock() and also free struct bgp_clear_node_queue used for work item. - bgp_clear_node_complete(): Do peer_unlock() after BGP_EVENT_ADD() in case peer is released by peer_unlock() call. - bgp_clear_route_table(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. Use struct bgp_clear_node_queue to supply data to worker. Add call to bgp_table_lock(). - bgp_clear_route(): Add support for BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT. - bgp_clear_route_all(): Use BGP_CLEAR_ROUTE_NORMAL. Bug 397 fixes: - bgp_default_originate() - bgp_announce_table() * bgpd/bgp_table.h: - struct bgp_table: Added reference count. Changed type of owner to be "struct peer *" rather than "void *". - struct bgp_node: Correct reference counter "lock" to be signed. * bgpd/bgp_table.c: - Added bgp_table reference counting. - bgp_table_free(): Fixed cleanup code. Call peer_unlock() on owner if set. - bgp_unlock_node(): Added assertion. - bgp_node_get(): Added call to bgp_lock_node() to code path that it was missing from. * bgpd/bgp_vty.c: - peer_rsclient_set_vty(): Call peer_lock() as part of peer assignment to owner. Handle failure gracefully. - peer_rsclient_unset_vty(): Add call to bgp_clear_route() with BGP_CLEAR_ROUTE_MY_RSCLIENT purpose. * bgpd/bgp_zebra.c: Made it so zclient is global so bgp_exit() can use it. * bgpd/bgpd.c: - peer_lock(): Allow to be called when status is "Deleted". - peer_deactivate(): Supply BGP_CLEAR_ROUTE_NORMAL purpose to bgp_clear_route() call. - peer_delete(): Common variable listnode pn. Fix bug in which rsclient was only dealt with if not part of a peer group. Call bgp_clear_route() for rsclient, if appropriate, and do so with BGP_CLEAR_ROUTE_MY_RSCLIENT purpose. - peer_group_get(): Use XSTRDUP() instead of strdup() for conf->host. - peer_group_bind(): Call bgp_clear_route() for rsclient, and do so with BGP_CLEAR_ROUTE_MY_RSCLIENT purpose. - bgp_create(): Use XSTRDUP() instead of strdup() for peer_self->host. - bgp_delete(): Delete peers before groups, rather than after. And then rather than deleting rsclients, verify that there are none at this point. - bgp_unlock(): Add assertion. - bgp_free(): Call bgp_table_finish() rather than doing XFREE() itself. * lib/command.c,h: Compiler warning fixes. Add cmd_terminate(). Fixed massive leak in install_element() in which cmd_make_descvec() was being called more than once for the same cmd->strvec/string/doc. * lib/log.c: Make closezlog() check fp before calling fclose(). * lib/memory.c: Catch when alloc count goes negative by using signed counts. Correct #endif comment. Add log_memstats_stderr(). * lib/memory.h: Add log_memstats_stderr(). * lib/thread.c: thread->funcname was being accessed in thread_call() after it had been freed. Rearranged things so that thread_call() frees funcname. Also made it so thread_master_free() cleans up cpu_record. * lib/vty.c,h: Use global command_cr. Add vty_terminate(). * lib/zclient.c,h: Re-enable zclient_free().
2009-07-18 07:44:03 +02:00
if ((cmd_node = vector_slot(cmdvec, i)) != NULL) {
// deleting the graph delets the cmd_element as
// well
graph_delete_graph(cmd_node->cmdgraph);
vector_free(cmd_node->cmd_vector);
hash_clean_and_free(&cmd_node->cmd_hash, NULL);
}
[bgpd] Stability fixes including bugs 397, 492 I've spent the last several weeks working on stability fixes to bgpd. These patches fix all of the numerous crashes, assertion failures, memory leaks and memory stomping I could find. Valgrind was used extensively. Added new function bgp_exit() to help catch problems. If "debug bgp" is configured and bgpd exits with status of 0, statistics on remaining lib/memory.c allocations are printed to stderr. It is my hope that other developers will use this to stay on top of memory issues. Example questionable exit: bgpd: memstats: Current memory utilization in module LIB: bgpd: memstats: Link List : 6 bgpd: memstats: Link Node : 5 bgpd: memstats: Hash : 8 bgpd: memstats: Hash Bucket : 2 bgpd: memstats: Hash Index : 8 bgpd: memstats: Work queue : 3 bgpd: memstats: Work queue item : 2 bgpd: memstats: Work queue name string : 3 bgpd: memstats: Current memory utilization in module BGP: bgpd: memstats: BGP instance : 1 bgpd: memstats: BGP peer : 1 bgpd: memstats: BGP peer hostname : 1 bgpd: memstats: BGP attribute : 1 bgpd: memstats: BGP extra attributes : 1 bgpd: memstats: BGP aspath : 1 bgpd: memstats: BGP aspath str : 1 bgpd: memstats: BGP table : 24 bgpd: memstats: BGP node : 1 bgpd: memstats: BGP route : 1 bgpd: memstats: BGP synchronise : 8 bgpd: memstats: BGP Process queue : 1 bgpd: memstats: BGP node clear queue : 1 bgpd: memstats: NOTE: If configuration exists, utilization may be expected. Example clean exit: bgpd: memstats: No remaining tracked memory utilization. This patch fixes bug #397: "Invalid free in bgp_announce_check()". This patch fixes bug #492: "SIGBUS in bgpd/bgp_route.c: bgp_clear_route_node()". My apologies for not separating out these changes into individual patches. The complexity of doing so boggled what is left of my brain. I hope this is all still useful to the community. This code has been production tested, in non-route-server-client mode, on a linux 32-bit box and a 64-bit box. Release/reset functions, used by bgp_exit(), added to: bgpd/bgp_attr.c,h bgpd/bgp_community.c,h bgpd/bgp_dump.c,h bgpd/bgp_ecommunity.c,h bgpd/bgp_filter.c,h bgpd/bgp_nexthop.c,h bgpd/bgp_route.c,h lib/routemap.c,h File by file analysis: * bgpd/bgp_aspath.c: Prevent re-use of ashash after it is released. * bgpd/bgp_attr.c: #if removed uncalled cluster_dup(). * bgpd/bgp_clist.c,h: Allow community_list_terminate() to be called from bgp_exit(). * bgpd/bgp_filter.c: Fix aslist->name use without allocation check, and also fix memory leak. * bgpd/bgp_main.c: Created bgp_exit() exit routine. This function frees allocations made as part of bgpd initialization and, to some extent, configuration. If "debug bgp" is configured, memory stats are printed as described above. * bgpd/bgp_nexthop.c: zclient_new() already allocates stream for ibuf/obuf, so bgp_scan_init() shouldn't do it too. Also, made it so zlookup is global so bgp_exit() can use it. * bgpd/bgp_packet.c: bgp_capability_msg_parse() call to bgp_clear_route() adjusted to use new BGP_CLEAR_ROUTE_NORMAL flag. * bgpd/bgp_route.h: Correct reference counter "lock" to be signed. bgp_clear_route() now accepts a bgp_clear_route_type of either BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT. * bgpd/bgp_route.c: - bgp_process_rsclient(): attr was being zero'ed and then bgp_attr_extra_free() was being called with it, even though it was never filled with valid data. - bgp_process_rsclient(): Make sure rsclient->group is not NULL before use. - bgp_processq_del(): Add call to bgp_table_unlock(). - bgp_process(): Add call to bgp_table_lock(). - bgp_update_rsclient(): memset clearing of new_attr not needed since declarationw with "= { 0 }" does it. memset was already commented out. - bgp_update_rsclient(): Fix screwed up misleading indentation. - bgp_withdraw_rsclient(): Fix screwed up misleading indentation. - bgp_clear_route_node(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. - bgp_clear_node_queue_del(): Add call to bgp_table_unlock() and also free struct bgp_clear_node_queue used for work item. - bgp_clear_node_complete(): Do peer_unlock() after BGP_EVENT_ADD() in case peer is released by peer_unlock() call. - bgp_clear_route_table(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. Use struct bgp_clear_node_queue to supply data to worker. Add call to bgp_table_lock(). - bgp_clear_route(): Add support for BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT. - bgp_clear_route_all(): Use BGP_CLEAR_ROUTE_NORMAL. Bug 397 fixes: - bgp_default_originate() - bgp_announce_table() * bgpd/bgp_table.h: - struct bgp_table: Added reference count. Changed type of owner to be "struct peer *" rather than "void *". - struct bgp_node: Correct reference counter "lock" to be signed. * bgpd/bgp_table.c: - Added bgp_table reference counting. - bgp_table_free(): Fixed cleanup code. Call peer_unlock() on owner if set. - bgp_unlock_node(): Added assertion. - bgp_node_get(): Added call to bgp_lock_node() to code path that it was missing from. * bgpd/bgp_vty.c: - peer_rsclient_set_vty(): Call peer_lock() as part of peer assignment to owner. Handle failure gracefully. - peer_rsclient_unset_vty(): Add call to bgp_clear_route() with BGP_CLEAR_ROUTE_MY_RSCLIENT purpose. * bgpd/bgp_zebra.c: Made it so zclient is global so bgp_exit() can use it. * bgpd/bgpd.c: - peer_lock(): Allow to be called when status is "Deleted". - peer_deactivate(): Supply BGP_CLEAR_ROUTE_NORMAL purpose to bgp_clear_route() call. - peer_delete(): Common variable listnode pn. Fix bug in which rsclient was only dealt with if not part of a peer group. Call bgp_clear_route() for rsclient, if appropriate, and do so with BGP_CLEAR_ROUTE_MY_RSCLIENT purpose. - peer_group_get(): Use XSTRDUP() instead of strdup() for conf->host. - peer_group_bind(): Call bgp_clear_route() for rsclient, and do so with BGP_CLEAR_ROUTE_MY_RSCLIENT purpose. - bgp_create(): Use XSTRDUP() instead of strdup() for peer_self->host. - bgp_delete(): Delete peers before groups, rather than after. And then rather than deleting rsclients, verify that there are none at this point. - bgp_unlock(): Add assertion. - bgp_free(): Call bgp_table_finish() rather than doing XFREE() itself. * lib/command.c,h: Compiler warning fixes. Add cmd_terminate(). Fixed massive leak in install_element() in which cmd_make_descvec() was being called more than once for the same cmd->strvec/string/doc. * lib/log.c: Make closezlog() check fp before calling fclose(). * lib/memory.c: Catch when alloc count goes negative by using signed counts. Correct #endif comment. Add log_memstats_stderr(). * lib/memory.h: Add log_memstats_stderr(). * lib/thread.c: thread->funcname was being accessed in thread_call() after it had been freed. Rearranged things so that thread_call() frees funcname. Also made it so thread_master_free() cleans up cpu_record. * lib/vty.c,h: Use global command_cr. Add vty_terminate(). * lib/zclient.c,h: Re-enable zclient_free().
2009-07-18 07:44:03 +02:00
vector_free(cmdvec);
cmdvec = NULL;
}
XFREE(MTYPE_HOST, host.name);
XFREE(MTYPE_HOST, host.system);
XFREE(MTYPE_HOST, host.release);
XFREE(MTYPE_HOST, host.version);
XFREE(MTYPE_HOST, host.domainname);
XFREE(MTYPE_HOST, host.password);
XFREE(MTYPE_HOST, host.password_encrypt);
XFREE(MTYPE_HOST, host.enable);
XFREE(MTYPE_HOST, host.enable_encrypt);
XFREE(MTYPE_HOST, host.motdfile);
XFREE(MTYPE_HOST, host.config);
XFREE(MTYPE_HOST, host.motd);
list_delete(&varhandlers);
qobj_finish();
[bgpd] Stability fixes including bugs 397, 492 I've spent the last several weeks working on stability fixes to bgpd. These patches fix all of the numerous crashes, assertion failures, memory leaks and memory stomping I could find. Valgrind was used extensively. Added new function bgp_exit() to help catch problems. If "debug bgp" is configured and bgpd exits with status of 0, statistics on remaining lib/memory.c allocations are printed to stderr. It is my hope that other developers will use this to stay on top of memory issues. Example questionable exit: bgpd: memstats: Current memory utilization in module LIB: bgpd: memstats: Link List : 6 bgpd: memstats: Link Node : 5 bgpd: memstats: Hash : 8 bgpd: memstats: Hash Bucket : 2 bgpd: memstats: Hash Index : 8 bgpd: memstats: Work queue : 3 bgpd: memstats: Work queue item : 2 bgpd: memstats: Work queue name string : 3 bgpd: memstats: Current memory utilization in module BGP: bgpd: memstats: BGP instance : 1 bgpd: memstats: BGP peer : 1 bgpd: memstats: BGP peer hostname : 1 bgpd: memstats: BGP attribute : 1 bgpd: memstats: BGP extra attributes : 1 bgpd: memstats: BGP aspath : 1 bgpd: memstats: BGP aspath str : 1 bgpd: memstats: BGP table : 24 bgpd: memstats: BGP node : 1 bgpd: memstats: BGP route : 1 bgpd: memstats: BGP synchronise : 8 bgpd: memstats: BGP Process queue : 1 bgpd: memstats: BGP node clear queue : 1 bgpd: memstats: NOTE: If configuration exists, utilization may be expected. Example clean exit: bgpd: memstats: No remaining tracked memory utilization. This patch fixes bug #397: "Invalid free in bgp_announce_check()". This patch fixes bug #492: "SIGBUS in bgpd/bgp_route.c: bgp_clear_route_node()". My apologies for not separating out these changes into individual patches. The complexity of doing so boggled what is left of my brain. I hope this is all still useful to the community. This code has been production tested, in non-route-server-client mode, on a linux 32-bit box and a 64-bit box. Release/reset functions, used by bgp_exit(), added to: bgpd/bgp_attr.c,h bgpd/bgp_community.c,h bgpd/bgp_dump.c,h bgpd/bgp_ecommunity.c,h bgpd/bgp_filter.c,h bgpd/bgp_nexthop.c,h bgpd/bgp_route.c,h lib/routemap.c,h File by file analysis: * bgpd/bgp_aspath.c: Prevent re-use of ashash after it is released. * bgpd/bgp_attr.c: #if removed uncalled cluster_dup(). * bgpd/bgp_clist.c,h: Allow community_list_terminate() to be called from bgp_exit(). * bgpd/bgp_filter.c: Fix aslist->name use without allocation check, and also fix memory leak. * bgpd/bgp_main.c: Created bgp_exit() exit routine. This function frees allocations made as part of bgpd initialization and, to some extent, configuration. If "debug bgp" is configured, memory stats are printed as described above. * bgpd/bgp_nexthop.c: zclient_new() already allocates stream for ibuf/obuf, so bgp_scan_init() shouldn't do it too. Also, made it so zlookup is global so bgp_exit() can use it. * bgpd/bgp_packet.c: bgp_capability_msg_parse() call to bgp_clear_route() adjusted to use new BGP_CLEAR_ROUTE_NORMAL flag. * bgpd/bgp_route.h: Correct reference counter "lock" to be signed. bgp_clear_route() now accepts a bgp_clear_route_type of either BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT. * bgpd/bgp_route.c: - bgp_process_rsclient(): attr was being zero'ed and then bgp_attr_extra_free() was being called with it, even though it was never filled with valid data. - bgp_process_rsclient(): Make sure rsclient->group is not NULL before use. - bgp_processq_del(): Add call to bgp_table_unlock(). - bgp_process(): Add call to bgp_table_lock(). - bgp_update_rsclient(): memset clearing of new_attr not needed since declarationw with "= { 0 }" does it. memset was already commented out. - bgp_update_rsclient(): Fix screwed up misleading indentation. - bgp_withdraw_rsclient(): Fix screwed up misleading indentation. - bgp_clear_route_node(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. - bgp_clear_node_queue_del(): Add call to bgp_table_unlock() and also free struct bgp_clear_node_queue used for work item. - bgp_clear_node_complete(): Do peer_unlock() after BGP_EVENT_ADD() in case peer is released by peer_unlock() call. - bgp_clear_route_table(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. Use struct bgp_clear_node_queue to supply data to worker. Add call to bgp_table_lock(). - bgp_clear_route(): Add support for BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT. - bgp_clear_route_all(): Use BGP_CLEAR_ROUTE_NORMAL. Bug 397 fixes: - bgp_default_originate() - bgp_announce_table() * bgpd/bgp_table.h: - struct bgp_table: Added reference count. Changed type of owner to be "struct peer *" rather than "void *". - struct bgp_node: Correct reference counter "lock" to be signed. * bgpd/bgp_table.c: - Added bgp_table reference counting. - bgp_table_free(): Fixed cleanup code. Call peer_unlock() on owner if set. - bgp_unlock_node(): Added assertion. - bgp_node_get(): Added call to bgp_lock_node() to code path that it was missing from. * bgpd/bgp_vty.c: - peer_rsclient_set_vty(): Call peer_lock() as part of peer assignment to owner. Handle failure gracefully. - peer_rsclient_unset_vty(): Add call to bgp_clear_route() with BGP_CLEAR_ROUTE_MY_RSCLIENT purpose. * bgpd/bgp_zebra.c: Made it so zclient is global so bgp_exit() can use it. * bgpd/bgpd.c: - peer_lock(): Allow to be called when status is "Deleted". - peer_deactivate(): Supply BGP_CLEAR_ROUTE_NORMAL purpose to bgp_clear_route() call. - peer_delete(): Common variable listnode pn. Fix bug in which rsclient was only dealt with if not part of a peer group. Call bgp_clear_route() for rsclient, if appropriate, and do so with BGP_CLEAR_ROUTE_MY_RSCLIENT purpose. - peer_group_get(): Use XSTRDUP() instead of strdup() for conf->host. - peer_group_bind(): Call bgp_clear_route() for rsclient, and do so with BGP_CLEAR_ROUTE_MY_RSCLIENT purpose. - bgp_create(): Use XSTRDUP() instead of strdup() for peer_self->host. - bgp_delete(): Delete peers before groups, rather than after. And then rather than deleting rsclients, verify that there are none at this point. - bgp_unlock(): Add assertion. - bgp_free(): Call bgp_table_finish() rather than doing XFREE() itself. * lib/command.c,h: Compiler warning fixes. Add cmd_terminate(). Fixed massive leak in install_element() in which cmd_make_descvec() was being called more than once for the same cmd->strvec/string/doc. * lib/log.c: Make closezlog() check fp before calling fclose(). * lib/memory.c: Catch when alloc count goes negative by using signed counts. Correct #endif comment. Add log_memstats_stderr(). * lib/memory.h: Add log_memstats_stderr(). * lib/thread.c: thread->funcname was being accessed in thread_call() after it had been freed. Rearranged things so that thread_call() frees funcname. Also made it so thread_master_free() cleans up cpu_record. * lib/vty.c,h: Use global command_cr. Add vty_terminate(). * lib/zclient.c,h: Re-enable zclient_free().
2009-07-18 07:44:03 +02:00
}