[BACK]Return to inet6.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / netstat

Annotation of src/usr.bin/netstat/inet6.c, Revision 1.13

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