]> git.proxmox.com Git - mirror_frr.git/blame - zebra/debug.c
lib: change comment block to #define to avoid indent.py from breaking comment
[mirror_frr.git] / zebra / debug.c
CommitLineData
718e3744 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 *
896014f4
DL
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
718e3744 20 */
21
22#include <zebra.h>
23#include "command.h"
24#include "debug.h"
25
26/* For debug statement. */
27unsigned long zebra_debug_event;
28unsigned long zebra_debug_packet;
29unsigned long zebra_debug_kernel;
b0498dc6 30unsigned long zebra_debug_rib;
5adc2528 31unsigned long zebra_debug_fpm;
fb018d25 32unsigned long zebra_debug_nht;
7758e3f3 33unsigned long zebra_debug_mpls;
13d60d35 34unsigned long zebra_debug_vxlan;
6833ae01 35unsigned long zebra_debug_pw;
718e3744 36
87f6dc50
DS
37DEFUN_NOSH (show_debugging_zebra,
38 show_debugging_zebra_cmd,
39 "show debugging [zebra]",
40 SHOW_STR
41 "Debugging information\n"
42 "Zebra configuration\n")
718e3744 43{
d62a17ae 44 vty_out(vty, "Zebra debugging status:\n");
45
46 if (IS_ZEBRA_DEBUG_EVENT)
47 vty_out(vty, " Zebra event debugging is on\n");
48
49 if (IS_ZEBRA_DEBUG_PACKET) {
50 if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV) {
51 vty_out(vty, " Zebra packet%s debugging is on\n",
52 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "");
53 } else {
54 if (IS_ZEBRA_DEBUG_SEND)
55 vty_out(vty,
56 " Zebra packet send%s debugging is on\n",
57 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "");
58 else
59 vty_out(vty,
60 " Zebra packet receive%s debugging is on\n",
61 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "");
62 }
718e3744 63 }
d62a17ae 64
65 if (IS_ZEBRA_DEBUG_KERNEL)
66 vty_out(vty, " Zebra kernel debugging is on\n");
67 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND)
68 vty_out(vty,
69 " Zebra kernel netlink message dumps (send) are on\n");
70 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV)
71 vty_out(vty,
72 " Zebra kernel netlink message dumps (recv) are on\n");
73
74 /* Check here using flags as the 'macro' does an OR */
d62a17ae 75 if (CHECK_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED))
76 vty_out(vty, " Zebra RIB detailed debugging is on\n");
ba9d46ff
DW
77 else if (CHECK_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB))
78 vty_out(vty, " Zebra RIB debugging is on\n");
d62a17ae 79
80 if (IS_ZEBRA_DEBUG_FPM)
81 vty_out(vty, " Zebra FPM debugging is on\n");
82 if (IS_ZEBRA_DEBUG_NHT)
83 vty_out(vty, " Zebra next-hop tracking debugging is on\n");
84 if (IS_ZEBRA_DEBUG_MPLS)
85 vty_out(vty, " Zebra MPLS debugging is on\n");
95744ad8
DS
86 if (IS_ZEBRA_DEBUG_VXLAN)
87 vty_out(vty, " Zebra VXLAN debugging is on\n");
6833ae01 88 if (IS_ZEBRA_DEBUG_PW)
89 vty_out(vty, " Zebra pseudowire debugging is on\n");
d62a17ae 90
91 return CMD_SUCCESS;
718e3744 92}
93
94DEFUN (debug_zebra_events,
95 debug_zebra_events_cmd,
96 "debug zebra events",
97 DEBUG_STR
98 "Zebra configuration\n"
99 "Debug option set for zebra events\n")
100{
d62a17ae 101 zebra_debug_event = ZEBRA_DEBUG_EVENT;
8527ce3a 102 return CMD_SUCCESS;
718e3744 103}
104
fb018d25
DS
105DEFUN (debug_zebra_nht,
106 debug_zebra_nht_cmd,
107 "debug zebra nht",
108 DEBUG_STR
109 "Zebra configuration\n"
110 "Debug option set for zebra next hop tracking\n")
111{
d62a17ae 112 zebra_debug_nht = ZEBRA_DEBUG_NHT;
8527ce3a 113 return CMD_SUCCESS;
fb018d25
DS
114}
115
7758e3f3 116DEFUN (debug_zebra_mpls,
117 debug_zebra_mpls_cmd,
118 "debug zebra mpls",
119 DEBUG_STR
120 "Zebra configuration\n"
121 "Debug option set for zebra MPLS LSPs\n")
122{
d62a17ae 123 zebra_debug_mpls = ZEBRA_DEBUG_MPLS;
8527ce3a 124 return CMD_SUCCESS;
7758e3f3 125}
126
13d60d35 127DEFUN (debug_zebra_vxlan,
128 debug_zebra_vxlan_cmd,
129 "debug zebra vxlan",
130 DEBUG_STR
131 "Zebra configuration\n"
132 "Debug option set for zebra VxLAN (EVPN)\n")
133{
d62a17ae 134 zebra_debug_vxlan = ZEBRA_DEBUG_VXLAN;
8527ce3a 135 return CMD_SUCCESS;
13d60d35 136}
137
6833ae01 138DEFUN (debug_zebra_pw,
139 debug_zebra_pw_cmd,
140 "[no] debug zebra pseudowires",
efd7904e 141 NO_STR
6833ae01 142 DEBUG_STR
143 "Zebra configuration\n"
144 "Debug option set for zebra pseudowires\n")
145{
146 if (strmatch(argv[0]->text, "no"))
147 UNSET_FLAG(zebra_debug_pw, ZEBRA_DEBUG_PW);
148 else
149 SET_FLAG(zebra_debug_pw, ZEBRA_DEBUG_PW);
8527ce3a 150 return CMD_SUCCESS;
6833ae01 151}
152
718e3744 153DEFUN (debug_zebra_packet,
154 debug_zebra_packet_cmd,
16cedbb0 155 "debug zebra packet [<recv|send>] [detail]",
718e3744 156 DEBUG_STR
157 "Zebra configuration\n"
158 "Debug option set for zebra packet\n"
159 "Debug option set for receive packet\n"
16cedbb0
QY
160 "Debug option set for send packet\n"
161 "Debug option set for detailed info\n")
718e3744 162{
d62a17ae 163 int idx = 0;
164 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
165
166 if (argv_find(argv, argc, "send", &idx))
167 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
ba9d46ff 168 else if (argv_find(argv, argc, "recv", &idx))
d62a17ae 169 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
ba9d46ff 170 else {
d62a17ae 171 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
172 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
173 }
ba9d46ff
DW
174
175 if (argv_find(argv, argc, "detail", &idx))
176 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL);
177
d62a17ae 178 return CMD_SUCCESS;
718e3744 179}
180
181DEFUN (debug_zebra_kernel,
182 debug_zebra_kernel_cmd,
183 "debug zebra kernel",
184 DEBUG_STR
185 "Zebra configuration\n"
186 "Debug option set for zebra between kernel interface\n")
187{
d62a17ae 188 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL);
ba9d46ff
DW
189
190 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV)
191 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
192
193 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND)
194 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
195
d62a17ae 196 return CMD_SUCCESS;
556b904e
QY
197}
198
199DEFUN (debug_zebra_kernel_msgdump,
200 debug_zebra_kernel_msgdump_cmd,
6de69f83 201 "debug zebra kernel msgdump [<recv|send>]",
556b904e
QY
202 DEBUG_STR
203 "Zebra configuration\n"
204 "Debug option set for zebra between kernel interface\n"
205 "Dump raw netlink messages, sent and received\n"
206 "Dump raw netlink messages received\n"
207 "Dump raw netlink messages sent\n")
208{
d62a17ae 209 int idx = 0;
ba9d46ff
DW
210
211 if (argv_find(argv, argc, "recv", &idx)) {
d62a17ae 212 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
ba9d46ff
DW
213
214 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND)
215 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
216
217 } else if (argv_find(argv, argc, "send", &idx)) {
d62a17ae 218 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
313605cb 219
ba9d46ff
DW
220 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV)
221 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
222
223 } else {
224 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
225 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
226 }
227
d62a17ae 228 return CMD_SUCCESS;
718e3744 229}
230
b0498dc6
PJ
231DEFUN (debug_zebra_rib,
232 debug_zebra_rib_cmd,
ba9d46ff 233 "debug zebra rib [detailed]",
b0498dc6
PJ
234 DEBUG_STR
235 "Zebra configuration\n"
236 "Debug RIB events\n"
41ec9222 237 "Detailed debugs\n")
b0498dc6 238{
ba9d46ff
DW
239 int idx = 0;
240 SET_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB);
241
242 if (argv_find(argv, argc, "detailed", &idx))
243 SET_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED);
244
d62a17ae 245 return CMD_SUCCESS;
b0498dc6
PJ
246}
247
5adc2528
AS
248DEFUN (debug_zebra_fpm,
249 debug_zebra_fpm_cmd,
250 "debug zebra fpm",
251 DEBUG_STR
252 "Zebra configuration\n"
253 "Debug zebra FPM events\n")
254{
d62a17ae 255 SET_FLAG(zebra_debug_fpm, ZEBRA_DEBUG_FPM);
256 return CMD_SUCCESS;
5adc2528
AS
257}
258
718e3744 259DEFUN (no_debug_zebra_events,
260 no_debug_zebra_events_cmd,
261 "no debug zebra events",
262 NO_STR
263 DEBUG_STR
264 "Zebra configuration\n"
265 "Debug option set for zebra events\n")
266{
d62a17ae 267 zebra_debug_event = 0;
268 return CMD_SUCCESS;
718e3744 269}
270
fb018d25
DS
271DEFUN (no_debug_zebra_nht,
272 no_debug_zebra_nht_cmd,
273 "no debug zebra nht",
274 NO_STR
275 DEBUG_STR
276 "Zebra configuration\n"
277 "Debug option set for zebra next hop tracking\n")
278{
d62a17ae 279 zebra_debug_nht = 0;
280 return CMD_SUCCESS;
fb018d25
DS
281}
282
7758e3f3 283DEFUN (no_debug_zebra_mpls,
284 no_debug_zebra_mpls_cmd,
285 "no debug zebra mpls",
286 NO_STR
287 DEBUG_STR
288 "Zebra configuration\n"
289 "Debug option set for zebra MPLS LSPs\n")
290{
d62a17ae 291 zebra_debug_mpls = 0;
292 return CMD_SUCCESS;
7758e3f3 293}
294
13d60d35 295DEFUN (no_debug_zebra_vxlan,
296 no_debug_zebra_vxlan_cmd,
297 "no debug zebra vxlan",
298 NO_STR
299 DEBUG_STR
300 "Zebra configuration\n"
301 "Debug option set for zebra VxLAN (EVPN)\n")
302{
d62a17ae 303 zebra_debug_vxlan = 0;
304 return CMD_SUCCESS;
13d60d35 305}
306
718e3744 307DEFUN (no_debug_zebra_packet,
308 no_debug_zebra_packet_cmd,
ba9d46ff 309 "no debug zebra packet [<recv|send>] [detail]",
718e3744 310 NO_STR
311 DEBUG_STR
312 "Zebra configuration\n"
313 "Debug option set for zebra packet\n"
314 "Debug option set for receive packet\n"
ba9d46ff
DW
315 "Debug option set for send packet\n"
316 "Debug option set for detailed info\n")
718e3744 317{
ba9d46ff 318 zebra_debug_packet = 0;
d62a17ae 319 return CMD_SUCCESS;
718e3744 320}
321
322DEFUN (no_debug_zebra_kernel,
323 no_debug_zebra_kernel_cmd,
324 "no debug zebra kernel",
325 NO_STR
326 DEBUG_STR
327 "Zebra configuration\n"
328 "Debug option set for zebra between kernel interface\n")
329{
ba9d46ff 330 zebra_debug_kernel = 0;
d62a17ae 331 return CMD_SUCCESS;
556b904e
QY
332}
333
334DEFUN (no_debug_zebra_kernel_msgdump,
335 no_debug_zebra_kernel_msgdump_cmd,
6de69f83 336 "no debug zebra kernel msgdump [<recv|send>]",
16cedbb0 337 NO_STR
556b904e
QY
338 DEBUG_STR
339 "Zebra configuration\n"
340 "Debug option set for zebra between kernel interface\n"
341 "Dump raw netlink messages, sent and received\n"
342 "Dump raw netlink messages received\n"
343 "Dump raw netlink messages sent\n")
344{
ba9d46ff 345 zebra_debug_kernel = 0;
d62a17ae 346 return CMD_SUCCESS;
718e3744 347}
348
b0498dc6
PJ
349DEFUN (no_debug_zebra_rib,
350 no_debug_zebra_rib_cmd,
ba9d46ff 351 "no debug zebra rib [detailed]",
b0498dc6
PJ
352 NO_STR
353 DEBUG_STR
354 "Zebra configuration\n"
355 "Debug zebra RIB\n"
41ec9222 356 "Detailed debugs\n")
b0498dc6 357{
ba9d46ff 358 zebra_debug_rib = 0;
d62a17ae 359 return CMD_SUCCESS;
b0498dc6
PJ
360}
361
5adc2528
AS
362DEFUN (no_debug_zebra_fpm,
363 no_debug_zebra_fpm_cmd,
364 "no debug zebra fpm",
365 NO_STR
366 DEBUG_STR
367 "Zebra configuration\n"
368 "Debug zebra FPM events\n")
369{
d62a17ae 370 zebra_debug_fpm = 0;
371 return CMD_SUCCESS;
5adc2528
AS
372}
373
718e3744 374/* Debug node. */
d62a17ae 375struct cmd_node debug_node = {DEBUG_NODE, "", /* Debug node has no interface. */
376 1};
718e3744 377
d62a17ae 378static int config_write_debug(struct vty *vty)
718e3744 379{
d62a17ae 380 int write = 0;
381
382 if (IS_ZEBRA_DEBUG_EVENT) {
383 vty_out(vty, "debug zebra events\n");
384 write++;
385 }
386 if (IS_ZEBRA_DEBUG_PACKET) {
387 if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV) {
388 vty_out(vty, "debug zebra packet%s\n",
389 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "");
390 write++;
391 } else {
392 if (IS_ZEBRA_DEBUG_SEND)
393 vty_out(vty, "debug zebra packet send%s\n",
394 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "");
395 else
396 vty_out(vty, "debug zebra packet recv%s\n",
397 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "");
398 write++;
399 }
400 }
ba9d46ff 401
d62a17ae 402 if (IS_ZEBRA_DEBUG_KERNEL) {
ba9d46ff
DW
403 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND && IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV) {
404 vty_out(vty, "debug zebra kernel msgdump\n");
405 write++;
406 } else if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV) {
407 vty_out(vty, "debug zebra kernel msgdump recv\n");
408 write++;
409 } else if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND) {
410 vty_out(vty, "debug zebra kernel msgdump send\n");
411 write++;
412 } else {
413 vty_out(vty, "debug zebra kernel\n");
414 write++;
415 }
d62a17ae 416 }
ba9d46ff 417
d62a17ae 418 if (CHECK_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED)) {
419 vty_out(vty, "debug zebra rib detailed\n");
420 write++;
ba9d46ff
DW
421 } else if (CHECK_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB)) {
422 vty_out(vty, "debug zebra rib\n");
423 write++;
d62a17ae 424 }
ba9d46ff 425
d62a17ae 426 if (IS_ZEBRA_DEBUG_FPM) {
427 vty_out(vty, "debug zebra fpm\n");
428 write++;
429 }
430 if (IS_ZEBRA_DEBUG_NHT) {
431 vty_out(vty, "debug zebra nht\n");
432 write++;
433 }
434 if (IS_ZEBRA_DEBUG_MPLS) {
435 vty_out(vty, "debug zebra mpls\n");
436 write++;
718e3744 437 }
d62a17ae 438 if (IS_ZEBRA_DEBUG_VXLAN) {
439 vty_out(vty, "debug zebra vxlan\n");
440 write++;
718e3744 441 }
6833ae01 442 if (IS_ZEBRA_DEBUG_PW) {
69965f53 443 vty_out(vty, "debug zebra pseudowires\n");
6833ae01 444 write++;
445 }
d62a17ae 446 return write;
718e3744 447}
448
d62a17ae 449void zebra_debug_init(void)
718e3744 450{
d62a17ae 451 zebra_debug_event = 0;
452 zebra_debug_packet = 0;
453 zebra_debug_kernel = 0;
454 zebra_debug_rib = 0;
455 zebra_debug_fpm = 0;
456 zebra_debug_mpls = 0;
457 zebra_debug_vxlan = 0;
6833ae01 458 zebra_debug_pw = 0;
d62a17ae 459
460 install_node(&debug_node, config_write_debug);
461
462 install_element(VIEW_NODE, &show_debugging_zebra_cmd);
463
464 install_element(ENABLE_NODE, &debug_zebra_events_cmd);
465 install_element(ENABLE_NODE, &debug_zebra_nht_cmd);
466 install_element(ENABLE_NODE, &debug_zebra_mpls_cmd);
467 install_element(ENABLE_NODE, &debug_zebra_vxlan_cmd);
6833ae01 468 install_element(ENABLE_NODE, &debug_zebra_pw_cmd);
d62a17ae 469 install_element(ENABLE_NODE, &debug_zebra_packet_cmd);
470 install_element(ENABLE_NODE, &debug_zebra_kernel_cmd);
471 install_element(ENABLE_NODE, &debug_zebra_kernel_msgdump_cmd);
472 install_element(ENABLE_NODE, &debug_zebra_rib_cmd);
d62a17ae 473 install_element(ENABLE_NODE, &debug_zebra_fpm_cmd);
474 install_element(ENABLE_NODE, &no_debug_zebra_events_cmd);
475 install_element(ENABLE_NODE, &no_debug_zebra_nht_cmd);
476 install_element(ENABLE_NODE, &no_debug_zebra_mpls_cmd);
477 install_element(ENABLE_NODE, &no_debug_zebra_vxlan_cmd);
478 install_element(ENABLE_NODE, &no_debug_zebra_packet_cmd);
479 install_element(ENABLE_NODE, &no_debug_zebra_kernel_cmd);
480 install_element(ENABLE_NODE, &no_debug_zebra_kernel_msgdump_cmd);
481 install_element(ENABLE_NODE, &no_debug_zebra_rib_cmd);
d62a17ae 482 install_element(ENABLE_NODE, &no_debug_zebra_fpm_cmd);
483
484 install_element(CONFIG_NODE, &debug_zebra_events_cmd);
485 install_element(CONFIG_NODE, &debug_zebra_nht_cmd);
486 install_element(CONFIG_NODE, &debug_zebra_mpls_cmd);
487 install_element(CONFIG_NODE, &debug_zebra_vxlan_cmd);
6833ae01 488 install_element(CONFIG_NODE, &debug_zebra_pw_cmd);
d62a17ae 489 install_element(CONFIG_NODE, &debug_zebra_packet_cmd);
490 install_element(CONFIG_NODE, &debug_zebra_kernel_cmd);
491 install_element(CONFIG_NODE, &debug_zebra_kernel_msgdump_cmd);
492 install_element(CONFIG_NODE, &debug_zebra_rib_cmd);
d62a17ae 493 install_element(CONFIG_NODE, &debug_zebra_fpm_cmd);
494 install_element(CONFIG_NODE, &no_debug_zebra_events_cmd);
495 install_element(CONFIG_NODE, &no_debug_zebra_nht_cmd);
496 install_element(CONFIG_NODE, &no_debug_zebra_mpls_cmd);
497 install_element(CONFIG_NODE, &no_debug_zebra_vxlan_cmd);
498 install_element(CONFIG_NODE, &no_debug_zebra_packet_cmd);
499 install_element(CONFIG_NODE, &no_debug_zebra_kernel_cmd);
500 install_element(CONFIG_NODE, &no_debug_zebra_kernel_msgdump_cmd);
501 install_element(CONFIG_NODE, &no_debug_zebra_rib_cmd);
d62a17ae 502 install_element(CONFIG_NODE, &no_debug_zebra_fpm_cmd);
718e3744 503}