Skip to content

Commit

Permalink
lib: common debug config output
Browse files Browse the repository at this point in the history
Implement common code for debug config output and remove daemon-specific
code that is duplicated everywhere.

Signed-off-by: Igor Ryzhov <[email protected]>
  • Loading branch information
idryzhov committed Apr 1, 2024
1 parent b0e6f69 commit e2e597f
Show file tree
Hide file tree
Showing 26 changed files with 79 additions and 248 deletions.
4 changes: 1 addition & 3 deletions lib/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,12 @@ enum node_type {
CONFIG_NODE, /* Config node. Default mode of config file. */
PREFIX_NODE, /* ip prefix-list node. */
PREFIX_IPV6_NODE, /* ipv6 prefix-list node. */
LIB_DEBUG_NODE, /* frrlib debug node. */
DEBUG_NODE, /* Debug node. */
VRF_DEBUG_NODE, /* Vrf Debug node. */
NORTHBOUND_DEBUG_NODE, /* Northbound Debug node. */
DEBUG_VNC_NODE, /* Debug VNC node. */
RMAP_DEBUG_NODE, /* Route-map debug node */
RESOLVER_DEBUG_NODE, /* Resolver debug node */
MGMT_BE_DEBUG_NODE, /* mgmtd backend-client debug node */
MGMT_FE_DEBUG_NODE, /* mgmtd frontend-client debug node */
AAA_NODE, /* AAA node. */
EXTLOG_NODE, /* RFC5424 & co. extended syslog */
KEYCHAIN_NODE, /* Key-chain node. */
Expand Down
21 changes: 21 additions & 0 deletions lib/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,25 @@ DEFUN_NOSH(debug_all, debug_all_cmd, "[no] debug all",

/* ------------------------------------------------------------------------- */

static int config_write_debug(struct vty *vty)
{
struct debug *debug;

frr_each (debug_list, &debug_head, debug) {
if (DEBUG_MODE_CHECK(debug, DEBUG_MODE_CONF))
vty_out(vty, "%s\n", debug->conf);
}

return 0;
}

static struct cmd_node debug_node = {
.name = "debug",
.node = LIB_DEBUG_NODE,
.prompt = "",
.config_write = config_write_debug,
};

void debug_install(struct debug *debug)
{
debug_list_add_tail(&debug_head, debug);
Expand All @@ -44,6 +63,8 @@ void debug_init(void)
{
debug_list_init(&debug_head);

install_node(&debug_node);

install_element(ENABLE_NODE, &debug_all_cmd);
install_element(CONFIG_NODE, &debug_all_cmd);
}
4 changes: 4 additions & 0 deletions lib/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ PREDECL_LIST(debug_list);
* manipulate the flags field in a multithreaded environment results in
* undefined behavior.
*
* conf
* The configuration string that will be written to the config file.
*
* desc
* Human-readable description of this debugging record.
*/
struct debug {
atomic_uint_fast32_t flags;
const char *conf;
const char *desc;

struct debug_list_item item;
Expand Down
17 changes: 1 addition & 16 deletions lib/mgmt_be_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ struct mgmt_be_client {
frr_each_safe (mgmt_be_txns, &(client_ctx)->txn_head, (txn))

struct debug mgmt_dbg_be_client = {
.conf = "debug mgmt client backend",
.desc = "Management backend client operations"
};

Expand Down Expand Up @@ -1115,27 +1116,12 @@ DEFPY(debug_mgmt_client_be, debug_mgmt_client_be_cmd,
return CMD_SUCCESS;
}

static int mgmt_debug_be_client_config_write(struct vty *vty)
{
if (DEBUG_MODE_CHECK(&mgmt_dbg_be_client, DEBUG_MODE_CONF))
vty_out(vty, "debug mgmt client backend\n");

return 1;
}

void mgmt_debug_be_client_show_debug(struct vty *vty)
{
if (debug_check_be_client())
vty_out(vty, "debug mgmt client backend\n");
}

static struct cmd_node mgmt_dbg_node = {
.name = "debug mgmt client backend",
.node = MGMT_BE_DEBUG_NODE,
.prompt = "",
.config_write = mgmt_debug_be_client_config_write,
};

struct mgmt_be_client *mgmt_be_client_create(const char *client_name,
struct mgmt_be_client_cbs *cbs,
uintptr_t user_data,
Expand Down Expand Up @@ -1183,7 +1169,6 @@ void mgmt_be_client_lib_vty_init(void)
{
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);
}
Expand Down
17 changes: 1 addition & 16 deletions lib/mgmt_fe_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct mgmt_fe_client {
frr_each_safe (mgmt_sessions, &(client)->sessions, (session))

struct debug mgmt_dbg_fe_client = {
.conf = "debug mgmt client frontend",
.desc = "Management frontend client operations"
};

Expand Down Expand Up @@ -706,27 +707,12 @@ DEFPY(debug_mgmt_client_fe, debug_mgmt_client_fe_cmd,
return CMD_SUCCESS;
}

static int mgmt_debug_fe_client_config_write(struct vty *vty)
{
if (DEBUG_MODE_CHECK(&mgmt_dbg_fe_client, DEBUG_MODE_CONF))
vty_out(vty, "debug mgmt client frontend\n");

return CMD_SUCCESS;
}

void mgmt_debug_fe_client_show_debug(struct vty *vty)
{
if (debug_check_fe_client())
vty_out(vty, "debug mgmt client frontend\n");
}

static struct cmd_node mgmt_dbg_node = {
.name = "debug mgmt client frontend",
.node = MGMT_FE_DEBUG_NODE,
.prompt = "",
.config_write = mgmt_debug_fe_client_config_write,
};

/*
* Initialize library and try connecting with MGMTD.
*/
Expand Down Expand Up @@ -769,7 +755,6 @@ void mgmt_fe_client_lib_vty_init(void)
{
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);
}
Expand Down
1 change: 0 additions & 1 deletion lib/northbound.h
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,6 @@ DECLARE_HOOK(nb_notification_send, (const char *xpath, struct list *arguments),
(xpath, arguments));
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));

/* Northbound debugging records */
extern struct debug nb_dbg_cbs_config;
Expand Down
57 changes: 13 additions & 44 deletions lib/northbound_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@
#include "northbound_db.h"
#include "lib/northbound_cli_clippy.c"

struct debug nb_dbg_cbs_config = {0, "Northbound callbacks: configuration"};
struct debug nb_dbg_cbs_state = {0, "Northbound callbacks: state"};
struct debug nb_dbg_cbs_rpc = {0, "Northbound callbacks: RPCs"};
struct debug nb_dbg_cbs_notify = {0, "Northbound callbacks: notifications"};
struct debug nb_dbg_notif = {0, "Northbound notifications"};
struct debug nb_dbg_events = {0, "Northbound events"};
struct debug nb_dbg_libyang = {0, "libyang debugging"};
struct debug nb_dbg_cbs_config = { 0, "debug northbound callbacks configuration",
"Northbound callbacks: configuration" };
struct debug nb_dbg_cbs_state = { 0, "debug northbound callbacks state",
"Northbound callbacks: state" };
struct debug nb_dbg_cbs_rpc = { 0, "debug northbound callbacks rpc",
"Northbound callbacks: RPCs" };
struct debug nb_dbg_cbs_notify = { 0, "debug northbound callbacks notify",
"Northbound callbacks: notifications" };
struct debug nb_dbg_notif = { 0, "debug northbound notifications",
"Northbound notifications" };
struct debug nb_dbg_events = { 0, "debug northbound events",
"Northbound events" };
struct debug nb_dbg_libyang = { 0, "debug northbound libyang", "libyang" };

struct nb_config *vty_shared_candidate_config;
static struct event_loop *master;
Expand Down Expand Up @@ -1771,22 +1777,6 @@ DEFPY (rollback_config,
}

/* Debug CLI commands. */
static struct debug *nb_debugs[] = {
&nb_dbg_cbs_config, &nb_dbg_cbs_state, &nb_dbg_cbs_rpc,
&nb_dbg_cbs_notify, &nb_dbg_notif, &nb_dbg_events,
&nb_dbg_libyang,
};

static const char *const nb_debugs_conflines[] = {
"debug northbound callbacks configuration",
"debug northbound callbacks state",
"debug northbound callbacks rpc",
"debug northbound callbacks notify",
"debug northbound notifications",
"debug northbound events",
"debug northbound libyang",
};

DEFPY (debug_nb,
debug_nb_cmd,
"[no] debug northbound\
Expand Down Expand Up @@ -1839,26 +1829,6 @@ DEFPY (debug_nb,
return CMD_SUCCESS;
}

DEFINE_HOOK(nb_client_debug_config_write, (struct vty *vty), (vty));

static int nb_debug_config_write(struct vty *vty)
{
for (unsigned int i = 0; i < array_size(nb_debugs); i++)
if (DEBUG_MODE_CHECK(nb_debugs[i], DEBUG_MODE_CONF))
vty_out(vty, "%s\n", nb_debugs_conflines[i]);

hook_call(nb_client_debug_config_write, vty);

return 1;
}

static struct cmd_node nb_debug_node = {
.name = "northbound debug",
.node = NORTHBOUND_DEBUG_NODE,
.prompt = "",
.config_write = nb_debug_config_write,
};

void nb_cli_install_default(int node)
{
_install_element(node, &show_config_candidate_section_cmd);
Expand Down Expand Up @@ -1927,7 +1897,6 @@ void nb_cli_init(struct event_loop *tm)
debug_install(&nb_dbg_events);
debug_install(&nb_dbg_libyang);

install_node(&nb_debug_node);
install_element(ENABLE_NODE, &debug_nb_cmd);
install_element(CONFIG_NODE, &debug_nb_cmd);

Expand Down
14 changes: 3 additions & 11 deletions lib/northbound_sysrepo.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#include <sysrepo/values.h>
#include <sysrepo/xpath.h>

static struct debug nb_dbg_client_sysrepo = {0, "Northbound client: Sysrepo"};
static struct debug nb_dbg_client_sysrepo = { 0,
"debug northbound client sysrepo",
"Northbound client: Sysrepo" };

static struct event_loop *master;
static sr_session_ctx_t *session;
Expand Down Expand Up @@ -606,18 +608,8 @@ DEFUN (debug_nb_sr,
return CMD_SUCCESS;
}

static int frr_sr_debug_config_write(struct vty *vty)
{
if (DEBUG_MODE_CHECK(&nb_dbg_client_sysrepo, DEBUG_MODE_CONF))
vty_out(vty, "debug northbound client sysrepo\n");

return 0;
}

static void frr_sr_cli_init(void)
{
hook_register(nb_client_debug_config_write, frr_sr_debug_config_write);

debug_install(&nb_dbg_client_sysrepo);

install_element(ENABLE_NODE, &debug_nb_sr_cmd);
Expand Down
12 changes: 8 additions & 4 deletions mgmtd/mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@
#include "mgmtd/mgmt_history.h"
#include "mgmtd/mgmt_memory.h"

struct debug mgmt_debug_be = {.desc = "Management backend adapater"};
struct debug mgmt_debug_ds = {.desc = "Management datastore"};
struct debug mgmt_debug_fe = {.desc = "Management frontend adapater"};
struct debug mgmt_debug_txn = {.desc = "Management transaction"};
struct debug mgmt_debug_be = { .conf = "debug mgmt backend",
.desc = "Management backend adapater" };
struct debug mgmt_debug_ds = { .conf = "debug mgmt datastore",
.desc = "Management datastore" };
struct debug mgmt_debug_fe = { .conf = "debug mgmt frontend",
.desc = "Management frontend adapater" };
struct debug mgmt_debug_txn = { .conf = "debug mgmt transaction",
.desc = "Management transaction" };

/* MGMTD process wide configuration. */
static struct mgmt_master mgmt_master;
Expand Down
14 changes: 0 additions & 14 deletions mgmtd/mgmt_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,6 @@ DEFPY(mgmt_rollback,
return CMD_SUCCESS;
}

int config_write_mgmt_debug(struct vty *vty);
static struct cmd_node debug_node = {
.name = "mgmt debug",
.node = DEBUG_NODE,
.prompt = "",
.config_write = config_write_mgmt_debug,
};

static int write_mgmt_debug_helper(struct vty *vty, bool config)
{
uint32_t mode = config ? DEBUG_MODE_CONF : DEBUG_MODE_ALL;
Expand All @@ -518,11 +510,6 @@ static int write_mgmt_debug_helper(struct vty *vty, bool config)
return 0;
}

int config_write_mgmt_debug(struct vty *vty)
{
return write_mgmt_debug_helper(vty, true);
}

DEFPY_NOSH(show_debugging_mgmt, show_debugging_mgmt_cmd,
"show debugging [mgmt]", SHOW_STR DEBUG_STR "MGMT Information\n")
{
Expand Down Expand Up @@ -623,7 +610,6 @@ void mgmt_vty_init(void)
event_add_event(mm->master, mgmt_config_read_in, NULL, 0,
&mgmt_daemon_info->read_in);

install_node(&debug_node);
install_node(&mgmtd_node);

install_element(VIEW_NODE, &show_mgmt_be_adapter_cmd);
Expand Down
12 changes: 0 additions & 12 deletions pathd/path_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -1305,20 +1305,8 @@ int config_write_segment_routing(struct vty *vty)
return 1;
}

static int path_policy_cli_debug_config_write(struct vty *vty)
{
if (DEBUG_MODE_CHECK(&path_policy_debug, DEBUG_MODE_CONF)) {
vty_out(vty, "debug pathd policy\n");
return 1;
}
return 0;
}

void path_cli_init(void)
{
hook_register(nb_client_debug_config_write,
path_policy_cli_debug_config_write);

debug_install(&path_policy_debug);

install_node(&segment_routing_node);
Expand Down
8 changes: 4 additions & 4 deletions pathd/path_pcep.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ DEFINE_MTYPE(PATHD, PCEP, "PCEP module");
* Globals.
*/
static struct pcep_glob pcep_glob_space = {
.dbg_basic = {0, "PCEP basic"},
.dbg_path = {0, "PCEP path"},
.dbg_msg = {0, "PCEP message"},
.dbg_lib = {0, "PCEP lib"},
.dbg_basic = { 0, "debug pathd pcep basic", "PCEP basic" },
.dbg_path = { 0, "debug pathd pcep path", "PCEP path" },
.dbg_msg = { 0, "debug pathd pcep message", "PCEP message" },
.dbg_lib = { 0, "debug pathd pcep pceplib", "PCEP lib" },
};
struct pcep_glob *pcep_g = &pcep_glob_space;

Expand Down
Loading

0 comments on commit e2e597f

Please sign in to comment.