/** handles requests for the expExpressionErrorTable table */ int expErrorTable_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { netsnmp_request_info *request; netsnmp_table_request_info *tinfo; struct expExpression *entry; DEBUGMSGTL(("disman:expr:mib", "Expression Error Table handler (%d)\n", reqinfo->mode)); switch (reqinfo->mode) { /* * Read-support (also covers GetNext requests) */ case MODE_GET: for (request = requests; request; request = request->next) { entry = (struct expExpression *) netsnmp_tdata_extract_entry(request); tinfo = netsnmp_extract_table_info(request); if (!entry || !(entry->flags & EXP_FLAG_VALID)) continue; /* * "Entries only appear in this table ... when there * has been an error for that [matching] expression" */ if (entry->expErrorCount == 0) continue; switch (tinfo->colnum) { case COLUMN_EXPERRORTIME: snmp_set_var_typed_integer(request->requestvb, ASN_TIMETICKS, entry->expErrorTime); break; case COLUMN_EXPERRORINDEX: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->expErrorIndex); break; case COLUMN_EXPERRORCODE: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->expErrorCode); break; case COLUMN_EXPERRORINSTANCE: snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID, (u_char *) entry->expErrorInstance, entry->expErrorInst_len*sizeof(oid)); break; } } break; } DEBUGMSGTL(("disman:expr:mib", "Expression Error handler - done \n")); return SNMP_ERR_NOERROR; }
static void psu_status_handler__(netsnmp_request_info *req, uint32_t index, onlp_snmp_sensor_t *ss ) { int value; onlp_psu_info_t *pi = &ss->sensor_info.pi; if (!ss->info_valid) { return; } value = ONLP_SNMP_SENSOR_STATUS_MISSING; if (pi->status & ONLP_PSU_STATUS_PRESENT) { value = ONLP_SNMP_SENSOR_STATUS_GOOD; /* failed or good is always reported */ if (pi->status & ONLP_PSU_STATUS_FAILED) { value = ONLP_SNMP_SENSOR_STATUS_FAILED; } /* if additional unplugged status is reported */ if (pi->status & ONLP_PSU_STATUS_UNPLUGGED) { value = ONLP_SNMP_SENSOR_STATUS_FAILED; } } snmp_set_var_typed_integer(req->requestvb, ASN_INTEGER, value); }
int handle_autoRespawn(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { /* We are never called for a GETNEXT if it's registered as a "instance", as it's "magically" handled for us. */ /* a instance handler also only hands us one request at a time, so we don't need to loop over a list of requests; we'll only get one. */ switch(reqinfo->mode) { case MODE_GET: snmp_set_var_typed_integer(requests->requestvb, ASN_INTEGER, cm->getGlobal()->get<ConfigBoolean>("auto-respawn")->read()); break; default: /* we should never get here, so this is a really bad error */ snmp_log(LOG_ERR, "unknown mode (%d) in handle_autoRespawn\n", reqinfo->mode ); return SNMP_ERR_GENERR; } return SNMP_ERR_NOERROR; }
//******************************************************************************** //******************************************************************************** static void delayed_response(unsigned int clientreg, void * clientarg) { syslog(LOG_DEBUG, "Enter: delayed_response, %s.", HANDLER_NAME); netsnmp_delegated_cache *cache = (netsnmp_delegated_cache *) clientarg; if(!netsnmp_handler_check_cache(cache)) { syslog(LOG_ERR, "%s", "illegal call to return delayed response."); return; } syslog(LOG_DEBUG, "delayed_instance, continuing delayed request, mode = %d.", cache->reqinfo->mode); cache->requests->delegated = 0; switch(cache->reqinfo->mode) { case MODE_GET: case MODE_GETNEXT: int32_t redirect = redirect_count(); snmp_set_var_typed_integer(cache->requests->requestvb, ASN_COUNTER, redirect); } netsnmp_free_delegated_cache(cache); syslog(LOG_DEBUG, "Exit: delayed_response, %s.", HANDLER_NAME); syslog(LOG_DEBUG,"%s", "==============================================================="); return; }
static void misc_index_handler__(netsnmp_request_info *req, uint32_t index, onlp_snmp_sensor_t *ss) { snmp_set_var_typed_integer(req->requestvb, ASN_INTEGER, index); }
static int handle_sysUpTime(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { snmp_set_var_typed_integer(requests->requestvb, ASN_TIMETICKS, netsnmp_get_agent_uptime()); return SNMP_ERR_NOERROR; }
netsnmp_variable_list * neIeee8021BridgeBasePortTable_getNext ( void **my_loop_context, void **my_data_context, netsnmp_variable_list *put_index_data, netsnmp_iterator_info *mydata) { ieee8021BridgeBasePortEntry_t *poEntry = NULL; netsnmp_variable_list *idx = put_index_data; if (*my_loop_context == NULL) { return NULL; } poEntry = xBTree_entry (*my_loop_context, ieee8021BridgeBasePortEntry_t, oBTreeNode); snmp_set_var_typed_integer (idx, ASN_UNSIGNED, poEntry->u32ComponentId); idx = idx->next_variable; snmp_set_var_typed_integer (idx, ASN_UNSIGNED, poEntry->u32Port); *my_data_context = (void*) poEntry; *my_loop_context = (void*) xBTree_nodeGetNext (&poEntry->oBTreeNode, &oIeee8021BridgeBasePortTable_BTree); return put_index_data; }
/** handles requests for the sctpLookupRemPortTable table */ int sctpLookupRemPortTable_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { netsnmp_request_info *request; netsnmp_table_request_info *table_info; sctpLookupRemPortTable_entry *table_entry; switch (reqinfo->mode) { /* * Read-support (also covers GetNext requests) */ case MODE_GET: for (request = requests; request; request = request->next) { if (request->processed) continue; table_entry = (sctpLookupRemPortTable_entry *) netsnmp_container_table_extract_context(request); table_info = netsnmp_extract_table_info(request); if ((NULL == table_entry) || (NULL == table_info)) { snmp_log(LOG_ERR, "could not extract table entry or info for sctpLookupRemPortTable\n"); snmp_set_var_typed_value(request->requestvb, SNMP_ERR_GENERR, NULL, 0); continue; } switch (table_info->colnum) { case COLUMN_SCTPLOOKUPREMPORTSTARTTIME: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_TIMETICKS, table_entry->sctpLookupRemPortStartTime); break; default: netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT); break; } } break; } return SNMP_ERR_NOERROR; }
netsnmp_variable_list * pgsqlPgAmopTable_get_next_data_point(void **my_loop_context, void **my_data_context, netsnmp_variable_list *put_index_data, netsnmp_iterator_info *mydata) { struct pgsqlPgAmopTable_entry *entry = (struct pgsqlPgAmopTable_entry *)*my_loop_context; netsnmp_variable_list *idx = put_index_data; snmp_log(LOG_INFO, "*** get_next called\n"); if ( entry ) { snmp_set_var_value( idx, entry->pgsnmpdConnID, sizeof(entry->pgsnmpdConnID) ); idx = idx->next_variable; snmp_set_var_typed_integer( idx, ASN_INTEGER, entry->rdbmsDbIndex ); idx = idx->next_variable; snmp_set_var_typed_integer( idx, ASN_INTEGER, entry->pgsqlPgAmopEntryOID ); idx = idx->next_variable; *my_data_context = (void *)entry; *my_loop_context = (void *)entry->next; return put_index_data; } else { return NULL; } }
int _mteEvent_fire_set (struct mteEvent *entry, /* The event to fire */ struct mteTrigger *trigger, /* Trigger that fired */ oid * suffix, size_t sfx_len) /* Matching instance */ { netsnmp_variable_list var; oid set_oid[MAX_OID_LEN]; size_t set_len; /* * Set the basic assignment OID... */ memset (set_oid, 0, sizeof (set_oid)); memcpy (set_oid, entry->mteSetOID, entry->mteSetOID_len * sizeof (oid)); set_len = entry->mteSetOID_len; /* * ... if the trigger value is wildcarded (sfx_len > 0), * *and* the SET event entry is wildcarded, * then add the supplied instance suffix... */ if (sfx_len && entry->flags & MTE_SET_FLAG_OBJWILD) { memcpy (&set_oid[set_len], suffix, sfx_len * sizeof (oid)); set_len += sfx_len; } /* * ... finally build the assignment varbind, * and pass it to be acted on. * * XXX: Need to handle (remote) targets and non-default contexts */ memset (&var, 0, sizeof (var)); snmp_set_var_objid (&var, set_oid, set_len); snmp_set_var_typed_integer (&var, ASN_INTEGER, entry->mteSetValue); if (entry->session) return netsnmp_query_set (&var, entry->session); else return netsnmp_query_set (&var, trigger->session); /* XXX - Need to check result */ }
netsnmp_variable_list * raidSetTable_get_next_data_point(void **my_loop_context, void **my_data_context, netsnmp_variable_list *put_index_data, netsnmp_iterator_info *mydata) { struct raidSetTable_entry *entry = (struct raidSetTable_entry *)*my_loop_context; netsnmp_variable_list *idx = put_index_data; if ( entry ) { snmp_set_var_typed_integer( idx, ASN_INTEGER, entry->raidSetIndex ); idx = idx->next_variable; *my_data_context = (void *)entry; *my_loop_context = (void *)entry->next; return put_index_data; } else { return NULL; } }
static netsnmp_variable_list *mib_ipRouteTable_get_next(void **my_loop_context, void **my_data_context, netsnmp_variable_list *put_index_data, netsnmp_iterator_info *iinfo) { struct ipRouteTable_entry *entry = (struct ipRouteTable_entry *)*my_loop_context; netsnmp_variable_list *idx = put_index_data; if ( entry ) { snmp_set_var_typed_integer( idx, ASN_IPADDRESS, entry->ipRouteDest ); idx = idx->next_variable; *my_data_context = (void *)entry; *my_loop_context = (void *)entry->next; return put_index_data; } else { return NULL; } }
/******************************************************************************* 函数名称 : mib_dot1qPortVlanTable_get_next 功能描述 : 输入参数 : 输出参数 : 返 回 值 : -------------------------------------------------------------------------------- 最近一次修改记录 : 修改作者 : 修改目的 : 修改日期 : *******************************************************************************/ static netsnmp_variable_list *mib_dot1qPortVlanTable_get_next(void **my_loop_context, void **my_data_context, netsnmp_variable_list *put_index_data, netsnmp_iterator_info *iinfo) { struct dot1qPortVlanTable_entry *entry = (struct dot1qPortVlanTable_entry *)*my_loop_context; netsnmp_variable_list *idx = put_index_data; if ( entry ) { snmp_set_var_typed_integer( idx, ASN_INTEGER, entry->ifIndex ); idx = idx->next_variable; *my_data_context = (void *)entry; *my_loop_context = (void *)entry->next; return put_index_data; } else { return NULL; } }
static void fan_status_handler__(netsnmp_request_info *req, uint32_t index, onlp_snmp_sensor_t *ss) { int value; onlp_fan_info_t *fi = &ss->sensor_info.fi; if (!ss->info_valid) { return; } value = ONLP_SNMP_SENSOR_STATUS_MISSING; if (fi->status & ONLP_FAN_STATUS_PRESENT) { value = ONLP_SNMP_SENSOR_STATUS_GOOD; if (fi->status & ONLP_FAN_STATUS_FAILED) { value = ONLP_SNMP_SENSOR_STATUS_FAILED; } } snmp_set_var_typed_integer(req->requestvb, ASN_INTEGER, value); }
/** handles requests for the mteEventTable table */ int mteEventTable_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { netsnmp_request_info *request; netsnmp_table_request_info *tinfo; netsnmp_tdata_row *row; struct mteEvent *entry; char mteOwner[MTE_STR1_LEN+1]; char mteEName[MTE_STR1_LEN+1]; long ret; DEBUGMSGTL(("disman:event:mib", "Event Table handler (%d)\n", reqinfo->mode)); switch (reqinfo->mode) { /* * Read-support (also covers GetNext requests) */ case MODE_GET: for (request = requests; request; request = request->next) { if (request->processed) continue; entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request); tinfo = netsnmp_extract_table_info(request); if (!entry || !(entry->flags & MTE_EVENT_FLAG_VALID)) continue; switch (tinfo->colnum) { case COLUMN_MTEEVENTCOMMENT: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, entry->mteEventComment, strlen(entry->mteEventComment)); break; case COLUMN_MTEEVENTACTIONS: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, &entry->mteEventActions, 1); break; case COLUMN_MTEEVENTENABLED: ret = (entry->flags & MTE_EVENT_FLAG_ENABLED ) ? TV_TRUE : TV_FALSE; snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret); break; case COLUMN_MTEEVENTENTRYSTATUS: ret = (entry->flags & MTE_EVENT_FLAG_ACTIVE ) ? RS_ACTIVE : RS_NOTINSERVICE; snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret); break; } } break; #ifndef NETSNMP_NO_WRITE_SUPPORT /* * Write-support */ case MODE_SET_RESERVE1: for (request = requests; request; request = request->next) { if (request->processed) continue; entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request); tinfo = netsnmp_extract_table_info(request); switch (tinfo->colnum) { case COLUMN_MTEEVENTCOMMENT: ret = netsnmp_check_vb_type_and_max_size( request->requestvb, ASN_OCTET_STR, MTE_STR1_LEN); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } /* * Can't modify the comment of an active row * (No good reason for this, but that's what the MIB says!) */ if (entry && entry->flags & MTE_EVENT_FLAG_ACTIVE ) { netsnmp_set_request_error(reqinfo, request, SNMP_ERR_INCONSISTENTVALUE); return SNMP_ERR_NOERROR; } break; case COLUMN_MTEEVENTACTIONS: ret = netsnmp_check_vb_type_and_size( request->requestvb, ASN_OCTET_STR, 1); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } /* * Can't modify the event types of an active row * (A little more understandable perhaps, * but still an unnecessary restriction IMO) */ if (entry && entry->flags & MTE_EVENT_FLAG_ACTIVE ) { netsnmp_set_request_error(reqinfo, request, SNMP_ERR_INCONSISTENTVALUE); return SNMP_ERR_NOERROR; } break; case COLUMN_MTEEVENTENABLED: ret = netsnmp_check_vb_truthvalue(request->requestvb); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } /* * The published version of the Event MIB forbids * enabling (or disabling) an active row, which * would make this object completely pointless! * Fortunately this ludicrous decision has since been corrected. */ break; case COLUMN_MTEEVENTENTRYSTATUS: ret = netsnmp_check_vb_rowstatus(request->requestvb, (entry ? RS_ACTIVE : RS_NONEXISTENT)); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } /* An active row can only be deleted */ if (entry && entry->flags & MTE_EVENT_FLAG_ACTIVE && *request->requestvb->val.integer == RS_NOTINSERVICE ) { netsnmp_set_request_error(reqinfo, request, SNMP_ERR_INCONSISTENTVALUE); return SNMP_ERR_NOERROR; } break; default: netsnmp_set_request_error(reqinfo, request, SNMP_ERR_NOTWRITABLE); return SNMP_ERR_NOERROR; } } break; case MODE_SET_RESERVE2: for (request = requests; request; request = request->next) { if (request->processed) continue; tinfo = netsnmp_extract_table_info(request); switch (tinfo->colnum) { case COLUMN_MTEEVENTENTRYSTATUS: switch (*request->requestvb->val.integer) { case RS_CREATEANDGO: case RS_CREATEANDWAIT: /* * Create an (empty) new row structure */ memset(mteOwner, 0, sizeof(mteOwner)); memcpy(mteOwner, tinfo->indexes->val.string, tinfo->indexes->val_len); memset(mteEName, 0, sizeof(mteEName)); memcpy(mteEName, tinfo->indexes->next_variable->val.string, tinfo->indexes->next_variable->val_len); row = mteEvent_createEntry(mteOwner, mteEName, 0); if (!row) { netsnmp_set_request_error(reqinfo, request, SNMP_ERR_RESOURCEUNAVAILABLE); return SNMP_ERR_NOERROR; } netsnmp_insert_tdata_row( request, row ); } } } break; case MODE_SET_FREE: for (request = requests; request; request = request->next) { if (request->processed) continue; tinfo = netsnmp_extract_table_info(request); switch (tinfo->colnum) { case COLUMN_MTEEVENTENTRYSTATUS: switch (*request->requestvb->val.integer) { case RS_CREATEANDGO: case RS_CREATEANDWAIT: /* * Tidy up after a failed row creation request */ entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request); if (entry && !(entry->flags & MTE_EVENT_FLAG_VALID)) { row = (netsnmp_tdata_row *) netsnmp_tdata_extract_row(request); mteEvent_removeEntry( row ); } } } } break; case MODE_SET_ACTION: for (request = requests; request; request = request->next) { if (request->processed) continue; tinfo = netsnmp_extract_table_info(request); entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request); if (!entry) { /* * New rows must be created via the RowStatus column */ netsnmp_set_request_error(reqinfo, request, SNMP_ERR_NOCREATION); /* or inconsistentName? */ return SNMP_ERR_NOERROR; } } break; case MODE_SET_UNDO: break; case MODE_SET_COMMIT: /* * All these assignments are "unfailable", so it's * (reasonably) safe to apply them in the Commit phase */ for (request = requests; request; request = request->next) { if (request->processed) continue; entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request); tinfo = netsnmp_extract_table_info(request); switch (tinfo->colnum) { case COLUMN_MTEEVENTCOMMENT: memset(entry->mteEventComment, 0, sizeof(entry->mteEventComment)); memcpy(entry->mteEventComment, request->requestvb->val.string, request->requestvb->val_len); break; case COLUMN_MTEEVENTACTIONS: entry->mteEventActions = request->requestvb->val.string[0]; break; case COLUMN_MTEEVENTENABLED: if (*request->requestvb->val.integer == TV_TRUE) entry->flags |= MTE_EVENT_FLAG_ENABLED; else entry->flags &= ~MTE_EVENT_FLAG_ENABLED; break; case COLUMN_MTEEVENTENTRYSTATUS: switch (*request->requestvb->val.integer) { case RS_ACTIVE: entry->flags |= MTE_EVENT_FLAG_ACTIVE; break; case RS_CREATEANDGO: entry->flags |= MTE_EVENT_FLAG_ACTIVE; /* fall-through */ case RS_CREATEANDWAIT: entry->flags |= MTE_EVENT_FLAG_VALID; entry->session = netsnmp_iquery_pdu_session(reqinfo->asp->pdu); break; case RS_DESTROY: row = (netsnmp_tdata_row *) netsnmp_tdata_extract_row(request); mteEvent_removeEntry(row); } } } break; #endif /* !NETSNMP_NO_WRITE_SUPPORT */ } DEBUGMSGTL(("disman:event:mib", "Table handler, done\n")); return SNMP_ERR_NOERROR; }
/* neIeee8021QBridgeVlanCurrentTable table mapper */ int neIeee8021QBridgeVlanCurrentTable_mapper ( netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { netsnmp_request_info *request; netsnmp_table_request_info *table_info; neIeee8021QBridgeVlanCurrentEntry_t *table_entry; register ieee8021QBridgeVlanCurrentEntry_t *poEntry = NULL; void *pvOldDdata = NULL; int ret; switch (reqinfo->mode) { /* * Read-support (also covers GetNext requests) */ case MODE_GET: for (request = requests; request != NULL; request = request->next) { poEntry = (ieee8021QBridgeVlanCurrentEntry_t*) netsnmp_extract_iterator_context (request); table_info = netsnmp_extract_table_info (request); if (poEntry == NULL) { netsnmp_set_request_error (reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } table_entry = &poEntry->oNe; switch (table_info->colnum) { case NEIEEE8021QBRIDGEVLANCURRENTADMINFLAGS: snmp_set_var_typed_value (request->requestvb, ASN_OCTET_STR, (u_char*) table_entry->au8AdminFlags, table_entry->u16AdminFlags_len); break; case NEIEEE8021QBRIDGEVLANCURRENTOPERSTATE: snmp_set_var_typed_integer (request->requestvb, ASN_INTEGER, table_entry->i32OperState); break; case NEIEEE8021QBRIDGEVLANCURRENTLEARNT: snmp_set_var_typed_value (request->requestvb, ASN_OCTET_STR, (u_char*) table_entry->pu8Learnt, table_entry->u16Learnt_len); break; case NEIEEE8021QBRIDGEVLANCURRENTIFINDEX: snmp_set_var_typed_integer (request->requestvb, ASN_INTEGER, table_entry->u32IfIndex); break; default: netsnmp_set_request_error (reqinfo, request, SNMP_NOSUCHOBJECT); break; } } break; /* * Write-support */ case MODE_SET_RESERVE1: for (request = requests; request != NULL; request = request->next) { poEntry = (ieee8021QBridgeVlanCurrentEntry_t*) netsnmp_extract_iterator_context (request); table_info = netsnmp_extract_table_info (request); table_entry = &poEntry->oNe; switch (table_info->colnum) { case NEIEEE8021QBRIDGEVLANCURRENTADMINFLAGS: ret = netsnmp_check_vb_type_and_max_size (request->requestvb, ASN_OCTET_STR, sizeof (table_entry->au8AdminFlags)); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error (reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; default: netsnmp_set_request_error (reqinfo, request, SNMP_ERR_NOTWRITABLE); return SNMP_ERR_NOERROR; } } break; case MODE_SET_RESERVE2: for (request = requests; request != NULL; request = request->next) { poEntry = (ieee8021QBridgeVlanCurrentEntry_t*) netsnmp_extract_iterator_context (request); table_info = netsnmp_extract_table_info (request); if (poEntry == NULL) { netsnmp_set_request_error (reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } table_entry = &poEntry->oNe; switch (table_info->colnum) { case NEIEEE8021QBRIDGEVLANCURRENTADMINFLAGS: if (poEntry->u8RowStatus == xRowStatus_active_c || poEntry->u8RowStatus == xRowStatus_notReady_c) { netsnmp_set_request_error (reqinfo, request, SNMP_ERR_RESOURCEUNAVAILABLE); return SNMP_ERR_NOERROR; } break; } } break; case MODE_SET_FREE: break; case MODE_SET_ACTION: for (request = requests; request != NULL; request = request->next) { pvOldDdata = netsnmp_request_get_list_data (request, ROLLBACK_BUFFER); poEntry = (ieee8021QBridgeVlanCurrentEntry_t*) netsnmp_extract_iterator_context (request); table_info = netsnmp_extract_table_info (request); table_entry = &poEntry->oNe; switch (table_info->colnum) { case NEIEEE8021QBRIDGEVLANCURRENTADMINFLAGS: if (pvOldDdata == NULL && (pvOldDdata = xBuffer_cAlloc (sizeof (xOctetString_t) + sizeof (table_entry->au8AdminFlags))) == NULL) { netsnmp_set_request_error (reqinfo, request, SNMP_ERR_RESOURCEUNAVAILABLE); return SNMP_ERR_NOERROR; } else if (pvOldDdata != table_entry) { ((xOctetString_t*) pvOldDdata)->pData = pvOldDdata + sizeof (xOctetString_t); ((xOctetString_t*) pvOldDdata)->u16Len = table_entry->u16AdminFlags_len; memcpy (((xOctetString_t*) pvOldDdata)->pData, table_entry->au8AdminFlags, sizeof (table_entry->au8AdminFlags)); netsnmp_request_add_list_data (request, netsnmp_create_data_list (ROLLBACK_BUFFER, pvOldDdata, &xBuffer_free)); } memset (table_entry->au8AdminFlags, 0, sizeof (table_entry->au8AdminFlags)); memcpy (table_entry->au8AdminFlags, request->requestvb->val.string, request->requestvb->val_len); table_entry->u16AdminFlags_len = request->requestvb->val_len; break; } } break; case MODE_SET_UNDO: for (request = requests; request != NULL; request = request->next) { pvOldDdata = netsnmp_request_get_list_data (request, ROLLBACK_BUFFER); poEntry = (ieee8021QBridgeVlanCurrentEntry_t*) netsnmp_extract_iterator_context (request); table_info = netsnmp_extract_table_info (request); if (poEntry == NULL || pvOldDdata == NULL) { continue; } table_entry = &poEntry->oNe; switch (table_info->colnum) { case NEIEEE8021QBRIDGEVLANCURRENTADMINFLAGS: memcpy (table_entry->au8AdminFlags, ((xOctetString_t*) pvOldDdata)->pData, ((xOctetString_t*) pvOldDdata)->u16Len); table_entry->u16AdminFlags_len = ((xOctetString_t*) pvOldDdata)->u16Len; break; } } break; case MODE_SET_COMMIT: break; } return SNMP_ERR_NOERROR; }
/** handles requests for the cpqSasPhyDrvTable table */ int cpqSasPhyDrvTable_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { netsnmp_request_info *request; netsnmp_table_request_info *table_info; cpqSasPhyDrvTable_entry *table_entry; DEBUGMSGTL(("cpqSasPhyDrvTable:handler", "Processing request (%d)\n", reqinfo->mode)); switch (reqinfo->mode) { /* * Read-support (also covers GetNext requests) */ case MODE_GET: for (request = requests; request; request = request->next) { if (request->processed) continue; table_entry = (cpqSasPhyDrvTable_entry *) netsnmp_container_table_extract_context(request); table_info = netsnmp_extract_table_info(request); if ((NULL == table_entry) || (NULL == table_info)) { snmp_log(LOG_ERR, "could not extract table entry or info for cpqSasPhyDrvTable\n"); snmp_set_var_typed_value(request->requestvb, SNMP_ERR_GENERR, NULL, 0); continue; } switch (table_info->colnum) { case COLUMN_CPQSASPHYDRVHBAINDEX: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry-> cpqSasPhyDrvHbaIndex); break; case COLUMN_CPQSASPHYDRVINDEX: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry->cpqSasPhyDrvIndex); break; case COLUMN_CPQSASPHYDRVLOCATIONSTRING: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, table_entry-> cpqSasPhyDrvLocationString, table_entry-> cpqSasPhyDrvLocationString_len); break; case COLUMN_CPQSASPHYDRVMODEL: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, table_entry->cpqSasPhyDrvModel, table_entry-> cpqSasPhyDrvModel_len); break; case COLUMN_CPQSASPHYDRVSTATUS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry-> cpqSasPhyDrvStatus); break; case COLUMN_CPQSASPHYDRVCONDITION: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry-> cpqSasPhyDrvCondition); break; case COLUMN_CPQSASPHYDRVFWREV: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, table_entry->cpqSasPhyDrvFWRev, table_entry-> cpqSasPhyDrvFWRev_len); break; case COLUMN_CPQSASPHYDRVSIZE: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry->cpqSasPhyDrvSize); break; case COLUMN_CPQSASPHYDRVUSEDREALLOCS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, table_entry-> cpqSasPhyDrvUsedReallocs); break; case COLUMN_CPQSASPHYDRVSERIALNUMBER: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, table_entry-> cpqSasPhyDrvSerialNumber, table_entry-> cpqSasPhyDrvSerialNumber_len); break; case COLUMN_CPQSASPHYDRVMEMBERLOGDRV: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry-> cpqSasPhyDrvMemberLogDrv); break; case COLUMN_CPQSASPHYDRVROTATIONALSPEED: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry-> cpqSasPhyDrvRotationalSpeed); break; case COLUMN_CPQSASPHYDRVOSNAME: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, table_entry->cpqSasPhyDrvOsName, table_entry-> cpqSasPhyDrvOsName_len); break; case COLUMN_CPQSASPHYDRVPLACEMENT: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry-> cpqSasPhyDrvPlacement); break; case COLUMN_CPQSASPHYDRVHOTPLUG: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry-> cpqSasPhyDrvHotPlug); break; case COLUMN_CPQSASPHYDRVTYPE: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry->cpqSasPhyDrvType); break; case COLUMN_CPQSASPHYDRVSASADDRESS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, table_entry-> cpqSasPhyDrvSasAddress, table_entry-> cpqSasPhyDrvSasAddress_len); break; case COLUMN_CPQSASPHYDRVMEDIATYPE: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry->cpqSasPhyDrvMediaType); break; case COLUMN_CPQSASPHYDRVSSDWEARSTATUS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry->cpqSasPhyDrvSSDWearStatus); break; case COLUMN_CPQSASPHYDRVPOWERONHOURS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, table_entry->cpqSasPhyDrvPowerOnHours); break; case COLUMN_CPQSASPHYDRVSSDPERCNTENDRNCEUSED: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_GAUGE, table_entry->cpqSasPhyDrvSSDPercntEndrnceUsed); break; case COLUMN_CPQSASPHYDRVSSDESTTIMEREMAININGHOURS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, table_entry->cpqSasPhyDrvSSDEstTimeRemainingHours); break; case COLUMN_CPQSASPHYDRVAUTHENTICATIONSTATUS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry->cpqSasPhyDrvAuthenticationStatus); break; case COLUMN_CPQSASPHYDRVSMARTCARRIERAPPFWREV: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry->cpqSasPhyDrvSmartCarrierAppFWRev); break; case COLUMN_CPQSASPHYDRVSMARTCARRIERBOOTLDRFWREV: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry->cpqSasPhyDrvSmartCarrierAppFWRev); break; case COLUMN_CPQSASPHYDRVCURRTEMPERATURE: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_GAUGE, table_entry->cpqSasPhyDrvCurrTemperature); break; case COLUMN_CPQSASPHYDRVTEMPERATURETHRESHOLD: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_GAUGE, table_entry->cpqSasPhyDrvTemperatureThreshold); break; default: netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT); break; } } break; } return SNMP_ERR_NOERROR; }
/** handles requests for the hrSWRunTable table */ int hrSWRunTable_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { netsnmp_request_info *request; netsnmp_table_request_info *table_info; netsnmp_swrun_entry *table_entry; switch (reqinfo->mode) { /* * Read-support (also covers GetNext requests) */ case MODE_GET: for (request = requests; request; request = request->next) { if (request->processed) continue; table_entry = (netsnmp_swrun_entry *) netsnmp_container_table_extract_context(request); table_info = netsnmp_extract_table_info(request); if ((NULL == table_entry) || (NULL == table_info)) { snmp_log(LOG_ERR, "could not extract table entry or info for " MYTABLE "\n"); snmp_set_var_typed_value(request->requestvb, SNMP_ERR_GENERR, NULL, 0); continue; } switch (table_info->colnum) { case COLUMN_HRSWRUNINDEX: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry->hrSWRunIndex); break; case COLUMN_HRSWRUNNAME: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) table_entry-> hrSWRunName, table_entry->hrSWRunName_len); break; case COLUMN_HRSWRUNID: snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID, #ifdef NETSNMP_SWRUN_HAVE_ID (u_char *) table_entry->hrSWRunID, table_entry->hrSWRunID_len #else (u_char *) &nullOid, nullOidLen #endif ); break; case COLUMN_HRSWRUNPATH: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) table_entry-> hrSWRunPath, table_entry->hrSWRunPath_len); break; case COLUMN_HRSWRUNPARAMETERS: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) table_entry-> hrSWRunParameters, table_entry-> hrSWRunParameters_len); break; case COLUMN_HRSWRUNTYPE: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry->hrSWRunType); break; case COLUMN_HRSWRUNSTATUS: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry->hrSWRunStatus); break; default: /* * An unsupported/unreadable column (if applicable) */ snmp_set_var_typed_value(request->requestvb, SNMP_NOSUCHOBJECT, NULL, 0); } } break; #ifndef NETSNMP_NO_WRITE_SUPPORT #ifdef NETSNMP_INCLUDE_HRSWRUN_WRITE_SUPPORT /* * Write-support */ case MODE_SET_RESERVE1: for (request = requests; request; request = request->next) { int pid; if (request->processed) continue; table_entry = (netsnmp_swrun_entry *) netsnmp_container_table_extract_context(request); table_info = netsnmp_extract_table_info(request); if ((NULL == table_entry) || (NULL == table_info)) { snmp_log(LOG_ERR, "could not extract table entry or info for " MYTABLE "\n"); snmp_set_var_typed_value(request->requestvb, SNMP_ERR_GENERR, NULL, 0); continue; } switch (table_info->colnum) { case COLUMN_HRSWRUNSTATUS: if (*request->requestvb->val.integer != HRSWRUNSTATUS_INVALID) { netsnmp_set_request_error(reqinfo, request, SNMP_ERR_WRONGVALUE); return SNMP_ERR_NOERROR; } pid = request->requestvb->name[request->requestvb->name_length-1]; if (1 == pid) { snmp_log(LOG_WARNING,"refusing to kill pid 1\n"); netsnmp_set_request_error(reqinfo, request, SNMP_ERR_NOACCESS); return SNMP_ERR_NOERROR; } break; default: netsnmp_set_request_error(reqinfo, request, SNMP_ERR_NOTWRITABLE); return SNMP_ERR_NOERROR; } } break; case MODE_SET_RESERVE2: break; case MODE_SET_FREE: break; case MODE_SET_ACTION: for (request = requests; request; request = request->next) { if (request->processed) continue; table_entry = (netsnmp_swrun_entry *) netsnmp_container_table_extract_context(request); table_info = netsnmp_extract_table_info(request); if ((NULL == table_entry) || (NULL == table_info)) { snmp_log(LOG_ERR, "could not extract table entry or info for " MYTABLE "\n"); snmp_set_var_typed_value(request->requestvb, SNMP_ERR_GENERR, NULL, 0); continue; } switch (table_info->colnum) { case COLUMN_HRSWRUNSTATUS: table_entry->old_hrSWRunStatus = table_entry->hrSWRunStatus; table_entry->hrSWRunStatus = *request->requestvb->val.integer; break; } } break; case MODE_SET_UNDO: for (request = requests; request; request = request->next) { if (request->processed) continue; container = netsnmp_container_table_extract_context(request); table_entry = (netsnmp_swrun_entry *) netsnmp_container_table_extract_context(request); table_info = netsnmp_extract_table_info(request); if ((NULL == table_entry) || (NULL == table_info)) { snmp_log(LOG_ERR, "could not extract table entry or info for " MYTABLE "\n"); snmp_set_var_typed_value(request->requestvb, SNMP_ERR_GENERR, NULL, 0); continue; } switch (table_info->colnum) { case COLUMN_HRSWRUNSTATUS: table_entry->hrSWRunStatus = table_entry->old_hrSWRunStatus; table_entry->old_hrSWRunStatus = 0; break; } } break; case MODE_SET_COMMIT: for (request = requests; request; request = request->next) { int pid; if (request->processed) continue; pid = request->requestvb->name[request->requestvb->name_length-1]; DEBUGMSGTL(("hrSWRunTable:commit", "kill(%d,TERM)\n", pid)); kill(pid, SIGTERM); } break; #endif /* NETSNMP_INCLUDE_HRSWRUN_WRITE_SUPPORT */ #endif /* !NETSNMP_NO_WRITE_SUPPORT */ } return SNMP_ERR_NOERROR; }
/** handles requests for the expObjectTable table */ int expObjectTable_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { netsnmp_request_info *request; netsnmp_table_request_info *tinfo; netsnmp_tdata_row *row; struct expObject *entry; struct expExpression *exp; char expOwner[EXP_STR1_LEN+1]; char expName[ EXP_STR1_LEN+1]; long objIndex; long ret; netsnmp_variable_list *vp; DEBUGMSGTL(("disman:expr:mib", "Expression Object Table handler (%d)\n", reqinfo->mode)); switch (reqinfo->mode) { /* * Read-support (also covers GetNext requests) */ case MODE_GET: for (request = requests; request; request = request->next) { entry = (struct expObject *)netsnmp_tdata_extract_entry(request); tinfo = netsnmp_extract_table_info(request); if (!entry || !(entry->flags & EXP_OBJ_FLAG_VALID)) continue; switch (tinfo->colnum) { case COLUMN_EXPOBJECTID: snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID, (u_char *) entry->expObjectID, entry->expObjectID_len*sizeof(oid)); break; case COLUMN_EXPOBJECTIDWILDCARD: ret = (entry->flags & EXP_OBJ_FLAG_OWILD) ? TV_TRUE : TV_FALSE; snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret); break; case COLUMN_EXPOBJECTSAMPLETYPE: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->expObjectSampleType); break; case COLUMN_EXPOBJECTDELTADISCONTINUITYID: /* * "This object [and the next two] are instantiated only if * expObjectSampleType is 'deltaValue' or 'changedValue'" */ if ( entry->expObjectSampleType == 1 ) continue; snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID, (u_char *) entry->expObjDeltaD, entry->expObjDeltaD_len*sizeof(oid)); break; case COLUMN_EXPOBJECTDISCONTINUITYIDWILDCARD: if ( entry->expObjectSampleType == 1 ) continue; ret = (entry->flags & EXP_OBJ_FLAG_DWILD) ? TV_TRUE : TV_FALSE; snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret); break; case COLUMN_EXPOBJECTDISCONTINUITYIDTYPE: if ( entry->expObjectSampleType == 1 ) continue; snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->expObjDiscontinuityType); break; case COLUMN_EXPOBJECTCONDITIONAL: snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID, (u_char *) entry->expObjCond, entry->expObjCond_len*sizeof(oid)); break; case COLUMN_EXPOBJECTCONDITIONALWILDCARD: ret = (entry->flags & EXP_OBJ_FLAG_CWILD) ? TV_TRUE : TV_FALSE; snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret); break; case COLUMN_EXPOBJECTENTRYSTATUS: /* What would indicate 'notReady' ? */ ret = (entry->flags & EXP_OBJ_FLAG_ACTIVE) ? RS_ACTIVE : RS_NOTINSERVICE; snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret); break; } } break; /* * Write-support */ case MODE_SET_RESERVE1: for (request = requests; request; request = request->next) { entry = (struct expObject *) netsnmp_tdata_extract_entry(request); tinfo = netsnmp_extract_table_info(request); switch (tinfo->colnum) { case COLUMN_EXPOBJECTID: case COLUMN_EXPOBJECTDELTADISCONTINUITYID: case COLUMN_EXPOBJECTCONDITIONAL: ret = netsnmp_check_vb_oid(request->requestvb); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_EXPOBJECTIDWILDCARD: case COLUMN_EXPOBJECTDISCONTINUITYIDWILDCARD: case COLUMN_EXPOBJECTCONDITIONALWILDCARD: ret = netsnmp_check_vb_truthvalue(request->requestvb); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_EXPOBJECTSAMPLETYPE: case COLUMN_EXPOBJECTDISCONTINUITYIDTYPE: ret = netsnmp_check_vb_int_range(request->requestvb, 1, 3); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_EXPOBJECTENTRYSTATUS: ret = netsnmp_check_vb_rowstatus(request->requestvb, (entry ? RS_ACTIVE : RS_NONEXISTENT)); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; default: netsnmp_set_request_error(reqinfo, request, SNMP_ERR_NOTWRITABLE); return SNMP_ERR_NOERROR; } } break; case MODE_SET_RESERVE2: for (request = requests; request; request = request->next) { tinfo = netsnmp_extract_table_info(request); switch (tinfo->colnum) { case COLUMN_EXPOBJECTENTRYSTATUS: switch (*request->requestvb->val.integer) { case RS_CREATEANDGO: case RS_CREATEANDWAIT: /* * Create an (empty) new row structure */ memset(expOwner, 0, sizeof(expOwner)); memcpy(expOwner, tinfo->indexes->val.string, tinfo->indexes->val_len); memset(expName, 0, sizeof(expName)); memcpy(expName, tinfo->indexes->next_variable->val.string, tinfo->indexes->next_variable->val_len); vp = tinfo->indexes->next_variable->next_variable; objIndex = *vp->val.integer; row = expObject_createRow(expOwner, expName, objIndex, 0); if (!row) { netsnmp_set_request_error(reqinfo, request, SNMP_ERR_RESOURCEUNAVAILABLE); return SNMP_ERR_NOERROR; } netsnmp_insert_tdata_row( request, row ); } } } break; case MODE_SET_FREE: for (request = requests; request; request = request->next) { tinfo = netsnmp_extract_table_info(request); switch (tinfo->colnum) { case COLUMN_EXPOBJECTENTRYSTATUS: switch (*request->requestvb->val.integer) { case RS_CREATEANDGO: case RS_CREATEANDWAIT: /* * Tidy up after a failed row creation request */ entry = (struct expObject *) netsnmp_tdata_extract_entry(request); if (entry && !(entry->flags & EXP_OBJ_FLAG_VALID)) { row = (netsnmp_tdata_row *) netsnmp_tdata_extract_row(request); expObject_removeEntry( row ); } } } } break; case MODE_SET_ACTION: for (request = requests; request; request = request->next) { tinfo = netsnmp_extract_table_info(request); entry = (struct expObject *) netsnmp_tdata_extract_entry(request); if (!entry) { /* * New rows must be created via the RowStatus column */ netsnmp_set_request_error(reqinfo, request, SNMP_ERR_NOCREATION); /* or inconsistentName? */ return SNMP_ERR_NOERROR; } } break; case MODE_SET_UNDO: break; case MODE_SET_COMMIT: /* * All these assignments are "unfailable", so it's * (reasonably) safe to apply them in the Commit phase */ ret = 0; /* Flag to re-check expExpressionPrefix settings */ for (request = requests; request; request = request->next) { entry = (struct expObject *) netsnmp_tdata_extract_entry(request); tinfo = netsnmp_extract_table_info(request); switch (tinfo->colnum) { case COLUMN_EXPOBJECTID: memset(entry->expObjectID, 0, sizeof(entry->expObjectID)); memcpy(entry->expObjectID, request->requestvb->val.string, request->requestvb->val_len); entry->expObjectID_len = request->requestvb->val_len; break; case COLUMN_EXPOBJECTIDWILDCARD: if (*request->requestvb->val.integer == TV_TRUE) entry->flags |= EXP_OBJ_FLAG_OWILD; else entry->flags &= ~EXP_OBJ_FLAG_OWILD; break; case COLUMN_EXPOBJECTSAMPLETYPE: entry->expObjectSampleType = *request->requestvb->val.integer; break; case COLUMN_EXPOBJECTDELTADISCONTINUITYID: memset(entry->expObjDeltaD, 0, sizeof(entry->expObjDeltaD)); memcpy(entry->expObjDeltaD, request->requestvb->val.string, request->requestvb->val_len); entry->expObjDeltaD_len = request->requestvb->val_len/sizeof(oid); /* XXX if ( snmp_oid_compare( entry->expObjDeltaD, entry->expObjDeltaD_len, sysUpTime_inst, sysUpTime_inst_len ) != 0 ) entry->flags |= EXP_OBJ_FLAG_DDISC; */ /* * If the OID used for the expExpressionPrefix object * has changed, then update the expression structure. */ if ( entry->flags & EXP_OBJ_FLAG_PREFIX ) { exp = expExpression_getEntry( entry->expOwner, entry->expName ); memcpy( exp->expPrefix, entry->expObjDeltaD, MAX_OID_LEN*sizeof(oid)); exp->expPrefix_len = entry->expObjDeltaD_len; } break; case COLUMN_EXPOBJECTDISCONTINUITYIDWILDCARD: if (*request->requestvb->val.integer == TV_TRUE) { /* * Possible new prefix OID candidate * Can't set the value here, since the OID * assignment might not have been processed yet. */ exp = expExpression_getEntry( entry->expOwner, entry->expName ); if (exp && exp->expPrefix_len == 0 ) ret = 1; /* Set the prefix later */ entry->flags |= EXP_OBJ_FLAG_DWILD; } else { if ( entry->flags | EXP_OBJ_FLAG_PREFIX ) { exp = expExpression_getEntry( entry->expOwner, entry->expName ); memset( exp->expPrefix, 0, MAX_OID_LEN*sizeof(oid)); exp->expPrefix_len = 0; ret = 1; /* Need a new prefix OID */ } entry->flags &= ~EXP_OBJ_FLAG_DWILD; } break; case COLUMN_EXPOBJECTDISCONTINUITYIDTYPE: entry->expObjDiscontinuityType = *request->requestvb->val.integer; break; case COLUMN_EXPOBJECTCONDITIONAL: memset(entry->expObjCond, 0, sizeof(entry->expObjCond)); memcpy(entry->expObjCond, request->requestvb->val.string, request->requestvb->val_len); entry->expObjCond_len = request->requestvb->val_len/sizeof(oid); break; case COLUMN_EXPOBJECTCONDITIONALWILDCARD: if (*request->requestvb->val.integer == TV_TRUE) entry->flags |= EXP_OBJ_FLAG_CWILD; else entry->flags &= ~EXP_OBJ_FLAG_CWILD; break; case COLUMN_EXPOBJECTENTRYSTATUS: switch (*request->requestvb->val.integer) { case RS_ACTIVE: entry->flags |= EXP_OBJ_FLAG_ACTIVE; break; case RS_NOTINSERVICE: entry->flags &= ~EXP_OBJ_FLAG_ACTIVE; break; case RS_CREATEANDGO: entry->flags |= EXP_OBJ_FLAG_ACTIVE; entry->flags |= EXP_OBJ_FLAG_VALID; break; case RS_CREATEANDWAIT: entry->flags |= EXP_OBJ_FLAG_VALID; break; case RS_DESTROY: row = (netsnmp_tdata_row *) netsnmp_tdata_extract_row(request); expObject_removeEntry(row); } } } /* * Need to check for changes in expExpressionPrefix handling */ for (request = requests; request; request = request->next) { entry = (struct expObject *) netsnmp_tdata_extract_entry(request); tinfo = netsnmp_extract_table_info(request); switch (tinfo->colnum) { case COLUMN_EXPOBJECTDISCONTINUITYIDWILDCARD: /* * If a column has just been marked as wild, * then consider using it as the prefix OID */ if (*request->requestvb->val.integer == TV_TRUE) { exp = expExpression_getEntry( entry->expOwner, entry->expName ); if ( exp->expPrefix_len == 0 ) { memcpy( exp->expPrefix, entry->expObjDeltaD, MAX_OID_LEN*sizeof(oid)); exp->expPrefix_len = entry->expObjDeltaD_len; entry->flags |= EXP_OBJ_FLAG_PREFIX; } } /* * If it's just been marked as non-wildcarded * then we need to look for a new candidate. */ else { } break; } } break; } DEBUGMSGTL(("disman:expr:mib", "Expression Object handler - done \n")); return SNMP_ERR_NOERROR; }
/** handles requests for the cpqLinOsProcessorTable table */ int cpqLinOsProcessorTable_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { netsnmp_request_info *request; netsnmp_table_request_info *table_info; cpqLinOsProcessorTable_entry *table_entry; DEBUGMSGTL(("cpqLinOsProcessorTable:handler", "Processing request (%d)\n", reqinfo->mode)); switch (reqinfo->mode) { /* * Read-support (also covers GetNext requests) */ case MODE_GET: for (request = requests; request; request = request->next) { if (request->processed) continue; table_entry = (cpqLinOsProcessorTable_entry *) netsnmp_container_table_extract_context(request); table_info = netsnmp_extract_table_info(request); if ((NULL == table_entry) || (NULL == table_info)) { snmp_log(LOG_ERR, "could not extract table entry or info for cpqLinOsProcessorTable\n"); snmp_set_var_typed_value(request->requestvb, SNMP_ERR_GENERR, NULL, 0); continue; } switch (table_info->colnum) { case COLUMN_CPQLINOSCPUINDEX: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry->cpqLinOsCpuIndex); break; case COLUMN_CPQLINOSCPUINSTANCE: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, table_entry->cpqLinOsCpuInstance, table_entry-> cpqLinOsCpuInstance_len); break; case COLUMN_CPQLINOSCPUINTERRUPTSPERSEC: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry-> cpqLinOsCpuInterruptsPerSec); break; case COLUMN_CPQLINOSCPUTIMEPERCENT: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry-> cpqLinOsCpuTimePercent); break; case COLUMN_CPQLINOSCPUUSERTIMEPERCENT: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry-> cpqLinOsCpuUserTimePercent); break; case COLUMN_CPQLINOSCPUPRIVILEGEDTIMEPERCENT: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry-> cpqLinOsCpuPrivilegedTimePercent); break; default: netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT); break; } } break; } return SNMP_ERR_NOERROR; }
int handle_channelList(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { netsnmp_request_info *request; netsnmp_table_request_info *table_info; chan_entry_t *entry; char dt_str[12]; switch (reqinfo->mode) { case MODE_GET: for (request = requests; request; request = request->next) { if (request->processed) continue; table_info = netsnmp_extract_table_info(request); entry = (chan_entry_t *) netsnmp_tdata_extract_entry(request); switch (table_info->colnum) { case CH_INDEX: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->idx); break; case CH_UUID: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->uuid, strlen(entry->uuid)); break; case CH_DIRECTION: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->direction, strlen(entry->direction)); break; case CH_CREATED: time_t_to_datetime(entry->created_epoch, (char *) &dt_str, sizeof(dt_str)); snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) &dt_str, sizeof(dt_str)); break; case CH_NAME: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->name, strlen(entry->name)); break; case CH_STATE: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->state, strlen(entry->state)); break; case CH_CID_NAME: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->cid_name, strlen(entry->cid_name)); break; case CH_CID_NUM: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->cid_num, strlen(entry->cid_num)); break; case CH_IP_ADDR_TYPE: if (entry->addr_family == AF_INET6) { snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, INETADDRESSTYPE_IPV6); } else { snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, INETADDRESSTYPE_IPV4); } break; case CH_IP_ADDR: if (entry->addr_family == AF_INET6) { snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) &entry->ip_addr.v6, sizeof(entry->ip_addr.v6)); } else { snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) &entry->ip_addr.v4, sizeof(entry->ip_addr.v4)); } break; case CH_DEST: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->dest, strlen(entry->dest)); break; case CH_APPLICATION: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->application, strlen(entry->application)); break; case CH_APPLICATION_DATA: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->application_data, strlen(entry->application_data)); break; case CH_DIALPLAN: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->dialplan, strlen(entry->dialplan)); break; case CH_CONTEXT: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->context, strlen(entry->context)); break; case CH_READ_CODEC: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->read_codec, strlen(entry->read_codec)); break; case CH_READ_RATE: snmp_set_var_typed_value(request->requestvb, ASN_GAUGE, (u_char *) &entry->read_rate, sizeof(entry->read_rate)); break; case CH_READ_BITRATE: snmp_set_var_typed_value(request->requestvb, ASN_GAUGE, (u_char *) &entry->read_bitrate, sizeof(entry->read_bitrate)); break; case CH_WRITE_CODEC: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->write_codec, strlen(entry->write_codec)); break; case CH_WRITE_RATE: snmp_set_var_typed_value(request->requestvb, ASN_GAUGE, (u_char *) &entry->write_rate, sizeof(entry->write_rate)); break; case CH_WRITE_BITRATE: snmp_set_var_typed_value(request->requestvb, ASN_GAUGE, (u_char *) &entry->write_bitrate, sizeof(entry->write_bitrate)); break; default: snmp_log(LOG_WARNING, "Unregistered OID-suffix requested (%d)\n", table_info->colnum); netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT); } } break; default: /* we should never get here, so this is a really bad error */ snmp_log(LOG_ERR, "Unknown mode (%d) in handle_channelList\n", reqinfo->mode ); return SNMP_ERR_GENERR; } return SNMP_ERR_NOERROR; }
/******************************************************************************* 函数名称 : mib_etherHistoryTable_handler 功能描述 : handles requests for the etherHistoryTable table 输入参数 : 输出参数 : 返 回 值 : -------------------------------------------------------------------------------- 最近一次修改记录 : 修改作者 : 修改目的 : 修改日期 : *******************************************************************************/ static int mib_etherHistoryTable_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { netsnmp_request_info *request; netsnmp_table_request_info *table_req_info; struct etherHistoryTable_entry *table_entry; switch (reqinfo->mode) { /* * 这里的GET操作已经覆盖了GET_NEXT操作 */ case MODE_GET: for (request = requests; request; request = request->next) { table_entry = (struct etherHistoryTable_entry *) netsnmp_extract_iterator_context(request); table_req_info = netsnmp_extract_table_info(request); if (NULL == table_req_info) { netsnmp_set_request_error(reqinfo, request, SNMP_ERR_NOACCESS); continue; } switch (table_req_info->colnum) { case COLUMN_ETHERHISTORYINDEX: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, htonl(table_entry-> etherHistoryIndex)); break; case COLUMN_ETHERHISTORYSAMPLEINDEX: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, htonl(table_entry-> etherHistorySampleIndex)); break; case COLUMN_ETHERHISTORYINTERVALSTART: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_TIMETICKS, htonl(table_entry-> etherHistoryIntervalStart)); break; case COLUMN_ETHERHISTORYDROPEVENTS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, htonl(table_entry-> etherHistoryDropEvents)); break; case COLUMN_ETHERHISTORYOCTETS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, htonl(table_entry-> etherHistoryOctets)); break; case COLUMN_ETHERHISTORYPKTS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, htonl(table_entry-> etherHistoryPkts)); break; case COLUMN_ETHERHISTORYBROADCASTPKTS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, htonl(table_entry-> etherHistoryBroadcastPkts)); break; case COLUMN_ETHERHISTORYMULTICASTPKTS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, htonl(table_entry-> etherHistoryMulticastPkts)); break; case COLUMN_ETHERHISTORYCRCALIGNERRORS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, htonl(table_entry-> etherHistoryCRCAlignErrors)); break; case COLUMN_ETHERHISTORYUNDERSIZEPKTS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, htonl(table_entry-> etherHistoryUndersizePkts)); break; case COLUMN_ETHERHISTORYOVERSIZEPKTS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, htonl(table_entry-> etherHistoryOversizePkts)); break; case COLUMN_ETHERHISTORYFRAGMENTS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, htonl(table_entry-> etherHistoryFragments)); break; case COLUMN_ETHERHISTORYJABBERS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, htonl(table_entry-> etherHistoryJabbers)); break; case COLUMN_ETHERHISTORYCOLLISIONS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, htonl(table_entry-> etherHistoryCollisions)); break; case COLUMN_ETHERHISTORYUTILIZATION: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, htonl(table_entry-> etherHistoryUtilization)); break; default: netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT); break; } } break; } return SNMP_ERR_NOERROR; }
/******************************************************************************* 函数名称 : mib_etherHistoryTable_get_first 功能描述 : Example iterator hook routines 输入参数 : 输出参数 : 返 回 值 : -------------------------------------------------------------------------------- 最近一次修改记录 : 修改作者 : 修改目的 : 修改日期 : *******************************************************************************/ static netsnmp_variable_list * mib_etherHistoryTable_get_first(void **my_loop_context, void **my_data_context, netsnmp_variable_list * put_index_data, netsnmp_iterator_info *iinfo) { netsnmp_table_request_info *table_req_info; unsigned int number_indexes; netsnmp_variable_list *req_index, *put_idx = put_index_data; int mode; long etherHistoryIndex; long etherHistorySampleIndex; struct etherHistoryTable_entry *entry; table_req_info = *my_loop_context; if (table_req_info) { number_indexes = table_req_info->number_indexes; req_index = table_req_info->indexes; /* * Compute request indexes */ if (number_indexes > 0) { etherHistoryIndex = ntohl(*(req_index->val.integer)); req_index = req_index->next_variable; number_indexes--; } else { etherHistoryIndex = 0; } if (number_indexes > 0) { etherHistorySampleIndex = ntohl(*(req_index->val.integer)); req_index = req_index->next_variable; number_indexes--; } else { etherHistorySampleIndex = 0; } mode = *(int *) my_data_context; iinfo->myvoid = (void *) my_data_context; switch (mode) { case MODE_GET: case MODE_SET_RESERVE1: break; case MODE_GETNEXT: if (0 != mib_etherHistoryTable_get_next_index(ðerHistoryIndex, ðerHistorySampleIndex) ) { //No record return NULL; } break; default: return NULL; } } else { //Get the first row if (0 != mib_etherHistoryTable_get_first_index(ðerHistoryIndex, ðerHistorySampleIndex) ) { //No record return NULL; } } entry = mib_etherHistoryTable_createEntry( //这里分配的内存在请求处理完成后释放 etherHistoryIndex, etherHistorySampleIndex); if (entry) { snmp_set_var_typed_integer(put_idx, ASN_INTEGER, entry->etherHistoryIndex); put_idx = put_idx->next_variable; snmp_set_var_typed_integer(put_idx, ASN_INTEGER, entry->etherHistorySampleIndex); put_idx = put_idx->next_variable; *my_data_context = (void *) entry; return put_index_data; } else { return NULL; } }
/** handles requests for the tlstmCertToTSNTable table */ static int tlstmCertToTSNTable_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { oid tsnm[] = { SNMP_TLS_TM_BASE, 1, 1, 0 }; static const int tsnm_pos = OID_LENGTH(tsnm) - 1; netsnmp_request_info *request = NULL; netsnmp_table_request_info *info; netsnmp_tdata *table; netsnmp_tdata_row *row; certToTSN_entry *entry; int ret = SNMP_ERR_NOERROR; DEBUGMSGTL(("tlstmCertToSN:handler", "Processing request (mode %s (%d))\n", se_find_label_in_slist("agent_mode", reqinfo->mode), reqinfo->mode)); switch (reqinfo->mode) { /** ######################################################### GET ##### * * Read-support (also covers GetNext requests) */ case MODE_GET: for (request = requests; request; request = request->next) { if (request->processed) continue; entry = (certToTSN_entry *) netsnmp_tdata_extract_entry(request); info = netsnmp_extract_table_info(request); netsnmp_assert(entry && info); switch (info->colnum) { case COL_SNMPTLSTMCERTTOTSN_FINGERPRINT: { /* * build SnmpTLSFingerprint */ u_char bin[42], *ptr = bin; size_t len = sizeof(bin); int rc; rc = netsnmp_tls_fingerprint_build(entry->hashType, entry->fingerprint, &ptr, &len, 0); if (SNMPERR_SUCCESS != rc) netsnmp_set_request_error(reqinfo, request, SNMP_ERR_GENERR); else snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, bin, len); } break; /* case COL_SNMPTLSTMCERTTOTSN_FINGERPRINT */ case COL_SNMPTLSTMCERTTOTSN_MAPTYPE: tsnm[tsnm_pos] = entry->mapType; snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID, tsnm, sizeof(tsnm)); break; /* case COL_SNMPTLSTMCERTTOTSN_MAPTYPE */ case COL_SNMPTLSTMCERTTOTSN_DATA: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, entry->data, entry->data_len); break; /* case COL_SNMPTLSTMCERTTOTSN_DATA */ case COL_SNMPTLSTMCERTTOTSN_STORAGETYPE: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->storageType); break; /* case COL_SNMPTLSTMCERTTOTSN_STORAGETYPE */ case COL_SNMPTLSTMCERTTOTSN_ROWSTATUS: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->rowStatus); break; /* case COL_SNMPTLSTMCERTTOTSN_ROWSTATUS */ default: netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT); break; } /* switch colnum */ } /* for requests */ break; /* case MODE_GET */ /* * Write-support */ /** #################################################### RESERVE1 ##### * * In RESERVE1 we are just checking basic ASN.1 size/type restrictions. * You probably don't need to change any of this code. Don't change any * of the column values here. Save that for the ACTION phase. * * The next phase is RESERVE2 or FREE. */ case MODE_SET_RESERVE1: for (request = requests; request; request = request->next) { netsnmp_assert(request->processed == 0); entry = (certToTSN_entry *) netsnmp_tdata_extract_entry(request); info = netsnmp_extract_table_info(request); if ((NULL != entry) && (ST_READONLY == entry->storageType)) { ret = SNMP_ERR_NOTWRITABLE; break; } switch (info->colnum) { case COL_SNMPTLSTMCERTTOTSN_FINGERPRINT: ret = netsnmp_check_vb_type_and_max_size (request->requestvb, ASN_OCTET_STR, sizeof(entry->fingerprint)); /** check len/algorithm MIB requirements */ if (ret == SNMP_ERR_NOERROR) ret = netsnmp_cert_check_vb_fingerprint(request->requestvb); break; /* case COL_SNMPTLSTMCERTTOTSN_FINGERPRINT */ case COL_SNMPTLSTMCERTTOTSN_MAPTYPE: ret = netsnmp_check_vb_type_and_max_size (request->requestvb, ASN_OBJECT_ID, SNMPTLSTMCERTTOTSN_MAPTYPE_MAX_SIZE); if (ret == SNMP_ERR_NOERROR) { if (_oid2type(request->requestvb->val.objid, request->requestvb->val_len) > TSNM_tlstmCert_MAX) ret = SNMP_ERR_WRONGVALUE; } break; /* case COL_SNMPTLSTMCERTTOTSN_MAPTYPE */ case COL_SNMPTLSTMCERTTOTSN_DATA: ret = netsnmp_check_vb_type_and_max_size (request->requestvb, ASN_OCTET_STR, sizeof(entry->data)); break; /* case COL_SNMPTLSTMCERTTOTSN_DATA */ case COL_SNMPTLSTMCERTTOTSN_STORAGETYPE: ret = netsnmp_check_vb_storagetype (request->requestvb,(entry ? entry->storageType : ST_NONE)); break; /* case COL_SNMPTLSTMCERTTOTSN_STORAGETYPE */ case COL_SNMPTLSTMCERTTOTSN_ROWSTATUS: ret = netsnmp_check_vb_rowstatus_with_storagetype (request->requestvb, (entry ? entry->rowStatus :RS_NONEXISTENT), (entry ? entry->storageType :ST_NONE)); break; /* case COL_SNMPTLSTMCERTTOTSN_ROWSTATUS */ default: ret = SNMP_ERR_NOTWRITABLE; } /* switch colnum */ if (ret != SNMP_ERR_NOERROR) break; } /* for requests */ break; /* case MODE_SET_RESERVE1 */ /** #################################################### RESERVE2 ##### * * RESERVE2 is for checking additional restrictions from the MIB. * Since these restrictions are often in the description of the object, * mib2c can't generate code. It's possible that you need to add * additional checks here. However, don't change any of the column * values here. Save that for the ACTION phase. * * The next phase is ACTION or FREE. */ case MODE_SET_RESERVE2: for (request = requests; request; request = request->next) { netsnmp_assert(request->processed == 0); entry = (certToTSN_entry *) netsnmp_tdata_extract_entry(request); table = netsnmp_tdata_extract_table(request); info = netsnmp_extract_table_info(request); /* * if no row, create one */ if (!entry) { row = tlstmCertToTSNTable_createEntry (table,*info->indexes->val.integer); if (!row) { ret = SNMP_ERR_RESOURCEUNAVAILABLE; break; } entry = row->data; _allocUndo(entry); if (!entry->undo) { tlstmCertToTSNTable_removeEntry(table, row); row = NULL; ret = SNMP_ERR_RESOURCEUNAVAILABLE; break; } entry->undo->fate = FATE_NEWLY_CREATED; /** associate row with requests */ netsnmp_insert_tdata_row(request, row); } /** allocate undo structure, if needed */ if (!entry->undo) { _allocUndo(entry); if (!entry->undo) { ret = SNMP_ERR_RESOURCEUNAVAILABLE; break; } } /* * save request ptr for column. if we already * have a value, bail. */ if (entry->undo->req[info->colnum]) { DEBUGMSGT(("tlstmCertToSN:reserve2", "multiple sets to col %d in request\n", info->colnum)); if (FATE_NEWLY_CREATED == entry->undo->fate) ret = SNMP_ERR_INCONSISTENTNAME; else ret = SNMP_ERR_INCONSISTENTVALUE; break; } entry->undo->req[info->colnum] = request; if (ret != SNMP_ERR_NOERROR) break; } /* for requests */ if (ret == SNMP_ERR_NOERROR) { /** make sure rowstatus is used to create rows */ for (request = requests; request; request = request->next) { if (request->processed) continue; entry = (certToTSN_entry *) netsnmp_tdata_extract_entry(request); if ((entry->undo->fate != FATE_NEWLY_CREATED) || (entry->undo->req[COL_SNMPTLSTMCERTTOTSN_ROWSTATUS])) continue; ret = SNMP_ERR_INCONSISTENTNAME; break; } /* creation for requests */ } /* no error */ break; /* case MODE_SET_RESERVE2 */ /** ######################################################## FREE ##### * * FREE is for cleaning up after a failed request (during either * RESERVE1 or RESERVE2). So any allocated resources need to be * released. * * This the final phase for this path in the state machine. */ case MODE_SET_FREE: /* * release undo resources * remove any newly created rows */ for (request = requests; request; request = request->next) { table = netsnmp_tdata_extract_table(request); row = netsnmp_tdata_extract_row(request); entry = (certToTSN_entry *) netsnmp_tdata_extract_entry(request); if (!entry || !entry->undo) continue; /** disassociate row with requests */ netsnmp_remove_tdata_row(request, row); if (FATE_NEWLY_CREATED == entry->undo->fate) tlstmCertToTSNTable_removeEntry(table, row); else _freeUndo(entry); } break; /* case MODE_SET_FREE */ /** ###################################################### ACTION ##### * * In the ACTION phase, we perform any sets that can be undone. * (Save anything that can't be undone for the COMMIT phase.) * * After individual columns have been done, you should check that the * row as a whole is consistent. * * The next phase is UNDO or COMMIT. */ case MODE_SET_ACTION: for (request = requests; request; request = request->next) { entry = (certToTSN_entry *) netsnmp_tdata_extract_entry(request); info = netsnmp_extract_table_info(request); /** reserve2 should enforce this */ netsnmp_assert(request == entry->undo->req[info->colnum]); /* * for each col, save old value and the set new value */ switch (info->colnum) { case COL_SNMPTLSTMCERTTOTSN_FINGERPRINT: { u_char *tmp = (u_char*)entry->fingerprint; u_int size = sizeof(entry->fingerprint); netsnmp_variable_list *vb = request->requestvb; memcpy(entry->undo->fingerprint, entry->fingerprint, sizeof(entry->fingerprint)); entry->undo->fingerprint_len = entry->fingerprint_len; entry->undo->hashType = entry->hashType; memset(entry->fingerprint, 0, sizeof(entry->fingerprint)); (void)netsnmp_tls_fingerprint_parse(vb->val.string, vb->val_len, (char**)&tmp, &size, 0, &entry->hashType); entry->fingerprint_len = size; if (0 == entry->fingerprint_len) ret = SNMP_ERR_GENERR; } break; /* case COL_SNMPTLSTMCERTTOTSN_FINGERPRINT */ case COL_SNMPTLSTMCERTTOTSN_MAPTYPE: entry->undo->mapType = entry->mapType; entry->mapType = _oid2type(request->requestvb->val.objid, request->requestvb->val_len); break; /* case COL_SNMPTLSTMCERTTOTSN_MAPTYPE */ case COL_SNMPTLSTMCERTTOTSN_DATA: memcpy(entry->undo->data, entry->data, sizeof(entry->data)); entry->undo->data_len = entry->data_len; memset(entry->data, 0, sizeof(entry->data)); memcpy(entry->data, request->requestvb->val.string, request->requestvb->val_len); entry->data_len = request->requestvb->val_len; break; /* case COL_SNMPTLSTMCERTTOTSN_DATA */ case COL_SNMPTLSTMCERTTOTSN_STORAGETYPE: entry->undo->storageType = entry->storageType; entry->storageType = *request->requestvb->val.integer; break; /* case COL_SNMPTLSTMCERTTOTSN_STORAGETYPE */ case COL_SNMPTLSTMCERTTOTSN_ROWSTATUS: entry->undo->rowStatus = entry->rowStatus; entry->rowStatus = *request->requestvb->val.integer; break; /* case COL_SNMPTLSTMCERTTOTSN_ROWSTATUS */ } /* switch colnum */ } /* set values for requests */ if (ret != SNMP_ERR_NOERROR) break; /* skip consistency if we've already got error */ /* * All columns now have their final values set. check the * internal consistency of each row. */ for (request = requests; request; request = request->next) { entry = (certToTSN_entry *) netsnmp_tdata_extract_entry(request); info = netsnmp_extract_table_info(request); if (entry->undo->is_consistent != -1) continue; /* already checked */ /** assume consistency */ entry->undo->is_consistent = 1; /* * per mib, can't have empty fingerprint and must * have data if indicated by map type. */ if (0 == entry->fingerprint_len) { DEBUGMSGTL(("tlstmCertToTSNTable:inconsistent", "fingerprint must not be empty\n")); entry->undo->is_consistent = 0; } else if ((TSNM_tlstmCertSpecified == entry->mapType) && (0 == entry->data_len)) { DEBUGMSGTL(("tlstmCertToTSNTable:inconsistent", "must specify Data for CertSpecified identity\n")); entry->undo->is_consistent = 0; } if ((RS_IS_ACTIVE(entry->rowStatus)) && ((!entry->undo->req[COL_SNMPTLSTMCERTTOTSN_ROWSTATUS]) || (RS_IS_ACTIVE(entry->undo->rowStatus)))) { /* * per mib, can't modify these while row active */ char _cols[3] = { COL_SNMPTLSTMCERTTOTSN_FINGERPRINT, COL_SNMPTLSTMCERTTOTSN_MAPTYPE, COL_SNMPTLSTMCERTTOTSN_DATA }; int i; for (i=0; i < 3; ++i ) { if (!entry->undo->req[i]) continue; DEBUGMSGTL(("tlstmCertToTSNTable:inconsistent", "can't modify row %d while active\n", _cols[i])); entry->undo->is_consistent = 0; ret = SNMP_ERR_NOTWRITABLE; request= entry->undo->req[i]; break; } } else if (RS_IS_GOING_ACTIVE(entry->rowStatus)) { /* * if going active, inconsistency is fatal */ if (!entry->undo->is_consistent) { netsnmp_assert(entry->undo->req[COL_SNMPTLSTMCERTTOTSN_ROWSTATUS]); if (FATE_NEWLY_CREATED == entry->undo->fate) ret = SNMP_ERR_INCONSISTENTNAME; else ret = SNMP_ERR_INCONSISTENTVALUE; request = entry->undo->req[COL_SNMPTLSTMCERTTOTSN_ROWSTATUS]; } } else if (RS_DESTROY == entry->rowStatus) { /* * can't destroy active row */ if (RS_IS_ACTIVE(entry->undo->rowStatus)) { DEBUGMSGTL(("tlstmCertToTSNTable:inconsistent", "can't destroy active row\n")); netsnmp_assert(entry->undo->req[COL_SNMPTLSTMCERTTOTSN_ROWSTATUS]); ret = SNMP_ERR_INCONSISTENTVALUE; request = entry->undo->req[COL_SNMPTLSTMCERTTOTSN_ROWSTATUS]; } } if (ret != SNMP_ERR_NOERROR) break; } /* consistency for requests */ break; /* case MODE_SET_ACTION */ /** ######################################################## UNDO ##### * * UNDO is for cleaning up any failed requests that went through the * ACTION phase. * * This the final phase for this path in the state machine. */ case MODE_SET_UNDO: for (request = requests; request; request = request->next) { row = netsnmp_tdata_extract_row(request); entry = (certToTSN_entry *) netsnmp_tdata_extract_entry(request); info = netsnmp_extract_table_info(request); /* * skip newly created rows, as we're going to delete * them below anyways */ if (FATE_NEWLY_CREATED == entry->undo->fate) continue; /* * restore values */ switch (info->colnum) { case COL_SNMPTLSTMCERTTOTSN_FINGERPRINT: memcpy(entry->fingerprint, entry->undo->fingerprint, sizeof(entry->fingerprint)); entry->fingerprint_len = entry->undo->fingerprint_len; entry->hashType = entry->undo->hashType; break; /* case COL_SNMPTLSTMCERTTOTSN_FINGERPRINT */ case COL_SNMPTLSTMCERTTOTSN_MAPTYPE: entry->mapType = entry->undo->mapType; break; /* case COL_SNMPTLSTMCERTTOTSN_MAPTYPE */ case COL_SNMPTLSTMCERTTOTSN_DATA: memcpy(entry->data, entry->undo->data, sizeof(entry->data)); entry->data_len = entry->undo->data_len; break; /* case COL_SNMPTLSTMCERTTOTSN_DATA */ case COL_SNMPTLSTMCERTTOTSN_STORAGETYPE: entry->storageType = entry->undo->storageType; break; /* case COL_SNMPTLSTMCERTTOTSN_STORAGETYPE */ case COL_SNMPTLSTMCERTTOTSN_ROWSTATUS: entry->rowStatus = entry->undo->rowStatus; break; /* case COL_SNMPTLSTMCERTTOTSN_ROWSTATUS */ } /* switch colnum */ } /* for requests */ /* * release undo data * or remove any newly created rows */ for (request = requests; request; request = request->next) { table = netsnmp_tdata_extract_table(request); row = netsnmp_tdata_extract_row(request); entry = (certToTSN_entry *) netsnmp_tdata_extract_entry(request); if (!entry || !entry->undo) continue; /** disassociate row with requests */ netsnmp_remove_tdata_row(request, row); if (FATE_NEWLY_CREATED == entry->undo->fate) tlstmCertToTSNTable_removeEntry(table, row); else _freeUndo(entry); } /* for requests */ break; /* case MODE_SET_UNDO */ /** ###################################################### COMMIT ##### * * COMMIT is the final success state, when all changes are finalized. * There is not recovery state should something faile here. * * This the final phase for this path in the state machine. */ case MODE_SET_COMMIT: for (request = requests; request; request = request->next) { row = netsnmp_tdata_extract_row(request); table = netsnmp_tdata_extract_table(request); info = netsnmp_extract_table_info(request); entry = (certToTSN_entry *) netsnmp_tdata_extract_entry(request); if ((RS_NOTREADY == entry->rowStatus) && entry->undo->is_consistent) entry->rowStatus = RS_NOTINSERVICE; else if ((RS_NOTINSERVICE == entry->rowStatus) && (0 == entry->undo->is_consistent)) entry->rowStatus = RS_NOTREADY; /** release undo data for requests with no rowstatus */ if (entry->undo && !entry->undo->req[COL_SNMPTLSTMCERTTOTSN_ROWSTATUS]) { _freeUndo(entry); if ((0 == entry->map_flags) && (entry->rowStatus == RS_ACTIVE)) _cert_map_add(entry); else if ((0 != entry->map_flags) && (entry->rowStatus == RS_DESTROY)) _cert_map_remove(entry); } switch (info->colnum) { case COL_SNMPTLSTMCERTTOTSN_ROWSTATUS: switch (entry->rowStatus) { case RS_CREATEANDGO: /** Fall-through */ case RS_ACTIVE: netsnmp_assert(entry->undo->is_consistent); entry->rowStatus = RS_ACTIVE; if (0 == entry->map_flags) _cert_map_add(entry); break; case RS_CREATEANDWAIT: /** Fall-through */ case RS_NOTINSERVICE: /** simply set status based on consistency */ if (entry->undo->is_consistent) entry->rowStatus = RS_NOTINSERVICE; else entry->rowStatus = RS_NOTREADY; if (0 != entry->map_flags) _cert_map_remove(entry); break; case RS_DESTROY: /** remove from cert map */ if (0 != entry->map_flags) _cert_map_remove(entry); /** disassociate row with requests */ netsnmp_remove_tdata_row(request, row); tlstmCertToTSNTable_removeEntry(table, row); row = NULL; entry = NULL; } /** release undo data */ _freeUndo(entry); break; /* case COL_SNMPTLSTMCERTTOTSN_ROWSTATUS */ case COL_SNMPTLSTMCERTTOTSN_STORAGETYPE: if (RS_ACTIVE == entry->rowStatus) _cert_map_tweak_storage(entry); break; /* case COL_SNMPTLSTMCERTTOTSN_STORAGETYPE */ case COL_SNMPTLSTMCERTTOTSN_FINGERPRINT: case COL_SNMPTLSTMCERTTOTSN_MAPTYPE: case COL_SNMPTLSTMCERTTOTSN_DATA: break; } /* switch colnum */ } /* for requests */ /** update last changed */ _last_changed = netsnmp_get_agent_uptime(); /** set up to save persistent store */ snmp_store_needed(NULL); break; /* case MODE_SET_COMMIT */ } /* switch (reqinfo->mode) */ if (ret != SNMP_ERR_NOERROR) netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; }
/** handles requests for the nsVacmAccessTable table */ int nsVacmAccessTable_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { netsnmp_request_info *request; netsnmp_table_request_info *table_info; netsnmp_variable_list *idx; struct vacm_accessEntry *entry; char atype[20]; int viewIdx, ret; char *gName, *cPrefix; int model, level; switch (reqinfo->mode) { /* * Read-support (also covers GetNext requests) */ case MODE_GET: for (request = requests; request; request = request->next) { entry = (struct vacm_accessEntry *) netsnmp_extract_iterator_context(request); table_info = netsnmp_extract_table_info(request); /* Extract the authType token from the list of indexes */ idx = table_info->indexes->next_variable->next_variable->next_variable->next_variable; memset(atype, 0, sizeof(atype)); memcpy(atype, (char *)idx->val.string, idx->val_len); viewIdx = se_find_value_in_slist(VACM_VIEW_ENUM_NAME, atype); DEBUGMSGTL(("nsVacm", "GET %s (%d)\n", idx->val.string, viewIdx)); if (!entry || viewIdx < 0) continue; switch (table_info->colnum) { case COLUMN_NSVACMCONTEXTMATCH: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->contextMatch); break; case COLUMN_NSVACMVIEWNAME: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *)entry->views[ viewIdx ], strlen(entry->views[ viewIdx ])); break; case COLUMN_VACMACCESSSTORAGETYPE: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->storageType); break; case COLUMN_NSVACMACCESSSTATUS: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->status); break; } } break; #ifndef NETSNMP_NO_WRITE_SUPPORT /* * Write-support */ case MODE_SET_RESERVE1: for (request = requests; request; request = request->next) { entry = (struct vacm_accessEntry *) netsnmp_extract_iterator_context(request); table_info = netsnmp_extract_table_info(request); ret = SNMP_ERR_NOERROR; switch (table_info->colnum) { case COLUMN_NSVACMCONTEXTMATCH: ret = netsnmp_check_vb_int_range(request->requestvb, 1, 2); break; case COLUMN_NSVACMVIEWNAME: ret = netsnmp_check_vb_type_and_max_size(request->requestvb, ASN_OCTET_STR, VACM_MAX_STRING); break; case COLUMN_VACMACCESSSTORAGETYPE: ret = netsnmp_check_vb_storagetype(request->requestvb, (/*entry ? entry->storageType :*/ SNMP_STORAGE_NONE)); break; case COLUMN_NSVACMACCESSSTATUS: /* * The usual 'check_vb_rowstatus' call is too simplistic * to be used here. Because we're implementing a table * within an existing table, it's quite possible for a * the vacmAccessTable entry to exist, even if this is * a "new" nsVacmAccessEntry. * * We can check that the value being assigned is suitable * for a RowStatus syntax object, but the transition * checks need to be done explicitly. */ ret = netsnmp_check_vb_rowstatus_value(request->requestvb); if ( ret != SNMP_ERR_NOERROR ) break; /* * Extract the authType token from the list of indexes */ idx = table_info->indexes->next_variable->next_variable->next_variable->next_variable; memset(atype, 0, sizeof(atype)); memcpy(atype, (char *)idx->val.string, idx->val_len); viewIdx = se_find_value_in_slist(VACM_VIEW_ENUM_NAME, atype); if ( viewIdx < 0 ) { ret = SNMP_ERR_NOCREATION; break; } switch ( *request->requestvb->val.integer ) { case RS_ACTIVE: case RS_NOTINSERVICE: /* Check that this particular view is already set */ if ( !entry || !entry->views[viewIdx][0] ) ret = SNMP_ERR_INCONSISTENTVALUE; break; case RS_CREATEANDWAIT: case RS_CREATEANDGO: /* Check that this particular view is not yet set */ if ( entry && entry->views[viewIdx][0] ) ret = SNMP_ERR_INCONSISTENTVALUE; break; } break; } /* switch(colnum) */ if ( ret != SNMP_ERR_NOERROR ) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } } break; case MODE_SET_RESERVE2: for (request = requests; request; request = request->next) { entry = (struct vacm_accessEntry *) netsnmp_extract_iterator_context(request); table_info = netsnmp_extract_table_info(request); switch (table_info->colnum) { case COLUMN_NSVACMACCESSSTATUS: switch (*request->requestvb->val.integer) { case RS_CREATEANDGO: case RS_CREATEANDWAIT: if (!entry) { idx = table_info->indexes; gName = (char*)idx->val.string; idx = idx->next_variable; cPrefix = (char*)idx->val.string; idx = idx->next_variable; model = *idx->val.integer; idx = idx->next_variable; level = *idx->val.integer; entry = vacm_createAccessEntry( gName, cPrefix, model, level ); entry->storageType = ST_NONVOLATILE; netsnmp_insert_iterator_context(request, (void*)entry); } } } } break; case MODE_SET_FREE: case MODE_SET_UNDO: /* XXX - TODO */ break; case MODE_SET_ACTION: /* ??? Empty ??? */ break; case MODE_SET_COMMIT: for (request = requests; request; request = request->next) { entry = (struct vacm_accessEntry *) netsnmp_extract_iterator_context(request); table_info = netsnmp_extract_table_info(request); if ( !entry ) continue; /* Shouldn't happen */ /* Extract the authType token from the list of indexes */ idx = table_info->indexes->next_variable->next_variable->next_variable->next_variable; memset(atype, 0, sizeof(atype)); memcpy(atype, (char *)idx->val.string, idx->val_len); viewIdx = se_find_value_in_slist(VACM_VIEW_ENUM_NAME, atype); if (viewIdx < 0) continue; switch (table_info->colnum) { case COLUMN_NSVACMCONTEXTMATCH: entry->contextMatch = *request->requestvb->val.integer; break; case COLUMN_NSVACMVIEWNAME: memset( entry->views[viewIdx], 0, VACMSTRINGLEN ); memcpy( entry->views[viewIdx], request->requestvb->val.string, request->requestvb->val_len); break; case COLUMN_VACMACCESSSTORAGETYPE: entry->storageType = *request->requestvb->val.integer; break; case COLUMN_NSVACMACCESSSTATUS: switch (*request->requestvb->val.integer) { case RS_DESTROY: memset( entry->views[viewIdx], 0, VACMSTRINGLEN ); break; } break; } } break; #endif /* !NETSNMP_NO_WRITE_SUPPORT */ } return SNMP_ERR_NOERROR; }
/************************************************************ * radiusAccClientExtTable_get_value * * This routine is called for get requests to copy the data * from the context to the varbind for the request. If the * context has been properly maintained, you don't need to * change in code in this fuction. */ int radiusAccClientExtTable_get_value(netsnmp_request_info *request, netsnmp_index * item, netsnmp_table_request_info *table_info) { netsnmp_variable_list *var = request->requestvb; radiusAccClientExtTable_context *ctx = (radiusAccClientExtTable_context *)item; struct dm_value_table *stats; ENTER(); if (!ctx->client) { snmp_log(LOG_ERR, "invalid client in " "radiusAccClientExtTable_get_value\n"); EXIT(); return SNMP_ERR_GENERR; } /** VAR: InternetGatewayDevice.X_TPLINO_NET_SessionControl.RadiusServer.Accounting.Client.{i}.Stats */ stats = dm_get_table_by_id(ctx->client, dm__IGD_SCG_RS_Acct_Clnt_i_Stats); switch (table_info->colnum) { case COLUMN_RADIUSACCCLIENTINETADDRESSTYPE: /** InetAddressType = ASN_INTEGER */ snmp_set_var_typed_integer(var, ASN_INTEGER, INETADDRESSTYPE_IPV4); break; case COLUMN_RADIUSACCCLIENTINETADDRESS: { char hname[NI_MAXHOST]; struct in_addr host; /** VAR: InternetGatewayDevice.X_TPLINO_NET_SessionControl.RadiusServer.Accounting.Client.{i}.Prefix */ host = dm_get_ipv4_by_id(ctx->client, dm__IGD_SCG_RS_Acct_Clnt_i_Prefix); inet_ntop(AF_INET, &host, hname, sizeof(hname)); /** InetAddress = ASN_OCTET_STR */ snmp_set_var_typed_value(var, ASN_OCTET_STR, (unsigned char *)hname, strlen(hname)); break; } case COLUMN_RADIUSACCCLIENTEXTID: { unsigned char *id; /** VAR: InternetGatewayDevice.X_TPLINO_NET_SessionControl.RadiusServer.Accounting.Client.{i}.Description */ id = dm_get_string_by_id(ctx->client, dm__IGD_SCG_RS_Acct_Clnt_i_Description); if (!id || !*id) id = ""; /** SnmpAdminString = ASN_OCTET_STR */ snmp_set_var_typed_value(var, ASN_OCTET_STR, id, strlen(id)); break; } case COLUMN_RADIUSACCSERVEXTPACKETSDROPPED: /** COUNTER = ASN_COUNTER */ /** VAR: InternetGatewayDevice.X_TPLINO_NET_SessionControl.RadiusServer.Accounting.Client.{i}.Stats.PacketsDropped */ snmp_set_var_typed_integer(var, ASN_COUNTER, dm_get_uint_by_id(stats, dm__IGD_SCG_RS_Acct_Clnt_i_Stats_PacketsDropped)); break; case COLUMN_RADIUSACCSERVEXTREQUESTS: /** COUNTER = ASN_COUNTER */ /** VAR: InternetGatewayDevice.X_TPLINO_NET_SessionControl.RadiusServer.Accounting.Client.{i}.Stats.Requests */ snmp_set_var_typed_integer(var, ASN_COUNTER, dm_get_uint_by_id(stats, dm__IGD_SCG_RS_Acct_Clnt_i_Stats_Requests)); break; case COLUMN_RADIUSACCSERVEXTDUPREQUESTS: /** COUNTER = ASN_COUNTER */ /** VAR: InternetGatewayDevice.X_TPLINO_NET_SessionControl.RadiusServer.Accounting.Client.{i}.Stats.DupRequests */ snmp_set_var_typed_integer(var, ASN_COUNTER, dm_get_uint_by_id(stats, dm__IGD_SCG_RS_Acct_Clnt_i_Stats_DupRequests)); break; case COLUMN_RADIUSACCSERVEXTRESPONSES: /** COUNTER = ASN_COUNTER */ /** VAR: InternetGatewayDevice.X_TPLINO_NET_SessionControl.RadiusServer.Accounting.Client.{i}.Stats.Responses */ snmp_set_var_typed_integer(var, ASN_COUNTER, dm_get_uint_by_id(stats, dm__IGD_SCG_RS_Acct_Clnt_i_Stats_Responses)); break; case COLUMN_RADIUSACCSERVEXTBADAUTHENTICATORS: /** COUNTER = ASN_COUNTER */ /** VAR: InternetGatewayDevice.X_TPLINO_NET_SessionControl.RadiusServer.Accounting.Client.{i}.Stats.BadAuthenticators */ snmp_set_var_typed_integer(var, ASN_COUNTER, dm_get_uint_by_id(stats, dm__IGD_SCG_RS_Acct_Clnt_i_Stats_BadAuthenticators)); break; case COLUMN_RADIUSACCSERVEXTMALFORMEDREQUESTS: /** COUNTER = ASN_COUNTER */ /** VAR: InternetGatewayDevice.X_TPLINO_NET_SessionControl.RadiusServer.Accounting.Client.{i}.Stats.MalformedRequests */ snmp_set_var_typed_integer(var, ASN_COUNTER, dm_get_uint_by_id(stats, dm__IGD_SCG_RS_Acct_Clnt_i_Stats_MalformedRequests)); break; case COLUMN_RADIUSACCSERVEXTNORECORDS: /** COUNTER = ASN_COUNTER */ /** VAR: InternetGatewayDevice.X_TPLINO_NET_SessionControl.RadiusServer.Accounting.Client.{i}.Stats.NoRecords */ snmp_set_var_typed_integer(var, ASN_COUNTER, dm_get_uint_by_id(stats, dm__IGD_SCG_RS_Acct_Clnt_i_Stats_NoRecords)); break; case COLUMN_RADIUSACCSERVEXTUNKNOWNTYPES: /** COUNTER = ASN_COUNTER */ /** VAR: InternetGatewayDevice.X_TPLINO_NET_SessionControl.RadiusServer.Accounting.Client.{i}.Stats.UnknownTypes */ snmp_set_var_typed_integer(var, ASN_COUNTER, dm_get_uint_by_id(stats, dm__IGD_SCG_RS_Acct_Clnt_i_Stats_UnknownTypes)); break; case COLUMN_RADIUSACCSERVERCOUNTERDISCONTINUITY: /** TICKS = ASN_TIMETICKS */ snmp_set_var_typed_integer(var, ASN_TIMETICKS, (ltime() - ctx->radiusAccServerCounterDiscontinuity) / 10); break; default:/** We shouldn't get here */ snmp_log(LOG_ERR, "unknown column in " "radiusAccClientExtTable_get_value\n"); EXIT(); return SNMP_ERR_GENERR; } EXIT(); return SNMP_ERR_NOERROR; }
/** handles requests for the mteTriggerThresholdTable table */ int mteTriggerThresholdTable_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { netsnmp_request_info *request; netsnmp_table_request_info *tinfo; struct mteTrigger *entry; int ret; DEBUGMSGTL(("disman:event:mib", "Threshold Table handler (%d)\n", reqinfo->mode)); switch (reqinfo->mode) { /* * Read-support (also covers GetNext requests) */ case MODE_GET: for (request = requests; request; request = request->next) { entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request); tinfo = netsnmp_extract_table_info(request); /* * The mteTriggerThresholdTable should only contains entries for * rows where the mteTriggerTest 'threshold(2)' bit is set. * So skip entries where this isn't the case. */ if (!entry || !(entry->mteTriggerTest & MTE_TRIGGER_THRESHOLD )) continue; switch (tinfo->colnum) { case COLUMN_MTETRIGGERTHRESHOLDSTARTUP: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->mteTThStartup); break; case COLUMN_MTETRIGGERTHRESHOLDRISING: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->mteTThRiseValue); break; case COLUMN_MTETRIGGERTHRESHOLDFALLING: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->mteTThFallValue); break; case COLUMN_MTETRIGGERTHRESHOLDDELTARISING: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->mteTThDRiseValue); break; case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLING: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->mteTThDFallValue); break; case COLUMN_MTETRIGGERTHRESHOLDOBJECTSOWNER: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->mteTThObjOwner, strlen(entry->mteTThObjOwner)); break; case COLUMN_MTETRIGGERTHRESHOLDOBJECTS: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->mteTThObjects, strlen(entry->mteTThObjects)); break; case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENTOWNER: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->mteTThRiseOwner, strlen(entry->mteTThRiseOwner)); break; case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENT: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->mteTThRiseEvent, strlen(entry->mteTThRiseEvent)); break; case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENTOWNER: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->mteTThFallOwner, strlen(entry->mteTThFallOwner)); break; case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENT: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->mteTThFallEvent, strlen(entry->mteTThFallEvent)); break; case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENTOWNER: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->mteTThDRiseOwner, strlen(entry->mteTThDRiseOwner)); break; case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENT: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->mteTThDRiseEvent, strlen(entry->mteTThDRiseEvent)); break; case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENTOWNER: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->mteTThDFallOwner, strlen(entry->mteTThDFallOwner)); break; case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENT: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) entry->mteTThDFallEvent, strlen(entry->mteTThDFallEvent)); break; } } break; #ifndef NETSNMP_NO_WRITE_SUPPORT /* * Write-support */ case MODE_SET_RESERVE1: for (request = requests; request; request = request->next) { entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request); tinfo = netsnmp_extract_table_info(request); /* * Since the mteTriggerThresholdTable only contains entries for * rows where the mteTriggerTest 'threshold(2)' bit is set, * strictly speaking we should reject assignments where * this isn't the case. * But SET requests that include an assignment of the * 'threshold(2)' bit at the same time are valid, so would * need to be accepted. Unfortunately, this assignment * is only applied in the COMMIT pass, so it's difficult * to detect whether this holds or not. * * Let's fudge things for now, by processing assignments * even if the 'threshold(2)' bit isn't set. */ switch (tinfo->colnum) { case COLUMN_MTETRIGGERTHRESHOLDSTARTUP: ret = netsnmp_check_vb_int_range(request->requestvb, MTE_THRESH_START_RISE, MTE_THRESH_START_RISEFALL ); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_MTETRIGGERTHRESHOLDRISING: case COLUMN_MTETRIGGERTHRESHOLDFALLING: case COLUMN_MTETRIGGERTHRESHOLDDELTARISING: case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLING: ret = netsnmp_check_vb_int(request->requestvb); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_MTETRIGGERTHRESHOLDOBJECTSOWNER: case COLUMN_MTETRIGGERTHRESHOLDOBJECTS: case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENTOWNER: case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENT: case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENTOWNER: case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENT: case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENTOWNER: case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENT: case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENTOWNER: case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENT: ret = netsnmp_check_vb_type_and_max_size( request->requestvb, ASN_OCTET_STR, MTE_STR1_LEN); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; default: netsnmp_set_request_error(reqinfo, request, SNMP_ERR_NOTWRITABLE); return SNMP_ERR_NOERROR; } /* * The Event MIB is somewhat ambiguous as to whether the * various trigger table entries can be modified once the * main mteTriggerTable entry has been marked 'active'. * But it's clear from discussion on the DisMan mailing * list is that the intention is not. * * So check for whether this row is already active, * and reject *all* SET requests if it is. */ entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request); if (entry && entry->flags & MTE_TRIGGER_FLAG_ACTIVE ) { netsnmp_set_request_error(reqinfo, request, SNMP_ERR_INCONSISTENTVALUE); return SNMP_ERR_NOERROR; } } break; case MODE_SET_RESERVE2: case MODE_SET_FREE: case MODE_SET_UNDO: break; case MODE_SET_ACTION: for (request = requests; request; request = request->next) { entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request); if (!entry) { /* * New rows must be created via the RowStatus column * (in the main mteTriggerTable) */ netsnmp_set_request_error(reqinfo, request, SNMP_ERR_NOCREATION); /* or inconsistentName? */ return SNMP_ERR_NOERROR; } } break; case MODE_SET_COMMIT: /* * All these assignments are "unfailable", so it's * (reasonably) safe to apply them in the Commit phase */ for (request = requests; request; request = request->next) { entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request); tinfo = netsnmp_extract_table_info(request); switch (tinfo->colnum) { case COLUMN_MTETRIGGERTHRESHOLDSTARTUP: entry->mteTThStartup = *request->requestvb->val.integer; break; case COLUMN_MTETRIGGERTHRESHOLDRISING: entry->mteTThRiseValue = *request->requestvb->val.integer; break; case COLUMN_MTETRIGGERTHRESHOLDFALLING: entry->mteTThFallValue = *request->requestvb->val.integer; break; case COLUMN_MTETRIGGERTHRESHOLDDELTARISING: entry->mteTThDRiseValue = *request->requestvb->val.integer; break; case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLING: entry->mteTThDFallValue = *request->requestvb->val.integer; break; case COLUMN_MTETRIGGERTHRESHOLDOBJECTSOWNER: memset(entry->mteTThObjOwner, 0, sizeof(entry->mteTThObjOwner)); memcpy(entry->mteTThObjOwner, request->requestvb->val.string, request->requestvb->val_len); break; case COLUMN_MTETRIGGERTHRESHOLDOBJECTS: memset(entry->mteTThObjects, 0, sizeof(entry->mteTThObjects)); memcpy(entry->mteTThObjects, request->requestvb->val.string, request->requestvb->val_len); break; case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENTOWNER: memset(entry->mteTThRiseOwner, 0, sizeof(entry->mteTThRiseOwner)); memcpy(entry->mteTThRiseOwner, request->requestvb->val.string, request->requestvb->val_len); break; case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENT: memset(entry->mteTThRiseEvent, 0, sizeof(entry->mteTThRiseEvent)); memcpy(entry->mteTThRiseEvent, request->requestvb->val.string, request->requestvb->val_len); break; case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENTOWNER: memset(entry->mteTThFallOwner, 0, sizeof(entry->mteTThFallOwner)); memcpy(entry->mteTThFallOwner, request->requestvb->val.string, request->requestvb->val_len); break; case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENT: memset(entry->mteTThFallEvent, 0, sizeof(entry->mteTThFallEvent)); memcpy(entry->mteTThFallEvent, request->requestvb->val.string, request->requestvb->val_len); break; case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENTOWNER: memset(entry->mteTThDRiseOwner, 0, sizeof(entry->mteTThDRiseOwner)); memcpy(entry->mteTThDRiseOwner, request->requestvb->val.string, request->requestvb->val_len); break; case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENT: memset(entry->mteTThDRiseEvent, 0, sizeof(entry->mteTThDRiseEvent)); memcpy(entry->mteTThDRiseEvent, request->requestvb->val.string, request->requestvb->val_len); break; case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENTOWNER: memset(entry->mteTThDFallOwner, 0, sizeof(entry->mteTThDFallOwner)); memcpy(entry->mteTThDFallOwner, request->requestvb->val.string, request->requestvb->val_len); break; case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENT: memset(entry->mteTThDFallEvent, 0, sizeof(entry->mteTThDFallEvent)); memcpy(entry->mteTThDFallEvent, request->requestvb->val.string, request->requestvb->val_len); break; } } break; #endif /* !NETSNMP_NO_WRITE_SUPPORT */ } return SNMP_ERR_NOERROR; }
/** handles requests for the hrSWInstalledTable table */ int hrSWInstalledTable_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { netsnmp_request_info *request; netsnmp_table_request_info *table_info; netsnmp_swinst_entry *table_entry; switch (reqinfo->mode) { /* * Read-support (also covers GetNext requests) */ case MODE_GET: for (request = requests; request; request = request->next) { if (request->processed) continue; table_entry = (netsnmp_swinst_entry *) netsnmp_container_table_extract_context(request); table_info = netsnmp_extract_table_info(request); if ((NULL == table_entry) || (NULL == table_info)) { snmp_log(LOG_ERR, "could not extract table entry or info for " MYTABLE "\n"); snmp_set_var_typed_value(request->requestvb, SNMP_ERR_GENERR, NULL, 0); continue; } switch (table_info->colnum) { case COLUMN_HRSWINSTALLEDINDEX: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry->swIndex); break; case COLUMN_HRSWINSTALLEDNAME: { snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) table_entry->swName, table_entry->swName_len); } break; case COLUMN_HRSWINSTALLEDID: snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID, (u_char *) &nullOid, nullOidLen); break; case COLUMN_HRSWINSTALLEDTYPE: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry->swType); break; case COLUMN_HRSWINSTALLEDDATE: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) table_entry->swDate, table_entry->swDate_len); break; default: /* * An unsupported/unreadable column (if applicable) */ snmp_set_var_typed_value(request->requestvb, SNMP_NOSUCHOBJECT, NULL, 0); } } break; } return SNMP_ERR_NOERROR; }
/** handles requests for the expExpressionTable table */ int expExpressionTable_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { netsnmp_request_info *request; netsnmp_table_request_info *tinfo; netsnmp_tdata_row *row; struct expExpression *entry; char expOwner[EXP_STR1_LEN+1]; char expName[ EXP_STR1_LEN+1]; long ret; DEBUGMSGTL(("disman:expr:mib", "Expression Table handler (%d)\n", reqinfo->mode)); switch (reqinfo->mode) { /* * Read-support (also covers GetNext requests) */ case MODE_GET: for (request = requests; request; request = request->next) { if (request->processed) continue; entry = (struct expExpression *) netsnmp_tdata_extract_entry(request); tinfo = netsnmp_extract_table_info(request); if (!entry || !(entry->flags & EXP_FLAG_VALID)) continue; switch (tinfo->colnum) { case COLUMN_EXPEXPRESSION: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char*)entry->expExpression, strlen(entry->expExpression)); break; case COLUMN_EXPEXPRESSIONVALUETYPE: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->expValueType); break; case COLUMN_EXPEXPRESSIONCOMMENT: snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char*)entry->expComment, strlen(entry->expComment)); break; case COLUMN_EXPEXPRESSIONDELTAINTERVAL: snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, entry->expDeltaInterval); break; case COLUMN_EXPEXPRESSIONPREFIX: /* * XXX - Need to search expObjectTable for a suitable OID */ /* * Empty OIDs (len=0) are converted into .0.0 * by the SNMP library automatically :-( */ if ( entry->expPrefix_len ) { snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID, (u_char *) entry->expPrefix, entry->expPrefix_len*sizeof(oid)); } else { /* XXX - possibly not needed */ request->requestvb->type = ASN_OBJECT_ID; request->requestvb->val_len = 0; } break; case COLUMN_EXPEXPRESSIONERRORS: snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, entry->expErrorCount); break; case COLUMN_EXPEXPRESSIONENTRYSTATUS: /* What would indicate 'notReady' ? */ ret = (entry->flags & EXP_FLAG_ACTIVE) ? RS_ACTIVE : RS_NOTINSERVICE; snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret); break; } } break; /* * Write-support */ case MODE_SET_RESERVE1: for (request = requests; request; request = request->next) { if (request->processed) continue; entry = (struct expExpression *) netsnmp_tdata_extract_entry(request); tinfo = netsnmp_extract_table_info(request); switch (tinfo->colnum) { case COLUMN_EXPEXPRESSION: ret = netsnmp_check_vb_type_and_max_size( request->requestvb, ASN_OCTET_STR, EXP_STR3_LEN); /* XXX - check new expression is syntactically valid */ if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_EXPEXPRESSIONVALUETYPE: ret = netsnmp_check_vb_int_range(request->requestvb, 1, 8); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_EXPEXPRESSIONCOMMENT: ret = netsnmp_check_vb_type_and_max_size( request->requestvb, ASN_OCTET_STR, EXP_STR2_LEN); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_EXPEXPRESSIONDELTAINTERVAL: ret = netsnmp_check_vb_int_range(request->requestvb, 0, 86400); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; case COLUMN_EXPEXPRESSIONENTRYSTATUS: ret = netsnmp_check_vb_rowstatus(request->requestvb, (entry ? RS_ACTIVE : RS_NONEXISTENT)); if (ret != SNMP_ERR_NOERROR) { netsnmp_set_request_error(reqinfo, request, ret); return SNMP_ERR_NOERROR; } break; default: netsnmp_set_request_error(reqinfo, request, SNMP_ERR_NOTWRITABLE); return SNMP_ERR_NOERROR; } } break; case MODE_SET_RESERVE2: for (request = requests; request; request = request->next) { if (request->processed) continue; tinfo = netsnmp_extract_table_info(request); switch (tinfo->colnum) { case COLUMN_EXPEXPRESSIONENTRYSTATUS: switch (*request->requestvb->val.integer) { case RS_CREATEANDGO: case RS_CREATEANDWAIT: /* * Create an (empty) new row structure */ memset(expOwner, 0, sizeof(expOwner)); memcpy(expOwner, tinfo->indexes->val.string, tinfo->indexes->val_len); memset(expName, 0, sizeof(expName)); memcpy(expName, tinfo->indexes->next_variable->val.string, tinfo->indexes->next_variable->val_len); row = expExpression_createRow(expOwner, expName, 0); if (!row) { netsnmp_set_request_error(reqinfo, request, SNMP_ERR_RESOURCEUNAVAILABLE); return SNMP_ERR_NOERROR; } netsnmp_insert_tdata_row( request, row ); } } } break; case MODE_SET_FREE: for (request = requests; request; request = request->next) { if (request->processed) continue; tinfo = netsnmp_extract_table_info(request); switch (tinfo->colnum) { case COLUMN_EXPEXPRESSIONENTRYSTATUS: switch (*request->requestvb->val.integer) { case RS_CREATEANDGO: case RS_CREATEANDWAIT: /* * Tidy up after a failed row creation request */ entry = (struct expExpression *) netsnmp_tdata_extract_entry(request); if (entry && !(entry->flags & EXP_FLAG_VALID)) { row = (netsnmp_tdata_row *) netsnmp_tdata_extract_row(request); expExpression_removeEntry( row ); } } } } break; case MODE_SET_ACTION: for (request = requests; request; request = request->next) { if (request->processed) continue; tinfo = netsnmp_extract_table_info(request); entry = (struct expExpression *) netsnmp_tdata_extract_entry(request); if (!entry) { /* * New rows must be created via the RowStatus column */ netsnmp_set_request_error(reqinfo, request, SNMP_ERR_NOCREATION); /* or inconsistentName? */ return SNMP_ERR_NOERROR; } } break; case MODE_SET_UNDO: break; case MODE_SET_COMMIT: /* * All these assignments are "unfailable", so it's * (reasonably) safe to apply them in the Commit phase */ for (request = requests; request; request = request->next) { if (request->processed) continue; entry = (struct expExpression *) netsnmp_tdata_extract_entry(request); tinfo = netsnmp_extract_table_info(request); switch (tinfo->colnum) { case COLUMN_EXPEXPRESSION: memset(entry->expExpression, 0, EXP_STR3_LEN+1); memcpy(entry->expExpression, request->requestvb->val.string, request->requestvb->val_len); break; case COLUMN_EXPEXPRESSIONVALUETYPE: entry->expValueType = *request->requestvb->val.integer; break; case COLUMN_EXPEXPRESSIONCOMMENT: memset(entry->expComment, 0, EXP_STR2_LEN+1); memcpy(entry->expComment, request->requestvb->val.string, request->requestvb->val_len); break; case COLUMN_EXPEXPRESSIONDELTAINTERVAL: entry->expDeltaInterval = *request->requestvb->val.integer; break; case COLUMN_EXPEXPRESSIONENTRYSTATUS: switch (*request->requestvb->val.integer) { case RS_ACTIVE: entry->flags |= EXP_FLAG_ACTIVE; expExpression_enable( entry ); break; case RS_NOTINSERVICE: entry->flags &= ~EXP_FLAG_ACTIVE; expExpression_disable( entry ); break; case RS_CREATEANDGO: entry->flags |= EXP_FLAG_ACTIVE; entry->flags |= EXP_FLAG_VALID; entry->session = netsnmp_iquery_pdu_session(reqinfo->asp->pdu); expExpression_enable( entry ); break; case RS_CREATEANDWAIT: entry->flags |= EXP_FLAG_VALID; entry->session = netsnmp_iquery_pdu_session(reqinfo->asp->pdu); break; case RS_DESTROY: row = (netsnmp_tdata_row *) netsnmp_tdata_extract_row(request); expExpression_removeEntry(row); } } } break; } DEBUGMSGTL(("disman:expr:mib", "Expression Table handler - done \n")); return SNMP_ERR_NOERROR; }
/** handles requests for the sctpAssocTable table */ int sctpAssocTable_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) { netsnmp_request_info *request; netsnmp_table_request_info *table_info; sctpAssocTable_entry *table_entry; switch (reqinfo->mode) { /* * Read-support (also covers GetNext requests) */ case MODE_GET: for (request = requests; request; request = request->next) { if (request->processed) continue; table_entry = (sctpAssocTable_entry *) netsnmp_container_table_extract_context(request); table_info = netsnmp_extract_table_info(request); if ((NULL == table_entry) || (NULL == table_info)) { snmp_log(LOG_ERR, "could not extract table entry or info for sctpAssocTable\n"); snmp_set_var_typed_value(request->requestvb, SNMP_ERR_GENERR, NULL, 0); continue; } switch (table_info->colnum) { case COLUMN_SCTPASSOCREMHOSTNAME: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) table_entry->sctpAssocRemHostName, table_entry->sctpAssocRemHostName_len); break; case COLUMN_SCTPASSOCLOCALPORT: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_UNSIGNED, table_entry->sctpAssocLocalPort); break; case COLUMN_SCTPASSOCREMPORT: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_UNSIGNED, table_entry->sctpAssocRemPort); break; case COLUMN_SCTPASSOCREMPRIMADDRTYPE: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry->sctpAssocRemPrimAddrType); break; case COLUMN_SCTPASSOCREMPRIMADDR: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, (u_char *) table_entry->sctpAssocRemPrimAddr, table_entry->sctpAssocRemPrimAddr_len); break; case COLUMN_SCTPASSOCHEARTBEATINTERVAL: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_UNSIGNED, table_entry->sctpAssocHeartBeatInterval); break; case COLUMN_SCTPASSOCSTATE: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, table_entry->sctpAssocState); break; case COLUMN_SCTPASSOCINSTREAMS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_UNSIGNED, table_entry->sctpAssocInStreams); break; case COLUMN_SCTPASSOCOUTSTREAMS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_UNSIGNED, table_entry->sctpAssocOutStreams); break; case COLUMN_SCTPASSOCMAXRETR: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_UNSIGNED, table_entry->sctpAssocMaxRetr); break; case COLUMN_SCTPASSOCPRIMPROCESS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_UNSIGNED, table_entry->sctpAssocPrimProcess); break; case COLUMN_SCTPASSOCT1EXPIREDS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, table_entry->sctpAssocT1expireds); break; case COLUMN_SCTPASSOCT2EXPIREDS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, table_entry->sctpAssocT2expireds); break; case COLUMN_SCTPASSOCRTXCHUNKS: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER, table_entry->sctpAssocRtxChunks); break; case COLUMN_SCTPASSOCSTARTTIME: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_TIMETICKS, table_entry->sctpAssocStartTime); break; case COLUMN_SCTPASSOCDISCONTINUITYTIME: if (!table_entry) { netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); continue; } snmp_set_var_typed_integer(request->requestvb, ASN_TIMETICKS, table_entry->sctpAssocDiscontinuityTime); break; default: netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT); break; } } break; /* * Write-support */ case MODE_SET_RESERVE1: for (request = requests; request; request = request->next) { if (request->processed) continue; netsnmp_set_request_error(reqinfo, request, SNMP_ERR_NOTWRITABLE); } break; case MODE_SET_RESERVE2: case MODE_SET_FREE: case MODE_SET_ACTION: case MODE_SET_UNDO: case MODE_SET_COMMIT: break; } return SNMP_ERR_NOERROR; }