static netsnmp_handler_registration * get_reg(const char *name, const char *ourname, const oid * reg_oid, size_t reg_oid_len, netsnmp_num_file_instance *it, int modes, Netsnmp_Node_Handler * scalarh, Netsnmp_Node_Handler * subhandler, const char *contextName) { netsnmp_handler_registration *myreg; netsnmp_mib_handler *myhandler; if (subhandler) { myreg = netsnmp_create_handler_registration(name, subhandler, reg_oid, reg_oid_len, modes); if (!myreg) return NULL; myhandler = netsnmp_create_handler(ourname, scalarh); if (!myhandler) { netsnmp_handler_registration_free(myreg); return NULL; } myhandler->myvoid = it; myhandler->data_clone = (void*(*)(void*))netsnmp_num_file_instance_ref; myhandler->data_free = (void(*)(void*))netsnmp_num_file_instance_deref; if (netsnmp_inject_handler(myreg, myhandler) != SNMPERR_SUCCESS) { netsnmp_handler_free(myhandler); netsnmp_handler_registration_free(myreg); return NULL; } } else { myreg = netsnmp_create_handler_registration(name, scalarh, reg_oid, reg_oid_len, modes); if (!myreg) return NULL; myreg->handler->myvoid = it; myreg->handler->data_clone = (void *(*)(void *))netsnmp_num_file_instance_ref; myreg->handler->data_free = (void (*)(void *))netsnmp_num_file_instance_deref; } if (contextName) { myreg->contextName = strdup(contextName); if (!myreg->contextName) { netsnmp_handler_registration_free(myreg); return NULL; } } return myreg; }
/** Initialize the nsModuleTable table by defining it's contents and how it's structured */ void initialize_table_nsModuleTable(void) { const oid nsModuleTable_oid[] = { 1, 3, 6, 1, 4, 1, 8072, 1, 2, 1 }; netsnmp_table_registration_info *table_info; netsnmp_handler_registration *my_handler; netsnmp_iterator_info *iinfo; /* * create the table structure itself */ table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info); /* * if your table is read only, it's easiest to change the * HANDLER_CAN_RWRITE definition below to HANDLER_CAN_RONLY */ my_handler = netsnmp_create_handler_registration("nsModuleTable", nsModuleTable_handler, nsModuleTable_oid, OID_LENGTH (nsModuleTable_oid), HANDLER_CAN_RWRITE); if (!my_handler || !table_info || !iinfo) { if (my_handler) netsnmp_handler_registration_free(my_handler); SNMP_FREE(table_info); SNMP_FREE(iinfo); return; /* mallocs failed */ } /*************************************************** * Setting up the table's definition */ netsnmp_table_helper_add_indexes(table_info, ASN_OCTET_STR, /* context name */ ASN_OBJECT_ID, /* reg point */ ASN_INTEGER, /* priority */ 0); table_info->min_column = 4; table_info->max_column = 6; /* * iterator access routines */ iinfo->get_first_data_point = nsModuleTable_get_first_data_point; iinfo->get_next_data_point = nsModuleTable_get_next_data_point; iinfo->free_loop_context_at_end = nsModuleTable_free; iinfo->table_reginfo = table_info; /*************************************************** * registering the table with the master agent */ DEBUGMSGTL(("initialize_table_nsModuleTable", "Registering table nsModuleTable as a table iterator\n")); netsnmp_register_table_iterator(my_handler, iinfo); }
/** Initialize the nsTransactionTable table by defining it's contents and how it's structured */ void initialize_table_nsTransactionTable(void) { static oid nsTransactionTable_oid[] = { 1, 3, 6, 1, 4, 1, 8072, 1, 8, 1 }; size_t nsTransactionTable_oid_len = OID_LENGTH(nsTransactionTable_oid); netsnmp_table_registration_info *table_info; netsnmp_handler_registration *my_handler; netsnmp_iterator_info *iinfo; /* * create the table structure itself */ table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info); /* * if your table is read only, it's easiest to change the * HANDLER_CAN_RWRITE definition below to HANDLER_CAN_RONLY */ my_handler = netsnmp_create_handler_registration("nsTransactionTable", nsTransactionTable_handler, nsTransactionTable_oid, nsTransactionTable_oid_len, HANDLER_CAN_RONLY); if (!my_handler || !table_info || !iinfo) { if (my_handler) netsnmp_handler_registration_free(my_handler); SNMP_FREE(table_info); SNMP_FREE(iinfo); return; /* mallocs failed */ } /*************************************************** * Setting up the table's definition */ netsnmp_table_helper_add_index(table_info, ASN_INTEGER); /* index: * * nsTransactionID */ table_info->min_column = 2; table_info->max_column = 2; iinfo->get_first_data_point = nsTransactionTable_get_first_data_point; iinfo->get_next_data_point = nsTransactionTable_get_next_data_point; iinfo->table_reginfo = table_info; /*************************************************** * registering the table with the master agent */ DEBUGMSGTL(("initialize_table_nsTransactionTable", "Registering table nsTransactionTable as a table iterator\n")); netsnmp_register_table_iterator(my_handler, iinfo); }
int netsnmp_cache_handler_register(netsnmp_handler_registration * reginfo, netsnmp_cache* cache) { if ((NULL == reginfo) || (NULL == cache)) { snmp_log(LOG_ERR, "bad param in netsnmp_cache_handler_register\n"); netsnmp_handler_registration_free(reginfo); return MIB_REGISTRATION_FAILED; } return _cache_handler_register(reginfo, netsnmp_cache_handler_get(cache)); }
/** * This function registers an instance helper handler, which is a way of * registering an exact OID such that GENEXT requests are handled entirely * by the helper. First need to inject it into the calling chain of the * handler defined by the netsnmp_handler_registration struct, reginfo. * The new handler is injected at the top of the list and will be the new * handler to be called first. This function also injects a serialize * handler before actually calling netsnmp_register_handle, registering * reginfo. * * @param reginfo a handler registration structure which could get created * using netsnmp_create_handler_registration. Used to register * an instance helper handler. * * @return * MIB_REGISTERED_OK is returned if the registration was a success. * Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION. */ int netsnmp_register_instance(netsnmp_handler_registration *reginfo) { netsnmp_mib_handler *handler = netsnmp_get_instance_handler(); if (handler) { handler->flags |= MIB_HANDLER_INSTANCE; if (netsnmp_inject_handler(reginfo, handler) == SNMPERR_SUCCESS) return netsnmp_register_serialize(reginfo); } snmp_log(LOG_ERR, "failed to register instance\n"); netsnmp_handler_free(handler); netsnmp_handler_registration_free(reginfo); return MIB_REGISTRATION_FAILED; }
/** registers a tdata-based MIB table */ int netsnmp_tdata_register(netsnmp_handler_registration *reginfo, netsnmp_tdata *table, netsnmp_table_registration_info *table_info) { netsnmp_mib_handler *handler = netsnmp_get_tdata_handler(table); if (!reginfo || !table || !table_info || !handler || (netsnmp_inject_handler(reginfo, handler) != SNMPERR_SUCCESS)) { snmp_log(LOG_ERR, "could not create tdata handler\n"); netsnmp_handler_free(handler); netsnmp_handler_registration_free(reginfo); return SNMP_ERR_GENERR; } return netsnmp_container_table_register(reginfo, table_info, table->container, TABLE_CONTAINER_KEY_NETSNMP_INDEX); }
int netsnmp_register_cache_handler(netsnmp_handler_registration * reginfo, int timeout, NetsnmpCacheLoad * load_hook, NetsnmpCacheFree * free_hook) { netsnmp_mib_handler *handler; if (NULL == reginfo) { snmp_log(LOG_ERR, "bad param in netsnmp_cache_handler_register\n"); netsnmp_handler_registration_free(reginfo); return MIB_REGISTRATION_FAILED; } handler = netsnmp_get_cache_handler(timeout, load_hook, free_hook, reginfo->rootoid, reginfo->rootoid_len); return _cache_handler_register(reginfo, handler); }
static int _cache_handler_register(netsnmp_handler_registration * reginfo, netsnmp_mib_handler *handler) { /** success path */ if (reginfo && handler && (netsnmp_inject_handler(reginfo, handler) == SNMPERR_SUCCESS)) return netsnmp_register_handler(reginfo); /** error path */ snmp_log(LOG_ERR, "could not register cache handler\n"); if (handler) netsnmp_handler_free(handler); netsnmp_handler_registration_free(reginfo); return MIB_REGISTRATION_FAILED; }
/** * This function injects a "read only" handler into the handler chain * prior to serializing/registering the handler. * * The only purpose of this "read only" handler is to return an * appropriate error for any requests passed to it in a SET mode. * Inserting it into your handler chain will ensure you're never * asked to perform a SET request so you can ignore those error * conditions. * * @param reginfo a handler registration structure which could get created * using netsnmp_create_handler_registration. Used to register * a read only instance helper handler. * * @return * MIB_REGISTERED_OK is returned if the registration was a success. * Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION. */ int netsnmp_register_read_only_instance(netsnmp_handler_registration *reginfo) { netsnmp_mib_handler *h1, *h2; if (!reginfo) return MIB_REGISTRATION_FAILED; h1 = netsnmp_get_instance_handler(); h2 = netsnmp_get_read_only_handler(); if (h1 && h2 && netsnmp_inject_handler(reginfo, h1) == SNMPERR_SUCCESS) { h1 = NULL; if (netsnmp_inject_handler(reginfo, h2) == SNMPERR_SUCCESS) return netsnmp_register_serialize(reginfo); } snmp_log(LOG_ERR, "failed to register read only instance\n"); netsnmp_handler_free(h1); netsnmp_handler_free(h2); netsnmp_handler_registration_free(reginfo); return MIB_REGISTRATION_FAILED; }
/** Initialize the cpqSasPhyDrvTable table by defining its contents and how it's structured */ void initialize_table_cpqSasPhyDrvTable(void) { netsnmp_handler_registration *reg = NULL; netsnmp_mib_handler *handler = NULL; netsnmp_container *container = NULL; netsnmp_table_registration_info *table_info = NULL; netsnmp_cache *cache = NULL; int reg_tbl_ret = SNMPERR_SUCCESS; DEBUGMSGTL(("cpqSasPhyDrvTable:init", "initializing table cpqSasPhyDrvTable\n")); reg = netsnmp_create_handler_registration("cpqSasPhyDrvTable", cpqSasPhyDrvTable_handler, cpqSasPhyDrvTable_oid, cpqSasPhyDrvTable_oid_len, HANDLER_CAN_RONLY); if (NULL == reg) { snmp_log(LOG_ERR, "error creating handler registration for cpqSasPhyDrvTable\n"); goto bail; } container = netsnmp_container_find("cpqSasPhyDrvTable:table_container"); if (NULL == container) { snmp_log(LOG_ERR, "error creating container for cpqSasPhyDrvTable\n"); goto bail; } table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); if (NULL == table_info) { snmp_log(LOG_ERR, "error allocating table registration for cpqSasPhyDrvTable\n"); goto bail; } netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, /* index: cpqSasPhyDrvHbaIndex */ ASN_INTEGER, /* index: cpqSasPhyDrvIndex */ 0); table_info->min_column = COLUMN_CPQSASPHYDRVHBAINDEX; table_info->max_column = COLUMN_CPQSASPHYDRVTEMPERATURETHRESHOLD; /************************************************* * * inject container_table helper */ handler = netsnmp_container_table_handler_get(table_info, container, TABLE_CONTAINER_KEY_NETSNMP_INDEX); if (NULL == handler) { snmp_log(LOG_ERR, "error allocating table registration for cpqSasPhyDrvTable\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR, "error injecting container_table handler for cpqSasPhyDrvTable\n"); goto bail; } handler = NULL; /* reg has it, will reuse below */ /************************************************* * * inject cache helper */ cache = netsnmp_cache_create(300, /* timeout in seconds */ _cache_load, _cache_free, cpqSasPhyDrvTable_oid, cpqSasPhyDrvTable_oid_len); if (NULL == cache) { snmp_log(LOG_ERR, "error creating cache for cpqSasPhyDrvTable\n"); goto bail; } cache->flags = NETSNMP_CACHE_PRELOAD | NETSNMP_CACHE_DONT_FREE_BEFORE_LOAD | NETSNMP_CACHE_DONT_FREE_EXPIRED | NETSNMP_CACHE_DONT_AUTO_RELEASE | NETSNMP_CACHE_DONT_INVALIDATE_ON_SET; cache->magic = container; handler = netsnmp_cache_handler_get(cache); if (NULL == handler) { snmp_log(LOG_ERR, "error creating cache handler for cpqSasPhyDrvTable\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR, "error injecting cache handler for cpqSasPhyDrvTable\n"); goto bail; } handler = NULL; /* reg has it */ /* * register the table */ reg_tbl_ret = netsnmp_register_table(reg, table_info); if (reg_tbl_ret != SNMPERR_SUCCESS) { snmp_log(LOG_ERR, "error registering table handler for cpqSasPhyDrvTable\n"); goto bail; } /* * Initialise the contents of the table here */ return; /* ok */ /* * Some error occurred during registration. Clean up and bail. */ bail: /* not ok */ if (handler) netsnmp_handler_free(handler); if (cache) netsnmp_cache_free(cache); if (table_info) netsnmp_table_registration_info_free(table_info); if (container) CONTAINER_FREE(container); if (reg_tbl_ret == SNMPERR_SUCCESS) if (reg) netsnmp_handler_registration_free(reg); }
/** Initialize the hrSWInstalledTable table by defining its contents and how it's structured */ void initialize_table_hrSWInstalledTable(void) { static oid hrSWInstalledTable_oid[] = { 1, 3, 6, 1, 2, 1, 25, 6, 3 }; size_t hrSWInstalledTable_oid_len = OID_LENGTH(hrSWInstalledTable_oid); netsnmp_handler_registration *reg; netsnmp_mib_handler *handler = NULL; netsnmp_container *container = NULL; netsnmp_cache *cache = NULL; DEBUGMSGTL(("hrSWInstalled", "initialize\n")); reg = netsnmp_create_handler_registration("hrSWInstalledTable", hrSWInstalledTable_handler, hrSWInstalledTable_oid, hrSWInstalledTable_oid_len, HANDLER_CAN_RONLY); if (NULL == reg) { snmp_log(LOG_ERR,"error creating handler registration for " MYTABLE "\n"); goto bail; } container = netsnmp_container_find("hrSWInstalledTable:table_container"); if (NULL == container) { snmp_log(LOG_ERR,"error creating container for " MYTABLE "\n"); goto bail; } table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); if (NULL == table_info) { snmp_log(LOG_ERR,"error allocating table registration for " MYTABLE "\n"); goto bail; } netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, /* index: hrSWInstalledIndex */ 0); table_info->min_column = COLUMN_HRSWINSTALLEDINDEX; table_info->max_column = COLUMN_HRSWINSTALLEDDATE; /************************************************* * * inject container_table helper */ handler = netsnmp_container_table_handler_get(table_info, container, TABLE_CONTAINER_KEY_NETSNMP_INDEX); if (NULL == handler) { snmp_log(LOG_ERR,"error allocating table registration for " MYTABLE "\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR,"error injecting container_table handler for " MYTABLE "\n"); goto bail; } handler = NULL; /* reg has it, will reuse below */ /************************************************* * * inject cache helper */ cache = netsnmp_cache_create(30, /* timeout in seconds */ _cache_load, _cache_free, hrSWInstalledTable_oid, hrSWInstalledTable_oid_len); if (NULL == cache) { snmp_log(LOG_ERR, "error creating cache for " MYTABLE "\n"); goto bail; } cache->magic = container; handler = netsnmp_cache_handler_get(cache); if (NULL == handler) { snmp_log(LOG_ERR, "error creating cache handler for " MYTABLE "\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR,"error injecting cache handler for " MYTABLE "\n"); goto bail; } handler = NULL; /* reg has it*/ if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) { snmp_log(LOG_ERR,"error registering table handler for " MYTABLE "\n"); reg = NULL; /* it was freed inside netsnmp_register_table */ goto bail; } return; /* ok */ bail: /* not ok */ if (handler) netsnmp_handler_free(handler); if (cache) netsnmp_cache_free(cache); if (table_info) netsnmp_table_registration_info_free(table_info); if (container) CONTAINER_FREE(container); if (reg) netsnmp_handler_registration_free(reg); }
/** Initialize the cpqLinOsProcessorTable table by defining its contents * and how it's structured */ void initialize_table_cpqLinOsProcessorTable(void) { netsnmp_handler_registration *reg = NULL; netsnmp_mib_handler *handler = NULL; netsnmp_container *container = NULL; netsnmp_table_registration_info *table_info = NULL; netsnmp_cache *cache = NULL; DEBUGMSGTL(("cpqLinOsProcessorTable:init", "initializing table cpqLinOsProcessorTable\n")); reg = netsnmp_create_handler_registration("cpqLinOsProcessorTable", cpqLinOsProcessorTable_handler, cpqLinOsProcessorTable_oid, cpqLinOsProcessorTable_oid_len, HANDLER_CAN_RONLY); if (NULL == reg) { snmp_log(LOG_ERR, "error creating handler registration for cpqLinOsProcessorTable\n"); goto bail; } container = netsnmp_container_find("cpqLinOsProcessorTable:table_container"); if (NULL == container) { snmp_log(LOG_ERR, "error creating container for cpqLinOsProcessorTable\n"); goto bail; } container->container_name = strdup("cpqLinOsProcessorTable container"); table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); if (NULL == table_info) { snmp_log(LOG_ERR, "error allocating table registration for cpqLinOsProcessorTable\n"); goto bail; } netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, /* index: cpqLinOsCpuIndex */ 0); table_info->min_column = COLUMN_CPQLINOSCPUINDEX; table_info->max_column = COLUMN_CPQLINOSCPUPRIVILEGEDTIMEPERCENT; /************************************************* * * inject container_table helper */ handler = netsnmp_container_table_handler_get(table_info, container, TABLE_CONTAINER_KEY_NETSNMP_INDEX); if (NULL == handler) { snmp_log(LOG_ERR, "error allocating table registration for cpqLinOsProcessorTable\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR, "error injecting container_table handler for cpqLinOsProcessorTable\n"); goto bail; } handler = NULL; /* reg has it, will reuse below */ /************************************************* * * inject cache helper */ cache = netsnmp_cache_create(5, /* timeout in seconds */ _cache_load, _cache_free, cpqLinOsProcessorTable_oid, cpqLinOsProcessorTable_oid_len); if (NULL == cache) { snmp_log(LOG_ERR, "error creating cache for cpqLinOsProcessorTable\n"); goto bail; } cache->flags = NETSNMP_CACHE_PRELOAD | NETSNMP_CACHE_DONT_FREE_EXPIRED | NETSNMP_CACHE_DONT_AUTO_RELEASE | NETSNMP_CACHE_DONT_FREE_BEFORE_LOAD | NETSNMP_CACHE_DONT_INVALIDATE_ON_SET; cache->magic = container; handler = netsnmp_cache_handler_get(cache); if (NULL == handler) { snmp_log(LOG_ERR, "error creating cache handler for cpqLinOsProcessorTable\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR, "error injecting cache handler for cpqLinOsProcessorTable\n"); goto bail; } handler = NULL; /* reg has it */ /* * register the table */ if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) { snmp_log(LOG_ERR, "error registering table handler for cpqLinOsProcessorTable\n"); reg = NULL; /* it was freed inside netsnmp_register_table */ goto bail; } return; /* ok */ /* * Some error occurred during registration. Clean up and bail. */ bail: /* not ok */ if (handler) netsnmp_handler_free(handler); if (cache) netsnmp_cache_free(cache); if (table_info) netsnmp_table_registration_info_free(table_info); if (container) CONTAINER_FREE(container); if (reg) netsnmp_handler_registration_free(reg); }
/** Initialize the hrSWRunTable table by defining its contents and how it's structured */ void initialize_table_hrSWRunTable(void) { netsnmp_handler_registration *reg; netsnmp_mib_handler *handler = NULL; #ifndef NETSNMP_NO_WRITE_SUPPORT #ifdef NETSNMP_INCLUDE_HRSWRUN_WRITE_SUPPORT # define SWRUN_ACCESS_LEVEL HANDLER_CAN_RWRITE #else # define SWRUN_ACCESS_LEVEL HANDLER_CAN_RONLY #endif #else /* !NETSNMP_NO_WRITE_SUPPORT */ # define SWRUN_ACCESS_LEVEL HANDLER_CAN_RONLY #endif /* !NETSNMP_NO_WRITE_SUPPORT */ reg = netsnmp_create_handler_registration(MYTABLE, hrSWRunTable_handler, hrSWRunTable_oid, hrSWRunTable_oid_len, SWRUN_ACCESS_LEVEL); if (NULL == reg) { snmp_log(LOG_ERR,"error creating handler registration for " MYTABLE "\n"); goto bail; } reg->modes |= HANDLER_CAN_NOT_CREATE; table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); if (NULL == table_info) { snmp_log(LOG_ERR,"error allocating table registration for " MYTABLE "\n"); goto bail; } netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, /* index: hrSWRunIndex */ 0); table_info->min_column = COLUMN_HRSWRUNINDEX; table_info->max_column = COLUMN_HRSWRUNSTATUS; /************************************************* * * inject container_table helper */ handler = netsnmp_container_table_handler_get(table_info, netsnmp_swrun_container(), TABLE_CONTAINER_KEY_NETSNMP_INDEX); if (NULL == handler) { snmp_log(LOG_ERR,"error allocating table registration for " MYTABLE "\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR,"error injecting container_table handler for " MYTABLE "\n"); goto bail; } handler = NULL; /* reg has it, will reuse below */ /************************************************* * * inject cache helper */ handler = netsnmp_cache_handler_get(netsnmp_swrun_cache()); if (NULL == handler) { snmp_log(LOG_ERR, "error creating cache handler for " MYTABLE "\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR,"error injecting cache handler for " MYTABLE "\n"); goto bail; } handler = NULL; /* reg has it*/ if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) { snmp_log(LOG_ERR,"error registering table handler for " MYTABLE "\n"); reg = NULL; /* it was freed inside netsnmp_register_table */ goto bail; } return; /* ok */ bail: /* not ok */ if (handler) netsnmp_handler_free(handler); if (table_info) netsnmp_table_registration_info_free(table_info); if (reg) netsnmp_handler_registration_free(reg); }
/** Initialize the sctpAssocTable table by defining its contents and how it's structured */ void initialize_table_sctpAssocTable(void) { static oid sctpAssocTable_oid[] = { 1, 3, 6, 1, 2, 1, 104, 1, 3 }; size_t sctpAssocTable_oid_len = OID_LENGTH(sctpAssocTable_oid); netsnmp_handler_registration *reg = NULL; netsnmp_mib_handler *handler = NULL; netsnmp_container *container = NULL; netsnmp_table_registration_info *table_info = NULL; netsnmp_cache *cache = NULL; reg = netsnmp_create_handler_registration("sctpAssocTable", sctpAssocTable_handler, sctpAssocTable_oid, sctpAssocTable_oid_len, HANDLER_CAN_RWRITE); if (NULL == reg) { snmp_log(LOG_ERR, "error creating handler registration for sctpAssocTable\n"); goto bail; } /** should a set on a non-existent row create a new one? */ /** reg->modes |= HANDLER_CAN_NOT_CREATE; */ container = netsnmp_container_find("sctpAssocTable:table_container"); if (NULL == container) { snmp_log(LOG_ERR, "error creating container for sctpAssocTable\n"); goto bail; } sctpAssocTable_container = container; table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); if (NULL == table_info) { snmp_log(LOG_ERR, "error allocating table registration for sctpAssocTable\n"); goto bail; } netsnmp_table_helper_add_indexes(table_info, ASN_UNSIGNED, /* index: sctpAssocId */ 0); table_info->min_column = COLUMN_SCTPASSOCREMHOSTNAME; table_info->max_column = COLUMN_SCTPASSOCDISCONTINUITYTIME; /************************************************* * * inject container_table helper */ handler = netsnmp_container_table_handler_get(table_info, container, TABLE_CONTAINER_KEY_NETSNMP_INDEX); if (NULL == handler) { snmp_log(LOG_ERR, "error allocating table registration for sctpAssocTable\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR, "error injecting container_table handler for sctpAssocTable\n"); goto bail; } handler = NULL; /* reg has it, will reuse below */ /************************************************* * * inject cache helper */ cache = netsnmp_cache_create(SCTP_TABLES_CACHE_TIMEOUT, /* timeout in seconds */ _cache_load, _cache_free, sctpAssocTable_oid, sctpAssocTable_oid_len); if (NULL == cache) { snmp_log(LOG_ERR, "error creating cache for sctpAssocTable\n"); goto bail; } cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET | NETSNMP_CACHE_AUTO_RELOAD | NETSNMP_CACHE_PRELOAD; cache->magic = container; handler = netsnmp_cache_handler_get(cache); if (NULL == handler) { snmp_log(LOG_ERR, "error creating cache handler for sctpAssocTable\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR, "error injecting cache handler for sctpAssocTable\n"); goto bail; } handler = NULL; /* reg has it */ /* * register the table */ if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) { snmp_log(LOG_ERR, "error registering table handler for sctpAssocTable\n"); goto bail; } /* * Initialise the contents of the table here */ return; /* ok */ /* * Some error occurred during registration. Clean up and bail. */ bail: /* not ok */ if (handler) netsnmp_handler_free(handler); if (container) CONTAINER_FREE(container); if (reg) netsnmp_handler_registration_free(reg); }
/** Initialize the cpqNicIfLogMapTable table by defining its contents and how it's structured */ void initialize_table_cpqNicIfLogMapTable(void) { const oid cpqNicIfLogMapTable_oid[] = { 1, 3, 6, 1, 4, 1, 232, 18, 2, 2, 1 }; const size_t cpqNicIfLogMapTable_oid_len = OID_LENGTH(cpqNicIfLogMapTable_oid); netsnmp_handler_registration *reg = NULL; netsnmp_mib_handler *handler = NULL; netsnmp_container *container = NULL; netsnmp_table_registration_info *table_info = NULL; netsnmp_cache *cache = NULL; int reg_tbl_ret = SNMPERR_SUCCESS; DEBUGMSGTL(("cpqNicIfLogMapTable:init", "initializing table cpqNicIfLogMapTable\n")); reg = netsnmp_create_handler_registration("cpqNicIfLogMapTable", cpqNicIfLogMapTable_handler, cpqNicIfLogMapTable_oid, cpqNicIfLogMapTable_oid_len, HANDLER_CAN_RONLY); if (NULL == reg) { snmp_log(LOG_ERR, "error creating handler registration for cpqNicIfLogMapTable\n"); goto bail; } container = netsnmp_container_find("cpqNicIfLogMapTable:table_container"); if (NULL == container) { snmp_log(LOG_ERR, "error creating container for cpqNicIfLogMapTable\n"); goto bail; } container->container_name = strdup("cpqNicIfLogMapTable container"); table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); if (NULL == table_info) { snmp_log(LOG_ERR, "error allocating table registration for cpqNicIfLogMapTable\n"); goto bail; } netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, /* index: cpqNicIfLogMapIndex */ 0); table_info->min_column = COLUMN_CPQNICIFLOGMAPINDEX; table_info->max_column = COLUMN_CPQNICIFLOGMAPPCILOCATION; /************************************************* * * inject container_table helper */ handler = netsnmp_container_table_handler_get(table_info, container, TABLE_CONTAINER_KEY_NETSNMP_INDEX); if (NULL == handler) { snmp_log(LOG_ERR, "error allocating table registration for cpqNicIfLogMapTable\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR, "error injecting container_table handler for cpqNicIfLogMapTable\n"); goto bail; } handler = NULL; /* reg has it, will reuse below */ /************************************************* * * inject cache helper */ cache = netsnmp_cache_create(30, /* timeout in seconds */ _cache_load, _cache_free, cpqNicIfLogMapTable_oid, cpqNicIfLogMapTable_oid_len); if (NULL == cache) { snmp_log(LOG_ERR, "error creating cache for cpqNicIfLogMapTable\n"); goto bail; } cache->flags = NETSNMP_CACHE_PRELOAD | NETSNMP_CACHE_DONT_FREE_EXPIRED | NETSNMP_CACHE_DONT_AUTO_RELEASE | NETSNMP_CACHE_DONT_FREE_BEFORE_LOAD | NETSNMP_CACHE_DONT_INVALIDATE_ON_SET; cache->magic = container; handler = netsnmp_cache_handler_get(cache); if (NULL == handler) { snmp_log(LOG_ERR, "error creating cache handler for cpqNicIfLogMapTable\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR, "error injecting cache handler for cpqNicIfLogMapTable\n"); goto bail; } handler = NULL; /* reg has it */ /* * register the table */ reg_tbl_ret = netsnmp_register_table(reg, table_info); if (reg_tbl_ret != SNMPERR_SUCCESS) { snmp_log(LOG_ERR, "error registering table handler for cpqNicIfLogMapTable\n"); goto bail; } return; /* ok */ /* * Some error occurred during registration. Clean up and bail. */ bail: /* not ok */ if (handler) netsnmp_handler_free(handler); if (cache) netsnmp_cache_free(cache); if (table_info) netsnmp_table_registration_info_free(table_info); if (container) CONTAINER_FREE(container); if (reg_tbl_ret == SNMPERR_SUCCESS) if (reg) netsnmp_handler_registration_free(reg); }
int netsnmp_table_row_register(netsnmp_handler_registration *reginfo, netsnmp_table_registration_info *tabreg, void *row, netsnmp_variable_list *index) { netsnmp_handler_registration *reg2; netsnmp_mib_handler *handler; oid row_oid[MAX_OID_LEN]; size_t row_oid_len, len; char tmp[SNMP_MAXBUF_MEDIUM]; if ((NULL == reginfo) || (NULL == reginfo->handler) || (NULL == tabreg)) { snmp_log(LOG_ERR, "bad param in netsnmp_table_row_register\n"); netsnmp_handler_registration_free(reginfo); return SNMPERR_GENERR; } /* * The first table_row invoked for a particular table should * register the full table as well, with a default handler to * process requests for non-existent (or incomplete) rows. * * Subsequent table_row registrations attempting to set up * this default handler would fail - preferably silently! */ snprintf(tmp, sizeof(tmp), "%s_table", reginfo->handlerName); reg2 = netsnmp_create_handler_registration( tmp, _table_row_default_handler, reginfo->rootoid, reginfo->rootoid_len, reginfo->modes); netsnmp_register_table(reg2, tabreg); /* Ignore return value */ /* * Adjust the OID being registered, to take account * of the indexes and column range provided.... */ row_oid_len = reginfo->rootoid_len; memcpy( row_oid, (u_char *) reginfo->rootoid, row_oid_len * sizeof(oid)); row_oid[row_oid_len++] = 1; /* tableEntry */ row_oid[row_oid_len++] = tabreg->min_column; reginfo->range_ubound = tabreg->max_column; reginfo->range_subid = row_oid_len-1; build_oid_noalloc(&row_oid[row_oid_len], MAX_OID_LEN-row_oid_len, &len, NULL, 0, index); row_oid_len += len; free(reginfo->rootoid); reginfo->rootoid = snmp_duplicate_objid(row_oid, row_oid_len); reginfo->rootoid_len = row_oid_len; /* * ... insert a minimal handler ... */ handler = netsnmp_table_row_handler_get(row); if (!handler || (netsnmp_inject_handler(reginfo, handler) != SNMPERR_SUCCESS)) { snmp_log(LOG_ERR, "could not create table row handler\n"); netsnmp_handler_free(handler); netsnmp_handler_registration_free(reginfo); return SNMP_ERR_GENERR; } /* * ... and register the row */ return netsnmp_register_handler(reginfo); }
/** Initialize the sctpLookupRemPortTable table by defining its contents and how it's structured */ void initialize_table_sctpLookupRemPortTable(void) { static oid sctpLookupRemPortTable_oid[] = { 1, 3, 6, 1, 2, 1, 104, 1, 7 }; size_t sctpLookupRemPortTable_oid_len = OID_LENGTH(sctpLookupRemPortTable_oid); netsnmp_handler_registration *reg = NULL; netsnmp_mib_handler *handler = NULL; netsnmp_container *container = NULL; reg = netsnmp_create_handler_registration("sctpLookupRemPortTable", sctpLookupRemPortTable_handler, sctpLookupRemPortTable_oid, sctpLookupRemPortTable_oid_len, HANDLER_CAN_RONLY); if (NULL == reg) { snmp_log(LOG_ERR, "error creating handler registration for sctpLookupRemPortTable\n"); goto bail; } container = netsnmp_container_find("sctpLookupRemPortTable:table_container"); if (NULL == container) { snmp_log(LOG_ERR, "error creating container for sctpLookupRemPortTable\n"); goto bail; } sctpLookupRemPortTable_container = container; table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); if (NULL == table_info) { snmp_log(LOG_ERR, "error allocating table registration for sctpLookupRemPortTable\n"); goto bail; } netsnmp_table_helper_add_indexes(table_info, ASN_UNSIGNED, /* index: sctpAssocRemPort */ ASN_UNSIGNED, /* index: sctpAssocId */ 0); table_info->min_column = COLUMN_SCTPLOOKUPREMPORTSTARTTIME; table_info->max_column = COLUMN_SCTPLOOKUPREMPORTSTARTTIME; /************************************************* * * inject container_table helper */ handler = netsnmp_container_table_handler_get(table_info, container, TABLE_CONTAINER_KEY_NETSNMP_INDEX); if (NULL == handler) { snmp_log(LOG_ERR, "error allocating table registration for sctpLookupRemPortTable\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR, "error injecting container_table handler for sctpLookupRemPortTable\n"); goto bail; } handler = NULL; /* reg has it, will reuse below */ /* * register the table */ if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) { snmp_log(LOG_ERR, "error registering table handler for sctpLookupRemPortTable\n"); reg = NULL; /* it was freed inside netsnmp_register_table */ goto bail; } return; /* ok */ /* * Some error occurred during registration. Clean up and bail. */ bail: /* not ok */ if (handler) netsnmp_handler_free(handler); if (table_info) netsnmp_table_registration_info_free(table_info); if (container) CONTAINER_FREE(container); if (reg) netsnmp_handler_registration_free(reg); }
/** registers a row within a mib table */ int netsnmp_register_mib_table_row(const char *moduleName, struct variable *var, size_t varsize, size_t numvars, oid * mibloc, size_t mibloclen, int priority, int var_subid, netsnmp_session * ss, const char *context, int timeout, int flags) { unsigned int i = 0, rc = 0; oid ubound = 0; for (i = 0; i < numvars; i++) { struct variable *vr = (struct variable *) ((char *) var + (i * varsize)); netsnmp_handler_registration *r; if ( var_subid > (int)mibloclen ) { break; /* doesn't make sense */ } r = SNMP_MALLOC_TYPEDEF(netsnmp_handler_registration); if (r == NULL) { /* * Unregister whatever we have registered so far, and * return an error. */ rc = MIB_REGISTRATION_FAILED; break; } memset(r, 0, sizeof(netsnmp_handler_registration)); r->handler = get_old_api_handler(); r->handlerName = strdup(moduleName); if (r->handlerName == NULL) { netsnmp_handler_registration_free(r); break; } r->rootoid_len = mibloclen; r->rootoid = (oid *) malloc(r->rootoid_len * sizeof(oid)); if (r->rootoid == NULL) { netsnmp_handler_registration_free(r); rc = MIB_REGISTRATION_FAILED; break; } memcpy(r->rootoid, mibloc, mibloclen * sizeof(oid)); memcpy((u_char *) (r->rootoid + (var_subid - vr->namelen)), vr->name, vr->namelen * sizeof(oid)); DEBUGMSGTL(("netsnmp_register_mib_table_row", "rootoid ")); DEBUGMSGOID(("netsnmp_register_mib_table_row", r->rootoid, r->rootoid_len)); DEBUGMSG(("netsnmp_register_mib_table_row", "(%d)\n", (var_subid - vr->namelen))); r->handler->myvoid = netsnmp_duplicate_variable(vr); r->handler->data_clone = (void *(*)(void *))netsnmp_duplicate_variable; r->handler->data_free = free; if (r->handler->myvoid == NULL) { netsnmp_handler_registration_free(r); rc = MIB_REGISTRATION_FAILED; break; } r->contextName = (context) ? strdup(context) : NULL; if (context != NULL && r->contextName == NULL) { netsnmp_handler_registration_free(r); rc = MIB_REGISTRATION_FAILED; break; } r->priority = priority; r->range_subid = 0; /* var_subid; */ r->range_ubound = 0; /* range_ubound; */ r->timeout = timeout; r->modes = HANDLER_CAN_RWRITE; /* * Register this column and row */ if ((rc = netsnmp_register_handler_nocallback(r)) != MIB_REGISTERED_OK) { DEBUGMSGTL(("netsnmp_register_mib_table_row", "register failed %d\n", rc)); netsnmp_handler_registration_free(r); break; } if (vr->namelen > 0) { if (vr->name[vr->namelen - 1] > ubound) { ubound = vr->name[vr->namelen - 1]; } } } if (rc == MIB_REGISTERED_OK) { struct register_parameters reg_parms; reg_parms.name = mibloc; reg_parms.namelen = mibloclen; reg_parms.priority = priority; reg_parms.flags = (u_char) flags; reg_parms.range_subid = var_subid; reg_parms.range_ubound = ubound; reg_parms.timeout = timeout; reg_parms.contextName = context; rc = snmp_call_callbacks(SNMP_CALLBACK_APPLICATION, SNMPD_CALLBACK_REGISTER_OID, ®_parms); } return rc; }