Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/netstat make netstat IPv6-ready.



details:   https://anonhg.NetBSD.org/src/rev/4674285d0a6c
branches:  trunk
changeset: 474211:4674285d0a6c
user:      itojun <itojun%NetBSD.org@localhost>
date:      Thu Jul 01 18:40:35 1999 +0000

description:
make netstat IPv6-ready.

diffstat:

 usr.bin/netstat/Makefile  |     6 +-
 usr.bin/netstat/if.c      |    27 +-
 usr.bin/netstat/inet.c    |   113 ++++-
 usr.bin/netstat/inet6.c   |  1131 +++++++++++++++++++++++++++++++++++++++++++++
 usr.bin/netstat/main.c    |   114 ++++-
 usr.bin/netstat/mroute6.c |   278 +++++++++++
 usr.bin/netstat/netstat.1 |     3 +-
 usr.bin/netstat/netstat.h |    19 +-
 usr.bin/netstat/route.c   |   132 +++++-
 9 files changed, 1801 insertions(+), 22 deletions(-)

diffs (truncated from 2111 to 300 lines):

diff -r 54707f07849a -r 4674285d0a6c usr.bin/netstat/Makefile
--- a/usr.bin/netstat/Makefile  Thu Jul 01 18:28:55 1999 +0000
+++ b/usr.bin/netstat/Makefile  Thu Jul 01 18:40:35 1999 +0000
@@ -1,13 +1,15 @@
-#      $NetBSD: Makefile,v 1.14 1997/05/08 21:11:44 gwr Exp $
+#      $NetBSD: Makefile,v 1.15 1999/07/01 18:40:35 itojun Exp $
 #      from: @(#)Makefile      8.1 (Berkeley) 6/12/93
 
 PROG=  netstat
 SRCS=  atalk.c if.c inet.c iso.c main.c mbuf.c mroute.c ns.c route.c \
-       tp_astring.c unix.c
+       tp_astring.c unix.c mroute6.c
+SRCS+= inet6.c
 .PATH: ${.CURDIR}/../../sys/netiso
 BINGRP=        kmem
 BINMODE=2555
 LDADD= -lkvm
 DPADD= ${LIBKVM}
+CPPFLAGS+= -DINET6 -DIPSEC
 
 .include <bsd.prog.mk>
diff -r 54707f07849a -r 4674285d0a6c usr.bin/netstat/if.c
--- a/usr.bin/netstat/if.c      Thu Jul 01 18:28:55 1999 +0000
+++ b/usr.bin/netstat/if.c      Thu Jul 01 18:40:35 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.31 1999/03/14 22:28:05 mycroft Exp $  */
+/*     $NetBSD: if.c,v 1.32 1999/07/01 18:40:35 itojun Exp $   */
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c 8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.31 1999/03/14 22:28:05 mycroft Exp $");
+__RCSID("$NetBSD: if.c,v 1.32 1999/07/01 18:40:35 itojun Exp $");
 #endif
 #endif /* not lint */
 
@@ -70,6 +70,11 @@
 static void sidewaysintpr __P((u_int, u_long));
 static void catchalarm __P((int));
 
+#ifdef INET6
+char *netname6 __P((struct in6_addr *, struct in6_addr *));
+static char ntop_buf[INET6_ADDRSTRLEN];                /* for inet_ntop() */
+#endif
+
 /*
  * Print a description of the network interfaces.
  * NOTE: ifnetaddr is the location of the kernel global "ifnet",
@@ -84,6 +89,9 @@
        union {
                struct ifaddr ifa;
                struct in_ifaddr in;
+#ifdef INET6
+               struct in6_ifaddr in6;
+#endif /* INET6 */
                struct ns_ifaddr ns;
                struct iso_ifaddr iso;
        } ifaddr;
@@ -129,6 +137,9 @@
        ifaddraddr = 0;
        while (ifnetaddr || ifaddraddr) {
                struct sockaddr_in *sin;
+#ifdef INET6
+               struct sockaddr_in6 *sin6;
+#endif /* INET6 */
                char *cp;
                int n, m;
 
@@ -201,6 +212,18 @@
                                        }
                                }
                                break;
+#ifdef INET6
+                       case AF_INET6:
+                               sin6 = (struct sockaddr_in6 *)sa;
+                               printf("%-13.13s ",
+                                   netname6(&ifaddr.in6.ia_addr.sin6_addr,
+                                       &ifaddr.in6.ia_prefixmask.sin6_addr));
+                               printf("%-17.17s ",
+                                   (char *)inet_ntop(AF_INET6,
+                                       &sin6->sin6_addr,
+                                       ntop_buf, sizeof(ntop_buf)));
+                               break;
+#endif /*INET6*/
 #ifndef SMALL
                        case AF_APPLETALK:
                                printf("atalk:%-7.7s ",
diff -r 54707f07849a -r 4674285d0a6c usr.bin/netstat/inet.c
--- a/usr.bin/netstat/inet.c    Thu Jul 01 18:28:55 1999 +0000
+++ b/usr.bin/netstat/inet.c    Thu Jul 01 18:40:35 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: inet.c,v 1.36 1999/04/29 03:58:27 thorpej Exp $        */
+/*     $NetBSD: inet.c,v 1.37 1999/07/01 18:40:35 itojun Exp $ */
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c       8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet.c,v 1.36 1999/04/29 03:58:27 thorpej Exp $");
+__RCSID("$NetBSD: inet.c,v 1.37 1999/07/01 18:40:35 itojun Exp $");
 #endif
 #endif /* not lint */
 
@@ -55,6 +55,11 @@
 #include <netinet/ip.h>
 #include <netinet/in_pcb.h>
 #include <netinet/ip_icmp.h>
+
+#ifdef INET6
+#include <netinet/ip6.h>
+#endif
+
 #include <netinet/icmp_var.h>
 #include <netinet/igmp_var.h>
 #include <netinet/ip_var.h>
@@ -69,6 +74,9 @@
 #include <netinet/tcp_debug.h>
 #include <netinet/udp.h>
 #include <netinet/udp_var.h>
+#ifdef IPSEC
+#include <netinet6/ipsec.h>
+#endif
 
 #include <arpa/inet.h>
 #include <netdb.h>
@@ -490,6 +498,107 @@
 #undef py
 }
 
+#ifdef IPSEC
+static char *ipsec_ahnames[] = {
+       "none",
+       "hmac MD5",
+       "hmac SHA1",
+       "keyed MD5",
+       "keyed SHA1",
+       "null",
+};
+
+static char *ipsec_espnames[] = {
+       "none",
+       "DES CBC",
+       "3DES CBC",
+       "simple",
+       "blowfish CBC",
+       "CAST128 CBC",
+       "DES derived IV",
+};
+
+/*
+ * Dump IPSEC statistics structure.
+ */
+void
+ipsec_stats(off, name)
+       u_long off;
+       char *name;
+{
+       struct ipsecstat ipsecstat;
+       int first, proto;
+
+       if (off == 0)
+               return;
+       printf ("%s:\n", name);
+       kread(off, (char *)&ipsecstat, sizeof (ipsecstat));
+
+#define        p(f, m) if (ipsecstat.f || sflag <= 1) \
+    printf(m, ipsecstat.f, plural(ipsecstat.f))
+
+       p(in_success, "\t%lu inbound packet%s processed successfully\n");
+       p(in_polvio, "\t%lu inbound packet%s violated process security "
+               "policy\n");
+       p(in_nosa, "\t%lu inbound packet%s with no SA available\n");
+       p(in_inval, "\t%lu inbound packet%s failed processing due to EINVAL\n");
+       p(in_badspi, "\t%lu inbound packet%s failed getting SPI\n");
+       p(in_ahreplay, "\t%lu inbound packet%s failed on AH replay check\n");
+       p(in_espreplay, "\t%lu inbound packet%s failed on ESP replay check\n");
+       p(in_ahauthsucc, "\t%lu inbound packet%s considered authentic\n");
+       p(in_ahauthfail, "\t%lu inbound packet%s failed on authentication\n");
+       for (first = 1, proto = 0; proto < SADB_AALG_MAX; proto++) {
+               if (ipsecstat.in_ahhist[proto] <= 0)
+                       continue;
+               if (first) {
+                       printf("\tAH input histogram:\n");
+                       first = 0;
+               }
+               printf("\t\t%s: %lu\n", ipsec_ahnames[proto],
+                       ipsecstat.in_ahhist[proto]);
+       }
+       for (first = 1, proto = 0; proto < SADB_EALG_MAX; proto++) {
+               if (ipsecstat.in_esphist[proto] <= 0)
+                       continue;
+               if (first) {
+                       printf("\tESP input histogram:\n");
+                       first = 0;
+               }
+               printf("\t\t%s: %lu\n", ipsec_espnames[proto],
+                       ipsecstat.in_esphist[proto]);
+       }
+
+       p(out_success, "\t%lu outbound packet%s processed successfully\n");
+       p(out_polvio, "\t%lu outbound packet%s violated process security "
+               "policy\n");
+       p(out_nosa, "\t%lu outbound packet%s with no SA available\n");
+       p(out_inval, "\t%lu outbound packet%s failed processing due to "
+               "EINVAL\n");
+       p(out_noroute, "\t%lu outbound packet%s with no route\n");
+       for (first = 1, proto = 0; proto < SADB_AALG_MAX; proto++) {
+               if (ipsecstat.out_ahhist[proto] <= 0)
+                       continue;
+               if (first) {
+                       printf("\tAH output histogram:\n");
+                       first = 0;
+               }
+               printf("\t\t%s: %lu\n", ipsec_ahnames[proto],
+                       ipsecstat.out_ahhist[proto]);
+       }
+       for (first = 1, proto = 0; proto < SADB_EALG_MAX; proto++) {
+               if (ipsecstat.out_esphist[proto] <= 0)
+                       continue;
+               if (first) {
+                       printf("\tESP output histogram:\n");
+                       first = 0;
+               }
+               printf("\t\t%s: %lu\n", ipsec_espnames[proto],
+                       ipsecstat.out_esphist[proto]);
+       }
+#undef p
+}
+#endif /*IPSEC*/
+
 /*
  * Pretty print an Internet address (net address + port).
  * If the nflag was specified, use numbers instead of names.
diff -r 54707f07849a -r 4674285d0a6c usr.bin/netstat/inet6.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/netstat/inet6.c   Thu Jul 01 18:40:35 1999 +0000
@@ -0,0 +1,1131 @@
+/*     BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp   */
+/*
+ * Copyright (c) 1983, 1988, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)inet.c     8.4 (Berkeley) 4/20/94";
+#else
+__RCSID("$Id: inet6.c,v 1.1 1999/07/01 18:40:36 itojun Exp $");
+#endif
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/mbuf.h>
+#include <sys/protosw.h>
+
+#include <net/route.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <netinet/ip6.h>
+#include <netinet/icmp6.h>
+#include <netinet/in_systm.h>
+#ifndef TCP6
+#include <netinet/ip.h>
+#include <netinet/ip_var.h>



Home | Main Index | Thread Index | Old Index