From c1b7328c39698ce792f7b5082de9dc079da8b848 Mon Sep 17 00:00:00 2001 From: Mitsuru Chinen Date: Mon, 20 Oct 2008 17:22:10 +0900 Subject: [PATCH] Add Default Router Table support From net-snmp patch tracker: [ 1708243 ] add linux support for ipDefaultRouterTable OID to net-snmp http://sourceforge.net/tracker/index.php?func=detail&aid=1708243&group_id=12694&atid=312694 [ 1724602 ] [Linux] ipDefaultRouterTable improvement http://sourceforge.net/tracker/index.php?func=detail&aid=1724602&group_id=12694&atid=312694 [ 1728223 ] [Linux] add configure check for netlink socket http://sourceforge.net/tracker/index.php?func=detail&aid=1728223&group_id=12694&atid=312694 Signed-off-by: Mitsuru Chinen --- agent/mibgroup/ip-mib/data_access/defaultrouter.h | 29 + .../ip-mib/data_access/defaultrouter_common.c | 291 ++++++ .../ip-mib/data_access/defaultrouter_linux.c | 322 ++++++ .../mibgroup/ip-mib/data_access/ipaddress_linux.c | 10 +- agent/mibgroup/ip-mib/ipDefaultRouterTable.h | 5 + .../ipDefaultRouterTable/ipDefaultRouterTable.c | 213 ++++ .../ipDefaultRouterTable/ipDefaultRouterTable.h | 212 ++++ .../ipDefaultRouterTable_data_access.c | 420 ++++++++ .../ipDefaultRouterTable_data_access.h | 76 ++ .../ipDefaultRouterTable_data_get.c | 325 +++++++ .../ipDefaultRouterTable_data_get.h | 84 ++ .../ipDefaultRouterTable_enums.h | 93 ++ .../ipDefaultRouterTable_interface.c | 1018 ++++++++++++++++++++ .../ipDefaultRouterTable_interface.h | 99 ++ .../ipDefaultRouterTable_oids.h | 39 + agent/mibgroup/mibII/var_route.c | 1 + configure.in | 23 + include/net-snmp/data_access/defaultrouter.h | 114 +++ 18 files changed, 3373 insertions(+), 1 deletions(-) create mode 100644 agent/mibgroup/ip-mib/data_access/defaultrouter.h create mode 100644 agent/mibgroup/ip-mib/data_access/defaultrouter_common.c create mode 100644 agent/mibgroup/ip-mib/data_access/defaultrouter_linux.c create mode 100644 agent/mibgroup/ip-mib/ipDefaultRouterTable.h create mode 100644 agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable.c create mode 100644 agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable.h create mode 100644 agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_data_access.c create mode 100644 agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_data_access.h create mode 100644 agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_data_get.c create mode 100644 agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_data_get.h create mode 100644 agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_enums.h create mode 100644 agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_interface.c create mode 100644 agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_interface.h create mode 100644 agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_oids.h create mode 100644 include/net-snmp/data_access/defaultrouter.h diff --git a/agent/mibgroup/ip-mib/data_access/defaultrouter.h b/agent/mibgroup/ip-mib/data_access/defaultrouter.h new file mode 100644 index 0000000..9e7b1ef --- /dev/null +++ b/agent/mibgroup/ip-mib/data_access/defaultrouter.h @@ -0,0 +1,29 @@ +/* + * defaultrouter data access header + * + * $Id: $ + */ +/**---------------------------------------------------------------------*/ +/* + * configure required files + * + * Notes: + * + * 1) prefer functionality over platform, where possible. If a method + * is available for multiple platforms, test that first. That way + * when a new platform is ported, it won't need a new test here. + * + * 2) don't do detail requirements here. If, for example, + * HPUX11 had different reuirements than other HPUX, that should + * be handled in the *_hpux.h header file. + */ +config_require(ip-mib/data_access/defaultrouter_common) +#if defined( linux ) +config_require(ip-mib/data_access/defaultrouter_linux) +#else +/* + * couldn't determine the correct file! + * require a bogus file to generate an error. + */ +config_require(ip-mib/data_access/defaultrouter-unknown-arch); +#endif diff --git a/agent/mibgroup/ip-mib/data_access/defaultrouter_common.c b/agent/mibgroup/ip-mib/data_access/defaultrouter_common.c new file mode 100644 index 0000000..64ca425 --- /dev/null +++ b/agent/mibgroup/ip-mib/data_access/defaultrouter_common.c @@ -0,0 +1,291 @@ +/* + * defaultrouter MIB architecture support + * + * $Id:$ + */ +#include +#include + +#include +#include + +#include "ip-mib/ipDefaultRouterTable/ipDefaultRouterTable.h" + +/**---------------------------------------------------------------------*/ +/* + * local static prototypes + */ +static int _access_defaultrouter_entry_compare_addr(const void *lhs, + const void *rhs); +static void _access_defaultrouter_entry_release(netsnmp_defaultrouter_entry * entry, + void *unused); + +/**---------------------------------------------------------------------*/ +/* + * external per-architecture functions prototypes + * + * These shouldn't be called by the general public, so they aren't in + * the header file. + */ +extern int +netsnmp_arch_defaultrouter_entry_init(netsnmp_defaultrouter_entry *entry); + +extern int +netsnmp_arch_defaultrouter_container_load(netsnmp_container* container, + u_int load_flags); + +/**---------------------------------------------------------------------*/ +/* + * container functions + */ +/** + */ +netsnmp_container * +netsnmp_access_defaultrouter_container_init(u_int flags) +{ + netsnmp_container *container1; + + DEBUGMSGTL(("access:defaultrouter:container", "init\n")); + + /* + * create the containers. one indexed by ifIndex, the other + * indexed by ifName. + */ + container1 = netsnmp_container_find("access_defaultrouter:table_container"); + if (NULL == container1) { + snmp_log(LOG_ERR, "defaultrouter primary container is not found\n"); + return NULL; + } + container1->container_name = strdup("dr_index"); + + if (flags & NETSNMP_ACCESS_DEFAULTROUTER_INIT_ADDL_IDX_BY_ADDR) { + netsnmp_container *container2 = + netsnmp_container_find("defaultrouter_addr:access_defaultrouter:table_container"); + if (NULL == container2) { + snmp_log(LOG_ERR, "defaultrouter secondary container not found\n"); + CONTAINER_FREE(container1); + return NULL; + } + + container2->compare = _access_defaultrouter_entry_compare_addr; + container2->container_name = strdup("dr_addr"); + + netsnmp_container_add_index(container1, container2); + } + + return container1; +} + +/** + * @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; +} + +void +netsnmp_access_defaultrouter_container_free(netsnmp_container *container, + u_int free_flags) +{ + DEBUGMSGTL(("access:defaultrouter:container", "free\n")); + + if (NULL == container) { + snmp_log(LOG_ERR, + "invalid container for netsnmp_access_defaultrouter_free\n"); + return; + } + + if(! (free_flags & NETSNMP_ACCESS_DEFAULTROUTER_FREE_DONT_CLEAR)) { + /* + * free all items. + */ + CONTAINER_CLEAR(container, + (netsnmp_container_obj_func*)_access_defaultrouter_entry_release, + NULL); + } + + if(! (free_flags & NETSNMP_ACCESS_DEFAULTROUTER_FREE_KEEP_CONTAINER)) + CONTAINER_FREE(container); +} + +/**---------------------------------------------------------------------*/ +/* + * defaultrouter_entry functions + */ +/** + */ +/** + */ +netsnmp_defaultrouter_entry * +netsnmp_access_defaultrouter_entry_create(void) +{ + int rc = 0; + netsnmp_defaultrouter_entry *entry = + SNMP_MALLOC_TYPEDEF(netsnmp_defaultrouter_entry); + + DEBUGMSGTL(("access:defaultrouter:entry", "create\n")); + + if(NULL == entry) + return NULL; + + entry->oid_index.len = 1; + entry->oid_index.oids = &entry->ns_dr_index; + + /* + * set up defaults + */ + entry->dr_lifetime = IPDEFAULTROUTERLIFETIME_MAX; + entry->dr_preference = IPDEFAULTROUTERPREFERENCE_MEDIUM; + + rc = netsnmp_arch_defaultrouter_entry_init(entry); + if (SNMP_ERR_NOERROR != rc) { + DEBUGMSGT(("access:defaultrouter:create","error %d in arch init\n")); + netsnmp_access_defaultrouter_entry_free(entry); + entry = NULL; + } + + return entry; +} + +void +netsnmp_access_defaultrouter_entry_free(netsnmp_defaultrouter_entry * entry) +{ + if (NULL == entry) + return; + + free(entry); +} + +/** + * update an old defaultrouter_entry from a new one + * + * @note: only mib related items are compared. Internal objects + * such as oid_index, ns_dr_index and flags are not compared. + * + * @retval -1 : error + * @retval >=0 : number of fields updated + */ +int +netsnmp_access_defaultrouter_entry_update(netsnmp_defaultrouter_entry *lhs, + netsnmp_defaultrouter_entry *rhs) +{ + int changed = 0; + + if (lhs->dr_addresstype != rhs->dr_addresstype) { + ++changed; + lhs->dr_addresstype = rhs->dr_addresstype; + } + + if (lhs->dr_address_len != rhs->dr_address_len) { + changed += 2; + lhs->dr_address_len = rhs->dr_address_len; + memcpy(lhs->dr_address, rhs->dr_address, rhs->dr_address_len); + } + else if (memcmp(lhs->dr_address, rhs->dr_address, rhs->dr_address_len) != 0) { + ++changed; + memcpy(lhs->dr_address, rhs->dr_address, rhs->dr_address_len); + } + + if (lhs->dr_if_index != rhs->dr_if_index) { + ++changed; + lhs->dr_if_index = rhs->dr_if_index; + } + + if (lhs->dr_lifetime != rhs->dr_lifetime) { + ++changed; + lhs->dr_lifetime = rhs->dr_lifetime; + } + + if (lhs->dr_preference != rhs->dr_preference) { + ++changed; + lhs->dr_preference = rhs->dr_preference; + } + + return changed; +} + +/** + * copy an defaultrouter_entry + * + * @retval -1 : error + * @retval 0 : no error + */ +int +netsnmp_access_defaultrouter_entry_copy(netsnmp_defaultrouter_entry *lhs, + netsnmp_defaultrouter_entry *rhs) +{ + lhs->dr_addresstype = rhs->dr_addresstype; + lhs->dr_address_len = rhs->dr_address_len; + memcpy(lhs->dr_address, rhs->dr_address, rhs->dr_address_len); + lhs->dr_if_index = rhs->dr_if_index; + lhs->dr_lifetime = rhs->dr_lifetime; + lhs->dr_preference = rhs->dr_preference; + + return 0; +} + +/**---------------------------------------------------------------------*/ +/* + * Utility routines + */ + +/** + */ +void +_access_defaultrouter_entry_release(netsnmp_defaultrouter_entry * entry, void *context) +{ + netsnmp_access_defaultrouter_entry_free(entry); +} + +static int _access_defaultrouter_entry_compare_addr(const void *lhs, + const void *rhs) +{ + const netsnmp_defaultrouter_entry *lh = (const netsnmp_defaultrouter_entry *)lhs; + const netsnmp_defaultrouter_entry *rh = (const netsnmp_defaultrouter_entry *)rhs; + + netsnmp_assert(NULL != lhs); + netsnmp_assert(NULL != rhs); + + /* + * compare address length + */ + if (lh->dr_address_len < rh->dr_address_len) + return -1; + else if (lh->dr_address_len > rh->dr_address_len) + return 1; + + /* + * length equal, compare address + */ + return memcmp(lh->dr_address, rh->dr_address, lh->dr_address_len); +} diff --git a/agent/mibgroup/ip-mib/data_access/defaultrouter_linux.c b/agent/mibgroup/ip-mib/data_access/defaultrouter_linux.c new file mode 100644 index 0000000..156e137 --- /dev/null +++ b/agent/mibgroup/ip-mib/data_access/defaultrouter_linux.c @@ -0,0 +1,322 @@ +/* + * Interface MIB architecture support + * + * $Id:$ + */ +#include +#include + +#include +#include + +#include "ip-mib/ipDefaultRouterTable/ipDefaultRouterTable.h" + +#include +#ifdef HAVE_LINUX_RTNETLINK_H +#include +#include +#endif +#include +#include +#include +#include + +#define RCVBUF_SIZE 32768 +#define SNDBUF_SIZE 512 + +#ifdef NETSNMP_ENABLE_IPV6 +#define DR_ADDRSTRLEN INET6_ADDRSTRLEN +#else +#define DR_ADDRSTRLEN INET_ADDRSTRLEN +#endif + +/**---------------------------------------------------------------------*/ +/* + * local static prototypes + */ +static int _load(netsnmp_container *container); + + +/* + * initialize arch specific storage + * + * @retval 0: success + * @retval <0: error + */ +int +netsnmp_arch_defaultrouter_entry_init(netsnmp_defaultrouter_entry *entry) +{ + /* + * init + */ + return 0; +} + +/** + * + * @retval 0 no errors + * @retval !0 errors + */ +int +netsnmp_arch_defaultrouter_container_load(netsnmp_container *container, + u_int load_flags) +{ + int rc = 0; + + DEBUGMSGTL(("access:defaultrouter:entry:arch", "load (linux)\n")); + + rc = _load(container); + if (rc < 0) { + u_int flags = NETSNMP_ACCESS_DEFAULTROUTER_FREE_KEEP_CONTAINER; + netsnmp_access_defaultrouter_container_free(container, flags); + } + + return rc; +} + +/** + * + * @retval 0 no errors + * @retval !0 errors + */ +static int +_load(netsnmp_container *container) +{ +#ifndef HAVE_LINUX_RTNETLINK_H + DEBUGMSGTL(("access:defaultrouter", + "cannot get default router information" + "as netlink socket is not available\n")); + return -1; +#else + int rc = 0; + int idx_offset = 0; + netsnmp_defaultrouter_entry *entry; + int nlsk; + struct sockaddr_nl addr; + unsigned char rcvbuf[RCVBUF_SIZE]; + int rcvbuf_size = RCVBUF_SIZE; + unsigned char sndbuf[SNDBUF_SIZE]; + struct nlmsghdr *hdr; + struct rtmsg *rthdr; + int count; + int end_of_message = 0; + long hz = sysconf(_SC_CLK_TCK); + + netsnmp_assert(NULL != container); + + /* + * Open a netlink socket + */ + nlsk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); + if (nlsk < 0) { + snmp_log(LOG_ERR, "Could not open netlink socket : %s\n", + strerror(errno)); + return -1; + } + + if (setsockopt(nlsk, SOL_SOCKET, SO_RCVBUF, + &rcvbuf_size, sizeof(rcvbuf_size)) < 0) { + snmp_log(LOG_ERR, "Could not open netlink socket : %s\n", + strerror(errno)); + close(nlsk); + return -1; + } + + memset(&addr, '\0', sizeof(struct sockaddr_nl)); + addr.nl_family = AF_NETLINK; + + memset(sndbuf, '\0', SNDBUF_SIZE); + hdr = (struct nlmsghdr *)sndbuf; + hdr->nlmsg_type = RTM_GETROUTE; + hdr->nlmsg_pid = getpid(); + hdr->nlmsg_seq = 0; + hdr->nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST; + hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); + rthdr = (struct rtmsg *)NLMSG_DATA(hdr); + rthdr->rtm_table = RT_TABLE_MAIN; + + /* + * Send a request to the kernel to dump the routing table to us + */ + count = sendto(nlsk, sndbuf, hdr->nlmsg_len, 0, + (struct sockaddr *)&addr, sizeof(struct sockaddr_nl)); + if (count < 0) { + snmp_log(LOG_ERR, "unable to send netlink message to kernel : %s\n", + strerror(errno)); + close(nlsk); + return -2; + } + + /* + * Now listen for response + */ + do { + struct nlmsghdr *nlmhp; + struct rtmsg *rtmp; + struct rtattr *rtap; + struct rta_cacheinfo *rtci; + socklen_t sock_len; + int rtcount; + + memset(rcvbuf, '\0', RCVBUF_SIZE); + sock_len = sizeof(struct sockaddr_nl); + + /* + * Get the message + */ + count = recvfrom(nlsk, rcvbuf, RCVBUF_SIZE, 0, + (struct sockaddr *)&addr, &sock_len); + if (count < 0) { + snmp_log(LOG_ERR, "unable to receive netlink messages: %s\n", + strerror(errno)); + rc = -1; + break; + } + + /* + * Walk all of the returned messages + */ + nlmhp = (struct nlmsghdr *)rcvbuf; + while (NLMSG_OK(nlmhp, count)) { + u_char addresstype; + char address[NETSNMP_ACCESS_DEFAULTROUTER_BUF_SIZE + 1]; + size_t address_len = 0; + int if_index = -1; + u_long lifetime = 0; + int preference = -3; + + /* + * Make sure the message is ok + */ + if (nlmhp->nlmsg_type == NLMSG_ERROR) { + snmp_log(LOG_ERR, "kernel produced nlmsg err\n"); + rc = -1; + break; + } + + /* + * End of message, we're done + */ + if (nlmhp->nlmsg_type & NLMSG_DONE) { + end_of_message = 1; + break; + } + + /* + * Get the pointer to the rtmsg struct + */ + rtmp = NLMSG_DATA(nlmhp); + + /* + * zero length destination is a default route + */ + if (rtmp->rtm_dst_len != 0) + goto next_nlmsghdr; + + /* + * Start scanning the attributes for needed info + */ + if (rtmp->rtm_family == AF_INET) { + addresstype = INETADDRESSTYPE_IPV4; + lifetime = IPDEFAULTROUTERLIFETIME_MAX; /* infinity */ + } +#ifdef NETSNMP_ENABLE_IPV6 + else if (rtmp->rtm_family == AF_INET6) { + addresstype = INETADDRESSTYPE_IPV6; + /* router lifetime for IPv6 is retrieved by RTA_CACHEINFO */ + lifetime = 0; + } +#endif + else + goto next_nlmsghdr; /* skip, we don't care about this route */ + + preference = 0; /* preference is medium(0) for now */ + + rtap = RTM_RTA(rtmp); + rtcount = RTM_PAYLOAD(nlmhp); + while (RTA_OK(rtap, rtcount)) { + switch (rtap->rta_type) { + case RTA_OIF: + if_index = *(int *)(RTA_DATA(rtap)); + break; + + case RTA_GATEWAY: + address_len = RTA_PAYLOAD(rtap); + memset(address, '\0', sizeof(address)); + memcpy(address, RTA_DATA(rtap), address_len); + break; + +#ifdef NETSNMP_ENABLE_IPV6 + case RTA_CACHEINFO: + rtci = RTA_DATA(rtap); + if ((rtmp->rtm_flags & RTM_F_CLONED) || + (rtci && rtci->rta_expires)) { + lifetime = rtci->rta_expires / hz; + } + break; +#endif + + default: + break; + } /* switch */ + + rtap = RTA_NEXT(rtap, rtcount); + } /* while RTA_OK(rtap) */ + + + if (address_len != 0 && if_index != -1 && + lifetime != 0 && preference != -3 ) { + DEBUGIF("access:defaultrouter") { + char addr_str[DR_ADDRSTRLEN]; + memset(addr_str, '\0', DR_ADDRSTRLEN); + + if (rtmp->rtm_family == AF_INET) + inet_ntop(AF_INET, address, addr_str, DR_ADDRSTRLEN); +#ifdef NETSNMP_ENABLE_IPV6 + else + inet_ntop(AF_INET6, address, addr_str, DR_ADDRSTRLEN); +#endif + DEBUGMSGTL(("access:defaultrouter", + "found default route: %s if_index %d " + "lifetime %lu preference %d\n", + addr_str, if_index, lifetime, preference)); + } + + entry = netsnmp_access_defaultrouter_entry_create(); + if (NULL == entry) { + rc = -3; + break; + } + + entry->ns_dr_index = ++idx_offset; + entry->dr_addresstype = addresstype; + entry->dr_address_len = address_len; + memcpy(entry->dr_address, address, + NETSNMP_ACCESS_DEFAULTROUTER_BUF_SIZE); + entry->dr_if_index = if_index; + entry->dr_lifetime = lifetime; + entry->dr_preference = preference; + + if (CONTAINER_INSERT(container, entry) < 0) + { + DEBUGMSGTL(("access:arp:container", + "error with defaultrouter_entry: " + "insert into container failed.\n")); + netsnmp_access_defaultrouter_entry_free(entry); + continue; + } + } + +next_nlmsghdr: + nlmhp = NLMSG_NEXT(nlmhp, count); + } /* while NLMSG_OK(nlmhp) */ + + if (rc < 0) + break; + + } while (!end_of_message); + + close(nlsk); + return rc; +#endif /* HAVE_LINUX_RTNETLINK_H */ +} diff --git a/agent/mibgroup/ip-mib/data_access/ipaddress_linux.c b/agent/mibgroup/ip-mib/data_access/ipaddress_linux.c index ac37578..4616649 100644 --- a/agent/mibgroup/ip-mib/data_access/ipaddress_linux.c +++ b/agent/mibgroup/ip-mib/data_access/ipaddress_linux.c @@ -19,9 +19,11 @@ #if defined (NETSNMP_ENABLE_IPV6) #include #include +#ifdef HAVE_LINUX_RTNETLINK_H #include #include #endif +#endif #include "ipaddress_ioctl.h" @@ -180,6 +182,12 @@ netsnmp_arch_ipaddress_container_load(netsnmp_container *container, int _load_v6(netsnmp_container *container, int idx_offset) { +#ifndef HAVE_LINUX_RTNETLINK_H + DEBUGMSGTL(("access:ipaddress:container", + "cannot get ip address information" + "as netlink socket is not available\n")); + return -1; +#else FILE *in; char line[80], addr[40]; char if_name[IFNAMSIZ+1];/* +1 for '\0' because of the ugly sscanf below */ @@ -438,6 +446,6 @@ netsnmp_access_other_info_get(int index, int family) } close(sd); return addr; +#endif } #endif - diff --git a/agent/mibgroup/ip-mib/ipDefaultRouterTable.h b/agent/mibgroup/ip-mib/ipDefaultRouterTable.h new file mode 100644 index 0000000..28ed84b --- /dev/null +++ b/agent/mibgroup/ip-mib/ipDefaultRouterTable.h @@ -0,0 +1,5 @@ +/* + * module to include the modules + */ + +config_require(ip-mib/ipDefaultRouterTable/ipDefaultRouterTable) diff --git a/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable.c b/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable.c new file mode 100644 index 0000000..8ce841d --- /dev/null +++ b/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable.c @@ -0,0 +1,213 @@ +/* + * Note: this file originally auto-generated by mib2c using + * version : 14170 $ of $ + * + * $Id:$ + */ +/** \page MFD helper for ipDefaultRouterTable + * + * \section intro Introduction + * Introductory text. + * + */ +/* + * standard Net-SNMP includes + */ +#include +#include +#include + +/* + * include our parent header + */ +#include "ipDefaultRouterTable.h" + +#include + +#include "ipDefaultRouterTable_interface.h" + +oid ipDefaultRouterTable_oid[] = { IPDEFAULTROUTERTABLE_OID }; +int ipDefaultRouterTable_oid_size = +OID_LENGTH(ipDefaultRouterTable_oid); + +ipDefaultRouterTable_registration ipDefaultRouterTable_user_context; + +void initialize_table_ipDefaultRouterTable(void); +void shutdown_table_ipDefaultRouterTable(void); + + +/** + * Initializes the ipDefaultRouterTable module + */ +void +init_ipDefaultRouterTable(void) +{ + DEBUGMSGTL(("verbose:ipDefaultRouterTable:init_ipDefaultRouterTable", + "called\n")); + + /* + * TODO:300:o: Perform ipDefaultRouterTable one-time module initialization. + */ + + /* + * here we initialize all the tables we're planning on supporting + */ + if (should_init("ipDefaultRouterTable")) + initialize_table_ipDefaultRouterTable(); + +} /* init_ipDefaultRouterTable */ + +/** + * Shut-down the ipDefaultRouterTable module (agent is exiting) + */ +void +shutdown_ipDefaultRouterTable(void) +{ + if (should_init("ipDefaultRouterTable")) + shutdown_table_ipDefaultRouterTable(); + +} + +/** + * Initialize the table ipDefaultRouterTable + * (Define its contents and how it's structured) + */ +void +initialize_table_ipDefaultRouterTable(void) +{ + ipDefaultRouterTable_registration *user_context; + u_long flags; + + DEBUGMSGTL(("verbose:ipDefaultRouterTable:initialize_table_ipDefaultRouterTable", "called\n")); + + /* + * TODO:301:o: Perform ipDefaultRouterTable one-time table initialization. + */ + + /* + * TODO:302:o: |->Initialize ipDefaultRouterTable 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("ipDefaultRouterTable", NULL, NULL); + + /* + * No support for any flags yet, but in the future you would + * set any flags here. + */ + flags = 0; + + /* + * call interface initialization code + */ + _ipDefaultRouterTable_initialize_interface(user_context, flags); +} /* initialize_table_ipDefaultRouterTable */ + +/** + * Shutdown the table ipDefaultRouterTable + */ +void +shutdown_table_ipDefaultRouterTable(void) +{ + /* + * call interface shutdown code + */ + _ipDefaultRouterTable_shutdown_interface + (&ipDefaultRouterTable_user_context); +} + +/** + * 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) + */ +int +ipDefaultRouterTable_rowreq_ctx_init(ipDefaultRouterTable_rowreq_ctx * + rowreq_ctx, void *user_init_ctx) +{ + DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_rowreq_ctx_init", "called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + /* + * TODO:210:o: |-> Perform extra ipDefaultRouterTable rowreq initialization. (eg DEFVALS) + */ + + return MFD_SUCCESS; +} /* ipDefaultRouterTable_rowreq_ctx_init */ + +/** + * extra context cleanup + * + */ +void +ipDefaultRouterTable_rowreq_ctx_cleanup(ipDefaultRouterTable_rowreq_ctx * + rowreq_ctx) +{ + DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_rowreq_ctx_cleanup", "called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + /* + * TODO:211:o: |-> Perform extra ipDefaultRouterTable rowreq cleanup. + */ +} /* ipDefaultRouterTable_rowreq_ctx_cleanup */ + +/** + * pre-request callback + * + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error + */ +int +ipDefaultRouterTable_pre_request(ipDefaultRouterTable_registration * + user_context) +{ + DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_pre_request", "called\n")); + + /* + * TODO:510:o: Perform ipDefaultRouterTable pre-request actions. + */ + + return MFD_SUCCESS; +} /* ipDefaultRouterTable_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) + */ +int +ipDefaultRouterTable_post_request(ipDefaultRouterTable_registration * + user_context, int rc) +{ + DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_post_request", "called\n")); + + /* + * TODO:511:o: Perform ipDefaultRouterTable post-request actions. + */ + + return MFD_SUCCESS; +} /* ipDefaultRouterTable_post_request */ + + +/** @{ */ diff --git a/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable.h b/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable.h new file mode 100644 index 0000000..1bca12e --- /dev/null +++ b/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable.h @@ -0,0 +1,212 @@ +/* + * Note: this file originally auto-generated by mib2c using + * version : 14170 $ of $ + * + * $Id:$ + */ +#ifndef IPDEFAULTROUTERTABLE_H +#define IPDEFAULTROUTERTABLE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/** @addtogroup misc misc: Miscellaneous routines + * + * @{ + */ +#include +#include + + /* + * other required module components + */ + /* *INDENT-OFF* */ +config_require(ip-mib/data_access/defaultrouter) +config_require(ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_interface) +config_require(ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_data_access) +config_require(ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_data_get) + /* *INDENT-ON* */ + + /* + * OID and column number definitions for ipDefaultRouterTable + */ +#include "ipDefaultRouterTable_oids.h" + + /* + * enum definions + */ +#include "ipDefaultRouterTable_enums.h" + + /* + ********************************************************************* + * function declarations + */ + void init_ipDefaultRouterTable(void); + void shutdown_ipDefaultRouterTable(void); + + /* + ********************************************************************* + * Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table ipDefaultRouterTable + *** + ********************************************************************** + **********************************************************************/ + /* + * IP-MIB::ipDefaultRouterTable is subid 37 of ip. + * Its status is Current. + * OID: .1.3.6.1.2.1.4.37, length: 8 + */ + /* + ********************************************************************* + * When you register your mib, you get to provide a generic + * pointer that will be passed back to you for most of the + * functions calls. + * + * TODO:100:r: Review all context structures + */ + /* + * TODO:101:o: |-> Review ipDefaultRouterTable registration context. + */ + typedef netsnmp_data_list ipDefaultRouterTable_registration; + +/**********************************************************************/ + /* + * TODO:110:r: |-> Review ipDefaultRouterTable data context structure. + * This structure is used to represent the data for ipDefaultRouterTable. + */ + typedef netsnmp_defaultrouter_entry ipDefaultRouterTable_data; + + + /* + * TODO:120:r: |-> Review ipDefaultRouterTable mib index. + * This structure is used to represent the index for ipDefaultRouterTable. + */ + typedef struct ipDefaultRouterTable_mib_index_s { + + /* + * ipDefaultRouterAddressType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h + */ + u_long ipDefaultRouterAddressType; + + /* + * ipDefaultRouterAddress(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h + */ + /** 128 - 2(other indexes) - oid length(10) = 115 */ + char ipDefaultRouterAddress[115]; + size_t ipDefaultRouterAddress_len; + + /* + * ipDefaultRouterIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/a/w/e/R/d/H + */ + long ipDefaultRouterIfIndex; + + + } ipDefaultRouterTable_mib_index; + + /* + * TODO:121:r: | |-> Review ipDefaultRouterTable max index length. + * If you KNOW that your indexes will never exceed a certain + * length, update this macro to that length. + * + * BE VERY CAREFUL TO TAKE INTO ACCOUNT THE MAXIMUM + * POSSIBLE LENGHT FOR EVERY VARIABLE LENGTH INDEX! + * Guessing 128 - col/entry(2) - oid len(8) + */ +#define MAX_ipDefaultRouterTable_IDX_LEN 118 + + + /* + ********************************************************************* + * TODO:130:o: |-> Review ipDefaultRouterTable Row request (rowreq) context. + * When your functions are called, you will be passed a + * ipDefaultRouterTable_rowreq_ctx pointer. + */ + typedef struct ipDefaultRouterTable_rowreq_ctx_s { + + /** this must be first for container compare to work */ + netsnmp_index oid_idx; + oid oid_tmp[MAX_ipDefaultRouterTable_IDX_LEN]; + + ipDefaultRouterTable_mib_index tbl_idx; + + ipDefaultRouterTable_data *data; + + /* + * flags per row. Currently, the first (lower) 8 bits are reserved + * for the user. See mfd.h for other flags. + */ + u_int rowreq_flags; + + /* + * TODO:131:o: | |-> Add useful data to ipDefaultRouterTable rowreq context. + */ + + /* + * storage for future expansion + */ + netsnmp_data_list *ipDefaultRouterTable_data_list; + + } ipDefaultRouterTable_rowreq_ctx; + + typedef struct ipDefaultRouterTable_ref_rowreq_ctx_s { + ipDefaultRouterTable_rowreq_ctx *rowreq_ctx; + } ipDefaultRouterTable_ref_rowreq_ctx; + + /* + ********************************************************************* + * function prototypes + */ + int + ipDefaultRouterTable_pre_request(ipDefaultRouterTable_registration + * user_context); + int + ipDefaultRouterTable_post_request(ipDefaultRouterTable_registration + * user_context, int rc); + + int + ipDefaultRouterTable_rowreq_ctx_init + (ipDefaultRouterTable_rowreq_ctx * rowreq_ctx, + void *user_init_ctx); + void + ipDefaultRouterTable_rowreq_ctx_cleanup + (ipDefaultRouterTable_rowreq_ctx * rowreq_ctx); + + ipDefaultRouterTable_data *ipDefaultRouterTable_allocate_data(void); + void + ipDefaultRouterTable_release_data(ipDefaultRouterTable_data * + data); + + + ipDefaultRouterTable_rowreq_ctx + *ipDefaultRouterTable_row_find_by_mib_index + (ipDefaultRouterTable_mib_index * mib_idx); + + extern oid ipDefaultRouterTable_oid[]; + extern int ipDefaultRouterTable_oid_size; + + +#include "ipDefaultRouterTable_interface.h" +#include "ipDefaultRouterTable_data_access.h" +#include "ipDefaultRouterTable_data_get.h" + + /* + * DUMMY markers, ignore + * + * TODO:099:x: ************************************************************* + * TODO:199:x: ************************************************************* + * TODO:299:x: ************************************************************* + * TODO:399:x: ************************************************************* + * TODO:499:x: ************************************************************* + */ + +#ifdef __cplusplus +} +#endif +#endif /* IPDEFAULTROUTERTABLE_H */ +/** @} */ diff --git a/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_data_access.c b/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_data_access.c new file mode 100644 index 0000000..70e1b23 --- /dev/null +++ b/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_data_access.c @@ -0,0 +1,420 @@ +/* + * Note: this file originally auto-generated by mib2c using + * version : 14170 $ of $ + * + * $Id:$ + */ +/* + * standard Net-SNMP includes + */ +#include +#include +#include + +/* + * include our parent header + */ +#include "ipDefaultRouterTable.h" + + +#include "ipDefaultRouterTable_data_access.h" + +/** @ingroup interface + * @addtogroup data_access data_access: Routines to access data + * + * These routines are used to locate the data used to satisfy + * requests. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table ipDefaultRouterTable + *** + ********************************************************************** + **********************************************************************/ +/* + * IP-MIB::ipDefaultRouterTable is subid 37 of ip. + * Its status is Current. + * OID: .1.3.6.1.2.1.4.37, length: 8 + */ + +/** + * initialization for ipDefaultRouterTable data access + * + * This function is called during startup to allow you to + * allocate any resources you need for the data table. + * + * @param ipDefaultRouterTable_reg + * Pointer to ipDefaultRouterTable_registration + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : unrecoverable error. + */ +int +ipDefaultRouterTable_init_data(ipDefaultRouterTable_registration * + ipDefaultRouterTable_reg) +{ + DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_init_data", "called\n")); + + /* + * TODO:303:o: Initialize ipDefaultRouterTable data. + */ + + return MFD_SUCCESS; +} /* ipDefaultRouterTable_init_data */ + +/** + * container overview + * + */ + +/** + * container initialization + * + * @param container_ptr_ptr A pointer to a container pointer. If you + * create a custom container, use this parameter to return it + * to the MFD helper. If set to NULL, the MFD helper will + * allocate a container for you. + * @param cache A pointer to a cache structure. You can set the timeout + * and other cache flags using this pointer. + * + * This function is called at startup to allow you to customize certain + * aspects of the access method. For the most part, it is for advanced + * users. The default code should suffice for most cases. If no custom + * container is allocated, the MFD code will create one for your. + * + * This is also the place to set up cache behavior. The default, to + * simply set the cache timeout, will work well with the default + * container. If you are using a custom container, you may want to + * look at the cache helper documentation to see if there are any + * flags you want to set. + * + * @remark + * This would also be a good place to do any initialization needed + * for you data source. For example, opening a connection to another + * process that will supply the data, opening a database, etc. + */ +void +ipDefaultRouterTable_container_init(netsnmp_container ** container_ptr_ptr, + netsnmp_cache * cache) +{ + DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_container_init", "called\n")); + + if (NULL == container_ptr_ptr) { + snmp_log(LOG_ERR, + "bad container param to ipDefaultRouterTable_container_init\n"); + return; + } + + /* + * For advanced users, you can use a custom container. If you + * do not create one, one will be created for you. + */ + *container_ptr_ptr = NULL; + + if (NULL == cache) { + snmp_log(LOG_ERR, + "bad cache param to ipDefaultRouterTable_container_init\n"); + return; + } + + /* + * TODO:345:A: Set up ipDefaultRouterTable cache properties. + * + * Also for advanced users, you can set parameters for the + * cache. Do not change the magic pointer, as it is used + * by the MFD helper. To completely disable caching, set + * cache->enabled to 0. + */ + cache->timeout = IPDEFAULTROUTERTABLE_CACHE_TIMEOUT; /* seconds */ +} /* ipDefaultRouterTable_container_init */ + +/** + * container shutdown + * + * @param container_ptr A pointer to the container. + * + * This function is called at shutdown to allow you to customize certain + * aspects of the access method. For the most part, it is for advanced + * users. The default code should suffice for most cases. + * + * This function is called before ipDefaultRouterTable_container_free(). + * + * @remark + * This would also be a good place to do any cleanup needed + * for you data source. For example, closing a connection to another + * process that supplied the data, closing a database, etc. + */ +void +ipDefaultRouterTable_container_shutdown(netsnmp_container * container_ptr) +{ + DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_container_shutdown", "called\n")); + + if (NULL == container_ptr) { + snmp_log(LOG_ERR, + "bad params to ipDefaultRouterTable_container_shutdown\n"); + return; + } + +} /* ipDefaultRouterTable_container_shutdown */ + +/** + * check entry for update + */ +static void +_check_entry_for_updates(ipDefaultRouterTable_rowreq_ctx * rowreq_ctx, + void **magic) +{ + netsnmp_container *defaultrouter_container = magic[0]; + netsnmp_container *to_delete = (netsnmp_container *) magic[1]; + + /* + * check for matching entry using secondary index. + */ + netsnmp_defaultrouter_entry *defaultrouter_entry = + CONTAINER_FIND(defaultrouter_container, rowreq_ctx->data); + if (NULL == defaultrouter_entry) { + DEBUGMSGTL(("ipDefaultRouterTable:access", "removing missing entry\n")); + + if (NULL == to_delete) { + magic[1] = to_delete = netsnmp_container_find("lifo"); + if (NULL == to_delete) + snmp_log(LOG_ERR, "couldn't create delete container\n"); + } + if (NULL != to_delete) + CONTAINER_INSERT(to_delete, rowreq_ctx); + } else { + DEBUGMSGTL(("ipDefaultRouterTable:access", "updating existing entry\n")); + + /* + * Check for changes & update + */ + netsnmp_access_defaultrouter_entry_update(rowreq_ctx->data, + defaultrouter_entry); + + /* + * remove entry from ifcontainer + */ + CONTAINER_REMOVE(defaultrouter_container, defaultrouter_entry); + netsnmp_access_defaultrouter_entry_free(defaultrouter_entry); + } +} + +/** + * add new entry + */ +static void +_add_new_entry(netsnmp_defaultrouter_entry *defaultrouter_entry, + netsnmp_container *container) +{ + ipDefaultRouterTable_rowreq_ctx *rowreq_ctx; + + DEBUGMSGTL(("ipDefaultRouterTable:access", "creating new entry\n")); + + netsnmp_assert(NULL != defaultrouter_entry); + netsnmp_assert(NULL != container); + + /* + * allocate an row context and set the index(es) + */ + rowreq_ctx = ipDefaultRouterTable_allocate_rowreq_ctx(defaultrouter_entry, + NULL); + if ((NULL != rowreq_ctx) && + (MFD_SUCCESS == + ipDefaultRouterTable_indexes_set(rowreq_ctx, + defaultrouter_entry->dr_addresstype, + defaultrouter_entry->dr_address, + defaultrouter_entry->dr_address_len, + defaultrouter_entry->dr_if_index))) { + if (CONTAINER_INSERT(container, rowreq_ctx) < 0) { + DEBUGMSGTL(("ipAddressTable:access", + "container insert failed for new entry\n")); + ipDefaultRouterTable_release_rowreq_ctx(rowreq_ctx); + return; + } + } else { + if (NULL != rowreq_ctx) { + snmp_log(LOG_ERR, "error setting index while loading " + "ipDefaultRouterTable cache.\n"); + ipDefaultRouterTable_release_rowreq_ctx(rowreq_ctx); + } else { + snmp_log(LOG_ERR, "memory allocation failed while loading " + "ipDefaultRouterTable cache.\n"); + netsnmp_access_defaultrouter_entry_free(defaultrouter_entry); + } + + return; + } +} + +/** + * 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 = 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", + "%d records\n", CONTAINER_SIZE(container))); + + return MFD_SUCCESS; +} + +/** + * container clean up + * + * @param container container with all current items + * + * This optional callback is called prior to all + * item's being removed from the container. If you + * need to do any processing before that, do it here. + * + * @note + * The MFD helper will take care of releasing all the row contexts. + * + */ +void +ipDefaultRouterTable_container_free(netsnmp_container * container) +{ + DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_container_free", "called\n")); + + /* + * TODO:380:M: Free ipDefaultRouterTable container data. + */ +} /* ipDefaultRouterTable_container_free */ + +/** + * prepare row for processing. + * + * When the agent has located the row for a request, this function is + * called to prepare the row for processing. If you fully populated + * the data context during the index setup phase, you may not need to + * do anything. + * + * @param rowreq_ctx pointer to a context. + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + */ +int +ipDefaultRouterTable_row_prep(ipDefaultRouterTable_rowreq_ctx * rowreq_ctx) +{ + DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_row_prep", "called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + /* + * TODO:390:o: Prepare row for request. + * If populating row data was delayed, this is the place to + * fill in the row for this request. + */ + + return MFD_SUCCESS; +} /* ipDefaultRouterTable_row_prep */ + +/** @} */ diff --git a/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_data_access.h b/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_data_access.h new file mode 100644 index 0000000..ed033f0 --- /dev/null +++ b/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_data_access.h @@ -0,0 +1,76 @@ +/* + * Note: this file originally auto-generated by mib2c using + * version : 14170 $ of $ + * + * $Id:$ + */ +#ifndef IPDEFAULTROUTERTABLE_DATA_ACCESS_H +#define IPDEFAULTROUTERTABLE_DATA_ACCESS_H + +#ifdef __cplusplus +extern "C" { +#endif + + + /* + ********************************************************************* + * function declarations + */ + + /* + ********************************************************************* + * Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table ipDefaultRouterTable + *** + ********************************************************************** + **********************************************************************/ + /* + * IP-MIB::ipDefaultRouterTable is subid 37 of ip. + * Its status is Current. + * OID: .1.3.6.1.2.1.4.37, length: 8 + */ + + + int + ipDefaultRouterTable_init_data(ipDefaultRouterTable_registration * + ipDefaultRouterTable_reg); + + + /* + * TODO:180:o: Review ipDefaultRouterTable cache timeout. + * The number of seconds before the cache times out + */ +#define IPDEFAULTROUTERTABLE_CACHE_TIMEOUT 60 + + void ipDefaultRouterTable_container_init(netsnmp_container + ** + container_ptr_ptr, + netsnmp_cache * + cache); + void + ipDefaultRouterTable_container_shutdown(netsnmp_container * + container_ptr); + + int ipDefaultRouterTable_container_load(netsnmp_container * + container); + void ipDefaultRouterTable_container_free(netsnmp_container * + container); + + int ipDefaultRouterTable_cache_load(netsnmp_container * + container); + void ipDefaultRouterTable_cache_free(netsnmp_container * + container); + int + ipDefaultRouterTable_row_prep(ipDefaultRouterTable_rowreq_ctx * + rowreq_ctx); + + + +#ifdef __cplusplus +} +#endif +#endif /* IPDEFAULTROUTERTABLE_DATA_ACCESS_H */ diff --git a/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_data_get.c b/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_data_get.c new file mode 100644 index 0000000..1177897 --- /dev/null +++ b/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_data_get.c @@ -0,0 +1,325 @@ +/* + * Note: this file originally auto-generated by mib2c using + * version : 12088 $ of $ + * + * $Id:$ + */ +/* + * standard Net-SNMP includes + */ +#include +#include +#include + +/* + * include our parent header + */ +#include "ipDefaultRouterTable.h" + + +/** @defgroup data_get data_get: Routines to get data + * + * TODO:230:M: Implement ipDefaultRouterTable get routines. + * TODO:240:M: Implement ipDefaultRouterTable mapping routines (if any). + * + * These routine are used to get the value for individual objects. The + * row context is passed, along with a pointer to the memory where the + * value should be copied. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table ipDefaultRouterTable + *** + ********************************************************************** + **********************************************************************/ +/* + * IP-MIB::ipDefaultRouterTable is subid 37 of ip. + * Its status is Current. + * OID: .1.3.6.1.2.1.4.37, length: 8 + */ + +/* + * --------------------------------------------------------------------- + * * TODO:200:r: Implement ipDefaultRouterTable data context functions. + */ +/* + * ipDefaultRouterTable_allocate_data + * + * Purpose: create new ipDefaultRouterTable_data. + */ +ipDefaultRouterTable_data * +ipDefaultRouterTable_allocate_data(void) +{ + /* + * TODO:201:r: |-> allocate memory for the ipDefaultRouterTable data context. + */ + ipDefaultRouterTable_data *rtn = + netsnmp_access_defaultrouter_entry_create(); + + DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_allocate_data", "called\n")); + + if (NULL == rtn) { + snmp_log(LOG_ERR, "unable to malloc memory for new " + "ipDefaultRouterTable_data.\n"); + } + + return rtn; +} /* ipDefaultRouterTable_allocate_data */ + +/* + * ipDefaultRouterTable_release_data + * + * Purpose: release ipDefaultRouterTable data. + */ +void +ipDefaultRouterTable_release_data(ipDefaultRouterTable_data * data) +{ + DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_release_data", "called\n")); + + /* + * TODO:202:r: |-> release memory for the ipDefaultRouterTable data context. + */ + netsnmp_access_defaultrouter_entry_free(data); +} /* ipDefaultRouterTable_release_data */ + + + +/** + * set mib index(es) + * + * @param tbl_idx mib index structure + * @param ipDefaultRouterAddressType_val + * @param ipDefaultRouterAddress_ptr + * @param ipDefaultRouterAddress_ptr_len + * @param ipDefaultRouterIfIndex_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. + */ +int +ipDefaultRouterTable_indexes_set_tbl_idx(ipDefaultRouterTable_mib_index * + tbl_idx, + u_long + ipDefaultRouterAddressType_val, + char + *ipDefaultRouterAddress_val_ptr, + size_t + ipDefaultRouterAddress_val_ptr_len, + long ipDefaultRouterIfIndex_val) +{ + DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_indexes_set_tbl_idx", "called\n")); + + /* + * ipDefaultRouterAddressType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h + */ + /** WARNING: this code might not work for netsnmp_defaultrouter_entry */ + tbl_idx->ipDefaultRouterAddressType = ipDefaultRouterAddressType_val; + + /* + * ipDefaultRouterAddress(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h + */ + tbl_idx->ipDefaultRouterAddress_len = sizeof(tbl_idx->ipDefaultRouterAddress) / sizeof(tbl_idx->ipDefaultRouterAddress[0]); /* max length */ + /** WARNING: this code might not work for netsnmp_defaultrouter_entry */ + /* + * make sure there is enough space for ipDefaultRouterAddress data + */ + if ((NULL == tbl_idx->ipDefaultRouterAddress) || + (tbl_idx->ipDefaultRouterAddress_len < + (ipDefaultRouterAddress_val_ptr_len))) { + snmp_log(LOG_ERR, "not enough space for value\n"); + return MFD_ERROR; + } + tbl_idx->ipDefaultRouterAddress_len = + ipDefaultRouterAddress_val_ptr_len; + memcpy(tbl_idx->ipDefaultRouterAddress, ipDefaultRouterAddress_val_ptr, + ipDefaultRouterAddress_val_ptr_len * + sizeof(ipDefaultRouterAddress_val_ptr[0])); + + /* + * ipDefaultRouterIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/a/w/e/R/d/H + */ + /** WARNING: this code might not work for netsnmp_defaultrouter_entry */ + tbl_idx->ipDefaultRouterIfIndex = ipDefaultRouterIfIndex_val; + + + return MFD_SUCCESS; +} /* ipDefaultRouterTable_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. + */ +int +ipDefaultRouterTable_indexes_set(ipDefaultRouterTable_rowreq_ctx * + rowreq_ctx, + u_long ipDefaultRouterAddressType_val, + char *ipDefaultRouterAddress_val_ptr, + size_t ipDefaultRouterAddress_val_ptr_len, + long ipDefaultRouterIfIndex_val) +{ + DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_indexes_set", "called\n")); + + if (MFD_SUCCESS != + ipDefaultRouterTable_indexes_set_tbl_idx(&rowreq_ctx->tbl_idx, + ipDefaultRouterAddressType_val, + ipDefaultRouterAddress_val_ptr, + ipDefaultRouterAddress_val_ptr_len, + ipDefaultRouterIfIndex_val)) + return MFD_ERROR; + + /* + * convert mib index to oid index + */ + rowreq_ctx->oid_idx.len = sizeof(rowreq_ctx->oid_tmp) / sizeof(oid); + if (0 != ipDefaultRouterTable_index_to_oid(&rowreq_ctx->oid_idx, + &rowreq_ctx->tbl_idx)) { + return MFD_ERROR; + } + + return MFD_SUCCESS; +} /* ipDefaultRouterTable_indexes_set */ + + +/*--------------------------------------------------------------------- + * IP-MIB::ipDefaultRouterEntry.ipDefaultRouterLifetime + * ipDefaultRouterLifetime is subid 4 of ipDefaultRouterEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.4.37.1.4 + * Description: +The remaining length of time, in seconds, that this router + will continue to be useful as a default router. A value of + zero indicates that it is no longer useful as a default + router. It is left to the implementer of the MIB as to + whether a router with a lifetime of zero is removed from the + list. + + For IPv6, this value should be extracted from the router + advertisement messages. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 0 + * settable 0 + * + * Ranges: 0 - 65535; + * + * Its syntax is UNSIGNED32 (based on perltype UNSIGNED32) + * The net-snmp type is ASN_UNSIGNED. The C type decl is u_long (u_long) + */ +/** + * Extract the current value of the ipDefaultRouterLifetime data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param ipDefaultRouterLifetime_val_ptr + * Pointer to storage for a u_long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +ipDefaultRouterLifetime_get(ipDefaultRouterTable_rowreq_ctx * rowreq_ctx, + u_long * ipDefaultRouterLifetime_val_ptr) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert(NULL != ipDefaultRouterLifetime_val_ptr); + + + DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterLifetime_get", + "called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + /* + * TODO:231:o: |-> Extract the current value of the ipDefaultRouterLifetime data. + * copy (* ipDefaultRouterLifetime_val_ptr ) from rowreq_ctx->data + */ + (*ipDefaultRouterLifetime_val_ptr) = rowreq_ctx->data->dr_lifetime; + + return MFD_SUCCESS; +} /* ipDefaultRouterLifetime_get */ + +/*--------------------------------------------------------------------- + * IP-MIB::ipDefaultRouterEntry.ipDefaultRouterPreference + * ipDefaultRouterPreference is subid 5 of ipDefaultRouterEntry. + * Its status is Current, and its access level is ReadOnly. + * OID: .1.3.6.1.2.1.4.37.1.5 + * Description: +An indication of preference given to this router as a + default router as described in he Default Router + Preferences document. Treating the value as a + 2 bit signed integer allows for simple arithmetic + comparisons. + + For IPv4 routers or IPv6 routers that are not using the + updated router advertisement format, this object is set to + medium (0). + * + * Attributes: + * accessible 1 isscalar 0 enums 1 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 0 + * + * Enum range: 3/8. Values: reserved(-2), low(-1), medium(0), high(1) + * + * Its syntax is INTEGER (based on perltype INTEGER) + * The net-snmp type is ASN_INTEGER. The C type decl is long (u_long) + */ +/** + * Extract the current value of the ipDefaultRouterPreference data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param ipDefaultRouterPreference_val_ptr + * Pointer to storage for a long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +ipDefaultRouterPreference_get(ipDefaultRouterTable_rowreq_ctx * rowreq_ctx, + u_long * ipDefaultRouterPreference_val_ptr) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert(NULL != ipDefaultRouterPreference_val_ptr); + + + DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterPreference_get", "called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + /* + * TODO:231:o: |-> Extract the current value of the ipDefaultRouterPreference data. + * copy (* ipDefaultRouterPreference_val_ptr ) from rowreq_ctx->data + */ + (*ipDefaultRouterPreference_val_ptr) = rowreq_ctx->data->dr_preference; + + return MFD_SUCCESS; +} /* ipDefaultRouterPreference_get */ + + + +/** @} */ diff --git a/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_data_get.h b/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_data_get.h new file mode 100644 index 0000000..8698675 --- /dev/null +++ b/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_data_get.h @@ -0,0 +1,84 @@ +/* + * Note: this file originally auto-generated by mib2c using + * version : 12088 $ of $ + * + * $Id:$ + * + * @file ipDefaultRouterTable_data_get.h + * + * @addtogroup get + * + * Prototypes for get functions + * + * @{ + */ +#ifndef IPDEFAULTROUTERTABLE_DATA_GET_H +#define IPDEFAULTROUTERTABLE_DATA_GET_H + +#ifdef __cplusplus +extern "C" { +#endif + + /* + ********************************************************************* + * GET function declarations + */ + + /* + ********************************************************************* + * GET Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table ipDefaultRouterTable + *** + ********************************************************************** + **********************************************************************/ + /* + * IP-MIB::ipDefaultRouterTable is subid 37 of ip. + * Its status is Current. + * OID: .1.3.6.1.2.1.4.37, length: 8 + */ + /* + * indexes + */ + + int + ipDefaultRouterLifetime_get(ipDefaultRouterTable_rowreq_ctx * + rowreq_ctx, + u_long * + ipDefaultRouterLifetime_val_ptr); + int + ipDefaultRouterPreference_get(ipDefaultRouterTable_rowreq_ctx * + rowreq_ctx, + u_long * + ipDefaultRouterPreference_val_ptr); + + + int + ipDefaultRouterTable_indexes_set_tbl_idx + (ipDefaultRouterTable_mib_index * tbl_idx, + u_long ipDefaultRouterAddressType_val, + char *ipDefaultRouterAddress_val_ptr, + size_t ipDefaultRouterAddress_val_ptr_len, + long ipDefaultRouterIfIndex_val); + int + ipDefaultRouterTable_indexes_set(ipDefaultRouterTable_rowreq_ctx * + rowreq_ctx, + u_long + ipDefaultRouterAddressType_val, + char + *ipDefaultRouterAddress_val_ptr, + size_t + ipDefaultRouterAddress_val_ptr_len, + long ipDefaultRouterIfIndex_val); + + + + +#ifdef __cplusplus +} +#endif +#endif /* IPDEFAULTROUTERTABLE_DATA_GET_H */ +/** @} */ diff --git a/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_enums.h b/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_enums.h new file mode 100644 index 0000000..bb46d10 --- /dev/null +++ b/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_enums.h @@ -0,0 +1,93 @@ +/* + * Note: this file originally auto-generated by mib2c using + * : generic-table-enums.m2c 12526 2005-07-15 22:41:16Z rstory $ + * + * $Id:$ + */ +#ifndef IPDEFAULTROUTERTABLE_ENUMS_H +#define IPDEFAULTROUTERTABLE_ENUMS_H + +#ifdef __cplusplus +extern "C" { +#endif + + /* + * NOTES on enums + * ============== + * + * Value Mapping + * ------------- + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them + * below. For example, a boolean flag (1/0) is usually represented + * as a TruthValue in a MIB, which maps to the values (1/2). + * + */ +/************************************************************************* + ************************************************************************* + * + * enum definitions for table ipDefaultRouterTable + * + ************************************************************************* + *************************************************************************/ + +/************************************************************* + * constants for enums for the MIB node + * ipDefaultRouterLifetime (UNSIGNED32 / ASN_UNSIGNED) + * + * since a Textual Convention may be referenced more than once in a + * MIB, protect againt redefinitions of the enum values. + */ +#ifndef IPDEFAULTROUTERLIFETIME_ENUMS +#define IPDEFAULTROUTERLIFETIME_ENUMS + +#define IPDEFAULTROUTERLIFETIME_MIN 0 +#define IPDEFAULTROUTERLIFETIME_MAX 0xFFFFFFFFUL + +#endif /* IPDEFAULTROUTERLIFETIME_ENUMS */ + + +/************************************************************* + * constants for enums for the MIB node + * ipDefaultRouterAddressType (InetAddressType / ASN_INTEGER) + * + * since a Textual Convention may be referenced more than once in a + * MIB, protect againt redefinitions of the enum values. + */ +#ifndef INETADDRESSTYPE_ENUMS +#define INETADDRESSTYPE_ENUMS + +#define INETADDRESSTYPE_UNKNOWN 0 +#define INETADDRESSTYPE_IPV4 1 +#define INETADDRESSTYPE_IPV6 2 +#define INETADDRESSTYPE_IPV4Z 3 +#define INETADDRESSTYPE_IPV6Z 4 +#define INETADDRESSTYPE_DNS 16 + +#endif /* INETADDRESSTYPE_ENUMS */ + + +/************************************************************* + * constants for enums for the MIB node + * ipDefaultRouterPreference (INTEGER / ASN_INTEGER) + * + * since a Textual Convention may be referenced more than once in a + * MIB, protect againt redefinitions of the enum values. + */ +#ifndef IPDEFAULTROUTERPREFERENCE_ENUMS +#define IPDEFAULTROUTERPREFERENCE_ENUMS + +#define IPDEFAULTROUTERPREFERENCE_RESERVED -2 +#define IPDEFAULTROUTERPREFERENCE_LOW -1 +#define IPDEFAULTROUTERPREFERENCE_MEDIUM 0 +#define IPDEFAULTROUTERPREFERENCE_HIGH 1 + +#endif /* IPDEFAULTROUTERPREFERENCE_ENUMS */ + + + + +#ifdef __cplusplus +} +#endif +#endif /* IPDEFAULTROUTERTABLE_ENUMS_H */ diff --git a/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_interface.c b/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_interface.c new file mode 100644 index 0000000..afe7e57 --- /dev/null +++ b/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_interface.c @@ -0,0 +1,1018 @@ +/* + * Note: this file originally auto-generated by mib2c using + * version : 15899 $ of $ + * + * $Id:$ + */ +/* + * ********************************************************************* + * ********************************************************************* + * ********************************************************************* + * *** *** + * *** NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE *** + * *** *** + * *** *** + * *** THIS FILE DOES NOT CONTAIN ANY USER EDITABLE CODE. *** + * *** *** + * *** *** + * *** THE GENERATED CODE IS INTERNAL IMPLEMENTATION, AND *** + * *** *** + * *** *** + * *** IS SUBJECT TO CHANGE WITHOUT WARNING IN FUTURE RELEASES. *** + * *** *** + * *** *** + * ********************************************************************* + * ********************************************************************* + * ********************************************************************* + */ + +/* + * standard Net-SNMP includes + */ +#include +#include +#include + +/* + * include our parent header + */ +#include "ipDefaultRouterTable.h" + + +#include +#include + +#include "ipDefaultRouterTable_interface.h" + +#include + +/********************************************************************** + ********************************************************************** + *** + *** Table ipDefaultRouterTable + *** + ********************************************************************** + **********************************************************************/ +/* + * IP-MIB::ipDefaultRouterTable is subid 37 of ip. + * Its status is Current. + * OID: .1.3.6.1.2.1.4.37, length: 8 + */ +typedef struct ipDefaultRouterTable_interface_ctx_s { + + netsnmp_container *container; + netsnmp_cache *cache; + + ipDefaultRouterTable_registration *user_ctx; + + netsnmp_table_registration_info tbl_info; + + netsnmp_baby_steps_access_methods access_multiplexer; + +} ipDefaultRouterTable_interface_ctx; + +static ipDefaultRouterTable_interface_ctx ipDefaultRouterTable_if_ctx; + +static void +_ipDefaultRouterTable_container_init(ipDefaultRouterTable_interface_ctx * + if_ctx); +static void +_ipDefaultRouterTable_container_shutdown(ipDefaultRouterTable_interface_ctx + * if_ctx); + + +netsnmp_container * +ipDefaultRouterTable_container_get(void) +{ + return ipDefaultRouterTable_if_ctx.container; +} + +ipDefaultRouterTable_registration * +ipDefaultRouterTable_registration_get(void) +{ + return ipDefaultRouterTable_if_ctx.user_ctx; +} + +ipDefaultRouterTable_registration * +ipDefaultRouterTable_registration_set(ipDefaultRouterTable_registration * + newreg) +{ + ipDefaultRouterTable_registration *old = + ipDefaultRouterTable_if_ctx.user_ctx; + ipDefaultRouterTable_if_ctx.user_ctx = newreg; + return old; +} + +int +ipDefaultRouterTable_container_size(void) +{ + return CONTAINER_SIZE(ipDefaultRouterTable_if_ctx.container); +} + +/* + * mfd multiplexer modes + */ +static Netsnmp_Node_Handler _mfd_ipDefaultRouterTable_pre_request; +static Netsnmp_Node_Handler _mfd_ipDefaultRouterTable_post_request; +static Netsnmp_Node_Handler _mfd_ipDefaultRouterTable_object_lookup; +static Netsnmp_Node_Handler _mfd_ipDefaultRouterTable_get_values; +/** + * @internal + * Initialize the table ipDefaultRouterTable + * (Define its contents and how it's structured) + */ +void +_ipDefaultRouterTable_initialize_interface + (ipDefaultRouterTable_registration * reg_ptr, u_long flags) +{ + netsnmp_baby_steps_access_methods *access_multiplexer = + &ipDefaultRouterTable_if_ctx.access_multiplexer; + netsnmp_table_registration_info *tbl_info = + &ipDefaultRouterTable_if_ctx.tbl_info; + netsnmp_handler_registration *reginfo; + netsnmp_mib_handler *handler; + int mfd_modes = 0; + + DEBUGMSGTL(("internal:ipDefaultRouterTable:_ipDefaultRouterTable_initialize_interface", "called\n")); + + + /************************************************* + * + * save interface context for ipDefaultRouterTable + */ + /* + * Setting up the table's definition + */ + netsnmp_table_helper_add_indexes(tbl_info, ASN_INTEGER, + /** index: ipDefaultRouterAddressType */ + ASN_OCTET_STR, + /** index: ipDefaultRouterAddress */ + ASN_INTEGER, + /** index: ipDefaultRouterIfIndex */ + 0); + + /* + * Define the minimum and maximum accessible columns. This + * optimizes retrival. + */ + tbl_info->min_column = IPDEFAULTROUTERTABLE_MIN_COL; + tbl_info->max_column = IPDEFAULTROUTERTABLE_MAX_COL; + + /* + * save users context + */ + ipDefaultRouterTable_if_ctx.user_ctx = reg_ptr; + + /* + * call data access initialization code + */ + ipDefaultRouterTable_init_data(reg_ptr); + + /* + * set up the container + */ + _ipDefaultRouterTable_container_init(&ipDefaultRouterTable_if_ctx); + if (NULL == ipDefaultRouterTable_if_ctx.container) { + snmp_log(LOG_ERR, + "could not initialize container for ipDefaultRouterTable\n"); + return; + } + + /* + * access_multiplexer: REQUIRED wrapper for get request handling + */ + access_multiplexer->object_lookup = + _mfd_ipDefaultRouterTable_object_lookup; + access_multiplexer->get_values = _mfd_ipDefaultRouterTable_get_values; + + /* + * no wrappers yet + */ + access_multiplexer->pre_request = + _mfd_ipDefaultRouterTable_pre_request; + access_multiplexer->post_request = + _mfd_ipDefaultRouterTable_post_request; + + + /************************************************* + * + * Create a registration, save our reg data, register table. + */ + DEBUGMSGTL(("ipDefaultRouterTable:init_ipDefaultRouterTable", + "Registering ipDefaultRouterTable as a mibs-for-dummies table.\n")); + handler = + netsnmp_baby_steps_access_multiplexer_get(access_multiplexer); + reginfo = + netsnmp_handler_registration_create("ipDefaultRouterTable", + handler, + ipDefaultRouterTable_oid, + ipDefaultRouterTable_oid_size, + HANDLER_CAN_BABY_STEP | + HANDLER_CAN_RONLY); + if (NULL == reginfo) { + snmp_log(LOG_ERR, + "error registering table ipDefaultRouterTable\n"); + return; + } + reginfo->my_reg_void = &ipDefaultRouterTable_if_ctx; + + /************************************************* + * + * set up baby steps handler, create it and inject it + */ + if (access_multiplexer->object_lookup) + mfd_modes |= BABY_STEP_OBJECT_LOOKUP; + if (access_multiplexer->set_values) + mfd_modes |= BABY_STEP_SET_VALUES; + if (access_multiplexer->irreversible_commit) + mfd_modes |= BABY_STEP_IRREVERSIBLE_COMMIT; + if (access_multiplexer->object_syntax_checks) + mfd_modes |= BABY_STEP_CHECK_OBJECT; + + if (access_multiplexer->pre_request) + mfd_modes |= BABY_STEP_PRE_REQUEST; + if (access_multiplexer->post_request) + mfd_modes |= BABY_STEP_POST_REQUEST; + + if (access_multiplexer->undo_setup) + mfd_modes |= BABY_STEP_UNDO_SETUP; + if (access_multiplexer->undo_cleanup) + mfd_modes |= BABY_STEP_UNDO_CLEANUP; + if (access_multiplexer->undo_sets) + mfd_modes |= BABY_STEP_UNDO_SETS; + + if (access_multiplexer->row_creation) + mfd_modes |= BABY_STEP_ROW_CREATE; + if (access_multiplexer->consistency_checks) + mfd_modes |= BABY_STEP_CHECK_CONSISTENCY; + if (access_multiplexer->commit) + mfd_modes |= BABY_STEP_COMMIT; + if (access_multiplexer->undo_commit) + mfd_modes |= BABY_STEP_UNDO_COMMIT; + + handler = netsnmp_baby_steps_handler_get(mfd_modes); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject row_merge helper with prefix rootoid_len + 2 (entry.col) + */ + handler = netsnmp_get_row_merge_handler(reginfo->rootoid_len + 2); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject container_table helper + */ + handler = + netsnmp_container_table_handler_get(tbl_info, + ipDefaultRouterTable_if_ctx. + container, + TABLE_CONTAINER_KEY_NETSNMP_INDEX); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject cache helper + */ + if (NULL != ipDefaultRouterTable_if_ctx.cache) { + handler = + netsnmp_cache_handler_get(ipDefaultRouterTable_if_ctx.cache); + netsnmp_inject_handler(reginfo, handler); + } + + /* + * register table + */ + netsnmp_register_table(reginfo, tbl_info); + +} /* _ipDefaultRouterTable_initialize_interface */ + +/** + * @internal + * Shutdown the table ipDefaultRouterTable + */ +void +_ipDefaultRouterTable_shutdown_interface(ipDefaultRouterTable_registration + * reg_ptr) +{ + /* + * shutdown the container + */ + _ipDefaultRouterTable_container_shutdown(&ipDefaultRouterTable_if_ctx); +} + +void +ipDefaultRouterTable_valid_columns_set(netsnmp_column_info *vc) +{ + ipDefaultRouterTable_if_ctx.tbl_info.valid_columns = vc; +} /* ipDefaultRouterTable_valid_columns_set */ + +/** + * @internal + * convert the index component stored in the context to an oid + */ +int +ipDefaultRouterTable_index_to_oid(netsnmp_index * oid_idx, + ipDefaultRouterTable_mib_index * mib_idx) +{ + int err = SNMP_ERR_NOERROR; + + /* + * temp storage for parsing indexes + */ + /* + * ipDefaultRouterAddressType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h + */ + netsnmp_variable_list var_ipDefaultRouterAddressType; + /* + * ipDefaultRouterAddress(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h + */ + netsnmp_variable_list var_ipDefaultRouterAddress; + /* + * ipDefaultRouterIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/a/w/e/R/d/H + */ + netsnmp_variable_list var_ipDefaultRouterIfIndex; + + /* + * set up varbinds + */ + memset(&var_ipDefaultRouterAddressType, 0x00, + sizeof(var_ipDefaultRouterAddressType)); + var_ipDefaultRouterAddressType.type = ASN_INTEGER; + memset(&var_ipDefaultRouterAddress, 0x00, + sizeof(var_ipDefaultRouterAddress)); + var_ipDefaultRouterAddress.type = ASN_OCTET_STR; + memset(&var_ipDefaultRouterIfIndex, 0x00, + sizeof(var_ipDefaultRouterIfIndex)); + var_ipDefaultRouterIfIndex.type = ASN_INTEGER; + + /* + * chain temp index varbinds together + */ + var_ipDefaultRouterAddressType.next_variable = + &var_ipDefaultRouterAddress; + var_ipDefaultRouterAddress.next_variable = &var_ipDefaultRouterIfIndex; + var_ipDefaultRouterIfIndex.next_variable = NULL; + + + DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_index_to_oid", "called\n")); + + /* + * ipDefaultRouterAddressType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h + */ + snmp_set_var_value(&var_ipDefaultRouterAddressType, + (u_char *) & mib_idx->ipDefaultRouterAddressType, + sizeof(mib_idx->ipDefaultRouterAddressType)); + + /* + * ipDefaultRouterAddress(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h + */ + snmp_set_var_value(&var_ipDefaultRouterAddress, + (u_char *) & mib_idx->ipDefaultRouterAddress, + mib_idx->ipDefaultRouterAddress_len * + sizeof(mib_idx->ipDefaultRouterAddress[0])); + + /* + * ipDefaultRouterIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/a/w/e/R/d/H + */ + snmp_set_var_value(&var_ipDefaultRouterIfIndex, + (u_char *) & mib_idx->ipDefaultRouterIfIndex, + sizeof(mib_idx->ipDefaultRouterIfIndex)); + + + err = build_oid_noalloc(oid_idx->oids, oid_idx->len, &oid_idx->len, + NULL, 0, &var_ipDefaultRouterAddressType); + 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_ipDefaultRouterAddressType); + + return err; +} /* ipDefaultRouterTable_index_to_oid */ + +/** + * extract ipDefaultRouterTable indexes from a netsnmp_index + * + * @retval SNMP_ERR_NOERROR : no error + * @retval SNMP_ERR_GENERR : error + */ +int +ipDefaultRouterTable_index_from_oid(netsnmp_index * oid_idx, + ipDefaultRouterTable_mib_index * + mib_idx) +{ + int err = SNMP_ERR_NOERROR; + + /* + * temp storage for parsing indexes + */ + /* + * ipDefaultRouterAddressType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h + */ + netsnmp_variable_list var_ipDefaultRouterAddressType; + /* + * ipDefaultRouterAddress(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h + */ + netsnmp_variable_list var_ipDefaultRouterAddress; + /* + * ipDefaultRouterIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/a/w/e/R/d/H + */ + netsnmp_variable_list var_ipDefaultRouterIfIndex; + + /* + * set up varbinds + */ + memset(&var_ipDefaultRouterAddressType, 0x00, + sizeof(var_ipDefaultRouterAddressType)); + var_ipDefaultRouterAddressType.type = ASN_INTEGER; + memset(&var_ipDefaultRouterAddress, 0x00, + sizeof(var_ipDefaultRouterAddress)); + var_ipDefaultRouterAddress.type = ASN_OCTET_STR; + memset(&var_ipDefaultRouterIfIndex, 0x00, + sizeof(var_ipDefaultRouterIfIndex)); + var_ipDefaultRouterIfIndex.type = ASN_INTEGER; + + /* + * chain temp index varbinds together + */ + var_ipDefaultRouterAddressType.next_variable = + &var_ipDefaultRouterAddress; + var_ipDefaultRouterAddress.next_variable = &var_ipDefaultRouterIfIndex; + var_ipDefaultRouterIfIndex.next_variable = NULL; + + + DEBUGMSGTL(("verbose:ipDefaultRouterTable:ipDefaultRouterTable_index_from_oid", "called\n")); + + /* + * parse the oid into the individual index components + */ + err = parse_oid_indexes(oid_idx->oids, oid_idx->len, + &var_ipDefaultRouterAddressType); + if (err == SNMP_ERR_NOERROR) { + /* + * copy out values + */ + mib_idx->ipDefaultRouterAddressType = + *((u_long *) var_ipDefaultRouterAddressType.val.string); + /* + * NOTE: val_len is in bytes, ipDefaultRouterAddress_len might not be + */ + if (var_ipDefaultRouterAddress.val_len > + sizeof(mib_idx->ipDefaultRouterAddress)) + err = SNMP_ERR_GENERR; + else { + memcpy(mib_idx->ipDefaultRouterAddress, + var_ipDefaultRouterAddress.val.string, + var_ipDefaultRouterAddress.val_len); + mib_idx->ipDefaultRouterAddress_len = + var_ipDefaultRouterAddress.val_len / + sizeof(mib_idx->ipDefaultRouterAddress[0]); + } + mib_idx->ipDefaultRouterIfIndex = + *((long *) var_ipDefaultRouterIfIndex.val.string); + + + } + + /* + * parsing may have allocated memory. free it. + */ + snmp_reset_var_buffers(&var_ipDefaultRouterAddressType); + + return err; +} /* ipDefaultRouterTable_index_from_oid */ + + +/* + ********************************************************************* + * @internal + * allocate resources for a ipDefaultRouterTable_rowreq_ctx + */ +ipDefaultRouterTable_rowreq_ctx * +ipDefaultRouterTable_allocate_rowreq_ctx(ipDefaultRouterTable_data * data, + void *user_init_ctx) +{ + ipDefaultRouterTable_rowreq_ctx *rowreq_ctx = + SNMP_MALLOC_TYPEDEF(ipDefaultRouterTable_rowreq_ctx); + + DEBUGMSGTL(("internal:ipDefaultRouterTable:ipDefaultRouterTable_allocate_rowreq_ctx", "called\n")); + + if (NULL == rowreq_ctx) { + snmp_log(LOG_ERR, "Couldn't allocate memory for a " + "ipDefaultRouterTable_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 = + ipDefaultRouterTable_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->ipDefaultRouterTable_data_list = NULL; + + /* + * if we allocated data, call init routine + */ + if (!(rowreq_ctx->rowreq_flags & MFD_ROW_DATA_FROM_USER)) { + if (SNMPERR_SUCCESS != + ipDefaultRouterTable_rowreq_ctx_init(rowreq_ctx, + user_init_ctx)) { + ipDefaultRouterTable_release_rowreq_ctx(rowreq_ctx); + rowreq_ctx = NULL; + } + } + + return rowreq_ctx; +} /* ipDefaultRouterTable_allocate_rowreq_ctx */ + +/* + * @internal + * release resources for a ipDefaultRouterTable_rowreq_ctx + */ +void +ipDefaultRouterTable_release_rowreq_ctx(ipDefaultRouterTable_rowreq_ctx * + rowreq_ctx) +{ + DEBUGMSGTL(("internal:ipDefaultRouterTable:ipDefaultRouterTable_release_rowreq_ctx", "called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + ipDefaultRouterTable_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)) + ipDefaultRouterTable_release_data(rowreq_ctx->data); + + /* + * free index oid pointer + */ + if (rowreq_ctx->oid_idx.oids != rowreq_ctx->oid_tmp) + free(rowreq_ctx->oid_idx.oids); + + SNMP_FREE(rowreq_ctx); +} /* ipDefaultRouterTable_release_rowreq_ctx */ + +/** + * @internal + * wrapper + */ +static int +_mfd_ipDefaultRouterTable_pre_request(netsnmp_mib_handler *handler, + netsnmp_handler_registration + *reginfo, + netsnmp_agent_request_info + *agtreq_info, + netsnmp_request_info *requests) +{ + int rc; + + DEBUGMSGTL(("internal:ipDefaultRouterTable:_mfd_ipDefaultRouterTable_pre_request", "called\n")); + + if (1 != netsnmp_row_merge_status_first(reginfo, agtreq_info)) { + DEBUGMSGTL(("internal:ipDefaultRouterTable", + "skipping additional pre_request\n")); + return SNMP_ERR_NOERROR; + } + + rc = ipDefaultRouterTable_pre_request(ipDefaultRouterTable_if_ctx. + user_ctx); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("ipDefaultRouterTable", "error %d from " + "ipDefaultRouterTable_pre_request\n", rc)); + netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_ipDefaultRouterTable_pre_request */ + +/** + * @internal + * wrapper + */ +static int +_mfd_ipDefaultRouterTable_post_request(netsnmp_mib_handler *handler, + netsnmp_handler_registration + *reginfo, + netsnmp_agent_request_info + *agtreq_info, + netsnmp_request_info *requests) +{ + ipDefaultRouterTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + int rc, packet_rc; + + DEBUGMSGTL(("internal:ipDefaultRouterTable:_mfd_ipDefaultRouterTable_post_request", "called\n")); + + /* + * release row context, if deleted + */ + if (rowreq_ctx && (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED)) + ipDefaultRouterTable_release_rowreq_ctx(rowreq_ctx); + + /* + * wait for last call before calling user + */ + if (1 != netsnmp_row_merge_status_last(reginfo, agtreq_info)) { + DEBUGMSGTL(("internal:ipDefaultRouterTable", + "waiting for last post_request\n")); + return SNMP_ERR_NOERROR; + } + + packet_rc = netsnmp_check_all_requests_error(agtreq_info->asp, 0); + rc = ipDefaultRouterTable_post_request(ipDefaultRouterTable_if_ctx. + user_ctx, packet_rc); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("ipDefaultRouterTable", "error %d from " + "ipDefaultRouterTable_post_request\n", rc)); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_ipDefaultRouterTable_post_request */ + +/** + * @internal + * wrapper + */ +static int +_mfd_ipDefaultRouterTable_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; + ipDefaultRouterTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + + DEBUGMSGTL(("internal:ipDefaultRouterTable:_mfd_ipDefaultRouterTable_object_lookup", "called\n")); + + /* + * get our context from mfd + * ipDefaultRouterTable_interface_ctx *if_ctx = + * (ipDefaultRouterTable_interface_ctx *)reginfo->my_reg_void; + */ + + if (NULL == rowreq_ctx) { + rc = SNMP_ERR_NOCREATION; + } + + if (MFD_SUCCESS != rc) + netsnmp_request_set_error_all(requests, rc); + else + ipDefaultRouterTable_row_prep(rowreq_ctx); + + return SNMP_VALIDATE_ERR(rc); +} /* _mfd_ipDefaultRouterTable_object_lookup */ + +/*********************************************************************** + * + * GET processing + * + ***********************************************************************/ +/* + * @internal + * Retrieve the value for a particular column + */ +NETSNMP_STATIC_INLINE int +_ipDefaultRouterTable_get_column(ipDefaultRouterTable_rowreq_ctx * + rowreq_ctx, netsnmp_variable_list * var, + int column) +{ + int rc = SNMPERR_SUCCESS; + + DEBUGMSGTL(("internal:ipDefaultRouterTable:_mfd_ipDefaultRouterTable_get_column", "called for %d\n", column)); + + + netsnmp_assert(NULL != rowreq_ctx); + + switch (column) { + + /* + * ipDefaultRouterLifetime(4)/UNSIGNED32/ASN_UNSIGNED/u_long(u_long)//l/A/w/e/R/d/h + */ + case COLUMN_IPDEFAULTROUTERLIFETIME: + var->val_len = sizeof(u_long); + var->type = ASN_UNSIGNED; + rc = ipDefaultRouterLifetime_get(rowreq_ctx, + (u_long *) var->val.string); + break; + + /* + * ipDefaultRouterPreference(5)/INTEGER/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h + */ + case COLUMN_IPDEFAULTROUTERPREFERENCE: + var->val_len = sizeof(u_long); + var->type = ASN_INTEGER; + rc = ipDefaultRouterPreference_get(rowreq_ctx, + (u_long *) var->val.string); + break; + + default: + if (IPDEFAULTROUTERTABLE_MIN_COL <= column + && column <= IPDEFAULTROUTERTABLE_MAX_COL) { + DEBUGMSGTL(("internal:ipDefaultRouterTable:_mfd_ipDefaultRouterTable_get_column", "assume column %d is reserved\n", column)); + rc = MFD_SKIP; + } else { + snmp_log(LOG_ERR, + "unknown column %d in _ipDefaultRouterTable_get_column\n", + column); + } + break; + } + + return rc; +} /* _ipDefaultRouterTable_get_column */ + +int +_mfd_ipDefaultRouterTable_get_values(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info + *agtreq_info, + netsnmp_request_info *requests) +{ + ipDefaultRouterTable_rowreq_ctx *rowreq_ctx = + netsnmp_container_table_row_extract(requests); + netsnmp_table_request_info *tri; + u_char *old_string; + void (*dataFreeHook) (void *); + int rc; + + DEBUGMSGTL(("internal:ipDefaultRouterTable:_mfd_ipDefaultRouterTable_get_values", "called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + for (; requests; requests = requests->next) { + /* + * save old pointer, so we can free it if replaced + */ + old_string = requests->requestvb->val.string; + dataFreeHook = requests->requestvb->dataFreeHook; + if (NULL == requests->requestvb->val.string) { + requests->requestvb->val.string = requests->requestvb->buf; + requests->requestvb->val_len = + sizeof(requests->requestvb->buf); + } else if (requests->requestvb->buf == + requests->requestvb->val.string) { + if (requests->requestvb->val_len != + sizeof(requests->requestvb->buf)) + requests->requestvb->val_len = + sizeof(requests->requestvb->buf); + } + + /* + * get column data + */ + tri = netsnmp_extract_table_info(requests); + if (NULL == tri) + continue; + + rc = _ipDefaultRouterTable_get_column(rowreq_ctx, + requests->requestvb, + tri->colnum); + if (rc) { + if (MFD_SKIP == rc) { + requests->requestvb->type = SNMP_NOSUCHINSTANCE; + rc = SNMP_ERR_NOERROR; + } + } else if (NULL == requests->requestvb->val.string) { + snmp_log(LOG_ERR, "NULL varbind data pointer!\n"); + rc = SNMP_ERR_GENERR; + } + if (rc) + netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc)); + + /* + * if the buffer wasn't used previously for the old data (i.e. it + * was allcoated memory) and the get routine replaced the pointer, + * we need to free the previous pointer. + */ + if (old_string && (old_string != requests->requestvb->buf) && + (requests->requestvb->val.string != old_string)) { + if (dataFreeHook) + (*dataFreeHook) (old_string); + else + free(old_string); + } + } /* for results */ + + return SNMP_ERR_NOERROR; +} /* _mfd_ipDefaultRouterTable_get_values */ + + +/*********************************************************************** + * + * SET processing + * + ***********************************************************************/ + +/* + * SET PROCESSING NOT APPLICABLE (per MIB or user setting) + */ +/*********************************************************************** + * + * DATA ACCESS + * + ***********************************************************************/ +static void _container_free(netsnmp_container * container); + +/** + * @internal + */ +static int +_cache_load(netsnmp_cache * cache, void *vmagic) +{ + DEBUGMSGTL(("internal:ipDefaultRouterTable:_cache_load", "called\n")); + + if ((NULL == cache) || (NULL == cache->magic)) { + snmp_log(LOG_ERR, + "invalid cache for ipDefaultRouterTable_cache_load\n"); + return -1; + } + + /** should only be called for an invalid or expired cache */ + netsnmp_assert((0 == cache->valid) || (1 == cache->expired)); + + /* + * call user code + */ + return ipDefaultRouterTable_container_load((netsnmp_container *) + cache->magic); +} /* _cache_load */ + +/** + * @internal + */ +static void +_cache_free(netsnmp_cache * cache, void *magic) +{ + netsnmp_container *container; + + DEBUGMSGTL(("internal:ipDefaultRouterTable:_cache_free", "called\n")); + + if ((NULL == cache) || (NULL == cache->magic)) { + snmp_log(LOG_ERR, + "invalid cache in ipDefaultRouterTable_cache_free\n"); + return; + } + + container = (netsnmp_container *) cache->magic; + + _container_free(container); +} /* _cache_free */ + +/** + * @internal + */ +static void +_container_item_free(ipDefaultRouterTable_rowreq_ctx * rowreq_ctx, + void *context) +{ + DEBUGMSGTL(("internal:ipDefaultRouterTable:_container_item_free", + "called\n")); + + if (NULL == rowreq_ctx) + return; + + ipDefaultRouterTable_release_rowreq_ctx(rowreq_ctx); +} /* _container_item_free */ + +/** + * @internal + */ +static void +_container_free(netsnmp_container * container) +{ + DEBUGMSGTL(("internal:ipDefaultRouterTable:_container_free", + "called\n")); + + if (NULL == container) { + snmp_log(LOG_ERR, + "invalid container in ipDefaultRouterTable_container_free\n"); + return; + } + + /* + * call user code + */ + ipDefaultRouterTable_container_free(container); + + /* + * free all items. inefficient, but easy. + */ + CONTAINER_CLEAR(container, + (netsnmp_container_obj_func *) _container_item_free, + NULL); +} /* _container_free */ + +/** + * @internal + * initialize the container with functions or wrappers + */ +void +_ipDefaultRouterTable_container_init(ipDefaultRouterTable_interface_ctx * + if_ctx) +{ + DEBUGMSGTL(("internal:ipDefaultRouterTable:_ipDefaultRouterTable_container_init", "called\n")); + + /* + * cache init + */ + if_ctx->cache = netsnmp_cache_create(30, /* timeout in seconds */ + _cache_load, _cache_free, + ipDefaultRouterTable_oid, + ipDefaultRouterTable_oid_size); + + if (NULL == if_ctx->cache) { + snmp_log(LOG_ERR, + "error creating cache for ipDefaultRouterTable\n"); + return; + } + + if_ctx->cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET; + + ipDefaultRouterTable_container_init(&if_ctx->container, if_ctx->cache); + if (NULL == if_ctx->container) + if_ctx->container = + netsnmp_container_find("ipDefaultRouterTable:table_container"); + if (NULL == if_ctx->container) { + snmp_log(LOG_ERR, "error creating container in " + "ipDefaultRouterTable_container_init\n"); + return; + } + + if (NULL != if_ctx->cache) + if_ctx->cache->magic = (void *) if_ctx->container; +} /* _ipDefaultRouterTable_container_init */ + +/** + * @internal + * shutdown the container with functions or wrappers + */ +void +_ipDefaultRouterTable_container_shutdown(ipDefaultRouterTable_interface_ctx + * if_ctx) +{ + DEBUGMSGTL(("internal:ipDefaultRouterTable:_ipDefaultRouterTable_container_shutdown", "called\n")); + + ipDefaultRouterTable_container_shutdown(if_ctx->container); + + _container_free(if_ctx->container); + +} /* _ipDefaultRouterTable_container_shutdown */ + + +ipDefaultRouterTable_rowreq_ctx * +ipDefaultRouterTable_row_find_by_mib_index(ipDefaultRouterTable_mib_index * + mib_idx) +{ + ipDefaultRouterTable_rowreq_ctx *rowreq_ctx; + oid oid_tmp[MAX_OID_LEN]; + netsnmp_index oid_idx; + int rc; + + /* + * set up storage for OID + */ + oid_idx.oids = oid_tmp; + oid_idx.len = sizeof(oid_tmp) / sizeof(oid); + + /* + * convert + */ + rc = ipDefaultRouterTable_index_to_oid(&oid_idx, mib_idx); + if (MFD_SUCCESS != rc) + return NULL; + + rowreq_ctx = + CONTAINER_FIND(ipDefaultRouterTable_if_ctx.container, &oid_idx); + + return rowreq_ctx; +} diff --git a/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_interface.h b/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_interface.h new file mode 100644 index 0000000..a780491 --- /dev/null +++ b/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_interface.h @@ -0,0 +1,99 @@ +/* + * Note: this file originally auto-generated by mib2c using + * version : 15899 $ of $ + * + * $Id:$ + */ +/** @ingroup interface: Routines to interface to Net-SNMP + * + * \warning This code should not be modified, called directly, + * or used to interpret functionality. It is subject to + * change at any time. + * + * @{ + */ +/* + * ********************************************************************* + * ********************************************************************* + * ********************************************************************* + * *** *** + * *** NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE *** + * *** *** + * *** *** + * *** THIS FILE DOES NOT CONTAIN ANY USER EDITABLE CODE. *** + * *** *** + * *** *** + * *** THE GENERATED CODE IS INTERNAL IMPLEMENTATION, AND *** + * *** *** + * *** *** + * *** IS SUBJECT TO CHANGE WITHOUT WARNING IN FUTURE RELEASES. *** + * *** *** + * *** *** + * ********************************************************************* + * ********************************************************************* + * ********************************************************************* + */ +#ifndef IPDEFAULTROUTERTABLE_INTERFACE_H +#define IPDEFAULTROUTERTABLE_INTERFACE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#include "ipDefaultRouterTable.h" + + + /* + ******************************************************************** + * Table declarations + */ + + /* + * PUBLIC interface initialization routine + */ + void + _ipDefaultRouterTable_initialize_interface + (ipDefaultRouterTable_registration * user_ctx, u_long flags); + void + _ipDefaultRouterTable_shutdown_interface + (ipDefaultRouterTable_registration * user_ctx); + + ipDefaultRouterTable_registration + *ipDefaultRouterTable_registration_get(void); + + ipDefaultRouterTable_registration + *ipDefaultRouterTable_registration_set + (ipDefaultRouterTable_registration * newreg); + + netsnmp_container *ipDefaultRouterTable_container_get(void); + int ipDefaultRouterTable_container_size(void); + + ipDefaultRouterTable_rowreq_ctx + *ipDefaultRouterTable_allocate_rowreq_ctx(ipDefaultRouterTable_data + *, void *); + void + ipDefaultRouterTable_release_rowreq_ctx + (ipDefaultRouterTable_rowreq_ctx * rowreq_ctx); + + int ipDefaultRouterTable_index_to_oid(netsnmp_index * + oid_idx, + ipDefaultRouterTable_mib_index + * mib_idx); + int ipDefaultRouterTable_index_from_oid(netsnmp_index * + oid_idx, + ipDefaultRouterTable_mib_index + * mib_idx); + + /* + * access to certain internals. use with caution! + */ + void + ipDefaultRouterTable_valid_columns_set(netsnmp_column_info *vc); + + +#ifdef __cplusplus +} +#endif +#endif /* IPDEFAULTROUTERTABLE_INTERFACE_H */ +/** @} */ diff --git a/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_oids.h b/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_oids.h new file mode 100644 index 0000000..6914e71 --- /dev/null +++ b/agent/mibgroup/ip-mib/ipDefaultRouterTable/ipDefaultRouterTable_oids.h @@ -0,0 +1,39 @@ +/* + * Note: this file originally auto-generated by mib2c using + * : generic-table-oids.m2c 12855 2005-09-27 15:56:08Z rstory $ + * + * $Id:$ + */ +#ifndef IPDEFAULTROUTERTABLE_OIDS_H +#define IPDEFAULTROUTERTABLE_OIDS_H + +#ifdef __cplusplus +extern "C" { +#endif + + + /* + * column number definitions for table ipDefaultRouterTable + */ +#define IPDEFAULTROUTERTABLE_OID 1,3,6,1,2,1,4,37 + +#define COLUMN_IPDEFAULTROUTERADDRESSTYPE 1 + +#define COLUMN_IPDEFAULTROUTERADDRESS 2 + +#define COLUMN_IPDEFAULTROUTERIFINDEX 3 + +#define COLUMN_IPDEFAULTROUTERLIFETIME 4 + +#define COLUMN_IPDEFAULTROUTERPREFERENCE 5 + + +#define IPDEFAULTROUTERTABLE_MIN_COL COLUMN_IPDEFAULTROUTERLIFETIME +#define IPDEFAULTROUTERTABLE_MAX_COL COLUMN_IPDEFAULTROUTERPREFERENCE + + + +#ifdef __cplusplus +} +#endif +#endif /* IPDEFAULTROUTERTABLE_OIDS_H */ diff --git a/agent/mibgroup/mibII/var_route.c b/agent/mibgroup/mibII/var_route.c index 0a811f3..3fa02ba 100644 --- a/agent/mibgroup/mibII/var_route.c +++ b/agent/mibgroup/mibII/var_route.c @@ -87,6 +87,7 @@ static size_t all_routes_size; extern const struct sockaddr *get_address(const void *, int, int); extern const struct in_addr *get_in_address(const void *, int, int); + /* * var_ipRouteEntry(... * Arguments: diff --git a/configure.in b/configure.in index 3ad7955..c5e05ba 100644 --- a/configure.in +++ b/configure.in @@ -3342,6 +3342,29 @@ typedef __u32 u32; /* ditto */ typedef __u16 u16; /* ditto */ typedef __u8 u8; /* ditto */ ]]) +# linux netlink +AC_CHECK_HEADERS(linux/netlink.h,,, +[[ +#if HAVE_ASM_TYPES_H +#include +#endif +#if HAVE_SYS_SOCKET_H +#include +#endif +]]) +# linux rtnetlink +AC_CHECK_HEADERS(linux/rtnetlink.h,,, +[[ +#if HAVE_ASM_TYPES_H +#include +#endif +#if HAVE_SYS_SOCKET_H +#include +#endif +#if HAVE_LINUX_NETLINK_H +#include +#endif +]]) # BSDi3 headers AC_CHECK_HEADERS(sys/stat.h) # BSDi3/IRIX headers diff --git a/include/net-snmp/data_access/defaultrouter.h b/include/net-snmp/data_access/defaultrouter.h new file mode 100644 index 0000000..93ac18f --- /dev/null +++ b/include/net-snmp/data_access/defaultrouter.h @@ -0,0 +1,114 @@ +/* + * defaultrouter data access header + * + * $Id:$ + */ +#ifndef NETSNMP_ACCESS_DEFAULTROUTER_H +#define NETSNMP_ACCESS_DEFAULTROUTER_H + +# ifdef __cplusplus +extern "C" { +#endif + +/**---------------------------------------------------------------------*/ +/* + * structure definitions + */ +#if defined( NETSNMP_ENABLE_IPV6 ) +# define NETSNMP_ACCESS_DEFAULTROUTER_BUF_SIZE 16 /* XXX: 20, for ip6z? */ +#else +# define NETSNMP_ACCESS_DEFAULTROUTER_BUF_SIZE 4 +#endif + + +/* + * netsnmp_default_route_entry + */ +typedef struct netsnmp_defaultrouter_s { + + netsnmp_index oid_index; /* MUST BE FIRST!! for container use */ + oid ns_dr_index; /* arbitrary index */ + + int flags; /* for net-snmp use */ + + /* + * mib related data + */ + u_char dr_addresstype; /* ipDefaultRouterAddressType */ + char dr_address[NETSNMP_ACCESS_DEFAULTROUTER_BUF_SIZE]; /* ipDefaultRouterAddress */ + size_t dr_address_len; /* length of ipDefaultRouterAddress */ + oid dr_if_index; /* ipDefaultRouterIfIndex */ + uint32_t dr_lifetime; /* ipDefaultRouterLifetime (0-65535) */ + char dr_preference; /* ipDefaultRouterPreference (-2,-1,0,1) */ + +} netsnmp_defaultrouter_entry; + + +/**---------------------------------------------------------------------*/ +/* + * ACCESS function prototypes + */ +/* + * container init + */ +netsnmp_container * +netsnmp_access_defaultrouter_container_init(u_int flags); +#define NETSNMP_ACCESS_DEFAULTROUTER_INIT_NOFLAGS 0x0000 +#define NETSNMP_ACCESS_DEFAULTROUTER_INIT_ADDL_IDX_BY_ADDR 0x0001 + +/* + * container load + */ +netsnmp_container* +netsnmp_access_defaultrouter_container_load(netsnmp_container* container, + u_int load_flags); +#define NETSNMP_ACCESS_DEFAULTROUTER_LOAD_NOFLAGS 0x0000 +#define NETSNMP_ACCESS_DEFAULTROUTER_LOAD_IPV4_ONLY 0x0001 +#define NETSNMP_ACCESS_DEFAULTROUTER_LOAD_IPV6_ONLY 0x0002 +#define NETSNMP_ACCESS_DEFAULTROUTER_LOAD_ADDL_IDX_BY_ADDR 0x0004 + +/* + * container free + */ +void +netsnmp_access_defaultrouter_container_free(netsnmp_container *container, + u_int free_flags); +#define NETSNMP_ACCESS_DEFAULTROUTER_FREE_NOFLAGS 0x0000 +#define NETSNMP_ACCESS_DEFAULTROUTER_FREE_DONT_CLEAR 0x0001 +#define NETSNMP_ACCESS_DEFAULTROUTER_FREE_KEEP_CONTAINER 0x0002 + +/* + * entry create + */ +netsnmp_defaultrouter_entry * +netsnmp_access_defaultrouter_entry_create(void); + +/* + * entry load + */ +int +netsnmp_access_defaultrouter_entry_load(size_t *num_entries, + netsnmp_defaultrouter_entry **entries); + +/* + * entry update + */ +int +netsnmp_access_defaultrouter_entry_update(netsnmp_defaultrouter_entry *lhs, + netsnmp_defaultrouter_entry *rhs); + +/* + * entry free + */ +void +netsnmp_access_defaultrouter_entry_free(netsnmp_defaultrouter_entry *entry); + + + +/**---------------------------------------------------------------------*/ + +# ifdef __cplusplus +} +#endif + +#endif /* NETSNMP_ACCESS_DEFAULTROUTER_H */ -- 1.6.0.2