]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: new APIs for get/set system hostname/domainname
authorMitesh Kanjariya <mitesh@marvel-07.cumulusnetworks.com>
Mon, 28 Aug 2017 23:52:29 +0000 (16:52 -0700)
committerMitesh Kanjariya <mitesh@marvel-07.cumulusnetworks.com>
Tue, 29 Aug 2017 00:16:52 +0000 (17:16 -0700)
1. Change hostname_get to cmd_hostname_get
2. Change domainname_get to cmd_domainname_get
3. New API to set domainname
3. Provide a CLI command to set domainname

Signed-off-by: Mitesh Kanjariya <mitesh@cumulusnetworks.com>
bgpd/bgp_open.c
bgpd/bgpd.c
isisd/isis_dynhn.c
isisd/isis_lsp.c
isisd/isis_misc.c
isisd/isisd.c
lib/command.c
lib/command.h
lib/vty.c
vtysh/vtysh.c
vtysh/vtysh_config.c

index 2e0cc2a8d072eedd9f136d5227865a7e23a4e1be..5c9ba89a5786c5f63e0cf5e306fd536eb9f976e9 100644 (file)
@@ -1440,7 +1440,7 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
        }
 
        /* Hostname capability */
-       if (hostname_get()) {
+       if (cmd_hostname_get()) {
                SET_FLAG(peer->cap, PEER_CAP_HOSTNAME_ADV);
                stream_putc(s, BGP_OPEN_OPT_CAP);
                rcapp = stream_get_endp(s); /* Ptr to length placeholder */
@@ -1448,20 +1448,19 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
                stream_putc(s, CAPABILITY_CODE_FQDN);
                capp = stream_get_endp(s);
                stream_putc(s, 0); /* dummy len for now */
-               len = strlen(hostname_get());
+               len = strlen(cmd_hostname_get());
                if (len > BGP_MAX_HOSTNAME)
                        len = BGP_MAX_HOSTNAME;
 
                stream_putc(s, len);
-               stream_put(s, hostname_get(), len);
-               if ((host.domainname)
-                   && (strcmp(host.domainname, "(none)") != 0)) {
-                       len = strlen(host.domainname);
+               stream_put(s, cmd_hostname_get(), len);
+               if (cmd_domainname_get()) {
+                       len = strlen(cmd_domainname_get());
                        if (len > BGP_MAX_HOSTNAME)
                                len = BGP_MAX_HOSTNAME;
 
                        stream_putc(s, len);
-                       stream_put(s, host.domainname, len);
+                       stream_put(s, cmd_domainname_get(), len);
                } else
                        stream_putc(s, 0); /* 0 length */
 
@@ -1474,7 +1473,8 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
                if (bgp_debug_neighbor_events(peer))
                        zlog_debug(
                                "%s Sending hostname cap with hn = %s, dn = %s",
-                               peer->host, hostname_get(), host.domainname);
+                               peer->host, cmd_hostname_get(),
+                               cmd_domainname_get());
        }
 
        /* Sending base graceful-restart capability irrespective of the config
index 8b70c24ac2941f2804ec7ef5e70ec9c382fc45f5..b6a48c9928d42969ee0c92d1c2ba9d7099052f0c 100644 (file)
@@ -2766,17 +2766,17 @@ static struct bgp *bgp_create(as_t *as, const char *name,
                XFREE(MTYPE_BGP_PEER_HOST, bgp->peer_self->hostname);
                bgp->peer_self->hostname = NULL;
        }
-       if (hostname_get())
+       if (cmd_hostname_get())
                bgp->peer_self->hostname = XSTRDUP(MTYPE_BGP_PEER_HOST,
-                                                  hostname_get());
+                                                  cmd_hostname_get());
 
        if (bgp->peer_self->domainname != NULL) {
                XFREE(MTYPE_BGP_PEER_HOST, bgp->peer_self->domainname);
                bgp->peer_self->domainname = NULL;
        }
-       if (domainname_get())
+       if (cmd_domainname_get())
                bgp->peer_self->domainname = XSTRDUP(MTYPE_BGP_PEER_HOST,
-                                                    domainname_get());
+                                                    cmd_domainname_get());
        bgp->peer = list_new();
        bgp->peer->cmp = (int (*)(void *, void *))peer_cmp;
        bgp->peerhash = hash_create(peer_hash_key_make, peer_hash_same, NULL);
index 40ac1919fdafd914db236222edc5e197b8f4ab63..17b043444c47d05732634455173c0914392e828d 100644 (file)
@@ -146,6 +146,6 @@ void dynhn_print_all(struct vty *vty)
        }
 
        vty_out(vty, "     * %s %s\n", sysid_print(isis->sysid),
-               hostname_get());
+               cmd_hostname_get());
        return;
 }
index bf6968c95561aa3721df2667018669b5c4810aed..cb979dd0dba256b99a938922da623342efd249a7 100644 (file)
@@ -600,7 +600,7 @@ static void lspid_print(u_char *lsp_id, u_char *trg, char dynhost, char frag)
        if (dyn)
                sprintf((char *)id, "%.14s", dyn->hostname);
        else if (!memcmp(isis->sysid, lsp_id, ISIS_SYS_ID_LEN) && dynhost)
-               sprintf((char *)id, "%.14s", hostname_get());
+               sprintf((char *)id, "%.14s", cmd_hostname_get());
        else
                memcpy(id, sysid_print(lsp_id), 15);
        if (frag)
@@ -880,9 +880,9 @@ static void lsp_build(struct isis_lsp *lsp, struct isis_area *area)
        }
        /* Dynamic Hostname */
        if (area->dynhostname) {
-               isis_tlvs_set_dynamic_hostname(lsp->tlvs, hostname_get());
+               isis_tlvs_set_dynamic_hostname(lsp->tlvs, cmd_hostname_get());
                lsp_debug("ISIS (%s): Adding dynamic hostname '%s'",
-                         area->area_tag, hostname_get());
+                         area->area_tag, cmd_hostname_get());
        } else {
                lsp_debug("ISIS (%s): Not adding dynamic hostname (disabled)",
                          area->area_tag);
index 37724e17bb36cdb7c86834be7824c58f0449a7c0..0a1d9aaa1ac54117687e2c74bf8da332c5d39440 100644 (file)
@@ -444,7 +444,7 @@ const char *print_sys_hostname(const u_char *sysid)
 
        /* For our system ID return our host name */
        if (memcmp(sysid, isis->sysid, ISIS_SYS_ID_LEN) == 0)
-               return hostname_get();
+               return cmd_hostname_get();
 
        dyn = dynhn_find_by_id(sysid);
        if (dyn)
index 0283ec3d00d9747f72befd881029eec1116cdc60..e654f8557c284d496ff187f0f470c33053920e25 100644 (file)
@@ -1440,7 +1440,7 @@ static int show_isis_database(struct vty *vty, const char *argv, int ui_level)
                                                lsp = lsp_search(
                                                        lspid,
                                                        area->lspdb[level]);
-                                       } else if (strncmp(hostname_get(),
+                                       } else if (strncmp(cmd_hostname_get(),
                                                           sysid, 15)
                                                   == 0) {
                                                memcpy(lspid, isis->sysid,
index 2d262c11468dcc9a66562406a1acb72508cd08ad..9421fadc0b1a70f87cfb26815b5537086eef7e29 100644 (file)
@@ -128,7 +128,7 @@ struct host host;
  * Returns host.name if any, otherwise
  * it returns the system hostname.
  */
-const char *hostname_get(void)
+const char *cmd_hostname_get(void)
 {
        return host.name;
 }
@@ -136,7 +136,7 @@ const char *hostname_get(void)
 /*
  * Returns unix domainname
  */
-const char *domainname_get(void)
+const char *cmd_domainname_get(void)
 {
        return host.domainname;
 }
@@ -487,8 +487,8 @@ static char *zencrypt(const char *passwd)
 /* This function write configuration of this host. */
 static int config_write_host(struct vty *vty)
 {
-       if (hostname_get())
-               vty_out(vty, "hostname %s\n", hostname_get());
+       if (cmd_hostname_get())
+               vty_out(vty, "hostname %s\n", cmd_hostname_get());
 
        if (host.encrypt) {
                if (host.password_encrypt)
@@ -1420,7 +1420,7 @@ DEFUN (show_version,
        "Displays zebra version\n")
 {
        vty_out(vty, "%s %s (%s).\n", FRR_FULL_NAME, FRR_VERSION,
-               hostname_get() ? hostname_get() : "");
+               cmd_hostname_get() ? cmd_hostname_get() : "");
        vty_out(vty, "%s%s\n", FRR_COPYRIGHT, GIT_INFO);
        vty_out(vty, "configured with:\n    %s\n", FRR_CONFIG_ARGS);
 
@@ -1754,6 +1754,40 @@ DEFUN (show_startup_config,
        return CMD_SUCCESS;
 }
 
+int cmd_domainname_set(const char *domainname)
+{
+       XFREE(MTYPE_HOST, host.domainname);
+       host.domainname = domainname ? XSTRDUP(MTYPE_HOST, domainname) : NULL;
+       return CMD_SUCCESS;
+}
+
+/* Hostname configuration */
+DEFUN (config_domainname,
+       domainname_cmd,
+       "domainname WORD",
+       "Set system's domain name\n"
+       "This system's domain name\n")
+{
+       struct cmd_token *word = argv[1];
+
+       if (!isalpha((int)word->arg[0])) {
+               vty_out(vty, "Please specify string starting with alphabet\n");
+               return CMD_WARNING_CONFIG_FAILED;
+       }
+
+       return cmd_domainname_set(word->arg);
+}
+
+DEFUN (config_no_domainname,
+       no_domainname_cmd,
+       "no domainname [DOMAINNAME]",
+       NO_STR
+       "Reset system's domain name\n"
+       "domain name of this router\n")
+{
+       return cmd_domainname_set(NULL);
+}
+
 int cmd_hostname_set(const char *hostname)
 {
        XFREE(MTYPE_HOST, host.name);
@@ -2529,7 +2563,10 @@ void cmd_init(int terminal)
        /* Default host value settings. */
        host.name = XSTRDUP(MTYPE_HOST, names.nodename);
 #ifdef HAVE_STRUCT_UTSNAME_DOMAINNAME
-       host.domainname = XSTRDUP(MTYPE_HOST, names.domainname);
+       if ((strcmp(names.domainname, "(none)") == 0))
+               host.domainname = NULL;
+       else
+               host.domainname = XSTRDUP(MTYPE_HOST, names.domainname);
 #else
        host.domainname = NULL;
 #endif
@@ -2584,6 +2621,8 @@ void cmd_init(int terminal)
 
        install_element(CONFIG_NODE, &hostname_cmd);
        install_element(CONFIG_NODE, &no_hostname_cmd);
+       install_element(CONFIG_NODE, &domainname_cmd);
+       install_element(CONFIG_NODE, &no_domainname_cmd);
        install_element(CONFIG_NODE, &frr_version_defaults_cmd);
 
        if (terminal > 0) {
index 70401eced0c2f48bb10a0f81fa42574042c9a28e..1c6938523ccffd33699bc2d096d8da080084a768 100644 (file)
@@ -401,9 +401,10 @@ extern void cmd_terminate(void);
 extern void cmd_exit(struct vty *vty);
 extern int cmd_list_cmds(struct vty *vty, int do_permute);
 
+extern int cmd_domainname_set(const char *domainname);
 extern int cmd_hostname_set(const char *hostname);
-extern const char *hostname_get(void);
-extern const char *domainname_get(void);
+extern const char *cmd_hostname_get(void);
+extern const char *cmd_domainname_get(void);
 
 /* NOT safe for general use; call this only if DEV_BUILD! */
 extern void grammar_sandbox_init(void);
index 0caded4a87ad10e811987b7880a9cf163efa98a2..cec5a916f337e7680f34c7c7a971174c58f9ce85 100644 (file)
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -252,7 +252,7 @@ static void vty_prompt(struct vty *vty)
 {
        if (vty->type == VTY_TERM) {
                vty_out(vty, cmd_prompt(vty->node),
-                       hostname_get());
+                       cmd_hostname_get());
        }
 }
 
index 2ac667f0b00f8e4e1479b4f5889faab823588b3d..9939a7fae9eda3c6d2f109c5aa98e67bc938cb1b 100644 (file)
@@ -2881,7 +2881,7 @@ char *vtysh_prompt(void)
 {
        static char buf[100];
 
-       snprintf(buf, sizeof buf, cmd_prompt(vty->node), hostname_get());
+       snprintf(buf, sizeof buf, cmd_prompt(vty->node), cmd_hostname_get());
        return buf;
 }
 
index c331e45886863d65528c1bd71333c41f3bff973c..1ce065fccf77221cadc07793afbfde32faeaa7b8 100644 (file)
@@ -421,8 +421,8 @@ void vtysh_config_write()
 {
        char line[81];
 
-       if (hostname_get()) {
-               sprintf(line, "hostname %s", hostname_get());
+       if (cmd_hostname_get()) {
+               sprintf(line, "hostname %s", cmd_hostname_get());
                vtysh_config_parse_line(NULL, line);
        }
        if (vtysh_write_integrated == WRITE_INTEGRATED_NO)