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