📄 expobjecttable.c
字号:
/* * DisMan Expression MIB: * Implementation of the expExpressionObjectTable MIB interface * See 'expObject.c' for active behaviour of this table. * * (Based on mib2c.table_data.conf output) */#include <net-snmp/net-snmp-config.h>#include <net-snmp/net-snmp-includes.h>#include <net-snmp/agent/net-snmp-agent-includes.h>#include "disman/expr/expObject.h"#include "disman/expr/expObjectTable.h"/* Initializes the expObjectTable module */voidinit_expObjectTable(void){ static oid expObjectTable_oid[] = { 1, 3, 6, 1, 2, 1, 90, 1, 2, 3 }; size_t expObjectTable_oid_len = OID_LENGTH(expObjectTable_oid); netsnmp_handler_registration *reg; netsnmp_table_registration_info *table_info; /* * Ensure the expObject table container is available... */ init_expObject_table_data(); /* * ... then set up the MIB interface to the expObjectTable */ reg = netsnmp_create_handler_registration("expObjectTable", expObjectTable_handler, expObjectTable_oid, expObjectTable_oid_len, HANDLER_CAN_RWRITE); table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); netsnmp_table_helper_add_indexes(table_info, /* index: expExpressionOwner */ ASN_OCTET_STR, /* index: expExpressionName */ ASN_OCTET_STR, /* index: expObjectIndex */ ASN_UNSIGNED, 0); table_info->min_column = COLUMN_EXPOBJECTID; table_info->max_column = COLUMN_EXPOBJECTENTRYSTATUS; /* Register this using the common expObject_table_data container */ netsnmp_tdata_register(reg, expObject_table_data, table_info); DEBUGMSGTL(("disman:expr:init", "Expression Object Table container (%x)\n", expObject_table_data));}/** handles requests for the expObjectTable table */intexpObjectTable_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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -