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