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