]> git.proxmox.com Git - mirror_frr.git/blob - zebra/debug.c
all: added some missing <>s within []s
[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 int idx_recv_send = 3;
134 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
135 if (strncmp ("send", argv[idx_recv_send]->arg, strlen (argv[idx_recv_send]->arg)) == 0)
136 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
137 if (strncmp ("recv", argv[idx_recv_send]->arg, strlen (argv[idx_recv_send]->arg)) == 0)
138 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
139 if (strncmp ("detail", argv[idx_recv_send]->arg, strlen (argv[idx_recv_send]->arg)) == 0)
140 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL);
141 return CMD_SUCCESS;
142 }
143
144 DEFUN (debug_zebra_packet_detail,
145 debug_zebra_packet_detail_cmd,
146 "debug zebra packet <recv|send> detail",
147 DEBUG_STR
148 "Zebra configuration\n"
149 "Debug option set for zebra packet\n"
150 "Debug option set for receive packet\n"
151 "Debug option set for send packet\n"
152 "Debug option set detailed information\n")
153 {
154 int idx_recv_send = 3;
155 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
156 if (strncmp ("send", argv[idx_recv_send]->arg, strlen (argv[idx_recv_send]->arg)) == 0)
157 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
158 if (strncmp ("recv", argv[idx_recv_send]->arg, strlen (argv[idx_recv_send]->arg)) == 0)
159 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
160 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL);
161 return CMD_SUCCESS;
162 }
163
164 DEFUN (debug_zebra_kernel,
165 debug_zebra_kernel_cmd,
166 "debug zebra kernel",
167 DEBUG_STR
168 "Zebra configuration\n"
169 "Debug option set for zebra between kernel interface\n")
170 {
171 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL);
172 return CMD_SUCCESS;
173 }
174
175 DEFUN (debug_zebra_kernel_msgdump,
176 debug_zebra_kernel_msgdump_cmd,
177 "debug zebra kernel msgdump [<recv|send>]",
178 DEBUG_STR
179 "Zebra configuration\n"
180 "Debug option set for zebra between kernel interface\n"
181 "Dump raw netlink messages, sent and received\n"
182 "Dump raw netlink messages received\n"
183 "Dump raw netlink messages sent\n")
184 {
185 int idx_recv_send = 4;
186 if (argv[idx_recv_send]->arg && strncmp(argv[idx_recv_send]->arg, "recv", strlen(argv[idx_recv_send]->arg)) == 0)
187 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
188 if (!argv[idx_recv_send]->arg || strncmp(argv[idx_recv_send]->arg, "send", strlen(argv[idx_recv_send]->arg)) == 0)
189 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
190 return CMD_SUCCESS;
191 }
192
193 DEFUN (debug_zebra_rib,
194 debug_zebra_rib_cmd,
195 "debug zebra rib",
196 DEBUG_STR
197 "Zebra configuration\n"
198 "Debug RIB events\n")
199 {
200 SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB);
201 return CMD_SUCCESS;
202 }
203
204 DEFUN (debug_zebra_rib_detailed,
205 debug_zebra_rib_detailed_cmd,
206 "debug zebra rib detailed",
207 DEBUG_STR
208 "Zebra configuration\n"
209 "Debug RIB events\n"
210 "Detailed debugs\n")
211 {
212 SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED);
213 return CMD_SUCCESS;
214 }
215
216 DEFUN (debug_zebra_fpm,
217 debug_zebra_fpm_cmd,
218 "debug zebra fpm",
219 DEBUG_STR
220 "Zebra configuration\n"
221 "Debug zebra FPM events\n")
222 {
223 SET_FLAG (zebra_debug_fpm, ZEBRA_DEBUG_FPM);
224 return CMD_SUCCESS;
225 }
226
227 DEFUN (no_debug_zebra_events,
228 no_debug_zebra_events_cmd,
229 "no debug zebra events",
230 NO_STR
231 DEBUG_STR
232 "Zebra configuration\n"
233 "Debug option set for zebra events\n")
234 {
235 zebra_debug_event = 0;
236 return CMD_SUCCESS;
237 }
238
239 DEFUN (no_debug_zebra_nht,
240 no_debug_zebra_nht_cmd,
241 "no debug zebra nht",
242 NO_STR
243 DEBUG_STR
244 "Zebra configuration\n"
245 "Debug option set for zebra next hop tracking\n")
246 {
247 zebra_debug_nht = 0;
248 return CMD_SUCCESS;
249 }
250
251 DEFUN (no_debug_zebra_packet,
252 no_debug_zebra_packet_cmd,
253 "no debug zebra packet",
254 NO_STR
255 DEBUG_STR
256 "Zebra configuration\n"
257 "Debug option set for zebra packet\n")
258 {
259 zebra_debug_packet = 0;
260 return CMD_SUCCESS;
261 }
262
263 DEFUN (no_debug_zebra_packet_direct,
264 no_debug_zebra_packet_direct_cmd,
265 "no debug zebra packet <recv|send>",
266 NO_STR
267 DEBUG_STR
268 "Zebra configuration\n"
269 "Debug option set for zebra packet\n"
270 "Debug option set for receive packet\n"
271 "Debug option set for send packet\n")
272 {
273 int idx_recv_send = 4;
274 if (strncmp ("send", argv[idx_recv_send]->arg, strlen (argv[idx_recv_send]->arg)) == 0)
275 UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
276 if (strncmp ("recv", argv[idx_recv_send]->arg, strlen (argv[idx_recv_send]->arg)) == 0)
277 UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
278 return CMD_SUCCESS;
279 }
280
281 DEFUN (no_debug_zebra_kernel,
282 no_debug_zebra_kernel_cmd,
283 "no debug zebra kernel",
284 NO_STR
285 DEBUG_STR
286 "Zebra configuration\n"
287 "Debug option set for zebra between kernel interface\n")
288 {
289 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL);
290 return CMD_SUCCESS;
291 }
292
293 DEFUN (no_debug_zebra_kernel_msgdump,
294 no_debug_zebra_kernel_msgdump_cmd,
295 "no debug zebra kernel msgdump [<recv|send>]",
296 DEBUG_STR
297 "Zebra configuration\n"
298 "Debug option set for zebra between kernel interface\n"
299 "Dump raw netlink messages, sent and received\n"
300 "Dump raw netlink messages received\n"
301 "Dump raw netlink messages sent\n")
302 {
303 int idx_recv_send = 5;
304 if (!argv[1] || (argv[idx_recv_send]->arg && strncmp(argv[idx_recv_send]->arg, "recv", strlen(argv[idx_recv_send]->arg)) == 0))
305 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
306 if (!argv[idx_recv_send]->arg || (argv[idx_recv_send]->arg && strncmp(argv[idx_recv_send]->arg, "send", strlen(argv[idx_recv_send]->arg)) == 0))
307 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
308 return CMD_SUCCESS;
309 }
310
311 DEFUN (no_debug_zebra_rib,
312 no_debug_zebra_rib_cmd,
313 "no debug zebra rib",
314 NO_STR
315 DEBUG_STR
316 "Zebra configuration\n"
317 "Debug zebra RIB\n")
318 {
319 zebra_debug_rib = 0;
320 return CMD_SUCCESS;
321 }
322
323 DEFUN (no_debug_zebra_rib_detailed,
324 no_debug_zebra_rib_detailed_cmd,
325 "no debug zebra rib detailed",
326 NO_STR
327 DEBUG_STR
328 "Zebra configuration\n"
329 "Debug zebra RIB\n"
330 "Detailed debugs\n")
331 {
332 UNSET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED);
333 return CMD_SUCCESS;
334 }
335
336 DEFUN (no_debug_zebra_fpm,
337 no_debug_zebra_fpm_cmd,
338 "no debug zebra fpm",
339 NO_STR
340 DEBUG_STR
341 "Zebra configuration\n"
342 "Debug zebra FPM events\n")
343 {
344 zebra_debug_fpm = 0;
345 return CMD_SUCCESS;
346 }
347
348 /* Debug node. */
349 struct cmd_node debug_node =
350 {
351 DEBUG_NODE,
352 "", /* Debug node has no interface. */
353 1
354 };
355
356 static int
357 config_write_debug (struct vty *vty)
358 {
359 int write = 0;
360
361 if (IS_ZEBRA_DEBUG_EVENT)
362 {
363 vty_out (vty, "debug zebra events%s", VTY_NEWLINE);
364 write++;
365 }
366 if (IS_ZEBRA_DEBUG_PACKET)
367 {
368 if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV)
369 {
370 vty_out (vty, "debug zebra packet%s%s",
371 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
372 VTY_NEWLINE);
373 write++;
374 }
375 else
376 {
377 if (IS_ZEBRA_DEBUG_SEND)
378 vty_out (vty, "debug zebra packet send%s%s",
379 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
380 VTY_NEWLINE);
381 else
382 vty_out (vty, "debug zebra packet recv%s%s",
383 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "",
384 VTY_NEWLINE);
385 write++;
386 }
387 }
388 if (IS_ZEBRA_DEBUG_KERNEL)
389 {
390 vty_out (vty, "debug zebra kernel%s", VTY_NEWLINE);
391 write++;
392 }
393 /* Check here using flags as the 'macro' does an OR */
394 if (CHECK_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB))
395 {
396 vty_out (vty, "debug zebra rib%s", VTY_NEWLINE);
397 write++;
398 }
399 if (CHECK_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED))
400 {
401 vty_out (vty, "debug zebra rib detailed%s", VTY_NEWLINE);
402 write++;
403 }
404 if (IS_ZEBRA_DEBUG_FPM)
405 {
406 vty_out (vty, "debug zebra fpm%s", VTY_NEWLINE);
407 write++;
408 }
409 return write;
410 }
411
412 void
413 zebra_debug_init (void)
414 {
415 zebra_debug_event = 0;
416 zebra_debug_packet = 0;
417 zebra_debug_kernel = 0;
418 zebra_debug_rib = 0;
419 zebra_debug_fpm = 0;
420
421 install_node (&debug_node, config_write_debug);
422
423 install_element (VIEW_NODE, &show_debugging_zebra_cmd);
424
425 install_element (ENABLE_NODE, &show_debugging_zebra_cmd);
426 install_element (ENABLE_NODE, &debug_zebra_events_cmd);
427 install_element (ENABLE_NODE, &debug_zebra_nht_cmd);
428 install_element (ENABLE_NODE, &debug_zebra_packet_cmd);
429 install_element (ENABLE_NODE, &debug_zebra_packet_direct_cmd);
430 install_element (ENABLE_NODE, &debug_zebra_packet_detail_cmd);
431 install_element (ENABLE_NODE, &debug_zebra_kernel_cmd);
432 install_element (ENABLE_NODE, &debug_zebra_kernel_msgdump_cmd);
433 install_element (ENABLE_NODE, &debug_zebra_rib_cmd);
434 install_element (ENABLE_NODE, &debug_zebra_rib_detailed_cmd);
435 install_element (ENABLE_NODE, &debug_zebra_fpm_cmd);
436 install_element (ENABLE_NODE, &no_debug_zebra_events_cmd);
437 install_element (ENABLE_NODE, &no_debug_zebra_nht_cmd);
438 install_element (ENABLE_NODE, &no_debug_zebra_packet_cmd);
439 install_element (ENABLE_NODE, &no_debug_zebra_kernel_cmd);
440 install_element (ENABLE_NODE, &no_debug_zebra_kernel_msgdump_cmd);
441 install_element (ENABLE_NODE, &no_debug_zebra_rib_cmd);
442 install_element (ENABLE_NODE, &no_debug_zebra_rib_detailed_cmd);
443 install_element (ENABLE_NODE, &no_debug_zebra_fpm_cmd);
444
445 install_element (CONFIG_NODE, &debug_zebra_events_cmd);
446 install_element (CONFIG_NODE, &debug_zebra_nht_cmd);
447 install_element (CONFIG_NODE, &debug_zebra_packet_cmd);
448 install_element (CONFIG_NODE, &debug_zebra_packet_direct_cmd);
449 install_element (CONFIG_NODE, &debug_zebra_packet_detail_cmd);
450 install_element (CONFIG_NODE, &debug_zebra_kernel_cmd);
451 install_element (CONFIG_NODE, &debug_zebra_kernel_msgdump_cmd);
452 install_element (CONFIG_NODE, &debug_zebra_rib_cmd);
453 install_element (CONFIG_NODE, &debug_zebra_rib_detailed_cmd);
454 install_element (CONFIG_NODE, &debug_zebra_fpm_cmd);
455 install_element (CONFIG_NODE, &no_debug_zebra_events_cmd);
456 install_element (CONFIG_NODE, &no_debug_zebra_nht_cmd);
457 install_element (CONFIG_NODE, &no_debug_zebra_packet_cmd);
458 install_element (CONFIG_NODE, &no_debug_zebra_kernel_cmd);
459 install_element (CONFIG_NODE, &no_debug_zebra_kernel_msgdump_cmd);
460 install_element (CONFIG_NODE, &no_debug_zebra_rib_cmd);
461 install_element (CONFIG_NODE, &no_debug_zebra_rib_detailed_cmd);
462 install_element (CONFIG_NODE, &no_debug_zebra_fpm_cmd);
463 }