Hello.
I have a rewrite of sysORTable that have the following advantages and
disadvantages:
Advantages:
* Supports reregistering of sysORTable entries from subagents
* Supports unregistering of sysORTable entries
* Defines a public interface
* Uses a container handler for the sysORTable
Disadvantages:
* The sysORTable data is part of the core agent so the size of the
agent for embedded use has grown slightly
* Uses a privately implemented double-linked list where the nodes
contain both container data and user data as opposed to a
pointer to user data.
I had the following requirements on the data structure that led
me to this solution:
* entry addresses should be stable
* O(1) inserts and erases in the list given a pointer to a
data item.
There are also some secondary features:
* The sysORIndex values are allocated sequentially in the range
and tracked so that there will be no reuse of indices before the
value wraps.
I do not know if this is a good idea but I thought it would be
nice if the entry index stayed the same regardless of any other
activity in the table.
I also have an outstanding question - should I add the registration
interface to net-snmp-agent-includes.h?
As a silly side effect of the patch it is now possible to have
sysORTable as a dl_open module...
Another problem of this patch is that it fails to follow the rules set
out in 'MIB Module ReWrites' since the structural changes in the agent
mmeans that the old implementation can't be linked to the agent any more
(symbols defined at multiple places)
/MF
Index: README.agent-mibs
===================================================================
--- README.agent-mibs (revision 16870)
+++ README.agent-mibs (working copy)
@@ -40,6 +40,7 @@
G scalar group helper
W watched scalar
M mfd
+ C container table
Platform Keys
------------------
@@ -65,7 +66,7 @@
SNMPv2-MIB
system.?.0 A 5.5 W mibII/system_mib.c
.sysORLastChange.0 A 5.5 W mibII/sysORTable.c
- sysORTable A 3.4 O mibII/sysORTable.c
+ sysORTable A 5.5 C mibII/sysORTable.c
snmp.*.0 A 5.5 G mibII/snmp_mib.c
setSerialNo.0 A 5.0 W mibII/setSerialNo.c
Index: include/net-snmp/agent/agent_sysORTable.h
===================================================================
--- include/net-snmp/agent/agent_sysORTable.h (revision 0)
+++ include/net-snmp/agent/agent_sysORTable.h (revision 0)
@@ -0,0 +1,25 @@
+#ifndef AGENT_SYSORTABLE_H
+#define AGENT_SYSORTABLE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct sysORTable;
+
+extern void netsnmp_sysORTable_foreach(void (*)(const struct sysORTable*,
+ void*),
+ void*);
+
+extern int register_sysORTable(oid *, size_t, const char *);
+extern int unregister_sysORTable(oid *, size_t);
+extern int register_sysORTable_sess(oid *, size_t, const char *,
+ netsnmp_session *);
+extern int unregister_sysORTable_sess(oid *, size_t, netsnmp_session *);
+extern void unregister_sysORTable_by_session(netsnmp_session *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* AGENT_SYSORTABLE_H */
Index: include/net-snmp/agent/sysORTable.h
===================================================================
--- include/net-snmp/agent/sysORTable.h (revision 0)
+++ include/net-snmp/agent/sysORTable.h (revision 0)
@@ -0,0 +1,54 @@
+#ifndef NETSNMP_SYSORTABLE_H
+#define NETSNMP_SYSORTABLE_H
+
+struct sysORTable {
+ const char *OR_descr;
+ oid *OR_oid;
+ size_t OR_oidlen;
+ netsnmp_session *OR_sess;
+ u_long OR_uptime;
+};
+
+struct register_sysOR_parameters {
+ const char *descr;
+ oid *name;
+ size_t namelen;
+};
+
+#define SYS_ORTABLE_REGISTERED_OK 0
+#define SYS_ORTABLE_REGISTRATION_FAILED -1
+#define SYS_ORTABLE_UNREGISTERED_OK 0
+#define SYS_ORTABLE_NO_SUCH_REGISTRATION -1
+
+#include <net-snmp/agent/agent_callbacks.h>
+
+#define REGISTER_SYSOR_TABLE(theoid, len, descr) \
+ do { \
+ struct sysORTable t = { \
+ descr, theoid, len, NULL, 0 }; \
+ snmp_call_callbacks(SNMP_CALLBACK_APPLICATION, \
+ SNMPD_CALLBACK_REQ_REG_SYSOR, &t); \
+ } while(0);
+
+#define REGISTER_SYSOR_ENTRY(theoid, descr) \
+ REGISTER_SYSOR_TABLE(theoid, sizeof(theoid) / sizeof(oid), \
+ descr)
+
+#define UNREGISTER_SYSOR_TABLE(theoid, len) \
+ do { \
+ struct sysORTable t = { \
+ NULL, theoid, len, NULL, 0 }; \
+ snmp_call_callbacks(SNMP_CALLBACK_APPLICATION, \
+ SNMPD_CALLBACK_REQ_UNREG_SYSOR, &t); \
+ } while(0);
+
+#define UNREGISTER_SYSOR_ENTRY(theoid) \
+ UNREGISTER_SYSOR_TABLE(theoid, sizeof(theoid) / sizeof(oid))
+
+#define UNREGISTER_SYSOR_SESS(sess) \
+ snmp_call_callbacks(SNMP_CALLBACK_APPLICATION, \
+ SNMPD_CALLBACK_REQ_UNREG_SYSOR_SESS, \
+ sess);
+
+
+#endif /* NETSNMP_SYSORTABLE_H */
Index: agent/Makefile.in
===================================================================
--- agent/Makefile.in (revision 16870)
+++ agent/Makefile.in (working copy)
@@ -25,6 +25,7 @@
INCLUDESUBDIRHEADERS=agent_read_config.h \
agent_registry.h \
agent_index.h \
+ agent_sysORTable.h \
agent_trap.h \
auto_nlist.h \
ds_agent.h \
@@ -34,7 +35,8 @@
agent_handler.h \
net-snmp-agent-includes.h \
mib_modules.h \
- agent_callbacks.h
+ agent_callbacks.h \
+ sysORTable.h
INSTALLBUILTSUBDIRHEADERS=../include/net-snmp/agent/mib_module_config.h \
../include/net-snmp/agent/agent_module_config.h \
@@ -60,6 +62,7 @@
agent_index.h \
agent_read_config.h \
agent_registry.h \
+ agent_sysORTable.h \
agent_trap.h \
auto_nlist.h \
ds_agent.h \
@@ -104,11 +107,11 @@
# libnetsnmpagent objects
LIBAGENTOBJS=snmp_agent.o snmp_vars.o agent_read_config.o \
- agent_registry.o agent_index.o agent_trap.o kernel.o \
- agent_handler.o $(agentgroup_list_o) @OTHERAGENTLIBOBJS@
+ agent_registry.o agent_index.o agent_sysORTable.o agent_trap.o \
+ kernel.o agent_handler.o $(agentgroup_list_o) @OTHERAGENTLIBOBJS@
LLIBAGENTOBJS=snmp_agent.lo snmp_vars.lo agent_read_config.lo \
- agent_registry.lo agent_index.lo agent_trap.lo kernel.lo \
- agent_handler.lo $(agentgroup_list_lo) @OTHERAGENTLIBLOBJS@
+ agent_registry.lo agent_index.lo agent_sysORTable.lo agent_trap.lo \
+ kernel.lo agent_handler.lo $(agentgroup_list_lo) @OTHERAGENTLIBLOBJS@
# The agent objects.
AGENTOBJS=snmpd.o @other_agentobjs@
Index: agent/mibgroup/agentx/master.h
===================================================================
--- agent/mibgroup/agentx/master.h (revision 16870)
+++ agent/mibgroup/agentx/master.h (working copy)
@@ -7,7 +7,6 @@
config_require(agentx/client)
config_require(agentx/master_admin)
config_require(agentx/agentx_config)
-config_require(mibII/sysORTable)
void init_master(void);
void real_init_master(void);
Index: agent/mibgroup/agentx/master_admin.c
===================================================================
--- agent/mibgroup/agentx/master_admin.c (revision 16870)
+++ agent/mibgroup/agentx/master_admin.c (working copy)
@@ -45,7 +45,7 @@
#include <net-snmp/agent/agent_index.h>
#include <net-snmp/agent/agent_trap.h>
#include <net-snmp/agent/agent_callbacks.h>
-#include "mibII/sysORTable.h"
+#include <net-snmp/agent/agent_sysORTable.h>
#include "master.h"
extern struct timeval starttime;
@@ -149,9 +149,7 @@
unregister_mibs_by_session(session);
unregister_index_by_session(session);
- snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
- SNMPD_CALLBACK_REQ_UNREG_SYSOR_SESS,
- (void*)session);
+ unregister_sysORTable_by_session(session);
SNMP_FREE(session->myvoid);
return AGENTX_ERR_NOERROR;
}
@@ -163,9 +161,7 @@
if (sp->sessid == sessid) {
unregister_mibs_by_session(sp);
unregister_index_by_session(sp);
- snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
- SNMPD_CALLBACK_REQ_UNREG_SYSOR_SESS,
- (void*)sp);
+ unregister_sysORTable_by_session(sp);
*prevNext = sp->next;
@@ -380,20 +376,17 @@
add_agent_caps_list(netsnmp_session * session, netsnmp_pdu *pdu)
{
netsnmp_session *sp;
- struct sysORTable parms;
+ char* description;
sp = find_agentx_session(session, pdu->sessid);
if (sp == NULL)
return AGENTX_ERR_NOT_OPEN;
- parms.OR_oid = pdu->variables->name;
- parms.OR_oidlen = pdu->variables->name_length;
- parms.OR_descr = netsnmp_strdup_and_null(pdu->variables->val.string,
- pdu->variables->val_len);
- parms.OR_sess = sp;
- snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
- SNMPD_CALLBACK_REQ_REG_SYSOR, (void*)&parms);
- free(parms.OR_descr);
+ description = netsnmp_strdup_and_null(pdu->variables->val.string,
+ pdu->variables->val_len);
+ register_sysORTable_sess(pdu->variables->name, pdu->variables->name_length,
+ description, sp);
+ free(description);
return AGENTX_ERR_NOERROR;
}
@@ -401,22 +394,18 @@
remove_agent_caps_list(netsnmp_session * session, netsnmp_pdu *pdu)
{
netsnmp_session *sp;
- struct sysORTable parms;
+ int rc;
sp = find_agentx_session(session, pdu->sessid);
if (sp == NULL)
return AGENTX_ERR_NOT_OPEN;
- parms.OR_oid = pdu->variables->name;
- parms.OR_oidlen = pdu->variables->name_length;
- parms.OR_sess = sp;
- snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
- SNMPD_CALLBACK_REQ_UNREG_SYSOR, (void*)&parms);
- /*
- * no easy way to get an error code...
- * if (rc < 0)
- * return AGENTX_ERR_UNKNOWN_AGENTCAPS;
- */
+ rc = unregister_sysORTable_sess(pdu->variables->name,
+ pdu->variables->name_length, sp);
+
+ if (rc < 0)
+ return AGENTX_ERR_UNKNOWN_AGENTCAPS;
+
return AGENTX_ERR_NOERROR;
}
Index: agent/mibgroup/agentx/subagent.c
===================================================================
--- agent/mibgroup/agentx/subagent.c (revision 16870)
+++ agent/mibgroup/agentx/subagent.c (working copy)
@@ -46,9 +46,7 @@
#include "agentx/agentx_config.h"
#include <net-snmp/agent/agent_callbacks.h>
#include <net-snmp/agent/agent_trap.h>
-#ifdef USING_MIBII_SYSORTABLE_MODULE
-#include "mibII/sysORTable.h"
-#endif
+#include <net-snmp/agent/sysORTable.h>
#include "subagent.h"
@@ -638,7 +636,6 @@
}
-#ifdef USING_MIBII_SYSORTABLE_MODULE
int
agentx_sysOR_callback(int majorID, int minorID, void *serverarg,
void *clientarg)
@@ -656,7 +653,6 @@
reg_parms->name,
reg_parms->namelen);
}
-#endif
static int
@@ -695,14 +691,12 @@
snmp_register_callback(SNMP_CALLBACK_APPLICATION,
SNMPD_CALLBACK_UNREGISTER_OID,
agentx_registration_callback, s);
-#ifdef USING_MIBII_SYSORTABLE_MODULE
snmp_register_callback(SNMP_CALLBACK_APPLICATION,
SNMPD_CALLBACK_REG_SYSOR,
agentx_sysOR_callback, s);
snmp_register_callback(SNMP_CALLBACK_APPLICATION,
SNMPD_CALLBACK_UNREG_SYSOR,
agentx_sysOR_callback, s);
-#endif
}
/*
@@ -722,15 +716,12 @@
snmp_unregister_callback(SNMP_CALLBACK_APPLICATION,
SNMPD_CALLBACK_UNREGISTER_OID,
agentx_registration_callback, ss, 1);
-#ifdef USING_MIBII_SYSORTABLE_MODULE
snmp_unregister_callback(SNMP_CALLBACK_APPLICATION,
SNMPD_CALLBACK_REG_SYSOR,
agentx_sysOR_callback, ss, 1);
snmp_unregister_callback(SNMP_CALLBACK_APPLICATION,
SNMPD_CALLBACK_UNREG_SYSOR,
agentx_sysOR_callback, ss, 1);
-#endif
-
}
/*
@@ -847,6 +838,11 @@
return 0;
}
+static void
+agentx_reopen_sysORTable(const struct sysORTable* data, void* v)
+{
+ agentx_sysOR_callback(0, SNMPD_CALLBACK_REG_SYSOR, data, v);
+}
/*
* Alarm callback function to open a session to the master agent. If a
@@ -875,6 +871,11 @@
register_mib_reattach();
/*
+ * Reregister all our sysOREntries
+ */
+ netsnmp_sysORTable_foreach(&agentx_reopen_sysORTable, main_session);
+
+ /*
* Register a ping alarm (if need be).
*/
subagent_register_ping_alarm(0, 0, 0, main_session);
Index: agent/mibgroup/mibII/udpTable.c
===================================================================
--- agent/mibgroup/mibII/udpTable.c (revision 16870)
+++ agent/mibgroup/mibII/udpTable.c (working copy)
@@ -33,7 +33,6 @@
#endif
#include "udp.h"
#include "udpTable.h"
-#include "sysORTable.h"
#ifdef hpux11
#define UDPTABLE_ENTRY_TYPE mib_udpLsnEnt
Index: agent/mibgroup/mibII/ip.c
===================================================================
--- agent/mibgroup/mibII/ip.c (revision 16870)
+++ agent/mibgroup/mibII/ip.c (working copy)
@@ -19,12 +19,12 @@
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <net-snmp/agent/auto_nlist.h>
+#include <net-snmp/agent/sysORTable.h>
#include "util_funcs.h"
#include "ip.h"
#include "ipAddr.h"
#include "interfaces.h"
-#include "sysORTable.h"
#ifndef MIB_STATS_CACHE_TIMEOUT
#define MIB_STATS_CACHE_TIMEOUT 5
Index: agent/mibgroup/mibII/vacm_vars.c
===================================================================
--- agent/mibgroup/mibII/vacm_vars.c (revision 16870)
+++ agent/mibgroup/mibII/vacm_vars.c (working copy)
@@ -48,10 +48,10 @@
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <net-snmp/agent/agent_callbacks.h>
+#include <net-snmp/agent/sysORTable.h>
#include "vacm_vars.h"
#include "util_funcs.h"
-#ifdef USING_MIBII_SYSORTABLE_MODULE
#if TIME_WITH_SYS_TIME
# ifdef WIN32
# include <sys/timeb.h>
@@ -66,17 +66,14 @@
# include <time.h>
# endif
#endif
-#include "sysORTable.h"
-#endif
+
static unsigned int vacmViewSpinLock = 0;
void
init_vacm_vars(void)
{
-#ifdef USING_MIBII_SYSORTABLE_MODULE
- static oid reg[] = { SNMP_OID_SNMPMODULES, 16, 2, 2, 1 };
-#endif
+ oid reg[] = { SNMP_OID_SNMPMODULES, 16, 2, 2, 1 };
#define PRIVRW (NETSNMP_SNMPV2ANY | 0x5000)
@@ -126,11 +123,7 @@
vacm_access_oid);
REGISTER_MIB("mibII/vacm:view", vacm_view, variable3, vacm_view_oid);
-#ifdef USING_MIBII_SYSORTABLE_MODULE
- register_sysORTable(reg, 10,
- "View-based Access Control Model for SNMP.");
-#endif
-
+ REGISTER_SYSOR_ENTRY(reg, "View-based Access Control Model for SNMP.");
}
Index: agent/mibgroup/mibII/interfaces.c
===================================================================
--- agent/mibgroup/mibII/interfaces.c (revision 16870)
+++ agent/mibgroup/mibII/interfaces.c (working copy)
@@ -197,12 +197,12 @@
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <net-snmp/agent/auto_nlist.h>
+#include <net-snmp/agent/sysORTable.h>
#include <net-snmp/data_access/interface.h>
#include "interfaces.h"
#include "struct.h"
#include "util_funcs.h"
-#include "sysORTable.h"
/* if you want caching enabled for speed retrival purposes, set this to 5?*/
#define MINLOADFREQ 0 /* min reload frequency in seconds */
Index: agent/mibgroup/mibII/sysORTable.c
===================================================================
--- agent/mibgroup/mibII/sysORTable.c (revision 16870)
+++ agent/mibgroup/mibII/sysORTable.c (working copy)
@@ -1,332 +1,289 @@
-/*
- * Template MIB group implementation - sysORTable.c
- *
- */
#include <net-snmp/net-snmp-config.h>
-#if HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-#if HAVE_STRING_H
-#include <string.h>
-#else
-#include <strings.h>
-#endif
-
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
-#include <net-snmp/agent/agent_callbacks.h>
+#include <net-snmp/agent/net-snmp-agent-includes.h>
+#include <net-snmp/agent/table_container.h>
+#include <net-snmp/agent/agent_sysORTable.h>
+#include <net-snmp/agent/sysORTable.h>
-#include "struct.h"
-#include "util_funcs.h"
#include "sysORTable.h"
-#include "snmpd.h"
-#ifdef USING_AGENTX_SUBAGENT_MODULE
-#include "agentx/subagent.h"
-#include "agentx/client.h"
-#endif
+/** Typical data structure for a row entry */
+typedef struct sysORTable_entry_s {
+ netsnmp_index oid_index;
+ oid sysORIndex;
+ const struct sysORTable* data;
+} sysORTable_entry;
-
-static int
-_register_sysOR_callback(int majorID, int minorID,
- void *serverarg, void *clientarg);
-static int
-_unregister_sysOR_callback(int majorID, int minorID,
- void *serverarg, void *clientarg);
-static int
-_unregister_sysOR_by_session_callback(int majorID, int minorID,
- void *serverarg, void *clientarg);
-
-static u_long sysORLastChange;
-static struct sysORTable *table = NULL;
-static int numEntries = 0;
-
/*
- * define the structure we're going to ask the agent to register our
- * information at
+ * column number definitions for table sysORTable
*/
-struct variable1 sysORTable_variables[] = {
- {SYSORTABLEID, ASN_OBJECT_ID, RONLY, var_sysORTable, 1, {2}},
- {SYSORTABLEDESCR, ASN_OCTET_STR, RONLY, var_sysORTable, 1, {3}},
- {SYSORTABLEUPTIME, ASN_TIMETICKS, RONLY, var_sysORTable, 1, {4}}
-};
+#define COLUMN_SYSORINDEX 1
+#define COLUMN_SYSORID 2
+#define COLUMN_SYSORDESCR 3
+#define COLUMN_SYSORUPTIME 4
-/*
- * Define the OID pointer to the top of the mib tree that we're
- * registering underneath
- */
-oid sysORTable_variables_oid[] = { SNMP_OID_MIB2, 1, 9, 1 };
-#ifdef USING_MIBII_SYSTEM_MIB_MODULE
-extern oid system_module_oid[];
-extern int system_module_oid_len;
-extern int system_module_count;
-#endif
+static netsnmp_container *table = NULL;
+static u_long sysORLastChange;
+static oid sysORNextIndex = 1;
-void
-init_sysORTable(void)
+/** create a new row in the table */
+static void
+register_foreach(const struct sysORTable* data, void* dummy)
{
- oid sysORLastChange_oid[] = { SNMP_OID_MIB2, 1, 8 };
- /*
- * register ourselves with the agent to handle our mib tree
- */
+ sysORTable_entry *entry;
- netsnmp_register_watched_scalar(
- netsnmp_create_handler_registration(
- "mibII/sysORLastChange", NULL,
- sysORLastChange_oid, OID_LENGTH(sysORLastChange_oid),
- HANDLER_CAN_RONLY),
- netsnmp_create_watcher_info(
- &sysORLastChange, sizeof(u_long),
- ASN_TIMETICKS, WATCHER_FIXED_SIZE));
+ sysORLastChange = data->OR_uptime;
-#ifdef USING_AGENTX_SUBAGENT_MODULE
- if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE) == MASTER_AGENT)
- (void) register_mib_priority("mibII/sysORTable",
- (struct variable *)
- sysORTable_variables,
- sizeof(struct variable1),
- sizeof(sysORTable_variables) /
- sizeof(struct variable1),
- sysORTable_variables_oid,
- sizeof(sysORTable_variables_oid) /
- sizeof(oid), 1);
- else
-#endif
- REGISTER_MIB("mibII/sysORTable", sysORTable_variables, variable1,
- sysORTable_variables_oid);
+ entry = SNMP_MALLOC_TYPEDEF(sysORTable_entry);
+ if (!entry) {
+ snmp_log(LOG_ERR,
+ "could not allocate storage, sysORTable is inconsistent\n");
+ } else {
+ const oid firstNext = sysORNextIndex;
+ netsnmp_iterator* it = CONTAINER_ITERATOR(table);
- snmp_register_callback(SNMP_CALLBACK_APPLICATION,
- SNMPD_CALLBACK_REQ_REG_SYSOR,
- _register_sysOR_callback, NULL);
- snmp_register_callback(SNMP_CALLBACK_APPLICATION,
- SNMPD_CALLBACK_REQ_UNREG_SYSOR,
- _unregister_sysOR_callback, NULL);
- snmp_register_callback(SNMP_CALLBACK_APPLICATION,
- SNMPD_CALLBACK_REQ_UNREG_SYSOR_SESS,
- _unregister_sysOR_by_session_callback, NULL);
+ do {
+ const sysORTable_entry* value;
+ const oid cur = sysORNextIndex;
- sysORLastChange = netsnmp_get_agent_uptime();
+ if (sysORNextIndex == SNMP_MIN(MAX_SUBID, 2147483647UL))
+ sysORNextIndex = 1;
+ else
+ ++sysORNextIndex;
-#ifdef USING_MIBII_SYSTEM_MIB_MODULE
- if (++system_module_count == 3)
- REGISTER_SYSOR_TABLE(system_module_oid, system_module_oid_len,
- "The MIB module for SNMPv2 entities");
-#endif
-}
+ for (value = it->curr(it);
+ value && value->sysORIndex < cur;
+ value = ITERATOR_NEXT(it)) {
+ }
- /*********************
- *
- * System specific implementation functions
- *
- *********************/
+ if (value && value->sysORIndex == cur) {
+ if (sysORNextIndex < cur)
+ it->reset(it);
+ } else {
+ entry->sysORIndex = cur;
+ break;
+ }
+ } while (firstNext != sysORNextIndex);
-u_char *
-var_sysORTable(struct variable *vp,
- oid * name,
- size_t * length,
- int exact, size_t * var_len, WriteMethod ** write_method)
-{
- unsigned long i = 0;
- static unsigned long ret;
- struct sysORTable *ptr = table;
+ ITERATOR_RELEASE(it);
- if (header_simple_table
- (vp, name, length, exact, var_len, write_method, numEntries))
- return NULL;
+ if(firstNext == sysORNextIndex) {
+ snmp_log(LOG_ERR, "Failed to locate a free index in sysORTable\n");
+ free(entry);
+ } else {
+ entry->data = data;
+ entry->oid_index.len = 1;
+ entry->oid_index.oids = &entry->sysORIndex;
- for (i = 1; ptr != NULL && i < name[*length - 1]; ptr = ptr->next, i++) {
- DEBUGMSGTL(("mibII/sysORTable", "sysORTable -- %lu != %lu\n",
- i, name[*length - 1]));
+ CONTAINER_INSERT(table, entry);
+ }
}
- if (ptr == NULL) {
- DEBUGMSGTL(("mibII/sysORTable", "sysORTable -- no match: %lu\n",
- i));
- return NULL;
- }
- DEBUGMSGTL(("mibII/sysORTable", "sysORTable -- match: %lu\n", i));
+}
- switch (vp->magic) {
- case SYSORTABLEID:
- *var_len = ptr->OR_oidlen * sizeof(ptr->OR_oid[0]);
- return (u_char *) ptr->OR_oid;
+static int
+register_cb(int major, int minor, void* serv, void* client)
+{
+ DEBUGMSGTL(("mibII/sysORTable/register_cb",
+ "register_cb(%d, %d, %p, %p)\n", major, minor, serv, client));
+ register_foreach((struct sysORTable*)serv, NULL);
+ return SNMP_ERR_NOERROR;
+}
- case SYSORTABLEDESCR:
- *var_len = strlen(ptr->OR_descr);
- return (u_char *) ptr->OR_descr;
+/** remove a row from the table */
+static int
+unregister_cb(int major, int minor, void* serv, void* client)
+{
+ sysORTable_entry *value;
+ netsnmp_iterator* it = CONTAINER_ITERATOR(table);
- case SYSORTABLEUPTIME:
- ret = netsnmp_timeval_uptime(&ptr->OR_uptime);
- return (u_char *) & ret;
+ DEBUGMSGTL(("mibII/sysORTable/unregister_cb",
+ "unregister_cb(%d, %d, %p, %p)\n", major, minor, serv, client));
+ sysORLastChange = ((struct sysORTable*)(serv))->OR_uptime;
- default:
- DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_sysORTable\n",
- vp->magic));
+ while ((value = ITERATOR_NEXT(it)) && value->data != serv);
+ ITERATOR_RELEASE(it);
+ if(value) {
+ CONTAINER_REMOVE(table, value);
+ free(value);
}
- return NULL;
+ return SNMP_ERR_NOERROR;
}
-
-int
-register_sysORTable_sess(oid * oidin,
- size_t oidlen,
- const char *descr, netsnmp_session * ss)
+/** handles requests for the sysORTable table */
+static int
+sysORTable_handler(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests)
{
- struct sysORTable *ptr, **nptr;
- struct register_sysOR_parameters reg_sysOR_parms;
+ netsnmp_request_info *request;
- DEBUGMSGTL(("mibII/sysORTable", "sysORTable registering: "));
- DEBUGMSGOID(("mibII/sysORTable", oidin, oidlen));
- DEBUGMSG(("mibII/sysORTable", "\n"));
+ DEBUGMSGTL(("mibII/sysORTable/sysORTable_handler",
+ "sysORTable_handler called\n"));
- ptr = (struct sysORTable *) malloc(sizeof(struct sysORTable));
- if (ptr == NULL) {
- return SYS_ORTABLE_REGISTRATION_FAILED;
+ if (reqinfo->mode != MODE_GET) {
+ snmp_log(LOG_ERR,
+ "Got unexpected operation for sysORTable\n");
+ return SNMP_ERR_GENERR;
}
- ptr->OR_descr = (char *) strdup(descr);
- if (ptr->OR_descr == NULL) {
- free(ptr);
- return SYS_ORTABLE_REGISTRATION_FAILED;
- }
- ptr->OR_oidlen = oidlen;
- ptr->OR_oid = (oid *) malloc(sizeof(oid) * oidlen);
- if (ptr->OR_oid == NULL) {
- free(ptr->OR_descr);
- free(ptr);
- return SYS_ORTABLE_REGISTRATION_FAILED;
- }
- memcpy(ptr->OR_oid, oidin, sizeof(oid) * oidlen);
- gettimeofday(&(ptr->OR_uptime), NULL);
- sysORLastChange = netsnmp_get_agent_uptime();
- ptr->OR_sess = ss;
- ptr->next = NULL;
- numEntries++;
- /* add this entry to the end of the chained list */
- nptr = &table;
- while (*nptr != NULL)
- nptr = &((*nptr)->next);
- *nptr = ptr;
+ /*
+ * Read-support (also covers GetNext requests)
+ */
+ request = requests;
+ while(request && request->processed)
+ request = request->next;
+ while(request) {
+ sysORTable_entry *table_entry;
+ netsnmp_table_request_info *table_info;
- reg_sysOR_parms.name = oidin;
- reg_sysOR_parms.namelen = oidlen;
- reg_sysOR_parms.descr = descr;
- snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
- SNMPD_CALLBACK_REG_SYSOR, ®_sysOR_parms);
-
- return SYS_ORTABLE_REGISTERED_OK;
+ if (NULL == (table_info = netsnmp_extract_table_info(request))) {
+ snmp_log(LOG_ERR,
+ "could not extract table info for sysORTable\n");
+ snmp_set_var_typed_value(
+ request->requestvb, SNMP_ERR_GENERR, NULL, 0);
+ } else if(NULL == (table_entry = (sysORTable_entry *)
+ netsnmp_container_table_extract_context(request))) {
+ switch (table_info->colnum) {
+ case COLUMN_SYSORID:
+ case COLUMN_SYSORDESCR:
+ case COLUMN_SYSORUPTIME:
+ netsnmp_set_request_error(reqinfo, request,
+ SNMP_NOSUCHINSTANCE);
+ break;
+ default:
+ netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
+ break;
+ }
+ } else {
+ switch (table_info->colnum) {
+ case COLUMN_SYSORID:
+ snmp_set_var_typed_value(
+ request->requestvb, ASN_OBJECT_ID,
+ (const u_char*)table_entry->data->OR_oid,
+ table_entry->data->OR_oidlen * sizeof(oid));
+ break;
+ case COLUMN_SYSORDESCR:
+ snmp_set_var_typed_value(
+ request->requestvb, ASN_OCTET_STR,
+ (const u_char*)table_entry->data->OR_descr,
+ strlen(table_entry->data->OR_descr));
+ break;
+ case COLUMN_SYSORUPTIME:
+ snmp_set_var_typed_integer(
+ request->requestvb, ASN_TIMETICKS,
+ table_entry->data->OR_uptime);
+ break;
+ default:
+ netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);
+ break;
+ }
+ }
+ do {
+ request = request->next;
+ } while(request && request->processed);
+ }
+ return SNMP_ERR_NOERROR;
}
-int
-register_sysORTable(oid * oidin, size_t oidlen, const char *descr)
-{
- return register_sysORTable_sess(oidin, oidlen, descr, NULL);
-}
+#ifdef USING_MIBII_SYSTEM_MIB_MODULE
+extern oid system_module_oid[];
+extern int system_module_oid_len;
+extern int system_module_count;
+#endif
+static netsnmp_handler_registration *sysORLastChange_reg;
+static netsnmp_watcher_info *sysORLastChange_winfo;
+static netsnmp_handler_registration *sysORTable_reg;
+static netsnmp_table_registration_info *sysORTable_table_info;
-
-int
-unregister_sysORTable_sess(oid * oidin,
- size_t oidlen, netsnmp_session * ss)
+/** Initializes the sysORTable module */
+void
+init_sysORTable(void)
{
- struct sysORTable *ptr, *prev = NULL, *next;
- int found = SYS_ORTABLE_NO_SUCH_REGISTRATION;
- struct register_sysOR_parameters reg_sysOR_parms;
+ oid sysORLastChange_oid[] = { 1, 3, 6, 1, 2, 1, 1, 8 };
+ oid sysORTable_oid[] = { 1, 3, 6, 1, 2, 1, 1, 9 };
- DEBUGMSGTL(("mibII/sysORTable", "sysORTable unregistering: "));
- DEBUGMSGOID(("mibII/sysORTable", oidin, oidlen));
- DEBUGMSG(("mibII/sysORTable", "\n"));
+ sysORTable_table_info =
+ SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
- for (ptr = table; ptr; ptr = next)
- {
- next = ptr->next;
- if (ptr->OR_sess == ss &&
- (snmp_oid_compare(oidin, oidlen, ptr->OR_oid, ptr->OR_oidlen) == 0))
- {
- if (prev == NULL)
- table = ptr->next;
- else
- prev->next = ptr->next;
+ table = netsnmp_container_find("sysORTable:table_container");
- free(ptr->OR_oid);
- free(ptr->OR_descr);
- free(ptr);
- numEntries--;
- sysORLastChange = netsnmp_get_agent_uptime();
- found = SYS_ORTABLE_UNREGISTERED_OK;
- break;
- } else
- prev = ptr;
+ if (sysORTable_table_info == NULL || table == NULL) {
+ SNMP_FREE(sysORTable_table_info);
+ CONTAINER_FREE(table);
+ return;
}
- reg_sysOR_parms.name = oidin;
- reg_sysOR_parms.namelen = oidlen;
- snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
- SNMPD_CALLBACK_UNREG_SYSOR, ®_sysOR_parms);
+ netsnmp_table_helper_add_indexes(sysORTable_table_info,
+ ASN_INTEGER, /** index: sysORIndex */
+ 0);
+ sysORTable_table_info->min_column = COLUMN_SYSORID;
+ sysORTable_table_info->max_column = COLUMN_SYSORUPTIME;
- return found;
-}
+ sysORLastChange_reg =
+ netsnmp_create_handler_registration(
+ "mibII/sysORLastChange", NULL,
+ sysORLastChange_oid, OID_LENGTH(sysORLastChange_oid),
+ HANDLER_CAN_RONLY);
+ sysORLastChange_winfo =
+ netsnmp_create_watcher_info(
+ &sysORLastChange, sizeof(u_long),
+ ASN_TIMETICKS, WATCHER_FIXED_SIZE);
+ netsnmp_register_watched_scalar(sysORLastChange_reg, sysORLastChange_winfo);
+ sysORTable_reg =
+ netsnmp_create_handler_registration(
+ "mibII/sysORTable", sysORTable_handler,
+ sysORTable_oid, OID_LENGTH(sysORTable_oid), HANDLER_CAN_RONLY);
+ netsnmp_container_table_register(sysORTable_reg, sysORTable_table_info,
+ table, TABLE_CONTAINER_KEY_NETSNMP_INDEX);
-int
-unregister_sysORTable(oid * oidin, size_t oidlen)
-{
- return unregister_sysORTable_sess(oidin, oidlen, NULL);
-}
+ sysORLastChange = netsnmp_get_agent_uptime();
-void
-unregister_sysORTable_by_session(netsnmp_session * ss)
-{
- struct sysORTable *ptr, *prev = NULL, *next;
+ /*
+ * Initialise the contents of the table here
+ */
+ netsnmp_sysORTable_foreach(®ister_foreach, NULL);
- for (ptr = table; ptr; ptr = next)
- {
- next = ptr->next;
- if (((ss->flags & SNMP_FLAGS_SUBSESSION) && ptr->OR_sess == ss) ||
- (!(ss->flags & SNMP_FLAGS_SUBSESSION) && ptr->OR_sess &&
- ptr->OR_sess->subsession == ss)) {
- if (prev == NULL)
- table = next;
- else
- prev->next = next;
- free(ptr->OR_oid);
- free(ptr->OR_descr);
- free(ptr);
- numEntries--;
- sysORLastChange = netsnmp_get_agent_uptime();
- } else
- prev = ptr;
- }
-}
+ /*
+ * Register callbacks
+ */
+ snmp_register_callback(SNMP_CALLBACK_APPLICATION,
+ SNMPD_CALLBACK_REG_SYSOR, register_cb, NULL);
+ snmp_register_callback(SNMP_CALLBACK_APPLICATION,
+ SNMPD_CALLBACK_UNREG_SYSOR, unregister_cb, NULL);
-static int
-_register_sysOR_callback(int majorID, int minorID, void *serverarg,
- void *clientarg)
-{
- struct sysORTable *parms = (struct sysORTable *) serverarg;
-
- return register_sysORTable_sess(parms->OR_oid, parms->OR_oidlen,
- parms->OR_descr, parms->OR_sess);
+#ifdef USING_MIBII_SYSTEM_MIB_MODULE
+ if (++system_module_count == 3)
+ REGISTER_SYSOR_TABLE(system_module_oid, system_module_oid_len,
+ "The MIB module for SNMPv2 entities");
+#endif
}
-static int
-_unregister_sysOR_by_session_callback(int majorID, int minorID,
- void *serverarg, void *clientarg)
+void
+shutdown_sysORTable(void)
{
- netsnmp_session *session = (netsnmp_session *) serverarg;
+#ifdef USING_MIBII_SYSTEM_MIB_MODULE
+ if (system_module_count-- == 3)
+ UNREGISTER_SYSOR_TABLE(system_module_oid, system_module_oid_len);
+#endif
- unregister_sysORTable_by_session(session);
+ snmp_unregister_callback(SNMP_CALLBACK_APPLICATION,
+ SNMPD_CALLBACK_UNREG_SYSOR, unregister_cb, NULL,
+ 1);
+ snmp_unregister_callback(SNMP_CALLBACK_APPLICATION,
+ SNMPD_CALLBACK_REG_SYSOR, register_cb, NULL, 1);
- return 0;
+ if (table)
+ CONTAINER_CLEAR(table, &free, NULL);
+ netsnmp_container_table_unregister(sysORTable_reg);
+ sysORTable_reg = NULL;
+ table = NULL;
+ netsnmp_table_registration_info_free(sysORTable_table_info);
+ sysORTable_table_info = NULL;
+ netsnmp_unregister_handler(sysORLastChange_reg);
+ sysORLastChange_reg = NULL;
+ SNMP_FREE(sysORLastChange_winfo);
}
-
-static int
-_unregister_sysOR_callback(int majorID, int minorID, void *serverarg,
- void *clientarg)
-{
- struct sysORTable *parms = (struct sysORTable *) serverarg;
-
- return unregister_sysORTable_sess(parms->OR_oid,
- parms->OR_oidlen,
- parms->OR_sess);
-}
-
Index: agent/mibgroup/mibII/udp.c
===================================================================
--- agent/mibgroup/mibII/udp.c (revision 16870)
+++ agent/mibgroup/mibII/udp.c (working copy)
@@ -16,6 +16,7 @@
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <net-snmp/agent/auto_nlist.h>
+#include <net-snmp/agent/sysORTable.h>
#include "util_funcs.h"
@@ -44,7 +45,6 @@
#endif
#include "udp.h"
#include "udpTable.h"
-#include "sysORTable.h"
#ifdef NETSNMP_CAN_USE_SYSCTL
#include <sys/sysctl.h>
Index: agent/mibgroup/mibII/vacm_conf.c
===================================================================
--- agent/mibgroup/mibII/vacm_conf.c (revision 16870)
+++ agent/mibgroup/mibII/vacm_conf.c (working copy)
@@ -51,24 +51,6 @@
#include "vacm_conf.h"
#include "util_funcs.h"
-#ifdef USING_MIBII_SYSORTABLE_MODULE
-#if TIME_WITH_SYS_TIME
-# ifdef WIN32
-# include <sys/timeb.h>
-# else
-# include <sys/time.h>
-# endif
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-# include <sys/time.h>
-# else
-# include <time.h>
-# endif
-#endif
-#include "sysORTable.h"
-#endif
-
#include "snmpd.h"
/**
Index: agent/mibgroup/mibII/sysORTable.h
===================================================================
--- agent/mibgroup/mibII/sysORTable.h (revision 16870)
+++ agent/mibgroup/mibII/sysORTable.h (working copy)
@@ -1,57 +1,7 @@
-/*
- * Template MIB group interface - sysORTable.h
- *
- */
-#ifndef _MIBGROUP_SYSORTABLE_H
-#define _MIBGROUP_SYSORTABLE_H
+#ifndef MIBGROUP_SYSORTABLE_H
+#define MIBGROUP_SYSORTABLE_H
-config_require(util_funcs)
-config_require(mibII/system_mib)
+extern void init_sysORTable(void);
+extern void shutdown_sysORTable(void);
- struct sysORTable {
- char *OR_descr;
- oid *OR_oid;
- size_t OR_oidlen;
- struct timeval OR_uptime;
- netsnmp_session *OR_sess;
- struct sysORTable *next;
- };
-
- struct register_sysOR_parameters {
- oid *name;
- int namelen;
- const char *descr;
- };
-
- extern void init_sysORTable(void);
- extern FindVarMethod var_sysORTable;
- extern FindVarMethod var_sysORLastChange;
- extern int register_sysORTable(oid *, size_t, const char *);
- extern int unregister_sysORTable(oid *, size_t);
- extern int register_sysORTable_sess(oid *, size_t, const char *,
- netsnmp_session *);
- extern int unregister_sysORTable_sess(oid *, size_t,
- netsnmp_session *);
- extern void unregister_sysORTable_by_session(netsnmp_session *);
-
-#define SYSORTABLEINDEX 1
-#define SYSORTABLEID 2
-#define SYSORTABLEDESCR 3
-#define SYSORTABLEUPTIME 4
-
-#define SYS_ORTABLE_REGISTERED_OK 0
-#define SYS_ORTABLE_REGISTRATION_FAILED -1
-#define SYS_ORTABLE_UNREGISTERED_OK 0
-#define SYS_ORTABLE_NO_SUCH_REGISTRATION -1
-
-#ifdef USING_MIBII_SYSORTABLE_MODULE
-#define REGISTER_SYSOR_ENTRY(theoid, descr) \
- (void)register_sysORTable(theoid, sizeof(theoid)/sizeof(oid), descr);
-#define REGISTER_SYSOR_TABLE(theoid, len, descr) \
- (void)register_sysORTable(theoid, len, descr);
-
-#else
-#define REGISTER_SYSOR_ENTRY(x,y)
-#define REGISTER_SYSOR_TABLE(x,y,z)
-#endif /* USING_MIBII_SYSORTABLE_MODULE */
-#endif /* _MIBGROUP_SYSORTABLE_H */
+#endif /* MIBGROUP_SYSORTABLE_H */
Index: agent/mibgroup/mibII/tcpTable.c
===================================================================
--- agent/mibgroup/mibII/tcpTable.c (revision 16870)
+++ agent/mibgroup/mibII/tcpTable.c (working copy)
@@ -36,7 +36,6 @@
#include "tcp.h"
#include "tcpTable.h"
-#include "sysORTable.h"
#ifdef hpux11
#define TCPTABLE_ENTRY_TYPE mib_tcpConnEnt
Index: agent/mibgroup/mibII/ipAddr.c
===================================================================
--- agent/mibgroup/mibII/ipAddr.c (revision 16870)
+++ agent/mibgroup/mibII/ipAddr.c (working copy)
@@ -118,7 +118,6 @@
#include "ip.h"
#include "interfaces.h"
-#include "sysORTable.h"
#ifdef cygwin
#include <windows.h>
Index: agent/mibgroup/mibII/snmp_mib.c
===================================================================
--- agent/mibgroup/mibII/snmp_mib.c (revision 16870)
+++ agent/mibgroup/mibII/snmp_mib.c (working copy)
@@ -1,10 +1,10 @@
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
+#include <net-snmp/agent/sysORTable.h>
#include "util_funcs.h"
#include "snmp_mib.h"
-#include "sysORTable.h"
#include "updates.h"
static oid snmp_oid[] = { 1, 3, 6, 1, 2, 1, 11 };
Index: agent/mibgroup/mibII/system_mib.c
===================================================================
--- agent/mibgroup/mibII/system_mib.c (revision 16870)
+++ agent/mibgroup/mibII/system_mib.c (working copy)
@@ -41,10 +41,10 @@
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
+#include <net-snmp/agent/sysORTable.h>
#include "util_funcs.h"
#include "system_mib.h"
-#include "sysORTable.h"
#include "updates.h"
/*********************
Index: agent/mibgroup/mibII/tcp.c
===================================================================
--- agent/mibgroup/mibII/tcp.c (revision 16870)
+++ agent/mibgroup/mibII/tcp.c (working copy)
@@ -49,11 +49,11 @@
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <net-snmp/agent/auto_nlist.h>
+#include <net-snmp/agent/sysORTable.h>
#include "util_funcs.h"
#include "tcp.h"
#include "tcpTable.h"
-#include "sysORTable.h"
#ifndef MIB_STATS_CACHE_TIMEOUT
#define MIB_STATS_CACHE_TIMEOUT 5
Index: agent/mibgroup/mibII/icmp.c
===================================================================
--- agent/mibgroup/mibII/icmp.c (revision 16870)
+++ agent/mibgroup/mibII/icmp.c (working copy)
@@ -18,10 +18,10 @@
#include <net-snmp/agent/cache_handler.h>
#include <net-snmp/agent/scalar_group.h>
+#include <net-snmp/agent/sysORTable.h>
#include "util_funcs.h"
#include "icmp.h"
-#include "sysORTable.h"
#ifndef MIB_STATS_CACHE_TIMEOUT
#define MIB_STATS_CACHE_TIMEOUT 5
Index: agent/mibgroup/snmpv3/snmpEngine.c
===================================================================
--- agent/mibgroup/snmpv3/snmpEngine.c (revision 16870)
+++ agent/mibgroup/snmpv3/snmpEngine.c (working copy)
@@ -10,9 +10,9 @@
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
+#include <net-snmp/agent/sysORTable.h>
#include "util_funcs.h"
-#include "mibII/sysORTable.h"
#include "snmpEngine.h"
struct variable2 snmpEngine_variables[] = {
@@ -56,10 +56,8 @@
void
init_snmpEngine(void)
{
-#ifdef USING_MIBII_SYSORTABLE_MODULE
- static oid reg[] = { 1, 3, 6, 1, 6, 3, 10, 3, 1, 1 };
- register_sysORTable(reg, 10, "The SNMP Management Architecture MIB.");
-#endif
+ oid reg[] = { 1, 3, 6, 1, 6, 3, 10, 3, 1, 1 };
+ REGISTER_SYSOR_ENTRY(reg, "The SNMP Management Architecture MIB.");
register_snmpEngine_scalars();
}
Index: agent/mibgroup/snmpv3/usmStats.c
===================================================================
--- agent/mibgroup/snmpv3/usmStats.c (revision 16870)
+++ agent/mibgroup/snmpv3/usmStats.c (working copy)
@@ -11,9 +11,9 @@
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
+#include <net-snmp/agent/sysORTable.h>
#include "util_funcs.h"
-#include "mibII/sysORTable.h"
#include "usmStats.h"
struct variable2 usmStats_variables[] = {
@@ -35,12 +35,10 @@
void
init_usmStats(void)
{
-#ifdef USING_MIBII_SYSORTABLE_MODULE
static oid reg[] = { 1, 3, 6, 1, 6, 3, 15, 2, 1, 1 };
- register_sysORTable(reg, 10,
- "The management information definitions for the SNMP User-based Security Model.");
-#endif
-
+ REGISTER_SYSOR_ENTRY(reg,
+ "The management information definitions for the "
+ "SNMP User-based Security Model.");
REGISTER_MIB("snmpv3/usmStats", usmStats_variables, variable2,
usmStats_variables_oid);
}
Index: agent/mibgroup/snmpv3/snmpMPDStats.c
===================================================================
--- agent/mibgroup/snmpv3/snmpMPDStats.c (revision 16870)
+++ agent/mibgroup/snmpv3/snmpMPDStats.c (working copy)
@@ -10,8 +10,8 @@
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
+#include <net-snmp/agent/sysORTable.h>
-#include "mibII/sysORTable.h"
#include "snmpMPDStats.h"
#include "util_funcs.h"
@@ -32,12 +32,9 @@
void
init_snmpMPDStats(void)
{
-#ifdef USING_MIBII_SYSORTABLE_MODULE
static oid reg[] = { 1, 3, 6, 1, 6, 3, 11, 3, 1, 1 };
- register_sysORTable(reg, 10,
- "The MIB for Message Processing and Dispatching.");
-#endif
-
+ REGISTER_SYSOR_ENTRY(reg,
+ "The MIB for Message Processing and Dispatching.");
REGISTER_MIB("snmpv3/snmpMPDStats", snmpMPDStats_variables, variable2,
snmpMPDStats_variables_oid);
}
Index: agent/mibgroup/tunnel/tunnel.c
===================================================================
--- agent/mibgroup/tunnel/tunnel.c (revision 16870)
+++ agent/mibgroup/tunnel/tunnel.c (working copy)
@@ -62,6 +62,7 @@
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
+#include <net-snmp/agent/sysORTable.h>
#include "util_funcs.h"
#include "tunnel.h"
@@ -158,11 +159,7 @@
-extern int register_sysORTable(oid *, size_t, const char *);
-extern int unregister_sysORTable(oid *, size_t);
-
static oid sysORTable_reg[] = { 1, 3, 6, 1, 2, 1, 10, 131 };
-static size_t sysORTable_reglen = 8;
static struct tunnel *tunnels;
@@ -171,7 +168,7 @@
void
deinit_tunnel(void)
{
- unregister_sysORTable(sysORTable_reg, sysORTable_reglen);
+ UNREGISTER_SYSOR_ENTRY(sysORTable_reg);
}
@@ -188,7 +185,7 @@
void
init_tunnel(void)
{
- register_sysORTable(sysORTable_reg, sysORTable_reglen,
+ REGISTER_SYSOR_ENTRY(sysORTable_reg,
"RFC 2667 TUNNEL-MIB implementation for "
"Linux 2.2.x kernels.");
Index: agent/agent_sysORTable.c
===================================================================
--- agent/agent_sysORTable.c (revision 0)
+++ agent/agent_sysORTable.c (revision 0)
@@ -0,0 +1,236 @@
+#include <net-snmp/net-snmp-config.h>
+#if HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#if HAVE_STRING_H
+#include <string.h>
+#else
+#include <strings.h>
+#endif
+#include <stddef.h>
+
+#include <net-snmp/net-snmp-includes.h>
+#include <net-snmp/agent/net-snmp-agent-includes.h>
+#include <net-snmp/agent/agent_callbacks.h>
+#include <net-snmp/agent/agent_sysORTable.h>
+#include <net-snmp/agent/sysORTable.h>
+
+typedef struct data_node_s {
+ struct sysORTable data;
+ struct data_node_s* next;
+ struct data_node_s* prev;
+}* data_node;
+
+static data_node table = NULL;
+
+static void
+erase(data_node entry)
+{
+ entry->data.OR_uptime = netsnmp_get_agent_uptime();
+ DEBUGMSGTL(("agent/sysORTable", "UNREG_SYSOR %p\n", &entry->data));
+ snmp_call_callbacks(SNMP_CALLBACK_APPLICATION, SNMPD_CALLBACK_UNREG_SYSOR,
+ &entry->data);
+ free(entry->data.OR_oid);
+ free((char*)entry->data.OR_descr);
+ if (entry->next == entry)
+ table = NULL;
+ else {
+ entry->next->prev = entry->prev;
+ entry->prev->next = entry->next;
+ if (entry == table)
+ table = entry->next;
+ }
+ free(entry);
+}
+
+void
+netsnmp_sysORTable_foreach(void (*f)(const struct sysORTable*, void*), void* c)
+{
+ DEBUGMSGTL(("agent/sysORTable", "foreach(%p, %p)\n", f, c));
+ if(table) {
+ data_node run = table;
+ do {
+ data_node tmp = run;
+ run = run->next;
+ f(&tmp->data, c);
+ } while(table && run != table);
+ }
+}
+
+int
+register_sysORTable_sess(oid * oidin,
+ size_t oidlen,
+ const char *descr, netsnmp_session * ss)
+{
+ data_node entry;
+
+ DEBUGMSGTL(("agent/sysORTable", "registering: "));
+ DEBUGMSGOID(("agent/sysORTable", oidin, oidlen));
+ DEBUGMSG(("agent/sysORTable", ", session %p\n", ss));
+
+ entry = calloc(1, sizeof(struct data_node_s));
+ if (entry == NULL) {
+ DEBUGMSGTL(("agent/sysORTable", "Failed to allocate new entry\n"));
+ return SYS_ORTABLE_REGISTRATION_FAILED;
+ }
+
+ entry->data.OR_descr = strdup(descr);
+ if (entry->data.OR_descr == NULL) {
+ DEBUGMSGTL(("agent/sysORTable", "Failed to allocate new sysORDescr\n"));
+ free(entry);
+ return SYS_ORTABLE_REGISTRATION_FAILED;
+ }
+
+ entry->data.OR_oid = (oid *) malloc(sizeof(oid) * oidlen);
+ if (entry->data.OR_oid == NULL) {
+ DEBUGMSGTL(("agent/sysORTable", "Failed to allocate new sysORID\n"));
+ free((char*)entry->data.OR_descr);
+ free(entry);
+ return SYS_ORTABLE_REGISTRATION_FAILED;
+ }
+
+ memcpy(entry->data.OR_oid, oidin, sizeof(oid) * oidlen);
+ entry->data.OR_oidlen = oidlen;
+ entry->data.OR_sess = ss;
+
+ if(table) {
+ entry->next = table;
+ entry->prev = table->prev;
+ table->prev->next = entry;
+ table->prev = entry;
+ } else
+ table = entry->next = entry->prev = entry;
+
+ entry->data.OR_uptime = netsnmp_get_agent_uptime();
+
+ snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
+ SNMPD_CALLBACK_REG_SYSOR, &entry->data);
+
+ return SYS_ORTABLE_REGISTERED_OK;
+}
+
+int
+register_sysORTable(oid * oidin, size_t oidlen, const char *descr)
+{
+ return register_sysORTable_sess(oidin, oidlen, descr, NULL);
+}
+
+int
+unregister_sysORTable_sess(oid * oidin,
+ size_t oidlen, netsnmp_session * ss)
+{
+ int any_unregistered = 0;
+
+ DEBUGMSGTL(("agent/sysORTable", "sysORTable unregistering: "));
+ DEBUGMSGOID(("agent/sysORTable", oidin, oidlen));
+ DEBUGMSG(("agent/sysORTable", ", session %p\n", ss));
+
+ if(table) {
+ data_node run = table;
+ do {
+ data_node tmp = run;
+ run = run->next;
+ if (tmp->data.OR_sess == ss &&
+ snmp_oid_compare(oidin, oidlen,
+ tmp->data.OR_oid, tmp->data.OR_oidlen) == 0) {
+ erase(tmp);
+ any_unregistered = 1;
+ }
+ } while(table && run != table);
+ }
+
+ if (any_unregistered) {
+ DEBUGMSGTL(("agent/sysORTable", "unregistering successfull\n"));
+ return SYS_ORTABLE_UNREGISTERED_OK;
+ } else {
+ DEBUGMSGTL(("agent/sysORTable", "unregistering failed\n"));
+ return SYS_ORTABLE_NO_SUCH_REGISTRATION;
+ }
+}
+
+
+int
+unregister_sysORTable(oid * oidin, size_t oidlen)
+{
+ return unregister_sysORTable_sess(oidin, oidlen, NULL);
+}
+
+
+void
+unregister_sysORTable_by_session(netsnmp_session * ss)
+{
+ DEBUGMSGTL(("agent/sysORTable",
+ "sysORTable unregistering session %p\n", ss));
+
+ if(table) {
+ data_node run = table;
+ do {
+ data_node tmp = run;
+ run = run->next;
+ if (((ss->flags & SNMP_FLAGS_SUBSESSION) &&
+ tmp->data.OR_sess == ss) ||
+ (!(ss->flags & SNMP_FLAGS_SUBSESSION) && tmp->data.OR_sess &&
+ tmp->data.OR_sess->subsession == ss))
+ erase(tmp);
+ } while(table && run != table);
+ }
+
+ DEBUGMSGTL(("agent/sysORTable",
+ "sysORTable unregistering session %p done\n", ss));
+}
+
+static int
+register_sysOR_callback(int majorID, int minorID, void *serverarg,
+ void *clientarg)
+{
+ struct sysORTable *parms = (struct sysORTable *) serverarg;
+
+ return register_sysORTable_sess(parms->OR_oid, parms->OR_oidlen,
+ parms->OR_descr, parms->OR_sess);
+}
+
+static int
+unregister_sysOR_by_session_callback(int majorID, int minorID,
+ void *serverarg, void *clientarg)
+{
+ netsnmp_session *session = (netsnmp_session *) serverarg;
+
+ unregister_sysORTable_by_session(session);
+
+ return 0;
+}
+
+static int
+unregister_sysOR_callback(int majorID, int minorID, void *serverarg,
+ void *clientarg)
+{
+ struct sysORTable *parms = (struct sysORTable *) serverarg;
+
+ return unregister_sysORTable_sess(parms->OR_oid,
+ parms->OR_oidlen,
+ parms->OR_sess);
+}
+
+void
+init_agent_sysORTable(void)
+{
+ DEBUGMSGTL(("agent/sysORTable", "init_agent_sysORTable\n"));
+
+ snmp_register_callback(SNMP_CALLBACK_APPLICATION,
+ SNMPD_CALLBACK_REQ_REG_SYSOR,
+ register_sysOR_callback, NULL);
+ snmp_register_callback(SNMP_CALLBACK_APPLICATION,
+ SNMPD_CALLBACK_REQ_UNREG_SYSOR,
+ unregister_sysOR_callback, NULL);
+ snmp_register_callback(SNMP_CALLBACK_APPLICATION,
+ SNMPD_CALLBACK_REQ_UNREG_SYSOR_SESS,
+ unregister_sysOR_by_session_callback, NULL);
+}
+
+void
+shutdown_agent_sysORTable(void)
+{
+ DEBUGMSGTL(("agent/sysORTable", "shutdown_sysORTable\n"));
+ while(table)
+ erase(table);
+}
Index: agent/snmp_vars.c
===================================================================
--- agent/snmp_vars.c (revision 16870)
+++ agent/snmp_vars.c (working copy)
@@ -307,6 +307,7 @@
netsnmp_init_helpers();
init_traps();
netsnmp_container_init_list();
+ init_agent_sysORTable();
#if defined(USING_AGENTX_SUBAGENT_MODULE) || defined(USING_AGENTX_MASTER_MODULE)
/*
@@ -361,6 +362,7 @@
netsnmp_clear_callback_list();
netsnmp_clear_tdomain_list();
netsnmp_clear_handler_list();
+ shutdown_agent_sysORTable();
netsnmp_container_free_list();
clear_sec_mod();
clear_snmp_enum();
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders