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