]> git.proxmox.com Git - mirror_frr.git/blob - pbrd/pbr_debug.c
Merge pull request #3452 from opensourcerouting/reprobuild-master
[mirror_frr.git] / pbrd / pbr_debug.c
1 /*
2 * PBR - debugging
3 * Copyright (C) 2018 Cumulus Networks, Inc.
4 * Quentin Young
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 #include <zebra.h>
21
22 #include "debug.h"
23 #include "command.h"
24 #include "vector.h"
25
26 #ifndef VTYSH_EXTRACT_PL
27 #include "pbrd/pbr_debug_clippy.c"
28 #endif
29 #include "pbrd/pbr_debug.h"
30
31 struct debug pbr_dbg_map = {0, "PBR map"};
32 struct debug pbr_dbg_zebra = {0, "PBR Zebra communications"};
33 struct debug pbr_dbg_nht = {0, "PBR nexthop tracking"};
34 struct debug pbr_dbg_event = {0, "PBR events"};
35
36 struct debug *pbr_debugs[] = {&pbr_dbg_map, &pbr_dbg_zebra, &pbr_dbg_nht,
37 &pbr_dbg_event};
38
39 const char *pbr_debugs_conflines[] = {
40 "debug pbr map",
41 "debug pbr zebra",
42 "debug pbr nht",
43 "debug pbr events",
44 };
45
46 void pbr_debug_set_all(uint32_t flags, bool set)
47 {
48 for (unsigned int i = 0; i < array_size(pbr_debugs); i++) {
49 DEBUG_FLAGS_SET(pbr_debugs[i], flags, set);
50
51 /* if all modes have been turned off, don't preserve options */
52 if (!DEBUG_MODE_CHECK(pbr_debugs[i], DEBUG_MODE_ALL))
53 DEBUG_CLEAR(pbr_debugs[i]);
54 }
55 }
56
57 int pbr_debug_config_write_helper(struct vty *vty, bool config)
58 {
59 uint32_t mode = DEBUG_MODE_ALL;
60
61 if (config)
62 mode = DEBUG_MODE_CONF;
63
64 for (unsigned int i = 0; i < array_size(pbr_debugs); i++)
65 if (DEBUG_MODE_CHECK(pbr_debugs[i], mode))
66 vty_out(vty, "%s\n", pbr_debugs_conflines[i]);
67 return 0;
68 }
69
70 int pbr_debug_config_write(struct vty *vty)
71 {
72 return pbr_debug_config_write_helper(vty, true);
73 }
74
75 struct debug_callbacks pbr_dbg_cbs = {.debug_set_all = pbr_debug_set_all};
76
77 void pbr_debug_init(void)
78 {
79 debug_init(&pbr_dbg_cbs);
80 }