From ca838758db3cbe92a321dbcb01fe836130081355 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Thu, 2 Apr 2015 12:26:46 +0300 Subject: [PATCH] lldpd: make chassis capabilities advertisement optional Signed-off-by: Alexandru Ardelean --- src/client/client.h | 2 +- src/client/conf-lldp.c | 47 ++++++++++++++++++++++++++++++++++++- src/client/conf.c | 2 +- src/daemon/client.c | 6 +++++ src/daemon/lldpd.c | 1 + src/daemon/protocols/lldp.c | 2 +- src/lib/atoms/config.c | 5 ++++ src/lib/lldpctl.h | 1 + src/lldpd-structs.h | 1 + 9 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/client/client.h b/src/client/client.h index db60fd0b..cd737c22 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -128,7 +128,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 *, struct cmd_node *); -void register_commands_configure_lldp(struct cmd_node *); +void register_commands_configure_lldp(struct cmd_node *, struct cmd_node *); void register_commands_configure_med(struct cmd_node *, struct cmd_node *); void register_commands_configure_dot3(struct cmd_node *); void register_commands_medpow(struct cmd_node *); diff --git a/src/client/conf-lldp.c b/src/client/conf-lldp.c index 49224f90..b23313af 100644 --- a/src/client/conf-lldp.c +++ b/src/client/conf-lldp.c @@ -145,6 +145,31 @@ cmd_portid_type(struct lldpctl_conn_t *conn, struct writer *w, return 1; } +static int +cmd_chassis_cap_advertise(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_chassis_cap_advertise, + arg?1:0) == NULL) { + log_warnx("lldpctl", "unable to %s chassis capabilities advertisement: %s", + arg?"enable":"disable", + lldpctl_last_strerror(conn)); + lldpctl_atom_dec_ref(config); + return 0; + } + log_info("lldpctl", "chassis capabilities advertisement %s", + arg?"enabled":"disabled"); + lldpctl_atom_dec_ref(config); + return 1; +} + /** * Register `configure lldp` commands. * @@ -152,12 +177,17 @@ cmd_portid_type(struct lldpctl_conn_t *conn, struct writer *w, * Dot1/Dot3/MED. Commands not related to LLDP should go in system instead. */ void -register_commands_configure_lldp(struct cmd_node *configure) +register_commands_configure_lldp(struct cmd_node *configure, + struct cmd_node *unconfigure) { struct cmd_node *configure_lldp = commands_new( configure, "lldp", "LLDP configuration", NULL, NULL, NULL); + struct cmd_node *unconfigure_lldp = commands_new( + unconfigure, + "lldp", "LLDP configuration", + NULL, NULL, NULL); commands_new( commands_new( @@ -227,4 +257,19 @@ register_commands_configure_lldp(struct cmd_node *configure) b_map->string); } } + + commands_new( + commands_new(configure_lldp, + "capabilities-advertisements", + "Enable chassis capabilities advertisement", + NULL, NULL, NULL), + NEWLINE, "Enable chassis capabilities advertisement", + NULL, cmd_chassis_cap_advertise, "enable"); + commands_new( + commands_new(unconfigure_lldp, + "capabilities-advertisements", + "Don't enable chassis capabilities advertisement", + NULL, NULL, NULL), + NEWLINE, "Don't enable chassis capabilities advertisement", + NULL, cmd_chassis_cap_advertise, NULL); } diff --git a/src/client/conf.c b/src/client/conf.c index d9f0111e..1a14981d 100644 --- a/src/client/conf.c +++ b/src/client/conf.c @@ -43,7 +43,7 @@ register_commands_configure(struct cmd_node *root) cmd_restrict_ports(unconfigure); register_commands_configure_system(configure, unconfigure); - register_commands_configure_lldp(configure); + register_commands_configure_lldp(configure, unconfigure); register_commands_configure_med(configure, unconfigure); register_commands_configure_dot3(configure); } diff --git a/src/daemon/client.c b/src/daemon/client.c index c9a4b2e2..a6cc4d2b 100644 --- a/src/daemon/client.c +++ b/src/daemon/client.c @@ -162,6 +162,12 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, cfg->g_config.c_promisc = config->c_promisc; levent_update_now(cfg); } + if (CHANGED(c_cap_advertise)) { + log_debug("rpc", "%s chassis capabilities advertisement", + config->c_promisc?"enable":"disable"); + cfg->g_config.c_cap_advertise = config->c_cap_advertise; + levent_update_now(cfg); + } if (CHANGED(c_bond_slave_src_mac_type)) { if (config->c_bond_slave_src_mac_type > LLDP_BOND_SLAVE_SRC_MAC_TYPE_UNKNOWN && diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index ea40c38a..21743502 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -1638,6 +1638,7 @@ lldpd_main(int argc, char *argv[], char *envp[]) if ((lchassis = (struct lldpd_chassis*) calloc(1, sizeof(struct lldpd_chassis))) == NULL) fatal("localchassis", NULL); + cfg->g_config.c_cap_advertise = 1; lchassis->c_cap_available = LLDP_CAP_BRIDGE | LLDP_CAP_WLAN | LLDP_CAP_ROUTER | LLDP_CAP_STATION; TAILQ_INIT(&lchassis->c_mgmt); diff --git a/src/daemon/protocols/lldp.c b/src/daemon/protocols/lldp.c index 108a3f73..835352d3 100644 --- a/src/daemon/protocols/lldp.c +++ b/src/daemon/protocols/lldp.c @@ -146,7 +146,7 @@ static int _lldp_send(struct lldpd *global, } /* System capabilities */ - if (chassis->c_cap_available) { + if (global->g_config.c_cap_advertise && chassis->c_cap_available) { if (!( POKE_START_LLDP_TLV(LLDP_TLV_SYSTEM_CAP) && POKE_UINT16(chassis->c_cap_available) && diff --git a/src/lib/atoms/config.c b/src/lib/atoms/config.c index 46388c36..48af9d3c 100644 --- a/src/lib/atoms/config.c +++ b/src/lib/atoms/config.c @@ -201,6 +201,8 @@ _lldpctl_atom_get_int_config(lldpctl_atom_t *atom, lldpctl_key_t key) return c->config->c_set_ifdescr; case lldpctl_k_config_iface_promisc: return c->config->c_promisc; + case lldpctl_k_config_chassis_cap_advertise: + return c->config->c_cap_advertise; #ifdef ENABLE_LLDPMED case lldpctl_k_config_lldpmed_noinventory: return c->config->c_noinventory; @@ -241,6 +243,9 @@ _lldpctl_atom_set_int_config(lldpctl_atom_t *atom, lldpctl_key_t key, case lldpctl_k_config_iface_promisc: config.c_promisc = c->config->c_promisc = value; break; + case lldpctl_k_config_chassis_cap_advertise: + config.c_cap_advertise = c->config->c_cap_advertise = value; + break; #ifdef ENABLE_LLDPMED case lldpctl_k_config_fast_start_enabled: config.c_enable_fast_start = c->config->c_enable_fast_start = value; diff --git a/src/lib/lldpctl.h b/src/lib/lldpctl.h index a2d9f296..f74463ba 100644 --- a/src/lib/lldpctl.h +++ b/src/lib/lldpctl.h @@ -612,6 +612,7 @@ typedef enum { 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_config_iface_promisc, /**< `(I,WO)` Enable or disable promiscuous mode on interfaces */ + lldpctl_k_config_chassis_cap_advertise, /**< `(I,WO)` Enable or disable chassis capabilities advertisement */ lldpctl_k_interface_name = 1000, /**< `(S)` The interface name. */ diff --git a/src/lldpd-structs.h b/src/lldpd-structs.h index 9a692802..d4b511f8 100644 --- a/src/lldpd-structs.h +++ b/src/lldpd-structs.h @@ -331,6 +331,7 @@ struct lldpd_config { int c_advertise_version; /* Should the precise version be advertised? */ int c_set_ifdescr; /* Set interface description */ int c_promisc; /* Interfaces should be in promiscuous mode */ + int c_cap_advertise; /* Chassis capabilities advertisement */ #ifdef ENABLE_LLDPMED int c_noinventory; /* Don't send inventory with LLDP-MED */ -- 2.39.5