From 461b5e4e20cc7f2a0bb5cb6c65400f8b62ffefc5 Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Tue, 26 Mar 2024 20:25:21 +0200 Subject: [PATCH] lib: common debug status output Implement common code for debug status output and remove daemon-specific code that is duplicated everywhere. Signed-off-by: Igor Ryzhov --- lib/command.c | 4 ++-- lib/debug.c | 10 ++++++++++ lib/debug.h | 3 +++ lib/mgmt_be_client.c | 6 ------ lib/mgmt_be_client.h | 5 ----- lib/mgmt_fe_client.c | 6 ------ lib/mgmt_fe_client.h | 5 ----- mgmtd/mgmt_vty.c | 28 ---------------------------- pathd/path_cli.c | 4 +--- pathd/path_pcep_cli.c | 22 ---------------------- pathd/path_ted.c | 11 ----------- pathd/path_ted.h | 1 - pathd/pathd.c | 6 ------ pathd/pathd.h | 1 - pbrd/pbr_debug.c | 23 ----------------------- pbrd/pbr_debug.h | 14 -------------- pbrd/pbr_vty.c | 2 -- staticd/static_debug.c | 31 ------------------------------- staticd/static_debug.h | 8 -------- staticd/static_vty.c | 2 -- vrrpd/vrrp_debug.c | 39 --------------------------------------- vrrpd/vrrp_vty.c | 2 -- 22 files changed, 16 insertions(+), 217 deletions(-) diff --git a/lib/command.c b/lib/command.c index 0288ab75995b..26f5b7a857ad 100644 --- a/lib/command.c +++ b/lib/command.c @@ -17,6 +17,7 @@ #include #include "command.h" +#include "debug.h" #include "frrstr.h" #include "memory.h" #include "log.h" @@ -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) diff --git a/lib/debug.c b/lib/debug.c index 043fad345099..a6843bfa24ed 100644 --- a/lib/debug.c +++ b/lib/debug.c @@ -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; diff --git a/lib/debug.h b/lib/debug.h index 60f42e30712b..eee314cff55a 100644 --- a/lib/debug.h +++ b/lib/debug.h @@ -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. */ diff --git a/lib/mgmt_be_client.c b/lib/mgmt_be_client.c index 91f2208f96f0..166cee71e6f7 100644 --- a/lib/mgmt_be_client.c +++ b/lib/mgmt_be_client.c @@ -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, diff --git a/lib/mgmt_be_client.h b/lib/mgmt_be_client.h index cd8b23752671..2a0800db3568 100644 --- a/lib/mgmt_be_client.h +++ b/lib/mgmt_be_client.h @@ -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). * diff --git a/lib/mgmt_fe_client.c b/lib/mgmt_fe_client.c index 0308d70a7eaa..af428dafea1a 100644 --- a/lib/mgmt_fe_client.c +++ b/lib/mgmt_fe_client.c @@ -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. */ diff --git a/lib/mgmt_fe_client.h b/lib/mgmt_fe_client.h index eee4594e17dc..011b2931d740 100644 --- a/lib/mgmt_fe_client.h +++ b/lib/mgmt_fe_client.h @@ -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. * diff --git a/mgmtd/mgmt_vty.c b/mgmtd/mgmt_vty.c index 8b0b2efee28b..0c8fd9af94cf 100644 --- a/mgmtd/mgmt_vty.c +++ b/mgmtd/mgmt_vty.c @@ -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; diff --git a/pathd/path_cli.c b/pathd/path_cli.c index 754fdf7a62a0..436883c1fd82 100644 --- a/pathd/path_cli.c +++ b/pathd/path_cli.c @@ -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; } diff --git a/pathd/path_pcep_cli.c b/pathd/path_pcep_cli.c index 6e2289073513..1c7efd6eb22b 100644 --- a/pathd/path_pcep_cli.c +++ b/pathd/path_pcep_cli.c @@ -1951,27 +1951,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}]", @@ -2367,7 +2346,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); diff --git a/pathd/path_ted.c b/pathd/path_ted.c index 88cda791870c..0f8d3827ff58 100644 --- a/pathd/path_ted.c +++ b/pathd/path_ted.c @@ -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 * diff --git a/pathd/path_ted.h b/pathd/path_ted.h index a166edd266fa..b6c97431f977 100644 --- a/pathd/path_ted.h +++ b/pathd/path_ted.h @@ -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 */ diff --git a/pathd/pathd.c b/pathd/pathd.c index e99955e6d31e..bb72fd75c62d 100644 --- a/pathd/pathd.c +++ b/pathd/pathd.c @@ -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(); diff --git a/pathd/pathd.h b/pathd/pathd.h index c8cde33a16f0..75e7eff920e7 100644 --- a/pathd/pathd.h +++ b/pathd/pathd.h @@ -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); diff --git a/pbrd/pbr_debug.c b/pbrd/pbr_debug.c index 027f1e2c5c17..6b0d1d5a811f 100644 --- a/pbrd/pbr_debug.c +++ b/pbrd/pbr_debug.c @@ -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); diff --git a/pbrd/pbr_debug.h b/pbrd/pbr_debug.h index 101c6986b3af..c1ffce99b815 100644 --- a/pbrd/pbr_debug.h +++ b/pbrd/pbr_debug.h @@ -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__ */ diff --git a/pbrd/pbr_vty.c b/pbrd/pbr_vty.c index d08310ca8194..08fe56c7bb3e 100644 --- a/pbrd/pbr_vty.c +++ b/pbrd/pbr_vty.c @@ -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; diff --git a/staticd/static_debug.c b/staticd/static_debug.c index 7e70271063cd..618ba91d1243 100644 --- a/staticd/static_debug.c +++ b/staticd/static_debug.c @@ -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. * diff --git a/staticd/static_debug.h b/staticd/static_debug.h index 347f38b63956..b990f7bcc9b7 100644 --- a/staticd/static_debug.h +++ b/staticd/static_debug.h @@ -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. * diff --git a/staticd/static_vty.c b/staticd/static_vty.c index 65c87368822d..07b8bc3d2816 100644 --- a/staticd/static_vty.c +++ b/staticd/static_vty.c @@ -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; diff --git a/vrrpd/vrrp_debug.c b/vrrpd/vrrp_debug.c index ccb0803c0c81..fd0edcfc77e6 100644 --- a/vrrpd/vrrp_debug.c +++ b/vrrpd/vrrp_debug.c @@ -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) diff --git a/vrrpd/vrrp_vty.c b/vrrpd/vrrp_vty.c index 53f66c79c9b6..985354af370a 100644 --- a/vrrpd/vrrp_vty.c +++ b/vrrpd/vrrp_vty.c @@ -738,8 +738,6 @@ DEFUN_NOSH (show_debugging_vrrp, { vty_out(vty, "VRRP debugging status:\n"); - vrrp_debug_status_write(vty); - cmd_show_lib_debugs(vty); return CMD_SUCCESS;