From ba1bdf6aaf765897b1f7b175e5d57f8d21040391 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sat, 6 Apr 2019 12:13:24 +0200 Subject: [PATCH] client: ability to set maximum of neighbors from lldpcli --- NEWS | 5 +++++ src/client/conf-lldp.c | 34 ++++++++++++++++++++++++++++++++++ src/client/display.c | 2 ++ src/client/lldpcli.8.in | 8 ++++++++ src/daemon/client.c | 5 +++++ src/lib/atoms/config.c | 6 ++++++ src/lib/lldpctl.h | 1 + tests/lldpcli.conf | 1 + 8 files changed, 62 insertions(+) diff --git a/NEWS b/NEWS index cd606215..41c44e6b 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +lldpd (1.0.4) + * Changes: + + Add "set system lldp max-neighbors XX" command to modify maximum + of neighbors accepted per port. + lldpd (1.0.3) * Fix: + Fix creation of chroot directory. diff --git a/src/client/conf-lldp.c b/src/client/conf-lldp.c index 8523f3cc..94f397e4 100644 --- a/src/client/conf-lldp.c +++ b/src/client/conf-lldp.c @@ -70,6 +70,30 @@ cmd_txhold(struct lldpctl_conn_t *conn, struct writer *w, return 1; } +static int +cmd_maxneighs(struct lldpctl_conn_t *conn, struct writer *w, + struct cmd_env *env, void *arg) +{ + log_debug("lldpctl", "set maximum neighbors"); + + 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_str(config, + lldpctl_k_config_max_neighbors, cmdenv_get(env, "max-neighbors")) == NULL) { + log_warnx("lldpctl", "unable to set maximum of neighbors. %s", + lldpctl_last_strerror(conn)); + lldpctl_atom_dec_ref(config); + return 0; + } + log_info("lldpctl", "maximum neighbors set to new value %s", cmdenv_get(env, "max-neighbors")); + lldpctl_atom_dec_ref(config); + return 1; +} + static int cmd_status(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, void *arg) @@ -536,6 +560,16 @@ register_commands_configure_lldp(struct cmd_node *configure, NEWLINE, "Set LLDP transmit hold", NULL, cmd_txhold, NULL); + commands_new( + commands_new( + commands_new(configure_lldp, + "max-neighbors", "Set maximum number of neighbors per port", + cmd_check_no_env, NULL, "ports"), + NULL, "Maximum number of neighbors", + NULL, cmd_store_env_value, "max-neighbors"), + NEWLINE, "Set maximum number of neighbors per port", + NULL, cmd_maxneighs, NULL); + struct cmd_node *status = commands_new(configure_lldp, "status", "Set administrative status", NULL, NULL, NULL); diff --git a/src/client/display.c b/src/client/display.c index f452fc52..312091de 100644 --- a/src/client/display.c +++ b/src/client/display.c @@ -886,6 +886,8 @@ display_configuration(lldpctl_conn_t *conn, struct writer *w) lldpctl_atom_get_str(configuration, lldpctl_k_config_tx_interval)); tag_datatag(w, "tx-hold", "Transmit hold", lldpctl_atom_get_str(configuration, lldpctl_k_config_tx_hold)); + tag_datatag(w, "max-neighbors", "Maximum number of neighbors", + lldpctl_atom_get_str(configuration, lldpctl_k_config_max_neighbors)); tag_datatag(w, "rx-only", "Receive mode", lldpctl_atom_get_int(configuration, lldpctl_k_config_receiveonly)? "yes":"no"); diff --git a/src/client/lldpcli.8.in b/src/client/lldpcli.8.in index ff2a8828..68de74e6 100644 --- a/src/client/lldpcli.8.in +++ b/src/client/lldpcli.8.in @@ -506,6 +506,14 @@ value and of the transmit delay. The default value is 4 and therefore the default TTL is 120 seconds. .Ed +.Cd configure +.Cd lldp max-neighbors Ar neighbors +.Bd -ragged -offset XXXXXX +Change the maximum number of neighbors accepted (for each protocol) on +an interface. This is a global value. The default is 32. This setting +only applies to future neighbors. +.Ed + .Cd configure .Op ports Ar ethX Op ,... .Cd lldp diff --git a/src/daemon/client.c b/src/daemon/client.c index e2ca4ff2..a95de9c1 100644 --- a/src/daemon/client.c +++ b/src/daemon/client.c @@ -87,6 +87,11 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, cfg->g_config.c_ttl = cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold; } + if (CHANGED(c_max_neighbors) && config->c_max_neighbors > 0) { + log_debug("rpc", "client change maximum neighbors to %d", + config->c_max_neighbors); + cfg->g_config.c_max_neighbors = config->c_max_neighbors; + } if (CHANGED(c_lldp_portid_type) && config->c_lldp_portid_type > LLDP_PORTID_SUBTYPE_UNKNOWN && config->c_lldp_portid_type <= LLDP_PORTID_SUBTYPE_MAX) { diff --git a/src/lib/atoms/config.c b/src/lib/atoms/config.c index 6971b400..66374c69 100644 --- a/src/lib/atoms/config.c +++ b/src/lib/atoms/config.c @@ -244,6 +244,8 @@ _lldpctl_atom_get_int_config(lldpctl_atom_t *atom, lldpctl_key_t key) #endif case lldpctl_k_config_tx_hold: return c->config->c_tx_hold; + case lldpctl_k_config_max_neighbors: + return c->config->c_max_neighbors; default: return SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); } @@ -292,6 +294,10 @@ _lldpctl_atom_set_int_config(lldpctl_atom_t *atom, lldpctl_key_t key, config.c_tx_hold = value; if (value > 0) c->config->c_tx_hold = value; break; + case lldpctl_k_config_max_neighbors: + config.c_max_neighbors = value; + if (value > 0) c->config->c_max_neighbors = value; + break; case lldpctl_k_config_bond_slave_src_mac_type: config.c_bond_slave_src_mac_type = value; c->config->c_bond_slave_src_mac_type = value; diff --git a/src/lib/lldpctl.h b/src/lib/lldpctl.h index e78d67ef..9c0c3c5d 100644 --- a/src/lib/lldpctl.h +++ b/src/lib/lldpctl.h @@ -790,6 +790,7 @@ typedef enum { lldpctl_k_config_bond_slave_src_mac_type, /**< `(I,WO)` bond slave src mac type. */ lldpctl_k_config_lldp_portid_type, /**< `(I,WO)` LLDP PortID TLV Subtype */ lldpctl_k_config_lldp_agent_type, /**< `(I,WO)` LLDP agent type */ + lldpctl_k_config_max_neighbors, /**< `(I,WO)`Maximum number of neighbors per port. */ lldpctl_k_custom_tlvs = 5000, /**< `(AL)` custom TLVs */ lldpctl_k_custom_tlvs_clear, /** `(I,WO)` clear list of custom TLVs */ diff --git a/tests/lldpcli.conf b/tests/lldpcli.conf index a74a4575..30aacc1c 100644 --- a/tests/lldpcli.conf +++ b/tests/lldpcli.conf @@ -29,6 +29,7 @@ configure lldp portidsubtype local Batman configure lldp portidsubtype local Batman description Batman configure lldp tx-interval 30 configure lldp tx-hold 4 +configure lldp max-neighbors 16 configure lldp ports eth0 status tx-only configure lldp status rx-and-tx configure lldp custom-tlv oui 33,44,55 subtype 44 -- 2.39.5