summaryrefslogtreecommitdiff
path: root/pbrd
diff options
context:
space:
mode:
authorIgor Ryzhov <iryzhov@nfware.com>2024-03-26 16:54:54 +0200
committerMark Stapp <mjs@cisco.com>2024-08-27 09:53:02 -0400
commit5dac6961540422a1ca139fae8c5ea9e5a437c4ba (patch)
tree3ff27afc04b9605f832c747b82449b58d5aa5455 /pbrd
parent1797b7eefc730bb4f5aec08f130861650c61dd97 (diff)
lib: rework debug init
The debug library allows to register a `debug_set_all` callback which should enable all debugs in a daemon. This callback is implemented exactly the same in each daemon. Instead of duplicating the code, rework the lib to allow registration of each debug type, and implement the common code only once in the lib. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
Diffstat (limited to 'pbrd')
-rw-r--r--pbrd/pbr_debug.c18
-rw-r--r--pbrd/pbr_vty.c17
2 files changed, 13 insertions, 22 deletions
diff --git a/pbrd/pbr_debug.c b/pbrd/pbr_debug.c
index b30b54b7f0..eca2802e98 100644
--- a/pbrd/pbr_debug.c
+++ b/pbrd/pbr_debug.c
@@ -28,17 +28,6 @@ const char *pbr_debugs_conflines[] = {
"debug pbr events",
};
-void pbr_debug_set_all(uint32_t flags, bool set)
-{
- for (unsigned int i = 0; i < array_size(pbr_debugs); i++) {
- DEBUG_FLAGS_SET(pbr_debugs[i], flags, set);
-
- /* if all modes have been turned off, don't preserve options */
- if (!DEBUG_MODE_CHECK(pbr_debugs[i], DEBUG_MODE_ALL))
- DEBUG_CLEAR(pbr_debugs[i]);
- }
-}
-
int pbr_debug_config_write_helper(struct vty *vty, bool config)
{
uint32_t mode = DEBUG_MODE_ALL;
@@ -57,9 +46,10 @@ int pbr_debug_config_write(struct vty *vty)
return pbr_debug_config_write_helper(vty, true);
}
-struct debug_callbacks pbr_dbg_cbs = {.debug_set_all = pbr_debug_set_all};
-
void pbr_debug_init(void)
{
- debug_init(&pbr_dbg_cbs);
+ debug_install(&pbr_dbg_map);
+ debug_install(&pbr_dbg_zebra);
+ debug_install(&pbr_dbg_nht);
+ debug_install(&pbr_dbg_event);
}
diff --git a/pbrd/pbr_vty.c b/pbrd/pbr_vty.c
index 64d88847c8..4378a3f414 100644
--- a/pbrd/pbr_vty.c
+++ b/pbrd/pbr_vty.c
@@ -1973,20 +1973,21 @@ DEFPY(debug_pbr,
"Events\n")
{
uint32_t mode = DEBUG_NODE2MODE(vty->node);
+ bool all = false;
- if (map)
+ /* no specific debug --> act on all of them */
+ if (strmatch(argv[argc - 1]->text, "pbr"))
+ all = true;
+
+ if (map || all)
DEBUG_MODE_SET(&pbr_dbg_map, mode, !no);
- if (zebra)
+ if (zebra || all)
DEBUG_MODE_SET(&pbr_dbg_zebra, mode, !no);
- if (nht)
+ if (nht || all)
DEBUG_MODE_SET(&pbr_dbg_nht, mode, !no);
- if (events)
+ if (events || all)
DEBUG_MODE_SET(&pbr_dbg_event, mode, !no);
- /* no specific debug --> act on all of them */
- if (strmatch(argv[argc - 1]->text, "pbr"))
- pbr_debug_set_all(mode, !no);
-
return CMD_SUCCESS;
}