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