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