CVS commit: src/usr.bin/netstat

2024-02-24 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 24 09:53:26 UTC 2024

Modified Files:
src/usr.bin/netstat: mbuf.c

Log Message:
Don't truncate mo_descr output and protect against missing terminating NUL.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/netstat/mbuf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/mbuf.c
diff -u src/usr.bin/netstat/mbuf.c:1.35 src/usr.bin/netstat/mbuf.c:1.36
--- src/usr.bin/netstat/mbuf.c:1.35	Thu Sep  1 10:10:20 2022
+++ src/usr.bin/netstat/mbuf.c	Sat Feb 24 09:53:26 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: mbuf.c,v 1.35 2022/09/01 10:10:20 msaitoh Exp $	*/
+/*	$NetBSD: mbuf.c,v 1.36 2024/02/24 09:53:26 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)mbuf.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: mbuf.c,v 1.35 2022/09/01 10:10:20 msaitoh Exp $");
+__RCSID("$NetBSD: mbuf.c,v 1.36 2024/02/24 09:53:26 mlelstv Exp $");
 #endif
 #endif /* not lint */
 
@@ -225,7 +225,7 @@ dump_drain:
 
 	for (mo = (void *) data, lines = 0; len >= sizeof(*mo);
 	len -= sizeof(*mo), mo++) {
-		char buf[32];
+		char buf[34];
 		if (vflag == 1 &&
 		mo->mo_counter[MOWNER_COUNTER_CLAIMS] == 0 &&
 		mo->mo_counter[MOWNER_COUNTER_EXT_CLAIMS] == 0 &&
@@ -239,7 +239,7 @@ dump_drain:
 		mo->mo_counter[MOWNER_COUNTER_CLUSTER_CLAIMS] ==
 		mo->mo_counter[MOWNER_COUNTER_CLUSTER_RELEASES])
 			continue;
-		snprintf(buf, sizeof(buf), "%16.16s %-13s",
+		snprintf(buf, sizeof(buf), "%16.16s %-13.16s",
 		mo->mo_name, mo->mo_descr);
 		if ((lines % 24) == 0 || lines > 24) {
 			printf("%30s %-8s %10s %10s %10s\n",



CVS commit: src/usr.bin/netstat

2024-02-24 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 24 09:53:26 UTC 2024

Modified Files:
src/usr.bin/netstat: mbuf.c

Log Message:
Don't truncate mo_descr output and protect against missing terminating NUL.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/netstat/mbuf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2023-08-18 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Aug 18 13:18:17 UTC 2023

Modified Files:
src/usr.bin/netstat: bpf.c main.c netstat.h

Log Message:
Rename local bpf_* functions to nsbpf_* to avoid conflicts with
new libpcap bpf_* functions


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/netstat/bpf.c
cvs rdiff -u -r1.104 -r1.105 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.53 -r1.54 src/usr.bin/netstat/netstat.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/bpf.c
diff -u src/usr.bin/netstat/bpf.c:1.17 src/usr.bin/netstat/bpf.c:1.18
--- src/usr.bin/netstat/bpf.c:1.17	Sat Nov 19 08:56:20 2022
+++ src/usr.bin/netstat/bpf.c	Fri Aug 18 13:18:17 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.17 2022/11/19 08:56:20 yamt Exp $	*/
+/*	$NetBSD: bpf.c,v 1.18 2023/08/18 13:18:17 martin Exp $	*/
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
 #include "prog_ops.h"
 
 void
-bpf_stats(void)
+nsbpf_stats(void)
 {
 	struct bpf_stat bpf_s;
 	size_t len = sizeof(bpf_s);
@@ -69,7 +69,7 @@ bpf_stats(void)
 }
 
 void
-bpf_dump(const char *bpfif)
+nsbpf_dump(const char *bpfif)
 {
 	struct bpf_d_ext *dpe;
 

Index: src/usr.bin/netstat/main.c
diff -u src/usr.bin/netstat/main.c:1.104 src/usr.bin/netstat/main.c:1.105
--- src/usr.bin/netstat/main.c:1.104	Mon Oct 24 08:11:25 2022
+++ src/usr.bin/netstat/main.c	Fri Aug 18 13:18:17 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.104 2022/10/24 08:11:25 msaitoh Exp $	*/
+/*	$NetBSD: main.c,v 1.105 2023/08/18 13:18:17 martin Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = "from: @(#)main.c	8.4 (Berkeley) 3/1/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.104 2022/10/24 08:11:25 msaitoh Exp $");
+__RCSID("$NetBSD: main.c,v 1.105 2023/08/18 13:18:17 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -560,9 +560,9 @@ main(int argc, char *argv[])
 #ifndef SMALL
 	if (Bflag) {
 		if (sflag)
-			bpf_stats();
+			nsbpf_stats();
 		else
-			bpf_dump(interface);
+			nsbpf_dump(interface);
 		exit(0);
 	}
 #endif

Index: src/usr.bin/netstat/netstat.h
diff -u src/usr.bin/netstat/netstat.h:1.53 src/usr.bin/netstat/netstat.h:1.54
--- src/usr.bin/netstat/netstat.h:1.53	Thu Sep  1 10:10:20 2022
+++ src/usr.bin/netstat/netstat.h	Fri Aug 18 13:18:17 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: netstat.h,v 1.53 2022/09/01 10:10:20 msaitoh Exp $	*/
+/*	$NetBSD: netstat.h,v 1.54 2023/08/18 13:18:17 martin Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -137,8 +137,8 @@ void	routepr(u_long);
 void	mroutepr(u_long, u_long, u_long, u_long);
 void	mrt_stats(u_long, u_long);
 
-void	bpf_stats(void);
-void	bpf_dump(const char *);
+void	nsbpf_stats(void);
+void	nsbpf_dump(const char *);
 
 kvm_t *get_kvmd(void);
 



CVS commit: src/usr.bin/netstat

2023-08-18 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Aug 18 13:18:17 UTC 2023

Modified Files:
src/usr.bin/netstat: bpf.c main.c netstat.h

Log Message:
Rename local bpf_* functions to nsbpf_* to avoid conflicts with
new libpcap bpf_* functions


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/netstat/bpf.c
cvs rdiff -u -r1.104 -r1.105 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.53 -r1.54 src/usr.bin/netstat/netstat.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2022-12-28 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Dec 28 18:34:33 UTC 2022

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
if not given an interface to monitor by default, pick the one
with the most bytes in/out the first time and keep using it.

in addition to picking the most likely intersting interface,
this actually fixes a bug where interfaces coming/going in
the middle of eg, "netstat -b -w 1", may end up showing the
data for another interface on any output line (including the
the header declaring the interface!)


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.108 src/usr.bin/netstat/if.c:1.109
--- src/usr.bin/netstat/if.c:1.108	Mon Dec 12 05:09:33 2022
+++ src/usr.bin/netstat/if.c	Wed Dec 28 18:34:33 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.108 2022/12/12 05:09:33 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.109 2022/12/28 18:34:33 mrg Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.108 2022/12/12 05:09:33 msaitoh Exp $");
+__RCSID("$NetBSD: if.c,v 1.109 2022/12/28 18:34:33 mrg Exp $");
 #endif
 #endif /* not lint */
 
@@ -1171,7 +1171,11 @@ fetchifs(void)
 
 			if_data_ext_get(name, );
 
-			if (interface != NULL && !strcmp(name, interface)) {
+			if ((interface != NULL && !strcmp(name, interface)) ||
+			(interface == NULL &&
+			((ip_cur.ift_ib + ip_cur.ift_ob) == 0 ||
+			 (ip_cur.ift_ib + ip_cur.ift_ob <
+			 ifd->ifi_ibytes + ifd->ifi_obytes {
 strlcpy(ip_cur.ift_name, name,
 sizeof(ip_cur.ift_name));
 ip_cur.ift_ip = ifd->ifi_ipackets;
@@ -1197,17 +1201,11 @@ fetchifs(void)
 			break;
 		}
 	}
-	if (interface == NULL) {
-		strlcpy(ip_cur.ift_name, name,
-		sizeof(ip_cur.ift_name));
-		ip_cur.ift_ip = ifd->ifi_ipackets;
-		ip_cur.ift_ib = ifd->ifi_ibytes;
-		ip_cur.ift_ie = ifd->ifi_ierrors;
-		ip_cur.ift_op = ifd->ifi_opackets;
-		ip_cur.ift_ob = ifd->ifi_obytes;
-		ip_cur.ift_oe = ifd->ifi_oerrors;
-		ip_cur.ift_co = ifd->ifi_collisions;
-		ip_cur.ift_iq = ifd->ifi_iqdrops;
-		ip_cur.ift_oq = dext.ifi_oqdrops;
-	}
+
+	/*
+	 * If we picked an interface, be sure to keep using it for the rest
+	 * of this instance.
+	 */
+	if (interface == NULL)
+		interface = ip_cur.ift_name;
 }



CVS commit: src/usr.bin/netstat

2022-12-28 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed Dec 28 18:34:33 UTC 2022

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
if not given an interface to monitor by default, pick the one
with the most bytes in/out the first time and keep using it.

in addition to picking the most likely intersting interface,
this actually fixes a bug where interfaces coming/going in
the middle of eg, "netstat -b -w 1", may end up showing the
data for another interface on any output line (including the
the header declaring the interface!)


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2022-12-21 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Dec 21 09:06:59 UTC 2022

Modified Files:
src/usr.bin/netstat: netstat.1

Log Message:
Add note about "netstat -mssv".


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/usr.bin/netstat/netstat.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/netstat.1
diff -u src/usr.bin/netstat/netstat.1:1.75 src/usr.bin/netstat/netstat.1:1.76
--- src/usr.bin/netstat/netstat.1:1.75	Fri Jan  7 10:17:39 2022
+++ src/usr.bin/netstat/netstat.1	Wed Dec 21 09:06:59 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: netstat.1,v 1.75 2022/01/07 10:17:39 bad Exp $
+.\"	$NetBSD: netstat.1,v 1.76 2022/12/21 09:06:59 msaitoh Exp $
 .\"
 .\" Copyright (c) 1983, 1990, 1992, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	@(#)netstat.1	8.8 (Berkeley) 4/18/94
 .\"
-.Dd July 21, 2020
+.Dd December 21, 2022
 .Dt NETSTAT 1
 .Os
 .Sh NAME
@@ -239,6 +239,12 @@ is used.
 .It Fl m
 Show statistics recorded by the mbuf memory management routines
 (the network manages a private pool of memory buffers).
+If the kernel option
+.Cd options MBUFTRACE
+is set, extra info can be retrieved with
+.Fl mssv .
+See also
+.Xr options 4 .
 .It Fl N Ar system
 Use
 .Xr kvm 3
@@ -436,6 +442,7 @@ And the fifth character shows the header
 .Xr kvm_openfiles 3 ,
 .Xr sysctl 3 ,
 .Xr bpf 4 ,
+.Xr options 4 ,
 .Xr route 4 ,
 .Xr hosts 5 ,
 .Xr networks 5 ,



CVS commit: src/usr.bin/netstat

2022-12-21 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Dec 21 09:06:59 UTC 2022

Modified Files:
src/usr.bin/netstat: netstat.1

Log Message:
Add note about "netstat -mssv".


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/usr.bin/netstat/netstat.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2022-12-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Dec 12 05:09:33 UTC 2022

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Use warn() instead of warnx() and simplify.


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2022-12-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Dec 12 05:09:33 UTC 2022

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Use warn() instead of warnx() and simplify.


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.107 src/usr.bin/netstat/if.c:1.108
--- src/usr.bin/netstat/if.c:1.107	Sat Nov 19 14:42:35 2022
+++ src/usr.bin/netstat/if.c	Mon Dec 12 05:09:33 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.107 2022/11/19 14:42:35 taca Exp $	*/
+/*	$NetBSD: if.c,v 1.108 2022/12/12 05:09:33 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.107 2022/11/19 14:42:35 taca Exp $");
+__RCSID("$NetBSD: if.c,v 1.108 2022/12/12 05:09:33 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -182,9 +182,8 @@ if_data_ext_get(const char *ifname, stru
 	snprintf(namebuf, sizeof(namebuf),
 	"net.interfaces.%s.sndq.drops", ifname);
 	len = sizeof(drops);
-	if (sysctlbyname(namebuf, , , NULL, 0)
-	== -1) {
-		warnx("'%s' not found", namebuf);
+	if (sysctlbyname(namebuf, , , NULL, 0) == -1) {
+		warn("%s", namebuf);
 		dext->ifi_oqdrops = 0;
 		return -1;
 	} else



CVS commit: src/usr.bin/netstat

2022-11-19 Thread Takahiro Kambe
Module Name:src
Committed By:   taca
Date:   Sat Nov 19 14:42:36 UTC 2022

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
netstat/if.c: Fix error message with "-w" option.

Now ifq_drops is 64bit unsigned integer.

No description in src/doc/CHANGES?


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.106 src/usr.bin/netstat/if.c:1.107
--- src/usr.bin/netstat/if.c:1.106	Mon Oct 24 08:11:25 2022
+++ src/usr.bin/netstat/if.c	Sat Nov 19 14:42:35 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.106 2022/10/24 08:11:25 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.107 2022/11/19 14:42:35 taca Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.106 2022/10/24 08:11:25 msaitoh Exp $");
+__RCSID("$NetBSD: if.c,v 1.107 2022/11/19 14:42:35 taca Exp $");
 #endif
 #endif /* not lint */
 
@@ -176,7 +176,7 @@ if_data_ext_get(const char *ifname, stru
 {
 	char namebuf[1024];
 	size_t len;
-	int drops;
+	uint64_t drops;
 
 	/* For sysctl */
 	snprintf(namebuf, sizeof(namebuf),



CVS commit: src/usr.bin/netstat

2022-11-19 Thread Takahiro Kambe
Module Name:src
Committed By:   taca
Date:   Sat Nov 19 14:42:36 UTC 2022

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
netstat/if.c: Fix error message with "-w" option.

Now ifq_drops is 64bit unsigned integer.

No description in src/doc/CHANGES?


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2022-11-19 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Sat Nov 19 08:56:20 UTC 2022

Modified Files:
src/usr.bin/netstat: bpf.c

Log Message:
netstat/bpf.c: Don't print garbage for stale pid


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/netstat/bpf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2022-11-19 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Sat Nov 19 08:56:20 UTC 2022

Modified Files:
src/usr.bin/netstat: bpf.c

Log Message:
netstat/bpf.c: Don't print garbage for stale pid


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/netstat/bpf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/bpf.c
diff -u src/usr.bin/netstat/bpf.c:1.16 src/usr.bin/netstat/bpf.c:1.17
--- src/usr.bin/netstat/bpf.c:1.16	Thu Sep  1 10:10:20 2022
+++ src/usr.bin/netstat/bpf.c	Sat Nov 19 08:56:20 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.16 2022/09/01 10:10:20 msaitoh Exp $	*/
+/*	$NetBSD: bpf.c,v 1.17 2022/11/19 08:56:20 yamt Exp $	*/
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -162,8 +162,13 @@ bpf_dump(const char *bpfif)
 			name[namelen++] = szproc;
 			name[namelen++] = 1;
 
+			/*
+			 * Note: The sysctl succeeds (returns 0) even if it failed
+			 * to find the process. The szproc check below is to detect
+			 * that case.
+			 */
 			if (prog_sysctl([0], namelen, , ,
-			NULL, 0) == -1)
+			NULL, 0) == -1 || szproc != sizeof(p))
 printf("-\n");
 			else
 printf("%s\n", p.p_comm);



CVS commit: src/usr.bin/netstat

2022-09-21 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Sep 21 07:59:19 UTC 2022

Modified Files:
src/usr.bin/netstat: if.c inet.c inet6.c

Log Message:
s/u_quad_t/uint64_t/. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.116 -r1.117 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.81 -r1.82 src/usr.bin/netstat/inet6.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.104 src/usr.bin/netstat/if.c:1.105
--- src/usr.bin/netstat/if.c:1.104	Mon Sep 12 02:25:44 2022
+++ src/usr.bin/netstat/if.c	Wed Sep 21 07:59:19 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.104 2022/09/12 02:25:44 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.105 2022/09/21 07:59:19 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.104 2022/09/12 02:25:44 msaitoh Exp $");
+__RCSID("$NetBSD: if.c,v 1.105 2022/09/21 07:59:19 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -73,15 +73,15 @@ __RCSID("$NetBSD: if.c,v 1.104 2022/09/1
 
 struct	iftot {
 	char ift_name[IFNAMSIZ];	/* interface name */
-	u_quad_t ift_ip;		/* input packets */
-	u_quad_t ift_ib;		/* input bytes */
-	u_quad_t ift_ie;		/* input errors */
-	u_quad_t ift_iq;		/* input drops */
-	u_quad_t ift_op;		/* output packets */
-	u_quad_t ift_ob;		/* output bytes */
-	u_quad_t ift_oe;		/* output errors */
-	u_quad_t ift_oq;		/* output drops */
-	u_quad_t ift_co;		/* collisions */
+	uint64_t ift_ip;		/* input packets */
+	uint64_t ift_ib;		/* input bytes */
+	uint64_t ift_ie;		/* input errors */
+	uint64_t ift_iq;		/* input drops */
+	uint64_t ift_op;		/* output packets */
+	uint64_t ift_ob;		/* output bytes */
+	uint64_t ift_oe;		/* output errors */
+	uint64_t ift_oq;		/* output drops */
+	uint64_t ift_co;		/* collisions */
 };
 
 struct if_data_ext {

Index: src/usr.bin/netstat/inet.c
diff -u src/usr.bin/netstat/inet.c:1.116 src/usr.bin/netstat/inet.c:1.117
--- src/usr.bin/netstat/inet.c:1.116	Fri Sep  2 06:25:43 2022
+++ src/usr.bin/netstat/inet.c	Wed Sep 21 07:59:19 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.116 2022/09/02 06:25:43 msaitoh Exp $	*/
+/*	$NetBSD: inet.c,v 1.117 2022/09/21 07:59:19 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet.c,v 1.116 2022/09/02 06:25:43 msaitoh Exp $");
+__RCSID("$NetBSD: inet.c,v 1.117 2022/09/21 07:59:19 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -539,7 +539,7 @@ void
 udp_stats(u_long off, const char *name)
 {
 	uint64_t udpstat[UDP_NSTATS];
-	u_quad_t delivered;
+	uint64_t delivered;
 
 	if (use_sysctl) {
 		size_t size = sizeof(udpstat);

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.81 src/usr.bin/netstat/inet6.c:1.82
--- src/usr.bin/netstat/inet6.c:1.81	Fri Sep  2 06:25:43 2022
+++ src/usr.bin/netstat/inet6.c	Wed Sep 21 07:59:19 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.81 2022/09/02 06:25:43 msaitoh Exp $	*/
+/*	$NetBSD: inet6.c,v 1.82 2022/09/21 07:59:19 msaitoh Exp $	*/
 /*	BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp	*/
 
 /*
@@ -64,7 +64,7 @@
 #if 0
 static char sccsid[] = "@(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet6.c,v 1.81 2022/09/02 06:25:43 msaitoh Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.82 2022/09/21 07:59:19 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -501,7 +501,7 @@ void
 udp6_stats(u_long off, const char *name)
 {
 	uint64_t udp6stat[UDP6_NSTATS];
-	u_quad_t delivered;
+	uint64_t delivered;
 
 	if (use_sysctl) {
 		size_t size = sizeof(udp6stat);
@@ -1349,7 +1349,7 @@ void
 rip6_stats(u_long off, const char *name)
 {
 	uint64_t rip6stat[RIP6_NSTATS];
-	u_quad_t delivered;
+	uint64_t delivered;
 
 	if (use_sysctl) {
 		size_t size = sizeof(rip6stat);



CVS commit: src/usr.bin/netstat

2022-09-21 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Sep 21 07:59:19 UTC 2022

Modified Files:
src/usr.bin/netstat: if.c inet.c inet6.c

Log Message:
s/u_quad_t/uint64_t/. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.116 -r1.117 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.81 -r1.82 src/usr.bin/netstat/inet6.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2022-09-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Sep 12 02:25:44 UTC 2022

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Print oqdrops correctly in continuous display mode using with kvm.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.103 src/usr.bin/netstat/if.c:1.104
--- src/usr.bin/netstat/if.c:1.103	Sun Sep 11 23:52:20 2022
+++ src/usr.bin/netstat/if.c	Mon Sep 12 02:25:44 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.103 2022/09/11 23:52:20 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.104 2022/09/12 02:25:44 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.103 2022/09/11 23:52:20 msaitoh Exp $");
+__RCSID("$NetBSD: if.c,v 1.104 2022/09/12 02:25:44 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -924,11 +924,12 @@ banner:
 		ip->ift_ip = 0;
 		ip->ift_ib = 0;
 		ip->ift_ie = 0;
+		ip->ift_iq = 0;
 		ip->ift_op = 0;
 		ip->ift_ob = 0;
 		ip->ift_oe = 0;
+		ip->ift_oq = 0;
 		ip->ift_co = 0;
-		ip->ift_iq = 0;
 	}
 	putchar('\n');
 	if (bflag)
@@ -956,11 +957,12 @@ loop:
 	sum->ift_ip = 0;
 	sum->ift_ib = 0;
 	sum->ift_ie = 0;
+	sum->ift_iq = 0;
 	sum->ift_op = 0;
 	sum->ift_ob = 0;
 	sum->ift_oe = 0;
+	sum->ift_oq = 0;
 	sum->ift_co = 0;
-	sum->ift_iq = 0;
 	for (off = firstifnet, ip = iftot; off && ip < lastif; ip++) {
 		if (kread(off, (char *), sizeof ifnet)) {
 			off = 0;



CVS commit: src/usr.bin/netstat

2022-09-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Sep 12 02:25:44 UTC 2022

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Print oqdrops correctly in continuous display mode using with kvm.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2022-09-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Sun Sep 11 23:52:20 UTC 2022

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Fix printing current output drop packet count in continuous display mode.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.102 src/usr.bin/netstat/if.c:1.103
--- src/usr.bin/netstat/if.c:1.102	Mon Sep  5 04:52:53 2022
+++ src/usr.bin/netstat/if.c	Sun Sep 11 23:52:20 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.102 2022/09/05 04:52:53 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.103 2022/09/11 23:52:20 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.102 2022/09/05 04:52:53 msaitoh Exp $");
+__RCSID("$NetBSD: if.c,v 1.103 2022/09/11 23:52:20 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -1182,7 +1182,7 @@ fetchifs(void)
 ip_cur.ift_oe = ifd->ifi_oerrors;
 ip_cur.ift_co = ifd->ifi_collisions;
 ip_cur.ift_iq = ifd->ifi_iqdrops;
-ip_cur.ift_oq = ifd->ifi_iqdrops; /* XXX */
+ip_cur.ift_oq = dext.ifi_oqdrops;
 			}
 
 			sum_cur.ift_ip += ifd->ifi_ipackets;



CVS commit: src/usr.bin/netstat

2022-09-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Sun Sep 11 23:52:20 UTC 2022

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Fix printing current output drop packet count in continuous display mode.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2022-09-04 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Sep  5 04:52:53 UTC 2022

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
G.C. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.101 src/usr.bin/netstat/if.c:1.102
--- src/usr.bin/netstat/if.c:1.101	Mon Sep  5 02:26:22 2022
+++ src/usr.bin/netstat/if.c	Mon Sep  5 04:52:53 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.101 2022/09/05 02:26:22 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.102 2022/09/05 04:52:53 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.101 2022/09/05 02:26:22 msaitoh Exp $");
+__RCSID("$NetBSD: if.c,v 1.102 2022/09/05 04:52:53 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -309,25 +309,8 @@ intpr_sysctl(void)
 			n = 5;
 
 		printf("%-*.*s %-5" PRIu64 " ", n, n, name, ifd->ifi_mtu);
-		if (dflag) {
-#if 0
-			char namebuf[1024];
-			int drops;
-
-			/* For sysctl */
-			snprintf(namebuf, sizeof(namebuf),
-			"net.interfaces.%s.sndq.drops", origname);
-			len = sizeof(drops);
-			if (sysctlbyname(namebuf, , , NULL, 0)
-			== -1) {
-warnx("'%s' not found", namebuf);
-dext.ifi_oqdrops = 0;
-			} else
-dext.ifi_oqdrops = drops;
-#else
+		if (dflag)
 			if_data_ext_get(origname, );
-#endif
-		}
 
 		print_addr(ifindex, rti_info[rtax], rti_info, ifd,
 		NULL, dflag ?  : NULL);



CVS commit: src/usr.bin/netstat

2022-09-04 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Sep  5 04:52:53 UTC 2022

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
G.C. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2022-09-04 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Sep  5 02:26:22 UTC 2022

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Print oqdrops correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.100 src/usr.bin/netstat/if.c:1.101
--- src/usr.bin/netstat/if.c:1.100	Mon Sep  5 00:18:25 2022
+++ src/usr.bin/netstat/if.c	Mon Sep  5 02:26:22 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.100 2022/09/05 00:18:25 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.101 2022/09/05 02:26:22 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.100 2022/09/05 00:18:25 msaitoh Exp $");
+__RCSID("$NetBSD: if.c,v 1.101 2022/09/05 02:26:22 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -76,16 +76,21 @@ struct	iftot {
 	u_quad_t ift_ip;		/* input packets */
 	u_quad_t ift_ib;		/* input bytes */
 	u_quad_t ift_ie;		/* input errors */
+	u_quad_t ift_iq;		/* input drops */
 	u_quad_t ift_op;		/* output packets */
 	u_quad_t ift_ob;		/* output bytes */
 	u_quad_t ift_oe;		/* output errors */
+	u_quad_t ift_oq;		/* output drops */
 	u_quad_t ift_co;		/* collisions */
-	u_quad_t ift_dr;		/* drops */
+};
+
+struct if_data_ext {
+	uint64_t ifi_oqdrops;
 };
 
 static void set_lines(void);
 static void print_addr(const int, struct sockaddr *, struct sockaddr **,
-struct if_data *, struct ifnet *);
+struct if_data *, struct ifnet *, struct if_data_ext *);
 static void sidewaysintpr(u_int, u_long);
 
 static void iftot_banner(struct iftot *);
@@ -96,6 +101,7 @@ static void catchalarm(int);
 static void get_rtaddrs(int, struct sockaddr *, struct sockaddr **);
 static void fetchifs(void);
 
+static int if_data_ext_get(const char *, struct if_data_ext *);
 static void intpr_sysctl(void);
 static void intpr_kvm(u_long, void (*)(const char *));
 
@@ -165,6 +171,28 @@ intpr_header(void)
 	}
 }
 
+int
+if_data_ext_get(const char *ifname, struct if_data_ext *dext)
+{
+	char namebuf[1024];
+	size_t len;
+	int drops;
+
+	/* For sysctl */
+	snprintf(namebuf, sizeof(namebuf),
+	"net.interfaces.%s.sndq.drops", ifname);
+	len = sizeof(drops);
+	if (sysctlbyname(namebuf, , , NULL, 0)
+	== -1) {
+		warnx("'%s' not found", namebuf);
+		dext->ifi_oqdrops = 0;
+		return -1;
+	} else
+		dext->ifi_oqdrops = drops;
+
+	return 0;
+}
+
 static void
 intpr_sysctl(void)
 {
@@ -182,6 +210,7 @@ intpr_sysctl(void)
 	size_t len;
 	int did = 1, rtax = 0, n;
 	char name[IFNAMSIZ + 1];	/* + 1 for `*' */
+	char origname[IFNAMSIZ];	/* without `*' */
 	int ifindex = 0;
 
 	if (prog_sysctl(mib, 6, NULL, , NULL, 0) == -1)
@@ -199,6 +228,8 @@ intpr_sysctl(void)
 
 	lim = buf + len;
 	for (next = buf; next < lim; next += rtm->rtm_msglen) {
+		struct if_data_ext dext;
+
 		rtm = (struct rt_msghdr *)next;
 		if (rtm->rtm_version != RTM_VERSION)
 			continue;
@@ -226,11 +257,15 @@ intpr_sysctl(void)
 
 			ifindex = sdl->sdl_index;
 
-			/* mark inactive interfaces with a '*' */
+			/* Keep the original name */
+			strcpy(origname, name);
+
+			/* Mark inactive interfaces with a '*' */
 			cp = strchr(name, '\0');
-			if ((ifm->ifm_flags & IFF_UP) == 0)
+			if ((ifm->ifm_flags & IFF_UP) == 0) {
 *cp++ = '*';
-			*cp = '\0';
+*cp = '\0';
+			}
 
 			if (qflag) {
 total = ifd->ifi_ibytes + ifd->ifi_obytes +
@@ -274,7 +309,28 @@ intpr_sysctl(void)
 			n = 5;
 
 		printf("%-*.*s %-5" PRIu64 " ", n, n, name, ifd->ifi_mtu);
-		print_addr(ifindex, rti_info[rtax], rti_info, ifd, NULL);
+		if (dflag) {
+#if 0
+			char namebuf[1024];
+			int drops;
+
+			/* For sysctl */
+			snprintf(namebuf, sizeof(namebuf),
+			"net.interfaces.%s.sndq.drops", origname);
+			len = sizeof(drops);
+			if (sysctlbyname(namebuf, , , NULL, 0)
+			== -1) {
+warnx("'%s' not found", namebuf);
+dext.ifi_oqdrops = 0;
+			} else
+dext.ifi_oqdrops = drops;
+#else
+			if_data_ext_get(origname, );
+#endif
+		}
+
+		print_addr(ifindex, rti_info[rtax], rti_info, ifd,
+		NULL, dflag ?  : NULL);
 	}
 }
 
@@ -376,7 +432,7 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 			sa = (struct sockaddr *)cp;
 			ifname_to_ifdata(s, name, );
 			print_addr(ifnet.if_index, sa, (void *),
-			, );
+			, , NULL);
 		}
 		ifaddraddr = (u_long)ifaddr.ifa.ifa_list.tqe_next;
 	}
@@ -473,8 +529,8 @@ mc4_print(const int ifindex)
 }
 
 static void
-print_addr(const int ifindex, struct sockaddr *sa,
-struct sockaddr **rtinfo, struct if_data *ifd, struct ifnet *ifnet)
+print_addr(const int ifindex, struct sockaddr *sa, struct sockaddr **rtinfo,
+struct if_data *ifd, struct ifnet *ifnet, struct if_data_ext *dext)
 {
 	char hexsep = '.';		/* for hexprint */
 	static const char hexfmt[] = "%02x%c";	

CVS commit: src/usr.bin/netstat

2022-09-04 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Sep  5 02:26:22 UTC 2022

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Print oqdrops correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2022-09-04 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Sep  5 00:18:25 UTC 2022

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Get if_data correctly when kvm is used.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.99 src/usr.bin/netstat/if.c:1.100
--- src/usr.bin/netstat/if.c:1.99	Fri Sep  2 06:25:43 2022
+++ src/usr.bin/netstat/if.c	Mon Sep  5 00:18:25 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.99 2022/09/02 06:25:43 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.100 2022/09/05 00:18:25 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.99 2022/09/02 06:25:43 msaitoh Exp $");
+__RCSID("$NetBSD: if.c,v 1.100 2022/09/05 00:18:25 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -287,27 +287,15 @@ union ifaddr_u {
 };
 
 static void
-ifnet_to_ifdata_kvm(const struct ifnet * const ifp, struct if_data * const ifd)
+ifname_to_ifdata(int s, const char *ifname, struct if_data * const ifd)
 {
+	struct ifdatareq ifdr;
 
-	/*
-	 * Interface statistics are no longer kept in struct ifnet,
-	 * and thus an if_data is no longer embedded in struct ifnet.
-	 * We cannot read stats via kvm without chasing per-cpu data,
-	 * and maybe someday we could do that.  But for now, this is
-	 * what we have.
-	 *
-	 * Just copy the fields that do exist.
-	 */
 	memset(ifd, 0, sizeof(*ifd));
-	ifd->ifi_type = ifp->if_type;
-	ifd->ifi_addrlen = ifp->if_addrlen;
-	ifd->ifi_hdrlen = ifp->if_hdrlen;
-	ifd->ifi_link_state = ifp->if_link_state;
-	ifd->ifi_mtu = ifp->if_mtu;
-	ifd->ifi_metric = ifp->if_metric;
-	ifd->ifi_baudrate = ifp->if_baudrate;
-	ifd->ifi_lastchange = ifp->if_lastchange;
+	strlcpy(ifdr.ifdr_name, ifname, sizeof(ifdr.ifdr_name));
+	if (ioctl(s, SIOCGIFDATA, ) != 0)
+		return;
+	memcpy(ifd, _data, sizeof(ifdr.ifdr_data));
 }
 
 static void
@@ -319,6 +307,7 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 	u_long ifaddraddr;
 	struct ifnet_head ifhead;	/* TAILQ_HEAD */
 	char name[IFNAMSIZ + 1];	/* + 1 for `*' */
+	int s;
 
 	if (ifnetaddr == 0) {
 		printf("ifnet: symbol not defined\n");
@@ -334,6 +323,9 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 		return;
 	ifnetaddr = (u_long)ifhead.tqh_first;
 
+	if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
+		return;
+
 	intpr_header();
 
 	ifaddraddr = 0;
@@ -382,13 +374,13 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 			cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
 			CP();
 			sa = (struct sockaddr *)cp;
-			ifnet_to_ifdata_kvm(, );
+			ifname_to_ifdata(s, name, );
 			print_addr(ifnet.if_index, sa, (void *),
 			, );
 		}
 		ifaddraddr = (u_long)ifaddr.ifa.ifa_list.tqe_next;
 	}
-
+	close(s);
 }
 
 static void
@@ -816,6 +808,7 @@ sidewaysintpr_kvm(unsigned interval, u_l
 	unsigned line;
 	struct iftot *lastif, *sum, *interesting;
 	struct ifnet_head ifhead;	/* TAILQ_HEAD */
+	int s;
 
 	set_lines();
 
@@ -828,6 +821,9 @@ sidewaysintpr_kvm(unsigned interval, u_l
 		return;
 	firstifnet = (u_long)ifhead.tqh_first;
 
+	if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
+		return;
+
 	lastif = iftot;
 	sum = iftot + MAXIF - 1;
 	total = sum - 1;
@@ -930,7 +926,7 @@ loop:
 			off = 0;
 			continue;
 		}
-		ifnet_to_ifdata_kvm(, );
+		ifname_to_ifdata(s, ip->ift_name, );
 		if (ip == interesting) {
 			if (bflag) {
 char humbuf[HUMBUF_SIZE];



CVS commit: src/usr.bin/netstat

2022-09-04 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Sep  5 00:18:25 UTC 2022

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Get if_data correctly when kvm is used.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2022-09-02 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Sep  2 06:25:43 UTC 2022

Modified Files:
src/usr.bin/netstat: atalk.c if.c inet.c inet6.c main.c pfkey.c
pfsync.c route.c unix.c

Log Message:
KNF. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/netstat/atalk.c
cvs rdiff -u -r1.98 -r1.99 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.115 -r1.116 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.80 -r1.81 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.102 -r1.103 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/netstat/pfkey.c \
src/usr.bin/netstat/pfsync.c
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/netstat/route.c
cvs rdiff -u -r1.36 -r1.37 src/usr.bin/netstat/unix.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/atalk.c
diff -u src/usr.bin/netstat/atalk.c:1.20 src/usr.bin/netstat/atalk.c:1.21
--- src/usr.bin/netstat/atalk.c:1.20	Thu Sep  1 10:10:20 2022
+++ src/usr.bin/netstat/atalk.c	Fri Sep  2 06:25:43 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: atalk.c,v 1.20 2022/09/01 10:10:20 msaitoh Exp $	*/
+/*	$NetBSD: atalk.c,v 1.21 2022/09/02 06:25:43 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from @(#)atalk.c	1.1 (Whistle) 6/6/96";
 #else
-__RCSID("$NetBSD: atalk.c,v 1.20 2022/09/01 10:10:20 msaitoh Exp $");
+__RCSID("$NetBSD: atalk.c,v 1.21 2022/09/02 06:25:43 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -244,9 +244,8 @@ atalkprotopr(u_long off, const char *nam
 			return;
 		next = ddpcb.ddp_next;
 #if 0
-		if (!aflag && atalk_nullhost(ddpcb.ddp_lsat)) {
+		if (!aflag && atalk_nullhost(ddpcb.ddp_lsat))
 			continue;
-		}
 #endif
 		if (kread((u_long)ddpcb.ddp_socket,
 			  (char *), sizeof(sockb)) < 0)

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.98 src/usr.bin/netstat/if.c:1.99
--- src/usr.bin/netstat/if.c:1.98	Thu Sep  1 10:10:20 2022
+++ src/usr.bin/netstat/if.c	Fri Sep  2 06:25:43 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.98 2022/09/01 10:10:20 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.99 2022/09/02 06:25:43 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.98 2022/09/01 10:10:20 msaitoh Exp $");
+__RCSID("$NetBSD: if.c,v 1.99 2022/09/02 06:25:43 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -132,12 +132,10 @@ intpr(int interval, u_long ifnetaddr, vo
 		return;
 	}
 
-	if (use_sysctl) {
+	if (use_sysctl)
 		intpr_sysctl();
-	} else {
+	else
 		intpr_kvm(ifnetaddr, pfunc);
-	}
-
 }
 
 static void
@@ -214,9 +212,9 @@ intpr_sysctl(void)
 			get_rtaddrs(ifm->ifm_addrs, sa, rti_info);
 
 			sdl = (struct sockaddr_dl *)rti_info[RTAX_IFP];
-			if (sdl == NULL || sdl->sdl_family != AF_LINK) {
+			if (sdl == NULL || sdl->sdl_family != AF_LINK)
 continue;
-			}
+
 			bzero(name, sizeof(name));
 			if (sdl->sdl_nlen >= IFNAMSIZ)
 memcpy(name, sdl->sdl_data, IFNAMSIZ - 1);
@@ -538,9 +536,8 @@ print_addr(const int ifindex, struct soc
 ia4_print(_addr);
 multiaddr = (u_long)inm.inm_list.le_next;
 			}
-		} else {
+		} else
 			mc4_print(ifindex);
-		}
 		break;
 #ifdef INET6
 	case AF_INET6:
@@ -551,9 +548,9 @@ print_addr(const int ifindex, struct soc
 			sin6->sin6_scope_id = 0;
 #endif
 
-		if (use_sysctl) {
+		if (use_sysctl)
 			netmask6 = (struct sockaddr_in6 *)rtinfo[RTAX_NETMASK];
-		} else {
+		else {
 			struct in6_ifaddr *ifaddr_in6 = (void *)rtinfo;
 			netmask6 = _in6->ia_prefixmask;
 		}
@@ -590,9 +587,8 @@ print_addr(const int ifindex, struct soc
 ia6_print(_addr);
 multiaddr = (u_long)inm.in6m_entry.le_next;
 			}
-		} else {
+		} else
 			mc6_print(ifindex);
-		}
 		break;
 #endif /*INET6*/
 #ifndef SMALL

Index: src/usr.bin/netstat/inet.c
diff -u src/usr.bin/netstat/inet.c:1.115 src/usr.bin/netstat/inet.c:1.116
--- src/usr.bin/netstat/inet.c:1.115	Thu Sep  1 10:10:20 2022
+++ src/usr.bin/netstat/inet.c	Fri Sep  2 06:25:43 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.115 2022/09/01 10:10:20 msaitoh Exp $	*/
+/*	$NetBSD: inet.c,v 1.116 2022/09/02 06:25:43 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet.c,v 1.115 2022/09/01 10:10:20 msaitoh Exp $");
+__RCSID("$NetBSD: inet.c,v 1.116 2022/09/02 06:25:43 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -365,8 +365,7 @@ protopr(u_long off, const char *name)
 		memcpy(, [i].ki_s, sizeof(src));
 		memcpy(, [i].ki_d, sizeof(dst));
 
-		if (!aflag &&
-		inet_lnaof(dst.sin_addr) == INADDR_ANY)
+		if (!aflag && (inet_lnaof(dst.sin_addr) == INADDR_ANY))
 			continue;
 
 		if (first) {
@@ -413,18 +412,18 @@ tcp_stats(u_long off, const char *name)
 
 	printf ("%s:\n", name);
 
-#define	

CVS commit: src/usr.bin/netstat

2022-09-02 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Sep  2 06:25:43 UTC 2022

Modified Files:
src/usr.bin/netstat: atalk.c if.c inet.c inet6.c main.c pfkey.c
pfsync.c route.c unix.c

Log Message:
KNF. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/netstat/atalk.c
cvs rdiff -u -r1.98 -r1.99 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.115 -r1.116 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.80 -r1.81 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.102 -r1.103 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/netstat/pfkey.c \
src/usr.bin/netstat/pfsync.c
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/netstat/route.c
cvs rdiff -u -r1.36 -r1.37 src/usr.bin/netstat/unix.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2022-09-01 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Sep  1 10:10:20 UTC 2022

Modified Files:
src/usr.bin/netstat: atalk.c bpf.c fast_ipsec.c if.c inet.c inet6.c
main.c mbuf.c mroute.c mroute6.c netstat.h pfkey.c pfsync.c route.c
unix.c vtw.c

Log Message:
KNF. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/netstat/atalk.c
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/netstat/bpf.c \
src/usr.bin/netstat/mroute6.c
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/netstat/fast_ipsec.c
cvs rdiff -u -r1.97 -r1.98 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.114 -r1.115 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.101 -r1.102 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/netstat/mbuf.c
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/netstat/mroute.c
cvs rdiff -u -r1.52 -r1.53 src/usr.bin/netstat/netstat.h
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/netstat/pfkey.c \
src/usr.bin/netstat/pfsync.c
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/netstat/route.c
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/netstat/unix.c
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/netstat/vtw.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2022-09-01 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Sep  1 10:10:20 UTC 2022

Modified Files:
src/usr.bin/netstat: atalk.c bpf.c fast_ipsec.c if.c inet.c inet6.c
main.c mbuf.c mroute.c mroute6.c netstat.h pfkey.c pfsync.c route.c
unix.c vtw.c

Log Message:
KNF. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/netstat/atalk.c
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/netstat/bpf.c \
src/usr.bin/netstat/mroute6.c
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/netstat/fast_ipsec.c
cvs rdiff -u -r1.97 -r1.98 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.114 -r1.115 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.101 -r1.102 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/netstat/mbuf.c
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/netstat/mroute.c
cvs rdiff -u -r1.52 -r1.53 src/usr.bin/netstat/netstat.h
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/netstat/pfkey.c \
src/usr.bin/netstat/pfsync.c
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/netstat/route.c
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/netstat/unix.c
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/netstat/vtw.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/atalk.c
diff -u src/usr.bin/netstat/atalk.c:1.19 src/usr.bin/netstat/atalk.c:1.20
--- src/usr.bin/netstat/atalk.c:1.19	Fri Aug 28 07:23:48 2020
+++ src/usr.bin/netstat/atalk.c	Thu Sep  1 10:10:20 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: atalk.c,v 1.19 2020/08/28 07:23:48 ozaki-r Exp $	*/
+/*	$NetBSD: atalk.c,v 1.20 2022/09/01 10:10:20 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from @(#)atalk.c	1.1 (Whistle) 6/6/96";
 #else
-__RCSID("$NetBSD: atalk.c,v 1.19 2020/08/28 07:23:48 ozaki-r Exp $");
+__RCSID("$NetBSD: atalk.c,v 1.20 2022/09/01 10:10:20 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -82,11 +82,12 @@ at_pr_net(const struct sockaddr_at *sat,
 		case 0x:
 			return "";
 		case ATADDR_ANYNET:
-			return ("*");
+			return "*";
 		}
 	}
-	(void)snprintf(mybuf, sizeof(mybuf), "%hu", ntohs(sat->sat_addr.s_net));
-	return (mybuf);
+	(void)snprintf(mybuf, sizeof(mybuf), "%hu",
+	ntohs(sat->sat_addr.s_net));
+	return mybuf;
 }
 
 static const char *
@@ -99,12 +100,12 @@ at_pr_host(const struct sockaddr_at *sat
 		case ATADDR_BCAST:
 			return "bcast";
 		case ATADDR_ANYNODE:
-			return ("*");
+			return "*";
 		}
 	}
-	(void)snprintf(mybuf, sizeof(mybuf), "%d", 
+	(void)snprintf(mybuf, sizeof(mybuf), "%d",
 	(unsigned int)sat->sat_addr.s_node);
-	return (mybuf);
+	return mybuf;
 }
 
 static const char *
@@ -114,13 +115,13 @@ at_pr_port(const struct sockaddr_at *sat
 
 	switch (sat->sat_port) {
 	case ATADDR_ANYPORT:
-		return ("*");
+		return "*";
 	case 0xff:
 		return "";
 	default:
 		(void)snprintf(mybuf, sizeof(mybuf), "%d",
 		(unsigned int)sat->sat_port);
-		return (mybuf);
+		return mybuf;
 	}
 }
 
@@ -138,7 +139,7 @@ at_pr_range(const struct sockaddr_at *sa
 		(void)snprintf(mybuf, sizeof(mybuf), "%d",
 			ntohs(sat->sat_range.r_netrange.nr_firstnet));
 	}
-	return (mybuf);
+	return mybuf;
 }
 
 
@@ -180,7 +181,7 @@ atalk_print(const struct sockaddr *sa, i
 		(void)snprintf(mybuf + strlen(mybuf),
 		sizeof(mybuf) - strlen(mybuf), ".%s", at_pr_port(sat));
 	}
-	return (mybuf);
+	return mybuf;
 }
 
 const char *
@@ -221,7 +222,7 @@ atalk_print2(const struct sockaddr *sa, 
 		if (l > 0)
 			n += l;
 	}
-	return (buf);
+	return buf;
 }
 
 void
@@ -261,7 +262,7 @@ atalkprotopr(u_long off, const char *nam
 			}
 			printf("%-5.5s %-6.6s %-6.6s  %*.*s %*.*s %s\n",
 			   "Proto", "Recv-Q", "Send-Q",
-			   -width, width, "Local Address", 
+			   -width, width, "Local Address",
 			   -width, width, "Foreign Address", "(state)");
 			first = 0;
 		}
@@ -276,8 +277,9 @@ atalkprotopr(u_long off, const char *nam
 		putchar('\n');
 	}
 }
-#define ANY(x,y,z) \
-	((sflag==1 || (x)) ? printf("\t%llu %s%s%s\n",(unsigned long long)x,y,plural(x),z) : 0)
+#define ANY(x,y,z)			  \
+	((sflag==1 || (x)) ?		  \
+	printf("\t%llu %s%s%s\n",(unsigned long long)x,y,plural(x),z) : 0)
 
 /*
  * Dump DDP statistics structure.
@@ -308,7 +310,9 @@ ddp_stats(u_long off, const char *name)
 	ANY(ddpstat[DDP_STAT_TOOSMALL], "packet", " with not enough data ");
 	ANY(ddpstat[DDP_STAT_FORWARD], "packet", " forwarded ");
 	ANY(ddpstat[DDP_STAT_ENCAP], "packet", " encapsulated ");
-	ANY(ddpstat[DDP_STAT_CANTFORWARD], "packet", " rcvd for unreachable dest ");
-	ANY(ddpstat[DDP_STAT_NOSOCKSPACE], "packet", " dropped due to no socket space ");
+	ANY(ddpstat[DDP_STAT_CANTFORWARD], "packet",
+	" rcvd for unreachable dest ");
+	ANY(ddpstat[DDP_STAT_NOSOCKSPACE], "packet",
+	" dropped due to no socket space ");
 }
 #undef ANY

Index: src/usr.bin/netstat/bpf.c
diff -u 

CVS commit: src/usr.bin/netstat

2022-08-18 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Aug 18 12:25:32 UTC 2022

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Use NULL instead of 0.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.96 src/usr.bin/netstat/if.c:1.97
--- src/usr.bin/netstat/if.c:1.96	Sun Feb  2 03:41:12 2020
+++ src/usr.bin/netstat/if.c	Thu Aug 18 12:25:32 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.96 2020/02/02 03:41:12 thorpej Exp $	*/
+/*	$NetBSD: if.c,v 1.97 2022/08/18 12:25:32 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.96 2020/02/02 03:41:12 thorpej Exp $");
+__RCSID("$NetBSD: if.c,v 1.97 2022/08/18 12:25:32 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -223,7 +223,7 @@ intpr_sysctl(void)
 			else if (sdl->sdl_nlen > 0) 
 memcpy(name, sdl->sdl_data, sdl->sdl_nlen);
 
-			if (interface != 0 && strcmp(name, interface) != 0)
+			if (interface != NULL && strcmp(name, interface) != 0)
 continue;
 
 			ifindex = sdl->sdl_index;
@@ -254,7 +254,7 @@ intpr_sysctl(void)
 		case RTM_NEWADDR:
 			if (qflag && total == 0)
 continue;
-			if (interface != 0 && strcmp(name, interface) != 0)
+			if (interface != NULL && strcmp(name, interface) != 0)
 continue;
 			ifam = (struct ifa_msghdr *)next;
 			if ((ifam->ifam_addrs & (RTA_NETMASK | RTA_IFA |
@@ -349,7 +349,7 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 			memmove(name, ifnet.if_xname, IFNAMSIZ);
 			name[IFNAMSIZ - 1] = '\0';	/* sanity */
 			ifnetaddr = (u_long)ifnet.if_list.tqe_next;
-			if (interface != 0 && strcmp(name, interface) != 0)
+			if (interface != NULL && strcmp(name, interface) != 0)
 continue;
 			cp = strchr(name, '\0');
 
@@ -1135,7 +1135,7 @@ fetchifs(void)
 			else if (sdl->sdl_nlen > 0) 
 memcpy(name, sdl->sdl_data, sdl->sdl_nlen);
 
-			if (interface != 0 && !strcmp(name, interface)) {
+			if (interface != NULL && !strcmp(name, interface)) {
 strlcpy(ip_cur.ift_name, name,
 sizeof(ip_cur.ift_name));
 ip_cur.ift_ip = ifd->ifi_ipackets;



CVS commit: src/usr.bin/netstat

2022-08-18 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Aug 18 12:25:32 UTC 2022

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Use NULL instead of 0.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2021-10-30 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Sat Oct 30 11:23:07 UTC 2021

Modified Files:
src/usr.bin/netstat: inet.c inet6.c vtw.c

Log Message:
netstat(1): convert malloc(x * y) and realloc(x * y) to reallocarr


To generate a diff of this commit:
cvs rdiff -u -r1.113 -r1.114 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/netstat/vtw.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/inet.c
diff -u src/usr.bin/netstat/inet.c:1.113 src/usr.bin/netstat/inet.c:1.114
--- src/usr.bin/netstat/inet.c:1.113	Fri Aug 28 07:23:48 2020
+++ src/usr.bin/netstat/inet.c	Sat Oct 30 11:23:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.113 2020/08/28 07:23:48 ozaki-r Exp $	*/
+/*	$NetBSD: inet.c,v 1.114 2021/10/30 11:23:07 nia Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet.c,v 1.113 2020/08/28 07:23:48 ozaki-r Exp $");
+__RCSID("$NetBSD: inet.c,v 1.114 2021/10/30 11:23:07 nia Exp $");
 #endif
 #endif /* not lint */
 
@@ -293,8 +293,9 @@ getpcblist_kmem(u_long off, const char *
 	next = TAILQ_FIRST(head);
 	prev = TAILQ_END(head);
 
-	if ((pcblist = malloc(size * sizeof(*pcblist))) == NULL)
-		err(1, "malloc");
+	pcblist = NULL;
+	if (reallocarr(, size, sizeof(*pcblist)) != 0)
+		err(1, "reallocarr");
 
 	i = 0;
 	while (next != TAILQ_END(head)) {
@@ -325,11 +326,8 @@ getpcblist_kmem(u_long off, const char *
 		pcblist[i].ki_pflags = inpcb.inp_flags;
 		if (i++ == size) {
 			size += 100;
-			struct kinfo_pcb *n = realloc(pcblist,
-			size * sizeof(*pcblist));
-			if (n == NULL)
-err(1, "realloc");
-			pcblist = n;
+			if (reallocarr(, size, sizeof(*pcblist)) != 0)
+err(1, "reallocarr");
 		}
 	}
 	*len = i;

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.78 src/usr.bin/netstat/inet6.c:1.79
--- src/usr.bin/netstat/inet6.c:1.78	Fri Sep 10 21:52:18 2021
+++ src/usr.bin/netstat/inet6.c	Sat Oct 30 11:23:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.78 2021/09/10 21:52:18 rillig Exp $	*/
+/*	$NetBSD: inet6.c,v 1.79 2021/10/30 11:23:07 nia Exp $	*/
 /*	BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp	*/
 
 /*
@@ -64,7 +64,7 @@
 #if 0
 static char sccsid[] = "@(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet6.c,v 1.78 2021/09/10 21:52:18 rillig Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.79 2021/10/30 11:23:07 nia Exp $");
 #endif
 #endif /* not lint */
 
@@ -302,8 +302,9 @@ getpcblist_kmem(u_long off, const char *
 	next = TAILQ_FIRST(head);
 	prev = TAILQ_END(head);
 
-	if ((pcblist = malloc(size * sizeof(*pcblist))) == NULL)
-		err(1, "malloc");
+	pcblist = NULL;
+	if (reallocarr(, size, sizeof(*pcblist)) != 0)
+		err(1, "reallocarr");
 
 	i = 0;
 	while (next != TAILQ_END(head)) {
@@ -338,11 +339,8 @@ getpcblist_kmem(u_long off, const char *
 		pcblist[i].ki_tstate = tcpcb.t_state;
 		if (i++ == size) {
 			size += 100;
-			struct kinfo_pcb *n = realloc(pcblist,
-			size * sizeof(*pcblist));
-			if (n == NULL)
-err(1, "realloc");
-			pcblist = n;
+			if (reallocarr(, size, sizeof(*pcblist)) != 0)
+err(1, "reallocarr");
 		}
 	}
 	*len = i;

Index: src/usr.bin/netstat/vtw.c
diff -u src/usr.bin/netstat/vtw.c:1.11 src/usr.bin/netstat/vtw.c:1.12
--- src/usr.bin/netstat/vtw.c:1.11	Tue Mar  2 01:02:12 2021
+++ src/usr.bin/netstat/vtw.c	Sat Oct 30 11:23:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: vtw.c,v 1.11 2021/03/02 01:02:12 simonb Exp $	*/
+/*	$NetBSD: vtw.c,v 1.12 2021/10/30 11:23:07 nia Exp $	*/
 
 /*
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: vtw.c,v 1.11 2021/03/02 01:02:12 simonb Exp $");
+__RCSID("$NetBSD: vtw.c,v 1.12 2021/10/30 11:23:07 nia Exp $");
 #endif
 #endif /* not lint */
 
@@ -303,8 +303,9 @@ show_vtw_v4(void (*print)(const vtw_t *)
 		n = (klim - kbase + 1);
 
 		if (!i) {
-			if ((ubase = malloc(n * sizeof(*kbase))) == NULL)
-err(EXIT_FAILURE, NULL);
+			ubase = NULL;
+			if (reallocarr(, n, sizeof(*kbase)) != 0)
+err(EXIT_FAILURE, "reallocarr");
 			snarf(kbase, ubase, n * sizeof(*ubase));
 
 			mem += n * sizeof(*ubase);
@@ -333,9 +334,9 @@ show_vtw_v4(void (*print)(const vtw_t *)
 
 	mem += (lim - base + 1) * sizeof(*base);
 
-	fat_tcpv4.base = malloc((lim - base + 1) * sizeof(*base));
-	if (fat_tcpv4.base == NULL)
-		err(EXIT_FAILURE, NULL);
+	fat_tcpv4.base = NULL;
+	if (reallocarr(_tcpv4.base, lim - base + 1, sizeof(*base)) != 0)
+		err(EXIT_FAILURE, "reallocarr");
 	fat_tcpv4.lim = fat_tcpv4.base + (lim - base);
 
 	snarf(base, fat_tcpv4.base, sizeof(*base) * (lim - base + 1));
@@ -347,10 +348,13 @@ show_vtw_v4(void (*print)(const vtw_t *)
 	hash = fat_tcpv4.hash;
 	port = fat_tcpv4.port;
 
-	

CVS commit: src/usr.bin/netstat

2021-10-30 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Sat Oct 30 11:23:07 UTC 2021

Modified Files:
src/usr.bin/netstat: inet.c inet6.c vtw.c

Log Message:
netstat(1): convert malloc(x * y) and realloc(x * y) to reallocarr


To generate a diff of this commit:
cvs rdiff -u -r1.113 -r1.114 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/netstat/vtw.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2021-03-09 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Wed Mar 10 00:32:16 UTC 2021

Modified Files:
src/usr.bin/netstat: main.c

Log Message:
Remove Network ATM soft intr queue reporting, we don't have that in the
kernel anymore.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/usr.bin/netstat/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2021-03-09 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Wed Mar 10 00:32:16 UTC 2021

Modified Files:
src/usr.bin/netstat: main.c

Log Message:
Remove Network ATM soft intr queue reporting, we don't have that in the
kernel anymore.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/usr.bin/netstat/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/main.c
diff -u src/usr.bin/netstat/main.c:1.100 src/usr.bin/netstat/main.c:1.101
--- src/usr.bin/netstat/main.c:1.100	Thu Apr 23 00:24:50 2020
+++ src/usr.bin/netstat/main.c	Wed Mar 10 00:32:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.100 2020/04/23 00:24:50 joerg Exp $	*/
+/*	$NetBSD: main.c,v 1.101 2021/03/10 00:32:15 simonb Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = "from: @(#)main.c	8.4 (Berkeley) 3/1/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.100 2020/04/23 00:24:50 joerg Exp $");
+__RCSID("$NetBSD: main.c,v 1.101 2021/03/10 00:32:15 simonb Exp $");
 #endif
 #endif /* not lint */
 
@@ -182,19 +182,17 @@ struct nlist nl[] = {
 	{ "_atintrq1", 0, 0, 0, 0 },
 #define	N_ATINTRQ2	40
 	{ "_atintrq2", 0, 0, 0, 0 },
-#define	N_NATMINTRQ	41
-	{ "_natmintrq", 0, 0, 0, 0 },
-#define	N_PPPOEDISCINQ	42
+#define	N_PPPOEDISCINQ	41
 	{ "_ppoediscinq", 0, 0, 0, 0 },
-#define	N_PPPOEINQ	43
+#define	N_PPPOEINQ	42
 	{ "_ppoeinq", 0, 0, 0, 0 },
-#define	N_HARDCLOCK_TICKS 44
+#define	N_HARDCLOCK_TICKS 43
 	{ "_hardclock_ticks", 0, 0, 0, 0 },
-#define N_PIMSTAT	45
+#define N_PIMSTAT	44
 	{ "_pimstat", 0, 0, 0, 0 },
-#define N_CARPSTAT	46
+#define N_CARPSTAT	45
 	{ "_carpstats", 0, 0, 0, 0 },	/* not available via kvm */
-#define N_PFSYNCSTAT	47
+#define N_PFSYNCSTAT	46
 	{ "_pfsyncstats", 0, 0, 0, 0},  /* not available via kvm */
 	{ "", 0, 0, 0, 0 },
 };
@@ -310,7 +308,6 @@ const struct softintrq {
 	{ "arpintrq", N_ARPINTRQ },
 	{ "atintrq1", N_ATINTRQ1 },
 	{ "atintrq2", N_ATINTRQ2 },
-	{ "natmintrq", N_NATMINTRQ },
 	{ "ppoediscinq", N_PPPOEDISCINQ },
 	{ "ppoeinq", N_PPPOEINQ },
 	{ NULL, -1 },



CVS commit: src/usr.bin/netstat

2021-03-01 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Tue Mar  2 01:02:12 UTC 2021

Modified Files:
src/usr.bin/netstat: vtw.c

Log Message:
Don't show any of the completely and utterly undocumented VTW info if
the feature isn't enabled (by checking net.inet.tcp.vtw.enable).


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/netstat/vtw.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/vtw.c
diff -u src/usr.bin/netstat/vtw.c:1.10 src/usr.bin/netstat/vtw.c:1.11
--- src/usr.bin/netstat/vtw.c:1.10	Thu May  3 07:13:48 2018
+++ src/usr.bin/netstat/vtw.c	Tue Mar  2 01:02:12 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: vtw.c,v 1.10 2018/05/03 07:13:48 maxv Exp $	*/
+/*	$NetBSD: vtw.c,v 1.11 2021/03/02 01:02:12 simonb Exp $	*/
 
 /*
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: vtw.c,v 1.10 2018/05/03 07:13:48 maxv Exp $");
+__RCSID("$NetBSD: vtw.c,v 1.11 2021/03/02 01:02:12 simonb Exp $");
 #endif
 #endif /* not lint */
 
@@ -115,10 +115,28 @@ __RCSID("$NetBSD: vtw.c,v 1.10 2018/05/0
 #include "vtw.h"
 #include "prog_ops.h"
 
+static bool	vtw_enabled(void);
 static void	snarf(const void *, void *, size_t);
 static void	*lookup(const char *);
 static void	process_vtw(const vtw_ctl_t *, void (*)(const vtw_t *));
 
+static bool
+vtw_enabled(void)
+{
+
+	if (use_sysctl) {
+		int enabled;
+		size_t size = sizeof(enabled);
+
+		if (prog_sysctlbyname("net.inet.tcp.vtw.enable",
+		, , NULL, 0) == -1)
+			return true;
+		return enabled ? true : false;
+	} else {
+		return true;
+	}
+}
+
 static void 
 snarf(const void *addr, void *buf, size_t len)
 {
@@ -172,6 +190,11 @@ timebase(struct timeval *tv)
 	void *p;
 	struct bintime timebasebin;
 
+	if (!vtw_enabled()) {
+		memset(tv, 0, sizeof(*tv));
+		return;
+	}
+
 	p = lookup("timebasebin");
 	if (!p)
 		return;
@@ -209,6 +232,9 @@ show_vtw_stats(void)
 	if (!Vflag)
 		return;
 
+	if (!vtw_enabled())
+		return;
+
 	if ((p = lookup("vtw_stats")) == NULL)
 		return;
 	snarf(p, , sizeof(stats));
@@ -248,6 +274,9 @@ show_vtw_v4(void (*print)(const vtw_t *)
 	int mem = 0;
 	void *p;
 
+	if (!vtw_enabled())
+		return;
+
 	if ((p = lookup("fat_tcpv4")) == NULL)
 		return;
 	snarf(p, _tcpv4, sizeof(fat_tcpv4));
@@ -350,6 +379,9 @@ show_vtw_v6(void (*print)(const vtw_t *)
 	int mem = 0;
 	void *p;
 
+	if (!vtw_enabled())
+		return;
+
 	if ((p = lookup("fat_tcpv6")) == NULL)
 		return;
 	snarf(p, _tcpv6, sizeof(fat_tcpv6));



CVS commit: src/usr.bin/netstat

2021-03-01 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Tue Mar  2 01:02:12 UTC 2021

Modified Files:
src/usr.bin/netstat: vtw.c

Log Message:
Don't show any of the completely and utterly undocumented VTW info if
the feature isn't enabled (by checking net.inet.tcp.vtw.enable).


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/netstat/vtw.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2020-08-28 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Aug 28 07:23:48 UTC 2020

Modified Files:
src/usr.bin/netstat: atalk.c bpf.c inet.c inet6.c pfkey.c pfsync.c

Log Message:
netstat: strengthen against kernel changes

netstat uses sysctlbyname to get counter data from the kernel.
sysctlbyname fails with ENOMEM if actual counter data in the kernel is
larger than a passed buffer.  netstat just skips showing counters of a
category if sysctlbyname fails, so if we added new counters of the
category to the kernel, nestat shows nothing for the category.

Fortunately sysctlbyname fills data as much as possible even if a passed
buffer is short.  So we can allow netstat to show the filled data anyway
if sysctlbyname fails with ENOMEM.

Note that this backcompat mechanism works only if new counters are
appended, and doesn't work if new counters are inserted into the middle
or counters are moved.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/netstat/atalk.c
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/netstat/bpf.c
cvs rdiff -u -r1.112 -r1.113 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.76 -r1.77 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/netstat/pfkey.c \
src/usr.bin/netstat/pfsync.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/atalk.c
diff -u src/usr.bin/netstat/atalk.c:1.18 src/usr.bin/netstat/atalk.c:1.19
--- src/usr.bin/netstat/atalk.c:1.18	Thu Apr 23 00:23:31 2020
+++ src/usr.bin/netstat/atalk.c	Fri Aug 28 07:23:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: atalk.c,v 1.18 2020/04/23 00:23:31 joerg Exp $	*/
+/*	$NetBSD: atalk.c,v 1.19 2020/08/28 07:23:48 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from @(#)atalk.c	1.1 (Whistle) 6/6/96";
 #else
-__RCSID("$NetBSD: atalk.c,v 1.18 2020/04/23 00:23:31 joerg Exp $");
+__RCSID("$NetBSD: atalk.c,v 1.19 2020/08/28 07:23:48 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -291,7 +291,7 @@ ddp_stats(u_long off, const char *name)
 		size_t size = sizeof(ddpstat);
 
 		if (prog_sysctlbyname("net.atalk.ddp.stats", ddpstat, ,
- NULL, 0) == -1)
+ NULL, 0) == -1 && errno != ENOMEM)
 			return;
 	} else {
 		warnx("%s stats not available via KVM.", name);

Index: src/usr.bin/netstat/bpf.c
diff -u src/usr.bin/netstat/bpf.c:1.14 src/usr.bin/netstat/bpf.c:1.15
--- src/usr.bin/netstat/bpf.c:1.14	Sun Aug 18 04:14:40 2019
+++ src/usr.bin/netstat/bpf.c	Fri Aug 28 07:23:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.14 2019/08/18 04:14:40 kamil Exp $	*/
+/*	$NetBSD: bpf.c,v 1.15 2020/08/28 07:23:48 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -53,7 +53,8 @@ bpf_stats(void)
 	size_t len = sizeof(bpf_s);
 
 	if (use_sysctl) {
-		if (prog_sysctlbyname("net.bpf.stats", _s, , NULL, 0) == -1)
+		if (prog_sysctlbyname("net.bpf.stats", _s, , NULL, 0) == -1 &&
+		errno != ENOMEM)
 			err(1, "net.bpf.stats");
 	
 		printf("bpf:\n");

Index: src/usr.bin/netstat/inet.c
diff -u src/usr.bin/netstat/inet.c:1.112 src/usr.bin/netstat/inet.c:1.113
--- src/usr.bin/netstat/inet.c:1.112	Fri Aug 28 06:34:17 2020
+++ src/usr.bin/netstat/inet.c	Fri Aug 28 07:23:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.112 2020/08/28 06:34:17 ozaki-r Exp $	*/
+/*	$NetBSD: inet.c,v 1.113 2020/08/28 07:23:48 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet.c,v 1.112 2020/08/28 06:34:17 ozaki-r Exp $");
+__RCSID("$NetBSD: inet.c,v 1.113 2020/08/28 07:23:48 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -404,7 +404,7 @@ tcp_stats(u_long off, const char *name)
 		size_t size = sizeof(tcpstat);
 
 		if (prog_sysctlbyname("net.inet.tcp.stats", tcpstat, ,
- NULL, 0) == -1)
+ NULL, 0) == -1 && errno != ENOMEM)
 			return;
 	} else {
 		warnx("%s stats not available via KVM.", name);
@@ -531,7 +531,7 @@ udp_stats(u_long off, const char *name)
 		size_t size = sizeof(udpstat);
 
 		if (prog_sysctlbyname("net.inet.udp.stats", udpstat, ,
- NULL, 0) == -1)
+ NULL, 0) == -1 && errno != ENOMEM)
 			return;
 	} else {
 		warnx("%s stats not available via KVM.", name);
@@ -584,7 +584,7 @@ ip_stats(u_long off, const char *name)
 		size_t size = sizeof(ipstat);
 
 		if (prog_sysctlbyname("net.inet.ip.stats", ipstat, ,
- NULL, 0) == -1)
+ NULL, 0) == -1 && errno != ENOMEM)
 			return;
 	} else {
 		warnx("%s stats not available via KVM.", name);
@@ -657,7 +657,7 @@ icmp_stats(u_long off, const char *name)
 		size_t size = sizeof(icmpstat);
 
 		if (prog_sysctlbyname("net.inet.icmp.stats", icmpstat, ,
- NULL, 0) == -1)
+ NULL, 0) == -1 && errno != ENOMEM)
 			return;
 	} else {
 		warnx("%s stats not available via KVM.", name);
@@ -713,7 +713,7 @@ igmp_stats(u_long off, const char *name)
 		

CVS commit: src/usr.bin/netstat

2020-08-28 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Aug 28 07:23:48 UTC 2020

Modified Files:
src/usr.bin/netstat: atalk.c bpf.c inet.c inet6.c pfkey.c pfsync.c

Log Message:
netstat: strengthen against kernel changes

netstat uses sysctlbyname to get counter data from the kernel.
sysctlbyname fails with ENOMEM if actual counter data in the kernel is
larger than a passed buffer.  netstat just skips showing counters of a
category if sysctlbyname fails, so if we added new counters of the
category to the kernel, nestat shows nothing for the category.

Fortunately sysctlbyname fills data as much as possible even if a passed
buffer is short.  So we can allow netstat to show the filled data anyway
if sysctlbyname fails with ENOMEM.

Note that this backcompat mechanism works only if new counters are
appended, and doesn't work if new counters are inserted into the middle
or counters are moved.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/netstat/atalk.c
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/netstat/bpf.c
cvs rdiff -u -r1.112 -r1.113 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.76 -r1.77 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/netstat/pfkey.c \
src/usr.bin/netstat/pfsync.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2020-08-28 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Aug 28 06:34:17 UTC 2020

Modified Files:
src/usr.bin/netstat: inet.c inet6.c

Log Message:
netstat: support new packet counters


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.75 -r1.76 src/usr.bin/netstat/inet6.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/inet.c
diff -u src/usr.bin/netstat/inet.c:1.111 src/usr.bin/netstat/inet.c:1.112
--- src/usr.bin/netstat/inet.c:1.111	Thu Aug  6 07:38:54 2020
+++ src/usr.bin/netstat/inet.c	Fri Aug 28 06:34:17 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.111 2020/08/06 07:38:54 knakahara Exp $	*/
+/*	$NetBSD: inet.c,v 1.112 2020/08/28 06:34:17 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet.c,v 1.111 2020/08/06 07:38:54 knakahara Exp $");
+__RCSID("$NetBSD: inet.c,v 1.112 2020/08/28 06:34:17 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -633,6 +633,13 @@ ip_stats(u_long off, const char *name)
 	p(IP_STAT_BADADDR, "\t%" PRIu64 " datagram%s with bad address in header\n");
 	p(IP_STAT_PFILDROP_IN, "\t%" PRIu64 " input packet%s dropped by pfil\n");
 	p(IP_STAT_PFILDROP_OUT, "\t%" PRIu64 " output packet%s dropped by pfil\n");
+	p(IP_STAT_IPSECDROP_IN, "\t%" PRIu64 " input packet%s dropped by IPsec\n");
+	p(IP_STAT_IPSECDROP_OUT, "\t%" PRIu64 " output packet%s dropped by IPsec\n");
+	p(IP_STAT_IFDROP, "\t%" PRIu64 " input packet%s dropped due to interface state\n");
+	p(IP_STAT_TIMXCEED, "\t%" PRIu64 " packet%s dropped due to TTL exceeded\n");
+	p(IP_STAT_IFNOADDR, "\t%" PRIu64 " output packet%s dropped (no IP address)\n");
+	p(IP_STAT_RTREJECT, "\t%" PRIu64 " output packet%s discarded due to reject route\n");
+	p(IP_STAT_BCASTDENIED, "\t%" PRIu64 " output packet%s dropped (broadcast prohibited)\n");
 #undef ps
 #undef p
 }

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.75 src/usr.bin/netstat/inet6.c:1.76
--- src/usr.bin/netstat/inet6.c:1.75	Thu Aug  6 07:38:54 2020
+++ src/usr.bin/netstat/inet6.c	Fri Aug 28 06:34:17 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.75 2020/08/06 07:38:54 knakahara Exp $	*/
+/*	$NetBSD: inet6.c,v 1.76 2020/08/28 06:34:17 ozaki-r Exp $	*/
 /*	BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp	*/
 
 /*
@@ -64,7 +64,7 @@
 #if 0
 static char sccsid[] = "@(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet6.c,v 1.75 2020/08/06 07:38:54 knakahara Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.76 2020/08/28 06:34:17 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -801,6 +801,13 @@ ip6_stats(u_long off, const char *name)
 	p1(IP6_STAT_FORWARD_CACHEMISS, "\t%llu forward cache miss\n");
 	p(IP6_STAT_PFILDROP_IN, "\t%llu input packet%s dropped by pfil\n");
 	p(IP6_STAT_PFILDROP_OUT, "\t%llu output packet%s dropped by pfil\n");
+	p(IP6_STAT_IPSECDROP_IN, "\t%llu input packet%s dropped by IPsec\n");
+	p(IP6_STAT_IPSECDROP_OUT, "\t%llu output packet%s dropped by IPsec\n");
+	p(IP6_STAT_IFDROP, "\t%llu input packet%s dropped due to interface state\n");
+	p(IP6_STAT_IDROPPED, "\t%llu input packet%s dropped due to no bufs, etc.\n");
+	p(IP6_STAT_TIMXCEED, "\t%llu packet%s dropped due to hop limit exceeded\n");
+	p(IP6_STAT_TOOBIG, "\t%llu packet%s dropped (too big)\n");
+	p(IP6_STAT_RTREJECT, "\t%llu output packet%s discarded due to reject route\n");
 #undef p
 #undef p1
 }



CVS commit: src/usr.bin/netstat

2020-08-28 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Aug 28 06:34:17 UTC 2020

Modified Files:
src/usr.bin/netstat: inet.c inet6.c

Log Message:
netstat: support new packet counters


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.75 -r1.76 src/usr.bin/netstat/inet6.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2020-08-06 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Aug  6 07:38:54 UTC 2020

Modified Files:
src/usr.bin/netstat: inet.c inet6.c

Log Message:
add missing {IP,IP6}_STAT_NOIPSEC to netstat.


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.74 -r1.75 src/usr.bin/netstat/inet6.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/inet.c
diff -u src/usr.bin/netstat/inet.c:1.110 src/usr.bin/netstat/inet.c:1.111
--- src/usr.bin/netstat/inet.c:1.110	Sun Aug 18 04:14:40 2019
+++ src/usr.bin/netstat/inet.c	Thu Aug  6 07:38:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.110 2019/08/18 04:14:40 kamil Exp $	*/
+/*	$NetBSD: inet.c,v 1.111 2020/08/06 07:38:54 knakahara Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet.c,v 1.110 2019/08/18 04:14:40 kamil Exp $");
+__RCSID("$NetBSD: inet.c,v 1.111 2020/08/06 07:38:54 knakahara Exp $");
 #endif
 #endif /* not lint */
 
@@ -622,6 +622,7 @@ ip_stats(u_long off, const char *name)
 	p(IP_STAT_CANTFORWARD, "\t%" PRIu64 " packet%s not forwardable\n");
 	p(IP_STAT_REDIRECTSENT, "\t%" PRIu64 " redirect%s sent\n");
 	p(IP_STAT_NOGIF, "\t%" PRIu64 " packet%s no matching gif found\n");
+	p(IP_STAT_NOIPSEC, "\t%" PRIu64 " packet%s no matching ipsecif found\n");
 	p(IP_STAT_LOCALOUT, "\t%" PRIu64 " packet%s sent from this host\n");
 	p(IP_STAT_RAWOUT, "\t%" PRIu64 " packet%s sent with fabricated ip header\n");
 	p(IP_STAT_ODROPPED, "\t%" PRIu64 " output packet%s dropped due to no bufs, etc.\n");

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.74 src/usr.bin/netstat/inet6.c:1.75
--- src/usr.bin/netstat/inet6.c:1.74	Thu Apr 23 00:24:16 2020
+++ src/usr.bin/netstat/inet6.c	Thu Aug  6 07:38:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.74 2020/04/23 00:24:16 joerg Exp $	*/
+/*	$NetBSD: inet6.c,v 1.75 2020/08/06 07:38:54 knakahara Exp $	*/
 /*	BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp	*/
 
 /*
@@ -64,7 +64,7 @@
 #if 0
 static char sccsid[] = "@(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet6.c,v 1.74 2020/04/23 00:24:16 joerg Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.75 2020/08/06 07:38:54 knakahara Exp $");
 #endif
 #endif /* not lint */
 
@@ -724,6 +724,7 @@ ip6_stats(u_long off, const char *name)
 	p(IP6_STAT_EXTHDRTOOLONG,
 	"\t%llu packet%s whose headers are not continuous\n");
 	p(IP6_STAT_NOGIF, "\t%llu tunneling packet%s that can't find gif\n");
+	p(IP6_STAT_NOIPSEC, "\t%llu tunneling packet%s that can't find ipsecif\n");
 	p(IP6_STAT_TOOMANYHDR,
 	"\t%llu packet%s discarded due to too many headers\n");
 



CVS commit: src/usr.bin/netstat

2020-08-06 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Aug  6 07:38:54 UTC 2020

Modified Files:
src/usr.bin/netstat: inet.c inet6.c

Log Message:
add missing {IP,IP6}_STAT_NOIPSEC to netstat.


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.74 -r1.75 src/usr.bin/netstat/inet6.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2020-07-20 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Tue Jul 21 04:58:44 UTC 2020

Modified Files:
src/usr.bin/netstat: netstat.1

Log Message:
netstat.1: add various xrefs present in the body to "See Also"


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/usr.bin/netstat/netstat.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/netstat.1
diff -u src/usr.bin/netstat/netstat.1:1.73 src/usr.bin/netstat/netstat.1:1.74
--- src/usr.bin/netstat/netstat.1:1.73	Thu May 12 03:44:11 2016
+++ src/usr.bin/netstat/netstat.1	Tue Jul 21 04:58:43 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: netstat.1,v 1.73 2016/05/12 03:44:11 ozaki-r Exp $
+.\"	$NetBSD: netstat.1,v 1.74 2020/07/21 04:58:43 gutteridge Exp $
 .\"
 .\" Copyright (c) 1983, 1990, 1992, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	@(#)netstat.1	8.8 (Berkeley) 4/18/94
 .\"
-.Dd May 12, 2016
+.Dd July 21, 2020
 .Dt NETSTAT 1
 .Os
 .Sh NAME
@@ -432,12 +432,17 @@ And the fifth character shows the header
 .Xr sockstat 1 ,
 .Xr vmstat 1 ,
 .Xr inet 3 ,
+.Xr kvm 3 ,
+.Xr kvm_openfiles 3 ,
+.Xr sysctl 3 ,
 .Xr bpf 4 ,
+.Xr route 4 ,
 .Xr hosts 5 ,
 .Xr networks 5 ,
 .Xr protocols 5 ,
 .Xr services 5 ,
 .Xr iostat 8 ,
+.Xr route 8 ,
 .Xr trpt 8
 .Sh HISTORY
 The



CVS commit: src/usr.bin/netstat

2020-07-20 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Tue Jul 21 04:58:44 UTC 2020

Modified Files:
src/usr.bin/netstat: netstat.1

Log Message:
netstat.1: add various xrefs present in the body to "See Also"


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/usr.bin/netstat/netstat.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2020-05-27 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed May 27 05:59:16 UTC 2020

Modified Files:
src/usr.bin/netstat: route.c

Log Message:
Update sysctl key in netstat(1)


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/usr.bin/netstat/route.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/route.c
diff -u src/usr.bin/netstat/route.c:1.85 src/usr.bin/netstat/route.c:1.86
--- src/usr.bin/netstat/route.c:1.85	Mon Apr  4 07:37:08 2016
+++ src/usr.bin/netstat/route.c	Wed May 27 05:59:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.85 2016/04/04 07:37:08 ozaki-r Exp $	*/
+/*	$NetBSD: route.c,v 1.86 2020/05/27 05:59:16 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)route.c	8.3 (Berkeley) 3/9/94";
 #else
-__RCSID("$NetBSD: route.c,v 1.85 2016/04/04 07:37:08 ozaki-r Exp $");
+__RCSID("$NetBSD: route.c,v 1.86 2020/05/27 05:59:16 yamaguchi Exp $");
 #endif
 #endif /* not lint */
 
@@ -303,7 +303,7 @@ rt_stats(u_long off)
 	if (use_sysctl) {
 		size_t rtsize = sizeof(rtstats);
 
-		if (sysctlbyname("net.route.stats", , ,
+		if (sysctlbyname("net.rtable.stats", , ,
 		NULL, 0) == -1)
 			err(1, "rt_stats: sysctl");
 	} else 	if (off == 0) {



CVS commit: src/usr.bin/netstat

2020-05-27 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed May 27 05:59:16 UTC 2020

Modified Files:
src/usr.bin/netstat: route.c

Log Message:
Update sysctl key in netstat(1)


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/usr.bin/netstat/route.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2020-04-22 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Apr 23 00:24:50 UTC 2020

Modified Files:
src/usr.bin/netstat: main.c netstat.h

Log Message:
Avoid common symbol definitions.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.51 -r1.52 src/usr.bin/netstat/netstat.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2020-04-22 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Apr 23 00:24:50 UTC 2020

Modified Files:
src/usr.bin/netstat: main.c netstat.h

Log Message:
Avoid common symbol definitions.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/usr.bin/netstat/main.c
cvs rdiff -u -r1.51 -r1.52 src/usr.bin/netstat/netstat.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/main.c
diff -u src/usr.bin/netstat/main.c:1.99 src/usr.bin/netstat/main.c:1.100
--- src/usr.bin/netstat/main.c:1.99	Thu Jul 14 20:13:10 2016
+++ src/usr.bin/netstat/main.c	Thu Apr 23 00:24:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.99 2016/07/14 20:13:10 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.100 2020/04/23 00:24:50 joerg Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = "from: @(#)main.c	8.4 (Berkeley) 3/1/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.99 2016/07/14 20:13:10 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.100 2020/04/23 00:24:50 joerg Exp $");
 #endif
 #endif /* not lint */
 
@@ -67,6 +67,38 @@ __RCSID("$NetBSD: main.c,v 1.99 2016/07/
 #include "rtutil.h"
 #include "prog_ops.h"
 
+int	Aflag;
+int	aflag;
+int	Bflag;
+int	bflag;
+int	dflag;
+#ifndef SMALL
+int	gflag;
+#endif
+int	hflag;
+int	iflag;
+int	Lflag;
+int	lflag;
+int	mflag;
+int	numeric_addr;
+int	numeric_port;
+int	nflag;
+int	Pflag;
+int	pflag;
+int	qflag;
+int	rflag;
+int	sflag;
+int	tagflag;
+int	tflag;
+int	Vflag;
+int	vflag;
+
+char	*interface;
+
+int	af;
+int	use_sysctl;
+int	force_sysctl;
+
 struct nlist nl[] = {
 #define	N_MBSTAT	0
 	{ "_mbstat", 0, 0, 0, 0 },

Index: src/usr.bin/netstat/netstat.h
diff -u src/usr.bin/netstat/netstat.h:1.51 src/usr.bin/netstat/netstat.h:1.52
--- src/usr.bin/netstat/netstat.h:1.51	Thu Nov  6 21:30:09 2014
+++ src/usr.bin/netstat/netstat.h	Thu Apr 23 00:24:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: netstat.h,v 1.51 2014/11/06 21:30:09 christos Exp $	*/
+/*	$NetBSD: netstat.h,v 1.52 2020/04/23 00:24:50 joerg Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -34,37 +34,37 @@
 #include 
 #include 
 
-int	Aflag;		/* show addresses of protocol control block */
-int	aflag;		/* show all sockets (including servers) */
-int	Bflag;		/* show Berkeley Packet Filter information */
-int	bflag;		/* show i/f byte stats */
-int	dflag;		/* show i/f dropped packets */
+extern int	Aflag;		/* show addresses of protocol control block */
+extern int	aflag;		/* show all sockets (including servers) */
+extern int	Bflag;		/* show Berkeley Packet Filter information */
+extern int	bflag;		/* show i/f byte stats */
+extern int	dflag;		/* show i/f dropped packets */
 #ifndef SMALL
-int	gflag;		/* show group (multicast) routing or stats */
+extern int	gflag;		/* show group (multicast) routing or stats */
 #endif
-int	hflag;		/* humanize byte counts */
-int	iflag;		/* show interfaces */
-int	Lflag;		/* don't show LLINFO entries */
-int	lflag;		/* show routing table with use and ref */
-int	mflag;		/* show memory stats */
-int	numeric_addr;	/* show addresses numerically */
-int	numeric_port;	/* show ports numerically */
-int	nflag;		/* same as above, for show.c compat */
-int	Pflag;		/* dump a PCB */
-int	pflag;		/* show given protocol */
-int	qflag;		/* show softintrq */
-int	rflag;		/* show routing tables (or routing stats) */
-int	sflag;		/* show protocol statistics */
-int	tagflag;	/* show route tags */
-int	tflag;		/* show i/f watchdog timers */
-int	Vflag;		/* show Vestigial TIME_WAIT (VTW) information */
-int	vflag;		/* verbose route information or don't truncate names */
-
-char	*interface;	/* desired i/f for stats, or NULL for all i/fs */
-
-int	af;		/* address family */
-int	use_sysctl;	/* use sysctl instead of kmem */
-int	force_sysctl;	/* force use of sysctl (or exit) - for testing */
+extern int	hflag;		/* humanize byte counts */
+extern int	iflag;		/* show interfaces */
+extern int	Lflag;		/* don't show LLINFO entries */
+extern int	lflag;		/* show routing table with use and ref */
+extern int	mflag;		/* show memory stats */
+extern int	numeric_addr;	/* show addresses numerically */
+extern int	numeric_port;	/* show ports numerically */
+extern int	nflag;		/* same as above, for show.c compat */
+extern int	Pflag;		/* dump a PCB */
+extern int	pflag;		/* show given protocol */
+extern int	qflag;		/* show softintrq */
+extern int	rflag;		/* show routing tables (or routing stats) */
+extern int	sflag;		/* show protocol statistics */
+extern int	tagflag;	/* show route tags */
+extern int	tflag;		/* show i/f watchdog timers */
+extern int	Vflag;		/* show Vestigial TIME_WAIT (VTW) information */
+extern int	vflag;		/* verbose route information or don't truncate names */
+
+extern char	*interface;	/* desired i/f for stats, or NULL for all i/fs */
+
+extern int	af;		/* address family */
+extern int	use_sysctl;	/* use sysctl instead of kmem 

CVS commit: src/usr.bin/netstat

2020-04-22 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Apr 23 00:23:31 UTC 2020

Modified Files:
src/usr.bin/netstat: atalk.c

Log Message:
Avoid global scope for variables only used locally


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/netstat/atalk.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/atalk.c
diff -u src/usr.bin/netstat/atalk.c:1.17 src/usr.bin/netstat/atalk.c:1.18
--- src/usr.bin/netstat/atalk.c:1.17	Sun Aug 18 04:14:40 2019
+++ src/usr.bin/netstat/atalk.c	Thu Apr 23 00:23:31 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: atalk.c,v 1.17 2019/08/18 04:14:40 kamil Exp $	*/
+/*	$NetBSD: atalk.c,v 1.18 2020/04/23 00:23:31 joerg Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from @(#)atalk.c	1.1 (Whistle) 6/6/96";
 #else
-__RCSID("$NetBSD: atalk.c,v 1.17 2019/08/18 04:14:40 kamil Exp $");
+__RCSID("$NetBSD: atalk.c,v 1.18 2020/04/23 00:23:31 joerg Exp $");
 #endif
 #endif /* not lint */
 
@@ -63,9 +63,6 @@ __RCSID("$NetBSD: atalk.c,v 1.17 2019/08
 #include "netstat.h"
 #include "prog_ops.h"
 
-struct ddpcbddpcb;
-struct socket   sockb;
-
 static int first = 1;
 
 /*
@@ -230,6 +227,8 @@ atalk_print2(const struct sockaddr *sa, 
 void
 atalkprotopr(u_long off, const char *name)
 {
+	struct ddpcb ddpcb;
+	struct socket sockb;
 	struct ddpcb *next;
 	struct ddpcb *initial;
 	int width = 22;



CVS commit: src/usr.bin/netstat

2020-04-22 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Apr 23 00:24:16 UTC 2020

Modified Files:
src/usr.bin/netstat: inet6.c

Log Message:
sockb is only used locally, so move it into the function


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/usr.bin/netstat/inet6.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.73 src/usr.bin/netstat/inet6.c:1.74
--- src/usr.bin/netstat/inet6.c:1.73	Sun Aug 18 04:14:40 2019
+++ src/usr.bin/netstat/inet6.c	Thu Apr 23 00:24:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.73 2019/08/18 04:14:40 kamil Exp $	*/
+/*	$NetBSD: inet6.c,v 1.74 2020/04/23 00:24:16 joerg Exp $	*/
 /*	BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp	*/
 
 /*
@@ -64,7 +64,7 @@
 #if 0
 static char sccsid[] = "@(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet6.c,v 1.73 2019/08/18 04:14:40 kamil Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.74 2020/04/23 00:24:16 joerg Exp $");
 #endif
 #endif /* not lint */
 
@@ -147,7 +147,6 @@ struct	tcp6cb tcp6cb;
 #else
 struct	tcpcb tcpcb;
 #endif
-struct	socket sockb;
 
 char	*inet6name(const struct in6_addr *);
 void	inet6print(const struct in6_addr *, int, const char *);
@@ -283,8 +282,9 @@ print_vtw_v6(const vtw_t *vtw)
 
 
 static struct kinfo_pcb *
-getpcblist_kmem(u_long off, const char *name, size_t *len) {
-
+getpcblist_kmem(u_long off, const char *name, size_t *len)
+{
+	struct socket sockb;
 	struct inpcbtable table;
 	struct inpcb_hdr *next, *prev;
 	int istcp = strcmp(name, "tcp6") == 0;



CVS commit: src/usr.bin/netstat

2020-04-22 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Apr 23 00:24:16 UTC 2020

Modified Files:
src/usr.bin/netstat: inet6.c

Log Message:
sockb is only used locally, so move it into the function


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/usr.bin/netstat/inet6.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2020-04-22 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Apr 23 00:23:31 UTC 2020

Modified Files:
src/usr.bin/netstat: atalk.c

Log Message:
Avoid global scope for variables only used locally


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/netstat/atalk.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2020-04-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Apr  3 16:42:00 UTC 2020

Modified Files:
src/usr.bin/netstat: Makefile netstat_hostops.c netstat_rumpops.c
Removed Files:
src/usr.bin/netstat: prog_ops.h

Log Message:
remove unused


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/netstat/Makefile
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/netstat/netstat_hostops.c \
src/usr.bin/netstat/netstat_rumpops.c
cvs rdiff -u -r1.4 -r0 src/usr.bin/netstat/prog_ops.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/Makefile
diff -u src/usr.bin/netstat/Makefile:1.47 src/usr.bin/netstat/Makefile:1.48
--- src/usr.bin/netstat/Makefile:1.47	Sun Oct 13 03:28:16 2019
+++ src/usr.bin/netstat/Makefile	Fri Apr  3 12:41:59 2020
@@ -1,10 +1,15 @@
-#	$NetBSD: Makefile,v 1.47 2019/10/13 07:28:16 mrg Exp $
+#	$NetBSD: Makefile,v 1.48 2020/04/03 16:41:59 christos Exp $
 #	from: @(#)Makefile	8.1 (Berkeley) 6/12/93
 
 .include 
 
 USE_FORT?= yes	# setgid
 
+ROUTE=${NETBSDSRCDIR}/sbin/route
+PF=${NETBSDSRCDIR}/sys/dist/pf
+
+.PATH: ${ROUTE} 
+
 RUMPPRG=netstat
 SRCS=	atalk.c bpf.c fast_ipsec.c if.c inet.c inet6.c \
 	main.c mbuf.c mroute.c mroute6.c pfkey.c pfsync.c route.c \
@@ -14,10 +19,8 @@ BINMODE=2555
 LDADD=	-lutil -lkvm
 DPADD=	${LIBUTIL} ${LIBKVM}
 CPPFLAGS+= -DIPSEC -I${.CURDIR}
-CPPFLAGS+= -I${NETBSDSRCDIR}/sys/dist/pf
-CPPFLAGS+= -I${NETBSDSRCDIR}/sbin/route
-
-.PATH:  ${.CURDIR}/../../sbin/route
+CPPFLAGS+= -I${PF}
+CPPFLAGS+= -I${ROUTE}
 
 .if (${MKRUMP} != "no")
 .PATH:  ${.CURDIR}/../../lib/libc/gen

Index: src/usr.bin/netstat/netstat_hostops.c
diff -u src/usr.bin/netstat/netstat_hostops.c:1.3 src/usr.bin/netstat/netstat_hostops.c:1.4
--- src/usr.bin/netstat/netstat_hostops.c:1.3	Fri Apr  3 12:20:51 2020
+++ src/usr.bin/netstat/netstat_hostops.c	Fri Apr  3 12:41:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: netstat_hostops.c,v 1.3 2020/04/03 16:20:51 martin Exp $	*/
+/*	$NetBSD: netstat_hostops.c,v 1.4 2020/04/03 16:41:59 christos Exp $	*/
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -26,9 +26,4 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include 
-#ifndef lint
-__RCSID("$NetBSD: netstat_hostops.c,v 1.3 2020/04/03 16:20:51 martin Exp $");
-#endif /* !lint */
-
-#include "../../sbin/route/route_hostops.c"
+#include "route_hostops.c"
Index: src/usr.bin/netstat/netstat_rumpops.c
diff -u src/usr.bin/netstat/netstat_rumpops.c:1.3 src/usr.bin/netstat/netstat_rumpops.c:1.4
--- src/usr.bin/netstat/netstat_rumpops.c:1.3	Fri Apr  3 12:20:51 2020
+++ src/usr.bin/netstat/netstat_rumpops.c	Fri Apr  3 12:41:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: netstat_rumpops.c,v 1.3 2020/04/03 16:20:51 martin Exp $	*/
+/*	$NetBSD: netstat_rumpops.c,v 1.4 2020/04/03 16:41:59 christos Exp $	*/
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -26,4 +26,4 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "../../sbin/route/route_rumpops.c"
+#include "route_rumpops.c"



CVS commit: src/usr.bin/netstat

2020-04-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Apr  3 16:42:00 UTC 2020

Modified Files:
src/usr.bin/netstat: Makefile netstat_hostops.c netstat_rumpops.c
Removed Files:
src/usr.bin/netstat: prog_ops.h

Log Message:
remove unused


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/netstat/Makefile
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/netstat/netstat_hostops.c \
src/usr.bin/netstat/netstat_rumpops.c
cvs rdiff -u -r1.4 -r0 src/usr.bin/netstat/prog_ops.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2020-02-01 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Feb  2 03:41:12 UTC 2020

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Update for per-cpu interface statistics.


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2020-02-01 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Feb  2 03:41:12 UTC 2020

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Update for per-cpu interface statistics.


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.95 src/usr.bin/netstat/if.c:1.96
--- src/usr.bin/netstat/if.c:1.95	Wed Jul 11 07:46:20 2018
+++ src/usr.bin/netstat/if.c	Sun Feb  2 03:41:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.95 2018/07/11 07:46:20 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.96 2020/02/02 03:41:12 thorpej Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.95 2018/07/11 07:46:20 msaitoh Exp $");
+__RCSID("$NetBSD: if.c,v 1.96 2020/02/02 03:41:12 thorpej Exp $");
 #endif
 #endif /* not lint */
 
@@ -289,9 +289,34 @@ union ifaddr_u {
 };
 
 static void
+ifnet_to_ifdata_kvm(const struct ifnet * const ifp, struct if_data * const ifd)
+{
+
+	/*
+	 * Interface statistics are no longer kept in struct ifnet,
+	 * and thus an if_data is no longer embedded in struct ifnet.
+	 * We cannot read stats via kvm without chasing per-cpu data,
+	 * and maybe someday we could do that.  But for now, this is
+	 * what we have.
+	 *
+	 * Just copy the fields that do exist.
+	 */
+	memset(ifd, 0, sizeof(*ifd));
+	ifd->ifi_type = ifp->if_type;
+	ifd->ifi_addrlen = ifp->if_addrlen;
+	ifd->ifi_hdrlen = ifp->if_hdrlen;
+	ifd->ifi_link_state = ifp->if_link_state;
+	ifd->ifi_mtu = ifp->if_mtu;
+	ifd->ifi_metric = ifp->if_metric;
+	ifd->ifi_baudrate = ifp->if_baudrate;
+	ifd->ifi_lastchange = ifp->if_lastchange;
+}
+
+static void
 intpr_kvm(u_long ifnetaddr, void (*pfunc)(const char *))
 {
 	struct ifnet ifnet;
+	struct if_data ifd;
 	union ifaddr_u ifaddr;
 	u_long ifaddraddr;
 	struct ifnet_head ifhead;	/* TAILQ_HEAD */
@@ -358,8 +383,9 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 			cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
 			CP();
 			sa = (struct sockaddr *)cp;
+			ifnet_to_ifdata_kvm(, );
 			print_addr(ifnet.if_index, sa, (void *),
-			_data, );
+			, );
 		}
 		ifaddraddr = (u_long)ifaddr.ifa.ifa_list.tqe_next;
 	}
@@ -787,6 +813,7 @@ sidewaysintpr_kvm(unsigned interval, u_l
 	sigset_t emptyset;
 	sigset_t noalrm;
 	struct ifnet ifnet;
+	struct if_data ifd;
 	u_long firstifnet;
 	struct iftot *ip, *total;
 	unsigned line;
@@ -906,53 +933,54 @@ loop:
 			off = 0;
 			continue;
 		}
+		ifnet_to_ifdata_kvm(, );
 		if (ip == interesting) {
 			if (bflag) {
 char humbuf[HUMBUF_SIZE];
 
 if (hflag && humanize_number(humbuf,
 sizeof(humbuf),
-ifnet.if_ibytes - ip->ift_ib, "",
+ifd.ifi_ibytes - ip->ift_ib, "",
 HN_AUTOSCALE, HN_NOSPACE | HN_B) > 0)
 	printf("%10s %8.8s ", humbuf, " ");
 else
 	printf("%10llu %8.8s ", 
 	(unsigned long long)
-	(ifnet.if_ibytes-ip->ift_ib), " ");
+	(ifd.ifi_ibytes-ip->ift_ib), " ");
 
 if (hflag && humanize_number(humbuf,
 sizeof(humbuf),
-ifnet.if_obytes - ip->ift_ob, "",
+ifd.ifi_obytes - ip->ift_ob, "",
 HN_AUTOSCALE, HN_NOSPACE | HN_B) > 0)
 	printf("%10s %5.5s", humbuf, " ");
 else
 	printf("%10llu %5.5s", 
 	(unsigned long long)
-	(ifnet.if_obytes-ip->ift_ob), " ");
+	(ifd.ifi_obytes-ip->ift_ob), " ");
 			} else {
 printf("%8llu %5llu %8llu %5llu %5llu",
 (unsigned long long)
-	(ifnet.if_ipackets - ip->ift_ip),
+	(ifd.ifi_ipackets - ip->ift_ip),
 (unsigned long long)
-	(ifnet.if_ierrors - ip->ift_ie),
+	(ifd.ifi_ierrors - ip->ift_ie),
 (unsigned long long)
-	(ifnet.if_opackets - ip->ift_op),
+	(ifd.ifi_opackets - ip->ift_op),
 (unsigned long long)
-	(ifnet.if_oerrors - ip->ift_oe),
+	(ifd.ifi_oerrors - ip->ift_oe),
 (unsigned long long)
-	(ifnet.if_collisions - ip->ift_co));
+	(ifd.ifi_collisions - ip->ift_co));
 			}
 			if (dflag)
 printf(" %5" PRIu64,
 	ifnet.if_snd.ifq_drops - ip->ift_dr);
 		}
-		ip->ift_ip = ifnet.if_ipackets;
-		ip->ift_ib = ifnet.if_ibytes;
-		ip->ift_ie = ifnet.if_ierrors;
-		ip->ift_op = ifnet.if_opackets;
-		ip->ift_ob = ifnet.if_obytes;
-		ip->ift_oe = ifnet.if_oerrors;
-		ip->ift_co = ifnet.if_collisions;
+		ip->ift_ip = ifd.ifi_ipackets;
+		ip->ift_ib = ifd.ifi_ibytes;
+		ip->ift_ie = ifd.ifi_ierrors;
+		ip->ift_op = ifd.ifi_opackets;
+		ip->ift_ob = ifd.ifi_obytes;
+		ip->ift_oe = ifd.ifi_oerrors;
+		ip->ift_co = ifd.ifi_collisions;
 		ip->ift_dr = ifnet.if_snd.ifq_drops;
 		sum->ift_ip += ip->ift_ip;
 		sum->ift_ib += ip->ift_ib;



CVS commit: src/usr.bin/netstat

2019-10-05 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Oct  6 00:27:50 UTC 2019

Modified Files:
src/usr.bin/netstat: mroute.c

Log Message:
sprintf() -> snprintf(), and adjust a buffer size to avoid any
potential for overflow.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/netstat/mroute.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2019-10-05 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Oct  6 00:27:50 UTC 2019

Modified Files:
src/usr.bin/netstat: mroute.c

Log Message:
sprintf() -> snprintf(), and adjust a buffer size to avoid any
potential for overflow.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/netstat/mroute.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/mroute.c
diff -u src/usr.bin/netstat/mroute.c:1.25 src/usr.bin/netstat/mroute.c:1.26
--- src/usr.bin/netstat/mroute.c:1.25	Thu Nov  6 21:30:09 2014
+++ src/usr.bin/netstat/mroute.c	Sun Oct  6 00:27:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: mroute.c,v 1.25 2014/11/06 21:30:09 christos Exp $	*/
+/*	$NetBSD: mroute.c,v 1.26 2019/10/06 00:27:50 mrg Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -76,7 +76,7 @@
 #if 0
 static char sccsid[] = "from: @(#)mroute.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: mroute.c,v 1.25 2014/11/06 21:30:09 christos Exp $");
+__RCSID("$NetBSD: mroute.c,v 1.26 2019/10/06 00:27:50 mrg Exp $");
 #endif
 #endif /* not lint */
 
@@ -269,7 +269,7 @@ mroutepr(u_long mrpaddr, u_long mfchasht
 static void
 print_bw_meter(struct bw_meter *bw_meter, int *banner_printed)
 {
-	char s0[256], s1[256], s2[256], s3[256];
+	char s0[256*3], s1[256], s2[256], s3[256];
 	struct timeval now, end, delta;
 
 	gettimeofday(, NULL);
@@ -286,37 +286,37 @@ print_bw_meter(struct bw_meter *bw_meter
 
 	/* The measured values */
 	if (bw_meter->bm_flags & BW_METER_UNIT_PACKETS)
-		sprintf(s1, "%llu", (unsigned long long)bw_meter->bm_measured.b_packets);
+		snprintf(s1, sizeof s1, "%llu", (unsigned long long)bw_meter->bm_measured.b_packets);
 	else
-		sprintf(s1, "?");
+		snprintf(s1, sizeof s1, "?");
 	if (bw_meter->bm_flags & BW_METER_UNIT_BYTES)
-		sprintf(s2, "%llu", (unsigned long long)bw_meter->bm_measured.b_bytes);
+		snprintf(s2, sizeof s2, "%llu", (unsigned long long)bw_meter->bm_measured.b_bytes);
 	else
-		sprintf(s2, "?");
-	sprintf(s0, "%lld.%ld|%s|%s",
+		snprintf(s2, sizeof s2, "?");
+	snprintf(s0, sizeof s0, "%lld.%ld|%s|%s",
 		(long long)bw_meter->bm_start_time.tv_sec,
 		(long)bw_meter->bm_start_time.tv_usec,
 		s1, s2);
 	printf("  %-30s", s0);
 
 	/* The type of entry */
-	sprintf(s0, "%s", "?");
+	snprintf(s0, sizeof s0, "%s", "?");
 	if (bw_meter->bm_flags & BW_METER_GEQ)
-		sprintf(s0, "%s", ">=");
+		snprintf(s0, sizeof s0, "%s", ">=");
 	else if (bw_meter->bm_flags & BW_METER_LEQ)
-		sprintf(s0, "%s", "<=");
+		snprintf(s0, sizeof s0, "%s", "<=");
 	printf("  %-3s", s0);
 
 	/* The threshold values */
 	if (bw_meter->bm_flags & BW_METER_UNIT_PACKETS)
-		sprintf(s1, "%llu", (unsigned long long)bw_meter->bm_threshold.b_packets);
+		snprintf(s1, sizeof s1, "%llu", (unsigned long long)bw_meter->bm_threshold.b_packets);
 	else
-		sprintf(s1, "?");
+		snprintf(s1, sizeof s1, "?");
 	if (bw_meter->bm_flags & BW_METER_UNIT_BYTES)
-		sprintf(s2, "%llu", (unsigned long long)bw_meter->bm_threshold.b_bytes);
+		snprintf(s2, sizeof s2, "%llu", (unsigned long long)bw_meter->bm_threshold.b_bytes);
 	else
-		sprintf(s2, "?");
-	sprintf(s0, "%lld.%ld|%s|%s",
+		snprintf(s2, sizeof s2, "?");
+	snprintf(s0, sizeof s0, "%lld.%ld|%s|%s",
 		(long long)bw_meter->bm_threshold.b_time.tv_sec,
 		(long)bw_meter->bm_threshold.b_time.tv_usec,
 		s1, s2);
@@ -327,12 +327,12 @@ print_bw_meter(struct bw_meter *bw_meter
 		 _meter->bm_threshold.b_time, );
 	if (timercmp(, , <=)) {
 		timersub(, , );
-		sprintf(s3, "%lld.%ld",
+		snprintf(s3, sizeof s3, "%lld.%ld",
 		(long long)delta.tv_sec, (long)delta.tv_usec);
 	} else {
 		/* Negative time */
 		timersub(, , );
-		sprintf(s3, "-%lld.%ld",
+		snprintf(s3, sizeof s3, "-%lld.%ld",
 		(long long)delta.tv_sec, (long)delta.tv_usec);
 	}
 	printf(" %s", s3);



CVS commit: src/usr.bin/netstat

2019-08-17 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Aug 18 04:14:41 UTC 2019

Modified Files:
src/usr.bin/netstat: Makefile atalk.c bpf.c fast_ipsec.c inet.c inet6.c
netstat_hostops.c netstat_rumpops.c pfkey.c pfsync.c prog_ops.h

Log Message:
netstat: Add indirection of symbols to remove clash with sanitizers

Add indirection and symbol renaming under MKSANITIZER for the linked in
version of sysctlbyname, sysctlgetmibinfo and sysctlnametomib.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/netstat/Makefile
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/netstat/atalk.c
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/netstat/bpf.c
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/netstat/fast_ipsec.c
cvs rdiff -u -r1.109 -r1.110 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.72 -r1.73 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/netstat/netstat_hostops.c \
src/usr.bin/netstat/netstat_rumpops.c src/usr.bin/netstat/pfkey.c \
src/usr.bin/netstat/pfsync.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/netstat/prog_ops.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2019-08-17 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Aug 18 04:14:41 UTC 2019

Modified Files:
src/usr.bin/netstat: Makefile atalk.c bpf.c fast_ipsec.c inet.c inet6.c
netstat_hostops.c netstat_rumpops.c pfkey.c pfsync.c prog_ops.h

Log Message:
netstat: Add indirection of symbols to remove clash with sanitizers

Add indirection and symbol renaming under MKSANITIZER for the linked in
version of sysctlbyname, sysctlgetmibinfo and sysctlnametomib.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/netstat/Makefile
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/netstat/atalk.c
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/netstat/bpf.c
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/netstat/fast_ipsec.c
cvs rdiff -u -r1.109 -r1.110 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.72 -r1.73 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/netstat/netstat_hostops.c \
src/usr.bin/netstat/netstat_rumpops.c src/usr.bin/netstat/pfkey.c \
src/usr.bin/netstat/pfsync.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/netstat/prog_ops.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/Makefile
diff -u src/usr.bin/netstat/Makefile:1.45 src/usr.bin/netstat/Makefile:1.46
--- src/usr.bin/netstat/Makefile:1.45	Tue Oct 10 19:31:10 2017
+++ src/usr.bin/netstat/Makefile	Sun Aug 18 04:14:40 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.45 2017/10/10 19:31:10 christos Exp $
+#	$NetBSD: Makefile,v 1.46 2019/08/18 04:14:40 kamil Exp $
 #	from: @(#)Makefile	8.1 (Berkeley) 6/12/93
 
 .include 
@@ -25,6 +25,10 @@ RUMPSRCS+= sysctlbyname.c sysctlgetmibin
 LDADD.rump+=	-lrumpres
 DPADD.add+=	${LIBRUMPRES}
 CPPFLAGS+=  -DRUMP_ACTION
+
+SANITIZER_RENAME_CLASSES+=	rump
+SANITIZER_RENAME_FILES.rump+=	${PROG}_rumpops.c ${RUMPSRCS}
+SANITIZER_RENAME_SYMBOL.rump+=	sysctlbyname sysctlgetmibinfo sysctlnametomib
 .endif
 
 

Index: src/usr.bin/netstat/atalk.c
diff -u src/usr.bin/netstat/atalk.c:1.16 src/usr.bin/netstat/atalk.c:1.17
--- src/usr.bin/netstat/atalk.c:1.16	Sat Jun  6 13:08:31 2015
+++ src/usr.bin/netstat/atalk.c	Sun Aug 18 04:14:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: atalk.c,v 1.16 2015/06/06 13:08:31 joerg Exp $	*/
+/*	$NetBSD: atalk.c,v 1.17 2019/08/18 04:14:40 kamil Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from @(#)atalk.c	1.1 (Whistle) 6/6/96";
 #else
-__RCSID("$NetBSD: atalk.c,v 1.16 2015/06/06 13:08:31 joerg Exp $");
+__RCSID("$NetBSD: atalk.c,v 1.17 2019/08/18 04:14:40 kamil Exp $");
 #endif
 #endif /* not lint */
 
@@ -61,6 +61,7 @@ __RCSID("$NetBSD: atalk.c,v 1.16 2015/06
 #include 
 #include 
 #include "netstat.h"
+#include "prog_ops.h"
 
 struct ddpcbddpcb;
 struct socket   sockb;
@@ -290,7 +291,7 @@ ddp_stats(u_long off, const char *name)
 	if (use_sysctl) {
 		size_t size = sizeof(ddpstat);
 
-		if (sysctlbyname("net.atalk.ddp.stats", ddpstat, ,
+		if (prog_sysctlbyname("net.atalk.ddp.stats", ddpstat, ,
  NULL, 0) == -1)
 			return;
 	} else {

Index: src/usr.bin/netstat/bpf.c
diff -u src/usr.bin/netstat/bpf.c:1.13 src/usr.bin/netstat/bpf.c:1.14
--- src/usr.bin/netstat/bpf.c:1.13	Tue Jun 26 09:50:42 2018
+++ src/usr.bin/netstat/bpf.c	Sun Aug 18 04:14:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.13 2018/06/26 09:50:42 msaitoh Exp $	*/
+/*	$NetBSD: bpf.c,v 1.14 2019/08/18 04:14:40 kamil Exp $	*/
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@ bpf_stats(void)
 	size_t len = sizeof(bpf_s);
 
 	if (use_sysctl) {
-		if (sysctlbyname("net.bpf.stats", _s, , NULL, 0) == -1)
+		if (prog_sysctlbyname("net.bpf.stats", _s, , NULL, 0) == -1)
 			err(1, "net.bpf.stats");
 	
 		printf("bpf:\n");
@@ -83,7 +83,7 @@ bpf_dump(const char *bpfif)
 		/* adapted from sockstat.c by Andrew Brown */
 
 		sz = CTL_MAXNAME;
-		if (sysctlnametomib("net.bpf.peers", [0], ) == -1)
+		if (prog_sysctlnametomib("net.bpf.peers", [0], ) == -1)
 			err(1, "sysctlnametomib: net.bpf.peers");
 		namelen = sz;
 

Index: src/usr.bin/netstat/fast_ipsec.c
diff -u src/usr.bin/netstat/fast_ipsec.c:1.22 src/usr.bin/netstat/fast_ipsec.c:1.23
--- src/usr.bin/netstat/fast_ipsec.c:1.22	Thu Jun 29 07:15:27 2017
+++ src/usr.bin/netstat/fast_ipsec.c	Sun Aug 18 04:14:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: fast_ipsec.c,v 1.22 2017/06/29 07:15:27 ozaki-r Exp $ */
+/*	$NetBSD: fast_ipsec.c,v 1.23 2019/08/18 04:14:40 kamil Exp $ */
 /* 	$FreeBSD: src/tools/tools/crypto/ipsecstats.c,v 1.1.4.1 2003/06/03 00:13:13 sam Exp $ */
 
 /*-
@@ -33,7 +33,7 @@
 #include 
 #ifndef lint
 #ifdef __NetBSD__
-__RCSID("$NetBSD: fast_ipsec.c,v 1.22 2017/06/29 07:15:27 ozaki-r Exp $");
+__RCSID("$NetBSD: fast_ipsec.c,v 1.23 2019/08/18 04:14:40 kamil Exp $");
 #endif
 #endif /* not lint*/
 
@@ -62,6 +62,7 @@ __RCSID("$NetBSD: fast_ipsec.c,v 1.22 20
 #include 
 
 #include "netstat.h"
+#include "prog_ops.h"
 
 /*
  * Table-driven mapping from SADB algorithm codes to 

CVS commit: src/usr.bin/netstat

2019-06-25 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Jun 25 14:52:56 UTC 2019

Modified Files:
src/usr.bin/netstat: mbuf.c

Log Message:
Limit maximum owner name to appease gcc


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/usr.bin/netstat/mbuf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/mbuf.c
diff -u src/usr.bin/netstat/mbuf.c:1.33 src/usr.bin/netstat/mbuf.c:1.34
--- src/usr.bin/netstat/mbuf.c:1.33	Tue Jul 28 19:46:42 2015
+++ src/usr.bin/netstat/mbuf.c	Tue Jun 25 14:52:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: mbuf.c,v 1.33 2015/07/28 19:46:42 christos Exp $	*/
+/*	$NetBSD: mbuf.c,v 1.34 2019/06/25 14:52:55 martin Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)mbuf.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: mbuf.c,v 1.33 2015/07/28 19:46:42 christos Exp $");
+__RCSID("$NetBSD: mbuf.c,v 1.34 2019/06/25 14:52:55 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -239,7 +239,7 @@ dump_drain:
 		mo->mo_counter[MOWNER_COUNTER_CLUSTER_CLAIMS] ==
 		mo->mo_counter[MOWNER_COUNTER_CLUSTER_RELEASES])
 			continue;
-		snprintf(buf, sizeof(buf), "%16s %-13s",
+		snprintf(buf, sizeof(buf), "%16.16s %-13s",
 		mo->mo_name, mo->mo_descr);
 		if ((lines % 24) == 0 || lines > 24) {
 			printf("%30s %-8s %10s %10s %10s\n",



CVS commit: src/usr.bin/netstat

2019-06-25 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Jun 25 14:52:56 UTC 2019

Modified Files:
src/usr.bin/netstat: mbuf.c

Log Message:
Limit maximum owner name to appease gcc


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/usr.bin/netstat/mbuf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2019-05-13 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon May 13 07:48:42 UTC 2019

Modified Files:
src/usr.bin/netstat: inet.c inet6.c

Log Message:
Show the number of packets dropped by pfil


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.71 -r1.72 src/usr.bin/netstat/inet6.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2019-05-13 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon May 13 07:48:42 UTC 2019

Modified Files:
src/usr.bin/netstat: inet.c inet6.c

Log Message:
Show the number of packets dropped by pfil


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.71 -r1.72 src/usr.bin/netstat/inet6.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/inet.c
diff -u src/usr.bin/netstat/inet.c:1.108 src/usr.bin/netstat/inet.c:1.109
--- src/usr.bin/netstat/inet.c:1.108	Thu May  3 07:13:48 2018
+++ src/usr.bin/netstat/inet.c	Mon May 13 07:48:42 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.108 2018/05/03 07:13:48 maxv Exp $	*/
+/*	$NetBSD: inet.c,v 1.109 2019/05/13 07:48:42 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet.c,v 1.108 2018/05/03 07:13:48 maxv Exp $");
+__RCSID("$NetBSD: inet.c,v 1.109 2019/05/13 07:48:42 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -630,6 +630,8 @@ ip_stats(u_long off, const char *name)
 	p(IP_STAT_OFRAGMENTS, "\t%" PRIu64 " fragment%s created\n");
 	p(IP_STAT_CANTFRAG, "\t%" PRIu64 " datagram%s that can't be fragmented\n");
 	p(IP_STAT_BADADDR, "\t%" PRIu64 " datagram%s with bad address in header\n");
+	p(IP_STAT_PFILDROP_IN, "\t%" PRIu64 " input packet%s dropped by pfil\n");
+	p(IP_STAT_PFILDROP_OUT, "\t%" PRIu64 " output packet%s dropped by pfil\n");
 #undef ps
 #undef p
 }

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.71 src/usr.bin/netstat/inet6.c:1.72
--- src/usr.bin/netstat/inet6.c:1.71	Thu May  3 07:13:48 2018
+++ src/usr.bin/netstat/inet6.c	Mon May 13 07:48:42 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.71 2018/05/03 07:13:48 maxv Exp $	*/
+/*	$NetBSD: inet6.c,v 1.72 2019/05/13 07:48:42 ozaki-r Exp $	*/
 /*	BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp	*/
 
 /*
@@ -64,7 +64,7 @@
 #if 0
 static char sccsid[] = "@(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet6.c,v 1.71 2018/05/03 07:13:48 maxv Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.72 2019/05/13 07:48:42 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -798,6 +798,8 @@ ip6_stats(u_long off, const char *name)
 
 	p1(IP6_STAT_FORWARD_CACHEHIT, "\t%llu forward cache hit\n");
 	p1(IP6_STAT_FORWARD_CACHEMISS, "\t%llu forward cache miss\n");
+	p(IP6_STAT_PFILDROP_IN, "\t%llu input packet%s dropped by pfil\n");
+	p(IP6_STAT_PFILDROP_OUT, "\t%llu output packet%s dropped by pfil\n");
 #undef p
 #undef p1
 }



CVS commit: src/usr.bin/netstat

2018-07-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Jul 11 07:46:21 UTC 2018

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
 Print iqdrops, too. This change also fixes a bug that Odrops prints
iqdrops when kvm read failed.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.94 src/usr.bin/netstat/if.c:1.95
--- src/usr.bin/netstat/if.c:1.94	Thu Feb 23 07:57:10 2017
+++ src/usr.bin/netstat/if.c	Wed Jul 11 07:46:20 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.94 2017/02/23 07:57:10 ozaki-r Exp $	*/
+/*	$NetBSD: if.c,v 1.95 2018/07/11 07:46:20 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.94 2017/02/23 07:57:10 ozaki-r Exp $");
+__RCSID("$NetBSD: if.c,v 1.95 2018/07/11 07:46:20 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -152,14 +152,17 @@ intpr_header(void)
 			   "Ibytes", "Obytes");
 		} else {
 			printf("%-5.5s %-5.5s %-13.13s %-17.17s "
-			   "%8.8s %5.5s %8.8s %5.5s %5.5s",
-			   "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs",
-			   "Opkts", "Oerrs", "Colls");
+			"%8.8s %5.5s",
+			"Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs");
+			if (dflag)
+printf(" %6.6s", "Idrops");
+			printf(" %8.8s %5.5s %5.5s",
+			"Opkts", "Oerrs", "Colls");
 		}
+		if (dflag)
+			printf(" %6.6s", "Odrops");
 		if (tflag)
 			printf(" %4.4s", "Time");
-		if (dflag)
-			printf(" %5.5s", "Drops");
 		putchar('\n');
 	}
 }
@@ -617,19 +620,21 @@ print_addr(const int ifindex, struct soc
 		else
 			printf("%10llu", (unsigned long long)ifd->ifi_obytes);
 	} else {
-		printf("%8llu %5llu %8llu %5llu %5llu",
+		printf("%8llu %5llu",
 			(unsigned long long)ifd->ifi_ipackets,
-			(unsigned long long)ifd->ifi_ierrors,
+			(unsigned long long)ifd->ifi_ierrors);
+		if (dflag)
+			printf(" %6" PRIu64, ifd->ifi_iqdrops);
+		printf(" %8llu %5llu %5llu",
 			(unsigned long long)ifd->ifi_opackets,
 			(unsigned long long)ifd->ifi_oerrors,
 			(unsigned long long)ifd->ifi_collisions);
 	}
+	if (dflag)
+		printf(" %6lld", ifnet ?
+		(unsigned long long)ifnet->if_snd.ifq_drops : 0);
 	if (tflag)
 		printf(" %4d", ifnet ? ifnet->if_timer : 0);
-	if (dflag)
-		printf(" %5lld", ifnet ?
-		(unsigned long long)ifnet->if_snd.ifq_drops :
-		ifd->ifi_iqdrops);
 	putchar('\n');
 }
 



CVS commit: src/usr.bin/netstat

2018-07-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Jul 11 07:46:21 UTC 2018

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
 Print iqdrops, too. This change also fixes a bug that Odrops prints
iqdrops when kvm read failed.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2018-06-26 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Jun 26 09:50:42 UTC 2018

Modified Files:
src/usr.bin/netstat: bpf.c

Log Message:
 Fix a bug that BPF_D_OUT isn't printed correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/netstat/bpf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/bpf.c
diff -u src/usr.bin/netstat/bpf.c:1.12 src/usr.bin/netstat/bpf.c:1.13
--- src/usr.bin/netstat/bpf.c:1.12	Tue Jun 26 06:48:03 2018
+++ src/usr.bin/netstat/bpf.c	Tue Jun 26 09:50:42 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.12 2018/06/26 06:48:03 msaitoh Exp $	*/
+/*	$NetBSD: bpf.c,v 1.13 2018/06/26 09:50:42 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -148,7 +148,7 @@ bpf_dump(const char *bpfif)
 			printf("%c", BPFEXT(bde_promisc) ? 'P' : '-');
 			printf("%c", BPFEXT(bde_immediate) ? 'R' : '-');
 			printf("%c", (BPFEXT(bde_direction) == BPF_D_IN) ? '-'
-			: (BPFEXT(bde_direction) == BPF_D_IN) ? 'O' : 'S');
+			: (BPFEXT(bde_direction) == BPF_D_OUT) ? 'O' : 'S');
 			printf("%c", BPFEXT(bde_hdrcmplt) ? 'H' : '-');
 			printf("  %-8d ", BPFEXT(bde_bufsize));
 



CVS commit: src/usr.bin/netstat

2018-06-26 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Jun 26 09:50:42 UTC 2018

Modified Files:
src/usr.bin/netstat: bpf.c

Log Message:
 Fix a bug that BPF_D_OUT isn't printed correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/netstat/bpf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2017-12-19 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Dec 19 17:05:15 UTC 2017

Modified Files:
src/usr.bin/netstat: inet6.c

Log Message:
Add names of a few more ICMPv6 messages, from RFC6275 (Mobile IPv6)
and RFC4286 (Multicast Router Discovery.) and as shown in the IANA
parameters page available at:
  https://www.ietf.org/assignments/icmpv6-parameters/icmpv6-parameters.txt

Also make the array be explicitly 256 entries long, one for each possible
code, which will detect attempts to insert names without deleting the
place holder (and mean a good solid NULL de-ref if too many place holders
are deleted, rather than just random results.)


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/usr.bin/netstat/inet6.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2017-12-19 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Tue Dec 19 17:05:15 UTC 2017

Modified Files:
src/usr.bin/netstat: inet6.c

Log Message:
Add names of a few more ICMPv6 messages, from RFC6275 (Mobile IPv6)
and RFC4286 (Multicast Router Discovery.) and as shown in the IANA
parameters page available at:
  https://www.ietf.org/assignments/icmpv6-parameters/icmpv6-parameters.txt

Also make the array be explicitly 256 entries long, one for each possible
code, which will detect attempts to insert names without deleting the
place holder (and mean a good solid NULL de-ref if too many place holders
are deleted, rather than just random results.)


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/usr.bin/netstat/inet6.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.69 src/usr.bin/netstat/inet6.c:1.70
--- src/usr.bin/netstat/inet6.c:1.69	Sat Dec 17 09:12:22 2016
+++ src/usr.bin/netstat/inet6.c	Tue Dec 19 17:05:15 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.69 2016/12/17 09:12:22 mlelstv Exp $	*/
+/*	$NetBSD: inet6.c,v 1.70 2017/12/19 17:05:15 kre Exp $	*/
 /*	BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp	*/
 
 /*
@@ -64,7 +64,7 @@
 #if 0
 static char sccsid[] = "@(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet6.c,v 1.69 2016/12/17 09:12:22 mlelstv Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.70 2017/12/19 17:05:15 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -860,7 +860,7 @@ ip6_ifstats(const char *ifname)
 #undef p_5
 }
 
-static	const char *icmp6names[] = {
+static	const char *icmp6names[256] = {
 	"#0",
 	"unreach",
 	"packet too big",
@@ -1004,17 +1004,17 @@ static	const char *icmp6names[] = {
 	"node information reply",
 	"#141",
 	"#142",
-	"#143",
-	"#144",
-	"#145",
-	"#146",
-	"#147",
+	"multicast listener report (v2)",
+	"home agent discovery request",
+	"home agent discovery reply",
+	"mobile prefix solicitation",
+	"mobile prefix advertisement",
 	"#148",
 	"#149",	
 	"#150",
-	"#151",
-	"#152",
-	"#153",
+	"multicast router advertisement",
+	"multicast router solicitation",
+	"multicast router termination",
 	"#154",
 	"#155",
 	"#156",



CVS commit: src/usr.bin/netstat

2017-10-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Oct 10 19:31:10 UTC 2017

Modified Files:
src/usr.bin/netstat: Makefile

Log Message:
use librumpres


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/usr.bin/netstat/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/Makefile
diff -u src/usr.bin/netstat/Makefile:1.44 src/usr.bin/netstat/Makefile:1.45
--- src/usr.bin/netstat/Makefile:1.44	Fri Dec 23 05:19:57 2016
+++ src/usr.bin/netstat/Makefile	Tue Oct 10 15:31:10 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.44 2016/12/23 10:19:57 mrg Exp $
+#	$NetBSD: Makefile,v 1.45 2017/10/10 19:31:10 christos Exp $
 #	from: @(#)Makefile	8.1 (Berkeley) 6/12/93
 
 .include 
@@ -17,12 +17,16 @@ CPPFLAGS+= -DIPSEC -I${.CURDIR}
 CPPFLAGS+= -I${NETBSDSRCDIR}/sys/dist/pf
 CPPFLAGS+= -I${NETBSDSRCDIR}/sbin/route
 
-.PATH:  ${.CURDIR}/../../lib/libc/gen
-.PATH:  ${.CURDIR}/../../lib/libc/net
 .PATH:  ${.CURDIR}/../../sbin/route
-CPPFLAGS+= -DRUMP_ACTION
+
+.if (${MKRUMP} != "no")
+.PATH:  ${.CURDIR}/../../lib/libc/gen
 RUMPSRCS+= sysctlbyname.c sysctlgetmibinfo.c sysctlnametomib.c
-RUMPSRCS+= if_indextoname.c getifaddrs.c getnameinfo.c
+LDADD.rump+=	-lrumpres
+DPADD.add+=	${LIBRUMPRES}
+CPPFLAGS+=  -DRUMP_ACTION
+.endif
+
 
 .if (${USE_INET6} != "no")
 CPPFLAGS+= -DINET6



CVS commit: src/usr.bin/netstat

2017-10-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Oct 10 19:31:10 UTC 2017

Modified Files:
src/usr.bin/netstat: Makefile

Log Message:
use librumpres


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/usr.bin/netstat/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2017-06-29 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Jun 29 07:15:27 UTC 2017

Modified Files:
src/usr.bin/netstat: fast_ipsec.c

Log Message:
Tweak outputs of netstat -s for IPsec

- Get rid of "Fast"
- Use ipsec and ipsec6 for titles to clarify protocol
- Indent outputs of sub protocols

Original outputs were organized like this:

(Fast) IPsec:
IPsec ah:
IPsec esp:
IPsec ipip:
IPsec ipcomp:
(Fast) IPsec:
IPsec ah:
IPsec esp:
IPsec ipip:
IPsec ipcomp:

New outputs are organized like this:

ipsec:
ah:
esp:
ipip:
ipcomp:
ipsec6:
ah:
esp:
ipip:
ipcomp:


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/netstat/fast_ipsec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/fast_ipsec.c
diff -u src/usr.bin/netstat/fast_ipsec.c:1.21 src/usr.bin/netstat/fast_ipsec.c:1.22
--- src/usr.bin/netstat/fast_ipsec.c:1.21	Thu Apr 13 16:38:32 2017
+++ src/usr.bin/netstat/fast_ipsec.c	Thu Jun 29 07:15:27 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fast_ipsec.c,v 1.21 2017/04/13 16:38:32 christos Exp $ */
+/*	$NetBSD: fast_ipsec.c,v 1.22 2017/06/29 07:15:27 ozaki-r Exp $ */
 /* 	$FreeBSD: src/tools/tools/crypto/ipsecstats.c,v 1.1.4.1 2003/06/03 00:13:13 sam Exp $ */
 
 /*-
@@ -33,7 +33,7 @@
 #include 
 #ifndef lint
 #ifdef __NetBSD__
-__RCSID("$NetBSD: fast_ipsec.c,v 1.21 2017/04/13 16:38:32 christos Exp $");
+__RCSID("$NetBSD: fast_ipsec.c,v 1.22 2017/06/29 07:15:27 ozaki-r Exp $");
 #endif
 #endif /* not lint*/
 
@@ -145,7 +145,7 @@ fast_ipsec_stats(u_long off, const char 
 	if (status < 0 && errno != ENOMEM)
 		err(1, "net.inet.ipip.ipip_stats");
 
-	printf("(Fast) IPsec:\n");
+	printf("%s:\n", name);
 
 #define	STAT(x,fmt)	if ((x) || sflag <= 1) printf("\t%"PRIu64" " fmt "\n", x)
 	if (ipsecstats[IPSEC_STAT_IN_POLVIO]+ipsecstats[IPSEC_STAT_OUT_POLVIO])
@@ -160,10 +160,9 @@ fast_ipsec_stats(u_long off, const char 
 	STAT(ipsecstats[IPSEC_STAT_SPDCACHELOOKUP], "SPD cache lookups");
 	STAT(ipsecstats[IPSEC_STAT_SPDCACHEMISS], "SPD cache misses");
 #undef STAT
-	printf("\n");
 	
-	printf("IPsec ah:\n");
-#define	AHSTAT(x,fmt)	if ((x) || sflag <= 1) printf("\t%"PRIu64" ah " fmt "\n", x)
+	printf("\tah:\n");
+#define	AHSTAT(x,fmt)	if ((x) || sflag <= 1) printf("\t\t%"PRIu64" ah " fmt "\n", x)
 	AHSTAT(ahstats[AH_STAT_INPUT],   "input packets processed");
 	AHSTAT(ahstats[AH_STAT_OUTPUT],  "output packets processed");
 	AHSTAT(ahstats[AH_STAT_HDROPS],  "headers too short");
@@ -192,10 +191,9 @@ fast_ipsec_stats(u_long off, const char 
 	AHSTAT(ahstats[AH_STAT_IBYTES], "bytes received");
 	AHSTAT(ahstats[AH_STAT_OBYTES], "bytes transmitted");
 #undef AHSTAT
-	printf("\n");
 
-	printf("IPsec esp:\n");
-#define	ESPSTAT(x,fmt) if ((x) || sflag <= 1) printf("\t%"PRIu64" esp " fmt "\n", x)
+	printf("\tesp:\n");
+#define	ESPSTAT(x,fmt) if ((x) || sflag <= 1) printf("\t\t%"PRIu64" esp " fmt "\n", x)
 	ESPSTAT(espstats[ESP_STAT_INPUT],"input packets processed");
 	ESPSTAT(espstats[ESP_STAT_OUTPUT],"output packets processed");
 	ESPSTAT(espstats[ESP_STAT_HDROPS],"headers too short");
@@ -224,10 +222,10 @@ fast_ipsec_stats(u_long off, const char 
 	ESPSTAT(espstats[ESP_STAT_IBYTES], "bytes received");
 	ESPSTAT(espstats[ESP_STAT_OBYTES], "bytes transmitted");
 #undef ESPSTAT
-	printf("IPsec ipip:\n");
+	printf("\tipip:\n");
 
 #define	IPIPSTAT(x,fmt) \
-	if ((x) || sflag <= 1) printf("\t%"PRIu64" ipip " fmt "\n", x)
+	if ((x) || sflag <= 1) printf("\t\t%"PRIu64" ipip " fmt "\n", x)
 	IPIPSTAT(ipips[IPIP_STAT_IPACKETS],"total input packets");
 	IPIPSTAT(ipips[IPIP_STAT_OPACKETS],"total output packets");
 	IPIPSTAT(ipips[IPIP_STAT_HDROPS],"packets too short for header length");
@@ -240,9 +238,9 @@ fast_ipsec_stats(u_long off, const char 
 	IPIPSTAT(ipips[IPIP_STAT_OBYTES],"output bytes processed");
 #undef IPIPSTAT
 
-	printf("IPsec ipcomp:\n");
+	printf("\tipcomp:\n");
 #define	IPCOMP(x,fmt) \
-	if ((x) || sflag <= 1) printf("\t%"PRIu64" ipcomp " fmt "\n", x)
+	if ((x) || sflag <= 1) printf("\t\t%"PRIu64" ipcomp " fmt "\n", x)
 
 	IPCOMP(ipcs[IPCOMP_STAT_HDROPS],"packets too short for header length");
 	IPCOMP(ipcs[IPCOMP_STAT_NOPF],	"protocol family not supported");
@@ -260,7 +258,7 @@ fast_ipsec_stats(u_long off, const char 
 	IPCOMP(ipcs[IPCOMP_STAT_PDROPS],"packets blocked due to policy");
 	IPCOMP(ipcs[IPCOMP_STAT_CRYPTO],"failed crypto requests");
 
-	printf("\tIPcomp histogram:\n");
+	printf("\tipcomp histogram:\n");
 	for (i = 0; i < IPCOMP_ALG_MAX; i++)
 		if (ipcs[IPCOMP_STAT_HIST + i])
 			printf("\t\tIPcomp packets with %s: %"PRIu64"\n"



CVS commit: src/usr.bin/netstat

2017-06-29 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Jun 29 07:15:27 UTC 2017

Modified Files:
src/usr.bin/netstat: fast_ipsec.c

Log Message:
Tweak outputs of netstat -s for IPsec

- Get rid of "Fast"
- Use ipsec and ipsec6 for titles to clarify protocol
- Indent outputs of sub protocols

Original outputs were organized like this:

(Fast) IPsec:
IPsec ah:
IPsec esp:
IPsec ipip:
IPsec ipcomp:
(Fast) IPsec:
IPsec ah:
IPsec esp:
IPsec ipip:
IPsec ipcomp:

New outputs are organized like this:

ipsec:
ah:
esp:
ipip:
ipcomp:
ipsec6:
ah:
esp:
ipip:
ipcomp:


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/netstat/fast_ipsec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2017-01-21 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Jan 22 04:52:04 UTC 2017

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
re-do the previous to avoid malloc/free on the same size every iteration.

with this, or the previous, 'netstat -b 1' no longer leaks memory in
-current (or any older release using sysctl for this.)


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.92 src/usr.bin/netstat/if.c:1.93
--- src/usr.bin/netstat/if.c:1.92	Sun Jan 22 04:26:31 2017
+++ src/usr.bin/netstat/if.c	Sun Jan 22 04:52:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.92 2017/01/22 04:26:31 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.93 2017/01/22 04:52:04 mrg Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.92 2017/01/22 04:26:31 christos Exp $");
+__RCSID("$NetBSD: if.c,v 1.93 2017/01/22 04:52:04 mrg Exp $");
 #endif
 #endif /* not lint */
 
@@ -169,7 +169,9 @@ intpr_sysctl(void)
 {
 	struct if_msghdr *ifm;
 	int mib[6] = { CTL_NET, AF_ROUTE, 0, 0, NET_RT_IFLIST, 0 };
-	char *buf = NULL, *next, *lim, *cp;
+	static char *buf = NULL;
+	static size_t olen;
+	char *next, *lim, *cp;
 	struct rt_msghdr *rtm;
 	struct ifa_msghdr *ifam;
 	struct if_data *ifd = NULL;
@@ -183,8 +185,12 @@ intpr_sysctl(void)
 
 	if (prog_sysctl(mib, 6, NULL, , NULL, 0) == -1)
 		err(1, "sysctl");
-	if ((buf = malloc(len)) == NULL)
-		err(1, NULL);
+	if (len > olen) {
+		free(buf);
+		if ((buf = malloc(len)) == NULL)
+			err(1, NULL);
+		olen = len;
+	}
 	if (prog_sysctl(mib, 6, buf, , NULL, 0) == -1)
 		err(1, "sysctl");
 
@@ -269,7 +275,6 @@ intpr_sysctl(void)
 		printf("%-*.*s %-5" PRIu64 " ", n, n, name, ifd->ifi_mtu);
 		print_addr(ifindex, rti_info[rtax], rti_info, ifd, NULL);
 	}
-	free(buf);
 }
 
 union ifaddr_u {
@@ -1058,14 +1063,20 @@ fetchifs(void)
 	struct if_data *ifd = NULL;
 	struct sockaddr *sa, *rti_info[RTAX_MAX];
 	struct sockaddr_dl *sdl;
-	char *buf, *next, *lim;
+	static char *buf = NULL;
+	static size_t olen;
+	char *next, *lim;
 	char name[IFNAMSIZ];
 	size_t len;
 
 	if (prog_sysctl(mib, 6, NULL, , NULL, 0) == -1)
 		err(1, "sysctl");
-	if ((buf = malloc(len)) == NULL)
-		err(1, NULL);
+	if (len > olen) {
+		free(buf);
+		if ((buf = malloc(len)) == NULL)
+			err(1, NULL);
+		olen = len;
+	}
 	if (prog_sysctl(mib, 6, buf, , NULL, 0) == -1)
 		err(1, "sysctl");
 
@@ -1127,5 +1138,4 @@ fetchifs(void)
 		ip_cur.ift_co = ifd->ifi_collisions;
 		ip_cur.ift_dr = ifd->ifi_iqdrops;
 	}
-	free(buf);
 }



CVS commit: src/usr.bin/netstat

2017-01-21 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Jan 22 04:52:04 UTC 2017

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
re-do the previous to avoid malloc/free on the same size every iteration.

with this, or the previous, 'netstat -b 1' no longer leaks memory in
-current (or any older release using sysctl for this.)


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2017-01-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jan 22 04:26:31 UTC 2017

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
sprinkle free


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2017-01-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jan 22 04:26:31 UTC 2017

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
sprinkle free


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.91 src/usr.bin/netstat/if.c:1.92
--- src/usr.bin/netstat/if.c:1.91	Tue Jan 10 20:25:05 2017
+++ src/usr.bin/netstat/if.c	Sat Jan 21 23:26:31 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.91 2017/01/11 01:25:05 ozaki-r Exp $	*/
+/*	$NetBSD: if.c,v 1.92 2017/01/22 04:26:31 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.91 2017/01/11 01:25:05 ozaki-r Exp $");
+__RCSID("$NetBSD: if.c,v 1.92 2017/01/22 04:26:31 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -269,6 +269,7 @@ intpr_sysctl(void)
 		printf("%-*.*s %-5" PRIu64 " ", n, n, name, ifd->ifi_mtu);
 		print_addr(ifindex, rti_info[rtax], rti_info, ifd, NULL);
 	}
+	free(buf);
 }
 
 union ifaddr_u {
@@ -1126,4 +1127,5 @@ fetchifs(void)
 		ip_cur.ift_co = ifd->ifi_collisions;
 		ip_cur.ift_dr = ifd->ifi_iqdrops;
 	}
+	free(buf);
 }



CVS commit: src/usr.bin/netstat

2017-01-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 13 04:22:51 UTC 2017

Modified Files:
src/usr.bin/netstat: unix.c

Log Message:
use _KMEMUSER for 


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/netstat/unix.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2017-01-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 13 04:22:51 UTC 2017

Modified Files:
src/usr.bin/netstat: unix.c

Log Message:
use _KMEMUSER for 


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/netstat/unix.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/unix.c
diff -u src/usr.bin/netstat/unix.c:1.34 src/usr.bin/netstat/unix.c:1.35
--- src/usr.bin/netstat/unix.c:1.34	Tue Mar 20 16:34:58 2012
+++ src/usr.bin/netstat/unix.c	Thu Jan 12 23:22:51 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: unix.c,v 1.34 2012/03/20 20:34:58 matt Exp $	*/
+/*	$NetBSD: unix.c,v 1.35 2017/01/13 04:22:51 christos Exp $	*/
 
 /*-
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)unix.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: unix.c,v 1.34 2012/03/20 20:34:58 matt Exp $");
+__RCSID("$NetBSD: unix.c,v 1.35 2017/01/13 04:22:51 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -52,9 +52,9 @@ __RCSID("$NetBSD: unix.c,v 1.34 2012/03/
 #include 
 #include 
 #include 
-#define _KERNEL
+#define _KMEMUSER
 #include 
-#undef _KERNEL
+#undef _KMEMUSER
 
 #include 
 



CVS commit: src/usr.bin/netstat

2017-01-10 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jan 11 01:25:05 UTC 2017

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Fix showing multicast addresses of !IFF_UP interfaces

netstat appends '*' to the name of an interface without IFF_UP, so
if_nametoindex which is used in mc_print fails. mc_print needs just
an interface index so pass it instead of a tweaked interface name.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.90 src/usr.bin/netstat/if.c:1.91
--- src/usr.bin/netstat/if.c:1.90	Thu Nov 24 00:05:13 2016
+++ src/usr.bin/netstat/if.c	Wed Jan 11 01:25:05 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.90 2016/11/24 00:05:13 dholland Exp $	*/
+/*	$NetBSD: if.c,v 1.91 2017/01/11 01:25:05 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.90 2016/11/24 00:05:13 dholland Exp $");
+__RCSID("$NetBSD: if.c,v 1.91 2017/01/11 01:25:05 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -84,7 +84,7 @@ struct	iftot {
 };
 
 static void set_lines(void);
-static void print_addr(const char *, struct sockaddr *, struct sockaddr **,
+static void print_addr(const int, struct sockaddr *, struct sockaddr **,
 struct if_data *, struct ifnet *);
 static void sidewaysintpr(u_int, u_long);
 
@@ -179,6 +179,7 @@ intpr_sysctl(void)
 	size_t len;
 	int did = 1, rtax = 0, n;
 	char name[IFNAMSIZ + 1];	/* + 1 for `*' */
+	int ifindex = 0;
 
 	if (prog_sysctl(mib, 6, NULL, , NULL, 0) == -1)
 		err(1, "sysctl");
@@ -216,6 +217,8 @@ intpr_sysctl(void)
 			if (interface != 0 && strcmp(name, interface) != 0)
 continue;
 
+			ifindex = sdl->sdl_index;
+
 			/* mark inactive interfaces with a '*' */
 			cp = strchr(name, '\0');
 			if ((ifm->ifm_flags & IFF_UP) == 0)
@@ -264,7 +267,7 @@ intpr_sysctl(void)
 			n = 5;
 
 		printf("%-*.*s %-5" PRIu64 " ", n, n, name, ifd->ifi_mtu);
-		print_addr(name, rti_info[rtax], rti_info, ifd, NULL);
+		print_addr(ifindex, rti_info[rtax], rti_info, ifd, NULL);
 	}
 }
 
@@ -346,8 +349,8 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 			cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
 			CP();
 			sa = (struct sockaddr *)cp;
-			print_addr(name, sa, (void *), _data,
-			);
+			print_addr(ifnet.if_index, sa, (void *),
+			_data, );
 		}
 		ifaddraddr = (u_long)ifaddr.ifa.ifa_list.tqe_next;
 	}
@@ -355,16 +358,12 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 }
 
 static void
-mc_print(const char *ifname, const size_t ias, const char *oid, int *mcast_oids,
+mc_print(const int ifindex, const size_t ias, const char *oid, int *mcast_oids,
 void (*pr)(const void *))
 {
 	uint8_t *mcast_addrs, *p;
 	const size_t incr = 2 * ias + sizeof(uint32_t);
 	size_t len;
-	int ifindex;
-
-	if ((ifindex = if_nametoindex(ifname)) == 0)
-		warn("Interface %s not found", ifname);
 
 	if (mcast_oids[0] == 0) {
 		size_t oidlen = 4;
@@ -423,11 +422,11 @@ ia6_print(const struct in6_addr *ia)
 }
 
 static void
-mc6_print(const char *ifname)
+mc6_print(const int ifindex)
 {
 	static int mcast_oids[4];
 
-	mc_print(ifname, sizeof(struct in6_addr), "net.inet6.multicast",
+	mc_print(ifindex, sizeof(struct in6_addr), "net.inet6.multicast",
 	mcast_oids, (void (*)(const void *))ia6_print);
 }
 #endif
@@ -439,17 +438,17 @@ ia4_print(const struct in_addr *ia)
 }
 
 static void
-mc4_print(const char *ifname)
+mc4_print(const int ifindex)
 {
 	static int mcast_oids[4];
 
-	mc_print(ifname, sizeof(struct in_addr), "net.inet.multicast",
+	mc_print(ifindex, sizeof(struct in_addr), "net.inet.multicast",
 	mcast_oids, (void (*)(const void *))ia4_print);
 }
 
 static void
-print_addr(const char *name, struct sockaddr *sa, struct sockaddr **rtinfo,
-struct if_data *ifd, struct ifnet *ifnet)
+print_addr(const int ifindex, struct sockaddr *sa,
+struct sockaddr **rtinfo, struct if_data *ifd, struct ifnet *ifnet)
 {
 	char hexsep = '.';		/* for hexprint */
 	static const char hexfmt[] = "%02x%c";	/* for hexprint */
@@ -503,7 +502,7 @@ print_addr(const char *name, struct sock
 multiaddr = (u_long)inm.inm_list.le_next;
 			}
 		} else {
-			mc4_print(name);
+			mc4_print(ifindex);
 		}
 		break;
 #ifdef INET6
@@ -555,7 +554,7 @@ print_addr(const char *name, struct sock
 multiaddr = (u_long)inm.in6m_entry.le_next;
 			}
 		} else {
-			mc6_print(name);
+			mc6_print(ifindex);
 		}
 		break;
 #endif /*INET6*/



CVS commit: src/usr.bin/netstat

2017-01-10 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jan 11 01:25:05 UTC 2017

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Fix showing multicast addresses of !IFF_UP interfaces

netstat appends '*' to the name of an interface without IFF_UP, so
if_nametoindex which is used in mc_print fails. mc_print needs just
an interface index so pass it instead of a tweaked interface name.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2016-12-22 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Fri Dec 23 06:22:00 UTC 2016

Modified Files:
src/usr.bin/netstat: inet.c

Log Message:
in getpcblist_sysctl() if sysctlnametomib() fails, return NULL and
set *len = 0, rather than bailing.  now "netstat" doesn't give up
early on kernels without INET6.


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/usr.bin/netstat/inet.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/inet.c
diff -u src/usr.bin/netstat/inet.c:1.106 src/usr.bin/netstat/inet.c:1.107
--- src/usr.bin/netstat/inet.c:1.106	Sun Feb  8 15:09:45 2015
+++ src/usr.bin/netstat/inet.c	Fri Dec 23 06:22:00 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.106 2015/02/08 15:09:45 christos Exp $	*/
+/*	$NetBSD: inet.c,v 1.107 2016/12/23 06:22:00 mrg Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet.c,v 1.106 2015/02/08 15:09:45 christos Exp $");
+__RCSID("$NetBSD: inet.c,v 1.107 2016/12/23 06:22:00 mrg Exp $");
 #endif
 #endif /* not lint */
 
@@ -88,6 +88,8 @@ __RCSID("$NetBSD: inet.c,v 1.106 2015/02
 #include 
 #include 
 #include 
+#include 
+
 #include "netstat.h"
 #include "vtw.h"
 #include "prog_ops.h"
@@ -240,8 +242,14 @@ getpcblist_sysctl(const char *name, size
 		err(1, "asprintf");
 
 	/* get dynamic pcblist node */
-	if (sysctlnametomib(mibname, mib, ) == -1)
+	if (sysctlnametomib(mibname, mib, ) == -1) {
+		if (errno == ENOENT) {
+			*len = 0;
+			return NULL;
+		}
+			
 		err(1, "sysctlnametomib: %s", mibname);
+	}
 
 	free(mibname);
 



CVS commit: src/usr.bin/netstat

2016-12-22 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Fri Dec 23 06:22:00 UTC 2016

Modified Files:
src/usr.bin/netstat: inet.c

Log Message:
in getpcblist_sysctl() if sysctlnametomib() fails, return NULL and
set *len = 0, rather than bailing.  now "netstat" doesn't give up
early on kernels without INET6.


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/usr.bin/netstat/inet.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2016-12-17 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Dec 17 09:12:22 UTC 2016

Modified Files:
src/usr.bin/netstat: inet6.c

Log Message:
Print previously missing fields from a TCP6 PCB.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/usr.bin/netstat/inet6.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.68 src/usr.bin/netstat/inet6.c:1.69
--- src/usr.bin/netstat/inet6.c:1.68	Sun Feb  8 15:09:45 2015
+++ src/usr.bin/netstat/inet6.c	Sat Dec 17 09:12:22 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.68 2015/02/08 15:09:45 christos Exp $	*/
+/*	$NetBSD: inet6.c,v 1.69 2016/12/17 09:12:22 mlelstv Exp $	*/
 /*	BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp	*/
 
 /*
@@ -64,7 +64,7 @@
 #if 0
 static char sccsid[] = "@(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet6.c,v 1.68 2015/02/08 15:09:45 christos Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.69 2016/12/17 09:12:22 mlelstv Exp $");
 #endif
 #endif /* not lint */
 
@@ -1494,6 +1494,9 @@ tcp6_dump(u_long off, const char *name, 
 #ifdef TCP6
 	printf("peermaxseg %u, maxseg %u, force %d\n\n", mypcb.t_peermaxseg,
 	mypcb.t_maxseg, mypcb.t_force);
+#else
+printf("peermss %u, ourmss %u, segsz %u, segqlen %u\n\n",
+	tcpcb.t_peermss, tcpcb.t_ourmss, tcpcb.t_segsz, tcpcb.t_segqlen);
 #endif
 
 	printf("snd_una %u, snd_nxt %u, snd_up %u\n",
@@ -1511,8 +1514,11 @@ tcp6_dump(u_long off, const char *name, 
 	(unsigned long long)mypcb.snd_ssthresh);
 
 #ifdef TCP6
-	printf("idle %d, rtt %d, " mypcb.t_idle, mypcb.t_rtt)
+	printf("idle %d, rtt %d, " mypcb.t_idle, mypcb.t_rtt);
+#else
+	printf("rcvtime %u, rtttime %u, ", tcpcb.t_rcvtime, tcpcb.t_rtttime);
 #endif
+
 	printf("rtseq %u, srtt %d, rttvar %d, rttmin %d, "
 	"max_sndwnd %llu\n\n", mypcb.t_rtseq,
 	mypcb.t_srtt, mypcb.t_rttvar, mypcb.t_rttmin,



CVS commit: src/usr.bin/netstat

2016-12-17 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Dec 17 09:12:22 UTC 2016

Modified Files:
src/usr.bin/netstat: inet6.c

Log Message:
Print previously missing fields from a TCP6 PCB.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/usr.bin/netstat/inet6.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2016-11-23 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Nov 24 00:05:13 UTC 2016

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Fix "sidewaysintpr", the thing that prints interface statistics in a
loop, to use signals properly. There are two copies of this code; one
uses kvm and the other uses sysctls. One copy had been updated to use
sigset_t and sigsuspend; the other was using vintage sigpause(). Sync
up the code so both use sigpause. Also, use sig_atomic_t, and block
SIGALRM when not waiting for it to avoid a small and unlikely but real
race.

Since the non-modernized copy of the code *had* for some been
modernized to use setitimer instead of just alarm(), propagate that
change to the other copy.

These copies could share more logic than they do.


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2016-11-23 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Nov 24 00:05:13 UTC 2016

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
Fix "sidewaysintpr", the thing that prints interface statistics in a
loop, to use signals properly. There are two copies of this code; one
uses kvm and the other uses sysctls. One copy had been updated to use
sigset_t and sigsuspend; the other was using vintage sigpause(). Sync
up the code so both use sigpause. Also, use sig_atomic_t, and block
SIGALRM when not waiting for it to avoid a small and unlikely but real
race.

Since the non-modernized copy of the code *had* for some been
modernized to use setitimer instead of just alarm(), propagate that
change to the other copy.

These copies could share more logic than they do.


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.89 src/usr.bin/netstat/if.c:1.90
--- src/usr.bin/netstat/if.c:1.89	Thu Jul 14 20:38:20 2016
+++ src/usr.bin/netstat/if.c	Thu Nov 24 00:05:13 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.89 2016/07/14 20:38:20 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.90 2016/11/24 00:05:13 dholland Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.89 2016/07/14 20:38:20 christos Exp $");
+__RCSID("$NetBSD: if.c,v 1.90 2016/11/24 00:05:13 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -100,7 +100,7 @@ static void intpr_sysctl(void);
 static void intpr_kvm(u_long, void (*)(const char *));
 
 struct iftot iftot[MAXIF], ip_cur, ip_old, sum_cur, sum_old;
-bool	signalled;			/* set if alarm goes off "early" */
+static sig_atomic_t signalled;		/* set when alarm goes off */
 
 static unsigned redraw_lines = 21;
 
@@ -712,7 +712,9 @@ iftot_print_sum(struct iftot *cur, struc
 __dead static void
 sidewaysintpr_sysctl(unsigned interval)
 {
+	struct itimerval it;
 	sigset_t emptyset;
+	sigset_t noalrm;
 	unsigned line;
 
 	set_lines();
@@ -724,9 +726,18 @@ sidewaysintpr_sysctl(unsigned interval)
 		exit(1);
 	}
 
-	(void)signal(SIGALRM, catchalarm);
+	sigemptyset();
+	sigemptyset();
+	sigaddset(, SIGALRM);
+	sigprocmask(SIG_SETMASK, , NULL);
+
 	signalled = 0;
-	(void)alarm(interval);
+	(void)signal(SIGALRM, catchalarm);
+
+	it.it_interval.tv_sec = it.it_value.tv_sec = interval;
+	it.it_interval.tv_usec = it.it_value.tv_usec = 0;
+	setitimer(ITIMER_REAL, , NULL);
+
 banner:
 	iftot_banner(_cur);
 
@@ -749,11 +760,10 @@ loop:
 	putchar('\n');
 	fflush(stdout);
 	line++;
-	sigemptyset();
-	if (!signalled)
+	if (signalled == 0) {
 		sigsuspend();
+	}
 	signalled = 0;
-	(void)alarm(interval);
 	if (line == redraw_lines)
 		goto banner;
 	goto loop;
@@ -764,13 +774,14 @@ static void
 sidewaysintpr_kvm(unsigned interval, u_long off)
 {
 	struct itimerval it;
+	sigset_t emptyset;
+	sigset_t noalrm;
 	struct ifnet ifnet;
 	u_long firstifnet;
 	struct iftot *ip, *total;
 	unsigned line;
 	struct iftot *lastif, *sum, *interesting;
 	struct ifnet_head ifhead;	/* TAILQ_HEAD */
-	int oldmask;
 
 	set_lines();
 
@@ -806,8 +817,13 @@ sidewaysintpr_kvm(unsigned interval, u_l
 	}
 	lastif = ip;
 
+	sigemptyset();
+	sigemptyset();
+	sigaddset(, SIGALRM);
+	sigprocmask(SIG_SETMASK, , NULL);
+
+	signalled = 0;
 	(void)signal(SIGALRM, catchalarm);
-	signalled = false;
 
 	it.it_interval.tv_sec = it.it_value.tv_sec = interval;
 	it.it_interval.tv_usec = it.it_value.tv_usec = 0;
@@ -980,12 +996,10 @@ loop:
 	putchar('\n');
 	fflush(stdout);
 	line++;
-	oldmask = sigblock(sigmask(SIGALRM));
-	if (! signalled) {
-		sigpause(0);
+	if (signalled == 0) {
+		sigsuspend();
 	}
-	sigsetmask(oldmask);
-	signalled = false;
+	signalled = 0;
 	if (line == redraw_lines)
 		goto banner;
 	goto loop;



CVS commit: src/usr.bin/netstat

2016-07-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jul 14 20:38:20 UTC 2016

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
more XXX removal.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.88 src/usr.bin/netstat/if.c:1.89
--- src/usr.bin/netstat/if.c:1.88	Thu Jul 14 16:34:36 2016
+++ src/usr.bin/netstat/if.c	Thu Jul 14 16:38:20 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.88 2016/07/14 20:34:36 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.89 2016/07/14 20:38:20 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.88 2016/07/14 20:34:36 christos Exp $");
+__RCSID("$NetBSD: if.c,v 1.89 2016/07/14 20:38:20 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -80,7 +80,7 @@ struct	iftot {
 	u_quad_t ift_ob;		/* output bytes */
 	u_quad_t ift_oe;		/* output errors */
 	u_quad_t ift_co;		/* collisions */
-	int ift_dr;			/* drops */
+	u_quad_t ift_dr;		/* drops */
 };
 
 static void set_lines(void);
@@ -687,7 +687,7 @@ iftot_print(struct iftot *cur, struct if
 		cur->ift_oe - old->ift_oe,
 		cur->ift_co - old->ift_co);
 	if (dflag)
-		printf(" %5u", cur->ift_dr - old->ift_dr);
+		printf(" %5" PRIu64, cur->ift_dr - old->ift_dr);
 }
 
 static void
@@ -706,7 +706,7 @@ iftot_print_sum(struct iftot *cur, struc
 		cur->ift_co - old->ift_co);
 
 	if (dflag)
-		printf(" %5u", cur->ift_dr - old->ift_dr);
+		printf(" %5" PRIu64, cur->ift_dr - old->ift_dr);
 }
 
 __dead static void
@@ -917,9 +917,8 @@ loop:
 	(ifnet.if_collisions - ip->ift_co));
 			}
 			if (dflag)
-printf(" %5llu",
-(unsigned long long)
-	(ifnet.if_snd.ifq_drops - ip->ift_dr));
+printf(" %5" PRIu64,
+	ifnet.if_snd.ifq_drops - ip->ift_dr);
 		}
 		ip->ift_ip = ifnet.if_ipackets;
 		ip->ift_ib = ifnet.if_ibytes;
@@ -1088,8 +1087,7 @@ fetchifs(void)
 ip_cur.ift_ob = ifd->ifi_obytes;
 ip_cur.ift_oe = ifd->ifi_oerrors;
 ip_cur.ift_co = ifd->ifi_collisions;
-ip_cur.ift_dr = 0;
-/* XXX-elad ifnet.if_snd.ifq_drops */
+ip_cur.ift_dr = ifd->ifi_iqdrops;
 			}
 
 			sum_cur.ift_ip += ifd->ifi_ipackets;
@@ -1099,7 +1097,7 @@ fetchifs(void)
 			sum_cur.ift_ob += ifd->ifi_obytes;
 			sum_cur.ift_oe += ifd->ifi_oerrors;
 			sum_cur.ift_co += ifd->ifi_collisions;
-			sum_cur.ift_dr += 0; /* XXX-elad ifnet.if_snd.ifq_drops */
+			sum_cur.ift_dr += ifd->ifi_iqdrops;
 			break;
 		}
 	}
@@ -1113,7 +,6 @@ fetchifs(void)
 		ip_cur.ift_ob = ifd->ifi_obytes;
 		ip_cur.ift_oe = ifd->ifi_oerrors;
 		ip_cur.ift_co = ifd->ifi_collisions;
-		ip_cur.ift_dr = 0;
-		/* XXX-elad ifnet.if_snd.ifq_drops */
+		ip_cur.ift_dr = ifd->ifi_iqdrops;
 	}
 }



CVS commit: src/usr.bin/netstat

2016-07-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jul 14 20:38:20 UTC 2016

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
more XXX removal.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2016-07-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jul 14 20:34:36 UTC 2016

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
XXX: removal


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.87 src/usr.bin/netstat/if.c:1.88
--- src/usr.bin/netstat/if.c:1.87	Thu Jul 14 15:39:41 2016
+++ src/usr.bin/netstat/if.c	Thu Jul 14 16:34:36 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.87 2016/07/14 19:39:41 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.88 2016/07/14 20:34:36 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.87 2016/07/14 19:39:41 christos Exp $");
+__RCSID("$NetBSD: if.c,v 1.88 2016/07/14 20:34:36 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -227,10 +227,8 @@ intpr_sysctl(void)
 ifd->ifi_ipackets + ifd->ifi_ierrors +
 ifd->ifi_opackets + ifd->ifi_oerrors +
 ifd->ifi_collisions;
-if (tflag)
-	total += 0; // XXX-elad ifnet.if_timer;
 if (dflag)
-	total += 0; // XXX-elad ifnet.if_snd.ifq_drops;
+	total += ifd->ifi_iqdrops;
 if (total == 0)
 	continue;
 			}
@@ -624,7 +622,9 @@ print_addr(const char *name, struct sock
 	if (tflag)
 		printf(" %4d", ifnet ? ifnet->if_timer : 0);
 	if (dflag)
-		printf(" %5d", ifnet ? ifnet->if_snd.ifq_drops : 0);
+		printf(" %5lld", ifnet ?
+		(unsigned long long)ifnet->if_snd.ifq_drops :
+		ifd->ifi_iqdrops);
 	putchar('\n');
 }
 
@@ -687,9 +687,7 @@ iftot_print(struct iftot *cur, struct if
 		cur->ift_oe - old->ift_oe,
 		cur->ift_co - old->ift_co);
 	if (dflag)
-		printf(" %5llu",
-		/* XXX ifnet.if_snd.ifq_drops - ip->ift_dr); */
-		0LL);
+		printf(" %5u", cur->ift_dr - old->ift_dr);
 }
 
 static void
@@ -708,7 +706,7 @@ iftot_print_sum(struct iftot *cur, struc
 		cur->ift_co - old->ift_co);
 
 	if (dflag)
-		printf(" %5llu", (unsigned long long)(cur->ift_dr - old->ift_dr));
+		printf(" %5u", cur->ift_dr - old->ift_dr);
 }
 
 __dead static void



CVS commit: src/usr.bin/netstat

2016-07-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jul 14 20:34:36 UTC 2016

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
XXX: removal


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2016-07-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jul 14 20:13:10 UTC 2016

Modified Files:
src/usr.bin/netstat: main.c

Log Message:
remove soft interrupt queues that don't exist anymore.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/usr.bin/netstat/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/main.c
diff -u src/usr.bin/netstat/main.c:1.98 src/usr.bin/netstat/main.c:1.99
--- src/usr.bin/netstat/main.c:1.98	Thu Jul 14 15:39:41 2016
+++ src/usr.bin/netstat/main.c	Thu Jul 14 16:13:10 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.98 2016/07/14 19:39:41 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.99 2016/07/14 20:13:10 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = "from: @(#)main.c	8.4 (Berkeley) 3/1/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.98 2016/07/14 19:39:41 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.99 2016/07/14 20:13:10 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -146,35 +146,23 @@ struct nlist nl[] = {
 	{ "_rip6stat", 0, 0, 0, 0 },	/* not available via kvm */
 #define	N_ARPINTRQ	38
 	{ "_arpintrq", 0, 0, 0, 0 },
-#define	N_IPINTRQ	39
-	{ "_ipintrq", 0, 0, 0, 0 },
-#define	N_IP6INTRQ	40
-	{ "_ip6intrq", 0, 0, 0, 0 },
-#define	N_ATINTRQ1	41
+#define	N_ATINTRQ1	39
 	{ "_atintrq1", 0, 0, 0, 0 },
-#define	N_ATINTRQ2	42
+#define	N_ATINTRQ2	40
 	{ "_atintrq2", 0, 0, 0, 0 },
-#define	N_NSINTRQ	43
-	{ "_nsintrq", 0, 0, 0, 0 },
-#define	N_LLCINTRQ	44
-	{ "_llcintrq", 0, 0, 0, 0 },
-#define	N_HDINTRQ	45
-	{ "_hdintrq", 0, 0, 0, 0 },
-#define	N_NATMINTRQ	46
+#define	N_NATMINTRQ	41
 	{ "_natmintrq", 0, 0, 0, 0 },
-#define	N_PPPOEDISCINQ	47
+#define	N_PPPOEDISCINQ	42
 	{ "_ppoediscinq", 0, 0, 0, 0 },
-#define	N_PPPOEINQ	48
+#define	N_PPPOEINQ	43
 	{ "_ppoeinq", 0, 0, 0, 0 },
-#define	N_PKINTRQ	49
-	{ "_pkintrq", 0, 0, 0, 0 },
-#define	N_HARDCLOCK_TICKS 50
+#define	N_HARDCLOCK_TICKS 44
 	{ "_hardclock_ticks", 0, 0, 0, 0 },
-#define N_PIMSTAT	51
+#define N_PIMSTAT	45
 	{ "_pimstat", 0, 0, 0, 0 },
-#define N_CARPSTAT	52
+#define N_CARPSTAT	46
 	{ "_carpstats", 0, 0, 0, 0 },	/* not available via kvm */
-#define N_PFSYNCSTAT	53
+#define N_PFSYNCSTAT	47
 	{ "_pfsyncstats", 0, 0, 0, 0},  /* not available via kvm */
 	{ "", 0, 0, 0, 0 },
 };
@@ -288,16 +276,11 @@ const struct softintrq {
 	int siq_index;
 } softintrq[] = {
 	{ "arpintrq", N_ARPINTRQ },
-	{ "ipintrq", N_IPINTRQ },
-	{ "ip6intrq", N_IP6INTRQ },
 	{ "atintrq1", N_ATINTRQ1 },
 	{ "atintrq2", N_ATINTRQ2 },
-	{ "llcintrq", N_LLCINTRQ },
-	{ "hdintrq", N_HDINTRQ },
 	{ "natmintrq", N_NATMINTRQ },
 	{ "ppoediscinq", N_PPPOEDISCINQ },
 	{ "ppoeinq", N_PPPOEINQ },
-	{ "pkintrq", N_PKINTRQ },
 	{ NULL, -1 },
 };
 



CVS commit: src/usr.bin/netstat

2016-07-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jul 14 20:13:10 UTC 2016

Modified Files:
src/usr.bin/netstat: main.c

Log Message:
remove soft interrupt queues that don't exist anymore.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/usr.bin/netstat/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2016-07-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jul 14 19:39:41 UTC 2016

Modified Files:
src/usr.bin/netstat: if.c main.c

Log Message:
remove __P


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.97 -r1.98 src/usr.bin/netstat/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2016-07-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jul 14 19:39:41 UTC 2016

Modified Files:
src/usr.bin/netstat: if.c main.c

Log Message:
remove __P


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/netstat/if.c
cvs rdiff -u -r1.97 -r1.98 src/usr.bin/netstat/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.86 src/usr.bin/netstat/if.c:1.87
--- src/usr.bin/netstat/if.c:1.86	Thu Jul 14 14:58:26 2016
+++ src/usr.bin/netstat/if.c	Thu Jul 14 15:39:41 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.86 2016/07/14 18:58:26 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.87 2016/07/14 19:39:41 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.86 2016/07/14 18:58:26 christos Exp $");
+__RCSID("$NetBSD: if.c,v 1.87 2016/07/14 19:39:41 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -92,7 +92,7 @@ static void iftot_banner(struct iftot *)
 static void iftot_print_sum(struct iftot *, struct iftot *);
 static void iftot_print(struct iftot *, struct iftot *);
 
-static void catchalarm __P((int));
+static void catchalarm(int);
 static void get_rtaddrs(int, struct sockaddr *, struct sockaddr **);
 static void fetchifs(void);
 

Index: src/usr.bin/netstat/main.c
diff -u src/usr.bin/netstat/main.c:1.97 src/usr.bin/netstat/main.c:1.98
--- src/usr.bin/netstat/main.c:1.97	Thu Jul 14 14:19:11 2016
+++ src/usr.bin/netstat/main.c	Thu Jul 14 15:39:41 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.97 2016/07/14 18:19:11 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.98 2016/07/14 19:39:41 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = "from: @(#)main.c	8.4 (Berkeley) 3/1/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.97 2016/07/14 18:19:11 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.98 2016/07/14 19:39:41 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -184,13 +184,13 @@ struct protox {
 	u_char	pr_sindex;		/* index into nlist of stat block */
 	u_char	pr_wanted;		/* 1 if wanted, 0 otherwise */
 	void	(*pr_cblocks)		/* control blocks printing routine */
-			__P((u_long, const char *));
+			(u_long, const char *);
 	void	(*pr_stats)		/* statistics printing routine */
-			__P((u_long, const char *));
+			(u_long, const char *);
 	void	(*pr_istats)
-			__P((const char *));	/* per/if statistics printing routine */
+			(const char *);	/* per/if statistics printing routine */
 	void	(*pr_dump)		/* PCB state dump routine */
-			__P((u_long, const char *, u_long));
+			(u_long, const char *, u_long);
 	const char *pr_name;		/* well-known name */
 } protox[] = {
 	{ N_TCBTABLE,	N_TCPSTAT,	1,	protopr,
@@ -301,12 +301,11 @@ const struct softintrq {
 	{ NULL, -1 },
 };
 
-int main __P((int, char *[]));
-static void printproto __P((struct protox *, const char *));
-static void print_softintrq __P((void));
+static void printproto(struct protox *, const char *);
+static void print_softintrq(void);
 __dead static void usage(void);
-static struct protox *name2protox __P((const char *));
-static struct protox *knownname __P((const char *));
+static struct protox *name2protox(const char *);
+static struct protox *knownname(const char *);
 static void prepare(const char *, const char *, struct protox *tp);
 static kvm_t *prepare_kvmd(const char *, const char *, char *);
 
@@ -723,7 +722,7 @@ main(int argc, char *argv[])
 static void
 printproto(struct protox *tp, const char *name)
 {
-	void (*pr) __P((u_long, const char *));
+	void (*pr)(u_long, const char *);
 	u_long off;
 
 	if (sflag) {



CVS commit: src/usr.bin/netstat

2016-07-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jul 14 18:58:26 UTC 2016

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
dedup


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2016-07-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jul 14 18:58:26 UTC 2016

Modified Files:
src/usr.bin/netstat: if.c

Log Message:
dedup


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/usr.bin/netstat/if.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/if.c
diff -u src/usr.bin/netstat/if.c:1.85 src/usr.bin/netstat/if.c:1.86
--- src/usr.bin/netstat/if.c:1.85	Thu Jul 14 14:19:11 2016
+++ src/usr.bin/netstat/if.c	Thu Jul 14 14:58:26 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.85 2016/07/14 18:19:11 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.86 2016/07/14 18:58:26 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c	8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.85 2016/07/14 18:19:11 christos Exp $");
+__RCSID("$NetBSD: if.c,v 1.86 2016/07/14 18:58:26 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -357,69 +357,42 @@ intpr_kvm(u_long ifnetaddr, void (*pfunc
 }
 
 static void
-ia6_print(struct in6_addr *ia)
+mc_print(const char *ifname, const size_t ias, const char *oid, int *mcast_oids,
+void (*pr)(const void *))
 {
-	struct sockaddr_in6 as6;
-	char hbuf[NI_MAXHOST];		/* for getnameinfo() */
-	int n;
-
-	memset(, 0, sizeof(as6));
-	as6.sin6_len = sizeof(struct sockaddr_in6);
-	as6.sin6_family = AF_INET6;
-	as6.sin6_addr = *ia;
-	inet6_getscopeid(, INET6_IS_ADDR_MC_LINKLOCAL);
-	if (getnameinfo((struct sockaddr *), as6.sin6_len, hbuf,
-	sizeof(hbuf), NULL, 0, NI_NUMERICHOST) != 0) {
-		strlcpy(hbuf, "??", sizeof(hbuf));
-	}
-	if (vflag)
-		n = strlen(hbuf) < 17 ? 17 : strlen(hbuf);
-	else
-		n = 17;
-	printf("\n%25s %-*.*s ", "", n, n, hbuf);
-}
-
-static void
-mc6_print(const char *ifname)
-{
-	static const size_t incr =
-	2 * sizeof(struct in6_addr) + sizeof(uint32_t);
-	static int mcast_oids[4];
-	static int oifindex = -1;
 	uint8_t *mcast_addrs, *p;
+	const size_t incr = 2 * ias + sizeof(uint32_t);
 	size_t len;
 	int ifindex;
 
 	if ((ifindex = if_nametoindex(ifname)) == 0)
 		warn("Interface %s not found", ifname);
 
-	if (ifindex == oifindex)
-		return;
-	oifindex = ifindex;
-
 	if (mcast_oids[0] == 0) {
-		size_t oidlen = __arraycount(mcast_oids);
-		if (sysctlnametomib("net.inet6.multicast", mcast_oids,
-		) == -1) {
-			warnx("net.inet6.multicast not found");
+		size_t oidlen = 4;
+		if (sysctlnametomib(oid, mcast_oids, ) == -1) {
+			warnx("'%s' not found", oid);
 			return;
 		}
 		if (oidlen != 3) {
-			warnx("Wrong OID path for net.inet6.multicast");
+			warnx("Wrong OID path for '%s'", oid);
 			return;
 		}
 	}
+
+	if (mcast_oids[3] == ifindex)
+		return;
 	mcast_oids[3] = ifindex;
 
 	mcast_addrs = asysctl(mcast_oids, 4, );
 	if (mcast_addrs == NULL && len != 0) {
-		warn("failed to read net.inet6.multicast");
+		warn("failed to read '%s'", oid);
 		return;
 	}
 	if (len) {
 		p = mcast_addrs;
 		while (len >= incr) {
-			ia6_print((void *)(p + sizeof(struct in6_addr)));
+			(*pr)((p + ias));
 			p += incr;
 			len -= incr;
 		}
@@ -427,58 +400,53 @@ mc6_print(const char *ifname)
 	free(mcast_addrs);
 }
 
+#ifdef INET6
 static void
-ia4_print(const struct in_addr *ia)
+ia6_print(const struct in6_addr *ia)
 {
-	printf("\n%25s %-17.17s ", "", routename4(ia->s_addr, nflag));
+	struct sockaddr_in6 as6;
+	char hbuf[NI_MAXHOST];		/* for getnameinfo() */
+	int n;
+
+	memset(, 0, sizeof(as6));
+	as6.sin6_len = sizeof(struct sockaddr_in6);
+	as6.sin6_family = AF_INET6;
+	as6.sin6_addr = *ia;
+	inet6_getscopeid(, INET6_IS_ADDR_MC_LINKLOCAL);
+	if (getnameinfo((struct sockaddr *), as6.sin6_len, hbuf,
+	sizeof(hbuf), NULL, 0, NI_NUMERICHOST) != 0) {
+		strlcpy(hbuf, "??", sizeof(hbuf));
+	}
+	if (vflag)
+		n = strlen(hbuf) < 17 ? 17 : strlen(hbuf);
+	else
+		n = 17;
+	printf("\n%25s %-*.*s ", "", n, n, hbuf);
 }
 
 static void
-mc4_print(const char *ifname)
+mc6_print(const char *ifname)
 {
-	static const size_t incr =
-	2 * sizeof(struct in_addr) + sizeof(uint32_t);
 	static int mcast_oids[4];
-	static int oifindex = -1;
-	uint8_t *mcast_addrs, *p;
-	size_t len;
-	int ifindex;
 
-	if ((ifindex = if_nametoindex(ifname)) == 0)
-		warn("Interface %s not found", ifname);
+	mc_print(ifname, sizeof(struct in6_addr), "net.inet6.multicast",
+	mcast_oids, (void (*)(const void *))ia6_print);
+}
+#endif
 
-	if (ifindex == oifindex)
-		return;
-	oifindex = ifindex;
+static void
+ia4_print(const struct in_addr *ia)
+{
+	printf("\n%25s %-17.17s ", "", routename4(ia->s_addr, nflag));
+}
 
-	if (mcast_oids[0] == 0) {
-		size_t oidlen = __arraycount(mcast_oids);
-		if (sysctlnametomib("net.inet.multicast", mcast_oids,
-		) == -1) {
-			warnx("net.inet.multicast not found");
-			return;
-		}
-		if (oidlen != 3) {
-			warnx("Wrong OID path for net.inet.multicast");
-			return;
-		}
-	}
-	mcast_oids[3] = ifindex;
+static void
+mc4_print(const char *ifname)

  1   2   3   >