From: Vincent Bernat Date: Thu, 20 Jun 2013 23:15:15 +0000 (+0200) Subject: lldpcli: `configure system description` to override chassis description X-Git-Tag: 0.7.4~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=decaec0d8a675c0e159248e448e82807f099b2cb;p=thirdparty%2Flldpd.git lldpcli: `configure system description` to override chassis description --- diff --git a/NEWS b/NEWS index 73613a91..0746abd1 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,7 @@ lldpd (0.7.4) * Features: + Allow to configure hold value from lldpcli (and hence the TTL). + Allow to configure pattern for valid interfaces from lldpcli. + + Allow to override system description from lldpcli. lldpd (0.7.3) * Features: diff --git a/src/client/conf-system.c b/src/client/conf-system.c index 49728002..30639a31 100644 --- a/src/client/conf-system.c +++ b/src/client/conf-system.c @@ -45,6 +45,30 @@ cmd_iface_pattern(struct lldpctl_conn_t *conn, struct writer *w, return 1; } +static int +cmd_system_description(struct lldpctl_conn_t *conn, struct writer *w, + struct cmd_env *env, void *arg) +{ + log_debug("lldpctl", "set system description"); + 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; + } + if (lldpctl_atom_set_str(config, + lldpctl_k_config_description, cmdenv_get(env, "description")) == NULL) { + log_warnx("lldpctl", "unable to set system description. %s", + lldpctl_last_strerror(conn)); + lldpctl_atom_dec_ref(config); + return 0; + } + log_info("lldpctl", "system description set to new value %s", + cmdenv_get(env, "description")); + lldpctl_atom_dec_ref(config); + return 1; +} + /** * Register `configure system` commands. * @@ -62,6 +86,16 @@ register_commands_configure_system(struct cmd_node *configure) "interface", "Configure interface related items", NULL, NULL, NULL); + commands_new( + commands_new( + commands_new(configure_system, + "description", "Override system description", + NULL, NULL, NULL), + NULL, "System description", + NULL, cmd_store_env_value, "description"), + NEWLINE, "Override system description", + NULL, cmd_system_description, NULL); + commands_new( commands_new( commands_new(configure_interface, diff --git a/src/client/lldpcli.8 b/src/client/lldpcli.8 index 2590b2ea..f2150ae2 100644 --- a/src/client/lldpcli.8 +++ b/src/client/lldpcli.8 @@ -166,6 +166,13 @@ Make update its information and send new LLDP PDU on all interfaces. .Ed +.Cd configure +.Cd system description Ar description +.Bd -ragged -offset XXXXXX +Override chassis description with the provided value instead of using +kernel name, node name, kernel version, build date and architecture. +.Ed + .Cd configure .Cd system interface pattern Ar pattern .Bd -ragged -offset XXXXXX diff --git a/src/daemon/client.c b/src/daemon/client.c index 5ba97732..3e5c84e3 100644 --- a/src/daemon/client.c +++ b/src/daemon/client.c @@ -94,11 +94,17 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, } #endif if (config->c_iface_pattern) { - log_debug("rpc", "change c_iface_pattern %s", config->c_iface_pattern); + log_debug("rpc", "change interface pattern to %s", config->c_iface_pattern); free(cfg->g_config.c_iface_pattern); cfg->g_config.c_iface_pattern = strdup(config->c_iface_pattern); levent_update_now(cfg); } + if (config->c_description) { + log_debug("rpc", "change system description to %s", config->c_description); + free(cfg->g_config.c_description); + cfg->g_config.c_description = strdup(config->c_description); + levent_update_now(cfg); + } lldpd_config_cleanup(config); free(config); diff --git a/src/lib/atom-private.c b/src/lib/atom-private.c index 9ec61ce6..573cbdb1 100644 --- a/src/lib/atom-private.c +++ b/src/lib/atom-private.c @@ -375,6 +375,7 @@ _lldpctl_atom_set_str_config(lldpctl_atom_t *atom, lldpctl_key_t key, (struct _lldpctl_atom_config_t *)atom; struct lldpd_config config; char *iface_pattern = NULL; + char *system_description = NULL; int rc, len; memset(&config, 0, sizeof(struct lldpd_config)); @@ -390,6 +391,15 @@ _lldpctl_atom_set_str_config(lldpctl_atom_t *atom, lldpctl_key_t key, free(c->config->c_iface_pattern); c->config->c_iface_pattern = strdup(iface_pattern); break; + case lldpctl_k_config_description: + system_description = _lldpctl_alloc_in_atom(atom, strlen(value) + 1); + if (!system_description) + return NULL; + memcpy(system_description, value, len); + config.c_description = system_description; + free(c->config->c_description); + c->config->c_description = strdup(system_description); + break; default: SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); return NULL; diff --git a/src/lib/lldpctl.h b/src/lib/lldpctl.h index 5362e8b6..993bc1a4 100644 --- a/src/lib/lldpctl.h +++ b/src/lib/lldpctl.h @@ -587,7 +587,7 @@ typedef enum { lldpctl_k_config_mgmt_pattern, /**< `(S)` Pattern to choose the management address */ lldpctl_k_config_iface_pattern, /**< `(S,WO)` Pattern of enabled interfaces */ lldpctl_k_config_cid_pattern, /**< `(S)` Interface pattern to choose the chassis ID */ - lldpctl_k_config_description, /**< `(S)` Chassis description overridden */ + lldpctl_k_config_description, /**< `(S,WO)` Chassis description overridden */ lldpctl_k_config_platform, /**< `(S)` Platform description overridden (CDP) */ lldpctl_k_config_advertise_version, /**< `(I)` Advertise version */ lldpctl_k_config_lldpmed_noinventory, /**< `(I)` Disable LLDP-MED inventory */