inet6.c revision 1.8 1 /* $NetBSD: inet6.c,v 1.8 2000/05/17 11:54:48 itojun Exp $ */
2 /* BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp */
3
4 /*
5 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the project nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33 /*
34 * Copyright (c) 1983, 1988, 1993
35 * The Regents of the University of California. All rights reserved.
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 * must display the following acknowledgement:
47 * This product includes software developed by the University of
48 * California, Berkeley and its contributors.
49 * 4. Neither the name of the University nor the names of its contributors
50 * may be used to endorse or promote products derived from this software
51 * without specific prior written permission.
52 *
53 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE.
64 */
65
66 #include <sys/cdefs.h>
67 #ifndef lint
68 #if 0
69 static char sccsid[] = "@(#)inet.c 8.4 (Berkeley) 4/20/94";
70 #else
71 __RCSID("$NetBSD: inet6.c,v 1.8 2000/05/17 11:54:48 itojun Exp $");
72 #endif
73 #endif /* not lint */
74
75 #include <sys/param.h>
76 #include <sys/socket.h>
77 #include <sys/socketvar.h>
78 #include <sys/ioctl.h>
79 #include <sys/mbuf.h>
80 #include <sys/protosw.h>
81
82 #include <net/route.h>
83 #include <net/if.h>
84 #include <netinet/in.h>
85 #include <netinet/ip6.h>
86 #include <netinet/icmp6.h>
87 #include <netinet/in_systm.h>
88 #ifndef TCP6
89 #include <netinet/ip.h>
90 #include <netinet/ip_var.h>
91 #endif
92 #include <netinet6/ip6_var.h>
93 #include <netinet6/in6_pcb.h>
94 #include <netinet6/in6_var.h>
95 #include <netinet6/ip6_var.h>
96 #ifdef TCP6
97 #include <netinet6/tcp6.h>
98 #include <netinet6/tcp6_seq.h>
99 #define TCP6STATES
100 #include <netinet6/tcp6_fsm.h>
101 #define TCP6TIMERS
102 #include <netinet6/tcp6_timer.h>
103 #include <netinet6/tcp6_var.h>
104 #include <netinet6/tcp6_debug.h>
105 #else
106 #include <netinet/tcp.h>
107 #include <netinet/tcpip.h>
108 #include <netinet/tcp_seq.h>
109 /*#define TCPSTATES*/
110 #include <netinet/tcp_fsm.h>
111 extern char *tcpstates[];
112 /*#define TCPTIMERS*/
113 #include <netinet/tcp_timer.h>
114 #include <netinet/tcp_var.h>
115 #include <netinet/tcp_debug.h>
116 #endif /*TCP6*/
117 #include <netinet6/udp6.h>
118 #include <netinet6/udp6_var.h>
119 #include <netinet6/pim6_var.h>
120
121 #include <arpa/inet.h>
122 #if 0
123 #include "gethostbyname2.h"
124 #endif
125 #include <netdb.h>
126
127 #include <stdio.h>
128 #include <string.h>
129 #include <unistd.h>
130 #include "netstat.h"
131
132 #ifdef INET6
133
134 struct in6pcb in6pcb;
135 #ifdef TCP6
136 struct tcp6cb tcp6cb;
137 #else
138 struct tcpcb tcpcb;
139 #endif
140 struct socket sockb;
141
142 char *inet6name __P((struct in6_addr *));
143 void inet6print __P((struct in6_addr *, int, char *));
144
145 /*
146 * Print a summary of connections related to an Internet
147 * protocol. For TCP, also give state of connection.
148 * Listening processes (aflag) are suppressed unless the
149 * -a (all) flag is specified.
150 */
151 void
152 ip6protopr(off, name)
153 u_long off;
154 char *name;
155 {
156 struct in6pcb cb;
157 register struct in6pcb *prev, *next;
158 int istcp;
159 static int first = 1;
160
161 if (off == 0)
162 return;
163 istcp = strcmp(name, "tcp6") == 0;
164 kread(off, (char *)&cb, sizeof (struct in6pcb));
165 in6pcb = cb;
166 prev = (struct in6pcb *)off;
167 if (in6pcb.in6p_next == (struct in6pcb *)off)
168 return;
169 while (in6pcb.in6p_next != (struct in6pcb *)off) {
170 next = in6pcb.in6p_next;
171 kread((u_long)next, (char *)&in6pcb, sizeof (in6pcb));
172 if (in6pcb.in6p_prev != prev) {
173 printf("???\n");
174 break;
175 }
176 if (!aflag && IN6_IS_ADDR_UNSPECIFIED(&in6pcb.in6p_laddr)) {
177 prev = next;
178 continue;
179 }
180 kread((u_long)in6pcb.in6p_socket, (char *)&sockb, sizeof (sockb));
181 if (istcp) {
182 #ifdef TCP6
183 kread((u_long)in6pcb.in6p_ppcb,
184 (char *)&tcp6cb, sizeof (tcp6cb));
185 #else
186 kread((u_long)in6pcb.in6p_ppcb,
187 (char *)&tcpcb, sizeof (tcpcb));
188 #endif
189 }
190 if (first) {
191 printf("Active Internet6 connections");
192 if (aflag)
193 printf(" (including servers)");
194 putchar('\n');
195 if (Aflag)
196 printf("%-8.8s ", "PCB");
197 printf(Aflag ?
198 "%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s %s\n" :
199 "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n",
200 "Proto", "Recv-Q", "Send-Q",
201 "Local Address", "Foreign Address", "(state)");
202 first = 0;
203 }
204 if (Aflag) {
205 if (istcp)
206 printf("%8p ", in6pcb.in6p_ppcb);
207 else
208 printf("%8p ", next);
209 }
210 printf("%-5.5s %6ld %6ld ", name, sockb.so_rcv.sb_cc,
211 sockb.so_snd.sb_cc);
212 /* xxx */
213 inet6print(&in6pcb.in6p_laddr, (int)in6pcb.in6p_lport, name);
214 inet6print(&in6pcb.in6p_faddr, (int)in6pcb.in6p_fport, name);
215 if (istcp) {
216 #ifdef TCP6
217 if (tcp6cb.t_state < 0 || tcp6cb.t_state >= TCP6_NSTATES)
218 printf(" %d", tcp6cb.t_state);
219 else
220 printf(" %s", tcp6states[tcp6cb.t_state]);
221 #else
222 if (tcpcb.t_state < 0 || tcpcb.t_state >= TCP_NSTATES)
223 printf(" %d", tcpcb.t_state);
224 else
225 printf(" %s", tcpstates[tcpcb.t_state]);
226 #endif
227 }
228 putchar('\n');
229 prev = next;
230 }
231 }
232
233 #ifdef TCP6
234 /*
235 * Dump TCP6 statistics structure.
236 */
237 void
238 tcp6_stats(off, name)
239 u_long off;
240 char *name;
241 {
242 struct tcp6stat tcp6stat;
243
244 if (off == 0)
245 return;
246 printf ("%s:\n", name);
247 kread(off, (char *)&tcp6stat, sizeof (tcp6stat));
248
249 #define p(f, m) if (tcp6stat.f || sflag <= 1) \
250 printf(m, tcp6stat.f, plural(tcp6stat.f))
251 #define p2(f1, f2, m) if (tcp6stat.f1 || tcp6stat.f2 || sflag <= 1) \
252 printf(m, tcp6stat.f1, plural(tcp6stat.f1), tcp6stat.f2, plural(tcp6stat.f2))
253 #define p3(f, m) if (tcp6stat.f || sflag <= 1) \
254 printf(m, tcp6stat.f, plurales(tcp6stat.f))
255
256 p(tcp6s_sndtotal, "\t%ld packet%s sent\n");
257 p2(tcp6s_sndpack,tcp6s_sndbyte,
258 "\t\t%ld data packet%s (%ld byte%s)\n");
259 p2(tcp6s_sndrexmitpack, tcp6s_sndrexmitbyte,
260 "\t\t%ld data packet%s (%ld byte%s) retransmitted\n");
261 p2(tcp6s_sndacks, tcp6s_delack,
262 "\t\t%ld ack-only packet%s (%ld packet%s delayed)\n");
263 p(tcp6s_sndurg, "\t\t%ld URG only packet%s\n");
264 p(tcp6s_sndprobe, "\t\t%ld window probe packet%s\n");
265 p(tcp6s_sndwinup, "\t\t%ld window update packet%s\n");
266 p(tcp6s_sndctrl, "\t\t%ld control packet%s\n");
267 p(tcp6s_rcvtotal, "\t%ld packet%s received\n");
268 p2(tcp6s_rcvackpack, tcp6s_rcvackbyte, "\t\t%ld ack%s (for %ld byte%s)\n");
269 p(tcp6s_rcvdupack, "\t\t%ld duplicate ack%s\n");
270 p(tcp6s_rcvacktoomuch, "\t\t%ld ack%s for unsent data\n");
271 p2(tcp6s_rcvpack, tcp6s_rcvbyte,
272 "\t\t%ld packet%s (%ld byte%s) received in-sequence\n");
273 p2(tcp6s_rcvduppack, tcp6s_rcvdupbyte,
274 "\t\t%ld completely duplicate packet%s (%ld byte%s)\n");
275 p(tcp6s_pawsdrop, "\t\t%ld old duplicate packet%s\n");
276 p2(tcp6s_rcvpartduppack, tcp6s_rcvpartdupbyte,
277 "\t\t%ld packet%s with some dup. data (%ld byte%s duped)\n");
278 p2(tcp6s_rcvoopack, tcp6s_rcvoobyte,
279 "\t\t%ld out-of-order packet%s (%ld byte%s)\n");
280 p2(tcp6s_rcvpackafterwin, tcp6s_rcvbyteafterwin,
281 "\t\t%ld packet%s (%ld byte%s) of data after window\n");
282 p(tcp6s_rcvwinprobe, "\t\t%ld window probe%s\n");
283 p(tcp6s_rcvwinupd, "\t\t%ld window update packet%s\n");
284 p(tcp6s_rcvafterclose, "\t\t%ld packet%s received after close\n");
285 p(tcp6s_rcvbadsum, "\t\t%ld discarded for bad checksum%s\n");
286 p(tcp6s_rcvbadoff, "\t\t%ld discarded for bad header offset field%s\n");
287 p(tcp6s_rcvshort, "\t\t%ld discarded because packet%s too short\n");
288 p(tcp6s_connattempt, "\t%ld connection request%s\n");
289 p(tcp6s_accepts, "\t%ld connection accept%s\n");
290 p(tcp6s_badsyn, "\t%ld bad connection attempt%s\n");
291 p(tcp6s_connects, "\t%ld connection%s established (including accepts)\n");
292 p2(tcp6s_closed, tcp6s_drops,
293 "\t%ld connection%s closed (including %ld drop%s)\n");
294 p(tcp6s_conndrops, "\t%ld embryonic connection%s dropped\n");
295 p2(tcp6s_rttupdated, tcp6s_segstimed,
296 "\t%ld segment%s updated rtt (of %ld attempt%s)\n");
297 p(tcp6s_rexmttimeo, "\t%ld retransmit timeout%s\n");
298 p(tcp6s_timeoutdrop, "\t\t%ld connection%s dropped by rexmit timeout\n");
299 p(tcp6s_persisttimeo, "\t%ld persist timeout%s\n");
300 p(tcp6s_persistdrop, "\t%ld connection%s timed out in persist\n");
301 p(tcp6s_keeptimeo, "\t%ld keepalive timeout%s\n");
302 p(tcp6s_keepprobe, "\t\t%ld keepalive probe%s sent\n");
303 p(tcp6s_keepdrops, "\t\t%ld connection%s dropped by keepalive\n");
304 p(tcp6s_predack, "\t%ld correct ACK header prediction%s\n");
305 p(tcp6s_preddat, "\t%ld correct data packet header prediction%s\n");
306 p3(tcp6s_pcbcachemiss, "\t%ld PCB cache miss%s\n");
307 #undef p
308 #undef p2
309 #undef p3
310 }
311 #endif
312
313 /*
314 * Dump UDP6 statistics structure.
315 */
316 void
317 udp6_stats(off, name)
318 u_long off;
319 char *name;
320 {
321 struct udp6stat udp6stat;
322 u_quad_t delivered;
323
324 if (off == 0)
325 return;
326 kread(off, (char *)&udp6stat, sizeof (udp6stat));
327 printf("%s:\n", name);
328 #define p(f, m) if (udp6stat.f || sflag <= 1) \
329 printf(m, (unsigned long long)udp6stat.f, plural(udp6stat.f))
330 #define p1(f, m) if (udp6stat.f || sflag <= 1) \
331 printf(m, (unsigned long long)udp6stat.f)
332 p(udp6s_ipackets, "\t%llu datagram%s received\n");
333 p1(udp6s_hdrops, "\t%llu with incomplete header\n");
334 p1(udp6s_badlen, "\t%llu with bad data length field\n");
335 p1(udp6s_badsum, "\t%llu with bad checksum\n");
336 p1(udp6s_nosum, "\t%llu with no checksum\n");
337 p1(udp6s_noport, "\t%llu dropped due to no socket\n");
338 p(udp6s_noportmcast,
339 "\t%llu multicast datagram%s dropped due to no socket\n");
340 p1(udp6s_fullsock, "\t%llu dropped due to full socket buffers\n");
341 delivered = udp6stat.udp6s_ipackets -
342 udp6stat.udp6s_hdrops -
343 udp6stat.udp6s_badlen -
344 udp6stat.udp6s_badsum -
345 udp6stat.udp6s_noport -
346 udp6stat.udp6s_noportmcast -
347 udp6stat.udp6s_fullsock;
348 if (delivered || sflag <= 1)
349 printf("\t%llu delivered\n", (unsigned long long)delivered);
350 p(udp6s_opackets, "\t%llu datagram%s output\n");
351 #undef p
352 #undef p1
353 }
354
355 static char *ip6nh[] = {
356 "hop by hop",
357 "ICMP",
358 "IGMP",
359 "#3",
360 "IP",
361 "#5",
362 "TCP",
363 "#7",
364 "#8",
365 "#9",
366 "#10",
367 "#11",
368 "#12",
369 "#13",
370 "#14",
371 "#15",
372 "#16",
373 "UDP",
374 "#18",
375 "#19",
376 "#20",
377 "#21",
378 "IDP",
379 "#23",
380 "#24",
381 "#25",
382 "#26",
383 "#27",
384 "#28",
385 "TP",
386 "#30",
387 "#31",
388 "#32",
389 "#33",
390 "#34",
391 "#35",
392 "#36",
393 "#37",
394 "#38",
395 "#39",
396 "#40",
397 "IP6",
398 "#42",
399 "routing",
400 "fragment",
401 "#45",
402 "#46",
403 "#47",
404 "#48",
405 "#49",
406 "ESP",
407 "AH",
408 "#52",
409 "#53",
410 "#54",
411 "#55",
412 "#56",
413 "#57",
414 "ICMP6",
415 "no next header",
416 "destination option",
417 "#61",
418 "#62",
419 "#63",
420 "#64",
421 "#65",
422 "#66",
423 "#67",
424 "#68",
425 "#69",
426 "#70",
427 "#71",
428 "#72",
429 "#73",
430 "#74",
431 "#75",
432 "#76",
433 "#77",
434 "#78",
435 "#79",
436 "ISOIP",
437 "#81",
438 "#82",
439 "#83",
440 "#84",
441 "#85",
442 "#86",
443 "#87",
444 "#88",
445 "#89",
446 "#80",
447 "#91",
448 "#92",
449 "#93",
450 "#94",
451 "#95",
452 "#96",
453 "Ethernet",
454 "#98",
455 "#99",
456 "#100",
457 "#101",
458 "#102",
459 "PIM",
460 "#104",
461 "#105",
462 "#106",
463 "#107",
464 "#108",
465 "#109",
466 "#110",
467 "#111",
468 "#112",
469 "#113",
470 "#114",
471 "#115",
472 "#116",
473 "#117",
474 "#118",
475 "#119",
476 "#120",
477 "#121",
478 "#122",
479 "#123",
480 "#124",
481 "#125",
482 "#126",
483 "#127",
484 "#128",
485 "#129",
486 "#130",
487 "#131",
488 "#132",
489 "#133",
490 "#134",
491 "#135",
492 "#136",
493 "#137",
494 "#138",
495 "#139",
496 "#140",
497 "#141",
498 "#142",
499 "#143",
500 "#144",
501 "#145",
502 "#146",
503 "#147",
504 "#148",
505 "#149",
506 "#150",
507 "#151",
508 "#152",
509 "#153",
510 "#154",
511 "#155",
512 "#156",
513 "#157",
514 "#158",
515 "#159",
516 "#160",
517 "#161",
518 "#162",
519 "#163",
520 "#164",
521 "#165",
522 "#166",
523 "#167",
524 "#168",
525 "#169",
526 "#170",
527 "#171",
528 "#172",
529 "#173",
530 "#174",
531 "#175",
532 "#176",
533 "#177",
534 "#178",
535 "#179",
536 "#180",
537 "#181",
538 "#182",
539 "#183",
540 "#184",
541 "#185",
542 "#186",
543 "#187",
544 "#188",
545 "#189",
546 "#180",
547 "#191",
548 "#192",
549 "#193",
550 "#194",
551 "#195",
552 "#196",
553 "#197",
554 "#198",
555 "#199",
556 "#200",
557 "#201",
558 "#202",
559 "#203",
560 "#204",
561 "#205",
562 "#206",
563 "#207",
564 "#208",
565 "#209",
566 "#210",
567 "#211",
568 "#212",
569 "#213",
570 "#214",
571 "#215",
572 "#216",
573 "#217",
574 "#218",
575 "#219",
576 "#220",
577 "#221",
578 "#222",
579 "#223",
580 "#224",
581 "#225",
582 "#226",
583 "#227",
584 "#228",
585 "#229",
586 "#230",
587 "#231",
588 "#232",
589 "#233",
590 "#234",
591 "#235",
592 "#236",
593 "#237",
594 "#238",
595 "#239",
596 "#240",
597 "#241",
598 "#242",
599 "#243",
600 "#244",
601 "#245",
602 "#246",
603 "#247",
604 "#248",
605 "#249",
606 "#250",
607 "#251",
608 "#252",
609 "#253",
610 "#254",
611 "#255",
612 };
613
614 /*
615 * Dump IP6 statistics structure.
616 */
617 void
618 ip6_stats(off, name)
619 u_long off;
620 char *name;
621 {
622 struct ip6stat ip6stat;
623 int first, i;
624
625 if (off == 0)
626 return;
627
628 kread(off, (char *)&ip6stat, sizeof (ip6stat));
629 printf("%s:\n", name);
630
631 #define p(f, m) if (ip6stat.f || sflag <= 1) \
632 printf(m, (unsigned long long)ip6stat.f, plural(ip6stat.f))
633 #define p1(f, m) if (ip6stat.f || sflag <= 1) \
634 printf(m, (unsigned long long)ip6stat.f)
635
636 p(ip6s_total, "\t%llu total packet%s received\n");
637 p1(ip6s_toosmall, "\t%llu with size smaller than minimum\n");
638 p1(ip6s_tooshort, "\t%llu with data size < data length\n");
639 p1(ip6s_badoptions, "\t%llu with bad options\n");
640 p1(ip6s_badvers, "\t%llu with incorrect version number\n");
641 p(ip6s_fragments, "\t%llu fragment%s received\n");
642 p(ip6s_fragdropped,
643 "\t%llu fragment%s dropped (dup or out of space)\n");
644 p(ip6s_fragtimeout, "\t%llu fragment%s dropped after timeout\n");
645 p(ip6s_fragoverflow, "\t%llu fragment%s that exceeded limit\n");
646 p(ip6s_reassembled, "\t%llu packet%s reassembled ok\n");
647 p(ip6s_delivered, "\t%llu packet%s for this host\n");
648 p(ip6s_forward, "\t%llu packet%s forwarded\n");
649 p(ip6s_cantforward, "\t%llu packet%s not forwardable\n");
650 p(ip6s_redirectsent, "\t%llu redirect%s sent\n");
651 p(ip6s_localout, "\t%llu packet%s sent from this host\n");
652 p(ip6s_rawout, "\t%llu packet%s sent with fabricated ip header\n");
653 p(ip6s_odropped,
654 "\t%llu output packet%s dropped due to no bufs, etc.\n");
655 p(ip6s_noroute, "\t%llu output packet%s discarded due to no route\n");
656 p(ip6s_fragmented, "\t%llu output datagram%s fragmented\n");
657 p(ip6s_ofragments, "\t%llu fragment%s created\n");
658 p(ip6s_cantfrag, "\t%llu datagram%s that can't be fragmented\n");
659 p(ip6s_badscope, "\t%llu packet%s that violated scope rules\n");
660 p(ip6s_notmember, "\t%llu multicast packet%s which we don't join\n");
661 for (first = 1, i = 0; i < 256; i++)
662 if (ip6stat.ip6s_nxthist[i] != 0) {
663 if (first) {
664 printf("\tInput histogram:\n");
665 first = 0;
666 }
667 printf("\t\t%s: %llu\n", ip6nh[i],
668 (unsigned long long)ip6stat.ip6s_nxthist[i]);
669 }
670 printf("\tMbuf statics:\n");
671 printf("\t\t%llu one mbuf\n", (unsigned long long)ip6stat.ip6s_m1);
672 for (first = 1, i = 0; i < 32; i++) {
673 char ifbuf[IFNAMSIZ];
674 if (ip6stat.ip6s_m2m[i] != 0) {
675 if (first) {
676 printf("\t\ttwo or more mbuf:\n");
677 first = 0;
678 }
679 printf("\t\t\t%s = %llu\n",
680 if_indextoname(i, ifbuf),
681 (unsigned long long)ip6stat.ip6s_m2m[i]);
682 }
683 }
684 printf("\t\t%llu one ext mbuf\n",
685 (unsigned long long)ip6stat.ip6s_mext1);
686 printf("\t\t%llu two or more ext mbuf\n",
687 (unsigned long long)ip6stat.ip6s_mext2m);
688 p(ip6s_exthdrtoolong,
689 "\t%llu packet%s whose headers are not continuous\n");
690 p(ip6s_nogif, "\t%llu tunneling packet%s that can't find gif\n");
691 p(ip6s_toomanyhdr,
692 "\t%llu packet%s discarded due to too many headers\n");
693
694 if (ip6stat.ip6s_exthdrget || ip6stat.ip6s_exthdrget0) {
695 p(ip6s_exthdrget, "\t%llu use%s of IP6_EXTHDR_GET\n");
696 p(ip6s_exthdrget0, "\t%llu use%s of IP6_EXTHDR_GET0\n");
697 p(ip6s_pulldown, "\t%llu call%s to m_pulldown\n");
698 p(ip6s_pulldown_alloc,
699 "\t%llu mbuf allocation%s in m_pulldown\n");
700 if (ip6stat.ip6s_pulldown_copy != 1) {
701 p1(ip6s_pulldown_copy,
702 "\t%llu mbuf copies in m_pulldown\n");
703 } else {
704 p1(ip6s_pulldown_copy,
705 "\t%llu mbuf copy in m_pulldown\n");
706 }
707 p(ip6s_pullup, "\t%llu call%s to m_pullup\n");
708 p(ip6s_pullup_alloc, "\t%llu mbuf allocation%s in m_pullup\n");
709 if (ip6stat.ip6s_pullup_copy != 1) {
710 p1(ip6s_pullup_copy,
711 "\t%llu mbuf copies in m_pullup\n");
712 } else {
713 p1(ip6s_pullup_copy, "\t%llu mbuf copy in m_pullup\n");
714 }
715 p(ip6s_pullup_fail, "\t%llu failure%s in m_pullup\n");
716 p(ip6s_pullup2, "\t%llu call%s to m_pullup2\n");
717 p(ip6s_pullup2_alloc,
718 "\t%llu mbuf allocation%s in m_pullup2\n");
719 if (ip6stat.ip6s_pullup2_copy != 1) {
720 p1(ip6s_pullup2_copy,
721 "\t%llu mbuf copies in m_pullup2\n");
722 } else {
723 p1(ip6s_pullup2_copy,
724 "\t%llu mbuf copy in m_pullup2\n");
725 }
726 p(ip6s_pullup2_fail, "\t%llu failure%s in m_pullup2\n");
727 }
728
729 /* for debugging source address selection */
730 #define PRINT_SCOPESTAT(s,i) do {\
731 switch(i) { /* XXX hardcoding in each case */\
732 case 1:\
733 p(s, "\t\t%llu node-local%s\n");\
734 break;\
735 case 2:\
736 p(s, "\t\t%llu link-local%s\n");\
737 break;\
738 case 5:\
739 p(s, "\t\t%llu site-local%s\n");\
740 break;\
741 case 14:\
742 p(s, "\t\t%llu global%s\n");\
743 break;\
744 default:\
745 printf("\t\t%llu addresses scope=%x\n",\
746 (unsigned long long)ip6stat.s, i);\
747 }\
748 } while(0);
749
750 p(ip6s_sources_none,
751 "\t%llu failure%s of source address selection\n");
752 for (first = 1, i = 0; i < 16; i++) {
753 if (ip6stat.ip6s_sources_sameif[i]) {
754 if (first) {
755 printf("\tsource addresses on an outgoing I/F\n");
756 first = 0;
757 }
758 PRINT_SCOPESTAT(ip6s_sources_sameif[i], i);
759 }
760 }
761 for (first = 1, i = 0; i < 16; i++) {
762 if (ip6stat.ip6s_sources_otherif[i]) {
763 if (first) {
764 printf("\tsource addresses on a non-outgoing I/F\n");
765 first = 0;
766 }
767 PRINT_SCOPESTAT(ip6s_sources_otherif[i], i);
768 }
769 }
770 for (first = 1, i = 0; i < 16; i++) {
771 if (ip6stat.ip6s_sources_samescope[i]) {
772 if (first) {
773 printf("\tsource addresses of same scope\n");
774 first = 0;
775 }
776 PRINT_SCOPESTAT(ip6s_sources_samescope[i], i);
777 }
778 }
779 for (first = 1, i = 0; i < 16; i++) {
780 if (ip6stat.ip6s_sources_otherscope[i]) {
781 if (first) {
782 printf("\tsource addresses of a different scope\n");
783 first = 0;
784 }
785 PRINT_SCOPESTAT(ip6s_sources_otherscope[i], i);
786 }
787 }
788 for (first = 1, i = 0; i < 16; i++) {
789 if (ip6stat.ip6s_sources_deprecated[i]) {
790 if (first) {
791 printf("\tdeprecated source addresses\n");
792 first = 0;
793 }
794 PRINT_SCOPESTAT(ip6s_sources_deprecated[i], i);
795 }
796 }
797 #undef p
798 #undef p1
799 }
800
801 /*
802 * Dump IPv6 per-interface statistics based on RFC 2465.
803 */
804 void
805 ip6_ifstats(ifname)
806 char *ifname;
807 {
808 struct in6_ifreq ifr;
809 int s;
810 #define p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
811 printf(m, (unsigned long long)ifr.ifr_ifru.ifru_stat.f, \
812 plural(ifr.ifr_ifru.ifru_stat.f))
813 #define p_5(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
814 printf(m, ip6stat.f)
815
816 if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
817 perror("Warning: socket(AF_INET6)");
818 return;
819 }
820
821 strcpy(ifr.ifr_name, ifname);
822 printf("ip6 on %s:\n", ifr.ifr_name);
823
824 if (ioctl(s, SIOCGIFSTAT_IN6, (char *)&ifr) < 0) {
825 perror("Warning: ioctl(SIOCGIFSTAT_IN6)");
826 goto end;
827 }
828
829 p(ifs6_in_receive, "\t%llu total input datagram%s\n");
830 p(ifs6_in_hdrerr, "\t%llu datagram%s with invalid header received\n");
831 p(ifs6_in_toobig, "\t%llu datagram%s exceeded MTU received\n");
832 p(ifs6_in_noroute, "\t%llu datagram%s with no route received\n");
833 p(ifs6_in_addrerr, "\t%llu datagram%s with invalid dst received\n");
834 p(ifs6_in_truncated, "\t%llu truncated datagram%s received\n");
835 p(ifs6_in_protounknown, "\t%llu datagram%s with unknown proto received\n");
836 p(ifs6_in_discard, "\t%llu input datagram%s discarded\n");
837 p(ifs6_in_deliver,
838 "\t%llu datagram%s delivered to an upper layer protocol\n");
839 p(ifs6_out_forward, "\t%llu datagram%s forwarded to this interface\n");
840 p(ifs6_out_request,
841 "\t%llu datagram%s sent from an upper layer protocol\n");
842 p(ifs6_out_discard, "\t%llu total discarded output datagram%s\n");
843 p(ifs6_out_fragok, "\t%llu output datagram%s fragmented\n");
844 p(ifs6_out_fragfail, "\t%llu output datagram%s failed on fragment\n");
845 p(ifs6_out_fragcreat, "\t%llu output datagram%s succeeded on fragment\n");
846 p(ifs6_reass_reqd, "\t%llu incoming datagram%s fragmented\n");
847 p(ifs6_reass_ok, "\t%llu datagram%s reassembled\n");
848 p(ifs6_reass_fail, "\t%llu datagram%s failed on reassembling\n");
849 p(ifs6_in_mcast, "\t%llu multicast datagram%s received\n");
850 p(ifs6_out_mcast, "\t%llu multicast datagram%s sent\n");
851
852 end:
853 close(s);
854
855 #undef p
856 #undef p_5
857 }
858
859 static char *icmp6names[] = {
860 "#0",
861 "unreach",
862 "packet too big",
863 "time exceed",
864 "parameter problem",
865 "#5",
866 "#6",
867 "#7",
868 "#8",
869 "#9",
870 "#10",
871 "#11",
872 "#12",
873 "#13",
874 "#14",
875 "#15",
876 "#16",
877 "#17",
878 "#18",
879 "#19",
880 "#20",
881 "#21",
882 "#22",
883 "#23",
884 "#24",
885 "#25",
886 "#26",
887 "#27",
888 "#28",
889 "#29",
890 "#30",
891 "#31",
892 "#32",
893 "#33",
894 "#34",
895 "#35",
896 "#36",
897 "#37",
898 "#38",
899 "#39",
900 "#40",
901 "#41",
902 "#42",
903 "#43",
904 "#44",
905 "#45",
906 "#46",
907 "#47",
908 "#48",
909 "#49",
910 "#50",
911 "#51",
912 "#52",
913 "#53",
914 "#54",
915 "#55",
916 "#56",
917 "#57",
918 "#58",
919 "#59",
920 "#60",
921 "#61",
922 "#62",
923 "#63",
924 "#64",
925 "#65",
926 "#66",
927 "#67",
928 "#68",
929 "#69",
930 "#70",
931 "#71",
932 "#72",
933 "#73",
934 "#74",
935 "#75",
936 "#76",
937 "#77",
938 "#78",
939 "#79",
940 "#80",
941 "#81",
942 "#82",
943 "#83",
944 "#84",
945 "#85",
946 "#86",
947 "#87",
948 "#88",
949 "#89",
950 "#80",
951 "#91",
952 "#92",
953 "#93",
954 "#94",
955 "#95",
956 "#96",
957 "#97",
958 "#98",
959 "#99",
960 "#100",
961 "#101",
962 "#102",
963 "#103",
964 "#104",
965 "#105",
966 "#106",
967 "#107",
968 "#108",
969 "#109",
970 "#110",
971 "#111",
972 "#112",
973 "#113",
974 "#114",
975 "#115",
976 "#116",
977 "#117",
978 "#118",
979 "#119",
980 "#120",
981 "#121",
982 "#122",
983 "#123",
984 "#124",
985 "#125",
986 "#126",
987 "#127",
988 "echo",
989 "echo reply",
990 "multicast listener query",
991 "multicast listener report",
992 "multicast listener done",
993 "router solicitation",
994 "router advertisment",
995 "neighbor solicitation",
996 "neighbor advertisment",
997 "redirect",
998 "router renumbering",
999 "node information request",
1000 "node information reply",
1001 "#141",
1002 "#142",
1003 "#143",
1004 "#144",
1005 "#145",
1006 "#146",
1007 "#147",
1008 "#148",
1009 "#149",
1010 "#150",
1011 "#151",
1012 "#152",
1013 "#153",
1014 "#154",
1015 "#155",
1016 "#156",
1017 "#157",
1018 "#158",
1019 "#159",
1020 "#160",
1021 "#161",
1022 "#162",
1023 "#163",
1024 "#164",
1025 "#165",
1026 "#166",
1027 "#167",
1028 "#168",
1029 "#169",
1030 "#170",
1031 "#171",
1032 "#172",
1033 "#173",
1034 "#174",
1035 "#175",
1036 "#176",
1037 "#177",
1038 "#178",
1039 "#179",
1040 "#180",
1041 "#181",
1042 "#182",
1043 "#183",
1044 "#184",
1045 "#185",
1046 "#186",
1047 "#187",
1048 "#188",
1049 "#189",
1050 "#180",
1051 "#191",
1052 "#192",
1053 "#193",
1054 "#194",
1055 "#195",
1056 "#196",
1057 "#197",
1058 "#198",
1059 "#199",
1060 "#200",
1061 "#201",
1062 "#202",
1063 "#203",
1064 "#204",
1065 "#205",
1066 "#206",
1067 "#207",
1068 "#208",
1069 "#209",
1070 "#210",
1071 "#211",
1072 "#212",
1073 "#213",
1074 "#214",
1075 "#215",
1076 "#216",
1077 "#217",
1078 "#218",
1079 "#219",
1080 "#220",
1081 "#221",
1082 "#222",
1083 "#223",
1084 "#224",
1085 "#225",
1086 "#226",
1087 "#227",
1088 "#228",
1089 "#229",
1090 "#230",
1091 "#231",
1092 "#232",
1093 "#233",
1094 "#234",
1095 "#235",
1096 "#236",
1097 "#237",
1098 "#238",
1099 "#239",
1100 "#240",
1101 "#241",
1102 "#242",
1103 "#243",
1104 "#244",
1105 "#245",
1106 "#246",
1107 "#247",
1108 "#248",
1109 "#249",
1110 "#250",
1111 "#251",
1112 "#252",
1113 "#253",
1114 "#254",
1115 "#255",
1116 };
1117
1118 /*
1119 * Dump ICMPv6 statistics.
1120 */
1121 void
1122 icmp6_stats(off, name)
1123 u_long off;
1124 char *name;
1125 {
1126 struct icmp6stat icmp6stat;
1127 register int i, first;
1128
1129 if (off == 0)
1130 return;
1131 kread(off, (char *)&icmp6stat, sizeof (icmp6stat));
1132 printf("%s:\n", name);
1133
1134 #define p(f, m) if (icmp6stat.f || sflag <= 1) \
1135 printf(m, (unsigned long long)icmp6stat.f, plural(icmp6stat.f))
1136
1137 p(icp6s_error, "\t%llu call%s to icmp6_error\n");
1138 p(icp6s_canterror,
1139 "\t%llu error%s not generated because old message was icmp6 or so\n");
1140 for (first = 1, i = 0; i < 256; i++)
1141 if (icmp6stat.icp6s_outhist[i] != 0) {
1142 if (first) {
1143 printf("\tOutput histogram:\n");
1144 first = 0;
1145 }
1146 printf("\t\t%s: %llu\n", icmp6names[i],
1147 (unsigned long long)icmp6stat.icp6s_outhist[i]);
1148 }
1149 p(icp6s_badcode, "\t%llu message%s with bad code fields\n");
1150 p(icp6s_tooshort, "\t%llu message%s < minimum length\n");
1151 p(icp6s_checksum, "\t%llu bad checksum%s\n");
1152 p(icp6s_badlen, "\t%llu message%s with bad length\n");
1153 for (first = 1, i = 0; i < ICMP6_MAXTYPE; i++)
1154 if (icmp6stat.icp6s_inhist[i] != 0) {
1155 if (first) {
1156 printf("\tInput histogram:\n");
1157 first = 0;
1158 }
1159 printf("\t\t%s: %llu\n", icmp6names[i],
1160 (unsigned long long)icmp6stat.icp6s_inhist[i]);
1161 }
1162 p(icp6s_reflect, "\t%llu message response%s generated\n");
1163 p(icp6s_nd_toomanyopt, "\t%llu message%s with too many ND options\n");
1164 #undef p
1165 }
1166
1167 /*
1168 * Dump ICMPv6 per-interface statistics based on RFC 2466.
1169 */
1170 void
1171 icmp6_ifstats(ifname)
1172 char *ifname;
1173 {
1174 struct in6_ifreq ifr;
1175 int s;
1176 #define p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \
1177 printf(m, (unsigned long long)ifr.ifr_ifru.ifru_icmp6stat.f, \
1178 plural(ifr.ifr_ifru.ifru_icmp6stat.f))
1179
1180 if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
1181 perror("Warning: socket(AF_INET6)");
1182 return;
1183 }
1184
1185 strcpy(ifr.ifr_name, ifname);
1186 printf("icmp6 on %s:\n", ifr.ifr_name);
1187
1188 if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) {
1189 perror("Warning: ioctl(SIOCGIFSTAT_ICMP6)");
1190 goto end;
1191 }
1192
1193 p(ifs6_in_msg, "\t%llu total input message%s\n");
1194 p(ifs6_in_error, "\t%llu total input error message%s\n");
1195 p(ifs6_in_dstunreach, "\t%llu input destination unreachable error%s\n");
1196 p(ifs6_in_adminprohib, "\t%llu input administratively prohibited error%s\n");
1197 p(ifs6_in_timeexceed, "\t%llu input time exceeded error%s\n");
1198 p(ifs6_in_paramprob, "\t%llu input parameter problem error%s\n");
1199 p(ifs6_in_pkttoobig, "\t%llu input packet too big error%s\n");
1200 p(ifs6_in_echo, "\t%llu input echo request%s\n");
1201 p(ifs6_in_echoreply, "\t%llu input echo reply%s\n");
1202 p(ifs6_in_routersolicit, "\t%llu input router solicitation%s\n");
1203 p(ifs6_in_routeradvert, "\t%llu input router advertisement%s\n");
1204 p(ifs6_in_neighborsolicit, "\t%llu input neighbor solicitation%s\n");
1205 p(ifs6_in_neighboradvert, "\t%llu input neighbor advertisement%s\n");
1206 p(ifs6_in_redirect, "\t%llu input redirect%s\n");
1207 p(ifs6_in_mldquery, "\t%llu input MLD query%s\n");
1208 p(ifs6_in_mldreport, "\t%llu input MLD report%s\n");
1209 p(ifs6_in_mlddone, "\t%llu input MLD done%s\n");
1210
1211 p(ifs6_out_msg, "\t%llu total output message%s\n");
1212 p(ifs6_out_error, "\t%llu total output error message%s\n");
1213 p(ifs6_out_dstunreach, "\t%llu output destination unreachable error%s\n");
1214 p(ifs6_out_adminprohib, "\t%llu output administratively prohibited error%s\n");
1215 p(ifs6_out_timeexceed, "\t%llu output time exceeded error%s\n");
1216 p(ifs6_out_paramprob, "\t%llu output parameter problem error%s\n");
1217 p(ifs6_out_pkttoobig, "\t%llu output packet too big error%s\n");
1218 p(ifs6_out_echo, "\t%llu output echo request%s\n");
1219 p(ifs6_out_echoreply, "\t%llu output echo reply%s\n");
1220 p(ifs6_out_routersolicit, "\t%llu output router solicitation%s\n");
1221 p(ifs6_out_routeradvert, "\t%llu output router advertisement%s\n");
1222 p(ifs6_out_neighborsolicit, "\t%llu output neighbor solicitation%s\n");
1223 p(ifs6_out_neighboradvert, "\t%llu output neighbor advertisement%s\n");
1224 p(ifs6_out_redirect, "\t%llu output redirect%s\n");
1225 p(ifs6_out_mldquery, "\t%llu output MLD query%s\n");
1226 p(ifs6_out_mldreport, "\t%llu output MLD report%s\n");
1227 p(ifs6_out_mlddone, "\t%llu output MLD done%s\n");
1228
1229 end:
1230 close(s);
1231 #undef p
1232 }
1233
1234 /*
1235 * Dump PIM statistics structure.
1236 */
1237 void
1238 pim6_stats(off, name)
1239 u_long off;
1240 char *name;
1241 {
1242 struct pim6stat pim6stat;
1243
1244 if (off == 0)
1245 return;
1246 kread(off, (char *)&pim6stat, sizeof(pim6stat));
1247 printf("%s:\n", name);
1248
1249 #define p(f, m) if (pim6stat.f || sflag <= 1) \
1250 printf(m, (unsigned long long)pim6stat.f, plural(pim6stat.f))
1251 p(pim6s_rcv_total, "\t%llu message%s received\n");
1252 p(pim6s_rcv_tooshort, "\t%llu message%s received with too few bytes\n");
1253 p(pim6s_rcv_badsum, "\t%llu message%s received with bad checksum\n");
1254 p(pim6s_rcv_badversion, "\t%llu message%s received with bad version\n");
1255 p(pim6s_rcv_registers, "\t%llu register%s received\n");
1256 p(pim6s_rcv_badregisters, "\t%llu bad register%s received\n");
1257 p(pim6s_snd_registers, "\t%llu register%s sent\n");
1258 #undef p
1259 }
1260
1261 /*
1262 * Pretty print an Internet address (net address + port).
1263 * If the nflag was specified, use numbers instead of names.
1264 */
1265
1266 void
1267 inet6print(in6, port, proto)
1268 register struct in6_addr *in6;
1269 int port;
1270 char *proto;
1271 {
1272 #define GETSERVBYPORT6(port, proto, ret)\
1273 do {\
1274 if (strcmp((proto), "tcp6") == 0)\
1275 (ret) = getservbyport((int)(port), "tcp");\
1276 else if (strcmp((proto), "udp6") == 0)\
1277 (ret) = getservbyport((int)(port), "udp");\
1278 else\
1279 (ret) = getservbyport((int)(port), (proto));\
1280 } while (0)
1281 struct servent *sp = 0;
1282 char line[80], *cp;
1283 int width;
1284
1285 width = Aflag ? 12 : 16;
1286 if (vflag && width < strlen(inet6name(in6)))
1287 width = strlen(inet6name(in6));
1288 sprintf(line, "%.*s.", width, inet6name(in6));
1289 cp = index(line, '\0');
1290 if (!nflag && port)
1291 GETSERVBYPORT6(port, proto, sp);
1292 if (sp || port == 0)
1293 sprintf(cp, "%.8s", sp ? sp->s_name : "*");
1294 else
1295 sprintf(cp, "%d", ntohs((u_short)port));
1296 width = Aflag ? 18 : 22;
1297 if (vflag && width < strlen(line))
1298 width = strlen(line);
1299 printf(" %-*.*s", width, width, line);
1300 }
1301
1302 /*
1303 * Construct an Internet address representation.
1304 * If the nflag has been supplied, give
1305 * numeric value, otherwise try for symbolic name.
1306 */
1307
1308 char *
1309 inet6name(in6p)
1310 struct in6_addr *in6p;
1311 {
1312 register char *cp;
1313 static char line[50];
1314 struct hostent *hp;
1315 static char domain[MAXHOSTNAMELEN + 1];
1316 static int first = 1;
1317 char hbuf[NI_MAXHOST];
1318 struct sockaddr_in6 sin6;
1319 #ifdef KAME_SCOPEID
1320 const int niflag = NI_NUMERICHOST | NI_WITHSCOPEID;
1321 #else
1322 const int niflag = NI_NUMERICHOST;
1323 #endif
1324
1325 if (first && !nflag) {
1326 first = 0;
1327 if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
1328 (cp = index(domain, '.')))
1329 (void) strcpy(domain, cp + 1);
1330 else
1331 domain[0] = 0;
1332 }
1333 cp = 0;
1334 if (!nflag && !IN6_IS_ADDR_UNSPECIFIED(in6p)) {
1335 hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6);
1336 if (hp) {
1337 if ((cp = index(hp->h_name, '.')) &&
1338 !strcmp(cp + 1, domain))
1339 *cp = 0;
1340 cp = hp->h_name;
1341 }
1342 }
1343 if (IN6_IS_ADDR_UNSPECIFIED(in6p))
1344 strcpy(line, "*");
1345 else if (cp)
1346 strcpy(line, cp);
1347 else {
1348 memset(&sin6, 0, sizeof(sin6));
1349 sin6.sin6_len = sizeof(sin6);
1350 sin6.sin6_family = AF_INET6;
1351 sin6.sin6_addr = *in6p;
1352 #ifdef KAME_SCOPEID
1353 if (IN6_IS_ADDR_LINKLOCAL(in6p)) {
1354 sin6.sin6_scope_id =
1355 ntohs(*(u_int16_t *)&in6p->s6_addr[2]);
1356 sin6.sin6_addr.s6_addr[2] = 0;
1357 sin6.sin6_addr.s6_addr[3] = 0;
1358 }
1359 #endif
1360 if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,
1361 hbuf, sizeof(hbuf), NULL, 0, niflag))
1362 strcpy(hbuf, "?");
1363 sprintf(line, "%s", hbuf);
1364 }
1365 return (line);
1366 }
1367
1368 #ifdef TCP6
1369 /*
1370 * Dump the contents of a TCP6 PCB.
1371 */
1372 void
1373 tcp6_dump(pcbaddr)
1374 u_long pcbaddr;
1375 {
1376 struct tcp6cb tcp6cb;
1377 int i;
1378
1379 kread(pcbaddr, (char *)&tcp6cb, sizeof(tcp6cb));
1380
1381 printf("TCP Protocol Control Block at 0x%08lx:\n\n", pcbaddr);
1382
1383 printf("Timers:\n");
1384 for (i = 0; i < TCP6T_NTIMERS; i++)
1385 printf("\t%s: %u", tcp6timers[i], tcp6cb.t_timer[i]);
1386 printf("\n\n");
1387
1388 if (tcp6cb.t_state < 0 || tcp6cb.t_state >= TCP6_NSTATES)
1389 printf("State: %d", tcp6cb.t_state);
1390 else
1391 printf("State: %s", tcp6states[tcp6cb.t_state]);
1392 printf(", flags 0x%x, in6pcb 0x%lx\n\n", tcp6cb.t_flags,
1393 (u_long)tcp6cb.t_in6pcb);
1394
1395 printf("rxtshift %d, rxtcur %d, dupacks %d\n", tcp6cb.t_rxtshift,
1396 tcp6cb.t_rxtcur, tcp6cb.t_dupacks);
1397 printf("peermaxseg %u, maxseg %u, force %d\n\n", tcp6cb.t_peermaxseg,
1398 tcp6cb.t_maxseg, tcp6cb.t_force);
1399
1400 printf("snd_una %u, snd_nxt %u, snd_up %u\n",
1401 tcp6cb.snd_una, tcp6cb.snd_nxt, tcp6cb.snd_up);
1402 printf("snd_wl1 %u, snd_wl2 %u, iss %u, snd_wnd %llu\n\n",
1403 tcp6cb.snd_wl1, tcp6cb.snd_wl2, tcp6cb.iss,
1404 (unsigned long long)tcp6cb.snd_wnd);
1405
1406 printf("rcv_wnd %llu, rcv_nxt %u, rcv_up %u, irs %u\n\n",
1407 (unsigned long long)cp6cb.rcv_wnd, tcp6cb.rcv_nxt,
1408 tcp6cb.rcv_up, tcp6cb.irs);
1409
1410 printf("rcv_adv %u, snd_max %u, snd_cwnd %llu, snd_ssthresh %llu\n",
1411 tcp6cb.rcv_adv, tcp6cb.snd_max, (unsigned long long)tcp6cb.snd_cwnd,
1412 (unsigned long long)tcp6cb.snd_ssthresh);
1413
1414 printf("idle %d, rtt %d, rtseq %u, srtt %d, rttvar %d, rttmin %d, "
1415 "max_sndwnd %llu\n\n", tcp6cb.t_idle, tcp6cb.t_rtt, tcp6cb.t_rtseq,
1416 tcp6cb.t_srtt, tcp6cb.t_rttvar, tcp6cb.t_rttmin,
1417 (unsigned long long)tcp6cb.max_sndwnd);
1418
1419 printf("oobflags %d, iobc %d, softerror %d\n\n", tcp6cb.t_oobflags,
1420 tcp6cb.t_iobc, tcp6cb.t_softerror);
1421
1422 printf("snd_scale %d, rcv_scale %d, req_r_scale %d, req_s_scale %d\n",
1423 tcp6cb.snd_scale, tcp6cb.rcv_scale, tcp6cb.request_r_scale,
1424 tcp6cb.requested_s_scale);
1425 printf("ts_recent %u, ts_regent_age %d, last_ack_sent %u\n",
1426 tcp6cb.ts_recent, tcp6cb.ts_recent_age, tcp6cb.last_ack_sent);
1427 }
1428 #endif
1429
1430 #endif /*INET6*/
1431