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