]> git.proxmox.com Git - mirror_frr.git/blame - zebra/debug.c
Use only the ISC license for .proto files.
[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 *
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. */
28unsigned long zebra_debug_event;
29unsigned long zebra_debug_packet;
30unsigned long zebra_debug_kernel;
b0498dc6 31unsigned long zebra_debug_rib;
5adc2528 32unsigned long zebra_debug_fpm;
fb018d25 33unsigned long zebra_debug_nht;
7758e3f3 34unsigned long zebra_debug_mpls;
718e3744 35
36DEFUN (show_debugging_zebra,
37 show_debugging_zebra_cmd,
38 "show debugging zebra",
39 SHOW_STR
2b00515a
CF
40 "Debugging information\n"
41 "Zebra configuration\n")
718e3744 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);
556b904e
QY
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);
718e3744 75
41ec9222 76 /* Check here using flags as the 'macro' does an OR */
77 if (CHECK_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB))
b0498dc6 78 vty_out (vty, " Zebra RIB debugging is on%s", VTY_NEWLINE);
41ec9222 79 if (CHECK_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED))
80 vty_out (vty, " Zebra RIB detailed debugging is on%s", VTY_NEWLINE);
b0498dc6 81
5adc2528
AS
82 if (IS_ZEBRA_DEBUG_FPM)
83 vty_out (vty, " Zebra FPM debugging is on%s", VTY_NEWLINE);
fb018d25
DS
84 if (IS_ZEBRA_DEBUG_NHT)
85 vty_out (vty, " Zebra next-hop tracking debugging is on%s", VTY_NEWLINE);
7758e3f3 86 if (IS_ZEBRA_DEBUG_MPLS)
87 vty_out (vty, " Zebra MPLS debugging is on%s", VTY_NEWLINE);
5adc2528 88
718e3744 89 return CMD_SUCCESS;
90}
91
92DEFUN (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
fb018d25
DS
103DEFUN (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
7758e3f3 114DEFUN (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
718e3744 125DEFUN (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;
0d72b344
QY
133 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
134 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
718e3744 135 return CMD_SUCCESS;
136}
137
138DEFUN (debug_zebra_packet_direct,
139 debug_zebra_packet_direct_cmd,
54f03be9 140 "debug zebra packet (recv|send|detail)",
718e3744 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)
0d72b344 149 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
718e3744 150 if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
0d72b344 151 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
54f03be9 152 if (strncmp ("detail", argv[0], strlen (argv[0])) == 0)
0d72b344 153 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL);
718e3744 154 return CMD_SUCCESS;
155}
156
157DEFUN (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"
2b00515a 165 "Debug option set detailed information\n")
718e3744 166{
167 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
168 if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
0d72b344 169 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
718e3744 170 if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
0d72b344
QY
171 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
172 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL);
718e3744 173 return CMD_SUCCESS;
174}
175
176DEFUN (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{
556b904e
QY
183 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL);
184 return CMD_SUCCESS;
185}
186
187DEFUN (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);
718e3744 201 return CMD_SUCCESS;
202}
203
b0498dc6
PJ
204DEFUN (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
41ec9222 215DEFUN (debug_zebra_rib_detailed,
216 debug_zebra_rib_detailed_cmd,
217 "debug zebra rib detailed",
b0498dc6
PJ
218 DEBUG_STR
219 "Zebra configuration\n"
220 "Debug RIB events\n"
41ec9222 221 "Detailed debugs\n")
b0498dc6 222{
41ec9222 223 SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED);
b0498dc6
PJ
224 return CMD_SUCCESS;
225}
226
5adc2528
AS
227DEFUN (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
718e3744 238DEFUN (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
fb018d25
DS
250DEFUN (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
7758e3f3 262DEFUN (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
718e3744 274DEFUN (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
286DEFUN (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)
0d72b344 297 UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
718e3744 298 if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
0d72b344 299 UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
718e3744 300 return CMD_SUCCESS;
301}
302
303DEFUN (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{
556b904e
QY
311 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL);
312 return CMD_SUCCESS;
313}
314
315DEFUN (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);
718e3744 329 return CMD_SUCCESS;
330}
331
b0498dc6
PJ
332DEFUN (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
41ec9222 344DEFUN (no_debug_zebra_rib_detailed,
345 no_debug_zebra_rib_detailed_cmd,
346 "no debug zebra rib detailed",
b0498dc6
PJ
347 NO_STR
348 DEBUG_STR
349 "Zebra configuration\n"
350 "Debug zebra RIB\n"
41ec9222 351 "Detailed debugs\n")
b0498dc6 352{
41ec9222 353 UNSET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED);
b0498dc6
PJ
354 return CMD_SUCCESS;
355}
356
5adc2528
AS
357DEFUN (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
718e3744 369/* Debug node. */
370struct cmd_node debug_node =
371{
372 DEBUG_NODE,
373 "", /* Debug node has no interface. */
374 1
375};
376
a1ac18c4 377static int
718e3744 378config_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 }
41ec9222 414 /* Check here using flags as the 'macro' does an OR */
415 if (CHECK_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB))
b0498dc6
PJ
416 {
417 vty_out (vty, "debug zebra rib%s", VTY_NEWLINE);
418 write++;
419 }
41ec9222 420 if (CHECK_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED))
b0498dc6 421 {
41ec9222 422 vty_out (vty, "debug zebra rib detailed%s", VTY_NEWLINE);
b0498dc6
PJ
423 write++;
424 }
5adc2528
AS
425 if (IS_ZEBRA_DEBUG_FPM)
426 {
427 vty_out (vty, "debug zebra fpm%s", VTY_NEWLINE);
428 write++;
429 }
7758e3f3 430 if (IS_ZEBRA_DEBUG_MPLS)
431 {
432 vty_out (vty, "debug zebra mpls%s", VTY_NEWLINE);
433 write++;
434 }
718e3744 435 return write;
436}
437
438void
a1ac18c4 439zebra_debug_init (void)
718e3744 440{
441 zebra_debug_event = 0;
442 zebra_debug_packet = 0;
b0498dc6
PJ
443 zebra_debug_kernel = 0;
444 zebra_debug_rib = 0;
5adc2528 445 zebra_debug_fpm = 0;
7758e3f3 446 zebra_debug_mpls = 0;
718e3744 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, &show_debugging_zebra_cmd);
453 install_element (ENABLE_NODE, &debug_zebra_events_cmd);
fb018d25 454 install_element (ENABLE_NODE, &debug_zebra_nht_cmd);
7758e3f3 455 install_element (ENABLE_NODE, &debug_zebra_mpls_cmd);
718e3744 456 install_element (ENABLE_NODE, &debug_zebra_packet_cmd);
457 install_element (ENABLE_NODE, &debug_zebra_packet_direct_cmd);
458 install_element (ENABLE_NODE, &debug_zebra_packet_detail_cmd);
459 install_element (ENABLE_NODE, &debug_zebra_kernel_cmd);
556b904e 460 install_element (ENABLE_NODE, &debug_zebra_kernel_msgdump_cmd);
b0498dc6 461 install_element (ENABLE_NODE, &debug_zebra_rib_cmd);
41ec9222 462 install_element (ENABLE_NODE, &debug_zebra_rib_detailed_cmd);
5adc2528 463 install_element (ENABLE_NODE, &debug_zebra_fpm_cmd);
718e3744 464 install_element (ENABLE_NODE, &no_debug_zebra_events_cmd);
fb018d25 465 install_element (ENABLE_NODE, &no_debug_zebra_nht_cmd);
7758e3f3 466 install_element (ENABLE_NODE, &no_debug_zebra_mpls_cmd);
718e3744 467 install_element (ENABLE_NODE, &no_debug_zebra_packet_cmd);
468 install_element (ENABLE_NODE, &no_debug_zebra_kernel_cmd);
556b904e 469 install_element (ENABLE_NODE, &no_debug_zebra_kernel_msgdump_cmd);
b0498dc6 470 install_element (ENABLE_NODE, &no_debug_zebra_rib_cmd);
41ec9222 471 install_element (ENABLE_NODE, &no_debug_zebra_rib_detailed_cmd);
5adc2528 472 install_element (ENABLE_NODE, &no_debug_zebra_fpm_cmd);
718e3744 473
474 install_element (CONFIG_NODE, &debug_zebra_events_cmd);
fb018d25 475 install_element (CONFIG_NODE, &debug_zebra_nht_cmd);
7758e3f3 476 install_element (CONFIG_NODE, &debug_zebra_mpls_cmd);
718e3744 477 install_element (CONFIG_NODE, &debug_zebra_packet_cmd);
478 install_element (CONFIG_NODE, &debug_zebra_packet_direct_cmd);
479 install_element (CONFIG_NODE, &debug_zebra_packet_detail_cmd);
480 install_element (CONFIG_NODE, &debug_zebra_kernel_cmd);
556b904e 481 install_element (CONFIG_NODE, &debug_zebra_kernel_msgdump_cmd);
b0498dc6 482 install_element (CONFIG_NODE, &debug_zebra_rib_cmd);
41ec9222 483 install_element (CONFIG_NODE, &debug_zebra_rib_detailed_cmd);
5adc2528 484 install_element (CONFIG_NODE, &debug_zebra_fpm_cmd);
718e3744 485 install_element (CONFIG_NODE, &no_debug_zebra_events_cmd);
fb018d25 486 install_element (CONFIG_NODE, &no_debug_zebra_nht_cmd);
7758e3f3 487 install_element (CONFIG_NODE, &no_debug_zebra_mpls_cmd);
718e3744 488 install_element (CONFIG_NODE, &no_debug_zebra_packet_cmd);
489 install_element (CONFIG_NODE, &no_debug_zebra_kernel_cmd);
556b904e 490 install_element (CONFIG_NODE, &no_debug_zebra_kernel_msgdump_cmd);
b0498dc6 491 install_element (CONFIG_NODE, &no_debug_zebra_rib_cmd);
41ec9222 492 install_element (CONFIG_NODE, &no_debug_zebra_rib_detailed_cmd);
5adc2528 493 install_element (CONFIG_NODE, &no_debug_zebra_fpm_cmd);
718e3744 494}