From: Thomas Eliasson Date: Thu, 8 Mar 2018 14:10:39 +0000 (+0100) Subject: handle lldpStatsRemTablesLastChangeTime correctly when items are removed X-Git-Tag: 1.0.0~2^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c79467f68440122837d1648d0ad52f29ff48cfcc;p=thirdparty%2Flldpd.git handle lldpStatsRemTablesLastChangeTime correctly when items are removed When a port is removed, the time has to be updated. The last removal time is registered per local port, and this timestamp will be used as lldpStatsRemTablesLastChangeTime if it is the latest timestamp. Also, the lldpStatsRemTablesDeletes is always increased when an entry in the table is deleted. Signed-off-by: Jonas Johansson --- diff --git a/src/daemon/agent.c b/src/daemon/agent.c index 3973183c..cc7701cb 100644 --- a/src/daemon/agent.c +++ b/src/daemon/agent.c @@ -619,11 +619,16 @@ agent_h_scalars(struct variable *vp, oid *name, size_t *length, return (u_char *)&long_ret; case LLDP_SNMP_LASTUPDATE: long_ret = 0; - TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) - TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { - if (SMART_HIDDEN(port)) continue; - if (port->p_lastchange > long_ret) - long_ret = port->p_lastchange; + TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { + /* Check if the last removal of a remote port on this local port was the last change. */ + if (hardware->h_lport.p_lastremove > long_ret) + long_ret = hardware->h_lport.p_lastremove; + /* Check if any change on the existing remote ports was the last change. */ + TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { + if (SMART_HIDDEN(port)) continue; + if (port->p_lastchange > long_ret) + long_ret = port->p_lastchange; + } } if (long_ret) long_ret = (long_ret - starttime.tv_sec) * 100; diff --git a/src/lldpd-structs.c b/src/lldpd-structs.c index 24b13527..f7f310d3 100644 --- a/src/lldpd-structs.c +++ b/src/lldpd-structs.c @@ -176,7 +176,6 @@ lldpd_remote_cleanup(struct lldpd_hardware *hardware, if (!all && expire && (now >= port->p_lastupdate + port->p_ttl)) { hardware->h_ageout_cnt++; - hardware->h_delete_cnt++; del = 1; } if (del) { @@ -186,6 +185,10 @@ lldpd_remote_cleanup(struct lldpd_hardware *hardware, * real list. It is only needed to be called when we * don't delete the entire list. */ if (!all) TAILQ_REMOVE(&hardware->h_rports, port, p_entries); + + hardware->h_delete_cnt++; + /* Register last removal to be able to report lldpStatsRemTablesLastChangeTime */ + hardware->h_lport.p_lastremove = time(NULL); lldpd_port_cleanup(port, 1); free(port); } diff --git a/src/lldpd-structs.h b/src/lldpd-structs.h index b44a43f3..4bfdd53d 100644 --- a/src/lldpd-structs.h +++ b/src/lldpd-structs.h @@ -243,6 +243,8 @@ struct lldpd_port { struct lldpd_chassis *p_chassis; /* Attached chassis */ time_t p_lastchange; /* Time of last change of values */ time_t p_lastupdate; /* Time of last update received */ + time_t p_lastremove; /* Time of last removal of a remote port. Used for local ports only + * Used for deciding lldpStatsRemTablesLastChangeTime */ struct lldpd_frame *p_lastframe; /* Frame received during last update */ u_int8_t p_protocol; /* Protocol used to get this port */ u_int8_t p_hidden_in:1; /* Considered as hidden for reception */