]> git.proxmox.com Git - mirror_frr.git/blob - staticd/static_debug.c
Merge pull request #13145 from donaldsharp/do_delete
[mirror_frr.git] / staticd / static_debug.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Staticd debug related functions
4 * Copyright (C) 2019 Volta Networks Inc.
5 * Mark Stapp
6 */
7
8 #include <zebra.h>
9
10 #include "lib/command.h"
11 #include "lib/debug.h"
12 #include "lib/bfd.h"
13
14 #include "static_debug.h"
15
16 /*
17 * Debug infra: a debug struct for each category, and a corresponding
18 * string.
19 */
20
21 /* clang-format off */
22 struct debug static_dbg_events = {0, "Staticd events"};
23 struct debug static_dbg_route = {0, "Staticd route"};
24 struct debug static_dbg_bfd = {0, "Staticd bfd"};
25
26 struct debug *static_debug_arr[] = {
27 &static_dbg_events,
28 &static_dbg_route,
29 &static_dbg_bfd
30 };
31
32 const char *static_debugs_conflines[] = {
33 "debug static events",
34 "debug static route",
35 "debug static bfd"
36 };
37 /* clang-format on */
38
39
40 /*
41 * Set or unset all staticd debugs
42 *
43 * flags
44 * The flags to set
45 *
46 * set
47 * Whether to set or unset the specified flags
48 */
49 static void static_debug_set_all(uint32_t flags, bool set)
50 {
51 for (unsigned int i = 0; i < array_size(static_debug_arr); i++) {
52 DEBUG_FLAGS_SET(static_debug_arr[i], flags, set);
53
54 /* if all modes have been turned off, don't preserve options */
55 if (!DEBUG_MODE_CHECK(static_debug_arr[i], DEBUG_MODE_ALL))
56 DEBUG_CLEAR(static_debug_arr[i]);
57 }
58 }
59
60 static int static_debug_config_write_helper(struct vty *vty, bool config)
61 {
62 uint32_t mode = DEBUG_MODE_ALL;
63
64 if (config)
65 mode = DEBUG_MODE_CONF;
66
67 for (unsigned int i = 0; i < array_size(static_debug_arr); i++)
68 if (DEBUG_MODE_CHECK(static_debug_arr[i], mode))
69 vty_out(vty, "%s\n", static_debugs_conflines[i]);
70
71 return 0;
72 }
73
74 int static_config_write_debug(struct vty *vty)
75 {
76 return static_debug_config_write_helper(vty, true);
77 }
78
79 int static_debug_status_write(struct vty *vty)
80 {
81 return static_debug_config_write_helper(vty, false);
82 }
83
84 /*
85 * Set debugging status.
86 *
87 * vtynode
88 * vty->node
89 *
90 * onoff
91 * Whether to turn the specified debugs on or off
92 *
93 * events
94 * Debug general internal events
95 *
96 */
97 void static_debug_set(int vtynode, bool onoff, bool events, bool route,
98 bool bfd)
99 {
100 uint32_t mode = DEBUG_NODE2MODE(vtynode);
101
102 if (events)
103 DEBUG_MODE_SET(&static_dbg_events, mode, onoff);
104 if (route)
105 DEBUG_MODE_SET(&static_dbg_route, mode, onoff);
106 if (bfd) {
107 DEBUG_MODE_SET(&static_dbg_bfd, mode, onoff);
108 bfd_protocol_integration_set_debug(onoff);
109 }
110 }
111
112 /*
113 * Debug lib initialization
114 */
115
116 struct debug_callbacks static_dbg_cbs = {
117 .debug_set_all = static_debug_set_all
118 };
119
120 void static_debug_init(void)
121 {
122 debug_init(&static_dbg_cbs);
123 }