]> git.proxmox.com Git - mirror_frr.git/blob - lib/log_vty.c
Merge pull request #5625 from qlyoung/fix-zapi-ipset-name-nullterm
[mirror_frr.git] / lib / log_vty.c
1 /*
2 * Logging - VTY code
3 * Copyright (C) 2019 Cumulus Networks, Inc.
4 * Stephen Worley
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "lib/log_vty.h"
24 #include "command.h"
25 #include "lib/vty.h"
26 #include "lib/log.h"
27 #ifndef VTYSH_EXTRACT_PL
28 #include "lib/log_vty_clippy.c"
29 #endif
30
31 DEFPY (log_filter,
32 log_filter_cmd,
33 "[no] log-filter WORD$filter",
34 NO_STR
35 FILTER_LOG_STR
36 "String to filter by\n")
37 {
38 int ret = 0;
39
40 if (no)
41 ret = zlog_filter_del(filter);
42 else
43 ret = zlog_filter_add(filter);
44
45 if (ret == 1) {
46 vty_out(vty, "%% filter table full\n");
47 return CMD_WARNING;
48 } else if (ret != 0) {
49 vty_out(vty, "%% failed to %s log filter\n",
50 (no ? "remove" : "apply"));
51 return CMD_WARNING;
52 }
53
54 vty_out(vty, " %s\n", filter);
55 return CMD_SUCCESS;
56 }
57
58 /* Clear all log filters */
59 DEFPY (log_filter_clear,
60 log_filter_clear_cmd,
61 "clear log-filter",
62 CLEAR_STR
63 FILTER_LOG_STR)
64 {
65 zlog_filter_clear();
66 return CMD_SUCCESS;
67 }
68
69 /* Show log filter */
70 DEFPY (show_log_filter,
71 show_log_filter_cmd,
72 "show log-filter",
73 SHOW_STR
74 FILTER_LOG_STR)
75 {
76 char log_filters[ZLOG_FILTERS_MAX * (ZLOG_FILTER_LENGTH_MAX + 3)] = "";
77 int len = 0;
78
79 len = zlog_filter_dump(log_filters, sizeof(log_filters));
80
81 if (len == -1) {
82 vty_out(vty, "%% failed to get filters\n");
83 return CMD_WARNING;
84 }
85
86 if (len != 0)
87 vty_out(vty, "%s", log_filters);
88
89 return CMD_SUCCESS;
90 }
91
92 void log_filter_cmd_init(void)
93 {
94 install_element(VIEW_NODE, &show_log_filter_cmd);
95 install_element(CONFIG_NODE, &log_filter_cmd);
96 install_element(CONFIG_NODE, &log_filter_clear_cmd);
97 }