]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpd: fix ttl range on ports
authorHangbin Liu <liuhangbin@gmail.com>
Mon, 2 Dec 2024 06:33:16 +0000 (14:33 +0800)
committerVincent Bernat <vincent@bernat.ch>
Sat, 7 Dec 2024 11:38:18 +0000 (12:38 +0100)
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 <feliu@redhat.com>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
src/client/display.c
src/daemon/protocols/edp.c
src/daemon/protocols/sonmp.c

index 6b23ec5b9e33e892f420d56a8192b88ff94218cf..978accf02eae0c5f89ef4009468cc84288ce8d1e 100644 (file)
@@ -21,6 +21,7 @@
 #include <ctype.h>
 #include <time.h>
 #include <errno.h>
+#include <sys/param.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/un.h>
@@ -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.");
index b55130b5480623a027d423396d436500b5509bb6..773d210653f6f9203bbe29532c91ac6468f78faa 100644 (file)
@@ -25,6 +25,7 @@
 #  include <errno.h>
 #  include <arpa/inet.h>
 #  include <fnmatch.h>
+#  include <sys/param.h>
 
 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) {
index ddc2771d75c1bee1dc1fcc8fbe5374f3aa5fb89b..59636262ed28d6bbeb18f72bba6f395fcd821f49 100644 (file)
@@ -24,6 +24,7 @@
 #  include <unistd.h>
 #  include <errno.h>
 #  include <arpa/inet.h>
+#  include <sys/param.h>
 
 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;