📄 ifxtable.c
字号:
/* * Note: this file originally auto-generated by mib2c using * version : 1.32 $ of : mfd-top.m2c,v $ * * $Id: ifXTable.c,v 1.12.2.1 2004/12/10 18:01:33 rstory Exp $ *//** \mainpage 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 <net-snmp/agent/mib_modules.h>#include "ifXTable_interface.h"#define LINE_TERM_CHAR '$'/* * 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";void initialize_table_ifXTable(void);static void _ifXTable_restore(const char *token, char *buf);static int _ifXTable_save(int majorID, int minorID, void *serverarg, void *clientarg);extern netsnmp_container *_ifXTable_container_get(void);/** * 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 */ if (should_init("ifXTable")) initialize_table_ifXTable();} /* init_ifXTable *//** * Initialize the table ifXTable * (Define its contents and how it's structured) */voidinitialize_table_ifXTable(void){ ifXTable_registration_ptr user_context; u_long flags; int rc; 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 == _ifXTable_container_get()) return; /* msg already logged */ register_config_handler(NULL, "ifXTable", _ifXTable_restore, NULL, NULL); rc = snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA, _ifXTable_save, _ifXTable_container_get()); if (rc != SNMP_ERR_NOERROR) snmp_log(LOG_ERR, "error registering for STORE_DATA callback " "in initialize_table_ifXTable\n");} /* initialize_table_ifXTable *//** * extra context initialization * * @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. * should never get here - ifTable should handle this */ netsnmp_assert(0); return MFD_SUCCESS;} /* 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 *//** * pre-request callback * * * @retval MFD_SUCCESS : success. * @retval MFD_ERROR : other error */intifXTable_pre_request(ifXTable_registration_ptr 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 * * * @retval MFD_SUCCESS : success. * @retval MFD_ERROR : other error (ignored) */intifXTable_post_request(ifXTable_registration_ptr user_context){ DEBUGMSGTL(("verbose:ifXTable:ifXTable_post_request", "called\n")); /* * TODO:511:o: Perform ifXTable pos-request actions. */ return MFD_SUCCESS;} /* ifXTable_post_request *//********************************************************************** ********************************************************************** *** *** Table ifXTable *** ********************************************************************** **********************************************************************//* * ifXTable is subid 1 of ifMIBObjects. * Its status is Current. * OID: .1.3.6.1.2.1.31.1.1, length: 9 *//** * set mib index(es) * * @param tbl_idx mib index structure * * @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 * * @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). * * @retval MFD_SUCCESS : success * @retval MFD_SKIP : skip this node (no value for now) * @retval MFD_ERROR : Any other error* * @note If you need more than (*ifName_val_ptr_len_ptr) bytes of memory, * allocate it using malloc() and update ifName_val_ptr_ptr. * <b>DO NOT</b> free the previous pointer. * The MFD helper will release the memory you allocate. * * @remark If you call this function yourself, you are responsible * for checking if the pointer changed, and freeing any * previously allocated memory. (Not necessary if you pass * in a pointer to static memory, obviously.) */intifName_get(ifXTable_rowreq_ctx * rowreq_ctx, char **ifName_val_ptr_ptr, size_t *ifName_val_ptr_len_ptr){ int tmp_len; /** we should have a non-NULL pointer and enough storage */ netsnmp_assert((NULL != ifName_val_ptr_ptr) && (NULL != *ifName_val_ptr_ptr)); netsnmp_assert(NULL != ifName_val_ptr_len_ptr); DEBUGMSGTL(("verbose:ifXTable:ifName_get", "called\n")); netsnmp_assert(NULL != rowreq_ctx); /*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -