]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpcli: `configure system description` to override chassis description
authorVincent Bernat <bernat@luffy.cx>
Thu, 20 Jun 2013 23:15:15 +0000 (01:15 +0200)
committerVincent Bernat <bernat@luffy.cx>
Thu, 20 Jun 2013 23:15:31 +0000 (01:15 +0200)
NEWS
src/client/conf-system.c
src/client/lldpcli.8
src/daemon/client.c
src/lib/atom-private.c
src/lib/lldpctl.h

diff --git a/NEWS b/NEWS
index 73613a91879d47d152d3eaad767f769e5b8f346d..0746abd129b80bb6ad36e9d1cdf10090459afe78 100644 (file)
--- 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:
index 497280020c0d7861ff93a0ffafb6c9c331bc06bb..30639a31f5482d80b5a962e5f76b8c3c6ba62401 100644 (file)
@@ -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,
index 2590b2eaada6652d4321c8cf5c6b4a902e368537..f2150ae2ddb4dc8aea82df81bd5e8d96257209fd 100644 (file)
@@ -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
index 5ba9773268aab83470554d0e51685403c8f8457f..3e5c84e35e82e2abdf85b8066cad9655709f5042 100644 (file)
@@ -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);
index 9ec61ce6d0ffaaf5f859eb8a6517fa09359a519c..573cbdb1de44ef0b6265cf30708061e34bb05bff 100644 (file)
@@ -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;
index 5362e8b6c23607f93f5c1ed24b7d4652d20308da..993bc1a44cd5cd6e459e27bb16c1dac7ac2e339e 100644 (file)
@@ -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 */