[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.77

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