inet6.c revision 1.10 1 /* $NetBSD: inet6.c,v 1.10 2000/07/06 12:40:19 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.10 2000/07/06 12:40:19 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 "OSPF",
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
798 p1(ip6s_forward_cachehit, "\t%llu forward cache hit\n");
799 p1(ip6s_forward_cachemiss, "\t%llu forward cache miss\n");
800 #undef p
801 #undef p1
802 }
803
804 /*
805 * Dump IPv6 per-interface statistics based on RFC 2465.
806 */
807 void
808 ip6_ifstats(ifname)
809 char *ifname;
810 {
811 struct in6_ifreq ifr;
812 int s;
813 #define p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
814 printf(m, (unsigned long long)ifr.ifr_ifru.ifru_stat.f, \
815 plural(ifr.ifr_ifru.ifru_stat.f))
816 #define p_5(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
817 printf(m, (unsigned long long)ip6stat.f)
818
819 if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
820 perror("Warning: socket(AF_INET6)");
821 return;
822 }
823
824 strcpy(ifr.ifr_name, ifname);
825 printf("ip6 on %s:\n", ifr.ifr_name);
826
827 if (ioctl(s, SIOCGIFSTAT_IN6, (char *)&ifr) < 0) {
828 perror("Warning: ioctl(SIOCGIFSTAT_IN6)");
829 goto end;
830 }
831
832 p(ifs6_in_receive, "\t%llu total input datagram%s\n");
833 p(ifs6_in_hdrerr, "\t%llu datagram%s with invalid header received\n");
834 p(ifs6_in_toobig, "\t%llu datagram%s exceeded MTU received\n");
835 p(ifs6_in_noroute, "\t%llu datagram%s with no route received\n");
836 p(ifs6_in_addrerr, "\t%llu datagram%s with invalid dst received\n");
837 p(ifs6_in_truncated, "\t%llu truncated datagram%s received\n");
838 p(ifs6_in_protounknown, "\t%llu datagram%s with unknown proto received\n");
839 p(ifs6_in_discard, "\t%llu input datagram%s discarded\n");
840 p(ifs6_in_deliver,
841 "\t%llu datagram%s delivered to an upper layer protocol\n");
842 p(ifs6_out_forward, "\t%llu datagram%s forwarded to this interface\n");
843 p(ifs6_out_request,
844 "\t%llu datagram%s sent from an upper layer protocol\n");
845 p(ifs6_out_discard, "\t%llu total discarded output datagram%s\n");
846 p(ifs6_out_fragok, "\t%llu output datagram%s fragmented\n");
847 p(ifs6_out_fragfail, "\t%llu output datagram%s failed on fragment\n");
848 p(ifs6_out_fragcreat, "\t%llu output datagram%s succeeded on fragment\n");
849 p(ifs6_reass_reqd, "\t%llu incoming datagram%s fragmented\n");
850 p(ifs6_reass_ok, "\t%llu datagram%s reassembled\n");
851 p(ifs6_reass_fail, "\t%llu datagram%s failed on reassembling\n");
852 p(ifs6_in_mcast, "\t%llu multicast datagram%s received\n");
853 p(ifs6_out_mcast, "\t%llu multicast datagram%s sent\n");
854
855 end:
856 close(s);
857
858 #undef p
859 #undef p_5
860 }
861
862 static char *icmp6names[] = {
863 "#0",
864 "unreach",
865 "packet too big",
866 "time exceed",
867 "parameter problem",
868 "#5",
869 "#6",
870 "#7",
871 "#8",
872 "#9",
873 "#10",
874 "#11",
875 "#12",
876 "#13",
877 "#14",
878 "#15",
879 "#16",
880 "#17",
881 "#18",
882 "#19",
883 "#20",
884 "#21",
885 "#22",
886 "#23",
887 "#24",
888 "#25",
889 "#26",
890 "#27",
891 "#28",
892 "#29",
893 "#30",
894 "#31",
895 "#32",
896 "#33",
897 "#34",
898 "#35",
899 "#36",
900 "#37",
901 "#38",
902 "#39",
903 "#40",
904 "#41",
905 "#42",
906 "#43",
907 "#44",
908 "#45",
909 "#46",
910 "#47",
911 "#48",
912 "#49",
913 "#50",
914 "#51",
915 "#52",
916 "#53",
917 "#54",
918 "#55",
919 "#56",
920 "#57",
921 "#58",
922 "#59",
923 "#60",
924 "#61",
925 "#62",
926 "#63",
927 "#64",
928 "#65",
929 "#66",
930 "#67",
931 "#68",
932 "#69",
933 "#70",
934 "#71",
935 "#72",
936 "#73",
937 "#74",
938 "#75",
939 "#76",
940 "#77",
941 "#78",
942 "#79",
943 "#80",
944 "#81",
945 "#82",
946 "#83",
947 "#84",
948 "#85",
949 "#86",
950 "#87",
951 "#88",
952 "#89",
953 "#80",
954 "#91",
955 "#92",
956 "#93",
957 "#94",
958 "#95",
959 "#96",
960 "#97",
961 "#98",
962 "#99",
963 "#100",
964 "#101",
965 "#102",
966 "#103",
967 "#104",
968 "#105",
969 "#106",
970 "#107",
971 "#108",
972 "#109",
973 "#110",
974 "#111",
975 "#112",
976 "#113",
977 "#114",
978 "#115",
979 "#116",
980 "#117",
981 "#118",
982 "#119",
983 "#120",
984 "#121",
985 "#122",
986 "#123",
987 "#124",
988 "#125",
989 "#126",
990 "#127",
991 "echo",
992 "echo reply",
993 "multicast listener query",
994 "multicast listener report",
995 "multicast listener done",
996 "router solicitation",
997 "router advertisment",
998 "neighbor solicitation",
999 "neighbor advertisment",
1000 "redirect",
1001 "router renumbering",
1002 "node information request",
1003 "node information reply",
1004 "#141",
1005 "#142",
1006 "#143",
1007 "#144",
1008 "#145",
1009 "#146",
1010 "#147",
1011 "#148",
1012 "#149",
1013 "#150",
1014 "#151",
1015 "#152",
1016 "#153",
1017 "#154",
1018 "#155",
1019 "#156",
1020 "#157",
1021 "#158",
1022 "#159",
1023 "#160",
1024 "#161",
1025 "#162",
1026 "#163",
1027 "#164",
1028 "#165",
1029 "#166",
1030 "#167",
1031 "#168",
1032 "#169",
1033 "#170",
1034 "#171",
1035 "#172",
1036 "#173",
1037 "#174",
1038 "#175",
1039 "#176",
1040 "#177",
1041 "#178",
1042 "#179",
1043 "#180",
1044 "#181",
1045 "#182",
1046 "#183",
1047 "#184",
1048 "#185",
1049 "#186",
1050 "#187",
1051 "#188",
1052 "#189",
1053 "#180",
1054 "#191",
1055 "#192",
1056 "#193",
1057 "#194",
1058 "#195",
1059 "#196",
1060 "#197",
1061 "#198",
1062 "#199",
1063 "#200",
1064 "#201",
1065 "#202",
1066 "#203",
1067 "#204",
1068 "#205",
1069 "#206",
1070 "#207",
1071 "#208",
1072 "#209",
1073 "#210",
1074 "#211",
1075 "#212",
1076 "#213",
1077 "#214",
1078 "#215",
1079 "#216",
1080 "#217",
1081 "#218",
1082 "#219",
1083 "#220",
1084 "#221",
1085 "#222",
1086 "#223",
1087 "#224",
1088 "#225",
1089 "#226",
1090 "#227",
1091 "#228",
1092 "#229",
1093 "#230",
1094 "#231",
1095 "#232",
1096 "#233",
1097 "#234",
1098 "#235",
1099 "#236",
1100 "#237",
1101 "#238",
1102 "#239",
1103 "#240",
1104 "#241",
1105 "#242",
1106 "#243",
1107 "#244",
1108 "#245",
1109 "#246",
1110 "#247",
1111 "#248",
1112 "#249",
1113 "#250",
1114 "#251",
1115 "#252",
1116 "#253",
1117 "#254",
1118 "#255",
1119 };
1120
1121 /*
1122 * Dump ICMPv6 statistics.
1123 */
1124 void
1125 icmp6_stats(off, name)
1126 u_long off;
1127 char *name;
1128 {
1129 struct icmp6stat icmp6stat;
1130 register int i, first;
1131
1132 if (off == 0)
1133 return;
1134 kread(off, (char *)&icmp6stat, sizeof (icmp6stat));
1135 printf("%s:\n", name);
1136
1137 #define p(f, m) if (icmp6stat.f || sflag <= 1) \
1138 printf(m, (unsigned long long)icmp6stat.f, plural(icmp6stat.f))
1139 #define p_5(f, m) if (icmp6stat.f || sflag <= 1) \
1140 printf(m, (unsigned long long)icmp6stat.f)
1141
1142 p(icp6s_error, "\t%llu call%s to icmp6_error\n");
1143 p(icp6s_canterror,
1144 "\t%llu error%s not generated because old message was icmp6 or so\n");
1145 p(icp6s_toofreq,
1146 "\t%llu error%s not generated because rate limitation\n");
1147 for (first = 1, i = 0; i < 256; i++)
1148 if (icmp6stat.icp6s_outhist[i] != 0) {
1149 if (first) {
1150 printf("\tOutput histogram:\n");
1151 first = 0;
1152 }
1153 printf("\t\t%s: %llu\n", icmp6names[i],
1154 (unsigned long long)icmp6stat.icp6s_outhist[i]);
1155 }
1156 p(icp6s_badcode, "\t%llu message%s with bad code fields\n");
1157 p(icp6s_tooshort, "\t%llu message%s < minimum length\n");
1158 p(icp6s_checksum, "\t%llu bad checksum%s\n");
1159 p(icp6s_badlen, "\t%llu message%s with bad length\n");
1160 for (first = 1, i = 0; i < ICMP6_MAXTYPE; i++)
1161 if (icmp6stat.icp6s_inhist[i] != 0) {
1162 if (first) {
1163 printf("\tInput histogram:\n");
1164 first = 0;
1165 }
1166 printf("\t\t%s: %llu\n", icmp6names[i],
1167 (unsigned long long)icmp6stat.icp6s_inhist[i]);
1168 }
1169 printf("\tHistogram of error messages to be generated:\n");
1170 p_5(icp6s_odst_unreach_noroute, "\t\t%llu no route\n");
1171 p_5(icp6s_odst_unreach_admin, "\t\t%llu administratively prohibited\n");
1172 p_5(icp6s_odst_unreach_beyondscope, "\t\t%llu beyond scope\n");
1173 p_5(icp6s_odst_unreach_addr, "\t\t%llu address unreachable\n");
1174 p_5(icp6s_odst_unreach_noport, "\t\t%llu port unreachable\n");
1175 p_5(icp6s_opacket_too_big, "\t\t%llu packet too big\n");
1176 p_5(icp6s_otime_exceed_transit, "\t\t%llu time exceed transit\n");
1177 p_5(icp6s_otime_exceed_reassembly, "\t\t%llu time exceed reassembly\n");
1178 p_5(icp6s_oparamprob_header, "\t\t%llu erroneous header field\n");
1179 p_5(icp6s_oparamprob_nextheader, "\t\t%llu unrecognized next header\n");
1180 p_5(icp6s_oparamprob_option, "\t\t%llu unrecognized option\n");
1181 p_5(icp6s_oredirect, "\t\t%llu redirect\n");
1182 p_5(icp6s_ounknown, "\t\t%llu unknown\n");
1183
1184 p(icp6s_reflect, "\t%llu message response%s generated\n");
1185 p(icp6s_nd_toomanyopt, "\t%llu message%s with too many ND options\n");
1186 #undef p
1187 #undef p_5
1188 }
1189
1190 /*
1191 * Dump ICMPv6 per-interface statistics based on RFC 2466.
1192 */
1193 void
1194 icmp6_ifstats(ifname)
1195 char *ifname;
1196 {
1197 struct in6_ifreq ifr;
1198 int s;
1199 #define p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \
1200 printf(m, (unsigned long long)ifr.ifr_ifru.ifru_icmp6stat.f, \
1201 plural(ifr.ifr_ifru.ifru_icmp6stat.f))
1202
1203 if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
1204 perror("Warning: socket(AF_INET6)");
1205 return;
1206 }
1207
1208 strcpy(ifr.ifr_name, ifname);
1209 printf("icmp6 on %s:\n", ifr.ifr_name);
1210
1211 if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) {
1212 perror("Warning: ioctl(SIOCGIFSTAT_ICMP6)");
1213 goto end;
1214 }
1215
1216 p(ifs6_in_msg, "\t%llu total input message%s\n");
1217 p(ifs6_in_error, "\t%llu total input error message%s\n");
1218 p(ifs6_in_dstunreach, "\t%llu input destination unreachable error%s\n");
1219 p(ifs6_in_adminprohib, "\t%llu input administratively prohibited error%s\n");
1220 p(ifs6_in_timeexceed, "\t%llu input time exceeded error%s\n");
1221 p(ifs6_in_paramprob, "\t%llu input parameter problem error%s\n");
1222 p(ifs6_in_pkttoobig, "\t%llu input packet too big error%s\n");
1223 p(ifs6_in_echo, "\t%llu input echo request%s\n");
1224 p(ifs6_in_echoreply, "\t%llu input echo reply%s\n");
1225 p(ifs6_in_routersolicit, "\t%llu input router solicitation%s\n");
1226 p(ifs6_in_routeradvert, "\t%llu input router advertisement%s\n");
1227 p(ifs6_in_neighborsolicit, "\t%llu input neighbor solicitation%s\n");
1228 p(ifs6_in_neighboradvert, "\t%llu input neighbor advertisement%s\n");
1229 p(ifs6_in_redirect, "\t%llu input redirect%s\n");
1230 p(ifs6_in_mldquery, "\t%llu input MLD query%s\n");
1231 p(ifs6_in_mldreport, "\t%llu input MLD report%s\n");
1232 p(ifs6_in_mlddone, "\t%llu input MLD done%s\n");
1233
1234 p(ifs6_out_msg, "\t%llu total output message%s\n");
1235 p(ifs6_out_error, "\t%llu total output error message%s\n");
1236 p(ifs6_out_dstunreach, "\t%llu output destination unreachable error%s\n");
1237 p(ifs6_out_adminprohib, "\t%llu output administratively prohibited error%s\n");
1238 p(ifs6_out_timeexceed, "\t%llu output time exceeded error%s\n");
1239 p(ifs6_out_paramprob, "\t%llu output parameter problem error%s\n");
1240 p(ifs6_out_pkttoobig, "\t%llu output packet too big error%s\n");
1241 p(ifs6_out_echo, "\t%llu output echo request%s\n");
1242 p(ifs6_out_echoreply, "\t%llu output echo reply%s\n");
1243 p(ifs6_out_routersolicit, "\t%llu output router solicitation%s\n");
1244 p(ifs6_out_routeradvert, "\t%llu output router advertisement%s\n");
1245 p(ifs6_out_neighborsolicit, "\t%llu output neighbor solicitation%s\n");
1246 p(ifs6_out_neighboradvert, "\t%llu output neighbor advertisement%s\n");
1247 p(ifs6_out_redirect, "\t%llu output redirect%s\n");
1248 p(ifs6_out_mldquery, "\t%llu output MLD query%s\n");
1249 p(ifs6_out_mldreport, "\t%llu output MLD report%s\n");
1250 p(ifs6_out_mlddone, "\t%llu output MLD done%s\n");
1251
1252 end:
1253 close(s);
1254 #undef p
1255 }
1256
1257 /*
1258 * Dump PIM statistics structure.
1259 */
1260 void
1261 pim6_stats(off, name)
1262 u_long off;
1263 char *name;
1264 {
1265 struct pim6stat pim6stat;
1266
1267 if (off == 0)
1268 return;
1269 kread(off, (char *)&pim6stat, sizeof(pim6stat));
1270 printf("%s:\n", name);
1271
1272 #define p(f, m) if (pim6stat.f || sflag <= 1) \
1273 printf(m, (unsigned long long)pim6stat.f, plural(pim6stat.f))
1274 p(pim6s_rcv_total, "\t%llu message%s received\n");
1275 p(pim6s_rcv_tooshort, "\t%llu message%s received with too few bytes\n");
1276 p(pim6s_rcv_badsum, "\t%llu message%s received with bad checksum\n");
1277 p(pim6s_rcv_badversion, "\t%llu message%s received with bad version\n");
1278 p(pim6s_rcv_registers, "\t%llu register%s received\n");
1279 p(pim6s_rcv_badregisters, "\t%llu bad register%s received\n");
1280 p(pim6s_snd_registers, "\t%llu register%s sent\n");
1281 #undef p
1282 }
1283
1284 /*
1285 * Pretty print an Internet address (net address + port).
1286 * If the nflag was specified, use numbers instead of names.
1287 */
1288
1289 void
1290 inet6print(in6, port, proto)
1291 register struct in6_addr *in6;
1292 int port;
1293 char *proto;
1294 {
1295 #define GETSERVBYPORT6(port, proto, ret)\
1296 do {\
1297 if (strcmp((proto), "tcp6") == 0)\
1298 (ret) = getservbyport((int)(port), "tcp");\
1299 else if (strcmp((proto), "udp6") == 0)\
1300 (ret) = getservbyport((int)(port), "udp");\
1301 else\
1302 (ret) = getservbyport((int)(port), (proto));\
1303 } while (0)
1304 struct servent *sp = 0;
1305 char line[80], *cp;
1306 int width;
1307
1308 width = Aflag ? 12 : 16;
1309 if (vflag && width < strlen(inet6name(in6)))
1310 width = strlen(inet6name(in6));
1311 sprintf(line, "%.*s.", width, inet6name(in6));
1312 cp = index(line, '\0');
1313 if (!nflag && port)
1314 GETSERVBYPORT6(port, proto, sp);
1315 if (sp || port == 0)
1316 sprintf(cp, "%.8s", sp ? sp->s_name : "*");
1317 else
1318 sprintf(cp, "%d", ntohs((u_short)port));
1319 width = Aflag ? 18 : 22;
1320 if (vflag && width < strlen(line))
1321 width = strlen(line);
1322 printf(" %-*.*s", width, width, line);
1323 }
1324
1325 /*
1326 * Construct an Internet address representation.
1327 * If the nflag has been supplied, give
1328 * numeric value, otherwise try for symbolic name.
1329 */
1330
1331 char *
1332 inet6name(in6p)
1333 struct in6_addr *in6p;
1334 {
1335 register char *cp;
1336 static char line[50];
1337 struct hostent *hp;
1338 static char domain[MAXHOSTNAMELEN + 1];
1339 static int first = 1;
1340 char hbuf[NI_MAXHOST];
1341 struct sockaddr_in6 sin6;
1342 #ifdef KAME_SCOPEID
1343 const int niflag = NI_NUMERICHOST | NI_WITHSCOPEID;
1344 #else
1345 const int niflag = NI_NUMERICHOST;
1346 #endif
1347
1348 if (first && !nflag) {
1349 first = 0;
1350 if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
1351 (cp = index(domain, '.')))
1352 (void) strcpy(domain, cp + 1);
1353 else
1354 domain[0] = 0;
1355 }
1356 cp = 0;
1357 if (!nflag && !IN6_IS_ADDR_UNSPECIFIED(in6p)) {
1358 hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6);
1359 if (hp) {
1360 if ((cp = index(hp->h_name, '.')) &&
1361 !strcmp(cp + 1, domain))
1362 *cp = 0;
1363 cp = hp->h_name;
1364 }
1365 }
1366 if (IN6_IS_ADDR_UNSPECIFIED(in6p))
1367 strcpy(line, "*");
1368 else if (cp)
1369 strcpy(line, cp);
1370 else {
1371 memset(&sin6, 0, sizeof(sin6));
1372 sin6.sin6_len = sizeof(sin6);
1373 sin6.sin6_family = AF_INET6;
1374 sin6.sin6_addr = *in6p;
1375 #ifdef KAME_SCOPEID
1376 if (IN6_IS_ADDR_LINKLOCAL(in6p)) {
1377 sin6.sin6_scope_id =
1378 ntohs(*(u_int16_t *)&in6p->s6_addr[2]);
1379 sin6.sin6_addr.s6_addr[2] = 0;
1380 sin6.sin6_addr.s6_addr[3] = 0;
1381 }
1382 #endif
1383 if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,
1384 hbuf, sizeof(hbuf), NULL, 0, niflag))
1385 strcpy(hbuf, "?");
1386 sprintf(line, "%s", hbuf);
1387 }
1388 return (line);
1389 }
1390
1391 #ifdef TCP6
1392 /*
1393 * Dump the contents of a TCP6 PCB.
1394 */
1395 void
1396 tcp6_dump(pcbaddr)
1397 u_long pcbaddr;
1398 {
1399 struct tcp6cb tcp6cb;
1400 int i;
1401
1402 kread(pcbaddr, (char *)&tcp6cb, sizeof(tcp6cb));
1403
1404 printf("TCP Protocol Control Block at 0x%08lx:\n\n", pcbaddr);
1405
1406 printf("Timers:\n");
1407 for (i = 0; i < TCP6T_NTIMERS; i++)
1408 printf("\t%s: %u", tcp6timers[i], tcp6cb.t_timer[i]);
1409 printf("\n\n");
1410
1411 if (tcp6cb.t_state < 0 || tcp6cb.t_state >= TCP6_NSTATES)
1412 printf("State: %d", tcp6cb.t_state);
1413 else
1414 printf("State: %s", tcp6states[tcp6cb.t_state]);
1415 printf(", flags 0x%x, in6pcb 0x%lx\n\n", tcp6cb.t_flags,
1416 (u_long)tcp6cb.t_in6pcb);
1417
1418 printf("rxtshift %d, rxtcur %d, dupacks %d\n", tcp6cb.t_rxtshift,
1419 tcp6cb.t_rxtcur, tcp6cb.t_dupacks);
1420 printf("peermaxseg %u, maxseg %u, force %d\n\n", tcp6cb.t_peermaxseg,
1421 tcp6cb.t_maxseg, tcp6cb.t_force);
1422
1423 printf("snd_una %u, snd_nxt %u, snd_up %u\n",
1424 tcp6cb.snd_una, tcp6cb.snd_nxt, tcp6cb.snd_up);
1425 printf("snd_wl1 %u, snd_wl2 %u, iss %u, snd_wnd %llu\n\n",
1426 tcp6cb.snd_wl1, tcp6cb.snd_wl2, tcp6cb.iss,
1427 (unsigned long long)tcp6cb.snd_wnd);
1428
1429 printf("rcv_wnd %llu, rcv_nxt %u, rcv_up %u, irs %u\n\n",
1430 (unsigned long long)cp6cb.rcv_wnd, tcp6cb.rcv_nxt,
1431 tcp6cb.rcv_up, tcp6cb.irs);
1432
1433 printf("rcv_adv %u, snd_max %u, snd_cwnd %llu, snd_ssthresh %llu\n",
1434 tcp6cb.rcv_adv, tcp6cb.snd_max, (unsigned long long)tcp6cb.snd_cwnd,
1435 (unsigned long long)tcp6cb.snd_ssthresh);
1436
1437 printf("idle %d, rtt %d, rtseq %u, srtt %d, rttvar %d, rttmin %d, "
1438 "max_sndwnd %llu\n\n", tcp6cb.t_idle, tcp6cb.t_rtt, tcp6cb.t_rtseq,
1439 tcp6cb.t_srtt, tcp6cb.t_rttvar, tcp6cb.t_rttmin,
1440 (unsigned long long)tcp6cb.max_sndwnd);
1441
1442 printf("oobflags %d, iobc %d, softerror %d\n\n", tcp6cb.t_oobflags,
1443 tcp6cb.t_iobc, tcp6cb.t_softerror);
1444
1445 printf("snd_scale %d, rcv_scale %d, req_r_scale %d, req_s_scale %d\n",
1446 tcp6cb.snd_scale, tcp6cb.rcv_scale, tcp6cb.request_r_scale,
1447 tcp6cb.requested_s_scale);
1448 printf("ts_recent %u, ts_regent_age %d, last_ack_sent %u\n",
1449 tcp6cb.ts_recent, tcp6cb.ts_recent_age, tcp6cb.last_ack_sent);
1450 }
1451 #endif
1452
1453 #endif /*INET6*/
1454