#include "debug.h"
#include "command.h"
-static struct debug_cb_list_head cb_head;
+static struct debug_list_head debug_head;
-DECLARE_LIST(debug_cb_list, struct debug_callbacks, item);
+DECLARE_LIST(debug_list, struct debug, item);
/* All code in this section should be reentrant and MT-safe */
-DEFUN_NOSH(debug_all, debug_all_cmd, "[no] debug all",
- NO_STR DEBUG_STR "Toggle all debugging output\n")
+DEFUN_NOSH (debug_all,
+ debug_all_cmd,
+ "[no] debug all",
+ NO_STR DEBUG_STR
+ "Toggle all debugging output\n")
{
- struct debug_callbacks *cb;
-
+ struct debug *debug;
bool set = !strmatch(argv[0]->text, "no");
uint32_t mode = DEBUG_NODE2MODE(vty->node);
- frr_each (debug_cb_list, &cb_head, cb)
- cb->debug_set_all(mode, set);
+ frr_each (debug_list, &debug_head, debug) {
+ DEBUG_MODE_SET(debug, mode, set);
+
+ /* If all modes have been turned off, don't preserve options. */
+ if (!DEBUG_MODE_CHECK(debug, DEBUG_MODE_ALL))
+ DEBUG_CLEAR(debug);
+ }
return CMD_SUCCESS;
}
/* ------------------------------------------------------------------------- */
-void debug_init(struct debug_callbacks *cb)
+void debug_install(struct debug *debug)
{
- static bool inited = false;
-
- if (!inited) {
- inited = true;
- debug_cb_list_init(&cb_head);
- }
-
- debug_cb_list_add_head(&cb_head, cb);
+ debug_list_add_tail(&debug_head, debug);
}
-void debug_init_cli(void)
+void debug_init(void)
{
+ debug_list_init(&debug_head);
+
install_element(ENABLE_NODE, &debug_all_cmd);
install_element(CONFIG_NODE, &debug_all_cmd);
}
#define DEBUG_OPT_NONE 0x00000000
+PREDECL_LIST(debug_list);
/*
* Debugging record.
*
struct debug {
atomic_uint_fast32_t flags;
const char *desc;
-};
-PREDECL_LIST(debug_cb_list);
-/*
- * Callback set for debugging code.
- *
- * debug_set_all
- * Function pointer to call when the user requests that all debugs have a
- * mode set.
- */
-struct debug_callbacks {
- /*
- * Linked list of Callbacks to call
- */
- struct debug_cb_list_item item;
-
- /*
- * flags
- * flags to set on debug flag fields
- *
- * set
- * true: set flags
- * false: unset flags
- */
- void (*debug_set_all)(uint32_t flags, bool set);
+ struct debug_list_item item;
};
/*
#define DEBUGD(name, fmt, ...) DEBUG(debug, name, fmt, ##__VA_ARGS__)
/*
- * Optional initializer for debugging. Highly recommended.
- *
- * This function installs common debugging commands and allows the caller to
- * specify callbacks to take when these commands are issued, allowing the
- * caller to respond to events such as a request to turn off all debugs.
- *
- * MT-Safe
+ * Register a debug item.
*/
-void debug_init(struct debug_callbacks *cb);
+void debug_install(struct debug *debug);
/*
- * Turn on the cli to turn on/off debugs.
- * Should only be called by libfrr
+ * Initialize debugging.
+ * Should only be called by libfrr.
*/
-void debug_init_cli(void);
+void debug_init(void);
#ifdef __cplusplus
}
vty_init(master, di->log_always);
lib_cmd_init();
+ debug_init();
frr_pthread_init();
#ifdef HAVE_SCRIPTING
"%s: failed to initialize northbound database",
__func__);
- debug_init_cli();
-
return master;
}
vty_out(vty, "debug mgmt client backend\n");
}
-static struct debug_callbacks mgmt_dbg_be_client_cbs = {
- .debug_set_all = mgmt_debug_client_be_set
-};
-
static struct cmd_node mgmt_dbg_node = {
.name = "debug mgmt client backend",
.node = MGMT_BE_DEBUG_NODE,
void mgmt_be_client_lib_vty_init(void)
{
- debug_init(&mgmt_dbg_be_client_cbs);
+ debug_install(&mgmt_dbg_be_client);
+
install_node(&mgmt_dbg_node);
install_element(ENABLE_NODE, &debug_mgmt_client_be_cmd);
install_element(CONFIG_NODE, &debug_mgmt_client_be_cmd);
vty_out(vty, "debug mgmt client frontend\n");
}
-static struct debug_callbacks mgmt_dbg_fe_client_cbs = {
- .debug_set_all = mgmt_debug_client_fe_set
-};
-
static struct cmd_node mgmt_dbg_node = {
.name = "debug mgmt client frontend",
.node = MGMT_FE_DEBUG_NODE,
void mgmt_fe_client_lib_vty_init(void)
{
- debug_init(&mgmt_dbg_fe_client_cbs);
+ debug_install(&mgmt_dbg_fe_client);
+
install_node(&mgmt_dbg_node);
install_element(ENABLE_NODE, &debug_mgmt_client_fe_cmd);
install_element(CONFIG_NODE, &debug_mgmt_client_fe_cmd);
DECLARE_HOOK(nb_notification_tree_send,
(const char *xpath, const struct lyd_node *tree), (xpath, tree));
DECLARE_HOOK(nb_client_debug_config_write, (struct vty *vty), (vty));
-DECLARE_HOOK(nb_client_debug_set_all, (uint32_t flags, bool set), (flags, set));
/* Northbound debugging records */
extern struct debug nb_dbg_cbs_config;
"debug northbound libyang",
};
-DEFINE_HOOK(nb_client_debug_set_all, (uint32_t flags, bool set), (flags, set));
-
-static void nb_debug_set_all(uint32_t flags, bool set)
-{
- for (unsigned int i = 0; i < array_size(nb_debugs); i++) {
- DEBUG_FLAGS_SET(nb_debugs[i], flags, set);
-
- /* If all modes have been turned off, don't preserve options. */
- if (!DEBUG_MODE_CHECK(nb_debugs[i], DEBUG_MODE_ALL))
- DEBUG_CLEAR(nb_debugs[i]);
- }
-
- hook_call(nb_client_debug_set_all, flags, set);
-}
-
DEFPY (debug_nb,
debug_nb_cmd,
"[no] debug northbound\
"libyang debugging\n")
{
uint32_t mode = DEBUG_NODE2MODE(vty->node);
+ bool all = false;
- if (cbs) {
+ /* no specific debug --> act on all of them */
+ if (strmatch(argv[argc - 1]->text, "northbound"))
+ all = true;
+
+ if (cbs || all) {
bool none = (!cbs_cfg && !cbs_state && !cbs_rpc && !cbs_notify);
if (none || cbs_cfg)
if (none || cbs_notify)
DEBUG_MODE_SET(&nb_dbg_cbs_notify, mode, !no);
}
- if (notifications)
+ if (notifications || all)
DEBUG_MODE_SET(&nb_dbg_notif, mode, !no);
- if (events)
+ if (events || all)
DEBUG_MODE_SET(&nb_dbg_events, mode, !no);
- if (libyang) {
+ if (libyang || all) {
DEBUG_MODE_SET(&nb_dbg_libyang, mode, !no);
yang_debugging_set(!no);
}
- /* no specific debug --> act on all of them */
- if (strmatch(argv[argc - 1]->text, "northbound")) {
- nb_debug_set_all(mode, !no);
- yang_debugging_set(!no);
- }
-
return CMD_SUCCESS;
}
return 1;
}
-static struct debug_callbacks nb_dbg_cbs = {.debug_set_all = nb_debug_set_all};
static struct cmd_node nb_debug_node = {
.name = "northbound debug",
.node = NORTHBOUND_DEBUG_NODE,
/* Initialize the shared candidate configuration. */
vty_shared_candidate_config = nb_config_new(NULL);
- debug_init(&nb_dbg_cbs);
+ debug_install(&nb_dbg_cbs_config);
+ debug_install(&nb_dbg_cbs_state);
+ debug_install(&nb_dbg_cbs_rpc);
+ debug_install(&nb_dbg_cbs_notify);
+ debug_install(&nb_dbg_notif);
+ debug_install(&nb_dbg_events);
+ debug_install(&nb_dbg_libyang);
install_node(&nb_debug_node);
install_element(ENABLE_NODE, &debug_nb_cmd);
return 0;
}
-static int frr_sr_debug_set_all(uint32_t flags, bool set)
-{
- DEBUG_FLAGS_SET(&nb_dbg_client_sysrepo, flags, set);
-
- /* If all modes have been turned off, don't preserve options. */
- if (!DEBUG_MODE_CHECK(&nb_dbg_client_sysrepo, DEBUG_MODE_ALL))
- DEBUG_CLEAR(&nb_dbg_client_sysrepo);
-
- return 0;
-}
-
static void frr_sr_cli_init(void)
{
hook_register(nb_client_debug_config_write, frr_sr_debug_config_write);
- hook_register(nb_client_debug_set_all, frr_sr_debug_set_all);
+
+ debug_install(&nb_dbg_client_sysrepo);
install_element(ENABLE_NODE, &debug_nb_sr_cmd);
install_element(CONFIG_NODE, &debug_nb_sr_cmd);
void mgmt_init(void)
{
+ debug_install(&mgmt_debug_be);
+ debug_install(&mgmt_debug_ds);
+ debug_install(&mgmt_debug_fe);
+ debug_install(&mgmt_debug_txn);
/* Initialize datastores */
mgmt_ds_init(mm);
return 0;
}
-static int path_policy_cli_debug_set_all(uint32_t flags, bool set)
-{
- DEBUG_FLAGS_SET(&path_policy_debug, flags, set);
-
- /* If all modes have been turned off, don't preserve options. */
- if (!DEBUG_MODE_CHECK(&path_policy_debug, DEBUG_MODE_ALL))
- DEBUG_CLEAR(&path_policy_debug);
-
- return 0;
-}
-
void path_cli_init(void)
{
hook_register(nb_client_debug_config_write,
path_policy_cli_debug_config_write);
- hook_register(nb_client_debug_set_all, path_policy_cli_debug_set_all);
+
+ debug_install(&path_policy_debug);
install_node(&segment_routing_node);
install_node(&sr_traffic_eng_node);
/* CLI Function declarations */
static int pcep_cli_debug_config_write(struct vty *vty);
-static int pcep_cli_debug_set_all(uint32_t flags, bool set);
static int pcep_cli_pcep_config_write(struct vty *vty);
static int pcep_cli_pcc_config_write(struct vty *vty);
static int pcep_cli_pce_config_write(struct vty *vty);
return 0;
}
-int pcep_cli_debug_set_all(uint32_t flags, bool set)
-{
- DEBUG_FLAGS_SET(&pcep_g->dbg, flags, set);
-
- /* If all modes have been turned off, don't preserve options. */
- if (!DEBUG_MODE_CHECK(&pcep_g->dbg, DEBUG_MODE_ALL))
- DEBUG_CLEAR(&pcep_g->dbg);
-
- return 0;
-}
-
int pcep_cli_pcep_config_write(struct vty *vty)
{
vty_out(vty, " pcep\n");
hook_register(pathd_srte_config_write, pcep_cli_pcep_config_write);
hook_register(nb_client_debug_config_write,
pcep_cli_debug_config_write);
- hook_register(nb_client_debug_set_all, pcep_cli_debug_set_all);
+
+ debug_install(&pcep_g->dbg_basic);
+ debug_install(&pcep_g->dbg_path);
+ debug_install(&pcep_g->dbg_msg);
+ debug_install(&pcep_g->dbg_lib);
memset(&pce_connections_g, 0, sizeof(pce_connections_g));
static void path_ted_timer_handler_sync(struct event *thread);
static void path_ted_timer_handler_refresh(struct event *thread);
static int path_ted_cli_debug_config_write(struct vty *vty);
-static int path_ted_cli_debug_set_all(uint32_t flags, bool set);
extern struct zclient *zclient;
vty_out(vty, " Path TED debugging is on\n");
}
-int path_ted_cli_debug_set_all(uint32_t flags, bool set)
-{
- DEBUG_FLAGS_SET(&ted_state_g.dbg, flags, set);
-
- /* If all modes have been turned off, don't preserve options. */
- if (!DEBUG_MODE_CHECK(&ted_state_g.dbg, DEBUG_MODE_ALL))
- DEBUG_CLEAR(&ted_state_g.dbg);
-
- return 0;
-}
-
/**
* Help fn to show ted related configuration
*
hook_register(nb_client_debug_config_write,
path_ted_cli_debug_config_write);
- hook_register(nb_client_debug_set_all, path_ted_cli_debug_set_all);
+
+ debug_install(&ted_state_g.dbg);
}
/**
"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;
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);
}
"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;
}
};
/* clang-format on */
-
-/*
- * Set or unset all staticd debugs
- *
- * flags
- * The flags to set
- *
- * set
- * Whether to set or unset the specified flags
- */
-static void static_debug_set_all(uint32_t flags, bool set)
-{
- for (unsigned int i = 0; i < array_size(static_debug_arr); i++) {
- DEBUG_FLAGS_SET(static_debug_arr[i], flags, set);
-
- /* if all modes have been turned off, don't preserve options */
- if (!DEBUG_MODE_CHECK(static_debug_arr[i], DEBUG_MODE_ALL))
- DEBUG_CLEAR(static_debug_arr[i]);
- }
-}
-
static int static_debug_config_write_helper(struct vty *vty, bool config)
{
uint32_t mode = DEBUG_MODE_ALL;
* Debug lib initialization
*/
-struct debug_callbacks static_dbg_cbs = {
- .debug_set_all = static_debug_set_all
-};
-
void static_debug_init(void)
{
- debug_init(&static_dbg_cbs);
+ debug_install(&static_dbg_events);
+ debug_install(&static_dbg_route);
+ debug_install(&static_dbg_bfd);
}
*/
#include <zebra.h>
+#include "debug.h"
#include "memory.h"
#include "plist.h"
#include "printfrr.h"
static void bgp_startup(void)
{
cmd_init(1);
+ debug_init();
zlog_aux_init("NONE: ", LOG_DEBUG);
zprivs_preinit(&bgpd_privs);
zprivs_init(&bgpd_privs);
#include <sys/stat.h>
#include <lib/version.h>
+#include "debug.h"
#include "getopt.h"
#include "frrevent.h"
#include "vty.h"
cmd_init(1);
vty_init(master, false);
lib_cmd_init();
+ debug_init();
nb_init(master, NULL, 0, false);
/* OSPF vty inits. */
#include <zebra.h>
#include <sys/stat.h>
+#include "debug.h"
#include "frrevent.h"
#include "vty.h"
#include "command.h"
vty_init(master, false);
lib_cmd_init();
+ debug_init();
for (yangcount = 0; test_yang_modules && test_yang_modules[yangcount];
yangcount++)
#include <stdlib.h>
#include <unistd.h>
+#include "debug.h"
#include "command.h"
#include "memory.h"
#include "vector.h"
struct cmd_element *cmd;
cmd_init(1);
+ debug_init();
nb_init(master, NULL, 0, false);
install_node(&bgp_node);
#include <zebra.h>
#include <sys/stat.h>
+#include "debug.h"
#include "frrevent.h"
#include "vty.h"
#include "command.h"
cmd_hostname_set("test");
vty_init(master, false);
lib_cmd_init();
+ debug_init();
nb_init(master, modules, array_size(modules), false);
install_element(ENABLE_NODE, &test_rpc_cmd);
#include <unistd.h>
#include <zebra.h>
+#include "debug.h"
#include "filter.h"
#include "frr_pthread.h"
#include "libfrr.h"
// static struct option_chain *oc;
cmd_init(1);
+ debug_init();
zlog_aux_init("NONE: ", LOG_DEBUG);
zprivs_preinit(&static_privs);
};
/* clang-format on */
-/*
- * Set or unset flags on all debugs for vrrpd.
- *
- * flags
- * The flags to set
- *
- * set
- * Whether to set or unset the specified flags
- */
-static void vrrp_debug_set_all(uint32_t flags, bool set)
-{
- for (unsigned int i = 0; i < array_size(vrrp_debugs); i++) {
- DEBUG_FLAGS_SET(vrrp_debugs[i], flags, set);
-
- /* if all modes have been turned off, don't preserve options */
- if (!DEBUG_MODE_CHECK(vrrp_debugs[i], DEBUG_MODE_ALL))
- DEBUG_CLEAR(vrrp_debugs[i]);
- }
-}
-
static int vrrp_debug_config_write_helper(struct vty *vty, bool config)
{
uint32_t mode = DEBUG_MODE_ALL;
/* ------------------------------------------------------------------------- */
-struct debug_callbacks vrrp_dbg_cbs = {.debug_set_all = vrrp_debug_set_all};
-
void vrrp_debug_init(void)
{
- debug_init(&vrrp_dbg_cbs);
+ debug_install(&vrrp_dbg_arp);
+ debug_install(&vrrp_dbg_auto);
+ debug_install(&vrrp_dbg_ndisc);
+ debug_install(&vrrp_dbg_pkt);
+ debug_install(&vrrp_dbg_proto);
+ debug_install(&vrrp_dbg_sock);
+ debug_install(&vrrp_dbg_zebra);
}