2 * Staticd debug related functions
3 * Copyright (C) 2019 Volta Networks Inc.
6 * This file is part of Free Range Routing (FRR).
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
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.
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
25 #include "lib/command.h"
26 #include "lib/debug.h"
28 #include "static_debug.h"
31 * Debug infra: a debug struct for each category, and a corresponding
35 /* clang-format off */
36 struct debug static_dbg_events
= {0, "Staticd events"};
38 struct debug
*static_debug_arr
[] = {
42 const char *static_debugs_conflines
[] = {
49 * Set or unset all staticd debugs
55 * Whether to set or unset the specified flags
57 static void static_debug_set_all(uint32_t flags
, bool set
)
59 for (unsigned int i
= 0; i
< array_size(static_debug_arr
); i
++) {
60 DEBUG_FLAGS_SET(static_debug_arr
[i
], flags
, set
);
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
]);
68 static int static_debug_config_write_helper(struct vty
*vty
, bool config
)
70 uint32_t mode
= DEBUG_MODE_ALL
;
73 mode
= DEBUG_MODE_CONF
;
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
]);
82 int static_config_write_debug(struct vty
*vty
)
84 return static_debug_config_write_helper(vty
, true);
87 int static_debug_status_write(struct vty
*vty
)
89 return static_debug_config_write_helper(vty
, false);
93 * Set debugging status.
99 * Whether to turn the specified debugs on or off
102 * Debug general internal events
105 void static_debug_set(int vtynode
, bool onoff
, bool events
)
107 uint32_t mode
= DEBUG_NODE2MODE(vtynode
);
110 DEBUG_MODE_SET(&static_dbg_events
, mode
, onoff
);
114 * Debug lib initialization
117 struct debug_callbacks static_dbg_cbs
= {
118 .debug_set_all
= static_debug_set_all
121 void static_debug_init(void)
123 debug_init(&static_dbg_cbs
);