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