net-snmp 5.7
|
00001 /* 00002 * Note: this file originally auto-generated by mib2c using 00003 * : mib2c.iterate_access.conf,v 1.4 2003/07/01 00:15:11 hardaker Exp $ 00004 */ 00005 00006 #include <net-snmp/net-snmp-config.h> 00007 #include <net-snmp/net-snmp-features.h> 00008 #include <net-snmp/net-snmp-includes.h> 00009 #include <net-snmp/agent/net-snmp-agent-includes.h> 00010 #include "netSnmpHostsTable.h" 00011 #include "netSnmpHostsTable_checkfns.h" 00012 #include "netSnmpHostsTable_access.h" 00013 00014 netsnmp_feature_require(oid_stash) 00015 netsnmp_feature_require(oid_stash_get_data) 00016 netsnmp_feature_require(oid_stash_add_data) 00017 00018 static netsnmp_oid_stash_node *undoStorage = NULL; 00019 static netsnmp_oid_stash_node *commitStorage = NULL; 00020 00021 struct undoInfo { 00022 void *ptr; 00023 size_t len; 00024 }; 00025 00026 struct commitInfo { 00027 void *data_context; 00028 int have_committed; 00029 int new_row; 00030 }; 00031 00032 void 00033 netSnmpHostsTable_free_undoInfo(void *vptr) 00034 { 00035 struct undoInfo *ui = vptr; 00036 if (!ui) 00037 return; 00038 SNMP_FREE(ui->ptr); 00039 SNMP_FREE(ui); 00040 } 00041 00043 void 00044 initialize_table_netSnmpHostsTable(void) 00045 { 00046 static oid netSnmpHostsTable_oid[] = 00047 { 1, 3, 6, 1, 4, 1, 8072, 2, 2, 2 }; 00048 netsnmp_table_registration_info *table_info; 00049 netsnmp_handler_registration *my_handler; 00050 netsnmp_iterator_info *iinfo; 00051 00053 table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); 00054 iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info); 00055 00058 my_handler = netsnmp_create_handler_registration("netSnmpHostsTable", 00059 netSnmpHostsTable_handler, 00060 netSnmpHostsTable_oid, 00061 OID_LENGTH 00062 (netSnmpHostsTable_oid), 00063 HANDLER_CAN_RWRITE); 00064 00065 if (!my_handler || !table_info || !iinfo) { 00066 snmp_log(LOG_ERR, 00067 "malloc failed in initialize_table_netSnmpHostsTable"); 00068 return; 00069 } 00070 00071 /*************************************************** 00072 * Setting up the table's definition 00073 */ 00074 netsnmp_table_helper_add_indexes(table_info, ASN_OCTET_STR, 00076 0); 00077 00080 table_info->min_column = 2; 00081 table_info->max_column = 5; 00082 00084 iinfo->get_first_data_point = netSnmpHostsTable_get_first_data_point; 00085 iinfo->get_next_data_point = netSnmpHostsTable_get_next_data_point; 00086 00088 iinfo->make_data_context = netSnmpHostsTable_context_convert_function; 00089 iinfo->free_data_context = netSnmpHostsTable_data_free; 00090 iinfo->free_loop_context_at_end = netSnmpHostsTable_loop_free; 00091 00093 iinfo->table_reginfo = table_info; 00094 00095 /*************************************************** 00096 * registering the table with the master agent 00097 */ 00098 DEBUGMSGTL(("initialize_table_netSnmpHostsTable", 00099 "Registering table netSnmpHostsTable as a table iterator\n")); 00100 netsnmp_register_table_iterator2(my_handler, iinfo); 00101 } 00102 00104 void 00105 init_netSnmpHostsTable(void) 00106 { 00107 00109 initialize_table_netSnmpHostsTable(); 00110 } 00111 00113 int 00114 netSnmpHostsTable_handler(netsnmp_mib_handler *handler, 00115 netsnmp_handler_registration *reginfo, 00116 netsnmp_agent_request_info *reqinfo, 00117 netsnmp_request_info *requests) 00118 { 00119 00120 netsnmp_request_info *request; 00121 netsnmp_table_request_info *table_info; 00122 struct commitInfo *ci = NULL; 00123 00124 void *data_context = NULL; 00125 00126 for (request = requests; request; request = request->next) { 00127 /* column and row index encoded portion */ 00128 netsnmp_variable_list *var = request->requestvb; 00129 const oid * const suffix = var->name + reginfo->rootoid_len + 1; 00130 const size_t suffix_len = var->name_length - (reginfo->rootoid_len + 1); 00131 00132 if (request->processed != 0) 00133 continue; 00134 00135 switch (reqinfo->mode) { 00136 case MODE_GET: 00137 case MODE_SET_RESERVE1: 00138 data_context = netsnmp_extract_iterator_context(request); 00139 if (data_context == NULL) { 00140 if (reqinfo->mode == MODE_GET) { 00141 netsnmp_set_request_error(reqinfo, request, 00142 SNMP_NOSUCHINSTANCE); 00143 continue; 00144 } 00145 } 00146 break; 00147 00148 default: /* == the other SET modes */ 00149 ci = netsnmp_oid_stash_get_data(commitStorage, 00150 suffix + 1, suffix_len - 1); 00151 break; 00152 00153 } 00154 00156 table_info = netsnmp_extract_table_info(request); 00162 if (table_info == NULL) { 00163 continue; 00164 } 00165 00166 switch (reqinfo->mode) { 00167 case MODE_GET: 00168 switch (table_info->colnum) { 00169 case COLUMN_NETSNMPHOSTADDRESSTYPE: 00170 { 00171 long *retval; 00172 size_t retval_len = 0; 00173 retval = 00174 get_netSnmpHostAddressType(data_context, 00175 &retval_len); 00176 snmp_set_var_typed_value(var, ASN_INTEGER, 00177 (const u_char *) retval, 00178 retval_len); 00179 } 00180 break; 00181 00182 case COLUMN_NETSNMPHOSTADDRESS: 00183 { 00184 char *retval; 00185 size_t retval_len = 0; 00186 retval = 00187 get_netSnmpHostAddress(data_context, &retval_len); 00188 snmp_set_var_typed_value(var, ASN_OCTET_STR, 00189 (const u_char *) retval, 00190 retval_len); 00191 } 00192 break; 00193 00194 case COLUMN_NETSNMPHOSTSTORAGE: 00195 { 00196 long *retval; 00197 size_t retval_len = 0; 00198 retval = 00199 get_netSnmpHostStorage(data_context, &retval_len); 00200 snmp_set_var_typed_value(var, ASN_INTEGER, 00201 (const u_char *) retval, 00202 retval_len); 00203 } 00204 break; 00205 00206 case COLUMN_NETSNMPHOSTROWSTATUS: 00207 { 00208 long *retval; 00209 size_t retval_len = 0; 00210 retval = 00211 get_netSnmpHostRowStatus(data_context, 00212 &retval_len); 00213 snmp_set_var_typed_value(var, ASN_INTEGER, 00214 (const u_char *) retval, 00215 retval_len); 00216 } 00217 break; 00218 00219 default: 00221 snmp_log(LOG_ERR, 00222 "problem encountered in netSnmpHostsTable_handler: unknown column\n"); 00223 } 00224 break; 00225 00226 case MODE_SET_RESERVE1: 00227 ci = netsnmp_oid_stash_get_data(commitStorage, 00228 suffix + 1, suffix_len - 1); 00229 00230 if (!ci) { 00232 ci = SNMP_MALLOC_STRUCT(commitInfo); 00233 if (!data_context) { 00234 ci->data_context = 00235 netSnmpHostsTable_create_data_context(table_info-> 00236 indexes); 00237 ci->new_row = 1; 00238 } else { 00239 ci->data_context = data_context; 00240 } 00241 netsnmp_oid_stash_add_data(&commitStorage, 00242 suffix + 1, suffix_len - 1, ci); 00243 } 00244 break; 00245 00246 case MODE_SET_RESERVE2: 00247 switch (table_info->colnum) { 00248 case COLUMN_NETSNMPHOSTADDRESSTYPE: 00249 { 00250 long *retval; 00251 size_t retval_len = 0; 00252 struct undoInfo *ui = NULL; 00253 int ret; 00254 00256 retval = 00257 get_netSnmpHostAddressType(ci->data_context, 00258 &retval_len); 00259 if (retval) { 00260 ui = SNMP_MALLOC_STRUCT(undoInfo); 00261 ui->len = retval_len; 00262 memdup((u_char **) & ui->ptr, 00263 (u_char *) retval, ui->len); 00264 } 00265 00268 ret = 00269 check_netSnmpHostAddressType(request->requestvb-> 00270 type, 00271 (long *) request-> 00272 requestvb->val.string, 00273 request->requestvb-> 00274 val_len, retval, 00275 retval_len); 00276 if (ret != 0) { 00277 netsnmp_set_request_error(reqinfo, request, ret); 00278 netSnmpHostsTable_free_undoInfo(ui); 00279 } else if (ui) { 00281 netsnmp_oid_stash_add_data(&undoStorage, 00282 suffix, suffix_len, ui); 00283 } 00284 00285 } 00286 break; 00287 case COLUMN_NETSNMPHOSTADDRESS: 00288 { 00289 char *retval; 00290 size_t retval_len = 0; 00291 struct undoInfo *ui = NULL; 00292 int ret; 00293 00295 retval = 00296 get_netSnmpHostAddress(ci->data_context, 00297 &retval_len); 00298 if (retval) { 00299 ui = SNMP_MALLOC_STRUCT(undoInfo); 00300 ui->len = retval_len; 00301 memdup((u_char **) & ui->ptr, 00302 (u_char *) retval, ui->len); 00303 } 00304 00307 ret = 00308 check_netSnmpHostAddress(request->requestvb->type, 00309 (char *) request-> 00310 requestvb->val.string, 00311 request->requestvb-> 00312 val_len, retval, 00313 retval_len); 00314 if (ret != 0) { 00315 netsnmp_set_request_error(reqinfo, request, ret); 00316 netSnmpHostsTable_free_undoInfo(ui); 00317 } else if (ui) { 00319 netsnmp_oid_stash_add_data(&undoStorage, 00320 suffix, suffix_len, ui); 00321 } 00322 00323 } 00324 break; 00325 case COLUMN_NETSNMPHOSTSTORAGE: 00326 { 00327 long *retval; 00328 size_t retval_len = 0; 00329 struct undoInfo *ui = NULL; 00330 int ret; 00331 00333 retval = 00334 get_netSnmpHostStorage(ci->data_context, 00335 &retval_len); 00336 if (retval) { 00337 ui = SNMP_MALLOC_STRUCT(undoInfo); 00338 ui->len = retval_len; 00339 memdup((u_char **) & ui->ptr, 00340 (u_char *) retval, ui->len); 00341 } 00342 00345 ret = 00346 check_netSnmpHostStorage(request->requestvb->type, 00347 (long *) request-> 00348 requestvb->val.string, 00349 request->requestvb-> 00350 val_len, retval, 00351 retval_len); 00352 if (ret != 0) { 00353 netsnmp_set_request_error(reqinfo, request, ret); 00354 netSnmpHostsTable_free_undoInfo(ui); 00355 } else if (ui) { 00357 netsnmp_oid_stash_add_data(&undoStorage, 00358 suffix, suffix_len, ui); 00359 } 00360 00361 } 00362 break; 00363 case COLUMN_NETSNMPHOSTROWSTATUS: 00364 { 00365 long *retval; 00366 size_t retval_len = 0; 00367 struct undoInfo *ui = NULL; 00368 int ret; 00369 00371 retval = 00372 get_netSnmpHostRowStatus(ci->data_context, 00373 &retval_len); 00374 if (retval) { 00375 ui = SNMP_MALLOC_STRUCT(undoInfo); 00376 ui->len = retval_len; 00377 memdup((u_char **) & ui->ptr, 00378 (u_char *) retval, ui->len); 00379 } 00380 00383 ret = 00384 check_netSnmpHostRowStatus(request->requestvb-> 00385 type, 00386 (long *) request-> 00387 requestvb->val.string, 00388 request->requestvb-> 00389 val_len, retval, 00390 retval_len); 00391 if (ret != 0) { 00392 netsnmp_set_request_error(reqinfo, request, ret); 00393 netSnmpHostsTable_free_undoInfo(ui); 00394 } else if (ui) { 00396 netsnmp_oid_stash_add_data(&undoStorage, 00397 suffix, suffix_len, ui); 00398 } 00399 00400 } 00401 break; 00402 default: 00403 netsnmp_set_request_error(reqinfo, request, 00404 SNMP_ERR_NOTWRITABLE); 00405 break; 00406 } 00407 break; 00408 00409 case MODE_SET_ACTION: 00411 switch (table_info->colnum) { 00412 case COLUMN_NETSNMPHOSTADDRESSTYPE: 00413 { 00414 int ret; 00415 ret = set_netSnmpHostAddressType(ci->data_context, 00416 (long *) request-> 00417 requestvb->val.string, 00418 request->requestvb-> 00419 val_len); 00420 if (ret) { 00421 netsnmp_set_request_error(reqinfo, request, ret); 00422 } 00423 } 00424 break; 00425 case COLUMN_NETSNMPHOSTADDRESS: 00426 { 00427 int ret; 00428 ret = set_netSnmpHostAddress(ci->data_context, 00429 (char *) request-> 00430 requestvb->val.string, 00431 request->requestvb-> 00432 val_len); 00433 if (ret) { 00434 netsnmp_set_request_error(reqinfo, request, ret); 00435 } 00436 } 00437 break; 00438 case COLUMN_NETSNMPHOSTSTORAGE: 00439 { 00440 int ret; 00441 ret = set_netSnmpHostStorage(ci->data_context, 00442 (long *) request-> 00443 requestvb->val.string, 00444 request->requestvb-> 00445 val_len); 00446 if (ret) { 00447 netsnmp_set_request_error(reqinfo, request, ret); 00448 } 00449 } 00450 break; 00451 case COLUMN_NETSNMPHOSTROWSTATUS: 00452 { 00453 int ret; 00454 ret = set_netSnmpHostRowStatus(ci->data_context, 00455 (long *) request-> 00456 requestvb->val.string, 00457 request->requestvb-> 00458 val_len); 00459 if (ret) { 00460 netsnmp_set_request_error(reqinfo, request, ret); 00461 } 00462 if (*request->requestvb->val.integer == RS_DESTROY) { 00463 ci->new_row = -1; 00464 } 00465 } 00466 break; 00467 } 00468 break; 00469 00470 case MODE_SET_COMMIT: 00471 if (!ci->have_committed) { 00473 netSnmpHostsTable_commit_row(&ci->data_context, 00474 ci->new_row); 00475 ci->have_committed = 1; 00476 } 00477 break; 00478 00479 case MODE_SET_UNDO: 00481 switch (table_info->colnum) { 00482 case COLUMN_NETSNMPHOSTADDRESSTYPE: 00483 { 00484 int retval; 00485 struct undoInfo *ui; 00486 ui = netsnmp_oid_stash_get_data(undoStorage, 00487 suffix, suffix_len); 00488 retval = 00489 set_netSnmpHostAddressType(ci->data_context, 00490 ui->ptr, ui->len); 00491 if (retval) { 00492 netsnmp_set_request_error(reqinfo, request, 00493 SNMP_ERR_UNDOFAILED); 00494 } 00495 } 00496 break; 00497 case COLUMN_NETSNMPHOSTADDRESS: 00498 { 00499 int retval; 00500 struct undoInfo *ui; 00501 ui = netsnmp_oid_stash_get_data(undoStorage, 00502 suffix, suffix_len); 00503 retval = 00504 set_netSnmpHostAddress(ci->data_context, ui->ptr, 00505 ui->len); 00506 if (retval) { 00507 netsnmp_set_request_error(reqinfo, request, 00508 SNMP_ERR_UNDOFAILED); 00509 } 00510 } 00511 break; 00512 case COLUMN_NETSNMPHOSTSTORAGE: 00513 { 00514 int retval; 00515 struct undoInfo *ui; 00516 ui = netsnmp_oid_stash_get_data(undoStorage, 00517 suffix, suffix_len); 00518 retval = 00519 set_netSnmpHostStorage(ci->data_context, ui->ptr, 00520 ui->len); 00521 if (retval) { 00522 netsnmp_set_request_error(reqinfo, request, 00523 SNMP_ERR_UNDOFAILED); 00524 } 00525 } 00526 break; 00527 case COLUMN_NETSNMPHOSTROWSTATUS: 00528 { 00529 int retval; 00530 struct undoInfo *ui; 00531 ui = netsnmp_oid_stash_get_data(undoStorage, 00532 suffix, suffix_len); 00533 retval = 00534 set_netSnmpHostRowStatus(ci->data_context, ui->ptr, 00535 ui->len); 00536 if (retval) { 00537 netsnmp_set_request_error(reqinfo, request, 00538 SNMP_ERR_UNDOFAILED); 00539 } 00540 } 00541 break; 00542 } 00543 break; 00544 00545 case MODE_SET_FREE: 00546 break; 00547 00548 default: 00549 snmp_log(LOG_ERR, 00550 "problem encountered in netSnmpHostsTable_handler: unsupported mode\n"); 00551 } 00552 } 00553 00555 switch (reqinfo->mode) { 00556 case MODE_SET_UNDO: 00557 case MODE_SET_FREE: 00558 case MODE_SET_COMMIT: 00560 netsnmp_oid_stash_free(&undoStorage, 00561 netSnmpHostsTable_free_undoInfo); 00562 netsnmp_oid_stash_free(&commitStorage, netsnmp_oid_stash_no_free); 00563 } 00564 00565 00566 return SNMP_ERR_NOERROR; 00567 }