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