📄 ipaddresstable_interface.c
字号:
/* * ipAddressAddr(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h */ snmp_set_var_value(&var_ipAddressAddr, (u_char *) & mib_idx->ipAddressAddr, mib_idx->ipAddressAddr_len * sizeof(mib_idx->ipAddressAddr[0])); err = build_oid_noalloc(oid_idx->oids, oid_idx->len, &oid_idx->len, NULL, 0, &var_ipAddressAddrType); if (err) snmp_log(LOG_ERR, "error %d converting index to oid\n", err); /* * parsing may have allocated memory. free it. */ snmp_reset_var_buffers(&var_ipAddressAddrType); return err;} /* ipAddressTable_index_to_oid *//** * extract ipAddressTable indexes from a netsnmp_index * * @retval SNMP_ERR_NOERROR : no error * @retval SNMP_ERR_GENERR : error */intipAddressTable_index_from_oid(netsnmp_index * oid_idx, ipAddressTable_mib_index * mib_idx){ int err = SNMP_ERR_NOERROR; /* * temp storage for parsing indexes */ /* * ipAddressAddrType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h */ netsnmp_variable_list var_ipAddressAddrType; /* * ipAddressAddr(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h */ netsnmp_variable_list var_ipAddressAddr; /* * set up varbinds */ memset(&var_ipAddressAddrType, 0x00, sizeof(var_ipAddressAddrType)); var_ipAddressAddrType.type = ASN_INTEGER; memset(&var_ipAddressAddr, 0x00, sizeof(var_ipAddressAddr)); var_ipAddressAddr.type = ASN_OCTET_STR; /* * chain temp index varbinds together */ var_ipAddressAddrType.next_variable = &var_ipAddressAddr; var_ipAddressAddr.next_variable = NULL; DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_index_from_oid", "called\n")); /* * parse the oid into the individual index components */ err = parse_oid_indexes(oid_idx->oids, oid_idx->len, &var_ipAddressAddrType); if (err == SNMP_ERR_NOERROR) { /* * copy out values */ mib_idx->ipAddressAddrType = *((u_long *) var_ipAddressAddrType.val.string); /* * NOTE: val_len is in bytes, ipAddressAddr_len might not be */ if (var_ipAddressAddr.val_len > sizeof(mib_idx->ipAddressAddr)) err = SNMP_ERR_GENERR; else { memcpy(mib_idx->ipAddressAddr, var_ipAddressAddr.val.string, var_ipAddressAddr.val_len); mib_idx->ipAddressAddr_len = var_ipAddressAddr.val_len / sizeof(mib_idx->ipAddressAddr[0]); } } /* * parsing may have allocated memory. free it. */ snmp_reset_var_buffers(&var_ipAddressAddrType); return err;} /* ipAddressTable_index_from_oid *//* ********************************************************************* * @internal * allocate resources for a ipAddressTable_rowreq_ctx */ipAddressTable_rowreq_ctx *ipAddressTable_allocate_rowreq_ctx(ipAddressTable_data * data, void *user_init_ctx){ 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"); return NULL; } else { if (NULL != data) { /* * track if we got data from user */ rowreq_ctx->rowreq_flags |= MFD_ROW_DATA_FROM_USER; 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; /* * if we allocated data, call init routine */ if (!(rowreq_ctx->rowreq_flags & MFD_ROW_DATA_FROM_USER)) { if (SNMPERR_SUCCESS != ipAddressTable_rowreq_ctx_init(rowreq_ctx, user_init_ctx)) { ipAddressTable_release_rowreq_ctx(rowreq_ctx); rowreq_ctx = NULL; } } 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); ipAddressTable_rowreq_ctx_cleanup(rowreq_ctx); /* * for non-transient data, don't free data we got from the user */ if ((rowreq_ctx->data) && !(rowreq_ctx->rowreq_flags & MFD_ROW_DATA_FROM_USER)) 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; DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_pre_request", "called\n")); if (1 != netsnmp_row_merge_status_first(reginfo, agtreq_info)) { DEBUGMSGTL(("internal:ipAddressTable", "skipping additional pre_request\n")); return SNMP_ERR_NOERROR; } rc = ipAddressTable_pre_request(ipAddressTable_if_ctx.user_ctx); if (MFD_SUCCESS != rc) { /* * nothing we can do about it but log it */ DEBUGMSGTL(("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 = netsnmp_container_table_row_extract(requests); int rc, packet_rc; DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_post_request", "called\n")); /* * release row context, if deleted */ if (rowreq_ctx && (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED)) ipAddressTable_release_rowreq_ctx(rowreq_ctx); /* * wait for last call before calling user */ if (1 != netsnmp_row_merge_status_last(reginfo, agtreq_info)) { DEBUGMSGTL(("internal:ipAddressTable", "waiting for last post_request\n")); return SNMP_ERR_NOERROR; } packet_rc = netsnmp_check_all_requests_error(agtreq_info->asp, 0); if ((MFD_SUCCESS != packet_rc) && ipAddressTable_dirty_get()) { /* * we shouldn't get here. the undo steps should also clear * the dirty flags. */ snmp_log(LOG_WARNING, "ipAddressTable dirty flag set in post_request " "but status != SUCCESS.\n"); } rc = ipAddressTable_post_request(ipAddressTable_if_ctx.user_ctx, packet_rc); if (MFD_SUCCESS != rc) { /* * nothing we can do about it but log it */ DEBUGMSGTL(("ipAddressTable", "error %d from " "ipAddressTable_post_request\n", rc)); } return SNMP_ERR_NOERROR;} /* _mfd_ipAddressTable_post_request *//** * @internal * wrapper */static ipAddressTable_rowreq_ctx *_mfd_ipAddressTable_rowreq_from_index(netsnmp_index * oid_idx, int *rc_ptr){ ipAddressTable_rowreq_ctx *rowreq_ctx; ipAddressTable_mib_index mib_idx; int rc; DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_rowreq_from_index", "called\n")); if (NULL == rc_ptr) rc_ptr = &rc; *rc_ptr = MFD_SUCCESS; memset(&mib_idx, 0x0, sizeof(mib_idx)); /* * try to parse oid */ *rc_ptr = ipAddressTable_index_from_oid(oid_idx, &mib_idx); if (MFD_SUCCESS != *rc_ptr) { DEBUGMSGT(("ipAddressTable", "error parsing index\n")); return NULL; } /* * allocate new context */ rowreq_ctx = ipAddressTable_allocate_rowreq_ctx(NULL, NULL); if (NULL == rowreq_ctx) { *rc_ptr = MFD_ERROR; return NULL; /* msg already logged */ } memcpy(&rowreq_ctx->tbl_idx, &mib_idx, sizeof(mib_idx)); /* * check indexes */ *rc_ptr = _ipAddressTable_check_indexes(rowreq_ctx); if (MFD_SUCCESS != *rc_ptr) { netsnmp_assert((*rc_ptr == SNMP_ERR_NOCREATION) || (*rc_ptr == SNMP_ERR_INCONSISTENTNAME)); ipAddressTable_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_ipAddressTable_rowreq_from_index *//** * @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){ int rc = SNMP_ERR_NOERROR; 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 rc = SNMP_ERR_NOCREATION;#else 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_ipAddressTable_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); }#endif } if (MFD_SUCCESS != rc) netsnmp_request_set_error_all(requests, rc); else ipAddressTable_row_prep(rowreq_ctx); return SNMP_VALIDATE_ERR(rc);} /* _mfd_ipAddressTable_object_lookup *//***********************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -