| 1 |
/* |
| 2 |
* DisMan Expression MIB: |
| 3 |
* Implementation of the expExpressionTable MIB interface |
| 4 |
* See 'expExpression.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 "utilities/iquery.h" |
| 14 |
#include "disman/expr/expExpression.h" |
| 15 |
#include "disman/expr/expExpressionTable.h" |
| 16 |
|
| 17 |
netsnmp_feature_require(iquery); |
| 18 |
netsnmp_feature_require(table_tdata); |
| 19 |
#ifndef NETSNMP_NO_WRITE_SUPPORT |
| 20 |
netsnmp_feature_require(check_vb_type_and_max_size); |
| 21 |
netsnmp_feature_require(table_tdata_insert_row); |
| 22 |
netsnmp_feature_require(iquery_pdu_session); |
| 23 |
#endif /* NETSNMP_NO_WRITE_SUPPORT */ |
| 24 |
|
| 25 |
static Netsnmp_Node_Handler expExpressionTable_handler; |
| 26 |
|
| 27 |
static netsnmp_handler_registration *expr_table_reg; |
| 28 |
static netsnmp_table_registration_info *expr_table_info; |
| 29 |
|
| 30 |
/* Initializes the expExpressionTable module */ |
| 31 |
void |
| 32 |
init_expExpressionTable(void) |
| 33 |
{ |
| 34 |
static oid expExpressionTable_oid[] = { 1, 3, 6, 1, 2, 1, 90, 1, 2, 1 }; |
| 35 |
size_t expExpressionTable_oid_len = OID_LENGTH(expExpressionTable_oid); |
| 36 |
|
| 37 |
/* |
| 38 |
* Ensure the expression table container is available... |
| 39 |
*/ |
| 40 |
init_expr_table_data(); |
| 41 |
|
| 42 |
/* |
| 43 |
* ... then set up the MIB interface to the expExpressionTable slice |
| 44 |
*/ |
| 45 |
expr_table_reg = netsnmp_create_handler_registration("expExpressionTable", |
| 46 |
expExpressionTable_handler, |
| 47 |
expExpressionTable_oid, |
| 48 |
expExpressionTable_oid_len, |
| 49 |
HANDLER_CAN_RWRITE); |
| 50 |
|
| 51 |
expr_table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); |
| 52 |
netsnmp_table_helper_add_indexes(expr_table_info, |
| 53 |
/* index: expExpressionOwner */ |
| 54 |
ASN_OCTET_STR, |
| 55 |
/* index: expExpressionName */ |
| 56 |
ASN_OCTET_STR, |
| 57 |
0); |
| 58 |
|
| 59 |
expr_table_info->min_column = COLUMN_EXPEXPRESSION; |
| 60 |
expr_table_info->max_column = COLUMN_EXPEXPRESSIONENTRYSTATUS; |
| 61 |
|
| 62 |
/* Register this using the (common) expr_table_data container */ |
| 63 |
netsnmp_tdata_register(expr_table_reg, expr_table_data, expr_table_info); |
| 64 |
DEBUGMSGTL(("disman:expr:init", "Expression Table container (%p)\n", |
| 65 |
expr_table_data)); |
| 66 |
} |
| 67 |
|
| 68 |
void |
| 69 |
shutdown_expExpressionTable(void) |
| 70 |
{ |
| 71 |
netsnmp_tdata_unregister(expr_table_reg); |
| 72 |
netsnmp_table_registration_info_free(expr_table_info); |
| 73 |
} |
| 74 |
|
| 75 |
/** handles requests for the expExpressionTable table */ |
| 76 |
int |
| 77 |
expExpressionTable_handler(netsnmp_mib_handler *handler, |
| 78 |
netsnmp_handler_registration *reginfo, |
| 79 |
netsnmp_agent_request_info *reqinfo, |
| 80 |
netsnmp_request_info *requests) |
| 81 |
{ |
| 82 |
|
| 83 |
netsnmp_request_info *request; |
| 84 |
netsnmp_table_request_info *tinfo; |
| 85 |
netsnmp_tdata_row *row; |
| 86 |
struct expExpression *entry; |
| 87 |
char expOwner[EXP_STR1_LEN+1]; |
| 88 |
char expName[ EXP_STR1_LEN+1]; |
| 89 |
long ret; |
| 90 |
|
| 91 |
DEBUGMSGTL(("disman:expr:mib", "Expression Table handler (%d)\n", |
| 92 |
reqinfo->mode)); |
| 93 |
|
| 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 expExpression *) |
| 104 |
netsnmp_tdata_extract_entry(request); |
| 105 |
tinfo = netsnmp_extract_table_info(request); |
| 106 |
if (!entry || !(entry->flags & EXP_FLAG_VALID)) |
| 107 |
continue; |
| 108 |
|
| 109 |
switch (tinfo->colnum) { |
| 110 |
case COLUMN_EXPEXPRESSION: |
| 111 |
snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, |
| 112 |
(u_char*)entry->expExpression, |
| 113 |
strlen(entry->expExpression)); |
| 114 |
break; |
| 115 |
case COLUMN_EXPEXPRESSIONVALUETYPE: |
| 116 |
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, |
| 117 |
entry->expValueType); |
| 118 |
break; |
| 119 |
case COLUMN_EXPEXPRESSIONCOMMENT: |
| 120 |
snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, |
| 121 |
(u_char*)entry->expComment, |
| 122 |
strlen(entry->expComment)); |
| 123 |
break; |
| 124 |
case COLUMN_EXPEXPRESSIONDELTAINTERVAL: |
| 125 |
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, |
| 126 |
entry->expDeltaInterval); |
| 127 |
break; |
| 128 |
case COLUMN_EXPEXPRESSIONPREFIX: |
| 129 |
/* |
| 130 |
* XXX - Need to search expObjectTable for a suitable OID |
| 131 |
*/ |
| 132 |
/* |
| 133 |
* Empty OIDs (len=0) are converted into .0.0 |
| 134 |
* by the SNMP library automatically :-( |
| 135 |
*/ |
| 136 |
if ( entry->expPrefix_len ) { |
| 137 |
snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID, |
| 138 |
(u_char *) entry->expPrefix, |
| 139 |
entry->expPrefix_len*sizeof(oid)); |
| 140 |
} else { |
| 141 |
/* XXX - possibly not needed */ |
| 142 |
request->requestvb->type = ASN_OBJECT_ID; |
| 143 |
request->requestvb->val_len = 0; |
| 144 |
} |
| 145 |
break; |
| 146 |
case COLUMN_EXPEXPRESSIONERRORS: |
| 147 |
snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, |
| 148 |
entry->expErrorCount); |
| 149 |
break; |
| 150 |
case COLUMN_EXPEXPRESSIONENTRYSTATUS: |
| 151 |
/* What would indicate 'notReady' ? */ |
| 152 |
ret = (entry->flags & EXP_FLAG_ACTIVE) ? |
| 153 |
RS_ACTIVE : RS_NOTINSERVICE; |
| 154 |
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret); |
| 155 |
break; |
| 156 |
} |
| 157 |
} |
| 158 |
break; |
| 159 |
|
| 160 |
/* |
| 161 |
* Write-support |
| 162 |
*/ |
| 163 |
case MODE_SET_RESERVE1: |
| 164 |
for (request = requests; request; request = request->next) { |
| 165 |
if (request->processed) |
| 166 |
continue; |
| 167 |
|
| 168 |
entry = (struct expExpression *) |
| 169 |
netsnmp_tdata_extract_entry(request); |
| 170 |
tinfo = netsnmp_extract_table_info(request); |
| 171 |
|
| 172 |
switch (tinfo->colnum) { |
| 173 |
case COLUMN_EXPEXPRESSION: |
| 174 |
ret = netsnmp_check_vb_type_and_max_size( |
| 175 |
request->requestvb, ASN_OCTET_STR, EXP_STR3_LEN); |
| 176 |
/* XXX - check new expression is syntactically valid */ |
| 177 |
if (ret != SNMP_ERR_NOERROR) { |
| 178 |
netsnmp_set_request_error(reqinfo, request, ret); |
| 179 |
return SNMP_ERR_NOERROR; |
| 180 |
} |
| 181 |
break; |
| 182 |
case COLUMN_EXPEXPRESSIONVALUETYPE: |
| 183 |
ret = netsnmp_check_vb_int_range(request->requestvb, 1, 8); |
| 184 |
if (ret != SNMP_ERR_NOERROR) { |
| 185 |
netsnmp_set_request_error(reqinfo, request, ret); |
| 186 |
return SNMP_ERR_NOERROR; |
| 187 |
} |
| 188 |
break; |
| 189 |
case COLUMN_EXPEXPRESSIONCOMMENT: |
| 190 |
ret = netsnmp_check_vb_type_and_max_size( |
| 191 |
request->requestvb, ASN_OCTET_STR, EXP_STR2_LEN); |
| 192 |
if (ret != SNMP_ERR_NOERROR) { |
| 193 |
netsnmp_set_request_error(reqinfo, request, ret); |
| 194 |
return SNMP_ERR_NOERROR; |
| 195 |
} |
| 196 |
break; |
| 197 |
case COLUMN_EXPEXPRESSIONDELTAINTERVAL: |
| 198 |
ret = netsnmp_check_vb_int_range(request->requestvb, 0, 86400); |
| 199 |
if (ret != SNMP_ERR_NOERROR) { |
| 200 |
netsnmp_set_request_error(reqinfo, request, ret); |
| 201 |
return SNMP_ERR_NOERROR; |
| 202 |
} |
| 203 |
break; |
| 204 |
case COLUMN_EXPEXPRESSIONENTRYSTATUS: |
| 205 |
ret = netsnmp_check_vb_rowstatus(request->requestvb, |
| 206 |
(entry ? RS_ACTIVE : RS_NONEXISTENT)); |
| 207 |
if (ret != SNMP_ERR_NOERROR) { |
| 208 |
netsnmp_set_request_error(reqinfo, request, ret); |
| 209 |
return SNMP_ERR_NOERROR; |
| 210 |
} |
| 211 |
break; |
| 212 |
default: |
| 213 |
netsnmp_set_request_error(reqinfo, request, |
| 214 |
SNMP_ERR_NOTWRITABLE); |
| 215 |
return SNMP_ERR_NOERROR; |
| 216 |
} |
| 217 |
} |
| 218 |
break; |
| 219 |
|
| 220 |
case MODE_SET_RESERVE2: |
| 221 |
for (request = requests; request; request = request->next) { |
| 222 |
if (request->processed) |
| 223 |
continue; |
| 224 |
|
| 225 |
tinfo = netsnmp_extract_table_info(request); |
| 226 |
|
| 227 |
switch (tinfo->colnum) { |
| 228 |
case COLUMN_EXPEXPRESSIONENTRYSTATUS: |
| 229 |
switch (*request->requestvb->val.integer) { |
| 230 |
case RS_CREATEANDGO: |
| 231 |
case RS_CREATEANDWAIT: |
| 232 |
/* |
| 233 |
* Create an (empty) new row structure |
| 234 |
*/ |
| 235 |
memset(expOwner, 0, sizeof(expOwner)); |
| 236 |
memcpy(expOwner, tinfo->indexes->val.string, |
| 237 |
tinfo->indexes->val_len); |
| 238 |
memset(expName, 0, sizeof(expName)); |
| 239 |
memcpy(expName, |
| 240 |
tinfo->indexes->next_variable->val.string, |
| 241 |
tinfo->indexes->next_variable->val_len); |
| 242 |
|
| 243 |
row = expExpression_createRow(expOwner, expName, 0); |
| 244 |
if (!row) { |
| 245 |
netsnmp_set_request_error(reqinfo, request, |
| 246 |
SNMP_ERR_RESOURCEUNAVAILABLE); |
| 247 |
return SNMP_ERR_NOERROR; |
| 248 |
} |
| 249 |
netsnmp_insert_tdata_row( request, row ); |
| 250 |
} |
| 251 |
} |
| 252 |
} |
| 253 |
break; |
| 254 |
|
| 255 |
case MODE_SET_FREE: |
| 256 |
for (request = requests; request; request = request->next) { |
| 257 |
if (request->processed) |
| 258 |
continue; |
| 259 |
|
| 260 |
tinfo = netsnmp_extract_table_info(request); |
| 261 |
|
| 262 |
switch (tinfo->colnum) { |
| 263 |
case COLUMN_EXPEXPRESSIONENTRYSTATUS: |
| 264 |
switch (*request->requestvb->val.integer) { |
| 265 |
case RS_CREATEANDGO: |
| 266 |
case RS_CREATEANDWAIT: |
| 267 |
/* |
| 268 |
* Tidy up after a failed row creation request |
| 269 |
*/ |
| 270 |
entry = (struct expExpression *) |
| 271 |
netsnmp_tdata_extract_entry(request); |
| 272 |
if (entry && |
| 273 |
!(entry->flags & EXP_FLAG_VALID)) { |
| 274 |
row = (netsnmp_tdata_row *) |
| 275 |
netsnmp_tdata_extract_row(request); |
| 276 |
expExpression_removeEntry( row ); |
| 277 |
} |
| 278 |
} |
| 279 |
} |
| 280 |
} |
| 281 |
break; |
| 282 |
|
| 283 |
case MODE_SET_ACTION: |
| 284 |
for (request = requests; request; request = request->next) { |
| 285 |
if (request->processed) |
| 286 |
continue; |
| 287 |
|
| 288 |
tinfo = netsnmp_extract_table_info(request); |
| 289 |
entry = (struct expExpression *) |
| 290 |
netsnmp_tdata_extract_entry(request); |
| 291 |
if (!entry && tinfo->colnum != COLUMN_EXPEXPRESSIONENTRYSTATUS && |
| 292 |
*request->requestvb->val.integer != RS_DESTROY) { |
| 293 |
/* |
| 294 |
* New rows must be created via the RowStatus column |
| 295 |
*/ |
| 296 |
netsnmp_set_request_error(reqinfo, request, |
| 297 |
SNMP_ERR_NOCREATION); |
| 298 |
/* or inconsistentName? */ |
| 299 |
return SNMP_ERR_NOERROR; |
| 300 |
|
| 301 |
} |
| 302 |
} |
| 303 |
break; |
| 304 |
|
| 305 |
case MODE_SET_UNDO: |
| 306 |
break; |
| 307 |
|
| 308 |
case MODE_SET_COMMIT: |
| 309 |
/* |
| 310 |
* All these assignments are "unfailable", so it's |
| 311 |
* (reasonably) safe to apply them in the Commit phase |
| 312 |
*/ |
| 313 |
for (request = requests; request; request = request->next) { |
| 314 |
if (request->processed) |
| 315 |
continue; |
| 316 |
|
| 317 |
entry = (struct expExpression *) |
| 318 |
netsnmp_tdata_extract_entry(request); |
| 319 |
tinfo = netsnmp_extract_table_info(request); |
| 320 |
|
| 321 |
switch (tinfo->colnum) { |
| 322 |
case COLUMN_EXPEXPRESSION: |
| 323 |
memset(entry->expExpression, 0, EXP_STR3_LEN+1); |
| 324 |
memcpy(entry->expExpression, |
| 325 |
request->requestvb->val.string, |
| 326 |
request->requestvb->val_len); |
| 327 |
break; |
| 328 |
case COLUMN_EXPEXPRESSIONVALUETYPE: |
| 329 |
entry->expValueType = *request->requestvb->val.integer; |
| 330 |
break; |
| 331 |
case COLUMN_EXPEXPRESSIONCOMMENT: |
| 332 |
memset(entry->expComment, 0, EXP_STR2_LEN+1); |
| 333 |
memcpy(entry->expComment, |
| 334 |
request->requestvb->val.string, |
| 335 |
request->requestvb->val_len); |
| 336 |
break; |
| 337 |
case COLUMN_EXPEXPRESSIONDELTAINTERVAL: |
| 338 |
entry->expDeltaInterval = *request->requestvb->val.integer; |
| 339 |
break; |
| 340 |
case COLUMN_EXPEXPRESSIONENTRYSTATUS: |
| 341 |
switch (*request->requestvb->val.integer) { |
| 342 |
case RS_ACTIVE: |
| 343 |
entry->flags |= EXP_FLAG_ACTIVE; |
| 344 |
expExpression_enable( entry ); |
| 345 |
break; |
| 346 |
case RS_NOTINSERVICE: |
| 347 |
entry->flags &= ~EXP_FLAG_ACTIVE; |
| 348 |
expExpression_disable( entry ); |
| 349 |
break; |
| 350 |
case RS_CREATEANDGO: |
| 351 |
entry->flags |= EXP_FLAG_ACTIVE; |
| 352 |
entry->flags |= EXP_FLAG_VALID; |
| 353 |
entry->session = |
| 354 |
netsnmp_iquery_pdu_session(reqinfo->asp->pdu); |
| 355 |
expExpression_enable( entry ); |
| 356 |
break; |
| 357 |
case RS_CREATEANDWAIT: |
| 358 |
entry->flags |= EXP_FLAG_VALID; |
| 359 |
entry->session = |
| 360 |
netsnmp_iquery_pdu_session(reqinfo->asp->pdu); |
| 361 |
break; |
| 362 |
|
| 363 |
case RS_DESTROY: |
| 364 |
row = (netsnmp_tdata_row *) |
| 365 |
netsnmp_tdata_extract_row(request); |
| 366 |
expExpression_removeEntry(row); |
| 367 |
} |
| 368 |
} |
| 369 |
} |
| 370 |
break; |
| 371 |
} |
| 372 |
DEBUGMSGTL(("disman:expr:mib", "Expression Table handler - done \n")); |
| 373 |
return SNMP_ERR_NOERROR; |
| 374 |
} |