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

Annotation of src/usr.bin/netstat/inet.c, Revision 1.91

1.91    ! itojun      1: /*     $OpenBSD: inet.c,v 1.90 2005/01/14 15:00:44 mcbride Exp $       */
1.1       deraadt     2: /*     $NetBSD: inet.c,v 1.14 1995/10/03 21:42:37 thorpej Exp $        */
                      3:
                      4: /*
                      5:  * Copyright (c) 1983, 1988, 1993
                      6:  *     The Regents of the University of California.  All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
1.65      millert    16:  * 3. Neither the name of the University nor the names of its contributors
1.1       deraadt    17:  *    may be used to endorse or promote products derived from this software
                     18:  *    without specific prior written permission.
                     19:  *
                     20:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     21:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     22:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     23:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     24:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     25:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     26:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     27:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     28:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     29:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     30:  * SUCH DAMAGE.
                     31:  */
                     32:
                     33: #ifndef lint
                     34: #if 0
                     35: static char sccsid[] = "from: @(#)inet.c       8.4 (Berkeley) 4/20/94";
                     36: #else
1.91    ! itojun     37: static const char *rcsid = "$OpenBSD: inet.c,v 1.90 2005/01/14 15:00:44 mcbride Exp $";
1.1       deraadt    38: #endif
                     39: #endif /* not lint */
                     40:
                     41: #include <sys/param.h>
                     42: #include <sys/queue.h>
                     43: #include <sys/socket.h>
                     44: #include <sys/socketvar.h>
                     45: #include <sys/mbuf.h>
                     46: #include <sys/protosw.h>
                     47:
                     48: #include <net/route.h>
                     49: #include <netinet/in.h>
                     50: #include <netinet/in_systm.h>
                     51: #include <netinet/ip.h>
                     52: #include <netinet/in_pcb.h>
                     53: #include <netinet/ip_icmp.h>
                     54: #include <netinet/icmp_var.h>
                     55: #include <netinet/igmp_var.h>
                     56: #include <netinet/ip_var.h>
1.90      mcbride    57: #include <netinet/pim_var.h>
1.1       deraadt    58: #include <netinet/tcp.h>
                     59: #include <netinet/tcpip.h>
                     60: #include <netinet/tcp_seq.h>
                     61: #define TCPSTATES
                     62: #include <netinet/tcp_fsm.h>
                     63: #include <netinet/tcp_timer.h>
                     64: #include <netinet/tcp_var.h>
                     65: #include <netinet/tcp_debug.h>
                     66: #include <netinet/udp.h>
                     67: #include <netinet/udp_var.h>
1.30      angelos    68: #include <netinet/ip_ipsp.h>
1.10      angelos    69: #include <netinet/ip_ah.h>
                     70: #include <netinet/ip_esp.h>
1.45      angelos    71: #include <netinet/ip_ipip.h>
1.52      angelos    72: #include <netinet/ip_ipcomp.h>
1.34      angelos    73: #include <netinet/ip_ether.h>
1.91    ! itojun     74: #ifdef DCCP
        !            75: #include <netinet/dccp.h>
        !            76: #define DCCPSTATES
        !            77: #include <netinet/dccp_var.h>
        !            78: #endif
1.69      mcbride    79: #include <netinet/ip_carp.h>
1.75      mcbride    80: #include <net/if.h>
                     81: #include <net/pfvar.h>
                     82: #include <net/if_pfsync.h>
1.1       deraadt    83:
                     84: #include <arpa/inet.h>
1.18      millert    85: #include <limits.h>
1.1       deraadt    86: #include <netdb.h>
                     87: #include <stdio.h>
                     88: #include <string.h>
                     89: #include <unistd.h>
1.14      dgregor    90: #include <stdlib.h>
1.1       deraadt    91: #include "netstat.h"
                     92:
1.5       deraadt    93: #include <rpc/rpc.h>
                     94: #include <rpc/pmap_prot.h>
                     95: #include <rpc/pmap_clnt.h>
                     96:
1.1       deraadt    97: struct inpcb inpcb;
                     98: struct tcpcb tcpcb;
1.91    ! itojun     99: #ifdef DCCP
        !           100: struct  dccpcb dccpcb;
        !           101: #endif
1.1       deraadt   102: struct socket sockb;
                    103:
1.56      millert   104: static void protopr0(u_long, char *, int);
1.48      itojun    105:
1.56      millert   106: char   *inetname(struct in_addr *);
1.63      deraadt   107: void   inetprint(struct in_addr *, in_port_t, char *, int);
1.38      itojun    108: #ifdef INET6
1.56      millert   109: char   *inet6name(struct in6_addr *);
                    110: void   inet6print(struct in6_addr *, int, char *, int);
1.38      itojun    111: #endif
1.1       deraadt   112:
                    113: /*
                    114:  * Print a summary of connections related to an Internet
                    115:  * protocol.  For TCP, also give state of connection.
                    116:  * Listening processes (aflag) are suppressed unless the
                    117:  * -a (all) flag is specified.
                    118:  */
                    119: void
1.63      deraadt   120: protopr(u_long off, char *name)
1.1       deraadt   121: {
1.48      itojun    122:        protopr0(off, name, AF_INET);
                    123: }
                    124:
                    125: #ifdef INET6
                    126: void
1.63      deraadt   127: ip6protopr(u_long off, char *name)
1.48      itojun    128: {
                    129:        protopr0(off, name, AF_INET6);
                    130: }
                    131: #endif
                    132:
                    133: static void
1.63      deraadt   134: protopr0(u_long off, char *name, int af)
1.48      itojun    135: {
1.1       deraadt   136:        struct inpcbtable table;
1.54      mpech     137:        struct inpcb *head, *next, *prev;
1.1       deraadt   138:        struct inpcb inpcb;
1.72      markus    139:        int istcp, israw;
1.91    ! itojun    140: #ifdef DCCP
        !           141:        int isdccp;
        !           142: #endif
1.54      mpech     143:        int first = 1;
1.38      itojun    144:        char *name0;
                    145:        char namebuf[20];
1.1       deraadt   146:
1.38      itojun    147:        name0 = name;
1.1       deraadt   148:        if (off == 0)
                    149:                return;
                    150:        istcp = strcmp(name, "tcp") == 0;
1.72      markus    151:        israw = strncmp(name, "ip", 2) == 0;
1.91    ! itojun    152: #ifdef DCCP
        !           153:        isdccp = strcmp(name, "dccp") == 0;
        !           154: #endif
1.1       deraadt   155:        kread(off, (char *)&table, sizeof table);
                    156:        prev = head =
                    157:            (struct inpcb *)&((struct inpcbtable *)off)->inpt_queue.cqh_first;
                    158:        next = table.inpt_queue.cqh_first;
                    159:
                    160:        while (next != head) {
                    161:                kread((u_long)next, (char *)&inpcb, sizeof inpcb);
                    162:                if (inpcb.inp_queue.cqe_prev != prev) {
                    163:                        printf("???\n");
                    164:                        break;
                    165:                }
                    166:                prev = next;
                    167:                next = inpcb.inp_queue.cqe_next;
1.48      itojun    168:
                    169:                switch (af) {
                    170:                case AF_INET:
                    171:                        if ((inpcb.inp_flags & INP_IPV6) != 0)
                    172:                                continue;
                    173:                        break;
                    174:                case AF_INET6:
                    175:                        if ((inpcb.inp_flags & INP_IPV6) == 0)
                    176:                                continue;
                    177:                        break;
                    178:                default:
                    179:                        break;
                    180:                }
1.1       deraadt   181:
                    182:                if (!aflag &&
                    183:                    inet_lnaof(inpcb.inp_laddr) == INADDR_ANY)
                    184:                        continue;
                    185:                kread((u_long)inpcb.inp_socket, (char *)&sockb, sizeof (sockb));
                    186:                if (istcp) {
                    187:                        kread((u_long)inpcb.inp_ppcb,
                    188:                            (char *)&tcpcb, sizeof (tcpcb));
                    189:                }
1.91    ! itojun    190: #ifdef DCCP
        !           191:                if (isdccp) {
        !           192:                        kread((u_long)inpcb.inp_ppcb,
        !           193:                            (char *)&dccpcb, sizeof (dccpcb));
        !           194:                }
        !           195: #endif
1.1       deraadt   196:                if (first) {
                    197:                        printf("Active Internet connections");
                    198:                        if (aflag)
                    199:                                printf(" (including servers)");
                    200:                        putchar('\n');
                    201:                        if (Aflag)
1.29      deraadt   202:                                printf("%-*.*s %-5.5s %-6.6s %-6.6s  %-18.18s %-18.18s %s\n",
1.18      millert   203:                                    PLEN, PLEN, "PCB", "Proto", "Recv-Q",
1.29      deraadt   204:                                    "Send-Q", "Local Address",
                    205:                                    "Foreign Address", "(state)");
1.18      millert   206:                        else
                    207:                                printf("%-5.5s %-6.6s %-6.6s  %-22.22s %-22.22s %s\n",
                    208:                                    "Proto", "Recv-Q", "Send-Q",
                    209:                                    "Local Address", "Foreign Address",
                    210:                                    "(state)");
1.1       deraadt   211:                        first = 0;
                    212:                }
1.38      itojun    213:                if (Aflag) {
1.91    ! itojun    214: #ifdef DCCP
        !           215:                        if (istcp || isdccp)
        !           216: #else
1.1       deraadt   217:                        if (istcp)
1.91    ! itojun    218: #endif
1.18      millert   219:                                printf("%*p ", PLEN, inpcb.inp_ppcb);
1.1       deraadt   220:                        else
1.18      millert   221:                                printf("%*p ", PLEN, prev);
1.38      itojun    222:                }
                    223: #ifdef INET6
1.72      markus    224:                if (inpcb.inp_flags & INP_IPV6 && !israw) {
1.60      deraadt   225:                        strlcpy(namebuf, name0, sizeof namebuf);
                    226:                        strlcat(namebuf, "6", sizeof namebuf);
1.38      itojun    227:                        name = namebuf;
                    228:                } else
                    229:                        name = name0;
                    230: #endif
1.16      millert   231:                printf("%-5.5s %6ld %6ld ", name, sockb.so_rcv.sb_cc,
1.63      deraadt   232:                    sockb.so_snd.sb_cc);
1.38      itojun    233: #ifdef INET6
                    234:                if (inpcb.inp_flags & INP_IPV6) {
                    235:                        inet6print(&inpcb.inp_laddr6, (int)inpcb.inp_lport,
1.63      deraadt   236:                            name, 1);
1.38      itojun    237:                        inet6print(&inpcb.inp_faddr6, (int)inpcb.inp_fport,
1.63      deraadt   238:                            name, 0);
1.38      itojun    239:                } else
                    240: #endif
                    241:                {
                    242:                        inetprint(&inpcb.inp_laddr, (int)inpcb.inp_lport,
1.63      deraadt   243:                            name, 1);
1.38      itojun    244:                        inetprint(&inpcb.inp_faddr, (int)inpcb.inp_fport,
1.63      deraadt   245:                            name, 0);
1.38      itojun    246:                }
1.1       deraadt   247:                if (istcp) {
                    248:                        if (tcpcb.t_state < 0 || tcpcb.t_state >= TCP_NSTATES)
                    249:                                printf(" %d", tcpcb.t_state);
                    250:                        else
                    251:                                printf(" %s", tcpstates[tcpcb.t_state]);
1.72      markus    252:                } else if (israw) {
                    253:                        u_int8_t proto;
                    254: #ifdef INET6
                    255:                        if (inpcb.inp_flags & INP_IPV6)
                    256:                                proto = inpcb.inp_ipv6.ip6_nxt;
                    257:                        else
                    258: #endif
                    259:                                proto = inpcb.inp_ip.ip_p;
1.88      otto      260:                        printf(" %u", proto);
1.1       deraadt   261:                }
                    262:                putchar('\n');
                    263:        }
                    264: }
                    265:
                    266: /*
                    267:  * Dump TCP statistics structure.
                    268:  */
                    269: void
1.63      deraadt   270: tcp_stats(u_long off, char *name)
1.1       deraadt   271: {
                    272:        struct tcpstat tcpstat;
                    273:
                    274:        if (off == 0)
                    275:                return;
1.63      deraadt   276:        printf("%s:\n", name);
1.1       deraadt   277:        kread(off, (char *)&tcpstat, sizeof (tcpstat));
                    278:
                    279: #define        p(f, m) if (tcpstat.f || sflag <= 1) \
1.60      deraadt   280:        printf(m, tcpstat.f, plural(tcpstat.f))
1.38      itojun    281: #define        p1(f, m) if (tcpstat.f || sflag <= 1) \
1.60      deraadt   282:        printf(m, tcpstat.f)
1.1       deraadt   283: #define        p2(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) \
1.60      deraadt   284:        printf(m, tcpstat.f1, plural(tcpstat.f1), tcpstat.f2, plural(tcpstat.f2))
1.38      itojun    285: #define        p2a(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) \
1.60      deraadt   286:        printf(m, tcpstat.f1, plural(tcpstat.f1), tcpstat.f2)
1.1       deraadt   287: #define        p3(f, m) if (tcpstat.f || sflag <= 1) \
1.60      deraadt   288:        printf(m, tcpstat.f, plurales(tcpstat.f))
1.1       deraadt   289:
1.38      itojun    290:        p(tcps_sndtotal, "\t%u packet%s sent\n");
1.1       deraadt   291:        p2(tcps_sndpack,tcps_sndbyte,
1.60      deraadt   292:            "\t\t%u data packet%s (%qd byte%s)\n");
1.1       deraadt   293:        p2(tcps_sndrexmitpack, tcps_sndrexmitbyte,
1.60      deraadt   294:            "\t\t%u data packet%s (%qd byte%s) retransmitted\n");
1.26      provos    295:        p(tcps_sndrexmitfast, "\t\t%qd fast retransmitted packet%s\n");
1.38      itojun    296:        p2a(tcps_sndacks, tcps_delack,
1.60      deraadt   297:            "\t\t%u ack-only packet%s (%u delayed)\n");
1.38      itojun    298:        p(tcps_sndurg, "\t\t%u URG only packet%s\n");
                    299:        p(tcps_sndprobe, "\t\t%u window probe packet%s\n");
                    300:        p(tcps_sndwinup, "\t\t%u window update packet%s\n");
                    301:        p(tcps_sndctrl, "\t\t%u control packet%s\n");
1.50      angelos   302:        p(tcps_outhwcsum, "\t\t%u packet%s hardware-checksummed\n");
1.38      itojun    303:        p(tcps_rcvtotal, "\t%u packet%s received\n");
                    304:        p2(tcps_rcvackpack, tcps_rcvackbyte, "\t\t%u ack%s (for %qd byte%s)\n");
                    305:        p(tcps_rcvdupack, "\t\t%u duplicate ack%s\n");
                    306:        p(tcps_rcvacktoomuch, "\t\t%u ack%s for unsent data\n");
1.85      markus    307:        p(tcps_rcvacktooold, "\t\t%u ack%s for old data\n");
1.1       deraadt   308:        p2(tcps_rcvpack, tcps_rcvbyte,
1.60      deraadt   309:            "\t\t%u packet%s (%qu byte%s) received in-sequence\n");
1.1       deraadt   310:        p2(tcps_rcvduppack, tcps_rcvdupbyte,
1.60      deraadt   311:            "\t\t%u completely duplicate packet%s (%qd byte%s)\n");
1.38      itojun    312:        p(tcps_pawsdrop, "\t\t%u old duplicate packet%s\n");
1.1       deraadt   313:        p2(tcps_rcvpartduppack, tcps_rcvpartdupbyte,
1.62      jsyn      314:            "\t\t%u packet%s with some duplicate data (%qd byte%s duplicated)\n");
1.1       deraadt   315:        p2(tcps_rcvoopack, tcps_rcvoobyte,
1.60      deraadt   316:            "\t\t%u out-of-order packet%s (%qd byte%s)\n");
1.1       deraadt   317:        p2(tcps_rcvpackafterwin, tcps_rcvbyteafterwin,
1.60      deraadt   318:            "\t\t%u packet%s (%qd byte%s) of data after window\n");
1.38      itojun    319:        p(tcps_rcvwinprobe, "\t\t%u window probe%s\n");
                    320:        p(tcps_rcvwinupd, "\t\t%u window update packet%s\n");
                    321:        p(tcps_rcvafterclose, "\t\t%u packet%s received after close\n");
                    322:        p(tcps_rcvbadsum, "\t\t%u discarded for bad checksum%s\n");
                    323:        p(tcps_rcvbadoff, "\t\t%u discarded for bad header offset field%s\n");
                    324:        p1(tcps_rcvshort, "\t\t%u discarded because packet too short\n");
1.58      miod      325:        p1(tcps_rcvnosec, "\t\t%u discarded for missing IPsec protection\n");
1.82      markus    326:        p1(tcps_rcvmemdrop, "\t\t%u discarded due to memory shortage\n");
1.50      angelos   327:        p(tcps_inhwcsum, "\t\t%u packet%s hardware-checksummed\n");
1.80      markus    328:        p(tcps_rcvbadsig, "\t\t%u bad/missing md5 checksum%s\n");
                    329:        p(tcps_rcvgoodsig, "\t\t%qd good md5 checksum%s\n");
1.38      itojun    330:        p(tcps_connattempt, "\t%u connection request%s\n");
                    331:        p(tcps_accepts, "\t%u connection accept%s\n");
                    332:        p(tcps_connects, "\t%u connection%s established (including accepts)\n");
1.1       deraadt   333:        p2(tcps_closed, tcps_drops,
1.60      deraadt   334:            "\t%u connection%s closed (including %u drop%s)\n");
1.83      markus    335:        p(tcps_conndrained, "\t%qd connection%s drained\n");
1.38      itojun    336:        p(tcps_conndrops, "\t%u embryonic connection%s dropped\n");
1.1       deraadt   337:        p2(tcps_rttupdated, tcps_segstimed,
1.60      deraadt   338:            "\t%u segment%s updated rtt (of %u attempt%s)\n");
1.38      itojun    339:        p(tcps_rexmttimeo, "\t%u retransmit timeout%s\n");
                    340:        p(tcps_timeoutdrop, "\t\t%u connection%s dropped by rexmit timeout\n");
                    341:        p(tcps_persisttimeo, "\t%u persist timeout%s\n");
                    342:        p(tcps_keeptimeo, "\t%u keepalive timeout%s\n");
                    343:        p(tcps_keepprobe, "\t\t%u keepalive probe%s sent\n");
                    344:        p(tcps_keepdrops, "\t\t%u connection%s dropped by keepalive\n");
                    345:        p(tcps_predack, "\t%u correct ACK header prediction%s\n");
                    346:        p(tcps_preddat, "\t%u correct data packet header prediction%s\n");
                    347:        p3(tcps_pcbhashmiss, "\t%u PCB cache miss%s\n");
1.59      kjc       348:
                    349:        p(tcps_ecn_accepts, "\t%u ECN connection%s accepted\n");
                    350:        p(tcps_ecn_rcvece, "\t\t%u ECE packet%s received\n");
                    351:        p(tcps_ecn_rcvcwr, "\t\t%u CWR packet%s received\n");
                    352:        p(tcps_ecn_rcvce, "\t\t%u CE packet%s received\n");
                    353:        p(tcps_ecn_sndect, "\t\t%u ECT packet%s sent\n");
                    354:        p(tcps_ecn_sndece, "\t\t%u ECE packet%s sent\n");
                    355:        p(tcps_ecn_sndcwr, "\t\t%u CWR packet%s sent\n");
                    356:        p1(tcps_cwr_frecovery, "\t\t\tcwr by fastrecovery: %u\n");
                    357:        p1(tcps_cwr_timeout, "\t\t\tcwr by timeout: %u\n");
                    358:        p1(tcps_cwr_ecn, "\t\t\tcwr by ecn: %u\n");
1.78      markus    359:
                    360:        p(tcps_badsyn, "\t%u bad connection attempt%s\n");
                    361:        p1(tcps_sc_added, "\t%qd SYN cache entries added\n");
                    362:        p(tcps_sc_collisions, "\t\t%qd hash collision%s\n");
                    363:        p1(tcps_sc_completed, "\t\t%qd completed\n");
                    364:        p1(tcps_sc_aborted, "\t\t%qd aborted (no space to build PCB)\n");
                    365:        p1(tcps_sc_timed_out, "\t\t%qd timed out\n");
                    366:        p1(tcps_sc_overflowed, "\t\t%qd dropped due to overflow\n");
                    367:        p1(tcps_sc_bucketoverflow, "\t\t%qd dropped due to bucket overflow\n");
                    368:        p1(tcps_sc_reset, "\t\t%qd dropped due to RST\n");
                    369:        p1(tcps_sc_unreach, "\t\t%qd dropped due to ICMP unreachable\n");
                    370:        p(tcps_sc_retransmitted, "\t%qd SYN,ACK%s retransmitted\n");
                    371:        p(tcps_sc_dupesyn, "\t%qd duplicate SYN%s received for entries "
                    372:                "already in the cache\n");
                    373:        p(tcps_sc_dropped, "\t%qd SYN%s dropped (no route or no space)\n");
1.59      kjc       374:
1.1       deraadt   375: #undef p
1.38      itojun    376: #undef p1
1.1       deraadt   377: #undef p2
1.38      itojun    378: #undef p2a
1.1       deraadt   379: #undef p3
                    380: }
                    381:
                    382: /*
                    383:  * Dump UDP statistics structure.
                    384:  */
                    385: void
1.63      deraadt   386: udp_stats(u_long off, char *name)
1.1       deraadt   387: {
                    388:        struct udpstat udpstat;
                    389:        u_long delivered;
                    390:
                    391:        if (off == 0)
                    392:                return;
                    393:        kread(off, (char *)&udpstat, sizeof (udpstat));
                    394:        printf("%s:\n", name);
                    395: #define        p(f, m) if (udpstat.f || sflag <= 1) \
1.60      deraadt   396:        printf(m, udpstat.f, plural(udpstat.f))
1.38      itojun    397: #define        p1(f, m) if (udpstat.f || sflag <= 1) \
1.60      deraadt   398:        printf(m, udpstat.f)
                    399:
1.16      millert   400:        p(udps_ipackets, "\t%lu datagram%s received\n");
1.38      itojun    401:        p1(udps_hdrops, "\t%lu with incomplete header\n");
                    402:        p1(udps_badlen, "\t%lu with bad data length field\n");
                    403:        p1(udps_badsum, "\t%lu with bad checksum\n");
                    404:        p1(udps_nosum, "\t%lu with no checksum\n");
1.50      angelos   405:        p(udps_inhwcsum, "\t%lu input packet%s hardware-checksummed\n");
                    406:        p(udps_outhwcsum, "\t%lu output packet%s hardware-checksummed\n");
1.38      itojun    407:        p1(udps_noport, "\t%lu dropped due to no socket\n");
1.16      millert   408:        p(udps_noportbcast, "\t%lu broadcast/multicast datagram%s dropped due to no socket\n");
1.58      miod      409:        p1(udps_nosec, "\t%lu dropped due to missing IPsec protection\n");
1.38      itojun    410:        p1(udps_fullsock, "\t%lu dropped due to full socket buffers\n");
1.60      deraadt   411:        delivered = udpstat.udps_ipackets - udpstat.udps_hdrops -
                    412:            udpstat.udps_badlen - udpstat.udps_badsum -
                    413:            udpstat.udps_noport - udpstat.udps_noportbcast -
                    414:            udpstat.udps_fullsock;
1.1       deraadt   415:        if (delivered || sflag <= 1)
1.16      millert   416:                printf("\t%lu delivered\n", delivered);
                    417:        p(udps_opackets, "\t%lu datagram%s output\n");
1.38      itojun    418:        p1(udps_pcbhashmiss, "\t%lu missed PCB cache\n");
1.1       deraadt   419: #undef p
1.38      itojun    420: #undef p1
1.1       deraadt   421: }
1.91    ! itojun    422:
        !           423: #ifdef DCCP
        !           424: void
        !           425: dccp_stats(off, name)
        !           426:        u_long off;
        !           427:        char *name;
        !           428: {
        !           429:        struct dccpstat dccpstat;
        !           430:
        !           431:        if (off == 0)
        !           432:                return;
        !           433:        printf("%s:\n", name);
        !           434:        kread(off, (char *)&dccpstat, sizeof (dccpstat));
        !           435:
        !           436: #define        p(f, m) if (dccpstat.f || sflag <= 1) \
        !           437:     printf(m, dccpstat.f, plural(dccpstat.f))
        !           438: #define        p1a(f, m) if (dccpstat.f || sflag <= 1) \
        !           439:     printf(m, dccpstat.f)
        !           440:        p(dccps_ipackets, "\t%lu packet%s received\n");
        !           441:        p(dccps_ibytes, "\t%lu byte%s received\n");
        !           442:        p(dccps_connattempt, "\t%lu connection request%s\n");
        !           443:        p(dccps_connects, "\t%lu connection%s established\n");
        !           444:        p(dccps_drops, "\t%lu packet%s dropped\n");
        !           445:        p(dccps_badlen, "\t%lu packet%s with bad data length field\n");
        !           446:        p(dccps_badsum, "\t%lu packet%s with bad checksum\n");
        !           447:        p(dccps_badseq, "\t%lu packet%s with bad sequencenumber\n");
        !           448:        p(dccps_noport, "\t%lu packet%s dropped due to no socket\n");
        !           449:        p(dccps_opackets, "\t%lu packet%s output\n");
        !           450:        p(dccps_obytes, "\t%lu byte%s output\n");
        !           451:
        !           452:        printf("\n\tTCPlike Sender:\n");
        !           453:        p(tcplikes_send_conn, "\t%lu connection%s established\n");
        !           454:        p(tcplikes_send_reploss, "\t%lu data packet%s reported lost\n");
        !           455:        p(tcplikes_send_assloss, "\t%lu data packet%s assumed lost\n");
        !           456:        p(tcplikes_send_ackrecv, "\t%lu acknowledgement%s received\n");
        !           457:        p(tcplikes_send_missack, "\t%lu ack packet%s assumed lost\n");
        !           458:        p(tcplikes_send_badseq, "\t%lu bad sequence number on outgoing packet%s\n");
        !           459:        p(tcplikes_send_memerr, "\t%lu memory allocation error%s\n");
        !           460:
        !           461:        printf("\tTCPlike Receiver:\n");
        !           462:        p(tcplikes_recv_conn, "\t%lu connection%s established\n");
        !           463:        p(tcplikes_recv_datarecv, "\t%lu data packet%s received\n");
        !           464:        p(tcplikes_recv_ackack, "\t%lu Ack-on-ack%s received\n");
        !           465:        p(tcplikes_recv_acksent, "\t%lu acknowledgement packet%s sent\n");
        !           466:        p(tcplikes_recv_memerr, "\t%lu memory allocation error%s\n");
        !           467:
        !           468: #undef p
        !           469: #undef p1a
        !           470: }
        !           471: #endif
1.1       deraadt   472:
                    473: /*
                    474:  * Dump IP statistics structure.
                    475:  */
                    476: void
1.63      deraadt   477: ip_stats(u_long off, char *name)
1.1       deraadt   478: {
                    479:        struct ipstat ipstat;
                    480:
                    481:        if (off == 0)
                    482:                return;
                    483:        kread(off, (char *)&ipstat, sizeof (ipstat));
                    484:        printf("%s:\n", name);
                    485:
                    486: #define        p(f, m) if (ipstat.f || sflag <= 1) \
1.60      deraadt   487:        printf(m, ipstat.f, plural(ipstat.f))
1.38      itojun    488: #define        p1(f, m) if (ipstat.f || sflag <= 1) \
1.60      deraadt   489:        printf(m, ipstat.f)
1.1       deraadt   490:
1.16      millert   491:        p(ips_total, "\t%lu total packet%s received\n");
                    492:        p(ips_badsum, "\t%lu bad header checksum%s\n");
1.38      itojun    493:        p1(ips_toosmall, "\t%lu with size smaller than minimum\n");
                    494:        p1(ips_tooshort, "\t%lu with data size < data length\n");
                    495:        p1(ips_badhlen, "\t%lu with header length < data size\n");
                    496:        p1(ips_badlen, "\t%lu with data length < header length\n");
                    497:        p1(ips_badoptions, "\t%lu with bad options\n");
                    498:        p1(ips_badvers, "\t%lu with incorrect version number\n");
1.16      millert   499:        p(ips_fragments, "\t%lu fragment%s received\n");
1.62      jsyn      500:        p(ips_fragdropped, "\t%lu fragment%s dropped (duplicates or out of space)\n");
1.16      millert   501:        p(ips_badfrags, "\t%lu malformed fragment%s dropped\n");
                    502:        p(ips_fragtimeout, "\t%lu fragment%s dropped after timeout\n");
                    503:        p(ips_reassembled, "\t%lu packet%s reassembled ok\n");
                    504:        p(ips_delivered, "\t%lu packet%s for this host\n");
                    505:        p(ips_noproto, "\t%lu packet%s for unknown/unsupported protocol\n");
                    506:        p(ips_forward, "\t%lu packet%s forwarded\n");
                    507:        p(ips_cantforward, "\t%lu packet%s not forwardable\n");
                    508:        p(ips_redirectsent, "\t%lu redirect%s sent\n");
                    509:        p(ips_localout, "\t%lu packet%s sent from this host\n");
                    510:        p(ips_rawout, "\t%lu packet%s sent with fabricated ip header\n");
                    511:        p(ips_odropped, "\t%lu output packet%s dropped due to no bufs, etc.\n");
                    512:        p(ips_noroute, "\t%lu output packet%s discarded due to no route\n");
                    513:        p(ips_fragmented, "\t%lu output datagram%s fragmented\n");
                    514:        p(ips_ofragments, "\t%lu fragment%s created\n");
                    515:        p(ips_cantfrag, "\t%lu datagram%s that can't be fragmented\n");
1.38      itojun    516:        p1(ips_rcvmemdrop, "\t%lu fragment floods\n");
1.42      itojun    517:        p(ips_toolong, "\t%lu packet%s with ip length > max ip packet size\n");
                    518:        p(ips_nogif, "\t%lu tunneling packet%s that can't find gif\n");
1.49      itojun    519:        p(ips_badaddr, "\t%lu datagram%s with bad address in header\n");
1.50      angelos   520:        p(ips_inhwcsum, "\t%lu input datagram%s checksum-processed by hardware\n");
                    521:        p(ips_outhwcsum, "\t%lu output datagram%s checksum-processed by hardware\n");
1.1       deraadt   522: #undef p
1.38      itojun    523: #undef p1
1.1       deraadt   524: }
                    525:
1.68      tedu      526: static char *icmpnames[ICMP_MAXTYPE + 1] = {
1.1       deraadt   527:        "echo reply",
                    528:        "#1",
                    529:        "#2",
                    530:        "destination unreachable",
                    531:        "source quench",
                    532:        "routing redirect",
                    533:        "#6",
                    534:        "#7",
                    535:        "echo",
1.9       deraadt   536:        "router advertisement",
                    537:        "router solicitation",
1.1       deraadt   538:        "time exceeded",
                    539:        "parameter problem",
                    540:        "time stamp",
                    541:        "time stamp reply",
                    542:        "information request",
                    543:        "information request reply",
                    544:        "address mask request",
                    545:        "address mask reply",
1.68      tedu      546:        "#19",
                    547:        "#20",
                    548:        "#21",
                    549:        "#22",
                    550:        "#23",
                    551:        "#24",
                    552:        "#25",
                    553:        "#26",
                    554:        "#27",
                    555:        "#28",
                    556:        "#29",
                    557:        "traceroute",
                    558:        "data conversion error",
                    559:        "mobile host redirect",
                    560:        "IPv6 where-are-you",
                    561:        "IPv6 i-am-here",
                    562:        "mobile registration request",
                    563:        "mobile registration reply",
                    564:        "#37",
                    565:        "#38",
                    566:        "SKIP",
                    567:        "Photuris",
1.1       deraadt   568: };
                    569:
                    570: /*
                    571:  * Dump ICMP statistics.
                    572:  */
                    573: void
1.63      deraadt   574: icmp_stats(u_long off, char *name)
1.1       deraadt   575: {
                    576:        struct icmpstat icmpstat;
1.54      mpech     577:        int i, first;
1.1       deraadt   578:
                    579:        if (off == 0)
                    580:                return;
                    581:        kread(off, (char *)&icmpstat, sizeof (icmpstat));
                    582:        printf("%s:\n", name);
                    583:
                    584: #define        p(f, m) if (icmpstat.f || sflag <= 1) \
1.60      deraadt   585:        printf(m, icmpstat.f, plural(icmpstat.f))
1.1       deraadt   586:
1.16      millert   587:        p(icps_error, "\t%lu call%s to icmp_error\n");
1.1       deraadt   588:        p(icps_oldicmp,
1.61      aaron     589:            "\t%lu error%s not generated because old message was icmp\n");
1.1       deraadt   590:        for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++)
                    591:                if (icmpstat.icps_outhist[i] != 0) {
                    592:                        if (first) {
1.43      itojun    593:                                printf("\tOutput packet histogram:\n");
1.1       deraadt   594:                                first = 0;
                    595:                        }
1.68      tedu      596:                        if (icmpnames[i])
                    597:                                printf("\t\t%s:", icmpnames[i]);
                    598:                        else
                    599:                                printf("\t\t#%d:", i);
                    600:                        printf(" %lu\n", icmpstat.icps_outhist[i]);
1.1       deraadt   601:                }
1.16      millert   602:        p(icps_badcode, "\t%lu message%s with bad code fields\n");
                    603:        p(icps_tooshort, "\t%lu message%s < minimum length\n");
                    604:        p(icps_checksum, "\t%lu bad checksum%s\n");
                    605:        p(icps_badlen, "\t%lu message%s with bad length\n");
1.1       deraadt   606:        for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++)
                    607:                if (icmpstat.icps_inhist[i] != 0) {
                    608:                        if (first) {
1.43      itojun    609:                                printf("\tInput packet histogram:\n");
1.1       deraadt   610:                                first = 0;
                    611:                        }
1.68      tedu      612:                        if (icmpnames[i])
                    613:                                printf("\t\t%s:", icmpnames[i]);
                    614:                        else
                    615:                                printf("\t\t#%d:", i);
                    616:                        printf(" %lu\n", icmpstat.icps_inhist[i]);
1.1       deraadt   617:                }
1.16      millert   618:        p(icps_reflect, "\t%lu message response%s generated\n");
1.1       deraadt   619: #undef p
                    620: }
                    621:
                    622: /*
                    623:  * Dump IGMP statistics structure.
                    624:  */
                    625: void
1.63      deraadt   626: igmp_stats(u_long off, char *name)
1.1       deraadt   627: {
                    628:        struct igmpstat igmpstat;
                    629:
                    630:        if (off == 0)
                    631:                return;
                    632:        kread(off, (char *)&igmpstat, sizeof (igmpstat));
                    633:        printf("%s:\n", name);
                    634:
                    635: #define        p(f, m) if (igmpstat.f || sflag <= 1) \
1.60      deraadt   636:        printf(m, igmpstat.f, plural(igmpstat.f))
1.1       deraadt   637: #define        py(f, m) if (igmpstat.f || sflag <= 1) \
1.60      deraadt   638:        printf(m, igmpstat.f, igmpstat.f != 1 ? "ies" : "y")
                    639:
1.16      millert   640:        p(igps_rcv_total, "\t%lu message%s received\n");
1.55      mickey    641:        p(igps_rcv_tooshort, "\t%lu message%s received with too few bytes\n");
                    642:        p(igps_rcv_badsum, "\t%lu message%s received with bad checksum\n");
                    643:        py(igps_rcv_queries, "\t%lu membership quer%s received\n");
                    644:        py(igps_rcv_badqueries, "\t%lu membership quer%s received with invalid field(s)\n");
                    645:        p(igps_rcv_reports, "\t%lu membership report%s received\n");
                    646:        p(igps_rcv_badreports, "\t%lu membership report%s received with invalid field(s)\n");
                    647:        p(igps_rcv_ourreports, "\t%lu membership report%s received for groups to which we belong\n");
                    648:        p(igps_snd_reports, "\t%lu membership report%s sent\n");
1.90      mcbride   649: #undef p
                    650: #undef py
                    651: }
                    652:
                    653: /*
                    654:  * Dump PIM statistics structure.
                    655:  */
                    656: void
                    657: pim_stats(u_long off, char *name)
                    658: {
                    659:        struct pimstat pimstat;
                    660:
                    661:        if (off == 0)
                    662:                return;
                    663:        if (kread(off, (char *)&pimstat, sizeof (pimstat)) != 0) {
                    664:                /* XXX: PIM is probably not enabled in the kernel */
                    665:                return;
                    666:        }
                    667:
                    668:        printf("%s:\n", name);
                    669:
                    670: #define        p(f, m) if (pimstat.f || sflag <= 1) \
                    671:        printf(m, pimstat.f, plural(pimstat.f))
                    672: #define        py(f, m) if (pimstat.f || sflag <= 1) \
                    673:        printf(m, pimstat.f, pimstat.f != 1 ? "ies" : "y")
                    674:
                    675:        p(pims_rcv_total_msgs, "\t%llu message%s received\n");
                    676:        p(pims_rcv_total_bytes, "\t%llu byte%s received\n");
                    677:        p(pims_rcv_tooshort, "\t%llu message%s received with too few bytes\n");
                    678:        p(pims_rcv_badsum, "\t%llu message%s received with bad checksum\n");
                    679:        p(pims_rcv_badversion, "\t%llu message%s received with bad version\n");
                    680:        p(pims_rcv_registers_msgs, "\t%llu data register message%s received\n");
                    681:        p(pims_rcv_registers_bytes, "\t%llu data register byte%s received\n");
                    682:        p(pims_rcv_registers_wrongiif, "\t%llu data register message%s received on wrong iif\n");
                    683:        p(pims_rcv_badregisters, "\t%llu bad register%s received\n");
                    684:        p(pims_snd_registers_msgs, "\t%llu data register message%s sent\n");
                    685:        p(pims_snd_registers_bytes, "\t%llu data register byte%s sent\n");
1.1       deraadt   686: #undef p
                    687: #undef py
                    688: }
                    689:
1.5       deraadt   690: struct rpcnams {
                    691:        struct rpcnams *next;
1.16      millert   692:        in_port_t port;
1.21      deraadt   693:        int       proto;
1.5       deraadt   694:        char    *rpcname;
                    695: };
                    696:
1.66      deraadt   697: static char *
1.63      deraadt   698: getrpcportnam(in_port_t port, int proto)
1.5       deraadt   699: {
                    700:        struct sockaddr_in server_addr;
1.54      mpech     701:        struct hostent *hp;
1.5       deraadt   702:        static struct pmaplist *head;
                    703:        int socket = RPC_ANYSOCK;
                    704:        struct timeval minutetimeout;
1.54      mpech     705:        CLIENT *client;
1.5       deraadt   706:        struct rpcent *rpc;
                    707:        static int first;
                    708:        static struct rpcnams *rpcn;
                    709:        struct rpcnams *n;
1.23      deraadt   710:        char num[20];
1.55      mickey    711:
1.5       deraadt   712:        if (first == 0) {
                    713:                first = 1;
1.7       deraadt   714:                memset((char *)&server_addr, 0, sizeof server_addr);
1.5       deraadt   715:                server_addr.sin_family = AF_INET;
                    716:                if ((hp = gethostbyname("localhost")) != NULL)
1.7       deraadt   717:                        memmove((caddr_t)&server_addr.sin_addr, hp->h_addr,
1.5       deraadt   718:                            hp->h_length);
                    719:                else
                    720:                        (void) inet_aton("0.0.0.0", &server_addr.sin_addr);
                    721:
                    722:                minutetimeout.tv_sec = 60;
                    723:                minutetimeout.tv_usec = 0;
                    724:                server_addr.sin_port = htons(PMAPPORT);
                    725:                if ((client = clnttcp_create(&server_addr, PMAPPROG,
1.7       deraadt   726:                    PMAPVERS, &socket, 50, 500)) == NULL)
                    727:                        return (NULL);
1.5       deraadt   728:                if (clnt_call(client, PMAPPROC_DUMP, xdr_void, NULL,
1.8       deraadt   729:                    xdr_pmaplist, &head, minutetimeout) != RPC_SUCCESS) {
1.7       deraadt   730:                        clnt_destroy(client);
                    731:                        return (NULL);
1.5       deraadt   732:                }
                    733:                for (; head != NULL; head = head->pml_next) {
                    734:                        n = (struct rpcnams *)malloc(sizeof(struct rpcnams));
                    735:                        if (n == NULL)
                    736:                                continue;
                    737:                        n->next = rpcn;
                    738:                        rpcn = n;
                    739:                        n->port = head->pml_map.pm_port;
1.21      deraadt   740:                        n->proto = head->pml_map.pm_prot;
1.5       deraadt   741:
                    742:                        rpc = getrpcbynumber(head->pml_map.pm_prog);
                    743:                        if (rpc)
                    744:                                n->rpcname = strdup(rpc->r_name);
                    745:                        else {
1.23      deraadt   746:                                snprintf(num, sizeof num, "%ld",
                    747:                                    head->pml_map.pm_prog);
1.5       deraadt   748:                                n->rpcname = strdup(num);
                    749:                        }
                    750:                }
                    751:                clnt_destroy(client);
                    752:        }
                    753:
                    754:        for (n = rpcn; n; n = n->next)
1.21      deraadt   755:                if (n->port == port && n->proto == proto)
1.5       deraadt   756:                        return (n->rpcname);
                    757:        return (NULL);
                    758: }
                    759:
1.1       deraadt   760: /*
                    761:  * Pretty print an Internet address (net address + port).
                    762:  * If the nflag was specified, use numbers instead of names.
                    763:  */
                    764: void
1.63      deraadt   765: inetprint(struct in_addr *in, in_port_t port, char *proto, int local)
1.1       deraadt   766: {
                    767:        struct servent *sp = 0;
1.5       deraadt   768:        char line[80], *cp, *nam;
1.1       deraadt   769:        int width;
                    770:
1.23      deraadt   771:        snprintf(line, sizeof line, "%.*s.", (Aflag && !nflag) ? 12 : 16,
                    772:            inetname(in));
1.4       millert   773:        cp = strchr(line, '\0');
1.1       deraadt   774:        if (!nflag && port)
                    775:                sp = getservbyport((int)port, proto);
                    776:        if (sp || port == 0)
1.23      deraadt   777:                snprintf(cp, line + sizeof line - cp, "%.8s",
                    778:                    sp ? sp->s_name : "*");
1.21      deraadt   779:        else if (local && !nflag && (nam = getrpcportnam(ntohs(port),
                    780:            (strcmp(proto, "tcp") == 0 ? IPPROTO_TCP : IPPROTO_UDP))))
1.23      deraadt   781:                snprintf(cp, line + sizeof line - cp, "%d[%.8s]",
                    782:                    ntohs(port), nam);
1.1       deraadt   783:        else
1.23      deraadt   784:                snprintf(cp, line + sizeof line - cp, "%d", ntohs(port));
1.1       deraadt   785:        width = Aflag ? 18 : 22;
                    786:        printf(" %-*.*s", width, width, line);
                    787: }
                    788:
                    789: /*
                    790:  * Construct an Internet address representation.
                    791:  * If the nflag has been supplied, give
                    792:  * numeric value, otherwise try for symbolic name.
                    793:  */
                    794: char *
1.63      deraadt   795: inetname(struct in_addr *inp)
1.1       deraadt   796: {
1.54      mpech     797:        char *cp;
1.1       deraadt   798:        static char line[50];
                    799:        struct hostent *hp;
                    800:        struct netent *np;
1.57      mpech     801:        static char domain[MAXHOSTNAMELEN];
1.1       deraadt   802:        static int first = 1;
                    803:
                    804:        if (first && !nflag) {
                    805:                first = 0;
1.57      mpech     806:                if (gethostname(domain, sizeof(domain)) == 0 &&
1.4       millert   807:                    (cp = strchr(domain, '.')))
1.60      deraadt   808:                        (void) strlcpy(domain, cp + 1, sizeof domain);
1.1       deraadt   809:                else
1.60      deraadt   810:                        domain[0] = '\0';
1.1       deraadt   811:        }
1.84      deraadt   812:        cp = NULL;
1.1       deraadt   813:        if (!nflag && inp->s_addr != INADDR_ANY) {
                    814:                int net = inet_netof(*inp);
                    815:                int lna = inet_lnaof(*inp);
                    816:
                    817:                if (lna == INADDR_ANY) {
                    818:                        np = getnetbyaddr(net, AF_INET);
                    819:                        if (np)
                    820:                                cp = np->n_name;
                    821:                }
1.84      deraadt   822:                if (cp == NULL) {
1.1       deraadt   823:                        hp = gethostbyaddr((char *)inp, sizeof (*inp), AF_INET);
                    824:                        if (hp) {
1.4       millert   825:                                if ((cp = strchr(hp->h_name, '.')) &&
1.1       deraadt   826:                                    !strcmp(cp + 1, domain))
1.84      deraadt   827:                                        *cp = '\0';
1.1       deraadt   828:                                cp = hp->h_name;
                    829:                        }
                    830:                }
                    831:        }
                    832:        if (inp->s_addr == INADDR_ANY)
1.23      deraadt   833:                snprintf(line, sizeof line, "*");
1.1       deraadt   834:        else if (cp)
1.23      deraadt   835:                snprintf(line, sizeof line, "%s", cp);
1.1       deraadt   836:        else {
                    837:                inp->s_addr = ntohl(inp->s_addr);
                    838: #define C(x)   ((x) & 0xff)
1.23      deraadt   839:                snprintf(line, sizeof line, "%u.%u.%u.%u",
                    840:                    C(inp->s_addr >> 24), C(inp->s_addr >> 16),
                    841:                    C(inp->s_addr >> 8), C(inp->s_addr));
1.1       deraadt   842:        }
                    843:        return (line);
1.10      angelos   844: }
                    845:
                    846: /*
                    847:  * Dump AH statistics structure.
                    848:  */
                    849: void
1.63      deraadt   850: ah_stats(u_long off, char *name)
1.10      angelos   851: {
1.55      mickey    852:        struct ahstat ahstat;
1.10      angelos   853:
1.55      mickey    854:        if (off == 0)
                    855:                return;
                    856:        kread(off, (char *)&ahstat, sizeof (ahstat));
                    857:        printf("%s:\n", name);
1.10      angelos   858:
                    859: #define p(f, m) if (ahstat.f || sflag <= 1) \
1.60      deraadt   860:        printf(m, ahstat.f, plural(ahstat.f))
1.38      itojun    861: #define p1(f, m) if (ahstat.f || sflag <= 1) \
1.60      deraadt   862:        printf(m, ahstat.f)
1.10      angelos   863:
1.38      itojun    864:        p1(ahs_input, "\t%u input AH packets\n");
                    865:        p1(ahs_output, "\t%u output AH packets\n");
1.55      mickey    866:        p(ahs_nopf, "\t%u packet%s from unsupported protocol families\n");
                    867:        p(ahs_hdrops, "\t%u packet%s shorter than header shows\n");
                    868:        p(ahs_pdrops, "\t%u packet%s dropped due to policy\n");
                    869:        p(ahs_notdb, "\t%u packet%s for which no TDB was found\n");
                    870:        p(ahs_badkcr, "\t%u input packet%s that failed to be processed\n");
                    871:        p(ahs_badauth, "\t%u packet%s that failed verification received\n");
                    872:        p(ahs_noxform, "\t%u packet%s for which no XFORM was set in TDB received\n");
                    873:        p(ahs_qfull, "\t%u packet%s were dropped due to full output queue\n");
                    874:        p(ahs_wrap, "\t%u packet%s where counter wrapping was detected\n");
                    875:        p(ahs_replay, "\t%u possibly replayed packet%s received\n");
                    876:        p(ahs_badauthl, "\t%u packet%s with bad authenticator length received\n");
1.62      jsyn      877:        p(ahs_invalid, "\t%u packet%s attempted to use an invalid TDB\n");
1.25      niklas    878:        p(ahs_toobig, "\t%u packet%s got larger than max IP packet size\n");
1.46      angelos   879:        p(ahs_crypto, "\t%u packet%s that failed crypto processing\n");
1.20      angelos   880:        p(ahs_ibytes, "\t%qu input byte%s\n");
                    881:        p(ahs_obytes, "\t%qu output byte%s\n");
                    882:
1.34      angelos   883: #undef p
1.38      itojun    884: #undef p1
1.34      angelos   885: }
                    886:
                    887: /*
                    888:  * Dump etherip statistics structure.
                    889:  */
                    890: void
1.63      deraadt   891: etherip_stats(u_long off, char *name)
1.34      angelos   892: {
1.55      mickey    893:        struct etheripstat etheripstat;
1.34      angelos   894:
1.55      mickey    895:        if (off == 0)
                    896:                return;
                    897:        kread(off, (char *)&etheripstat, sizeof (etheripstat));
                    898:        printf("%s:\n", name);
1.34      angelos   899:
                    900: #define p(f, m) if (etheripstat.f || sflag <= 1) \
1.60      deraadt   901:        printf(m, etheripstat.f, plural(etheripstat.f))
1.34      angelos   902:
1.53      brian     903:        p(etherip_hdrops, "\t%u packet%s shorter than header shows\n");
                    904:        p(etherip_qfull, "\t%u packet%s were dropped due to full output queue\n");
1.34      angelos   905:        p(etherip_noifdrops, "\t%u packet%s were dropped because of no interface/bridge information\n");
1.53      brian     906:        p(etherip_pdrops, "\t%u packet%s dropped due to policy\n");
                    907:        p(etherip_adrops, "\t%u packet%s dropped for other reasons\n");
                    908:        p(etherip_ipackets, "\t%u input ethernet-in-IP packet%s\n");
                    909:        p(etherip_opackets, "\t%u output ethernet-in-IP packet%s\n");
1.34      angelos   910:        p(etherip_ibytes, "\t%qu input byte%s\n");
                    911:        p(etherip_obytes, "\t%qu output byte%s\n");
1.10      angelos   912: #undef p
                    913: }
                    914:
                    915: /*
                    916:  * Dump ESP statistics structure.
                    917:  */
                    918: void
1.63      deraadt   919: esp_stats(u_long off, char *name)
1.10      angelos   920: {
1.55      mickey    921:        struct espstat espstat;
1.10      angelos   922:
1.55      mickey    923:        if (off == 0)
                    924:                return;
                    925:        kread(off, (char *)&espstat, sizeof (espstat));
                    926:        printf("%s:\n", name);
1.10      angelos   927:
                    928: #define p(f, m) if (espstat.f || sflag <= 1) \
1.60      deraadt   929:        printf(m, espstat.f, plural(espstat.f))
1.10      angelos   930:
1.38      itojun    931:        p(esps_input, "\t%u input ESP packet%s\n");
                    932:        p(esps_output, "\t%u output ESP packet%s\n");
1.55      mickey    933:        p(esps_nopf, "\t%u packet%s from unsupported protocol families\n");
                    934:        p(esps_hdrops, "\t%u packet%s shorter than header shows\n");
                    935:        p(esps_pdrops, "\t%u packet%s dropped due to policy\n");
                    936:        p(esps_notdb, "\t%u packet%s for which no TDB was found\n");
                    937:        p(esps_badkcr, "\t%u input packet%s that failed to be processed\n");
                    938:        p(esps_badenc, "\t%u packet%s with bad encryption received\n");
                    939:        p(esps_badauth, "\t%u packet%s that failed verification received\n");
                    940:        p(esps_noxform, "\t%u packet%s for which no XFORM was set in TDB received\n");
                    941:        p(esps_qfull, "\t%u packet%s were dropped due to full output queue\n");
                    942:        p(esps_wrap, "\t%u packet%s where counter wrapping was detected\n");
                    943:        p(esps_replay, "\t%u possibly replayed packet%s received\n");
                    944:        p(esps_badilen, "\t%u packet%s with bad payload size or padding received\n");
1.62      jsyn      945:        p(esps_invalid, "\t%u packet%s attempted to use an invalid TDB\n");
1.25      niklas    946:        p(esps_toobig, "\t%u packet%s got larger than max IP packet size\n");
1.46      angelos   947:        p(esps_crypto, "\t%u packet%s that failed crypto processing\n");
1.74      markus    948:        p(esps_udpencin, "\t%u input UDP encapsulated ESP packet%s\n");
                    949:        p(esps_udpencout, "\t%u output UDP encapsulated ESP packet%s\n");
                    950:        p(esps_udpinval, "\t%u UDP packet%s for non-encapsulating TDB received\n");
1.20      angelos   951:        p(esps_ibytes, "\t%qu input byte%s\n");
                    952:        p(esps_obytes, "\t%qu output byte%s\n");
1.10      angelos   953:
                    954: #undef p
                    955: }
                    956:
                    957: /*
1.67      deraadt   958:  * Dump IP-in-IP statistics structure.
1.10      angelos   959:  */
                    960: void
1.63      deraadt   961: ipip_stats(u_long off, char *name)
1.10      angelos   962: {
1.55      mickey    963:        struct ipipstat ipipstat;
1.10      angelos   964:
1.55      mickey    965:        if (off == 0)
                    966:                return;
                    967:        kread(off, (char *)&ipipstat, sizeof (ipipstat));
                    968:        printf("%s:\n", name);
1.10      angelos   969:
1.45      angelos   970: #define p(f, m) if (ipipstat.f || sflag <= 1) \
1.60      deraadt   971:        printf(m, ipipstat.f, plural(ipipstat.f))
1.10      angelos   972:
1.55      mickey    973:        p(ipips_ipackets, "\t%u total input packet%s\n");
                    974:        p(ipips_opackets, "\t%u total output packet%s\n");
                    975:        p(ipips_hdrops, "\t%u packet%s shorter than header shows\n");
                    976:        p(ipips_pdrops, "\t%u packet%s dropped due to policy\n");
                    977:        p(ipips_spoof, "\t%u packet%s with possibly spoofed local addresses\n");
                    978:        p(ipips_qfull, "\t%u packet%s were dropped due to full output queue\n");
1.45      angelos   979:        p(ipips_ibytes, "\t%qu input byte%s\n");
                    980:        p(ipips_obytes, "\t%qu output byte%s\n");
1.63      deraadt   981:        p(ipips_family, "\t%u protocol family mismatche%s\n");
                    982:        p(ipips_unspec, "\t%u attempt%s to use tunnel with unspecified endpoint(s)\n");
1.69      mcbride   983: #undef p
                    984: }
                    985:
1.84      deraadt   986: /*
1.69      mcbride   987:  * Dump CARP statistics structure.
                    988:  */
                    989: void
                    990: carp_stats(u_long off, char *name)
                    991: {
                    992:        struct carpstats carpstat;
                    993:
                    994:        if (off == 0)
                    995:                return;
                    996:        kread(off, (char *)&carpstat, sizeof(carpstat));
                    997:        printf("%s:\n", name);
                    998:
                    999: #define p(f, m) if (carpstat.f || sflag <= 1) \
                   1000:        printf(m, carpstat.f, plural(carpstat.f))
                   1001: #define p2(f, m) if (carpstat.f || sflag <= 1) \
                   1002:        printf(m, carpstat.f)
                   1003:
1.87      mcbride  1004:        p(carps_ipackets, "\t%llu packet%s received (IPv4)\n");
                   1005:        p(carps_ipackets6, "\t%llu packet%s received (IPv6)\n");
                   1006:        p(carps_badif, "\t\t%llu packet%s discarded for bad interface\n");
1.89      mcbride  1007:        p(carps_badttl, "\t\t%llu packet%s discarded for wrong TTL\n");
1.87      mcbride  1008:        p(carps_hdrops, "\t\t%llu packet%s shorter than header\n");
                   1009:        p(carps_badsum, "\t\t%llu discarded for bad checksum%s\n");
                   1010:        p(carps_badver, "\t\t%llu discarded packet%s with a bad version\n");
                   1011:        p2(carps_badlen, "\t\t%llu discarded because packet too short\n");
                   1012:        p2(carps_badauth, "\t\t%llu discarded for bad authentication\n");
                   1013:        p2(carps_badvhid, "\t\t%llu discarded for bad vhid\n");
                   1014:        p2(carps_badaddrs, "\t\t%llu discarded because of a bad address list\n");
                   1015:        p(carps_opackets, "\t%llu packet%s sent (IPv4)\n");
                   1016:        p(carps_opackets6, "\t%llu packet%s sent (IPv6)\n");
1.89      mcbride  1017:        p2(carps_onomem, "\t\t%llu send failed due to mbuf memory error\n");
1.51      jjbg     1018: #undef p
1.70      mcbride  1019: #undef p2
1.51      jjbg     1020: }
                   1021:
1.75      mcbride  1022: /*
                   1023:  * Dump pfsync statistics structure.
                   1024:  */
                   1025: void
                   1026: pfsync_stats(u_long off, char *name)
                   1027: {
                   1028:        struct pfsyncstats pfsyncstat;
                   1029:
                   1030:        if (off == 0)
                   1031:                return;
                   1032:        kread(off, (char *)&pfsyncstat, sizeof(pfsyncstat));
                   1033:        printf("%s:\n", name);
                   1034:
                   1035: #define p(f, m) if (pfsyncstat.f || sflag <= 1) \
                   1036:        printf(m, pfsyncstat.f, plural(pfsyncstat.f))
                   1037: #define p2(f, m) if (pfsyncstat.f || sflag <= 1) \
                   1038:        printf(m, pfsyncstat.f)
                   1039:
1.86      mcbride  1040:        p(pfsyncs_ipackets, "\t%llu packet%s received (IPv4)\n");
                   1041:        p(pfsyncs_ipackets6, "\t%llu packet%s received (IPv6)\n");
                   1042:        p(pfsyncs_badif, "\t\t%llu packet%s discarded for bad interface\n");
                   1043:        p(pfsyncs_badttl, "\t\t%llu packet%s discarded for bad ttl\n");
                   1044:        p(pfsyncs_hdrops, "\t\t%llu packet%s shorter than header\n");
                   1045:        p(pfsyncs_badver, "\t\t%llu packet%s discarded for bad version\n");
                   1046:        p(pfsyncs_badauth, "\t\t%llu packet%s discarded for bad HMAC\n");
                   1047:        p(pfsyncs_badact,"\t\t%llu packet%s discarded for bad action\n");
                   1048:        p(pfsyncs_badlen, "\t\t%llu packet%s discarded for short packet\n");
                   1049:        p(pfsyncs_badval, "\t\t%llu state%s discarded for bad values\n");
                   1050:        p(pfsyncs_stale, "\t\t%llu stale state%s\n");
                   1051:        p(pfsyncs_badstate, "\t\t%llu failed state lookup/insert%s\n");
                   1052:        p(pfsyncs_opackets, "\t%llu packet%s sent (IPv4)\n");
                   1053:        p(pfsyncs_opackets6, "\t%llu packet%s sent (IPv6)\n");
                   1054:        p2(pfsyncs_onomem, "\t\t%llu send failed due to mbuf memory error\n");
                   1055:        p2(pfsyncs_oerrors, "\t\t%llu send error\n");
1.75      mcbride  1056: #undef p
                   1057: #undef p2
                   1058: }
                   1059:
1.51      jjbg     1060: /*
                   1061:  * Dump IPCOMP statistics structure.
                   1062:  */
                   1063: void
1.63      deraadt  1064: ipcomp_stats(u_long off, char *name)
1.51      jjbg     1065: {
                   1066:        struct ipcompstat ipcompstat;
                   1067:
                   1068:        if (off == 0)
                   1069:                return;
                   1070:        kread(off, (char *)&ipcompstat, sizeof (ipcompstat));
                   1071:        printf("%s:\n", name);
                   1072:
                   1073: #define p(f, m) if (ipcompstat.f || sflag <= 1) \
1.60      deraadt  1074:        printf(m, ipcompstat.f, plural(ipcompstat.f))
1.51      jjbg     1075:
                   1076:        p(ipcomps_input, "\t%u input IPCOMP packet%s\n");
                   1077:        p(ipcomps_output, "\t%u output IPCOMP packet%s\n");
                   1078:        p(ipcomps_nopf, "\t%u packet%s from unsupported protocol families\n");
                   1079:        p(ipcomps_hdrops, "\t%u packet%s shorter than header shows\n");
                   1080:        p(ipcomps_pdrops, "\t%u packet%s dropped due to policy\n");
                   1081:        p(ipcomps_notdb, "\t%u packet%s for which no TDB was found\n");
                   1082:        p(ipcomps_badkcr, "\t%u input packet%s that failed to be processed\n");
1.55      mickey   1083:        p(ipcomps_noxform, "\t%u packet%s for which no XFORM was set in TDB received\n");
1.51      jjbg     1084:        p(ipcomps_qfull, "\t%u packet%s were dropped due to full output queue\n");
                   1085:        p(ipcomps_wrap, "\t%u packet%s where counter wrapping was detected\n");
1.62      jsyn     1086:        p(ipcomps_invalid, "\t%u packet%s attempted to use an invalid TDB\n");
1.51      jjbg     1087:        p(ipcomps_toobig, "\t%u packet%s got larger than max IP packet size\n");
                   1088:        p(ipcomps_crypto, "\t%u packet%s that failed (de)compression processing\n");
1.64      jason    1089:        p(ipcomps_minlen, "\t%u packet%s less than minimum compression length\n");
1.51      jjbg     1090:        p(ipcomps_ibytes, "\t%qu input byte%s\n");
                   1091:        p(ipcomps_obytes, "\t%qu output byte%s\n");
                   1092:
1.10      angelos  1093: #undef p
1.1       deraadt  1094: }