]> git.proxmox.com Git - mirror_frr.git/blob - zebra/debug.c
Merge remote-tracking branch 'origin/cmaster' into cmaster-next
[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
18 * along with GNU Zebra; see the file COPYING. If not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23 #include <zebra.h>
24 #include "command.h"
25 #include "debug.h"
26
27 /* For debug statement. */
28 unsigned long zebra_debug_event;
29 unsigned long zebra_debug_packet;
30 unsigned long zebra_debug_kernel;
31 unsigned long zebra_debug_rib;
32 unsigned long zebra_debug_fpm;
33 unsigned long zebra_debug_nht;
34 unsigned long zebra_debug_mpls;
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:%s", VTY_NEWLINE);
44
45 if (IS_ZEBRA_DEBUG_EVENT)
46 vty_out (vty, " Zebra event debugging is on%s", VTY_NEWLINE);
47
48 if (IS_ZEBRA_DEBUG_PACKET)
49 {
50 if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV)
51 {
52 vty_out (vty, " Zebra packet%s debugging is on%s",
53 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
54 VTY_NEWLINE);
55 }
56 else
57 {
58 if (IS_ZEBRA_DEBUG_SEND)
59 vty_out (vty, " Zebra packet send%s debugging is on%s",
60 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
61 VTY_NEWLINE);
62 else
63 vty_out (vty, " Zebra packet receive%s debugging is on%s",
64 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
65 VTY_NEWLINE);
66 }
67 }
68
69 if (IS_ZEBRA_DEBUG_KERNEL)
70 vty_out (vty, " Zebra kernel debugging is on%s", VTY_NEWLINE);
71 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND)
72 vty_out (vty, " Zebra kernel netlink message dumps (send) are on%s", VTY_NEWLINE);
73 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV)
74 vty_out (vty, " Zebra kernel netlink message dumps (recv) are on%s", VTY_NEWLINE);
75
76 /* Check here using flags as the 'macro' does an OR */
77 if (CHECK_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB))
78 vty_out (vty, " Zebra RIB debugging is on%s", VTY_NEWLINE);
79 if (CHECK_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED))
80 vty_out (vty, " Zebra RIB detailed debugging is on%s", VTY_NEWLINE);
81
82 if (IS_ZEBRA_DEBUG_FPM)
83 vty_out (vty, " Zebra FPM debugging is on%s", VTY_NEWLINE);
84 if (IS_ZEBRA_DEBUG_NHT)
85 vty_out (vty, " Zebra next-hop tracking debugging is on%s", VTY_NEWLINE);
86 if (IS_ZEBRA_DEBUG_MPLS)
87 vty_out (vty, " Zebra MPLS debugging is on%s", VTY_NEWLINE);
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;
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;
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;
123 }
124
125 DEFUN (debug_zebra_packet,
126 debug_zebra_packet_cmd,
127 "debug zebra packet",
128 DEBUG_STR
129 "Zebra configuration\n"
130 "Debug option set for zebra packet\n")
131 {
132 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
133 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
134 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
135 return CMD_SUCCESS;
136 }
137
138 DEFUN (debug_zebra_packet_direct,
139 debug_zebra_packet_direct_cmd,
140 "debug zebra packet (recv|send|detail)",
141 DEBUG_STR
142 "Zebra configuration\n"
143 "Debug option set for zebra packet\n"
144 "Debug option set for receive packet\n"
145 "Debug option set for send packet\n")
146 {
147 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
148 if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
149 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
150 if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
151 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
152 if (strncmp ("detail", argv[0], strlen (argv[0])) == 0)
153 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL);
154 return CMD_SUCCESS;
155 }
156
157 DEFUN (debug_zebra_packet_detail,
158 debug_zebra_packet_detail_cmd,
159 "debug zebra packet (recv|send) detail",
160 DEBUG_STR
161 "Zebra configuration\n"
162 "Debug option set for zebra packet\n"
163 "Debug option set for receive packet\n"
164 "Debug option set for send packet\n"
165 "Debug option set detailed information\n")
166 {
167 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
168 if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
169 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
170 if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
171 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
172 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL);
173 return CMD_SUCCESS;
174 }
175
176 DEFUN (debug_zebra_kernel,
177 debug_zebra_kernel_cmd,
178 "debug zebra kernel",
179 DEBUG_STR
180 "Zebra configuration\n"
181 "Debug option set for zebra between kernel interface\n")
182 {
183 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL);
184 return CMD_SUCCESS;
185 }
186
187 DEFUN (debug_zebra_kernel_msgdump,
188 debug_zebra_kernel_msgdump_cmd,
189 "debug zebra kernel msgdump {recv|send}",
190 DEBUG_STR
191 "Zebra configuration\n"
192 "Debug option set for zebra between kernel interface\n"
193 "Dump raw netlink messages, sent and received\n"
194 "Dump raw netlink messages received\n"
195 "Dump raw netlink messages sent\n")
196 {
197 if (!argv[1] || (argv[0] && strncmp(argv[0], "recv", strlen(argv[0])) == 0))
198 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
199 if (!argv[0] || (argv[1] && strncmp(argv[1], "send", strlen(argv[1])) == 0))
200 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
201 return CMD_SUCCESS;
202 }
203
204 DEFUN (debug_zebra_rib,
205 debug_zebra_rib_cmd,
206 "debug zebra rib",
207 DEBUG_STR
208 "Zebra configuration\n"
209 "Debug RIB events\n")
210 {
211 SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB);
212 return CMD_SUCCESS;
213 }
214
215 DEFUN (debug_zebra_rib_detailed,
216 debug_zebra_rib_detailed_cmd,
217 "debug zebra rib detailed",
218 DEBUG_STR
219 "Zebra configuration\n"
220 "Debug RIB events\n"
221 "Detailed debugs\n")
222 {
223 SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED);
224 return CMD_SUCCESS;
225 }
226
227 DEFUN (debug_zebra_fpm,
228 debug_zebra_fpm_cmd,
229 "debug zebra fpm",
230 DEBUG_STR
231 "Zebra configuration\n"
232 "Debug zebra FPM events\n")
233 {
234 SET_FLAG (zebra_debug_fpm, ZEBRA_DEBUG_FPM);
235 return CMD_SUCCESS;
236 }
237
238 DEFUN (no_debug_zebra_events,
239 no_debug_zebra_events_cmd,
240 "no debug zebra events",
241 NO_STR
242 DEBUG_STR
243 "Zebra configuration\n"
244 "Debug option set for zebra events\n")
245 {
246 zebra_debug_event = 0;
247 return CMD_SUCCESS;
248 }
249
250 DEFUN (no_debug_zebra_nht,
251 no_debug_zebra_nht_cmd,
252 "no debug zebra nht",
253 NO_STR
254 DEBUG_STR
255 "Zebra configuration\n"
256 "Debug option set for zebra next hop tracking\n")
257 {
258 zebra_debug_nht = 0;
259 return CMD_SUCCESS;
260 }
261
262 DEFUN (no_debug_zebra_mpls,
263 no_debug_zebra_mpls_cmd,
264 "no debug zebra mpls",
265 NO_STR
266 DEBUG_STR
267 "Zebra configuration\n"
268 "Debug option set for zebra MPLS LSPs\n")
269 {
270 zebra_debug_mpls = 0;
271 return CMD_SUCCESS;
272 }
273
274 DEFUN (no_debug_zebra_packet,
275 no_debug_zebra_packet_cmd,
276 "no debug zebra packet",
277 NO_STR
278 DEBUG_STR
279 "Zebra configuration\n"
280 "Debug option set for zebra packet\n")
281 {
282 zebra_debug_packet = 0;
283 return CMD_SUCCESS;
284 }
285
286 DEFUN (no_debug_zebra_packet_direct,
287 no_debug_zebra_packet_direct_cmd,
288 "no debug zebra packet (recv|send)",
289 NO_STR
290 DEBUG_STR
291 "Zebra configuration\n"
292 "Debug option set for zebra packet\n"
293 "Debug option set for receive packet\n"
294 "Debug option set for send packet\n")
295 {
296 if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
297 UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
298 if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
299 UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
300 return CMD_SUCCESS;
301 }
302
303 DEFUN (no_debug_zebra_kernel,
304 no_debug_zebra_kernel_cmd,
305 "no debug zebra kernel",
306 NO_STR
307 DEBUG_STR
308 "Zebra configuration\n"
309 "Debug option set for zebra between kernel interface\n")
310 {
311 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL);
312 return CMD_SUCCESS;
313 }
314
315 DEFUN (no_debug_zebra_kernel_msgdump,
316 no_debug_zebra_kernel_msgdump_cmd,
317 "no debug zebra kernel msgdump {recv|send}",
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 if (!argv[1] || (argv[0] && strncmp(argv[0], "recv", strlen(argv[0])) == 0))
326 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
327 if (!argv[0] || (argv[1] && strncmp(argv[1], "send", strlen(argv[1])) == 0))
328 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
329 return CMD_SUCCESS;
330 }
331
332 DEFUN (no_debug_zebra_rib,
333 no_debug_zebra_rib_cmd,
334 "no debug zebra rib",
335 NO_STR
336 DEBUG_STR
337 "Zebra configuration\n"
338 "Debug zebra RIB\n")
339 {
340 zebra_debug_rib = 0;
341 return CMD_SUCCESS;
342 }
343
344 DEFUN (no_debug_zebra_rib_detailed,
345 no_debug_zebra_rib_detailed_cmd,
346 "no debug zebra rib detailed",
347 NO_STR
348 DEBUG_STR
349 "Zebra configuration\n"
350 "Debug zebra RIB\n"
351 "Detailed debugs\n")
352 {
353 UNSET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED);
354 return CMD_SUCCESS;
355 }
356
357 DEFUN (no_debug_zebra_fpm,
358 no_debug_zebra_fpm_cmd,
359 "no debug zebra fpm",
360 NO_STR
361 DEBUG_STR
362 "Zebra configuration\n"
363 "Debug zebra FPM events\n")
364 {
365 zebra_debug_fpm = 0;
366 return CMD_SUCCESS;
367 }
368
369 /* Debug node. */
370 struct cmd_node debug_node =
371 {
372 DEBUG_NODE,
373 "", /* Debug node has no interface. */
374 1
375 };
376
377 static int
378 config_write_debug (struct vty *vty)
379 {
380 int write = 0;
381
382 if (IS_ZEBRA_DEBUG_EVENT)
383 {
384 vty_out (vty, "debug zebra events%s", VTY_NEWLINE);
385 write++;
386 }
387 if (IS_ZEBRA_DEBUG_PACKET)
388 {
389 if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV)
390 {
391 vty_out (vty, "debug zebra packet%s%s",
392 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
393 VTY_NEWLINE);
394 write++;
395 }
396 else
397 {
398 if (IS_ZEBRA_DEBUG_SEND)
399 vty_out (vty, "debug zebra packet send%s%s",
400 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
401 VTY_NEWLINE);
402 else
403 vty_out (vty, "debug zebra packet recv%s%s",
404 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
405 VTY_NEWLINE);
406 write++;
407 }
408 }
409 if (IS_ZEBRA_DEBUG_KERNEL)
410 {
411 vty_out (vty, "debug zebra kernel%s", VTY_NEWLINE);
412 write++;
413 }
414 /* Check here using flags as the 'macro' does an OR */
415 if (CHECK_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB))
416 {
417 vty_out (vty, "debug zebra rib%s", VTY_NEWLINE);
418 write++;
419 }
420 if (CHECK_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED))
421 {
422 vty_out (vty, "debug zebra rib detailed%s", VTY_NEWLINE);
423 write++;
424 }
425 if (IS_ZEBRA_DEBUG_FPM)
426 {
427 vty_out (vty, "debug zebra fpm%s", VTY_NEWLINE);
428 write++;
429 }
430 if (IS_ZEBRA_DEBUG_MPLS)
431 {
432 vty_out (vty, "debug zebra mpls%s", VTY_NEWLINE);
433 write++;
434 }
435 return write;
436 }
437
438 void
439 zebra_debug_init (void)
440 {
441 zebra_debug_event = 0;
442 zebra_debug_packet = 0;
443 zebra_debug_kernel = 0;
444 zebra_debug_rib = 0;
445 zebra_debug_fpm = 0;
446 zebra_debug_mpls = 0;
447
448 install_node (&debug_node, config_write_debug);
449
450 install_element (VIEW_NODE, &show_debugging_zebra_cmd);
451
452 install_element (ENABLE_NODE, &debug_zebra_events_cmd);
453 install_element (ENABLE_NODE, &debug_zebra_nht_cmd);
454 install_element (ENABLE_NODE, &debug_zebra_mpls_cmd);
455 install_element (ENABLE_NODE, &debug_zebra_packet_cmd);
456 install_element (ENABLE_NODE, &debug_zebra_packet_direct_cmd);
457 install_element (ENABLE_NODE, &debug_zebra_packet_detail_cmd);
458 install_element (ENABLE_NODE, &debug_zebra_kernel_cmd);
459 install_element (ENABLE_NODE, &debug_zebra_kernel_msgdump_cmd);
460 install_element (ENABLE_NODE, &debug_zebra_rib_cmd);
461 install_element (ENABLE_NODE, &debug_zebra_rib_detailed_cmd);
462 install_element (ENABLE_NODE, &debug_zebra_fpm_cmd);
463 install_element (ENABLE_NODE, &no_debug_zebra_events_cmd);
464 install_element (ENABLE_NODE, &no_debug_zebra_nht_cmd);
465 install_element (ENABLE_NODE, &no_debug_zebra_mpls_cmd);
466 install_element (ENABLE_NODE, &no_debug_zebra_packet_cmd);
467 install_element (ENABLE_NODE, &no_debug_zebra_kernel_cmd);
468 install_element (ENABLE_NODE, &no_debug_zebra_kernel_msgdump_cmd);
469 install_element (ENABLE_NODE, &no_debug_zebra_rib_cmd);
470 install_element (ENABLE_NODE, &no_debug_zebra_rib_detailed_cmd);
471 install_element (ENABLE_NODE, &no_debug_zebra_fpm_cmd);
472
473 install_element (CONFIG_NODE, &debug_zebra_events_cmd);
474 install_element (CONFIG_NODE, &debug_zebra_nht_cmd);
475 install_element (CONFIG_NODE, &debug_zebra_mpls_cmd);
476 install_element (CONFIG_NODE, &debug_zebra_packet_cmd);
477 install_element (CONFIG_NODE, &debug_zebra_packet_direct_cmd);
478 install_element (CONFIG_NODE, &debug_zebra_packet_detail_cmd);
479 install_element (CONFIG_NODE, &debug_zebra_kernel_cmd);
480 install_element (CONFIG_NODE, &debug_zebra_kernel_msgdump_cmd);
481 install_element (CONFIG_NODE, &debug_zebra_rib_cmd);
482 install_element (CONFIG_NODE, &debug_zebra_rib_detailed_cmd);
483 install_element (CONFIG_NODE, &debug_zebra_fpm_cmd);
484 install_element (CONFIG_NODE, &no_debug_zebra_events_cmd);
485 install_element (CONFIG_NODE, &no_debug_zebra_nht_cmd);
486 install_element (CONFIG_NODE, &no_debug_zebra_mpls_cmd);
487 install_element (CONFIG_NODE, &no_debug_zebra_packet_cmd);
488 install_element (CONFIG_NODE, &no_debug_zebra_kernel_cmd);
489 install_element (CONFIG_NODE, &no_debug_zebra_kernel_msgdump_cmd);
490 install_element (CONFIG_NODE, &no_debug_zebra_rib_cmd);
491 install_element (CONFIG_NODE, &no_debug_zebra_rib_detailed_cmd);
492 install_element (CONFIG_NODE, &no_debug_zebra_fpm_cmd);
493 }