components/net-snmp/patches/003.solaris-ip-mib.patch
author Gabriel Carrillo <Gabriel.Carrillo@Oracle.COM>
Wed, 13 Jun 2012 09:33:37 -0700
branchs11-sru
changeset 2290 1eee62467178
parent 252 ee0fb1eabcbf
permissions -rw-r--r--
Added tag S11SRU9_02 for changeset d47b778ad3d1

--- net-snmp-5.4.1/agent/mibgroup/ip-mib/data_access/systemstats_solaris2.c	(revision 0)
+++ net-snmp-5.4.1-patch/agent/mibgroup/ip-mib/data_access/systemstats_solaris2.c	(revision 0)
@@ -0,0 +1,199 @@
+#include <net-snmp/net-snmp-config.h>
+#include <net-snmp/net-snmp-includes.h>
+
+#include <net-snmp/agent/net-snmp-agent-includes.h>
+#include <net-snmp/data_access/ipstats.h>
+#include <net-snmp/data_access/systemstats.h>
+
+#include "kernel_sunos5.h"
+
+static int _systemstats(mibgroup_e, netsnmp_container *, u_int);
+static void _add_ipstats(mib2_ipIfStatsEntry_t *, mib2_ipIfStatsEntry_t *);
+static int _insert_entry(netsnmp_container *, mib2_ipIfStatsEntry_t *);
+
+void
+netsnmp_access_systemstats_arch_init(void)
+{
+    init_kernel_sunos5();
+}
+
+/*
+ * @retval  0 success
+ * @retval -1 container error
+ * @retval -2 could not create entry (probably malloc)
+ */
+int
+netsnmp_access_systemstats_container_arch_load(netsnmp_container* container,
+                                             u_int load_flags)
+{
+    int rc; 
+    
+    if (container == NULL)
+        return (-1);
+
+    if ((rc = _systemstats(MIB_IP_TRAFFIC_STATS, container, load_flags)) < 0)
+        return (rc);
+#if defined(NETSNMP_ENABLE_IPV6)
+    if ((rc = _systemstats(MIB_IP6, container, load_flags)) < 0) {
+            netsnmp_access_systemstats_container_free(container,
+                NETSNMP_ACCESS_SYSTEMSTATS_FREE_NOFLAGS);
+        return (rc);
+    }
+#endif
+    return (0);
+}
+
+/*
+ * @retval 0 success 
+ * @retval <0 error
+ */
+static int
+_systemstats(mibgroup_e mib, netsnmp_container *container, u_int load_flags)
+{
+    mib2_ipIfStatsEntry_t ipe, iptot;
+    req_e req = GET_FIRST;
+    int ipversion = (mib == MIB_IP6) ? MIB2_INETADDRESSTYPE_ipv6 :
+                                       MIB2_INETADDRESSTYPE_ipv4;
+    bzero((void *)&iptot, sizeof(iptot));
+
+    while (getMibstat(mib, &ipe, sizeof(ipe), req, 
+                      &Get_everything, NULL) == 0) { 
+        req = GET_NEXT;
+        netsnmp_assert(ipe.ipIfStatsIPVersion == ipversion);
+        _add_ipstats(&iptot, &ipe);
+    }
+    iptot.ipIfStatsIPVersion = ipversion;
+    return _insert_entry(container, &iptot);
+}
+
+static void
+_add_ipstats(mib2_ipIfStatsEntry_t *o1, mib2_ipIfStatsEntry_t *o2)
+{
+    o1->ipIfStatsInHdrErrors += o2->ipIfStatsInHdrErrors;
+    o1->ipIfStatsInTooBigErrors += o2->ipIfStatsInTooBigErrors;
+    o1->ipIfStatsInNoRoutes += o2->ipIfStatsInNoRoutes;
+    o1->ipIfStatsInAddrErrors += o2->ipIfStatsInAddrErrors;
+    o1->ipIfStatsInUnknownProtos += o2->ipIfStatsInUnknownProtos;
+    o1->ipIfStatsInTruncatedPkts += o2->ipIfStatsInTruncatedPkts;
+    o1->ipIfStatsInDiscards += o2->ipIfStatsInDiscards;
+    o1->ipIfStatsOutDiscards += o2->ipIfStatsOutDiscards;
+    o1->ipIfStatsOutFragOKs += o2->ipIfStatsOutFragOKs;
+    o1->ipIfStatsOutFragFails += o2->ipIfStatsOutFragFails;
+    o1->ipIfStatsOutFragCreates += o2->ipIfStatsOutFragCreates;
+    o1->ipIfStatsReasmReqds += o2->ipIfStatsReasmReqds;
+    o1->ipIfStatsReasmOKs += o2->ipIfStatsReasmOKs;
+    o1->ipIfStatsReasmFails += o2->ipIfStatsReasmFails;
+    o1->ipIfStatsOutNoRoutes += o2->ipIfStatsOutNoRoutes;
+    o1->ipIfStatsReasmDuplicates += o2->ipIfStatsReasmDuplicates;
+    o1->ipIfStatsReasmPartDups += o2->ipIfStatsReasmPartDups;
+    o1->ipIfStatsForwProhibits += o2->ipIfStatsForwProhibits;
+    o1->udpInCksumErrs += o2->udpInCksumErrs;
+    o1->udpInOverflows += o2->udpInOverflows;
+    o1->rawipInOverflows += o2->rawipInOverflows;
+    o1->ipIfStatsInWrongIPVersion += o2->ipIfStatsInWrongIPVersion;
+    o1->ipIfStatsOutWrongIPVersion += o2->ipIfStatsOutWrongIPVersion;
+    o1->ipIfStatsOutSwitchIPVersion += o2->ipIfStatsOutSwitchIPVersion;
+    o1->ipIfStatsHCInReceives += o2->ipIfStatsHCInReceives;
+    o1->ipIfStatsHCInOctets += o2->ipIfStatsHCInOctets;
+    o1->ipIfStatsHCInForwDatagrams += o2->ipIfStatsHCInForwDatagrams;
+    o1->ipIfStatsHCInDelivers += o2->ipIfStatsHCInDelivers;
+    o1->ipIfStatsHCOutRequests += o2->ipIfStatsHCOutRequests;
+    o1->ipIfStatsHCOutForwDatagrams += o2->ipIfStatsHCOutForwDatagrams;
+    o1->ipIfStatsOutFragReqds += o2->ipIfStatsOutFragReqds;
+    o1->ipIfStatsHCOutTransmits += o2->ipIfStatsHCOutTransmits;
+    o1->ipIfStatsHCOutOctets += o2->ipIfStatsHCOutOctets;
+    o1->ipIfStatsHCInMcastPkts += o2->ipIfStatsHCInMcastPkts;
+    o1->ipIfStatsHCInMcastOctets += o2->ipIfStatsHCInMcastOctets;
+    o1->ipIfStatsHCOutMcastPkts += o2->ipIfStatsHCOutMcastPkts;
+    o1->ipIfStatsHCOutMcastOctets += o2->ipIfStatsHCOutMcastOctets;
+    o1->ipIfStatsHCInBcastPkts += o2->ipIfStatsHCInBcastPkts;
+    o1->ipIfStatsHCOutBcastPkts += o2->ipIfStatsHCOutBcastPkts;
+    o1->ipsecInSucceeded += o2->ipsecInSucceeded;
+    o1->ipsecInFailed += o2->ipsecInFailed;
+    o1->ipInCksumErrs += o2->ipInCksumErrs;
+    o1->tcpInErrs += o2->tcpInErrs;
+    o1->udpNoPorts += o2->udpNoPorts;
+}
+
+/*
+ * @retval 0 entry was successfully inserted in the container 
+ * @retval -1 container error
+ * @retval -2 memory allocation error
+ */
+static int 
+_insert_entry(netsnmp_container *container, mib2_ipIfStatsEntry_t *ipe)
+{
+    netsnmp_systemstats_entry *ep =
+        netsnmp_access_systemstats_entry_create(ipe->ipIfStatsIPVersion); 
+
+    DEBUGMSGTL(("access:systemstats:arch", "insert entry for v%d\n",
+                ipe->ipIfStatsIPVersion)); 
+    if (ep == NULL) {
+        DEBUGMSGT(("access:systemstats:arch", "insert failed (alloc)"));
+        return (-2);
+    }
+
+    ep->stats.HCInReceives.low = 
+        ipe->ipIfStatsHCInReceives & 0xffffffff;
+    ep->stats.HCInReceives.high = ipe->ipIfStatsHCInReceives >> 32;
+    ep->stats.HCInOctets.low = 
+        ipe->ipIfStatsHCInOctets & 0xffffffff;
+    ep->stats.HCInOctets.high = ipe->ipIfStatsHCInOctets >> 32;
+    ep->stats.InHdrErrors = ipe->ipIfStatsInHdrErrors;
+    ep->stats.InAddrErrors = ipe->ipIfStatsInAddrErrors;
+    ep->stats.InUnknownProtos = ipe->ipIfStatsInUnknownProtos;
+    ep->stats.InTruncatedPkts = ipe->ipIfStatsInTruncatedPkts;
+    ep->stats.HCInForwDatagrams.low = 
+        ipe->ipIfStatsHCInForwDatagrams & 0xffffffff;
+    ep->stats.HCInForwDatagrams.high = 
+        ipe->ipIfStatsHCInForwDatagrams >> 32;
+    ep->stats.ReasmReqds = ipe->ipIfStatsReasmReqds; 
+    ep->stats.ReasmOKs = ipe->ipIfStatsReasmOKs; 
+    ep->stats.ReasmFails = ipe->ipIfStatsReasmFails; 
+    ep->stats.InDiscards = ipe->ipIfStatsInDiscards;
+    ep->stats.HCInDelivers.low = 
+        ipe->ipIfStatsHCInDelivers & 0xffffffff; 
+    ep->stats.HCInDelivers.high = 
+        ipe->ipIfStatsHCInDelivers >> 32; 
+    ep->stats.HCOutRequests.low = 
+        ipe->ipIfStatsHCOutRequests & 0xffffffff;
+    ep->stats.HCOutRequests.high = 
+        ipe->ipIfStatsHCOutRequests >> 32; 
+    ep->stats.OutNoRoutes = ipe->ipIfStatsOutNoRoutes; 
+    ep->stats.HCOutForwDatagrams.low = 
+        ipe->ipIfStatsHCOutForwDatagrams & 0xffffffff;
+    ep->stats.HCOutForwDatagrams.high = 
+        ipe->ipIfStatsHCOutForwDatagrams >> 32;
+    ep->stats.OutDiscards = ipe->ipIfStatsOutDiscards; 
+    ep->stats.OutFragOKs = ipe->ipIfStatsOutFragOKs; 
+    ep->stats.OutFragFails = ipe->ipIfStatsOutFragFails; 
+    ep->stats.OutFragCreates = ipe->ipIfStatsOutFragCreates; 
+    ep->stats.HCOutTransmits.low = 
+        ipe->ipIfStatsHCOutTransmits & 0xffffffff;
+    ep->stats.HCOutTransmits.high = ipe->ipIfStatsHCOutTransmits >> 32;
+    ep->stats.HCOutOctets.low = ipe->ipIfStatsHCOutOctets & 0xffffffff;
+    ep->stats.HCOutOctets.high = ipe->ipIfStatsHCOutOctets >> 32;
+    ep->stats.HCInMcastPkts.low = ipe->ipIfStatsHCInMcastPkts & 0xffffffff;
+    ep->stats.HCInMcastPkts.high = ipe->ipIfStatsHCInMcastPkts >> 32;
+    ep->stats.HCInMcastOctets.low = 
+        ipe->ipIfStatsHCInMcastOctets & 0xffffffff;
+    ep->stats.HCInMcastOctets.high = ipe->ipIfStatsHCInMcastOctets >> 32;
+    ep->stats.HCOutMcastPkts.low = 
+        ipe->ipIfStatsHCOutMcastPkts & 0xffffffff;
+    ep->stats.HCOutMcastPkts.high = ipe->ipIfStatsHCOutMcastPkts >> 32;
+    ep->stats.HCOutMcastOctets.low = 
+        ipe->ipIfStatsHCOutMcastOctets & 0xffffffff;
+    ep->stats.HCOutMcastOctets.high = ipe->ipIfStatsHCOutMcastOctets >> 32;
+    ep->stats.HCInBcastPkts.low = ipe->ipIfStatsHCInBcastPkts & 0xffffffff;
+    ep->stats.HCInBcastPkts.high = ipe->ipIfStatsHCInBcastPkts >> 32;
+    ep->stats.HCOutBcastPkts.low = 
+        ipe->ipIfStatsHCOutBcastPkts & 0xffffffff;
+    ep->stats.HCOutBcastPkts.high = ipe->ipIfStatsHCOutBcastPkts >> 32;
+
+    if (CONTAINER_INSERT(container, ep) < 0) {
+        DEBUGMSGT(("access:systemstats:arch", "unable to insert entry")); 
+        netsnmp_access_systemstats_entry_free(ep); 
+        return (-1);
+    }
+    return (0);
+}
--- net-snmp-5.4.1/agent/mibgroup/ip-mib/data_access/ipaddress_solaris2.c	(revision 0)
+++ net-snmp-5.4.1-patch/agent/mibgroup/ip-mib/data_access/ipaddress_solaris2.c	(revision 0)
@@ -0,0 +1,286 @@
+/*
+ *  IP-MIB architecture support
+ *
+ */
+#include <net-snmp/net-snmp-config.h>
+#include <net-snmp/net-snmp-includes.h>
+
+#include <net-snmp/agent/net-snmp-agent-includes.h>
+#include <net-snmp/data_access/ipaddress.h>
+#include <net-snmp/data_access/interface.h>
+
+#include "ip-mib/ipAddressTable/ipAddressTable_constants.h"
+
+#include "kernel_sunos5.h"
+#include "mibII/mibII_common.h"
+
+static int _load_v4(netsnmp_container *container, int idx_offset);
+#if defined( NETSNMP_ENABLE_IPV6 )
+static int _load_v6(netsnmp_container *container, int idx_offset);
+#endif
+
+/*
+ * initialize arch specific storage
+ *
+ * @retval  0: success
+ * @retval <0: error
+ */
+int
+netsnmp_arch_ipaddress_entry_init(netsnmp_ipaddress_entry *entry)
+{
+    init_kernel_sunos5();
+    return 0;
+}
+
+/*
+ * cleanup arch specific storage
+ */
+void
+netsnmp_arch_ipaddress_entry_cleanup(netsnmp_ipaddress_entry *entry)
+{
+    /*
+     * Nothing to do.
+     */
+}
+
+/*
+ * copy arch specific storage
+ */
+int
+netsnmp_arch_ipaddress_entry_copy(netsnmp_ipaddress_entry *lhs,
+                                  netsnmp_ipaddress_entry *rhs)
+{
+    /*
+     * Nothing to do. 
+     */
+    return 0;
+}
+
+/*
+ * create a new entry
+ */
+int
+netsnmp_arch_ipaddress_create(netsnmp_ipaddress_entry *entry)
+{
+    if (NULL == entry)
+        return -1;
+
+    DEBUGMSGT(("access:ipaddress:create", "not applicable\n"));
+        return 0;
+}
+
+/*
+ * delete an entry
+ */
+int
+netsnmp_arch_ipaddress_delete(netsnmp_ipaddress_entry *entry)
+{
+    if (NULL == entry)
+        return -1;
+
+    DEBUGMSGT(("access:ipaddress:create", "not applicable\n"));
+    return 0;
+}
+
+/**
+ *
+ * @retval  0 no errors
+ * @retval !0 errors
+ */
+int
+netsnmp_arch_ipaddress_container_load(netsnmp_container *container,
+                                      u_int load_flags)
+{
+    int rc = 0, idx_offset = 0;
+
+    if (!(load_flags & NETSNMP_ACCESS_IPADDRESS_LOAD_IPV6_ONLY)) {
+        rc = _load_v4(container, idx_offset);
+        if(rc < 0) {
+            u_int flags = NETSNMP_ACCESS_IPADDRESS_FREE_KEEP_CONTAINER;
+            netsnmp_access_ipaddress_container_free(container, flags);
+        }
+    }
+
+#if defined( NETSNMP_ENABLE_IPV6 )
+
+    if (!(load_flags & NETSNMP_ACCESS_IPADDRESS_LOAD_IPV4_ONLY)) {
+        if (rc < 0)
+            rc = 0;
+
+        idx_offset = rc;
+
+        rc = _load_v6(container, idx_offset);
+        if(rc < 0) {
+            u_int flags = NETSNMP_ACCESS_IPADDRESS_FREE_KEEP_CONTAINER;
+            netsnmp_access_ipaddress_container_free(container, flags);
+        }
+    }
+#endif
+
+    /*
+     * return no errors (0) if we found any interfaces
+     */
+    if(rc > 0)
+        rc = 0;
+    return rc;
+}
+
+/*
+ * @retval >=idx_offset ok
+ * @retval -1 memory allocation error
+ * @retval -2 interface lookup error
+ * @retval -3 container error
+ */
+static int
+_load_v4(netsnmp_container *container, int idx_offset)
+{
+    mib2_ipAddrEntry_t      ipae;
+    netsnmp_ipaddress_entry *entry;
+    req_e                   req = GET_FIRST;
+    int                     rc = 0;
+
+    DEBUGMSGTL(("access:ipaddress:container", "loading v4\n"));
+    while ((rc = getMibstat(MIB_IP_ADDR, &ipae, sizeof(ipae), req,
+                            &Get_everything, NULL)) == 0) {
+        req = GET_NEXT;
+        entry = netsnmp_access_ipaddress_entry_create();
+        if (entry == NULL)
+            return (-1);    
+        if (ipae.ipAdEntAddr == INADDR_ANY)
+            continue;
+
+        ipae.ipAdEntIfIndex.o_bytes[ipae.ipAdEntIfIndex.o_length] = '\0';
+        DEBUGMSGTL(("access:ipaddress:container", "found if %s\n",
+                    ipae.ipAdEntIfIndex.o_bytes));
+        /* Obtain interface index */
+        entry->if_index = 
+            netsnmp_access_interface_index_find(ipae.ipAdEntIfIndex.o_bytes);
+        if (entry->if_index == 0) {
+            DEBUGMSGTL(("access:ipaddress:container", "cannot find if %s\n",
+                        ipae.ipAdEntIfIndex));
+            netsnmp_access_ipaddress_entry_free(entry);
+            return (-2);    
+        }
+
+        if (strchr((const char *)&ipae.ipAdEntIfIndex.o_bytes, ':') != 0)
+            entry->flags |= NETSNMP_ACCESS_IPADDRESS_ISALIAS;
+
+        /* Get the address */
+        entry->ia_address_len = sizeof(ipae.ipAdEntAddr);
+        netsnmp_assert(entry->ia_address_len == 4 &&
+            entry->ia_address_len <= sizeof(entry->ia_address));
+        memcpy(&entry->ia_address, &ipae.ipAdEntAddr, entry->ia_address_len);
+
+        /* prefix */
+        entry->ia_prefix_len = ipae.ipAdEntInfo.ae_subnet_len;
+
+        /* set the Origin */
+        if (ipae.ipAdEntInfo.ae_flags & IFF_DHCPRUNNING)
+            entry->ia_origin = IPADDRESSORIGINTC_DHCP;
+        else
+            entry->ia_origin = IPADDRESSORIGINTC_MANUAL;
+
+        /* set ipv4 constants */
+        entry->ia_type = IPADDRESSTYPE_UNICAST;
+        entry->ia_status = IPADDRESSSTATUSTC_PREFERRED;
+
+        entry->ns_ia_index = ++idx_offset;
+
+        DEBUGMSGTL(("access:ipaddress:container", "insert if %d, addrlen %d\n", 
+                    entry->if_index, entry->ia_address_len));
+
+        if (CONTAINER_INSERT(container, entry) < 0) {
+            DEBUGMSGTL(("access:ipaddress:container", "unable to insert %s\n", 
+                        ipae.ipAdEntIfIndex.o_bytes));
+            netsnmp_access_ipaddress_entry_free(entry);
+            return (-3);
+        }
+    }
+    return (idx_offset);
+}
+
+/*
+ * @retval >=idx_offset ok
+ * @retval -1 memory allocation error
+ * @retval -2 interface lookup error
+ * @retval -3 container error
+ */
+#if defined( NETSNMP_ENABLE_IPV6 )
+static int
+_load_v6(netsnmp_container *container, int idx_offset)
+{
+    mib2_ipv6AddrEntry_t    ip6ae;
+    netsnmp_ipaddress_entry *entry;
+    req_e                   req = GET_FIRST;
+    int                     rc = 0;
+
+    DEBUGMSGTL(("access:ipaddress:container", "loading v6... cache %d\n",
+                MIB_IP6_ADDR));
+    while ((rc = getMibstat(MIB_IP6_ADDR, &ip6ae, sizeof(ip6ae), req,
+                            &Get_everything, NULL)) == 0) {
+        req = GET_NEXT;
+        entry = netsnmp_access_ipaddress_entry_create();
+        if (entry == NULL)
+            return (-1);    
+        if (bcmp((const void *)&ip6ae.ipv6AddrAddress,
+                 (const void *)&in6addr_any,
+                 sizeof (ip6ae.ipv6AddrAddress)) == 0)
+            continue;
+
+        ip6ae.ipv6AddrIfIndex.o_bytes[ip6ae.ipv6AddrIfIndex.o_length] = '\0';
+        DEBUGMSGTL(("access:ipaddress:container", "found if %s\n",
+                    ip6ae.ipv6AddrIfIndex.o_bytes));
+
+        /* Obtain interface index */
+        entry->if_index = 
+            netsnmp_access_interface_index_find(
+            ip6ae.ipv6AddrIfIndex.o_bytes);
+        if (entry->if_index == 0) {
+            DEBUGMSGTL(("access:ipaddress:container", "cannot find if %s\n", 
+                        ip6ae.ipv6AddrIfIndex.o_bytes));
+            netsnmp_access_ipaddress_entry_free(entry);
+            return (-2);    
+        }
+
+        /* Get the address */
+        entry->ia_address_len = sizeof(ip6ae.ipv6AddrAddress);
+        netsnmp_assert(entry->ia_address_len == 16 &&
+                       entry->ia_address_len <= sizeof(entry->ia_address));
+        memcpy(&entry->ia_address, &ip6ae.ipv6AddrAddress, 
+               entry->ia_address_len);
+               
+        /* prefix */
+        entry->ia_prefix_len = ip6ae.ipv6AddrPfxLength;
+
+        /* type is anycast? (mib2.h: 1 = yes, 2 = no) */
+        entry->ia_type = (ip6ae.ipv6AddrAnycastFlag == 1) ? 
+            IPADDRESSTYPE_ANYCAST : IPADDRESSTYPE_UNICAST;
+
+        /* origin (mib2.h: 1 = stateless, 2 = stateful, 3 = unknown) */
+        DEBUGMSGTL(("access:ipaddress:container", "origin %d\n", 
+                        ip6ae.ipv6AddrType));
+        if (ip6ae.ipv6AddrType == 1)
+            entry->ia_origin = IPADDRESSORIGINTC_LINKLAYER;
+        else if (ip6ae.ipv6AddrInfo.ae_flags & IFF_DHCPRUNNING)
+            entry->ia_origin = IPADDRESSORIGINTC_DHCP;
+        else
+            entry->ia_origin = IPADDRESSORIGINTC_MANUAL;
+        
+        /* status */
+        entry->ia_status = ip6ae.ipv6AddrStatus;
+
+        entry->ns_ia_index = ++idx_offset;
+        
+        DEBUGMSGTL(("access:ipaddress:container", "insert if %d, addrlen %d\n", 
+                    entry->if_index, entry->ia_address_len));
+
+        if (CONTAINER_INSERT(container, entry) < 0) {
+            DEBUGMSGTL(("access:ipaddress:container", "unable to insert %s\n", 
+                        ip6ae.ipv6AddrIfIndex.o_bytes));
+            netsnmp_access_ipaddress_entry_free(entry);
+            return (-3);
+        }
+    }    
+    return (idx_offset);
+}
+#endif /* defined( NETSNMP_ENABLE_IPV6 ) */