📄 inetnettomediatable_interface.c
字号:
if (MFD_SUCCESS != *rc_ptr) { netsnmp_assert((*rc_ptr == SNMP_ERR_NOCREATION) || (*rc_ptr == SNMP_ERR_INCONSISTENTNAME)); inetNetToMediaTable_release_rowreq_ctx(rowreq_ctx); return NULL; } /* * copy indexes */ rowreq_ctx->oid_idx.len = oid_idx->len; memcpy(rowreq_ctx->oid_idx.oids, oid_idx->oids, oid_idx->len * sizeof(oid)); return rowreq_ctx;} /* _mfd_inetNetToMediaTable_rowreq_from_index *//** * @internal * wrapper */static int_mfd_inetNetToMediaTable_object_lookup(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests){ int rc = SNMP_ERR_NOERROR; inetNetToMediaTable_rowreq_ctx *rowreq_ctx = netsnmp_container_table_row_extract(requests); DEBUGMSGTL(("internal:inetNetToMediaTable:_mfd_inetNetToMediaTable_object_lookup", "called\n")); /* * get our context from mfd * inetNetToMediaTable_interface_ctx *if_ctx = * (inetNetToMediaTable_interface_ctx *)reginfo->my_reg_void; */ if (NULL == rowreq_ctx) { netsnmp_table_request_info *tblreq_info; netsnmp_index oid_idx; tblreq_info = netsnmp_extract_table_info(requests); if (NULL == tblreq_info) { snmp_log(LOG_ERR, "request had no table info\n"); return MFD_ERROR; } /* * try create rowreq */ oid_idx.oids = tblreq_info->index_oid; oid_idx.len = tblreq_info->index_oid_len; rowreq_ctx = _mfd_inetNetToMediaTable_rowreq_from_index(&oid_idx, &rc); if (MFD_SUCCESS == rc) { netsnmp_assert(NULL != rowreq_ctx); rowreq_ctx->rowreq_flags |= MFD_ROW_CREATED; /* * add rowreq_ctx to request data lists */ netsnmp_container_table_row_insert(requests, (netsnmp_index *) rowreq_ctx); } } if (MFD_SUCCESS != rc) netsnmp_request_set_error_all(requests, rc); else inetNetToMediaTable_row_prep(rowreq_ctx); return SNMP_VALIDATE_ERR(rc);} /* _mfd_inetNetToMediaTable_object_lookup *//*********************************************************************** * * GET processing * ***********************************************************************//* * @internal * Retrieve the value for a particular column */NETSNMP_STATIC_INLINE int_inetNetToMediaTable_get_column(inetNetToMediaTable_rowreq_ctx * rowreq_ctx, netsnmp_variable_list * var, int column){ int rc = SNMPERR_SUCCESS; DEBUGMSGTL(("internal:inetNetToMediaTable:_mfd_inetNetToMediaTable_get_column", "called for %d\n", column)); netsnmp_assert(NULL != rowreq_ctx); switch (column) { /* * inetNetToMediaPhysAddress(4)/PhysAddress/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */ case COLUMN_INETNETTOMEDIAPHYSADDRESS: var->type = ASN_OCTET_STR; rc = inetNetToMediaPhysAddress_get(rowreq_ctx, (char **) &var->val.string, &var->val_len); break; /* * inetNetToMediaLastUpdated(5)/TimeStamp/ASN_TIMETICKS/u_long(u_long)//l/A/w/e/r/d/h */ case COLUMN_INETNETTOMEDIALASTUPDATED: var->val_len = sizeof(u_long); var->type = ASN_TIMETICKS; rc = inetNetToMediaLastUpdated_get(rowreq_ctx, (u_long *) var->val.string); break; /* * inetNetToMediaType(6)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h */ case COLUMN_INETNETTOMEDIATYPE: var->val_len = sizeof(u_long); var->type = ASN_INTEGER; rc = inetNetToMediaType_get(rowreq_ctx, (u_long *) var->val.string); break; /* * inetNetToMediaState(7)/INTEGER/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h */ case COLUMN_INETNETTOMEDIASTATE: var->val_len = sizeof(u_long); var->type = ASN_INTEGER; rc = inetNetToMediaState_get(rowreq_ctx, (u_long *) var->val.string); break; /* * inetNetToMediaRowStatus(8)/RowStatus/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h */ case COLUMN_INETNETTOMEDIAROWSTATUS: var->val_len = sizeof(u_long); var->type = ASN_INTEGER; rc = inetNetToMediaRowStatus_get(rowreq_ctx, (u_long *) var->val.string); break; default: snmp_log(LOG_ERR, "unknown column %d in _inetNetToMediaTable_get_column\n", column); break; } return rc;} /* _inetNetToMediaTable_get_column */int_mfd_inetNetToMediaTable_get_values(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests){ inetNetToMediaTable_rowreq_ctx *rowreq_ctx = netsnmp_container_table_row_extract(requests); netsnmp_table_request_info *tri; u_char *old_string; void (*dataFreeHook) (void *); int rc; DEBUGMSGTL(("internal:inetNetToMediaTable:_mfd_inetNetToMediaTable_get_values", "called\n")); netsnmp_assert(NULL != rowreq_ctx); for (; requests; requests = requests->next) { /* * save old pointer, so we can free it if replaced */ old_string = requests->requestvb->val.string; dataFreeHook = requests->requestvb->dataFreeHook; if (NULL == requests->requestvb->val.string) { requests->requestvb->val.string = requests->requestvb->buf; requests->requestvb->val_len = sizeof(requests->requestvb->buf); } else if (requests->requestvb->buf == requests->requestvb->val.string) { if (requests->requestvb->val_len != sizeof(requests->requestvb->buf)) requests->requestvb->val_len = sizeof(requests->requestvb->buf); } /* * get column data */ tri = netsnmp_extract_table_info(requests); if (NULL == tri) continue; rc = _inetNetToMediaTable_get_column(rowreq_ctx, requests->requestvb, tri->colnum); if (rc) { if (MFD_SKIP == rc) { requests->requestvb->type = SNMP_NOSUCHINSTANCE; rc = SNMP_ERR_NOERROR; } } else if (NULL == requests->requestvb->val.string) { snmp_log(LOG_ERR, "NULL varbind data pointer!\n"); rc = SNMP_ERR_GENERR; } if (rc) netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc)); /* * if the buffer wasn't used previously for the old data (i.e. it * was allcoated memory) and the get routine replaced the pointer, * we need to free the previous pointer. */ if (old_string && (old_string != requests->requestvb->buf) && (requests->requestvb->val.string != old_string)) { if (dataFreeHook) (*dataFreeHook) (old_string); else free(old_string); } } /* for results */ return SNMP_ERR_NOERROR;} /* _mfd_inetNetToMediaTable_get_values */NETSNMP_STATIC_INLINE int_inetNetToMediaTable_check_indexes(inetNetToMediaTable_rowreq_ctx * rowreq_ctx){ int rc = SNMPERR_SUCCESS; DEBUGMSGTL(("internal:inetNetToMediaTable:_inetNetToMediaTable_check_indexes", "called\n")); netsnmp_assert(NULL != rowreq_ctx); /* * (INDEX) inetNetToMediaIfIndex(1)/InterfaceIndex/ASN_INTEGER/long(long)//l/a/w/e/R/d/H */ /* * check defined range(s). */ if ((SNMPERR_SUCCESS == rc) && ((rowreq_ctx->tbl_idx.inetNetToMediaIfIndex < 1) || (rowreq_ctx->tbl_idx.inetNetToMediaIfIndex > 2147483647)) ) { rc = SNMP_ERR_WRONGVALUE; } if (MFD_SUCCESS != rc) return rc; rc = inetNetToMediaIfIndex_check_index(rowreq_ctx); if (MFD_SUCCESS != rc) return SNMP_ERR_NOCREATION; /* * (INDEX) inetNetToMediaNetAddressType(2)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h */ /* * check that the value is one of defined enums */ if ((SNMPERR_SUCCESS == rc) && (rowreq_ctx->tbl_idx.inetNetToMediaNetAddressType != INETADDRESSTYPE_UNKNOWN) && (rowreq_ctx->tbl_idx.inetNetToMediaNetAddressType != INETADDRESSTYPE_IPV4) && (rowreq_ctx->tbl_idx.inetNetToMediaNetAddressType != INETADDRESSTYPE_IPV6) && (rowreq_ctx->tbl_idx.inetNetToMediaNetAddressType != INETADDRESSTYPE_IPV4Z) && (rowreq_ctx->tbl_idx.inetNetToMediaNetAddressType != INETADDRESSTYPE_IPV6Z) && (rowreq_ctx->tbl_idx.inetNetToMediaNetAddressType != INETADDRESSTYPE_DNS) ) { rc = SNMP_ERR_WRONGVALUE; } if (MFD_SUCCESS != rc) return rc; rc = inetNetToMediaNetAddressType_check_index(rowreq_ctx); if (MFD_SUCCESS != rc) return SNMP_ERR_NOCREATION; /* * (INDEX) inetNetToMediaNetAddress(3)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h */ /* * check defined range(s). */ if ((SNMPERR_SUCCESS == rc) && ((rowreq_ctx->tbl_idx.inetNetToMediaNetAddress_len < 0) || (rowreq_ctx->tbl_idx.inetNetToMediaNetAddress_len > 255)) ) { rc = SNMP_ERR_WRONGLENGTH; } if (MFD_SUCCESS != rc) return rc; rc = inetNetToMediaNetAddress_check_index(rowreq_ctx); if (MFD_SUCCESS != rc) return SNMP_ERR_NOCREATION; /* * if individual parts look ok, check them as a whole */ return inetNetToMediaTable_validate_index(inetNetToMediaTable_if_ctx. user_ctx, rowreq_ctx);} /* _inetNetToMediaTable_check_indexes *//*********************************************************************** * * SET processing * ***********************************************************************//*---------------------------------------------------------------------- * * SET: Syntax checks * *---------------------------------------------------------------------*//* * @internal * Check the syntax for a particular column */NETSNMP_STATIC_INLINE int_inetNetToMediaTable_check_column(inetNetToMediaTable_rowreq_ctx * rowreq_ctx, netsnmp_variable_list * var, int column){ int rc = SNMPERR_SUCCESS; DEBUGMSGTL(("internal:inetNetToMediaTable:_inetNetToMediaTable_check_column", "called for %d\n", column)); netsnmp_assert(NULL != rowreq_ctx); switch (column) { /* * (INDEX) inetNetToMediaIfIndex(1)/InterfaceIndex/ASN_INTEGER/long(long)//l/a/w/e/R/d/H */ case COLUMN_INETNETTOMEDIAIFINDEX: rc = SNMP_ERR_NOTWRITABLE; /* can not change index of active row */ break; /* * (INDEX) inetNetToMediaNetAddressType(2)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h */ case COLUMN_INETNETTOMEDIANETADDRESSTYPE: rc = SNMP_ERR_NOTWRITABLE; /* can not change index of active row */ break; /* * (INDEX) inetNetToMediaNetAddress(3)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h */ case COLUMN_INETNETTOMEDIANETADDRESS: rc = SNMP_ERR_NOTWRITABLE; /* can not change index of active row */ break; /* * inetNetToMediaPhysAddress(4)/PhysAddress/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */ case COLUMN_INETNETTOMEDIAPHYSADDRESS: rc = netsnmp_check_vb_type(var, ASN_OCTET_STR); /* * check defined range(s). */ if ((SNMPERR_SUCCESS == rc) && ((var->val_len < 0) || (var->val_len > 65535)) ) { rc = SNMP_ERR_WRONGLENGTH; } if (SNMPERR_SUCCESS != rc) { DEBUGMSGTL(("inetNetToMediaTable:_inetNetToMediaTable_check_column:inetNetToMediaPhysAddress", "varbind validation failed (eg bad type or size)\n")); } else { rc = inetNetToMediaPhysAddress_check_value(rowreq_ctx, (char *) var->val. string, var->val_len); if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc) && (MFD_NOT_VALID_NOW != rc)) { snmp_log(LOG_ERR,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -