Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/netstat Introduce -q flag to print some information ...



details:   https://anonhg.NetBSD.org/src/rev/7a4569e0d684
branches:  trunk
changeset: 533516:7a4569e0d684
user:      enami <enami%NetBSD.org@localhost>
date:      Wed Jul 03 01:42:59 2002 +0000

description:
Introduce -q flag to print some information (like number of packets dropped
due to queue full) about software interrupt queues such as ipintrq.

diffstat:

 usr.bin/netstat/main.c    |  80 ++++++++++++++++++++++++++++++++++++++++++++--
 usr.bin/netstat/netstat.1 |   6 ++-
 usr.bin/netstat/netstat.h |   3 +-
 3 files changed, 81 insertions(+), 8 deletions(-)

diffs (196 lines):

diff -r 4e10fe0f92e0 -r 7a4569e0d684 usr.bin/netstat/main.c
--- a/usr.bin/netstat/main.c    Wed Jul 03 01:27:23 2002 +0000
+++ b/usr.bin/netstat/main.c    Wed Jul 03 01:42:59 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.36 2002/07/02 21:34:18 soren Exp $  */
+/*     $NetBSD: main.c,v 1.37 2002/07/03 01:42:59 enami Exp $  */
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -43,7 +43,7 @@
 #if 0
 static char sccsid[] = "from: @(#)main.c       8.4 (Berkeley) 3/1/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.36 2002/07/02 21:34:18 soren Exp $");
+__RCSID("$NetBSD: main.c,v 1.37 2002/07/03 01:42:59 enami Exp $");
 #endif
 #endif /* not lint */
 
@@ -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.
@@ -639,6 +686,29 @@
 }
 
 /*
+ * 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);
+       }
+}
+
+/*
  * Read kernel memory, return 0 on success.
  */
 int
@@ -726,7 +796,7 @@
        (void)fprintf(stderr,
 "usage: %s [-Aan] [-f address_family] [-M core] [-N system]\n", progname);
        (void)fprintf(stderr,
-"       %s [-bdgiLmnrsSv] [-f address_family] [-M core] [-N system]\n", 
+"       %s [-bdgiLmnqrsSv] [-f address_family] [-M core] [-N system]\n", 
        progname);
        (void)fprintf(stderr,
 "       %s [-dn] [-I interface] [-M core] [-N system] [-w wait]\n", progname);
diff -r 4e10fe0f92e0 -r 7a4569e0d684 usr.bin/netstat/netstat.1
--- a/usr.bin/netstat/netstat.1 Wed Jul 03 01:27:23 2002 +0000
+++ b/usr.bin/netstat/netstat.1 Wed Jul 03 01:42:59 2002 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: netstat.1,v 1.34 2002/07/02 21:34:18 soren Exp $
+.\"    $NetBSD: netstat.1,v 1.35 2002/07/03 01:42:59 enami Exp $
 .\"
 .\" Copyright (c) 1983, 1990, 1992, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -46,7 +46,7 @@
 .Op Fl M Ar core
 .Op Fl N Ar system
 .Nm ""
-.Op Fl bdgiLmnrsSv
+.Op Fl bdgiLmnqrsSv
 .Op Fl f Ar address_family
 .Op Fl M Ar core
 .Op Fl N Ar system
@@ -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.
diff -r 4e10fe0f92e0 -r 7a4569e0d684 usr.bin/netstat/netstat.h
--- a/usr.bin/netstat/netstat.h Wed Jul 03 01:27:23 2002 +0000
+++ b/usr.bin/netstat/netstat.h Wed Jul 03 01:42:59 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netstat.h,v 1.24 2002/02/27 03:55:14 lukem Exp $       */
+/*     $NetBSD: netstat.h,v 1.25 2002/07/03 01:42:59 enami Exp $       */
 
 /*
  * Copyright (c) 1992, 1993
@@ -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 */



Home | Main Index | Thread Index | Old Index