]> git.puffer.fish Git - mirror/frr.git/commitdiff
vtysh: Add an option to set banner motd from an input
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Tue, 22 Oct 2019 15:06:03 +0000 (18:06 +0300)
committerDonatas Abraitis <donatas.abraitis@gmail.com>
Thu, 31 Oct 2019 13:02:47 +0000 (15:02 +0200)
This allows to set motd from an input instead of creating a file.

Example:

root@exit2-debian-9:~/frr# telnet 127.0.0.1 2605
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Hello, this is bgpd
User Access Verification

Password:
exit2-debian-9> enable
exit2-debian-9# sh run

Current configuration:
!
frr version 7.3-dev-MyOwnFRRVersion
frr defaults traditional
!
hostname exit2-debian-9
password belekas
log file /var/log/frr/labas.log
log syslog informational
banner motd line Hello, this is bgpd
!
!
!
line vty
!
end
exit2-debian-9#

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
lib/command.c
lib/command.h
vtysh/vtysh_user.c

index e52893f0ba8a777fc10683e32e8164a2023b919b..59668e95fca8b649c391ca46d298d3aa292f0594 100644 (file)
@@ -198,9 +198,6 @@ static struct cmd_node enable_node = {
 
 static struct cmd_node config_node = {CONFIG_NODE, "%s(config)# ", 1};
 
-/* Default motd string. */
-static const char *default_motd = FRR_DEFAULT_MOTD;
-
 static const struct facility_map {
        int facility;
        const char *name;
@@ -592,6 +589,10 @@ static int config_write_host(struct vty *vty)
 
                if (host.motdfile)
                        vty_out(vty, "banner motd file %s\n", host.motdfile);
+               else if (host.motd
+                        && strncmp(host.motd, FRR_DEFAULT_MOTD,
+                                   strlen(host.motd)))
+                       vty_out(vty, "banner motd line %s\n", host.motd);
                else if (!host.motd)
                        vty_out(vty, "no banner motd\n");
        }
@@ -2668,6 +2669,13 @@ int cmd_banner_motd_file(const char *file)
        return success;
 }
 
+void cmd_banner_motd_line(const char *line)
+{
+       if (host.motd)
+               XFREE(MTYPE_HOST, host.motd);
+       host.motd = XSTRDUP(MTYPE_HOST, line);
+}
+
 DEFUN (banner_motd_file,
        banner_motd_file_cmd,
        "banner motd file FILE",
@@ -2688,6 +2696,26 @@ DEFUN (banner_motd_file,
        return cmd;
 }
 
+DEFUN (banner_motd_line,
+       banner_motd_line_cmd,
+       "banner motd line LINE...",
+       "Set banner\n"
+       "Banner for motd\n"
+       "Banner from an input\n"
+       "Text\n")
+{
+       int idx = 0;
+       char *motd;
+
+       argv_find(argv, argc, "LINE", &idx);
+       motd = argv_concat(argv, argc, idx);
+
+       cmd_banner_motd_line(motd);
+       XFREE(MTYPE_TMP, motd);
+
+       return CMD_SUCCESS;
+}
+
 DEFUN (banner_motd_default,
        banner_motd_default_cmd,
        "banner motd default",
@@ -2695,7 +2723,7 @@ DEFUN (banner_motd_default,
        "Strings for motd\n"
        "Default string\n")
 {
-       host.motd = default_motd;
+       cmd_banner_motd_line(FRR_DEFAULT_MOTD);
        return CMD_SUCCESS;
 }
 
@@ -2864,7 +2892,7 @@ void cmd_init(int terminal)
        host.config = NULL;
        host.noconfig = (terminal < 0);
        host.lines = -1;
-       host.motd = default_motd;
+       cmd_banner_motd_line(FRR_DEFAULT_MOTD);
        host.motdfile = NULL;
 
        /* Install top nodes. */
@@ -2944,6 +2972,7 @@ void cmd_init(int terminal)
                install_element(CONFIG_NODE, &no_service_password_encrypt_cmd);
                install_element(CONFIG_NODE, &banner_motd_default_cmd);
                install_element(CONFIG_NODE, &banner_motd_file_cmd);
+               install_element(CONFIG_NODE, &banner_motd_line_cmd);
                install_element(CONFIG_NODE, &no_banner_motd_cmd);
                install_element(CONFIG_NODE, &service_terminal_length_cmd);
                install_element(CONFIG_NODE, &no_service_terminal_length_cmd);
@@ -2988,6 +3017,7 @@ void cmd_terminate(void)
        XFREE(MTYPE_HOST, host.logfile);
        XFREE(MTYPE_HOST, host.motdfile);
        XFREE(MTYPE_HOST, host.config);
+       XFREE(MTYPE_HOST, host.motd);
 
        list_delete(&varhandlers);
        qobj_finish();
index d5dc129c72f5cdeb9cf7a58f5c4b53936e95b675..73c15469e7ddec1cdd8fab30c346d1731ec7775e 100644 (file)
@@ -78,7 +78,7 @@ struct host {
        int encrypt;
 
        /* Banner configuration. */
-       const char *motd;
+       char *motd;
        char *motdfile;
 };
 
@@ -499,6 +499,7 @@ extern void host_config_set(const char *);
 extern void print_version(const char *);
 
 extern int cmd_banner_motd_file(const char *);
+extern void cmd_banner_motd_line(const char *line);
 
 /* struct host global, ick */
 extern struct host host;
index 17e5a7331c26c71fe4a85db1d645790d13f5154d..a7067984c488ace7131e6195e703561c281f20bd 100644 (file)
@@ -147,6 +147,26 @@ DEFUN (vtysh_banner_motd_file,
        return cmd_banner_motd_file(argv[idx_file]->arg);
 }
 
+DEFUN (vtysh_banner_motd_line,
+       vtysh_banner_motd_line_cmd,
+       "banner motd line LINE...",
+       "Set banner\n"
+       "Banner for motd\n"
+       "Banner from an input\n"
+       "Text\n")
+{
+       int idx = 0;
+       char *motd;
+
+       argv_find(argv, argc, "LINE", &idx);
+       motd = argv_concat(argv, argc, idx);
+
+       cmd_banner_motd_line(motd);
+       XFREE(MTYPE_TMP, motd);
+
+       return CMD_SUCCESS;
+}
+
 DEFUN (username_nopassword,
        username_nopassword_cmd,
        "username WORD nopassword",
@@ -203,4 +223,5 @@ void vtysh_user_init(void)
        userlist = list_new();
        install_element(CONFIG_NODE, &username_nopassword_cmd);
        install_element(CONFIG_NODE, &vtysh_banner_motd_file_cmd);
+       install_element(CONFIG_NODE, &vtysh_banner_motd_line_cmd);
 }