return 1;
}
+static int
+cmd_hostname(struct lldpctl_conn_t *conn, struct writer *w,
+ struct cmd_env *env, void *arg)
+{
+ log_debug("lldpctl", "set system name");
+
+ lldpctl_atom_t *config = lldpctl_get_configuration(conn);
+ if (config == NULL) {
+ log_warnx("lldpctl", "unable to get configuration from lldpd. %s",
+ lldpctl_last_strerror(conn));
+ return 0;
+ }
+ const char *value = cmdenv_get(env, "hostname");
+
+ if (lldpctl_atom_set_str(config,
+ lldpctl_k_config_hostname, cmdenv_get(env, "hostname")) == NULL) {
+ log_warnx("lldpctl", "unable to set system name. %s",
+ lldpctl_last_strerror(conn));
+ lldpctl_atom_dec_ref(config);
+ return 0;
+ }
+ log_info("lldpctl", "system name set to new value %s", cmdenv_get(env, "hostname"));
+ lldpctl_atom_dec_ref(config);
+ return 1;
+}
+
static int
cmd_update_descriptions(struct lldpctl_conn_t *conn, struct writer *w,
struct cmd_env *env, void *arg)
NEWLINE, "Override platform description",
NULL, cmd_system_description, NULL);
+ commands_new(
+ commands_new(
+ commands_new(configure_system,
+ "hostname", "Override system name",
+ NULL, NULL, NULL),
+ NULL, "System name",
+ NULL, cmd_store_env_value, "hostname"),
+ NEWLINE, "Override system name",
+ NULL, cmd_hostname, NULL);
+
commands_new(
commands_new(
commands_new(configure_interface,
N(lldpctl_atom_get_str(configuration, lldpctl_k_config_description)));
tag_datatag(w, "platform", "Override platform with",
N(lldpctl_atom_get_str(configuration, lldpctl_k_config_platform)));
+ tag_datatag(w, "hostname", "Override system name with",
+ N(lldpctl_atom_get_str(configuration, lldpctl_k_config_hostname)));
tag_datatag(w, "advertise-version", "Advertise version",
lldpctl_atom_get_int(configuration, lldpctl_k_config_advertise_version)?
"yes":"no");
cfg->g_config.c_platform = strdup(config->c_platform);
levent_update_now(cfg);
}
+ if (config->c_hostname) {
+ log_debug("rpc", "change system name to %s", config->c_hostname);
+ free(cfg->g_config.c_hostname);
+ cfg->g_config.c_hostname = strdup(config->c_hostname);
+ levent_update_now(cfg);
+ }
if (config->c_set_ifdescr != cfg->g_config.c_set_ifdescr) {
log_debug("rpc", "%s setting of interface description based on discovered neighbors",
config->c_set_ifdescr?"enable":"disable");
fprintf(stderr, "-k Disable advertising of kernel release, version, machine.\n");
fprintf(stderr, "-S descr Override the default system description.\n");
fprintf(stderr, "-P name Override the default hardware platform.\n");
+ fprintf(stderr, "-N name Override the default system name.\n");
fprintf(stderr, "-m IP Specify the IPv4 management addresses of this system.\n");
fprintf(stderr, "-u file Specify the Unix-domain socket used for communication with lldpctl(8).\n");
fprintf(stderr, "-H mode Specify the behaviour when detecting multiple neighbors.\n");
/* Set system name and description */
if (uname(&un) < 0)
fatal("localchassis", "failed to get system information");
- if ((hp = priv_gethostbyname()) == NULL)
- fatal("localchassis", "failed to get system name");
+ if (cfg->g_config.c_hostname) {
+ log_debug("localchassis", "use overridden system name `%s`", cfg->g_config.c_hostname);
+ hp = cfg->g_config.c_hostname;
+ } else {
+ if ((hp = priv_gethostbyname()) == NULL)
+ fatal("localchassis", "failed to get system name");
+ }
free(LOCAL_CHASSIS(cfg)->c_name);
free(LOCAL_CHASSIS(cfg)->c_descr);
if ((LOCAL_CHASSIS(cfg)->c_name = strdup(hp)) == NULL)
char *cidp = NULL;
char *interfaces = NULL;
char *popt, opts[] =
- "H:vhkrdD:xX:m:u:4:6:I:C:p:M:P:S:iL:@ ";
+ "H:vhkrdD:xX:m:u:4:6:I:C:p:M:P:N:S:iL:@ ";
int i, found, advertise_version = 1;
#ifdef ENABLE_LLDPMED
int lldpmed = 0, noinventory = 0;
#endif
char *descr_override = NULL;
char *platform_override = NULL;
+ char *hostname_override = NULL;
char *lsb_release = NULL;
const char *lldpcli = LLDPCLI_PATH;
int smart = 15;
free(platform_override);
platform_override = strdup(optarg);
break;
+ case 'N':
+ hostname_override = strdup(optarg);
+ break;
case 'H':
smart = atoi(optarg);
break;
if (platform_override)
cfg->g_config.c_platform = platform_override;
+ if (hostname_override)
+ cfg->g_config.c_hostname = hostname_override;
+
/* Set system capabilities */
log_debug("main", "set system capabilities");
if ((lchassis = (struct lldpd_chassis*)
res = c->config->c_description; break;
case lldpctl_k_config_platform:
res = c->config->c_platform; break;
+ case lldpctl_k_config_hostname:
+ res = c->config->c_hostname; break;
case lldpctl_k_config_bond_slave_src_mac_type:
return map_lookup(bond_slave_src_mac_map,
c->config->c_bond_slave_src_mac_type);
free(c->config->c_platform);
c->config->c_description = strdup(description);
break;
+ case lldpctl_k_config_hostname:
+ description = _lldpctl_alloc_in_atom(atom, strlen(value) + 1);
+ if (!description)
+ return NULL;
+ memcpy(description, value, len);
+ config.c_hostname = description;
+ free(c->config->c_hostname);
+ c->config->c_hostname = strdup(description);
+ break;
default:
SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST);
return NULL;
lldpctl_k_config_cid_pattern, /**< `(S)` Interface pattern to choose the chassis ID */
lldpctl_k_config_description, /**< `(S,WO)` Chassis description overridden */
lldpctl_k_config_platform, /**< `(S,WO)` Platform description overridden (CDP) */
+ lldpctl_k_config_hostname, /**< `(S,WO)` System name overridden */
lldpctl_k_config_advertise_version, /**< `(I)` Advertise version */
lldpctl_k_config_lldpmed_noinventory, /**< `(I)` Disable LLDP-MED inventory */
lldpctl_k_config_paused, /**< `(I)` lldpd is paused */
free(config->c_mgmt_pattern);
free(config->c_cid_pattern);
free(config->c_iface_pattern);
+ free(config->c_hostname);
free(config->c_platform);
free(config->c_description);
}
char *c_platform; /* Override platform description (for CDP) */
char *c_description; /* Override chassis description */
+ char *c_hostname; /* Override system name */
int c_advertise_version; /* Should the precise version be advertised? */
int c_set_ifdescr; /* Set interface description */
MARSHAL_STR(lldpd_config, c_mgmt_pattern)
MARSHAL_STR(lldpd_config, c_cid_pattern)
MARSHAL_STR(lldpd_config, c_iface_pattern)
+MARSHAL_STR(lldpd_config, c_hostname)
MARSHAL_STR(lldpd_config, c_platform)
MARSHAL_STR(lldpd_config, c_description)
MARSHAL_END(lldpd_config);