]> git.proxmox.com Git - mirror_frr.git/blame - staticd/static_debug.c
Merge pull request #13145 from donaldsharp/do_delete
[mirror_frr.git] / staticd / static_debug.c
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
31ddf3b7
MS
2/*
3 * Staticd debug related functions
4 * Copyright (C) 2019 Volta Networks Inc.
5 * Mark Stapp
31ddf3b7
MS
6 */
7
8#include <zebra.h>
9
10#include "lib/command.h"
11#include "lib/debug.h"
b27499d6 12#include "lib/bfd.h"
31ddf3b7
MS
13
14#include "static_debug.h"
15
16/*
17 * Debug infra: a debug struct for each category, and a corresponding
18 * string.
19 */
20
21/* clang-format off */
22struct debug static_dbg_events = {0, "Staticd events"};
b2f6ab67 23struct debug static_dbg_route = {0, "Staticd route"};
b27499d6 24struct debug static_dbg_bfd = {0, "Staticd bfd"};
31ddf3b7
MS
25
26struct debug *static_debug_arr[] = {
b2f6ab67 27 &static_dbg_events,
b27499d6
PG
28 &static_dbg_route,
29 &static_dbg_bfd
31ddf3b7
MS
30};
31
32const char *static_debugs_conflines[] = {
b2f6ab67 33 "debug static events",
b27499d6
PG
34 "debug static route",
35 "debug static bfd"
31ddf3b7
MS
36};
37/* clang-format on */
38
39
40/*
41 * Set or unset all staticd debugs
42 *
43 * flags
44 * The flags to set
45 *
46 * set
47 * Whether to set or unset the specified flags
48 */
49static void static_debug_set_all(uint32_t flags, bool set)
50{
51 for (unsigned int i = 0; i < array_size(static_debug_arr); i++) {
52 DEBUG_FLAGS_SET(static_debug_arr[i], flags, set);
53
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]);
57 }
58}
59
60static int static_debug_config_write_helper(struct vty *vty, bool config)
61{
62 uint32_t mode = DEBUG_MODE_ALL;
63
64 if (config)
65 mode = DEBUG_MODE_CONF;
66
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]);
70
71 return 0;
72}
73
74int static_config_write_debug(struct vty *vty)
75{
76 return static_debug_config_write_helper(vty, true);
77}
78
79int static_debug_status_write(struct vty *vty)
80{
81 return static_debug_config_write_helper(vty, false);
82}
83
84/*
85 * Set debugging status.
86 *
87 * vtynode
88 * vty->node
89 *
90 * onoff
91 * Whether to turn the specified debugs on or off
92 *
93 * events
94 * Debug general internal events
95 *
96 */
b27499d6
PG
97void static_debug_set(int vtynode, bool onoff, bool events, bool route,
98 bool bfd)
31ddf3b7
MS
99{
100 uint32_t mode = DEBUG_NODE2MODE(vtynode);
101
102 if (events)
103 DEBUG_MODE_SET(&static_dbg_events, mode, onoff);
b2f6ab67 104 if (route)
105 DEBUG_MODE_SET(&static_dbg_route, mode, onoff);
b27499d6
PG
106 if (bfd) {
107 DEBUG_MODE_SET(&static_dbg_bfd, mode, onoff);
108 bfd_protocol_integration_set_debug(onoff);
109 }
31ddf3b7
MS
110}
111
112/*
113 * Debug lib initialization
114 */
115
116struct debug_callbacks static_dbg_cbs = {
117 .debug_set_all = static_debug_set_all
118};
119
120void static_debug_init(void)
121{
122 debug_init(&static_dbg_cbs);
123}