Annotation of src/usr.bin/netstat/inet6.c, Revision 1.20
1.20 ! deraadt 1: /* $OpenBSD: inet6.c,v 1.19 2002/02/19 18:38:02 mpech Exp $ */
1.1 itojun 2: /* BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp */
3: /*
4: * Copyright (c) 1983, 1988, 1993
5: * The Regents of the University of California. All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed by the University of
18: * California, Berkeley and its contributors.
19: * 4. Neither the name of the University nor the names of its contributors
20: * may be used to endorse or promote products derived from this software
21: * without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33: * SUCH DAMAGE.
34: */
35:
36: #include <sys/cdefs.h>
37: #ifndef lint
38: #if 0
39: static char sccsid[] = "@(#)inet.c 8.4 (Berkeley) 4/20/94";
40: #else
1.20 ! deraadt 41: /*__RCSID("$OpenBSD: inet6.c,v 1.19 2002/02/19 18:38:02 mpech Exp $");*/
1.5 itojun 42: /*__RCSID("KAME Id: inet6.c,v 1.10 2000/02/09 10:49:31 itojun Exp");*/
1.1 itojun 43: #endif
44: #endif /* not lint */
45:
46: #include <sys/param.h>
47: #include <sys/socket.h>
48: #include <sys/socketvar.h>
49: #include <sys/ioctl.h>
50: #include <sys/mbuf.h>
51: #include <sys/protosw.h>
52:
53: #include <net/route.h>
54: #include <net/if.h>
55: #include <netinet/in.h>
56: #include <netinet/ip6.h>
57: #include <netinet/icmp6.h>
58: #include <netinet/in_systm.h>
59: #ifndef TCP6
60: #include <netinet/ip.h>
61: #include <netinet/ip_var.h>
62: #endif
1.5 itojun 63: #include <netinet6/ip6_var.h>
1.1 itojun 64: #include <netinet6/in6_var.h>
65: #include <netinet6/pim6_var.h>
66:
67: #include <arpa/inet.h>
68: #if 0
69: #include "gethostbyname2.h"
70: #endif
71: #include <netdb.h>
72:
73: #include <stdio.h>
74: #include <string.h>
75: #include <unistd.h>
76: #include "netstat.h"
77:
78: #ifdef INET6
79:
80: struct socket sockb;
81:
1.18 millert 82: char *inet6name(struct in6_addr *);
83: void inet6print(struct in6_addr *, int, char *);
1.1 itojun 84:
85: static char *ip6nh[] = {
86: "hop by hop",
87: "ICMP",
88: "IGMP",
89: "#3",
90: "IP",
91: "#5",
92: "TCP",
93: "#7",
94: "#8",
95: "#9",
96: "#10",
97: "#11",
98: "#12",
99: "#13",
100: "#14",
101: "#15",
102: "#16",
103: "UDP",
104: "#18",
1.17 mickey 105: "#19",
1.1 itojun 106: "#20",
107: "#21",
108: "IDP",
109: "#23",
110: "#24",
111: "#25",
112: "#26",
113: "#27",
114: "#28",
1.17 mickey 115: "TP",
1.1 itojun 116: "#30",
117: "#31",
118: "#32",
119: "#33",
120: "#34",
121: "#35",
122: "#36",
123: "#37",
124: "#38",
1.17 mickey 125: "#39",
1.1 itojun 126: "#40",
127: "IP6",
128: "#42",
129: "routing",
130: "fragment",
131: "#45",
132: "#46",
133: "#47",
134: "#48",
1.17 mickey 135: "#49",
1.1 itojun 136: "ESP",
137: "AH",
138: "#52",
139: "#53",
140: "#54",
141: "#55",
142: "#56",
143: "#57",
144: "ICMP6",
1.17 mickey 145: "no next header",
1.1 itojun 146: "destination option",
147: "#61",
148: "#62",
149: "#63",
150: "#64",
151: "#65",
152: "#66",
153: "#67",
154: "#68",
1.17 mickey 155: "#69",
1.1 itojun 156: "#70",
157: "#71",
158: "#72",
159: "#73",
160: "#74",
161: "#75",
162: "#76",
163: "#77",
164: "#78",
1.17 mickey 165: "#79",
1.1 itojun 166: "ISOIP",
167: "#81",
168: "#82",
169: "#83",
170: "#84",
171: "#85",
172: "#86",
173: "#87",
174: "#88",
1.17 mickey 175: "OSPF",
1.1 itojun 176: "#80",
177: "#91",
178: "#92",
179: "#93",
180: "#94",
181: "#95",
182: "#96",
183: "Ethernet",
184: "#98",
1.17 mickey 185: "#99",
1.1 itojun 186: "#100",
187: "#101",
188: "#102",
189: "PIM",
190: "#104",
191: "#105",
192: "#106",
193: "#107",
194: "#108",
1.17 mickey 195: "#109",
1.1 itojun 196: "#110",
197: "#111",
198: "#112",
199: "#113",
200: "#114",
201: "#115",
202: "#116",
203: "#117",
204: "#118",
1.17 mickey 205: "#119",
1.1 itojun 206: "#120",
207: "#121",
208: "#122",
209: "#123",
210: "#124",
211: "#125",
212: "#126",
213: "#127",
214: "#128",
1.17 mickey 215: "#129",
1.1 itojun 216: "#130",
217: "#131",
218: "#132",
219: "#133",
220: "#134",
221: "#135",
222: "#136",
223: "#137",
224: "#138",
1.17 mickey 225: "#139",
1.1 itojun 226: "#140",
227: "#141",
228: "#142",
229: "#143",
230: "#144",
231: "#145",
232: "#146",
233: "#147",
234: "#148",
1.17 mickey 235: "#149",
1.1 itojun 236: "#150",
237: "#151",
238: "#152",
239: "#153",
240: "#154",
241: "#155",
242: "#156",
243: "#157",
244: "#158",
1.17 mickey 245: "#159",
1.1 itojun 246: "#160",
247: "#161",
248: "#162",
249: "#163",
250: "#164",
251: "#165",
252: "#166",
253: "#167",
254: "#168",
1.17 mickey 255: "#169",
1.1 itojun 256: "#170",
257: "#171",
258: "#172",
259: "#173",
260: "#174",
261: "#175",
262: "#176",
263: "#177",
264: "#178",
1.17 mickey 265: "#179",
1.1 itojun 266: "#180",
267: "#181",
268: "#182",
269: "#183",
270: "#184",
271: "#185",
272: "#186",
273: "#187",
274: "#188",
1.17 mickey 275: "#189",
1.1 itojun 276: "#180",
277: "#191",
278: "#192",
279: "#193",
280: "#194",
281: "#195",
282: "#196",
283: "#197",
284: "#198",
1.17 mickey 285: "#199",
1.1 itojun 286: "#200",
287: "#201",
288: "#202",
289: "#203",
290: "#204",
291: "#205",
292: "#206",
293: "#207",
294: "#208",
1.17 mickey 295: "#209",
1.1 itojun 296: "#210",
297: "#211",
298: "#212",
299: "#213",
300: "#214",
301: "#215",
302: "#216",
303: "#217",
304: "#218",
1.17 mickey 305: "#219",
1.1 itojun 306: "#220",
307: "#221",
308: "#222",
309: "#223",
310: "#224",
311: "#225",
312: "#226",
313: "#227",
314: "#228",
1.17 mickey 315: "#229",
1.1 itojun 316: "#230",
317: "#231",
318: "#232",
319: "#233",
320: "#234",
321: "#235",
322: "#236",
323: "#237",
324: "#238",
1.17 mickey 325: "#239",
1.1 itojun 326: "#240",
327: "#241",
328: "#242",
329: "#243",
330: "#244",
331: "#245",
332: "#246",
333: "#247",
334: "#248",
1.17 mickey 335: "#249",
1.1 itojun 336: "#250",
337: "#251",
338: "#252",
339: "#253",
340: "#254",
341: "#255",
342: };
343:
344: /*
345: * Dump IP6 statistics structure.
346: */
347: void
348: ip6_stats(off, name)
349: u_long off;
350: char *name;
351: {
352: struct ip6stat ip6stat;
353: int first, i;
1.14 itojun 354: struct protoent *ep;
355: const char *n;
1.1 itojun 356:
357: if (off == 0)
358: return;
359:
360: kread(off, (char *)&ip6stat, sizeof (ip6stat));
361: printf("%s:\n", name);
362:
363: #define p(f, m) if (ip6stat.f || sflag <= 1) \
1.20 ! deraadt 364: printf(m, (unsigned long long)ip6stat.f, plural(ip6stat.f))
1.1 itojun 365: #define p1(f, m) if (ip6stat.f || sflag <= 1) \
1.20 ! deraadt 366: printf(m, (unsigned long long)ip6stat.f)
1.1 itojun 367:
1.14 itojun 368: p(ip6s_total, "\t%llu total packet%s received\n");
369: p1(ip6s_toosmall, "\t%llu with size smaller than minimum\n");
370: p1(ip6s_tooshort, "\t%llu with data size < data length\n");
371: p1(ip6s_badoptions, "\t%llu with bad options\n");
372: p1(ip6s_badvers, "\t%llu with incorrect version number\n");
373: p(ip6s_fragments, "\t%llu fragment%s received\n");
374: p(ip6s_fragdropped,
375: "\t%llu fragment%s dropped (dup or out of space)\n");
376: p(ip6s_fragtimeout, "\t%llu fragment%s dropped after timeout\n");
377: p(ip6s_fragoverflow, "\t%llu fragment%s that exceeded limit\n");
378: p(ip6s_reassembled, "\t%llu packet%s reassembled ok\n");
379: p(ip6s_delivered, "\t%llu packet%s for this host\n");
380: p(ip6s_forward, "\t%llu packet%s forwarded\n");
381: p(ip6s_cantforward, "\t%llu packet%s not forwardable\n");
382: p(ip6s_redirectsent, "\t%llu redirect%s sent\n");
383: p(ip6s_localout, "\t%llu packet%s sent from this host\n");
384: p(ip6s_rawout, "\t%llu packet%s sent with fabricated ip header\n");
385: p(ip6s_odropped,
386: "\t%llu output packet%s dropped due to no bufs, etc.\n");
387: p(ip6s_noroute, "\t%llu output packet%s discarded due to no route\n");
388: p(ip6s_fragmented, "\t%llu output datagram%s fragmented\n");
389: p(ip6s_ofragments, "\t%llu fragment%s created\n");
390: p(ip6s_cantfrag, "\t%llu datagram%s that can't be fragmented\n");
391: p(ip6s_badscope, "\t%llu packet%s that violated scope rules\n");
392: p(ip6s_notmember, "\t%llu multicast packet%s which we don't join\n");
1.1 itojun 393: for (first = 1, i = 0; i < 256; i++)
394: if (ip6stat.ip6s_nxthist[i] != 0) {
395: if (first) {
1.3 itojun 396: printf("\tInput packet histogram:\n");
1.1 itojun 397: first = 0;
398: }
1.14 itojun 399: n = NULL;
400: if (ip6nh[i])
401: n = ip6nh[i];
402: else if ((ep = getprotobynumber(i)) != NULL)
403: n = ep->p_name;
404: if (n)
405: printf("\t\t%s: %llu\n", n,
406: (unsigned long long)ip6stat.ip6s_nxthist[i]);
407: else
408: printf("\t\t#%d: %llu\n", i,
409: (unsigned long long)ip6stat.ip6s_nxthist[i]);
1.1 itojun 410: }
1.10 itojun 411: printf("\tMbuf statistics:\n");
1.14 itojun 412: p(ip6s_m1, "\t\t%llu one mbuf%s\n");
1.1 itojun 413: for (first = 1, i = 0; i < 32; i++) {
414: char ifbuf[IFNAMSIZ];
1.17 mickey 415: if (ip6stat.ip6s_m2m[i] != 0) {
1.1 itojun 416: if (first) {
417: printf("\t\ttwo or more mbuf:\n");
418: first = 0;
419: }
1.14 itojun 420: printf("\t\t\t%s = %llu\n",
1.20 ! deraadt 421: if_indextoname(i, ifbuf),
! 422: (unsigned long long)ip6stat.ip6s_m2m[i]);
1.1 itojun 423: }
424: }
1.14 itojun 425: p(ip6s_mext1, "\t\t%llu one ext mbuf%s\n");
426: p(ip6s_mext2m, "\t\t%llu two or more ext mbuf%s\n");
427: p(ip6s_exthdrtoolong,
428: "\t%llu packet%s whose headers are not continuous\n");
429: p(ip6s_nogif, "\t%llu tunneling packet%s that can't find gif\n");
430: p(ip6s_toomanyhdr,
431: "\t%llu packet%s discarded due to too many headers\n");
1.5 itojun 432:
433: /* for debugging source address selection */
434: #define PRINT_SCOPESTAT(s,i) do {\
435: switch(i) { /* XXX hardcoding in each case */\
436: case 1:\
1.14 itojun 437: p(s, "\t\t%llu node-local%s\n");\
1.5 itojun 438: break;\
439: case 2:\
1.14 itojun 440: p(s, "\t\t%llu link-local%s\n");\
1.5 itojun 441: break;\
442: case 5:\
1.14 itojun 443: p(s, "\t\t%llu site-local%s\n");\
1.5 itojun 444: break;\
445: case 14:\
1.14 itojun 446: p(s, "\t\t%llu global%s\n");\
1.5 itojun 447: break;\
448: default:\
1.14 itojun 449: printf("\t\t%llu addresses scope=%x\n",\
1.20 ! deraadt 450: (unsigned long long)ip6stat.s, i);\
1.5 itojun 451: }\
452: } while(0);
453:
454: p(ip6s_sources_none,
1.20 ! deraadt 455: "\t%llu failure%s of source address selection\n");
1.5 itojun 456: for (first = 1, i = 0; i < 16; i++) {
457: if (ip6stat.ip6s_sources_sameif[i]) {
458: if (first) {
459: printf("\tsource addresses on an outgoing I/F\n");
460: first = 0;
461: }
462: PRINT_SCOPESTAT(ip6s_sources_sameif[i], i);
463: }
464: }
465: for (first = 1, i = 0; i < 16; i++) {
466: if (ip6stat.ip6s_sources_otherif[i]) {
467: if (first) {
468: printf("\tsource addresses on a non-outgoing I/F\n");
469: first = 0;
470: }
471: PRINT_SCOPESTAT(ip6s_sources_otherif[i], i);
472: }
473: }
474: for (first = 1, i = 0; i < 16; i++) {
475: if (ip6stat.ip6s_sources_samescope[i]) {
476: if (first) {
477: printf("\tsource addresses of same scope\n");
478: first = 0;
479: }
480: PRINT_SCOPESTAT(ip6s_sources_samescope[i], i);
481: }
482: }
483: for (first = 1, i = 0; i < 16; i++) {
484: if (ip6stat.ip6s_sources_otherscope[i]) {
485: if (first) {
486: printf("\tsource addresses of a different scope\n");
487: first = 0;
488: }
489: PRINT_SCOPESTAT(ip6s_sources_otherscope[i], i);
490: }
491: }
492: for (first = 1, i = 0; i < 16; i++) {
493: if (ip6stat.ip6s_sources_deprecated[i]) {
494: if (first) {
495: printf("\tdeprecated source addresses\n");
496: first = 0;
497: }
498: PRINT_SCOPESTAT(ip6s_sources_deprecated[i], i);
499: }
500: }
1.8 itojun 501:
502: p1(ip6s_forward_cachehit, "\t%llu forward cache hit\n");
503: p1(ip6s_forward_cachemiss, "\t%llu forward cache miss\n");
1.1 itojun 504: #undef p
505: #undef p1
506: }
507:
508: /*
509: * Dump IPv6 per-interface statistics based on RFC 2465.
510: */
511: void
512: ip6_ifstats(ifname)
513: char *ifname;
514: {
515: struct in6_ifreq ifr;
516: int s;
1.20 ! deraadt 517:
1.1 itojun 518: #define p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
1.20 ! deraadt 519: printf(m, (unsigned long long)ifr.ifr_ifru.ifru_stat.f, \
! 520: plural(ifr.ifr_ifru.ifru_stat.f))
1.1 itojun 521: #define p_5(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
1.20 ! deraadt 522: printf(m, (unsigned long long)ip6stat.f)
1.1 itojun 523:
524: if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
525: perror("Warning: socket(AF_INET6)");
526: return;
527: }
528:
1.20 ! deraadt 529: strlcpy(ifr.ifr_name, ifname, sizeof ifr.ifr_name);
1.1 itojun 530: printf("ip6 on %s:\n", ifr.ifr_name);
531:
532: if (ioctl(s, SIOCGIFSTAT_IN6, (char *)&ifr) < 0) {
533: perror("Warning: ioctl(SIOCGIFSTAT_IN6)");
534: goto end;
535: }
536:
1.14 itojun 537: p(ifs6_in_receive, "\t%llu total input datagram%s\n");
538: p(ifs6_in_hdrerr, "\t%llu datagram%s with invalid header received\n");
539: p(ifs6_in_toobig, "\t%llu datagram%s exceeded MTU received\n");
540: p(ifs6_in_noroute, "\t%llu datagram%s with no route received\n");
541: p(ifs6_in_addrerr, "\t%llu datagram%s with invalid dst received\n");
542: p(ifs6_in_truncated, "\t%llu truncated datagram%s received\n");
543: p(ifs6_in_protounknown, "\t%llu datagram%s with unknown proto received\n");
544: p(ifs6_in_discard, "\t%llu input datagram%s discarded\n");
1.1 itojun 545: p(ifs6_in_deliver,
1.20 ! deraadt 546: "\t%llu datagram%s delivered to an upper layer protocol\n");
1.14 itojun 547: p(ifs6_out_forward, "\t%llu datagram%s forwarded to this interface\n");
1.1 itojun 548: p(ifs6_out_request,
1.20 ! deraadt 549: "\t%llu datagram%s sent from an upper layer protocol\n");
1.14 itojun 550: p(ifs6_out_discard, "\t%llu total discarded output datagram%s\n");
551: p(ifs6_out_fragok, "\t%llu output datagram%s fragmented\n");
552: p(ifs6_out_fragfail, "\t%llu output datagram%s failed on fragment\n");
553: p(ifs6_out_fragcreat, "\t%llu output datagram%s succeeded on fragment\n");
554: p(ifs6_reass_reqd, "\t%llu incoming datagram%s fragmented\n");
555: p(ifs6_reass_ok, "\t%llu datagram%s reassembled\n");
556: p(ifs6_reass_fail, "\t%llu datagram%s failed on reassembling\n");
557: p(ifs6_in_mcast, "\t%llu multicast datagram%s received\n");
558: p(ifs6_out_mcast, "\t%llu multicast datagram%s sent\n");
1.1 itojun 559:
560: end:
561: close(s);
562:
563: #undef p
564: #undef p_5
565: }
566:
567: static char *icmp6names[] = {
568: "#0",
569: "unreach",
570: "packet too big",
571: "time exceed",
572: "parameter problem",
573: "#5",
574: "#6",
575: "#7",
576: "#8",
577: "#9",
578: "#10",
579: "#11",
580: "#12",
581: "#13",
582: "#14",
583: "#15",
584: "#16",
585: "#17",
586: "#18",
1.17 mickey 587: "#19",
1.1 itojun 588: "#20",
589: "#21",
590: "#22",
591: "#23",
592: "#24",
593: "#25",
594: "#26",
595: "#27",
596: "#28",
1.17 mickey 597: "#29",
1.1 itojun 598: "#30",
599: "#31",
600: "#32",
601: "#33",
602: "#34",
603: "#35",
604: "#36",
605: "#37",
606: "#38",
1.17 mickey 607: "#39",
1.1 itojun 608: "#40",
609: "#41",
610: "#42",
611: "#43",
612: "#44",
613: "#45",
614: "#46",
615: "#47",
616: "#48",
1.17 mickey 617: "#49",
1.1 itojun 618: "#50",
619: "#51",
620: "#52",
621: "#53",
622: "#54",
623: "#55",
624: "#56",
625: "#57",
626: "#58",
1.17 mickey 627: "#59",
1.1 itojun 628: "#60",
629: "#61",
630: "#62",
631: "#63",
632: "#64",
633: "#65",
634: "#66",
635: "#67",
636: "#68",
1.17 mickey 637: "#69",
1.1 itojun 638: "#70",
639: "#71",
640: "#72",
641: "#73",
642: "#74",
643: "#75",
644: "#76",
645: "#77",
646: "#78",
1.17 mickey 647: "#79",
1.1 itojun 648: "#80",
649: "#81",
650: "#82",
651: "#83",
652: "#84",
653: "#85",
654: "#86",
655: "#87",
656: "#88",
1.17 mickey 657: "#89",
1.1 itojun 658: "#80",
659: "#91",
660: "#92",
661: "#93",
662: "#94",
663: "#95",
664: "#96",
665: "#97",
666: "#98",
1.17 mickey 667: "#99",
1.1 itojun 668: "#100",
669: "#101",
670: "#102",
671: "#103",
672: "#104",
673: "#105",
674: "#106",
675: "#107",
676: "#108",
1.17 mickey 677: "#109",
1.1 itojun 678: "#110",
679: "#111",
680: "#112",
681: "#113",
682: "#114",
683: "#115",
684: "#116",
685: "#117",
686: "#118",
1.17 mickey 687: "#119",
1.1 itojun 688: "#120",
689: "#121",
690: "#122",
691: "#123",
692: "#124",
693: "#125",
694: "#126",
695: "#127",
696: "echo",
1.17 mickey 697: "echo reply",
1.1 itojun 698: "multicast listener query",
699: "multicast listener report",
700: "multicast listener done",
701: "router solicitation",
1.15 itojun 702: "router advertisement",
1.1 itojun 703: "neighbor solicitation",
1.15 itojun 704: "neighbor advertisement",
1.1 itojun 705: "redirect",
706: "router renumbering",
707: "node information request",
708: "node information reply",
709: "#141",
710: "#142",
711: "#143",
712: "#144",
713: "#145",
714: "#146",
715: "#147",
716: "#148",
1.17 mickey 717: "#149",
1.1 itojun 718: "#150",
719: "#151",
720: "#152",
721: "#153",
722: "#154",
723: "#155",
724: "#156",
725: "#157",
726: "#158",
1.17 mickey 727: "#159",
1.1 itojun 728: "#160",
729: "#161",
730: "#162",
731: "#163",
732: "#164",
733: "#165",
734: "#166",
735: "#167",
736: "#168",
1.17 mickey 737: "#169",
1.1 itojun 738: "#170",
739: "#171",
740: "#172",
741: "#173",
742: "#174",
743: "#175",
744: "#176",
745: "#177",
746: "#178",
1.17 mickey 747: "#179",
1.1 itojun 748: "#180",
749: "#181",
750: "#182",
751: "#183",
752: "#184",
753: "#185",
754: "#186",
755: "#187",
756: "#188",
1.17 mickey 757: "#189",
1.1 itojun 758: "#180",
759: "#191",
760: "#192",
761: "#193",
762: "#194",
763: "#195",
764: "#196",
765: "#197",
766: "#198",
1.17 mickey 767: "#199",
1.1 itojun 768: "#200",
769: "#201",
770: "#202",
771: "#203",
772: "#204",
773: "#205",
774: "#206",
775: "#207",
776: "#208",
1.17 mickey 777: "#209",
1.1 itojun 778: "#210",
779: "#211",
780: "#212",
781: "#213",
782: "#214",
783: "#215",
784: "#216",
785: "#217",
786: "#218",
1.17 mickey 787: "#219",
1.1 itojun 788: "#220",
789: "#221",
790: "#222",
791: "#223",
792: "#224",
793: "#225",
794: "#226",
795: "#227",
796: "#228",
1.17 mickey 797: "#229",
1.1 itojun 798: "#230",
799: "#231",
800: "#232",
801: "#233",
802: "#234",
803: "#235",
804: "#236",
805: "#237",
806: "#238",
1.17 mickey 807: "#239",
1.1 itojun 808: "#240",
809: "#241",
810: "#242",
811: "#243",
812: "#244",
813: "#245",
814: "#246",
815: "#247",
816: "#248",
1.17 mickey 817: "#249",
1.1 itojun 818: "#250",
819: "#251",
820: "#252",
821: "#253",
822: "#254",
823: "#255",
824: };
825:
826: /*
827: * Dump ICMPv6 statistics.
828: */
829: void
830: icmp6_stats(off, name)
831: u_long off;
832: char *name;
833: {
834: struct icmp6stat icmp6stat;
1.16 mpech 835: int i, first;
1.1 itojun 836:
837: if (off == 0)
838: return;
839: kread(off, (char *)&icmp6stat, sizeof (icmp6stat));
840: printf("%s:\n", name);
841:
842: #define p(f, m) if (icmp6stat.f || sflag <= 1) \
1.20 ! deraadt 843: printf(m, (unsigned long long)icmp6stat.f, plural(icmp6stat.f))
1.8 itojun 844: #define p_5(f, m) if (icmp6stat.f || sflag <= 1) \
1.20 ! deraadt 845: printf(m, (unsigned long long)icmp6stat.f)
1.1 itojun 846:
1.14 itojun 847: p(icp6s_error, "\t%llu call%s to icmp6_error\n");
1.1 itojun 848: p(icp6s_canterror,
1.14 itojun 849: "\t%llu error%s not generated because old message was icmp6 or so\n");
1.7 itojun 850: p(icp6s_toofreq,
1.14 itojun 851: "\t%llu error%s not generated because of rate limitation\n");
1.1 itojun 852: for (first = 1, i = 0; i < 256; i++)
853: if (icmp6stat.icp6s_outhist[i] != 0) {
854: if (first) {
1.3 itojun 855: printf("\tOutput packet histogram:\n");
1.1 itojun 856: first = 0;
857: }
1.14 itojun 858: printf("\t\t%s: %llu\n", icmp6names[i],
859: (unsigned long long)icmp6stat.icp6s_outhist[i]);
1.1 itojun 860: }
1.14 itojun 861: p(icp6s_badcode, "\t%llu message%s with bad code fields\n");
862: p(icp6s_tooshort, "\t%llu message%s < minimum length\n");
863: p(icp6s_checksum, "\t%llu bad checksum%s\n");
864: p(icp6s_badlen, "\t%llu message%s with bad length\n");
1.1 itojun 865: for (first = 1, i = 0; i < ICMP6_MAXTYPE; i++)
866: if (icmp6stat.icp6s_inhist[i] != 0) {
867: if (first) {
1.3 itojun 868: printf("\tInput packet histogram:\n");
1.1 itojun 869: first = 0;
870: }
1.14 itojun 871: printf("\t\t%s: %llu\n", icmp6names[i],
872: (unsigned long long)icmp6stat.icp6s_inhist[i]);
1.1 itojun 873: }
1.8 itojun 874: printf("\tHistogram of error messages to be generated:\n");
1.14 itojun 875: p_5(icp6s_odst_unreach_noroute, "\t\t%llu no route\n");
876: p_5(icp6s_odst_unreach_admin, "\t\t%llu administratively prohibited\n");
877: p_5(icp6s_odst_unreach_beyondscope, "\t\t%llu beyond scope\n");
878: p_5(icp6s_odst_unreach_addr, "\t\t%llu address unreachable\n");
879: p_5(icp6s_odst_unreach_noport, "\t\t%llu port unreachable\n");
880: p_5(icp6s_opacket_too_big, "\t\t%llu packet too big\n");
881: p_5(icp6s_otime_exceed_transit, "\t\t%llu time exceed transit\n");
882: p_5(icp6s_otime_exceed_reassembly, "\t\t%llu time exceed reassembly\n");
883: p_5(icp6s_oparamprob_header, "\t\t%llu erroneous header field\n");
884: p_5(icp6s_oparamprob_nextheader, "\t\t%llu unrecognized next header\n");
885: p_5(icp6s_oparamprob_option, "\t\t%llu unrecognized option\n");
886: p_5(icp6s_oredirect, "\t\t%llu redirect\n");
887: p_5(icp6s_ounknown, "\t\t%llu unknown\n");
888:
889: p(icp6s_reflect, "\t%llu message response%s generated\n");
890: p(icp6s_nd_toomanyopt, "\t%llu message%s with too many ND options\n");
891: p(icp6s_nd_badopt, "\t%llu message%s with bad ND options\n");
892: p(icp6s_badns, "\t%llu bad neighbor solicitation message%s\n");
893: p(icp6s_badna, "\t%llu bad neighbor advertisement message%s\n");
894: p(icp6s_badrs, "\t%llu bad router solicitation message%s\n");
895: p(icp6s_badra, "\t%llu bad router advertisement message%s\n");
896: p(icp6s_badredirect, "\t%llu bad redirect message%s\n");
1.12 itojun 897: p(icp6s_pmtuchg, "\t%llu path MTU change%s\n");
1.14 itojun 898: #undef p
1.8 itojun 899: #undef p_5
1.1 itojun 900: }
901:
902: /*
903: * Dump ICMPv6 per-interface statistics based on RFC 2466.
904: */
905: void
906: icmp6_ifstats(ifname)
907: char *ifname;
908: {
909: struct in6_ifreq ifr;
910: int s;
1.20 ! deraadt 911:
1.1 itojun 912: #define p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \
1.20 ! deraadt 913: printf(m, (unsigned long long)ifr.ifr_ifru.ifru_icmp6stat.f, \
! 914: plural(ifr.ifr_ifru.ifru_icmp6stat.f))
1.1 itojun 915:
916: if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
917: perror("Warning: socket(AF_INET6)");
918: return;
919: }
920:
1.20 ! deraadt 921: strlcpy(ifr.ifr_name, ifname, sizeof ifr.ifr_name);
1.1 itojun 922: printf("icmp6 on %s:\n", ifr.ifr_name);
923:
924: if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) {
925: perror("Warning: ioctl(SIOCGIFSTAT_ICMP6)");
926: goto end;
927: }
928:
1.14 itojun 929: p(ifs6_in_msg, "\t%llu total input message%s\n");
1.17 mickey 930: p(ifs6_in_error, "\t%llu total input error message%s\n");
1.14 itojun 931: p(ifs6_in_dstunreach, "\t%llu input destination unreachable error%s\n");
932: p(ifs6_in_adminprohib, "\t%llu input administratively prohibited error%s\n");
933: p(ifs6_in_timeexceed, "\t%llu input time exceeded error%s\n");
934: p(ifs6_in_paramprob, "\t%llu input parameter problem error%s\n");
935: p(ifs6_in_pkttoobig, "\t%llu input packet too big error%s\n");
936: p(ifs6_in_echo, "\t%llu input echo request%s\n");
937: p(ifs6_in_echoreply, "\t%llu input echo reply%s\n");
938: p(ifs6_in_routersolicit, "\t%llu input router solicitation%s\n");
939: p(ifs6_in_routeradvert, "\t%llu input router advertisement%s\n");
940: p(ifs6_in_neighborsolicit, "\t%llu input neighbor solicitation%s\n");
941: p(ifs6_in_neighboradvert, "\t%llu input neighbor advertisement%s\n");
942: p(ifs6_in_redirect, "\t%llu input redirect%s\n");
943: p(ifs6_in_mldquery, "\t%llu input MLD query%s\n");
944: p(ifs6_in_mldreport, "\t%llu input MLD report%s\n");
945: p(ifs6_in_mlddone, "\t%llu input MLD done%s\n");
946:
947: p(ifs6_out_msg, "\t%llu total output message%s\n");
948: p(ifs6_out_error, "\t%llu total output error message%s\n");
949: p(ifs6_out_dstunreach, "\t%llu output destination unreachable error%s\n");
950: p(ifs6_out_adminprohib, "\t%llu output administratively prohibited error%s\n");
951: p(ifs6_out_timeexceed, "\t%llu output time exceeded error%s\n");
952: p(ifs6_out_paramprob, "\t%llu output parameter problem error%s\n");
953: p(ifs6_out_pkttoobig, "\t%llu output packet too big error%s\n");
954: p(ifs6_out_echo, "\t%llu output echo request%s\n");
955: p(ifs6_out_echoreply, "\t%llu output echo reply%s\n");
956: p(ifs6_out_routersolicit, "\t%llu output router solicitation%s\n");
957: p(ifs6_out_routeradvert, "\t%llu output router advertisement%s\n");
958: p(ifs6_out_neighborsolicit, "\t%llu output neighbor solicitation%s\n");
959: p(ifs6_out_neighboradvert, "\t%llu output neighbor advertisement%s\n");
960: p(ifs6_out_redirect, "\t%llu output redirect%s\n");
961: p(ifs6_out_mldquery, "\t%llu output MLD query%s\n");
962: p(ifs6_out_mldreport, "\t%llu output MLD report%s\n");
963: p(ifs6_out_mlddone, "\t%llu output MLD done%s\n");
1.1 itojun 964:
965: end:
966: close(s);
967: #undef p
968: }
969:
970: /*
971: * Dump PIM statistics structure.
972: */
973: void
974: pim6_stats(off, name)
975: u_long off;
976: char *name;
977: {
978: struct pim6stat pim6stat;
979:
980: if (off == 0)
981: return;
982: kread(off, (char *)&pim6stat, sizeof(pim6stat));
983: printf("%s:\n", name);
984:
985: #define p(f, m) if (pim6stat.f || sflag <= 1) \
1.20 ! deraadt 986: printf(m, (unsigned long long)pim6stat.f, plural(pim6stat.f))
! 987:
1.14 itojun 988: p(pim6s_rcv_total, "\t%llu message%s received\n");
989: p(pim6s_rcv_tooshort, "\t%llu message%s received with too few bytes\n");
990: p(pim6s_rcv_badsum, "\t%llu message%s received with bad checksum\n");
991: p(pim6s_rcv_badversion, "\t%llu message%s received with bad version\n");
992: p(pim6s_rcv_registers, "\t%llu register%s received\n");
993: p(pim6s_rcv_badregisters, "\t%llu bad register%s received\n");
994: p(pim6s_snd_registers, "\t%llu register%s sent\n");
1.1 itojun 995: #undef p
996: }
997:
998: /*
999: * Pretty print an Internet address (net address + port).
1000: * If the nflag was specified, use numbers instead of names.
1001: */
1002:
1003: void
1004: inet6print(in6, port, proto)
1.16 mpech 1005: struct in6_addr *in6;
1.1 itojun 1006: int port;
1007: char *proto;
1008: {
1009: #define GETSERVBYPORT6(port, proto, ret)\
1.14 itojun 1010: do {\
1.1 itojun 1011: if (strcmp((proto), "tcp6") == 0)\
1012: (ret) = getservbyport((int)(port), "tcp");\
1013: else if (strcmp((proto), "udp6") == 0)\
1014: (ret) = getservbyport((int)(port), "udp");\
1015: else\
1016: (ret) = getservbyport((int)(port), (proto));\
1.14 itojun 1017: } while (0)
1.1 itojun 1018: struct servent *sp = 0;
1019: char line[80], *cp;
1020: int width;
1021:
1.14 itojun 1022: width = Aflag ? 12 : 16;
1023: if (vflag && width < strlen(inet6name(in6)))
1024: width = strlen(inet6name(in6));
1.20 ! deraadt 1025: snprintf(line, sizeof line, "%.*s.", width, inet6name(in6));
1.1 itojun 1026: cp = index(line, '\0');
1027: if (!nflag && port)
1028: GETSERVBYPORT6(port, proto, sp);
1029: if (sp || port == 0)
1030: sprintf(cp, "%.8s", sp ? sp->s_name : "*");
1031: else
1032: sprintf(cp, "%d", ntohs((u_short)port));
1033: width = Aflag ? 18 : 22;
1.14 itojun 1034: if (vflag && width < strlen(line))
1035: width = strlen(line);
1.1 itojun 1036: printf(" %-*.*s", width, width, line);
1037: }
1038:
1039: /*
1040: * Construct an Internet address representation.
1041: * If the nflag has been supplied, give
1042: * numeric value, otherwise try for symbolic name.
1043: */
1044:
1045: char *
1046: inet6name(in6p)
1047: struct in6_addr *in6p;
1048: {
1.16 mpech 1049: char *cp;
1.14 itojun 1050: static char line[NI_MAXHOST];
1.1 itojun 1051: struct hostent *hp;
1.19 mpech 1052: static char domain[MAXHOSTNAMELEN];
1.1 itojun 1053: static int first = 1;
1.14 itojun 1054: char hbuf[NI_MAXHOST];
1.1 itojun 1055: struct sockaddr_in6 sin6;
1056: #ifdef NI_WITHSCOPEID
1057: const int niflag = NI_NUMERICHOST | NI_WITHSCOPEID;
1058: #else
1059: const int niflag = NI_NUMERICHOST;
1060: #endif
1061:
1062: if (first && !nflag) {
1063: first = 0;
1.19 mpech 1064: if (gethostname(domain, sizeof(domain)) == 0 &&
1.1 itojun 1065: (cp = index(domain, '.')))
1.20 ! deraadt 1066: (void) strlcpy(domain, cp + 1, sizeof domain);
1.1 itojun 1067: else
1.20 ! deraadt 1068: domain[0] = '\0';
1.1 itojun 1069: }
1070: cp = 0;
1071: if (!nflag && !IN6_IS_ADDR_UNSPECIFIED(in6p)) {
1072: hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6);
1073: if (hp) {
1074: if ((cp = index(hp->h_name, '.')) &&
1075: !strcmp(cp + 1, domain))
1076: *cp = 0;
1077: cp = hp->h_name;
1078: }
1079: }
1080: if (IN6_IS_ADDR_UNSPECIFIED(in6p))
1.14 itojun 1081: strlcpy(line, "*", sizeof(line));
1.1 itojun 1082: else if (cp)
1.14 itojun 1083: strlcpy(line, cp, sizeof(line));
1.1 itojun 1084: else {
1085: memset(&sin6, 0, sizeof(sin6));
1086: sin6.sin6_len = sizeof(sin6);
1087: sin6.sin6_family = AF_INET6;
1088: sin6.sin6_addr = *in6p;
1089: #ifdef KAME_SCOPEID
1090: if (IN6_IS_ADDR_LINKLOCAL(in6p)) {
1091: sin6.sin6_scope_id =
1.20 ! deraadt 1092: ntohs(*(u_int16_t *)&in6p->s6_addr[2]);
1.1 itojun 1093: sin6.sin6_addr.s6_addr[2] = 0;
1094: sin6.sin6_addr.s6_addr[3] = 0;
1095: }
1096: #endif
1097: if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,
1.20 ! deraadt 1098: hbuf, sizeof(hbuf), NULL, 0, niflag) != 0)
! 1099: strlcpy(hbuf, "?", sizeof hbuf);
1.14 itojun 1100: strlcpy(line, hbuf, sizeof(line));
1.1 itojun 1101: }
1102: return (line);
1103: }
1104:
1105: #ifdef TCP6
1106: /*
1107: * Dump the contents of a TCP6 PCB.
1108: */
1109: void
1110: tcp6_dump(pcbaddr)
1111: u_long pcbaddr;
1112: {
1113: struct tcp6cb tcp6cb;
1114: int i;
1115:
1116: kread(pcbaddr, (char *)&tcp6cb, sizeof(tcp6cb));
1117:
1118: printf("TCP Protocol Control Block at 0x%08lx:\n\n", pcbaddr);
1119:
1120: printf("Timers:\n");
1121: for (i = 0; i < TCP6T_NTIMERS; i++)
1122: printf("\t%s: %u", tcp6timers[i], tcp6cb.t_timer[i]);
1123: printf("\n\n");
1124:
1125: if (tcp6cb.t_state < 0 || tcp6cb.t_state >= TCP6_NSTATES)
1126: printf("State: %d", tcp6cb.t_state);
1127: else
1128: printf("State: %s", tcp6states[tcp6cb.t_state]);
1129: printf(", flags 0x%x, in6pcb 0x%lx\n\n", tcp6cb.t_flags,
1130: (u_long)tcp6cb.t_in6pcb);
1131:
1132: printf("rxtshift %d, rxtcur %d, dupacks %d\n", tcp6cb.t_rxtshift,
1133: tcp6cb.t_rxtcur, tcp6cb.t_dupacks);
1134: printf("peermaxseg %u, maxseg %u, force %d\n\n", tcp6cb.t_peermaxseg,
1135: tcp6cb.t_maxseg, tcp6cb.t_force);
1136:
1137: printf("snd_una %u, snd_nxt %u, snd_up %u\n",
1138: tcp6cb.snd_una, tcp6cb.snd_nxt, tcp6cb.snd_up);
1139: printf("snd_wl1 %u, snd_wl2 %u, iss %u, snd_wnd %lu\n\n",
1140: tcp6cb.snd_wl1, tcp6cb.snd_wl2, tcp6cb.iss, tcp6cb.snd_wnd);
1141:
1142: printf("rcv_wnd %lu, rcv_nxt %u, rcv_up %u, irs %u\n\n",
1143: tcp6cb.rcv_wnd, tcp6cb.rcv_nxt, tcp6cb.rcv_up, tcp6cb.irs);
1144:
1145: printf("rcv_adv %u, snd_max %u, snd_cwnd %lu, snd_ssthresh %lu\n",
1146: tcp6cb.rcv_adv, tcp6cb.snd_max, tcp6cb.snd_cwnd, tcp6cb.snd_ssthresh);
1147:
1148: printf("idle %d, rtt %d, rtseq %u, srtt %d, rttvar %d, rttmin %d, "
1149: "max_sndwnd %lu\n\n", tcp6cb.t_idle, tcp6cb.t_rtt, tcp6cb.t_rtseq,
1150: tcp6cb.t_srtt, tcp6cb.t_rttvar, tcp6cb.t_rttmin, tcp6cb.max_sndwnd);
1151:
1152: printf("oobflags %d, iobc %d, softerror %d\n\n", tcp6cb.t_oobflags,
1153: tcp6cb.t_iobc, tcp6cb.t_softerror);
1154:
1155: printf("snd_scale %d, rcv_scale %d, req_r_scale %d, req_s_scale %d\n",
1156: tcp6cb.snd_scale, tcp6cb.rcv_scale, tcp6cb.request_r_scale,
1157: tcp6cb.requested_s_scale);
1158: printf("ts_recent %u, ts_regent_age %d, last_ack_sent %u\n",
1159: tcp6cb.ts_recent, tcp6cb.ts_recent_age, tcp6cb.last_ack_sent);
1160: }
1161: #endif
1162:
1163: #endif /*INET6*/