]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpcli: directive to configure IP management pattern
authorVincent Bernat <vincent@bernat.im>
Sun, 11 May 2014 14:21:33 +0000 (16:21 +0200)
committerVincent Bernat <vincent@bernat.im>
Sun, 11 May 2014 14:22:14 +0000 (16:22 +0200)
This closes #54.

NEWS
src/client/conf-system.c
src/client/lldpcli.8.in
src/daemon/client.c
src/lib/atom-private.c

diff --git a/NEWS b/NEWS
index 5d1603ea886ce7512549f0e155db075b4c49ebeb..8888edc418c232144beaa44464a006e3ea7b527a 100644 (file)
--- 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:
index 60d6ad9c56458757823f4f0763f14af66344dbe7..dba48c01202e97374d5060f4c40afac0af68b390 100644 (file)
@@ -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);
index 7933bab63ec3693ec4d341f002f2060273ca5053..e7f1ac4a3ae4359d29391a3cd6f57c04a68c4971 100644 (file)
@@ -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
index 674b854ffd1605ec6e569a191235cd64881b4be7..dffe605199bb45c424e1a3d5107ec8bc60d1760b 100644 (file)
@@ -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);
index 313ec5d2eebffc26dcd9a872c708677151ecb688..318daff26c0c78e0a72cacd49542bf779f256e6b 100644 (file)
@@ -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)