]> git.proxmox.com Git - mirror_frr.git/blob - staticd/static_debug.c
Merge pull request #5787 from karamalla0406/rmac_check
[mirror_frr.git] / staticd / static_debug.c
1 /*
2 * Staticd debug related functions
3 * Copyright (C) 2019 Volta Networks Inc.
4 * Mark Stapp
5 *
6 * This file is part of Free Range Routing (FRR).
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include <zebra.h>
24
25 #include "lib/command.h"
26 #include "lib/debug.h"
27
28 #include "static_debug.h"
29
30 /*
31 * Debug infra: a debug struct for each category, and a corresponding
32 * string.
33 */
34
35 /* clang-format off */
36 struct debug static_dbg_events = {0, "Staticd events"};
37
38 struct debug *static_debug_arr[] = {
39 &static_dbg_events
40 };
41
42 const char *static_debugs_conflines[] = {
43 "debug static events"
44 };
45 /* clang-format on */
46
47
48 /*
49 * Set or unset all staticd debugs
50 *
51 * flags
52 * The flags to set
53 *
54 * set
55 * Whether to set or unset the specified flags
56 */
57 static void static_debug_set_all(uint32_t flags, bool set)
58 {
59 for (unsigned int i = 0; i < array_size(static_debug_arr); i++) {
60 DEBUG_FLAGS_SET(static_debug_arr[i], flags, set);
61
62 /* if all modes have been turned off, don't preserve options */
63 if (!DEBUG_MODE_CHECK(static_debug_arr[i], DEBUG_MODE_ALL))
64 DEBUG_CLEAR(static_debug_arr[i]);
65 }
66 }
67
68 static int static_debug_config_write_helper(struct vty *vty, bool config)
69 {
70 uint32_t mode = DEBUG_MODE_ALL;
71
72 if (config)
73 mode = DEBUG_MODE_CONF;
74
75 for (unsigned int i = 0; i < array_size(static_debug_arr); i++)
76 if (DEBUG_MODE_CHECK(static_debug_arr[i], mode))
77 vty_out(vty, "%s\n", static_debugs_conflines[i]);
78
79 return 0;
80 }
81
82 int static_config_write_debug(struct vty *vty)
83 {
84 return static_debug_config_write_helper(vty, true);
85 }
86
87 int static_debug_status_write(struct vty *vty)
88 {
89 return static_debug_config_write_helper(vty, false);
90 }
91
92 /*
93 * Set debugging status.
94 *
95 * vtynode
96 * vty->node
97 *
98 * onoff
99 * Whether to turn the specified debugs on or off
100 *
101 * events
102 * Debug general internal events
103 *
104 */
105 void static_debug_set(int vtynode, bool onoff, bool events)
106 {
107 uint32_t mode = DEBUG_NODE2MODE(vtynode);
108
109 if (events)
110 DEBUG_MODE_SET(&static_dbg_events, mode, onoff);
111 }
112
113 /*
114 * Debug lib initialization
115 */
116
117 struct debug_callbacks static_dbg_cbs = {
118 .debug_set_all = static_debug_set_all
119 };
120
121 void static_debug_init(void)
122 {
123 debug_init(&static_dbg_cbs);
124 }