]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/rfapi/vnc_debug.c
Merge pull request #5881 from patrasar/2386420
[mirror_frr.git] / bgpd / rfapi / vnc_debug.c
1 /*
2 *
3 * Copyright 2016, LabN Consulting, L.L.C.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "lib/zebra.h"
21
22 #include <lib/version.h>
23 #include "lib/prefix.h"
24 #include "lib/linklist.h"
25 #include "lib/stream.h"
26 #include "lib/command.h"
27 #include "lib/log.h"
28 #include "bgpd/rfapi/vnc_debug.h"
29
30 /*
31 * debug state storage
32 */
33 unsigned long conf_vnc_debug;
34 unsigned long term_vnc_debug;
35
36 struct vnc_debug {
37 unsigned long bit;
38 const char *name;
39 };
40
41 static const struct vnc_debug vncdebug[] = {
42 {VNC_DEBUG_RFAPI_QUERY, "rfapi-query"},
43 {VNC_DEBUG_IMPORT_BI_ATTACH, "import-bi-attach"},
44 {VNC_DEBUG_IMPORT_DEL_REMOTE, "import-del-remote"},
45 {VNC_DEBUG_EXPORT_BGP_GETCE, "export-bgp-getce"},
46 {VNC_DEBUG_EXPORT_BGP_DIRECT_ADD, "export-bgp-direct-add"},
47 {VNC_DEBUG_IMPORT_BGP_ADD_ROUTE, "import-bgp-add-route"},
48 {VNC_DEBUG_VERBOSE, "verbose"},
49 };
50
51 #define VNC_STR "VNC information\n"
52
53 /***********************************************************************
54 * debug bgp vnc <foo>
55 ***********************************************************************/
56 DEFUN (debug_bgp_vnc,
57 debug_bgp_vnc_cmd,
58 "debug bgp vnc <rfapi-query|import-bi-attach|import-del-remote|verbose>",
59 DEBUG_STR
60 BGP_STR
61 VNC_STR
62 "rfapi query handling\n"
63 "import BI atachment\n"
64 "import delete remote routes\n"
65 "verbose logging\n")
66 {
67 size_t i;
68
69 for (i = 0; i < (sizeof(vncdebug) / sizeof(struct vnc_debug)); ++i) {
70 if (strmatch(argv[3]->text, vncdebug[i].name)) {
71 if (vty->node == CONFIG_NODE) {
72 conf_vnc_debug |= vncdebug[i].bit;
73 term_vnc_debug |= vncdebug[i].bit;
74 } else {
75 term_vnc_debug |= vncdebug[i].bit;
76 vty_out(vty, "BGP vnc %s debugging is on\n",
77 vncdebug[i].name);
78 }
79 return CMD_SUCCESS;
80 }
81 }
82 vty_out(vty, "Unknown debug flag: %s\n", argv[3]->arg);
83 return CMD_WARNING_CONFIG_FAILED;
84 }
85
86 DEFUN (no_debug_bgp_vnc,
87 no_debug_bgp_vnc_cmd,
88 "no debug bgp vnc <rfapi-query|import-bi-attach|import-del-remote|verbose>",
89 NO_STR
90 DEBUG_STR
91 BGP_STR
92 VNC_STR
93 "rfapi query handling\n"
94 "import BI atachment\n"
95 "import delete remote routes\n"
96 "verbose logging\n")
97 {
98 size_t i;
99
100 for (i = 0; i < (sizeof(vncdebug) / sizeof(struct vnc_debug)); ++i) {
101 if (strmatch(argv[argc - 1]->text, vncdebug[i].name)) {
102 if (vty->node == CONFIG_NODE) {
103 conf_vnc_debug &= ~vncdebug[i].bit;
104 term_vnc_debug &= ~vncdebug[i].bit;
105 } else {
106 term_vnc_debug &= ~vncdebug[i].bit;
107 vty_out(vty, "BGP vnc %s debugging is off\n",
108 vncdebug[i].name);
109 }
110 return CMD_SUCCESS;
111 }
112 }
113 vty_out(vty, "Unknown debug flag: %s\n", argv[3]->arg);
114 return CMD_WARNING_CONFIG_FAILED;
115 }
116
117 /***********************************************************************
118 * no debug bgp vnc all
119 ***********************************************************************/
120
121 DEFUN (no_debug_bgp_vnc_all,
122 no_debug_bgp_vnc_all_cmd,
123 "no debug all bgp vnc",
124 NO_STR
125 DEBUG_STR
126 "Disable all VNC debugging\n"
127 BGP_STR
128 VNC_STR)
129 {
130 term_vnc_debug = 0;
131 vty_out(vty, "All possible VNC debugging has been turned off\n");
132
133 return CMD_SUCCESS;
134 }
135
136 /***********************************************************************
137 * show/save
138 ***********************************************************************/
139
140 DEFUN_NOSH (show_debugging_bgp_vnc,
141 show_debugging_bgp_vnc_cmd,
142 "show debugging bgp vnc",
143 SHOW_STR
144 DEBUG_STR
145 BGP_STR
146 VNC_STR)
147 {
148 size_t i;
149
150 vty_out(vty, "BGP VNC debugging status:\n");
151
152 for (i = 0; i < (sizeof(vncdebug) / sizeof(struct vnc_debug)); ++i) {
153 if (term_vnc_debug & vncdebug[i].bit) {
154 vty_out(vty, " BGP VNC %s debugging is on\n",
155 vncdebug[i].name);
156 }
157 }
158 vty_out(vty, "\n");
159 return CMD_SUCCESS;
160 }
161
162 static int bgp_vnc_config_write_debug(struct vty *vty)
163 {
164 int write = 0;
165 size_t i;
166
167 for (i = 0; i < array_size(vncdebug); ++i) {
168 if (conf_vnc_debug & vncdebug[i].bit) {
169 vty_out(vty, "debug bgp vnc %s\n", vncdebug[i].name);
170 write++;
171 }
172 }
173 return write;
174 }
175
176 static int bgp_vnc_config_write_debug(struct vty *vty);
177 static struct cmd_node debug_node = {
178 .name = "vnc debug",
179 .node = DEBUG_VNC_NODE,
180 .prompt = "",
181 .config_write = bgp_vnc_config_write_debug,
182 };
183
184 void vnc_debug_init(void)
185 {
186 install_node(&debug_node);
187 install_element(ENABLE_NODE, &show_debugging_bgp_vnc_cmd);
188
189 install_element(ENABLE_NODE, &debug_bgp_vnc_cmd);
190 install_element(CONFIG_NODE, &debug_bgp_vnc_cmd);
191 install_element(ENABLE_NODE, &no_debug_bgp_vnc_cmd);
192 install_element(CONFIG_NODE, &no_debug_bgp_vnc_cmd);
193
194 install_element(ENABLE_NODE, &no_debug_bgp_vnc_all_cmd);
195 install_element(CONFIG_NODE, &no_debug_bgp_vnc_all_cmd);
196 }