blob: 23c4de3a498a9c9242c60d8bc9dd26ec6b36b276 [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;
paul718e3742002-12-13 20:15:29 +000032
33DEFUN (show_debugging_zebra,
34 show_debugging_zebra_cmd,
35 "show debugging zebra",
36 SHOW_STR
37 "Zebra configuration\n"
38 "Debugging information\n")
39{
40 vty_out (vty, "Zebra debugging status:%s", VTY_NEWLINE);
41
42 if (IS_ZEBRA_DEBUG_EVENT)
43 vty_out (vty, " Zebra event debugging is on%s", VTY_NEWLINE);
44
45 if (IS_ZEBRA_DEBUG_PACKET)
46 {
47 if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV)
48 {
49 vty_out (vty, " Zebra packet%s debugging is on%s",
50 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
51 VTY_NEWLINE);
52 }
53 else
54 {
55 if (IS_ZEBRA_DEBUG_SEND)
56 vty_out (vty, " Zebra packet send%s debugging is on%s",
57 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
58 VTY_NEWLINE);
59 else
60 vty_out (vty, " Zebra packet receive%s debugging is on%s",
61 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
62 VTY_NEWLINE);
63 }
64 }
65
66 if (IS_ZEBRA_DEBUG_KERNEL)
67 vty_out (vty, " Zebra kernel debugging is on%s", VTY_NEWLINE);
68
Paul Jakmab0498dc2006-07-27 21:35:33 +000069 if (IS_ZEBRA_DEBUG_RIB)
70 vty_out (vty, " Zebra RIB debugging is on%s", VTY_NEWLINE);
71 if (IS_ZEBRA_DEBUG_RIB_Q)
72 vty_out (vty, " Zebra RIB queue debugging is on%s", VTY_NEWLINE);
73
paul718e3742002-12-13 20:15:29 +000074 return CMD_SUCCESS;
75}
76
77DEFUN (debug_zebra_events,
78 debug_zebra_events_cmd,
79 "debug zebra events",
80 DEBUG_STR
81 "Zebra configuration\n"
82 "Debug option set for zebra events\n")
83{
84 zebra_debug_event = ZEBRA_DEBUG_EVENT;
85 return CMD_WARNING;
86}
87
88DEFUN (debug_zebra_packet,
89 debug_zebra_packet_cmd,
90 "debug zebra packet",
91 DEBUG_STR
92 "Zebra configuration\n"
93 "Debug option set for zebra packet\n")
94{
95 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
96 zebra_debug_packet |= ZEBRA_DEBUG_SEND;
97 zebra_debug_packet |= ZEBRA_DEBUG_RECV;
98 return CMD_SUCCESS;
99}
100
101DEFUN (debug_zebra_packet_direct,
102 debug_zebra_packet_direct_cmd,
103 "debug zebra packet (recv|send)",
104 DEBUG_STR
105 "Zebra configuration\n"
106 "Debug option set for zebra packet\n"
107 "Debug option set for receive packet\n"
108 "Debug option set for send packet\n")
109{
110 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
111 if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
112 zebra_debug_packet |= ZEBRA_DEBUG_SEND;
113 if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
114 zebra_debug_packet |= ZEBRA_DEBUG_RECV;
115 zebra_debug_packet &= ~ZEBRA_DEBUG_DETAIL;
116 return CMD_SUCCESS;
117}
118
119DEFUN (debug_zebra_packet_detail,
120 debug_zebra_packet_detail_cmd,
121 "debug zebra packet (recv|send) detail",
122 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 "Debug option set detaied information\n")
128{
129 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
130 if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
131 zebra_debug_packet |= ZEBRA_DEBUG_SEND;
132 if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
133 zebra_debug_packet |= ZEBRA_DEBUG_RECV;
134 zebra_debug_packet |= ZEBRA_DEBUG_DETAIL;
135 return CMD_SUCCESS;
136}
137
138DEFUN (debug_zebra_kernel,
139 debug_zebra_kernel_cmd,
140 "debug zebra kernel",
141 DEBUG_STR
142 "Zebra configuration\n"
143 "Debug option set for zebra between kernel interface\n")
144{
145 zebra_debug_kernel = ZEBRA_DEBUG_KERNEL;
146 return CMD_SUCCESS;
147}
148
Paul Jakmab0498dc2006-07-27 21:35:33 +0000149DEFUN (debug_zebra_rib,
150 debug_zebra_rib_cmd,
151 "debug zebra rib",
152 DEBUG_STR
153 "Zebra configuration\n"
154 "Debug RIB events\n")
155{
156 SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB);
157 return CMD_SUCCESS;
158}
159
160DEFUN (debug_zebra_rib_q,
161 debug_zebra_rib_q_cmd,
162 "debug zebra rib queue",
163 DEBUG_STR
164 "Zebra configuration\n"
165 "Debug RIB events\n"
166 "Debug RIB queueing\n")
167{
168 SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_Q);
169 return CMD_SUCCESS;
170}
171
paul718e3742002-12-13 20:15:29 +0000172DEFUN (no_debug_zebra_events,
173 no_debug_zebra_events_cmd,
174 "no debug zebra events",
175 NO_STR
176 DEBUG_STR
177 "Zebra configuration\n"
178 "Debug option set for zebra events\n")
179{
180 zebra_debug_event = 0;
181 return CMD_SUCCESS;
182}
183
184DEFUN (no_debug_zebra_packet,
185 no_debug_zebra_packet_cmd,
186 "no debug zebra packet",
187 NO_STR
188 DEBUG_STR
189 "Zebra configuration\n"
190 "Debug option set for zebra packet\n")
191{
192 zebra_debug_packet = 0;
193 return CMD_SUCCESS;
194}
195
196DEFUN (no_debug_zebra_packet_direct,
197 no_debug_zebra_packet_direct_cmd,
198 "no debug zebra packet (recv|send)",
199 NO_STR
200 DEBUG_STR
201 "Zebra configuration\n"
202 "Debug option set for zebra packet\n"
203 "Debug option set for receive packet\n"
204 "Debug option set for send packet\n")
205{
206 if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
207 zebra_debug_packet &= ~ZEBRA_DEBUG_SEND;
208 if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
209 zebra_debug_packet &= ~ZEBRA_DEBUG_RECV;
210 return CMD_SUCCESS;
211}
212
213DEFUN (no_debug_zebra_kernel,
214 no_debug_zebra_kernel_cmd,
215 "no debug zebra kernel",
216 NO_STR
217 DEBUG_STR
218 "Zebra configuration\n"
219 "Debug option set for zebra between kernel interface\n")
220{
221 zebra_debug_kernel = 0;
222 return CMD_SUCCESS;
223}
224
Paul Jakmab0498dc2006-07-27 21:35:33 +0000225DEFUN (no_debug_zebra_rib,
226 no_debug_zebra_rib_cmd,
227 "no debug zebra rib",
228 NO_STR
229 DEBUG_STR
230 "Zebra configuration\n"
231 "Debug zebra RIB\n")
232{
233 zebra_debug_rib = 0;
234 return CMD_SUCCESS;
235}
236
237DEFUN (no_debug_zebra_rib_q,
238 no_debug_zebra_rib_q_cmd,
239 "no debug zebra rib queueu",
240 NO_STR
241 DEBUG_STR
242 "Zebra configuration\n"
243 "Debug zebra RIB\n"
244 "Debug RIB queueing\n")
245{
246 UNSET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_Q);
247 return CMD_SUCCESS;
248}
249
paul718e3742002-12-13 20:15:29 +0000250/* Debug node. */
251struct cmd_node debug_node =
252{
253 DEBUG_NODE,
254 "", /* Debug node has no interface. */
255 1
256};
257
paula1ac18c2005-06-28 17:17:12 +0000258static int
paul718e3742002-12-13 20:15:29 +0000259config_write_debug (struct vty *vty)
260{
261 int write = 0;
262
263 if (IS_ZEBRA_DEBUG_EVENT)
264 {
265 vty_out (vty, "debug zebra events%s", VTY_NEWLINE);
266 write++;
267 }
268 if (IS_ZEBRA_DEBUG_PACKET)
269 {
270 if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV)
271 {
272 vty_out (vty, "debug zebra packet%s%s",
273 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
274 VTY_NEWLINE);
275 write++;
276 }
277 else
278 {
279 if (IS_ZEBRA_DEBUG_SEND)
280 vty_out (vty, "debug zebra packet send%s%s",
281 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
282 VTY_NEWLINE);
283 else
284 vty_out (vty, "debug zebra packet recv%s%s",
285 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
286 VTY_NEWLINE);
287 write++;
288 }
289 }
290 if (IS_ZEBRA_DEBUG_KERNEL)
291 {
292 vty_out (vty, "debug zebra kernel%s", VTY_NEWLINE);
293 write++;
294 }
Paul Jakmab0498dc2006-07-27 21:35:33 +0000295 if (IS_ZEBRA_DEBUG_RIB)
296 {
297 vty_out (vty, "debug zebra rib%s", VTY_NEWLINE);
298 write++;
299 }
300 if (IS_ZEBRA_DEBUG_RIB_Q)
301 {
302 vty_out (vty, "debug zebra rib queue%s", VTY_NEWLINE);
303 write++;
304 }
paul718e3742002-12-13 20:15:29 +0000305 return write;
306}
307
308void
paula1ac18c2005-06-28 17:17:12 +0000309zebra_debug_init (void)
paul718e3742002-12-13 20:15:29 +0000310{
311 zebra_debug_event = 0;
312 zebra_debug_packet = 0;
Paul Jakmab0498dc2006-07-27 21:35:33 +0000313 zebra_debug_kernel = 0;
314 zebra_debug_rib = 0;
paul718e3742002-12-13 20:15:29 +0000315
316 install_node (&debug_node, config_write_debug);
317
318 install_element (VIEW_NODE, &show_debugging_zebra_cmd);
319
320 install_element (ENABLE_NODE, &show_debugging_zebra_cmd);
321 install_element (ENABLE_NODE, &debug_zebra_events_cmd);
322 install_element (ENABLE_NODE, &debug_zebra_packet_cmd);
323 install_element (ENABLE_NODE, &debug_zebra_packet_direct_cmd);
324 install_element (ENABLE_NODE, &debug_zebra_packet_detail_cmd);
325 install_element (ENABLE_NODE, &debug_zebra_kernel_cmd);
Paul Jakmab0498dc2006-07-27 21:35:33 +0000326 install_element (ENABLE_NODE, &debug_zebra_rib_cmd);
327 install_element (ENABLE_NODE, &debug_zebra_rib_q_cmd);
paul718e3742002-12-13 20:15:29 +0000328 install_element (ENABLE_NODE, &no_debug_zebra_events_cmd);
329 install_element (ENABLE_NODE, &no_debug_zebra_packet_cmd);
330 install_element (ENABLE_NODE, &no_debug_zebra_kernel_cmd);
Paul Jakmab0498dc2006-07-27 21:35:33 +0000331 install_element (ENABLE_NODE, &no_debug_zebra_rib_cmd);
332 install_element (ENABLE_NODE, &no_debug_zebra_rib_q_cmd);
paul718e3742002-12-13 20:15:29 +0000333
334 install_element (CONFIG_NODE, &debug_zebra_events_cmd);
335 install_element (CONFIG_NODE, &debug_zebra_packet_cmd);
336 install_element (CONFIG_NODE, &debug_zebra_packet_direct_cmd);
337 install_element (CONFIG_NODE, &debug_zebra_packet_detail_cmd);
338 install_element (CONFIG_NODE, &debug_zebra_kernel_cmd);
Paul Jakmab0498dc2006-07-27 21:35:33 +0000339 install_element (CONFIG_NODE, &debug_zebra_rib_cmd);
340 install_element (CONFIG_NODE, &debug_zebra_rib_q_cmd);
paul718e3742002-12-13 20:15:29 +0000341 install_element (CONFIG_NODE, &no_debug_zebra_events_cmd);
342 install_element (CONFIG_NODE, &no_debug_zebra_packet_cmd);
343 install_element (CONFIG_NODE, &no_debug_zebra_kernel_cmd);
Paul Jakmab0498dc2006-07-27 21:35:33 +0000344 install_element (CONFIG_NODE, &no_debug_zebra_rib_cmd);
345 install_element (CONFIG_NODE, &no_debug_zebra_rib_q_cmd);
paul718e3742002-12-13 20:15:29 +0000346}