]> git.proxmox.com Git - mirror_frr.git/blob - zebra/debug.c
zebra: debug cleanup
[mirror_frr.git] / zebra / debug.c
1 /*
2 * Zebra debug related function
3 * Copyright (C) 1999 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <zebra.h>
23 #include "command.h"
24 #include "debug.h"
25
26 /* For debug statement. */
27 unsigned long zebra_debug_event;
28 unsigned long zebra_debug_packet;
29 unsigned long zebra_debug_kernel;
30 unsigned long zebra_debug_rib;
31 unsigned long zebra_debug_fpm;
32 unsigned long zebra_debug_nht;
33 unsigned long zebra_debug_mpls;
34 unsigned long zebra_debug_vxlan;
35
36 DEFUN (show_debugging_zebra,
37 show_debugging_zebra_cmd,
38 "show debugging zebra",
39 SHOW_STR
40 "Debugging information\n"
41 "Zebra configuration\n")
42 {
43 vty_out(vty, "Zebra debugging status:\n");
44
45 if (IS_ZEBRA_DEBUG_EVENT)
46 vty_out(vty, " Zebra event debugging is on\n");
47
48 if (IS_ZEBRA_DEBUG_PACKET) {
49 if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV) {
50 vty_out(vty, " Zebra packet%s debugging is on\n",
51 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "");
52 } else {
53 if (IS_ZEBRA_DEBUG_SEND)
54 vty_out(vty,
55 " Zebra packet send%s debugging is on\n",
56 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "");
57 else
58 vty_out(vty,
59 " Zebra packet receive%s debugging is on\n",
60 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "");
61 }
62 }
63
64 if (IS_ZEBRA_DEBUG_KERNEL)
65 vty_out(vty, " Zebra kernel debugging is on\n");
66 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND)
67 vty_out(vty,
68 " Zebra kernel netlink message dumps (send) are on\n");
69 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV)
70 vty_out(vty,
71 " Zebra kernel netlink message dumps (recv) are on\n");
72
73 /* Check here using flags as the 'macro' does an OR */
74 if (CHECK_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED))
75 vty_out(vty, " Zebra RIB detailed debugging is on\n");
76 else if (CHECK_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB))
77 vty_out(vty, " Zebra RIB debugging is on\n");
78
79 if (IS_ZEBRA_DEBUG_FPM)
80 vty_out(vty, " Zebra FPM debugging is on\n");
81 if (IS_ZEBRA_DEBUG_NHT)
82 vty_out(vty, " Zebra next-hop tracking debugging is on\n");
83 if (IS_ZEBRA_DEBUG_MPLS)
84 vty_out(vty, " Zebra MPLS debugging is on\n");
85
86 return CMD_SUCCESS;
87 }
88
89 DEFUN (debug_zebra_events,
90 debug_zebra_events_cmd,
91 "debug zebra events",
92 DEBUG_STR
93 "Zebra configuration\n"
94 "Debug option set for zebra events\n")
95 {
96 zebra_debug_event = ZEBRA_DEBUG_EVENT;
97 return CMD_WARNING_CONFIG_FAILED;
98 }
99
100 DEFUN (debug_zebra_nht,
101 debug_zebra_nht_cmd,
102 "debug zebra nht",
103 DEBUG_STR
104 "Zebra configuration\n"
105 "Debug option set for zebra next hop tracking\n")
106 {
107 zebra_debug_nht = ZEBRA_DEBUG_NHT;
108 return CMD_WARNING_CONFIG_FAILED;
109 }
110
111 DEFUN (debug_zebra_mpls,
112 debug_zebra_mpls_cmd,
113 "debug zebra mpls",
114 DEBUG_STR
115 "Zebra configuration\n"
116 "Debug option set for zebra MPLS LSPs\n")
117 {
118 zebra_debug_mpls = ZEBRA_DEBUG_MPLS;
119 return CMD_WARNING_CONFIG_FAILED;
120 }
121
122 DEFUN (debug_zebra_vxlan,
123 debug_zebra_vxlan_cmd,
124 "debug zebra vxlan",
125 DEBUG_STR
126 "Zebra configuration\n"
127 "Debug option set for zebra VxLAN (EVPN)\n")
128 {
129 zebra_debug_vxlan = ZEBRA_DEBUG_VXLAN;
130 return CMD_WARNING;
131 }
132
133 DEFUN (debug_zebra_packet,
134 debug_zebra_packet_cmd,
135 "debug zebra packet [<recv|send>] [detail]",
136 DEBUG_STR
137 "Zebra configuration\n"
138 "Debug option set for zebra packet\n"
139 "Debug option set for receive packet\n"
140 "Debug option set for send packet\n"
141 "Debug option set for detailed info\n")
142 {
143 int idx = 0;
144 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
145
146 if (argv_find(argv, argc, "send", &idx))
147 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
148 else if (argv_find(argv, argc, "recv", &idx))
149 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
150 else {
151 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
152 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
153 }
154
155 if (argv_find(argv, argc, "detail", &idx))
156 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL);
157
158 return CMD_SUCCESS;
159 }
160
161 DEFUN (debug_zebra_kernel,
162 debug_zebra_kernel_cmd,
163 "debug zebra kernel",
164 DEBUG_STR
165 "Zebra configuration\n"
166 "Debug option set for zebra between kernel interface\n")
167 {
168 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL);
169
170 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV)
171 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
172
173 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND)
174 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
175
176 return CMD_SUCCESS;
177 }
178
179 DEFUN (debug_zebra_kernel_msgdump,
180 debug_zebra_kernel_msgdump_cmd,
181 "debug zebra kernel msgdump [<recv|send>]",
182 DEBUG_STR
183 "Zebra configuration\n"
184 "Debug option set for zebra between kernel interface\n"
185 "Dump raw netlink messages, sent and received\n"
186 "Dump raw netlink messages received\n"
187 "Dump raw netlink messages sent\n")
188 {
189 int idx = 0;
190
191 if (argv_find(argv, argc, "recv", &idx)) {
192 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
193
194 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND)
195 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
196
197 } else if (argv_find(argv, argc, "send", &idx)) {
198 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
199
200 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV)
201 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
202
203 } else {
204 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
205 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
206 }
207
208 return CMD_SUCCESS;
209 }
210
211 DEFUN (debug_zebra_rib,
212 debug_zebra_rib_cmd,
213 "debug zebra rib [detailed]",
214 DEBUG_STR
215 "Zebra configuration\n"
216 "Debug RIB events\n"
217 "Detailed debugs\n")
218 {
219 int idx = 0;
220 SET_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB);
221
222 if (argv_find(argv, argc, "detailed", &idx))
223 SET_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED);
224
225 return CMD_SUCCESS;
226 }
227
228 DEFUN (debug_zebra_fpm,
229 debug_zebra_fpm_cmd,
230 "debug zebra fpm",
231 DEBUG_STR
232 "Zebra configuration\n"
233 "Debug zebra FPM events\n")
234 {
235 SET_FLAG(zebra_debug_fpm, ZEBRA_DEBUG_FPM);
236 return CMD_SUCCESS;
237 }
238
239 DEFUN (no_debug_zebra_events,
240 no_debug_zebra_events_cmd,
241 "no debug zebra events",
242 NO_STR
243 DEBUG_STR
244 "Zebra configuration\n"
245 "Debug option set for zebra events\n")
246 {
247 zebra_debug_event = 0;
248 return CMD_SUCCESS;
249 }
250
251 DEFUN (no_debug_zebra_nht,
252 no_debug_zebra_nht_cmd,
253 "no debug zebra nht",
254 NO_STR
255 DEBUG_STR
256 "Zebra configuration\n"
257 "Debug option set for zebra next hop tracking\n")
258 {
259 zebra_debug_nht = 0;
260 return CMD_SUCCESS;
261 }
262
263 DEFUN (no_debug_zebra_mpls,
264 no_debug_zebra_mpls_cmd,
265 "no debug zebra mpls",
266 NO_STR
267 DEBUG_STR
268 "Zebra configuration\n"
269 "Debug option set for zebra MPLS LSPs\n")
270 {
271 zebra_debug_mpls = 0;
272 return CMD_SUCCESS;
273 }
274
275 DEFUN (no_debug_zebra_vxlan,
276 no_debug_zebra_vxlan_cmd,
277 "no debug zebra vxlan",
278 NO_STR
279 DEBUG_STR
280 "Zebra configuration\n"
281 "Debug option set for zebra VxLAN (EVPN)\n")
282 {
283 zebra_debug_vxlan = 0;
284 return CMD_SUCCESS;
285 }
286
287 DEFUN (no_debug_zebra_packet,
288 no_debug_zebra_packet_cmd,
289 "no debug zebra packet [<recv|send>] [detail]",
290 NO_STR
291 DEBUG_STR
292 "Zebra configuration\n"
293 "Debug option set for zebra packet\n"
294 "Debug option set for receive packet\n"
295 "Debug option set for send packet\n"
296 "Debug option set for detailed info\n")
297 {
298 zebra_debug_packet = 0;
299 return CMD_SUCCESS;
300 }
301
302 DEFUN (no_debug_zebra_kernel,
303 no_debug_zebra_kernel_cmd,
304 "no debug zebra kernel",
305 NO_STR
306 DEBUG_STR
307 "Zebra configuration\n"
308 "Debug option set for zebra between kernel interface\n")
309 {
310 zebra_debug_kernel = 0;
311 return CMD_SUCCESS;
312 }
313
314 DEFUN (no_debug_zebra_kernel_msgdump,
315 no_debug_zebra_kernel_msgdump_cmd,
316 "no debug zebra kernel msgdump [<recv|send>]",
317 NO_STR
318 DEBUG_STR
319 "Zebra configuration\n"
320 "Debug option set for zebra between kernel interface\n"
321 "Dump raw netlink messages, sent and received\n"
322 "Dump raw netlink messages received\n"
323 "Dump raw netlink messages sent\n")
324 {
325 zebra_debug_kernel = 0;
326 return CMD_SUCCESS;
327 }
328
329 DEFUN (no_debug_zebra_rib,
330 no_debug_zebra_rib_cmd,
331 "no debug zebra rib [detailed]",
332 NO_STR
333 DEBUG_STR
334 "Zebra configuration\n"
335 "Debug zebra RIB\n"
336 "Detailed debugs\n")
337 {
338 zebra_debug_rib = 0;
339 return CMD_SUCCESS;
340 }
341
342 DEFUN (no_debug_zebra_fpm,
343 no_debug_zebra_fpm_cmd,
344 "no debug zebra fpm",
345 NO_STR
346 DEBUG_STR
347 "Zebra configuration\n"
348 "Debug zebra FPM events\n")
349 {
350 zebra_debug_fpm = 0;
351 return CMD_SUCCESS;
352 }
353
354 /* Debug node. */
355 struct cmd_node debug_node = {DEBUG_NODE, "", /* Debug node has no interface. */
356 1};
357
358 static int config_write_debug(struct vty *vty)
359 {
360 int write = 0;
361
362 if (IS_ZEBRA_DEBUG_EVENT) {
363 vty_out(vty, "debug zebra events\n");
364 write++;
365 }
366 if (IS_ZEBRA_DEBUG_PACKET) {
367 if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV) {
368 vty_out(vty, "debug zebra packet%s\n",
369 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "");
370 write++;
371 } else {
372 if (IS_ZEBRA_DEBUG_SEND)
373 vty_out(vty, "debug zebra packet send%s\n",
374 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "");
375 else
376 vty_out(vty, "debug zebra packet recv%s\n",
377 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "");
378 write++;
379 }
380 }
381
382 if (IS_ZEBRA_DEBUG_KERNEL) {
383 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND && IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV) {
384 vty_out(vty, "debug zebra kernel msgdump\n");
385 write++;
386 } else if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV) {
387 vty_out(vty, "debug zebra kernel msgdump recv\n");
388 write++;
389 } else if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND) {
390 vty_out(vty, "debug zebra kernel msgdump send\n");
391 write++;
392 } else {
393 vty_out(vty, "debug zebra kernel\n");
394 write++;
395 }
396 }
397
398 if (CHECK_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED)) {
399 vty_out(vty, "debug zebra rib detailed\n");
400 write++;
401 } else if (CHECK_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB)) {
402 vty_out(vty, "debug zebra rib\n");
403 write++;
404 }
405
406 if (IS_ZEBRA_DEBUG_FPM) {
407 vty_out(vty, "debug zebra fpm\n");
408 write++;
409 }
410 if (IS_ZEBRA_DEBUG_NHT) {
411 vty_out(vty, "debug zebra nht\n");
412 write++;
413 }
414 if (IS_ZEBRA_DEBUG_MPLS) {
415 vty_out(vty, "debug zebra mpls\n");
416 write++;
417 }
418 if (IS_ZEBRA_DEBUG_VXLAN) {
419 vty_out(vty, "debug zebra vxlan\n");
420 write++;
421 }
422 return write;
423 }
424
425 void zebra_debug_init(void)
426 {
427 zebra_debug_event = 0;
428 zebra_debug_packet = 0;
429 zebra_debug_kernel = 0;
430 zebra_debug_rib = 0;
431 zebra_debug_fpm = 0;
432 zebra_debug_mpls = 0;
433 zebra_debug_vxlan = 0;
434
435 install_node(&debug_node, config_write_debug);
436
437 install_element(VIEW_NODE, &show_debugging_zebra_cmd);
438
439 install_element(ENABLE_NODE, &debug_zebra_events_cmd);
440 install_element(ENABLE_NODE, &debug_zebra_nht_cmd);
441 install_element(ENABLE_NODE, &debug_zebra_mpls_cmd);
442 install_element(ENABLE_NODE, &debug_zebra_vxlan_cmd);
443 install_element(ENABLE_NODE, &debug_zebra_packet_cmd);
444 install_element(ENABLE_NODE, &debug_zebra_kernel_cmd);
445 install_element(ENABLE_NODE, &debug_zebra_kernel_msgdump_cmd);
446 install_element(ENABLE_NODE, &debug_zebra_rib_cmd);
447 install_element(ENABLE_NODE, &debug_zebra_fpm_cmd);
448 install_element(ENABLE_NODE, &no_debug_zebra_events_cmd);
449 install_element(ENABLE_NODE, &no_debug_zebra_nht_cmd);
450 install_element(ENABLE_NODE, &no_debug_zebra_mpls_cmd);
451 install_element(ENABLE_NODE, &no_debug_zebra_vxlan_cmd);
452 install_element(ENABLE_NODE, &no_debug_zebra_packet_cmd);
453 install_element(ENABLE_NODE, &no_debug_zebra_kernel_cmd);
454 install_element(ENABLE_NODE, &no_debug_zebra_kernel_msgdump_cmd);
455 install_element(ENABLE_NODE, &no_debug_zebra_rib_cmd);
456 install_element(ENABLE_NODE, &no_debug_zebra_fpm_cmd);
457
458 install_element(CONFIG_NODE, &debug_zebra_events_cmd);
459 install_element(CONFIG_NODE, &debug_zebra_nht_cmd);
460 install_element(CONFIG_NODE, &debug_zebra_mpls_cmd);
461 install_element(CONFIG_NODE, &debug_zebra_vxlan_cmd);
462 install_element(CONFIG_NODE, &debug_zebra_packet_cmd);
463 install_element(CONFIG_NODE, &debug_zebra_kernel_cmd);
464 install_element(CONFIG_NODE, &debug_zebra_kernel_msgdump_cmd);
465 install_element(CONFIG_NODE, &debug_zebra_rib_cmd);
466 install_element(CONFIG_NODE, &debug_zebra_fpm_cmd);
467 install_element(CONFIG_NODE, &no_debug_zebra_events_cmd);
468 install_element(CONFIG_NODE, &no_debug_zebra_nht_cmd);
469 install_element(CONFIG_NODE, &no_debug_zebra_mpls_cmd);
470 install_element(CONFIG_NODE, &no_debug_zebra_vxlan_cmd);
471 install_element(CONFIG_NODE, &no_debug_zebra_packet_cmd);
472 install_element(CONFIG_NODE, &no_debug_zebra_kernel_cmd);
473 install_element(CONFIG_NODE, &no_debug_zebra_kernel_msgdump_cmd);
474 install_element(CONFIG_NODE, &no_debug_zebra_rib_cmd);
475 install_element(CONFIG_NODE, &no_debug_zebra_fpm_cmd);
476 }