From: Vincent Bernat Date: Sat, 2 Dec 2023 20:56:29 +0000 (+0100) Subject: daemon/lldpd: do not set interface description continuously X-Git-Tag: 1.0.18~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aa6e92977681a8816718c1b1e820b9b415d36a2a;p=thirdparty%2Flldpd.git daemon/lldpd: do not set interface description continuously Otherwise, we get a continuous flow of netlink updates. Fix #623 --- diff --git a/NEWS b/NEWS index 767a4020..2f13b0a0 100644 --- 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: diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index f3d94728..4859fb8e 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -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 diff --git a/src/lldpd-structs.h b/src/lldpd-structs.h index 5647c83f..8d192827 100644 --- a/src/lldpd-structs.h +++ b/src/lldpd-structs.h @@ -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 */