summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitesh Kanjariya <mitesh@marvel-07.cumulusnetworks.com>2017-08-21 23:56:06 +0200
committerMitesh Kanjariya <mitesh@marvel-07.cumulusnetworks.com>2017-08-25 01:37:16 +0200
commit419cd5a03f8bbf3d068ab99d1497dfe183753899 (patch)
treeaa7eb92aef44848db554e24674b5ef2ddf08a57c
parentzebra: lookup link by ifindex (diff)
downloadfrr-419cd5a03f8bbf3d068ab99d1497dfe183753899.tar.xz
frr-419cd5a03f8bbf3d068ab99d1497dfe183753899.zip
lib/bgpd: provide/use API to get hostname/domainname
Signed-off-by: Mitesh Kanjariya <mitesh@cumulusnetworks.com>
-rw-r--r--bgpd/bgp_open.c27
-rw-r--r--bgpd/bgpd.c10
-rw-r--r--isisd/isis_dynhn.c2
-rw-r--r--isisd/isis_lsp.c6
-rw-r--r--isisd/isis_misc.c20
-rw-r--r--isisd/isis_misc.h1
-rw-r--r--isisd/isisd.c2
-rw-r--r--lib/command.c35
-rw-r--r--lib/command.h5
-rw-r--r--lib/grammar_sandbox_main.c1
-rw-r--r--lib/vty.c11
-rw-r--r--vtysh/vtysh.c14
-rw-r--r--vtysh/vtysh_config.c5
13 files changed, 59 insertions, 80 deletions
diff --git a/bgpd/bgp_open.c b/bgpd/bgp_open.c
index 3ee865e3b..2e0cc2a8d 100644
--- a/bgpd/bgp_open.c
+++ b/bgpd/bgp_open.c
@@ -1271,7 +1271,6 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
as_t local_as;
u_int32_t restart_time;
u_char afi_safi_count = 0;
- struct utsname names;
int adv_addpath_tx = 0;
/* Remember current pointer for Opt Parm Len. */
@@ -1441,8 +1440,7 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
}
/* Hostname capability */
- uname(&names);
- if (names.nodename[0] != '\0') {
+ if (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 */
@@ -1450,26 +1448,22 @@ 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(names.nodename);
+ len = strlen(hostname_get());
if (len > BGP_MAX_HOSTNAME)
len = BGP_MAX_HOSTNAME;
stream_putc(s, len);
- stream_put(s, names.nodename, len);
-#ifdef HAVE_STRUCT_UTSNAME_DOMAINNAME
- if ((names.domainname[0] != '\0')
- && (strcmp(names.domainname, "(none)") != 0)) {
- len = strlen(names.domainname);
+ stream_put(s, hostname_get(), len);
+ if ((host.domainname)
+ && (strcmp(host.domainname, "(none)") != 0)) {
+ len = strlen(host.domainname);
if (len > BGP_MAX_HOSTNAME)
len = BGP_MAX_HOSTNAME;
stream_putc(s, len);
- stream_put(s, names.domainname, len);
+ stream_put(s, host.domainname, len);
} else
-#endif
- {
stream_putc(s, 0); /* 0 length */
- }
/* Set the lengths straight */
len = stream_get_endp(s) - rcapp - 1;
@@ -1478,14 +1472,9 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
stream_putc_at(s, capp, len);
if (bgp_debug_neighbor_events(peer))
-#ifdef HAVE_STRUCT_UTSNAME_DOMAINNAME
zlog_debug(
"%s Sending hostname cap with hn = %s, dn = %s",
- peer->host, names.nodename, names.domainname);
-#else
- zlog_debug("%s Sending hostname cap with hn = %s",
- peer->host, names.nodename);
-#endif
+ peer->host, hostname_get(), host.domainname);
}
/* Sending base graceful-restart capability irrespective of the config
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index 24d4ea36b..c64ebf122 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -2738,9 +2738,6 @@ static struct bgp *bgp_create(as_t *as, const char *name,
struct bgp *bgp;
afi_t afi;
safi_t safi;
- struct utsname names;
-
- uname(&names);
if ((bgp = XCALLOC(MTYPE_BGP, sizeof(struct bgp))) == NULL)
return NULL;
@@ -2769,16 +2766,15 @@ 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;
}
- bgp->peer_self->hostname = XSTRDUP(MTYPE_BGP_PEER_HOST, names.nodename);
+ bgp->peer_self->hostname = XSTRDUP(MTYPE_BGP_PEER_HOST,
+ hostname_get());
if (bgp->peer_self->domainname != NULL) {
XFREE(MTYPE_BGP_PEER_HOST, bgp->peer_self->domainname);
bgp->peer_self->domainname = NULL;
}
-#ifdef HAVE_STRUCT_UTSNAME_DOMAINNAME
bgp->peer_self->domainname = XSTRDUP(MTYPE_BGP_PEER_HOST,
- names.domainname);
-#endif
+ 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);
diff --git a/isisd/isis_dynhn.c b/isisd/isis_dynhn.c
index 6fa798830..40ac1919f 100644
--- a/isisd/isis_dynhn.c
+++ b/isisd/isis_dynhn.c
@@ -146,6 +146,6 @@ void dynhn_print_all(struct vty *vty)
}
vty_out(vty, " * %s %s\n", sysid_print(isis->sysid),
- unix_hostname());
+ hostname_get());
return;
}
diff --git a/isisd/isis_lsp.c b/isisd/isis_lsp.c
index 6bf6e45d9..bf6968c95 100644
--- a/isisd/isis_lsp.c
+++ b/isisd/isis_lsp.c
@@ -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", unix_hostname());
+ sprintf((char *)id, "%.14s", 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, unix_hostname());
+ isis_tlvs_set_dynamic_hostname(lsp->tlvs, hostname_get());
lsp_debug("ISIS (%s): Adding dynamic hostname '%s'",
- area->area_tag, unix_hostname());
+ area->area_tag, hostname_get());
} else {
lsp_debug("ISIS (%s): Not adding dynamic hostname (disabled)",
area->area_tag);
diff --git a/isisd/isis_misc.c b/isisd/isis_misc.c
index e8888a5f5..37724e17b 100644
--- a/isisd/isis_misc.c
+++ b/isisd/isis_misc.c
@@ -432,24 +432,6 @@ struct in_addr newprefix2inaddr(u_char *prefix_start, u_char prefix_masklen)
}
/*
- * Returns host.name if any, otherwise
- * it returns the system hostname.
- */
-const char *unix_hostname(void)
-{
- static struct utsname names;
- const char *hostname;
-
- hostname = host.name;
- if (!hostname) {
- uname(&names);
- hostname = names.nodename;
- }
-
- return hostname;
-}
-
-/*
* Returns the dynamic hostname associated with the passed system ID.
* If no dynamic hostname found then returns formatted system ID.
*/
@@ -462,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 unix_hostname();
+ return hostname_get();
dyn = dynhn_find_by_id(sysid);
if (dyn)
diff --git a/isisd/isis_misc.h b/isisd/isis_misc.h
index 5a19a1ffa..b81db34df 100644
--- a/isisd/isis_misc.h
+++ b/isisd/isis_misc.h
@@ -56,7 +56,6 @@ void zlog_dump_data(void *data, int len);
* misc functions
*/
unsigned long isis_jitter(unsigned long timer, unsigned long jitter);
-const char *unix_hostname(void);
/*
* macros
diff --git a/isisd/isisd.c b/isisd/isisd.c
index 60b9367da..0283ec3d0 100644
--- a/isisd/isisd.c
+++ b/isisd/isisd.c
@@ -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(unix_hostname(),
+ } else if (strncmp(hostname_get(),
sysid, 15)
== 0) {
memcpy(lspid, isis->sysid,
diff --git a/lib/command.c b/lib/command.c
index 45b5593a3..2d262c114 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -124,6 +124,23 @@ vector cmdvec = NULL;
/* Host information structure. */
struct host host;
+/*
+ * Returns host.name if any, otherwise
+ * it returns the system hostname.
+ */
+const char *hostname_get(void)
+{
+ return host.name;
+}
+
+/*
+ * Returns unix domainname
+ */
+const char *domainname_get(void)
+{
+ return host.domainname;
+}
+
/* Standard command node structures. */
static struct cmd_node auth_node = {
AUTH_NODE, "Password: ",
@@ -470,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 (host.name)
- vty_out(vty, "hostname %s\n", host.name);
+ if (hostname_get())
+ vty_out(vty, "hostname %s\n", hostname_get());
if (host.encrypt) {
if (host.password_encrypt)
@@ -1403,7 +1420,7 @@ DEFUN (show_version,
"Displays zebra version\n")
{
vty_out(vty, "%s %s (%s).\n", FRR_FULL_NAME, FRR_VERSION,
- host.name ? host.name : "");
+ hostname_get() ? hostname_get() : "");
vty_out(vty, "%s%s\n", FRR_COPYRIGHT, GIT_INFO);
vty_out(vty, "configured with:\n %s\n", FRR_CONFIG_ARGS);
@@ -2496,9 +2513,12 @@ void install_default(enum node_type node)
* terminal = -1 -- watchfrr / no logging, but minimal config control */
void cmd_init(int terminal)
{
+ struct utsname names;
+
if (array_size(node_names) != NODE_TYPE_MAX)
assert(!"Update the CLI node description array!");
+ uname(&names);
qobj_init();
varhandlers = list_new();
@@ -2507,7 +2527,12 @@ void cmd_init(int terminal)
cmdvec = vector_init(VECTOR_MIN_SIZE);
/* Default host value settings. */
- host.name = NULL;
+ host.name = XSTRDUP(MTYPE_HOST, names.nodename);
+#ifdef HAVE_STRUCT_UTSNAME_DOMAINNAME
+ host.domainname = XSTRDUP(MTYPE_HOST, names.domainname);
+#else
+ host.domainname = NULL;
+#endif
host.password = NULL;
host.enable = NULL;
host.logfile = NULL;
@@ -2623,6 +2648,8 @@ void cmd_terminate()
if (host.name)
XFREE(MTYPE_HOST, host.name);
+ if (host.domainname)
+ XFREE(MTYPE_HOST, host.domainname);
if (host.password)
XFREE(MTYPE_HOST, host.password);
if (host.password_encrypt)
diff --git a/lib/command.h b/lib/command.h
index 8f12e2aab..92220dd7b 100644
--- a/lib/command.h
+++ b/lib/command.h
@@ -41,6 +41,9 @@ struct host {
/* Host name of this router. */
char *name;
+ /* Domain name of this router */
+ char *domainname;
+
/* Password for vty interface. */
char *password;
char *password_encrypt;
@@ -399,6 +402,8 @@ extern void cmd_exit(struct vty *vty);
extern int cmd_list_cmds(struct vty *vty, int do_permute);
extern int cmd_hostname_set(const char *hostname);
+extern const char *hostname_get(void);
+extern const char *domainname_get(void);
/* NOT safe for general use; call this only if DEV_BUILD! */
extern void grammar_sandbox_init(void);
diff --git a/lib/grammar_sandbox_main.c b/lib/grammar_sandbox_main.c
index 89b0993d1..264c7c48f 100644
--- a/lib/grammar_sandbox_main.c
+++ b/lib/grammar_sandbox_main.c
@@ -50,6 +50,7 @@ int main(int argc, char **argv)
/* Library inits. */
cmd_init(1);
host.name = strdup("test");
+ host.domainname = strdup("testdomainname");
vty_init(master);
memory_init();
diff --git a/lib/vty.c b/lib/vty.c
index 59a882535..0caded4a8 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -250,16 +250,9 @@ void vty_hello(struct vty *vty)
/* Put out prompt and wait input from user. */
static void vty_prompt(struct vty *vty)
{
- struct utsname names;
- const char *hostname;
-
if (vty->type == VTY_TERM) {
- hostname = host.name;
- if (!hostname) {
- uname(&names);
- hostname = names.nodename;
- }
- vty_out(vty, cmd_prompt(vty->node), hostname);
+ vty_out(vty, cmd_prompt(vty->node),
+ hostname_get());
}
}
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c
index f971c171b..2ac667f0b 100644
--- a/vtysh/vtysh.c
+++ b/vtysh/vtysh.c
@@ -2879,21 +2879,9 @@ void vtysh_readline_init(void)
char *vtysh_prompt(void)
{
- static struct utsname names;
static char buf[100];
- const char *hostname;
- extern struct host host;
-
- hostname = host.name;
-
- if (!hostname) {
- if (!names.nodename[0])
- uname(&names);
- hostname = names.nodename;
- }
-
- snprintf(buf, sizeof buf, cmd_prompt(vty->node), hostname);
+ snprintf(buf, sizeof buf, cmd_prompt(vty->node), hostname_get());
return buf;
}
diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c
index c561b5222..c331e4588 100644
--- a/vtysh/vtysh_config.c
+++ b/vtysh/vtysh_config.c
@@ -420,10 +420,9 @@ int vtysh_read_config(const char *config_default_dir)
void vtysh_config_write()
{
char line[81];
- extern struct host host;
- if (host.name) {
- sprintf(line, "hostname %s", host.name);
+ if (hostname_get()) {
+ sprintf(line, "hostname %s", hostname_get());
vtysh_config_parse_line(NULL, line);
}
if (vtysh_write_integrated == WRITE_INTEGRATED_NO)