]> git.puffer.fish Git - matthieu/frr.git/commitdiff
pathd: rework debugs
authorIgor Ryzhov <iryzhov@nfware.com>
Tue, 26 Mar 2024 14:38:45 +0000 (16:38 +0200)
committerMark Stapp <mjs@cisco.com>
Tue, 20 Aug 2024 15:07:45 +0000 (11:07 -0400)
Pathd uses a single debug struct with additional option flags to
configure different types of debug messages. This is not how debug
library is supposed to be used. The idea of option flags is to allow
more granular control of a single type, not to represent multiple types.

This commit adds a separate debug struct for each type which greatly
simplifies the code.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
pathd/path_cli.c
pathd/path_pcep.c
pathd/path_pcep.h
pathd/path_pcep_cli.c
pathd/path_ted.c
pathd/path_ted.h
pathd/pathd.c
pathd/pathd.h

index e22931c13e1e282257e355918644090f5576af48..b841d29bd0f4debe324471918cf4f91acd993470 100644 (file)
@@ -1101,10 +1101,8 @@ DEFPY(debug_path_policy, debug_path_policy_cmd, "[no] debug pathd policy",
       "policy debugging\n")
 {
        uint32_t mode = DEBUG_NODE2MODE(vty->node);
-       bool no_debug = no;
 
        DEBUG_MODE_SET(&path_policy_debug, mode, !no);
-       DEBUG_FLAGS_SET(&path_policy_debug, PATH_POLICY_DEBUG_BASIC, !no_debug);
        return CMD_SUCCESS;
 }
 
@@ -1310,9 +1308,7 @@ int config_write_segment_routing(struct vty *vty)
 static int path_policy_cli_debug_config_write(struct vty *vty)
 {
        if (DEBUG_MODE_CHECK(&path_policy_debug, DEBUG_MODE_CONF)) {
-               if (DEBUG_FLAGS_CHECK(&path_policy_debug,
-                                     PATH_POLICY_DEBUG_BASIC))
-                       vty_out(vty, "debug pathd policy\n");
+               vty_out(vty, "debug pathd policy\n");
                return 1;
        }
        return 0;
index ec9d8adfc1453d7c576ca87c00098e91b4b59c48..65ee2b5a5f5c3e6a88d6b8e9b7efc02c63f8bdc1 100644 (file)
@@ -31,7 +31,12 @@ DEFINE_MTYPE(PATHD, PCEP, "PCEP module");
 /*
  * Globals.
  */
-static struct pcep_glob pcep_glob_space = {.dbg = {0, "pathd module: pcep"}};
+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"},
+};
 struct pcep_glob *pcep_g = &pcep_glob_space;
 
 /* Main Thread Even Handler */
index d6dbcb5c08c9a6206d773882d7729f98cb050a60..a4f899df58a05fd2d07f553fedfbeea1b1306e53 100644 (file)
@@ -27,40 +27,22 @@ DECLARE_MTYPE(PCEP);
 #define PCEP_DEBUG_MODE_PCEPLIB 0x08
 #define PCEP_DEBUG_MODE_ALL 0x0F
 #define PCEP_DEBUG(fmt, ...)                                                   \
-       do {                                                                   \
-               if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_BASIC))    \
-                       DEBUGD(&pcep_g->dbg, "pcep: " fmt, ##__VA_ARGS__);     \
-       } while (0)
+       DEBUGD(&pcep_g->dbg_basic, "pcep: " fmt, ##__VA_ARGS__)
 #define PCEP_DEBUG_PATH(fmt, ...)                                              \
-       do {                                                                   \
-               if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_PATH))     \
-                       DEBUGD(&pcep_g->dbg, "pcep: " fmt, ##__VA_ARGS__);     \
-       } while (0)
+       DEBUGD(&pcep_g->dbg_path, "pcep: " fmt, ##__VA_ARGS__)
 #define PCEP_DEBUG_PCEP(fmt, ...)                                              \
-       do {                                                                   \
-               if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEP))     \
-                       DEBUGD(&pcep_g->dbg, "pcep: " fmt, ##__VA_ARGS__);     \
-       } while (0)
+       DEBUGD(&pcep_g->dbg_msg, "pcep: " fmt, ##__VA_ARGS__)
 #define PCEP_DEBUG_PCEPLIB(priority, fmt, ...)                                 \
        do {                                                                   \
                switch (priority) {                                            \
                case LOG_DEBUG:                                                \
-                       if (DEBUG_FLAGS_CHECK(&pcep_g->dbg,                    \
-                                             PCEP_DEBUG_MODE_PCEPLIB))        \
-                               DEBUGD(&pcep_g->dbg, "pcep: " fmt,             \
-                                      ##__VA_ARGS__);                         \
+                       DEBUGD(&pcep_g->dbg_lib, "pcep: " fmt, ##__VA_ARGS__); \
                        break;                                                 \
                case LOG_INFO:                                                 \
-                       if (DEBUG_FLAGS_CHECK(&pcep_g->dbg,                    \
-                                             PCEP_DEBUG_MODE_PCEPLIB))        \
-                               DEBUGI(&pcep_g->dbg, "pcep: " fmt,             \
-                                      ##__VA_ARGS__);                         \
+                       DEBUGI(&pcep_g->dbg_lib, "pcep: " fmt, ##__VA_ARGS__); \
                        break;                                                 \
                case LOG_NOTICE:                                               \
-                       if (DEBUG_FLAGS_CHECK(&pcep_g->dbg,                    \
-                                             PCEP_DEBUG_MODE_PCEPLIB))        \
-                               DEBUGN(&pcep_g->dbg, "pcep: " fmt,             \
-                                      ##__VA_ARGS__);                         \
+                       DEBUGN(&pcep_g->dbg_lib, "pcep: " fmt, ##__VA_ARGS__); \
                        break;                                                 \
                case LOG_WARNING:                                              \
                case LOG_ERR:                                                  \
@@ -294,7 +276,10 @@ struct path {
 };
 
 struct pcep_glob {
-       struct debug dbg;
+       struct debug dbg_basic;
+       struct debug dbg_path;
+       struct debug dbg_msg;
+       struct debug dbg_lib;
        struct event_loop *master;
        struct frr_pthread *fpt;
        uint8_t num_pce_opts_cli;
index 47a811d144f1e5fde1f6b9d7a8b831a446eb951b..66d1aa8b4e6aa51e710254838b5c1f5d75b9b967 100644 (file)
@@ -110,10 +110,6 @@ static const char PCEP_VTYSH_ARG_DELEGATION_TIMEOUT[] = "delegation-timeout";
 static const char PCEP_VTYSH_ARG_SR_DRAFT07[] = "sr-draft07";
 static const char PCEP_VTYSH_ARG_PCE_INIT[] = "pce-initiated";
 static const char PCEP_VTYSH_ARG_TCP_MD5[] = "tcp-md5-auth";
-static const char PCEP_VTYSH_ARG_BASIC[] = "basic";
-static const char PCEP_VTYSH_ARG_PATH[] = "path";
-static const char PCEP_VTYSH_ARG_MESSAGE[] = "message";
-static const char PCEP_VTYSH_ARG_PCEPLIB[] = "pceplib";
 static const char PCEP_CLI_CAP_STATEFUL[] = " [Stateful PCE]";
 static const char PCEP_CLI_CAP_INCL_DB_VER[] = " [Include DB version]";
 static const char PCEP_CLI_CAP_LSP_TRIGGERED[] = " [LSP Triggered Resync]";
@@ -463,31 +459,19 @@ static void pcep_cli_remove_pce_connection(struct pce_opts *pce_opts)
  * VTY command implementations
  */
 
-static int path_pcep_cli_debug(struct vty *vty, const char *debug_type, bool set)
+static int path_pcep_cli_debug(struct vty *vty, bool onoff, bool basic,
+                              bool path, bool message, bool lib)
 {
        uint32_t mode = DEBUG_NODE2MODE(vty->node);
 
-       /* Global Set */
-       if (debug_type == NULL) {
-               DEBUG_MODE_SET(&pcep_g->dbg, mode, set);
-               DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_ALL, set);
-               return CMD_SUCCESS;
-       }
-
-       DEBUG_MODE_SET(&pcep_g->dbg, mode, true);
-
-       if (strcmp(debug_type, "basic") == 0)
-               DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_BASIC, set);
-       else if (strcmp(debug_type, "path") == 0)
-               DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_PATH, set);
-       else if (strcmp(debug_type, "message") == 0)
-               DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEP, set);
-       else if (strcmp(debug_type, "pceplib") == 0)
-               DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEPLIB, set);
-
-       /* Unset the pcep debug mode if there is no flag at least set*/
-       if (!DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_ALL))
-               DEBUG_MODE_SET(&pcep_g->dbg, mode, false);
+       if (basic)
+               DEBUG_MODE_SET(&pcep_g->dbg_basic, mode, onoff);
+       if (path)
+               DEBUG_MODE_SET(&pcep_g->dbg_path, mode, onoff);
+       if (message)
+               DEBUG_MODE_SET(&pcep_g->dbg_msg, mode, onoff);
+       if (lib)
+               DEBUG_MODE_SET(&pcep_g->dbg_lib, mode, onoff);
 
        return CMD_SUCCESS;
 }
@@ -1714,25 +1698,14 @@ static int path_pcep_cli_clear_srte_pcep_session(struct vty *vty,
 
 int pcep_cli_debug_config_write(struct vty *vty)
 {
-       char buff[128] = "";
-
-       if (DEBUG_MODE_CHECK(&pcep_g->dbg, DEBUG_MODE_CONF)) {
-               if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_BASIC))
-                       csnprintfrr(buff, sizeof(buff), " %s",
-                                   PCEP_VTYSH_ARG_BASIC);
-               if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_PATH))
-                       csnprintfrr(buff, sizeof(buff), " %s",
-                                   PCEP_VTYSH_ARG_PATH);
-               if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEP))
-                       csnprintfrr(buff, sizeof(buff), " %s",
-                                   PCEP_VTYSH_ARG_MESSAGE);
-               if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEPLIB))
-                       csnprintfrr(buff, sizeof(buff), " %s",
-                                   PCEP_VTYSH_ARG_PCEPLIB);
-               vty_out(vty, "debug pathd pcep%s\n", buff);
-               buff[0] = 0;
-               return 1;
-       }
+       if (DEBUG_MODE_CHECK(&pcep_g->dbg_basic, DEBUG_MODE_CONF))
+               vty_out(vty, "debug pathd pcep basic\n");
+       if (DEBUG_MODE_CHECK(&pcep_g->dbg_path, DEBUG_MODE_CONF))
+               vty_out(vty, "debug pathd pcep path\n");
+       if (DEBUG_MODE_CHECK(&pcep_g->dbg_msg, DEBUG_MODE_CONF))
+               vty_out(vty, "debug pathd pcep message\n");
+       if (DEBUG_MODE_CHECK(&pcep_g->dbg_lib, DEBUG_MODE_CONF))
+               vty_out(vty, "debug pathd pcep pceplib\n");
 
        return 0;
 }
@@ -2015,27 +1988,21 @@ DEFPY(show_debugging_pathd_pcep,
 {
        vty_out(vty, "Pathd pcep debugging status:\n");
 
-       if (DEBUG_MODE_CHECK(&pcep_g->dbg, DEBUG_MODE_CONF)) {
-               if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_BASIC))
-                       vty_out(vty, "  Pathd pcep %s debugging is on\n",
-                               PCEP_VTYSH_ARG_BASIC);
-               if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_PATH))
-                       vty_out(vty, "  Pathd pcep %s debugging is on\n",
-                               PCEP_VTYSH_ARG_PATH);
-               if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEP))
-                       vty_out(vty, "  Pathd pcep %s debugging is on\n",
-                               PCEP_VTYSH_ARG_MESSAGE);
-               if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEPLIB))
-                       vty_out(vty, "  Pathd pcep %s debugging is on\n",
-                               PCEP_VTYSH_ARG_PCEPLIB);
-       }
+       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|path|message|pceplib>$debug_type]",
+      "[no] debug pathd pcep [{basic$basic|path$path|message$msg|pceplib$lib}]",
       NO_STR DEBUG_STR
       "pathd debugging\n"
       "pcep module debugging\n"
@@ -2044,7 +2011,11 @@ DEFPY(pcep_cli_debug,
       "pcep message debugging\n"
       "pceplib debugging\n")
 {
-       return path_pcep_cli_debug(vty, debug_type, !no);
+       if (strmatch(argv[argc - 1]->text, "pcep"))
+               return path_pcep_cli_debug(vty, !no, true, true, true, true);
+       else
+               return path_pcep_cli_debug(vty, !no, !!basic, !!path, !!msg,
+                                          !!lib);
 }
 
 DEFPY(pcep_cli_show_srte_pcep_counters,
index df23f9312744f1da4b720db783a6ff063649fefc..f8348f15819945e7054f9355b40cb9d8437251a3 100644 (file)
@@ -335,10 +335,8 @@ DEFPY (debug_path_ted,
        "ted debugging\n")
 {
        uint32_t mode = DEBUG_NODE2MODE(vty->node);
-       bool no_debug = (no != NULL);
 
        DEBUG_MODE_SET(&ted_state_g.dbg, mode, !no);
-       DEBUG_FLAGS_SET(&ted_state_g.dbg, PATH_TED_DEBUG_BASIC, !no_debug);
        return CMD_SUCCESS;
 }
 
@@ -473,8 +471,7 @@ DEFPY (show_pathd_ted_db,
 int path_ted_cli_debug_config_write(struct vty *vty)
 {
        if (DEBUG_MODE_CHECK(&ted_state_g.dbg, DEBUG_MODE_CONF)) {
-               if (DEBUG_FLAGS_CHECK(&ted_state_g.dbg, PATH_TED_DEBUG_BASIC))
-                       vty_out(vty, "debug pathd mpls-te\n");
+               vty_out(vty, "debug pathd mpls-te\n");
                return 1;
        }
        return 0;
@@ -482,7 +479,7 @@ int path_ted_cli_debug_config_write(struct vty *vty)
 
 void path_ted_show_debugging(struct vty *vty)
 {
-       if (DEBUG_FLAGS_CHECK(&ted_state_g.dbg, PATH_TED_DEBUG_BASIC))
+       if (DEBUG_MODE_CHECK(&ted_state_g.dbg, DEBUG_MODE_ALL))
                vty_out(vty, "  Path TED debugging is on\n");
 }
 
index a1bc784b7f096ce8b463e97ba68fb9e0d29cd4ee..449e62f84f79ef6aae23d80c5d352d15e21a1db2 100644 (file)
@@ -59,28 +59,17 @@ struct ted_state {
        struct debug dbg;
 };
 /* Debug flags. */
-#define PATH_TED_DEBUG_BASIC   0x01
 #define PATH_TED_DEBUG(fmt, ...)                                               \
-       do {                                                                   \
-               if (DEBUG_FLAGS_CHECK(&ted_state_g.dbg, PATH_TED_DEBUG_BASIC))  \
-                       DEBUGD(&ted_state_g.dbg, "mpls-te: " fmt, ##__VA_ARGS__); \
-       } while (0)
+       DEBUGD(&ted_state_g.dbg, "mpls-te: " fmt, ##__VA_ARGS__)
 
 #define PATH_TED_ERROR(fmt, ...)                                               \
-       do {                                                                   \
-               if (DEBUG_FLAGS_CHECK(&ted_state_g.dbg, PATH_TED_DEBUG_BASIC)) \
-                       DEBUGE(&ted_state_g.dbg, "mpls-te: " fmt, ##__VA_ARGS__); \
-       } while (0)
+       DEBUGE(&ted_state_g.dbg, "mpls-te: " fmt, ##__VA_ARGS__)
+
 #define PATH_TED_WARN(fmt, ...)                                                \
-       do {                                                                   \
-               if (DEBUG_FLAGS_CHECK(&ted_state_g.dbg, PATH_TED_DEBUG_BASIC))  \
-                       DEBUGW(&ted_state_g.dbg, "mpls-te: " fmt, ##__VA_ARGS__); \
-       } while (0)
+       DEBUGW(&ted_state_g.dbg, "mpls-te: " fmt, ##__VA_ARGS__)
+
 #define PATH_TED_INFO(fmt, ...)                                                \
-       do {                                                                   \
-               if (DEBUG_FLAGS_CHECK(&ted_state_g.dbg, PATH_TED_DEBUG_BASIC)) \
-                       DEBUGI(&ted_state_g.dbg, "mpls-te: " fmt, ##__VA_ARGS__); \
-       } while (0)
+       DEBUGI(&ted_state_g.dbg, "mpls-te: " fmt, ##__VA_ARGS__)
 
 /* TED management functions */
 bool path_ted_is_initialized(void);
index 9bb7dbae84a4ed6de949718855b09efbd93a8d0c..d5c37898ae76107ea3dede041243161c1c0db238 100644 (file)
@@ -36,12 +36,7 @@ DEFINE_HOOK(pathd_candidate_removed, (struct srte_candidate * candidate),
 struct debug path_policy_debug;
 
 #define PATH_POLICY_DEBUG(fmt, ...)                                            \
-       do {                                                                   \
-               if (DEBUG_FLAGS_CHECK(&path_policy_debug,                      \
-                                     PATH_POLICY_DEBUG_BASIC))                \
-                       DEBUGD(&path_policy_debug, "policy: " fmt,             \
-                              ##__VA_ARGS__);                                 \
-       } while (0)
+       DEBUGD(&path_policy_debug, "policy: " fmt, ##__VA_ARGS__)
 
 
 static void trigger_pathd_candidate_created(struct srte_candidate *candidate);
@@ -1283,7 +1278,7 @@ const char *srte_origin2str(enum srte_protocol_origin origin)
 
 void path_policy_show_debugging(struct vty *vty)
 {
-       if (DEBUG_FLAGS_CHECK(&path_policy_debug, PATH_POLICY_DEBUG_BASIC))
+       if (DEBUG_MODE_CHECK(&path_policy_debug, DEBUG_MODE_ALL))
                vty_out(vty, "  Path policy debugging is on\n");
 }
 
index 73ad49226e2a0dd39d0550c50a7de8e3e0619f31..c8cde33a16f0c4c4c76d7fc40d74a92d6ad39e73 100644 (file)
@@ -32,8 +32,6 @@ enum srte_protocol_origin {
 
 extern struct debug path_policy_debug;
 
-#define PATH_POLICY_DEBUG_BASIC 0x01
-
 enum srte_policy_status {
        SRTE_POLICY_STATUS_UNKNOWN = 0,
        SRTE_POLICY_STATUS_DOWN = 1,