📄 inetcidrroutetable_interface.c
字号:
oid_idx.oids = tblreq_info->index_oid; oid_idx.len = tblreq_info->index_oid_len; rc = inetCidrRouteTable_index_from_oid(&oid_idx, &mib_idx); if (MFD_SUCCESS != rc) { DEBUGMSGT(("inetCidrRouteTable", "error parsing index\n")); netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); } else { /* * allocate new context */ rowreq_ctx = inetCidrRouteTable_allocate_rowreq_ctx(NULL); if (NULL == rowreq_ctx) return MFD_ERROR; /* msg already logged */ memcpy(&rowreq_ctx->tbl_idx, &mib_idx, sizeof(mib_idx)); /* * check indexes */ rc = _inetCidrRouteTable_check_indexes(rowreq_ctx); if (MFD_SUCCESS != rc) { netsnmp_assert((rc == SNMP_ERR_NOCREATION) || (rc == SNMP_ERR_INCONSISTENTNAME)); netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); inetCidrRouteTable_release_rowreq_ctx(rowreq_ctx); } else { rowreq_ctx->rowreq_flags |= MFD_ROW_CREATED; netsnmp_container_table_row_insert(requests, rowreq_ctx); } } } else { inetCidrRouteTable_row_prep(rowreq_ctx); } return SNMP_ERR_NOERROR;} /* _mfd_inetCidrRouteTable_object_lookup *//*********************************************************************** * * GET processing * ***********************************************************************//* * @internal * Retrieve the value for a particular column */NETSNMP_STATIC_INLINE int_inetCidrRouteTable_get_column(inetCidrRouteTable_rowreq_ctx * rowreq_ctx, netsnmp_variable_list * var, int column){ int rc = SNMPERR_SUCCESS; DEBUGMSGTL(("internal:inetCidrRouteTable:_mfd_inetCidrRouteTable_get_column", "called\n")); netsnmp_assert(NULL != rowreq_ctx); switch (column) { /* * inetCidrRouteIfIndex(7)/InterfaceIndexOrZero/ASN_INTEGER/long(long)//l/A/W/e/R/d/H */ case COLUMN_INETCIDRROUTEIFINDEX: var->val_len = sizeof(long); var->type = ASN_INTEGER; rc = inetCidrRouteIfIndex_get(rowreq_ctx, (long *) var->val.string); break; /* * inetCidrRouteType(8)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h */ case COLUMN_INETCIDRROUTETYPE: var->val_len = sizeof(u_long); var->type = ASN_INTEGER; rc = inetCidrRouteType_get(rowreq_ctx, (u_long *) var->val.string); break; /* * inetCidrRouteProto(9)/IANAipRouteProtocol/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h */ case COLUMN_INETCIDRROUTEPROTO: var->val_len = sizeof(u_long); var->type = ASN_INTEGER; rc = inetCidrRouteProto_get(rowreq_ctx, (u_long *) var->val.string); break; /* * inetCidrRouteAge(10)/GAUGE/ASN_GAUGE/u_long(u_long)//l/A/w/e/r/d/h */ case COLUMN_INETCIDRROUTEAGE: var->val_len = sizeof(u_long); var->type = ASN_GAUGE; rc = inetCidrRouteAge_get(rowreq_ctx, (u_long *) var->val.string); break; /* * inetCidrRouteNextHopAS(11)/InetAutonomousSystemNumber/ASN_UNSIGNED/u_long(u_long)//l/A/W/e/r/D/H */ case COLUMN_INETCIDRROUTENEXTHOPAS: var->val_len = sizeof(u_long); var->type = ASN_UNSIGNED; rc = inetCidrRouteNextHopAS_get(rowreq_ctx, (u_long *) var->val.string); break; /* * inetCidrRouteMetric1(12)/INTEGER32/ASN_INTEGER/long(long)//l/A/W/e/r/D/h */ case COLUMN_INETCIDRROUTEMETRIC1: var->val_len = sizeof(long); var->type = ASN_INTEGER; rc = inetCidrRouteMetric1_get(rowreq_ctx, (long *) var->val.string); break; /* * inetCidrRouteMetric2(13)/INTEGER32/ASN_INTEGER/long(long)//l/A/W/e/r/D/h */ case COLUMN_INETCIDRROUTEMETRIC2: var->val_len = sizeof(long); var->type = ASN_INTEGER; rc = inetCidrRouteMetric2_get(rowreq_ctx, (long *) var->val.string); break; /* * inetCidrRouteMetric3(14)/INTEGER32/ASN_INTEGER/long(long)//l/A/W/e/r/D/h */ case COLUMN_INETCIDRROUTEMETRIC3: var->val_len = sizeof(long); var->type = ASN_INTEGER; rc = inetCidrRouteMetric3_get(rowreq_ctx, (long *) var->val.string); break; /* * inetCidrRouteMetric4(15)/INTEGER32/ASN_INTEGER/long(long)//l/A/W/e/r/D/h */ case COLUMN_INETCIDRROUTEMETRIC4: var->val_len = sizeof(long); var->type = ASN_INTEGER; rc = inetCidrRouteMetric4_get(rowreq_ctx, (long *) var->val.string); break; /* * inetCidrRouteMetric5(16)/INTEGER32/ASN_INTEGER/long(long)//l/A/W/e/r/D/h */ case COLUMN_INETCIDRROUTEMETRIC5: var->val_len = sizeof(long); var->type = ASN_INTEGER; rc = inetCidrRouteMetric5_get(rowreq_ctx, (long *) var->val.string); break; /* * inetCidrRouteStatus(17)/RowStatus/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h */ case COLUMN_INETCIDRROUTESTATUS: var->val_len = sizeof(u_long); var->type = ASN_INTEGER; rc = inetCidrRouteStatus_get(rowreq_ctx, (u_long *) var->val.string); break; default: snmp_log(LOG_ERR, "unknown column %d in _inetCidrRouteTable_get_column\n", column); break; } return rc;} /* _inetCidrRouteTable_get_column */int_mfd_inetCidrRouteTable_get_values(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests){ inetCidrRouteTable_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:inetCidrRouteTable:_mfd_inetCidrRouteTable_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 = _inetCidrRouteTable_get_column(rowreq_ctx, requests->requestvb, tri->colnum); if (rc) { if (MFD_SKIP == rc) { requests->requestvb->type = ASN_PRIV_RETRY; 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_inetCidrRouteTable_get_values *//*********************************************************************** * * SET processing * ***********************************************************************//*---------------------------------------------------------------------- * * SET: Syntax checks * *---------------------------------------------------------------------*//* * @internal * Check the syntax for a particular column */NETSNMP_STATIC_INLINE int_inetCidrRouteTable_check_column(inetCidrRouteTable_rowreq_ctx * rowreq_ctx, netsnmp_variable_list * var, int column){ int rc = SNMPERR_SUCCESS; DEBUGMSGTL(("internal:inetCidrRouteTable:_inetCidrRouteTable_check_column", "called\n")); netsnmp_assert(NULL != rowreq_ctx); switch (column) { /* * inetCidrRouteIfIndex(7)/InterfaceIndexOrZero/ASN_INTEGER/long(long)//l/A/W/e/R/d/H */ case COLUMN_INETCIDRROUTEIFINDEX: rc = netsnmp_check_vb_type(var, ASN_INTEGER); if (SNMPERR_SUCCESS == rc) { /* * check that the value is in the defined range(s); inefficent * * but keeps rc value knowledge in libarary where it belongs. */ if (1 && ((rc = netsnmp_check_vb_int_range(var, 0, 2147483647)) != SNMP_ERR_NOERROR) ) { ; /* rc set in condition */ } } if (SNMPERR_SUCCESS == rc) { rc = inetCidrRouteIfIndex_check_value(rowreq_ctx, *((long *) var->val. string)); if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc) && (MFD_NOT_VALID_NOW != rc)) { snmp_log(LOG_ERR, "bad rc %d from inetCidrRouteIfIndex_check_value\n", rc); rc = SNMP_ERR_GENERR; } } break; /* * inetCidrRouteType(8)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h */ case COLUMN_INETCIDRROUTETYPE: rc = netsnmp_check_vb_type(var, ASN_INTEGER); if (SNMPERR_SUCCESS == rc) { /* * check that the value is one of defined enums */ if (1 && (*var->val.integer != INETCIDRROUTETYPE_OTHER) && (*var->val.integer != INETCIDRROUTETYPE_REJECT) && (*var->val.integer != INETCIDRROUTETYPE_LOCAL) && (*var->val.integer != INETCIDRROUTETYPE_REMOTE) && (*var->val.integer != INETCIDRROUTETYPE_BLACKHOLE) ) { rc = SNMP_ERR_WRONGVALUE; } } if (SNMPERR_SUCCESS == rc) { rc = inetCidrRouteType_check_value(rowreq_ctx, *((u_long *) var->val. string)); if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc) && (MFD_NOT_VALID_NOW != rc)) { snmp_log(LOG_ERR, "bad rc %d from inetCidrRouteType_check_value\n", rc); rc = SNMP_ERR_GENERR; } } break; /* * inetCidrRouteNextHopAS(11)/InetAutonomousSystemNumber/ASN_UNSIGNED/u_long(u_long)//l/A/W/e/r/D/H */ case COLUMN_INETCIDRROUTENEXTHOPAS: rc = netsnmp_check_vb_type(var, ASN_UNSIGNED); /* * yyy-rks: anything else we can do here? */ if (SNMPERR_SUCCESS == rc) { rc = inetCidrRouteNextHopAS_check_value(rowreq_ctx, *((u_long *) var->val. string)); if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc) && (MFD_NOT_VALID_NOW != rc)) { snmp_log(LOG_ERR, "bad rc %d from inetCidrRouteNextHopAS_check_value\n", rc); rc = SNMP_ERR_GENERR; } } break; /*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -