]> git.proxmox.com Git - mirror_frr.git/commitdiff
vtysh: dispatch unique-id backtrace cmd properly
authorDavid Lamparter <equinox@opensourcerouting.org>
Tue, 16 Nov 2021 12:29:44 +0000 (13:29 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Tue, 16 Nov 2021 17:51:22 +0000 (18:51 +0100)
i.e. to whoever cares, since some unique IDs (from libfrr) are valid
everywhere but some others (from the daemons) only apply to specific
daemons.

(Default handling aborts on first error, so configuring any unique IDs
that don't exist on the first daemon vtysh connects to just failed
before this.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
lib/log_vty.c
vtysh/vtysh.c

index 99113235537efe73bcbd6823114c8f34dfb75ec6..621949ab57f74eb16e14277c7933ef8567bf605c 100644 (file)
@@ -269,14 +269,14 @@ DEFUN_HIDDEN (no_config_log_monitor,
        return CMD_SUCCESS;
 }
 
-DEFPY (debug_uid_backtrace,
-       debug_uid_backtrace_cmd,
-       "[no] debug unique-id UID backtrace",
-       NO_STR
-       DEBUG_STR
-       "Options per individual log message, by unique ID\n"
-       "Log message unique ID (XXXXX-XXXXX)\n"
-       "Add backtrace to log when message is printed\n")
+DEFPY_NOSH (debug_uid_backtrace,
+           debug_uid_backtrace_cmd,
+           "[no] debug unique-id UID backtrace",
+           NO_STR
+           DEBUG_STR
+           "Options per individual log message, by unique ID\n"
+           "Log message unique ID (XXXXX-XXXXX)\n"
+           "Add backtrace to log when message is printed\n")
 {
        struct xrefdata search, *xrd;
        struct xrefdata_logmsg *xrdl;
@@ -285,10 +285,9 @@ DEFPY (debug_uid_backtrace,
        strlcpy(search.uid, uid, sizeof(search.uid));
        xrd = xrefdata_uid_find(&xrefdata_uid, &search);
 
-       if (!xrd) {
-               vty_out(vty, "%% no log message with ID \"%s\" found\n", uid);
-               return CMD_WARNING;
-       }
+       if (!xrd)
+               return CMD_ERR_NOTHING_TODO;
+
        if (xrd->xref->type != XREFT_LOGMSG) {
                vty_out(vty, "%% ID \"%s\" is not a log message\n", uid);
                return CMD_WARNING;
index f6c86a321c424c41df675a3c772ac162c5abaeb9..e695c45dd87e7c9b4e77aadb71347e0c1d46b98c 100644 (file)
@@ -3035,6 +3035,60 @@ DEFUNSH(VTYSH_ALL, vtysh_debug_memstats,
        return CMD_SUCCESS;
 }
 
+DEFUN(vtysh_debug_uid_backtrace,
+      vtysh_debug_uid_backtrace_cmd,
+      "[no] debug unique-id UID backtrace",
+      NO_STR
+      DEBUG_STR
+      "Options per individual log message, by unique ID\n"
+      "Log message unique ID (XXXXX-XXXXX)\n"
+      "Add backtrace to log when message is printed\n")
+{
+       unsigned int i, ok = 0;
+       int err = CMD_SUCCESS, ret;
+       const char *uid;
+       char line[64];
+
+       if (!strcmp(argv[0]->text, "no")) {
+               uid = argv[3]->arg;
+               snprintfrr(line, sizeof(line),
+                          "no debug unique-id %s backtrace", uid);
+       } else {
+               uid = argv[2]->arg;
+               snprintfrr(line, sizeof(line), "debug unique-id %s backtrace",
+                          uid);
+       }
+
+       for (i = 0; i < array_size(vtysh_client); i++)
+               if (vtysh_client[i].fd >= 0 || vtysh_client[i].next) {
+                       ret = vtysh_client_execute(&vtysh_client[i], line);
+                       switch (ret) {
+                       case CMD_SUCCESS:
+                               ok++;
+                               break;
+                       case CMD_ERR_NOTHING_TODO:
+                               /* ignore this daemon
+                                *
+                                * note this doesn't need to handle instances
+                                * of the same daemon individually because
+                                * the same daemon will have the same UIDs
+                                */
+                               break;
+                       default:
+                               if (err == CMD_SUCCESS)
+                                       err = ret;
+                               break;
+                       }
+               }
+
+       if (err == CMD_SUCCESS && !ok) {
+               vty_out(vty, "%% no running daemon recognizes unique-ID %s\n",
+                       uid);
+               err = CMD_WARNING;
+       }
+       return err;
+}
+
 DEFUNSH(VTYSH_ALL, vtysh_service_password_encrypt,
        vtysh_service_password_encrypt_cmd, "service password-encryption",
        "Set up miscellaneous service\n"
@@ -4461,6 +4515,8 @@ void vtysh_init_vty(void)
        install_element(CONFIG_NODE, &vtysh_debug_all_cmd);
        install_element(ENABLE_NODE, &vtysh_debug_memstats_cmd);
        install_element(CONFIG_NODE, &vtysh_debug_memstats_cmd);
+       install_element(ENABLE_NODE, &vtysh_debug_uid_backtrace_cmd);
+       install_element(CONFIG_NODE, &vtysh_debug_uid_backtrace_cmd);
 
        /* northbound */
        install_element(ENABLE_NODE, &show_config_running_cmd);