]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
handle lldpStatsRemTablesLastChangeTime correctly when items are removed 272/head
authorThomas Eliasson <thomas.eliasson@westermo.se>
Thu, 8 Mar 2018 14:10:39 +0000 (15:10 +0100)
committerJonas Johansson <jonas.johansson@westermo.se>
Mon, 12 Mar 2018 09:53:09 +0000 (10:53 +0100)
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 <jonas.johansson@westermo.se>
src/daemon/agent.c
src/lldpd-structs.c
src/lldpd-structs.h

index 3973183c0c5ee84382fee6b2ff85758b75895890..cc7701cb5a0f0f3f501a2dcdbb5bbd35ef0740f9 100644 (file)
@@ -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;
index 24b13527d35d5a92ecfd772b3058c74b5b7ed3ce..f7f310d3be47c08cbeea3cbe3f057f6cf90a0240 100644 (file)
@@ -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);
                }
index b44a43f34035389bc25e33ea7e50d7d1fb5c9bb3..4bfdd53d97d650b64a4e5aae536989f34a0ee4b2 100644 (file)
@@ -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 */