/** * * @retval 0 no errors * @retval !0 errors */ int netsnmp_arch_defaultrouter_container_load(netsnmp_container *container, u_int load_flags) { int err; err = 0; idx_offset = 0; DEBUGMSGTL(("access:defaultrouter:entry:arch", "load\n")); if (NULL == container) { snmp_log(LOG_ERR, "netsnmp_arch_defaultrouter_container_load: container invalid\n"); return 1; } err = _load_defaultrouter_from_sysctl(container, AF_INET); if (err != 0) { u_int flags = NETSNMP_ACCESS_DEFAULTROUTER_FREE_KEEP_CONTAINER; netsnmp_access_defaultrouter_container_free(container, flags); goto out; } #ifdef NETSNMP_ENABLE_IPV6 err = _load_defaultrouter_from_sysctl(container, AF_INET6); if (err != 0) { u_int flags = NETSNMP_ACCESS_DEFAULTROUTER_FREE_KEEP_CONTAINER; netsnmp_access_defaultrouter_container_free(container, flags); goto out; } #endif out: return err; }
/** * @retval NULL error * @retval !NULL pointer to container */ netsnmp_container* netsnmp_access_defaultrouter_container_load(netsnmp_container* container, u_int load_flags) { int rc; u_int container_flags = 0; DEBUGMSGTL(("access:defaultrouter:container", "load\n")); if (NULL == container) { if (load_flags & NETSNMP_ACCESS_DEFAULTROUTER_LOAD_ADDL_IDX_BY_ADDR) { container_flags |= NETSNMP_ACCESS_DEFAULTROUTER_INIT_ADDL_IDX_BY_ADDR; } container = netsnmp_access_defaultrouter_container_init(container_flags); } if (NULL == container) { snmp_log(LOG_ERR, "no container specified/found for access_defaultrouter\n"); return NULL; } rc = netsnmp_arch_defaultrouter_container_load(container, load_flags); if (0 != rc) { netsnmp_access_defaultrouter_container_free(container, NETSNMP_ACCESS_DEFAULTROUTER_FREE_NOFLAGS); container = NULL; } return container; }
/** * load initial data * * TODO:350:M: Implement ipDefaultRouterTable data load * This function will also be called by the cache helper to load * the container again (after the container free function has been * called to free the previous contents). * * @param container container to which items should be inserted * * @retval MFD_SUCCESS : success. * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source * @retval MFD_ERROR : other error. * * This function is called to load the index(es) (and data, optionally) * for the every row in the data set. * * @remark * While loading the data, the only important thing is the indexes. * If access to your data is cheap/fast (e.g. you have a pointer to a * structure in memory), it would make sense to update the data here. * If, however, the accessing the data invovles more work (e.g. parsing * some other existing data, or peforming calculations to derive the data), * then you can limit yourself to setting the indexes and saving any * information you will need later. Then use the saved information in * ipDefaultRouterTable_row_prep() for populating data. * * @note * If you need consistency between rows (like you want statistics * for each row to be from the same time frame), you should set all * data here. * */ int ipDefaultRouterTable_container_load(netsnmp_container * container) { netsnmp_container *defaultrouter_container; void *tmp_ptr[2]; DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_container_load", "called\n")); /* * TODO:351:M: |-> Load/update data in the ipDefaultRouterTable container. * loop over your ipDefaultRouterTable data, allocate a rowreq context, * set the index(es) [and data, optionally] and insert into * the container. */ defaultrouter_container = netsnmp_access_defaultrouter_container_load(NULL, NETSNMP_ACCESS_DEFAULTROUTER_LOAD_ADDL_IDX_BY_ADDR); if (NULL == defaultrouter_container) return MFD_RESOURCE_UNAVAILABLE; /* msg already logged */ /* * we just got a fresh copy of interface data. compare it to * what we've already got, and make any adjustments, saving * missing addresses to be deleted. */ tmp_ptr[0] = defaultrouter_container->next; tmp_ptr[1] = NULL; CONTAINER_FOR_EACH(container, (netsnmp_container_obj_func *) _check_entry_for_updates, tmp_ptr); /* * now add any new interfaces */ CONTAINER_FOR_EACH(defaultrouter_container, (netsnmp_container_obj_func *) _add_new_entry, container); /* * free the container. we've either claimed each entry, or released it, * so the access function doesn't need to clear the container. */ netsnmp_access_defaultrouter_container_free(defaultrouter_container, NETSNMP_ACCESS_DEFAULTROUTER_FREE_DONT_CLEAR); /* * remove deleted addresses from table container */ if (NULL != tmp_ptr[1]) { netsnmp_container *tmp_container = (netsnmp_container *) tmp_ptr[1]; ipDefaultRouterTable_rowreq_ctx *tmp_ctx; /* * this works because the tmp_container is a linked list, * which can be used like a stack... */ while (CONTAINER_SIZE(tmp_container)) { /* * get from delete list */ tmp_ctx = (ipDefaultRouterTable_rowreq_ctx *) CONTAINER_FIRST(tmp_container); /* * release context, delete from table container */ CONTAINER_REMOVE(container, tmp_ctx); ipDefaultRouterTable_release_rowreq_ctx(tmp_ctx); /* * pop off delete list */ CONTAINER_REMOVE(tmp_container, NULL); } } DEBUGMSGT(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_container_load", "%" NETSNMP_PRIz "d records\n", CONTAINER_SIZE(container))); return MFD_SUCCESS; }