]> git.proxmox.com Git - mirror_frr.git/blob - zebra/debug.c
Merge pull request #468 from qlyoung/fix-list-perm
[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 [<recv|send>] [detail]",
128 DEBUG_STR
129 "Zebra configuration\n"
130 "Debug option set for zebra packet\n"
131 "Debug option set for receive packet\n"
132 "Debug option set for send packet\n"
133 "Debug option set for detailed info\n")
134 {
135 int idx = 0;
136 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
137
138 if (argv_find (argv, argc, "send", &idx))
139 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
140 idx = 0;
141 if (argv_find (argv, argc, "recv", &idx))
142 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
143 idx = 0;
144 if (argv_find (argv, argc, "detail", &idx))
145 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL);
146
147 if (!(zebra_debug_packet & ZEBRA_DEBUG_SEND & ZEBRA_DEBUG_RECV))
148 {
149 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
150 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
151 }
152 return CMD_SUCCESS;
153 }
154
155 DEFUN (debug_zebra_kernel,
156 debug_zebra_kernel_cmd,
157 "debug zebra kernel",
158 DEBUG_STR
159 "Zebra configuration\n"
160 "Debug option set for zebra between kernel interface\n")
161 {
162 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL);
163 return CMD_SUCCESS;
164 }
165
166 DEFUN (debug_zebra_kernel_msgdump,
167 debug_zebra_kernel_msgdump_cmd,
168 "debug zebra kernel msgdump [<recv|send>]",
169 DEBUG_STR
170 "Zebra configuration\n"
171 "Debug option set for zebra between kernel interface\n"
172 "Dump raw netlink messages, sent and received\n"
173 "Dump raw netlink messages received\n"
174 "Dump raw netlink messages sent\n")
175 {
176 int idx = 0;
177 if (argc == 4 || argv_find (argv, argc, "recv", &idx))
178 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
179 if (argc == 4 || argv_find (argv, argc, "send", &idx))
180 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
181
182 return CMD_SUCCESS;
183 }
184
185 DEFUN (debug_zebra_rib,
186 debug_zebra_rib_cmd,
187 "debug zebra rib",
188 DEBUG_STR
189 "Zebra configuration\n"
190 "Debug RIB events\n")
191 {
192 SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB);
193 return CMD_SUCCESS;
194 }
195
196 DEFUN (debug_zebra_rib_detailed,
197 debug_zebra_rib_detailed_cmd,
198 "debug zebra rib detailed",
199 DEBUG_STR
200 "Zebra configuration\n"
201 "Debug RIB events\n"
202 "Detailed debugs\n")
203 {
204 SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED);
205 return CMD_SUCCESS;
206 }
207
208 DEFUN (debug_zebra_fpm,
209 debug_zebra_fpm_cmd,
210 "debug zebra fpm",
211 DEBUG_STR
212 "Zebra configuration\n"
213 "Debug zebra FPM events\n")
214 {
215 SET_FLAG (zebra_debug_fpm, ZEBRA_DEBUG_FPM);
216 return CMD_SUCCESS;
217 }
218
219 DEFUN (no_debug_zebra_events,
220 no_debug_zebra_events_cmd,
221 "no debug zebra events",
222 NO_STR
223 DEBUG_STR
224 "Zebra configuration\n"
225 "Debug option set for zebra events\n")
226 {
227 zebra_debug_event = 0;
228 return CMD_SUCCESS;
229 }
230
231 DEFUN (no_debug_zebra_nht,
232 no_debug_zebra_nht_cmd,
233 "no debug zebra nht",
234 NO_STR
235 DEBUG_STR
236 "Zebra configuration\n"
237 "Debug option set for zebra next hop tracking\n")
238 {
239 zebra_debug_nht = 0;
240 return CMD_SUCCESS;
241 }
242
243 DEFUN (no_debug_zebra_mpls,
244 no_debug_zebra_mpls_cmd,
245 "no debug zebra mpls",
246 NO_STR
247 DEBUG_STR
248 "Zebra configuration\n"
249 "Debug option set for zebra MPLS LSPs\n")
250 {
251 zebra_debug_mpls = 0;
252 return CMD_SUCCESS;
253 }
254
255 DEFUN (no_debug_zebra_packet,
256 no_debug_zebra_packet_cmd,
257 "no debug zebra packet [<recv|send>]",
258 NO_STR
259 DEBUG_STR
260 "Zebra configuration\n"
261 "Debug option set for zebra packet\n"
262 "Debug option set for receive packet\n"
263 "Debug option set for send packet\n")
264 {
265 int idx = 0;
266 if (argc == 4 || argv_find (argv, argc, "send", &idx))
267 UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
268 if (argc == 4 || argv_find (argv, argc, "recv", &idx))
269 UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
270 return CMD_SUCCESS;
271 }
272
273 DEFUN (no_debug_zebra_kernel,
274 no_debug_zebra_kernel_cmd,
275 "no debug zebra kernel",
276 NO_STR
277 DEBUG_STR
278 "Zebra configuration\n"
279 "Debug option set for zebra between kernel interface\n")
280 {
281 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL);
282 return CMD_SUCCESS;
283 }
284
285 DEFUN (no_debug_zebra_kernel_msgdump,
286 no_debug_zebra_kernel_msgdump_cmd,
287 "no debug zebra kernel msgdump [<recv|send>]",
288 NO_STR
289 DEBUG_STR
290 "Zebra configuration\n"
291 "Debug option set for zebra between kernel interface\n"
292 "Dump raw netlink messages, sent and received\n"
293 "Dump raw netlink messages received\n"
294 "Dump raw netlink messages sent\n")
295 {
296 int idx = 0;
297 if (argc == 5 || argv_find (argv, argc, "recv", &idx))
298 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
299 if (argc == 5 || argv_find (argv, argc, "send", &idx))
300 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
301
302 return CMD_SUCCESS;
303 }
304
305 DEFUN (no_debug_zebra_rib,
306 no_debug_zebra_rib_cmd,
307 "no debug zebra rib",
308 NO_STR
309 DEBUG_STR
310 "Zebra configuration\n"
311 "Debug zebra RIB\n")
312 {
313 zebra_debug_rib = 0;
314 return CMD_SUCCESS;
315 }
316
317 DEFUN (no_debug_zebra_rib_detailed,
318 no_debug_zebra_rib_detailed_cmd,
319 "no debug zebra rib detailed",
320 NO_STR
321 DEBUG_STR
322 "Zebra configuration\n"
323 "Debug zebra RIB\n"
324 "Detailed debugs\n")
325 {
326 UNSET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED);
327 return CMD_SUCCESS;
328 }
329
330 DEFUN (no_debug_zebra_fpm,
331 no_debug_zebra_fpm_cmd,
332 "no debug zebra fpm",
333 NO_STR
334 DEBUG_STR
335 "Zebra configuration\n"
336 "Debug zebra FPM events\n")
337 {
338 zebra_debug_fpm = 0;
339 return CMD_SUCCESS;
340 }
341
342 /* Debug node. */
343 struct cmd_node debug_node =
344 {
345 DEBUG_NODE,
346 "", /* Debug node has no interface. */
347 1
348 };
349
350 static int
351 config_write_debug (struct vty *vty)
352 {
353 int write = 0;
354
355 if (IS_ZEBRA_DEBUG_EVENT)
356 {
357 vty_out (vty, "debug zebra events%s", VTY_NEWLINE);
358 write++;
359 }
360 if (IS_ZEBRA_DEBUG_PACKET)
361 {
362 if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV)
363 {
364 vty_out (vty, "debug zebra packet%s%s",
365 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
366 VTY_NEWLINE);
367 write++;
368 }
369 else
370 {
371 if (IS_ZEBRA_DEBUG_SEND)
372 vty_out (vty, "debug zebra packet send%s%s",
373 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
374 VTY_NEWLINE);
375 else
376 vty_out (vty, "debug zebra packet recv%s%s",
377 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
378 VTY_NEWLINE);
379 write++;
380 }
381 }
382 if (IS_ZEBRA_DEBUG_KERNEL)
383 {
384 vty_out (vty, "debug zebra kernel%s", VTY_NEWLINE);
385 write++;
386 }
387 /* Check here using flags as the 'macro' does an OR */
388 if (CHECK_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB))
389 {
390 vty_out (vty, "debug zebra rib%s", VTY_NEWLINE);
391 write++;
392 }
393 if (CHECK_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED))
394 {
395 vty_out (vty, "debug zebra rib detailed%s", VTY_NEWLINE);
396 write++;
397 }
398 if (IS_ZEBRA_DEBUG_FPM)
399 {
400 vty_out (vty, "debug zebra fpm%s", VTY_NEWLINE);
401 write++;
402 }
403 if (IS_ZEBRA_DEBUG_NHT)
404 {
405 vty_out (vty, "debug zebra nht%s", VTY_NEWLINE);
406 write++;
407 }
408 if (IS_ZEBRA_DEBUG_MPLS)
409 {
410 vty_out (vty, "debug zebra mpls%s", VTY_NEWLINE);
411 write++;
412 }
413 return write;
414 }
415
416 void
417 zebra_debug_init (void)
418 {
419 zebra_debug_event = 0;
420 zebra_debug_packet = 0;
421 zebra_debug_kernel = 0;
422 zebra_debug_rib = 0;
423 zebra_debug_fpm = 0;
424 zebra_debug_mpls = 0;
425
426 install_node (&debug_node, config_write_debug);
427
428 install_element (VIEW_NODE, &show_debugging_zebra_cmd);
429
430 install_element (ENABLE_NODE, &debug_zebra_events_cmd);
431 install_element (ENABLE_NODE, &debug_zebra_nht_cmd);
432 install_element (ENABLE_NODE, &debug_zebra_mpls_cmd);
433 install_element (ENABLE_NODE, &debug_zebra_packet_cmd);
434 install_element (ENABLE_NODE, &debug_zebra_kernel_cmd);
435 install_element (ENABLE_NODE, &debug_zebra_kernel_msgdump_cmd);
436 install_element (ENABLE_NODE, &debug_zebra_rib_cmd);
437 install_element (ENABLE_NODE, &debug_zebra_rib_detailed_cmd);
438 install_element (ENABLE_NODE, &debug_zebra_fpm_cmd);
439 install_element (ENABLE_NODE, &no_debug_zebra_events_cmd);
440 install_element (ENABLE_NODE, &no_debug_zebra_nht_cmd);
441 install_element (ENABLE_NODE, &no_debug_zebra_mpls_cmd);
442 install_element (ENABLE_NODE, &no_debug_zebra_packet_cmd);
443 install_element (ENABLE_NODE, &no_debug_zebra_kernel_cmd);
444 install_element (ENABLE_NODE, &no_debug_zebra_kernel_msgdump_cmd);
445 install_element (ENABLE_NODE, &no_debug_zebra_rib_cmd);
446 install_element (ENABLE_NODE, &no_debug_zebra_rib_detailed_cmd);
447 install_element (ENABLE_NODE, &no_debug_zebra_fpm_cmd);
448
449 install_element (CONFIG_NODE, &debug_zebra_events_cmd);
450 install_element (CONFIG_NODE, &debug_zebra_nht_cmd);
451 install_element (CONFIG_NODE, &debug_zebra_mpls_cmd);
452 install_element (CONFIG_NODE, &debug_zebra_packet_cmd);
453 install_element (CONFIG_NODE, &debug_zebra_kernel_cmd);
454 install_element (CONFIG_NODE, &debug_zebra_kernel_msgdump_cmd);
455 install_element (CONFIG_NODE, &debug_zebra_rib_cmd);
456 install_element (CONFIG_NODE, &debug_zebra_rib_detailed_cmd);
457 install_element (CONFIG_NODE, &debug_zebra_fpm_cmd);
458 install_element (CONFIG_NODE, &no_debug_zebra_events_cmd);
459 install_element (CONFIG_NODE, &no_debug_zebra_nht_cmd);
460 install_element (CONFIG_NODE, &no_debug_zebra_mpls_cmd);
461 install_element (CONFIG_NODE, &no_debug_zebra_packet_cmd);
462 install_element (CONFIG_NODE, &no_debug_zebra_kernel_cmd);
463 install_element (CONFIG_NODE, &no_debug_zebra_kernel_msgdump_cmd);
464 install_element (CONFIG_NODE, &no_debug_zebra_rib_cmd);
465 install_element (CONFIG_NODE, &no_debug_zebra_rib_detailed_cmd);
466 install_element (CONFIG_NODE, &no_debug_zebra_fpm_cmd);
467 }