blob: 537c47662fd6d7fd0e970271882a330ed1b1ac19 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
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;
Paul Jakmab0498dc2006-07-27 21:35:33 +000031unsigned long zebra_debug_rib;
Avneesh Sachdev5adc2522012-11-13 22:48:59 +000032unsigned long zebra_debug_fpm;
paul718e3742002-12-13 20:15:29 +000033
34DEFUN (show_debugging_zebra,
35 show_debugging_zebra_cmd,
36 "show debugging zebra",
37 SHOW_STR
Christian Franke2b005152013-09-30 12:27:49 +000038 "Debugging information\n"
39 "Zebra configuration\n")
paul718e3742002-12-13 20:15:29 +000040{
41 vty_out (vty, "Zebra debugging status:%s", VTY_NEWLINE);
42
43 if (IS_ZEBRA_DEBUG_EVENT)
44 vty_out (vty, " Zebra event debugging is on%s", VTY_NEWLINE);
45
46 if (IS_ZEBRA_DEBUG_PACKET)
47 {
48 if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV)
49 {
50 vty_out (vty, " Zebra packet%s debugging is on%s",
51 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
52 VTY_NEWLINE);
53 }
54 else
55 {
56 if (IS_ZEBRA_DEBUG_SEND)
57 vty_out (vty, " Zebra packet send%s debugging is on%s",
58 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
59 VTY_NEWLINE);
60 else
61 vty_out (vty, " Zebra packet receive%s debugging is on%s",
62 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
63 VTY_NEWLINE);
64 }
65 }
66
67 if (IS_ZEBRA_DEBUG_KERNEL)
68 vty_out (vty, " Zebra kernel debugging is on%s", VTY_NEWLINE);
69
Paul Jakmab0498dc2006-07-27 21:35:33 +000070 if (IS_ZEBRA_DEBUG_RIB)
71 vty_out (vty, " Zebra RIB debugging is on%s", VTY_NEWLINE);
72 if (IS_ZEBRA_DEBUG_RIB_Q)
73 vty_out (vty, " Zebra RIB queue debugging is on%s", VTY_NEWLINE);
74
Avneesh Sachdev5adc2522012-11-13 22:48:59 +000075 if (IS_ZEBRA_DEBUG_FPM)
76 vty_out (vty, " Zebra FPM debugging is on%s", VTY_NEWLINE);
77
paul718e3742002-12-13 20:15:29 +000078 return CMD_SUCCESS;
79}
80
81DEFUN (debug_zebra_events,
82 debug_zebra_events_cmd,
83 "debug zebra events",
84 DEBUG_STR
85 "Zebra configuration\n"
86 "Debug option set for zebra events\n")
87{
88 zebra_debug_event = ZEBRA_DEBUG_EVENT;
89 return CMD_WARNING;
90}
91
92DEFUN (debug_zebra_packet,
93 debug_zebra_packet_cmd,
94 "debug zebra packet",
95 DEBUG_STR
96 "Zebra configuration\n"
97 "Debug option set for zebra packet\n")
98{
99 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
100 zebra_debug_packet |= ZEBRA_DEBUG_SEND;
101 zebra_debug_packet |= ZEBRA_DEBUG_RECV;
102 return CMD_SUCCESS;
103}
104
105DEFUN (debug_zebra_packet_direct,
106 debug_zebra_packet_direct_cmd,
Lou Bergerd7be0422016-01-12 13:41:43 -0500107 "debug zebra packet (recv|send|detail)",
paul718e3742002-12-13 20:15:29 +0000108 DEBUG_STR
109 "Zebra configuration\n"
110 "Debug option set for zebra packet\n"
111 "Debug option set for receive packet\n"
112 "Debug option set for send packet\n")
113{
114 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
115 if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
116 zebra_debug_packet |= ZEBRA_DEBUG_SEND;
117 if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
118 zebra_debug_packet |= ZEBRA_DEBUG_RECV;
Lou Bergerd7be0422016-01-12 13:41:43 -0500119 if (strncmp ("detail", argv[0], strlen (argv[0])) == 0)
120 zebra_debug_packet |= ZEBRA_DEBUG_DETAIL;
paul718e3742002-12-13 20:15:29 +0000121 return CMD_SUCCESS;
122}
123
124DEFUN (debug_zebra_packet_detail,
125 debug_zebra_packet_detail_cmd,
126 "debug zebra packet (recv|send) detail",
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"
Christian Franke2b005152013-09-30 12:27:49 +0000132 "Debug option set detailed information\n")
paul718e3742002-12-13 20:15:29 +0000133{
134 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
135 if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
136 zebra_debug_packet |= ZEBRA_DEBUG_SEND;
137 if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
138 zebra_debug_packet |= ZEBRA_DEBUG_RECV;
139 zebra_debug_packet |= ZEBRA_DEBUG_DETAIL;
140 return CMD_SUCCESS;
141}
142
143DEFUN (debug_zebra_kernel,
144 debug_zebra_kernel_cmd,
145 "debug zebra kernel",
146 DEBUG_STR
147 "Zebra configuration\n"
148 "Debug option set for zebra between kernel interface\n")
149{
150 zebra_debug_kernel = ZEBRA_DEBUG_KERNEL;
151 return CMD_SUCCESS;
152}
153
Paul Jakmab0498dc2006-07-27 21:35:33 +0000154DEFUN (debug_zebra_rib,
155 debug_zebra_rib_cmd,
156 "debug zebra rib",
157 DEBUG_STR
158 "Zebra configuration\n"
159 "Debug RIB events\n")
160{
161 SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB);
162 return CMD_SUCCESS;
163}
164
165DEFUN (debug_zebra_rib_q,
166 debug_zebra_rib_q_cmd,
167 "debug zebra rib queue",
168 DEBUG_STR
169 "Zebra configuration\n"
170 "Debug RIB events\n"
171 "Debug RIB queueing\n")
172{
173 SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_Q);
174 return CMD_SUCCESS;
175}
176
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000177DEFUN (debug_zebra_fpm,
178 debug_zebra_fpm_cmd,
179 "debug zebra fpm",
180 DEBUG_STR
181 "Zebra configuration\n"
182 "Debug zebra FPM events\n")
183{
184 SET_FLAG (zebra_debug_fpm, ZEBRA_DEBUG_FPM);
185 return CMD_SUCCESS;
186}
187
paul718e3742002-12-13 20:15:29 +0000188DEFUN (no_debug_zebra_events,
189 no_debug_zebra_events_cmd,
190 "no debug zebra events",
191 NO_STR
192 DEBUG_STR
193 "Zebra configuration\n"
194 "Debug option set for zebra events\n")
195{
196 zebra_debug_event = 0;
197 return CMD_SUCCESS;
198}
199
200DEFUN (no_debug_zebra_packet,
201 no_debug_zebra_packet_cmd,
202 "no debug zebra packet",
203 NO_STR
204 DEBUG_STR
205 "Zebra configuration\n"
206 "Debug option set for zebra packet\n")
207{
208 zebra_debug_packet = 0;
209 return CMD_SUCCESS;
210}
211
212DEFUN (no_debug_zebra_packet_direct,
213 no_debug_zebra_packet_direct_cmd,
214 "no debug zebra packet (recv|send)",
215 NO_STR
216 DEBUG_STR
217 "Zebra configuration\n"
218 "Debug option set for zebra packet\n"
219 "Debug option set for receive packet\n"
220 "Debug option set for send packet\n")
221{
222 if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
223 zebra_debug_packet &= ~ZEBRA_DEBUG_SEND;
224 if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
225 zebra_debug_packet &= ~ZEBRA_DEBUG_RECV;
226 return CMD_SUCCESS;
227}
228
229DEFUN (no_debug_zebra_kernel,
230 no_debug_zebra_kernel_cmd,
231 "no debug zebra kernel",
232 NO_STR
233 DEBUG_STR
234 "Zebra configuration\n"
235 "Debug option set for zebra between kernel interface\n")
236{
237 zebra_debug_kernel = 0;
238 return CMD_SUCCESS;
239}
240
Paul Jakmab0498dc2006-07-27 21:35:33 +0000241DEFUN (no_debug_zebra_rib,
242 no_debug_zebra_rib_cmd,
243 "no debug zebra rib",
244 NO_STR
245 DEBUG_STR
246 "Zebra configuration\n"
247 "Debug zebra RIB\n")
248{
249 zebra_debug_rib = 0;
250 return CMD_SUCCESS;
251}
252
253DEFUN (no_debug_zebra_rib_q,
254 no_debug_zebra_rib_q_cmd,
Stephen Hemmingere5248432008-08-17 18:08:24 +0100255 "no debug zebra rib queue",
Paul Jakmab0498dc2006-07-27 21:35:33 +0000256 NO_STR
257 DEBUG_STR
258 "Zebra configuration\n"
259 "Debug zebra RIB\n"
260 "Debug RIB queueing\n")
261{
262 UNSET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_Q);
263 return CMD_SUCCESS;
264}
265
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000266DEFUN (no_debug_zebra_fpm,
267 no_debug_zebra_fpm_cmd,
268 "no debug zebra fpm",
269 NO_STR
270 DEBUG_STR
271 "Zebra configuration\n"
272 "Debug zebra FPM events\n")
273{
274 zebra_debug_fpm = 0;
275 return CMD_SUCCESS;
276}
277
paul718e3742002-12-13 20:15:29 +0000278/* Debug node. */
279struct cmd_node debug_node =
280{
281 DEBUG_NODE,
282 "", /* Debug node has no interface. */
283 1
284};
285
paula1ac18c2005-06-28 17:17:12 +0000286static int
paul718e3742002-12-13 20:15:29 +0000287config_write_debug (struct vty *vty)
288{
289 int write = 0;
290
291 if (IS_ZEBRA_DEBUG_EVENT)
292 {
293 vty_out (vty, "debug zebra events%s", VTY_NEWLINE);
294 write++;
295 }
296 if (IS_ZEBRA_DEBUG_PACKET)
297 {
298 if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV)
299 {
300 vty_out (vty, "debug zebra packet%s%s",
301 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
302 VTY_NEWLINE);
303 write++;
304 }
305 else
306 {
307 if (IS_ZEBRA_DEBUG_SEND)
308 vty_out (vty, "debug zebra packet send%s%s",
309 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
310 VTY_NEWLINE);
311 else
312 vty_out (vty, "debug zebra packet recv%s%s",
313 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
314 VTY_NEWLINE);
315 write++;
316 }
317 }
318 if (IS_ZEBRA_DEBUG_KERNEL)
319 {
320 vty_out (vty, "debug zebra kernel%s", VTY_NEWLINE);
321 write++;
322 }
Paul Jakmab0498dc2006-07-27 21:35:33 +0000323 if (IS_ZEBRA_DEBUG_RIB)
324 {
325 vty_out (vty, "debug zebra rib%s", VTY_NEWLINE);
326 write++;
327 }
328 if (IS_ZEBRA_DEBUG_RIB_Q)
329 {
330 vty_out (vty, "debug zebra rib queue%s", VTY_NEWLINE);
331 write++;
332 }
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000333 if (IS_ZEBRA_DEBUG_FPM)
334 {
335 vty_out (vty, "debug zebra fpm%s", VTY_NEWLINE);
336 write++;
337 }
paul718e3742002-12-13 20:15:29 +0000338 return write;
339}
340
341void
paula1ac18c2005-06-28 17:17:12 +0000342zebra_debug_init (void)
paul718e3742002-12-13 20:15:29 +0000343{
344 zebra_debug_event = 0;
345 zebra_debug_packet = 0;
Paul Jakmab0498dc2006-07-27 21:35:33 +0000346 zebra_debug_kernel = 0;
347 zebra_debug_rib = 0;
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000348 zebra_debug_fpm = 0;
paul718e3742002-12-13 20:15:29 +0000349
350 install_node (&debug_node, config_write_debug);
351
352 install_element (VIEW_NODE, &show_debugging_zebra_cmd);
353
354 install_element (ENABLE_NODE, &show_debugging_zebra_cmd);
355 install_element (ENABLE_NODE, &debug_zebra_events_cmd);
356 install_element (ENABLE_NODE, &debug_zebra_packet_cmd);
357 install_element (ENABLE_NODE, &debug_zebra_packet_direct_cmd);
358 install_element (ENABLE_NODE, &debug_zebra_packet_detail_cmd);
359 install_element (ENABLE_NODE, &debug_zebra_kernel_cmd);
Paul Jakmab0498dc2006-07-27 21:35:33 +0000360 install_element (ENABLE_NODE, &debug_zebra_rib_cmd);
361 install_element (ENABLE_NODE, &debug_zebra_rib_q_cmd);
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000362 install_element (ENABLE_NODE, &debug_zebra_fpm_cmd);
paul718e3742002-12-13 20:15:29 +0000363 install_element (ENABLE_NODE, &no_debug_zebra_events_cmd);
364 install_element (ENABLE_NODE, &no_debug_zebra_packet_cmd);
365 install_element (ENABLE_NODE, &no_debug_zebra_kernel_cmd);
Paul Jakmab0498dc2006-07-27 21:35:33 +0000366 install_element (ENABLE_NODE, &no_debug_zebra_rib_cmd);
367 install_element (ENABLE_NODE, &no_debug_zebra_rib_q_cmd);
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000368 install_element (ENABLE_NODE, &no_debug_zebra_fpm_cmd);
paul718e3742002-12-13 20:15:29 +0000369
370 install_element (CONFIG_NODE, &debug_zebra_events_cmd);
371 install_element (CONFIG_NODE, &debug_zebra_packet_cmd);
372 install_element (CONFIG_NODE, &debug_zebra_packet_direct_cmd);
373 install_element (CONFIG_NODE, &debug_zebra_packet_detail_cmd);
374 install_element (CONFIG_NODE, &debug_zebra_kernel_cmd);
Paul Jakmab0498dc2006-07-27 21:35:33 +0000375 install_element (CONFIG_NODE, &debug_zebra_rib_cmd);
376 install_element (CONFIG_NODE, &debug_zebra_rib_q_cmd);
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000377 install_element (CONFIG_NODE, &debug_zebra_fpm_cmd);
paul718e3742002-12-13 20:15:29 +0000378 install_element (CONFIG_NODE, &no_debug_zebra_events_cmd);
379 install_element (CONFIG_NODE, &no_debug_zebra_packet_cmd);
380 install_element (CONFIG_NODE, &no_debug_zebra_kernel_cmd);
Paul Jakmab0498dc2006-07-27 21:35:33 +0000381 install_element (CONFIG_NODE, &no_debug_zebra_rib_cmd);
382 install_element (CONFIG_NODE, &no_debug_zebra_rib_q_cmd);
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000383 install_element (CONFIG_NODE, &no_debug_zebra_fpm_cmd);
paul718e3742002-12-13 20:15:29 +0000384}