summaryrefslogtreecommitdiff
path: root/lib/command.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/command.c')
-rw-r--r--lib/command.c90
1 files changed, 50 insertions, 40 deletions
diff --git a/lib/command.c b/lib/command.c
index a23afb1e43..8025ab534f 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* CLI backend interface.
*
@@ -6,22 +7,6 @@
* Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
* Copyright (C) 2013 by Open Source Routing.
* Copyright (C) 2013 by Internet Systems Consortium, Inc. ("ISC")
- *
- * This file is part of GNU Zebra.
- *
- * GNU Zebra is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
- *
- * GNU Zebra is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
@@ -32,7 +17,7 @@
#include "memory.h"
#include "log.h"
#include "log_vty.h"
-#include "thread.h"
+#include "frrevent.h"
#include "vector.h"
#include "linklist.h"
#include "vty.h"
@@ -46,8 +31,11 @@
#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"
@@ -70,6 +58,7 @@ const struct message tokennames[] = {
item(IPV6_PREFIX_TKN),
item(MAC_TKN),
item(MAC_PREFIX_TKN),
+ item(ASNUM_TKN),
item(FORK_TKN),
item(JOIN_TKN),
item(START_TKN),
@@ -126,6 +115,11 @@ bool cmd_allow_reserved_ranges_get(void)
return host.allow_reserved_ranges;
}
+const char *cmd_software_version_get(void)
+{
+ return FRR_FULL_NAME "/" FRR_VERSION;
+}
+
static int root_on_exit(struct vty *vty);
/* Standard command node structures. */
@@ -264,8 +258,7 @@ void install_node(struct cmd_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, CMD_ATTR_NORMAL, NULL, NULL);
+ struct cmd_token *token = cmd_token_new(START_TKN, 0, NULL, NULL);
graph_new_node(node->cmdgraph, token,
(void (*)(void *)) & cmd_token_del);
@@ -325,7 +318,7 @@ void _install_element(enum node_type ntype, const struct cmd_element *cmd)
if (cnode->graph_built || !defer_cli_tree) {
struct graph *graph = graph_new();
struct cmd_token *token =
- cmd_token_new(START_TKN, CMD_ATTR_NORMAL, NULL, NULL);
+ cmd_token_new(START_TKN, 0, NULL, NULL);
graph_new_node(graph, token,
(void (*)(void *)) & cmd_token_del);
@@ -348,8 +341,7 @@ 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, CMD_ATTR_NORMAL, NULL, NULL);
+ struct cmd_token *token = cmd_token_new(START_TKN, 0, NULL, NULL);
graph_new_node(graph, token, (void (*)(void *)) & cmd_token_del);
@@ -404,7 +396,7 @@ void uninstall_element(enum node_type ntype, const struct cmd_element *cmd)
if (cnode->graph_built) {
struct graph *graph = graph_new();
struct cmd_token *token =
- cmd_token_new(START_TKN, CMD_ATTR_NORMAL, NULL, NULL);
+ cmd_token_new(START_TKN, 0, NULL, NULL);
graph_new_node(graph, token,
(void (*)(void *)) & cmd_token_del);
@@ -503,7 +495,7 @@ static int config_write_host(struct vty *vty)
else if (cputime_threshold != 5000000)
#endif
vty_out(vty, "service cputime-warning %lu\n",
- cputime_threshold);
+ cputime_threshold / 1000);
if (!walltime_threshold)
vty_out(vty, "no service walltime-warning\n");
@@ -513,7 +505,7 @@ static int config_write_host(struct vty *vty)
else if (walltime_threshold != 5000000)
#endif
vty_out(vty, "service walltime-warning %lu\n",
- walltime_threshold);
+ walltime_threshold / 1000);
if (host.advanced)
vty_out(vty, "service advanced-vty\n");
@@ -743,9 +735,13 @@ char *cmd_variable_comp2str(vector comps, unsigned short cols)
char *item = vector_slot(comps, j);
itemlen = strlen(item);
- if (cs + itemlen + AUTOCOMP_INDENT + 3 >= bsz)
- buf = XREALLOC(MTYPE_TMP, buf, (bsz *= 2));
+ 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, "");
@@ -950,7 +946,8 @@ static int cmd_execute_command_real(vector vline, enum cmd_filter_type filter,
return CMD_ERR_INCOMPLETE;
case MATCHER_AMBIGUOUS:
return CMD_ERR_AMBIGUOUS;
- default:
+ case MATCHER_NO_MATCH:
+ case MATCHER_OK:
return CMD_ERR_NO_MATCH;
}
}
@@ -990,7 +987,7 @@ static int cmd_execute_command_real(vector vline, enum cmd_filter_type filter,
* Perform pending commit (if any) before executing
* non-YANG command.
*/
- if (matched_element->attr != CMD_ATTR_YANG)
+ if (!(matched_element->attr & CMD_ATTR_YANG))
(void)nb_cli_pending_commit_check(vty);
}
@@ -1290,6 +1287,7 @@ int command_config_read_one_line(struct vty *vty,
memcpy(ve->error_buf, vty->buf, VTY_BUFSIZ);
ve->line_num = line_num;
+ ve->cmd_ret = ret;
if (!vty->error)
vty->error = list_new();
@@ -1310,6 +1308,14 @@ int config_from_file(struct vty *vty, FILE *fp, unsigned int *line_num)
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);
if (ret != CMD_SUCCESS && ret != CMD_WARNING
@@ -1327,11 +1333,12 @@ int config_from_file(struct vty *vty, FILE *fp, unsigned int *line_num)
/* Configuration from terminal */
DEFUN (config_terminal,
config_terminal_cmd,
- "configure [terminal]",
+ "configure [terminal [file-lock]]",
"Configuration from vty interface\n"
+ "Configuration with locked datastores\n"
"Configuration terminal\n")
{
- return vty_config_enter(vty, false, false);
+ return vty_config_enter(vty, false, false, argc == 3);
}
/* Enable command */
@@ -1471,8 +1478,7 @@ static void permute(struct graph_node *start, struct vty *vty)
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
- || tok->attr == CMD_ATTR_DEPRECATED)
+ if (tok->attr & CMD_ATTR_HIDDEN)
continue;
else if (tok->type == END_TKN || gn == start) {
vty_out(vty, " ");
@@ -1561,9 +1567,8 @@ int cmd_list_cmds(struct vty *vty, int do_permute)
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_DEPRECATED
- && element->attr != CMD_ATTR_HIDDEN) {
+ if ((element = vector_slot(node->cmd_vector, i)) &&
+ !(element->attr & CMD_ATTR_HIDDEN)) {
vty_out(vty, " ");
print_cmd(vty, element->string);
}
@@ -2446,6 +2451,13 @@ const char *host_config_get(void)
return host.config;
}
+void cmd_show_lib_debugs(struct vty *vty)
+{
+ route_map_show_debug(vty);
+ mgmt_debug_be_client_show_debug(vty);
+ mgmt_debug_fe_client_show_debug(vty);
+}
+
void install_default(enum node_type node)
{
_install_element(node, &config_exit_cmd);
@@ -2548,7 +2560,7 @@ void cmd_init(int terminal)
install_default(CONFIG_NODE);
- thread_cmd_init();
+ event_cmd_init();
workqueue_cmd_init();
hash_cmd_init();
}
@@ -2602,9 +2614,7 @@ void cmd_terminate(void)
// well
graph_delete_graph(cmd_node->cmdgraph);
vector_free(cmd_node->cmd_vector);
- hash_clean(cmd_node->cmd_hash, NULL);
- hash_free(cmd_node->cmd_hash);
- cmd_node->cmd_hash = NULL;
+ hash_clean_and_free(&cmd_node->cmd_hash, NULL);
}
vector_free(cmdvec);