]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
client: add "configure/unconfigure system interface description" command
authorVincent Bernat <bernat@luffy.cx>
Wed, 3 Jul 2013 08:05:23 +0000 (10:05 +0200)
committerVincent Bernat <bernat@luffy.cx>
Wed, 3 Jul 2013 08:05:23 +0000 (10:05 +0200)
This allows to enable/disable updating interface description based on
visible neighbors.

12 files changed:
NEWS
src/client/client.h
src/client/conf-system.c
src/client/conf.c
src/client/display.c
src/client/lldpcli.8
src/daemon/client.c
src/daemon/lldpd.c
src/lib/Makefile.am
src/lib/atom-private.c
src/lib/lldpctl.h
src/lldpd-structs.h

diff --git a/NEWS b/NEWS
index 2f7dbb39854594ad66746b11ede8d5a0c031abf3..d0f8d6db97b3f2ba713081304b2e042a2d08ad1a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
 lldpd (0.7.6)
   * Features:
     + Provide a way to build packages for OSX.
+    + Add an option to update interface description with neighbor name.
   * Fixes:
     + Compilation fix for OSX 10.6.
 
index a2de319250f0e4fd6a2fa800ba3170402155c420..600acc64fc1bd391905dca4682584b04627bebe8 100644 (file)
@@ -124,7 +124,7 @@ void register_commands_watch(struct cmd_node *);
 
 /* conf*.c */
 void register_commands_configure(struct cmd_node *);
-void register_commands_configure_system(struct cmd_node *);
+void register_commands_configure_system(struct cmd_node *, struct cmd_node *);
 void register_commands_configure_lldp(struct cmd_node *);
 void register_commands_configure_med(struct cmd_node *, struct cmd_node *);
 void register_commands_configure_dot3(struct cmd_node *);
index bb98ba86f7a5be12e90380b6d70a9d26461db2a4..442a60d7cb1252dd3dae30d30e918ea8f4d4796b 100644 (file)
@@ -76,21 +76,55 @@ cmd_system_description(struct lldpctl_conn_t *conn, struct writer *w,
        return 1;
 }
 
+static int
+cmd_update_descriptions(struct lldpctl_conn_t *conn, struct writer *w,
+    struct cmd_env *env, void *arg)
+{
+       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_int(config,
+               lldpctl_k_config_ifdescr_update,
+               arg?1:0) == NULL) {
+               log_warnx("lldpctl", "unable to %s interface description update: %s",
+                   arg?"enable":"disable",
+                   lldpctl_last_strerror(conn));
+               lldpctl_atom_dec_ref(config);
+               return 0;
+       }
+       log_info("lldpctl", "interface description update %s",
+           arg?"enabled":"disabled");
+       lldpctl_atom_dec_ref(config);
+       return 1;
+}
+
 /**
  * Register `configure system` commands.
  *
  * Those are the commands to configure protocol-independant stuff.
  */
 void
-register_commands_configure_system(struct cmd_node *configure)
+register_commands_configure_system(struct cmd_node *configure,
+    struct cmd_node *unconfigure)
 {
        struct cmd_node *configure_system = commands_new(
                configure,
                "system", "System configuration",
                cmd_check_no_env, NULL, "ports");
+       struct cmd_node *unconfigure_system = commands_new(
+               unconfigure,
+               "system", "System configuration",
+               cmd_check_no_env, NULL, "ports");
        struct cmd_node *configure_interface = commands_new(
                configure_system,
-               "interface", "Configure interface related items",
+               "interface", "Interface related items",
+               NULL, NULL, NULL);
+       struct cmd_node *unconfigure_interface = commands_new(
+               unconfigure_system,
+               "interface", "Interface related items",
                NULL, NULL, NULL);
 
        commands_new(
@@ -122,4 +156,18 @@ register_commands_configure_system(struct cmd_node *configure)
                        NULL, cmd_store_env_value, "iface-pattern"),
                NEWLINE, "Set active interface pattern",
                NULL, cmd_iface_pattern, NULL);
+
+       commands_new(
+               commands_new(configure_interface,
+                   "description", "Update interface descriptions with neighbor name",
+                   NULL, NULL, NULL),
+               NEWLINE, "Update interface descriptions with neighbor name",
+               NULL, cmd_update_descriptions, "enable");
+       commands_new(
+               commands_new(unconfigure_interface,
+                   "description", "Don't update interface descriptions with neighbor name",
+                   NULL, NULL, NULL),
+               NEWLINE, "Don't update interface descriptions with neighbor name",
+               NULL, cmd_update_descriptions, NULL);
 }
+
index 7b8e68acdba501b2badce6ba8d5c240982ae7628..7e7c67a2d6f82b43a3dedcfb583a40d1417825ec 100644 (file)
@@ -40,7 +40,7 @@ register_commands_configure(struct cmd_node *root)
        cmd_restrict_ports(configure);
        cmd_restrict_ports(unconfigure);
 
-       register_commands_configure_system(configure);
+       register_commands_configure_system(configure, unconfigure);
        register_commands_configure_lldp(configure);
        register_commands_configure_med(configure, unconfigure);
        register_commands_configure_dot3(configure);
index 03f1b7da605a697407c0945ca2de50ebdfc900d0..7e83d615b6a81ca6f88e0d902120b90c417727f0 100644 (file)
@@ -726,6 +726,9 @@ display_configuration(lldpctl_conn_t *conn, struct writer *w)
        tag_datatag(w, "advertise-version", "Advertise version",
            lldpctl_atom_get_int(configuration, lldpctl_k_config_advertise_version)?
            "yes":"no");
+       tag_datatag(w, "ifdescr-update", "Update interface descriptions",
+           lldpctl_atom_get_int(configuration, lldpctl_k_config_ifdescr_update)?
+           "yes":"no");
        tag_datatag(w, "lldpmed-no-inventory", "Disable LLDP-MED inventory",
            (lldpctl_atom_get_int(configuration, lldpctl_k_config_lldpmed_noinventory) == 0)?
            "no":"yes");
index 4e27f5905be5cbcad396bb3ffc8c9aea0ef098c1..5d419701bf5e339cb1d97deddfa6e4f2a885c0f3 100644 (file)
@@ -200,6 +200,16 @@ and
 .Em eth2 .
 .Ed
 
+.Cd configure
+.Cd system interface description
+.Bd -ragged -offset XXXXXX
+Some OS allows the user to set a description for an interface. Setting
+this option will enable
+.Nm lldpd
+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 lldp tx-interval Ar interval
 .Bd -ragged -offset XXXXXX
index 01e5a8849656bd73ee28482f9c6f53027af9e89c..325104eec99f56c7134ea0e7c232f1520a3d6988 100644 (file)
@@ -111,6 +111,12 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type,
                cfg->g_config.c_platform = strdup(config->c_platform);
                levent_update_now(cfg);
        }
+       if (config->c_set_ifdescr != cfg->g_config.c_set_ifdescr) {
+               log_debug("rpc", "%s setting of interface description based on discovered neighbors",
+                   config->c_set_ifdescr?"enable":"disable");
+               cfg->g_config.c_set_ifdescr = config->c_set_ifdescr;
+               levent_update_now(cfg);
+       }
 
        lldpd_config_cleanup(config);
        free(config);
index 27e7ef7106e08603d43a2711ec16edbcfd6b4920..ff854c3e1f0084a43386aef2a2004ba8fb3bedf5 100644 (file)
@@ -216,6 +216,7 @@ lldpd_hardware_cleanup(struct lldpd *cfg, struct lldpd_hardware *hardware)
 static void
 lldpd_display_neighbors(struct lldpd *cfg)
 {
+       if (!cfg->g_config.c_set_ifdescr) return;
        struct lldpd_hardware *hardware;
        TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) {
                struct lldpd_port *port;
index 2ebd9055d9021fd2cb43044d4d65215d3d7d22cd..f074c4f16102b609e6bdea8d3c6672e4e9897c5b 100644 (file)
@@ -5,7 +5,7 @@ include_HEADERS = lldpctl.h
 
 liblldpctl_la_SOURCES = lldpctl.h private.h errors.c connection.c atom.c atom-private.c
 liblldpctl_la_LIBADD  = $(top_builddir)/src/libcommon-daemon-lib.la
-liblldpctl_la_LDFLAGS = -export-symbols-regex '^lldpctl_' -version-info 4:0:0
+liblldpctl_la_LDFLAGS = -export-symbols-regex '^lldpctl_' -version-info 5:0:1
 
 # -version-info format is `current`:`revision`:`age`. For more details, see:
 #   http://sources.redhat.com/autobook/autobook/autobook_91.html#SEC91
index 4325012e7ef50508455dcabe436e24c32815fad1..efb18f42ba8b83266d01e5df58d3aabd6f37e2c9 100644 (file)
@@ -437,6 +437,8 @@ _lldpctl_atom_get_int_config(lldpctl_atom_t *atom, lldpctl_key_t key)
                return c->config->c_receiveonly;
        case lldpctl_k_config_advertise_version:
                return c->config->c_advertise_version;
+       case lldpctl_k_config_ifdescr_update:
+               return c->config->c_set_ifdescr;
 #ifdef ENABLE_LLDPMED
        case lldpctl_k_config_lldpmed_noinventory:
                return c->config->c_noinventory;
@@ -469,6 +471,9 @@ _lldpctl_atom_set_int_config(lldpctl_atom_t *atom, lldpctl_key_t key,
                config.c_tx_interval = value;
                if (value > 0) c->config->c_tx_interval = value;
                break;
+       case lldpctl_k_config_ifdescr_update:
+               config.c_set_ifdescr = c->config->c_set_ifdescr = value;
+               break;
 #ifdef ENABLE_LLDPMED
        case lldpctl_k_config_fast_start_enabled:
                config.c_enable_fast_start =  value?1:2;
index cf3cf76df93a131ec7ce953127f2ec7990d10660..171ac23eeabeaf149f95435574fef3d2e9bfeb97 100644 (file)
@@ -594,6 +594,7 @@ typedef enum {
        lldpctl_k_config_paused,              /**< `(I)` lldpd is paused */
        lldpctl_k_config_fast_start_enabled, /**< `(I,WO)` Is fast start enabled */
        lldpctl_k_config_fast_start_interval, /**< `(I,WO)` Start fast transmit interval */
+       lldpctl_k_config_ifdescr_update, /**< `(I,WO)` Enable or disable setting interface description */
 
        lldpctl_k_interface_name = 1000, /**< `(S)` The interface name. */
 
index f2d25add4d1690b406b763bde6d932867ad8afa2..67c047f50802f4271dc7e0e5f54be0fc9cdec09c 100644 (file)
@@ -324,6 +324,7 @@ struct lldpd_config {
        char *c_platform;       /* Override platform description (for CDP) */
        char *c_description;    /* Override chassis description */
        int c_advertise_version; /* Should the precise version be advertised? */
+       int c_set_ifdescr;       /* Set interface description */
 
 #ifdef ENABLE_LLDPMED
        int c_noinventory;      /* Don't send inventory with LLDP-MED */