The counters _v1_sessions and _v2_sessions in the source file
agent/agent_trap.c keep track of how many trap sessions have been
created. These counters are not updated if a row is added to
snmpTargetAddrTable. The result is that all snmpTargetAddrTable
rows are ignored if no trap sessions have been created. Fix this
by removing the _v1_sessions and _v2_sessions counters.
---
 agent/agent_trap.c | 62 ++--------------------------------------------
 1 file changed, 2 insertions(+), 60 deletions(-)

diff --git a/agent/agent_trap.c b/agent/agent_trap.c
index d49c2dca495c..028990131be1 100644
--- a/agent/agent_trap.c
+++ b/agent/agent_trap.c
@@ -92,11 +92,6 @@ struct trap_sink {
 
 struct trap_sink *sinks = NULL;
 
-#ifndef NETSNMP_DISABLE_SNMPV1
-static int _v1_sessions = 0;
-#endif /* NETSNMP_DISABLE_SNMPV1 */
-static int _v2_sessions = 0;
-
 const oid       objid_enterprisetrap[] = { NETSNMP_NOTIFICATION_MIB };
 const oid       trap_version_id[] = { NETSNMP_SYSTEM_MIB };
 const int       enterprisetrap_len = OID_LENGTH(objid_enterprisetrap);
@@ -159,55 +154,6 @@ free_trap_session(struct trap_sink *sp)
     free(sp);
 }
 
-static void
-_trap_version_incr(int version)
-{
-    switch (version) {
-#ifndef NETSNMP_DISABLE_SNMPV1
-        case SNMP_VERSION_1:
-            ++_v1_sessions;
-            break;
-#endif
-#ifndef NETSNMP_DISABLE_SNMPV2C
-        case SNMP_VERSION_2c:
-#endif
-        case SNMP_VERSION_3:
-            ++_v2_sessions;
-            break;
-        default:
-            snmp_log(LOG_ERR, "unknown snmp version %d\n", version);
-    }
-    return;
-}
-
-static void
-_trap_version_decr(int version)
-{
-    switch (version) {
-#ifndef NETSNMP_DISABLE_SNMPV1
-        case SNMP_VERSION_1:
-            if (--_v1_sessions < 0) {
-                snmp_log(LOG_ERR,"v1 session count < 0! fixed.\n");
-                _v1_sessions = 0;
-            }
-            break;
-#endif
-#ifndef NETSNMP_DISABLE_SNMPV2C
-        case SNMP_VERSION_2c:
-#endif
-        case SNMP_VERSION_3:
-            if (--_v2_sessions < 0) {
-                snmp_log(LOG_ERR,"v2 session count < 0! fixed.\n");
-                _v2_sessions = 0;
-            }
-            break;
-        default:
-            snmp_log(LOG_ERR, "unknown snmp version %d\n", version);
-    }
-    return;
-}
-
-
 #ifndef NETSNMP_NO_TRAP_STATS
 static void
 _dump_trap_stats(netsnmp_session *sess)
@@ -285,8 +231,6 @@ netsnmp_add_notification_session(netsnmp_session * ss, int 
pdutype,
         sinks = new_sink;
     }
 
-    _trap_version_incr(version);
-
     return 1;
 }
 
@@ -338,7 +282,6 @@ remove_trap_session(netsnmp_session * ss)
             } else {
                 sinks = sp->next;
             }
-            _trap_version_decr(ss->version);
             /*
              * I don't believe you *really* want to close the session here;
              * it may still be in use for other purposes.  In particular this
@@ -490,7 +433,6 @@ snmpd_free_trapsinks(void)
     DEBUGMSGTL(("trap", "freeing trap sessions\n"));
     while (sp) {
         sinks = sinks->next;
-        _trap_version_decr(sp->version);
         free_trap_session(sp);
         sp = sinks;
     }
@@ -1025,11 +967,11 @@ netsnmp_send_traps(int trap, int specific,
         }
     }
 #ifndef NETSNMP_DISABLE_SNMPV1
-    if (template_v1pdu && _v1_sessions)
+    if (template_v1pdu)
         snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
                         SNMPD_CALLBACK_SEND_TRAP1, template_v1pdu);
 #endif
-    if (template_v2pdu && _v2_sessions)
+    if (template_v2pdu)
         snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
                         SNMPD_CALLBACK_SEND_TRAP2, template_v2pdu);
     snmp_free_pdu(template_v1pdu);
-- 
2.17.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to