Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 2 Oct 2014 19:11:08 +0000 (UTC)
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r369851 - in head/devel/plan9port: . files
Message-ID:  <201410021911.s92JB82f048400@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: glebius (src committer)
Date: Thu Oct  2 19:11:07 2014
New Revision: 369851
URL: https://svnweb.freebsd.org/changeset/ports/369851
QAT: https://qat.redports.org/buildarchive/r369851/

Log:
  Use getifaddrs(3) instead of kvm(3) to access ifnet statistics. Fixes
  current breakage on head and future ones.
  
  Approved by:	bapt (blanket)

Added:
  head/devel/plan9port/files/patch-src-cmd-auxstats-FreeBSD.c   (contents, props changed)
Modified:
  head/devel/plan9port/Makefile

Modified: head/devel/plan9port/Makefile
==============================================================================
--- head/devel/plan9port/Makefile	Thu Oct  2 19:07:34 2014	(r369850)
+++ head/devel/plan9port/Makefile	Thu Oct  2 19:11:07 2014	(r369851)
@@ -3,7 +3,7 @@
 
 PORTNAME=	plan9port
 PORTVERSION=	20140306
-PORTREVISION=	1
+PORTREVISION=	2
 CATEGORIES=	devel plan9
 MASTER_SITES=	http://swtch.com/${PORTNAME}/
 

Added: head/devel/plan9port/files/patch-src-cmd-auxstats-FreeBSD.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/devel/plan9port/files/patch-src-cmd-auxstats-FreeBSD.c	Thu Oct  2 19:11:07 2014	(r369851)
@@ -0,0 +1,89 @@
+--- src/cmd/auxstats/FreeBSD.c.orig	2010-03-18 01:25:34.000000000 +0300
++++ src/cmd/auxstats/FreeBSD.c	2014-10-02 22:55:32.000000000 +0400
+@@ -8,20 +8,15 @@
+ #include <sys/time.h>
+ #include <sys/dkstat.h>
+ #include <net/if.h>
+-#include <net/if_var.h>
+ #include <net/if_dl.h>
+ #include <net/if_types.h>
+-#if __FreeBSD_version < 600000
+-#include <machine/apm_bios.h>
+-#endif
+ #include <sys/ioctl.h>
+ #include <limits.h>
+ #include <libc.h>
+ #include <bio.h>
++#include <ifaddrs.h>
+ #include "dat.h"
+ 
+-/* XXX: #if __FreeBSD_version */
+-
+ void xapm(int);
+ void xloadavg(int);
+ void xcpu(int);
+@@ -45,7 +40,6 @@
+ static kvm_t *kvm;
+ 
+ static struct nlist nl[] = {
+-	{ "_ifnet" },
+ 	{ "_cp_time" },
+ 	{ "" }
+ };
+@@ -86,44 +80,26 @@
+ void
+ xnet(int first)
+ {
++	struct ifaddrs *ifap, *ifa;
+ 	ulong out, in, outb, inb, err;
+-	static ulong ifnetaddr;
+-	ulong addr;
+-	struct ifnet ifnet;
+-	struct ifnethead ifnethead;
+-	char name[16];
+ 
+ 	if(first)
+ 		return;
+ 
+-	if(ifnetaddr == 0){
+-		ifnetaddr = nl[0].n_value;
+-		if(ifnetaddr == 0)
+-			return;
+-	}
+-
+-	if(kread(ifnetaddr, (char*)&ifnethead, sizeof ifnethead) < 0)
++	if (getifaddrs(&ifap) != 0)
+ 		return;
+ 
+ 	out = in = outb = inb = err = 0;
+-	addr = (ulong)TAILQ_FIRST(&ifnethead);
+-	while(addr){
+-#if __FreeBSD_version < 500000
+-		if(kread(addr, (char*)&ifnet, sizeof ifnet) < 0
+-		|| kread((ulong)ifnet.if_name, name, 16) < 0)
+-			return;
+-#else
+-		if(kread(addr, (char*)&ifnet, sizeof ifnet) < 0
+-		|| kread((ulong)ifnet.if_dname, name, 16) < 0)
+-			return;
+-#endif
+-		name[15] = 0;
+-		addr = (ulong)TAILQ_NEXT(&ifnet, if_link);
+-		out += ifnet.if_opackets;
+-		in += ifnet.if_ipackets;
+-		outb += ifnet.if_obytes;
+-		inb += ifnet.if_ibytes;
+-		err += ifnet.if_oerrors+ifnet.if_ierrors;
++
++#define	IFA_STAT(s)	(((struct if_data *)ifa->ifa_data)->ifi_ ## s)
++	for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
++		if (ifa->ifa_addr->sa_family != AF_LINK)
++			continue;
++		out += IFA_STAT(opackets);
++		in += IFA_STAT(ipackets);
++		outb += IFA_STAT(obytes);
++		inb += IFA_STAT(ibytes);
++		err += IFA_STAT(oerrors) + IFA_STAT(ierrors);
+ 	}
+ 	Bprint(&bout, "etherin %lud 1000\n", in);
+ 	Bprint(&bout, "etherout %lud 1000\n", out);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201410021911.s92JB82f048400>