| 1 |
/* |
| 2 |
* DisMan Expression MIB: |
| 3 |
* Implementation of the expExpressionObjectTable MIB interface |
| 4 |
* See 'expObject.c' for active behaviour of this table. |
| 5 |
* |
| 6 |
* (Based on mib2c.table_data.conf output) |
| 7 |
*/ |
| 8 |
|
| 9 |
#include <net-snmp/net-snmp-config.h> |
| 10 |
#include <net-snmp/net-snmp-features.h> |
| 11 |
#include <net-snmp/net-snmp-includes.h> |
| 12 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 13 |
#include "disman/expr/expObject.h" |
| 14 |
#include "disman/expr/expObjectTable.h" |
| 15 |
|
| 16 |
netsnmp_feature_require(table_tdata); |
| 17 |
#ifndef NETSNMP_NO_WRITE_SUPPORT |
| 18 |
netsnmp_feature_require(check_vb_oid); |
| 19 |
netsnmp_feature_require(check_vb_truthvalue); |
| 20 |
netsnmp_feature_require(table_tdata_insert_row); |
| 21 |
#endif /* NETSNMP_NO_WRITE_SUPPORT */ |
| 22 |
|
| 23 |
static netsnmp_handler_registration *object_table_reg; |
| 24 |
static netsnmp_table_registration_info *object_table_info; |
| 25 |
|
| 26 |
/* Initializes the expObjectTable module */ |
| 27 |
void |
| 28 |
init_expObjectTable(void) |
| 29 |
{ |
| 30 |
static oid expObjectTable_oid[] = { 1, 3, 6, 1, 2, 1, 90, 1, 2, 3 }; |
| 31 |
size_t expObjectTable_oid_len = OID_LENGTH(expObjectTable_oid); |
| 32 |
|
| 33 |
/* |
| 34 |
* Ensure the expObject table container is available... |
| 35 |
*/ |
| 36 |
init_expObject_table_data(); |
| 37 |
|
| 38 |
/* |
| 39 |
* ... then set up the MIB interface to the expObjectTable |
| 40 |
*/ |
| 41 |
object_table_reg = netsnmp_create_handler_registration("expObjectTable", |
| 42 |
expObjectTable_handler, |
| 43 |
expObjectTable_oid, |
| 44 |
expObjectTable_oid_len, |
| 45 |
HANDLER_CAN_RWRITE); |
| 46 |
|
| 47 |
object_table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); |
| 48 |
netsnmp_table_helper_add_indexes(object_table_info, |
| 49 |
/* index: expExpressionOwner */ |
| 50 |
ASN_OCTET_STR, |
| 51 |
/* index: expExpressionName */ |
| 52 |
ASN_OCTET_STR, |
| 53 |
/* index: expObjectIndex */ |
| 54 |
ASN_UNSIGNED, |
| 55 |
0); |
| 56 |
|
| 57 |
object_table_info->min_column = COLUMN_EXPOBJECTID; |
| 58 |
object_table_info->max_column = COLUMN_EXPOBJECTENTRYSTATUS; |
| 59 |
|
| 60 |
/* Register this using the common expObject_table_data container */ |
| 61 |
netsnmp_tdata_register(object_table_reg, expObject_table_data, object_table_info); |
| 62 |
DEBUGMSGTL(("disman:expr:init", "Expression Object Table container (%p)\n", |
| 63 |
expObject_table_data)); |
| 64 |
} |
| 65 |
|
| 66 |
void |
| 67 |
shutdown_expObjectTable(void) |
| 68 |
{ |
| 69 |
netsnmp_tdata_unregister(object_table_reg); |
| 70 |
netsnmp_table_registration_info_free(object_table_info); |
| 71 |
} |
| 72 |
|
| 73 |
/** handles requests for the expObjectTable table */ |
| 74 |
int |
| 75 |
expObjectTable_handler(netsnmp_mib_handler *handler, |
| 76 |
netsnmp_handler_registration *reginfo, |
| 77 |
netsnmp_agent_request_info *reqinfo, |
| 78 |
netsnmp_request_info *requests) |
| 79 |
{ |
| 80 |
|
| 81 |
netsnmp_request_info *request; |
| 82 |
netsnmp_table_request_info *tinfo; |
| 83 |
netsnmp_tdata_row *row; |
| 84 |
struct expObject *entry; |
| 85 |
struct expExpression *exp; |
| 86 |
char expOwner[EXP_STR1_LEN+1]; |
| 87 |
char expName[ EXP_STR1_LEN+1]; |
| 88 |
long objIndex; |
| 89 |
long ret; |
| 90 |
netsnmp_variable_list *vp; |
| 91 |
|
| 92 |
DEBUGMSGTL(("disman:expr:mib", "Expression Object Table handler (%d)\n", |
| 93 |
reqinfo->mode)); |
| 94 |
switch (reqinfo->mode) { |
| 95 |
/* |
| 96 |
* Read-support (also covers GetNext requests) |
| 97 |
*/ |
| 98 |
case MODE_GET: |
| 99 |
for (request = requests; request; request = request->next) { |
| 100 |
if (request->processed) |
| 101 |
continue; |
| 102 |
|
| 103 |
entry = (struct expObject *)netsnmp_tdata_extract_entry(request); |
| 104 |
tinfo = netsnmp_extract_table_info(request); |
| 105 |
if (!entry || !(entry->flags & EXP_OBJ_FLAG_VALID)) |
| 106 |
continue; |
| 107 |
|
| 108 |
switch (tinfo->colnum) { |
| 109 |
case COLUMN_EXPOBJECTID: |
| 110 |
snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID, |
| 111 |
(u_char *) entry->expObjectID, |
| 112 |
entry->expObjectID_len*sizeof(oid)); |
| 113 |
break; |
| 114 |
case COLUMN_EXPOBJECTIDWILDCARD: |
| 115 |
ret = (entry->flags & EXP_OBJ_FLAG_OWILD) ? |
| 116 |
TV_TRUE : TV_FALSE; |
| 117 |
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret); |
| 118 |
break; |
| 119 |
case COLUMN_EXPOBJECTSAMPLETYPE: |
| 120 |
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, |
| 121 |
entry->expObjectSampleType); |
| 122 |
break; |
| 123 |
case COLUMN_EXPOBJECTDELTADISCONTINUITYID: |
| 124 |
/* |
| 125 |
* "This object [and the next two] are instantiated only if |
| 126 |
* expObjectSampleType is 'deltaValue' or 'changedValue'" |
| 127 |
*/ |
| 128 |
if ( entry->expObjectSampleType == 1 ) |
| 129 |
continue; |
| 130 |
snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID, |
| 131 |
(u_char *) entry->expObjDeltaD, |
| 132 |
entry->expObjDeltaD_len*sizeof(oid)); |
| 133 |
break; |
| 134 |
case COLUMN_EXPOBJECTDISCONTINUITYIDWILDCARD: |
| 135 |
if ( entry->expObjectSampleType == 1 ) |
| 136 |
continue; |
| 137 |
ret = (entry->flags & EXP_OBJ_FLAG_DWILD) ? |
| 138 |
TV_TRUE : TV_FALSE; |
| 139 |
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret); |
| 140 |
break; |
| 141 |
case COLUMN_EXPOBJECTDISCONTINUITYIDTYPE: |
| 142 |
if ( entry->expObjectSampleType == 1 ) |
| 143 |
continue; |
| 144 |
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, |
| 145 |
entry->expObjDiscontinuityType); |
| 146 |
break; |
| 147 |
case COLUMN_EXPOBJECTCONDITIONAL: |
| 148 |
snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID, |
| 149 |
(u_char *) entry->expObjCond, |
| 150 |
entry->expObjCond_len*sizeof(oid)); |
| 151 |
break; |
| 152 |
case COLUMN_EXPOBJECTCONDITIONALWILDCARD: |
| 153 |
ret = (entry->flags & EXP_OBJ_FLAG_CWILD) ? |
| 154 |
TV_TRUE : TV_FALSE; |
| 155 |
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret); |
| 156 |
break; |
| 157 |
case COLUMN_EXPOBJECTENTRYSTATUS: |
| 158 |
/* What would indicate 'notReady' ? */ |
| 159 |
ret = (entry->flags & EXP_OBJ_FLAG_ACTIVE) ? |
| 160 |
RS_ACTIVE : RS_NOTINSERVICE; |
| 161 |
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret); |
| 162 |
break; |
| 163 |
} |
| 164 |
} |
| 165 |
break; |
| 166 |
|
| 167 |
/* |
| 168 |
* Write-support |
| 169 |
*/ |
| 170 |
case MODE_SET_RESERVE1: |
| 171 |
for (request = requests; request; request = request->next) { |
| 172 |
if (request->processed) |
| 173 |
continue; |
| 174 |
|
| 175 |
entry = (struct expObject *) |
| 176 |
netsnmp_tdata_extract_entry(request); |
| 177 |
tinfo = netsnmp_extract_table_info(request); |
| 178 |
|
| 179 |
switch (tinfo->colnum) { |
| 180 |
case COLUMN_EXPOBJECTID: |
| 181 |
case COLUMN_EXPOBJECTDELTADISCONTINUITYID: |
| 182 |
case COLUMN_EXPOBJECTCONDITIONAL: |
| 183 |
ret = netsnmp_check_vb_oid(request->requestvb); |
| 184 |
if (ret != SNMP_ERR_NOERROR) { |
| 185 |
netsnmp_set_request_error(reqinfo, request, ret); |
| 186 |
return SNMP_ERR_NOERROR; |
| 187 |
} |
| 188 |
break; |
| 189 |
|
| 190 |
case COLUMN_EXPOBJECTIDWILDCARD: |
| 191 |
case COLUMN_EXPOBJECTDISCONTINUITYIDWILDCARD: |
| 192 |
case COLUMN_EXPOBJECTCONDITIONALWILDCARD: |
| 193 |
ret = netsnmp_check_vb_truthvalue(request->requestvb); |
| 194 |
if (ret != SNMP_ERR_NOERROR) { |
| 195 |
netsnmp_set_request_error(reqinfo, request, ret); |
| 196 |
return SNMP_ERR_NOERROR; |
| 197 |
} |
| 198 |
break; |
| 199 |
|
| 200 |
case COLUMN_EXPOBJECTSAMPLETYPE: |
| 201 |
case COLUMN_EXPOBJECTDISCONTINUITYIDTYPE: |
| 202 |
ret = netsnmp_check_vb_int_range(request->requestvb, 1, 3); |
| 203 |
if (ret != SNMP_ERR_NOERROR) { |
| 204 |
netsnmp_set_request_error(reqinfo, request, ret); |
| 205 |
return SNMP_ERR_NOERROR; |
| 206 |
} |
| 207 |
break; |
| 208 |
|
| 209 |
case COLUMN_EXPOBJECTENTRYSTATUS: |
| 210 |
ret = netsnmp_check_vb_rowstatus(request->requestvb, |
| 211 |
(entry ? RS_ACTIVE : RS_NONEXISTENT)); |
| 212 |
if (ret != SNMP_ERR_NOERROR) { |
| 213 |
netsnmp_set_request_error(reqinfo, request, ret); |
| 214 |
return SNMP_ERR_NOERROR; |
| 215 |
} |
| 216 |
break; |
| 217 |
default: |
| 218 |
netsnmp_set_request_error(reqinfo, request, |
| 219 |
SNMP_ERR_NOTWRITABLE); |
| 220 |
return SNMP_ERR_NOERROR; |
| 221 |
} |
| 222 |
} |
| 223 |
break; |
| 224 |
|
| 225 |
case MODE_SET_RESERVE2: |
| 226 |
for (request = requests; request; request = request->next) { |
| 227 |
if (request->processed) |
| 228 |
continue; |
| 229 |
|
| 230 |
tinfo = netsnmp_extract_table_info(request); |
| 231 |
|
| 232 |
switch (tinfo->colnum) { |
| 233 |
case COLUMN_EXPOBJECTENTRYSTATUS: |
| 234 |
switch (*request->requestvb->val.integer) { |
| 235 |
case RS_CREATEANDGO: |
| 236 |
case RS_CREATEANDWAIT: |
| 237 |
/* |
| 238 |
* Create an (empty) new row structure |
| 239 |
*/ |
| 240 |
memset(expOwner, 0, sizeof(expOwner)); |
| 241 |
memcpy(expOwner, tinfo->indexes->val.string, |
| 242 |
tinfo->indexes->val_len); |
| 243 |
memset(expName, 0, sizeof(expName)); |
| 244 |
memcpy(expName, |
| 245 |
tinfo->indexes->next_variable->val.string, |
| 246 |
tinfo->indexes->next_variable->val_len); |
| 247 |
vp = tinfo->indexes->next_variable->next_variable; |
| 248 |
objIndex = *vp->val.integer; |
| 249 |
|
| 250 |
row = expObject_createRow(expOwner, expName, objIndex, 0); |
| 251 |
if (!row) { |
| 252 |
netsnmp_set_request_error(reqinfo, request, |
| 253 |
SNMP_ERR_RESOURCEUNAVAILABLE); |
| 254 |
return SNMP_ERR_NOERROR; |
| 255 |
} |
| 256 |
netsnmp_insert_tdata_row( request, row ); |
| 257 |
} |
| 258 |
} |
| 259 |
} |
| 260 |
break; |
| 261 |
|
| 262 |
case MODE_SET_FREE: |
| 263 |
for (request = requests; request; request = request->next) { |
| 264 |
if (request->processed) |
| 265 |
continue; |
| 266 |
|
| 267 |
tinfo = netsnmp_extract_table_info(request); |
| 268 |
|
| 269 |
switch (tinfo->colnum) { |
| 270 |
case COLUMN_EXPOBJECTENTRYSTATUS: |
| 271 |
switch (*request->requestvb->val.integer) { |
| 272 |
case RS_CREATEANDGO: |
| 273 |
case RS_CREATEANDWAIT: |
| 274 |
/* |
| 275 |
* Tidy up after a failed row creation request |
| 276 |
*/ |
| 277 |
entry = (struct expObject *) |
| 278 |
netsnmp_tdata_extract_entry(request); |
| 279 |
if (entry && |
| 280 |
!(entry->flags & EXP_OBJ_FLAG_VALID)) { |
| 281 |
row = (netsnmp_tdata_row *) |
| 282 |
netsnmp_tdata_extract_row(request); |
| 283 |
expObject_removeEntry( row ); |
| 284 |
} |
| 285 |
} |
| 286 |
} |
| 287 |
} |
| 288 |
break; |
| 289 |
|
| 290 |
case MODE_SET_ACTION: |
| 291 |
for (request = requests; request; request = request->next) { |
| 292 |
if (request->processed) |
| 293 |
continue; |
| 294 |
|
| 295 |
tinfo = netsnmp_extract_table_info(request); |
| 296 |
entry = (struct expObject *) |
| 297 |
netsnmp_tdata_extract_entry(request); |
| 298 |
if (!entry && tinfo->colnum != COLUMN_EXPOBJECTENTRYSTATUS && |
| 299 |
*request->requestvb->val.integer != RS_DESTROY) { |
| 300 |
/* |
| 301 |
* New rows must be created via the RowStatus column |
| 302 |
*/ |
| 303 |
netsnmp_set_request_error(reqinfo, request, |
| 304 |
SNMP_ERR_NOCREATION); |
| 305 |
/* or inconsistentName? */ |
| 306 |
return SNMP_ERR_NOERROR; |
| 307 |
|
| 308 |
} |
| 309 |
} |
| 310 |
break; |
| 311 |
|
| 312 |
case MODE_SET_UNDO: |
| 313 |
break; |
| 314 |
|
| 315 |
case MODE_SET_COMMIT: |
| 316 |
/* |
| 317 |
* All these assignments are "unfailable", so it's |
| 318 |
* (reasonably) safe to apply them in the Commit phase |
| 319 |
*/ |
| 320 |
ret = 0; /* Flag to re-check expExpressionPrefix settings */ |
| 321 |
for (request = requests; request; request = request->next) { |
| 322 |
if (request->processed) |
| 323 |
continue; |
| 324 |
|
| 325 |
entry = (struct expObject *) netsnmp_tdata_extract_entry(request); |
| 326 |
tinfo = netsnmp_extract_table_info(request); |
| 327 |
|
| 328 |
switch (tinfo->colnum) { |
| 329 |
case COLUMN_EXPOBJECTID: |
| 330 |
memset(entry->expObjectID, 0, sizeof(entry->expObjectID)); |
| 331 |
memcpy(entry->expObjectID, request->requestvb->val.string, |
| 332 |
request->requestvb->val_len); |
| 333 |
entry->expObjectID_len = request->requestvb->val_len/sizeof(oid); |
| 334 |
break; |
| 335 |
case COLUMN_EXPOBJECTIDWILDCARD: |
| 336 |
if (*request->requestvb->val.integer == TV_TRUE) |
| 337 |
entry->flags |= EXP_OBJ_FLAG_OWILD; |
| 338 |
else |
| 339 |
entry->flags &= ~EXP_OBJ_FLAG_OWILD; |
| 340 |
break; |
| 341 |
case COLUMN_EXPOBJECTSAMPLETYPE: |
| 342 |
entry->expObjectSampleType = *request->requestvb->val.integer; |
| 343 |
break; |
| 344 |
case COLUMN_EXPOBJECTDELTADISCONTINUITYID: |
| 345 |
memset(entry->expObjDeltaD, 0, sizeof(entry->expObjDeltaD)); |
| 346 |
memcpy(entry->expObjDeltaD, request->requestvb->val.string, |
| 347 |
request->requestvb->val_len); |
| 348 |
entry->expObjDeltaD_len = request->requestvb->val_len/sizeof(oid); |
| 349 |
/* XXX |
| 350 |
if ( snmp_oid_compare( entry->expObjDeltaD, |
| 351 |
entry->expObjDeltaD_len, |
| 352 |
sysUpTime_inst, |
| 353 |
sysUpTime_inst_len ) != 0 ) |
| 354 |
entry->flags |= EXP_OBJ_FLAG_DDISC; |
| 355 |
*/ |
| 356 |
|
| 357 |
/* |
| 358 |
* If the OID used for the expExpressionPrefix object |
| 359 |
* has changed, then update the expression structure. |
| 360 |
*/ |
| 361 |
if ( entry->flags & EXP_OBJ_FLAG_PREFIX ) { |
| 362 |
exp = expExpression_getEntry( entry->expOwner, |
| 363 |
entry->expName ); |
| 364 |
memcpy( exp->expPrefix, entry->expObjDeltaD, |
| 365 |
MAX_OID_LEN*sizeof(oid)); |
| 366 |
exp->expPrefix_len = entry->expObjDeltaD_len; |
| 367 |
} |
| 368 |
break; |
| 369 |
case COLUMN_EXPOBJECTDISCONTINUITYIDWILDCARD: |
| 370 |
if (*request->requestvb->val.integer == TV_TRUE) { |
| 371 |
/* |
| 372 |
* Possible new prefix OID candidate |
| 373 |
* Can't set the value here, since the OID |
| 374 |
* assignment might not have been processed yet. |
| 375 |
*/ |
| 376 |
exp = expExpression_getEntry( entry->expOwner, |
| 377 |
entry->expName ); |
| 378 |
if (exp && exp->expPrefix_len == 0 ) |
| 379 |
ret = 1; /* Set the prefix later */ |
| 380 |
entry->flags |= EXP_OBJ_FLAG_DWILD; |
| 381 |
} else { |
| 382 |
if ( entry->flags & EXP_OBJ_FLAG_PREFIX ) { |
| 383 |
exp = expExpression_getEntry( entry->expOwner, |
| 384 |
entry->expName ); |
| 385 |
memset( exp->expPrefix, 0, MAX_OID_LEN*sizeof(oid)); |
| 386 |
exp->expPrefix_len = 0; |
| 387 |
ret = 1; /* Need a new prefix OID */ |
| 388 |
} |
| 389 |
entry->flags &= ~EXP_OBJ_FLAG_DWILD; |
| 390 |
} |
| 391 |
break; |
| 392 |
case COLUMN_EXPOBJECTDISCONTINUITYIDTYPE: |
| 393 |
entry->expObjDiscontinuityType = |
| 394 |
*request->requestvb->val.integer; |
| 395 |
break; |
| 396 |
case COLUMN_EXPOBJECTCONDITIONAL: |
| 397 |
memset(entry->expObjCond, 0, sizeof(entry->expObjCond)); |
| 398 |
memcpy(entry->expObjCond, request->requestvb->val.string, |
| 399 |
request->requestvb->val_len); |
| 400 |
entry->expObjCond_len = request->requestvb->val_len/sizeof(oid); |
| 401 |
break; |
| 402 |
case COLUMN_EXPOBJECTCONDITIONALWILDCARD: |
| 403 |
if (*request->requestvb->val.integer == TV_TRUE) |
| 404 |
entry->flags |= EXP_OBJ_FLAG_CWILD; |
| 405 |
else |
| 406 |
entry->flags &= ~EXP_OBJ_FLAG_CWILD; |
| 407 |
break; |
| 408 |
case COLUMN_EXPOBJECTENTRYSTATUS: |
| 409 |
switch (*request->requestvb->val.integer) { |
| 410 |
case RS_ACTIVE: |
| 411 |
entry->flags |= EXP_OBJ_FLAG_ACTIVE; |
| 412 |
break; |
| 413 |
case RS_NOTINSERVICE: |
| 414 |
entry->flags &= ~EXP_OBJ_FLAG_ACTIVE; |
| 415 |
break; |
| 416 |
case RS_CREATEANDGO: |
| 417 |
entry->flags |= EXP_OBJ_FLAG_ACTIVE; |
| 418 |
entry->flags |= EXP_OBJ_FLAG_VALID; |
| 419 |
break; |
| 420 |
case RS_CREATEANDWAIT: |
| 421 |
entry->flags |= EXP_OBJ_FLAG_VALID; |
| 422 |
break; |
| 423 |
|
| 424 |
case RS_DESTROY: |
| 425 |
row = (netsnmp_tdata_row *) |
| 426 |
netsnmp_tdata_extract_row(request); |
| 427 |
expObject_removeEntry(row); |
| 428 |
} |
| 429 |
} |
| 430 |
} |
| 431 |
|
| 432 |
/* |
| 433 |
* Need to check for changes in expExpressionPrefix handling |
| 434 |
*/ |
| 435 |
for (request = requests; request; request = request->next) { |
| 436 |
entry = (struct expObject *) netsnmp_tdata_extract_entry(request); |
| 437 |
tinfo = netsnmp_extract_table_info(request); |
| 438 |
|
| 439 |
switch (tinfo->colnum) { |
| 440 |
case COLUMN_EXPOBJECTDISCONTINUITYIDWILDCARD: |
| 441 |
/* |
| 442 |
* If a column has just been marked as wild, |
| 443 |
* then consider using it as the prefix OID |
| 444 |
*/ |
| 445 |
if (*request->requestvb->val.integer == TV_TRUE) { |
| 446 |
exp = expExpression_getEntry( entry->expOwner, |
| 447 |
entry->expName ); |
| 448 |
if ( exp->expPrefix_len == 0 ) { |
| 449 |
memcpy( exp->expPrefix, entry->expObjDeltaD, |
| 450 |
MAX_OID_LEN*sizeof(oid)); |
| 451 |
exp->expPrefix_len = entry->expObjDeltaD_len; |
| 452 |
entry->flags |= EXP_OBJ_FLAG_PREFIX; |
| 453 |
} |
| 454 |
} |
| 455 |
/* |
| 456 |
* If it's just been marked as non-wildcarded |
| 457 |
* then we need to look for a new candidate. |
| 458 |
*/ |
| 459 |
else { |
| 460 |
|
| 461 |
} |
| 462 |
break; |
| 463 |
} |
| 464 |
} |
| 465 |
break; |
| 466 |
} |
| 467 |
DEBUGMSGTL(("disman:expr:mib", "Expression Object handler - done \n")); |
| 468 |
return SNMP_ERR_NOERROR; |
| 469 |
} |