1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Staticd debug related functions
4 * Copyright (C) 2019 Volta Networks Inc.
10 #include "lib/command.h"
11 #include "lib/debug.h"
14 #include "static_debug.h"
17 * Debug infra: a debug struct for each category, and a corresponding
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"};
26 struct debug
*static_debug_arr
[] = {
32 const char *static_debugs_conflines
[] = {
33 "debug static events",
41 * Set or unset all staticd debugs
47 * Whether to set or unset the specified flags
49 static void static_debug_set_all(uint32_t flags
, bool set
)
51 for (unsigned int i
= 0; i
< array_size(static_debug_arr
); i
++) {
52 DEBUG_FLAGS_SET(static_debug_arr
[i
], flags
, set
);
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
]);
60 static int static_debug_config_write_helper(struct vty
*vty
, bool config
)
62 uint32_t mode
= DEBUG_MODE_ALL
;
65 mode
= DEBUG_MODE_CONF
;
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
]);
74 int static_config_write_debug(struct vty
*vty
)
76 return static_debug_config_write_helper(vty
, true);
79 int static_debug_status_write(struct vty
*vty
)
81 return static_debug_config_write_helper(vty
, false);
85 * Set debugging status.
91 * Whether to turn the specified debugs on or off
94 * Debug general internal events
97 void static_debug_set(int vtynode
, bool onoff
, bool events
, bool route
,
100 uint32_t mode
= DEBUG_NODE2MODE(vtynode
);
103 DEBUG_MODE_SET(&static_dbg_events
, mode
, onoff
);
105 DEBUG_MODE_SET(&static_dbg_route
, mode
, onoff
);
107 DEBUG_MODE_SET(&static_dbg_bfd
, mode
, onoff
);
108 bfd_protocol_integration_set_debug(onoff
);
113 * Debug lib initialization
116 struct debug_callbacks static_dbg_cbs
= {
117 .debug_set_all
= static_debug_set_all
120 void static_debug_init(void)
122 debug_init(&static_dbg_cbs
);