blob: 5dd38f00dcfd52f1f87b68897d7ce7651ca11ba6 [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;
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -050033unsigned long zebra_debug_nht;
paul718e3742002-12-13 20:15:29 +000034
35DEFUN (show_debugging_zebra,
36 show_debugging_zebra_cmd,
37 "show debugging zebra",
38 SHOW_STR
Christian Franke2b005152013-09-30 12:27:49 +000039 "Debugging information\n"
40 "Zebra configuration\n")
paul718e3742002-12-13 20:15:29 +000041{
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);
70
Paul Jakmab0498dc2006-07-27 21:35:33 +000071 if (IS_ZEBRA_DEBUG_RIB)
72 vty_out (vty, " Zebra RIB debugging is on%s", VTY_NEWLINE);
73 if (IS_ZEBRA_DEBUG_RIB_Q)
74 vty_out (vty, " Zebra RIB queue debugging is on%s", VTY_NEWLINE);
75
Avneesh Sachdev5adc2522012-11-13 22:48:59 +000076 if (IS_ZEBRA_DEBUG_FPM)
77 vty_out (vty, " Zebra FPM debugging is on%s", VTY_NEWLINE);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -050078 if (IS_ZEBRA_DEBUG_NHT)
79 vty_out (vty, " Zebra next-hop tracking debugging is on%s", VTY_NEWLINE);
Avneesh Sachdev5adc2522012-11-13 22:48:59 +000080
paul718e3742002-12-13 20:15:29 +000081 return CMD_SUCCESS;
82}
83
84DEFUN (debug_zebra_events,
85 debug_zebra_events_cmd,
86 "debug zebra events",
87 DEBUG_STR
88 "Zebra configuration\n"
89 "Debug option set for zebra events\n")
90{
91 zebra_debug_event = ZEBRA_DEBUG_EVENT;
92 return CMD_WARNING;
93}
94
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -050095DEFUN (debug_zebra_nht,
96 debug_zebra_nht_cmd,
97 "debug zebra nht",
98 DEBUG_STR
99 "Zebra configuration\n"
100 "Debug option set for zebra next hop tracking\n")
101{
102 zebra_debug_nht = ZEBRA_DEBUG_NHT;
103 return CMD_WARNING;
104}
105
paul718e3742002-12-13 20:15:29 +0000106DEFUN (debug_zebra_packet,
107 debug_zebra_packet_cmd,
108 "debug zebra packet",
109 DEBUG_STR
110 "Zebra configuration\n"
111 "Debug option set for zebra packet\n")
112{
113 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
114 zebra_debug_packet |= ZEBRA_DEBUG_SEND;
115 zebra_debug_packet |= ZEBRA_DEBUG_RECV;
116 return CMD_SUCCESS;
117}
118
119DEFUN (debug_zebra_packet_direct,
120 debug_zebra_packet_direct_cmd,
Lou Bergerd7be0422016-01-12 13:41:43 -0500121 "debug zebra packet (recv|send|detail)",
paul718e3742002-12-13 20:15:29 +0000122 DEBUG_STR
123 "Zebra configuration\n"
124 "Debug option set for zebra packet\n"
125 "Debug option set for receive packet\n"
126 "Debug option set for send packet\n")
127{
128 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
129 if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
130 zebra_debug_packet |= ZEBRA_DEBUG_SEND;
131 if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
132 zebra_debug_packet |= ZEBRA_DEBUG_RECV;
Lou Bergerd7be0422016-01-12 13:41:43 -0500133 if (strncmp ("detail", argv[0], strlen (argv[0])) == 0)
134 zebra_debug_packet |= ZEBRA_DEBUG_DETAIL;
paul718e3742002-12-13 20:15:29 +0000135 return CMD_SUCCESS;
136}
137
138DEFUN (debug_zebra_packet_detail,
139 debug_zebra_packet_detail_cmd,
140 "debug zebra packet (recv|send) detail",
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"
Christian Franke2b005152013-09-30 12:27:49 +0000146 "Debug option set detailed information\n")
paul718e3742002-12-13 20:15:29 +0000147{
148 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
149 if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
150 zebra_debug_packet |= ZEBRA_DEBUG_SEND;
151 if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
152 zebra_debug_packet |= ZEBRA_DEBUG_RECV;
153 zebra_debug_packet |= ZEBRA_DEBUG_DETAIL;
154 return CMD_SUCCESS;
155}
156
157DEFUN (debug_zebra_kernel,
158 debug_zebra_kernel_cmd,
159 "debug zebra kernel",
160 DEBUG_STR
161 "Zebra configuration\n"
162 "Debug option set for zebra between kernel interface\n")
163{
164 zebra_debug_kernel = ZEBRA_DEBUG_KERNEL;
165 return CMD_SUCCESS;
166}
167
Paul Jakmab0498dc2006-07-27 21:35:33 +0000168DEFUN (debug_zebra_rib,
169 debug_zebra_rib_cmd,
170 "debug zebra rib",
171 DEBUG_STR
172 "Zebra configuration\n"
173 "Debug RIB events\n")
174{
175 SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB);
176 return CMD_SUCCESS;
177}
178
179DEFUN (debug_zebra_rib_q,
180 debug_zebra_rib_q_cmd,
181 "debug zebra rib queue",
182 DEBUG_STR
183 "Zebra configuration\n"
184 "Debug RIB events\n"
185 "Debug RIB queueing\n")
186{
187 SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_Q);
188 return CMD_SUCCESS;
189}
190
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000191DEFUN (debug_zebra_fpm,
192 debug_zebra_fpm_cmd,
193 "debug zebra fpm",
194 DEBUG_STR
195 "Zebra configuration\n"
196 "Debug zebra FPM events\n")
197{
198 SET_FLAG (zebra_debug_fpm, ZEBRA_DEBUG_FPM);
199 return CMD_SUCCESS;
200}
201
paul718e3742002-12-13 20:15:29 +0000202DEFUN (no_debug_zebra_events,
203 no_debug_zebra_events_cmd,
204 "no debug zebra events",
205 NO_STR
206 DEBUG_STR
207 "Zebra configuration\n"
208 "Debug option set for zebra events\n")
209{
210 zebra_debug_event = 0;
211 return CMD_SUCCESS;
212}
213
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500214DEFUN (no_debug_zebra_nht,
215 no_debug_zebra_nht_cmd,
216 "no debug zebra nht",
217 NO_STR
218 DEBUG_STR
219 "Zebra configuration\n"
220 "Debug option set for zebra next hop tracking\n")
221{
222 zebra_debug_nht = 0;
223 return CMD_SUCCESS;
224}
225
paul718e3742002-12-13 20:15:29 +0000226DEFUN (no_debug_zebra_packet,
227 no_debug_zebra_packet_cmd,
228 "no debug zebra packet",
229 NO_STR
230 DEBUG_STR
231 "Zebra configuration\n"
232 "Debug option set for zebra packet\n")
233{
234 zebra_debug_packet = 0;
235 return CMD_SUCCESS;
236}
237
238DEFUN (no_debug_zebra_packet_direct,
239 no_debug_zebra_packet_direct_cmd,
240 "no debug zebra packet (recv|send)",
241 NO_STR
242 DEBUG_STR
243 "Zebra configuration\n"
244 "Debug option set for zebra packet\n"
245 "Debug option set for receive packet\n"
246 "Debug option set for send packet\n")
247{
248 if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
249 zebra_debug_packet &= ~ZEBRA_DEBUG_SEND;
250 if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
251 zebra_debug_packet &= ~ZEBRA_DEBUG_RECV;
252 return CMD_SUCCESS;
253}
254
255DEFUN (no_debug_zebra_kernel,
256 no_debug_zebra_kernel_cmd,
257 "no debug zebra kernel",
258 NO_STR
259 DEBUG_STR
260 "Zebra configuration\n"
261 "Debug option set for zebra between kernel interface\n")
262{
263 zebra_debug_kernel = 0;
264 return CMD_SUCCESS;
265}
266
Paul Jakmab0498dc2006-07-27 21:35:33 +0000267DEFUN (no_debug_zebra_rib,
268 no_debug_zebra_rib_cmd,
269 "no debug zebra rib",
270 NO_STR
271 DEBUG_STR
272 "Zebra configuration\n"
273 "Debug zebra RIB\n")
274{
275 zebra_debug_rib = 0;
276 return CMD_SUCCESS;
277}
278
279DEFUN (no_debug_zebra_rib_q,
280 no_debug_zebra_rib_q_cmd,
Stephen Hemmingere5248432008-08-17 18:08:24 +0100281 "no debug zebra rib queue",
Paul Jakmab0498dc2006-07-27 21:35:33 +0000282 NO_STR
283 DEBUG_STR
284 "Zebra configuration\n"
285 "Debug zebra RIB\n"
286 "Debug RIB queueing\n")
287{
288 UNSET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_Q);
289 return CMD_SUCCESS;
290}
291
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000292DEFUN (no_debug_zebra_fpm,
293 no_debug_zebra_fpm_cmd,
294 "no debug zebra fpm",
295 NO_STR
296 DEBUG_STR
297 "Zebra configuration\n"
298 "Debug zebra FPM events\n")
299{
300 zebra_debug_fpm = 0;
301 return CMD_SUCCESS;
302}
303
paul718e3742002-12-13 20:15:29 +0000304/* Debug node. */
305struct cmd_node debug_node =
306{
307 DEBUG_NODE,
308 "", /* Debug node has no interface. */
309 1
310};
311
paula1ac18c2005-06-28 17:17:12 +0000312static int
paul718e3742002-12-13 20:15:29 +0000313config_write_debug (struct vty *vty)
314{
315 int write = 0;
316
317 if (IS_ZEBRA_DEBUG_EVENT)
318 {
319 vty_out (vty, "debug zebra events%s", VTY_NEWLINE);
320 write++;
321 }
322 if (IS_ZEBRA_DEBUG_PACKET)
323 {
324 if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV)
325 {
326 vty_out (vty, "debug zebra packet%s%s",
327 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
328 VTY_NEWLINE);
329 write++;
330 }
331 else
332 {
333 if (IS_ZEBRA_DEBUG_SEND)
334 vty_out (vty, "debug zebra packet send%s%s",
335 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
336 VTY_NEWLINE);
337 else
338 vty_out (vty, "debug zebra packet recv%s%s",
339 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
340 VTY_NEWLINE);
341 write++;
342 }
343 }
344 if (IS_ZEBRA_DEBUG_KERNEL)
345 {
346 vty_out (vty, "debug zebra kernel%s", VTY_NEWLINE);
347 write++;
348 }
Paul Jakmab0498dc2006-07-27 21:35:33 +0000349 if (IS_ZEBRA_DEBUG_RIB)
350 {
351 vty_out (vty, "debug zebra rib%s", VTY_NEWLINE);
352 write++;
353 }
354 if (IS_ZEBRA_DEBUG_RIB_Q)
355 {
356 vty_out (vty, "debug zebra rib queue%s", VTY_NEWLINE);
357 write++;
358 }
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000359 if (IS_ZEBRA_DEBUG_FPM)
360 {
361 vty_out (vty, "debug zebra fpm%s", VTY_NEWLINE);
362 write++;
363 }
paul718e3742002-12-13 20:15:29 +0000364 return write;
365}
366
367void
paula1ac18c2005-06-28 17:17:12 +0000368zebra_debug_init (void)
paul718e3742002-12-13 20:15:29 +0000369{
370 zebra_debug_event = 0;
371 zebra_debug_packet = 0;
Paul Jakmab0498dc2006-07-27 21:35:33 +0000372 zebra_debug_kernel = 0;
373 zebra_debug_rib = 0;
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000374 zebra_debug_fpm = 0;
paul718e3742002-12-13 20:15:29 +0000375
376 install_node (&debug_node, config_write_debug);
377
378 install_element (VIEW_NODE, &show_debugging_zebra_cmd);
379
paul718e3742002-12-13 20:15:29 +0000380 install_element (ENABLE_NODE, &debug_zebra_events_cmd);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500381 install_element (ENABLE_NODE, &debug_zebra_nht_cmd);
paul718e3742002-12-13 20:15:29 +0000382 install_element (ENABLE_NODE, &debug_zebra_packet_cmd);
383 install_element (ENABLE_NODE, &debug_zebra_packet_direct_cmd);
384 install_element (ENABLE_NODE, &debug_zebra_packet_detail_cmd);
385 install_element (ENABLE_NODE, &debug_zebra_kernel_cmd);
Paul Jakmab0498dc2006-07-27 21:35:33 +0000386 install_element (ENABLE_NODE, &debug_zebra_rib_cmd);
387 install_element (ENABLE_NODE, &debug_zebra_rib_q_cmd);
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000388 install_element (ENABLE_NODE, &debug_zebra_fpm_cmd);
paul718e3742002-12-13 20:15:29 +0000389 install_element (ENABLE_NODE, &no_debug_zebra_events_cmd);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500390 install_element (ENABLE_NODE, &no_debug_zebra_nht_cmd);
paul718e3742002-12-13 20:15:29 +0000391 install_element (ENABLE_NODE, &no_debug_zebra_packet_cmd);
392 install_element (ENABLE_NODE, &no_debug_zebra_kernel_cmd);
Paul Jakmab0498dc2006-07-27 21:35:33 +0000393 install_element (ENABLE_NODE, &no_debug_zebra_rib_cmd);
394 install_element (ENABLE_NODE, &no_debug_zebra_rib_q_cmd);
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000395 install_element (ENABLE_NODE, &no_debug_zebra_fpm_cmd);
paul718e3742002-12-13 20:15:29 +0000396
397 install_element (CONFIG_NODE, &debug_zebra_events_cmd);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500398 install_element (CONFIG_NODE, &debug_zebra_nht_cmd);
paul718e3742002-12-13 20:15:29 +0000399 install_element (CONFIG_NODE, &debug_zebra_packet_cmd);
400 install_element (CONFIG_NODE, &debug_zebra_packet_direct_cmd);
401 install_element (CONFIG_NODE, &debug_zebra_packet_detail_cmd);
402 install_element (CONFIG_NODE, &debug_zebra_kernel_cmd);
Paul Jakmab0498dc2006-07-27 21:35:33 +0000403 install_element (CONFIG_NODE, &debug_zebra_rib_cmd);
404 install_element (CONFIG_NODE, &debug_zebra_rib_q_cmd);
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000405 install_element (CONFIG_NODE, &debug_zebra_fpm_cmd);
paul718e3742002-12-13 20:15:29 +0000406 install_element (CONFIG_NODE, &no_debug_zebra_events_cmd);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500407 install_element (CONFIG_NODE, &no_debug_zebra_nht_cmd);
paul718e3742002-12-13 20:15:29 +0000408 install_element (CONFIG_NODE, &no_debug_zebra_packet_cmd);
409 install_element (CONFIG_NODE, &no_debug_zebra_kernel_cmd);
Paul Jakmab0498dc2006-07-27 21:35:33 +0000410 install_element (CONFIG_NODE, &no_debug_zebra_rib_cmd);
411 install_element (CONFIG_NODE, &no_debug_zebra_rib_q_cmd);
Avneesh Sachdev5adc2522012-11-13 22:48:59 +0000412 install_element (CONFIG_NODE, &no_debug_zebra_fpm_cmd);
paul718e3742002-12-13 20:15:29 +0000413}