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