]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
Merge pull request #272 from westermo/fix-snmp-remTablesLastChange
authorVincent Bernat <vincent@bernat.im>
Sat, 17 Mar 2018 16:06:38 +0000 (17:06 +0100)
committerGitHub <noreply@github.com>
Sat, 17 Mar 2018 16:06:38 +0000 (17:06 +0100)
handle lldpStatsRemTablesLastChangeTime correctly when items are removed

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 */