]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: Add '--command-log-always` to all daemons startup
authorDonald Sharp <sharpd@cumulusnetworks.com>
Tue, 8 Jan 2019 13:08:13 +0000 (08:08 -0500)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 31 May 2019 14:06:42 +0000 (10:06 -0400)
Add 'no log commands' cli and at the same time add a
--command-log-always to the daemon startup cli.

If --command-log-always is specified then all commands are
auto-logged and the 'no log commands' form of the command
is now ignored.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
lib/grammar_sandbox_main.c
lib/libfrr.c
lib/libfrr.h
lib/subdir.am
lib/vty.c
lib/vty.h
tests/helpers/c/main.c
tests/lib/cli/common_cli.c
tests/lib/northbound/test_oper_data.c

index 38494fb0074e6186c0efb0acee294e801c71f819..6d28a667b387b968b3038050ebed247fc5c48afa 100644 (file)
@@ -56,7 +56,7 @@ int main(int argc, char **argv)
        host.name = strdup("test");
        host.domainname = strdup("testdomainname");
 
-       vty_init(master);
+       vty_init(master, true);
        memory_init();
        yang_init();
        nb_init(master, NULL, 0);
index 15de96feee62f518c118a06881f1e93f27aa6102..194a1d9bd495611043d75d17e5fdee973a7bdd8d 100644 (file)
@@ -94,6 +94,7 @@ static void opt_extend(const struct optspec *os)
 #define OPTION_LOGLEVEL  1004
 #define OPTION_TCLI      1005
 #define OPTION_DB_FILE   1006
+#define OPTION_LOGGING   1007
 
 static const struct option lo_always[] = {
        {"help", no_argument, NULL, 'h'},
@@ -105,6 +106,7 @@ static const struct option lo_always[] = {
        {"log", required_argument, NULL, OPTION_LOG},
        {"log-level", required_argument, NULL, OPTION_LOGLEVEL},
        {"tcli", no_argument, NULL, OPTION_TCLI},
+       {"command-log-always", no_argument, NULL, OPTION_LOGGING},
        {NULL}};
 static const struct optspec os_always = {
        "hvdM:",
@@ -496,6 +498,9 @@ static int frr_opt(int opt)
        case OPTION_LOGLEVEL:
                di->early_loglevel = optarg;
                break;
+       case OPTION_LOGGING:
+               di->log_always = true;
+               break;
        default:
                return 1;
        }
@@ -648,7 +653,7 @@ struct thread_master *frr_init(void)
        else
                cmd_init(1);
 
-       vty_init(master);
+       vty_init(master, di->log_always);
        memory_init();
 
        log_ref_init();
index 891e2c12825c6599d83ef1f0f82bb76e84276518..d17495e04a8dc410a34b8dbd6d2f5380bba93e3f 100644 (file)
@@ -97,6 +97,8 @@ struct frr_daemon_info {
 
        const struct frr_yang_module_info **yang_modules;
        size_t n_yang_modules;
+
+       bool log_always;
 };
 
 /* execname is the daemon's executable (and pidfile and configfile) name,
index 4897f5e8e528b7447fe7ca32a8b38b459adf2906..61dded05f86c288dd802101fc6c84b22b9619f3a 100644 (file)
@@ -131,6 +131,8 @@ lib/nexthop_group_clippy.c: $(CLIPPY_DEPS)
 lib/nexthop_group.lo: lib/nexthop_group_clippy.c
 lib/northbound_cli_clippy.c: $(CLIPPY_DEPS)
 lib/northbound_cli.lo: lib/northbound_cli_clippy.c
+lib/vty_clippy.c: $(CLIPPY_DEPS)
+lib/vty.lo: lib/vty_clippy.c
 
 pkginclude_HEADERS += \
        lib/agg_table.h \
index 2d97cca351bfacd76aa18af8dc2810b654c89261..8273d0e0c009dd1f84ecc854fe7d5fea4d1fce97 100644 (file)
--- a/lib/vty.c
+++ b/lib/vty.c
 #include <arpa/telnet.h>
 #include <termios.h>
 
+#ifndef VTYSH_EXTRACT_PL
+#include "lib/vty_clippy.c"
+#endif
+
 DEFINE_MTYPE_STATIC(LIB, VTY, "VTY")
 DEFINE_MTYPE_STATIC(LIB, VTY_OUT_BUF, "VTY output buffer")
 DEFINE_MTYPE_STATIC(LIB, VTY_HIST, "VTY history")
@@ -92,7 +96,8 @@ static int no_password_check = 0;
 /* Integrated configuration file path */
 static char integrate_default[] = SYSCONFDIR INTEGRATE_DEFAULT_CONFIG;
 
-static int do_log_commands = 0;
+static bool do_log_commands;
+static bool do_log_commands_perm;
 
 void vty_frame(struct vty *vty, const char *format, ...)
 {
@@ -2975,13 +2980,24 @@ DEFUN_NOSH (show_history,
 }
 
 /* vty login. */
-DEFUN (log_commands,
+DEFPY (log_commands,
        log_commands_cmd,
-       "log commands",
+       "[no] log commands",
+       NO_STR
        "Logging control\n"
-       "Log all commands (can't be unset without restart)\n")
+       "Log all commands\n")
 {
-       do_log_commands = 1;
+       if (no) {
+               if (do_log_commands_perm) {
+                       vty_out(vty,
+                               "Daemon started with permanent logging turned on for commands, ignoring\n");
+                       return CMD_WARNING;
+               }
+
+               do_log_commands = false;
+       } else
+               do_log_commands = true;
+
        return CMD_SUCCESS;
 }
 
@@ -3101,7 +3117,7 @@ void vty_init_vtysh(void)
 }
 
 /* Install vty's own commands like `who' command. */
-void vty_init(struct thread_master *master_thread)
+void vty_init(struct thread_master *master_thread, bool do_command_logging)
 {
        /* For further configuration read, preserve current directory. */
        vty_save_cwd();
@@ -3125,6 +3141,12 @@ void vty_init(struct thread_master *master_thread)
        install_element(CONFIG_NODE, &no_service_advanced_vty_cmd);
        install_element(CONFIG_NODE, &show_history_cmd);
        install_element(CONFIG_NODE, &log_commands_cmd);
+
+       if (do_command_logging) {
+               do_log_commands = true;
+               do_log_commands_perm = true;
+       }
+
        install_element(ENABLE_NODE, &terminal_monitor_cmd);
        install_element(ENABLE_NODE, &terminal_no_monitor_cmd);
        install_element(ENABLE_NODE, &no_terminal_monitor_cmd);
index 98d75542fd3794796e84fdc5832704e5a51faf97..4847c9f18998eadd3a219b306a729b5cc3fc0c6d 100644 (file)
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -290,7 +290,7 @@ struct vty_arg {
 #endif
 
 /* Prototypes. */
-extern void vty_init(struct thread_master *);
+extern void vty_init(struct thread_master *, bool do_command_logging);
 extern void vty_init_vtysh(void);
 extern void vty_terminate(void);
 extern void vty_reset(void);
index 11db2dabc38fafd53d941b19f2685307c4a79b17..b1dcfcf7075c38d9724e92c44c3b6f0a03dcac7e 100644 (file)
@@ -153,7 +153,7 @@ int main(int argc, char **argv)
 
        /* Library inits. */
        cmd_init(1);
-       vty_init(master);
+       vty_init(master, false);
        memory_init();
        yang_init();
        nb_init(master, NULL, 0);
index 393b58874571310f3690f7e18dd5cd47dbee286e..2071ae08cd7e80820d41e306c42c1a4c08b5b484 100644 (file)
@@ -82,7 +82,7 @@ int main(int argc, char **argv)
        cmd_hostname_set("test");
        cmd_domainname_set("test.domain");
 
-       vty_init(master);
+       vty_init(master, false);
        memory_init();
        yang_init();
        nb_init(master, NULL, 0);
index 7cd622854e886806746ec4eb2352bae020f93a33..3180f9f9f3fd252c86ddd7ac44bc742d61a04506 100644 (file)
@@ -411,7 +411,7 @@ int main(int argc, char **argv)
        /* Library inits. */
        cmd_init(1);
        cmd_hostname_set("test");
-       vty_init(master);
+       vty_init(master, false);
        memory_init();
        yang_init();
        nb_init(master, modules, array_size(modules));