Subject: bin/19381: netstat shows negative percentage
To: None <gnats-bugs@gnats.netbsd.org>
From: None <mlelstv@serpens.de>
List: netbsd-bugs
Date: 12/14/2002 11:07:53
>Number:         19381
>Category:       bin
>Synopsis:       netstat shows negative percentage
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Dec 14 02:08:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Michael van Elst
>Release:        NetBSD 1.6_STABLE
>Organization:
none
>Environment:
	
	
System: NetBSD pepew 1.6_STABLE NetBSD 1.6_STABLE (PEPEW) #23: Sun Nov 24 01:46:15 MET 2002 src@pepew:/amd/fud/d/0/src/sys/arch/i386/compile/PEPEW i386
Architecture: i386
Machine: i386
>Description:
When more than about 20.5MByte are allocated to the network
netstat reports a negative percentage because (totused * 100)
overflows integer arithmetic.

>How-To-Repeat:
Mount an NFS server via IPSEC (AH-as-transport or ESP-as-tunnel) and
use it for a while. This will leak mbufs.

| pepew% netstat -m
| 33114 mbufs in use:
|         33109 mbufs allocated to data
|         3 mbufs allocated to packet headers
|         2 mbufs allocated to socket names and addresses
| 165/174 mapped pages in use
| 25020 Kbytes allocated to network (-67% in use)
| 0 requests for memory denied
| 0 requests for memory delayed
| 14 calls to protocol drain routines

>Fix:

RCS file: /cvsroot/basesrc/usr.bin/netstat/mbuf.c,v
retrieving revision 1.17
diff -u -r1.17 mbuf.c
--- mbuf.c      2002/03/09 23:26:51     1.17
+++ mbuf.c      2002/12/14 09:56:39
@@ -157,7 +157,7 @@
            (mclpool.pr_npages << mclpa.pa_pageshift);
        totused = (mbpool.pr_nget - mbpool.pr_nput) * mbpool.pr_size +
            (mclpool.pr_nget - mclpool.pr_nput) * mclpool.pr_size;
-       totpct = (totmem == 0)? 0 : ((totused * 100)/totmem);
+       totpct = (totmem == 0)? 0 : (int)(((double)totused * 100)/totmem);
        printf("%u Kbytes allocated to network (%d%% in use)\n",
            totmem / 1024, totpct);
        printf("%lu requests for memory denied\n", mbstat.m_drops);

>Release-Note:
>Audit-Trail:
>Unformatted: