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