From 346a0f6961ba16ba96a96f9919fd02e13a5ef769 Mon Sep 17 00:00:00 2001 From: roopa Date: Thu, 16 May 2013 19:58:58 -0700 Subject: [PATCH] lldpcli: Add support to set iface-pattern 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 --- src/client/conf.c | 34 ++++++++++++++++++++++++++++++++++ src/daemon/client.c | 4 ++++ src/lib/atom-private.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) diff --git a/src/client/conf.c b/src/client/conf.c index a7a7a512..05db254b 100644 --- a/src/client/conf.c +++ b/src/client/conf.c @@ -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); } /** diff --git a/src/daemon/client.c b/src/daemon/client.c index f92a34e8..a3029e5c 100644 --- a/src/daemon/client.c +++ b/src/daemon/client.c @@ -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); diff --git a/src/lib/atom-private.c b/src/lib/atom-private.c index 9a269d1f..804154e7 100644 --- a/src/lib/atom-private.c +++ b/src/lib/atom-private.c @@ -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), -- 2.39.5