SF.net SVN: gar:[24493] csw/mgar/pkg/netsnmp/trunk
cgrzemba at users.sourceforge.net
cgrzemba at users.sourceforge.net
Fri Dec 19 13:32:23 CET 2014
Revision: 24493
http://sourceforge.net/p/gar/code/24493
Author: cgrzemba
Date: 2014-12-19 12:32:22 +0000 (Fri, 19 Dec 2014)
Log Message:
-----------
netsnmp/trunk: split off special SunOS5.11 patch
Modified Paths:
--------------
csw/mgar/pkg/netsnmp/trunk/Makefile
csw/mgar/pkg/netsnmp/trunk/files/0035-bug-1849903.patch
csw/mgar/pkg/netsnmp/trunk/files/0052-dyn-cpu-cpu_kstat.patch
Added Paths:
-----------
csw/mgar/pkg/netsnmp/trunk/files/0024-kernel_sunos5.5.10.patch
csw/mgar/pkg/netsnmp/trunk/files/0024-kernel_sunos5.5.11.patch
Removed Paths:
-------------
csw/mgar/pkg/netsnmp/trunk/files/0024-kernel_sunos5.patch
Modified: csw/mgar/pkg/netsnmp/trunk/Makefile
===================================================================
--- csw/mgar/pkg/netsnmp/trunk/Makefile 2014-12-19 12:18:08 UTC (rev 24492)
+++ csw/mgar/pkg/netsnmp/trunk/Makefile 2014-12-19 12:32:22 UTC (rev 24493)
@@ -39,7 +39,7 @@
PATCHFILES += 0011-Makefile.in.patch
PATCHFILES += 0012-Makefile.PL.patch
PATCHFILES += 0015+0016-vmstat_solaris2.patch
-PATCHFILES += 0024-kernel_sunos5.patch
+PATCHFILES += 0024-kernel_sunos5.$(GAROSREL).patch
PATCHFILES += 0034-manpage-snmptrapd.conf.5.def.patch
PATCHFILES += 0035-bug-1849903.patch
PATCHFILES += 0048+0027-mnt-cache-hr_filesys.patch
@@ -51,7 +51,7 @@
# GARCOMPILER = SOS12U3
GARCOMPILER = GCC4
BUILD_DEP_PKGS = CSWpy-setuptools
-PACKAGING_PLATFORMS += solaris10-sparc solaris10-i386
+PACKAGING_PLATFORMS += solaris10-sparc solaris10-i386 solaris11-sparc solaris11-i386
INITSMF = $(sysconfdir)/init.d/netsnmpd
INITSMF += $(sysconfdir)/init.d/netsnmptrapd
Added: csw/mgar/pkg/netsnmp/trunk/files/0024-kernel_sunos5.5.10.patch
===================================================================
--- csw/mgar/pkg/netsnmp/trunk/files/0024-kernel_sunos5.5.10.patch (rev 0)
+++ csw/mgar/pkg/netsnmp/trunk/files/0024-kernel_sunos5.5.10.patch 2014-12-19 12:32:22 UTC (rev 24493)
@@ -0,0 +1,561 @@
+--- a/agent/mibgroup/kernel_sunos5.c
++++ b/agent/mibgroup/kernel_sunos5.c
+@@ -82,15 +84,15 @@ kstat_ctl_t *kstat_fd = 0;
+ static
+ mibcache Mibcache[MIBCACHE_SIZE+1] = {
+ {MIB_SYSTEM, 0, (void *) -1, 0, 0, 0, 0},
+- {MIB_INTERFACES, 50 * sizeof(mib2_ifEntry_t), (void *) -1, 0, 30, 0,
++ {MIB_INTERFACES, 128 * sizeof(mib2_ifEntry_t), (void *) -1, 0, 30, 0,
+ 0},
+ {MIB_AT, 0, (void *) -1, 0, 0, 0, 0},
+ {MIB_IP, sizeof(mib2_ip_t), (void *) -1, 0, 60, 0, 0},
+- {MIB_IP_ADDR, 20 * sizeof(mib2_ipAddrEntry_t), (void *) -1, 0, 60, 0,
++ {MIB_IP_ADDR, 128 * sizeof(mib2_ipAddrEntry_t), (void *) -1, 0, 60, 0,
+ 0},
+- {MIB_IP_ROUTE, 200 * sizeof(mib2_ipRouteEntry_t), (void *) -1, 0, 30,
++ {MIB_IP_ROUTE, 400 * sizeof(mib2_ipRouteEntry_t), (void *) -1, 0, 30,
+ 0, 0},
+- {MIB_IP_NET, 100 * sizeof(mib2_ipNetToMediaEntry_t), (void *) -1, 0,
++ {MIB_IP_NET, 400 * sizeof(mib2_ipNetToMediaEntry_t), (void *) -1, 0,
+ 300, 0, 0},
+ {MIB_ICMP, sizeof(mib2_icmp_t), (void *) -1, 0, 60, 0, 0},
+ {MIB_TCP, sizeof(mib2_tcp_t), (void *) -1, 0, 60, 0, 0},
+@@ -105,13 +107,13 @@ mibcache Mibcache[MIBCACHE_SIZE+1] = {
+ {MIB_SNMP, 0, (void *) -1, 0, 0, 0, 0},
+ #ifdef SOLARIS_HAVE_IPV6_MIB_SUPPORT
+ #ifdef SOLARIS_HAVE_RFC4293_SUPPORT
+- {MIB_IP_TRAFFIC_STATS, 20 * sizeof(mib2_ipIfStatsEntry_t), (void *)-1, 0,
++ {MIB_IP_TRAFFIC_STATS, 128 * sizeof(mib2_ipIfStatsEntry_t), (void *)-1, 0,
+ 30, 0, 0},
+- {MIB_IP6, 20 * sizeof(mib2_ipIfStatsEntry_t), (void *)-1, 0, 30, 0, 0},
++ {MIB_IP6, 128 * sizeof(mib2_ipIfStatsEntry_t), (void *)-1, 0, 30, 0, 0},
+ #else
+- {MIB_IP6, 20 * sizeof(mib2_ipv6IfStatsEntry_t), (void *)-1, 0, 30, 0, 0},
++ {MIB_IP6, 128 * sizeof(mib2_ipv6IfStatsEntry_t), (void *)-1, 0, 30, 0, 0},
+ #endif
+- {MIB_IP6_ADDR, 20 * sizeof(mib2_ipv6AddrEntry_t), (void *)-1, 0, 30, 0, 0},
++ {MIB_IP6_ADDR, 128 * sizeof(mib2_ipv6AddrEntry_t), (void *)-1, 0, 30, 0, 0},
+ {MIB_TCP6_CONN, 1000 * sizeof(mib2_tcp6ConnEntry_t), (void *) -1, 0, 30,
+ 0, 0},
+ {MIB_UDP6_ENDPOINT, 1000 * sizeof(mib2_udp6Entry_t), (void *) -1, 0, 30,
+@@ -184,7 +186,7 @@ getif(mib2_ifEntry_t *ifbuf, size_t size, req_e req_type, mib2_ifEntry_t *resp,
+ size_t *length, int (*comp)(void *, void *), void *arg);
+ static void
+ set_if_info(mib2_ifEntry_t *ifp, unsigned index, char *name, uint64_t flags,
+- int mtu);
++ boolean_t flags_unknown, int mtu);
+ static int get_if_stats(mib2_ifEntry_t *ifp);
+
+ #if defined(HAVE_IF_NAMEINDEX) && defined(NETSNMP_INCLUDE_IFTABLE_REWRITES)
+@@ -294,7 +296,9 @@ getKstatInt(const char *classname, const char *statname,
+ kstat_t *ks;
+ kid_t kid;
+ kstat_named_t *named;
++
+ int ret = -1; /* fail unless ... */
++ int lookup_stat = 0;
+
+ if (kstat_fd == 0) {
+ kstat_fd = kstat_open();
+@@ -305,27 +309,88 @@ getKstatInt(const char *classname, const char *statname,
+ if ((ksc = kstat_fd) == NULL) {
+ goto Return;
+ }
+- ks = kstat_lookup(ksc, classname, -1, statname);
+- if (ks == NULL) {
+- DEBUGMSGTL(("kernel_sunos5", "class %s, stat %s not found\n",
+- classname ? classname : "NULL",
+- statname ? statname : "NULL"));
+- goto Return;
+- }
+- kid = kstat_read(ksc, ks, NULL);
+- if (kid == -1) {
+- DEBUGMSGTL(("kernel_sunos5", "cannot read class %s stats %s\n",
+- classname ? classname : "NULL", statname ? statname : "NULL"));
+- goto Return;
+- }
+- named = kstat_data_lookup(ks, varname);
+- if (named == NULL) {
+- DEBUGMSGTL(("kernel_sunos5", "no var %s for class %s stat %s\n",
+- varname, classname ? classname : "NULL",
+- statname ? statname : "NULL"));
+- goto Return;
++
++ if ((ks = kstat_lookup(ksc, statname, -1, "link")) != NULL)
++ {
++ kid = kstat_read(ksc, ks, NULL);
++ if (kid == -1) {
++ DEBUGMSGTL(("kernel_sunos5", "cannot read class %s stats %s\n",
++ statname ? statname : "NULL", "link"));
++ }
++ else
++ {
++ named = kstat_data_lookup(ks, varname);
++ if (named == NULL) {
++ DEBUGMSGTL(("kernel_sunos5", "no var %s for class %s stat %s\n",
++ varname, statname ? statname : "NULL", "link"));
++ }
++ else {
++ switch (named->data_type) {
++#ifdef KSTAT_DATA_INT32 /* Solaris 2.6 and up */
++ case KSTAT_DATA_INT32:
++ if(named->value.i32)
++ lookup_stat = 1;
++ break;
++ case KSTAT_DATA_UINT32:
++ if(named->value.ui32)
++ lookup_stat = 1;
++ break;
++ case KSTAT_DATA_INT64:
++ if(named->value.i64)
++ lookup_stat = 1;
++ break;
++ case KSTAT_DATA_UINT64:
++ if(named->value.ui64)
++ lookup_stat = 1;
++ break;
++#else
++ case KSTAT_DATA_LONG:
++ if(named->value.l)
++ lookup_stat = 1;
++ break;
++ case KSTAT_DATA_ULONG:
++ if(named->value.ul)
++ lookup_stat = 1;
++ break;
++ case KSTAT_DATA_LONGLONG:
++ if(named->value.ll)
++ lookup_stat = 1;
++ break;
++ case KSTAT_DATA_ULONGLONG:
++ if(named->value.ull)
++ lookup_stat = 1;
++ break;
++#endif
++ }
++ }
++ }
+ }
+-
++
++ if(!lookup_stat)
++ {
++ ks = kstat_lookup(ksc, classname, -1, statname);
++ if (ks == NULL) {
++ DEBUGMSGTL(("kernel_sunos5", "class %s, stat %s not found\n",
++ classname ? classname : "NULL",
++ statname ? statname : "NULL"));
++ goto Return;
++ }
++
++ kid = kstat_read(ksc, ks, NULL);
++ if (kid == -1) {
++ DEBUGMSGTL(("kernel_sunos5", "cannot read class %s stats %s\n",
++ classname ? classname : "NULL", statname ? statname : "NULL"));
++ goto Return;
++ }
++
++ named = kstat_data_lookup(ks, varname);
++ if (named == NULL) {
++ DEBUGMSGTL(("kernel_sunos5", "no var %s for class %s stat %s\n",
++ varname, classname ? classname : "NULL",
++ statname ? statname : "NULL"));
++ goto Return;
++ }
++ }
+ ret = 0; /* maybe successful */
+ switch (named->data_type) {
+ #ifdef KSTAT_DATA_INT32 /* Solaris 2.6 and up */
+@@ -442,11 +507,20 @@ getKstat(const char *statname, const char *varname, void *value)
+ /*
+ * Get the named statistics
+ */
+- if ((ks = kstat_lookup(ksc, module_name, instance, statname)) == NULL) {
+- ret = -10;
+- goto Return; /* kstat errors */
+- }
+
++ if ((ks = kstat_lookup(ksc, module_name, instance, statname)) == NULL)
++ {
++ /*
++ * Try to lookup the kstat module with
++ * modulename = linkname and statname = "link".
++ */
++
++ if ((ks = kstat_lookup(ksc, statname, 0, "link")) == NULL) {
++ ret = -10;
++ goto Return; /* kstat errors */
++ }
++ }
++
+ if (kstat_read(ksc, ks, NULL) <= 0) {
+ ret = -10;
+ goto Return; /* kstat errors */
+@@ -1080,18 +1154,21 @@ getmib(int groupname, int subgroupname, void **statbuf, size_t *size,
+ static int
+ _dlpi_open(const char *devname)
+ {
+- char *devstr;
++ char devstr[255], devstrcpy[255];
+ int fd = -1;
+ int ppa = -1;
++ int ret = -1;
+
+ DEBUGMSGTL(("kernel_sunos5", "_dlpi_open called\n"));
+
+ if (devname == NULL)
+- return (-1);
++ return (-1);
++
++ ret = snprintf(devstr, sizeof(devstr), "/dev/%s", devname);
+
+- if ((devstr = malloc(5 + strlen(devname) + 1)) == NULL)
+- return (-1);
+- (void) sprintf(devstr, "/dev/%s", devname);
++ if(ret < 0 || ret > sizeof(devstr) - 1)
++ return -1;
++
+ DEBUGMSGTL(("kernel_sunos5:dlpi", "devstr(%s)\n", devstr));
+ /*
+ * First try opening the device using style 1, if the device does not
+@@ -1102,13 +1179,49 @@ _dlpi_open(const char *devname)
+ DEBUGMSGTL(("kernel_sunos5:dlpi", "style1 open(%s)\n", devstr));
+ if ((fd = open(devstr, O_RDWR | O_NONBLOCK)) < 0) {
+ DEBUGMSGTL(("kernel_sunos5:dlpi", "style1 open failed\n"));
+- if (_dlpi_parse_devname(devstr, &ppa) == 0) {
+- DEBUGMSGTL(("kernel_sunos5:dlpi", "style2 parse: %s, %d\n",
+- devstr, ppa));
+- /* try style 2 */
+- DEBUGMSGTL(("kernel_sunos5:dlpi", "style2 open(%s)\n", devstr));
++ fd = -1;
++ } else {
++ DEBUGMSGTL(("kernel_sunos5:dlpi", "style1 open succeeded\n"));
++ }
++
++ /* Creating a copy of the devname incase style 3 open
++ * is required
++ */
++ ret = strlcpy(devstrcpy, devstr, sizeof(devstrcpy));
++
++ if(ret > sizeof(devstrcpy) - 1)
++ return -1;
+
+- if ((fd = open(devstr, O_RDWR | O_NONBLOCK)) != -1) {
++ DEBUGMSGTL(("kernel_sunos5:dlpi", "devstrcpy(%s)\n", devstrcpy));
++
++
++ if (fd == -1 ) {
++ ret = snprintf(devstr, sizeof(devstr), "/dev/net/%s", devname);
++
++ if(ret < 0 || ret > sizeof(devstr) - 1)
++ return -1;
++
++ DEBUGMSGTL(("kernel_sunos5:dlpi", "devstr(%s)\n", devstr));
++
++ /* try style 2 */
++
++ if ((fd = open(devstr, O_RDWR | O_NONBLOCK)) < 0) {
++ DEBUGMSGTL(("kernel_sunos5:dlpi", "style2 open failed\n"));
++ fd = -1;
++ } else {
++ DEBUGMSGTL(("kernel_sunos5:dlpi", "style2 open succeeded\n"));
++ }
++ }
++
++
++ if (fd == -1 ) {
++ if (_dlpi_parse_devname(devstrcpy, &ppa) == 0) {
++ DEBUGMSGTL(("kernel_sunos5:dlpi", "style3 parse: %s, %d\n",
++ devstrcpy, ppa));
++ /* try style 3 */
++ DEBUGMSGTL(("kernel_sunos5:dlpi", "style3 open(%s)\n", devstrcpy));
++
++ if ((fd = open(devstrcpy, O_RDWR | O_NONBLOCK)) != -1) {
+ if (_dlpi_attach(fd, ppa) == 0) {
+ DEBUGMSGTL(("kernel_sunos5:dlpi", "attached\n"));
+ } else {
+@@ -1117,16 +1230,11 @@ _dlpi_open(const char *devname)
+ fd = -1;
+ }
+ } else {
+- DEBUGMSGTL(("kernel_sunos5:dlpi", "style2 open failed\n"));
++ DEBUGMSGTL(("kernel_sunos5:dlpi", "style3 open failed\n"));
+ }
+ }
+- } else {
+- DEBUGMSGTL(("kernel_sunos5:dlpi", "style1 open succeeded\n"));
+ }
+
+- /* clean up */
+- free(devstr);
+-
+ return (fd);
+ }
+
+@@ -1141,7 +1249,9 @@ _dlpi_get_phys_address(int fd, char *addr, int maxlen, int *addrlen)
+ struct strbuf ctlbuf;
+ char buf[MAX(DL_PHYS_ADDR_ACK_SIZE+64, DL_ERROR_ACK_SIZE)];
+ int flag = 0;
+-
++ struct pollfd pfd;
++ int timeout = 100;
++
+ DEBUGMSGTL(("kernel_sunos5:dlpi", "_dlpi_get_phys_address\n"));
+
+ paddr_req.dl_primitive = DL_PHYS_ADDR_REQ;
+@@ -1154,7 +1264,22 @@ _dlpi_get_phys_address(int fd, char *addr, int maxlen, int *addrlen)
+ ctlbuf.maxlen = sizeof(buf);
+ ctlbuf.len = 0;
+ ctlbuf.buf = buf;
+- if (getmsg(fd, &ctlbuf, NULL, &flag) < 0)
++
++ pfd.fd = fd;
++ pfd.events = POLLIN | POLLPRI;
++
++ switch (poll(&pfd, 1, timeout)) {
++ default:
++ if (pfd.revents & POLLHUP)
++ return (-1);
++ break;
++ case 0:
++ return (-1);
++ case -1:
++ return (-1);
++ }
++
++ if (getmsg(fd, &ctlbuf, NULL, &flag) < 0)
+ return (-1);
+
+ if (ctlbuf.len < sizeof(uint32_t))
+@@ -1196,6 +1321,8 @@ _dlpi_get_iftype(int fd, unsigned int *iftype)
+ struct strbuf ctlbuf;
+ char buf[MAX(DL_INFO_ACK_SIZE, DL_ERROR_ACK_SIZE)];
+ int flag = 0;
++ struct pollfd pfd;
++ int timeout = 100;
+
+ DEBUGMSGTL(("kernel_sunos5:dlpi", "_dlpi_get_iftype\n"));
+
+@@ -1210,7 +1337,22 @@ _dlpi_get_iftype(int fd, unsigned int *iftype)
+ ctlbuf.maxlen = sizeof(buf);
+ ctlbuf.len = 0;
+ ctlbuf.buf = buf;
+- if (getmsg(fd, &ctlbuf, NULL, &flag) < 0) {
++
++ pfd.fd = fd;
++ pfd.events = POLLIN | POLLPRI;
++
++ switch (poll(&pfd, 1, timeout)) {
++ default:
++ if (pfd.revents & POLLHUP)
++ return (-1);
++ break;
++ case 0:
++ return (-1);
++ case -1:
++ return (-1);
++ }
++
++ if (getmsg(fd, &ctlbuf, NULL, &flag) < 0) {
+ DEBUGMSGTL(("kernel_sunos5:dlpi", "getmsg failed: %d\n", errno));
+ return (-1);
+ }
+@@ -1367,8 +1509,9 @@ getif(mib2_ifEntry_t *ifbuf, size_t size, req_e req_type,
+ mib2_ifEntry_t *ifp;
+ int nentries = size / sizeof(mib2_ifEntry_t);
+ found_e result = NOT_FOUND;
+- boolean_t if_isv6;
++ boolean_t if_isv6, flags_unknown;
+ uint64_t if_flags;
++ short mtu = 0;
+ struct if_nameindex *ifname, *ifnp;
+
+ lifrp = &lifreq;
+@@ -1400,6 +1543,7 @@ getif(mib2_ifEntry_t *ifbuf, size_t size, req_e req_type,
+ memcpy(lifrp->lifr_name, ifnp->if_name, LIFNAMSIZ);
+ if_isv6 = B_FALSE;
+
++ flags_unknown = B_FALSE;
+ if (ioctl(ifsd, SIOCGLIFFLAGS, lifrp) < 0) {
+ if (ifsd6 == -1) {
+ if ((ifsd6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
+@@ -1408,17 +1552,19 @@ getif(mib2_ifEntry_t *ifbuf, size_t size, req_e req_type,
+ }
+ }
+ if (ioctl(ifsd6, SIOCGLIFFLAGS, lifrp) < 0) {
+- snmp_log(LOG_ERR, "SIOCGLIFFLAGS %s: %s\n",
+- lifrp->lifr_name, strerror(errno));
+- continue;
++ DEBUGMSGTL(("kernel_sunos5",
++ "...... SIOCGLIFFLAGS failed\n"));
++ flags_unknown = B_TRUE;
+ }
+ if_isv6 = B_TRUE;
+ }
+ if_flags = lifrp->lifr_flags;
+
+ if (ioctl(if_isv6?ifsd6:ifsd, SIOCGLIFMTU, lifrp) < 0) {
++ mtu = 0;
+ DEBUGMSGTL(("kernel_sunos5", "...... SIOCGLIFMTU failed\n"));
+- continue;
++ } else {
++ mtu = lifrp->lifr_mtu;
+ }
+
+ memset(ifp, 0, sizeof(mib2_ifEntry_t));
+@@ -1433,11 +1579,12 @@ getif(mib2_ifEntry_t *ifbuf, size_t size, req_e req_type,
+ }
+
+ set_if_info(ifp, ifnp->if_index, ifnp->if_name, if_flags,
+- lifrp->lifr_metric);
++ flags_unknown, mtu);
+
+ if (get_if_stats(ifp) < 0) {
++ snmp_log(LOG_ERR, "Failed to get interface statistics for %s\n",
++ ifnp->if_name);
+ DEBUGMSGTL(("kernel_sunos5", "...... get_if_stats failed\n"));
+- continue;
+ }
+
+ /*
+@@ -1614,11 +1761,109 @@ getif(mib2_ifEntry_t *ifbuf, size_t size, req_e req_type,
+ }
+ #endif /*defined(HAVE_IF_NAMEINDEX)&&defined(NETSNMP_INCLUDE_IFTABLE_REWRITES)*/
+
++
++static int getKstatIntInstance(const char *classname, int instance,
++ const char *statname, const char *varname,
++ int *value)
++{
++ kstat_ctl_t *ksc;
++ kstat_t *ks;
++ kid_t kid;
++ kstat_named_t *named;
++
++ int ret = -1; /* fail unless ... */
++ int lookup_stat = 0;
++
++ DEBUGMSGTL(("kernel_sunos5","\n Inside getKstatIntInstance: variable = %s",
++ varname));
++
++ if (kstat_fd == 0) {
++ kstat_fd = kstat_open();
++ if (kstat_fd == 0) {
++ snmp_log_perror("kstat_open");
++ }
++ }
++ if ((ksc = kstat_fd) == NULL) {
++ goto Return;
++ }
++
++ ks = kstat_lookup(ksc, classname, instance, statname);
++ if (ks == NULL) {
++ DEBUGMSGTL(("kernel_sunos5","\nclass %s, stat %s not found\n",
++ classname ? classname : "NULL",
++ statname ? statname : "NULL"));
++ goto Return;
++ }
++
++ kid = kstat_read(ksc, ks, NULL);
++ if (kid == -1) {
++ DEBUGMSGTL(("kernel_sunos5","\ncannot read class %s stats %s\n",
++ classname ? classname : "NULL",
++ statname ? statname : "NULL"));
++ goto Return;
++ }
++
++ named = kstat_data_lookup(ks, varname);
++ if (named == NULL) {
++ DEBUGMSGTL(("kernel_sunos5","\nno var %s for class %s stat %s\n",
++ varname, classname ? classname : "NULL",
++ statname ? statname : "NULL"));
++ goto Return;
++ }
++ ret = 0; /* maybe successful */
++ switch (named->data_type) {
++#ifdef KSTAT_DATA_INT32 /* Solaris 2.6 and up */
++ case KSTAT_DATA_INT32:
++ DEBUGMSGTL(("kernel_sunos5"," value: %d\n", named->value.i32));
++ *value = named->value.i32;
++ break;
++ case KSTAT_DATA_UINT32:
++ DEBUGMSGTL(("kernel_sunos5"," value: %u\n", named->value.ui32));
++ *value = named->value.ui32;
++ break;
++ case KSTAT_DATA_INT64:
++ DEBUGMSGTL(("kernel_sunos5"," value: %ld\n", named->value.i64));
++ *value = named->value.i64;
++ break;
++ case KSTAT_DATA_UINT64:
++ DEBUGMSGTL(("kernel_sunos5"," value: %llu\n", named->value.ui64));
++ *value = named->value.ui64;
++ break;
++#else
++ case KSTAT_DATA_LONG:
++ DEBUGMSGTL(("kernel_sunos5"," value: %ld\n", named->value.l));
++ *value = named->value.l;
++ break;
++ case KSTAT_DATA_ULONG:
++ DEBUGMSGTL(("kernel_sunos5"," value: %lu\n", named->value.ul));
++ *value = named->value.ul;
++ break;
++ case KSTAT_DATA_LONGLONG:
++ DEBUGMSGTL(("kernel_sunos5"," value: %lld\n", (long) named->value.ll));
++ *value = (long)named->value.ll;
++ break;
++ case KSTAT_DATA_ULONGLONG:
++ DEBUGMSGTL(("kernel_sunos5"," value: %llu\n",
++ (unsigned long) named->value.ull));
++ *value = (unsigned long)named->value.ull;
++ break;
++#endif
++ default:
++ ret = -1; /* fail */
++ break;
++ }
++ Return:
++ return ret;
++}
++
+ static void
+ set_if_info(mib2_ifEntry_t *ifp, unsigned index, char *name, uint64_t flags,
+- int mtu)
++ boolean_t flags_unknown, int mtu)
+ {
+ boolean_t havespeed = B_FALSE;
++ char phydevname[100];
++ char devbasename[100];
++ int instance = -1;
+
+ /*
+ * Set basic information
+@@ -1627,7 +1918,10 @@ set_if_info(mib2_ifEntry_t *ifp, unsigned index, char *name, uint64_t flags,
+ ifp->ifDescr.o_length = strlen(name);
+ strcpy(ifp->ifDescr.o_bytes, name);
+ ifp->ifAdminStatus = (flags & IFF_UP) ? 1 : 2;
+- ifp->ifOperStatus = ((flags & IFF_UP) && (flags & IFF_RUNNING)) ? 1 : 2;
++ if (flags_unknown)
++ ifp->ifOperStatus = 4; /* status unknown */
++ else
++ ifp->ifOperStatus = ((flags & IFF_UP) && (flags & IFF_RUNNING)) ? 1 : 2;
+ ifp->ifLastChange = 0; /* Who knows ... */
+ ifp->flags = flags;
+ ifp->ifMtu = mtu;
+@@ -1649,14 +1943,16 @@ set_if_info(mib2_ifEntry_t *ifp, unsigned index, char *name, uint64_t flags,
+ * this is good
+ */
+ havespeed = B_TRUE;
++ } else if ((getKstatInt("link", name, "ifspeed", &ifp->ifSpeed) == 0) ||
++ (getKstatInt("link", name, "ifSpeed", &ifp->ifSpeed) == 0)) {
++ havespeed = B_TRUE;
+ }
+-
+ /* make ifOperStatus depend on link status if available */
+ if (ifp->ifAdminStatus == 1) {
+ int i_tmp;
+ /* only UPed interfaces get correct link status - if any */
+ if (getKstatInt(NULL, name,"link_up",&i_tmp) == 0) {
+ ifp->ifOperStatus = i_tmp ? 1 : 2;
+ #ifdef IFF_FAILED
+ } else if (flags & IFF_FAILED) {
+ /*
Added: csw/mgar/pkg/netsnmp/trunk/files/0024-kernel_sunos5.5.11.patch
===================================================================
--- csw/mgar/pkg/netsnmp/trunk/files/0024-kernel_sunos5.5.11.patch (rev 0)
+++ csw/mgar/pkg/netsnmp/trunk/files/0024-kernel_sunos5.5.11.patch 2014-12-19 12:32:22 UTC (rev 24493)
@@ -0,0 +1,629 @@
+--- a/agent/mibgroup/kernel_sunos5.c
++++ b/agent/mibgroup/kernel_sunos5.c
+@@ -60,6 +60,8 @@
+ #include <net/if.h>
+ #include <netinet/in.h>
+
++#include <libdladm.h>
++#include <libdllink.h>
+ /*-
+ * Includes of local application header files
+ */
+@@ -82,15 +84,15 @@ kstat_ctl_t *kstat_fd = 0;
+ static
+ mibcache Mibcache[MIBCACHE_SIZE+1] = {
+ {MIB_SYSTEM, 0, (void *) -1, 0, 0, 0, 0},
+- {MIB_INTERFACES, 50 * sizeof(mib2_ifEntry_t), (void *) -1, 0, 30, 0,
++ {MIB_INTERFACES, 128 * sizeof(mib2_ifEntry_t), (void *) -1, 0, 30, 0,
+ 0},
+ {MIB_AT, 0, (void *) -1, 0, 0, 0, 0},
+ {MIB_IP, sizeof(mib2_ip_t), (void *) -1, 0, 60, 0, 0},
+- {MIB_IP_ADDR, 20 * sizeof(mib2_ipAddrEntry_t), (void *) -1, 0, 60, 0,
++ {MIB_IP_ADDR, 128 * sizeof(mib2_ipAddrEntry_t), (void *) -1, 0, 60, 0,
+ 0},
+- {MIB_IP_ROUTE, 200 * sizeof(mib2_ipRouteEntry_t), (void *) -1, 0, 30,
++ {MIB_IP_ROUTE, 400 * sizeof(mib2_ipRouteEntry_t), (void *) -1, 0, 30,
+ 0, 0},
+- {MIB_IP_NET, 100 * sizeof(mib2_ipNetToMediaEntry_t), (void *) -1, 0,
++ {MIB_IP_NET, 400 * sizeof(mib2_ipNetToMediaEntry_t), (void *) -1, 0,
+ 300, 0, 0},
+ {MIB_ICMP, sizeof(mib2_icmp_t), (void *) -1, 0, 60, 0, 0},
+ {MIB_TCP, sizeof(mib2_tcp_t), (void *) -1, 0, 60, 0, 0},
+@@ -105,13 +107,13 @@ mibcache Mibcache[MIBCACHE_SIZE+1] = {
+ {MIB_SNMP, 0, (void *) -1, 0, 0, 0, 0},
+ #ifdef SOLARIS_HAVE_IPV6_MIB_SUPPORT
+ #ifdef SOLARIS_HAVE_RFC4293_SUPPORT
+- {MIB_IP_TRAFFIC_STATS, 20 * sizeof(mib2_ipIfStatsEntry_t), (void *)-1, 0,
++ {MIB_IP_TRAFFIC_STATS, 128 * sizeof(mib2_ipIfStatsEntry_t), (void *)-1, 0,
+ 30, 0, 0},
+- {MIB_IP6, 20 * sizeof(mib2_ipIfStatsEntry_t), (void *)-1, 0, 30, 0, 0},
++ {MIB_IP6, 128 * sizeof(mib2_ipIfStatsEntry_t), (void *)-1, 0, 30, 0, 0},
+ #else
+- {MIB_IP6, 20 * sizeof(mib2_ipv6IfStatsEntry_t), (void *)-1, 0, 30, 0, 0},
++ {MIB_IP6, 128 * sizeof(mib2_ipv6IfStatsEntry_t), (void *)-1, 0, 30, 0, 0},
+ #endif
+- {MIB_IP6_ADDR, 20 * sizeof(mib2_ipv6AddrEntry_t), (void *)-1, 0, 30, 0, 0},
++ {MIB_IP6_ADDR, 128 * sizeof(mib2_ipv6AddrEntry_t), (void *)-1, 0, 30, 0, 0},
+ {MIB_TCP6_CONN, 1000 * sizeof(mib2_tcp6ConnEntry_t), (void *) -1, 0, 30,
+ 0, 0},
+ {MIB_UDP6_ENDPOINT, 1000 * sizeof(mib2_udp6Entry_t), (void *) -1, 0, 30,
+@@ -184,9 +186,9 @@ getif(mib2_ifEntry_t *ifbuf, size_t size, req_e req_type, mib2_ifEntry_t *resp,
+ size_t *length, int (*comp)(void *, void *), void *arg);
+ static void
+ set_if_info(mib2_ifEntry_t *ifp, unsigned index, char *name, uint64_t flags,
+- int mtu);
++ boolean_t flags_unknown, int mtu);
+ static int get_if_stats(mib2_ifEntry_t *ifp);
+-
++static int link_to_phydev(char *link, char *phy_devname);
+ #if defined(HAVE_IF_NAMEINDEX) && defined(NETSNMP_INCLUDE_IFTABLE_REWRITES)
+ static int _dlpi_open(const char *devname);
+ static int _dlpi_get_phys_address(int fd, char *paddr, int maxlen,
+@@ -294,7 +296,9 @@ getKstatInt(const char *classname, const char *statname,
+ kstat_t *ks;
+ kid_t kid;
+ kstat_named_t *named;
++
+ int ret = -1; /* fail unless ... */
++ int lookup_stat = 0;
+
+ if (kstat_fd == 0) {
+ kstat_fd = kstat_open();
+@@ -305,27 +309,88 @@ getKstatInt(const char *classname, const char *statname,
+ if ((ksc = kstat_fd) == NULL) {
+ goto Return;
+ }
+- ks = kstat_lookup(ksc, classname, -1, statname);
+- if (ks == NULL) {
+- DEBUGMSGTL(("kernel_sunos5", "class %s, stat %s not found\n",
+- classname ? classname : "NULL",
+- statname ? statname : "NULL"));
+- goto Return;
+- }
+- kid = kstat_read(ksc, ks, NULL);
+- if (kid == -1) {
+- DEBUGMSGTL(("kernel_sunos5", "cannot read class %s stats %s\n",
+- classname ? classname : "NULL", statname ? statname : "NULL"));
+- goto Return;
+- }
+- named = kstat_data_lookup(ks, varname);
+- if (named == NULL) {
+- DEBUGMSGTL(("kernel_sunos5", "no var %s for class %s stat %s\n",
+- varname, classname ? classname : "NULL",
+- statname ? statname : "NULL"));
+- goto Return;
++
++ if ((ks = kstat_lookup(ksc, statname, -1, "link")) != NULL)
++ {
++ kid = kstat_read(ksc, ks, NULL);
++ if (kid == -1) {
++ DEBUGMSGTL(("kernel_sunos5", "cannot read class %s stats %s\n",
++ statname ? statname : "NULL", "link"));
++ }
++ else
++ {
++ named = kstat_data_lookup(ks, varname);
++ if (named == NULL) {
++ DEBUGMSGTL(("kernel_sunos5", "no var %s for class %s stat %s\n",
++ varname, statname ? statname : "NULL", "link"));
++ }
++ else {
++ switch (named->data_type) {
++#ifdef KSTAT_DATA_INT32 /* Solaris 2.6 and up */
++ case KSTAT_DATA_INT32:
++ if(named->value.i32)
++ lookup_stat = 1;
++ break;
++ case KSTAT_DATA_UINT32:
++ if(named->value.ui32)
++ lookup_stat = 1;
++ break;
++ case KSTAT_DATA_INT64:
++ if(named->value.i64)
++ lookup_stat = 1;
++ break;
++ case KSTAT_DATA_UINT64:
++ if(named->value.ui64)
++ lookup_stat = 1;
++ break;
++#else
++ case KSTAT_DATA_LONG:
++ if(named->value.l)
++ lookup_stat = 1;
++ break;
++ case KSTAT_DATA_ULONG:
++ if(named->value.ul)
++ lookup_stat = 1;
++ break;
++ case KSTAT_DATA_LONGLONG:
++ if(named->value.ll)
++ lookup_stat = 1;
++ break;
++ case KSTAT_DATA_ULONGLONG:
++ if(named->value.ull)
++ lookup_stat = 1;
++ break;
++#endif
++ }
++ }
++ }
+ }
+-
++
++ if(!lookup_stat)
++ {
++ ks = kstat_lookup(ksc, classname, -1, statname);
++ if (ks == NULL) {
++ DEBUGMSGTL(("kernel_sunos5", "class %s, stat %s not found\n",
++ classname ? classname : "NULL",
++ statname ? statname : "NULL"));
++ goto Return;
++ }
++
++ kid = kstat_read(ksc, ks, NULL);
++ if (kid == -1) {
++ DEBUGMSGTL(("kernel_sunos5", "cannot read class %s stats %s\n",
++ classname ? classname : "NULL", statname ? statname : "NULL"));
++ goto Return;
++ }
++
++ named = kstat_data_lookup(ks, varname);
++ if (named == NULL) {
++ DEBUGMSGTL(("kernel_sunos5", "no var %s for class %s stat %s\n",
++ varname, classname ? classname : "NULL",
++ statname ? statname : "NULL"));
++ goto Return;
++ }
++ }
+ ret = 0; /* maybe successful */
+ switch (named->data_type) {
+ #ifdef KSTAT_DATA_INT32 /* Solaris 2.6 and up */
+@@ -442,11 +507,20 @@ getKstat(const char *statname, const char *varname, void *value)
+ /*
+ * Get the named statistics
+ */
+- if ((ks = kstat_lookup(ksc, module_name, instance, statname)) == NULL) {
+- ret = -10;
+- goto Return; /* kstat errors */
+- }
+
++ if ((ks = kstat_lookup(ksc, module_name, instance, statname)) == NULL)
++ {
++ /*
++ * Try to lookup the kstat module with
++ * modulename = linkname and statname = "link".
++ */
++
++ if ((ks = kstat_lookup(ksc, statname, 0, "link")) == NULL) {
++ ret = -10;
++ goto Return; /* kstat errors */
++ }
++ }
++
+ if (kstat_read(ksc, ks, NULL) <= 0) {
+ ret = -10;
+ goto Return; /* kstat errors */
+@@ -1080,18 +1154,21 @@ getmib(int groupname, int subgroupname, void **statbuf, size_t *size,
+ static int
+ _dlpi_open(const char *devname)
+ {
+- char *devstr;
++ char devstr[255], devstrcpy[255];
+ int fd = -1;
+ int ppa = -1;
++ int ret = -1;
+
+ DEBUGMSGTL(("kernel_sunos5", "_dlpi_open called\n"));
+
+ if (devname == NULL)
+- return (-1);
++ return (-1);
++
++ ret = snprintf(devstr, sizeof(devstr), "/dev/%s", devname);
+
+- if ((devstr = malloc(5 + strlen(devname) + 1)) == NULL)
+- return (-1);
+- (void) sprintf(devstr, "/dev/%s", devname);
++ if(ret < 0 || ret > sizeof(devstr) - 1)
++ return -1;
++
+ DEBUGMSGTL(("kernel_sunos5:dlpi", "devstr(%s)\n", devstr));
+ /*
+ * First try opening the device using style 1, if the device does not
+@@ -1102,13 +1179,49 @@ _dlpi_open(const char *devname)
+ DEBUGMSGTL(("kernel_sunos5:dlpi", "style1 open(%s)\n", devstr));
+ if ((fd = open(devstr, O_RDWR | O_NONBLOCK)) < 0) {
+ DEBUGMSGTL(("kernel_sunos5:dlpi", "style1 open failed\n"));
+- if (_dlpi_parse_devname(devstr, &ppa) == 0) {
+- DEBUGMSGTL(("kernel_sunos5:dlpi", "style2 parse: %s, %d\n",
+- devstr, ppa));
+- /* try style 2 */
+- DEBUGMSGTL(("kernel_sunos5:dlpi", "style2 open(%s)\n", devstr));
++ fd = -1;
++ } else {
++ DEBUGMSGTL(("kernel_sunos5:dlpi", "style1 open succeeded\n"));
++ }
++
++ /* Creating a copy of the devname incase style 3 open
++ * is required
++ */
++ ret = strlcpy(devstrcpy, devstr, sizeof(devstrcpy));
++
++ if(ret > sizeof(devstrcpy) - 1)
++ return -1;
+
+- if ((fd = open(devstr, O_RDWR | O_NONBLOCK)) != -1) {
++ DEBUGMSGTL(("kernel_sunos5:dlpi", "devstrcpy(%s)\n", devstrcpy));
++
++
++ if (fd == -1 ) {
++ ret = snprintf(devstr, sizeof(devstr), "/dev/net/%s", devname);
++
++ if(ret < 0 || ret > sizeof(devstr) - 1)
++ return -1;
++
++ DEBUGMSGTL(("kernel_sunos5:dlpi", "devstr(%s)\n", devstr));
++
++ /* try style 2 */
++
++ if ((fd = open(devstr, O_RDWR | O_NONBLOCK)) < 0) {
++ DEBUGMSGTL(("kernel_sunos5:dlpi", "style2 open failed\n"));
++ fd = -1;
++ } else {
++ DEBUGMSGTL(("kernel_sunos5:dlpi", "style2 open succeeded\n"));
++ }
++ }
++
++
++ if (fd == -1 ) {
++ if (_dlpi_parse_devname(devstrcpy, &ppa) == 0) {
++ DEBUGMSGTL(("kernel_sunos5:dlpi", "style3 parse: %s, %d\n",
++ devstrcpy, ppa));
++ /* try style 3 */
++ DEBUGMSGTL(("kernel_sunos5:dlpi", "style3 open(%s)\n", devstrcpy));
++
++ if ((fd = open(devstrcpy, O_RDWR | O_NONBLOCK)) != -1) {
+ if (_dlpi_attach(fd, ppa) == 0) {
+ DEBUGMSGTL(("kernel_sunos5:dlpi", "attached\n"));
+ } else {
+@@ -1117,16 +1230,11 @@ _dlpi_open(const char *devname)
+ fd = -1;
+ }
+ } else {
+- DEBUGMSGTL(("kernel_sunos5:dlpi", "style2 open failed\n"));
++ DEBUGMSGTL(("kernel_sunos5:dlpi", "style3 open failed\n"));
+ }
+ }
+- } else {
+- DEBUGMSGTL(("kernel_sunos5:dlpi", "style1 open succeeded\n"));
+ }
+
+- /* clean up */
+- free(devstr);
+-
+ return (fd);
+ }
+
+@@ -1141,7 +1249,9 @@ _dlpi_get_phys_address(int fd, char *addr, int maxlen, int *addrlen)
+ struct strbuf ctlbuf;
+ char buf[MAX(DL_PHYS_ADDR_ACK_SIZE+64, DL_ERROR_ACK_SIZE)];
+ int flag = 0;
+-
++ struct pollfd pfd;
++ int timeout = 100;
++
+ DEBUGMSGTL(("kernel_sunos5:dlpi", "_dlpi_get_phys_address\n"));
+
+ paddr_req.dl_primitive = DL_PHYS_ADDR_REQ;
+@@ -1154,7 +1264,22 @@ _dlpi_get_phys_address(int fd, char *addr, int maxlen, int *addrlen)
+ ctlbuf.maxlen = sizeof(buf);
+ ctlbuf.len = 0;
+ ctlbuf.buf = buf;
+- if (getmsg(fd, &ctlbuf, NULL, &flag) < 0)
++
++ pfd.fd = fd;
++ pfd.events = POLLIN | POLLPRI;
++
++ switch (poll(&pfd, 1, timeout)) {
++ default:
++ if (pfd.revents & POLLHUP)
++ return (-1);
++ break;
++ case 0:
++ return (-1);
++ case -1:
++ return (-1);
++ }
++
++ if (getmsg(fd, &ctlbuf, NULL, &flag) < 0)
+ return (-1);
+
+ if (ctlbuf.len < sizeof(uint32_t))
+@@ -1196,6 +1321,8 @@ _dlpi_get_iftype(int fd, unsigned int *iftype)
+ struct strbuf ctlbuf;
+ char buf[MAX(DL_INFO_ACK_SIZE, DL_ERROR_ACK_SIZE)];
+ int flag = 0;
++ struct pollfd pfd;
++ int timeout = 100;
+
+ DEBUGMSGTL(("kernel_sunos5:dlpi", "_dlpi_get_iftype\n"));
+
+@@ -1210,7 +1337,22 @@ _dlpi_get_iftype(int fd, unsigned int *iftype)
+ ctlbuf.maxlen = sizeof(buf);
+ ctlbuf.len = 0;
+ ctlbuf.buf = buf;
+- if (getmsg(fd, &ctlbuf, NULL, &flag) < 0) {
++
++ pfd.fd = fd;
++ pfd.events = POLLIN | POLLPRI;
++
++ switch (poll(&pfd, 1, timeout)) {
++ default:
++ if (pfd.revents & POLLHUP)
++ return (-1);
++ break;
++ case 0:
++ return (-1);
++ case -1:
++ return (-1);
++ }
++
++ if (getmsg(fd, &ctlbuf, NULL, &flag) < 0) {
+ DEBUGMSGTL(("kernel_sunos5:dlpi", "getmsg failed: %d\n", errno));
+ return (-1);
+ }
+@@ -1367,8 +1509,9 @@ getif(mib2_ifEntry_t *ifbuf, size_t size, req_e req_type,
+ mib2_ifEntry_t *ifp;
+ int nentries = size / sizeof(mib2_ifEntry_t);
+ found_e result = NOT_FOUND;
+- boolean_t if_isv6;
++ boolean_t if_isv6, flags_unknown;
+ uint64_t if_flags;
++ short mtu = 0;
+ struct if_nameindex *ifname, *ifnp;
+
+ lifrp = &lifreq;
+@@ -1400,6 +1543,7 @@ getif(mib2_ifEntry_t *ifbuf, size_t size, req_e req_type,
+ memcpy(lifrp->lifr_name, ifnp->if_name, LIFNAMSIZ);
+ if_isv6 = B_FALSE;
+
++ flags_unknown = B_FALSE;
+ if (ioctl(ifsd, SIOCGLIFFLAGS, lifrp) < 0) {
+ if (ifsd6 == -1) {
+ if ((ifsd6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
+@@ -1408,17 +1552,19 @@ getif(mib2_ifEntry_t *ifbuf, size_t size, req_e req_type,
+ }
+ }
+ if (ioctl(ifsd6, SIOCGLIFFLAGS, lifrp) < 0) {
+- snmp_log(LOG_ERR, "SIOCGLIFFLAGS %s: %s\n",
+- lifrp->lifr_name, strerror(errno));
+- continue;
++ DEBUGMSGTL(("kernel_sunos5",
++ "...... SIOCGLIFFLAGS failed\n"));
++ flags_unknown = B_TRUE;
+ }
+ if_isv6 = B_TRUE;
+ }
+ if_flags = lifrp->lifr_flags;
+
+ if (ioctl(if_isv6?ifsd6:ifsd, SIOCGLIFMTU, lifrp) < 0) {
++ mtu = 0;
+ DEBUGMSGTL(("kernel_sunos5", "...... SIOCGLIFMTU failed\n"));
+- continue;
++ } else {
++ mtu = lifrp->lifr_mtu;
+ }
+
+ memset(ifp, 0, sizeof(mib2_ifEntry_t));
+@@ -1433,11 +1579,12 @@ getif(mib2_ifEntry_t *ifbuf, size_t size, req_e req_type,
+ }
+
+ set_if_info(ifp, ifnp->if_index, ifnp->if_name, if_flags,
+- lifrp->lifr_metric);
++ flags_unknown, mtu);
+
+ if (get_if_stats(ifp) < 0) {
++ snmp_log(LOG_ERR, "Failed to get interface statistics for %s\n",
++ ifnp->if_name);
+ DEBUGMSGTL(("kernel_sunos5", "...... get_if_stats failed\n"));
+- continue;
+ }
+
+ /*
+@@ -1614,11 +1761,155 @@ getif(mib2_ifEntry_t *ifbuf, size_t size, req_e req_type,
+ }
+ #endif /*defined(HAVE_IF_NAMEINDEX)&&defined(NETSNMP_INCLUDE_IFTABLE_REWRITES)*/
+
++int link_to_phydev(char *link, char *phy_devname)
++{
++ char *key = NULL;
++ datalink_id_t linkid;
++ dladm_phys_attr_t dpa;
++ dladm_handle_t handle;
++
++ if (dladm_open(&handle, NULL) != DLADM_STATUS_OK) {
++ DEBUGMSGTL(("kernel_sunos5","dladm_open failed "
++ "with errno=%d\n",errno));
++ return (-1);
++ }
++
++ if (dladm_name2info(handle, link, &linkid, NULL, NULL, NULL) !=
++ DLADM_STATUS_OK) {
++ DEBUGMSGTL(("kernel_sunos5","dladm_name2info failed "
++ "with errno=%d\n",errno));
++ dladm_close(handle);
++ return (-1);
++ }
++
++ /*
++ * Get the device name of the link, which will be used as the door
++ * file name used to communicate with the driver.
++ */
++ if (dladm_phys_info(handle, linkid, &dpa, DLADM_OPT_ACTIVE) !=
++ DLADM_STATUS_OK) {
++ DEBUGMSGTL(("kernel_sunos5","dladm_phys_info failed "
++ "with errno=%d\n",errno));
++ dladm_close(handle);
++ return (-1);
++ }
++
++ if(dpa.dp_dev == NULL) {
++ DEBUGMSGTL(("kernel_sunos5","device name from "
++ "dladm_phys_info = NULL\n"));
++ dladm_close(handle);
++ return -1;
++
++ }
++ strcpy(phy_devname, dpa.dp_dev);
++ dladm_close(handle);
++
++ return 0;
++}
++
++
++static int getKstatIntInstance(const char *classname, int instance,
++ const char *statname, const char *varname,
++ int *value)
++{
++ kstat_ctl_t *ksc;
++ kstat_t *ks;
++ kid_t kid;
++ kstat_named_t *named;
++
++ int ret = -1; /* fail unless ... */
++ int lookup_stat = 0;
++
++ DEBUGMSGTL(("kernel_sunos5","\n Inside getKstatIntInstance: variable = %s",
++ varname));
++
++ if (kstat_fd == 0) {
++ kstat_fd = kstat_open();
++ if (kstat_fd == 0) {
++ snmp_log_perror("kstat_open");
++ }
++ }
++ if ((ksc = kstat_fd) == NULL) {
++ goto Return;
++ }
++
++ ks = kstat_lookup(ksc, classname, instance, statname);
++ if (ks == NULL) {
++ DEBUGMSGTL(("kernel_sunos5","\nclass %s, stat %s not found\n",
++ classname ? classname : "NULL",
++ statname ? statname : "NULL"));
++ goto Return;
++ }
++
++ kid = kstat_read(ksc, ks, NULL);
++ if (kid == -1) {
++ DEBUGMSGTL(("kernel_sunos5","\ncannot read class %s stats %s\n",
++ classname ? classname : "NULL",
++ statname ? statname : "NULL"));
++ goto Return;
++ }
++
++ named = kstat_data_lookup(ks, varname);
++ if (named == NULL) {
++ DEBUGMSGTL(("kernel_sunos5","\nno var %s for class %s stat %s\n",
++ varname, classname ? classname : "NULL",
++ statname ? statname : "NULL"));
++ goto Return;
++ }
++ ret = 0; /* maybe successful */
++ switch (named->data_type) {
++#ifdef KSTAT_DATA_INT32 /* Solaris 2.6 and up */
++ case KSTAT_DATA_INT32:
++ DEBUGMSGTL(("kernel_sunos5"," value: %d\n", named->value.i32));
++ *value = named->value.i32;
++ break;
++ case KSTAT_DATA_UINT32:
++ DEBUGMSGTL(("kernel_sunos5"," value: %u\n", named->value.ui32));
++ *value = named->value.ui32;
++ break;
++ case KSTAT_DATA_INT64:
++ DEBUGMSGTL(("kernel_sunos5"," value: %ld\n", named->value.i64));
++ *value = named->value.i64;
++ break;
++ case KSTAT_DATA_UINT64:
++ DEBUGMSGTL(("kernel_sunos5"," value: %llu\n", named->value.ui64));
++ *value = named->value.ui64;
++ break;
++#else
++ case KSTAT_DATA_LONG:
++ DEBUGMSGTL(("kernel_sunos5"," value: %ld\n", named->value.l));
++ *value = named->value.l;
++ break;
++ case KSTAT_DATA_ULONG:
++ DEBUGMSGTL(("kernel_sunos5"," value: %lu\n", named->value.ul));
++ *value = named->value.ul;
++ break;
++ case KSTAT_DATA_LONGLONG:
++ DEBUGMSGTL(("kernel_sunos5"," value: %lld\n", (long) named->value.ll));
++ *value = (long)named->value.ll;
++ break;
++ case KSTAT_DATA_ULONGLONG:
++ DEBUGMSGTL(("kernel_sunos5"," value: %llu\n",
++ (unsigned long) named->value.ull));
++ *value = (unsigned long)named->value.ull;
++ break;
++#endif
++ default:
++ ret = -1; /* fail */
++ break;
++ }
++ Return:
++ return ret;
++}
++
+ static void
+ set_if_info(mib2_ifEntry_t *ifp, unsigned index, char *name, uint64_t flags,
+- int mtu)
++ boolean_t flags_unknown, int mtu)
+ {
+ boolean_t havespeed = B_FALSE;
++ char phydevname[100];
++ char devbasename[100];
++ int instance = -1;
+
+ /*
+ * Set basic information
+@@ -1627,7 +1918,10 @@ set_if_info(mib2_ifEntry_t *ifp, unsigned index, char *name, uint64_t flags,
+ ifp->ifDescr.o_length = strlen(name);
+ strcpy(ifp->ifDescr.o_bytes, name);
+ ifp->ifAdminStatus = (flags & IFF_UP) ? 1 : 2;
+- ifp->ifOperStatus = ((flags & IFF_UP) && (flags & IFF_RUNNING)) ? 1 : 2;
++ if (flags_unknown)
++ ifp->ifOperStatus = 4; /* status unknown */
++ else
++ ifp->ifOperStatus = ((flags & IFF_UP) && (flags & IFF_RUNNING)) ? 1 : 2;
+ ifp->ifLastChange = 0; /* Who knows ... */
+ ifp->flags = flags;
+ ifp->ifMtu = mtu;
+@@ -1649,14 +1943,26 @@ set_if_info(mib2_ifEntry_t *ifp, unsigned index, char *name, uint64_t flags,
+ * this is good
+ */
+ havespeed = B_TRUE;
++ } else if ((getKstatInt("link", name, "ifspeed", &ifp->ifSpeed) == 0) ||
++ (getKstatInt("link", name, "ifSpeed", &ifp->ifSpeed) == 0)) {
++ havespeed = B_TRUE;
+ }
+-
+ /* make ifOperStatus depend on link status if available */
+ if (ifp->ifAdminStatus == 1) {
+ int i_tmp;
+ /* only UPed interfaces get correct link status - if any */
+ if (getKstatInt(NULL, name,"link_up",&i_tmp) == 0) {
+ ifp->ifOperStatus = i_tmp ? 1 : 2;
++ } else if(link_to_phydev(name, phydevname) == 0) {
++ strcpy(devbasename, phydevname);
++ DEBUGMSGTL(("kernel_sunos5","phydevname = %s\n", phydevname));
++ _dlpi_parse_devname(devbasename, &instance);
++ DEBUGMSGTL(("kernel_sunos5","devbasename = %s, "
++ "instance= %d\n", devbasename, instance));
++ if(getKstatIntInstance(devbasename, instance, "phys",
++ "link_up", &i_tmp) == 0) {
++ ifp->ifOperStatus = i_tmp ? 1 : 2;
++ }
+ #ifdef IFF_FAILED
+ } else if (flags & IFF_FAILED) {
+ /*
Deleted: csw/mgar/pkg/netsnmp/trunk/files/0024-kernel_sunos5.patch
===================================================================
--- csw/mgar/pkg/netsnmp/trunk/files/0024-kernel_sunos5.patch 2014-12-19 12:18:08 UTC (rev 24492)
+++ csw/mgar/pkg/netsnmp/trunk/files/0024-kernel_sunos5.patch 2014-12-19 12:32:22 UTC (rev 24493)
@@ -1,629 +0,0 @@
---- a/agent/mibgroup/kernel_sunos5.c
-+++ b/agent/mibgroup/kernel_sunos5.c
-@@ -60,6 +60,8 @@
- #include <net/if.h>
- #include <netinet/in.h>
-
-+#include <libdladm.h>
-+#include <libdllink.h>
- /*-
- * Includes of local application header files
- */
-@@ -82,15 +84,15 @@ kstat_ctl_t *kstat_fd = 0;
- static
- mibcache Mibcache[MIBCACHE_SIZE+1] = {
- {MIB_SYSTEM, 0, (void *) -1, 0, 0, 0, 0},
-- {MIB_INTERFACES, 50 * sizeof(mib2_ifEntry_t), (void *) -1, 0, 30, 0,
-+ {MIB_INTERFACES, 128 * sizeof(mib2_ifEntry_t), (void *) -1, 0, 30, 0,
- 0},
- {MIB_AT, 0, (void *) -1, 0, 0, 0, 0},
- {MIB_IP, sizeof(mib2_ip_t), (void *) -1, 0, 60, 0, 0},
-- {MIB_IP_ADDR, 20 * sizeof(mib2_ipAddrEntry_t), (void *) -1, 0, 60, 0,
-+ {MIB_IP_ADDR, 128 * sizeof(mib2_ipAddrEntry_t), (void *) -1, 0, 60, 0,
- 0},
-- {MIB_IP_ROUTE, 200 * sizeof(mib2_ipRouteEntry_t), (void *) -1, 0, 30,
-+ {MIB_IP_ROUTE, 400 * sizeof(mib2_ipRouteEntry_t), (void *) -1, 0, 30,
- 0, 0},
-- {MIB_IP_NET, 100 * sizeof(mib2_ipNetToMediaEntry_t), (void *) -1, 0,
-+ {MIB_IP_NET, 400 * sizeof(mib2_ipNetToMediaEntry_t), (void *) -1, 0,
- 300, 0, 0},
- {MIB_ICMP, sizeof(mib2_icmp_t), (void *) -1, 0, 60, 0, 0},
- {MIB_TCP, sizeof(mib2_tcp_t), (void *) -1, 0, 60, 0, 0},
-@@ -105,13 +107,13 @@ mibcache Mibcache[MIBCACHE_SIZE+1] = {
- {MIB_SNMP, 0, (void *) -1, 0, 0, 0, 0},
- #ifdef SOLARIS_HAVE_IPV6_MIB_SUPPORT
- #ifdef SOLARIS_HAVE_RFC4293_SUPPORT
-- {MIB_IP_TRAFFIC_STATS, 20 * sizeof(mib2_ipIfStatsEntry_t), (void *)-1, 0,
-+ {MIB_IP_TRAFFIC_STATS, 128 * sizeof(mib2_ipIfStatsEntry_t), (void *)-1, 0,
- 30, 0, 0},
-- {MIB_IP6, 20 * sizeof(mib2_ipIfStatsEntry_t), (void *)-1, 0, 30, 0, 0},
-+ {MIB_IP6, 128 * sizeof(mib2_ipIfStatsEntry_t), (void *)-1, 0, 30, 0, 0},
- #else
-- {MIB_IP6, 20 * sizeof(mib2_ipv6IfStatsEntry_t), (void *)-1, 0, 30, 0, 0},
-+ {MIB_IP6, 128 * sizeof(mib2_ipv6IfStatsEntry_t), (void *)-1, 0, 30, 0, 0},
- #endif
-- {MIB_IP6_ADDR, 20 * sizeof(mib2_ipv6AddrEntry_t), (void *)-1, 0, 30, 0, 0},
-+ {MIB_IP6_ADDR, 128 * sizeof(mib2_ipv6AddrEntry_t), (void *)-1, 0, 30, 0, 0},
- {MIB_TCP6_CONN, 1000 * sizeof(mib2_tcp6ConnEntry_t), (void *) -1, 0, 30,
- 0, 0},
- {MIB_UDP6_ENDPOINT, 1000 * sizeof(mib2_udp6Entry_t), (void *) -1, 0, 30,
-@@ -184,9 +186,9 @@ getif(mib2_ifEntry_t *ifbuf, size_t size, req_e req_type, mib2_ifEntry_t *resp,
- size_t *length, int (*comp)(void *, void *), void *arg);
- static void
- set_if_info(mib2_ifEntry_t *ifp, unsigned index, char *name, uint64_t flags,
-- int mtu);
-+ boolean_t flags_unknown, int mtu);
- static int get_if_stats(mib2_ifEntry_t *ifp);
--
-+static int link_to_phydev(char *link, char *phy_devname);
- #if defined(HAVE_IF_NAMEINDEX) && defined(NETSNMP_INCLUDE_IFTABLE_REWRITES)
- static int _dlpi_open(const char *devname);
- static int _dlpi_get_phys_address(int fd, char *paddr, int maxlen,
-@@ -294,7 +296,9 @@ getKstatInt(const char *classname, const char *statname,
- kstat_t *ks;
- kid_t kid;
- kstat_named_t *named;
-+
- int ret = -1; /* fail unless ... */
-+ int lookup_stat = 0;
-
- if (kstat_fd == 0) {
- kstat_fd = kstat_open();
-@@ -305,27 +309,88 @@ getKstatInt(const char *classname, const char *statname,
- if ((ksc = kstat_fd) == NULL) {
- goto Return;
- }
-- ks = kstat_lookup(ksc, classname, -1, statname);
-- if (ks == NULL) {
-- DEBUGMSGTL(("kernel_sunos5", "class %s, stat %s not found\n",
-- classname ? classname : "NULL",
-- statname ? statname : "NULL"));
-- goto Return;
-- }
-- kid = kstat_read(ksc, ks, NULL);
-- if (kid == -1) {
-- DEBUGMSGTL(("kernel_sunos5", "cannot read class %s stats %s\n",
-- classname ? classname : "NULL", statname ? statname : "NULL"));
-- goto Return;
-- }
-- named = kstat_data_lookup(ks, varname);
-- if (named == NULL) {
-- DEBUGMSGTL(("kernel_sunos5", "no var %s for class %s stat %s\n",
-- varname, classname ? classname : "NULL",
-- statname ? statname : "NULL"));
-- goto Return;
-+
-+ if ((ks = kstat_lookup(ksc, statname, -1, "link")) != NULL)
-+ {
-+ kid = kstat_read(ksc, ks, NULL);
-+ if (kid == -1) {
-+ DEBUGMSGTL(("kernel_sunos5", "cannot read class %s stats %s\n",
-+ statname ? statname : "NULL", "link"));
-+ }
-+ else
-+ {
-+ named = kstat_data_lookup(ks, varname);
-+ if (named == NULL) {
-+ DEBUGMSGTL(("kernel_sunos5", "no var %s for class %s stat %s\n",
-+ varname, statname ? statname : "NULL", "link"));
-+ }
-+ else {
-+ switch (named->data_type) {
-+#ifdef KSTAT_DATA_INT32 /* Solaris 2.6 and up */
-+ case KSTAT_DATA_INT32:
-+ if(named->value.i32)
-+ lookup_stat = 1;
-+ break;
-+ case KSTAT_DATA_UINT32:
-+ if(named->value.ui32)
-+ lookup_stat = 1;
-+ break;
-+ case KSTAT_DATA_INT64:
-+ if(named->value.i64)
-+ lookup_stat = 1;
-+ break;
-+ case KSTAT_DATA_UINT64:
-+ if(named->value.ui64)
-+ lookup_stat = 1;
-+ break;
-+#else
-+ case KSTAT_DATA_LONG:
-+ if(named->value.l)
-+ lookup_stat = 1;
-+ break;
-+ case KSTAT_DATA_ULONG:
-+ if(named->value.ul)
-+ lookup_stat = 1;
-+ break;
-+ case KSTAT_DATA_LONGLONG:
-+ if(named->value.ll)
-+ lookup_stat = 1;
-+ break;
-+ case KSTAT_DATA_ULONGLONG:
-+ if(named->value.ull)
-+ lookup_stat = 1;
-+ break;
-+#endif
-+ }
-+ }
-+ }
- }
--
-+
-+ if(!lookup_stat)
-+ {
-+ ks = kstat_lookup(ksc, classname, -1, statname);
-+ if (ks == NULL) {
-+ DEBUGMSGTL(("kernel_sunos5", "class %s, stat %s not found\n",
-+ classname ? classname : "NULL",
-+ statname ? statname : "NULL"));
-+ goto Return;
-+ }
-+
-+ kid = kstat_read(ksc, ks, NULL);
-+ if (kid == -1) {
-+ DEBUGMSGTL(("kernel_sunos5", "cannot read class %s stats %s\n",
-+ classname ? classname : "NULL", statname ? statname : "NULL"));
-+ goto Return;
-+ }
-+
-+ named = kstat_data_lookup(ks, varname);
-+ if (named == NULL) {
-+ DEBUGMSGTL(("kernel_sunos5", "no var %s for class %s stat %s\n",
-+ varname, classname ? classname : "NULL",
-+ statname ? statname : "NULL"));
-+ goto Return;
-+ }
-+ }
- ret = 0; /* maybe successful */
- switch (named->data_type) {
- #ifdef KSTAT_DATA_INT32 /* Solaris 2.6 and up */
-@@ -442,11 +507,20 @@ getKstat(const char *statname, const char *varname, void *value)
- /*
- * Get the named statistics
- */
-- if ((ks = kstat_lookup(ksc, module_name, instance, statname)) == NULL) {
-- ret = -10;
-- goto Return; /* kstat errors */
-- }
-
-+ if ((ks = kstat_lookup(ksc, module_name, instance, statname)) == NULL)
-+ {
-+ /*
-+ * Try to lookup the kstat module with
-+ * modulename = linkname and statname = "link".
-+ */
-+
-+ if ((ks = kstat_lookup(ksc, statname, 0, "link")) == NULL) {
-+ ret = -10;
-+ goto Return; /* kstat errors */
-+ }
-+ }
-+
- if (kstat_read(ksc, ks, NULL) <= 0) {
- ret = -10;
- goto Return; /* kstat errors */
-@@ -1080,18 +1154,21 @@ getmib(int groupname, int subgroupname, void **statbuf, size_t *size,
- static int
- _dlpi_open(const char *devname)
- {
-- char *devstr;
-+ char devstr[255], devstrcpy[255];
- int fd = -1;
- int ppa = -1;
-+ int ret = -1;
-
- DEBUGMSGTL(("kernel_sunos5", "_dlpi_open called\n"));
-
- if (devname == NULL)
-- return (-1);
-+ return (-1);
-+
-+ ret = snprintf(devstr, sizeof(devstr), "/dev/%s", devname);
-
-- if ((devstr = malloc(5 + strlen(devname) + 1)) == NULL)
-- return (-1);
-- (void) sprintf(devstr, "/dev/%s", devname);
-+ if(ret < 0 || ret > sizeof(devstr) - 1)
-+ return -1;
-+
- DEBUGMSGTL(("kernel_sunos5:dlpi", "devstr(%s)\n", devstr));
- /*
- * First try opening the device using style 1, if the device does not
-@@ -1102,13 +1179,49 @@ _dlpi_open(const char *devname)
- DEBUGMSGTL(("kernel_sunos5:dlpi", "style1 open(%s)\n", devstr));
- if ((fd = open(devstr, O_RDWR | O_NONBLOCK)) < 0) {
- DEBUGMSGTL(("kernel_sunos5:dlpi", "style1 open failed\n"));
-- if (_dlpi_parse_devname(devstr, &ppa) == 0) {
-- DEBUGMSGTL(("kernel_sunos5:dlpi", "style2 parse: %s, %d\n",
-- devstr, ppa));
-- /* try style 2 */
-- DEBUGMSGTL(("kernel_sunos5:dlpi", "style2 open(%s)\n", devstr));
-+ fd = -1;
-+ } else {
-+ DEBUGMSGTL(("kernel_sunos5:dlpi", "style1 open succeeded\n"));
-+ }
-+
-+ /* Creating a copy of the devname incase style 3 open
-+ * is required
-+ */
-+ ret = strlcpy(devstrcpy, devstr, sizeof(devstrcpy));
-+
-+ if(ret > sizeof(devstrcpy) - 1)
-+ return -1;
-
-- if ((fd = open(devstr, O_RDWR | O_NONBLOCK)) != -1) {
-+ DEBUGMSGTL(("kernel_sunos5:dlpi", "devstrcpy(%s)\n", devstrcpy));
-+
-+
-+ if (fd == -1 ) {
-+ ret = snprintf(devstr, sizeof(devstr), "/dev/net/%s", devname);
-+
-+ if(ret < 0 || ret > sizeof(devstr) - 1)
-+ return -1;
-+
-+ DEBUGMSGTL(("kernel_sunos5:dlpi", "devstr(%s)\n", devstr));
-+
-+ /* try style 2 */
-+
-+ if ((fd = open(devstr, O_RDWR | O_NONBLOCK)) < 0) {
-+ DEBUGMSGTL(("kernel_sunos5:dlpi", "style2 open failed\n"));
-+ fd = -1;
-+ } else {
-+ DEBUGMSGTL(("kernel_sunos5:dlpi", "style2 open succeeded\n"));
-+ }
-+ }
-+
-+
-+ if (fd == -1 ) {
-+ if (_dlpi_parse_devname(devstrcpy, &ppa) == 0) {
-+ DEBUGMSGTL(("kernel_sunos5:dlpi", "style3 parse: %s, %d\n",
-+ devstrcpy, ppa));
-+ /* try style 3 */
-+ DEBUGMSGTL(("kernel_sunos5:dlpi", "style3 open(%s)\n", devstrcpy));
-+
-+ if ((fd = open(devstrcpy, O_RDWR | O_NONBLOCK)) != -1) {
- if (_dlpi_attach(fd, ppa) == 0) {
- DEBUGMSGTL(("kernel_sunos5:dlpi", "attached\n"));
- } else {
-@@ -1117,16 +1230,11 @@ _dlpi_open(const char *devname)
- fd = -1;
- }
- } else {
-- DEBUGMSGTL(("kernel_sunos5:dlpi", "style2 open failed\n"));
-+ DEBUGMSGTL(("kernel_sunos5:dlpi", "style3 open failed\n"));
- }
- }
-- } else {
-- DEBUGMSGTL(("kernel_sunos5:dlpi", "style1 open succeeded\n"));
- }
-
-- /* clean up */
-- free(devstr);
--
- return (fd);
- }
-
-@@ -1141,7 +1249,9 @@ _dlpi_get_phys_address(int fd, char *addr, int maxlen, int *addrlen)
- struct strbuf ctlbuf;
- char buf[MAX(DL_PHYS_ADDR_ACK_SIZE+64, DL_ERROR_ACK_SIZE)];
- int flag = 0;
--
-+ struct pollfd pfd;
-+ int timeout = 100;
-+
- DEBUGMSGTL(("kernel_sunos5:dlpi", "_dlpi_get_phys_address\n"));
-
- paddr_req.dl_primitive = DL_PHYS_ADDR_REQ;
-@@ -1154,7 +1264,22 @@ _dlpi_get_phys_address(int fd, char *addr, int maxlen, int *addrlen)
- ctlbuf.maxlen = sizeof(buf);
- ctlbuf.len = 0;
- ctlbuf.buf = buf;
-- if (getmsg(fd, &ctlbuf, NULL, &flag) < 0)
-+
-+ pfd.fd = fd;
-+ pfd.events = POLLIN | POLLPRI;
-+
-+ switch (poll(&pfd, 1, timeout)) {
-+ default:
-+ if (pfd.revents & POLLHUP)
-+ return (-1);
-+ break;
-+ case 0:
-+ return (-1);
-+ case -1:
-+ return (-1);
-+ }
-+
-+ if (getmsg(fd, &ctlbuf, NULL, &flag) < 0)
- return (-1);
-
- if (ctlbuf.len < sizeof(uint32_t))
-@@ -1196,6 +1321,8 @@ _dlpi_get_iftype(int fd, unsigned int *iftype)
- struct strbuf ctlbuf;
- char buf[MAX(DL_INFO_ACK_SIZE, DL_ERROR_ACK_SIZE)];
- int flag = 0;
-+ struct pollfd pfd;
-+ int timeout = 100;
-
- DEBUGMSGTL(("kernel_sunos5:dlpi", "_dlpi_get_iftype\n"));
-
-@@ -1210,7 +1337,22 @@ _dlpi_get_iftype(int fd, unsigned int *iftype)
- ctlbuf.maxlen = sizeof(buf);
- ctlbuf.len = 0;
- ctlbuf.buf = buf;
-- if (getmsg(fd, &ctlbuf, NULL, &flag) < 0) {
-+
-+ pfd.fd = fd;
-+ pfd.events = POLLIN | POLLPRI;
-+
-+ switch (poll(&pfd, 1, timeout)) {
-+ default:
-+ if (pfd.revents & POLLHUP)
-+ return (-1);
-+ break;
-+ case 0:
-+ return (-1);
-+ case -1:
-+ return (-1);
-+ }
-+
-+ if (getmsg(fd, &ctlbuf, NULL, &flag) < 0) {
- DEBUGMSGTL(("kernel_sunos5:dlpi", "getmsg failed: %d\n", errno));
- return (-1);
- }
-@@ -1367,8 +1509,9 @@ getif(mib2_ifEntry_t *ifbuf, size_t size, req_e req_type,
- mib2_ifEntry_t *ifp;
- int nentries = size / sizeof(mib2_ifEntry_t);
- found_e result = NOT_FOUND;
-- boolean_t if_isv6;
-+ boolean_t if_isv6, flags_unknown;
- uint64_t if_flags;
-+ short mtu = 0;
- struct if_nameindex *ifname, *ifnp;
-
- lifrp = &lifreq;
-@@ -1400,6 +1543,7 @@ getif(mib2_ifEntry_t *ifbuf, size_t size, req_e req_type,
- memcpy(lifrp->lifr_name, ifnp->if_name, LIFNAMSIZ);
- if_isv6 = B_FALSE;
-
-+ flags_unknown = B_FALSE;
- if (ioctl(ifsd, SIOCGLIFFLAGS, lifrp) < 0) {
- if (ifsd6 == -1) {
- if ((ifsd6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
-@@ -1408,17 +1552,19 @@ getif(mib2_ifEntry_t *ifbuf, size_t size, req_e req_type,
- }
- }
- if (ioctl(ifsd6, SIOCGLIFFLAGS, lifrp) < 0) {
-- snmp_log(LOG_ERR, "SIOCGLIFFLAGS %s: %s\n",
-- lifrp->lifr_name, strerror(errno));
-- continue;
-+ DEBUGMSGTL(("kernel_sunos5",
-+ "...... SIOCGLIFFLAGS failed\n"));
-+ flags_unknown = B_TRUE;
- }
- if_isv6 = B_TRUE;
- }
- if_flags = lifrp->lifr_flags;
-
- if (ioctl(if_isv6?ifsd6:ifsd, SIOCGLIFMTU, lifrp) < 0) {
-+ mtu = 0;
- DEBUGMSGTL(("kernel_sunos5", "...... SIOCGLIFMTU failed\n"));
-- continue;
-+ } else {
-+ mtu = lifrp->lifr_mtu;
- }
-
- memset(ifp, 0, sizeof(mib2_ifEntry_t));
-@@ -1433,11 +1579,12 @@ getif(mib2_ifEntry_t *ifbuf, size_t size, req_e req_type,
- }
-
- set_if_info(ifp, ifnp->if_index, ifnp->if_name, if_flags,
-- lifrp->lifr_metric);
-+ flags_unknown, mtu);
-
- if (get_if_stats(ifp) < 0) {
-+ snmp_log(LOG_ERR, "Failed to get interface statistics for %s\n",
-+ ifnp->if_name);
- DEBUGMSGTL(("kernel_sunos5", "...... get_if_stats failed\n"));
-- continue;
- }
-
- /*
-@@ -1614,11 +1761,155 @@ getif(mib2_ifEntry_t *ifbuf, size_t size, req_e req_type,
- }
- #endif /*defined(HAVE_IF_NAMEINDEX)&&defined(NETSNMP_INCLUDE_IFTABLE_REWRITES)*/
-
-+int link_to_phydev(char *link, char *phy_devname)
-+{
-+ char *key = NULL;
-+ datalink_id_t linkid;
-+ dladm_phys_attr_t dpa;
-+ dladm_handle_t handle;
-+
-+ if (dladm_open(&handle, NULL) != DLADM_STATUS_OK) {
-+ DEBUGMSGTL(("kernel_sunos5","dladm_open failed "
-+ "with errno=%d\n",errno));
-+ return (-1);
-+ }
-+
-+ if (dladm_name2info(handle, link, &linkid, NULL, NULL, NULL) !=
-+ DLADM_STATUS_OK) {
-+ DEBUGMSGTL(("kernel_sunos5","dladm_name2info failed "
-+ "with errno=%d\n",errno));
-+ dladm_close(handle);
-+ return (-1);
-+ }
-+
-+ /*
-+ * Get the device name of the link, which will be used as the door
-+ * file name used to communicate with the driver.
-+ */
-+ if (dladm_phys_info(handle, linkid, &dpa, DLADM_OPT_ACTIVE) !=
-+ DLADM_STATUS_OK) {
-+ DEBUGMSGTL(("kernel_sunos5","dladm_phys_info failed "
-+ "with errno=%d\n",errno));
-+ dladm_close(handle);
-+ return (-1);
-+ }
-+
-+ if(dpa.dp_dev == NULL) {
-+ DEBUGMSGTL(("kernel_sunos5","device name from "
-+ "dladm_phys_info = NULL\n"));
-+ dladm_close(handle);
-+ return -1;
-+
-+ }
-+ strcpy(phy_devname, dpa.dp_dev);
-+ dladm_close(handle);
-+
-+ return 0;
-+}
-+
-+
-+static int getKstatIntInstance(const char *classname, int instance,
-+ const char *statname, const char *varname,
-+ int *value)
-+{
-+ kstat_ctl_t *ksc;
-+ kstat_t *ks;
-+ kid_t kid;
-+ kstat_named_t *named;
-+
-+ int ret = -1; /* fail unless ... */
-+ int lookup_stat = 0;
-+
-+ DEBUGMSGTL(("kernel_sunos5","\n Inside getKstatIntInstance: variable = %s",
-+ varname));
-+
-+ if (kstat_fd == 0) {
-+ kstat_fd = kstat_open();
-+ if (kstat_fd == 0) {
-+ snmp_log_perror("kstat_open");
-+ }
-+ }
-+ if ((ksc = kstat_fd) == NULL) {
-+ goto Return;
-+ }
-+
-+ ks = kstat_lookup(ksc, classname, instance, statname);
-+ if (ks == NULL) {
-+ DEBUGMSGTL(("kernel_sunos5","\nclass %s, stat %s not found\n",
-+ classname ? classname : "NULL",
-+ statname ? statname : "NULL"));
-+ goto Return;
-+ }
-+
-+ kid = kstat_read(ksc, ks, NULL);
-+ if (kid == -1) {
-+ DEBUGMSGTL(("kernel_sunos5","\ncannot read class %s stats %s\n",
-+ classname ? classname : "NULL",
-+ statname ? statname : "NULL"));
-+ goto Return;
-+ }
-+
-+ named = kstat_data_lookup(ks, varname);
-+ if (named == NULL) {
-+ DEBUGMSGTL(("kernel_sunos5","\nno var %s for class %s stat %s\n",
-+ varname, classname ? classname : "NULL",
-+ statname ? statname : "NULL"));
-+ goto Return;
-+ }
-+ ret = 0; /* maybe successful */
-+ switch (named->data_type) {
-+#ifdef KSTAT_DATA_INT32 /* Solaris 2.6 and up */
-+ case KSTAT_DATA_INT32:
-+ DEBUGMSGTL(("kernel_sunos5"," value: %d\n", named->value.i32));
-+ *value = named->value.i32;
-+ break;
-+ case KSTAT_DATA_UINT32:
-+ DEBUGMSGTL(("kernel_sunos5"," value: %u\n", named->value.ui32));
-+ *value = named->value.ui32;
-+ break;
-+ case KSTAT_DATA_INT64:
-+ DEBUGMSGTL(("kernel_sunos5"," value: %ld\n", named->value.i64));
-+ *value = named->value.i64;
-+ break;
-+ case KSTAT_DATA_UINT64:
-+ DEBUGMSGTL(("kernel_sunos5"," value: %llu\n", named->value.ui64));
-+ *value = named->value.ui64;
-+ break;
-+#else
-+ case KSTAT_DATA_LONG:
-+ DEBUGMSGTL(("kernel_sunos5"," value: %ld\n", named->value.l));
-+ *value = named->value.l;
-+ break;
-+ case KSTAT_DATA_ULONG:
-+ DEBUGMSGTL(("kernel_sunos5"," value: %lu\n", named->value.ul));
-+ *value = named->value.ul;
-+ break;
-+ case KSTAT_DATA_LONGLONG:
-+ DEBUGMSGTL(("kernel_sunos5"," value: %lld\n", (long) named->value.ll));
-+ *value = (long)named->value.ll;
-+ break;
-+ case KSTAT_DATA_ULONGLONG:
-+ DEBUGMSGTL(("kernel_sunos5"," value: %llu\n",
-+ (unsigned long) named->value.ull));
-+ *value = (unsigned long)named->value.ull;
-+ break;
-+#endif
-+ default:
-+ ret = -1; /* fail */
-+ break;
-+ }
-+ Return:
-+ return ret;
-+}
-+
- static void
- set_if_info(mib2_ifEntry_t *ifp, unsigned index, char *name, uint64_t flags,
-- int mtu)
-+ boolean_t flags_unknown, int mtu)
- {
- boolean_t havespeed = B_FALSE;
-+ char phydevname[100];
-+ char devbasename[100];
-+ int instance = -1;
-
- /*
- * Set basic information
-@@ -1627,7 +1918,10 @@ set_if_info(mib2_ifEntry_t *ifp, unsigned index, char *name, uint64_t flags,
- ifp->ifDescr.o_length = strlen(name);
- strcpy(ifp->ifDescr.o_bytes, name);
- ifp->ifAdminStatus = (flags & IFF_UP) ? 1 : 2;
-- ifp->ifOperStatus = ((flags & IFF_UP) && (flags & IFF_RUNNING)) ? 1 : 2;
-+ if (flags_unknown)
-+ ifp->ifOperStatus = 4; /* status unknown */
-+ else
-+ ifp->ifOperStatus = ((flags & IFF_UP) && (flags & IFF_RUNNING)) ? 1 : 2;
- ifp->ifLastChange = 0; /* Who knows ... */
- ifp->flags = flags;
- ifp->ifMtu = mtu;
-@@ -1649,14 +1943,26 @@ set_if_info(mib2_ifEntry_t *ifp, unsigned index, char *name, uint64_t flags,
- * this is good
- */
- havespeed = B_TRUE;
-+ } else if ((getKstatInt("link", name, "ifspeed", &ifp->ifSpeed) == 0) ||
-+ (getKstatInt("link", name, "ifSpeed", &ifp->ifSpeed) == 0)) {
-+ havespeed = B_TRUE;
- }
--
- /* make ifOperStatus depend on link status if available */
- if (ifp->ifAdminStatus == 1) {
- int i_tmp;
- /* only UPed interfaces get correct link status - if any */
- if (getKstatInt(NULL, name,"link_up",&i_tmp) == 0) {
- ifp->ifOperStatus = i_tmp ? 1 : 2;
-+ } else if(link_to_phydev(name, phydevname) == 0) {
-+ strcpy(devbasename, phydevname);
-+ DEBUGMSGTL(("kernel_sunos5","phydevname = %s\n", phydevname));
-+ _dlpi_parse_devname(devbasename, &instance);
-+ DEBUGMSGTL(("kernel_sunos5","devbasename = %s, "
-+ "instance= %d\n", devbasename, instance));
-+ if(getKstatIntInstance(devbasename, instance, "phys",
-+ "link_up", &i_tmp) == 0) {
-+ ifp->ifOperStatus = i_tmp ? 1 : 2;
-+ }
- #ifdef IFF_FAILED
- } else if (flags & IFF_FAILED) {
- /*
Modified: csw/mgar/pkg/netsnmp/trunk/files/0035-bug-1849903.patch
===================================================================
--- csw/mgar/pkg/netsnmp/trunk/files/0035-bug-1849903.patch 2014-12-19 12:18:08 UTC (rev 24492)
+++ csw/mgar/pkg/netsnmp/trunk/files/0035-bug-1849903.patch 2014-12-19 12:32:22 UTC (rev 24493)
@@ -1,18 +1,5 @@
--- a/agent/mibgroup/if-mib/ifTable/ifTable_data_access.c
+++ b/agent/mibgroup/if-mib/ifTable/ifTable_data_access.c
-@@ -14,6 +14,12 @@
-
- netsnmp_feature_require(container_linked_list)
-
-+typedef struct cd_container_s {
-+ netsnmp_container *current;
-+ netsnmp_container *deleted;
-+} cd_container;
-+
-+
- /*
- * include our parent header
- */
@@ -485,8 +491,21 @@ static void
_add_new_interface(netsnmp_interface_entry *ifentry,
netsnmp_container *container)
@@ -37,28 +24,6 @@
DEBUGMSGTL(("ifTable:access", "creating new entry\n"));
/*
-@@ -533,6 +552,21 @@ _add_new_interface(netsnmp_interface_entry *ifentry,
- }
- }
- }
-+
-+/**
-+ * delete removed entry
-+ */
-+static void
-+_delete_missing_interface(ifTable_rowreq_ctx *rowreq_ctx,
-+ netsnmp_container *container)
-+{
-+ DEBUGMSGTL(("ifTable:access", "removing missing entry %s\n",
-+ rowreq_ctx->data.ifName));
-+
-+ CONTAINER_REMOVE(container, rowreq_ctx);
-+
-+ ifTable_release_rowreq_ctx(rowreq_ctx);
-+}
-
- /**
- * add new entry
--- a/agent/mibgroup/if-mib/ifTable/ifTable_data_access.h
+++ b/agent/mibgroup/if-mib/ifTable/ifTable_data_access.h
@@ -50,6 +50,8 @@ extern "C" {
Modified: csw/mgar/pkg/netsnmp/trunk/files/0052-dyn-cpu-cpu_kstat.patch
===================================================================
--- csw/mgar/pkg/netsnmp/trunk/files/0052-dyn-cpu-cpu_kstat.patch 2014-12-19 12:18:08 UTC (rev 24492)
+++ csw/mgar/pkg/netsnmp/trunk/files/0052-dyn-cpu-cpu_kstat.patch 2014-12-19 12:32:22 UTC (rev 24493)
@@ -185,3 +185,111 @@
int
_cpu_status( char *state)
{
+--- a/agent/mibgroup/hardware/cpu/cpu.c
++++ b/agent/mibgroup/hardware/cpu/cpu.c
+@@ -271,4 +271,60 @@ void _cpu_copy_stats( netsnmp_cpu_info *cpu )
+ cpu2->pageIn = cpu->pageIn;
+ cpu2->pageOut = cpu->pageOut;
+ }
++
++ /*
++ * Updates the cpu list, keeping the cpus whose indices are passed
++ * assumes the passed linked list of indices is sorted in ascending order
++ * returns the number of deleted cpus
++ */
++int netsnmp_update_cpu_list( struct cpu_idx *new_cpu_list )
++{
++ netsnmp_cpu_info *prev, *current, *temp1, *temp2;
++ int n=0;
++ netsnmp_cpu_info *cpu;
++
++ for( prev=current=_cpu_head; current && new_cpu_list ;
++ current=current->next, new_cpu_list=new_cpu_list->next ) {
++ if ( current->idx == new_cpu_list->idx ) {
++ prev=current;
++ } else {
++ current=current->next;
++ while ( current && (current->idx != new_cpu_list->idx) )
++ current = current->next;
++ if ( !current ) {
++ /*This shouldn't happen. Something went really wrong */
++ return -1;
++ }
++
++ temp1 = prev->next;
++ prev->next = current;
++ prev = current;
++ /* remove the unassigned cpus */
++ while ( temp1 != current ) {
++ temp2 = temp1;
++ temp1 = temp1->next;
++ n++;
++ SNMP_FREE(temp2->history);
++ SNMP_FREE(temp2);
++ }
++ }
++ } /*end of for */
++
++ if ( !current && new_cpu_list ) {
++ /* This shouldn't happen. */
++ return -1;
++ }
++
++ /* Delete the unassigned trailing cpus from the list */
++ while ( current ) {
++ temp2 = current;
++ current = current->next;
++ n++;
++ SNMP_FREE(temp2->history);
++ SNMP_FREE(temp2);
++ }
++ prev->next = NULL;
++ return n;
++}
++
+ #endif /* NETSNMP_FEATURE_REMOVE_HARDWARE_CPU_COPY_STATS */
+--- a/agent/mibgroup/hardware/cpu/cpu_kstat.c
++++ b/agent/mibgroup/hardware/cpu/cpu_kstat.c
+@@ -18,7 +18,9 @@ extern kstat_ctl_t *kstat_fd;
+ extern int cpu_num;
+ int _cpu_status(char *state);
+ static void add_new_kstat_cpu_entry(kstat_t *ksp);
++
+ static struct cpu_idx * add_cpu_idx(struct cpu_idx * head, int idx);
++int netsnmp_update_cpu_list( struct cpu_idx * ); /* returns the number of deleted cpus */
+
+ /*
+ * Initialise the list of CPUs on the system
+@@ -49,7 +51,7 @@ void init_cpu_kstat( void ) {
+ }
+
+ /*
+- * adds the new cpu entry to the exisitng list
++ * adds the new cpu entry to the existing list
+ */
+ static void
+ add_new_kstat_cpu_entry( kstat_t *ksp ) {
+@@ -211,7 +213,8 @@ add_cpu_idx(struct cpu_idx * head, int idx)
+ return head;
+ }
+ }
+-
++ DEBUGMSG(("cpu", "(cpu_idx creation failed)\n"));
++ return head;
+ }
+
+ int
+--- a/include/net-snmp/agent/hardware/cpu.h
++++ b/include/net-snmp/agent/hardware/cpu.h
+@@ -66,3 +66,11 @@ netsnmp_cpu_info *netsnmp_cpu_get_byName( char*, int );
+
+ netsnmp_cache *netsnmp_cpu_get_cache( void );
+ int netsnmp_cpu_load( void );
++
++ /* Auxilary structure used for updating the new cpu list */
++struct cpu_idx {
++ int idx;
++ struct cpu_idx *next;
++};
++
++
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the devel
mailing list