mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-05 04:40:21 +00:00
lib: new APIs for get/set system hostname/domainname
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>
This commit is contained in:
parent
0802e118dd
commit
6b3ee3a0b0
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user