3
* Implementation of the mteObjectsTable MIB interface
4
* See 'mteObjects.c' for active behaviour of this table.
6
* (based on mib2c.table_data.conf output)
9
#include <net-snmp/net-snmp-config.h>
10
#include <net-snmp/net-snmp-includes.h>
11
#include <net-snmp/agent/net-snmp-agent-includes.h>
12
#include "disman/event/mteObjects.h"
13
#include "disman/event/mteObjectsTable.h"
15
/** Initializes the mteObjectsTable module */
17
init_mteObjectsTable(void)
20
static oid mteObjectsTable_oid[] = { 1, 3, 6, 1, 2, 1, 88, 1, 3, 1 };
21
size_t mteObjectsTable_oid_len = OID_LENGTH(mteObjectsTable_oid);
22
netsnmp_handler_registration *reg;
23
netsnmp_table_registration_info *table_info;
26
* Ensure the object table container is available...
28
init_objects_table_data();
31
* ... then set up the MIB interface to this table
33
reg = netsnmp_create_handler_registration("mteObjectsTable",
34
mteObjectsTable_handler,
36
mteObjectsTable_oid_len,
39
table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
40
netsnmp_table_helper_add_indexes(table_info,
41
ASN_OCTET_STR, /* index: mteOwner */
42
ASN_OCTET_STR, /* index: mteObjectsName */
43
ASN_UNSIGNED, /* index: mteObjectsIndex */
46
table_info->min_column = COLUMN_MTEOBJECTSID;
47
table_info->max_column = COLUMN_MTEOBJECTSENTRYSTATUS;
50
netsnmp_tdata_register(reg, objects_table_data, table_info);
54
/** handles requests for the mteObjectsTable table */
56
mteObjectsTable_handler(netsnmp_mib_handler *handler,
57
netsnmp_handler_registration *reginfo,
58
netsnmp_agent_request_info *reqinfo,
59
netsnmp_request_info *requests)
62
netsnmp_request_info *request;
63
netsnmp_table_request_info *tinfo;
64
netsnmp_tdata_row *row;
65
struct mteObject *entry;
66
char mteOwner[MTE_STR1_LEN+1];
67
char mteOName[MTE_STR1_LEN+1];
70
DEBUGMSGTL(("disman:event:mib", "ObjTable handler (%d)\n", reqinfo->mode));
72
switch (reqinfo->mode) {
74
* Read-support (also covers GetNext requests)
77
for (request = requests; request; request = request->next) {
78
entry = (struct mteObject *) netsnmp_tdata_extract_entry(request);
79
tinfo = netsnmp_extract_table_info(request);
81
switch (tinfo->colnum) {
82
case COLUMN_MTEOBJECTSID:
83
snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID,
84
(u_char *) entry->mteObjectID,
85
entry->mteObjectID_len*sizeof(oid));
87
case COLUMN_MTEOBJECTSIDWILDCARD:
88
ret = (entry->flags & MTE_OBJECT_FLAG_WILD ) ?
90
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret);
92
case COLUMN_MTEOBJECTSENTRYSTATUS:
93
ret = (entry->flags & MTE_OBJECT_FLAG_ACTIVE ) ?
94
RS_ACTIVE : RS_NOTINSERVICE;
95
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret);
104
case MODE_SET_RESERVE1:
106
for (request = requests; request; request = request->next) {
107
entry = (struct mteObject *) netsnmp_tdata_extract_entry(request);
108
tinfo = netsnmp_extract_table_info(request);
110
switch (tinfo->colnum) {
111
case COLUMN_MTEOBJECTSID:
112
ret = netsnmp_check_vb_oid( request->requestvb );
113
if (ret != SNMP_ERR_NOERROR) {
114
netsnmp_set_request_error(reqinfo, request, ret);
115
return SNMP_ERR_NOERROR;
118
* Can't modify the OID of an active row
119
* (an unnecessary restriction, IMO)
122
entry->flags & MTE_OBJECT_FLAG_ACTIVE ) {
123
netsnmp_set_request_error(reqinfo, request,
124
SNMP_ERR_INCONSISTENTVALUE);
125
return SNMP_ERR_NOERROR;
128
case COLUMN_MTEOBJECTSIDWILDCARD:
129
ret = netsnmp_check_vb_truthvalue( request->requestvb );
130
if (ret != SNMP_ERR_NOERROR) {
131
netsnmp_set_request_error(reqinfo, request, ret);
132
return SNMP_ERR_NOERROR;
135
* Can't modify the wildcarding of an active row
136
* (an unnecessary restriction, IMO)
139
entry->flags & MTE_OBJECT_FLAG_ACTIVE ) {
140
netsnmp_set_request_error(reqinfo, request,
141
SNMP_ERR_INCONSISTENTVALUE);
142
return SNMP_ERR_NOERROR;
145
case COLUMN_MTEOBJECTSENTRYSTATUS:
146
ret = netsnmp_check_vb_rowstatus(request->requestvb,
147
(entry ? RS_ACTIVE : RS_NONEXISTENT));
148
if (ret != SNMP_ERR_NOERROR) {
149
netsnmp_set_request_error(reqinfo, request, ret);
150
return SNMP_ERR_NOERROR;
152
/* An active row can only be deleted */
154
entry->flags & MTE_OBJECT_FLAG_ACTIVE &&
155
*request->requestvb->val.integer == RS_NOTINSERVICE ) {
156
netsnmp_set_request_error(reqinfo, request,
157
SNMP_ERR_INCONSISTENTVALUE);
158
return SNMP_ERR_NOERROR;
162
netsnmp_set_request_error(reqinfo, request,
163
SNMP_ERR_NOTWRITABLE);
164
return SNMP_ERR_NOERROR;
169
case MODE_SET_RESERVE2:
171
for (request = requests; request; request = request->next) {
172
tinfo = netsnmp_extract_table_info(request);
174
switch (tinfo->colnum) {
175
case COLUMN_MTEOBJECTSENTRYSTATUS:
176
switch (*request->requestvb->val.integer) {
178
case RS_CREATEANDWAIT:
180
* Create an (empty) new row structure
182
memset(mteOwner, 0, sizeof(mteOwner));
183
memcpy(mteOwner, tinfo->indexes->val.string,
184
tinfo->indexes->val_len);
185
memset(mteOName, 0, sizeof(mteOName));
187
tinfo->indexes->next_variable->val.string,
188
tinfo->indexes->next_variable->val_len);
189
ret = *tinfo->indexes->next_variable->next_variable->val.integer;
191
row = mteObjects_createEntry(mteOwner, mteOName, ret, 0);
193
netsnmp_set_request_error(reqinfo, request,
194
SNMP_ERR_RESOURCEUNAVAILABLE);
195
return SNMP_ERR_NOERROR;
197
netsnmp_insert_tdata_row( request, row );
205
for (request = requests; request; request = request->next) {
206
tinfo = netsnmp_extract_table_info(request);
208
switch (tinfo->colnum) {
209
case COLUMN_MTEOBJECTSENTRYSTATUS:
210
switch (*request->requestvb->val.integer) {
212
case RS_CREATEANDWAIT:
214
* Tidy up after a failed row creation request
216
entry = (struct mteObject *)
217
netsnmp_tdata_extract_entry(request);
219
!(entry->flags & MTE_OBJECT_FLAG_VALID)) {
220
row = (netsnmp_tdata_row *)
221
netsnmp_tdata_extract_row(request);
222
mteObjects_removeEntry( row );
229
case MODE_SET_ACTION:
230
for (request = requests; request; request = request->next) {
231
entry = (struct mteObject *) netsnmp_tdata_extract_entry(request);
234
* New rows must be created via the RowStatus column
236
netsnmp_set_request_error(reqinfo, request,
237
SNMP_ERR_NOCREATION);
238
/* or inconsistentName? */
239
return SNMP_ERR_NOERROR;
248
case MODE_SET_COMMIT:
250
* All these assignments are "unfailable", so it's
251
* (reasonably) safe to apply them in the Commit phase
253
for (request = requests; request; request = request->next) {
254
entry = (struct mteObject *) netsnmp_tdata_extract_entry(request);
255
tinfo = netsnmp_extract_table_info(request);
257
switch (tinfo->colnum) {
258
case COLUMN_MTEOBJECTSID:
259
memset(entry->mteObjectID, 0, sizeof(entry->mteObjectID));
260
memcpy(entry->mteObjectID, request->requestvb->val.objid,
261
request->requestvb->val_len);
262
entry->mteObjectID_len = request->requestvb->val_len/sizeof(oid);
265
case COLUMN_MTEOBJECTSIDWILDCARD:
266
if (*request->requestvb->val.integer == TV_TRUE)
267
entry->flags |= MTE_OBJECT_FLAG_WILD;
269
entry->flags &= ~MTE_OBJECT_FLAG_WILD;
272
case COLUMN_MTEOBJECTSENTRYSTATUS:
273
switch (*request->requestvb->val.integer) {
275
entry->flags |= MTE_OBJECT_FLAG_ACTIVE;
278
entry->flags |= MTE_OBJECT_FLAG_VALID;
279
entry->flags |= MTE_OBJECT_FLAG_ACTIVE;
281
case RS_CREATEANDWAIT:
282
entry->flags |= MTE_OBJECT_FLAG_VALID;
286
row = (netsnmp_tdata_row *)
287
netsnmp_tdata_extract_row(request);
288
mteObjects_removeEntry(row);
294
return SNMP_ERR_NOERROR;