165475bc8SDavid E. O'Brien /*- 205ddff6eSPeter Wemm * Copyright (c) 1983, 1988, 1993, 1995 39b50d902SRodney W. Grimes * The Regents of the University of California. All rights reserved. 49b50d902SRodney W. Grimes * 59b50d902SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 69b50d902SRodney W. Grimes * modification, are permitted provided that the following conditions 79b50d902SRodney W. Grimes * are met: 89b50d902SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 99b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 109b50d902SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 119b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 129b50d902SRodney W. Grimes * documentation and/or other materials provided with the distribution. 13fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 149b50d902SRodney W. Grimes * may be used to endorse or promote products derived from this software 159b50d902SRodney W. Grimes * without specific prior written permission. 169b50d902SRodney W. Grimes * 179b50d902SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 189b50d902SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 199b50d902SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 209b50d902SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 219b50d902SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 229b50d902SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 239b50d902SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 249b50d902SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 259b50d902SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 269b50d902SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 279b50d902SRodney W. Grimes * SUCH DAMAGE. 289b50d902SRodney W. Grimes */ 299b50d902SRodney W. Grimes 306cc6f122SPhilippe Charnier #if 0 319b50d902SRodney W. Grimes #ifndef lint 3205ddff6eSPeter Wemm static char sccsid[] = "@(#)inet.c 8.5 (Berkeley) 5/24/95"; 339b50d902SRodney W. Grimes #endif /* not lint */ 346cc6f122SPhilippe Charnier #endif 356cc6f122SPhilippe Charnier 366cc6f122SPhilippe Charnier #include <sys/cdefs.h> 376cc6f122SPhilippe Charnier __FBSDID("$FreeBSD$"); 389b50d902SRodney W. Grimes 399b50d902SRodney W. Grimes #include <sys/param.h> 40d8d89152SDavid Greenman #include <sys/queue.h> 41feda1a43SJohn Baldwin #include <sys/domain.h> 42f35a2092SMaksim Yevmenkin #include <sys/protosw.h> 439b50d902SRodney W. Grimes #include <sys/socket.h> 44*0e229f34SGleb Smirnoff #define _WANT_SOCKET 459b50d902SRodney W. Grimes #include <sys/socketvar.h> 464e00c309SGarrett Wollman #include <sys/sysctl.h> 479b50d902SRodney W. Grimes 489b50d902SRodney W. Grimes #include <net/route.h> 4954fc657dSGeorge V. Neville-Neil #include <net/if_arp.h> 509b50d902SRodney W. Grimes #include <netinet/in.h> 519b50d902SRodney W. Grimes #include <netinet/in_systm.h> 529b50d902SRodney W. Grimes #include <netinet/ip.h> 53a9771948SGleb Smirnoff #include <netinet/ip_carp.h> 54cfa1ca9dSYoshinobu Inoue #ifdef INET6 55cfa1ca9dSYoshinobu Inoue #include <netinet/ip6.h> 56cfa1ca9dSYoshinobu Inoue #endif /* INET6 */ 579b50d902SRodney W. Grimes #include <netinet/in_pcb.h> 589b50d902SRodney W. Grimes #include <netinet/ip_icmp.h> 599b50d902SRodney W. Grimes #include <netinet/icmp_var.h> 609b50d902SRodney W. Grimes #include <netinet/igmp_var.h> 619b50d902SRodney W. Grimes #include <netinet/ip_var.h> 62c7b9b5bbSJeffrey Hsu #include <netinet/pim_var.h> 639b50d902SRodney W. Grimes #include <netinet/tcp.h> 649b50d902SRodney W. Grimes #include <netinet/tcpip.h> 659b50d902SRodney W. Grimes #include <netinet/tcp_seq.h> 669b50d902SRodney W. Grimes #define TCPSTATES 679b50d902SRodney W. Grimes #include <netinet/tcp_fsm.h> 689b50d902SRodney W. Grimes #include <netinet/tcp_timer.h> 699b50d902SRodney W. Grimes #include <netinet/tcp_var.h> 709b50d902SRodney W. Grimes #include <netinet/udp.h> 719b50d902SRodney W. Grimes #include <netinet/udp_var.h> 729b50d902SRodney W. Grimes 739b50d902SRodney W. Grimes #include <arpa/inet.h> 744f81ef50SGarrett Wollman #include <err.h> 754f81ef50SGarrett Wollman #include <errno.h> 76d121b556SBrian Somers #include <libutil.h> 779b50d902SRodney W. Grimes #include <netdb.h> 787b95a1ebSYaroslav Tykhiy #include <stdint.h> 799b50d902SRodney W. Grimes #include <stdio.h> 804f81ef50SGarrett Wollman #include <stdlib.h> 81ade9ccfeSMarcel Moolenaar #include <stdbool.h> 829b50d902SRodney W. Grimes #include <string.h> 839b50d902SRodney W. Grimes #include <unistd.h> 84ade9ccfeSMarcel Moolenaar #include <libxo/xo.h> 859b50d902SRodney W. Grimes #include "netstat.h" 86dbfd8708SGleb Smirnoff #include "nl_defs.h" 879b50d902SRodney W. Grimes 88046aad39SHajimu UMEMOTO void inetprint(const char *, struct in_addr *, int, const char *, int, 89046aad39SHajimu UMEMOTO const int); 90cfa1ca9dSYoshinobu Inoue #ifdef INET6 91aa0a1e58SJeff Roberson static int udp_done, tcp_done, sdp_done; 92cfa1ca9dSYoshinobu Inoue #endif /* INET6 */ 939b50d902SRodney W. Grimes 94feda1a43SJohn Baldwin static int 95cc65eb4eSGleb Smirnoff pcblist_sysctl(int proto, const char *name, char **bufp) 96feda1a43SJohn Baldwin { 97feda1a43SJohn Baldwin const char *mibvar; 98feda1a43SJohn Baldwin char *buf; 99feda1a43SJohn Baldwin size_t len; 100feda1a43SJohn Baldwin 101feda1a43SJohn Baldwin switch (proto) { 102feda1a43SJohn Baldwin case IPPROTO_TCP: 103feda1a43SJohn Baldwin mibvar = "net.inet.tcp.pcblist"; 104feda1a43SJohn Baldwin break; 105feda1a43SJohn Baldwin case IPPROTO_UDP: 106feda1a43SJohn Baldwin mibvar = "net.inet.udp.pcblist"; 107feda1a43SJohn Baldwin break; 108feda1a43SJohn Baldwin case IPPROTO_DIVERT: 109feda1a43SJohn Baldwin mibvar = "net.inet.divert.pcblist"; 110feda1a43SJohn Baldwin break; 111feda1a43SJohn Baldwin default: 112feda1a43SJohn Baldwin mibvar = "net.inet.raw.pcblist"; 113feda1a43SJohn Baldwin break; 114feda1a43SJohn Baldwin } 115aa0a1e58SJeff Roberson if (strncmp(name, "sdp", 3) == 0) 116aa0a1e58SJeff Roberson mibvar = "net.inet.sdp.pcblist"; 117feda1a43SJohn Baldwin len = 0; 118feda1a43SJohn Baldwin if (sysctlbyname(mibvar, 0, &len, 0, 0) < 0) { 119feda1a43SJohn Baldwin if (errno != ENOENT) 120ade9ccfeSMarcel Moolenaar xo_warn("sysctl: %s", mibvar); 121feda1a43SJohn Baldwin return (0); 122feda1a43SJohn Baldwin } 123ef1cb629SMarcelo Araujo if ((buf = malloc(len)) == NULL) { 124ade9ccfeSMarcel Moolenaar xo_warnx("malloc %lu bytes", (u_long)len); 125feda1a43SJohn Baldwin return (0); 126feda1a43SJohn Baldwin } 127feda1a43SJohn Baldwin if (sysctlbyname(mibvar, buf, &len, 0, 0) < 0) { 128ade9ccfeSMarcel Moolenaar xo_warn("sysctl: %s", mibvar); 129feda1a43SJohn Baldwin free(buf); 130feda1a43SJohn Baldwin return (0); 131feda1a43SJohn Baldwin } 132feda1a43SJohn Baldwin *bufp = buf; 133feda1a43SJohn Baldwin return (1); 134feda1a43SJohn Baldwin } 135feda1a43SJohn Baldwin 136feda1a43SJohn Baldwin /* 137feda1a43SJohn Baldwin * Copied directly from uipc_socket2.c. We leave out some fields that are in 138feda1a43SJohn Baldwin * nested structures that aren't used to avoid extra work. 139feda1a43SJohn Baldwin */ 140feda1a43SJohn Baldwin static void 141feda1a43SJohn Baldwin sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb) 142feda1a43SJohn Baldwin { 1430f9d0a73SGleb Smirnoff xsb->sb_cc = sb->sb_ccc; 144feda1a43SJohn Baldwin xsb->sb_hiwat = sb->sb_hiwat; 145feda1a43SJohn Baldwin xsb->sb_mbcnt = sb->sb_mbcnt; 14649f287f8SGeorge V. Neville-Neil xsb->sb_mcnt = sb->sb_mcnt; 14749f287f8SGeorge V. Neville-Neil xsb->sb_ccnt = sb->sb_ccnt; 148feda1a43SJohn Baldwin xsb->sb_mbmax = sb->sb_mbmax; 149feda1a43SJohn Baldwin xsb->sb_lowat = sb->sb_lowat; 150feda1a43SJohn Baldwin xsb->sb_flags = sb->sb_flags; 151feda1a43SJohn Baldwin xsb->sb_timeo = sb->sb_timeo; 152feda1a43SJohn Baldwin } 153feda1a43SJohn Baldwin 154feda1a43SJohn Baldwin int 155feda1a43SJohn Baldwin sotoxsocket(struct socket *so, struct xsocket *xso) 156feda1a43SJohn Baldwin { 157feda1a43SJohn Baldwin struct protosw proto; 158feda1a43SJohn Baldwin struct domain domain; 159feda1a43SJohn Baldwin 160feda1a43SJohn Baldwin bzero(xso, sizeof *xso); 161feda1a43SJohn Baldwin xso->xso_len = sizeof *xso; 162feda1a43SJohn Baldwin xso->xso_so = so; 163feda1a43SJohn Baldwin xso->so_type = so->so_type; 164feda1a43SJohn Baldwin xso->so_options = so->so_options; 165feda1a43SJohn Baldwin xso->so_linger = so->so_linger; 166feda1a43SJohn Baldwin xso->so_state = so->so_state; 167feda1a43SJohn Baldwin xso->so_pcb = so->so_pcb; 168feda1a43SJohn Baldwin if (kread((uintptr_t)so->so_proto, &proto, sizeof(proto)) != 0) 169feda1a43SJohn Baldwin return (-1); 170feda1a43SJohn Baldwin xso->xso_protocol = proto.pr_protocol; 171feda1a43SJohn Baldwin if (kread((uintptr_t)proto.pr_domain, &domain, sizeof(domain)) != 0) 172feda1a43SJohn Baldwin return (-1); 173feda1a43SJohn Baldwin xso->xso_family = domain.dom_family; 174feda1a43SJohn Baldwin xso->so_timeo = so->so_timeo; 175feda1a43SJohn Baldwin xso->so_error = so->so_error; 176*0e229f34SGleb Smirnoff if ((so->so_options & SO_ACCEPTCONN) != 0) { 177779f106aSGleb Smirnoff xso->so_qlen = so->sol_qlen; 178779f106aSGleb Smirnoff xso->so_incqlen = so->sol_incqlen; 179779f106aSGleb Smirnoff xso->so_qlimit = so->sol_qlimit; 180779f106aSGleb Smirnoff } else { 181feda1a43SJohn Baldwin sbtoxsockbuf(&so->so_snd, &xso->so_snd); 182feda1a43SJohn Baldwin sbtoxsockbuf(&so->so_rcv, &xso->so_rcv); 183779f106aSGleb Smirnoff xso->so_oobmark = so->so_oobmark; 184779f106aSGleb Smirnoff } 185feda1a43SJohn Baldwin return (0); 186feda1a43SJohn Baldwin } 187feda1a43SJohn Baldwin 1889b50d902SRodney W. Grimes /* 1899b50d902SRodney W. Grimes * Print a summary of connections related to an Internet 1909b50d902SRodney W. Grimes * protocol. For TCP, also give state of connection. 1919b50d902SRodney W. Grimes * Listening processes (aflag) are suppressed unless the 1929b50d902SRodney W. Grimes * -a (all) flag is specified. 1939b50d902SRodney W. Grimes */ 1949b50d902SRodney W. Grimes void 195feda1a43SJohn Baldwin protopr(u_long off, const char *name, int af1, int proto) 1969b50d902SRodney W. Grimes { 1979b50d902SRodney W. Grimes static int first = 1; 198cc65eb4eSGleb Smirnoff int istcp; 1994f81ef50SGarrett Wollman char *buf; 200feda1a43SJohn Baldwin const char *vchar; 201cc65eb4eSGleb Smirnoff struct xtcpcb *tp; 202cc65eb4eSGleb Smirnoff struct xinpcb *inp; 2034f81ef50SGarrett Wollman struct xinpgen *xig, *oxig; 2044f81ef50SGarrett Wollman struct xsocket *so; 2059b50d902SRodney W. Grimes 2064f81ef50SGarrett Wollman istcp = 0; 2074f81ef50SGarrett Wollman switch (proto) { 2084f81ef50SGarrett Wollman case IPPROTO_TCP: 209cfa1ca9dSYoshinobu Inoue #ifdef INET6 210aa0a1e58SJeff Roberson if (strncmp(name, "sdp", 3) != 0) { 211cfa1ca9dSYoshinobu Inoue if (tcp_done != 0) 212cfa1ca9dSYoshinobu Inoue return; 213cfa1ca9dSYoshinobu Inoue else 214cfa1ca9dSYoshinobu Inoue tcp_done = 1; 215aa0a1e58SJeff Roberson } else { 216aa0a1e58SJeff Roberson if (sdp_done != 0) 217aa0a1e58SJeff Roberson return; 218aa0a1e58SJeff Roberson else 219aa0a1e58SJeff Roberson sdp_done = 1; 220aa0a1e58SJeff Roberson } 221cfa1ca9dSYoshinobu Inoue #endif 2224f81ef50SGarrett Wollman istcp = 1; 2234f81ef50SGarrett Wollman break; 2244f81ef50SGarrett Wollman case IPPROTO_UDP: 225cfa1ca9dSYoshinobu Inoue #ifdef INET6 226cfa1ca9dSYoshinobu Inoue if (udp_done != 0) 227cfa1ca9dSYoshinobu Inoue return; 228cfa1ca9dSYoshinobu Inoue else 229cfa1ca9dSYoshinobu Inoue udp_done = 1; 230cfa1ca9dSYoshinobu Inoue #endif 2314f81ef50SGarrett Wollman break; 2324f81ef50SGarrett Wollman } 233cc65eb4eSGleb Smirnoff 234cc65eb4eSGleb Smirnoff if (!pcblist_sysctl(proto, name, &buf)) 2359b50d902SRodney W. Grimes return; 2364f81ef50SGarrett Wollman 2374f81ef50SGarrett Wollman oxig = xig = (struct xinpgen *)buf; 2384f81ef50SGarrett Wollman for (xig = (struct xinpgen *)((char *)xig + xig->xig_len); 2394f81ef50SGarrett Wollman xig->xig_len > sizeof(struct xinpgen); 2404f81ef50SGarrett Wollman xig = (struct xinpgen *)((char *)xig + xig->xig_len)) { 2419b50d902SRodney W. Grimes if (istcp) { 242cc65eb4eSGleb Smirnoff tp = (struct xtcpcb *)xig; 243cc65eb4eSGleb Smirnoff inp = &tp->xt_inp; 2444f81ef50SGarrett Wollman } else { 245cc65eb4eSGleb Smirnoff inp = (struct xinpcb *)xig; 2469b50d902SRodney W. Grimes } 247cc65eb4eSGleb Smirnoff so = &inp->xi_socket; 2484f81ef50SGarrett Wollman 2494f81ef50SGarrett Wollman /* Ignore sockets for protocols other than the desired one. */ 250feda1a43SJohn Baldwin if (so->xso_protocol != proto) 2514f81ef50SGarrett Wollman continue; 2524f81ef50SGarrett Wollman 2534f81ef50SGarrett Wollman /* Ignore PCBs which were freed during copyout. */ 2544f81ef50SGarrett Wollman if (inp->inp_gencnt > oxig->xig_gen) 2554f81ef50SGarrett Wollman continue; 2564f81ef50SGarrett Wollman 257a01e3379SDavid Malone if ((af1 == AF_INET && (inp->inp_vflag & INP_IPV4) == 0) 258cfa1ca9dSYoshinobu Inoue #ifdef INET6 259a01e3379SDavid Malone || (af1 == AF_INET6 && (inp->inp_vflag & INP_IPV6) == 0) 260cfa1ca9dSYoshinobu Inoue #endif /* INET6 */ 261a01e3379SDavid Malone || (af1 == AF_UNSPEC && ((inp->inp_vflag & INP_IPV4) == 0 262cfa1ca9dSYoshinobu Inoue #ifdef INET6 2633feeb332SDavid E. O'Brien && (inp->inp_vflag & INP_IPV6) == 0 264cfa1ca9dSYoshinobu Inoue #endif /* INET6 */ 265cfa1ca9dSYoshinobu Inoue )) 266cfa1ca9dSYoshinobu Inoue ) 267cfa1ca9dSYoshinobu Inoue continue; 268cfa1ca9dSYoshinobu Inoue if (!aflag && 269cfa1ca9dSYoshinobu Inoue ( 2702b286cedSBruce M Simpson (istcp && tp->t_state == TCPS_LISTEN) 2712b286cedSBruce M Simpson || (af1 == AF_INET && 272cfa1ca9dSYoshinobu Inoue inet_lnaof(inp->inp_laddr) == INADDR_ANY) 273cfa1ca9dSYoshinobu Inoue #ifdef INET6 274a01e3379SDavid Malone || (af1 == AF_INET6 && 275cfa1ca9dSYoshinobu Inoue IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)) 276cfa1ca9dSYoshinobu Inoue #endif /* INET6 */ 277a01e3379SDavid Malone || (af1 == AF_UNSPEC && 278cfa1ca9dSYoshinobu Inoue (((inp->inp_vflag & INP_IPV4) != 0 && 279cfa1ca9dSYoshinobu Inoue inet_lnaof(inp->inp_laddr) == INADDR_ANY) 280cfa1ca9dSYoshinobu Inoue #ifdef INET6 281cfa1ca9dSYoshinobu Inoue || ((inp->inp_vflag & INP_IPV6) != 0 && 282cfa1ca9dSYoshinobu Inoue IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)) 283cfa1ca9dSYoshinobu Inoue #endif 284cfa1ca9dSYoshinobu Inoue )) 285cfa1ca9dSYoshinobu Inoue )) 2864f81ef50SGarrett Wollman continue; 2874f81ef50SGarrett Wollman 2889b50d902SRodney W. Grimes if (first) { 289ac55add0SGuido van Rooij if (!Lflag) { 290ade9ccfeSMarcel Moolenaar xo_emit("Active Internet connections"); 2919b50d902SRodney W. Grimes if (aflag) 292ade9ccfeSMarcel Moolenaar xo_emit(" (including servers)"); 293ac55add0SGuido van Rooij } else 294ade9ccfeSMarcel Moolenaar xo_emit( 295ac55add0SGuido van Rooij "Current listen queue sizes (qlen/incqlen/maxqlen)"); 296ade9ccfeSMarcel Moolenaar xo_emit("\n"); 2979b50d902SRodney W. Grimes if (Aflag) 298ade9ccfeSMarcel Moolenaar xo_emit("{T:/%-*s} ", 2 * (int)sizeof(void *), 299ade9ccfeSMarcel Moolenaar "Tcpcb"); 300ac55add0SGuido van Rooij if (Lflag) 301ade9ccfeSMarcel Moolenaar xo_emit((Aflag && !Wflag) ? 302db2627f4SMichael Tuexen "{T:/%-5.5s} {T:/%-32.32s} {T:/%-18.18s}" : 303046aad39SHajimu UMEMOTO ((!Wflag || af1 == AF_INET) ? 304db2627f4SMichael Tuexen "{T:/%-5.5s} {T:/%-32.32s} {T:/%-22.22s}" : 305db2627f4SMichael Tuexen "{T:/%-5.5s} {T:/%-32.32s} {T:/%-45.45s}"), 306afc74015SRuslan Ermilov "Proto", "Listen", "Local Address"); 307afc74015SRuslan Ermilov else if (Tflag) 308ade9ccfeSMarcel Moolenaar xo_emit((Aflag && !Wflag) ? 309ade9ccfeSMarcel Moolenaar "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-18.18s} {T:/%s}" : 310046aad39SHajimu UMEMOTO ((!Wflag || af1 == AF_INET) ? 311046aad39SHajimu UMEMOTO "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-22.22s} {T:/%s}" : 312046aad39SHajimu UMEMOTO "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-45.45s} {T:/%s}"), 313f5d34df5SGeorge V. Neville-Neil "Proto", "Rexmit", "OOORcv", "0-win", 31449f287f8SGeorge V. Neville-Neil "Local Address", "Foreign Address"); 315afc74015SRuslan Ermilov else { 316ade9ccfeSMarcel Moolenaar xo_emit((Aflag && !Wflag) ? 317ade9ccfeSMarcel Moolenaar "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-18.18s} {T:/%-18.18s}" : 318046aad39SHajimu UMEMOTO ((!Wflag || af1 == AF_INET) ? 319046aad39SHajimu UMEMOTO "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-22.22s} {T:/%-22.22s}" : 320046aad39SHajimu UMEMOTO "{T:/%-5.5s} {T:/%-6.6s} {T:/%-6.6s} {T:/%-45.45s} {T:/%-45.45s}"), 321afc74015SRuslan Ermilov "Proto", "Recv-Q", "Send-Q", 322afc74015SRuslan Ermilov "Local Address", "Foreign Address"); 32385b0f0f3SAdrian Chadd if (!xflag && !Rflag) 324ade9ccfeSMarcel Moolenaar xo_emit(" (state)"); 325afc74015SRuslan Ermilov } 326b8614722SMike Silbersack if (xflag) { 327ade9ccfeSMarcel Moolenaar xo_emit(" {T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} " 328ade9ccfeSMarcel Moolenaar "{T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} " 329ade9ccfeSMarcel Moolenaar "{T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s} " 330ade9ccfeSMarcel Moolenaar "{T:/%-6.6s} {T:/%-6.6s} {T:/%-6.6s}", 331ade9ccfeSMarcel Moolenaar "R-MBUF", "S-MBUF", "R-CLUS", "S-CLUS", 332ade9ccfeSMarcel Moolenaar "R-HIWA", "S-HIWA", "R-LOWA", "S-LOWA", 333ade9ccfeSMarcel Moolenaar "R-BCNT", "S-BCNT", "R-BMAX", "S-BMAX"); 334ade9ccfeSMarcel Moolenaar xo_emit(" {T:/%7.7s} {T:/%7.7s} {T:/%7.7s} " 335ade9ccfeSMarcel Moolenaar "{T:/%7.7s} {T:/%7.7s} {T:/%7.7s}", 336ade9ccfeSMarcel Moolenaar "rexmt", "persist", "keep", "2msl", 337ade9ccfeSMarcel Moolenaar "delack", "rcvtime"); 33885b0f0f3SAdrian Chadd } else if (Rflag) { 339ade9ccfeSMarcel Moolenaar xo_emit(" {T:/%8.8s} {T:/%5.5s}", 34085b0f0f3SAdrian Chadd "flowid", "ftype"); 34194f138feSGeorge V. Neville-Neil } 342ade9ccfeSMarcel Moolenaar xo_emit("\n"); 3439b50d902SRodney W. Grimes first = 0; 3449b50d902SRodney W. Grimes } 345fb5d0fbdSRuslan Ermilov if (Lflag && so->so_qlimit == 0) 346fb5d0fbdSRuslan Ermilov continue; 347ade9ccfeSMarcel Moolenaar xo_open_instance("socket"); 348e4ec3989SDag-Erling Smørgrav if (Aflag) { 349e4ec3989SDag-Erling Smørgrav if (istcp) 350ade9ccfeSMarcel Moolenaar xo_emit("{q:address/%*lx} ", 351ade9ccfeSMarcel Moolenaar 2 * (int)sizeof(void *), 352ade9ccfeSMarcel Moolenaar (u_long)inp->inp_ppcb); 353e4ec3989SDag-Erling Smørgrav else 354d9646465SGleb Smirnoff xo_emit("{q:address/%*lx} ", 355ade9ccfeSMarcel Moolenaar 2 * (int)sizeof(void *), 356ade9ccfeSMarcel Moolenaar (u_long)so->so_pcb); 357e4ec3989SDag-Erling Smørgrav } 358cfa1ca9dSYoshinobu Inoue #ifdef INET6 359fc60ab7bSYoshinobu Inoue if ((inp->inp_vflag & INP_IPV6) != 0) 3603feeb332SDavid E. O'Brien vchar = ((inp->inp_vflag & INP_IPV4) != 0) ? 3613feeb332SDavid E. O'Brien "46" : "6"; 362fc60ab7bSYoshinobu Inoue else 363cfa1ca9dSYoshinobu Inoue #endif 3643feeb332SDavid E. O'Brien vchar = ((inp->inp_vflag & INP_IPV4) != 0) ? 3653feeb332SDavid E. O'Brien "4" : ""; 36609fe6320SNavdeep Parhar if (istcp && (tp->t_flags & TF_TOE) != 0) 367ade9ccfeSMarcel Moolenaar xo_emit("{:protocol/%-3.3s%-2.2s/%s%s} ", "toe", vchar); 36809fe6320SNavdeep Parhar else 369ade9ccfeSMarcel Moolenaar xo_emit("{:protocol/%-3.3s%-2.2s/%s%s} ", name, vchar); 370fb5d0fbdSRuslan Ermilov if (Lflag) { 3717325dfbbSAlfred Perlstein char buf1[33]; 372fc60ab7bSYoshinobu Inoue 3737325dfbbSAlfred Perlstein snprintf(buf1, sizeof buf1, "%u/%u/%u", so->so_qlen, 374fb5d0fbdSRuslan Ermilov so->so_incqlen, so->so_qlimit); 3757325dfbbSAlfred Perlstein xo_emit("{:listen-queue-sizes/%-32.32s} ", buf1); 376f5d34df5SGeorge V. Neville-Neil } else if (Tflag) { 377f5d34df5SGeorge V. Neville-Neil if (istcp) 378ade9ccfeSMarcel Moolenaar xo_emit("{:sent-retransmit-packets/%6u} " 379ade9ccfeSMarcel Moolenaar "{:received-out-of-order-packets/%6u} " 380ade9ccfeSMarcel Moolenaar "{:sent-zero-window/%6u} ", 381ade9ccfeSMarcel Moolenaar tp->t_sndrexmitpack, tp->t_rcvoopack, 382ade9ccfeSMarcel Moolenaar tp->t_sndzerowin); 3830eaa116eSHajimu UMEMOTO else 3840eaa116eSHajimu UMEMOTO xo_emit("{P:/%21s}", ""); 385fb5d0fbdSRuslan Ermilov } else { 386ade9ccfeSMarcel Moolenaar xo_emit("{:receive-bytes-waiting/%6u} " 387ade9ccfeSMarcel Moolenaar "{:send-bytes-waiting/%6u} ", 3880f9d0a73SGleb Smirnoff so->so_rcv.sb_cc, so->so_snd.sb_cc); 389fc60ab7bSYoshinobu Inoue } 39065ea0024SAssar Westerlund if (numeric_port) { 391cfa1ca9dSYoshinobu Inoue if (inp->inp_vflag & INP_IPV4) { 392ade9ccfeSMarcel Moolenaar inetprint("local", &inp->inp_laddr, 393046aad39SHajimu UMEMOTO (int)inp->inp_lport, name, 1, af1); 394ac55add0SGuido van Rooij if (!Lflag) 395ade9ccfeSMarcel Moolenaar inetprint("remote", &inp->inp_faddr, 396046aad39SHajimu UMEMOTO (int)inp->inp_fport, name, 1, af1); 397cfa1ca9dSYoshinobu Inoue } 398cfa1ca9dSYoshinobu Inoue #ifdef INET6 399cfa1ca9dSYoshinobu Inoue else if (inp->inp_vflag & INP_IPV6) { 400ade9ccfeSMarcel Moolenaar inet6print("local", &inp->in6p_laddr, 401cfa1ca9dSYoshinobu Inoue (int)inp->inp_lport, name, 1); 402ac55add0SGuido van Rooij if (!Lflag) 403ade9ccfeSMarcel Moolenaar inet6print("remote", &inp->in6p_faddr, 404cfa1ca9dSYoshinobu Inoue (int)inp->inp_fport, name, 1); 405cfa1ca9dSYoshinobu Inoue } /* else nothing printed now */ 406cfa1ca9dSYoshinobu Inoue #endif /* INET6 */ 4074f81ef50SGarrett Wollman } else if (inp->inp_flags & INP_ANONPORT) { 408cfa1ca9dSYoshinobu Inoue if (inp->inp_vflag & INP_IPV4) { 409ade9ccfeSMarcel Moolenaar inetprint("local", &inp->inp_laddr, 410046aad39SHajimu UMEMOTO (int)inp->inp_lport, name, 1, af1); 411ac55add0SGuido van Rooij if (!Lflag) 412ade9ccfeSMarcel Moolenaar inetprint("remote", &inp->inp_faddr, 413046aad39SHajimu UMEMOTO (int)inp->inp_fport, name, 0, af1); 414cfa1ca9dSYoshinobu Inoue } 415cfa1ca9dSYoshinobu Inoue #ifdef INET6 416cfa1ca9dSYoshinobu Inoue else if (inp->inp_vflag & INP_IPV6) { 417ade9ccfeSMarcel Moolenaar inet6print("local", &inp->in6p_laddr, 418cfa1ca9dSYoshinobu Inoue (int)inp->inp_lport, name, 1); 419ac55add0SGuido van Rooij if (!Lflag) 420ade9ccfeSMarcel Moolenaar inet6print("remote", &inp->in6p_faddr, 421cfa1ca9dSYoshinobu Inoue (int)inp->inp_fport, name, 0); 422cfa1ca9dSYoshinobu Inoue } /* else nothing printed now */ 423cfa1ca9dSYoshinobu Inoue #endif /* INET6 */ 4248d612dd2SPoul-Henning Kamp } else { 425cfa1ca9dSYoshinobu Inoue if (inp->inp_vflag & INP_IPV4) { 426ade9ccfeSMarcel Moolenaar inetprint("local", &inp->inp_laddr, 427046aad39SHajimu UMEMOTO (int)inp->inp_lport, name, 0, af1); 428ac55add0SGuido van Rooij if (!Lflag) 429ade9ccfeSMarcel Moolenaar inetprint("remote", &inp->inp_faddr, 430ac55add0SGuido van Rooij (int)inp->inp_fport, name, 431046aad39SHajimu UMEMOTO inp->inp_lport != inp->inp_fport, 432046aad39SHajimu UMEMOTO af1); 433cfa1ca9dSYoshinobu Inoue } 434cfa1ca9dSYoshinobu Inoue #ifdef INET6 435cfa1ca9dSYoshinobu Inoue else if (inp->inp_vflag & INP_IPV6) { 436ade9ccfeSMarcel Moolenaar inet6print("local", &inp->in6p_laddr, 437cfa1ca9dSYoshinobu Inoue (int)inp->inp_lport, name, 0); 438ac55add0SGuido van Rooij if (!Lflag) 439ade9ccfeSMarcel Moolenaar inet6print("remote", &inp->in6p_faddr, 440cfa1ca9dSYoshinobu Inoue (int)inp->inp_fport, name, 4413feeb332SDavid E. O'Brien inp->inp_lport != inp->inp_fport); 442cfa1ca9dSYoshinobu Inoue } /* else nothing printed now */ 443cfa1ca9dSYoshinobu Inoue #endif /* INET6 */ 4448d612dd2SPoul-Henning Kamp } 44549f287f8SGeorge V. Neville-Neil if (xflag) { 446ade9ccfeSMarcel Moolenaar xo_emit("{:receive-mbufs/%6u} {:send-mbufs/%6u} " 447ade9ccfeSMarcel Moolenaar "{:receive-clusters/%6u} {:send-clusters/%6u} " 448ade9ccfeSMarcel Moolenaar "{:receive-high-water/%6u} {:send-high-water/%6u} " 449ade9ccfeSMarcel Moolenaar "{:receive-low-water/%6u} {:send-low-water/%6u} " 450ade9ccfeSMarcel Moolenaar "{:receive-mbuf-bytes/%6u} {:send-mbuf-bytes/%6u} " 451ade9ccfeSMarcel Moolenaar "{:receive-mbuf-bytes-max/%6u} " 452ade9ccfeSMarcel Moolenaar "{:send-mbuf-bytes-max/%6u}", 45349f287f8SGeorge V. Neville-Neil so->so_rcv.sb_mcnt, so->so_snd.sb_mcnt, 45449f287f8SGeorge V. Neville-Neil so->so_rcv.sb_ccnt, so->so_snd.sb_ccnt, 45549f287f8SGeorge V. Neville-Neil so->so_rcv.sb_hiwat, so->so_snd.sb_hiwat, 45649f287f8SGeorge V. Neville-Neil so->so_rcv.sb_lowat, so->so_snd.sb_lowat, 45749f287f8SGeorge V. Neville-Neil so->so_rcv.sb_mbcnt, so->so_snd.sb_mbcnt, 45849f287f8SGeorge V. Neville-Neil so->so_rcv.sb_mbmax, so->so_snd.sb_mbmax); 459cc65eb4eSGleb Smirnoff if (istcp) 460ade9ccfeSMarcel Moolenaar xo_emit(" {:retransmit-timer/%4d.%02d} " 461ade9ccfeSMarcel Moolenaar "{:persist-timer/%4d.%02d} " 462ade9ccfeSMarcel Moolenaar "{:keepalive-timer/%4d.%02d} " 463ade9ccfeSMarcel Moolenaar "{:msl2-timer/%4d.%02d} " 464ade9ccfeSMarcel Moolenaar "{:delay-ack-timer/%4d.%02d} " 465ade9ccfeSMarcel Moolenaar "{:inactivity-timer/%4d.%02d}", 466cc65eb4eSGleb Smirnoff tp->tt_rexmt / 1000, 467cc65eb4eSGleb Smirnoff (tp->tt_rexmt % 1000) / 10, 468cc65eb4eSGleb Smirnoff tp->tt_persist / 1000, 469cc65eb4eSGleb Smirnoff (tp->tt_persist % 1000) / 10, 470cc65eb4eSGleb Smirnoff tp->tt_keep / 1000, 471cc65eb4eSGleb Smirnoff (tp->tt_keep % 1000) / 10, 472cc65eb4eSGleb Smirnoff tp->tt_2msl / 1000, 473cc65eb4eSGleb Smirnoff (tp->tt_2msl % 1000) / 10, 474cc65eb4eSGleb Smirnoff tp->tt_delack / 1000, 475cc65eb4eSGleb Smirnoff (tp->tt_delack % 1000) / 10, 476cc65eb4eSGleb Smirnoff tp->t_rcvtime / 1000, 477cc65eb4eSGleb Smirnoff (tp->t_rcvtime % 1000) / 10); 478b8614722SMike Silbersack } 47985b0f0f3SAdrian Chadd if (istcp && !Lflag && !xflag && !Tflag && !Rflag) { 4804f81ef50SGarrett Wollman if (tp->t_state < 0 || tp->t_state >= TCP_NSTATES) 481ade9ccfeSMarcel Moolenaar xo_emit("{:tcp-state/%d}", tp->t_state); 4829a94a597SGarrett Wollman else { 483ade9ccfeSMarcel Moolenaar xo_emit("{:tcp-state/%s}", 484ade9ccfeSMarcel Moolenaar tcpstates[tp->t_state]); 485513822ddSAdam David #if defined(TF_NEEDSYN) && defined(TF_NEEDFIN) 4869a94a597SGarrett Wollman /* Show T/TCP `hidden state' */ 4874f81ef50SGarrett Wollman if (tp->t_flags & (TF_NEEDSYN|TF_NEEDFIN)) 488ade9ccfeSMarcel Moolenaar xo_emit("{:need-syn-or-fin/*}"); 489513822ddSAdam David #endif /* defined(TF_NEEDSYN) && defined(TF_NEEDFIN) */ 4909a94a597SGarrett Wollman } 4919b50d902SRodney W. Grimes } 49285b0f0f3SAdrian Chadd if (Rflag) { 493ade9ccfeSMarcel Moolenaar /* XXX: is this right Alfred */ 494ade9ccfeSMarcel Moolenaar xo_emit(" {:flow-id/%08x} {:flow-type/%5d}", 49585b0f0f3SAdrian Chadd inp->inp_flowid, 49685b0f0f3SAdrian Chadd inp->inp_flowtype); 49785b0f0f3SAdrian Chadd } 498ade9ccfeSMarcel Moolenaar xo_emit("\n"); 499ade9ccfeSMarcel Moolenaar xo_close_instance("socket"); 5009b50d902SRodney W. Grimes } 5014f81ef50SGarrett Wollman if (xig != oxig && xig->xig_gen != oxig->xig_gen) { 5024f81ef50SGarrett Wollman if (oxig->xig_count > xig->xig_count) { 503ade9ccfeSMarcel Moolenaar xo_emit("Some {d:lost/%s} sockets may have been " 504ade9ccfeSMarcel Moolenaar "deleted.\n", name); 5054f81ef50SGarrett Wollman } else if (oxig->xig_count < xig->xig_count) { 506ade9ccfeSMarcel Moolenaar xo_emit("Some {d:created/%s} sockets may have been " 507ade9ccfeSMarcel Moolenaar "created.\n", name); 5084f81ef50SGarrett Wollman } else { 509ade9ccfeSMarcel Moolenaar xo_emit("Some {d:changed/%s} sockets may have been " 510ade9ccfeSMarcel Moolenaar "created or deleted.\n", name); 5114f81ef50SGarrett Wollman } 5124f81ef50SGarrett Wollman } 5134f81ef50SGarrett Wollman free(buf); 5149b50d902SRodney W. Grimes } 5159b50d902SRodney W. Grimes 5169b50d902SRodney W. Grimes /* 5179b50d902SRodney W. Grimes * Dump TCP statistics structure. 5189b50d902SRodney W. Grimes */ 5199b50d902SRodney W. Grimes void 520feda1a43SJohn Baldwin tcp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) 5219b50d902SRodney W. Grimes { 5229eddb899SMark Johnston struct tcpstat tcpstat; 523dbfd8708SGleb Smirnoff uint64_t tcps_states[TCP_NSTATES]; 5249b50d902SRodney W. Grimes 525cfa1ca9dSYoshinobu Inoue #ifdef INET6 526cfa1ca9dSYoshinobu Inoue if (tcp_done != 0) 527cfa1ca9dSYoshinobu Inoue return; 528cfa1ca9dSYoshinobu Inoue else 529cfa1ca9dSYoshinobu Inoue tcp_done = 1; 530cfa1ca9dSYoshinobu Inoue #endif 531cfa1ca9dSYoshinobu Inoue 5329eddb899SMark Johnston if (fetch_stats("net.inet.tcp.stats", off, &tcpstat, 5339eddb899SMark Johnston sizeof(tcpstat), kread_counters) != 0) 534feda1a43SJohn Baldwin return; 535feda1a43SJohn Baldwin 536dbfd8708SGleb Smirnoff if (fetch_stats_ro("net.inet.tcp.states", nl[N_TCPS_STATES].n_value, 537dbfd8708SGleb Smirnoff &tcps_states, sizeof(tcps_states), kread_counters) != 0) 538dbfd8708SGleb Smirnoff return; 539dbfd8708SGleb Smirnoff 540ade9ccfeSMarcel Moolenaar xo_open_container("tcp"); 541ade9ccfeSMarcel Moolenaar xo_emit("{T:/%s}:\n", name); 5429b50d902SRodney W. Grimes 5439b50d902SRodney W. Grimes #define p(f, m) if (tcpstat.f || sflag <= 1) \ 544ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t )tcpstat.f, plural(tcpstat.f)) 54522694ebaSBruce Evans #define p1a(f, m) if (tcpstat.f || sflag <= 1) \ 546ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t )tcpstat.f) 5479b50d902SRodney W. Grimes #define p2(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) \ 548ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t )tcpstat.f1, plural(tcpstat.f1), \ 5495923c293SGleb Smirnoff (uintmax_t )tcpstat.f2, plural(tcpstat.f2)) 55022694ebaSBruce Evans #define p2a(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) \ 551ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t )tcpstat.f1, plural(tcpstat.f1), \ 5525923c293SGleb Smirnoff (uintmax_t )tcpstat.f2) 5539b50d902SRodney W. Grimes #define p3(f, m) if (tcpstat.f || sflag <= 1) \ 554ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t )tcpstat.f, pluralies(tcpstat.f)) 5559b50d902SRodney W. Grimes 556ade9ccfeSMarcel Moolenaar p(tcps_sndtotal, "\t{:sent-packets/%ju} {N:/packet%s sent}\n"); 557ade9ccfeSMarcel Moolenaar p2(tcps_sndpack,tcps_sndbyte, "\t\t{:sent-data-packets/%ju} " 558ade9ccfeSMarcel Moolenaar "{N:/data packet%s} ({:sent-data-bytes/%ju} {N:/byte%s})\n"); 559ade9ccfeSMarcel Moolenaar p2(tcps_sndrexmitpack, tcps_sndrexmitbyte, "\t\t" 560ade9ccfeSMarcel Moolenaar "{:sent-retransmitted-packets/%ju} {N:/data packet%s} " 561ade9ccfeSMarcel Moolenaar "({:sent-retransmitted-bytes/%ju} {N:/byte%s}) " 562ade9ccfeSMarcel Moolenaar "{N:retransmitted}\n"); 563ade9ccfeSMarcel Moolenaar p(tcps_sndrexmitbad, "\t\t" 564ade9ccfeSMarcel Moolenaar "{:sent-unnecessary-retransmitted-packets/%ju} " 565ade9ccfeSMarcel Moolenaar "{N:/data packet%s unnecessarily retransmitted}\n"); 566ade9ccfeSMarcel Moolenaar p(tcps_mturesent, "\t\t{:sent-resends-by-mtu-discovery/%ju} " 567ade9ccfeSMarcel Moolenaar "{N:/resend%s initiated by MTU discovery}\n"); 568ade9ccfeSMarcel Moolenaar p2a(tcps_sndacks, tcps_delack, "\t\t{:sent-ack-only-packets/%ju} " 569ade9ccfeSMarcel Moolenaar "{N:/ack-only packet%s/} ({:sent-packets-delayed/%ju} " 570ade9ccfeSMarcel Moolenaar "{N:delayed})\n"); 571ade9ccfeSMarcel Moolenaar p(tcps_sndurg, "\t\t{:sent-urg-only-packets/%ju} " 572ade9ccfeSMarcel Moolenaar "{N:/URG only packet%s}\n"); 573ade9ccfeSMarcel Moolenaar p(tcps_sndprobe, "\t\t{:sent-window-probe-packets/%ju} " 574ade9ccfeSMarcel Moolenaar "{N:/window probe packet%s}\n"); 575ade9ccfeSMarcel Moolenaar p(tcps_sndwinup, "\t\t{:sent-window-update-packets/%ju} " 576ade9ccfeSMarcel Moolenaar "{N:/window update packet%s}\n"); 577ade9ccfeSMarcel Moolenaar p(tcps_sndctrl, "\t\t{:sent-control-packets/%ju} " 578ade9ccfeSMarcel Moolenaar "{N:/control packet%s}\n"); 579ade9ccfeSMarcel Moolenaar p(tcps_rcvtotal, "\t{:received-packets/%ju} " 580ade9ccfeSMarcel Moolenaar "{N:/packet%s received}\n"); 581ade9ccfeSMarcel Moolenaar p2(tcps_rcvackpack, tcps_rcvackbyte, "\t\t" 582ade9ccfeSMarcel Moolenaar "{:received-ack-packets/%ju} {N:/ack%s} " 583ade9ccfeSMarcel Moolenaar "{N:(for} {:received-ack-bytes/%ju} {N:/byte%s})\n"); 584ade9ccfeSMarcel Moolenaar p(tcps_rcvdupack, "\t\t{:received-duplicate-acks/%ju} " 585ade9ccfeSMarcel Moolenaar "{N:/duplicate ack%s}\n"); 586ade9ccfeSMarcel Moolenaar p(tcps_rcvacktoomuch, "\t\t{:received-acks-for-unsent-data/%ju} " 587ade9ccfeSMarcel Moolenaar "{N:/ack%s for unsent data}\n"); 588ade9ccfeSMarcel Moolenaar p2(tcps_rcvpack, tcps_rcvbyte, "\t\t" 589ade9ccfeSMarcel Moolenaar "{:received-in-sequence-packets/%ju} {N:/packet%s} " 590ade9ccfeSMarcel Moolenaar "({:received-in-sequence-bytes/%ju} {N:/byte%s}) " 591ade9ccfeSMarcel Moolenaar "{N:received in-sequence}\n"); 592ade9ccfeSMarcel Moolenaar p2(tcps_rcvduppack, tcps_rcvdupbyte, "\t\t" 593ade9ccfeSMarcel Moolenaar "{:received-completely-duplicate-packets/%ju} " 594ade9ccfeSMarcel Moolenaar "{N:/completely duplicate packet%s} " 595ade9ccfeSMarcel Moolenaar "({:received-completely-duplicate-bytes/%ju} {N:/byte%s})\n"); 596ade9ccfeSMarcel Moolenaar p(tcps_pawsdrop, "\t\t{:received-old-duplicate-packets/%ju} " 597ade9ccfeSMarcel Moolenaar "{N:/old duplicate packet%s}\n"); 598ade9ccfeSMarcel Moolenaar p2(tcps_rcvpartduppack, tcps_rcvpartdupbyte, "\t\t" 599ade9ccfeSMarcel Moolenaar "{:received-some-duplicate-packets/%ju} " 600ade9ccfeSMarcel Moolenaar "{N:/packet%s with some dup. data} " 601ade9ccfeSMarcel Moolenaar "({:received-some-duplicate-bytes/%ju} {N:/byte%s duped/})\n"); 602ade9ccfeSMarcel Moolenaar p2(tcps_rcvoopack, tcps_rcvoobyte, "\t\t{:received-out-of-order/%ju} " 603ade9ccfeSMarcel Moolenaar "{N:/out-of-order packet%s} " 604ade9ccfeSMarcel Moolenaar "({:received-out-of-order-bytes/%ju} {N:/byte%s})\n"); 605ade9ccfeSMarcel Moolenaar p2(tcps_rcvpackafterwin, tcps_rcvbyteafterwin, "\t\t" 606ade9ccfeSMarcel Moolenaar "{:received-after-window-packets/%ju} {N:/packet%s} " 607ade9ccfeSMarcel Moolenaar "({:received-after-window-bytes/%ju} {N:/byte%s}) " 608ade9ccfeSMarcel Moolenaar "{N:of data after window}\n"); 609ade9ccfeSMarcel Moolenaar p(tcps_rcvwinprobe, "\t\t{:received-window-probes/%ju} " 610ade9ccfeSMarcel Moolenaar "{N:/window probe%s}\n"); 611ade9ccfeSMarcel Moolenaar p(tcps_rcvwinupd, "\t\t{:receive-window-update-packets/%ju} " 612ade9ccfeSMarcel Moolenaar "{N:/window update packet%s}\n"); 613ade9ccfeSMarcel Moolenaar p(tcps_rcvafterclose, "\t\t{:received-after-close-packets/%ju} " 614ade9ccfeSMarcel Moolenaar "{N:/packet%s received after close}\n"); 615ade9ccfeSMarcel Moolenaar p(tcps_rcvbadsum, "\t\t{:discard-bad-checksum/%ju} " 616ade9ccfeSMarcel Moolenaar "{N:/discarded for bad checksum%s}\n"); 617ade9ccfeSMarcel Moolenaar p(tcps_rcvbadoff, "\t\t{:discard-bad-header-offset/%ju} " 618ade9ccfeSMarcel Moolenaar "{N:/discarded for bad header offset field%s}\n"); 619ade9ccfeSMarcel Moolenaar p1a(tcps_rcvshort, "\t\t{:discard-too-short/%ju} " 620ade9ccfeSMarcel Moolenaar "{N:discarded because packet too short}\n"); 621ade9ccfeSMarcel Moolenaar p1a(tcps_rcvmemdrop, "\t\t{:discard-memory-problems/%ju} " 622ade9ccfeSMarcel Moolenaar "{N:discarded due to memory problems}\n"); 623ade9ccfeSMarcel Moolenaar p(tcps_connattempt, "\t{:connection-requests/%ju} " 624ade9ccfeSMarcel Moolenaar "{N:/connection request%s}\n"); 625ade9ccfeSMarcel Moolenaar p(tcps_accepts, "\t{:connections-accepts/%ju} " 626ade9ccfeSMarcel Moolenaar "{N:/connection accept%s}\n"); 627ade9ccfeSMarcel Moolenaar p(tcps_badsyn, "\t{:bad-connection-attempts/%ju} " 628ade9ccfeSMarcel Moolenaar "{N:/bad connection attempt%s}\n"); 629ade9ccfeSMarcel Moolenaar p(tcps_listendrop, "\t{:listen-queue-overflows/%ju} " 630ade9ccfeSMarcel Moolenaar "{N:/listen queue overflow%s}\n"); 631ade9ccfeSMarcel Moolenaar p(tcps_badrst, "\t{:ignored-in-window-resets/%ju} " 632ade9ccfeSMarcel Moolenaar "{N:/ignored RSTs in the window%s}\n"); 633ade9ccfeSMarcel Moolenaar p(tcps_connects, "\t{:connections-established/%ju} " 634ade9ccfeSMarcel Moolenaar "{N:/connection%s established (including accepts)}\n"); 635e9d2c201SMarcelo Araujo p(tcps_usedrtt, "\t\t{:connections-hostcache-rtt/%ju} " 636e9d2c201SMarcelo Araujo "{N:/time%s used RTT from hostcache}\n"); 637e9d2c201SMarcelo Araujo p(tcps_usedrttvar, "\t\t{:connections-hostcache-rttvar/%ju} " 638e9d2c201SMarcelo Araujo "{N:/time%s used RTT variance from hostcache}\n"); 639e9d2c201SMarcelo Araujo p(tcps_usedssthresh, "\t\t{:connections-hostcache-ssthresh/%ju} " 640e9d2c201SMarcelo Araujo "{N:/time%s used slow-start threshold from hostcache}\n"); 641ade9ccfeSMarcel Moolenaar p2(tcps_closed, tcps_drops, "\t{:connections-closed/%ju} " 642ade9ccfeSMarcel Moolenaar "{N:/connection%s closed (including} " 643ade9ccfeSMarcel Moolenaar "{:connection-drops/%ju} {N:/drop%s})\n"); 644ade9ccfeSMarcel Moolenaar p(tcps_cachedrtt, "\t\t{:connections-updated-rtt-on-close/%ju} " 645ade9ccfeSMarcel Moolenaar "{N:/connection%s updated cached RTT on close}\n"); 646ade9ccfeSMarcel Moolenaar p(tcps_cachedrttvar, "\t\t" 647ade9ccfeSMarcel Moolenaar "{:connections-updated-variance-on-close/%ju} " 648ade9ccfeSMarcel Moolenaar "{N:/connection%s updated cached RTT variance on close}\n"); 649ade9ccfeSMarcel Moolenaar p(tcps_cachedssthresh, "\t\t" 650ade9ccfeSMarcel Moolenaar "{:connections-updated-ssthresh-on-close/%ju} " 651ade9ccfeSMarcel Moolenaar "{N:/connection%s updated cached ssthresh on close}\n"); 652ade9ccfeSMarcel Moolenaar p(tcps_conndrops, "\t{:embryonic-connections-dropped/%ju} " 653ade9ccfeSMarcel Moolenaar "{N:/embryonic connection%s dropped}\n"); 654ade9ccfeSMarcel Moolenaar p2(tcps_rttupdated, tcps_segstimed, "\t{:segments-updated-rtt/%ju} " 655ade9ccfeSMarcel Moolenaar "{N:/segment%s updated rtt (of} " 656ade9ccfeSMarcel Moolenaar "{:segment-update-attempts/%ju} {N:/attempt%s})\n"); 657ade9ccfeSMarcel Moolenaar p(tcps_rexmttimeo, "\t{:retransmit-timeouts/%ju} " 658ade9ccfeSMarcel Moolenaar "{N:/retransmit timeout%s}\n"); 659ade9ccfeSMarcel Moolenaar p(tcps_timeoutdrop, "\t\t" 660ade9ccfeSMarcel Moolenaar "{:connections-dropped-by-retransmit-timeout/%ju} " 661ade9ccfeSMarcel Moolenaar "{N:/connection%s dropped by rexmit timeout}\n"); 662ade9ccfeSMarcel Moolenaar p(tcps_persisttimeo, "\t{:persist-timeout/%ju} " 663ade9ccfeSMarcel Moolenaar "{N:/persist timeout%s}\n"); 664ade9ccfeSMarcel Moolenaar p(tcps_persistdrop, "\t\t" 665ade9ccfeSMarcel Moolenaar "{:connections-dropped-by-persist-timeout/%ju} " 666ade9ccfeSMarcel Moolenaar "{N:/connection%s dropped by persist timeout}\n"); 667ade9ccfeSMarcel Moolenaar p(tcps_finwait2_drops, "\t" 668ade9ccfeSMarcel Moolenaar "{:connections-dropped-by-finwait2-timeout/%ju} " 669ade9ccfeSMarcel Moolenaar "{N:/Connection%s (fin_wait_2) dropped because of timeout}\n"); 670ade9ccfeSMarcel Moolenaar p(tcps_keeptimeo, "\t{:keepalive-timeout/%ju} " 671ade9ccfeSMarcel Moolenaar "{N:/keepalive timeout%s}\n"); 672ade9ccfeSMarcel Moolenaar p(tcps_keepprobe, "\t\t{:keepalive-probes/%ju} " 673ade9ccfeSMarcel Moolenaar "{N:/keepalive probe%s sent}\n"); 674ade9ccfeSMarcel Moolenaar p(tcps_keepdrops, "\t\t{:connections-dropped-by-keepalives/%ju} " 675ade9ccfeSMarcel Moolenaar "{N:/connection%s dropped by keepalive}\n"); 676ade9ccfeSMarcel Moolenaar p(tcps_predack, "\t{:ack-header-predictions/%ju} " 677ade9ccfeSMarcel Moolenaar "{N:/correct ACK header prediction%s}\n"); 678ade9ccfeSMarcel Moolenaar p(tcps_preddat, "\t{:data-packet-header-predictions/%ju} " 679ade9ccfeSMarcel Moolenaar "{N:/correct data packet header prediction%s}\n"); 68060a31b3aSJonathan Lemon 681ade9ccfeSMarcel Moolenaar xo_open_container("syncache"); 682b6101dafSPaul Saab 683ade9ccfeSMarcel Moolenaar p3(tcps_sc_added, "\t{:entries-added/%ju} " 684ade9ccfeSMarcel Moolenaar "{N:/syncache entr%s added}\n"); 685ade9ccfeSMarcel Moolenaar p1a(tcps_sc_retransmitted, "\t\t{:retransmitted/%ju} " 686ade9ccfeSMarcel Moolenaar "{N:/retransmitted}\n"); 687ade9ccfeSMarcel Moolenaar p1a(tcps_sc_dupsyn, "\t\t{:duplicates/%ju} {N:/dupsyn}\n"); 688ade9ccfeSMarcel Moolenaar p1a(tcps_sc_dropped, "\t\t{:dropped/%ju} {N:/dropped}\n"); 689ade9ccfeSMarcel Moolenaar p1a(tcps_sc_completed, "\t\t{:completed/%ju} {N:/completed}\n"); 690ade9ccfeSMarcel Moolenaar p1a(tcps_sc_bucketoverflow, "\t\t{:bucket-overflow/%ju} " 691ade9ccfeSMarcel Moolenaar "{N:/bucket overflow}\n"); 692ade9ccfeSMarcel Moolenaar p1a(tcps_sc_cacheoverflow, "\t\t{:cache-overflow/%ju} " 693ade9ccfeSMarcel Moolenaar "{N:/cache overflow}\n"); 694ade9ccfeSMarcel Moolenaar p1a(tcps_sc_reset, "\t\t{:reset/%ju} {N:/reset}\n"); 695ade9ccfeSMarcel Moolenaar p1a(tcps_sc_stale, "\t\t{:stale/%ju} {N:/stale}\n"); 696ade9ccfeSMarcel Moolenaar p1a(tcps_sc_aborted, "\t\t{:aborted/%ju} {N:/aborted}\n"); 697ade9ccfeSMarcel Moolenaar p1a(tcps_sc_badack, "\t\t{:bad-ack/%ju} {N:/badack}\n"); 698ade9ccfeSMarcel Moolenaar p1a(tcps_sc_unreach, "\t\t{:unreachable/%ju} {N:/unreach}\n"); 699ade9ccfeSMarcel Moolenaar p(tcps_sc_zonefail, "\t\t{:zone-failures/%ju} {N:/zone failure%s}\n"); 700ade9ccfeSMarcel Moolenaar p(tcps_sc_sendcookie, "\t{:sent-cookies/%ju} {N:/cookie%s sent}\n"); 701ade9ccfeSMarcel Moolenaar p(tcps_sc_recvcookie, "\t{:receivd-cookies/%ju} " 702ade9ccfeSMarcel Moolenaar "{N:/cookie%s received}\n"); 703699ef999SRuslan Ermilov 704ade9ccfeSMarcel Moolenaar xo_close_container("syncache"); 705b6101dafSPaul Saab 706ade9ccfeSMarcel Moolenaar xo_open_container("hostcache"); 707a4993b25SBjoern A. Zeeb 708ade9ccfeSMarcel Moolenaar p3(tcps_hc_added, "\t{:entries-added/%ju} " 709ade9ccfeSMarcel Moolenaar "{N:/hostcache entr%s added}\n"); 710ade9ccfeSMarcel Moolenaar p1a(tcps_hc_bucketoverflow, "\t\t{:buffer-overflows/%ju} " 711ade9ccfeSMarcel Moolenaar "{N:/bucket overflow}\n"); 712ade9ccfeSMarcel Moolenaar 713ade9ccfeSMarcel Moolenaar xo_close_container("hostcache"); 714ade9ccfeSMarcel Moolenaar 715ade9ccfeSMarcel Moolenaar xo_open_container("sack"); 716ade9ccfeSMarcel Moolenaar 717ade9ccfeSMarcel Moolenaar p(tcps_sack_recovery_episode, "\t{:recovery-episodes/%ju} " 718ade9ccfeSMarcel Moolenaar "{N:/SACK recovery episode%s}\n"); 719ade9ccfeSMarcel Moolenaar p(tcps_sack_rexmits, "\t{:segment-retransmits/%ju} " 720ade9ccfeSMarcel Moolenaar "{N:/segment rexmit%s in SACK recovery episodes}\n"); 721ade9ccfeSMarcel Moolenaar p(tcps_sack_rexmit_bytes, "\t{:byte-retransmits/%ju} " 722ade9ccfeSMarcel Moolenaar "{N:/byte rexmit%s in SACK recovery episodes}\n"); 723ade9ccfeSMarcel Moolenaar p(tcps_sack_rcv_blocks, "\t{:received-blocks/%ju} " 724ade9ccfeSMarcel Moolenaar "{N:/SACK option%s (SACK blocks) received}\n"); 725ade9ccfeSMarcel Moolenaar p(tcps_sack_send_blocks, "\t{:sent-option-blocks/%ju} " 726ade9ccfeSMarcel Moolenaar "{N:/SACK option%s (SACK blocks) sent}\n"); 727ade9ccfeSMarcel Moolenaar p1a(tcps_sack_sboverflow, "\t{:scoreboard-overflows/%ju} " 728ade9ccfeSMarcel Moolenaar "{N:/SACK scoreboard overflow}\n"); 729ade9ccfeSMarcel Moolenaar 730ade9ccfeSMarcel Moolenaar xo_close_container("sack"); 731ade9ccfeSMarcel Moolenaar xo_open_container("ecn"); 732ade9ccfeSMarcel Moolenaar 733ade9ccfeSMarcel Moolenaar p(tcps_ecn_ce, "\t{:ce-packets/%ju} " 734ade9ccfeSMarcel Moolenaar "{N:/packet%s with ECN CE bit set}\n"); 735ade9ccfeSMarcel Moolenaar p(tcps_ecn_ect0, "\t{:ect0-packets/%ju} " 736ade9ccfeSMarcel Moolenaar "{N:/packet%s with ECN ECT(0) bit set}\n"); 737ade9ccfeSMarcel Moolenaar p(tcps_ecn_ect1, "\t{:ect1-packets/%ju} " 738ade9ccfeSMarcel Moolenaar "{N:/packet%s with ECN ECT(1) bit set}\n"); 739ade9ccfeSMarcel Moolenaar p(tcps_ecn_shs, "\t{:handshakes/%ju} " 740ade9ccfeSMarcel Moolenaar "{N:/successful ECN handshake%s}\n"); 741ade9ccfeSMarcel Moolenaar p(tcps_ecn_rcwnd, "\t{:congestion-reductions/%ju} " 742ade9ccfeSMarcel Moolenaar "{N:/time%s ECN reduced the congestion window}\n"); 743fcf59617SAndrey V. Elsukov 744fcf59617SAndrey V. Elsukov xo_close_container("ecn"); 745fcf59617SAndrey V. Elsukov xo_open_container("tcp-signature"); 746fcf59617SAndrey V. Elsukov p(tcps_sig_rcvgoodsig, "\t{:received-good-signature/%ju} " 747fcf59617SAndrey V. Elsukov "{N:/packet%s with matching signature received}\n"); 748fcf59617SAndrey V. Elsukov p(tcps_sig_rcvbadsig, "\t{:received-bad-signature/%ju} " 749fcf59617SAndrey V. Elsukov "{N:/packet%s with bad signature received}\n"); 750fcf59617SAndrey V. Elsukov p(tcps_sig_err_buildsig, "\t{:failed-make-signature/%ju} " 751fcf59617SAndrey V. Elsukov "{N:/time%s failed to make signature due to no SA}\n"); 752fcf59617SAndrey V. Elsukov p(tcps_sig_err_sigopt, "\t{:no-signature-expected/%ju} " 753fcf59617SAndrey V. Elsukov "{N:/time%s unexpected signature received}\n"); 754fcf59617SAndrey V. Elsukov p(tcps_sig_err_nosigopt, "\t{:no-signature-provided/%ju} " 755fcf59617SAndrey V. Elsukov "{N:/time%s no signature provided by segment}\n"); 75632a04bb8SSean Bruno 75732a04bb8SSean Bruno xo_close_container("tcp-signature"); 75832a04bb8SSean Bruno xo_open_container("pmtud"); 75932a04bb8SSean Bruno 76032a04bb8SSean Bruno p(tcps_pmtud_blackhole_activated, "\t{:pmtud-activated/%ju} " 76132a04bb8SSean Bruno "{N:/Path MTU discovery black hole detection activation%s}\n"); 76232a04bb8SSean Bruno p(tcps_pmtud_blackhole_activated_min_mss, 76332a04bb8SSean Bruno "\t{:pmtud-activated-min-mss/%ju} " 76432a04bb8SSean Bruno "{N:/Path MTU discovery black hole detection min MSS activation%s}\n"); 76532a04bb8SSean Bruno p(tcps_pmtud_blackhole_failed, "\t{:pmtud-failed/%ju} " 76632a04bb8SSean Bruno "{N:/Path MTU discovery black hole detection failure%s}\n"); 7679b50d902SRodney W. Grimes #undef p 76822694ebaSBruce Evans #undef p1a 7699b50d902SRodney W. Grimes #undef p2 77022694ebaSBruce Evans #undef p2a 7719b50d902SRodney W. Grimes #undef p3 77232a04bb8SSean Bruno xo_close_container("pmtud"); 77332a04bb8SSean Bruno 774dbfd8708SGleb Smirnoff 775dbfd8708SGleb Smirnoff xo_open_container("TCP connection count by state"); 776dbfd8708SGleb Smirnoff xo_emit("{T:/TCP connection count by state}:\n"); 777dbfd8708SGleb Smirnoff for (int i = 0; i < TCP_NSTATES; i++) { 778dbfd8708SGleb Smirnoff /* 779dbfd8708SGleb Smirnoff * XXXGL: is there a way in libxo to use %s 780dbfd8708SGleb Smirnoff * in the "content string" of a format 781dbfd8708SGleb Smirnoff * string? I failed to do that, that's why 782dbfd8708SGleb Smirnoff * a temporary buffer is used to construct 783dbfd8708SGleb Smirnoff * format string for xo_emit(). 784dbfd8708SGleb Smirnoff */ 785dbfd8708SGleb Smirnoff char fmtbuf[80]; 786dbfd8708SGleb Smirnoff 787dbfd8708SGleb Smirnoff if (sflag > 1 && tcps_states[i] == 0) 788dbfd8708SGleb Smirnoff continue; 789dbfd8708SGleb Smirnoff snprintf(fmtbuf, sizeof(fmtbuf), "\t{:%s/%%ju} " 790dbfd8708SGleb Smirnoff "{Np:/connection ,connections} in %s state\n", 791dbfd8708SGleb Smirnoff tcpstates[i], tcpstates[i]); 792dbfd8708SGleb Smirnoff xo_emit(fmtbuf, (uintmax_t )tcps_states[i]); 793dbfd8708SGleb Smirnoff } 794dbfd8708SGleb Smirnoff xo_close_container("TCP connection count by state"); 795dbfd8708SGleb Smirnoff 796ade9ccfeSMarcel Moolenaar xo_close_container("tcp"); 7979b50d902SRodney W. Grimes } 7989b50d902SRodney W. Grimes 7999b50d902SRodney W. Grimes /* 8009b50d902SRodney W. Grimes * Dump UDP statistics structure. 8019b50d902SRodney W. Grimes */ 8029b50d902SRodney W. Grimes void 803feda1a43SJohn Baldwin udp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) 8049b50d902SRodney W. Grimes { 8059eddb899SMark Johnston struct udpstat udpstat; 806c80211e3SAndrey V. Elsukov uint64_t delivered; 8079b50d902SRodney W. Grimes 808cfa1ca9dSYoshinobu Inoue #ifdef INET6 809cfa1ca9dSYoshinobu Inoue if (udp_done != 0) 810cfa1ca9dSYoshinobu Inoue return; 811cfa1ca9dSYoshinobu Inoue else 812cfa1ca9dSYoshinobu Inoue udp_done = 1; 813cfa1ca9dSYoshinobu Inoue #endif 814cfa1ca9dSYoshinobu Inoue 8159eddb899SMark Johnston if (fetch_stats("net.inet.udp.stats", off, &udpstat, 8169eddb899SMark Johnston sizeof(udpstat), kread_counters) != 0) 817feda1a43SJohn Baldwin return; 818feda1a43SJohn Baldwin 819ade9ccfeSMarcel Moolenaar xo_open_container("udp"); 820ade9ccfeSMarcel Moolenaar xo_emit("{T:/%s}:\n", name); 821ade9ccfeSMarcel Moolenaar 8229b50d902SRodney W. Grimes #define p(f, m) if (udpstat.f || sflag <= 1) \ 823ade9ccfeSMarcel Moolenaar xo_emit("\t" m, (uintmax_t)udpstat.f, plural(udpstat.f)) 82422694ebaSBruce Evans #define p1a(f, m) if (udpstat.f || sflag <= 1) \ 825ade9ccfeSMarcel Moolenaar xo_emit("\t" m, (uintmax_t)udpstat.f) 826ade9ccfeSMarcel Moolenaar 827ade9ccfeSMarcel Moolenaar p(udps_ipackets, "{:received-datagrams/%ju} " 828ade9ccfeSMarcel Moolenaar "{N:/datagram%s received}\n"); 829ade9ccfeSMarcel Moolenaar p1a(udps_hdrops, "{:dropped-incomplete-headers/%ju} " 830ade9ccfeSMarcel Moolenaar "{N:/with incomplete header}\n"); 831ade9ccfeSMarcel Moolenaar p1a(udps_badlen, "{:dropped-bad-data-length/%ju} " 832ade9ccfeSMarcel Moolenaar "{N:/with bad data length field}\n"); 833ade9ccfeSMarcel Moolenaar p1a(udps_badsum, "{:dropped-bad-checksum/%ju} " 834ade9ccfeSMarcel Moolenaar "{N:/with bad checksum}\n"); 835ade9ccfeSMarcel Moolenaar p1a(udps_nosum, "{:dropped-no-checksum/%ju} " 836ade9ccfeSMarcel Moolenaar "{N:/with no checksum}\n"); 837ade9ccfeSMarcel Moolenaar p1a(udps_noport, "{:dropped-no-socket/%ju} " 838ade9ccfeSMarcel Moolenaar "{N:/dropped due to no socket}\n"); 839ade9ccfeSMarcel Moolenaar p(udps_noportbcast, "{:dropped-broadcast-multicast/%ju} " 840ade9ccfeSMarcel Moolenaar "{N:/broadcast\\/multicast datagram%s undelivered}\n"); 841ade9ccfeSMarcel Moolenaar p1a(udps_fullsock, "{:dropped-full-socket-buffer/%ju} " 842ade9ccfeSMarcel Moolenaar "{N:/dropped due to full socket buffers}\n"); 843ade9ccfeSMarcel Moolenaar p1a(udpps_pcbhashmiss, "{:not-for-hashed-pcb/%ju} " 844ade9ccfeSMarcel Moolenaar "{N:/not for hashed pcb}\n"); 8459b50d902SRodney W. Grimes delivered = udpstat.udps_ipackets - 8469b50d902SRodney W. Grimes udpstat.udps_hdrops - 8479b50d902SRodney W. Grimes udpstat.udps_badlen - 8489b50d902SRodney W. Grimes udpstat.udps_badsum - 8499b50d902SRodney W. Grimes udpstat.udps_noport - 8509b50d902SRodney W. Grimes udpstat.udps_noportbcast - 8519b50d902SRodney W. Grimes udpstat.udps_fullsock; 8529b50d902SRodney W. Grimes if (delivered || sflag <= 1) 853ade9ccfeSMarcel Moolenaar xo_emit("\t{:delivered-packets/%ju} {N:/delivered}\n", 854ade9ccfeSMarcel Moolenaar (uint64_t)delivered); 855ade9ccfeSMarcel Moolenaar p(udps_opackets, "{:output-packets/%ju} {N:/datagram%s output}\n"); 85671498f30SBruce M Simpson /* the next statistic is cumulative in udps_noportbcast */ 857ade9ccfeSMarcel Moolenaar p(udps_filtermcast, "{:multicast-source-filter-matches/%ju} " 858ade9ccfeSMarcel Moolenaar "{N:/time%s multicast source filter matched}\n"); 8599b50d902SRodney W. Grimes #undef p 86022694ebaSBruce Evans #undef p1a 861ade9ccfeSMarcel Moolenaar xo_close_container("udp"); 8629b50d902SRodney W. Grimes } 8639b50d902SRodney W. Grimes 8649b50d902SRodney W. Grimes /* 865a9771948SGleb Smirnoff * Dump CARP statistics structure. 866a9771948SGleb Smirnoff */ 867a9771948SGleb Smirnoff void 868feda1a43SJohn Baldwin carp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) 869a9771948SGleb Smirnoff { 8709eddb899SMark Johnston struct carpstats carpstat; 871a9771948SGleb Smirnoff 8729eddb899SMark Johnston if (fetch_stats("net.inet.carp.stats", off, &carpstat, 8739eddb899SMark Johnston sizeof(carpstat), kread_counters) != 0) 874a9771948SGleb Smirnoff return; 875a9771948SGleb Smirnoff 876ade9ccfeSMarcel Moolenaar xo_open_container(name); 877ade9ccfeSMarcel Moolenaar xo_emit("{T:/%s}:\n", name); 878a9771948SGleb Smirnoff 879a9771948SGleb Smirnoff #define p(f, m) if (carpstat.f || sflag <= 1) \ 880ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t)carpstat.f, plural(carpstat.f)) 881a9771948SGleb Smirnoff #define p2(f, m) if (carpstat.f || sflag <= 1) \ 882ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t)carpstat.f) 883a9771948SGleb Smirnoff 884ade9ccfeSMarcel Moolenaar p(carps_ipackets, "\t{:received-inet-packets/%ju} " 885ade9ccfeSMarcel Moolenaar "{N:/packet%s received (IPv4)}\n"); 886ade9ccfeSMarcel Moolenaar p(carps_ipackets6, "\t{:received-inet6-packets/%ju} " 887ade9ccfeSMarcel Moolenaar "{N:/packet%s received (IPv6)}\n"); 888ade9ccfeSMarcel Moolenaar p(carps_badttl, "\t\t{:dropped-wrong-ttl/%ju} " 889ade9ccfeSMarcel Moolenaar "{N:/packet%s discarded for wrong TTL}\n"); 890ade9ccfeSMarcel Moolenaar p(carps_hdrops, "\t\t{:dropped-short-header/%ju} " 891ade9ccfeSMarcel Moolenaar "{N:/packet%s shorter than header}\n"); 892ade9ccfeSMarcel Moolenaar p(carps_badsum, "\t\t{:dropped-bad-checksum/%ju} " 893ade9ccfeSMarcel Moolenaar "{N:/discarded for bad checksum%s}\n"); 894ade9ccfeSMarcel Moolenaar p(carps_badver, "\t\t{:dropped-bad-version/%ju} " 895ade9ccfeSMarcel Moolenaar "{N:/discarded packet%s with a bad version}\n"); 896ade9ccfeSMarcel Moolenaar p2(carps_badlen, "\t\t{:dropped-short-packet/%ju} " 897ade9ccfeSMarcel Moolenaar "{N:/discarded because packet too short}\n"); 898ade9ccfeSMarcel Moolenaar p2(carps_badauth, "\t\t{:dropped-bad-authentication/%ju} " 899ade9ccfeSMarcel Moolenaar "{N:/discarded for bad authentication}\n"); 900ade9ccfeSMarcel Moolenaar p2(carps_badvhid, "\t\t{:dropped-bad-vhid/%ju} " 901ade9ccfeSMarcel Moolenaar "{N:/discarded for bad vhid}\n"); 902ade9ccfeSMarcel Moolenaar p2(carps_badaddrs, "\t\t{:dropped-bad-address-list/%ju} " 903ade9ccfeSMarcel Moolenaar "{N:/discarded because of a bad address list}\n"); 904ade9ccfeSMarcel Moolenaar p(carps_opackets, "\t{:sent-inet-packets/%ju} " 905ade9ccfeSMarcel Moolenaar "{N:/packet%s sent (IPv4)}\n"); 906ade9ccfeSMarcel Moolenaar p(carps_opackets6, "\t{:sent-inet6-packets/%ju} " 907ade9ccfeSMarcel Moolenaar "{N:/packet%s sent (IPv6)}\n"); 908ade9ccfeSMarcel Moolenaar p2(carps_onomem, "\t\t{:send-failed-memory-error/%ju} " 909ade9ccfeSMarcel Moolenaar "{N:/send failed due to mbuf memory error}\n"); 910a9771948SGleb Smirnoff #if notyet 911ade9ccfeSMarcel Moolenaar p(carps_ostates, "\t\t{:send-state-updates/%s} " 912ade9ccfeSMarcel Moolenaar "{N:/state update%s sent}\n"); 913a9771948SGleb Smirnoff #endif 914a9771948SGleb Smirnoff #undef p 915a9771948SGleb Smirnoff #undef p2 916ade9ccfeSMarcel Moolenaar xo_close_container(name); 917a9771948SGleb Smirnoff } 918a9771948SGleb Smirnoff 919a9771948SGleb Smirnoff /* 9209b50d902SRodney W. Grimes * Dump IP statistics structure. 9219b50d902SRodney W. Grimes */ 9229b50d902SRodney W. Grimes void 923feda1a43SJohn Baldwin ip_stats(u_long off, const char *name, int af1 __unused, int proto __unused) 9249b50d902SRodney W. Grimes { 9259eddb899SMark Johnston struct ipstat ipstat; 9269b50d902SRodney W. Grimes 9279eddb899SMark Johnston if (fetch_stats("net.inet.ip.stats", off, &ipstat, 9289eddb899SMark Johnston sizeof(ipstat), kread_counters) != 0) 9299b50d902SRodney W. Grimes return; 9304f81ef50SGarrett Wollman 931ade9ccfeSMarcel Moolenaar xo_open_container(name); 932ade9ccfeSMarcel Moolenaar xo_emit("{T:/%s}:\n", name); 9339b50d902SRodney W. Grimes 9349b50d902SRodney W. Grimes #define p(f, m) if (ipstat.f || sflag <= 1) \ 935ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t )ipstat.f, plural(ipstat.f)) 93622694ebaSBruce Evans #define p1a(f, m) if (ipstat.f || sflag <= 1) \ 937ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t )ipstat.f) 9389b50d902SRodney W. Grimes 939ade9ccfeSMarcel Moolenaar p(ips_total, "\t{:received-packets/%ju} " 940ade9ccfeSMarcel Moolenaar "{N:/total packet%s received}\n"); 941ade9ccfeSMarcel Moolenaar p(ips_badsum, "\t{:dropped-bad-checksum/%ju} " 942ade9ccfeSMarcel Moolenaar "{N:/bad header checksum%s}\n"); 943ade9ccfeSMarcel Moolenaar p1a(ips_toosmall, "\t{:dropped-below-minimum-size/%ju} " 944ade9ccfeSMarcel Moolenaar "{N:/with size smaller than minimum}\n"); 945ade9ccfeSMarcel Moolenaar p1a(ips_tooshort, "\t{:dropped-short-packets/%ju} " 946ade9ccfeSMarcel Moolenaar "{N:/with data size < data length}\n"); 947ade9ccfeSMarcel Moolenaar p1a(ips_toolong, "\t{:dropped-too-long/%ju} " 948ade9ccfeSMarcel Moolenaar "{N:/with ip length > max ip packet size}\n"); 949ade9ccfeSMarcel Moolenaar p1a(ips_badhlen, "\t{:dropped-short-header-length/%ju} " 950ade9ccfeSMarcel Moolenaar "{N:/with header length < data size}\n"); 951ade9ccfeSMarcel Moolenaar p1a(ips_badlen, "\t{:dropped-short-data/%ju} " 952ade9ccfeSMarcel Moolenaar "{N:/with data length < header length}\n"); 953ade9ccfeSMarcel Moolenaar p1a(ips_badoptions, "\t{:dropped-bad-options/%ju} " 954ade9ccfeSMarcel Moolenaar "{N:/with bad options}\n"); 955ade9ccfeSMarcel Moolenaar p1a(ips_badvers, "\t{:dropped-bad-version/%ju} " 956ade9ccfeSMarcel Moolenaar "{N:/with incorrect version number}\n"); 957ade9ccfeSMarcel Moolenaar p(ips_fragments, "\t{:received-fragments/%ju} " 958ade9ccfeSMarcel Moolenaar "{N:/fragment%s received}\n"); 959ade9ccfeSMarcel Moolenaar p(ips_fragdropped, "\t{:dropped-fragments/%ju} " 960ade9ccfeSMarcel Moolenaar "{N:/fragment%s dropped (dup or out of space)}\n"); 961ade9ccfeSMarcel Moolenaar p(ips_fragtimeout, "\t{:dropped-fragments-after-timeout/%ju} " 962ade9ccfeSMarcel Moolenaar "{N:/fragment%s dropped after timeout}\n"); 963ade9ccfeSMarcel Moolenaar p(ips_reassembled, "\t{:reassembled-packets/%ju} " 964ade9ccfeSMarcel Moolenaar "{N:/packet%s reassembled ok}\n"); 965ade9ccfeSMarcel Moolenaar p(ips_delivered, "\t{:received-local-packets/%ju} " 966ade9ccfeSMarcel Moolenaar "{N:/packet%s for this host}\n"); 967ade9ccfeSMarcel Moolenaar p(ips_noproto, "\t{:dropped-unknown-protocol/%ju} " 968ade9ccfeSMarcel Moolenaar "{N:/packet%s for unknown\\/unsupported protocol}\n"); 969ade9ccfeSMarcel Moolenaar p(ips_forward, "\t{:forwarded-packets/%ju} " 970ade9ccfeSMarcel Moolenaar "{N:/packet%s forwarded}"); 971ade9ccfeSMarcel Moolenaar p(ips_fastforward, " ({:fast-forwarded-packets/%ju} " 972ade9ccfeSMarcel Moolenaar "{N:/packet%s fast forwarded})"); 973958d6f7fSPierre Beyssac if (ipstat.ips_forward || sflag <= 1) 974ade9ccfeSMarcel Moolenaar xo_emit("\n"); 975ade9ccfeSMarcel Moolenaar p(ips_cantforward, "\t{:packets-cannot-forward/%ju} " 976ade9ccfeSMarcel Moolenaar "{N:/packet%s not forwardable}\n"); 977ade9ccfeSMarcel Moolenaar p(ips_notmember, "\t{:received-unknown-multicast-group/%ju} " 978ade9ccfeSMarcel Moolenaar "{N:/packet%s received for unknown multicast group}\n"); 979ade9ccfeSMarcel Moolenaar p(ips_redirectsent, "\t{:redirects-sent/%ju} " 980ade9ccfeSMarcel Moolenaar "{N:/redirect%s sent}\n"); 981ade9ccfeSMarcel Moolenaar p(ips_localout, "\t{:sent-packets/%ju} " 982ade9ccfeSMarcel Moolenaar "{N:/packet%s sent from this host}\n"); 983ade9ccfeSMarcel Moolenaar p(ips_rawout, "\t{:send-packets-fabricated-header/%ju} " 984ade9ccfeSMarcel Moolenaar "{N:/packet%s sent with fabricated ip header}\n"); 985ade9ccfeSMarcel Moolenaar p(ips_odropped, "\t{:discard-no-mbufs/%ju} " 986ade9ccfeSMarcel Moolenaar "{N:/output packet%s dropped due to no bufs, etc.}\n"); 987ade9ccfeSMarcel Moolenaar p(ips_noroute, "\t{:discard-no-route/%ju} " 988ade9ccfeSMarcel Moolenaar "{N:/output packet%s discarded due to no route}\n"); 989ade9ccfeSMarcel Moolenaar p(ips_fragmented, "\t{:sent-fragments/%ju} " 990ade9ccfeSMarcel Moolenaar "{N:/output datagram%s fragmented}\n"); 991ade9ccfeSMarcel Moolenaar p(ips_ofragments, "\t{:fragments-created/%ju} " 992ade9ccfeSMarcel Moolenaar "{N:/fragment%s created}\n"); 993ade9ccfeSMarcel Moolenaar p(ips_cantfrag, "\t{:discard-cannot-fragment/%ju} " 994ade9ccfeSMarcel Moolenaar "{N:/datagram%s that can't be fragmented}\n"); 995ade9ccfeSMarcel Moolenaar p(ips_nogif, "\t{:discard-tunnel-no-gif/%ju} " 996ade9ccfeSMarcel Moolenaar "{N:/tunneling packet%s that can't find gif}\n"); 997ade9ccfeSMarcel Moolenaar p(ips_badaddr, "\t{:discard-bad-address/%ju} " 998ade9ccfeSMarcel Moolenaar "{N:/datagram%s with bad address in header}\n"); 9999b50d902SRodney W. Grimes #undef p 100022694ebaSBruce Evans #undef p1a 1001ade9ccfeSMarcel Moolenaar xo_close_container(name); 10029b50d902SRodney W. Grimes } 10039b50d902SRodney W. Grimes 100454fc657dSGeorge V. Neville-Neil /* 100554fc657dSGeorge V. Neville-Neil * Dump ARP statistics structure. 100654fc657dSGeorge V. Neville-Neil */ 100754fc657dSGeorge V. Neville-Neil void 100854fc657dSGeorge V. Neville-Neil arp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) 100954fc657dSGeorge V. Neville-Neil { 10109eddb899SMark Johnston struct arpstat arpstat; 101154fc657dSGeorge V. Neville-Neil 10129eddb899SMark Johnston if (fetch_stats("net.link.ether.arp.stats", off, &arpstat, 10139eddb899SMark Johnston sizeof(arpstat), kread_counters) != 0) 101454fc657dSGeorge V. Neville-Neil return; 101554fc657dSGeorge V. Neville-Neil 1016ade9ccfeSMarcel Moolenaar xo_open_container(name); 1017ade9ccfeSMarcel Moolenaar xo_emit("{T:/%s}:\n", name); 101854fc657dSGeorge V. Neville-Neil 101954fc657dSGeorge V. Neville-Neil #define p(f, m) if (arpstat.f || sflag <= 1) \ 1020ade9ccfeSMarcel Moolenaar xo_emit("\t" m, (uintmax_t)arpstat.f, plural(arpstat.f)) 102154fc657dSGeorge V. Neville-Neil #define p2(f, m) if (arpstat.f || sflag <= 1) \ 1022ade9ccfeSMarcel Moolenaar xo_emit("\t" m, (uintmax_t)arpstat.f, pluralies(arpstat.f)) 102354fc657dSGeorge V. Neville-Neil 1024ade9ccfeSMarcel Moolenaar p(txrequests, "{:sent-requests/%ju} {N:/ARP request%s sent}\n"); 1025ade9ccfeSMarcel Moolenaar p2(txreplies, "{:sent-replies/%ju} {N:/ARP repl%s sent}\n"); 1026ade9ccfeSMarcel Moolenaar p(rxrequests, "{:received-requests/%ju} " 1027ade9ccfeSMarcel Moolenaar "{N:/ARP request%s received}\n"); 1028ade9ccfeSMarcel Moolenaar p2(rxreplies, "{:received-replies/%ju} " 1029ade9ccfeSMarcel Moolenaar "{N:/ARP repl%s received}\n"); 1030ade9ccfeSMarcel Moolenaar p(received, "{:received-packers/%ju} " 1031ade9ccfeSMarcel Moolenaar "{N:/ARP packet%s received}\n"); 1032ade9ccfeSMarcel Moolenaar p(dropped, "{:dropped-no-entry/%ju} " 1033ade9ccfeSMarcel Moolenaar "{N:/total packet%s dropped due to no ARP entry}\n"); 1034ade9ccfeSMarcel Moolenaar p(timeouts, "{:entries-timeout/%ju} " 1035ade9ccfeSMarcel Moolenaar "{N:/ARP entry%s timed out}\n"); 1036ade9ccfeSMarcel Moolenaar p(dupips, "{:dropped-duplicate-address/%ju} " 1037ade9ccfeSMarcel Moolenaar "{N:/Duplicate IP%s seen}\n"); 103854fc657dSGeorge V. Neville-Neil #undef p 103954fc657dSGeorge V. Neville-Neil #undef p2 1040ade9ccfeSMarcel Moolenaar xo_close_container(name); 104154fc657dSGeorge V. Neville-Neil } 104254fc657dSGeorge V. Neville-Neil 104354fc657dSGeorge V. Neville-Neil 104454fc657dSGeorge V. Neville-Neil 10454063583aSMaxim Konovalov static const char *icmpnames[ICMP_MAXTYPE + 1] = { 10464063583aSMaxim Konovalov "echo reply", /* RFC 792 */ 10479b50d902SRodney W. Grimes "#1", 10489b50d902SRodney W. Grimes "#2", 10494063583aSMaxim Konovalov "destination unreachable", /* RFC 792 */ 10504063583aSMaxim Konovalov "source quench", /* RFC 792 */ 10514063583aSMaxim Konovalov "routing redirect", /* RFC 792 */ 10529b50d902SRodney W. Grimes "#6", 10539b50d902SRodney W. Grimes "#7", 10544063583aSMaxim Konovalov "echo", /* RFC 792 */ 10554063583aSMaxim Konovalov "router advertisement", /* RFC 1256 */ 10564063583aSMaxim Konovalov "router solicitation", /* RFC 1256 */ 10574063583aSMaxim Konovalov "time exceeded", /* RFC 792 */ 10584063583aSMaxim Konovalov "parameter problem", /* RFC 792 */ 10594063583aSMaxim Konovalov "time stamp", /* RFC 792 */ 10604063583aSMaxim Konovalov "time stamp reply", /* RFC 792 */ 10614063583aSMaxim Konovalov "information request", /* RFC 792 */ 10624063583aSMaxim Konovalov "information request reply", /* RFC 792 */ 10634063583aSMaxim Konovalov "address mask request", /* RFC 950 */ 10644063583aSMaxim Konovalov "address mask reply", /* RFC 950 */ 10654063583aSMaxim Konovalov "#19", 10664063583aSMaxim Konovalov "#20", 10674063583aSMaxim Konovalov "#21", 10684063583aSMaxim Konovalov "#22", 10694063583aSMaxim Konovalov "#23", 10704063583aSMaxim Konovalov "#24", 10714063583aSMaxim Konovalov "#25", 10724063583aSMaxim Konovalov "#26", 10734063583aSMaxim Konovalov "#27", 10744063583aSMaxim Konovalov "#28", 10754063583aSMaxim Konovalov "#29", 10764063583aSMaxim Konovalov "icmp traceroute", /* RFC 1393 */ 10774063583aSMaxim Konovalov "datagram conversion error", /* RFC 1475 */ 10784063583aSMaxim Konovalov "mobile host redirect", 10794063583aSMaxim Konovalov "IPv6 where-are-you", 10804063583aSMaxim Konovalov "IPv6 i-am-here", 10814063583aSMaxim Konovalov "mobile registration req", 10824063583aSMaxim Konovalov "mobile registration reply", 10834063583aSMaxim Konovalov "domain name request", /* RFC 1788 */ 10844063583aSMaxim Konovalov "domain name reply", /* RFC 1788 */ 10854063583aSMaxim Konovalov "icmp SKIP", 10864063583aSMaxim Konovalov "icmp photuris", /* RFC 2521 */ 10879b50d902SRodney W. Grimes }; 10889b50d902SRodney W. Grimes 10899b50d902SRodney W. Grimes /* 10909b50d902SRodney W. Grimes * Dump ICMP statistics. 10919b50d902SRodney W. Grimes */ 10929b50d902SRodney W. Grimes void 1093feda1a43SJohn Baldwin icmp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) 10949b50d902SRodney W. Grimes { 10959eddb899SMark Johnston struct icmpstat icmpstat; 10964e00c309SGarrett Wollman size_t len; 10979eddb899SMark Johnston int i, first; 10989b50d902SRodney W. Grimes 10999eddb899SMark Johnston if (fetch_stats("net.inet.icmp.stats", off, &icmpstat, 11009eddb899SMark Johnston sizeof(icmpstat), kread_counters) != 0) 1101c73d99b5SRuslan Ermilov return; 11024e00c309SGarrett Wollman 1103ade9ccfeSMarcel Moolenaar xo_open_container(name); 1104ade9ccfeSMarcel Moolenaar xo_emit("{T:/%s}:\n", name); 11059b50d902SRodney W. Grimes 11069b50d902SRodney W. Grimes #define p(f, m) if (icmpstat.f || sflag <= 1) \ 1107ade9ccfeSMarcel Moolenaar xo_emit(m, icmpstat.f, plural(icmpstat.f)) 110822694ebaSBruce Evans #define p1a(f, m) if (icmpstat.f || sflag <= 1) \ 1109ade9ccfeSMarcel Moolenaar xo_emit(m, icmpstat.f) 1110bd714208SRuslan Ermilov #define p2(f, m) if (icmpstat.f || sflag <= 1) \ 1111ade9ccfeSMarcel Moolenaar xo_emit(m, icmpstat.f, plurales(icmpstat.f)) 11129b50d902SRodney W. Grimes 1113ade9ccfeSMarcel Moolenaar p(icps_error, "\t{:icmp-calls/%lu} " 1114ade9ccfeSMarcel Moolenaar "{N:/call%s to icmp_error}\n"); 1115ade9ccfeSMarcel Moolenaar p(icps_oldicmp, "\t{:errors-not-from-message/%lu} " 1116ade9ccfeSMarcel Moolenaar "{N:/error%s not generated in response to an icmp message}\n"); 1117ade9ccfeSMarcel Moolenaar 1118ade9ccfeSMarcel Moolenaar for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++) { 11199b50d902SRodney W. Grimes if (icmpstat.icps_outhist[i] != 0) { 11209b50d902SRodney W. Grimes if (first) { 1121ade9ccfeSMarcel Moolenaar xo_open_list("output-histogram"); 1122ade9ccfeSMarcel Moolenaar xo_emit("\tOutput histogram:\n"); 11239b50d902SRodney W. Grimes first = 0; 11249b50d902SRodney W. Grimes } 1125ade9ccfeSMarcel Moolenaar xo_open_instance("output-histogram"); 11264063583aSMaxim Konovalov if (icmpnames[i] != NULL) 1127ade9ccfeSMarcel Moolenaar xo_emit("\t\t{k:name/%s}: {:count/%lu}\n", 1128ade9ccfeSMarcel Moolenaar icmpnames[i], icmpstat.icps_outhist[i]); 11294063583aSMaxim Konovalov else 1130ade9ccfeSMarcel Moolenaar xo_emit("\t\tunknown ICMP #{k:name/%d}: " 1131ade9ccfeSMarcel Moolenaar "{:count/%lu}\n", 1132ade9ccfeSMarcel Moolenaar i, icmpstat.icps_outhist[i]); 1133ade9ccfeSMarcel Moolenaar xo_close_instance("output-histogram"); 11349b50d902SRodney W. Grimes } 1135ade9ccfeSMarcel Moolenaar } 1136ade9ccfeSMarcel Moolenaar if (!first) 1137ade9ccfeSMarcel Moolenaar xo_close_list("output-histogram"); 1138ade9ccfeSMarcel Moolenaar 1139ade9ccfeSMarcel Moolenaar p(icps_badcode, "\t{:dropped-bad-code/%lu} " 1140ade9ccfeSMarcel Moolenaar "{N:/message%s with bad code fields}\n"); 1141ade9ccfeSMarcel Moolenaar p(icps_tooshort, "\t{:dropped-too-short/%lu} " 1142ade9ccfeSMarcel Moolenaar "{N:/message%s less than the minimum length}\n"); 1143ade9ccfeSMarcel Moolenaar p(icps_checksum, "\t{:dropped-bad-checksum/%lu} " 1144ade9ccfeSMarcel Moolenaar "{N:/message%s with bad checksum}\n"); 1145ade9ccfeSMarcel Moolenaar p(icps_badlen, "\t{:dropped-bad-length/%lu} " 1146ade9ccfeSMarcel Moolenaar "{N:/message%s with bad length}\n"); 1147ade9ccfeSMarcel Moolenaar p1a(icps_bmcastecho, "\t{:dropped-multicast-echo/%lu} " 1148ade9ccfeSMarcel Moolenaar "{N:/multicast echo requests ignored}\n"); 1149ade9ccfeSMarcel Moolenaar p1a(icps_bmcasttstamp, "\t{:dropped-multicast-timestamp/%lu} " 1150ade9ccfeSMarcel Moolenaar "{N:/multicast timestamp requests ignored}\n"); 1151ade9ccfeSMarcel Moolenaar 1152ade9ccfeSMarcel Moolenaar for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++) { 11539b50d902SRodney W. Grimes if (icmpstat.icps_inhist[i] != 0) { 11549b50d902SRodney W. Grimes if (first) { 1155ade9ccfeSMarcel Moolenaar xo_open_list("input-histogram"); 1156ade9ccfeSMarcel Moolenaar xo_emit("\tInput histogram:\n"); 11579b50d902SRodney W. Grimes first = 0; 11589b50d902SRodney W. Grimes } 1159ade9ccfeSMarcel Moolenaar xo_open_instance("input-histogram"); 11604063583aSMaxim Konovalov if (icmpnames[i] != NULL) 1161ade9ccfeSMarcel Moolenaar xo_emit("\t\t{k:name/%s}: {:count/%lu}\n", 1162ade9ccfeSMarcel Moolenaar icmpnames[i], 11639b50d902SRodney W. Grimes icmpstat.icps_inhist[i]); 11644063583aSMaxim Konovalov else 1165ade9ccfeSMarcel Moolenaar xo_emit( 1166ade9ccfeSMarcel Moolenaar "\t\tunknown ICMP #{k:name/%d}: {:count/%lu}\n", 1167ade9ccfeSMarcel Moolenaar i, icmpstat.icps_inhist[i]); 1168ade9ccfeSMarcel Moolenaar xo_close_instance("input-histogram"); 11699b50d902SRodney W. Grimes } 1170ade9ccfeSMarcel Moolenaar } 1171ade9ccfeSMarcel Moolenaar if (!first) 1172ade9ccfeSMarcel Moolenaar xo_close_list("input-histogram"); 1173ade9ccfeSMarcel Moolenaar 1174ade9ccfeSMarcel Moolenaar p(icps_reflect, "\t{:sent-packets/%lu} " 1175ade9ccfeSMarcel Moolenaar "{N:/message response%s generated}\n"); 1176ade9ccfeSMarcel Moolenaar p2(icps_badaddr, "\t{:discard-invalid-return-address/%lu} " 1177ade9ccfeSMarcel Moolenaar "{N:/invalid return address%s}\n"); 1178ade9ccfeSMarcel Moolenaar p(icps_noroute, "\t{:discard-no-route/%lu} " 1179ade9ccfeSMarcel Moolenaar "{N:/no return route%s}\n"); 11809b50d902SRodney W. Grimes #undef p 118122694ebaSBruce Evans #undef p1a 1182bd714208SRuslan Ermilov #undef p2 1183feda1a43SJohn Baldwin if (live) { 11844e00c309SGarrett Wollman len = sizeof i; 1185feda1a43SJohn Baldwin if (sysctlbyname("net.inet.icmp.maskrepl", &i, &len, NULL, 0) < 1186feda1a43SJohn Baldwin 0) 11874e00c309SGarrett Wollman return; 1188ade9ccfeSMarcel Moolenaar xo_emit("\tICMP address mask responses are " 1189ade9ccfeSMarcel Moolenaar "{q:icmp-address-responses/%sabled}\n", i ? "en" : "dis"); 11909b50d902SRodney W. Grimes } 1191ade9ccfeSMarcel Moolenaar 1192ade9ccfeSMarcel Moolenaar xo_close_container(name); 1193feda1a43SJohn Baldwin } 11949b50d902SRodney W. Grimes 1195d10910e6SBruce M Simpson /* 1196d10910e6SBruce M Simpson * Dump IGMP statistics structure. 1197d10910e6SBruce M Simpson */ 1198d10910e6SBruce M Simpson void 1199d10910e6SBruce M Simpson igmp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) 1200d10910e6SBruce M Simpson { 12019eddb899SMark Johnston struct igmpstat igmpstat; 1202d10910e6SBruce M Simpson 12039eddb899SMark Johnston if (fetch_stats("net.inet.igmp.stats", 0, &igmpstat, 12049eddb899SMark Johnston sizeof(igmpstat), kread) != 0) 1205d10910e6SBruce M Simpson return; 1206d10910e6SBruce M Simpson 1207d10910e6SBruce M Simpson if (igmpstat.igps_version != IGPS_VERSION_3) { 1208ade9ccfeSMarcel Moolenaar xo_warnx("%s: version mismatch (%d != %d)", __func__, 1209d10910e6SBruce M Simpson igmpstat.igps_version, IGPS_VERSION_3); 1210d10910e6SBruce M Simpson } 1211d10910e6SBruce M Simpson if (igmpstat.igps_len != IGPS_VERSION3_LEN) { 1212ade9ccfeSMarcel Moolenaar xo_warnx("%s: size mismatch (%d != %d)", __func__, 1213d10910e6SBruce M Simpson igmpstat.igps_len, IGPS_VERSION3_LEN); 1214d10910e6SBruce M Simpson } 1215d10910e6SBruce M Simpson 1216ade9ccfeSMarcel Moolenaar xo_open_container(name); 1217ade9ccfeSMarcel Moolenaar xo_emit("{T:/%s}:\n", name); 1218d10910e6SBruce M Simpson 1219d10910e6SBruce M Simpson #define p64(f, m) if (igmpstat.f || sflag <= 1) \ 1220ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t) igmpstat.f, plural(igmpstat.f)) 1221d10910e6SBruce M Simpson #define py64(f, m) if (igmpstat.f || sflag <= 1) \ 1222ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t) igmpstat.f, pluralies(igmpstat.f)) 1223ade9ccfeSMarcel Moolenaar 1224ade9ccfeSMarcel Moolenaar p64(igps_rcv_total, "\t{:received-messages/%ju} " 1225ade9ccfeSMarcel Moolenaar "{N:/message%s received}\n"); 1226ade9ccfeSMarcel Moolenaar p64(igps_rcv_tooshort, "\t{:dropped-too-short/%ju} " 1227ade9ccfeSMarcel Moolenaar "{N:/message%s received with too few bytes}\n"); 1228ade9ccfeSMarcel Moolenaar p64(igps_rcv_badttl, "\t{:dropped-wrong-ttl/%ju} " 1229ade9ccfeSMarcel Moolenaar "{N:/message%s received with wrong TTL}\n"); 1230ade9ccfeSMarcel Moolenaar p64(igps_rcv_badsum, "\t{:dropped-bad-checksum/%ju} " 1231ade9ccfeSMarcel Moolenaar "{N:/message%s received with bad checksum}\n"); 1232ade9ccfeSMarcel Moolenaar py64(igps_rcv_v1v2_queries, "\t{:received-membership-queries/%ju} " 1233ade9ccfeSMarcel Moolenaar "{N:/V1\\/V2 membership quer%s received}\n"); 1234ade9ccfeSMarcel Moolenaar py64(igps_rcv_v3_queries, "\t{:received-v3-membership-queries/%ju} " 1235ade9ccfeSMarcel Moolenaar "{N:/V3 membership quer%s received}\n"); 1236ade9ccfeSMarcel Moolenaar py64(igps_rcv_badqueries, "\t{:dropped-membership-queries/%ju} " 1237ade9ccfeSMarcel Moolenaar "{N:/membership quer%s received with invalid field(s)}\n"); 1238ade9ccfeSMarcel Moolenaar py64(igps_rcv_gen_queries, "\t{:received-general-queries/%ju} " 1239ade9ccfeSMarcel Moolenaar "{N:/general quer%s received}\n"); 1240ade9ccfeSMarcel Moolenaar py64(igps_rcv_group_queries, "\t{:received-group-queries/%ju} " 1241ade9ccfeSMarcel Moolenaar "{N:/group quer%s received}\n"); 1242ade9ccfeSMarcel Moolenaar py64(igps_rcv_gsr_queries, "\t{:received-group-source-queries/%ju} " 1243ade9ccfeSMarcel Moolenaar "{N:/group-source quer%s received}\n"); 1244ade9ccfeSMarcel Moolenaar py64(igps_drop_gsr_queries, "\t{:dropped-group-source-queries/%ju} " 1245ade9ccfeSMarcel Moolenaar "{N:/group-source quer%s dropped}\n"); 1246ade9ccfeSMarcel Moolenaar p64(igps_rcv_reports, "\t{:received-membership-requests/%ju} " 1247ade9ccfeSMarcel Moolenaar "{N:/membership report%s received}\n"); 1248ade9ccfeSMarcel Moolenaar p64(igps_rcv_badreports, "\t{:dropped-membership-reports/%ju} " 1249ade9ccfeSMarcel Moolenaar "{N:/membership report%s received with invalid field(s)}\n"); 1250ade9ccfeSMarcel Moolenaar p64(igps_rcv_ourreports, "\t" 1251ade9ccfeSMarcel Moolenaar "{:received-membership-reports-matching/%ju} " 1252ade9ccfeSMarcel Moolenaar "{N:/membership report%s received for groups to which we belong}" 1253ade9ccfeSMarcel Moolenaar "\n"); 1254ade9ccfeSMarcel Moolenaar p64(igps_rcv_nora, "\t{:received-v3-reports-no-router-alert/%ju} " 1255ade9ccfeSMarcel Moolenaar "{N:/V3 report%s received without Router Alert}\n"); 1256ade9ccfeSMarcel Moolenaar p64(igps_snd_reports, "\t{:sent-membership-reports/%ju} " 1257ade9ccfeSMarcel Moolenaar "{N:/membership report%s sent}\n"); 1258d10910e6SBruce M Simpson #undef p64 1259d10910e6SBruce M Simpson #undef py64 1260ade9ccfeSMarcel Moolenaar xo_close_container(name); 1261d10910e6SBruce M Simpson } 12629b50d902SRodney W. Grimes 12639b50d902SRodney W. Grimes /* 1264c7b9b5bbSJeffrey Hsu * Dump PIM statistics structure. 1265c7b9b5bbSJeffrey Hsu */ 1266c7b9b5bbSJeffrey Hsu void 1267feda1a43SJohn Baldwin pim_stats(u_long off __unused, const char *name, int af1 __unused, 1268feda1a43SJohn Baldwin int proto __unused) 1269c7b9b5bbSJeffrey Hsu { 12709eddb899SMark Johnston struct pimstat pimstat; 1271c7b9b5bbSJeffrey Hsu 12729eddb899SMark Johnston if (fetch_stats("net.inet.pim.stats", off, &pimstat, 12739eddb899SMark Johnston sizeof(pimstat), kread_counters) != 0) 1274c7b9b5bbSJeffrey Hsu return; 1275c7b9b5bbSJeffrey Hsu 1276ade9ccfeSMarcel Moolenaar xo_open_container(name); 1277ade9ccfeSMarcel Moolenaar xo_emit("{T:/%s}:\n", name); 1278c7b9b5bbSJeffrey Hsu 1279c7b9b5bbSJeffrey Hsu #define p(f, m) if (pimstat.f || sflag <= 1) \ 1280ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t)pimstat.f, plural(pimstat.f)) 1281c7b9b5bbSJeffrey Hsu #define py(f, m) if (pimstat.f || sflag <= 1) \ 1282ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t)pimstat.f, pimstat.f != 1 ? "ies" : "y") 1283ade9ccfeSMarcel Moolenaar 1284ade9ccfeSMarcel Moolenaar p(pims_rcv_total_msgs, "\t{:received-messages/%ju} " 1285ade9ccfeSMarcel Moolenaar "{N:/message%s received}\n"); 1286ade9ccfeSMarcel Moolenaar p(pims_rcv_total_bytes, "\t{:received-bytes/%ju} " 1287ade9ccfeSMarcel Moolenaar "{N:/byte%s received}\n"); 1288ade9ccfeSMarcel Moolenaar p(pims_rcv_tooshort, "\t{:dropped-too-short/%ju} " 1289ade9ccfeSMarcel Moolenaar "{N:/message%s received with too few bytes}\n"); 1290ade9ccfeSMarcel Moolenaar p(pims_rcv_badsum, "\t{:dropped-bad-checksum/%ju} " 1291ade9ccfeSMarcel Moolenaar "{N:/message%s received with bad checksum}\n"); 1292ade9ccfeSMarcel Moolenaar p(pims_rcv_badversion, "\t{:dropped-bad-version/%ju} " 1293ade9ccfeSMarcel Moolenaar "{N:/message%s received with bad version}\n"); 1294ade9ccfeSMarcel Moolenaar p(pims_rcv_registers_msgs, "\t{:received-data-register-messages/%ju} " 1295ade9ccfeSMarcel Moolenaar "{N:/data register message%s received}\n"); 1296ade9ccfeSMarcel Moolenaar p(pims_rcv_registers_bytes, "\t{:received-data-register-bytes/%ju} " 1297ade9ccfeSMarcel Moolenaar "{N:/data register byte%s received}\n"); 1298ade9ccfeSMarcel Moolenaar p(pims_rcv_registers_wrongiif, "\t" 1299ade9ccfeSMarcel Moolenaar "{:received-data-register-wrong-interface/%ju} " 1300ade9ccfeSMarcel Moolenaar "{N:/data register message%s received on wrong iif}\n"); 1301ade9ccfeSMarcel Moolenaar p(pims_rcv_badregisters, "\t{:received-bad-registers/%ju} " 1302ade9ccfeSMarcel Moolenaar "{N:/bad register%s received}\n"); 1303ade9ccfeSMarcel Moolenaar p(pims_snd_registers_msgs, "\t{:sent-data-register-messages/%ju} " 1304ade9ccfeSMarcel Moolenaar "{N:/data register message%s sent}\n"); 1305ade9ccfeSMarcel Moolenaar p(pims_snd_registers_bytes, "\t{:sent-data-register-bytes/%ju} " 1306ade9ccfeSMarcel Moolenaar "{N:/data register byte%s sent}\n"); 1307c7b9b5bbSJeffrey Hsu #undef p 1308c7b9b5bbSJeffrey Hsu #undef py 1309ade9ccfeSMarcel Moolenaar xo_close_container(name); 1310c7b9b5bbSJeffrey Hsu } 1311c7b9b5bbSJeffrey Hsu 1312c7b9b5bbSJeffrey Hsu /* 13139b50d902SRodney W. Grimes * Pretty print an Internet address (net address + port). 13149b50d902SRodney W. Grimes */ 13159b50d902SRodney W. Grimes void 1316ade9ccfeSMarcel Moolenaar inetprint(const char *container, struct in_addr *in, int port, 1317046aad39SHajimu UMEMOTO const char *proto, int num_port, const int af1) 13189b50d902SRodney W. Grimes { 13199b50d902SRodney W. Grimes struct servent *sp = 0; 13209b50d902SRodney W. Grimes char line[80], *cp; 1321cfa1ca9dSYoshinobu Inoue int width; 1322f193c8ceSXin LI size_t alen, plen; 13239b50d902SRodney W. Grimes 1324ade9ccfeSMarcel Moolenaar if (container) 1325ade9ccfeSMarcel Moolenaar xo_open_container(container); 1326ade9ccfeSMarcel Moolenaar 1327080b7f49SDag-Erling Smørgrav if (Wflag) 1328f193c8ceSXin LI snprintf(line, sizeof(line), "%s.", inetname(in)); 1329080b7f49SDag-Erling Smørgrav else 1330f193c8ceSXin LI snprintf(line, sizeof(line), "%.*s.", 1331f193c8ceSXin LI (Aflag && !num_port) ? 12 : 16, inetname(in)); 1332f193c8ceSXin LI alen = strlen(line); 1333f193c8ceSXin LI cp = line + alen; 1334a01e3379SDavid Malone if (!num_port && port) 13359b50d902SRodney W. Grimes sp = getservbyport((int)port, proto); 13369b50d902SRodney W. Grimes if (sp || port == 0) 1337f193c8ceSXin LI snprintf(cp, sizeof(line) - alen, 1338f193c8ceSXin LI "%.15s ", sp ? sp->s_name : "*"); 13399b50d902SRodney W. Grimes else 1340f193c8ceSXin LI snprintf(cp, sizeof(line) - alen, 1341f193c8ceSXin LI "%d ", ntohs((u_short)port)); 1342046aad39SHajimu UMEMOTO width = (Aflag && !Wflag) ? 18 : 1343046aad39SHajimu UMEMOTO ((!Wflag || af1 == AF_INET) ? 22 : 45); 1344080b7f49SDag-Erling Smørgrav if (Wflag) 1345ade9ccfeSMarcel Moolenaar xo_emit("{d:target/%-*s} ", width, line); 1346080b7f49SDag-Erling Smørgrav else 1347ade9ccfeSMarcel Moolenaar xo_emit("{d:target/%-*.*s} ", width, width, line); 1348ade9ccfeSMarcel Moolenaar 1349f193c8ceSXin LI plen = strlen(cp) - 1; 1350f193c8ceSXin LI alen--; 1351ade9ccfeSMarcel Moolenaar xo_emit("{e:address/%*.*s}{e:port/%*.*s}", alen, alen, line, plen, 1352ade9ccfeSMarcel Moolenaar plen, cp); 1353ade9ccfeSMarcel Moolenaar 1354ade9ccfeSMarcel Moolenaar if (container) 1355ade9ccfeSMarcel Moolenaar xo_close_container(container); 13569b50d902SRodney W. Grimes } 13579b50d902SRodney W. Grimes 13589b50d902SRodney W. Grimes /* 13599b50d902SRodney W. Grimes * Construct an Internet address representation. 136065ea0024SAssar Westerlund * If numeric_addr has been supplied, give 13619b50d902SRodney W. Grimes * numeric value, otherwise try for symbolic name. 13629b50d902SRodney W. Grimes */ 13639b50d902SRodney W. Grimes char * 13645e051718SAssar Westerlund inetname(struct in_addr *inp) 13659b50d902SRodney W. Grimes { 1366a01e3379SDavid Malone char *cp; 1367d121b556SBrian Somers static char line[MAXHOSTNAMELEN]; 13689b50d902SRodney W. Grimes struct hostent *hp; 13699b50d902SRodney W. Grimes struct netent *np; 13709b50d902SRodney W. Grimes 13719b50d902SRodney W. Grimes cp = 0; 137265ea0024SAssar Westerlund if (!numeric_addr && inp->s_addr != INADDR_ANY) { 13739b50d902SRodney W. Grimes int net = inet_netof(*inp); 13749b50d902SRodney W. Grimes int lna = inet_lnaof(*inp); 13759b50d902SRodney W. Grimes 13769b50d902SRodney W. Grimes if (lna == INADDR_ANY) { 13779b50d902SRodney W. Grimes np = getnetbyaddr(net, AF_INET); 13789b50d902SRodney W. Grimes if (np) 13799b50d902SRodney W. Grimes cp = np->n_name; 13809b50d902SRodney W. Grimes } 1381ef1cb629SMarcelo Araujo if (cp == NULL) { 13829b50d902SRodney W. Grimes hp = gethostbyaddr((char *)inp, sizeof (*inp), AF_INET); 13839b50d902SRodney W. Grimes if (hp) { 13849b50d902SRodney W. Grimes cp = hp->h_name; 1385d121b556SBrian Somers trimdomain(cp, strlen(cp)); 13869b50d902SRodney W. Grimes } 13879b50d902SRodney W. Grimes } 13889b50d902SRodney W. Grimes } 13899b50d902SRodney W. Grimes if (inp->s_addr == INADDR_ANY) 13909b50d902SRodney W. Grimes strcpy(line, "*"); 13919a1f6729SWarner Losh else if (cp) { 13921c109628SXin LI strlcpy(line, cp, sizeof(line)); 13939a1f6729SWarner Losh } else { 13949b50d902SRodney W. Grimes inp->s_addr = ntohl(inp->s_addr); 139522694ebaSBruce Evans #define C(x) ((u_int)((x) & 0xff)) 1396f193c8ceSXin LI snprintf(line, sizeof(line), "%u.%u.%u.%u", 1397f193c8ceSXin LI C(inp->s_addr >> 24), C(inp->s_addr >> 16), 1398f193c8ceSXin LI C(inp->s_addr >> 8), C(inp->s_addr)); 13999b50d902SRodney W. Grimes } 14009b50d902SRodney W. Grimes return (line); 14019b50d902SRodney W. Grimes } 1402