]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpd: limit tx ttl to 65535 672/head
authorHangbin Liu <liuhangbin@gmail.com>
Wed, 10 Jul 2024 07:49:32 +0000 (15:49 +0800)
committerHangbin Liu <liuhangbin@gmail.com>
Wed, 10 Jul 2024 08:16:23 +0000 (16:16 +0800)
Based on IEEE 802.1AB(2016) 9.2.5.22 txTTL:
  During normal operation, txTTL is set to whichever is the smaller of the
  values represented by Equation (1) and Equation (2):
      (msgTxInterval x msgTxHold) + 1   (1)
      65535                             (2)

Reported-by: Matt Lucius <malucius@redhat.com>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
src/daemon/client.c
src/daemon/lldpd.c

index d9d907fd74dcc168b030f501f0573d0ed4c28802..c4894ac112eadc38e70f7936293b1cb66b395228 100644 (file)
@@ -18,6 +18,7 @@
 #include "lldpd.h"
 #include "trace.h"
 
+#include <sys/param.h>
 #include <sys/utsname.h>
 
 static ssize_t
@@ -80,7 +81,7 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, void *i
                        cfg->g_config.c_tx_interval = config->c_tx_interval;
                        cfg->g_config.c_ttl =
                            cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold;
-                       cfg->g_config.c_ttl = (cfg->g_config.c_ttl + 999) / 1000;
+                       cfg->g_config.c_ttl = MIN((cfg->g_config.c_ttl + 999) / 1000, 65535);
                }
                levent_send_now(cfg);
        }
@@ -90,7 +91,7 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, void *i
                cfg->g_config.c_tx_hold = config->c_tx_hold;
                cfg->g_config.c_ttl =
                    cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold;
-               cfg->g_config.c_ttl = (cfg->g_config.c_ttl + 999) / 1000;
+               cfg->g_config.c_ttl = MIN((cfg->g_config.c_ttl + 999) / 1000, 65535);
        }
        if (CHANGED(c_max_neighbors) && config->c_max_neighbors > 0) {
                log_debug("rpc", "client change maximum neighbors to %d",
index 6b5721e2e336dda47d36332e98cb45e358d6587a..c3b67c6dfeb29234b91f7b432bceca31d6fa5862 100644 (file)
@@ -28,6 +28,7 @@
 #include <time.h>
 #include <libgen.h>
 #include <assert.h>
+#include <sys/param.h>
 #include <sys/utsname.h>
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -1932,7 +1933,7 @@ lldpd_main(int argc, char *argv[], char *envp[])
        cfg->g_config.c_tx_interval = LLDPD_TX_INTERVAL * 1000;
        cfg->g_config.c_tx_hold = LLDPD_TX_HOLD;
        cfg->g_config.c_ttl = cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold;
-       cfg->g_config.c_ttl = (cfg->g_config.c_ttl + 999) / 1000;
+       cfg->g_config.c_ttl = MIN((cfg->g_config.c_ttl + 999) / 1000, 65535);
        cfg->g_config.c_max_neighbors = LLDPD_MAX_NEIGHBORS;
 #ifdef ENABLE_LLDPMED
        cfg->g_config.c_enable_fast_start = enable_fast_start;