]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
daemon/lldpd: do not set interface description continuously
authorVincent Bernat <vincent@bernat.ch>
Sat, 2 Dec 2023 20:56:29 +0000 (21:56 +0100)
committerVincent Bernat <vincent@bernat.ch>
Sat, 2 Dec 2023 20:56:29 +0000 (21:56 +0100)
Otherwise, we get a continuous flow of netlink updates.

Fix #623

NEWS
src/daemon/lldpd.c
src/lldpd-structs.h

diff --git a/NEWS b/NEWS
index 767a4020d3989603e8e2bd2683a7953d0d5824ab..2f13b0a08900d7b93b6d1058c3a42f759ac59911 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ lldpd (1.0.18)
    + Remove support for building 802.3bt TLVs (broken).
  * Fix:
    + Fix memory leaks in EDP/FDP decoding when receiving some TLVs twice.
+   + Do not set interface description continuously.
 
 lldpd (1.0.17)
  * Fix:
index f3d94728f3bb2dd1fe280a689fb635130c293908..4859fb8e0fc4c796e1b5e9d2b29476ff6ce647a2 100644 (file)
@@ -294,6 +294,7 @@ lldpd_hardware_cleanup(struct lldpd *cfg, struct lldpd_hardware *hardware)
        free(hardware->h_lport_previous);
        free(hardware->h_lchassis_previous_id);
        free(hardware->h_lport_previous_id);
+       free(hardware->h_ifdescr_previous);
        lldpd_port_cleanup(&hardware->h_lport, 1);
        if (hardware->h_ops && hardware->h_ops->cleanup)
                hardware->h_ops->cleanup(cfg, hardware);
@@ -302,7 +303,7 @@ lldpd_hardware_cleanup(struct lldpd *cfg, struct lldpd_hardware *hardware)
 }
 
 static void
-lldpd_display_neighbors(struct lldpd *cfg)
+lldpd_ifdescr_neighbors(struct lldpd *cfg)
 {
        if (!cfg->g_config.c_set_ifdescr) return;
        struct lldpd_hardware *hardware;
@@ -317,19 +318,24 @@ lldpd_display_neighbors(struct lldpd *cfg)
                        neighbor = port->p_chassis->c_name;
                }
                if (neighbors == 0)
-                       priv_iface_description(hardware->h_ifname, "");
+                       description = strdup("");
                else if (neighbors == 1 && neighbor && *neighbor != '\0') {
-                       if (asprintf(&description, "%s", neighbor) != -1) {
-                               priv_iface_description(hardware->h_ifname, description);
-                               free(description);
+                       if (asprintf(&description, "%s", neighbor) == -1) {
+                               continue;
                        }
                } else {
                        if (asprintf(&description, "%d neighbor%s", neighbors,
-                               (neighbors > 1) ? "s" : "") != -1) {
-                               priv_iface_description(hardware->h_ifname, description);
-                               free(description);
+                               (neighbors > 1) ? "s" : "") == -1) {
+                               continue;
                        }
                }
+               if (hardware->h_ifdescr_previous == NULL ||
+                   strcmp(hardware->h_ifdescr_previous, description)) {
+                       priv_iface_description(hardware->h_ifname, description);
+                       free(hardware->h_ifdescr_previous);
+                       hardware->h_ifdescr_previous = description;
+               } else
+                       free(description);
        }
 }
 
@@ -352,7 +358,7 @@ lldpd_count_neighbors(struct lldpd *cfg)
        else
                setproctitle("%d neighbor%s.", neighbors, (neighbors > 1) ? "s" : "");
 #endif
-       lldpd_display_neighbors(cfg);
+       lldpd_ifdescr_neighbors(cfg);
 }
 
 static void
index 5647c83f2bdb8774e48c80f80f872f79407123ed..8d192827fadcd9139ed5a24ca79a4de87ca1e976 100644 (file)
@@ -496,6 +496,7 @@ struct lldpd_hardware {
        u_int8_t h_lport_previous_id_subtype;
        char *h_lport_previous_id;
        int h_lport_previous_id_len;
+       char *h_ifdescr_previous;
 
        struct lldpd_port h_lport;         /* Port attached to this hardware port */
        TAILQ_HEAD(, lldpd_port) h_rports; /* Remote ports */