]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpd: make chassis capabilities advertisement optional
authorAlexandru Ardelean <ardeleanalex@gmail.com>
Thu, 2 Apr 2015 09:26:46 +0000 (12:26 +0300)
committerAlexandru Ardelean <ardeleanalex@gmail.com>
Thu, 9 Apr 2015 12:26:59 +0000 (15:26 +0300)
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
src/client/client.h
src/client/conf-lldp.c
src/client/conf.c
src/daemon/client.c
src/daemon/lldpd.c
src/daemon/protocols/lldp.c
src/lib/atoms/config.c
src/lib/lldpctl.h
src/lldpd-structs.h

index db60fd0b5a8622b166f8c540c0e003fc07380e95..cd737c225c7b4172e710ba3abd755b681b2b61e0 100644 (file)
@@ -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 *);
index 49224f9088cd2f00da12fab38ecce257f1ea9356..b23313af2a058d27451ca9b874dfc7bb7737bb89 100644 (file)
@@ -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);
 }
index d9f0111e0cc4aa54d6503ddc34233eb2a8afbbaf..1a14981d251513b281bb8e3ed96287e489b7c325 100644 (file)
@@ -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);
 }
index c9a4b2e2144b5ba86f0152c9616556e63c230419..a6cc4d2ba652c8a649f8542c86b90080fe992ad9 100644 (file)
@@ -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 &&
index ea40c38a10a35c5e8f3f6a8f2968f9289f7ba686..217435027df99890788b5307a0a07d0fe407c1b6 100644 (file)
@@ -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);
index 108a3f736f2f25f752be194ab970e2ac50332428..835352d3caa4fe3509cdca08875a0f41a67597fb 100644 (file)
@@ -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) &&
index 46388c36c24d8d5da949f1e6394ae3f62be65b37..48af9d3cb566f515db807bb2d811dbcef674b083 100644 (file)
@@ -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;
index a2d9f296122d9053e0da34828f22ddf6be456bcf..f74463baad3d0a2a0256734161e6fc6f56c3aa5a 100644 (file)
@@ -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. */
 
index 9a692802889f8efa55650dd2294a8a5e17b9720f..d4b511f8edc5dad9c959b9641126d0db7000d2ed 100644 (file)
@@ -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 */