View | Details | Raw Unified | Return to bug 194096 | Differences between
and this patch

Collapse All | Expand All

(-)Makefile (-1 / +1 lines)
Lines 3-9 Link Here
3
3
4
PORTNAME=	netxms
4
PORTNAME=	netxms
5
PORTVERSION=	1.2.14
5
PORTVERSION=	1.2.14
6
PORTREVISION=	1
6
PORTREVISION=	2
7
CATEGORIES=	net-mgmt
7
CATEGORIES=	net-mgmt
8
MASTER_SITES=	http://www.netxms.org/download/ \
8
MASTER_SITES=	http://www.netxms.org/download/ \
9
		http://www.netxms.org/download/archive/
9
		http://www.netxms.org/download/archive/
(-)files/patch-src-agent-subagents-freebsd-freebsd.cpp (+23 lines)
Line 0 Link Here
1
--- src/agent/subagents/freebsd/freebsd.cpp.orig	2014-10-02 16:57:50.000000000 +0400
2
+++ src/agent/subagents/freebsd/freebsd.cpp	2014-10-02 16:58:48.000000000 +0400
3
@@ -48,14 +48,14 @@
4
 	{ _T("FileSystem.UsedPerc(*)"),       H_DiskInfo,        (const TCHAR *)DISK_USED_PERC,    DCI_DT_FLOAT,	DCIDESC_FS_USEDPERC },
5
 
6
 	{ _T("Net.Interface.AdminStatus(*)"), H_NetIfAdmStatus,  NULL,				DCI_DT_INT,	DCIDESC_NET_INTERFACE_ADMINSTATUS },
7
-	{ _T("Net.Interface.BytesIn(*)"),     H_NetIfInfoFromKVM, (const TCHAR *)IF_INFO_BYTES_IN,    DCI_DT_UINT64, DCIDESC_NET_INTERFACE_BYTESIN },
8
-	{ _T("Net.Interface.BytesOut(*)"),    H_NetIfInfoFromKVM, (const TCHAR *)IF_INFO_BYTES_OUT,   DCI_DT_UINT64, DCIDESC_NET_INTERFACE_BYTESOUT },
9
-	{ _T("Net.Interface.InErrors(*)"),    H_NetIfInfoFromKVM, (const TCHAR *)IF_INFO_IN_ERRORS,   DCI_DT_UINT64, DCIDESC_NET_INTERFACE_INERRORS },
10
+	{ _T("Net.Interface.BytesIn(*)"),     H_NetIfInfo, (const TCHAR *)IF_INFO_BYTES_IN,    DCI_DT_UINT64, DCIDESC_NET_INTERFACE_BYTESIN },
11
+	{ _T("Net.Interface.BytesOut(*)"),    H_NetIfInfo, (const TCHAR *)IF_INFO_BYTES_OUT,   DCI_DT_UINT64, DCIDESC_NET_INTERFACE_BYTESOUT },
12
+	{ _T("Net.Interface.InErrors(*)"),    H_NetIfInfo, (const TCHAR *)IF_INFO_IN_ERRORS,   DCI_DT_UINT64, DCIDESC_NET_INTERFACE_INERRORS },
13
 	{ _T("Net.Interface.Link(*)"),        H_NetIfLink,       NULL,				DCI_DT_DEPRECATED,	DCIDESC_DEPRECATED },
14
 	{ _T("Net.Interface.OperStatus(*)"),  H_NetIfLink,       NULL,				DCI_DT_INT,	DCIDESC_NET_INTERFACE_OPERSTATUS },
15
-	{ _T("Net.Interface.OutErrors(*)"),   H_NetIfInfoFromKVM, (const TCHAR *)IF_INFO_OUT_ERRORS,  DCI_DT_UINT64, DCIDESC_NET_INTERFACE_OUTERRORS },
16
-	{ _T("Net.Interface.PacketsIn(*)"),   H_NetIfInfoFromKVM, (const TCHAR *)IF_INFO_PACKETS_IN,  DCI_DT_UINT64, DCIDESC_NET_INTERFACE_PACKETSIN },
17
-	{ _T("Net.Interface.PacketsOut(*)"),  H_NetIfInfoFromKVM, (const TCHAR *)IF_INFO_PACKETS_OUT, DCI_DT_UINT64, DCIDESC_NET_INTERFACE_PACKETSOUT },
18
+	{ _T("Net.Interface.OutErrors(*)"),   H_NetIfInfo, (const TCHAR *)IF_INFO_OUT_ERRORS,  DCI_DT_UINT64, DCIDESC_NET_INTERFACE_OUTERRORS },
19
+	{ _T("Net.Interface.PacketsIn(*)"),   H_NetIfInfo, (const TCHAR *)IF_INFO_PACKETS_IN,  DCI_DT_UINT64, DCIDESC_NET_INTERFACE_PACKETSIN },
20
+	{ _T("Net.Interface.PacketsOut(*)"),  H_NetIfInfo, (const TCHAR *)IF_INFO_PACKETS_OUT, DCI_DT_UINT64, DCIDESC_NET_INTERFACE_PACKETSOUT },
21
 	{ _T("Net.IP.Forwarding"),            H_NetIpForwarding, (const TCHAR *)4,			DCI_DT_INT,	DCIDESC_NET_IP_FORWARDING },
22
 	{ _T("Net.IP6.Forwarding"),           H_NetIpForwarding, (const TCHAR *)6,			DCI_DT_INT,	DCIDESC_NET_IP6_FORWARDING },
23
 
(-)files/patch-src-agent-subagents-freebsd-net.cpp (+181 lines)
Line 0 Link Here
1
--- src/agent/subagents/freebsd/net.cpp.orig	2014-10-02 16:54:48.000000000 +0400
2
+++ src/agent/subagents/freebsd/net.cpp	2014-10-02 17:19:53.000000000 +0400
3
@@ -32,7 +32,6 @@
4
 #include <net/if_media.h>
5
 #include <net/if_dl.h>
6
 #include <net/if_types.h>
7
-#include <net/if_var.h>
8
 #include <net/route.h>
9
 #include <net/iso88025.h>
10
 #include <netinet/if_ether.h>
11
@@ -40,8 +39,7 @@
12
 #include <ifaddrs.h>
13
 #include <arpa/inet.h>
14
 #include <net/ethernet.h>
15
-#include <kvm.h>
16
-#include <nlist.h>
17
+#include <ifaddrs.h>
18
 
19
 #include "net.h"
20
 
21
@@ -60,14 +58,6 @@
22
 	int index;
23
 } IFLIST;
24
 
25
-struct nlist nl[] = {
26
-#define N_IFNET 0
27
-	{ (char *)"_ifnet" },
28
-	{ NULL },
29
-};
30
-
31
-kvm_t *kvmd = NULL;
32
-
33
 LONG H_NetIpForwarding(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *pValue)
34
 {
35
 	int nVer = CAST_FROM_POINTER(pArg, int);
36
@@ -568,94 +558,66 @@
37
 	return nRet;
38
 }
39
 
40
-LONG H_NetIfInfoFromKVM(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *pValue)
41
+LONG H_NetIfInfo(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *pValue)
42
 {
43
-	int nRet = SYSINFO_RC_SUCCESS;
44
 	char szArg[512];
45
-	u_long ifnetaddr;
46
-	struct ifnet ifnet;
47
-	struct ifnethead ifnethead;
48
-#if __FreeBSD__ < 5
49
-	char szTName[IFNAMSIZ];
50
-#endif
51
-	char szName[IFNAMSIZ];
52
+	struct ifaddrs *ifap, *ifa;
53
+	u_int index;
54
 
55
 	AgentGetParameterArgA(pszParam, 1, szArg, sizeof(szArg));
56
 
57
-	if (szArg[0] != 0)
58
+	if (szArg[0] == 0)
59
+		return SYSINFO_RC_SUCCESS;
60
+
61
+	if (szArg[0] >= '0' && szArg[0] <= '9')
62
+		index = atoi(szArg);
63
+	else
64
+		index = 0;
65
+
66
+	if (getifaddrs(&ifap) != 0)
67
 	{
68
-		if (szArg[0] >= '0' && szArg[0] <= '9')
69
-		{
70
-			// index
71
-			if (if_indextoname(atoi(szArg), szArg) != szArg)
72
-			{
73
-				// not found
74
-				nRet = SYSINFO_RC_ERROR;
75
-			}
76
-		}
77
+		return SYSINFO_RC_ERROR;
78
+	}
79
 
80
-		if (nRet == SYSINFO_RC_SUCCESS)
81
-		{
82
-			nRet = SYSINFO_RC_ERROR;
83
+	for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
84
+		if (ifa->ifa_addr->sa_family != AF_LINK)
85
+			continue;
86
+		if (index) {
87
+			if (index != if_nametoindex(ifa->ifa_name))
88
+				continue;
89
+		} else if (strcmp(ifa->ifa_name, szArg) != 0)
90
+			continue;
91
 
92
-			if (kvmd == NULL) {
93
-				kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, NULL);
94
-				if (kvmd == NULL)
95
-					return SYSINFO_RC_ERROR;
96
-				if (kvm_nlist(kvmd, nl) < 0)
97
-					return SYSINFO_RC_ERROR;
98
-				if (nl[0].n_type == 0)
99
-					return SYSINFO_RC_ERROR;
100
-			}
101
-			ifnetaddr = nl[N_IFNET].n_value;
102
-			if (kvm_read(kvmd, ifnetaddr, &ifnethead, sizeof(ifnethead)) != sizeof(ifnethead))
103
-				return SYSINFO_RC_ERROR;
104
-			ifnetaddr = (u_long)TAILQ_FIRST(&ifnethead);
105
-			while (ifnetaddr) {
106
-				if (kvm_read(kvmd, ifnetaddr, &ifnet, sizeof(ifnet)) != sizeof(ifnet))
107
-					return SYSINFO_RC_ERROR;
108
-				ifnetaddr = (u_long)TAILQ_NEXT(&ifnet, if_link);
109
-#if __FreeBSD__ >= 5
110
-				strlcpy(szName, ifnet.if_xname, sizeof(szName));
111
-#else
112
-				if (kvm_read(kvmd, ifnet.if_name, szTName, sizeof(szTName)) != sizeof(szTName))
113
-					return SYSINFO_RC_ERROR;
114
-				szTName[sizeof(szTName) - 1] = '\0';
115
-				snprintf(szName, sizeof(szName), "%s%d", szTName, ifnet.if_unit);
116
-#endif
117
-				if (strcmp(szName, szArg) == 0) {
118
-					nRet = SYSINFO_RC_SUCCESS;
119
-					switch((long)pArg)
120
-					{
121
-						case IF_INFO_BYTES_IN:
122
-							ret_uint(pValue, ifnet.if_ibytes);
123
-							break;
124
-						case IF_INFO_BYTES_OUT:
125
-							ret_uint(pValue, ifnet.if_obytes);
126
-							break;
127
-						case IF_INFO_IN_ERRORS:
128
-							ret_uint(pValue, ifnet.if_ierrors);
129
-							break;
130
-						case IF_INFO_OUT_ERRORS:
131
-							ret_uint(pValue, ifnet.if_oerrors);
132
-							break;
133
-						case IF_INFO_PACKETS_IN:
134
-							ret_uint(pValue, ifnet.if_ipackets);
135
-							break;
136
-						case IF_INFO_PACKETS_OUT:
137
-							ret_uint(pValue, ifnet.if_opackets);
138
-							break;
139
-						default:
140
-							nRet = SYSINFO_RC_UNSUPPORTED;
141
-							break;
142
-					}
143
-					break;
144
-				}
145
-				else
146
-					continue;
147
-			}
148
+#define	IFA_STAT(s)	(((struct if_data *)ifa->ifa_data)->ifi_ ## s)
149
+
150
+		switch((long)pArg)
151
+		{
152
+			case IF_INFO_BYTES_IN:
153
+				ret_uint(pValue, IFA_STAT(ibytes));
154
+				break;
155
+			case IF_INFO_BYTES_OUT:
156
+				ret_uint(pValue, IFA_STAT(obytes));
157
+				break;
158
+			case IF_INFO_IN_ERRORS:
159
+				ret_uint(pValue, IFA_STAT(ierrors));
160
+				break;
161
+			case IF_INFO_OUT_ERRORS:
162
+				ret_uint(pValue, IFA_STAT(oerrors));
163
+				break;
164
+			case IF_INFO_PACKETS_IN:
165
+				ret_uint(pValue, IFA_STAT(ipackets));
166
+				break;
167
+			case IF_INFO_PACKETS_OUT:
168
+				ret_uint(pValue, IFA_STAT(opackets));
169
+				break;
170
+			default:
171
+				freeifaddrs(ifap);
172
+				return SYSINFO_RC_UNSUPPORTED;
173
 		}
174
+		freeifaddrs(ifap);
175
+		return SYSINFO_RC_SUCCESS;
176
 	}
177
 
178
-	return nRet;
179
+	freeifaddrs(ifap);
180
+	return SYSINFO_RC_ERROR;
181
 }
(-)files/patch-src-agent-subagents-freebsd-net.h (+10 lines)
Line 0 Link Here
1
--- src/agent/subagents/freebsd/net.h.orig	2014-10-02 16:59:04.000000000 +0400
2
+++ src/agent/subagents/freebsd/net.h	2014-10-02 16:59:10.000000000 +0400
3
@@ -39,6 +39,6 @@
4
 LONG H_NetArpCache(const TCHAR *, const TCHAR *, StringList *);
5
 LONG H_NetIfList(const TCHAR *, const TCHAR *, StringList *);
6
 LONG H_NetRoutingTable(const TCHAR *, const TCHAR *, StringList *);
7
-LONG H_NetIfInfoFromKVM(const TCHAR *, const TCHAR *, TCHAR *);
8
+LONG H_NetIfInfo(const TCHAR *, const TCHAR *, TCHAR *);
9
 
10
 #endif // __NET_H__

Return to bug 194096