Skip to content

Commit

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

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
  • Loading branch information
idryzhov committed Apr 1, 2024
1 parent e2e597f commit e0ce651
Show file tree
Hide file tree
Showing 22 changed files with 16 additions and 217 deletions.
4 changes: 2 additions & 2 deletions lib/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <lib/version.h>

#include "command.h"
#include "debug.h"
#include "frrstr.h"
#include "memory.h"
#include "log.h"
Expand Down Expand Up @@ -2463,8 +2464,7 @@ const char *host_config_get(void)
void cmd_show_lib_debugs(struct vty *vty)
{
route_map_show_debug(vty);
mgmt_debug_be_client_show_debug(vty);
mgmt_debug_fe_client_show_debug(vty);
debug_status_write(vty);
}

void install_default(enum node_type node)
Expand Down
10 changes: 10 additions & 0 deletions lib/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ DEFUN_NOSH(debug_all, debug_all_cmd, "[no] debug all",

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

void debug_status_write(struct vty *vty)
{
struct debug *debug;

frr_each (debug_list, &debug_head, debug) {
if (DEBUG_MODE_CHECK(debug, DEBUG_MODE_ALL))
vty_out(vty, " %s debugging is on\n", debug->desc);
}
}

static int config_write_debug(struct vty *vty)
{
struct debug *debug;
Expand Down
3 changes: 3 additions & 0 deletions lib/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ struct debug {
#define DEBUGN(name, fmt, ...) DEBUG(notice, name, fmt, ##__VA_ARGS__)
#define DEBUGD(name, fmt, ...) DEBUG(debug, name, fmt, ##__VA_ARGS__)

/* Show current debugging status. */
void debug_status_write(struct vty *vty);

/*
* Register a debug item.
*/
Expand Down
6 changes: 0 additions & 6 deletions lib/mgmt_be_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1116,12 +1116,6 @@ DEFPY(debug_mgmt_client_be, debug_mgmt_client_be_cmd,
return CMD_SUCCESS;
}

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

struct mgmt_be_client *mgmt_be_client_create(const char *client_name,
struct mgmt_be_client_cbs *cbs,
uintptr_t user_data,
Expand Down
5 changes: 0 additions & 5 deletions lib/mgmt_be_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,6 @@ mgmt_be_client_create(const char *name, struct mgmt_be_client_cbs *cbs,
*/
extern void mgmt_be_client_lib_vty_init(void);

/*
* Print enabled debugging commands.
*/
extern void mgmt_debug_be_client_show_debug(struct vty *vty);

/*
* [Un]-subscribe with MGMTD for one or more YANG subtree(s).
*
Expand Down
6 changes: 0 additions & 6 deletions lib/mgmt_fe_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,12 +707,6 @@ DEFPY(debug_mgmt_client_fe, debug_mgmt_client_fe_cmd,
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");
}

/*
* Initialize library and try connecting with MGMTD.
*/
Expand Down
5 changes: 0 additions & 5 deletions lib/mgmt_fe_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,6 @@ mgmt_fe_client_create(const char *client_name, struct mgmt_fe_client_cbs *cbs,
*/
extern void mgmt_fe_client_lib_vty_init(void);

/*
* Print enabled debugging commands.
*/
extern void mgmt_debug_fe_client_show_debug(struct vty *vty);

/*
* Create a new Session for a Frontend Client connection.
*
Expand Down
28 changes: 0 additions & 28 deletions mgmtd/mgmt_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,39 +484,11 @@ DEFPY(mgmt_rollback,
return CMD_SUCCESS;
}

static int write_mgmt_debug_helper(struct vty *vty, bool config)
{
uint32_t mode = config ? DEBUG_MODE_CONF : DEBUG_MODE_ALL;
bool be = DEBUG_MODE_CHECK(&mgmt_debug_be, mode);
bool ds = DEBUG_MODE_CHECK(&mgmt_debug_ds, mode);
bool fe = DEBUG_MODE_CHECK(&mgmt_debug_fe, mode);
bool txn = DEBUG_MODE_CHECK(&mgmt_debug_txn, mode);

if (!(be || ds || fe || txn))
return 0;

vty_out(vty, "debug mgmt");
if (be)
vty_out(vty, " backend");
if (ds)
vty_out(vty, " datastore");
if (fe)
vty_out(vty, " frontend");
if (txn)
vty_out(vty, " transaction");

vty_out(vty, "\n");

return 0;
}

DEFPY_NOSH(show_debugging_mgmt, show_debugging_mgmt_cmd,
"show debugging [mgmt]", SHOW_STR DEBUG_STR "MGMT Information\n")
{
vty_out(vty, "MGMT debugging status:\n");

write_mgmt_debug_helper(vty, false);

cmd_show_lib_debugs(vty);

return CMD_SUCCESS;
Expand Down
4 changes: 1 addition & 3 deletions pathd/path_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -1089,9 +1089,7 @@ DEFPY_NOSH(show_debugging_pathd, show_debugging_pathd_cmd,
vty_out(vty, "Path debugging status:\n");

cmd_show_lib_debugs(vty);
/* nothing to do here */
path_ted_show_debugging(vty);
path_policy_show_debugging(vty);

return CMD_SUCCESS;
}

Expand Down
22 changes: 0 additions & 22 deletions pathd/path_pcep_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -1952,27 +1952,6 @@ int pcep_cli_pcep_pce_config_write(struct vty *vty)
* The param names are taken from the path_pcep_cli_clippy.c generated file.
*/

DEFPY(show_debugging_pathd_pcep,
show_debugging_pathd_pcep_cmd,
"show debugging pathd-pcep",
SHOW_STR
"State of each debugging option\n"
"pathd pcep module debugging\n")
{
vty_out(vty, "Pathd pcep debugging status:\n");

if (DEBUG_MODE_CHECK(&pcep_g->dbg_basic, DEBUG_MODE_ALL))
vty_out(vty, "PCEP basic debugging is on\n");
if (DEBUG_MODE_CHECK(&pcep_g->dbg_path, DEBUG_MODE_ALL))
vty_out(vty, "PCEP path debugging is on\n");
if (DEBUG_MODE_CHECK(&pcep_g->dbg_msg, DEBUG_MODE_ALL))
vty_out(vty, "PCEP message debugging is on\n");
if (DEBUG_MODE_CHECK(&pcep_g->dbg_lib, DEBUG_MODE_ALL))
vty_out(vty, "PCEP lib debugging is on\n");

return CMD_SUCCESS;
}

DEFPY(pcep_cli_debug,
pcep_cli_debug_cmd,
"[no] debug pathd pcep [{basic$basic|path$path|message$msg|pceplib$lib}]",
Expand Down Expand Up @@ -2369,7 +2348,6 @@ void pcep_cli_init(void)
/* Top commands */
install_element(CONFIG_NODE, &pcep_cli_debug_cmd);
install_element(ENABLE_NODE, &pcep_cli_debug_cmd);
install_element(ENABLE_NODE, &show_debugging_pathd_pcep_cmd);
install_element(ENABLE_NODE, &pcep_cli_show_srte_pcep_counters_cmd);
install_element(ENABLE_NODE, &pcep_cli_show_srte_pcep_pce_config_cmd);
install_element(ENABLE_NODE, &pcep_cli_show_srte_pcep_pce_cmd);
Expand Down
11 changes: 0 additions & 11 deletions pathd/path_ted.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,17 +463,6 @@ DEFPY (show_pathd_ted_db,
return CMD_SUCCESS;
}

/*
* Config Write functions
*/


void path_ted_show_debugging(struct vty *vty)
{
if (DEBUG_MODE_CHECK(&ted_state_g.dbg, DEBUG_MODE_ALL))
vty_out(vty, " Path TED debugging is on\n");
}

/**
* Help fn to show ted related configuration
*
Expand Down
1 change: 0 additions & 1 deletion pathd/path_ted.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ int path_ted_segment_list_refresh(void);

/* TED configuration functions */
uint32_t path_ted_config_write(struct vty *vty);
void path_ted_show_debugging(struct vty *vty);

/* TED util functions */
/* clang-format off */
Expand Down
6 changes: 0 additions & 6 deletions pathd/pathd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1269,12 +1269,6 @@ const char *srte_origin2str(enum srte_protocol_origin origin)
assert(!"Reached end of function we should never hit");
}

void path_policy_show_debugging(struct vty *vty)
{
if (DEBUG_MODE_CHECK(&path_policy_debug, DEBUG_MODE_ALL))
vty_out(vty, " Path policy debugging is on\n");
}

void pathd_shutdown(void)
{
path_ted_teardown();
Expand Down
1 change: 0 additions & 1 deletion pathd/pathd.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ void srte_candidate_status_update(struct srte_candidate *candidate, int status);
void srte_candidate_unset_segment_list(const char *originator, bool force);
const char *srte_origin2str(enum srte_protocol_origin origin);
void pathd_shutdown(void);
void path_policy_show_debugging(struct vty *vty);

/* path_cli.c */
void path_cli_init(void);
Expand Down
23 changes: 0 additions & 23 deletions pbrd/pbr_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,6 @@ struct debug pbr_dbg_zebra = { 0, "debug pbr zebra",
struct debug pbr_dbg_nht = { 0, "debug pbr nht", "PBR nexthop tracking" };
struct debug pbr_dbg_event = { 0, "debug pbr events", "PBR events" };

struct debug *pbr_debugs[] = {&pbr_dbg_map, &pbr_dbg_zebra, &pbr_dbg_nht,
&pbr_dbg_event};

const char *pbr_debugs_conflines[] = {
"debug pbr map",
"debug pbr zebra",
"debug pbr nht",
"debug pbr events",
};

int pbr_debug_config_write_helper(struct vty *vty, bool config)
{
uint32_t mode = DEBUG_MODE_ALL;

if (config)
mode = DEBUG_MODE_CONF;

for (unsigned int i = 0; i < array_size(pbr_debugs); i++)
if (DEBUG_MODE_CHECK(pbr_debugs[i], mode))
vty_out(vty, "%s\n", pbr_debugs_conflines[i]);
return 0;
}

void pbr_debug_init(void)
{
debug_install(&pbr_dbg_map);
Expand Down
14 changes: 0 additions & 14 deletions pbrd/pbr_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,4 @@ void pbr_debug_init(void);
*/
void pbr_debug_set_all(uint32_t flags, bool set);

/*
* Config write helper.
*
* vty
* Vty to write to
*
* config
* Whether we are writing to show run or saving config file
*
* Returns:
* 0 for convenience
*/
int pbr_debug_config_write_helper(struct vty *vty, bool config);

#endif /* __PBR_DEBUG_H__ */
2 changes: 0 additions & 2 deletions pbrd/pbr_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -1993,8 +1993,6 @@ DEFUN_NOSH(show_debugging_pbr,
{
vty_out(vty, "PBR debugging status:\n");

pbr_debug_config_write_helper(vty, false);

cmd_show_lib_debugs(vty);

return CMD_SUCCESS;
Expand Down
31 changes: 0 additions & 31 deletions staticd/static_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,8 @@
struct debug static_dbg_events = {0, "debug static events", "Staticd events"};
struct debug static_dbg_route = {0, "debug static route", "Staticd route"};
struct debug static_dbg_bfd = {0, "debug static bfd", "Staticd bfd"};

struct debug *static_debug_arr[] = {
&static_dbg_events,
&static_dbg_route,
&static_dbg_bfd
};

const char *static_debugs_conflines[] = {
"debug static events",
"debug static route",
"debug static bfd"
};
/* clang-format on */

static int static_debug_config_write_helper(struct vty *vty, bool config)
{
uint32_t mode = DEBUG_MODE_ALL;

if (config)
mode = DEBUG_MODE_CONF;

for (unsigned int i = 0; i < array_size(static_debug_arr); i++)
if (DEBUG_MODE_CHECK(static_debug_arr[i], mode))
vty_out(vty, "%s\n", static_debugs_conflines[i]);

return 0;
}

int static_debug_status_write(struct vty *vty)
{
return static_debug_config_write_helper(vty, false);
}

/*
* Set debugging status.
*
Expand Down
8 changes: 0 additions & 8 deletions staticd/static_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ extern struct debug static_dbg_bfd;
*/
void static_debug_init(void);

/*
* Print staticd debugging configuration, human readable form.
*
* vty
* VTY to print debugging configuration to.
*/
int static_debug_status_write(struct vty *vty);

/*
* Set debugging status.
*
Expand Down
2 changes: 0 additions & 2 deletions staticd/static_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -1639,8 +1639,6 @@ DEFUN_NOSH (show_debugging_static,
{
vty_out(vty, "Staticd debugging status\n");

static_debug_status_write(vty);

cmd_show_lib_debugs(vty);

return CMD_SUCCESS;
Expand Down
39 changes: 0 additions & 39 deletions vrrpd/vrrp_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,8 @@ struct debug vrrp_dbg_pkt = {0, "debug vrrp packets", "VRRP packets"};
struct debug vrrp_dbg_proto = {0, "debug vrrp protocol", "VRRP protocol events"};
struct debug vrrp_dbg_sock = {0, "debug vrrp sockets", "VRRP sockets"};
struct debug vrrp_dbg_zebra = {0, "debug vrrp zebra", "VRRP Zebra events"};

struct debug *vrrp_debugs[] = {
&vrrp_dbg_arp,
&vrrp_dbg_auto,
&vrrp_dbg_ndisc,
&vrrp_dbg_pkt,
&vrrp_dbg_proto,
&vrrp_dbg_sock,
&vrrp_dbg_zebra
};

const char *vrrp_debugs_conflines[] = {
"debug vrrp arp",
"debug vrrp autoconfigure",
"debug vrrp ndisc",
"debug vrrp packets",
"debug vrrp protocol",
"debug vrrp sockets",
"debug vrrp zebra",
};
/* clang-format on */

static int vrrp_debug_config_write_helper(struct vty *vty, bool config)
{
uint32_t mode = DEBUG_MODE_ALL;

if (config)
mode = DEBUG_MODE_CONF;

for (unsigned int i = 0; i < array_size(vrrp_debugs); i++)
if (DEBUG_MODE_CHECK(vrrp_debugs[i], mode))
vty_out(vty, "%s\n", vrrp_debugs_conflines[i]);

return 0;
}

int vrrp_debug_status_write(struct vty *vty)
{
return vrrp_debug_config_write_helper(vty, false);
}

void vrrp_debug_set(struct interface *ifp, uint8_t vrid, int vtynode,
bool onoff, bool proto, bool autoconf, bool pkt, bool sock,
bool ndisc, bool arp, bool zebra)
Expand Down

0 comments on commit e0ce651

Please sign in to comment.