Stuart Henderson <st...@openbsd.org> writes:

> On 2015/12/06 09:11, Antoine Jacoutot wrote:
>> * net/ifstat
>> * net/libdnet
>> * net/nmap
>> * net/ocserv
>> * security/aircrack-ng
>
> From my test build:
>
> None of the above actually need things from if_var.h, they're ok with the
> whole file wrapped in ifdef kernel.
>
>> * devel/libgtop2
>
> mpi's already taking care of libgtop2
>
>> * net/zabbix

The following patch is supposed to affect only OpenBSD and thus should
be easy to push upstream.  No need to read kernel mem to get if_data,
zabbix already had code in case kvm_read fails.

Robert, does the following work fine for you?

Index: Makefile
===================================================================
RCS file: /cvs/ports/net/zabbix/Makefile,v
retrieving revision 1.117
diff -u -p -r1.117 Makefile
--- Makefile    30 Oct 2015 12:47:40 -0000      1.117
+++ Makefile    7 Dec 2015 12:18:37 -0000
@@ -5,7 +5,7 @@ COMMENT-server =        network and application
 COMMENT-web =          network and application monitoring - web frontend
 
 VERSION =              2.4.6
-REVISION-main =                1
+REVISION-main =                2
 REVISION-server =      0
 DISTNAME =             zabbix-${VERSION}
 FULLPKGNAME-main =     zabbix-agent-${VERSION}
Index: patches/patch-src_libs_zbxsysinfo_openbsd_net_c
===================================================================
RCS file: patches/patch-src_libs_zbxsysinfo_openbsd_net_c
diff -N patches/patch-src_libs_zbxsysinfo_openbsd_net_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_libs_zbxsysinfo_openbsd_net_c     7 Dec 2015 12:18:37 
-0000
@@ -0,0 +1,99 @@
+$OpenBSD$
+
+Stop using struct ifnet and libkvm for interface stats.
+
+--- src/libs/zbxsysinfo/openbsd/net.c.orig     Sun Dec  6 15:59:59 2015
++++ src/libs/zbxsysinfo/openbsd/net.c  Sun Dec  6 16:19:21 2015
+@@ -24,13 +24,8 @@
+ 
+ #include <sys/sockio.h>
+ 
+-#if OpenBSD >= 201405
+-#     include <net/if_var.h>  /* structs ifnet and ifnet_head are defined in 
this header since OpenBSD 5.5 */
+-#endif
+-
+ static struct nlist kernel_symbols[] =
+ {
+-      {"_ifnet", N_UNDF, 0, 0, 0},
+       {"_tcbtable", N_UNDF, 0, 0, 0},
+       {NULL, 0, 0, 0, 0}
+ };
+@@ -43,11 +38,6 @@ static int  get_ifdata(const char *if_name,
+               zbx_uint64_t *tbytes, zbx_uint64_t *tpackets, zbx_uint64_t 
*terrors,
+               zbx_uint64_t *icollisions, char **error)
+ {
+-      struct ifnet_head       head;
+-      struct ifnet            *ifp;
+-
+-      kvm_t   *kp;
+-      int     len = 0;
+       int     ret = SYSINFO_RET_FAIL;
+ 
+       if (NULL == if_name || '\0' == *if_name)
+@@ -88,66 +78,7 @@ static int  get_ifdata(const char *if_name,
+       if (icollisions)
+               *icollisions = 0;
+ 
+-      if (NULL != (kp = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL))) /* 
requires root privileges */
+       {
+-              struct ifnet    v;
+-
+-              if (N_UNDF == kernel_symbols[IFNET_ID].n_type)
+-                      if (0 != kvm_nlist(kp, &kernel_symbols[0]))
+-                              kernel_symbols[IFNET_ID].n_type = N_UNDF;
+-
+-              if (N_UNDF != kernel_symbols[IFNET_ID].n_type)
+-              {
+-                      len = sizeof(struct ifnet_head);
+-
+-                      if (kvm_read(kp, kernel_symbols[IFNET_ID].n_value, 
&head, len) >= len)
+-                      {
+-                              len = sizeof(struct ifnet);
+-
+-                              for (ifp = head.tqh_first; ifp; ifp = 
v.if_list.tqe_next)
+-                              {
+-                                      if (kvm_read(kp, (u_long)ifp, &v, len) 
< len)
+-                                              break;
+-
+-                                      if (0 == strcmp(if_name, v.if_xname))
+-                                      {
+-                                              if (ibytes)
+-                                                      *ibytes += v.if_ibytes;
+-                                              if (ipackets)
+-                                                      *ipackets += 
v.if_ipackets;
+-                                              if (ierrors)
+-                                                      *ierrors += 
v.if_ierrors;
+-                                              if (idropped)
+-                                                      *idropped += 
v.if_iqdrops;
+-                                              if (obytes)
+-                                                      *obytes += v.if_obytes;
+-                                              if (opackets)
+-                                                      *opackets += 
v.if_opackets;
+-                                              if (oerrors)
+-                                                      *oerrors += 
v.if_oerrors;
+-                                              if (tbytes)
+-                                                      *tbytes += v.if_ibytes 
+ v.if_obytes;
+-                                              if (tpackets)
+-                                                      *tpackets += 
v.if_ipackets + v.if_opackets;
+-                                              if (terrors)
+-                                                      *terrors += 
v.if_ierrors + v.if_oerrors;
+-                                              if (icollisions)
+-                                                      *icollisions += 
v.if_collisions;
+-
+-                                              ret = SYSINFO_RET_OK;
+-                                      }
+-                              }
+-                      }
+-              }
+-              kvm_close(kp);
+-
+-              if (SYSINFO_RET_FAIL == ret)
+-                      *error = zbx_strdup(NULL, "Cannot find information for 
this network interface.");
+-      }
+-      else
+-      {
+-              /* fallback to using SIOCGIFDATA */
+-
+               int             if_s;
+               struct ifreq    ifr;
+               struct if_data  v;


-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to