]> git.proxmox.com Git - mirror_frr.git/blob - zebra/debug.c
zebra: argv update for all but zebra_vty.c
[mirror_frr.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 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);
74
75 /* Check here using flags as the 'macro' does an OR */
76 if (CHECK_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB))
77 vty_out (vty, " Zebra RIB debugging is on%s", VTY_NEWLINE);
78 if (CHECK_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED))
79 vty_out (vty, " Zebra RIB detailed debugging is on%s", VTY_NEWLINE);
80
81 if (IS_ZEBRA_DEBUG_FPM)
82 vty_out (vty, " Zebra FPM debugging is on%s", VTY_NEWLINE);
83 if (IS_ZEBRA_DEBUG_NHT)
84 vty_out (vty, " Zebra next-hop tracking debugging is on%s", VTY_NEWLINE);
85
86 return CMD_SUCCESS;
87 }
88
89 DEFUN (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
100 DEFUN (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
111 DEFUN (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;
119 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
120 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
121 return CMD_SUCCESS;
122 }
123
124 DEFUN (debug_zebra_packet_direct,
125 debug_zebra_packet_direct_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")
132 {
133 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
134 if (strncmp ("send", argv[3]->arg, strlen (argv[3]->arg)) == 0)
135 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
136 if (strncmp ("recv", argv[3]->arg, strlen (argv[3]->arg)) == 0)
137 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
138 if (strncmp ("detail", argv[3]->arg, strlen (argv[3]->arg)) == 0)
139 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL);
140 return CMD_SUCCESS;
141 }
142
143 DEFUN (debug_zebra_packet_detail,
144 debug_zebra_packet_detail_cmd,
145 "debug zebra packet (recv|send) detail",
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"
151 "Debug option set detailed information\n")
152 {
153 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
154 if (strncmp ("send", argv[3]->arg, strlen (argv[3]->arg)) == 0)
155 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
156 if (strncmp ("recv", argv[3]->arg, strlen (argv[3]->arg)) == 0)
157 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
158 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL);
159 return CMD_SUCCESS;
160 }
161
162 DEFUN (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 {
169 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL);
170 return CMD_SUCCESS;
171 }
172
173 DEFUN (debug_zebra_kernel_msgdump,
174 debug_zebra_kernel_msgdump_cmd,
175 "debug zebra kernel msgdump {recv|send}",
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 {
183 if (argv[4]->arg && strncmp(argv[4]->arg, "recv", strlen(argv[4]->arg)) == 0)
184 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
185 if (!argv[4]->arg || strncmp(argv[4]->arg, "send", strlen(argv[4]->arg)) == 0)
186 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
187 return CMD_SUCCESS;
188 }
189
190 DEFUN (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
201 DEFUN (debug_zebra_rib_detailed,
202 debug_zebra_rib_detailed_cmd,
203 "debug zebra rib detailed",
204 DEBUG_STR
205 "Zebra configuration\n"
206 "Debug RIB events\n"
207 "Detailed debugs\n")
208 {
209 SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED);
210 return CMD_SUCCESS;
211 }
212
213 DEFUN (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
224 DEFUN (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
236 DEFUN (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
248 DEFUN (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
260 DEFUN (no_debug_zebra_packet_direct,
261 no_debug_zebra_packet_direct_cmd,
262 "no debug zebra packet (recv|send)",
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 {
270 if (strncmp ("send", argv[4]->arg, strlen (argv[4]->arg)) == 0)
271 UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
272 if (strncmp ("recv", argv[4]->arg, strlen (argv[4]->arg)) == 0)
273 UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
274 return CMD_SUCCESS;
275 }
276
277 DEFUN (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 {
285 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL);
286 return CMD_SUCCESS;
287 }
288
289 DEFUN (no_debug_zebra_kernel_msgdump,
290 no_debug_zebra_kernel_msgdump_cmd,
291 "no debug zebra kernel msgdump {recv|send}",
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 {
299 if (!argv[1] || (argv[5]->arg && strncmp(argv[5]->arg, "recv", strlen(argv[5]->arg)) == 0))
300 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
301 if (!argv[5]->arg || (argv[5]->arg && strncmp(argv[5]->arg, "send", strlen(argv[5]->arg)) == 0))
302 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
303 return CMD_SUCCESS;
304 }
305
306 DEFUN (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
318 DEFUN (no_debug_zebra_rib_detailed,
319 no_debug_zebra_rib_detailed_cmd,
320 "no debug zebra rib detailed",
321 NO_STR
322 DEBUG_STR
323 "Zebra configuration\n"
324 "Debug zebra RIB\n"
325 "Detailed debugs\n")
326 {
327 UNSET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED);
328 return CMD_SUCCESS;
329 }
330
331 DEFUN (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
343 /* Debug node. */
344 struct cmd_node debug_node =
345 {
346 DEBUG_NODE,
347 "", /* Debug node has no interface. */
348 1
349 };
350
351 static int
352 config_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 }
388 /* Check here using flags as the 'macro' does an OR */
389 if (CHECK_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB))
390 {
391 vty_out (vty, "debug zebra rib%s", VTY_NEWLINE);
392 write++;
393 }
394 if (CHECK_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED))
395 {
396 vty_out (vty, "debug zebra rib detailed%s", VTY_NEWLINE);
397 write++;
398 }
399 if (IS_ZEBRA_DEBUG_FPM)
400 {
401 vty_out (vty, "debug zebra fpm%s", VTY_NEWLINE);
402 write++;
403 }
404 return write;
405 }
406
407 void
408 zebra_debug_init (void)
409 {
410 zebra_debug_event = 0;
411 zebra_debug_packet = 0;
412 zebra_debug_kernel = 0;
413 zebra_debug_rib = 0;
414 zebra_debug_fpm = 0;
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);
422 install_element (ENABLE_NODE, &debug_zebra_nht_cmd);
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);
427 install_element (ENABLE_NODE, &debug_zebra_kernel_msgdump_cmd);
428 install_element (ENABLE_NODE, &debug_zebra_rib_cmd);
429 install_element (ENABLE_NODE, &debug_zebra_rib_detailed_cmd);
430 install_element (ENABLE_NODE, &debug_zebra_fpm_cmd);
431 install_element (ENABLE_NODE, &no_debug_zebra_events_cmd);
432 install_element (ENABLE_NODE, &no_debug_zebra_nht_cmd);
433 install_element (ENABLE_NODE, &no_debug_zebra_packet_cmd);
434 install_element (ENABLE_NODE, &no_debug_zebra_kernel_cmd);
435 install_element (ENABLE_NODE, &no_debug_zebra_kernel_msgdump_cmd);
436 install_element (ENABLE_NODE, &no_debug_zebra_rib_cmd);
437 install_element (ENABLE_NODE, &no_debug_zebra_rib_detailed_cmd);
438 install_element (ENABLE_NODE, &no_debug_zebra_fpm_cmd);
439
440 install_element (CONFIG_NODE, &debug_zebra_events_cmd);
441 install_element (CONFIG_NODE, &debug_zebra_nht_cmd);
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);
446 install_element (CONFIG_NODE, &debug_zebra_kernel_msgdump_cmd);
447 install_element (CONFIG_NODE, &debug_zebra_rib_cmd);
448 install_element (CONFIG_NODE, &debug_zebra_rib_detailed_cmd);
449 install_element (CONFIG_NODE, &debug_zebra_fpm_cmd);
450 install_element (CONFIG_NODE, &no_debug_zebra_events_cmd);
451 install_element (CONFIG_NODE, &no_debug_zebra_nht_cmd);
452 install_element (CONFIG_NODE, &no_debug_zebra_packet_cmd);
453 install_element (CONFIG_NODE, &no_debug_zebra_kernel_cmd);
454 install_element (CONFIG_NODE, &no_debug_zebra_kernel_msgdump_cmd);
455 install_element (CONFIG_NODE, &no_debug_zebra_rib_cmd);
456 install_element (CONFIG_NODE, &no_debug_zebra_rib_detailed_cmd);
457 install_element (CONFIG_NODE, &no_debug_zebra_fpm_cmd);
458 }