New upstream release and new maintainer
[quagga-debian.git] / zebra / debug.c
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. */
28 unsigned long zebra_debug_event;
29 unsigned long zebra_debug_packet;
30 unsigned long zebra_debug_kernel;
31 unsigned long zebra_debug_rib;
32 unsigned long zebra_debug_fpm;
33 unsigned long zebra_debug_nht;
34
35 DEFUN (show_debugging_zebra,
36        show_debugging_zebra_cmd,
37        "show debugging zebra",
38        SHOW_STR
39        "Debugging information\n"
40        "Zebra configuration\n")
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);
70
71   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
76   if (IS_ZEBRA_DEBUG_FPM)
77     vty_out (vty, "  Zebra FPM debugging is on%s", VTY_NEWLINE);
78   if (IS_ZEBRA_DEBUG_NHT)
79     vty_out (vty, "  Zebra next-hop tracking debugging is on%s", VTY_NEWLINE);
80
81   return CMD_SUCCESS;
82 }
83
84 DEFUN (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
95 DEFUN (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
106 DEFUN (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   SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
115   SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
116   return CMD_SUCCESS;
117 }
118
119 DEFUN (debug_zebra_packet_direct,
120        debug_zebra_packet_direct_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 {
128   zebra_debug_packet = ZEBRA_DEBUG_PACKET;
129   if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
130     SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
131   if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
132     SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
133   if (strncmp ("detail", argv[0], strlen (argv[0])) == 0)
134     SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL);
135   return CMD_SUCCESS;
136 }
137
138 DEFUN (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"
146        "Debug option set detailed information\n")
147 {
148   zebra_debug_packet = ZEBRA_DEBUG_PACKET;
149   if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
150     SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
151   if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
152     SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
153   SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL);
154   return CMD_SUCCESS;
155 }
156
157 DEFUN (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
168 DEFUN (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
179 DEFUN (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
191 DEFUN (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
202 DEFUN (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
214 DEFUN (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
226 DEFUN (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
238 DEFUN (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     UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
250   if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
251     UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
252   return CMD_SUCCESS;
253 }
254
255 DEFUN (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
267 DEFUN (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
279 DEFUN (no_debug_zebra_rib_q,
280        no_debug_zebra_rib_q_cmd,
281        "no debug zebra rib queue",
282        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
292 DEFUN (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
304 /* Debug node. */
305 struct cmd_node debug_node =
306 {
307   DEBUG_NODE,
308   "",                           /* Debug node has no interface. */
309   1
310 };
311
312 static int
313 config_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     }
349   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     }
359   if (IS_ZEBRA_DEBUG_FPM)
360     {
361       vty_out (vty, "debug zebra fpm%s", VTY_NEWLINE);
362       write++;
363     }
364   return write;
365 }
366
367 void
368 zebra_debug_init (void)
369 {
370   zebra_debug_event = 0;
371   zebra_debug_packet = 0;
372   zebra_debug_kernel = 0;
373   zebra_debug_rib = 0;
374   zebra_debug_fpm = 0;
375
376   install_node (&debug_node, config_write_debug);
377
378   install_element (VIEW_NODE, &show_debugging_zebra_cmd);
379
380   install_element (ENABLE_NODE, &debug_zebra_events_cmd);
381   install_element (ENABLE_NODE, &debug_zebra_nht_cmd);
382   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);
386   install_element (ENABLE_NODE, &debug_zebra_rib_cmd);
387   install_element (ENABLE_NODE, &debug_zebra_rib_q_cmd);
388   install_element (ENABLE_NODE, &debug_zebra_fpm_cmd);
389   install_element (ENABLE_NODE, &no_debug_zebra_events_cmd);
390   install_element (ENABLE_NODE, &no_debug_zebra_nht_cmd);
391   install_element (ENABLE_NODE, &no_debug_zebra_packet_cmd);
392   install_element (ENABLE_NODE, &no_debug_zebra_kernel_cmd);
393   install_element (ENABLE_NODE, &no_debug_zebra_rib_cmd);
394   install_element (ENABLE_NODE, &no_debug_zebra_rib_q_cmd);
395   install_element (ENABLE_NODE, &no_debug_zebra_fpm_cmd);
396
397   install_element (CONFIG_NODE, &debug_zebra_events_cmd);
398   install_element (CONFIG_NODE, &debug_zebra_nht_cmd);
399   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);
403   install_element (CONFIG_NODE, &debug_zebra_rib_cmd);
404   install_element (CONFIG_NODE, &debug_zebra_rib_q_cmd);
405   install_element (CONFIG_NODE, &debug_zebra_fpm_cmd);
406   install_element (CONFIG_NODE, &no_debug_zebra_events_cmd);
407   install_element (CONFIG_NODE, &no_debug_zebra_nht_cmd);
408   install_element (CONFIG_NODE, &no_debug_zebra_packet_cmd);
409   install_element (CONFIG_NODE, &no_debug_zebra_kernel_cmd);
410   install_element (CONFIG_NODE, &no_debug_zebra_rib_cmd);
411   install_element (CONFIG_NODE, &no_debug_zebra_rib_q_cmd);
412   install_element (CONFIG_NODE, &no_debug_zebra_fpm_cmd);
413 }