Subject: small netstat changes
To: None <tech-net@netbsd.org>
From: enami tsugutomo <enami@sm.sony.co.jp>
List: tech-net
Date: 06/07/2002 11:30:25
Hi all.

IIRC, there is no way to see the number of packets dropped due to
softintr queue (like ipintrq) full, except examining using debugger.

So, I'd like to change netstat as follows.  It add new flag -q.

Commnets?

enami.
Index: main.c
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/netstat/main.c,v
retrieving revision 1.34
diff -u -r1.34 main.c
--- main.c	2001/10/18 09:26:16	1.34
+++ main.c	2002/06/07 02:25:58
@@ -52,6 +52,7 @@
 #include <sys/protosw.h>
 #include <sys/socket.h>
 
+#include <net/if.h>
 #include <netinet/in.h>
 
 #include <ctype.h>
@@ -181,6 +182,26 @@
 	{ "_arpstat" },
 #define N_RIP6STAT	55
 	{ "_rip6stat" },
+#define	N_ARPINTRQ	56
+	{ "_arpintrq" },
+#define	N_IPINTRQ	57
+	{ "_ipintrq" },
+#define	N_IP6INTRQ	58
+	{ "_ip6intrq" },
+#define	N_ATINTRQ1	59
+	{ "_atintrq1" },
+#define	N_ATINTRQ2	60
+	{ "_atintrq2" },
+#define	N_NSINTRQ	61
+	{ "_nsintrq" },
+#define	N_CLNLINTRQ	62
+	{ "_clnlintrq" },
+#define	N_LLCINTRQ	63
+	{ "_llcintrq" },
+#define	N_HDINTRQ	64
+	{ "_hdintrq" },
+#define	N_NATMINTRQ	65
+	{ "_natmintrq" },
 	{ "" },
 };
 
@@ -306,8 +327,26 @@
 #endif
 				 NULL };
 
+const struct softintrq {
+	const char *siq_name;
+	int siq_index;
+} softintrq[] = {
+	{ "arpintrq", N_ARPINTRQ },
+	{ "ipintrq", N_IPINTRQ },
+	{ "ip6intrq", N_IP6INTRQ },
+	{ "atintrq1", N_ATINTRQ1 },
+	{ "atintrq2", N_ATINTRQ2 },
+	{ "nsintrq", N_NSINTRQ },
+	{ "clnlintrq", N_CLNLINTRQ },
+	{ "llcintrq", N_LLCINTRQ },
+	{ "hdintrq", N_HDINTRQ },
+	{ "natmintrq", N_NATMINTRQ },
+	{ NULL, -1 },
+};
+
 int main __P((int, char *[]));
 static void printproto __P((struct protox *, char *));
+static void print_softintrq __P((void));
 static void usage __P((void));
 static struct protox *name2protox __P((char *));
 static struct protox *knownname __P((char *));
@@ -332,8 +371,9 @@
 	af = AF_UNSPEC;
 	pcbaddr = 0;
 
-	while ((ch = getopt(argc, argv, "Aabdf:ghI:LliM:mN:nP:p:rsStuvw:")) != -1)
-		switch(ch) {
+	while ((ch = getopt(argc, argv,
+	    "Aabdf:ghI:LliM:mN:nP:p:qrsStuvw:")) != -1)
+		switch (ch) {
 		case 'A':
 			Aflag = 1;
 			break;
@@ -411,6 +451,9 @@
 				    optarg);
 			pflag = 1;
 			break;
+		case 'q':
+			qflag = 1;
+			break;
 		case 'r':
 			rflag = 1;
 			break;
@@ -510,6 +553,10 @@
 			printf("%s: no stats routine\n", tp->pr_name);
 		exit(0);
 	}
+	if (qflag) {
+		print_softintrq();
+		exit(0);
+	}
 	/*
 	 * Keep file descriptors open to avoid overhead
 	 * of open/close on each call to get* routines.
@@ -636,6 +683,29 @@
 	}
 	if (pr != NULL && (off || af != AF_UNSPEC))
 		(*pr)(off, name);
+}
+
+/*
+ * Print softintrq status.
+ */
+void
+print_softintrq()
+{
+	struct ifqueue intrq, *ifq = &intrq;
+	const struct softintrq *siq;
+	u_long off;
+
+	for (siq = softintrq; siq->siq_name != NULL; siq++) {
+		off = nl[siq->siq_index].n_value;
+		if (off == 0)
+			continue;
+
+		kread(off, (char *)ifq, sizeof(*ifq));
+		printf("%s:\n", siq->siq_name);
+		printf("\tqueue length: %d\n", ifq->ifq_len);
+		printf("\tmaximum queue length: %d\n", ifq->ifq_maxlen);
+		printf("\tpackets dropped: %d\n", ifq->ifq_drops);
+	}
 }
 
 /*
Index: netstat.1
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/netstat/netstat.1,v
retrieving revision 1.33
diff -u -r1.33 netstat.1
--- netstat.1	2001/12/01 16:43:21	1.33
+++ netstat.1	2002/06/07 02:25:58
@@ -232,6 +232,8 @@
 The program will complain if
 .Ar protocol
 is unknown or if there is no statistics routine for it.
+.It Fl q
+Show software interrupt queue setting/statistics for all protocols.
 .It Fl s
 Show per-protocol statistics.
 If this option is repeated, counters with a value of zero are suppressed.
Index: netstat.h
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/netstat/netstat.h,v
retrieving revision 1.24
diff -u -r1.24 netstat.h
--- netstat.h	2002/02/27 03:55:14	1.24
+++ netstat.h	2002/06/07 02:25:58
@@ -52,6 +52,7 @@
 int	numeric_port;	/* show ports numerically */
 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	tflag;		/* show i/f watchdog timers */