]>
Commit | Line | Data |
---|---|---|
31ddf3b7 MS |
1 | /* |
2 | * Staticd debug related functions | |
3 | * Copyright (C) 2019 Volta Networks Inc. | |
4 | * Mark Stapp | |
5 | * | |
8678d638 | 6 | * This file is part of FRRouting (FRR). |
31ddf3b7 MS |
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"}; | |
b2f6ab67 | 37 | struct debug static_dbg_route = {0, "Staticd route"}; |
31ddf3b7 MS |
38 | |
39 | struct debug *static_debug_arr[] = { | |
b2f6ab67 | 40 | &static_dbg_events, |
41 | &static_dbg_route | |
31ddf3b7 MS |
42 | }; |
43 | ||
44 | const char *static_debugs_conflines[] = { | |
b2f6ab67 | 45 | "debug static events", |
46 | "debug static route" | |
31ddf3b7 MS |
47 | }; |
48 | /* clang-format on */ | |
49 | ||
50 | ||
51 | /* | |
52 | * Set or unset all staticd debugs | |
53 | * | |
54 | * flags | |
55 | * The flags to set | |
56 | * | |
57 | * set | |
58 | * Whether to set or unset the specified flags | |
59 | */ | |
60 | static void static_debug_set_all(uint32_t flags, bool set) | |
61 | { | |
62 | for (unsigned int i = 0; i < array_size(static_debug_arr); i++) { | |
63 | DEBUG_FLAGS_SET(static_debug_arr[i], flags, set); | |
64 | ||
65 | /* if all modes have been turned off, don't preserve options */ | |
66 | if (!DEBUG_MODE_CHECK(static_debug_arr[i], DEBUG_MODE_ALL)) | |
67 | DEBUG_CLEAR(static_debug_arr[i]); | |
68 | } | |
69 | } | |
70 | ||
71 | static int static_debug_config_write_helper(struct vty *vty, bool config) | |
72 | { | |
73 | uint32_t mode = DEBUG_MODE_ALL; | |
74 | ||
75 | if (config) | |
76 | mode = DEBUG_MODE_CONF; | |
77 | ||
78 | for (unsigned int i = 0; i < array_size(static_debug_arr); i++) | |
79 | if (DEBUG_MODE_CHECK(static_debug_arr[i], mode)) | |
80 | vty_out(vty, "%s\n", static_debugs_conflines[i]); | |
81 | ||
82 | return 0; | |
83 | } | |
84 | ||
85 | int static_config_write_debug(struct vty *vty) | |
86 | { | |
87 | return static_debug_config_write_helper(vty, true); | |
88 | } | |
89 | ||
90 | int static_debug_status_write(struct vty *vty) | |
91 | { | |
92 | return static_debug_config_write_helper(vty, false); | |
93 | } | |
94 | ||
95 | /* | |
96 | * Set debugging status. | |
97 | * | |
98 | * vtynode | |
99 | * vty->node | |
100 | * | |
101 | * onoff | |
102 | * Whether to turn the specified debugs on or off | |
103 | * | |
104 | * events | |
105 | * Debug general internal events | |
106 | * | |
107 | */ | |
b2f6ab67 | 108 | void static_debug_set(int vtynode, bool onoff, bool events, bool route) |
31ddf3b7 MS |
109 | { |
110 | uint32_t mode = DEBUG_NODE2MODE(vtynode); | |
111 | ||
112 | if (events) | |
113 | DEBUG_MODE_SET(&static_dbg_events, mode, onoff); | |
b2f6ab67 | 114 | if (route) |
115 | DEBUG_MODE_SET(&static_dbg_route, mode, onoff); | |
31ddf3b7 MS |
116 | } |
117 | ||
118 | /* | |
119 | * Debug lib initialization | |
120 | */ | |
121 | ||
122 | struct debug_callbacks static_dbg_cbs = { | |
123 | .debug_set_all = static_debug_set_all | |
124 | }; | |
125 | ||
126 | void static_debug_init(void) | |
127 | { | |
128 | debug_init(&static_dbg_cbs); | |
129 | } |