#define SR_STR "Segment-Routing specific commands\n"
#define WATCHFRR_STR "watchfrr information\n"
#define ZEBRA_STR "Zebra information\n"
+#define FILTER_LOG_STR "Filter Logs\n"
#define CMD_VNI_RANGE "(1-16777215)"
#define CONF_BACKUP_EXT ".sav"
#include "command.h"
#include "version.h"
#include "memory_vty.h"
+#include "log_vty.h"
#include "zclient.h"
#include "log_int.h"
#include "module.h"
vty_init(master, di->log_always);
memory_init();
+ log_filter_cmd_init();
log_ref_init();
lib_error_init();
--- /dev/null
+/*
+ * Logging - VTY code
+ * Copyright (C) 2019 Cumulus Networks, Inc.
+ * Stephen Worley
+ *
+ * This program 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 of the License, or (at your option)
+ * any later version.
+ *
+ * This program 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>
+
+#include "lib/log_vty.h"
+#include "command.h"
+#include "lib/vty.h"
+#include "lib/log.h"
+#ifndef VTYSH_EXTRACT_PL
+#include "lib/log_vty_clippy.c"
+#endif
+
+/* Log filter */
+DEFPY (log_filter,
+ log_filter_cmd,
+ "[no] log-filter WORD$filter",
+ NO_STR
+ FILTER_LOG_STR
+ "String to filter by\n")
+{
+ int ret = 0;
+
+ if (no)
+ ret = zlog_filter_del(filter);
+ else
+ ret = zlog_filter_add(filter);
+
+ if (ret == 1) {
+ vty_out(vty, "\tfilter table full\n");
+ return CMD_WARNING;
+ } else if (ret != 0) {
+ vty_out(vty, "\tfailed to %s log filter\n",
+ (no ? "remove" : "apply"));
+ return CMD_WARNING;
+ }
+
+ vty_out(vty, "\t%s\n", filter);
+ return CMD_SUCCESS;
+}
+
+/* Clear all log filters */
+DEFPY (log_filter_clear,
+ log_filter_clear_cmd,
+ "clear log-filter",
+ CLEAR_STR
+ FILTER_LOG_STR)
+{
+ zlog_filter_clear();
+ vty_out(vty, "\tcleared all filters\n");
+ return CMD_SUCCESS;
+}
+
+/* Show log filter */
+DEFPY (show_log_filter,
+ show_log_filter_cmd,
+ "show log-filter",
+ SHOW_STR
+ FILTER_LOG_STR)
+{
+ char log_filters[ZLOG_FILTERS_MAX * (ZLOG_FILTER_LENGTH_MAX + 3)] = "";
+ int len = 0;
+
+ len = zlog_filter_dump(log_filters, sizeof(log_filters));
+
+ if (len == -1) {
+ vty_out(vty, "\tfailed to get filters\n");
+ return CMD_WARNING;
+ }
+
+ if (len != 0)
+ vty_out(vty, "%s", log_filters);
+
+ return CMD_SUCCESS;
+}
+
+void log_filter_cmd_init(void)
+{
+ install_element(VIEW_NODE, &show_log_filter_cmd);
+ install_element(CONFIG_NODE, &log_filter_cmd);
+ install_element(CONFIG_NODE, &log_filter_clear_cmd);
+}
--- /dev/null
+/*
+ * Logging - VTY library
+ * Copyright (C) 2019 Cumulus Networks, Inc.
+ * Stephen Worley
+ *
+ * This program 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 of the License, or (at your option)
+ * any later version.
+ *
+ * This program 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
+ */
+
+#ifndef __LOG_VTY_H__
+#define __LOG_VTY_H__
+extern void log_filter_cmd_init(void);
+#endif /* __LOG_VTY_H__ */
lib/libfrr.c \
lib/linklist.c \
lib/log.c \
+ lib/log_vty.c \
lib/md5.c \
lib/memory.c \
lib/memory_vty.c \
lib/northbound_cli.lo: lib/northbound_cli_clippy.c
lib/vty_clippy.c: $(CLIPPY_DEPS)
lib/vty.lo: lib/vty_clippy.c
+lib/log_vty_clippy.c: $(CLIPPY_DEPS)
+lib/log_vty.lo: lib/log_vty_clippy.c
pkginclude_HEADERS += \
lib/agg_table.h \
lib/libospf.h \
lib/linklist.h \
lib/log.h \
+ lib/log_vty.h \
lib/md5.h \
lib/memory.h \
lib/memory_vty.h \
return CMD_SUCCESS;
}
+/* Log filter */
+DEFUN (vtysh_log_filter,
+ vtysh_log_filter_cmd,
+ "[no] log-filter WORD ["DAEMONS_LIST"]",
+ NO_STR
+ FILTER_LOG_STR
+ "String to filter by\n"
+ DAEMONS_STR)
+{
+ char *filter = NULL;
+ char *daemon = NULL;
+ int found = 0;
+ int idx = 0;
+ int daemon_idx = 2;
+ int total_len = 0;
+ int len = 0;
+
+ char line[ZLOG_FILTER_LENGTH_MAX + 20];
+
+ found = argv_find(argv, argc, "no", &idx);
+ if (found == 1) {
+ len = snprintf(line, sizeof(line), "no log-filter");
+ daemon_idx += 1;
+ } else
+ len = snprintf(line, sizeof(line), "log-filter");
+
+ total_len += len;
+
+ idx = 1;
+ found = argv_find(argv, argc, "WORD", &idx);
+ if (found != 1) {
+ vty_out(vty, "No filter string given\n");
+ return CMD_WARNING;
+ }
+ filter = argv[idx]->arg;
+
+ if (strnlen(filter, ZLOG_FILTER_LENGTH_MAX + 1)
+ > ZLOG_FILTER_LENGTH_MAX) {
+ vty_out(vty, "Filter is too long\n");
+ return CMD_WARNING;
+ }
+
+ len = snprintf(line + total_len, sizeof(line) - total_len, " %s\n",
+ filter);
+
+ if ((len < 0) || (size_t)(total_len + len) > sizeof(line)) {
+ vty_out(vty, "Error buffering filter to daemons\n");
+ return CMD_ERR_INCOMPLETE;
+ }
+
+ if (argc >= (daemon_idx + 1))
+ daemon = argv[daemon_idx]->text;
+
+ if (daemon != NULL) {
+ vty_out(vty, "Applying log filter change to %s:\n", daemon);
+ return vtysh_client_execute_name(daemon, line);
+ } else
+ return show_per_daemon(line,
+ "Applying log filter change to %s:\n");
+}
+
+/* Clear log filters */
+DEFUN (vtysh_log_filter_clear,
+ vtysh_log_filter_clear_cmd,
+ "log-filter clear ["DAEMONS_LIST"]",
+ FILTER_LOG_STR
+ CLEAR_STR
+ DAEMONS_STR)
+{
+ char *daemon = NULL;
+ int daemon_idx = 2;
+
+ char line[] = "clear log-filter\n";
+
+ if (argc >= (daemon_idx + 1))
+ daemon = argv[daemon_idx]->text;
+
+ if (daemon != NULL) {
+ vty_out(vty, "Clearing all filters applied to %s:\n", daemon);
+ return vtysh_client_execute_name(daemon, line);
+ } else
+ return show_per_daemon(line,
+ "Clearing all filters applied to %s:\n");
+}
+
+/* Show log filter */
+DEFUN (vtysh_show_log_filter,
+ vtysh_show_log_filter_cmd,
+ "show log-filter",
+ SHOW_STR
+ FILTER_LOG_STR)
+{
+ char line[] = "do show log-filter\n";
+
+ return show_per_daemon(line, "Log filters applied to %s:\n");
+}
+
DEFUN (vtysh_write_terminal,
vtysh_write_terminal_cmd,
"write terminal ["DAEMONS_LIST"]",
/* Logging */
install_element(VIEW_NODE, &vtysh_show_logging_cmd);
+ install_element(VIEW_NODE, &vtysh_show_log_filter_cmd);
+ install_element(CONFIG_NODE, &vtysh_log_filter_cmd);
+ install_element(CONFIG_NODE, &vtysh_log_filter_clear_cmd);
install_element(CONFIG_NODE, &vtysh_log_stdout_cmd);
install_element(CONFIG_NODE, &vtysh_log_stdout_level_cmd);
install_element(CONFIG_NODE, &no_vtysh_log_stdout_cmd);