]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpd: Add tx_hold
authorroopa <roopa@cumulusnetworks.com>
Tue, 14 May 2013 12:43:00 +0000 (05:43 -0700)
committerVincent Bernat <bernat@luffy.cx>
Tue, 14 May 2013 20:52:10 +0000 (22:52 +0200)
This patch adds a new parameter tx_hold and also
changes txTTL calculation to be a multiple of
tx_hold and tx_interval

Also adds cli support to configure tx-hold:
#lldpcli configure lldp tx-hold 1

Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
src/client/conf.c
src/client/display.c
src/daemon/client.c
src/daemon/edp.c
src/daemon/lldpd.c
src/daemon/lldpd.h
src/daemon/sonmp.c
src/lib/atom-private.c
src/lib/lldpctl.h
src/lldpd-structs.h

index 27274c678220580588a8a2c5bb766c471ab56487..a7a7a512bcd7384523c90c24a45542657f183510 100644 (file)
@@ -45,6 +45,30 @@ cmd_txdelay(struct lldpctl_conn_t *conn, struct writer *w,
        return 1;
 }
 
+static int
+cmd_txhold(struct lldpctl_conn_t *conn, struct writer *w,
+    struct cmd_env *env, void *arg)
+{
+       log_debug("lldpctl", "set transmit hold");
+
+       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_tx_hold, cmdenv_get(env, "tx-hold")) == NULL) {
+               log_warnx("lldpctl", "unable to set transmit hold. %s",
+                   lldpctl_last_strerror(conn));
+               lldpctl_atom_dec_ref(config);
+               return 0;
+       }
+       log_info("lldpctl", "transmit hold set to new value %s", cmdenv_get(env, "tx-hold"));
+       lldpctl_atom_dec_ref(config);
+       return 1;
+}
+
 /**
  * Register `configure lldp` commands.
  */
@@ -65,6 +89,16 @@ register_commands_configure_lldp(struct cmd_node *configure)
                        NULL, cmd_store_env_value, "tx-interval"),
                NEWLINE, "Set LLDP transmit delay",
                NULL, cmd_txdelay, NULL);
+
+        commands_new(
+               commands_new(
+                       commands_new(configure_lldp,
+                           "tx-hold", "Set LLDP transmit hold",
+                           cmd_check_no_env, NULL, "ports"),
+                       NULL, "LLDP transmit hold in seconds",
+                       NULL, cmd_store_env_value, "tx-hold"),
+               NEWLINE, "Set LLDP transmit hold",
+               NULL, cmd_txhold, NULL);
 }
 
 /**
index 748169eea99c94c1529c742e5797ef3b739a299c..680eb06d4f83b87aeda6a9dea1069c11dd23a4c0 100644 (file)
@@ -709,6 +709,8 @@ display_configuration(lldpctl_conn_t *conn, struct writer *w)
 
        tag_datatag(w, "tx-delay", "Transmit delay",
            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, "rx-only", "Receive mode",
            lldpctl_atom_get_int(configuration, lldpctl_k_config_receiveonly)?
            "yes":"no");
index c986467a2500a7edd4409e50f36cb394d7528187..f92a34e8976ac71b4606fc397ef7085ac754418f 100644 (file)
@@ -62,6 +62,15 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type,
                log_debug("rpc", "client change transmit interval to %d",
                        config->c_tx_interval);
                cfg->g_config.c_tx_interval = config->c_tx_interval;
+               LOCAL_CHASSIS(cfg)->c_ttl = cfg->g_config.c_tx_interval *
+                       cfg->g_config.c_tx_hold;
+       }
+       if (config->c_tx_hold > 0) {
+               log_debug("rpc", "client change transmit hold to %d",
+                       config->c_tx_hold);
+               cfg->g_config.c_tx_hold = config->c_tx_hold;
+               LOCAL_CHASSIS(cfg)->c_ttl = cfg->g_config.c_tx_interval *
+                       cfg->g_config.c_tx_hold;
        }
        if (config->c_tx_interval < 0) {
                log_debug("rpc", "client asked for immediate retransmission");
index 326d1940d6a4947dc5d29bf5bd4e306fc08f1d65..71c0958e58444e78217cdbcb8b824a56e91c92d5 100644 (file)
@@ -309,7 +309,7 @@ edp_decode(struct lldpd *cfg, char *frame, int s,
                    hardware->h_ifname);
                goto malformed;
        }
-       chassis->c_ttl = LLDPD_TTL;
+       chassis->c_ttl = cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold;
        chassis->c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
        chassis->c_id_len = ETHER_ADDR_LEN;
        if ((chassis->c_id = (char *)malloc(ETHER_ADDR_LEN)) == NULL) {
index 17aa30d03dec89705547b4b06bc085cc02d86bc4..9957f039e7dda6563c085ed117c6a80ed38c07d6 100644 (file)
@@ -1401,6 +1401,7 @@ lldpd_main(int argc, char *argv[])
                cfg->g_config.c_paused = 1;
        cfg->g_config.c_receiveonly = receiveonly;
        cfg->g_config.c_tx_interval = LLDPD_TX_INTERVAL;
+       cfg->g_config.c_tx_hold = LLDPD_TX_HOLD;
        cfg->g_config.c_max_neighbors = LLDPD_MAX_NEIGHBORS;
 #ifdef ENABLE_LLDPMED
        cfg->g_config.c_enable_fast_start = enable_fast_start;
@@ -1450,7 +1451,7 @@ lldpd_main(int argc, char *argv[])
 #endif
 
        /* Set TTL */
-       lchassis->c_ttl = LLDPD_TTL;
+       lchassis->c_ttl = cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold;
 
        log_debug("main", "initialize protocols");
        cfg->g_protocols = protos;
index 2afb3b87105b3007ff87bd41c41608913c3ddadd..27bf0b6fd4df2ffabfb72d2bc138c24dd91434fb 100644 (file)
@@ -62,8 +62,9 @@ struct event_base;
 
 #define SYSFS_CLASS_NET "/sys/class/net/"
 #define SYSFS_CLASS_DMI "/sys/class/dmi/id/"
-#define LLDPD_TTL              120
 #define LLDPD_TX_INTERVAL      30
+#define LLDPD_TX_HOLD          4
+#define LLDPD_TTL              LLDPD_TX_INTERVAL * LLDPD_TX_HOLD
 #define LLDPD_TX_MSGDELAY      1
 #define LLDPD_MAX_NEIGHBORS    4
 #define LLDPD_PID_FILE         "/var/run/lldpd.pid"
index c756ced1bb04e026dfcdf8d9e6ad8219afb13003..af89f3225b5430dd3b1de847982f76402d446960 100644 (file)
@@ -364,7 +364,7 @@ sonmp_decode(struct lldpd *cfg, char *frame, int s,
                goto malformed;
        }
        TAILQ_INSERT_TAIL(&chassis->c_mgmt, mgmt, m_entries);
-       chassis->c_ttl = LLDPD_TTL;
+       chassis->c_ttl = cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold;
 
        port->p_id_subtype = LLDP_PORTID_SUBTYPE_LOCAL;
        if (asprintf(&port->p_id, "%02x-%02x-%02x",
index 2624ad2e168f4df0510312be0abcae8c8b2de72f..9a269d1f38d993dd00525e6cb9398e641c563dbb 100644 (file)
@@ -389,6 +389,8 @@ _lldpctl_atom_get_int_config(lldpctl_atom_t *atom, lldpctl_key_t key)
        case lldpctl_k_config_fast_start_interval:
                return c->config->c_tx_fast_interval;
 #endif
+       case lldpctl_k_config_tx_hold:
+               return c->config->c_tx_hold;
        default:
                return SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST);
        }
@@ -421,6 +423,10 @@ _lldpctl_atom_set_int_config(lldpctl_atom_t *atom, lldpctl_key_t key,
                config.c_tx_fast_interval = c->config->c_tx_fast_interval = value;
                break;
 #endif
+       case lldpctl_k_config_tx_hold:
+               config.c_tx_hold = value;
+               if (value > 0) c->config->c_tx_hold = value;
+               break;
        default:
                SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST);
                return NULL;
index 20af00a7f44ccfdeef1a0f72e4ae4e03e90e4731..c4efd997a65fa931851477dcb9deb815a95ddab3 100644 (file)
@@ -706,6 +706,7 @@ typedef enum {
        lldpctl_k_ageout_cnt,   /**< `(I)` ageout cnt. Only works for a local port. */
        lldpctl_k_insert_cnt,   /**< `(I)` insert cnt. Only works for a local port. */
        lldpctl_k_delete_cnt,   /**< `(I)` delete cnt. Only works for a local port. */
+       lldpctl_k_config_tx_hold, /**< `(I,WO)` Transmit hold interval. */
 } lldpctl_key_t;
 
 /**
index 1c47919d417c30e297960214660859ce409c18ec..69e9fffbd6ff7d751e167a6c4d875c6c2af3c24e 100644 (file)
@@ -331,6 +331,7 @@ struct lldpd_config {
        int c_tx_fast_init;     /* Num of lldpd lldppdu's for fast start */
        int c_tx_fast_interval; /* Time intr between sends during fast start */
 #endif
+       int c_tx_hold;          /* Transmit hold */
 };
 MARSHAL_BEGIN(lldpd_config)
 MARSHAL_STR(lldpd_config, c_mgmt_pattern)