From 0beb61abc21c082e18dc1f1d78e256ca57cff337 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 16 Nov 2021 13:29:44 +0100 Subject: [PATCH] vtysh: dispatch unique-id backtrace cmd properly 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 --- lib/log_vty.c | 23 ++++++++++----------- vtysh/vtysh.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 12 deletions(-) diff --git a/lib/log_vty.c b/lib/log_vty.c index 9911323553..621949ab57 100644 --- a/lib/log_vty.c +++ b/lib/log_vty.c @@ -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; diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index f6c86a321c..e695c45dd8 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -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); -- 2.39.5