From: Vincent Bernat Date: Wed, 3 Jul 2013 08:05:23 +0000 (+0200) Subject: client: add "configure/unconfigure system interface description" command X-Git-Tag: 0.7.6~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bb37268d812b783d956863cd8a159195bad6c4f0;p=thirdparty%2Flldpd.git client: add "configure/unconfigure system interface description" command This allows to enable/disable updating interface description based on visible neighbors. --- diff --git a/NEWS b/NEWS index 2f7dbb39..d0f8d6db 100644 --- 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. diff --git a/src/client/client.h b/src/client/client.h index a2de3192..600acc64 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -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 *); diff --git a/src/client/conf-system.c b/src/client/conf-system.c index bb98ba86..442a60d7 100644 --- a/src/client/conf-system.c +++ b/src/client/conf-system.c @@ -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); } + diff --git a/src/client/conf.c b/src/client/conf.c index 7b8e68ac..7e7c67a2 100644 --- a/src/client/conf.c +++ b/src/client/conf.c @@ -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); diff --git a/src/client/display.c b/src/client/display.c index 03f1b7da..7e83d615 100644 --- a/src/client/display.c +++ b/src/client/display.c @@ -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"); diff --git a/src/client/lldpcli.8 b/src/client/lldpcli.8 index 4e27f590..5d419701 100644 --- a/src/client/lldpcli.8 +++ b/src/client/lldpcli.8 @@ -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 diff --git a/src/daemon/client.c b/src/daemon/client.c index 01e5a884..325104ee 100644 --- a/src/daemon/client.c +++ b/src/daemon/client.c @@ -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); diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index 27e7ef71..ff854c3e 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -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; diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 2ebd9055..f074c4f1 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -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 diff --git a/src/lib/atom-private.c b/src/lib/atom-private.c index 4325012e..efb18f42 100644 --- a/src/lib/atom-private.c +++ b/src/lib/atom-private.c @@ -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; diff --git a/src/lib/lldpctl.h b/src/lib/lldpctl.h index cf3cf76d..171ac23e 100644 --- a/src/lib/lldpctl.h +++ b/src/lib/lldpctl.h @@ -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. */ diff --git a/src/lldpd-structs.h b/src/lldpd-structs.h index f2d25add..67c047f5 100644 --- a/src/lldpd-structs.h +++ b/src/lldpd-structs.h @@ -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 */