2 * Staticd debug related functions
3 * Copyright (C) 2019 Volta Networks Inc.
6 * This file is part of FRRouting (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"
29 #include "static_debug.h"
32 * Debug infra: a debug struct for each category, and a corresponding
36 /* clang-format off */
37 struct debug static_dbg_events
= {0, "Staticd events"};
38 struct debug static_dbg_route
= {0, "Staticd route"};
39 struct debug static_dbg_bfd
= {0, "Staticd bfd"};
41 struct debug
*static_debug_arr
[] = {
47 const char *static_debugs_conflines
[] = {
48 "debug static events",
56 * Set or unset all staticd debugs
62 * Whether to set or unset the specified flags
64 static void static_debug_set_all(uint32_t flags
, bool set
)
66 for (unsigned int i
= 0; i
< array_size(static_debug_arr
); i
++) {
67 DEBUG_FLAGS_SET(static_debug_arr
[i
], flags
, set
);
69 /* if all modes have been turned off, don't preserve options */
70 if (!DEBUG_MODE_CHECK(static_debug_arr
[i
], DEBUG_MODE_ALL
))
71 DEBUG_CLEAR(static_debug_arr
[i
]);
75 static int static_debug_config_write_helper(struct vty
*vty
, bool config
)
77 uint32_t mode
= DEBUG_MODE_ALL
;
80 mode
= DEBUG_MODE_CONF
;
82 for (unsigned int i
= 0; i
< array_size(static_debug_arr
); i
++)
83 if (DEBUG_MODE_CHECK(static_debug_arr
[i
], mode
))
84 vty_out(vty
, "%s\n", static_debugs_conflines
[i
]);
89 int static_config_write_debug(struct vty
*vty
)
91 return static_debug_config_write_helper(vty
, true);
94 int static_debug_status_write(struct vty
*vty
)
96 return static_debug_config_write_helper(vty
, false);
100 * Set debugging status.
106 * Whether to turn the specified debugs on or off
109 * Debug general internal events
112 void static_debug_set(int vtynode
, bool onoff
, bool events
, bool route
,
115 uint32_t mode
= DEBUG_NODE2MODE(vtynode
);
118 DEBUG_MODE_SET(&static_dbg_events
, mode
, onoff
);
120 DEBUG_MODE_SET(&static_dbg_route
, mode
, onoff
);
122 DEBUG_MODE_SET(&static_dbg_bfd
, mode
, onoff
);
123 bfd_protocol_integration_set_debug(onoff
);
128 * Debug lib initialization
131 struct debug_callbacks static_dbg_cbs
= {
132 .debug_set_all
= static_debug_set_all
135 void static_debug_init(void)
137 debug_init(&static_dbg_cbs
);