📄 ifxtable.c
字号:
/* * Note: this file originally auto-generated by mib2c using * version : 1.48 $ of : mfd-top.m2c,v $ * * $Id: ifXTable.c 15462 2006-10-19 21:42:46Z hardaker $ *//** \page MFD helper for ifXTable * * \section intro Introduction * Introductory text. * *//* * standard Net-SNMP includes */#include <net-snmp/net-snmp-config.h>#include <net-snmp/net-snmp-includes.h>#include <net-snmp/agent/net-snmp-agent-includes.h>#include <ctype.h>/* * include our parent header */#include "ifXTable.h"#include "if-mib/ifTable/ifTable_defs.h"#include <net-snmp/agent/mib_modules.h>#include "ifXTable_interface.h"/* * not sure if we want to support set for promiscuous mode, because * 1) careful thought should go into any settable object that performs * an action that requires root access * 2) i don't want to write the code right now * */#undef NETSNMP_ENABLE_PROMISCUOUSMODE_SEToid ifXTable_oid[] = { IFXTABLE_OID };int ifXTable_oid_size = OID_LENGTH(ifXTable_oid);const char *row_token = "ifXTable";ifXTable_registration ifXTable_user_context;/** * Initializes the ifXTable module */voidinit_ifXTable(void){ DEBUGMSGTL(("verbose:ifXTable:init_ifXTable", "called\n")); /* * TODO:300:o: Perform ifXTable one-time module initialization. */ /* * here we initialize all the tables we're planning on supporting */ init_ifTable();} /* init_ifXTable *//** * Initialize the table ifXTable * (Define its contents and how it's structured) */voidinitialize_table_ifXTable(void){ ifXTable_registration *user_context; u_long flags; DEBUGMSGTL(("verbose:ifXTable:initialize_table_ifXTable", "called\n")); /* * TODO:301:o: Perform ifXTable one-time table initialization. */ /* * TODO:302:o: |->Initialize ifXTable user context * if you'd like to pass in a pointer to some data for this * table, allocate or set it up here. */ /* * a netsnmp_data_list is a simple way to store void pointers. A simple * string token is used to add, find or remove pointers. */ user_context = netsnmp_create_data_list("ifXTable", NULL, NULL); /* * No support for any flags yet, but in the future you would * set any flags here. */ flags = 0; /* * call interface initialization code */ _ifXTable_initialize_interface(user_context, flags); /* * if there is no container, bail. otherwise, register the callbacks * for persistent storage. */ if (NULL == ifTable_container_get()) return; /* msg already logged */} /* initialize_table_ifXTable *//** * extra context initialization (eg default values) * * @param rowreq_ctx : row request context * @param user_init_ctx : void pointer for user (parameter to rowreq_ctx_allocate) * * @retval MFD_SUCCESS : no errors * @retval MFD_ERROR : error (context allocate will fail) */intifXTable_rowreq_ctx_init(ifXTable_rowreq_ctx * rowreq_ctx, void *user_init_ctx){ DEBUGMSGTL(("verbose:ifXTable:ifXTable_rowreq_ctx_init", "called\n")); netsnmp_assert(NULL != rowreq_ctx); /* * TODO:210:o: |-> Perform extra ifXTable rowreq initialization. (eg DEFVALS) * should never get here - ifTable should handle this */ netsnmp_assert(0); return MFD_ERROR;} /* ifXTable_rowreq_ctx_init *//** * extra context cleanup * */voidifXTable_rowreq_ctx_cleanup(ifXTable_rowreq_ctx * rowreq_ctx){ DEBUGMSGTL(("verbose:ifXTable:ifXTable_rowreq_ctx_cleanup", "called\n")); netsnmp_assert(NULL != rowreq_ctx); /* * TODO:211:o: |-> Perform extra ifXTable rowreq cleanup. */ /* * should never get here - ifTable should handle this */ netsnmp_assert(0);} /* ifXTable_rowreq_ctx_cleanup *//** * the *_should_save routine is called to determine if a row * should be stored persistently. * * Note that this is not a 'dirty' check (i.e. if a row has changed), * but a check for volatile rows that should not be saved between * restarts. * * @param rowreq_ctx * * @return 1 if the row should be stored * @return 0 if the row should not be stored */intifXTable_container_should_save(ifXTable_rowreq_ctx * rowreq_ctx){ return 1; /* save the row */}/** * pre-request callback * * @param user_context * @retval MFD_SUCCESS : success. * @retval MFD_ERROR : other error */intifXTable_pre_request(ifXTable_registration * user_context){ DEBUGMSGTL(("verbose:ifXTable:ifXTable_pre_request", "called\n")); /* * TODO:510:o: Perform ifXTable pre-request actions. */ return MFD_SUCCESS;} /* ifXTable_pre_request *//** * post-request callback * * Note: * New rows have been inserted into the container, and * deleted rows have been removed from the container and * released. * * @param user_context * @param rc : MFD_SUCCESS if all requests succeeded * * @retval MFD_SUCCESS : success. * @retval MFD_ERROR : other error (ignored) */intifXTable_post_request(ifXTable_registration * user_context, int rc){ DEBUGMSGTL(("verbose:ifXTable:ifXTable_post_request", "called\n")); /* * TODO:511:o: Perform ifXTable post-request actions. */ /* * check to set if any rows were changed. */ if (ifXTable_dirty_get()) { /* * check if request was successful. If so, this would be * a good place to save data to its persistent store. */ if (MFD_SUCCESS == rc) { /* * save changed rows, if you haven't already */ snmp_store(netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_APPTYPE)); } ifXTable_dirty_set(0); /* clear table dirty flag */ } return MFD_SUCCESS;} /* ifXTable_post_request *//********************************************************************** ********************************************************************** *** *** Table ifXTable *** ********************************************************************** **********************************************************************//* * IF-MIB::ifXTable is subid 1 of ifMIBObjects. * Its status is Current. * OID: .1.3.6.1.2.1.31.1.1, length: 9 *//* * --------------------------------------------------------------------- * * TODO:200:r: Implement ifXTable data context functions. *//** * set mib index(es) * * @param tbl_idx mib index structure * @param ifIndex_val * * @retval MFD_SUCCESS : success. * @retval MFD_ERROR : other error. * * @remark * This convenience function is useful for setting all the MIB index * components with a single function call. It is assume that the C values * have already been mapped from their native/rawformat to the MIB format. */intifXTable_indexes_set_tbl_idx(ifXTable_mib_index * tbl_idx, long ifIndex_val){ DEBUGMSGTL(("verbose:ifXTable:ifXTable_indexes_set_tbl_idx", "called\n")); /* * ifIndex(1)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/w/e/R/d/H */ tbl_idx->ifIndex = ifIndex_val; return MFD_SUCCESS;} /* ifXTable_indexes_set_tbl_idx *//** * @internal * set row context indexes * * @param reqreq_ctx the row context that needs updated indexes * @param ifIndex_val * * @retval MFD_SUCCESS : success. * @retval MFD_ERROR : other error. * * @remark * This function sets the mib indexs, then updates the oid indexs * from the mib index. */intifXTable_indexes_set(ifXTable_rowreq_ctx * rowreq_ctx, long ifIndex_val){ DEBUGMSGTL(("verbose:ifXTable:ifXTable_indexes_set", "called\n")); if (MFD_SUCCESS != ifXTable_indexes_set_tbl_idx(&rowreq_ctx->tbl_idx, ifIndex_val)) return MFD_ERROR; /* * convert mib index to oid index */ rowreq_ctx->oid_idx.len = sizeof(rowreq_ctx->oid_tmp) / sizeof(oid); if (0 != ifXTable_index_to_oid(&rowreq_ctx->oid_idx, &rowreq_ctx->tbl_idx)) { return MFD_ERROR; } return MFD_SUCCESS;} /* ifXTable_indexes_set *//*--------------------------------------------------------------------- * IF-MIB::ifXEntry.ifName * ifName is subid 1 of ifXEntry. * Its status is Current, and its access level is ReadOnly. * OID: .1.3.6.1.2.1.31.1.1.1.1 * Description:The textual name of the interface. The value of this object should be the name of the interface as assigned by the local device and should be suitable for use in commands entered at the device's `console'. This might be a text name, such as `le0' or a simple port number, such as `1', depending on the interface naming syntax of the device. If several entries in the ifTable together represent a single interface as named by the device, then each will have the same value of ifName. Note that for an agent which responds to SNMP queries concerning an interface on some other (proxied) device, then the value of ifName for such an interface is the proxied device's local name for it. If there is no local name, or this object is otherwise not applicable, then this object contains a zero-length string. * * Attributes: * accessible 1 isscalar 0 enums 0 hasdefval 0 * readable 1 iscolumn 1 ranges 1 hashint 1 * settable 0 * hint: 255a * * Ranges: 0 - 255; * * Its syntax is DisplayString (based on perltype OCTETSTR) * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) * This data type requires a length. (Max 255) *//** * Extract the current value of the ifName data. * * Set a value using the data context for the row. * * @param rowreq_ctx * Pointer to the row request context. * @param ifName_val_ptr_ptr * Pointer to storage for a char variable * @param ifName_val_ptr_len_ptr * Pointer to a size_t. On entry, it will contain the size (in bytes) * pointed to by ifName. * On exit, this value should contain the data size (in bytes).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -