From 54c057d1190d4405d66e752dff789a01b8612f9b Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Mon, 2 Dec 2024 14:33:16 +0800 Subject: [PATCH] lldpd: fix ttl range on ports In the following fixed commit, I forgot to fix the ttl range for interfaces/ports. Fixes: a73e04f46ebe ("lldpd: limit tx ttl to 65535") Reported-by: Fei Liu Signed-off-by: Hangbin Liu --- src/client/display.c | 3 ++- src/daemon/protocols/edp.c | 3 ++- src/daemon/protocols/sonmp.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/client/display.c b/src/client/display.c index 6b23ec5b..978accf0 100644 --- a/src/client/display.c +++ b/src/client/display.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -599,7 +600,7 @@ display_local_ttl(struct writer *w, lldpctl_conn_t *conn, int details) tx_interval = lldpctl_atom_get_int(configuration, lldpctl_k_config_tx_interval_ms); - tx_interval = (tx_interval * tx_hold + 999) / 1000; + tx_interval = MIN((tx_interval * tx_hold + 999) / 1000, 65535); if (asprintf(&ttl, "%lu", tx_interval) == -1) { log_warnx("lldpctl", "not enough memory to build TTL."); diff --git a/src/daemon/protocols/edp.c b/src/daemon/protocols/edp.c index b55130b5..773d2106 100644 --- a/src/daemon/protocols/edp.c +++ b/src/daemon/protocols/edp.c @@ -25,6 +25,7 @@ # include # include # include +# include static int seq = 0; @@ -296,7 +297,7 @@ edp_decode(struct lldpd *cfg, char *frame, int s, struct lldpd_hardware *hardwar goto malformed; } port->p_ttl = cfg ? cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold : 0; - port->p_ttl = (port->p_ttl + 999) / 1000; + port->p_ttl = MIN((port->p_ttl + 999) / 1000, 65535); 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) { diff --git a/src/daemon/protocols/sonmp.c b/src/daemon/protocols/sonmp.c index ddc2771d..59636262 100644 --- a/src/daemon/protocols/sonmp.c +++ b/src/daemon/protocols/sonmp.c @@ -24,6 +24,7 @@ # include # include # include +# include static struct sonmp_chassis sonmp_chassis_types[] = { { 1, "unknown (via SONMP)" }, @@ -369,7 +370,7 @@ sonmp_decode(struct lldpd *cfg, char *frame, int s, struct lldpd_hardware *hardw TAILQ_INSERT_TAIL(&chassis->c_mgmt, mgmt, m_entries); port->p_ttl = cfg ? (cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold) : LLDPD_TTL; - port->p_ttl = (port->p_ttl + 999) / 1000; + port->p_ttl = MIN((port->p_ttl + 999) / 1000, 65535); port->p_id_subtype = LLDP_PORTID_SUBTYPE_LOCAL; -- 2.39.5