Home | History | Annotate | Line # | Download | only in netstat
inet6.c revision 1.2
      1  1.2  itojun /*	$NetBSD: inet6.c,v 1.2 1999/07/06 13:18:46 itojun Exp $	*/
      2  1.2  itojun 
      3  1.1  itojun /*	BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp	*/
      4  1.1  itojun /*
      5  1.1  itojun  * Copyright (c) 1983, 1988, 1993
      6  1.1  itojun  *	The Regents of the University of California.  All rights reserved.
      7  1.1  itojun  *
      8  1.1  itojun  * Redistribution and use in source and binary forms, with or without
      9  1.1  itojun  * modification, are permitted provided that the following conditions
     10  1.1  itojun  * are met:
     11  1.1  itojun  * 1. Redistributions of source code must retain the above copyright
     12  1.1  itojun  *    notice, this list of conditions and the following disclaimer.
     13  1.1  itojun  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  itojun  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  itojun  *    documentation and/or other materials provided with the distribution.
     16  1.1  itojun  * 3. All advertising materials mentioning features or use of this software
     17  1.1  itojun  *    must display the following acknowledgement:
     18  1.1  itojun  *	This product includes software developed by the University of
     19  1.1  itojun  *	California, Berkeley and its contributors.
     20  1.1  itojun  * 4. Neither the name of the University nor the names of its contributors
     21  1.1  itojun  *    may be used to endorse or promote products derived from this software
     22  1.1  itojun  *    without specific prior written permission.
     23  1.1  itojun  *
     24  1.1  itojun  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  1.1  itojun  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  1.1  itojun  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  1.1  itojun  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  1.1  itojun  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  1.1  itojun  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  1.1  itojun  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  1.1  itojun  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  1.1  itojun  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  1.1  itojun  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  1.1  itojun  * SUCH DAMAGE.
     35  1.1  itojun  */
     36  1.1  itojun 
     37  1.1  itojun #include <sys/cdefs.h>
     38  1.1  itojun #ifndef lint
     39  1.1  itojun #if 0
     40  1.1  itojun static char sccsid[] = "@(#)inet.c	8.4 (Berkeley) 4/20/94";
     41  1.1  itojun #else
     42  1.2  itojun __RCSID("$NetBSD: inet6.c,v 1.2 1999/07/06 13:18:46 itojun Exp $");
     43  1.1  itojun #endif
     44  1.1  itojun #endif /* not lint */
     45  1.1  itojun 
     46  1.1  itojun #include <sys/param.h>
     47  1.1  itojun #include <sys/socket.h>
     48  1.1  itojun #include <sys/socketvar.h>
     49  1.1  itojun #include <sys/mbuf.h>
     50  1.1  itojun #include <sys/protosw.h>
     51  1.1  itojun 
     52  1.1  itojun #include <net/route.h>
     53  1.1  itojun #include <net/if.h>
     54  1.1  itojun #include <netinet/in.h>
     55  1.1  itojun #include <netinet/ip6.h>
     56  1.1  itojun #include <netinet/icmp6.h>
     57  1.1  itojun #include <netinet/in_systm.h>
     58  1.1  itojun #ifndef TCP6
     59  1.1  itojun #include <netinet/ip.h>
     60  1.1  itojun #include <netinet/ip_var.h>
     61  1.1  itojun #endif
     62  1.1  itojun #include <netinet6/in6_systm.h>
     63  1.1  itojun #include <netinet6/in6_pcb.h>
     64  1.1  itojun #include <netinet6/ip6_var.h>
     65  1.1  itojun #ifdef TCP6
     66  1.1  itojun #include <netinet6/tcp6.h>
     67  1.1  itojun #include <netinet6/tcp6_seq.h>
     68  1.1  itojun #define TCP6STATES
     69  1.1  itojun #include <netinet6/tcp6_fsm.h>
     70  1.1  itojun #define TCP6TIMERS
     71  1.1  itojun #include <netinet6/tcp6_timer.h>
     72  1.1  itojun #include <netinet6/tcp6_var.h>
     73  1.1  itojun #include <netinet6/tcp6_debug.h>
     74  1.1  itojun #else
     75  1.1  itojun #include <netinet/tcp.h>
     76  1.1  itojun #include <netinet/tcpip.h>
     77  1.1  itojun #include <netinet/tcp_seq.h>
     78  1.1  itojun /*#define TCPSTATES*/
     79  1.1  itojun #include <netinet/tcp_fsm.h>
     80  1.1  itojun extern char *tcpstates[];
     81  1.1  itojun /*#define	TCPTIMERS*/
     82  1.1  itojun #include <netinet/tcp_timer.h>
     83  1.1  itojun #include <netinet/tcp_var.h>
     84  1.1  itojun #include <netinet/tcp_debug.h>
     85  1.1  itojun #endif /*TCP6*/
     86  1.1  itojun #include <netinet6/udp6.h>
     87  1.1  itojun #include <netinet6/udp6_var.h>
     88  1.1  itojun #include <netinet6/pim6_var.h>
     89  1.1  itojun 
     90  1.1  itojun #include <arpa/inet.h>
     91  1.1  itojun #if 0
     92  1.1  itojun #include "gethostbyname2.h"
     93  1.1  itojun #endif
     94  1.1  itojun #include <netdb.h>
     95  1.1  itojun 
     96  1.1  itojun #include <stdio.h>
     97  1.1  itojun #include <string.h>
     98  1.1  itojun #include <unistd.h>
     99  1.1  itojun #include "netstat.h"
    100  1.1  itojun 
    101  1.1  itojun #ifdef INET6
    102  1.1  itojun 
    103  1.1  itojun struct	in6pcb in6pcb;
    104  1.1  itojun #ifdef TCP6
    105  1.1  itojun struct	tcp6cb tcp6cb;
    106  1.1  itojun #else
    107  1.1  itojun struct	tcpcb tcpcb;
    108  1.1  itojun #endif
    109  1.1  itojun struct	socket sockb;
    110  1.1  itojun 
    111  1.1  itojun char	*inet6name __P((struct in6_addr *));
    112  1.1  itojun void	inet6print __P((struct in6_addr *, int, char *));
    113  1.1  itojun 
    114  1.1  itojun static char ntop_buf[INET6_ADDRSTRLEN];
    115  1.1  itojun 
    116  1.1  itojun /*
    117  1.1  itojun  * Print a summary of connections related to an Internet
    118  1.1  itojun  * protocol.  For TCP, also give state of connection.
    119  1.1  itojun  * Listening processes (aflag) are suppressed unless the
    120  1.1  itojun  * -a (all) flag is specified.
    121  1.1  itojun  */
    122  1.1  itojun void
    123  1.1  itojun ip6protopr(off, name)
    124  1.1  itojun 	u_long off;
    125  1.1  itojun 	char *name;
    126  1.1  itojun {
    127  1.1  itojun 	struct in6pcb cb;
    128  1.1  itojun 	register struct in6pcb *prev, *next;
    129  1.1  itojun 	int istcp;
    130  1.1  itojun 	static int first = 1;
    131  1.1  itojun 
    132  1.1  itojun 	if (off == 0)
    133  1.1  itojun 		return;
    134  1.1  itojun 	istcp = strcmp(name, "tcp6") == 0;
    135  1.1  itojun 	kread(off, (char *)&cb, sizeof (struct in6pcb));
    136  1.1  itojun 	in6pcb = cb;
    137  1.1  itojun 	prev = (struct in6pcb *)off;
    138  1.1  itojun 	if (in6pcb.in6p_next == (struct in6pcb *)off)
    139  1.1  itojun 		return;
    140  1.1  itojun 	while (in6pcb.in6p_next != (struct in6pcb *)off) {
    141  1.1  itojun 		next = in6pcb.in6p_next;
    142  1.1  itojun 		kread((u_long)next, (char *)&in6pcb, sizeof (in6pcb));
    143  1.1  itojun 		if (in6pcb.in6p_prev != prev) {
    144  1.1  itojun 			printf("???\n");
    145  1.1  itojun 			break;
    146  1.1  itojun 		}
    147  1.1  itojun 		if (!aflag && IN6_IS_ADDR_ANY(&in6pcb.in6p_laddr)) {
    148  1.1  itojun 			prev = next;
    149  1.1  itojun 			continue;
    150  1.1  itojun 		}
    151  1.1  itojun 		kread((u_long)in6pcb.in6p_socket, (char *)&sockb, sizeof (sockb));
    152  1.1  itojun 		if (istcp) {
    153  1.1  itojun #ifdef TCP6
    154  1.1  itojun 			kread((u_long)in6pcb.in6p_ppcb,
    155  1.1  itojun 			    (char *)&tcp6cb, sizeof (tcp6cb));
    156  1.1  itojun #else
    157  1.1  itojun 			kread((u_long)in6pcb.in6p_ppcb,
    158  1.1  itojun 			    (char *)&tcpcb, sizeof (tcpcb));
    159  1.1  itojun #endif
    160  1.1  itojun 		}
    161  1.1  itojun 		if (first) {
    162  1.1  itojun 			printf("Active Internet6 connections");
    163  1.1  itojun 			if (aflag)
    164  1.1  itojun 				printf(" (including servers)");
    165  1.1  itojun 			putchar('\n');
    166  1.1  itojun 			if (Aflag)
    167  1.1  itojun 				printf("%-8.8s ", "PCB");
    168  1.1  itojun 			printf(Aflag ?
    169  1.1  itojun 				"%-5.5s %-6.6s %-6.6s  %-18.18s %-18.18s %s\n" :
    170  1.1  itojun 				"%-5.5s %-6.6s %-6.6s  %-22.22s %-22.22s %s\n",
    171  1.1  itojun 				"Proto", "Recv-Q", "Send-Q",
    172  1.1  itojun 				"Local Address", "Foreign Address", "(state)");
    173  1.1  itojun 			first = 0;
    174  1.1  itojun 		}
    175  1.1  itojun 		if (Aflag) {
    176  1.1  itojun 			if (istcp)
    177  1.1  itojun 				printf("%8p ", in6pcb.in6p_ppcb);
    178  1.1  itojun 			else
    179  1.1  itojun 				printf("%8p ", next);
    180  1.1  itojun 		}
    181  1.1  itojun 		printf("%-5.5s %6ld %6ld ", name, sockb.so_rcv.sb_cc,
    182  1.1  itojun 			sockb.so_snd.sb_cc);
    183  1.1  itojun 		/* xxx */
    184  1.1  itojun 		inet6print(&in6pcb.in6p_laddr, (int)in6pcb.in6p_lport, name);
    185  1.1  itojun 		inet6print(&in6pcb.in6p_faddr, (int)in6pcb.in6p_fport, name);
    186  1.1  itojun 		if (istcp) {
    187  1.1  itojun #ifdef TCP6
    188  1.1  itojun 			if (tcp6cb.t_state < 0 || tcp6cb.t_state >= TCP6_NSTATES)
    189  1.1  itojun 				printf(" %d", tcp6cb.t_state);
    190  1.1  itojun 			else
    191  1.1  itojun 				printf(" %s", tcp6states[tcp6cb.t_state]);
    192  1.1  itojun #else
    193  1.1  itojun 			if (tcpcb.t_state < 0 || tcpcb.t_state >= TCP_NSTATES)
    194  1.1  itojun 				printf(" %d", tcpcb.t_state);
    195  1.1  itojun 			else
    196  1.1  itojun 				printf(" %s", tcpstates[tcpcb.t_state]);
    197  1.1  itojun #endif
    198  1.1  itojun 		}
    199  1.1  itojun 		putchar('\n');
    200  1.1  itojun 		prev = next;
    201  1.1  itojun 	}
    202  1.1  itojun }
    203  1.1  itojun 
    204  1.1  itojun #ifdef TCP6
    205  1.1  itojun /*
    206  1.1  itojun  * Dump TCP6 statistics structure.
    207  1.1  itojun  */
    208  1.1  itojun void
    209  1.1  itojun tcp6_stats(off, name)
    210  1.1  itojun 	u_long off;
    211  1.1  itojun 	char *name;
    212  1.1  itojun {
    213  1.1  itojun 	struct tcp6stat tcp6stat;
    214  1.1  itojun 
    215  1.1  itojun 	if (off == 0)
    216  1.1  itojun 		return;
    217  1.1  itojun 	printf ("%s:\n", name);
    218  1.1  itojun 	kread(off, (char *)&tcp6stat, sizeof (tcp6stat));
    219  1.1  itojun 
    220  1.1  itojun #define	p(f, m) if (tcp6stat.f || sflag <= 1) \
    221  1.1  itojun     printf(m, tcp6stat.f, plural(tcp6stat.f))
    222  1.1  itojun #define	p2(f1, f2, m) if (tcp6stat.f1 || tcp6stat.f2 || sflag <= 1) \
    223  1.1  itojun     printf(m, tcp6stat.f1, plural(tcp6stat.f1), tcp6stat.f2, plural(tcp6stat.f2))
    224  1.1  itojun #define	p3(f, m) if (tcp6stat.f || sflag <= 1) \
    225  1.1  itojun     printf(m, tcp6stat.f, plurales(tcp6stat.f))
    226  1.1  itojun 
    227  1.1  itojun 	p(tcp6s_sndtotal, "\t%ld packet%s sent\n");
    228  1.1  itojun 	p2(tcp6s_sndpack,tcp6s_sndbyte,
    229  1.1  itojun 		"\t\t%ld data packet%s (%ld byte%s)\n");
    230  1.1  itojun 	p2(tcp6s_sndrexmitpack, tcp6s_sndrexmitbyte,
    231  1.1  itojun 		"\t\t%ld data packet%s (%ld byte%s) retransmitted\n");
    232  1.1  itojun 	p2(tcp6s_sndacks, tcp6s_delack,
    233  1.1  itojun 		"\t\t%ld ack-only packet%s (%ld packet%s delayed)\n");
    234  1.1  itojun 	p(tcp6s_sndurg, "\t\t%ld URG only packet%s\n");
    235  1.1  itojun 	p(tcp6s_sndprobe, "\t\t%ld window probe packet%s\n");
    236  1.1  itojun 	p(tcp6s_sndwinup, "\t\t%ld window update packet%s\n");
    237  1.1  itojun 	p(tcp6s_sndctrl, "\t\t%ld control packet%s\n");
    238  1.1  itojun 	p(tcp6s_rcvtotal, "\t%ld packet%s received\n");
    239  1.1  itojun 	p2(tcp6s_rcvackpack, tcp6s_rcvackbyte, "\t\t%ld ack%s (for %ld byte%s)\n");
    240  1.1  itojun 	p(tcp6s_rcvdupack, "\t\t%ld duplicate ack%s\n");
    241  1.1  itojun 	p(tcp6s_rcvacktoomuch, "\t\t%ld ack%s for unsent data\n");
    242  1.1  itojun 	p2(tcp6s_rcvpack, tcp6s_rcvbyte,
    243  1.1  itojun 		"\t\t%ld packet%s (%ld byte%s) received in-sequence\n");
    244  1.1  itojun 	p2(tcp6s_rcvduppack, tcp6s_rcvdupbyte,
    245  1.1  itojun 		"\t\t%ld completely duplicate packet%s (%ld byte%s)\n");
    246  1.1  itojun 	p(tcp6s_pawsdrop, "\t\t%ld old duplicate packet%s\n");
    247  1.1  itojun 	p2(tcp6s_rcvpartduppack, tcp6s_rcvpartdupbyte,
    248  1.1  itojun 		"\t\t%ld packet%s with some dup. data (%ld byte%s duped)\n");
    249  1.1  itojun 	p2(tcp6s_rcvoopack, tcp6s_rcvoobyte,
    250  1.1  itojun 		"\t\t%ld out-of-order packet%s (%ld byte%s)\n");
    251  1.1  itojun 	p2(tcp6s_rcvpackafterwin, tcp6s_rcvbyteafterwin,
    252  1.1  itojun 		"\t\t%ld packet%s (%ld byte%s) of data after window\n");
    253  1.1  itojun 	p(tcp6s_rcvwinprobe, "\t\t%ld window probe%s\n");
    254  1.1  itojun 	p(tcp6s_rcvwinupd, "\t\t%ld window update packet%s\n");
    255  1.1  itojun 	p(tcp6s_rcvafterclose, "\t\t%ld packet%s received after close\n");
    256  1.1  itojun 	p(tcp6s_rcvbadsum, "\t\t%ld discarded for bad checksum%s\n");
    257  1.1  itojun 	p(tcp6s_rcvbadoff, "\t\t%ld discarded for bad header offset field%s\n");
    258  1.1  itojun 	p(tcp6s_rcvshort, "\t\t%ld discarded because packet%s too short\n");
    259  1.1  itojun 	p(tcp6s_connattempt, "\t%ld connection request%s\n");
    260  1.1  itojun 	p(tcp6s_accepts, "\t%ld connection accept%s\n");
    261  1.1  itojun 	p(tcp6s_badsyn, "\t%ld bad connection attempt%s\n");
    262  1.1  itojun 	p(tcp6s_connects, "\t%ld connection%s established (including accepts)\n");
    263  1.1  itojun 	p2(tcp6s_closed, tcp6s_drops,
    264  1.1  itojun 		"\t%ld connection%s closed (including %ld drop%s)\n");
    265  1.1  itojun 	p(tcp6s_conndrops, "\t%ld embryonic connection%s dropped\n");
    266  1.1  itojun 	p2(tcp6s_rttupdated, tcp6s_segstimed,
    267  1.1  itojun 		"\t%ld segment%s updated rtt (of %ld attempt%s)\n");
    268  1.1  itojun 	p(tcp6s_rexmttimeo, "\t%ld retransmit timeout%s\n");
    269  1.1  itojun 	p(tcp6s_timeoutdrop, "\t\t%ld connection%s dropped by rexmit timeout\n");
    270  1.1  itojun 	p(tcp6s_persisttimeo, "\t%ld persist timeout%s\n");
    271  1.1  itojun 	p(tcp6s_persistdrop, "\t%ld connection%s timed out in persist\n");
    272  1.1  itojun 	p(tcp6s_keeptimeo, "\t%ld keepalive timeout%s\n");
    273  1.1  itojun 	p(tcp6s_keepprobe, "\t\t%ld keepalive probe%s sent\n");
    274  1.1  itojun 	p(tcp6s_keepdrops, "\t\t%ld connection%s dropped by keepalive\n");
    275  1.1  itojun 	p(tcp6s_predack, "\t%ld correct ACK header prediction%s\n");
    276  1.1  itojun 	p(tcp6s_preddat, "\t%ld correct data packet header prediction%s\n");
    277  1.1  itojun 	p3(tcp6s_pcbcachemiss, "\t%ld PCB cache miss%s\n");
    278  1.1  itojun #undef p
    279  1.1  itojun #undef p2
    280  1.1  itojun #undef p3
    281  1.1  itojun }
    282  1.1  itojun #endif
    283  1.1  itojun 
    284  1.1  itojun /*
    285  1.1  itojun  * Dump UDP6 statistics structure.
    286  1.1  itojun  */
    287  1.1  itojun void
    288  1.1  itojun udp6_stats(off, name)
    289  1.1  itojun 	u_long off;
    290  1.1  itojun 	char *name;
    291  1.1  itojun {
    292  1.1  itojun 	struct udp6stat udp6stat;
    293  1.1  itojun 	u_long delivered;
    294  1.1  itojun 
    295  1.1  itojun 	if (off == 0)
    296  1.1  itojun 		return;
    297  1.1  itojun 	kread(off, (char *)&udp6stat, sizeof (udp6stat));
    298  1.1  itojun 	printf("%s:\n", name);
    299  1.1  itojun #define	p(f, m) if (udp6stat.f || sflag <= 1) \
    300  1.1  itojun     printf(m, udp6stat.f, plural(udp6stat.f))
    301  1.1  itojun #define	p1(f, m) if (udp6stat.f || sflag <= 1) \
    302  1.1  itojun     printf(m, udp6stat.f)
    303  1.1  itojun 	p(udp6s_ipackets, "\t%lu datagram%s received\n");
    304  1.1  itojun 	p1(udp6s_hdrops, "\t%lu with incomplete header\n");
    305  1.1  itojun 	p1(udp6s_badlen, "\t%lu with bad data length field\n");
    306  1.1  itojun 	p1(udp6s_badsum, "\t%lu with bad checksum\n");
    307  1.1  itojun 	p1(udp6s_nosum, "\t%lu with no checksum\n");
    308  1.1  itojun 	p1(udp6s_noport, "\t%lu dropped due to no socket\n");
    309  1.1  itojun 	p(udp6s_noportmcast, "\t%lu multicast datagram%s dropped due to no socket\n");
    310  1.1  itojun 	p1(udp6s_fullsock, "\t%lu dropped due to full socket buffers\n");
    311  1.1  itojun 	delivered = udp6stat.udp6s_ipackets -
    312  1.1  itojun 		    udp6stat.udp6s_hdrops -
    313  1.1  itojun 		    udp6stat.udp6s_badlen -
    314  1.1  itojun 		    udp6stat.udp6s_badsum -
    315  1.1  itojun 		    udp6stat.udp6s_noport -
    316  1.1  itojun 		    udp6stat.udp6s_noportmcast -
    317  1.1  itojun 		    udp6stat.udp6s_fullsock;
    318  1.1  itojun 	if (delivered || sflag <= 1)
    319  1.1  itojun 		printf("\t%lu delivered\n", delivered);
    320  1.1  itojun 	p(udp6s_opackets, "\t%lu datagram%s output\n");
    321  1.1  itojun #undef p
    322  1.1  itojun #undef p1
    323  1.1  itojun }
    324  1.1  itojun 
    325  1.1  itojun static	char *ip6nh[] = {
    326  1.1  itojun 	"hop by hop",
    327  1.1  itojun 	"ICMP",
    328  1.1  itojun 	"IGMP",
    329  1.1  itojun 	"#3",
    330  1.1  itojun 	"IP",
    331  1.1  itojun 	"#5",
    332  1.1  itojun 	"TCP",
    333  1.1  itojun 	"#7",
    334  1.1  itojun 	"#8",
    335  1.1  itojun 	"#9",
    336  1.1  itojun 	"#10",
    337  1.1  itojun 	"#11",
    338  1.1  itojun 	"#12",
    339  1.1  itojun 	"#13",
    340  1.1  itojun 	"#14",
    341  1.1  itojun 	"#15",
    342  1.1  itojun 	"#16",
    343  1.1  itojun 	"UDP",
    344  1.1  itojun 	"#18",
    345  1.1  itojun 	"#19",
    346  1.1  itojun 	"#20",
    347  1.1  itojun 	"#21",
    348  1.1  itojun 	"IDP",
    349  1.1  itojun 	"#23",
    350  1.1  itojun 	"#24",
    351  1.1  itojun 	"#25",
    352  1.1  itojun 	"#26",
    353  1.1  itojun 	"#27",
    354  1.1  itojun 	"#28",
    355  1.1  itojun 	"TP",
    356  1.1  itojun 	"#30",
    357  1.1  itojun 	"#31",
    358  1.1  itojun 	"#32",
    359  1.1  itojun 	"#33",
    360  1.1  itojun 	"#34",
    361  1.1  itojun 	"#35",
    362  1.1  itojun 	"#36",
    363  1.1  itojun 	"#37",
    364  1.1  itojun 	"#38",
    365  1.1  itojun 	"#39",
    366  1.1  itojun 	"#40",
    367  1.1  itojun 	"IP6",
    368  1.1  itojun 	"#42",
    369  1.1  itojun 	"routing",
    370  1.1  itojun 	"fragment",
    371  1.1  itojun 	"#45",
    372  1.1  itojun 	"#46",
    373  1.1  itojun 	"#47",
    374  1.1  itojun 	"#48",
    375  1.1  itojun 	"#49",
    376  1.1  itojun 	"ESP",
    377  1.1  itojun 	"AH",
    378  1.1  itojun 	"#52",
    379  1.1  itojun 	"#53",
    380  1.1  itojun 	"#54",
    381  1.1  itojun 	"#55",
    382  1.1  itojun 	"#56",
    383  1.1  itojun 	"#57",
    384  1.1  itojun 	"ICMP6",
    385  1.1  itojun 	"no next header",
    386  1.1  itojun 	"destination option",
    387  1.1  itojun 	"#61",
    388  1.1  itojun 	"#62",
    389  1.1  itojun 	"#63",
    390  1.1  itojun 	"#64",
    391  1.1  itojun 	"#65",
    392  1.1  itojun 	"#66",
    393  1.1  itojun 	"#67",
    394  1.1  itojun 	"#68",
    395  1.1  itojun 	"#69",
    396  1.1  itojun 	"#70",
    397  1.1  itojun 	"#71",
    398  1.1  itojun 	"#72",
    399  1.1  itojun 	"#73",
    400  1.1  itojun 	"#74",
    401  1.1  itojun 	"#75",
    402  1.1  itojun 	"#76",
    403  1.1  itojun 	"#77",
    404  1.1  itojun 	"#78",
    405  1.1  itojun 	"#79",
    406  1.1  itojun 	"ISOIP",
    407  1.1  itojun 	"#81",
    408  1.1  itojun 	"#82",
    409  1.1  itojun 	"#83",
    410  1.1  itojun 	"#84",
    411  1.1  itojun 	"#85",
    412  1.1  itojun 	"#86",
    413  1.1  itojun 	"#87",
    414  1.1  itojun 	"#88",
    415  1.1  itojun 	"#89",
    416  1.1  itojun 	"#80",
    417  1.1  itojun 	"#91",
    418  1.1  itojun 	"#92",
    419  1.1  itojun 	"#93",
    420  1.1  itojun 	"#94",
    421  1.1  itojun 	"#95",
    422  1.1  itojun 	"#96",
    423  1.1  itojun 	"Ethernet",
    424  1.1  itojun 	"#98",
    425  1.1  itojun 	"#99",
    426  1.1  itojun 	"#100",
    427  1.1  itojun 	"#101",
    428  1.1  itojun 	"#102",
    429  1.1  itojun 	"PIM",
    430  1.1  itojun 	"#104",
    431  1.1  itojun 	"#105",
    432  1.1  itojun 	"#106",
    433  1.1  itojun 	"#107",
    434  1.1  itojun 	"#108",
    435  1.1  itojun 	"#109",
    436  1.1  itojun 	"#110",
    437  1.1  itojun 	"#111",
    438  1.1  itojun 	"#112",
    439  1.1  itojun 	"#113",
    440  1.1  itojun 	"#114",
    441  1.1  itojun 	"#115",
    442  1.1  itojun 	"#116",
    443  1.1  itojun 	"#117",
    444  1.1  itojun 	"#118",
    445  1.1  itojun 	"#119",
    446  1.1  itojun 	"#120",
    447  1.1  itojun 	"#121",
    448  1.1  itojun 	"#122",
    449  1.1  itojun 	"#123",
    450  1.1  itojun 	"#124",
    451  1.1  itojun 	"#125",
    452  1.1  itojun 	"#126",
    453  1.1  itojun 	"#127",
    454  1.1  itojun 	"#128",
    455  1.1  itojun 	"#129",
    456  1.1  itojun 	"#130",
    457  1.1  itojun 	"#131",
    458  1.1  itojun 	"#132",
    459  1.1  itojun 	"#133",
    460  1.1  itojun 	"#134",
    461  1.1  itojun 	"#135",
    462  1.1  itojun 	"#136",
    463  1.1  itojun 	"#137",
    464  1.1  itojun 	"#138",
    465  1.1  itojun 	"#139",
    466  1.1  itojun 	"#140",
    467  1.1  itojun 	"#141",
    468  1.1  itojun 	"#142",
    469  1.1  itojun 	"#143",
    470  1.1  itojun 	"#144",
    471  1.1  itojun 	"#145",
    472  1.1  itojun 	"#146",
    473  1.1  itojun 	"#147",
    474  1.1  itojun 	"#148",
    475  1.1  itojun 	"#149",
    476  1.1  itojun 	"#150",
    477  1.1  itojun 	"#151",
    478  1.1  itojun 	"#152",
    479  1.1  itojun 	"#153",
    480  1.1  itojun 	"#154",
    481  1.1  itojun 	"#155",
    482  1.1  itojun 	"#156",
    483  1.1  itojun 	"#157",
    484  1.1  itojun 	"#158",
    485  1.1  itojun 	"#159",
    486  1.1  itojun 	"#160",
    487  1.1  itojun 	"#161",
    488  1.1  itojun 	"#162",
    489  1.1  itojun 	"#163",
    490  1.1  itojun 	"#164",
    491  1.1  itojun 	"#165",
    492  1.1  itojun 	"#166",
    493  1.1  itojun 	"#167",
    494  1.1  itojun 	"#168",
    495  1.1  itojun 	"#169",
    496  1.1  itojun 	"#170",
    497  1.1  itojun 	"#171",
    498  1.1  itojun 	"#172",
    499  1.1  itojun 	"#173",
    500  1.1  itojun 	"#174",
    501  1.1  itojun 	"#175",
    502  1.1  itojun 	"#176",
    503  1.1  itojun 	"#177",
    504  1.1  itojun 	"#178",
    505  1.1  itojun 	"#179",
    506  1.1  itojun 	"#180",
    507  1.1  itojun 	"#181",
    508  1.1  itojun 	"#182",
    509  1.1  itojun 	"#183",
    510  1.1  itojun 	"#184",
    511  1.1  itojun 	"#185",
    512  1.1  itojun 	"#186",
    513  1.1  itojun 	"#187",
    514  1.1  itojun 	"#188",
    515  1.1  itojun 	"#189",
    516  1.1  itojun 	"#180",
    517  1.1  itojun 	"#191",
    518  1.1  itojun 	"#192",
    519  1.1  itojun 	"#193",
    520  1.1  itojun 	"#194",
    521  1.1  itojun 	"#195",
    522  1.1  itojun 	"#196",
    523  1.1  itojun 	"#197",
    524  1.1  itojun 	"#198",
    525  1.1  itojun 	"#199",
    526  1.1  itojun 	"#200",
    527  1.1  itojun 	"#201",
    528  1.1  itojun 	"#202",
    529  1.1  itojun 	"#203",
    530  1.1  itojun 	"#204",
    531  1.1  itojun 	"#205",
    532  1.1  itojun 	"#206",
    533  1.1  itojun 	"#207",
    534  1.1  itojun 	"#208",
    535  1.1  itojun 	"#209",
    536  1.1  itojun 	"#210",
    537  1.1  itojun 	"#211",
    538  1.1  itojun 	"#212",
    539  1.1  itojun 	"#213",
    540  1.1  itojun 	"#214",
    541  1.1  itojun 	"#215",
    542  1.1  itojun 	"#216",
    543  1.1  itojun 	"#217",
    544  1.1  itojun 	"#218",
    545  1.1  itojun 	"#219",
    546  1.1  itojun 	"#220",
    547  1.1  itojun 	"#221",
    548  1.1  itojun 	"#222",
    549  1.1  itojun 	"#223",
    550  1.1  itojun 	"#224",
    551  1.1  itojun 	"#225",
    552  1.1  itojun 	"#226",
    553  1.1  itojun 	"#227",
    554  1.1  itojun 	"#228",
    555  1.1  itojun 	"#229",
    556  1.1  itojun 	"#230",
    557  1.1  itojun 	"#231",
    558  1.1  itojun 	"#232",
    559  1.1  itojun 	"#233",
    560  1.1  itojun 	"#234",
    561  1.1  itojun 	"#235",
    562  1.1  itojun 	"#236",
    563  1.1  itojun 	"#237",
    564  1.1  itojun 	"#238",
    565  1.1  itojun 	"#239",
    566  1.1  itojun 	"#240",
    567  1.1  itojun 	"#241",
    568  1.1  itojun 	"#242",
    569  1.1  itojun 	"#243",
    570  1.1  itojun 	"#244",
    571  1.1  itojun 	"#245",
    572  1.1  itojun 	"#246",
    573  1.1  itojun 	"#247",
    574  1.1  itojun 	"#248",
    575  1.1  itojun 	"#249",
    576  1.1  itojun 	"#250",
    577  1.1  itojun 	"#251",
    578  1.1  itojun 	"#252",
    579  1.1  itojun 	"#253",
    580  1.1  itojun 	"#254",
    581  1.1  itojun 	"#255",
    582  1.1  itojun };
    583  1.1  itojun 
    584  1.1  itojun /*
    585  1.1  itojun  * Dump IP6 statistics structure.
    586  1.1  itojun  */
    587  1.1  itojun void
    588  1.1  itojun ip6_stats(off, name)
    589  1.1  itojun 	u_long off;
    590  1.1  itojun 	char *name;
    591  1.1  itojun {
    592  1.1  itojun 	struct ip6stat ip6stat;
    593  1.1  itojun 	int first, i;
    594  1.1  itojun 
    595  1.1  itojun 	if (off == 0)
    596  1.1  itojun 		return;
    597  1.1  itojun 
    598  1.1  itojun 	kread(off, (char *)&ip6stat, sizeof (ip6stat));
    599  1.1  itojun 	printf("%s:\n", name);
    600  1.1  itojun 
    601  1.1  itojun #define	p(f, m) if (ip6stat.f || sflag <= 1) \
    602  1.1  itojun     printf(m, ip6stat.f, plural(ip6stat.f))
    603  1.1  itojun #define	p1(f, m) if (ip6stat.f || sflag <= 1) \
    604  1.1  itojun     printf(m, ip6stat.f)
    605  1.1  itojun 
    606  1.1  itojun 	p(ip6s_total, "\t%lu total packet%s received\n");
    607  1.1  itojun 	p1(ip6s_toosmall, "\t%lu with size smaller than minimum\n");
    608  1.1  itojun 	p1(ip6s_tooshort, "\t%lu with data size < data length\n");
    609  1.1  itojun 	p1(ip6s_badoptions, "\t%lu with bad options\n");
    610  1.1  itojun 	p1(ip6s_badvers, "\t%lu with incorrect version number\n");
    611  1.1  itojun 	p(ip6s_fragments, "\t%lu fragment%s received\n");
    612  1.1  itojun 	p(ip6s_fragdropped, "\t%lu fragment%s dropped (dup or out of space)\n");
    613  1.1  itojun 	p(ip6s_fragtimeout, "\t%lu fragment%s dropped after timeout\n");
    614  1.1  itojun 	p(ip6s_fragoverflow, "\t%lu fragment%s that exceeded limit\n");
    615  1.1  itojun 	p(ip6s_reassembled, "\t%lu packet%s reassembled ok\n");
    616  1.1  itojun 	p(ip6s_delivered, "\t%lu packet%s for this host\n");
    617  1.1  itojun 	p(ip6s_forward, "\t%lu packet%s forwarded\n");
    618  1.1  itojun 	p(ip6s_cantforward, "\t%lu packet%s not forwardable\n");
    619  1.1  itojun 	p(ip6s_redirectsent, "\t%lu redirect%s sent\n");
    620  1.1  itojun 	p(ip6s_localout, "\t%lu packet%s sent from this host\n");
    621  1.1  itojun 	p(ip6s_rawout, "\t%lu packet%s sent with fabricated ip header\n");
    622  1.1  itojun 	p(ip6s_odropped, "\t%lu output packet%s dropped due to no bufs, etc.\n");
    623  1.1  itojun 	p(ip6s_noroute, "\t%lu output packet%s discarded due to no route\n");
    624  1.1  itojun 	p(ip6s_fragmented, "\t%lu output datagram%s fragmented\n");
    625  1.1  itojun 	p(ip6s_ofragments, "\t%lu fragment%s created\n");
    626  1.1  itojun 	p(ip6s_cantfrag, "\t%lu datagram%s that can't be fragmented\n");
    627  1.1  itojun 	p(ip6s_badscope, "\t%lu packet%s that violated scope rules\n");
    628  1.1  itojun 	p(ip6s_notmember, "\t%lu multicast packet%s which we don't join\n");
    629  1.1  itojun 	for (first = 1, i = 0; i < 256; i++)
    630  1.1  itojun 		if (ip6stat.ip6s_nxthist[i] != 0) {
    631  1.1  itojun 			if (first) {
    632  1.1  itojun 				printf("\tInput histogram:\n");
    633  1.1  itojun 				first = 0;
    634  1.1  itojun 			}
    635  1.1  itojun 			printf("\t\t%s: %lu\n", ip6nh[i],
    636  1.1  itojun 			       ip6stat.ip6s_nxthist[i]);
    637  1.1  itojun 		}
    638  1.1  itojun 	printf("\tMbuf statics:\n");
    639  1.1  itojun 	printf("\t\t%lu one mbuf\n", ip6stat.ip6s_m1);
    640  1.1  itojun 	for (first = 1, i = 0; i < 32; i++) {
    641  1.1  itojun 		char ifbuf[IFNAMSIZ];
    642  1.1  itojun 		if (ip6stat.ip6s_m2m[i] != 0) {
    643  1.1  itojun 			if (first) {
    644  1.1  itojun 				printf("\t\ttwo or more mbuf:\n");
    645  1.1  itojun 				first = 0;
    646  1.1  itojun 			}
    647  1.1  itojun 			printf("\t\t\t%s = %ld\n",
    648  1.1  itojun 			       if_indextoname(i, ifbuf),
    649  1.1  itojun 			       ip6stat.ip6s_m2m[i]);
    650  1.1  itojun 		}
    651  1.1  itojun 	}
    652  1.1  itojun 	printf("\t\t%lu one ext mbuf\n", ip6stat.ip6s_mext1);
    653  1.1  itojun 	printf("\t\t%lu two or more ext mbuf\n", ip6stat.ip6s_mext2m);
    654  1.1  itojun 	p(ip6s_exthdrtoolong, "\t%lu packet%s whose headers are not continuous\n");
    655  1.1  itojun 	p(ip6s_nogif, "\t%lu tunneling packet%s that can't find gif\n");
    656  1.1  itojun #undef p
    657  1.1  itojun #undef p1
    658  1.1  itojun }
    659  1.1  itojun 
    660  1.1  itojun static	char *icmp6names[] = {
    661  1.1  itojun 	"#0",
    662  1.1  itojun 	"unreach",
    663  1.1  itojun 	"packet too big",
    664  1.1  itojun 	"time exceed",
    665  1.1  itojun 	"parameter problem",
    666  1.1  itojun 	"#5",
    667  1.1  itojun 	"#6",
    668  1.1  itojun 	"#7",
    669  1.1  itojun 	"#8",
    670  1.1  itojun 	"#9",
    671  1.1  itojun 	"#10",
    672  1.1  itojun 	"#11",
    673  1.1  itojun 	"#12",
    674  1.1  itojun 	"#13",
    675  1.1  itojun 	"#14",
    676  1.1  itojun 	"#15",
    677  1.1  itojun 	"#16",
    678  1.1  itojun 	"#17",
    679  1.1  itojun 	"#18",
    680  1.1  itojun 	"#19",
    681  1.1  itojun 	"#20",
    682  1.1  itojun 	"#21",
    683  1.1  itojun 	"#22",
    684  1.1  itojun 	"#23",
    685  1.1  itojun 	"#24",
    686  1.1  itojun 	"#25",
    687  1.1  itojun 	"#26",
    688  1.1  itojun 	"#27",
    689  1.1  itojun 	"#28",
    690  1.1  itojun 	"#29",
    691  1.1  itojun 	"#30",
    692  1.1  itojun 	"#31",
    693  1.1  itojun 	"#32",
    694  1.1  itojun 	"#33",
    695  1.1  itojun 	"#34",
    696  1.1  itojun 	"#35",
    697  1.1  itojun 	"#36",
    698  1.1  itojun 	"#37",
    699  1.1  itojun 	"#38",
    700  1.1  itojun 	"#39",
    701  1.1  itojun 	"#40",
    702  1.1  itojun 	"#41",
    703  1.1  itojun 	"#42",
    704  1.1  itojun 	"#43",
    705  1.1  itojun 	"#44",
    706  1.1  itojun 	"#45",
    707  1.1  itojun 	"#46",
    708  1.1  itojun 	"#47",
    709  1.1  itojun 	"#48",
    710  1.1  itojun 	"#49",
    711  1.1  itojun 	"#50",
    712  1.1  itojun 	"#51",
    713  1.1  itojun 	"#52",
    714  1.1  itojun 	"#53",
    715  1.1  itojun 	"#54",
    716  1.1  itojun 	"#55",
    717  1.1  itojun 	"#56",
    718  1.1  itojun 	"#57",
    719  1.1  itojun 	"#58",
    720  1.1  itojun 	"#59",
    721  1.1  itojun 	"#60",
    722  1.1  itojun 	"#61",
    723  1.1  itojun 	"#62",
    724  1.1  itojun 	"#63",
    725  1.1  itojun 	"#64",
    726  1.1  itojun 	"#65",
    727  1.1  itojun 	"#66",
    728  1.1  itojun 	"#67",
    729  1.1  itojun 	"#68",
    730  1.1  itojun 	"#69",
    731  1.1  itojun 	"#70",
    732  1.1  itojun 	"#71",
    733  1.1  itojun 	"#72",
    734  1.1  itojun 	"#73",
    735  1.1  itojun 	"#74",
    736  1.1  itojun 	"#75",
    737  1.1  itojun 	"#76",
    738  1.1  itojun 	"#77",
    739  1.1  itojun 	"#78",
    740  1.1  itojun 	"#79",
    741  1.1  itojun 	"#80",
    742  1.1  itojun 	"#81",
    743  1.1  itojun 	"#82",
    744  1.1  itojun 	"#83",
    745  1.1  itojun 	"#84",
    746  1.1  itojun 	"#85",
    747  1.1  itojun 	"#86",
    748  1.1  itojun 	"#87",
    749  1.1  itojun 	"#88",
    750  1.1  itojun 	"#89",
    751  1.1  itojun 	"#80",
    752  1.1  itojun 	"#91",
    753  1.1  itojun 	"#92",
    754  1.1  itojun 	"#93",
    755  1.1  itojun 	"#94",
    756  1.1  itojun 	"#95",
    757  1.1  itojun 	"#96",
    758  1.1  itojun 	"#97",
    759  1.1  itojun 	"#98",
    760  1.1  itojun 	"#99",
    761  1.1  itojun 	"#100",
    762  1.1  itojun 	"#101",
    763  1.1  itojun 	"#102",
    764  1.1  itojun 	"#103",
    765  1.1  itojun 	"#104",
    766  1.1  itojun 	"#105",
    767  1.1  itojun 	"#106",
    768  1.1  itojun 	"#107",
    769  1.1  itojun 	"#108",
    770  1.1  itojun 	"#109",
    771  1.1  itojun 	"#110",
    772  1.1  itojun 	"#111",
    773  1.1  itojun 	"#112",
    774  1.1  itojun 	"#113",
    775  1.1  itojun 	"#114",
    776  1.1  itojun 	"#115",
    777  1.1  itojun 	"#116",
    778  1.1  itojun 	"#117",
    779  1.1  itojun 	"#118",
    780  1.1  itojun 	"#119",
    781  1.1  itojun 	"#120",
    782  1.1  itojun 	"#121",
    783  1.1  itojun 	"#122",
    784  1.1  itojun 	"#123",
    785  1.1  itojun 	"#124",
    786  1.1  itojun 	"#125",
    787  1.1  itojun 	"#126",
    788  1.1  itojun 	"#127",
    789  1.1  itojun 	"echo",
    790  1.1  itojun 	"echo reply",
    791  1.1  itojun 	"group member query",
    792  1.1  itojun 	"group member report",
    793  1.1  itojun 	"group member termination",
    794  1.1  itojun 	"router solicitation",
    795  1.1  itojun 	"router advertisment",
    796  1.1  itojun 	"neighbor solicitation",
    797  1.1  itojun 	"neighbor advertisment",
    798  1.1  itojun 	"redirect",
    799  1.1  itojun 	"router renumbering",
    800  1.1  itojun 	"node information request",
    801  1.1  itojun 	"node information reply",
    802  1.1  itojun 	"#141",
    803  1.1  itojun 	"#142",
    804  1.1  itojun 	"#143",
    805  1.1  itojun 	"#144",
    806  1.1  itojun 	"#145",
    807  1.1  itojun 	"#146",
    808  1.1  itojun 	"#147",
    809  1.1  itojun 	"#148",
    810  1.1  itojun 	"#149",
    811  1.1  itojun 	"#150",
    812  1.1  itojun 	"#151",
    813  1.1  itojun 	"#152",
    814  1.1  itojun 	"#153",
    815  1.1  itojun 	"#154",
    816  1.1  itojun 	"#155",
    817  1.1  itojun 	"#156",
    818  1.1  itojun 	"#157",
    819  1.1  itojun 	"#158",
    820  1.1  itojun 	"#159",
    821  1.1  itojun 	"#160",
    822  1.1  itojun 	"#161",
    823  1.1  itojun 	"#162",
    824  1.1  itojun 	"#163",
    825  1.1  itojun 	"#164",
    826  1.1  itojun 	"#165",
    827  1.1  itojun 	"#166",
    828  1.1  itojun 	"#167",
    829  1.1  itojun 	"#168",
    830  1.1  itojun 	"#169",
    831  1.1  itojun 	"#170",
    832  1.1  itojun 	"#171",
    833  1.1  itojun 	"#172",
    834  1.1  itojun 	"#173",
    835  1.1  itojun 	"#174",
    836  1.1  itojun 	"#175",
    837  1.1  itojun 	"#176",
    838  1.1  itojun 	"#177",
    839  1.1  itojun 	"#178",
    840  1.1  itojun 	"#179",
    841  1.1  itojun 	"#180",
    842  1.1  itojun 	"#181",
    843  1.1  itojun 	"#182",
    844  1.1  itojun 	"#183",
    845  1.1  itojun 	"#184",
    846  1.1  itojun 	"#185",
    847  1.1  itojun 	"#186",
    848  1.1  itojun 	"#187",
    849  1.1  itojun 	"#188",
    850  1.1  itojun 	"#189",
    851  1.1  itojun 	"#180",
    852  1.1  itojun 	"#191",
    853  1.1  itojun 	"#192",
    854  1.1  itojun 	"#193",
    855  1.1  itojun 	"#194",
    856  1.1  itojun 	"#195",
    857  1.1  itojun 	"#196",
    858  1.1  itojun 	"#197",
    859  1.1  itojun 	"#198",
    860  1.1  itojun 	"#199",
    861  1.1  itojun 	"#200",
    862  1.1  itojun 	"#201",
    863  1.1  itojun 	"#202",
    864  1.1  itojun 	"#203",
    865  1.1  itojun 	"#204",
    866  1.1  itojun 	"#205",
    867  1.1  itojun 	"#206",
    868  1.1  itojun 	"#207",
    869  1.1  itojun 	"#208",
    870  1.1  itojun 	"#209",
    871  1.1  itojun 	"#210",
    872  1.1  itojun 	"#211",
    873  1.1  itojun 	"#212",
    874  1.1  itojun 	"#213",
    875  1.1  itojun 	"#214",
    876  1.1  itojun 	"#215",
    877  1.1  itojun 	"#216",
    878  1.1  itojun 	"#217",
    879  1.1  itojun 	"#218",
    880  1.1  itojun 	"#219",
    881  1.1  itojun 	"#220",
    882  1.1  itojun 	"#221",
    883  1.1  itojun 	"#222",
    884  1.1  itojun 	"#223",
    885  1.1  itojun 	"#224",
    886  1.1  itojun 	"#225",
    887  1.1  itojun 	"#226",
    888  1.1  itojun 	"#227",
    889  1.1  itojun 	"#228",
    890  1.1  itojun 	"#229",
    891  1.1  itojun 	"#230",
    892  1.1  itojun 	"#231",
    893  1.1  itojun 	"#232",
    894  1.1  itojun 	"#233",
    895  1.1  itojun 	"#234",
    896  1.1  itojun 	"#235",
    897  1.1  itojun 	"#236",
    898  1.1  itojun 	"#237",
    899  1.1  itojun 	"#238",
    900  1.1  itojun 	"#239",
    901  1.1  itojun 	"#240",
    902  1.1  itojun 	"#241",
    903  1.1  itojun 	"#242",
    904  1.1  itojun 	"#243",
    905  1.1  itojun 	"#244",
    906  1.1  itojun 	"#245",
    907  1.1  itojun 	"#246",
    908  1.1  itojun 	"#247",
    909  1.1  itojun 	"#248",
    910  1.1  itojun 	"#249",
    911  1.1  itojun 	"#250",
    912  1.1  itojun 	"#251",
    913  1.1  itojun 	"#252",
    914  1.1  itojun 	"#253",
    915  1.1  itojun 	"#254",
    916  1.1  itojun 	"#255",
    917  1.1  itojun };
    918  1.1  itojun 
    919  1.1  itojun /*
    920  1.1  itojun  * Dump ICMP6 statistics.
    921  1.1  itojun  */
    922  1.1  itojun void
    923  1.1  itojun icmp6_stats(off, name)
    924  1.1  itojun 	u_long off;
    925  1.1  itojun 	char *name;
    926  1.1  itojun {
    927  1.1  itojun 	struct icmp6stat icmp6stat;
    928  1.1  itojun 	register int i, first;
    929  1.1  itojun 
    930  1.1  itojun 	if (off == 0)
    931  1.1  itojun 		return;
    932  1.1  itojun 	kread(off, (char *)&icmp6stat, sizeof (icmp6stat));
    933  1.1  itojun 	printf("%s:\n", name);
    934  1.1  itojun 
    935  1.1  itojun #define	p(f, m) if (icmp6stat.f || sflag <= 1) \
    936  1.1  itojun     printf(m, icmp6stat.f, plural(icmp6stat.f))
    937  1.1  itojun 
    938  1.1  itojun 	p(icp6s_error, "\t%lu call%s to icmp_error\n");
    939  1.1  itojun 	p(icp6s_canterror,
    940  1.1  itojun 	    "\t%lu error%s not generated because old message was icmp or so\n");
    941  1.1  itojun 	for (first = 1, i = 0; i < 256; i++)
    942  1.1  itojun 		if (icmp6stat.icp6s_outhist[i] != 0) {
    943  1.1  itojun 			if (first) {
    944  1.1  itojun 				printf("\tOutput histogram:\n");
    945  1.1  itojun 				first = 0;
    946  1.1  itojun 			}
    947  1.1  itojun 			printf("\t\t%s: %lu\n", icmp6names[i],
    948  1.1  itojun 				icmp6stat.icp6s_outhist[i]);
    949  1.1  itojun 		}
    950  1.1  itojun 	p(icp6s_badcode, "\t%lu message%s with bad code fields\n");
    951  1.1  itojun 	p(icp6s_tooshort, "\t%lu message%s < minimum length\n");
    952  1.1  itojun 	p(icp6s_checksum, "\t%lu bad checksum%s\n");
    953  1.1  itojun 	p(icp6s_badlen, "\t%lu message%s with bad length\n");
    954  1.1  itojun 	for (first = 1, i = 0; i < ICMP6_MAXTYPE; i++)
    955  1.1  itojun 		if (icmp6stat.icp6s_inhist[i] != 0) {
    956  1.1  itojun 			if (first) {
    957  1.1  itojun 				printf("\tInput histogram:\n");
    958  1.1  itojun 				first = 0;
    959  1.1  itojun 			}
    960  1.1  itojun 			printf("\t\t%s: %lu\n", icmp6names[i],
    961  1.1  itojun 				icmp6stat.icp6s_inhist[i]);
    962  1.1  itojun 		}
    963  1.1  itojun 	p(icp6s_reflect, "\t%lu message response%s generated\n");
    964  1.1  itojun #undef p
    965  1.1  itojun }
    966  1.1  itojun 
    967  1.1  itojun /*
    968  1.1  itojun  * Dump PIM statistics structure.
    969  1.1  itojun  */
    970  1.1  itojun void
    971  1.1  itojun pim6_stats(off, name)
    972  1.1  itojun 	u_long off;
    973  1.1  itojun 	char *name;
    974  1.1  itojun {
    975  1.1  itojun 	struct pim6stat pim6stat;
    976  1.1  itojun 
    977  1.1  itojun 	if (off == 0)
    978  1.1  itojun 		return;
    979  1.1  itojun 	kread(off, (char *)&pim6stat, sizeof(pim6stat));
    980  1.1  itojun 	printf("%s:\n", name);
    981  1.1  itojun 
    982  1.1  itojun #define	p(f, m) if (pim6stat.f || sflag <= 1) \
    983  1.1  itojun     printf(m, pim6stat.f, plural(pim6stat.f))
    984  1.1  itojun 	p(pim6s_rcv_total, "\t%u message%s received\n");
    985  1.1  itojun 	p(pim6s_rcv_tooshort, "\t%u message%s received with too few bytes\n");
    986  1.1  itojun 	p(pim6s_rcv_badsum, "\t%u message%s received with bad checksum\n");
    987  1.1  itojun 	p(pim6s_rcv_badversion, "\t%u message%s received with bad version\n");
    988  1.1  itojun 	p(pim6s_rcv_registers, "\t%u register%s received\n");
    989  1.1  itojun 	p(pim6s_rcv_badregisters, "\t%u bad register%s received\n");
    990  1.1  itojun 	p(pim6s_snd_registers, "\t%u register%s sent\n");
    991  1.1  itojun #undef p
    992  1.1  itojun }
    993  1.1  itojun 
    994  1.1  itojun /*
    995  1.1  itojun  * Pretty print an Internet address (net address + port).
    996  1.1  itojun  * If the nflag was specified, use numbers instead of names.
    997  1.1  itojun  */
    998  1.1  itojun 
    999  1.1  itojun void
   1000  1.1  itojun inet6print(in6, port, proto)
   1001  1.1  itojun 	register struct in6_addr *in6;
   1002  1.1  itojun 	int port;
   1003  1.1  itojun 	char *proto;
   1004  1.1  itojun {
   1005  1.1  itojun #define GETSERVBYPORT6(port, proto, ret)\
   1006  1.1  itojun {\
   1007  1.1  itojun 	if (strcmp((proto), "tcp6") == 0)\
   1008  1.1  itojun 		(ret) = getservbyport((int)(port), "tcp");\
   1009  1.1  itojun 	else if (strcmp((proto), "udp6") == 0)\
   1010  1.1  itojun 		(ret) = getservbyport((int)(port), "udp");\
   1011  1.1  itojun 	else\
   1012  1.1  itojun 		(ret) = getservbyport((int)(port), (proto));\
   1013  1.1  itojun };
   1014  1.1  itojun 	struct servent *sp = 0;
   1015  1.1  itojun 	char line[80], *cp;
   1016  1.1  itojun 	int width;
   1017  1.1  itojun 
   1018  1.1  itojun 	sprintf(line, "%.*s.", (Aflag && !nflag) ? 12 : 16, inet6name(in6));
   1019  1.1  itojun 	cp = index(line, '\0');
   1020  1.1  itojun 	if (!nflag && port)
   1021  1.1  itojun 		GETSERVBYPORT6(port, proto, sp);
   1022  1.1  itojun 	if (sp || port == 0)
   1023  1.1  itojun 		sprintf(cp, "%.8s", sp ? sp->s_name : "*");
   1024  1.1  itojun 	else
   1025  1.1  itojun 		sprintf(cp, "%d", ntohs((u_short)port));
   1026  1.1  itojun 	width = Aflag ? 18 : 22;
   1027  1.1  itojun 	printf(" %-*.*s", width, width, line);
   1028  1.1  itojun }
   1029  1.1  itojun 
   1030  1.1  itojun /*
   1031  1.1  itojun  * Construct an Internet address representation.
   1032  1.1  itojun  * If the nflag has been supplied, give
   1033  1.1  itojun  * numeric value, otherwise try for symbolic name.
   1034  1.1  itojun  */
   1035  1.1  itojun 
   1036  1.1  itojun char *
   1037  1.1  itojun inet6name(in6p)
   1038  1.1  itojun 	struct in6_addr *in6p;
   1039  1.1  itojun {
   1040  1.1  itojun 	register char *cp;
   1041  1.1  itojun 	static char line[50];
   1042  1.1  itojun 	struct hostent *hp;
   1043  1.1  itojun 	static char domain[MAXHOSTNAMELEN + 1];
   1044  1.1  itojun 	static int first = 1;
   1045  1.1  itojun 
   1046  1.1  itojun 	if (first && !nflag) {
   1047  1.1  itojun 		first = 0;
   1048  1.1  itojun 		if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
   1049  1.1  itojun 		    (cp = index(domain, '.')))
   1050  1.1  itojun 			(void) strcpy(domain, cp + 1);
   1051  1.1  itojun 		else
   1052  1.1  itojun 			domain[0] = 0;
   1053  1.1  itojun 	}
   1054  1.1  itojun 	cp = 0;
   1055  1.1  itojun 	if (!nflag && !IN6_IS_ADDR_UNSPECIFIED(in6p)) {
   1056  1.1  itojun 		hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6);
   1057  1.1  itojun 		if (hp) {
   1058  1.1  itojun 			if ((cp = index(hp->h_name, '.')) &&
   1059  1.1  itojun 			    !strcmp(cp + 1, domain))
   1060  1.1  itojun 				*cp = 0;
   1061  1.1  itojun 			cp = hp->h_name;
   1062  1.1  itojun 		}
   1063  1.1  itojun 	}
   1064  1.1  itojun 	if (IN6_IS_ADDR_UNSPECIFIED(in6p))
   1065  1.1  itojun 		strcpy(line, "*");
   1066  1.1  itojun 	else if (cp)
   1067  1.1  itojun 		strcpy(line, cp);
   1068  1.1  itojun 	else
   1069  1.1  itojun 		sprintf(line, "%s",
   1070  1.1  itojun 			inet_ntop(AF_INET6, (void *)in6p, ntop_buf,
   1071  1.1  itojun 				sizeof(ntop_buf)));
   1072  1.1  itojun 	return (line);
   1073  1.1  itojun }
   1074  1.1  itojun 
   1075  1.1  itojun #ifdef TCP6
   1076  1.1  itojun /*
   1077  1.1  itojun  * Dump the contents of a TCP6 PCB.
   1078  1.1  itojun  */
   1079  1.1  itojun void
   1080  1.1  itojun tcp6_dump(pcbaddr)
   1081  1.1  itojun 	u_long pcbaddr;
   1082  1.1  itojun {
   1083  1.1  itojun 	struct tcp6cb tcp6cb;
   1084  1.1  itojun 	int i;
   1085  1.1  itojun 
   1086  1.1  itojun 	kread(pcbaddr, (char *)&tcp6cb, sizeof(tcp6cb));
   1087  1.1  itojun 
   1088  1.1  itojun 	printf("TCP Protocol Control Block at 0x%08lx:\n\n", pcbaddr);
   1089  1.1  itojun 
   1090  1.1  itojun 	printf("Timers:\n");
   1091  1.1  itojun 	for (i = 0; i < TCP6T_NTIMERS; i++)
   1092  1.1  itojun 		printf("\t%s: %u", tcp6timers[i], tcp6cb.t_timer[i]);
   1093  1.1  itojun 	printf("\n\n");
   1094  1.1  itojun 
   1095  1.1  itojun 	if (tcp6cb.t_state < 0 || tcp6cb.t_state >= TCP6_NSTATES)
   1096  1.1  itojun 		printf("State: %d", tcp6cb.t_state);
   1097  1.1  itojun 	else
   1098  1.1  itojun 		printf("State: %s", tcp6states[tcp6cb.t_state]);
   1099  1.1  itojun 	printf(", flags 0x%x, in6pcb 0x%lx\n\n", tcp6cb.t_flags,
   1100  1.1  itojun 	    (u_long)tcp6cb.t_in6pcb);
   1101  1.1  itojun 
   1102  1.1  itojun 	printf("rxtshift %d, rxtcur %d, dupacks %d\n", tcp6cb.t_rxtshift,
   1103  1.1  itojun 	    tcp6cb.t_rxtcur, tcp6cb.t_dupacks);
   1104  1.1  itojun 	printf("peermaxseg %u, maxseg %u, force %d\n\n", tcp6cb.t_peermaxseg,
   1105  1.1  itojun 	    tcp6cb.t_maxseg, tcp6cb.t_force);
   1106  1.1  itojun 
   1107  1.1  itojun 	printf("snd_una %u, snd_nxt %u, snd_up %u\n",
   1108  1.1  itojun 	    tcp6cb.snd_una, tcp6cb.snd_nxt, tcp6cb.snd_up);
   1109  1.1  itojun 	printf("snd_wl1 %u, snd_wl2 %u, iss %u, snd_wnd %lu\n\n",
   1110  1.1  itojun 	    tcp6cb.snd_wl1, tcp6cb.snd_wl2, tcp6cb.iss, tcp6cb.snd_wnd);
   1111  1.1  itojun 
   1112  1.1  itojun 	printf("rcv_wnd %lu, rcv_nxt %u, rcv_up %u, irs %u\n\n",
   1113  1.1  itojun 	    tcp6cb.rcv_wnd, tcp6cb.rcv_nxt, tcp6cb.rcv_up, tcp6cb.irs);
   1114  1.1  itojun 
   1115  1.1  itojun 	printf("rcv_adv %u, snd_max %u, snd_cwnd %lu, snd_ssthresh %lu\n",
   1116  1.1  itojun 	    tcp6cb.rcv_adv, tcp6cb.snd_max, tcp6cb.snd_cwnd, tcp6cb.snd_ssthresh);
   1117  1.1  itojun 
   1118  1.1  itojun 	printf("idle %d, rtt %d, rtseq %u, srtt %d, rttvar %d, rttmin %d, "
   1119  1.1  itojun 	    "max_sndwnd %lu\n\n", tcp6cb.t_idle, tcp6cb.t_rtt, tcp6cb.t_rtseq,
   1120  1.1  itojun 	    tcp6cb.t_srtt, tcp6cb.t_rttvar, tcp6cb.t_rttmin, tcp6cb.max_sndwnd);
   1121  1.1  itojun 
   1122  1.1  itojun 	printf("oobflags %d, iobc %d, softerror %d\n\n", tcp6cb.t_oobflags,
   1123  1.1  itojun 	    tcp6cb.t_iobc, tcp6cb.t_softerror);
   1124  1.1  itojun 
   1125  1.1  itojun 	printf("snd_scale %d, rcv_scale %d, req_r_scale %d, req_s_scale %d\n",
   1126  1.1  itojun 	    tcp6cb.snd_scale, tcp6cb.rcv_scale, tcp6cb.request_r_scale,
   1127  1.1  itojun 	    tcp6cb.requested_s_scale);
   1128  1.1  itojun 	printf("ts_recent %u, ts_regent_age %d, last_ack_sent %u\n",
   1129  1.1  itojun 	    tcp6cb.ts_recent, tcp6cb.ts_recent_age, tcp6cb.last_ack_sent);
   1130  1.1  itojun }
   1131  1.1  itojun #endif
   1132  1.1  itojun 
   1133  1.1  itojun #endif /*INET6*/
   1134