]> git.proxmox.com Git - mirror_frr.git/blame - zebra/debug.c
convert <1-255> to (1-255), ()s to <>s, etc
[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;
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);
5adc2528 85
718e3744 86 return CMD_SUCCESS;
87}
88
89DEFUN (debug_zebra_events,
90 debug_zebra_events_cmd,
91 "debug zebra events",
92 DEBUG_STR
93 "Zebra configuration\n"
94 "Debug option set for zebra events\n")
95{
96 zebra_debug_event = ZEBRA_DEBUG_EVENT;
97 return CMD_WARNING;
98}
99
fb018d25
DS
100DEFUN (debug_zebra_nht,
101 debug_zebra_nht_cmd,
102 "debug zebra nht",
103 DEBUG_STR
104 "Zebra configuration\n"
105 "Debug option set for zebra next hop tracking\n")
106{
107 zebra_debug_nht = ZEBRA_DEBUG_NHT;
108 return CMD_WARNING;
109}
110
718e3744 111DEFUN (debug_zebra_packet,
112 debug_zebra_packet_cmd,
113 "debug zebra packet",
114 DEBUG_STR
115 "Zebra configuration\n"
116 "Debug option set for zebra packet\n")
117{
118 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
0d72b344
QY
119 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
120 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
718e3744 121 return CMD_SUCCESS;
122}
123
124DEFUN (debug_zebra_packet_direct,
125 debug_zebra_packet_direct_cmd,
6147e2c6 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"
131 "Debug option set for send packet\n")
132{
133 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
8b3f0677 134 if (strncmp ("send", argv[3]->arg, strlen (argv[3]->arg)) == 0)
0d72b344 135 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
8b3f0677 136 if (strncmp ("recv", argv[3]->arg, strlen (argv[3]->arg)) == 0)
0d72b344 137 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
8b3f0677 138 if (strncmp ("detail", argv[3]->arg, strlen (argv[3]->arg)) == 0)
0d72b344 139 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL);
718e3744 140 return CMD_SUCCESS;
141}
142
143DEFUN (debug_zebra_packet_detail,
144 debug_zebra_packet_detail_cmd,
6147e2c6 145 "debug zebra packet <recv|send> detail",
718e3744 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"
2b00515a 151 "Debug option set detailed information\n")
718e3744 152{
153 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
8b3f0677 154 if (strncmp ("send", argv[3]->arg, strlen (argv[3]->arg)) == 0)
0d72b344 155 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
8b3f0677 156 if (strncmp ("recv", argv[3]->arg, strlen (argv[3]->arg)) == 0)
0d72b344
QY
157 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
158 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL);
718e3744 159 return CMD_SUCCESS;
160}
161
162DEFUN (debug_zebra_kernel,
163 debug_zebra_kernel_cmd,
164 "debug zebra kernel",
165 DEBUG_STR
166 "Zebra configuration\n"
167 "Debug option set for zebra between kernel interface\n")
168{
556b904e
QY
169 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL);
170 return CMD_SUCCESS;
171}
172
173DEFUN (debug_zebra_kernel_msgdump,
174 debug_zebra_kernel_msgdump_cmd,
6147e2c6 175 "debug zebra kernel msgdump [recv|send]",
556b904e
QY
176 DEBUG_STR
177 "Zebra configuration\n"
178 "Debug option set for zebra between kernel interface\n"
179 "Dump raw netlink messages, sent and received\n"
180 "Dump raw netlink messages received\n"
181 "Dump raw netlink messages sent\n")
182{
8b3f0677 183 if (argv[4]->arg && strncmp(argv[4]->arg, "recv", strlen(argv[4]->arg)) == 0)
556b904e 184 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
8b3f0677 185 if (!argv[4]->arg || strncmp(argv[4]->arg, "send", strlen(argv[4]->arg)) == 0)
556b904e 186 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
718e3744 187 return CMD_SUCCESS;
188}
189
b0498dc6
PJ
190DEFUN (debug_zebra_rib,
191 debug_zebra_rib_cmd,
192 "debug zebra rib",
193 DEBUG_STR
194 "Zebra configuration\n"
195 "Debug RIB events\n")
196{
197 SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB);
198 return CMD_SUCCESS;
199}
200
41ec9222 201DEFUN (debug_zebra_rib_detailed,
202 debug_zebra_rib_detailed_cmd,
203 "debug zebra rib detailed",
b0498dc6
PJ
204 DEBUG_STR
205 "Zebra configuration\n"
206 "Debug RIB events\n"
41ec9222 207 "Detailed debugs\n")
b0498dc6 208{
41ec9222 209 SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED);
b0498dc6
PJ
210 return CMD_SUCCESS;
211}
212
5adc2528
AS
213DEFUN (debug_zebra_fpm,
214 debug_zebra_fpm_cmd,
215 "debug zebra fpm",
216 DEBUG_STR
217 "Zebra configuration\n"
218 "Debug zebra FPM events\n")
219{
220 SET_FLAG (zebra_debug_fpm, ZEBRA_DEBUG_FPM);
221 return CMD_SUCCESS;
222}
223
718e3744 224DEFUN (no_debug_zebra_events,
225 no_debug_zebra_events_cmd,
226 "no debug zebra events",
227 NO_STR
228 DEBUG_STR
229 "Zebra configuration\n"
230 "Debug option set for zebra events\n")
231{
232 zebra_debug_event = 0;
233 return CMD_SUCCESS;
234}
235
fb018d25
DS
236DEFUN (no_debug_zebra_nht,
237 no_debug_zebra_nht_cmd,
238 "no debug zebra nht",
239 NO_STR
240 DEBUG_STR
241 "Zebra configuration\n"
242 "Debug option set for zebra next hop tracking\n")
243{
244 zebra_debug_nht = 0;
245 return CMD_SUCCESS;
246}
247
718e3744 248DEFUN (no_debug_zebra_packet,
249 no_debug_zebra_packet_cmd,
250 "no debug zebra packet",
251 NO_STR
252 DEBUG_STR
253 "Zebra configuration\n"
254 "Debug option set for zebra packet\n")
255{
256 zebra_debug_packet = 0;
257 return CMD_SUCCESS;
258}
259
260DEFUN (no_debug_zebra_packet_direct,
261 no_debug_zebra_packet_direct_cmd,
6147e2c6 262 "no debug zebra packet <recv|send>",
718e3744 263 NO_STR
264 DEBUG_STR
265 "Zebra configuration\n"
266 "Debug option set for zebra packet\n"
267 "Debug option set for receive packet\n"
268 "Debug option set for send packet\n")
269{
8b3f0677 270 if (strncmp ("send", argv[4]->arg, strlen (argv[4]->arg)) == 0)
0d72b344 271 UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
8b3f0677 272 if (strncmp ("recv", argv[4]->arg, strlen (argv[4]->arg)) == 0)
0d72b344 273 UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
718e3744 274 return CMD_SUCCESS;
275}
276
277DEFUN (no_debug_zebra_kernel,
278 no_debug_zebra_kernel_cmd,
279 "no debug zebra kernel",
280 NO_STR
281 DEBUG_STR
282 "Zebra configuration\n"
283 "Debug option set for zebra between kernel interface\n")
284{
556b904e
QY
285 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL);
286 return CMD_SUCCESS;
287}
288
289DEFUN (no_debug_zebra_kernel_msgdump,
290 no_debug_zebra_kernel_msgdump_cmd,
6147e2c6 291 "no debug zebra kernel msgdump [recv|send]",
556b904e
QY
292 DEBUG_STR
293 "Zebra configuration\n"
294 "Debug option set for zebra between kernel interface\n"
295 "Dump raw netlink messages, sent and received\n"
296 "Dump raw netlink messages received\n"
297 "Dump raw netlink messages sent\n")
298{
8b3f0677 299 if (!argv[1] || (argv[5]->arg && strncmp(argv[5]->arg, "recv", strlen(argv[5]->arg)) == 0))
556b904e 300 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
8b3f0677 301 if (!argv[5]->arg || (argv[5]->arg && strncmp(argv[5]->arg, "send", strlen(argv[5]->arg)) == 0))
556b904e 302 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
718e3744 303 return CMD_SUCCESS;
304}
305
b0498dc6
PJ
306DEFUN (no_debug_zebra_rib,
307 no_debug_zebra_rib_cmd,
308 "no debug zebra rib",
309 NO_STR
310 DEBUG_STR
311 "Zebra configuration\n"
312 "Debug zebra RIB\n")
313{
314 zebra_debug_rib = 0;
315 return CMD_SUCCESS;
316}
317
41ec9222 318DEFUN (no_debug_zebra_rib_detailed,
319 no_debug_zebra_rib_detailed_cmd,
320 "no debug zebra rib detailed",
b0498dc6
PJ
321 NO_STR
322 DEBUG_STR
323 "Zebra configuration\n"
324 "Debug zebra RIB\n"
41ec9222 325 "Detailed debugs\n")
b0498dc6 326{
41ec9222 327 UNSET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED);
b0498dc6
PJ
328 return CMD_SUCCESS;
329}
330
5adc2528
AS
331DEFUN (no_debug_zebra_fpm,
332 no_debug_zebra_fpm_cmd,
333 "no debug zebra fpm",
334 NO_STR
335 DEBUG_STR
336 "Zebra configuration\n"
337 "Debug zebra FPM events\n")
338{
339 zebra_debug_fpm = 0;
340 return CMD_SUCCESS;
341}
342
718e3744 343/* Debug node. */
344struct cmd_node debug_node =
345{
346 DEBUG_NODE,
347 "", /* Debug node has no interface. */
348 1
349};
350
a1ac18c4 351static int
718e3744 352config_write_debug (struct vty *vty)
353{
354 int write = 0;
355
356 if (IS_ZEBRA_DEBUG_EVENT)
357 {
358 vty_out (vty, "debug zebra events%s", VTY_NEWLINE);
359 write++;
360 }
361 if (IS_ZEBRA_DEBUG_PACKET)
362 {
363 if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV)
364 {
365 vty_out (vty, "debug zebra packet%s%s",
366 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
367 VTY_NEWLINE);
368 write++;
369 }
370 else
371 {
372 if (IS_ZEBRA_DEBUG_SEND)
373 vty_out (vty, "debug zebra packet send%s%s",
374 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
375 VTY_NEWLINE);
376 else
377 vty_out (vty, "debug zebra packet recv%s%s",
378 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
379 VTY_NEWLINE);
380 write++;
381 }
382 }
383 if (IS_ZEBRA_DEBUG_KERNEL)
384 {
385 vty_out (vty, "debug zebra kernel%s", VTY_NEWLINE);
386 write++;
387 }
41ec9222 388 /* Check here using flags as the 'macro' does an OR */
389 if (CHECK_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB))
b0498dc6
PJ
390 {
391 vty_out (vty, "debug zebra rib%s", VTY_NEWLINE);
392 write++;
393 }
41ec9222 394 if (CHECK_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED))
b0498dc6 395 {
41ec9222 396 vty_out (vty, "debug zebra rib detailed%s", VTY_NEWLINE);
b0498dc6
PJ
397 write++;
398 }
5adc2528
AS
399 if (IS_ZEBRA_DEBUG_FPM)
400 {
401 vty_out (vty, "debug zebra fpm%s", VTY_NEWLINE);
402 write++;
403 }
718e3744 404 return write;
405}
406
407void
a1ac18c4 408zebra_debug_init (void)
718e3744 409{
410 zebra_debug_event = 0;
411 zebra_debug_packet = 0;
b0498dc6
PJ
412 zebra_debug_kernel = 0;
413 zebra_debug_rib = 0;
5adc2528 414 zebra_debug_fpm = 0;
718e3744 415
416 install_node (&debug_node, config_write_debug);
417
418 install_element (VIEW_NODE, &show_debugging_zebra_cmd);
419
420 install_element (ENABLE_NODE, &show_debugging_zebra_cmd);
421 install_element (ENABLE_NODE, &debug_zebra_events_cmd);
fb018d25 422 install_element (ENABLE_NODE, &debug_zebra_nht_cmd);
718e3744 423 install_element (ENABLE_NODE, &debug_zebra_packet_cmd);
424 install_element (ENABLE_NODE, &debug_zebra_packet_direct_cmd);
425 install_element (ENABLE_NODE, &debug_zebra_packet_detail_cmd);
426 install_element (ENABLE_NODE, &debug_zebra_kernel_cmd);
556b904e 427 install_element (ENABLE_NODE, &debug_zebra_kernel_msgdump_cmd);
b0498dc6 428 install_element (ENABLE_NODE, &debug_zebra_rib_cmd);
41ec9222 429 install_element (ENABLE_NODE, &debug_zebra_rib_detailed_cmd);
5adc2528 430 install_element (ENABLE_NODE, &debug_zebra_fpm_cmd);
718e3744 431 install_element (ENABLE_NODE, &no_debug_zebra_events_cmd);
fb018d25 432 install_element (ENABLE_NODE, &no_debug_zebra_nht_cmd);
718e3744 433 install_element (ENABLE_NODE, &no_debug_zebra_packet_cmd);
434 install_element (ENABLE_NODE, &no_debug_zebra_kernel_cmd);
556b904e 435 install_element (ENABLE_NODE, &no_debug_zebra_kernel_msgdump_cmd);
b0498dc6 436 install_element (ENABLE_NODE, &no_debug_zebra_rib_cmd);
41ec9222 437 install_element (ENABLE_NODE, &no_debug_zebra_rib_detailed_cmd);
5adc2528 438 install_element (ENABLE_NODE, &no_debug_zebra_fpm_cmd);
718e3744 439
440 install_element (CONFIG_NODE, &debug_zebra_events_cmd);
fb018d25 441 install_element (CONFIG_NODE, &debug_zebra_nht_cmd);
718e3744 442 install_element (CONFIG_NODE, &debug_zebra_packet_cmd);
443 install_element (CONFIG_NODE, &debug_zebra_packet_direct_cmd);
444 install_element (CONFIG_NODE, &debug_zebra_packet_detail_cmd);
445 install_element (CONFIG_NODE, &debug_zebra_kernel_cmd);
556b904e 446 install_element (CONFIG_NODE, &debug_zebra_kernel_msgdump_cmd);
b0498dc6 447 install_element (CONFIG_NODE, &debug_zebra_rib_cmd);
41ec9222 448 install_element (CONFIG_NODE, &debug_zebra_rib_detailed_cmd);
5adc2528 449 install_element (CONFIG_NODE, &debug_zebra_fpm_cmd);
718e3744 450 install_element (CONFIG_NODE, &no_debug_zebra_events_cmd);
fb018d25 451 install_element (CONFIG_NODE, &no_debug_zebra_nht_cmd);
718e3744 452 install_element (CONFIG_NODE, &no_debug_zebra_packet_cmd);
453 install_element (CONFIG_NODE, &no_debug_zebra_kernel_cmd);
556b904e 454 install_element (CONFIG_NODE, &no_debug_zebra_kernel_msgdump_cmd);
b0498dc6 455 install_element (CONFIG_NODE, &no_debug_zebra_rib_cmd);
41ec9222 456 install_element (CONFIG_NODE, &no_debug_zebra_rib_detailed_cmd);
5adc2528 457 install_element (CONFIG_NODE, &no_debug_zebra_fpm_cmd);
718e3744 458}