From: Vincent Bernat Date: Sun, 11 May 2014 14:21:33 +0000 (+0200) Subject: lldpcli: directive to configure IP management pattern X-Git-Tag: 0.7.9~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=622d14bbdf1622ec34f9fdc27b8556bf83ab7e82;p=thirdparty%2Flldpd.git lldpcli: directive to configure IP management pattern This closes #54. --- diff --git a/NEWS b/NEWS index 5d1603ea..8888edc4 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ lldpd (0.7.9) it as default. * Features: + Add support for shutdown LLDPU. + + Ability to configure IP management pattern from lldpcli. lldpd (0.7.8) * Fixes: diff --git a/src/client/conf-system.c b/src/client/conf-system.c index 60d6ad9c..dba48c01 100644 --- a/src/client/conf-system.c +++ b/src/client/conf-system.c @@ -76,6 +76,32 @@ cmd_system_description(struct lldpctl_conn_t *conn, struct writer *w, return 1; } +static int +cmd_management(struct lldpctl_conn_t *conn, struct writer *w, + struct cmd_env *env, void *arg) +{ + log_debug("lldpctl", "set management 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; + } + const char *value = cmdenv_get(env, "management-pattern"); + + if (lldpctl_atom_set_str(config, + lldpctl_k_config_mgmt_pattern, value) == NULL) { + log_warnx("lldpctl", "unable to set management pattern. %s", + lldpctl_last_strerror(conn)); + lldpctl_atom_dec_ref(config); + return 0; + } + log_info("lldpctl", "management pattaren set to new value %s", value); + lldpctl_atom_dec_ref(config); + return 1; +} + static int cmd_hostname(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, void *arg) @@ -91,7 +117,7 @@ cmd_hostname(struct lldpctl_conn_t *conn, struct writer *w, const char *value = cmdenv_get(env, "hostname"); if (lldpctl_atom_set_str(config, - lldpctl_k_config_hostname, cmdenv_get(env, "hostname")) == NULL) { + lldpctl_k_config_hostname, value) == NULL) { log_warnx("lldpctl", "unable to set system name. %s", lldpctl_last_strerror(conn)); lldpctl_atom_dec_ref(config); @@ -282,12 +308,28 @@ register_commands_configure_system(struct cmd_node *configure, NEWLINE, "Override system name", NULL, cmd_hostname, NULL); + commands_new( + commands_new( + commands_new( + commands_new( + commands_new(configure_system, + "ip", "IP related options", + NULL, NULL, NULL), + "management", "IP management related options", + NULL, NULL, NULL), + "pattern", "Set IP management pattern", + NULL, NULL, NULL), + NULL, "IP management pattern (comma-separated list of wildcards)", + NULL, cmd_store_env_value, "management-pattern"), + NEWLINE, "Set IP management pattern", + NULL, cmd_management, NULL); + commands_new( commands_new( commands_new(configure_interface, "pattern", "Set active interface pattern", NULL, NULL, NULL), - NULL, "Interface pattern (comma separated list of wildcards)", + NULL, "Interface pattern (comma-separated list of wildcards)", NULL, cmd_store_env_value, "iface-pattern"), NEWLINE, "Set active interface pattern", NULL, cmd_iface_pattern, NULL); diff --git a/src/client/lldpcli.8.in b/src/client/lldpcli.8.in index 7933bab6..e7f1ac4a 100644 --- a/src/client/lldpcli.8.in +++ b/src/client/lldpcli.8.in @@ -218,6 +218,18 @@ to override this description with the name of the peer neighbor if one is found or with the number of neighbors found. .Ed +.Cd configure +.Cd system ip management pattern Ar pattern +.Bd -ragged -offset XXXXXX +Specify the management addresses of this system. As for interfaces +(described above), this option can use wildcards and inversions. +Without this option, the first IPv4 and the first IPv6 are used. If +only negative patterns are provided, only one IPv4 and one IPv6 +addresses are chosen. Otherwise, many of them can be selected. If you +want to blacklist IPv6 addresses, you can use +.Em !*:* . +.Ed + .Cd configure .Cd lldp tx-interval Ar interval .Bd -ragged -offset XXXXXX diff --git a/src/daemon/client.c b/src/daemon/client.c index 674b854f..dffe6051 100644 --- a/src/daemon/client.c +++ b/src/daemon/client.c @@ -100,6 +100,12 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, cfg->g_config.c_iface_pattern = strdup(config->c_iface_pattern); levent_update_now(cfg); } + if (config->c_mgmt_pattern) { + log_debug("rpc", "change management pattern to %s", config->c_mgmt_pattern); + free(cfg->g_config.c_mgmt_pattern); + cfg->g_config.c_mgmt_pattern = strdup(config->c_mgmt_pattern); + levent_update_now(cfg); + } if (config->c_description) { log_debug("rpc", "change chassis description to %s", config->c_description); free(cfg->g_config.c_description); diff --git a/src/lib/atom-private.c b/src/lib/atom-private.c index 313ec5d2..318daff2 100644 --- a/src/lib/atom-private.c +++ b/src/lib/atom-private.c @@ -386,7 +386,7 @@ _lldpctl_atom_set_str_config(lldpctl_atom_t *atom, lldpctl_key_t key, struct _lldpctl_atom_config_t *c = (struct _lldpctl_atom_config_t *)atom; struct lldpd_config config = {}; - char *iface_pattern = NULL; + char *iface_pattern = NULL, *mgmt_pattern = NULL; char *description = NULL; int rc, len; @@ -402,6 +402,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_mgmt_pattern: + mgmt_pattern = _lldpctl_alloc_in_atom(atom, strlen(value) + 1); + if (!mgmt_pattern) + return NULL; + memcpy(mgmt_pattern, value, len); + config.c_mgmt_pattern = mgmt_pattern; + free(c->config->c_mgmt_pattern); + c->config->c_mgmt_pattern = strdup(mgmt_pattern); + break; case lldpctl_k_config_description: description = _lldpctl_alloc_in_atom(atom, strlen(value) + 1); if (!description)