📄 ipaddresstable_interface.c
字号:
return err;} /* ipAddressTable_index_from_oid *//* ********************************************************************* * @internal * allocate resources for a ipAddressTable_rowreq_ctx */ipAddressTable_rowreq_ctx *ipAddressTable_allocate_rowreq_ctx(ipAddressTable_data * data){ ipAddressTable_rowreq_ctx *rowreq_ctx = SNMP_MALLOC_TYPEDEF(ipAddressTable_rowreq_ctx); DEBUGMSGTL(("internal:ipAddressTable:ipAddressTable_allocate_rowreq_ctx", "called\n")); if (NULL == rowreq_ctx) { snmp_log(LOG_ERR, "Couldn't allocate memory for a " "ipAddressTable_rowreq_ctx.\n"); } else { if (NULL != data) { rowreq_ctx->data = data; } else if (NULL == (rowreq_ctx->data = ipAddressTable_allocate_data())) { SNMP_FREE(rowreq_ctx); return NULL; } } /* * undo context will be allocated when needed (in *_undo_setup) */ rowreq_ctx->oid_idx.oids = rowreq_ctx->oid_tmp; rowreq_ctx->ipAddressTable_data_list = NULL; rowreq_ctx->ipAddressTable_reg = ipAddressTable_if_ctx.user_ctx; return rowreq_ctx;} /* ipAddressTable_allocate_rowreq_ctx *//* * @internal * release resources for a ipAddressTable_rowreq_ctx */voidipAddressTable_release_rowreq_ctx(ipAddressTable_rowreq_ctx * rowreq_ctx){ DEBUGMSGTL(("internal:ipAddressTable:ipAddressTable_release_rowreq_ctx", "called\n")); netsnmp_assert(NULL != rowreq_ctx); if (rowreq_ctx->data) ipAddressTable_release_data(rowreq_ctx->data); if (rowreq_ctx->undo) ipAddressTable_release_data(rowreq_ctx->undo); /* * free index oid pointer */ if (rowreq_ctx->oid_idx.oids != rowreq_ctx->oid_tmp) free(rowreq_ctx->oid_idx.oids); SNMP_FREE(rowreq_ctx);} /* ipAddressTable_release_rowreq_ctx *//** * @internal * wrapper */static int_mfd_ipAddressTable_pre_request(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests){ int rc = ipAddressTable_pre_request(ipAddressTable_if_ctx.user_ctx); if (MFD_SUCCESS != rc) { /* * nothing we can do about it but log it */ DEBUGMSGTL(("internal:ipAddressTable", "error %d from " "ipAddressTable_pre_request\n", rc)); netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); } return SNMP_ERR_NOERROR;} /* _mfd_ipAddressTable_pre_request *//** * @internal * wrapper */static int_mfd_ipAddressTable_post_request(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests){ ipAddressTable_rowreq_ctx *rowreq_ctx; int rc = ipAddressTable_post_request(ipAddressTable_if_ctx.user_ctx); if (MFD_SUCCESS != rc) { /* * nothing we can do about it but log it */ DEBUGMSGTL(("internal:ipAddressTable", "error %d from " "ipAddressTable_post_request\n", rc)); } /* * if it was set, clear row created flag. */ rowreq_ctx = netsnmp_container_table_row_extract(requests); if ((NULL != rowreq_ctx) && (rowreq_ctx->rowreq_flags & MFD_ROW_CREATED)) rowreq_ctx->rowreq_flags &= ~MFD_ROW_CREATED; return SNMP_ERR_NOERROR;} /* _mfd_ipAddressTable_post_request *//** * @internal * wrapper */static int_mfd_ipAddressTable_object_lookup(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests){ ipAddressTable_rowreq_ctx *rowreq_ctx = netsnmp_container_table_row_extract(requests); DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_object_lookup", "called\n")); /* * get our context from mfd * ipAddressTable_interface_ctx *if_ctx = * (ipAddressTable_interface_ctx *)reginfo->my_reg_void; */ if (NULL == rowreq_ctx) {#define NETSNMP_IPADDRESSTABLE_CREATE_SUPPORT 1#ifndef NETSNMP_IPADDRESSTABLE_CREATE_SUPPORT netsnmp_request_set_error(requests, SNMP_ERR_NOCREATION);#else int rc = MFD_SUCCESS; netsnmp_table_request_info *tblreq_info; netsnmp_index oid_idx; ipAddressTable_mib_index mib_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 to parse oid */ oid_idx.oids = tblreq_info->index_oid; oid_idx.len = tblreq_info->index_oid_len; rc = ipAddressTable_index_from_oid(&oid_idx, &mib_idx); if (MFD_SUCCESS != rc) { DEBUGMSGT(("ipAddressTable", "error parsing index\n")); netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); } else { /* * allocate new context */ rowreq_ctx = ipAddressTable_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 = _ipAddressTable_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)); ipAddressTable_release_rowreq_ctx(rowreq_ctx); } else { rowreq_ctx->rowreq_flags |= MFD_ROW_CREATED; netsnmp_container_table_row_insert(requests, rowreq_ctx); } }#endif /* NETSNMP_IPADDRESSTABLE_CREATE_SUPPORT */ } else { ipAddressTable_row_prep(rowreq_ctx); } return SNMP_ERR_NOERROR;} /* _mfd_ipAddressTable_object_lookup *//*********************************************************************** * * GET processing * ***********************************************************************//* * @internal * Retrieve the value for a particular column */NETSNMP_STATIC_INLINE int_ipAddressTable_get_column(ipAddressTable_rowreq_ctx * rowreq_ctx, netsnmp_variable_list * var, int column){ int rc = SNMPERR_SUCCESS; DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_get_column", "called\n")); netsnmp_assert(NULL != rowreq_ctx); switch (column) { /* * ipAddressIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/W/e/R/d/H */ case COLUMN_IPADDRESSIFINDEX: var->val_len = sizeof(long); var->type = ASN_INTEGER; rc = ipAddressIfIndex_get(rowreq_ctx, (long *) var->val.string); break; /* * ipAddressType(4)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h */ case COLUMN_IPADDRESSTYPE: var->val_len = sizeof(u_long); var->type = ASN_INTEGER; rc = ipAddressType_get(rowreq_ctx, (u_long *) var->val.string); break; /* * ipAddressPrefix(5)/RowPointer/ASN_OBJECT_ID/oid(oid)//L/A/w/e/r/D/h */ case COLUMN_IPADDRESSPREFIX: var->type = ASN_OBJECT_ID; rc = ipAddressPrefix_get(rowreq_ctx, (oid **) & var->val.string, &var->val_len); break; /* * ipAddressOrigin(6)/IpAddressOriginTC/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h */ case COLUMN_IPADDRESSORIGIN: var->val_len = sizeof(u_long); var->type = ASN_INTEGER; rc = ipAddressOrigin_get(rowreq_ctx, (u_long *) var->val.string); break; /* * ipAddressStatus(7)/IpAddressStatusTC/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h */ case COLUMN_IPADDRESSSTATUS: var->val_len = sizeof(u_long); var->type = ASN_INTEGER; rc = ipAddressStatus_get(rowreq_ctx, (u_long *) var->val.string); break; /* * ipAddressCreated(8)/TimeStamp/ASN_TIMETICKS/u_long(u_long)//l/A/w/e/r/d/h */ case COLUMN_IPADDRESSCREATED: var->val_len = sizeof(u_long); var->type = ASN_TIMETICKS; rc = ipAddressCreated_get(rowreq_ctx, (u_long *) var->val.string); break; /* * ipAddressLastChanged(9)/TimeStamp/ASN_TIMETICKS/u_long(u_long)//l/A/w/e/r/d/h */ case COLUMN_IPADDRESSLASTCHANGED: var->val_len = sizeof(u_long); var->type = ASN_TIMETICKS; rc = ipAddressLastChanged_get(rowreq_ctx, (u_long *) var->val.string); break; /* * ipAddressRowStatus(10)/RowStatus/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h */ case COLUMN_IPADDRESSROWSTATUS: var->val_len = sizeof(u_long); var->type = ASN_INTEGER; rc = ipAddressRowStatus_get(rowreq_ctx, (u_long *) var->val.string); break; /* * ipAddressStorageType(11)/StorageType/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h */ case COLUMN_IPADDRESSSTORAGETYPE: var->val_len = sizeof(u_long); var->type = ASN_INTEGER; rc = ipAddressStorageType_get(rowreq_ctx, (u_long *) var->val.string); break; default: snmp_log(LOG_ERR, "unknown column %d in _ipAddressTable_get_column\n", column); break; } return rc;} /* _ipAddressTable_get_column */int_mfd_ipAddressTable_get_values(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests){ ipAddressTable_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:ipAddressTable:_mfd_ipAddressTable_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 = _ipAddressTable_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_ipAddressTable_get_values *//*********************************************************************** * * SET processing * ***********************************************************************//*---------------------------------------------------------------------- * * SET: Syntax checks * *---------------------------------------------------------------------*//* * @internal * Check the syntax for a particular column */NETSNMP_STATIC_INLINE int_ipAddressTable_check_column(ipAddressTable_rowreq_ctx * rowreq_ctx, netsnmp_variable_list * var, int column){ int rc = SNMPERR_SUCCESS; DEBUGMSGTL(("internal:ipAddressTable:_ipAddressTable_check_column", "called\n")); netsnmp_assert(NULL != rowreq_ctx); switch (column) { /* * ipAddressIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/W/e/R/d/H */ case COLUMN_IPADDRESSIFINDEX: rc = netsnmp_check_vb_type(var, ASN_INTEGER); if (SNMPERR_SUCCESS == rc) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -