]> git.proxmox.com Git - mirror_frr.git/blame - zebra/debug.c
*: reindent
[mirror_frr.git] / zebra / debug.c
CommitLineData
718e3744 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 *
896014f4
DL
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
718e3744 20 */
21
22#include <zebra.h>
23#include "command.h"
24#include "debug.h"
25
26/* For debug statement. */
27unsigned long zebra_debug_event;
28unsigned long zebra_debug_packet;
29unsigned long zebra_debug_kernel;
b0498dc6 30unsigned long zebra_debug_rib;
5adc2528 31unsigned long zebra_debug_fpm;
fb018d25 32unsigned long zebra_debug_nht;
7758e3f3 33unsigned long zebra_debug_mpls;
13d60d35 34unsigned long zebra_debug_vxlan;
718e3744 35
36DEFUN (show_debugging_zebra,
37 show_debugging_zebra_cmd,
38 "show debugging zebra",
39 SHOW_STR
2b00515a
CF
40 "Debugging information\n"
41 "Zebra configuration\n")
718e3744 42{
d62a17ae 43 vty_out(vty, "Zebra debugging status:\n");
44
45 if (IS_ZEBRA_DEBUG_EVENT)
46 vty_out(vty, " Zebra event debugging is on\n");
47
48 if (IS_ZEBRA_DEBUG_PACKET) {
49 if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV) {
50 vty_out(vty, " Zebra packet%s debugging is on\n",
51 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "");
52 } else {
53 if (IS_ZEBRA_DEBUG_SEND)
54 vty_out(vty,
55 " Zebra packet send%s debugging is on\n",
56 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "");
57 else
58 vty_out(vty,
59 " Zebra packet receive%s debugging is on\n",
60 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "");
61 }
718e3744 62 }
d62a17ae 63
64 if (IS_ZEBRA_DEBUG_KERNEL)
65 vty_out(vty, " Zebra kernel debugging is on\n");
66 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND)
67 vty_out(vty,
68 " Zebra kernel netlink message dumps (send) are on\n");
69 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV)
70 vty_out(vty,
71 " Zebra kernel netlink message dumps (recv) are on\n");
72
73 /* Check here using flags as the 'macro' does an OR */
74 if (CHECK_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB))
75 vty_out(vty, " Zebra RIB debugging is on\n");
76 if (CHECK_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED))
77 vty_out(vty, " Zebra RIB detailed debugging is on\n");
78
79 if (IS_ZEBRA_DEBUG_FPM)
80 vty_out(vty, " Zebra FPM debugging is on\n");
81 if (IS_ZEBRA_DEBUG_NHT)
82 vty_out(vty, " Zebra next-hop tracking debugging is on\n");
83 if (IS_ZEBRA_DEBUG_MPLS)
84 vty_out(vty, " Zebra MPLS debugging is on\n");
85
86 return CMD_SUCCESS;
718e3744 87}
88
89DEFUN (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{
d62a17ae 96 zebra_debug_event = ZEBRA_DEBUG_EVENT;
97 return CMD_WARNING_CONFIG_FAILED;
718e3744 98}
99
fb018d25
DS
100DEFUN (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{
d62a17ae 107 zebra_debug_nht = ZEBRA_DEBUG_NHT;
108 return CMD_WARNING_CONFIG_FAILED;
fb018d25
DS
109}
110
7758e3f3 111DEFUN (debug_zebra_mpls,
112 debug_zebra_mpls_cmd,
113 "debug zebra mpls",
114 DEBUG_STR
115 "Zebra configuration\n"
116 "Debug option set for zebra MPLS LSPs\n")
117{
d62a17ae 118 zebra_debug_mpls = ZEBRA_DEBUG_MPLS;
119 return CMD_WARNING_CONFIG_FAILED;
7758e3f3 120}
121
13d60d35 122DEFUN (debug_zebra_vxlan,
123 debug_zebra_vxlan_cmd,
124 "debug zebra vxlan",
125 DEBUG_STR
126 "Zebra configuration\n"
127 "Debug option set for zebra VxLAN (EVPN)\n")
128{
d62a17ae 129 zebra_debug_vxlan = ZEBRA_DEBUG_VXLAN;
130 return CMD_WARNING;
13d60d35 131}
132
718e3744 133DEFUN (debug_zebra_packet,
134 debug_zebra_packet_cmd,
16cedbb0 135 "debug zebra packet [<recv|send>] [detail]",
718e3744 136 DEBUG_STR
137 "Zebra configuration\n"
138 "Debug option set for zebra packet\n"
139 "Debug option set for receive packet\n"
16cedbb0
QY
140 "Debug option set for send packet\n"
141 "Debug option set for detailed info\n")
718e3744 142{
d62a17ae 143 int idx = 0;
144 zebra_debug_packet = ZEBRA_DEBUG_PACKET;
145
146 if (argv_find(argv, argc, "send", &idx))
147 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
148 idx = 0;
149 if (argv_find(argv, argc, "recv", &idx))
150 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
151 idx = 0;
152 if (argv_find(argv, argc, "detail", &idx))
153 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL);
154
155 if (!(zebra_debug_packet & ZEBRA_DEBUG_SEND & ZEBRA_DEBUG_RECV)) {
156 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
157 SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
158 }
159 return CMD_SUCCESS;
718e3744 160}
161
162DEFUN (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{
d62a17ae 169 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL);
170 return CMD_SUCCESS;
556b904e
QY
171}
172
173DEFUN (debug_zebra_kernel_msgdump,
174 debug_zebra_kernel_msgdump_cmd,
6de69f83 175 "debug zebra kernel msgdump [<recv|send>]",
556b904e
QY
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{
d62a17ae 183 int idx = 0;
184 if (argc == 4 || argv_find(argv, argc, "recv", &idx))
185 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
186 if (argc == 4 || argv_find(argv, argc, "send", &idx))
187 SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
313605cb 188
d62a17ae 189 return CMD_SUCCESS;
718e3744 190}
191
b0498dc6
PJ
192DEFUN (debug_zebra_rib,
193 debug_zebra_rib_cmd,
194 "debug zebra rib",
195 DEBUG_STR
196 "Zebra configuration\n"
197 "Debug RIB events\n")
198{
d62a17ae 199 SET_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB);
200 return CMD_SUCCESS;
b0498dc6
PJ
201}
202
41ec9222 203DEFUN (debug_zebra_rib_detailed,
204 debug_zebra_rib_detailed_cmd,
205 "debug zebra rib detailed",
b0498dc6
PJ
206 DEBUG_STR
207 "Zebra configuration\n"
208 "Debug RIB events\n"
41ec9222 209 "Detailed debugs\n")
b0498dc6 210{
d62a17ae 211 SET_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED);
212 return CMD_SUCCESS;
b0498dc6
PJ
213}
214
5adc2528
AS
215DEFUN (debug_zebra_fpm,
216 debug_zebra_fpm_cmd,
217 "debug zebra fpm",
218 DEBUG_STR
219 "Zebra configuration\n"
220 "Debug zebra FPM events\n")
221{
d62a17ae 222 SET_FLAG(zebra_debug_fpm, ZEBRA_DEBUG_FPM);
223 return CMD_SUCCESS;
5adc2528
AS
224}
225
718e3744 226DEFUN (no_debug_zebra_events,
227 no_debug_zebra_events_cmd,
228 "no debug zebra events",
229 NO_STR
230 DEBUG_STR
231 "Zebra configuration\n"
232 "Debug option set for zebra events\n")
233{
d62a17ae 234 zebra_debug_event = 0;
235 return CMD_SUCCESS;
718e3744 236}
237
fb018d25
DS
238DEFUN (no_debug_zebra_nht,
239 no_debug_zebra_nht_cmd,
240 "no debug zebra nht",
241 NO_STR
242 DEBUG_STR
243 "Zebra configuration\n"
244 "Debug option set for zebra next hop tracking\n")
245{
d62a17ae 246 zebra_debug_nht = 0;
247 return CMD_SUCCESS;
fb018d25
DS
248}
249
7758e3f3 250DEFUN (no_debug_zebra_mpls,
251 no_debug_zebra_mpls_cmd,
252 "no debug zebra mpls",
253 NO_STR
254 DEBUG_STR
255 "Zebra configuration\n"
256 "Debug option set for zebra MPLS LSPs\n")
257{
d62a17ae 258 zebra_debug_mpls = 0;
259 return CMD_SUCCESS;
7758e3f3 260}
261
13d60d35 262DEFUN (no_debug_zebra_vxlan,
263 no_debug_zebra_vxlan_cmd,
264 "no debug zebra vxlan",
265 NO_STR
266 DEBUG_STR
267 "Zebra configuration\n"
268 "Debug option set for zebra VxLAN (EVPN)\n")
269{
d62a17ae 270 zebra_debug_vxlan = 0;
271 return CMD_SUCCESS;
13d60d35 272}
273
718e3744 274DEFUN (no_debug_zebra_packet,
275 no_debug_zebra_packet_cmd,
16cedbb0 276 "no debug zebra packet [<recv|send>]",
718e3744 277 NO_STR
278 DEBUG_STR
279 "Zebra configuration\n"
280 "Debug option set for zebra packet\n"
281 "Debug option set for receive packet\n"
282 "Debug option set for send packet\n")
283{
d62a17ae 284 int idx = 0;
285 if (argc == 4 || argv_find(argv, argc, "send", &idx))
286 UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND);
287 if (argc == 4 || argv_find(argv, argc, "recv", &idx))
288 UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV);
289 return CMD_SUCCESS;
718e3744 290}
291
292DEFUN (no_debug_zebra_kernel,
293 no_debug_zebra_kernel_cmd,
294 "no debug zebra kernel",
295 NO_STR
296 DEBUG_STR
297 "Zebra configuration\n"
298 "Debug option set for zebra between kernel interface\n")
299{
d62a17ae 300 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL);
301 return CMD_SUCCESS;
556b904e
QY
302}
303
304DEFUN (no_debug_zebra_kernel_msgdump,
305 no_debug_zebra_kernel_msgdump_cmd,
6de69f83 306 "no debug zebra kernel msgdump [<recv|send>]",
16cedbb0 307 NO_STR
556b904e
QY
308 DEBUG_STR
309 "Zebra configuration\n"
310 "Debug option set for zebra between kernel interface\n"
311 "Dump raw netlink messages, sent and received\n"
312 "Dump raw netlink messages received\n"
313 "Dump raw netlink messages sent\n")
314{
d62a17ae 315 int idx = 0;
316 if (argc == 5 || argv_find(argv, argc, "recv", &idx))
317 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
318 if (argc == 5 || argv_find(argv, argc, "send", &idx))
319 UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
16cedbb0 320
d62a17ae 321 return CMD_SUCCESS;
718e3744 322}
323
b0498dc6
PJ
324DEFUN (no_debug_zebra_rib,
325 no_debug_zebra_rib_cmd,
326 "no debug zebra rib",
327 NO_STR
328 DEBUG_STR
329 "Zebra configuration\n"
330 "Debug zebra RIB\n")
331{
d62a17ae 332 zebra_debug_rib = 0;
333 return CMD_SUCCESS;
b0498dc6
PJ
334}
335
41ec9222 336DEFUN (no_debug_zebra_rib_detailed,
337 no_debug_zebra_rib_detailed_cmd,
338 "no debug zebra rib detailed",
b0498dc6
PJ
339 NO_STR
340 DEBUG_STR
341 "Zebra configuration\n"
342 "Debug zebra RIB\n"
41ec9222 343 "Detailed debugs\n")
b0498dc6 344{
d62a17ae 345 UNSET_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED);
346 return CMD_SUCCESS;
b0498dc6
PJ
347}
348
5adc2528
AS
349DEFUN (no_debug_zebra_fpm,
350 no_debug_zebra_fpm_cmd,
351 "no debug zebra fpm",
352 NO_STR
353 DEBUG_STR
354 "Zebra configuration\n"
355 "Debug zebra FPM events\n")
356{
d62a17ae 357 zebra_debug_fpm = 0;
358 return CMD_SUCCESS;
5adc2528
AS
359}
360
718e3744 361/* Debug node. */
d62a17ae 362struct cmd_node debug_node = {DEBUG_NODE, "", /* Debug node has no interface. */
363 1};
718e3744 364
d62a17ae 365static int config_write_debug(struct vty *vty)
718e3744 366{
d62a17ae 367 int write = 0;
368
369 if (IS_ZEBRA_DEBUG_EVENT) {
370 vty_out(vty, "debug zebra events\n");
371 write++;
372 }
373 if (IS_ZEBRA_DEBUG_PACKET) {
374 if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV) {
375 vty_out(vty, "debug zebra packet%s\n",
376 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "");
377 write++;
378 } else {
379 if (IS_ZEBRA_DEBUG_SEND)
380 vty_out(vty, "debug zebra packet send%s\n",
381 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "");
382 else
383 vty_out(vty, "debug zebra packet recv%s\n",
384 IS_ZEBRA_DEBUG_DETAIL ? " detail" : "");
385 write++;
386 }
387 }
388 if (IS_ZEBRA_DEBUG_KERNEL) {
389 vty_out(vty, "debug zebra kernel\n");
390 write++;
391 }
392 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV) {
393 vty_out(vty, "debug zebra kernel msgdump recv\n");
394 write++;
395 }
396 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND) {
397 vty_out(vty, "debug zebra kernel msgdump send\n");
398 write++;
399 }
400 /* Check here using flags as the 'macro' does an OR */
401 if (CHECK_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB)) {
402 vty_out(vty, "debug zebra rib\n");
403 write++;
404 }
405 if (CHECK_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED)) {
406 vty_out(vty, "debug zebra rib detailed\n");
407 write++;
408 }
409 if (IS_ZEBRA_DEBUG_FPM) {
410 vty_out(vty, "debug zebra fpm\n");
411 write++;
412 }
413 if (IS_ZEBRA_DEBUG_NHT) {
414 vty_out(vty, "debug zebra nht\n");
415 write++;
416 }
417 if (IS_ZEBRA_DEBUG_MPLS) {
418 vty_out(vty, "debug zebra mpls\n");
419 write++;
718e3744 420 }
d62a17ae 421 if (IS_ZEBRA_DEBUG_VXLAN) {
422 vty_out(vty, "debug zebra vxlan\n");
423 write++;
718e3744 424 }
d62a17ae 425 return write;
718e3744 426}
427
d62a17ae 428void zebra_debug_init(void)
718e3744 429{
d62a17ae 430 zebra_debug_event = 0;
431 zebra_debug_packet = 0;
432 zebra_debug_kernel = 0;
433 zebra_debug_rib = 0;
434 zebra_debug_fpm = 0;
435 zebra_debug_mpls = 0;
436 zebra_debug_vxlan = 0;
437
438 install_node(&debug_node, config_write_debug);
439
440 install_element(VIEW_NODE, &show_debugging_zebra_cmd);
441
442 install_element(ENABLE_NODE, &debug_zebra_events_cmd);
443 install_element(ENABLE_NODE, &debug_zebra_nht_cmd);
444 install_element(ENABLE_NODE, &debug_zebra_mpls_cmd);
445 install_element(ENABLE_NODE, &debug_zebra_vxlan_cmd);
446 install_element(ENABLE_NODE, &debug_zebra_packet_cmd);
447 install_element(ENABLE_NODE, &debug_zebra_kernel_cmd);
448 install_element(ENABLE_NODE, &debug_zebra_kernel_msgdump_cmd);
449 install_element(ENABLE_NODE, &debug_zebra_rib_cmd);
450 install_element(ENABLE_NODE, &debug_zebra_rib_detailed_cmd);
451 install_element(ENABLE_NODE, &debug_zebra_fpm_cmd);
452 install_element(ENABLE_NODE, &no_debug_zebra_events_cmd);
453 install_element(ENABLE_NODE, &no_debug_zebra_nht_cmd);
454 install_element(ENABLE_NODE, &no_debug_zebra_mpls_cmd);
455 install_element(ENABLE_NODE, &no_debug_zebra_vxlan_cmd);
456 install_element(ENABLE_NODE, &no_debug_zebra_packet_cmd);
457 install_element(ENABLE_NODE, &no_debug_zebra_kernel_cmd);
458 install_element(ENABLE_NODE, &no_debug_zebra_kernel_msgdump_cmd);
459 install_element(ENABLE_NODE, &no_debug_zebra_rib_cmd);
460 install_element(ENABLE_NODE, &no_debug_zebra_rib_detailed_cmd);
461 install_element(ENABLE_NODE, &no_debug_zebra_fpm_cmd);
462
463 install_element(CONFIG_NODE, &debug_zebra_events_cmd);
464 install_element(CONFIG_NODE, &debug_zebra_nht_cmd);
465 install_element(CONFIG_NODE, &debug_zebra_mpls_cmd);
466 install_element(CONFIG_NODE, &debug_zebra_vxlan_cmd);
467 install_element(CONFIG_NODE, &debug_zebra_packet_cmd);
468 install_element(CONFIG_NODE, &debug_zebra_kernel_cmd);
469 install_element(CONFIG_NODE, &debug_zebra_kernel_msgdump_cmd);
470 install_element(CONFIG_NODE, &debug_zebra_rib_cmd);
471 install_element(CONFIG_NODE, &debug_zebra_rib_detailed_cmd);
472 install_element(CONFIG_NODE, &debug_zebra_fpm_cmd);
473 install_element(CONFIG_NODE, &no_debug_zebra_events_cmd);
474 install_element(CONFIG_NODE, &no_debug_zebra_nht_cmd);
475 install_element(CONFIG_NODE, &no_debug_zebra_mpls_cmd);
476 install_element(CONFIG_NODE, &no_debug_zebra_vxlan_cmd);
477 install_element(CONFIG_NODE, &no_debug_zebra_packet_cmd);
478 install_element(CONFIG_NODE, &no_debug_zebra_kernel_cmd);
479 install_element(CONFIG_NODE, &no_debug_zebra_kernel_msgdump_cmd);
480 install_element(CONFIG_NODE, &no_debug_zebra_rib_cmd);
481 install_element(CONFIG_NODE, &no_debug_zebra_rib_detailed_cmd);
482 install_element(CONFIG_NODE, &no_debug_zebra_fpm_cmd);
718e3744 483}