int instance_proc_handler(netsnmp_mib_handler * handler, netsnmp_handler_registration * reginfo, netsnmp_agent_request_info * reqinfo, netsnmp_request_info * requests) { register_info *info; proc_info *pinfo; int i = 0, num_proc; pthread_t thread_id; /** XXX * Yet another tree structure specific computation */ /* what node do you want? */ num_proc = reginfo->rootoid[reginfo->rootoid_len - 2]; for(info = register_info_list; info; info = info->next) if(info->type == PROC && info->function_info.proc->num == num_proc) break; if(!info) { /* not found */ netsnmp_request_set_error(requests, SNMP_ERR_GENERR); return SNMP_ERR_GENERR; } pinfo = info->function_info.proc; switch (reqinfo->mode) { case MODE_GET: snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, (u_char *) & (pinfo->trigger), sizeof(pinfo->trigger)); break; case MODE_SET_ACTION: switch (pinfo->trigger) { case SNMP_ADM_READY: /* call the proc */ pthread_create(&thread_id, NULL, launch_proc, pinfo); break; case SNMP_ADM_PROGRESS: netsnmp_request_set_error(requests, SNMP_ERR_GENERR); return SNMP_ERR_GENERR; case SNMP_ADM_DONE: case SNMP_ADM_ERROR: if((*requests->requestvb->val.integer) == 0) { /* raz */ for(i = 0; i < pinfo->nb_in; i++) memset(pinfo->inputs[i], 0, sizeof(snmp_adm_type_union)); for(i = 0; i < pinfo->nb_out; i++) memset(pinfo->outputs[i], 0, sizeof(snmp_adm_type_union)); pinfo->trigger = SNMP_ADM_READY; } break; } } return SNMP_ERR_NOERROR; }
static int iptNetflowSysctl_handler( netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *request) { struct snmp_vars *sys; oid obj; obj = request->requestvb->name[request->requestvb->name_length - 2]; switch (reqinfo->mode) { case MODE_GET: return sysctl_read(request, obj); case MODE_SET_RESERVE1: sys = find_varinfo(sysctls, obj); if (request->requestvb->type != sys->type) netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE); if (!sysctl_access_ok(sys->name)) netsnmp_request_set_error(request, SNMP_ERR_NOSUCHNAME); break; case MODE_SET_RESERVE2: case MODE_SET_FREE: case MODE_SET_UNDO: case MODE_SET_COMMIT: return SNMP_ERR_NOERROR; case MODE_SET_ACTION: return sysctl_write(request, obj); default: return SNMP_ERR_GENERR; } return SNMP_ERR_NOERROR; }
static int sysctl_write(netsnmp_request_info *request, int obj) { struct snmp_vars *sys = find_varinfo(sysctls, obj); char buf[225]; int len; if (!sys) { netsnmp_request_set_error(request, SNMP_NOSUCHOBJECT); return SNMP_ERR_NOERROR; } switch (sys->type) { case ASN_INTEGER: snprintf(buf, sizeof(buf), "%ld\n", *(request->requestvb->val.integer)); break; case ASN_UNSIGNED: snprintf(buf, sizeof(buf), "%lu\n", *(request->requestvb->val.integer)); break; case ASN_OCTET_STR: snprintf(buf, sizeof(buf), "%s\n", request->requestvb->val.string); break; default: netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE); return SNMP_ERR_NOERROR; } len = strlen(buf); if (sysctl_write_string(sys->name, buf, len) < len) netsnmp_request_set_error(request, SNMP_ERR_BADVALUE); return SNMP_ERR_NOERROR; }
int instance_ip_handler(netsnmp_mib_handler * handler, netsnmp_handler_registration * reginfo, netsnmp_agent_request_info * reqinfo, netsnmp_request_info * requests) { in_addr_t *it = (in_addr_t *) handler->myvoid; switch (reqinfo->mode) { /* * data requests */ case MODE_GET: snmp_set_var_typed_value(requests->requestvb, ASN_IPADDRESS, (u_char *) it, sizeof(*it)); break; case MODE_SET_ACTION: /* * update current */ if(check_procedure_access(reginfo)) { netsnmp_request_set_error(requests, SNMP_ERR_READONLY); return SNMP_ERR_READONLY; } memcpy(it, requests->requestvb->val.string, sizeof(*it)); break; } return SNMP_ERR_NOERROR; }
static int sysctl_read(netsnmp_request_info *request, int obj) { struct snmp_vars *sys = find_varinfo(sysctls, obj); char buf[225]; char *p; long value; if (!sys) goto nosuchobject; p = sysctl_read_string(sys->name, buf, sizeof(buf)); if (!p) goto nosuchobject; switch (sys->type) { case ASN_INTEGER: value = atoi(p); snmp_set_var_typed_value(request->requestvb, sys->type, (u_char *)&value, sizeof(value)); return SNMP_ERR_NOERROR; case ASN_OCTET_STR: snmp_set_var_typed_value(request->requestvb, sys->type, (u_char *)p, strcspn(p, "\n")); return SNMP_ERR_NOERROR; } nosuchobject: netsnmp_request_set_error(request, SNMP_NOSUCHOBJECT); return SNMP_ERR_NOERROR; }
int _mfd_dot11ConfTotalTrapGroupTable_check_objects(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests) { dot11ConfTotalTrapGroupTable_rowreq_ctx *rowreq_ctx = netsnmp_container_table_row_extract(requests); netsnmp_table_request_info * tri; int rc; DEBUGMSGTL(("internal:dot11ConfTotalTrapGroupTable:_mfd_dot11ConfTotalTrapGroupTable_check_objects","called\n")); netsnmp_assert(NULL != rowreq_ctx); for(;requests; requests = requests->next) { /* * get column number from table request info, and check that column */ tri = netsnmp_extract_table_info(requests); if(NULL == tri) continue; rc = _dot11ConfTotalTrapGroupTable_check_column(rowreq_ctx, requests->requestvb, tri->colnum); if(rc) { netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc)); break; } } /* for results */ return SNMP_ERR_NOERROR; } /* _mfd_dot11ConfTotalTrapGroupTable_check_objects */
void saHpiDomainEventTable_set_reserve2( netsnmp_request_group *rg ) { // saHpiDomainEventTable_context *row_ctx = (saHpiDomainEventTable_context *)rg->existing_row; // saHpiDomainEventTable_context *undo_ctx = (saHpiDomainEventTable_context *)rg->undo_info; netsnmp_request_group_item *current; netsnmp_variable_list *var; int rc; rg->rg_void = rg->list->ri; /* * TODO: loop through columns, check for valid * values and any range constraints. */ for( current = rg->list; current; current = current->next ) { var = current->ri->requestvb; rc = SNMP_ERR_NOERROR; switch(current->tri->colnum) { default: /** We shouldn't get here */ netsnmp_assert(0); /** why wasn't this caught in reserve1? */ } if (rc) netsnmp_request_set_error( current->ri, rc); } /* * done with all the columns. Could check row related * requirements here. */ }
/************************************************************ * Assuming that the RESERVE phases were successful, the next * stage is indicated by the action value ACTION. This is used * to actually implement the set operation. However, this must * either be done into temporary (persistent) storage, or the * previous value stored similarly, in case any of the subsequent * ACTION calls fail. * * In your case, changes should be made to row_ctx. A copy of * the original row is in undo_ctx. */ void saHpiSensorReadingMaxTable_set_action( netsnmp_request_group *rg ) { netsnmp_variable_list *var; // saHpiSensorReadingMaxTable_context *row_ctx = (saHpiSensorReadingMaxTable_context *)rg->existing_row; // saHpiSensorReadingMaxTable_context *undo_ctx = (saHpiSensorReadingMaxTable_context *)rg->undo_info; netsnmp_request_group_item *current; int row_err = 0; subagent_lock(&hpi_lock_data); DEBUGMSGTL ((AGENT, "saHpiSensorReadingMaxTable_set_action, called\n")); /* * TODO: loop through columns, copy varbind values * to context structure for the row. */ for ( current = rg->list; current; current = current->next ) { var = current->ri->requestvb; switch (current->tri->colnum) { default: /** We shouldn't get here */ netsnmp_assert(0); /** why wasn't this caught in reserve1? */ } } if (row_err) { netsnmp_request_set_error((netsnmp_request_info*)rg->rg_void, row_err); } subagent_unlock(&hpi_lock_data); return; }
static int iptNetflowTotals_handler( netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *request) { struct snmp_vars *sys; time_t now = time(NULL); oid obj; unsigned int uval32; int val32; struct counter64 c64; grab_ipt_netflow_snmp(now); obj = request->requestvb->name[request->requestvb->name_length - 2]; sys = find_varinfo(totals, obj); if (!sys || ((now - sys->ts) > (TOTAL_INTERVAL * 2 + 3))) { netsnmp_request_set_error(request, SNMP_ERR_NOSUCHNAME); return SNMP_ERR_NOERROR; } if (reqinfo->mode != MODE_GET) { netsnmp_request_set_error(request, SNMP_ERR_READONLY); return SNMP_ERR_NOERROR; } switch (sys->type) { case ASN_GAUGE: val32 = (int)sys->val64; snmp_set_var_typed_value(request->requestvb, sys->type, (u_char *)&val32, sizeof(val32)); break; case ASN_COUNTER: uval32 = (unsigned int)sys->val64; snmp_set_var_typed_value(request->requestvb, sys->type, (u_char *)&uval32, sizeof(uval32)); break; case ASN_COUNTER64: c64.low = (uint32_t)sys->val64; c64.high = sys->val64 >> 32; snmp_set_var_typed_value(request->requestvb, ASN_COUNTER64, (u_char *)&c64, sizeof(c64)); break; default: return SNMP_ERR_GENERR; } return SNMP_ERR_NOERROR; }
void saHpiCtrlAnalogTable_set_reserve2( netsnmp_request_group *rg ) { saHpiCtrlAnalogTable_context *row_ctx = (saHpiCtrlAnalogTable_context *)rg->existing_row; // saHpiCtrlAnalogTable_context *undo_ctx = (saHpiCtrlAnalogTable_context *)rg->undo_info; netsnmp_request_group_item *current; netsnmp_variable_list *var; int rc = SNMP_ERR_NOERROR; DEBUGMSGTL ((AGENT, "saHpiCtrlAnalogTable_set_reserve2, called\n")); rg->rg_void = rg->list->ri; /* * TODO: loop through columns, check for valid * values and any range constraints. */ for ( current = rg->list; current; current = current->next ) { var = current->ri->requestvb; rc = SNMP_ERR_NOERROR; switch (current->tri->colnum) { case COLUMN_SAHPICTRLANALOGMODE: if (row_ctx->saHpiCtrlAnalogIsReadOnly == MIB_TRUE) { snmp_log(LOG_ERR, "COLUMN_SAHPICTRLANALOGMODE mode is ReadOnly, Failed\n"); DEBUGMSGTL ((AGENT, "COLUMN_SAHPICTRLANALOGMODE mode is ReadOnly, Failed\n")); rc = SNMP_ERR_READONLY; } if (oh_lookup_ctrlmode(*var->val.integer - 1) == NULL) { snmp_log(LOG_ERR, "COLUMN_SAHPICTRLANALOGMODE Invalid Mode, Failed\n"); DEBUGMSGTL ((AGENT, "COLUMN_SAHPICTRLANALOGMODE Invalid Mode, Failed\n")); rc = SNMP_ERR_BADVALUE; } break; case COLUMN_SAHPICTRLANALOGSTATE: if (row_ctx->saHpiCtrlAnalogMode == (SAHPI_CTRL_MODE_AUTO + 1) ) { snmp_log(LOG_ERR, "COLUMN_SAHPICTRLANALOGSTATE mode is AUTO, Failed\n"); DEBUGMSGTL ((AGENT, "COLUMN_SAHPICTRLANALOGSTATE mode is AUTO, Failed\n")); rc = SNMP_ERR_GENERR; } break; default: /** We shouldn't get here */ netsnmp_assert(0); /** why wasn't this caught in reserve1? */ } if (rc) netsnmp_request_set_error( current->ri, rc); } /* * done with all the columns. Could check row related * requirements here. */ }
/************************************************************ * RESERVE is used to check the syntax of all the variables * provided, that the values being set are sensible and consistent, * and to allocate any resources required for performing the SET. * After this stage, the expectation is that the set ought to * succeed, though this is not guaranteed. (In fact, with the UCD * agent, this is done in two passes - RESERVE1, and * RESERVE2, to allow for dependancies between variables). * * BEFORE calling this routine, the agent will call duplicate_row * to create a copy of the row (unless this is a new row; i.e. * row_created == 1). * * next state -> SET_RESERVE2 || SET_FREE */ void saHpiSensorThdUpMinorTable_set_reserve1( netsnmp_request_group *rg ) { saHpiSensorThdUpMinorTable_context *row_ctx = (saHpiSensorThdUpMinorTable_context *)rg->existing_row; // saHpiSensorThdUpMinorTable_context *undo_ctx = // (saHpiSensorThdUpMinorTable_context *)rg->undo_info; netsnmp_variable_list *var; netsnmp_request_group_item *current; int rc; DEBUGMSGTL ((AGENT, "saHpiSensorThdUpMinorTable_set_reserve1, called\n")); /* * TODO: loop through columns, check syntax and lengths. For * columns which have no dependencies, you could also move * the value/range checking here to attempt to catch error * cases as early as possible. */ for ( current = rg->list; current; current = current->next ) { var = current->ri->requestvb; rc = SNMP_ERR_NOERROR; switch (current->tri->colnum) { case COLUMN_SAHPISENSORTHDUPMINORVALUE: /** SaHpiSensorReadingValue = ASN_OCTET_STR */ rc = netsnmp_check_vb_type(var, ASN_OCTET_STR); if (rc == SNMP_ERR_NOERROR ) { rc = check_sensor_reading_value( var->val_len, row_ctx->saHpiSensorThdUpMinorType); if (rc != SNMP_ERR_NOERROR) { DEBUGMSGTL ((AGENT, "COLUMN_SAHPISENSORTHDUPMINORVALUE ERROR: %d\n", rc)); } } break; default: /** We shouldn't get here */ rc = SNMP_ERR_GENERR; snmp_log(LOG_ERR, "unknown column in " "saHpiSensorThdUpMinorTable_set_reserve1\n"); } if (rc) netsnmp_request_set_error( current->ri, rc ); rg->status = SNMP_MAX( rg->status, current->ri->status ); } /* * done with all the columns. Could check row related * requirements here. */ }
int instance_string_handler(netsnmp_mib_handler * handler, netsnmp_handler_registration * reginfo, netsnmp_agent_request_info * reqinfo, netsnmp_request_info * requests) { int len; switch (reqinfo->mode) { /* * data requests */ case MODE_GET: snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, (u_char *) handler->myvoid, strlen(handler->myvoid)); break; case MODE_SET_ACTION: /* * update current */ if(check_procedure_access(reginfo)) { netsnmp_request_set_error(requests, SNMP_ERR_READONLY); return SNMP_ERR_READONLY; } len = strnlen(requests->requestvb->val.string, sizeof(requests->requestvb->val.string)); if(len >= sizeof(requests->requestvb->val.string)) netsnmp_request_set_error(requests, SNMP_ERR_BADVALUE); else { memcpy(handler->myvoid, requests->requestvb->val.string, len + 1); } break; /* XXX do not add a default case otherwise netsnmp will never send SET_ACTION (because SET_RESERVE is considered as failed) see AGENT.txt section 8 */ } return SNMP_ERR_NOERROR; }
int instance_bigint_handler(netsnmp_mib_handler * handler, netsnmp_handler_registration * reginfo, netsnmp_agent_request_info * reqinfo, netsnmp_request_info * requests) { int err; int64_t *it = (int64_t *) handler->myvoid; int64_t tmp_it; char str[256]; switch (reqinfo->mode) { /* * data requests */ case MODE_GET: err = big2str(str, *it); if(!err) snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, (u_char *) str, strlen(str)); else netsnmp_request_set_error(requests, SNMP_ERR_BADVALUE); break; case MODE_SET_ACTION: /* * update current */ if(check_procedure_access(reginfo)) { netsnmp_request_set_error(requests, SNMP_ERR_READONLY); return SNMP_ERR_READONLY; } err = str2big(&tmp_it, (char *)(requests->requestvb->val.string)); if(!err) *it = tmp_it; else netsnmp_request_set_error(requests, SNMP_ERR_BADVALUE); break; } return SNMP_ERR_NOERROR; }
/** * Process the get request. This is called in the mode end callback. */ int clSnmpProcessRequest(netsnmp_request_info *requests) { ClRcT rc = CL_SNMP_ERR_NOERROR; ClUint32T i = 0; ClMedErrorListT medErrList = {0}; _ClSnmpGetReqInfoT *pReqInfo = NULL; clLogDebug("SNP", NULL, "Calling the snmpCommit now."); rc = clSnmpCommit (&medErrList); if (CL_OK != rc) { clSnmpDataReset(); clLogError("SNP", NULL, "Failed while committing the get request. rc[0x%x]", rc); if (CL_ERR_NO_MEMORY == rc) rc = CL_SNMP_ERR_NOCREATION; else rc = CL_SNMP_ERR_GENERR; netsnmp_request_set_error(requests, rc); return rc; } for (i = 0 ; i < gOper.opInfo.varCount ; i++) { pReqInfo = ((_ClSnmpGetReqInfoT *)(gOper.pOpAddData) + i); clLogDebug("SNP", NULL, "Processing the agentId [%s]", gOper.opInfo.varInfo[i].attrId.id); if (gOper.opInfo.varInfo[i].errId == CL_OK) { snmp_set_var_typed_value(pReqInfo->pRequest->requestvb, pReqInfo->columnType, gOper.opInfo.varInfo[i].pVal, gOper.opInfo.varInfo[i].len); } else { clLogDebug("SNP", NULL, "Job failed with error [0x%x]", gOper.opInfo.varInfo[i].errId); netsnmp_request_set_error(pReqInfo->pRequest, gOper.opInfo.varInfo[i].errId); } } clSnmpDataReset(); return rc; }
/************************************************************ * Assuming that the RESERVE phases were successful, the next * stage is indicated by the action value ACTION. This is used * to actually implement the set operation. However, this must * either be done into temporary (persistent) storage, or the * previous value stored similarly, in case any of the subsequent * ACTION calls fail. * * In your case, changes should be made to row_ctx. A copy of * the original row is in undo_ctx. */ void saHpiCtrlStreamTable_set_action( netsnmp_request_group *rg ) { netsnmp_variable_list *var; saHpiCtrlStreamTable_context *row_ctx = (saHpiCtrlStreamTable_context *)rg->existing_row; // saHpiCtrlStreamTable_context *undo_ctx = (saHpiCtrlStreamTable_context *)rg->undo_info; netsnmp_request_group_item *current; int row_err = 0; DEBUGMSGTL ((AGENT, "saHpiCtrlStreamTable_set_action, called\n")); /* * TODO: loop through columns, copy varbind values * to context structure for the row. */ for ( current = rg->list; current; current = current->next ) { var = current->ri->requestvb; switch (current->tri->colnum) { case COLUMN_SAHPICTRLSTREAMMODE: /** SaHpiCtrlMode = ASN_INTEGER */ row_ctx->saHpiCtrlStreamMode = *var->val.integer; row_err = set_table_ctrl_stream (row_ctx); break; case COLUMN_SAHPICTRLSTREAMREPEAT: /** TruthValue = ASN_INTEGER */ row_ctx->saHpiCtrlStreamRepeat = *var->val.integer; row_err = set_table_ctrl_stream (row_ctx); break; case COLUMN_SAHPICTRLSTREAMSTATE: /** SaHpiText = ASN_OCTET_STR */ memcpy(row_ctx->saHpiCtrlStreamState,var->val.string,var->val_len); row_ctx->saHpiCtrlStreamState_len = var->val_len; row_err = set_table_ctrl_stream (row_ctx); break; default: /** We shouldn't get here */ netsnmp_assert(0); /** why wasn't this caught in reserve1? */ } } if (row_err) { netsnmp_request_set_error((netsnmp_request_info*)rg->rg_void, row_err); return; } /* * TODO: if you have dependencies on other tables, this would be * a good place to check those, too. */ }
/************************************************************ * Assuming that the RESERVE phases were successful, the next * stage is indicated by the action value ACTION. This is used * to actually implement the set operation. However, this must * either be done into temporary (persistent) storage, or the * previous value stored similarly, in case any of the subsequent * ACTION calls fail. * * In your case, changes should be made to row_ctx. A copy of * the original row is in undo_ctx. */ void saHpiCtrlAnalogTable_set_action( netsnmp_request_group *rg ) { netsnmp_variable_list *var; saHpiCtrlAnalogTable_context *row_ctx = (saHpiCtrlAnalogTable_context *)rg->existing_row; // saHpiCtrlAnalogTable_context *undo_ctx = (saHpiCtrlAnalogTable_context *)rg->undo_info; netsnmp_request_group_item *current; int row_err = 0; subagent_lock(&hpi_lock_data); DEBUGMSGTL ((AGENT, "saHpiCtrlAnalogTable_set_action, called\n")); /* * TODO: loop through columns, copy varbind values * to context structure for the row. */ for ( current = rg->list; current; current = current->next ) { var = current->ri->requestvb; switch (current->tri->colnum) { case COLUMN_SAHPICTRLANALOGMODE: /** SaHpiCtrlMode = ASN_INTEGER */ row_ctx->saHpiCtrlAnalogMode = *var->val.integer; row_err = set_table_ctrl_analog_mode (row_ctx); break; case COLUMN_SAHPICTRLANALOGSTATE: /** INTEGER = ASN_INTEGER */ row_ctx->saHpiCtrlAnalogState = *var->val.integer; row_err = set_table_ctrl_analog_state (row_ctx); break; default: /** We shouldn't get here */ netsnmp_assert(0); /** why wasn't this caught in reserve1? */ } } if (row_err) { netsnmp_request_set_error((netsnmp_request_info*)rg->rg_void, row_err); } subagent_unlock(&hpi_lock_data); return; /* * TODO: if you have dependencies on other tables, this would be * a good place to check those, too. */ }
static int handle_sysServices(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { #if NETSNMP_NO_DUMMY_VALUES if (reqinfo->mode == MODE_GET && !sysServicesConfiged) netsnmp_request_set_error(requests, SNMP_NOSUCHINSTANCE); #endif return SNMP_ERR_NOERROR; }
/************************************************************ * RESERVE is used to check the syntax of all the variables * provided, that the values being set are sensible and consistent, * and to allocate any resources required for performing the SET. * After this stage, the expectation is that the set ought to * succeed, though this is not guaranteed. (In fact, with the UCD * agent, this is done in two passes - RESERVE1, and * RESERVE2, to allow for dependancies between variables). * * BEFORE calling this routine, the agent will call duplicate_row * to create a copy of the row (unless this is a new row; i.e. * row_created == 1). * * next state -> SET_RESERVE2 || SET_FREE */ void saHpiAutoInsertTimeoutTable_set_reserve1( netsnmp_request_group *rg ) { // saHpiAutoInsertTimeoutTable_context *row_ctx = // (saHpiAutoInsertTimeoutTable_context *)rg->existing_row; // saHpiAutoInsertTimeoutTable_context *undo_ctx = // (saHpiAutoInsertTimeoutTable_context *)rg->undo_info; netsnmp_variable_list *var; netsnmp_request_group_item *current; int rc; /* * TODO: loop through columns, check syntax and lengths. For * columns which have no dependencies, you could also move * the value/range checking here to attempt to catch error * cases as early as possible. */ for( current = rg->list; current; current = current->next ) { var = current->ri->requestvb; rc = SNMP_ERR_NOERROR; switch(current->tri->colnum) { case COLUMN_SAHPIAUTOINSERTTIMEOUTFORINSERT: /** SafUnsigned64 = ASN_OPAQUE */ rc = netsnmp_check_vb_type(var, ASN_OPAQUE); if (rc == SNMP_ERR_NOERROR ) { if (var->val_len > SAF_UNSIGNED_64_LEN) { rc = SNMP_ERR_WRONGLENGTH; DEBUGMSGTL ((AGENT, "COLUMN_SAHPIAUTOINSERTTIMEOUTFORINSERT" " SNMP_ERR_WRONGLENGTH\n", rc)); } } break; default: /** We shouldn't get here */ rc = SNMP_ERR_GENERR; snmp_log(LOG_ERR, "unknown column in " "saHpiAutoInsertTimeoutTable_set_reserve1\n"); } if (rc) netsnmp_request_set_error( current->ri, rc ); rg->status = SNMP_MAX( rg->status, current->ri->status ); } /* * done with all the columns. Could check row related * requirements here. */ }
/************************************************************ * RESERVE is used to check the syntax of all the variables * provided, that the values being set are sensible and consistent, * and to allocate any resources required for performing the SET. * After this stage, the expectation is that the set ought to * succeed, though this is not guaranteed. (In fact, with the UCD * agent, this is done in two passes - RESERVE1, and * RESERVE2, to allow for dependancies between variables). * * BEFORE calling this routine, the agent will call duplicate_row * to create a copy of the row (unless this is a new row; i.e. * row_created == 1). * * next state -> SET_RESERVE2 || SET_FREE */ void saHpiCtrlDigitalTable_set_reserve1( netsnmp_request_group *rg ) { saHpiCtrlDigitalTable_context *row_ctx = (saHpiCtrlDigitalTable_context *)rg->existing_row; // saHpiCtrlDigitalTable_context *undo_ctx = // (saHpiCtrlDigitalTable_context *)rg->undo_info; netsnmp_variable_list *var; netsnmp_request_group_item *current; int rc; DEBUGMSGTL ((AGENT, "saHpiCtrlDigitalTable_set_reserve1, called\n")); /* * TODO: loop through columns, check syntax and lengths. For * columns which have no dependencies, you could also move * the value/range checking here to attempt to catch error * cases as early as possible. */ for ( current = rg->list; current; current = current->next ) { var = current->ri->requestvb; rc = SNMP_ERR_NOERROR; switch (current->tri->colnum) { case COLUMN_SAHPICTRLDIGITALMODE: /** SaHpiCtrlMode = ASN_INTEGER */ rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER, sizeof(row_ctx->saHpiCtrlDigitalMode)); break; case COLUMN_SAHPICTRLDIGITALSTATE: /** SaHpiCtrlStateDigital = ASN_INTEGER */ rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER, sizeof(row_ctx->saHpiCtrlDigitalState)); break; default: /** We shouldn't get here */ rc = SNMP_ERR_GENERR; snmp_log(LOG_ERR, "unknown column in " "saHpiCtrlDigitalTable_set_reserve1\n"); } if (rc) netsnmp_request_set_error( current->ri, rc ); rg->status = SNMP_MAX( rg->status, current->ri->status ); } /* * done with all the columns. Could check row related * requirements here. */ }
/************************************************************ * Assuming that the RESERVE phases were successful, the next * stage is indicated by the action value ACTION. This is used * to actually implement the set operation. However, this must * either be done into temporary (persistent) storage, or the * previous value stored similarly, in case any of the subsequent * ACTION calls fail. * * In your case, changes should be made to row_ctx. A copy of * the original row is in undo_ctx. */ void saHpiAutoInsertTimeoutTable_set_action( netsnmp_request_group *rg ) { netsnmp_variable_list *var; saHpiAutoInsertTimeoutTable_context *row_ctx = (saHpiAutoInsertTimeoutTable_context *)rg->existing_row; // saHpiAutoInsertTimeoutTable_context *undo_ctx = (saHpiAutoInsertTimeoutTable_context *)rg->undo_info; netsnmp_request_group_item *current; // unsigned char buff[sizeof(SaHpiTimeT)]; //For timeout int row_err = 0; printf("7\n"); /* * TODO: loop through columns, copy varbind values * to context structure for the row. */ for( current = rg->list; current; current = current->next ) { var = current->ri->requestvb; switch(current->tri->colnum) { case COLUMN_SAHPIAUTOINSERTTIMEOUTFORINSERT: /** SafUnsigned64 = ASN_OPAQUE */ assign_timeout(var, row_ctx->saHpiAutoInsertTimeoutForInsert); row_ctx->saHpiAutoInsertTimeoutForInsert_len = var->val_len; row_err = auto_insert_timeout_set(row_ctx); break; default: /** We shouldn't get here */ netsnmp_assert(0); /** why wasn't this caught in reserve1? */ } } /* * done with all the columns. Could check row related * requirements here. */ if(row_err) { netsnmp_request_set_error((netsnmp_request_info*)rg->rg_void, row_err); return; } /* * TODO: if you have dependencies on other tables, this would be * a good place to check those, too. */ }
void saHpiSensorThdLowMinorTable_set_reserve2( netsnmp_request_group *rg ) { // saHpiSensorThdLowMinorTable_context *row_ctx = // (saHpiSensorThdLowMinorTable_context *)rg->existing_row; // saHpiSensorThdLowMinorTable_context *undo_ctx = // (saHpiSensorThdLowMinorTable_context *)rg->undo_info; netsnmp_request_group_item *current; netsnmp_variable_list *var; int rc; DEBUGMSGTL ((AGENT, "saHpiSensorThdLowMinorTable_set_reserve2, called\n")); rg->rg_void = rg->list->ri; /* * TODO: loop through columns, check for valid * values and any range constraints. */ for( current = rg->list; current; current = current->next ) { var = current->ri->requestvb; rc = SNMP_ERR_NOERROR; switch(current->tri->colnum) { case COLUMN_SAHPISENSORTHDLOWMINORVALUE: /** SaHpiSensorReadingValue = ASN_OCTET_STR */ /* * TODO: routine to check valid values * * EXAMPLE: * * if ( XXX_check_value( var->val.string, XXX ) ) { * rc = SNMP_ERR_INCONSISTENTVALUE; * rc = SNMP_ERR_BADVALUE; * } */ break; default: /** We shouldn't get here */ netsnmp_assert(0); /** why wasn't this caught in reserve1? */ } if (rc) netsnmp_request_set_error( current->ri, rc); } /* * done with all the columns. Could check row related * requirements here. */ }
static int handle_truthvalue(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { if (reqinfo->mode == MODE_SET_RESERVE1) { int res = netsnmp_check_vb_truthvalue(requests->requestvb); if (res != SNMP_ERR_NOERROR) netsnmp_request_set_error(requests, res); } return SNMP_ERR_NOERROR; }
static int handle_updates (netsnmp_mib_handler * handler, netsnmp_handler_registration * reginfo, netsnmp_agent_request_info * reqinfo, netsnmp_request_info * requests) { int *set = (int *) handler->myvoid; #ifndef NETSNMP_NO_WRITE_SUPPORT if (reqinfo->mode == MODE_SET_RESERVE1 && *set < 0) netsnmp_request_set_error (requests, SNMP_ERR_NOTWRITABLE); else if (reqinfo->mode == MODE_SET_COMMIT) *set = 1; #endif /* NETSNMP_NO_WRITE_SUPPORT */ return SNMP_ERR_NOERROR; }
void saHpiAutoInsertTimeoutTable_set_reserve2( netsnmp_request_group *rg ) { // saHpiAutoInsertTimeoutTable_context *row_ctx = (saHpiAutoInsertTimeoutTable_context *)rg->existing_row; // saHpiAutoInsertTimeoutTable_context *undo_ctx = (saHpiAutoInsertTimeoutTable_context *)rg->undo_info; netsnmp_request_group_item *current; netsnmp_variable_list *var; int rc; rg->rg_void = rg->list->ri; /* * TODO: loop through columns, check for valid * values and any range constraints. */ for( current = rg->list; current; current = current->next ) { var = current->ri->requestvb; rc = SNMP_ERR_NOERROR; switch(current->tri->colnum) { case COLUMN_SAHPIAUTOINSERTTIMEOUTFORINSERT: /** SafUnsigned64 = ASN_OPAQUE */ /* * TODO: routine to check valid values * * EXAMPLE: * * if ( XXX_check_value( var->val.string, XXX ) ) { * rc = SNMP_ERR_INCONSISTENTVALUE; * rc = SNMP_ERR_BADVALUE; * } */ break; default: /** We shouldn't get here */ netsnmp_assert(0); /** why wasn't this caught in reserve1? */ } if (rc) netsnmp_request_set_error( current->ri, rc); } /* * done with all the columns. Could check row related * requirements here. */ }
/************************************************************ * Assuming that the RESERVE phases were successful, the next * stage is indicated by the action value ACTION. This is used * to actually implement the set operation. However, this must * either be done into temporary (persistent) storage, or the * previous value stored similarly, in case any of the subsequent * ACTION calls fail. * * In your case, changes should be made to row_ctx. A copy of * the original row is in undo_ctx. */ void saHpiSensorThdLowMinorTable_set_action( netsnmp_request_group *rg ) { netsnmp_variable_list *var; saHpiSensorThdLowMinorTable_context *row_ctx = (saHpiSensorThdLowMinorTable_context *)rg->existing_row; // saHpiSensorThdLowMinorTable_context *undo_ctx = // (saHpiSensorThdLowMinorTable_context *)rg->undo_info; netsnmp_request_group_item *current; int row_err = 0; subagent_lock(&hpi_lock_data); DEBUGMSGTL ((AGENT, "saHpiSensorThdLowMinorTable_set_action, called\n")); /* * TODO: loop through columns, copy varbind values * to context structure for the row. */ for( current = rg->list; current; current = current->next ) { var = current->ri->requestvb; switch(current->tri->colnum) { case COLUMN_SAHPISENSORTHDLOWMINORVALUE: /** SaHpiSensorReadingValue = ASN_OCTET_STR */ memcpy(row_ctx->saHpiSensorThdLowMinorValue, var->val.string, var->val_len); row_ctx->saHpiSensorThdLowMinorValue_len = var->val_len; row_err = set_table_sen_thds_low_minor (row_ctx); break; default: /** We shouldn't get here */ netsnmp_assert(0); /** why wasn't this caught in reserve1? */ } } if(row_err) { netsnmp_request_set_error((netsnmp_request_info*)rg->rg_void, row_err); } subagent_unlock(&hpi_lock_data); return; }
/************************************************************ * Assuming that the RESERVE phases were successful, the next * stage is indicated by the action value ACTION. This is used * to actually implement the set operation. However, this must * either be done into temporary (persistent) storage, or the * previous value stored similarly, in case any of the subsequent * ACTION calls fail. * * In your case, changes should be made to row_ctx. A copy of * the original row is in undo_ctx. */ void saHpiDomainEventTable_set_action( netsnmp_request_group *rg ) { netsnmp_variable_list *var; // saHpiDomainEventTable_context *row_ctx = (saHpiDomainEventTable_context *)rg->existing_row; // saHpiDomainEventTable_context *undo_ctx = (saHpiDomainEventTable_context *)rg->undo_info; netsnmp_request_group_item *current; int row_err = 0; /* * TODO: loop through columns, copy varbind values * to context structure for the row. */ for( current = rg->list; current; current = current->next ) { var = current->ri->requestvb; switch(current->tri->colnum) { default: /** We shouldn't get here */ netsnmp_assert(0); /** why wasn't this caught in reserve1? */ } } /* * done with all the columns. Could check row related * requirements here. */ /* * check activation/deactivation */ if(row_err) { netsnmp_request_set_error((netsnmp_request_info*)rg->rg_void, row_err); return; } /* * TODO: if you have dependencies on other tables, this would be * a good place to check those, too. */ }
/************************************************************ * RESERVE is used to check the syntax of all the variables * provided, that the values being set are sensible and consistent, * and to allocate any resources required for performing the SET. * After this stage, the expectation is that the set ought to * succeed, though this is not guaranteed. (In fact, with the UCD * agent, this is done in two passes - RESERVE1, and * RESERVE2, to allow for dependancies between variables). * * BEFORE calling this routine, the agent will call duplicate_row * to create a copy of the row (unless this is a new row; i.e. * row_created == 1). * * next state -> SET_RESERVE2 || SET_FREE */ void saHpiSensorReadingNormalMaxTable_set_reserve1( netsnmp_request_group *rg ) { // saHpiSensorReadingNormalMaxTable_context *row_ctx = // (saHpiSensorReadingNormalMaxTable_context *)rg->existing_row; // saHpiSensorReadingNormalMaxTable_context *undo_ctx = // (saHpiSensorReadingNormalMaxTable_context *)rg->undo_info; netsnmp_variable_list *var; netsnmp_request_group_item *current; int rc; DEBUGMSGTL ((AGENT, "saHpiSensorReadingNormalMaxTable_set_reserve1, called\n")); /* * TODO: loop through columns, check syntax and lengths. For * columns which have no dependencies, you could also move * the value/range checking here to attempt to catch error * cases as early as possible. */ for ( current = rg->list; current; current = current->next ) { var = current->ri->requestvb; rc = SNMP_ERR_NOERROR; switch (current->tri->colnum) { default: /** We shouldn't get here */ rc = SNMP_ERR_GENERR; snmp_log(LOG_ERR, "unknown column in " "saHpiSensorReadingNormalMaxTable_set_reserve1\n"); } if (rc) netsnmp_request_set_error( current->ri, rc ); rg->status = SNMP_MAX( rg->status, current->ri->status ); } /* * done with all the columns. Could check row related * requirements here. */ }
/************************************************************ * Assuming that the RESERVE phases were successful, the next * stage is indicated by the action value ACTION. This is used * to actually implement the set operation. However, this must * either be done into temporary (persistent) storage, or the * previous value stored similarly, in case any of the subsequent * ACTION calls fail. * * In your case, changes should be made to row_ctx. A copy of * the original row is in undo_ctx. */ void saHpiSensorReadingNormalMinTable_set_action( netsnmp_request_group *rg ) { netsnmp_variable_list *var; // saHpiSensorReadingNormalMinTable_context *row_ctx = // (saHpiSensorReadingNormalMinTable_context *)rg->existing_row; // saHpiSensorReadingNormalMinTable_context *undo_ctx = // (saHpiSensorReadingNormalMinTable_context *)rg->undo_info; netsnmp_request_group_item *current; DEBUGMSGTL ((AGENT, "saHpiSensorReadingNormalMinTable_set_action, called\n")); int row_err = 0; /* * TODO: loop through columns, copy varbind values * to context structure for the row. */ for ( current = rg->list; current; current = current->next ) { var = current->ri->requestvb; switch (current->tri->colnum) { default: /** We shouldn't get here */ netsnmp_assert(0); /** why wasn't this caught in reserve1? */ } } if (row_err) { netsnmp_request_set_error((netsnmp_request_info*)rg->rg_void, row_err); return; } /* * TODO: if you have dependencies on other tables, this would be * a good place to check those, too. */ }
int instance_time_handler(netsnmp_mib_handler * handler, netsnmp_handler_registration * reginfo, netsnmp_agent_request_info * reqinfo, netsnmp_request_info * requests) { unsigned int *it = (unsigned int *)handler->myvoid; unsigned int tmp_it; switch (reqinfo->mode) { /* * data requests */ case MODE_GET: tmp_it = (*it) * 100; snmp_set_var_typed_value(requests->requestvb, ASN_TIMETICKS, (u_char *) & tmp_it, sizeof(tmp_it)); break; case MODE_SET_ACTION: /* * update current */ if(check_procedure_access(reginfo)) { netsnmp_request_set_error(requests, SNMP_ERR_READONLY); return SNMP_ERR_READONLY; } tmp_it = *((unsigned int *)(requests->requestvb->val.integer)); *it = tmp_it / 100; break; break; } return SNMP_ERR_NOERROR; }
int _mfd_ipv4InterfaceTable_get_values(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests) { ipv4InterfaceTable_rowreq_ctx *rowreq_ctx = netsnmp_container_table_row_extract(requests); netsnmp_table_request_info *tri; u_char *old_string; void (*dataFreeHook) (void *); int rc; DEBUGMSGTL(("internal:ipv4InterfaceTable:_mfd_ipv4InterfaceTable_get_values", "called\n")); netsnmp_assert(NULL != rowreq_ctx); for (; requests; requests = requests->next) { /* * save old pointer, so we can free it if replaced */ old_string = requests->requestvb->val.string; dataFreeHook = requests->requestvb->dataFreeHook; if (NULL == requests->requestvb->val.string) { requests->requestvb->val.string = requests->requestvb->buf; requests->requestvb->val_len = sizeof(requests->requestvb->buf); } else if (requests->requestvb->buf == requests->requestvb->val.string) { if (requests->requestvb->val_len != sizeof(requests->requestvb->buf)) requests->requestvb->val_len = sizeof(requests->requestvb->buf); } /* * get column data */ tri = netsnmp_extract_table_info(requests); if (NULL == tri) continue; rc = _ipv4InterfaceTable_get_column(rowreq_ctx, requests->requestvb, tri->colnum); if (rc) { if (MFD_SKIP == rc) { requests->requestvb->type = SNMP_NOSUCHINSTANCE; rc = SNMP_ERR_NOERROR; } } else if (NULL == requests->requestvb->val.string) { snmp_log(LOG_ERR, "NULL varbind data pointer!\n"); rc = SNMP_ERR_GENERR; } if (rc) netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc)); /* * if the buffer wasn't used previously for the old data (i.e. it * was allcoated memory) and the get routine replaced the pointer, * we need to free the previous pointer. */ if (old_string && (old_string != requests->requestvb->buf) && (requests->requestvb->val.string != old_string)) { if (dataFreeHook) (*dataFreeHook) (old_string); else free(old_string); } } /* for results */ return SNMP_ERR_NOERROR; } /* _mfd_ipv4InterfaceTable_get_values */