]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpcli: Add support to set iface-pattern
authorroopa <roopa@cumulusnetworks.com>
Fri, 17 May 2013 02:58:58 +0000 (19:58 -0700)
committerVincent Bernat <bernat@luffy.cx>
Sat, 1 Jun 2013 09:20:54 +0000 (11:20 +0200)
This patch adds a new configure lldp command to set iface-pattern

Currently only sets iface-pattern on the server.
More incremental work is needed to trigger an interface
update and send.

Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
src/client/conf.c
src/daemon/client.c
src/lib/atom-private.c

index a7a7a512bcd7384523c90c24a45542657f183510..05db254b5c86bdab0e775a587e5d7a67f2ee8c90 100644 (file)
@@ -69,6 +69,30 @@ cmd_txhold(struct lldpctl_conn_t *conn, struct writer *w,
        return 1;
 }
 
+static int
+cmd_iface_pattern(struct lldpctl_conn_t *conn, struct writer *w,
+    struct cmd_env *env, void *arg)
+{
+       log_debug("lldpctl", "set iface pattern");
+
+       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_iface_pattern, cmdenv_get(env, "iface-pattern")) == NULL) {
+               log_warnx("lldpctl", "unable to set iface-pattern. %s",
+                   lldpctl_last_strerror(conn));
+               lldpctl_atom_dec_ref(config);
+               return 0;
+       }
+       log_info("lldpctl", "iface-pattern set to new value %s", cmdenv_get(env, "iface-pattern"));
+       lldpctl_atom_dec_ref(config);
+       return 1;
+}
+
 /**
  * Register `configure lldp` commands.
  */
@@ -99,6 +123,16 @@ register_commands_configure_lldp(struct cmd_node *configure)
                        NULL, cmd_store_env_value, "tx-hold"),
                NEWLINE, "Set LLDP transmit hold",
                NULL, cmd_txhold, NULL);
+
+        commands_new(
+               commands_new(
+                       commands_new(configure_lldp,
+                           "iface-pattern", "Set LLDP iface pattern",
+                           cmd_check_no_env, NULL, "ports"),
+                       NULL, "LLDP iface pattern",
+                       NULL, cmd_store_env_value, "iface-pattern"),
+               NEWLINE, "Set LLDP iface pattern",
+               NULL, cmd_iface_pattern, NULL);
 }
 
 /**
index f92a34e8976ac71b4606fc397ef7085ac754418f..a3029e5cb89fbcc40bec67c99a82a78b78ca38b1 100644 (file)
@@ -95,6 +95,10 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type,
                cfg->g_config.c_tx_fast_interval = config->c_tx_fast_interval;
        }
 #endif
+       if (config->c_iface_pattern) {
+               log_debug("rpc", "change c_iface_pattern %s", config->c_iface_pattern);
+               cfg->g_config.c_iface_pattern = strdup(config->c_iface_pattern);
+       }
 
        lldpd_config_cleanup(config);
 
index 9a269d1f38d993dd00525e6cb9398e641c563dbb..804154e79e47920915252ebd38a2091393a765ca 100644 (file)
@@ -367,6 +367,43 @@ _lldpctl_atom_get_str_config(lldpctl_atom_t *atom, lldpctl_key_t key)
        return res?res:"";
 }
 
+static lldpctl_atom_t*
+_lldpctl_atom_set_str_config(lldpctl_atom_t *atom, lldpctl_key_t key,
+    const char *value)
+{
+       struct _lldpctl_atom_config_t *c =
+           (struct _lldpctl_atom_config_t *)atom;
+       struct lldpd_config config;
+       char *iface_pattern = NULL;
+       int rc, len;
+
+       memset(&config, 0, sizeof(struct lldpd_config));
+       len = strlen(value) + 1;
+
+       switch (key) {
+       case lldpctl_k_config_iface_pattern:
+               iface_pattern = _lldpctl_alloc_in_atom(atom, strlen(value) + 1);
+               if (!iface_pattern)
+                       return NULL;
+               memcpy(iface_pattern, value, len);
+               config.c_iface_pattern = iface_pattern;
+               c->config->c_iface_pattern = strdup(iface_pattern);
+               break;
+       default:
+               SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST);
+               return NULL;
+       }
+
+       rc = _lldpctl_do_something(atom->conn,
+           CONN_STATE_SET_CONFIG_SEND, CONN_STATE_SET_CONFIG_RECV,
+           NULL,
+           SET_CONFIG, &config, &MARSHAL_INFO(lldpd_config),
+           NULL, NULL);
+       if (rc == 0) return atom;
+
+       return NULL;
+}
+
 static long int
 _lldpctl_atom_get_int_config(lldpctl_atom_t *atom, lldpctl_key_t key)
 {
@@ -2476,6 +2513,7 @@ struct atom_builder builders[] = {
          .init = _lldpctl_atom_new_config,
          .free = _lldpctl_atom_free_config,
          .get_str = _lldpctl_atom_get_str_config,
+         .set_str = _lldpctl_atom_set_str_config,
          .get_int = _lldpctl_atom_get_int_config,
          .set_int = _lldpctl_atom_set_int_config },
        { atom_interfaces_list, sizeof(struct _lldpctl_atom_interfaces_list_t),