Index: stable/10/usr.bin/netstat/flowtable.c =================================================================== --- stable/10/usr.bin/netstat/flowtable.c (revision 293306) +++ stable/10/usr.bin/netstat/flowtable.c (revision 293307) @@ -1,84 +1,87 @@ /*- * Copyright (c) 2014 Gleb Smirnoff * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); + #include -#include + #include -#include + #include #include + #include "netstat.h" /* * Print flowtable statistics. */ static void print_stats(struct flowtable_stat *stat) { #define p(f, m) if (stat->f || sflag <= 1) \ printf(m, (uintmax_t)stat->f, plural(stat->f)) #define p2(f, m) if (stat->f || sflag <= 1) \ printf(m, (uintmax_t)stat->f, plurales(stat->f)) p(ft_lookups, "\t%ju lookup%s\n"); p(ft_hits, "\t%ju hit%s\n"); p2(ft_misses, "\t%ju miss%s\n"); p(ft_inserts, "\t%ju insert%s\n"); p(ft_collisions, "\t%ju collision%s\n"); p(ft_free_checks, "\t%ju free check%s\n"); p(ft_frees, "\t%ju free%s\n"); p(ft_fail_lle_invalid, "\t%ju lookup%s with not resolved Layer 2 address\n"); #undef p2 #undef p } void flowtable_stats(void) { struct flowtable_stat stat; - size_t len = sizeof(stat); if (!live) return; - if (sysctlbyname("net.flowtable.ip4.stat", &stat, &len, NULL, 0) == 0) { + if (fetch_stats("net.flowtable.ip4.stat", 0, &stat, + sizeof(stat), NULL) == 0) { printf("flowtable for IPv4:\n"); print_stats(&stat); } - if (sysctlbyname("net.flowtable.ip6.stat", &stat, &len, NULL, 0) == 0) { + if (fetch_stats("net.flowtable.ip6.stat", 0, &stat, + sizeof(stat), NULL) == 0) { printf("flowtable for IPv6:\n"); print_stats(&stat); } } Index: stable/10/usr.bin/netstat/if.c =================================================================== --- stable/10/usr.bin/netstat/if.c (revision 293306) +++ stable/10/usr.bin/netstat/if.c (revision 293307) @@ -1,607 +1,597 @@ /*- * Copyright (c) 2013 Gleb Smirnoff * Copyright (c) 1983, 1988, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if 0 #ifndef lint static char sccsid[] = "@(#)if.c 8.3 (Berkeley) 4/28/95"; #endif /* not lint */ #endif #include __FBSDID("$FreeBSD$"); #include #include #include #include -#include #include #define _IFI_OQDROPS #include #include #include #include #include #include #include #include #include #include #ifdef PF #include #include #endif #include #include #include #include #ifdef INET6 #include #endif #include #include #include #include #include #include #include #include #include "netstat.h" static void sidewaysintpr(int); #ifdef INET6 static char addr_buf[NI_MAXHOST]; /* for getnameinfo() */ #endif #ifdef PF static const char* pfsyncacts[] = { /* PFSYNC_ACT_CLR */ "clear all request", /* PFSYNC_ACT_INS */ "state insert", /* PFSYNC_ACT_INS_ACK */ "state inserted ack", /* PFSYNC_ACT_UPD */ "state update", /* PFSYNC_ACT_UPD_C */ "compressed state update", /* PFSYNC_ACT_UPD_REQ */ "uncompressed state request", /* PFSYNC_ACT_DEL */ "state delete", /* PFSYNC_ACT_DEL_C */ "compressed state delete", /* PFSYNC_ACT_INS_F */ "fragment insert", /* PFSYNC_ACT_DEL_F */ "fragment delete", /* PFSYNC_ACT_BUS */ "bulk update mark", /* PFSYNC_ACT_TDB */ "TDB replay counter update", /* PFSYNC_ACT_EOF */ "end of frame mark", }; static void pfsync_acts_stats(const char *fmt, uint64_t *a) { int i; for (i = 0; i < PFSYNC_ACT_MAX; i++, a++) if (*a || sflag <= 1) printf(fmt, *a, pfsyncacts[i], plural(*a)); } /* * Dump pfsync statistics structure. */ void pfsync_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { - struct pfsyncstats pfsyncstat, zerostat; - size_t len = sizeof(struct pfsyncstats); + struct pfsyncstats pfsyncstat; - if (live) { - if (zflag) - memset(&zerostat, 0, len); - if (sysctlbyname("net.pfsync.stats", &pfsyncstat, &len, - zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { - if (errno != ENOENT) - warn("sysctl: net.pfsync.stats"); - return; - } - } else - kread(off, &pfsyncstat, len); + if (fetch_stats("net.pfsync.stats", off, &pfsyncstat, + sizeof(pfsyncstat), kread) != 0) + return; printf("%s:\n", name); #define p(f, m) if (pfsyncstat.f || sflag <= 1) \ printf(m, (uintmax_t)pfsyncstat.f, plural(pfsyncstat.f)) p(pfsyncs_ipackets, "\t%ju packet%s received (IPv4)\n"); p(pfsyncs_ipackets6, "\t%ju packet%s received (IPv6)\n"); pfsync_acts_stats("\t %ju %s%s received\n", &pfsyncstat.pfsyncs_iacts[0]); p(pfsyncs_badif, "\t\t%ju packet%s discarded for bad interface\n"); p(pfsyncs_badttl, "\t\t%ju packet%s discarded for bad ttl\n"); p(pfsyncs_hdrops, "\t\t%ju packet%s shorter than header\n"); p(pfsyncs_badver, "\t\t%ju packet%s discarded for bad version\n"); p(pfsyncs_badauth, "\t\t%ju packet%s discarded for bad HMAC\n"); p(pfsyncs_badact,"\t\t%ju packet%s discarded for bad action\n"); p(pfsyncs_badlen, "\t\t%ju packet%s discarded for short packet\n"); p(pfsyncs_badval, "\t\t%ju state%s discarded for bad values\n"); p(pfsyncs_stale, "\t\t%ju stale state%s\n"); p(pfsyncs_badstate, "\t\t%ju failed state lookup/insert%s\n"); p(pfsyncs_opackets, "\t%ju packet%s sent (IPv4)\n"); p(pfsyncs_opackets6, "\t%ju packet%s sent (IPv6)\n"); pfsync_acts_stats("\t %ju %s%s sent\n", &pfsyncstat.pfsyncs_oacts[0]); p(pfsyncs_onomem, "\t\t%ju failure%s due to mbuf memory error\n"); p(pfsyncs_oerrors, "\t\t%ju send error%s\n"); #undef p } #endif /* PF */ /* * Display a formatted value, or a '-' in the same space. */ static void show_stat(const char *fmt, int width, u_long value, short showvalue, int div1000) { const char *lsep, *rsep; char newfmt[32]; lsep = ""; if (strncmp(fmt, "LS", 2) == 0) { lsep = " "; fmt += 2; } rsep = " "; if (strncmp(fmt, "NRS", 3) == 0) { rsep = ""; fmt += 3; } if (showvalue == 0) { /* Print just dash. */ sprintf(newfmt, "%s%%%ds%s", lsep, width, rsep); printf(newfmt, "-"); return; } if (hflag) { char buf[5]; /* Format in human readable form. */ humanize_number(buf, sizeof(buf), (int64_t)value, "", HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL | \ ((div1000) ? HN_DIVISOR_1000 : 0)); sprintf(newfmt, "%s%%%ds%s", lsep, width, rsep); printf(newfmt, buf); } else { /* Construct the format string. */ sprintf(newfmt, "%s%%%d%s%s", lsep, width, fmt, rsep); printf(newfmt, value); } } /* * Find next multiaddr for a given interface name. */ static struct ifmaddrs * next_ifma(struct ifmaddrs *ifma, const char *name, const sa_family_t family) { for(; ifma != NULL; ifma = ifma->ifma_next) { struct sockaddr_dl *sdl; sdl = (struct sockaddr_dl *)ifma->ifma_name; if (ifma->ifma_addr->sa_family == family && strcmp(sdl->sdl_data, name) == 0) break; } return (ifma); } /* * Print a description of the network interfaces. */ void intpr(int interval, void (*pfunc)(char *), int af) { struct ifaddrs *ifap, *ifa; struct ifmaddrs *ifmap, *ifma; u_int ifn_len_max = 5; if (interval) return sidewaysintpr(interval); if (getifaddrs(&ifap) != 0) err(EX_OSERR, "getifaddrs"); if (aflag && getifmaddrs(&ifmap) != 0) err(EX_OSERR, "getifmaddrs"); if (Wflag) { for (ifa = ifap; ifa; ifa = ifa->ifa_next) { if (interface != NULL && strcmp(ifa->ifa_name, interface) != 0) continue; if (af != AF_UNSPEC && ifa->ifa_addr->sa_family != af) continue; ifn_len_max = MAX(ifn_len_max, strlen(ifa->ifa_name)); } } if (!pfunc) { printf("%-*.*s", ifn_len_max, ifn_len_max, "Name"); printf(" %5.5s %-13.13s %-17.17s %8.8s %5.5s %5.5s", "Mtu", "Network", "Address", "Ipkts", "Ierrs", "Idrop"); if (bflag) printf(" %10.10s","Ibytes"); printf(" %8.8s %5.5s", "Opkts", "Oerrs"); if (bflag) printf(" %10.10s","Obytes"); printf(" %5s", "Coll"); if (dflag) printf(" %s", "Drop"); putchar('\n'); } for (ifa = ifap; ifa; ifa = ifa->ifa_next) { bool network = false, link = false; if (interface != NULL && strcmp(ifa->ifa_name, interface) != 0) continue; if (pfunc) { char *name; name = ifa->ifa_name; (*pfunc)(name); /* * Skip all ifaddrs belonging to same interface. */ while(ifa->ifa_next != NULL && (strcmp(ifa->ifa_next->ifa_name, name) == 0)) { ifa = ifa->ifa_next; } continue; } if (af != AF_UNSPEC && ifa->ifa_addr->sa_family != af) continue; printf("%-*.*s", ifn_len_max, ifn_len_max, ifa->ifa_name); #define IFA_MTU(ifa) (((struct if_data *)(ifa)->ifa_data)->ifi_mtu) show_stat("lu", 6, IFA_MTU(ifa), IFA_MTU(ifa), 0); #undef IFA_MTU switch (ifa->ifa_addr->sa_family) { case AF_UNSPEC: printf("%-13.13s ", "none"); printf("%-15.15s ", "none"); break; case AF_INET: { struct sockaddr_in *sin, *mask; sin = (struct sockaddr_in *)ifa->ifa_addr; mask = (struct sockaddr_in *)ifa->ifa_netmask; printf("%-13.13s ", netname(sin->sin_addr.s_addr, mask->sin_addr.s_addr)); printf("%-17.17s ", routename(sin->sin_addr.s_addr)); network = true; break; } #ifdef INET6 case AF_INET6: { struct sockaddr_in6 *sin6, *mask; sin6 = (struct sockaddr_in6 *)ifa->ifa_addr; mask = (struct sockaddr_in6 *)ifa->ifa_netmask; printf("%-13.13s ", netname6(sin6, &mask->sin6_addr)); getnameinfo(ifa->ifa_addr, ifa->ifa_addr->sa_len, addr_buf, sizeof(addr_buf), 0, 0, NI_NUMERICHOST); printf("%-17.17s ", addr_buf); network = 1; break; } #endif /* INET6 */ case AF_IPX: { struct sockaddr_ipx *sipx; u_long net; char netnum[10]; sipx = (struct sockaddr_ipx *)ifa->ifa_addr; *(union ipx_net *) &net = sipx->sipx_addr.x_net; sprintf(netnum, "%lx", (u_long)ntohl(net)); printf("ipx:%-8s ", netnum); printf("%-17s ", ipx_phost((struct sockaddr *)sipx)); network = 1; break; } case AF_APPLETALK: printf("atalk:%-12.12s ", atalk_print(ifa->ifa_addr, 0x10)); printf("%-11.11s ", atalk_print(ifa->ifa_addr, 0x0b)); break; case AF_LINK: { struct sockaddr_dl *sdl; char *cp, linknum[10]; int n, m; sdl = (struct sockaddr_dl *)ifa->ifa_addr; cp = (char *)LLADDR(sdl); n = sdl->sdl_alen; sprintf(linknum, "", sdl->sdl_index); m = printf("%-13.13s ", linknum); while ((--n >= 0) && (m < 30)) m += printf("%02x%c", *cp++ & 0xff, n > 0 ? ':' : ' '); m = 32 - m; while (m-- > 0) putchar(' '); link = 1; break; } } #define IFA_STAT(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s) show_stat("lu", 8, IFA_STAT(ipackets), link|network, 1); show_stat("lu", 5, IFA_STAT(ierrors), link, 1); show_stat("lu", 5, IFA_STAT(iqdrops), link, 1); if (bflag) show_stat("lu", 10, IFA_STAT(ibytes), link|network, 0); show_stat("lu", 8, IFA_STAT(opackets), link|network, 1); show_stat("lu", 5, IFA_STAT(oerrors), link, 1); if (bflag) show_stat("lu", 10, IFA_STAT(obytes), link|network, 0); show_stat("NRSlu", 5, IFA_STAT(collisions), link, 1); if (dflag) show_stat("LSlu", 5, IFA_STAT(oqdrops), link, 1); putchar('\n'); if (!aflag) continue; /* * Print family's multicast addresses. */ for (ifma = next_ifma(ifmap, ifa->ifa_name, ifa->ifa_addr->sa_family); ifma != NULL; ifma = next_ifma(ifma, ifa->ifa_name, ifa->ifa_addr->sa_family)) { const char *fmt = NULL; switch (ifma->ifma_addr->sa_family) { case AF_INET: { struct sockaddr_in *sin; sin = (struct sockaddr_in *)ifma->ifma_addr; fmt = routename(sin->sin_addr.s_addr); break; } #ifdef INET6 case AF_INET6: /* in6_fillscopeid(&msa.in6); */ getnameinfo(ifma->ifma_addr, ifma->ifma_addr->sa_len, addr_buf, sizeof(addr_buf), 0, 0, NI_NUMERICHOST); printf("%*s %s\n", Wflag ? 27 : 25, "", addr_buf); break; #endif /* INET6 */ case AF_LINK: { struct sockaddr_dl *sdl; sdl = (struct sockaddr_dl *)ifma->ifma_addr; switch (sdl->sdl_type) { case IFT_ETHER: case IFT_FDDI: fmt = ether_ntoa( (struct ether_addr *)LLADDR(sdl)); break; } break; } } if (fmt) { printf("%*s %-17.17s", Wflag ? 27 : 25, "", fmt); if (ifma->ifma_addr->sa_family == AF_LINK) { printf(" %8lu", IFA_STAT(imcasts)); printf("%*s", bflag ? 17 : 6, ""); printf(" %8lu", IFA_STAT(omcasts)); } putchar('\n'); } ifma = ifma->ifma_next; } } freeifaddrs(ifap); if (aflag) freeifmaddrs(ifmap); } struct iftot { u_long ift_ip; /* input packets */ u_long ift_ie; /* input errors */ u_long ift_id; /* input drops */ u_long ift_op; /* output packets */ u_long ift_oe; /* output errors */ u_long ift_od; /* output drops */ u_long ift_co; /* collisions */ u_long ift_ib; /* input bytes */ u_long ift_ob; /* output bytes */ }; /* * Obtain stats for interface(s). */ static void fill_iftot(struct iftot *st) { struct ifaddrs *ifap, *ifa; bool found = false; if (getifaddrs(&ifap) != 0) err(EX_OSERR, "getifaddrs"); bzero(st, sizeof(*st)); for (ifa = ifap; ifa; ifa = ifa->ifa_next) { if (ifa->ifa_addr->sa_family != AF_LINK) continue; if (interface) { if (strcmp(ifa->ifa_name, interface) == 0) found = true; else continue; } st->ift_ip += IFA_STAT(ipackets); st->ift_ie += IFA_STAT(ierrors); st->ift_id += IFA_STAT(iqdrops); st->ift_ib += IFA_STAT(ibytes); st->ift_op += IFA_STAT(opackets); st->ift_oe += IFA_STAT(oerrors); st->ift_od += IFA_STAT(oqdrops); st->ift_ob += IFA_STAT(obytes); st->ift_co += IFA_STAT(collisions); } if (interface && found == false) err(EX_DATAERR, "interface %s not found", interface); freeifaddrs(ifap); } /* * Set a flag to indicate that a signal from the periodic itimer has been * caught. */ static sig_atomic_t signalled; static void catchalarm(int signo __unused) { signalled = true; } /* * Print a running summary of interface statistics. * Repeat display every interval seconds, showing statistics * collected over that interval. Assumes that interval is non-zero. * First line printed at top of screen is always cumulative. */ static void sidewaysintpr(int interval) { struct iftot ift[2], *new, *old; struct itimerval interval_it; int oldmask, line; new = &ift[0]; old = &ift[1]; fill_iftot(old); (void)signal(SIGALRM, catchalarm); signalled = false; interval_it.it_interval.tv_sec = interval; interval_it.it_interval.tv_usec = 0; interval_it.it_value = interval_it.it_interval; setitimer(ITIMER_REAL, &interval_it, NULL); banner: printf("%17s %14s %16s", "input", interface != NULL ? interface : "(Total)", "output"); putchar('\n'); printf("%10s %5s %5s %10s %10s %5s %10s %5s", "packets", "errs", "idrops", "bytes", "packets", "errs", "bytes", "colls"); if (dflag) printf(" %5.5s", "drops"); putchar('\n'); fflush(stdout); line = 0; loop: if ((noutputs != 0) && (--noutputs == 0)) exit(0); oldmask = sigblock(sigmask(SIGALRM)); while (!signalled) sigpause(0); signalled = false; sigsetmask(oldmask); line++; fill_iftot(new); show_stat("lu", 10, new->ift_ip - old->ift_ip, 1, 1); show_stat("lu", 5, new->ift_ie - old->ift_ie, 1, 1); show_stat("lu", 5, new->ift_id - old->ift_id, 1, 1); show_stat("lu", 10, new->ift_ib - old->ift_ib, 1, 0); show_stat("lu", 10, new->ift_op - old->ift_op, 1, 1); show_stat("lu", 5, new->ift_oe - old->ift_oe, 1, 1); show_stat("lu", 10, new->ift_ob - old->ift_ob, 1, 0); show_stat("NRSlu", 5, new->ift_co - old->ift_co, 1, 1); if (dflag) show_stat("LSlu", 5, new->ift_od - old->ift_od, 1, 1); putchar('\n'); fflush(stdout); if (new == &ift[0]) { new = &ift[1]; old = &ift[0]; } else { new = &ift[0]; old = &ift[1]; } if (line == 21) goto banner; else goto loop; /* NOTREACHED */ } Index: stable/10/usr.bin/netstat/inet.c =================================================================== --- stable/10/usr.bin/netstat/inet.c (revision 293306) +++ stable/10/usr.bin/netstat/inet.c (revision 293307) @@ -1,1334 +1,1238 @@ /*- * Copyright (c) 1983, 1988, 1993, 1995 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if 0 #ifndef lint static char sccsid[] = "@(#)inet.c 8.5 (Berkeley) 5/24/95"; #endif /* not lint */ #endif #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef INET6 #include #endif /* INET6 */ #include #include #include #include #include #include #include #include #include #define TCPSTATES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "netstat.h" char *inetname(struct in_addr *); void inetprint(struct in_addr *, int, const char *, int); #ifdef INET6 static int udp_done, tcp_done, sdp_done; #endif /* INET6 */ static int pcblist_sysctl(int proto, const char *name, char **bufp, int istcp __unused) { const char *mibvar; char *buf; size_t len; switch (proto) { case IPPROTO_TCP: mibvar = "net.inet.tcp.pcblist"; break; case IPPROTO_UDP: mibvar = "net.inet.udp.pcblist"; break; case IPPROTO_DIVERT: mibvar = "net.inet.divert.pcblist"; break; default: mibvar = "net.inet.raw.pcblist"; break; } if (strncmp(name, "sdp", 3) == 0) mibvar = "net.inet.sdp.pcblist"; len = 0; if (sysctlbyname(mibvar, 0, &len, 0, 0) < 0) { if (errno != ENOENT) warn("sysctl: %s", mibvar); return (0); } if ((buf = malloc(len)) == 0) { warnx("malloc %lu bytes", (u_long)len); return (0); } if (sysctlbyname(mibvar, buf, &len, 0, 0) < 0) { warn("sysctl: %s", mibvar); free(buf); return (0); } *bufp = buf; return (1); } /* * Copied directly from uipc_socket2.c. We leave out some fields that are in * nested structures that aren't used to avoid extra work. */ static void sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb) { xsb->sb_cc = sb->sb_cc; xsb->sb_hiwat = sb->sb_hiwat; xsb->sb_mbcnt = sb->sb_mbcnt; xsb->sb_mcnt = sb->sb_mcnt; xsb->sb_ccnt = sb->sb_ccnt; xsb->sb_mbmax = sb->sb_mbmax; xsb->sb_lowat = sb->sb_lowat; xsb->sb_flags = sb->sb_flags; xsb->sb_timeo = sb->sb_timeo; } int sotoxsocket(struct socket *so, struct xsocket *xso) { struct protosw proto; struct domain domain; bzero(xso, sizeof *xso); xso->xso_len = sizeof *xso; xso->xso_so = so; xso->so_type = so->so_type; xso->so_options = so->so_options; xso->so_linger = so->so_linger; xso->so_state = so->so_state; xso->so_pcb = so->so_pcb; if (kread((uintptr_t)so->so_proto, &proto, sizeof(proto)) != 0) return (-1); xso->xso_protocol = proto.pr_protocol; if (kread((uintptr_t)proto.pr_domain, &domain, sizeof(domain)) != 0) return (-1); xso->xso_family = domain.dom_family; xso->so_qlen = so->so_qlen; xso->so_incqlen = so->so_incqlen; xso->so_qlimit = so->so_qlimit; xso->so_timeo = so->so_timeo; xso->so_error = so->so_error; xso->so_oobmark = so->so_oobmark; sbtoxsockbuf(&so->so_snd, &xso->so_snd); sbtoxsockbuf(&so->so_rcv, &xso->so_rcv); return (0); } static int pcblist_kvm(u_long off, char **bufp, int istcp) { struct inpcbinfo pcbinfo; struct inpcbhead listhead; struct inpcb *inp; struct xinpcb xi; struct xinpgen xig; struct xtcpcb xt; struct socket so; struct xsocket *xso; char *buf, *p; size_t len; if (off == 0) return (0); kread(off, &pcbinfo, sizeof(pcbinfo)); if (istcp) len = 2 * sizeof(xig) + (pcbinfo.ipi_count + pcbinfo.ipi_count / 8) * sizeof(struct xtcpcb); else len = 2 * sizeof(xig) + (pcbinfo.ipi_count + pcbinfo.ipi_count / 8) * sizeof(struct xinpcb); if ((buf = malloc(len)) == 0) { warnx("malloc %lu bytes", (u_long)len); return (0); } p = buf; #define COPYOUT(obj, size) do { \ if (len < (size)) { \ warnx("buffer size exceeded"); \ goto fail; \ } \ bcopy((obj), p, (size)); \ len -= (size); \ p += (size); \ } while (0) #define KREAD(off, buf, len) do { \ if (kread((uintptr_t)(off), (buf), (len)) != 0) \ goto fail; \ } while (0) /* Write out header. */ xig.xig_len = sizeof xig; xig.xig_count = pcbinfo.ipi_count; xig.xig_gen = pcbinfo.ipi_gencnt; xig.xig_sogen = 0; COPYOUT(&xig, sizeof xig); /* Walk the PCB list. */ xt.xt_len = sizeof xt; xi.xi_len = sizeof xi; if (istcp) xso = &xt.xt_socket; else xso = &xi.xi_socket; KREAD(pcbinfo.ipi_listhead, &listhead, sizeof(listhead)); LIST_FOREACH(inp, &listhead, inp_list) { if (istcp) { KREAD(inp, &xt.xt_inp, sizeof(*inp)); inp = &xt.xt_inp; } else { KREAD(inp, &xi.xi_inp, sizeof(*inp)); inp = &xi.xi_inp; } if (inp->inp_gencnt > pcbinfo.ipi_gencnt) continue; if (istcp) { if (inp->inp_ppcb == NULL) bzero(&xt.xt_tp, sizeof xt.xt_tp); else if (inp->inp_flags & INP_TIMEWAIT) { bzero(&xt.xt_tp, sizeof xt.xt_tp); xt.xt_tp.t_state = TCPS_TIME_WAIT; } else KREAD(inp->inp_ppcb, &xt.xt_tp, sizeof xt.xt_tp); } if (inp->inp_socket) { KREAD(inp->inp_socket, &so, sizeof(so)); if (sotoxsocket(&so, xso) != 0) goto fail; } else { bzero(xso, sizeof(*xso)); if (istcp) xso->xso_protocol = IPPROTO_TCP; } if (istcp) COPYOUT(&xt, sizeof xt); else COPYOUT(&xi, sizeof xi); } /* Reread the pcbinfo and write out the footer. */ kread(off, &pcbinfo, sizeof(pcbinfo)); xig.xig_count = pcbinfo.ipi_count; xig.xig_gen = pcbinfo.ipi_gencnt; COPYOUT(&xig, sizeof xig); *bufp = buf; return (1); fail: free(buf); return (0); #undef COPYOUT #undef KREAD } /* * Print a summary of connections related to an Internet * protocol. For TCP, also give state of connection. * Listening processes (aflag) are suppressed unless the * -a (all) flag is specified. */ void protopr(u_long off, const char *name, int af1, int proto) { int istcp; static int first = 1; char *buf; const char *vchar; struct tcpcb *tp = NULL; struct inpcb *inp; struct xinpgen *xig, *oxig; struct xsocket *so; struct xtcp_timer *timer; istcp = 0; switch (proto) { case IPPROTO_TCP: #ifdef INET6 if (strncmp(name, "sdp", 3) != 0) { if (tcp_done != 0) return; else tcp_done = 1; } else { if (sdp_done != 0) return; else sdp_done = 1; } #endif istcp = 1; break; case IPPROTO_UDP: #ifdef INET6 if (udp_done != 0) return; else udp_done = 1; #endif break; } if (live) { if (!pcblist_sysctl(proto, name, &buf, istcp)) return; } else { if (!pcblist_kvm(off, &buf, istcp)) return; } oxig = xig = (struct xinpgen *)buf; for (xig = (struct xinpgen *)((char *)xig + xig->xig_len); xig->xig_len > sizeof(struct xinpgen); xig = (struct xinpgen *)((char *)xig + xig->xig_len)) { if (istcp) { timer = &((struct xtcpcb *)xig)->xt_timer; tp = &((struct xtcpcb *)xig)->xt_tp; inp = &((struct xtcpcb *)xig)->xt_inp; so = &((struct xtcpcb *)xig)->xt_socket; } else { inp = &((struct xinpcb *)xig)->xi_inp; so = &((struct xinpcb *)xig)->xi_socket; timer = NULL; } /* Ignore sockets for protocols other than the desired one. */ if (so->xso_protocol != proto) continue; /* Ignore PCBs which were freed during copyout. */ if (inp->inp_gencnt > oxig->xig_gen) continue; if ((af1 == AF_INET && (inp->inp_vflag & INP_IPV4) == 0) #ifdef INET6 || (af1 == AF_INET6 && (inp->inp_vflag & INP_IPV6) == 0) #endif /* INET6 */ || (af1 == AF_UNSPEC && ((inp->inp_vflag & INP_IPV4) == 0 #ifdef INET6 && (inp->inp_vflag & INP_IPV6) == 0 #endif /* INET6 */ )) ) continue; if (!aflag && ( (istcp && tp->t_state == TCPS_LISTEN) || (af1 == AF_INET && inet_lnaof(inp->inp_laddr) == INADDR_ANY) #ifdef INET6 || (af1 == AF_INET6 && IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)) #endif /* INET6 */ || (af1 == AF_UNSPEC && (((inp->inp_vflag & INP_IPV4) != 0 && inet_lnaof(inp->inp_laddr) == INADDR_ANY) #ifdef INET6 || ((inp->inp_vflag & INP_IPV6) != 0 && IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)) #endif )) )) continue; if (first) { if (!Lflag) { printf("Active Internet connections"); if (aflag) printf(" (including servers)"); } else printf( "Current listen queue sizes (qlen/incqlen/maxqlen)"); putchar('\n'); if (Aflag) printf("%-*s ", 2 * (int)sizeof(void *), "Tcpcb"); if (Lflag) printf((Aflag && !Wflag) ? "%-5.5s %-14.14s %-18.18s" : "%-5.5s %-14.14s %-22.22s", "Proto", "Listen", "Local Address"); else if (Tflag) printf((Aflag && !Wflag) ? "%-5.5s %-6.6s %-6.6s %-6.6s %-18.18s %s" : "%-5.5s %-6.6s %-6.6s %-6.6s %-22.22s %s", "Proto", "Rexmit", "OOORcv", "0-win", "Local Address", "Foreign Address"); else { printf((Aflag && !Wflag) ? "%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s" : "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s", "Proto", "Recv-Q", "Send-Q", "Local Address", "Foreign Address"); if (!xflag && !Rflag) printf(" (state)"); } if (xflag) { printf(" %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s", "R-MBUF", "S-MBUF", "R-CLUS", "S-CLUS", "R-HIWA", "S-HIWA", "R-LOWA", "S-LOWA", "R-BCNT", "S-BCNT", "R-BMAX", "S-BMAX"); printf(" %7.7s %7.7s %7.7s %7.7s %7.7s %7.7s", "rexmt", "persist", "keep", "2msl", "delack", "rcvtime"); } else if (Rflag) { printf (" %8.8s %5.5s", "flowid", "ftype"); } putchar('\n'); first = 0; } if (Lflag && so->so_qlimit == 0) continue; if (Aflag) { if (istcp) printf("%*lx ", 2 * (int)sizeof(void *), (u_long)inp->inp_ppcb); else printf("%*lx ", 2 * (int)sizeof(void *), (u_long)so->so_pcb); } #ifdef INET6 if ((inp->inp_vflag & INP_IPV6) != 0) vchar = ((inp->inp_vflag & INP_IPV4) != 0) ? "46" : "6 "; else #endif vchar = ((inp->inp_vflag & INP_IPV4) != 0) ? "4 " : " "; if (istcp && (tp->t_flags & TF_TOE) != 0) printf("%-3.3s%-2.2s ", "toe", vchar); else printf("%-3.3s%-2.2s ", name, vchar); if (Lflag) { char buf1[15]; snprintf(buf1, 15, "%d/%d/%d", so->so_qlen, so->so_incqlen, so->so_qlimit); printf("%-14.14s ", buf1); } else if (Tflag) { if (istcp) printf("%6u %6u %6u ", tp->t_sndrexmitpack, tp->t_rcvoopack, tp->t_sndzerowin); } else { printf("%6u %6u ", so->so_rcv.sb_cc, so->so_snd.sb_cc); } if (numeric_port) { if (inp->inp_vflag & INP_IPV4) { inetprint(&inp->inp_laddr, (int)inp->inp_lport, name, 1); if (!Lflag) inetprint(&inp->inp_faddr, (int)inp->inp_fport, name, 1); } #ifdef INET6 else if (inp->inp_vflag & INP_IPV6) { inet6print(&inp->in6p_laddr, (int)inp->inp_lport, name, 1); if (!Lflag) inet6print(&inp->in6p_faddr, (int)inp->inp_fport, name, 1); } /* else nothing printed now */ #endif /* INET6 */ } else if (inp->inp_flags & INP_ANONPORT) { if (inp->inp_vflag & INP_IPV4) { inetprint(&inp->inp_laddr, (int)inp->inp_lport, name, 1); if (!Lflag) inetprint(&inp->inp_faddr, (int)inp->inp_fport, name, 0); } #ifdef INET6 else if (inp->inp_vflag & INP_IPV6) { inet6print(&inp->in6p_laddr, (int)inp->inp_lport, name, 1); if (!Lflag) inet6print(&inp->in6p_faddr, (int)inp->inp_fport, name, 0); } /* else nothing printed now */ #endif /* INET6 */ } else { if (inp->inp_vflag & INP_IPV4) { inetprint(&inp->inp_laddr, (int)inp->inp_lport, name, 0); if (!Lflag) inetprint(&inp->inp_faddr, (int)inp->inp_fport, name, inp->inp_lport != inp->inp_fport); } #ifdef INET6 else if (inp->inp_vflag & INP_IPV6) { inet6print(&inp->in6p_laddr, (int)inp->inp_lport, name, 0); if (!Lflag) inet6print(&inp->in6p_faddr, (int)inp->inp_fport, name, inp->inp_lport != inp->inp_fport); } /* else nothing printed now */ #endif /* INET6 */ } if (xflag) { printf("%6u %6u %6u %6u %6u %6u %6u %6u %6u %6u %6u %6u", so->so_rcv.sb_mcnt, so->so_snd.sb_mcnt, so->so_rcv.sb_ccnt, so->so_snd.sb_ccnt, so->so_rcv.sb_hiwat, so->so_snd.sb_hiwat, so->so_rcv.sb_lowat, so->so_snd.sb_lowat, so->so_rcv.sb_mbcnt, so->so_snd.sb_mbcnt, so->so_rcv.sb_mbmax, so->so_snd.sb_mbmax); if (timer != NULL) printf(" %4d.%02d %4d.%02d %4d.%02d %4d.%02d %4d.%02d %4d.%02d", timer->tt_rexmt / 1000, (timer->tt_rexmt % 1000) / 10, timer->tt_persist / 1000, (timer->tt_persist % 1000) / 10, timer->tt_keep / 1000, (timer->tt_keep % 1000) / 10, timer->tt_2msl / 1000, (timer->tt_2msl % 1000) / 10, timer->tt_delack / 1000, (timer->tt_delack % 1000) / 10, timer->t_rcvtime / 1000, (timer->t_rcvtime % 1000) / 10); } if (istcp && !Lflag && !xflag && !Tflag && !Rflag) { if (tp->t_state < 0 || tp->t_state >= TCP_NSTATES) printf("%d", tp->t_state); else { printf("%s", tcpstates[tp->t_state]); #if defined(TF_NEEDSYN) && defined(TF_NEEDFIN) /* Show T/TCP `hidden state' */ if (tp->t_flags & (TF_NEEDSYN|TF_NEEDFIN)) putchar('*'); #endif /* defined(TF_NEEDSYN) && defined(TF_NEEDFIN) */ } } if (Rflag) { printf(" %08x %5d", inp->inp_flowid, inp->inp_flowtype); } putchar('\n'); } if (xig != oxig && xig->xig_gen != oxig->xig_gen) { if (oxig->xig_count > xig->xig_count) { printf("Some %s sockets may have been deleted.\n", name); } else if (oxig->xig_count < xig->xig_count) { printf("Some %s sockets may have been created.\n", name); } else { printf( "Some %s sockets may have been created or deleted.\n", name); } } free(buf); } /* * Dump TCP statistics structure. */ void tcp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { - struct tcpstat tcpstat, zerostat; - size_t len = sizeof tcpstat; + struct tcpstat tcpstat; #ifdef INET6 if (tcp_done != 0) return; else tcp_done = 1; #endif - if (live) { - if (zflag) - memset(&zerostat, 0, len); - if (sysctlbyname("net.inet.tcp.stats", &tcpstat, &len, - zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { - warn("sysctl: net.inet.tcp.stats"); - return; - } - } else - kread_counters(off, &tcpstat, len); + if (fetch_stats("net.inet.tcp.stats", off, &tcpstat, + sizeof(tcpstat), kread_counters) != 0) + return; printf ("%s:\n", name); #define p(f, m) if (tcpstat.f || sflag <= 1) \ printf(m, (uintmax_t )tcpstat.f, plural(tcpstat.f)) #define p1a(f, m) if (tcpstat.f || sflag <= 1) \ printf(m, (uintmax_t )tcpstat.f) #define p2(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) \ printf(m, (uintmax_t )tcpstat.f1, plural(tcpstat.f1), \ (uintmax_t )tcpstat.f2, plural(tcpstat.f2)) #define p2a(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) \ printf(m, (uintmax_t )tcpstat.f1, plural(tcpstat.f1), \ (uintmax_t )tcpstat.f2) #define p3(f, m) if (tcpstat.f || sflag <= 1) \ printf(m, (uintmax_t )tcpstat.f, pluralies(tcpstat.f)) p(tcps_sndtotal, "\t%ju packet%s sent\n"); p2(tcps_sndpack,tcps_sndbyte, "\t\t%ju data packet%s (%ju byte%s)\n"); p2(tcps_sndrexmitpack, tcps_sndrexmitbyte, "\t\t%ju data packet%s (%ju byte%s) retransmitted\n"); p(tcps_sndrexmitbad, "\t\t%ju data packet%s unnecessarily retransmitted\n"); p(tcps_mturesent, "\t\t%ju resend%s initiated by MTU discovery\n"); p2a(tcps_sndacks, tcps_delack, "\t\t%ju ack-only packet%s (%ju delayed)\n"); p(tcps_sndurg, "\t\t%ju URG only packet%s\n"); p(tcps_sndprobe, "\t\t%ju window probe packet%s\n"); p(tcps_sndwinup, "\t\t%ju window update packet%s\n"); p(tcps_sndctrl, "\t\t%ju control packet%s\n"); p(tcps_rcvtotal, "\t%ju packet%s received\n"); p2(tcps_rcvackpack, tcps_rcvackbyte, "\t\t%ju ack%s (for %ju byte%s)\n"); p(tcps_rcvdupack, "\t\t%ju duplicate ack%s\n"); p(tcps_rcvacktoomuch, "\t\t%ju ack%s for unsent data\n"); p2(tcps_rcvpack, tcps_rcvbyte, "\t\t%ju packet%s (%ju byte%s) received in-sequence\n"); p2(tcps_rcvduppack, tcps_rcvdupbyte, "\t\t%ju completely duplicate packet%s (%ju byte%s)\n"); p(tcps_pawsdrop, "\t\t%ju old duplicate packet%s\n"); p2(tcps_rcvpartduppack, tcps_rcvpartdupbyte, "\t\t%ju packet%s with some dup. data (%ju byte%s duped)\n"); p2(tcps_rcvoopack, tcps_rcvoobyte, "\t\t%ju out-of-order packet%s (%ju byte%s)\n"); p2(tcps_rcvpackafterwin, tcps_rcvbyteafterwin, "\t\t%ju packet%s (%ju byte%s) of data after window\n"); p(tcps_rcvwinprobe, "\t\t%ju window probe%s\n"); p(tcps_rcvwinupd, "\t\t%ju window update packet%s\n"); p(tcps_rcvafterclose, "\t\t%ju packet%s received after close\n"); p(tcps_rcvbadsum, "\t\t%ju discarded for bad checksum%s\n"); p(tcps_rcvbadoff, "\t\t%ju discarded for bad header offset field%s\n"); p1a(tcps_rcvshort, "\t\t%ju discarded because packet too short\n"); p1a(tcps_rcvmemdrop, "\t\t%ju discarded due to memory problems\n"); p(tcps_connattempt, "\t%ju connection request%s\n"); p(tcps_accepts, "\t%ju connection accept%s\n"); p(tcps_badsyn, "\t%ju bad connection attempt%s\n"); p(tcps_listendrop, "\t%ju listen queue overflow%s\n"); p(tcps_badrst, "\t%ju ignored RSTs in the window%s\n"); p(tcps_connects, "\t%ju connection%s established (including accepts)\n"); p2(tcps_closed, tcps_drops, "\t%ju connection%s closed (including %ju drop%s)\n"); p(tcps_cachedrtt, "\t\t%ju connection%s updated cached RTT on close\n"); p(tcps_cachedrttvar, "\t\t%ju connection%s updated cached RTT variance on close\n"); p(tcps_cachedssthresh, "\t\t%ju connection%s updated cached ssthresh on close\n"); p(tcps_conndrops, "\t%ju embryonic connection%s dropped\n"); p2(tcps_rttupdated, tcps_segstimed, "\t%ju segment%s updated rtt (of %ju attempt%s)\n"); p(tcps_rexmttimeo, "\t%ju retransmit timeout%s\n"); p(tcps_timeoutdrop, "\t\t%ju connection%s dropped by rexmit timeout\n"); p(tcps_persisttimeo, "\t%ju persist timeout%s\n"); p(tcps_persistdrop, "\t\t%ju connection%s dropped by persist timeout\n"); p(tcps_finwait2_drops, "\t%ju Connection%s (fin_wait_2) dropped because of timeout\n"); p(tcps_keeptimeo, "\t%ju keepalive timeout%s\n"); p(tcps_keepprobe, "\t\t%ju keepalive probe%s sent\n"); p(tcps_keepdrops, "\t\t%ju connection%s dropped by keepalive\n"); p(tcps_predack, "\t%ju correct ACK header prediction%s\n"); p(tcps_preddat, "\t%ju correct data packet header prediction%s\n"); p3(tcps_sc_added, "\t%ju syncache entr%s added\n"); p1a(tcps_sc_retransmitted, "\t\t%ju retransmitted\n"); p1a(tcps_sc_dupsyn, "\t\t%ju dupsyn\n"); p1a(tcps_sc_dropped, "\t\t%ju dropped\n"); p1a(tcps_sc_completed, "\t\t%ju completed\n"); p1a(tcps_sc_bucketoverflow, "\t\t%ju bucket overflow\n"); p1a(tcps_sc_cacheoverflow, "\t\t%ju cache overflow\n"); p1a(tcps_sc_reset, "\t\t%ju reset\n"); p1a(tcps_sc_stale, "\t\t%ju stale\n"); p1a(tcps_sc_aborted, "\t\t%ju aborted\n"); p1a(tcps_sc_badack, "\t\t%ju badack\n"); p1a(tcps_sc_unreach, "\t\t%ju unreach\n"); p(tcps_sc_zonefail, "\t\t%ju zone failure%s\n"); p(tcps_sc_sendcookie, "\t%ju cookie%s sent\n"); p(tcps_sc_recvcookie, "\t%ju cookie%s received\n"); p3(tcps_hc_added, "\t%ju hostcache entr%s added\n"); p1a(tcps_hc_bucketoverflow, "\t\t%ju bucket overflow\n"); p(tcps_sack_recovery_episode, "\t%ju SACK recovery episode%s\n"); p(tcps_sack_rexmits, "\t%ju segment rexmit%s in SACK recovery episodes\n"); p(tcps_sack_rexmit_bytes, "\t%ju byte rexmit%s in SACK recovery episodes\n"); p(tcps_sack_rcv_blocks, "\t%ju SACK option%s (SACK blocks) received\n"); p(tcps_sack_send_blocks, "\t%ju SACK option%s (SACK blocks) sent\n"); p1a(tcps_sack_sboverflow, "\t%ju SACK scoreboard overflow\n"); p(tcps_ecn_ce, "\t%ju packet%s with ECN CE bit set\n"); p(tcps_ecn_ect0, "\t%ju packet%s with ECN ECT(0) bit set\n"); p(tcps_ecn_ect1, "\t%ju packet%s with ECN ECT(1) bit set\n"); p(tcps_ecn_shs, "\t%ju successful ECN handshake%s\n"); p(tcps_ecn_rcwnd, "\t%ju time%s ECN reduced the congestion window\n"); p(tcps_sig_rcvgoodsig, "\t%ju packet%s with valid tcp-md5 signature received\n"); p(tcps_sig_rcvbadsig, "\t%ju packet%s with invalid tcp-md5 signature received\n"); p(tcps_sig_err_buildsig, "\t%ju packet%s with tcp-md5 signature mismatch\n"); p(tcps_sig_err_sigopt, "\t%ju packet%s with unexpected tcp-md5 signature received\n"); p(tcps_sig_err_nosigopt, "\t%ju packet%s without expected tcp-md5 signature received\n"); #undef p #undef p1a #undef p2 #undef p2a #undef p3 } /* * Dump UDP statistics structure. */ void udp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { - struct udpstat udpstat, zerostat; - size_t len = sizeof udpstat; + struct udpstat udpstat; uint64_t delivered; #ifdef INET6 if (udp_done != 0) return; else udp_done = 1; #endif - if (live) { - if (zflag) - memset(&zerostat, 0, len); - if (sysctlbyname("net.inet.udp.stats", &udpstat, &len, - zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { - warn("sysctl: net.inet.udp.stats"); - return; - } - } else - kread_counters(off, &udpstat, len); + if (fetch_stats("net.inet.udp.stats", off, &udpstat, + sizeof(udpstat), kread_counters) != 0) + return; printf("%s:\n", name); #define p(f, m) if (udpstat.f || sflag <= 1) \ printf("\t%ju " m, (uintmax_t)udpstat.f, plural(udpstat.f)) #define p1a(f, m) if (udpstat.f || sflag <= 1) \ printf("\t%ju " m, (uintmax_t)udpstat.f) p(udps_ipackets, "datagram%s received\n"); p1a(udps_hdrops, "with incomplete header\n"); p1a(udps_badlen, "with bad data length field\n"); p1a(udps_badsum, "with bad checksum\n"); p1a(udps_nosum, "with no checksum\n"); p1a(udps_noport, "dropped due to no socket\n"); p(udps_noportbcast, "broadcast/multicast datagram%s undelivered\n"); p1a(udps_fullsock, "dropped due to full socket buffers\n"); p1a(udpps_pcbhashmiss, "not for hashed pcb\n"); delivered = udpstat.udps_ipackets - udpstat.udps_hdrops - udpstat.udps_badlen - udpstat.udps_badsum - udpstat.udps_noport - udpstat.udps_noportbcast - udpstat.udps_fullsock; if (delivered || sflag <= 1) printf("\t%ju delivered\n", (uint64_t)delivered); p(udps_opackets, "datagram%s output\n"); /* the next statistic is cumulative in udps_noportbcast */ p(udps_filtermcast, "time%s multicast source filter matched\n"); #undef p #undef p1a } /* * Dump CARP statistics structure. */ void carp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { - struct carpstats carpstat, zerostat; - size_t len = sizeof(struct carpstats); + struct carpstats carpstat; - if (live) { - if (zflag) - memset(&zerostat, 0, len); - if (sysctlbyname("net.inet.carp.stats", &carpstat, &len, - zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { - if (errno != ENOENT) - warn("sysctl: net.inet.carp.stats"); - return; - } - } else { - if (off == 0) - return; - kread_counters(off, &carpstat, len); - } + if (fetch_stats("net.inet.carp.stats", off, &carpstat, + sizeof(carpstat), kread_counters) != 0) + return; printf("%s:\n", name); #define p(f, m) if (carpstat.f || sflag <= 1) \ printf(m, (uintmax_t)carpstat.f, plural(carpstat.f)) #define p2(f, m) if (carpstat.f || sflag <= 1) \ printf(m, (uintmax_t)carpstat.f) p(carps_ipackets, "\t%ju packet%s received (IPv4)\n"); p(carps_ipackets6, "\t%ju packet%s received (IPv6)\n"); p(carps_badttl, "\t\t%ju packet%s discarded for wrong TTL\n"); p(carps_hdrops, "\t\t%ju packet%s shorter than header\n"); p(carps_badsum, "\t\t%ju discarded for bad checksum%s\n"); p(carps_badver, "\t\t%ju discarded packet%s with a bad version\n"); p2(carps_badlen, "\t\t%ju discarded because packet too short\n"); p2(carps_badauth, "\t\t%ju discarded for bad authentication\n"); p2(carps_badvhid, "\t\t%ju discarded for bad vhid\n"); p2(carps_badaddrs, "\t\t%ju discarded because of a bad address list\n"); p(carps_opackets, "\t%ju packet%s sent (IPv4)\n"); p(carps_opackets6, "\t%ju packet%s sent (IPv6)\n"); p2(carps_onomem, "\t\t%ju send failed due to mbuf memory error\n"); #if notyet p(carps_ostates, "\t\t%s state update%s sent\n"); #endif #undef p #undef p2 } /* * Dump IP statistics structure. */ void ip_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { - struct ipstat ipstat, zerostat; - size_t len = sizeof ipstat; + struct ipstat ipstat; - if (live) { - if (zflag) - memset(&zerostat, 0, len); - if (sysctlbyname("net.inet.ip.stats", &ipstat, &len, - zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { - warn("sysctl: net.inet.ip.stats"); - return; - } - } else - kread_counters(off, &ipstat, len); + if (fetch_stats("net.inet.ip.stats", off, &ipstat, + sizeof(ipstat), kread_counters) != 0) + return; printf("%s:\n", name); #define p(f, m) if (ipstat.f || sflag <= 1) \ printf(m, (uintmax_t )ipstat.f, plural(ipstat.f)) #define p1a(f, m) if (ipstat.f || sflag <= 1) \ printf(m, (uintmax_t )ipstat.f) p(ips_total, "\t%ju total packet%s received\n"); p(ips_badsum, "\t%ju bad header checksum%s\n"); p1a(ips_toosmall, "\t%ju with size smaller than minimum\n"); p1a(ips_tooshort, "\t%ju with data size < data length\n"); p1a(ips_toolong, "\t%ju with ip length > max ip packet size\n"); p1a(ips_badhlen, "\t%ju with header length < data size\n"); p1a(ips_badlen, "\t%ju with data length < header length\n"); p1a(ips_badoptions, "\t%ju with bad options\n"); p1a(ips_badvers, "\t%ju with incorrect version number\n"); p(ips_fragments, "\t%ju fragment%s received\n"); p(ips_fragdropped, "\t%ju fragment%s dropped (dup or out of space)\n"); p(ips_fragtimeout, "\t%ju fragment%s dropped after timeout\n"); p(ips_reassembled, "\t%ju packet%s reassembled ok\n"); p(ips_delivered, "\t%ju packet%s for this host\n"); p(ips_noproto, "\t%ju packet%s for unknown/unsupported protocol\n"); p(ips_forward, "\t%ju packet%s forwarded"); p(ips_fastforward, " (%ju packet%s fast forwarded)"); if (ipstat.ips_forward || sflag <= 1) putchar('\n'); p(ips_cantforward, "\t%ju packet%s not forwardable\n"); p(ips_notmember, "\t%ju packet%s received for unknown multicast group\n"); p(ips_redirectsent, "\t%ju redirect%s sent\n"); p(ips_localout, "\t%ju packet%s sent from this host\n"); p(ips_rawout, "\t%ju packet%s sent with fabricated ip header\n"); p(ips_odropped, "\t%ju output packet%s dropped due to no bufs, etc.\n"); p(ips_noroute, "\t%ju output packet%s discarded due to no route\n"); p(ips_fragmented, "\t%ju output datagram%s fragmented\n"); p(ips_ofragments, "\t%ju fragment%s created\n"); p(ips_cantfrag, "\t%ju datagram%s that can't be fragmented\n"); p(ips_nogif, "\t%ju tunneling packet%s that can't find gif\n"); p(ips_badaddr, "\t%ju datagram%s with bad address in header\n"); #undef p #undef p1a } /* * Dump ARP statistics structure. */ void arp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { - struct arpstat arpstat, zerostat; - size_t len = sizeof(arpstat); + struct arpstat arpstat; - if (live) { - if (zflag) - memset(&zerostat, 0, len); - if (sysctlbyname("net.link.ether.arp.stats", &arpstat, &len, - zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { - warn("sysctl: net.link.ether.arp.stats"); - return; - } - } else - kread_counters(off, &arpstat, len); + if (fetch_stats("net.link.ether.arp.stats", off, &arpstat, + sizeof(arpstat), kread_counters) != 0) + return; printf("%s:\n", name); #define p(f, m) if (arpstat.f || sflag <= 1) \ printf("\t%ju " m, (uintmax_t)arpstat.f, plural(arpstat.f)) #define p2(f, m) if (arpstat.f || sflag <= 1) \ printf("\t%ju " m, (uintmax_t)arpstat.f, pluralies(arpstat.f)) p(txrequests, "ARP request%s sent\n"); p2(txreplies, "ARP repl%s sent\n"); p(rxrequests, "ARP request%s received\n"); p2(rxreplies, "ARP repl%s received\n"); p(received, "ARP packet%s received\n"); p(dropped, "total packet%s dropped due to no ARP entry\n"); p(timeouts, "ARP entry%s timed out\n"); p(dupips, "Duplicate IP%s seen\n"); #undef p #undef p2 } static const char *icmpnames[ICMP_MAXTYPE + 1] = { "echo reply", /* RFC 792 */ "#1", "#2", "destination unreachable", /* RFC 792 */ "source quench", /* RFC 792 */ "routing redirect", /* RFC 792 */ "#6", "#7", "echo", /* RFC 792 */ "router advertisement", /* RFC 1256 */ "router solicitation", /* RFC 1256 */ "time exceeded", /* RFC 792 */ "parameter problem", /* RFC 792 */ "time stamp", /* RFC 792 */ "time stamp reply", /* RFC 792 */ "information request", /* RFC 792 */ "information request reply", /* RFC 792 */ "address mask request", /* RFC 950 */ "address mask reply", /* RFC 950 */ "#19", "#20", "#21", "#22", "#23", "#24", "#25", "#26", "#27", "#28", "#29", "icmp traceroute", /* RFC 1393 */ "datagram conversion error", /* RFC 1475 */ "mobile host redirect", "IPv6 where-are-you", "IPv6 i-am-here", "mobile registration req", "mobile registration reply", "domain name request", /* RFC 1788 */ "domain name reply", /* RFC 1788 */ "icmp SKIP", "icmp photuris", /* RFC 2521 */ }; /* * Dump ICMP statistics. */ void icmp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { - struct icmpstat icmpstat, zerostat; - int i, first; + struct icmpstat icmpstat; size_t len; + int i, first; - len = sizeof icmpstat; - if (live) { - if (zflag) - memset(&zerostat, 0, len); - if (sysctlbyname("net.inet.icmp.stats", &icmpstat, &len, - zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { - warn("sysctl: net.inet.icmp.stats"); - return; - } - } else - kread_counters(off, &icmpstat, len); + if (fetch_stats("net.inet.icmp.stats", off, &icmpstat, + sizeof(icmpstat), kread_counters) != 0) + return; printf("%s:\n", name); #define p(f, m) if (icmpstat.f || sflag <= 1) \ printf(m, icmpstat.f, plural(icmpstat.f)) #define p1a(f, m) if (icmpstat.f || sflag <= 1) \ printf(m, icmpstat.f) #define p2(f, m) if (icmpstat.f || sflag <= 1) \ printf(m, icmpstat.f, plurales(icmpstat.f)) p(icps_error, "\t%lu call%s to icmp_error\n"); p(icps_oldicmp, "\t%lu error%s not generated in response to an icmp message\n"); for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++) if (icmpstat.icps_outhist[i] != 0) { if (first) { printf("\tOutput histogram:\n"); first = 0; } if (icmpnames[i] != NULL) printf("\t\t%s: %lu\n", icmpnames[i], icmpstat.icps_outhist[i]); else printf("\t\tunknown ICMP #%d: %lu\n", i, icmpstat.icps_outhist[i]); } p(icps_badcode, "\t%lu message%s with bad code fields\n"); p(icps_tooshort, "\t%lu message%s less than the minimum length\n"); p(icps_checksum, "\t%lu message%s with bad checksum\n"); p(icps_badlen, "\t%lu message%s with bad length\n"); p1a(icps_bmcastecho, "\t%lu multicast echo requests ignored\n"); p1a(icps_bmcasttstamp, "\t%lu multicast timestamp requests ignored\n"); for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++) if (icmpstat.icps_inhist[i] != 0) { if (first) { printf("\tInput histogram:\n"); first = 0; } if (icmpnames[i] != NULL) printf("\t\t%s: %lu\n", icmpnames[i], icmpstat.icps_inhist[i]); else printf("\t\tunknown ICMP #%d: %lu\n", i, icmpstat.icps_inhist[i]); } p(icps_reflect, "\t%lu message response%s generated\n"); p2(icps_badaddr, "\t%lu invalid return address%s\n"); p(icps_noroute, "\t%lu no return route%s\n"); #undef p #undef p1a #undef p2 if (live) { len = sizeof i; if (sysctlbyname("net.inet.icmp.maskrepl", &i, &len, NULL, 0) < 0) return; printf("\tICMP address mask responses are %sabled\n", i ? "en" : "dis"); } } #ifndef BURN_BRIDGES /* * Dump IGMP statistics structure (pre 8.x kernel). */ static void igmp_stats_live_old(const char *name) { struct oigmpstat oigmpstat, zerostat; size_t len = sizeof(oigmpstat); if (zflag) memset(&zerostat, 0, len); if (sysctlbyname("net.inet.igmp.stats", &oigmpstat, &len, zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { warn("sysctl: net.inet.igmp.stats"); return; } printf("%s:\n", name); #define p(f, m) if (oigmpstat.f || sflag <= 1) \ printf(m, oigmpstat.f, plural(oigmpstat.f)) #define py(f, m) if (oigmpstat.f || sflag <= 1) \ printf(m, oigmpstat.f, oigmpstat.f != 1 ? "ies" : "y") p(igps_rcv_total, "\t%u message%s received\n"); p(igps_rcv_tooshort, "\t%u message%s received with too few bytes\n"); p(igps_rcv_badsum, "\t%u message%s received with bad checksum\n"); py(igps_rcv_queries, "\t%u membership quer%s received\n"); py(igps_rcv_badqueries, "\t%u membership quer%s received with invalid field(s)\n"); p(igps_rcv_reports, "\t%u membership report%s received\n"); p(igps_rcv_badreports, "\t%u membership report%s received with invalid field(s)\n"); p(igps_rcv_ourreports, "\t%u membership report%s received for groups to which we belong\n"); p(igps_snd_reports, "\t%u membership report%s sent\n"); #undef p #undef py } #endif /* !BURN_BRIDGES */ /* * Dump IGMP statistics structure. */ void igmp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { - struct igmpstat igmpstat, zerostat; - size_t len; + struct igmpstat igmpstat; -#ifndef BURN_BRIDGES - if (live) { - /* - * Detect if we are being run against a pre-IGMPv3 kernel. - * We cannot do this for a core file as the legacy - * struct igmpstat has no size field, nor does it - * export it in any readily-available symbols. - */ - len = 0; - if (sysctlbyname("net.inet.igmp.stats", NULL, &len, NULL, - 0) < 0) { - warn("sysctl: net.inet.igmp.stats"); - return; - } - if (len < sizeof(igmpstat)) { - igmp_stats_live_old(name); - return; - } - } -#endif /* !BURN_BRIDGES */ + if (fetch_stats("net.inet.igmp.stats", 0, &igmpstat, + sizeof(igmpstat), kread) != 0) + return; - len = sizeof(igmpstat); - if (live) { - if (zflag) - memset(&zerostat, 0, len); - if (sysctlbyname("net.inet.igmp.stats", &igmpstat, &len, - zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { - warn("sysctl: net.inet.igmp.stats"); - return; - } - } else { - len = sizeof(igmpstat); - kread(off, &igmpstat, len); - } - if (igmpstat.igps_version != IGPS_VERSION_3) { warnx("%s: version mismatch (%d != %d)", __func__, igmpstat.igps_version, IGPS_VERSION_3); } if (igmpstat.igps_len != IGPS_VERSION3_LEN) { warnx("%s: size mismatch (%d != %d)", __func__, igmpstat.igps_len, IGPS_VERSION3_LEN); } printf("%s:\n", name); #define p64(f, m) if (igmpstat.f || sflag <= 1) \ printf(m, (uintmax_t) igmpstat.f, plural(igmpstat.f)) #define py64(f, m) if (igmpstat.f || sflag <= 1) \ printf(m, (uintmax_t) igmpstat.f, pluralies(igmpstat.f)) p64(igps_rcv_total, "\t%ju message%s received\n"); p64(igps_rcv_tooshort, "\t%ju message%s received with too few bytes\n"); p64(igps_rcv_badttl, "\t%ju message%s received with wrong TTL\n"); p64(igps_rcv_badsum, "\t%ju message%s received with bad checksum\n"); py64(igps_rcv_v1v2_queries, "\t%ju V1/V2 membership quer%s received\n"); py64(igps_rcv_v3_queries, "\t%ju V3 membership quer%s received\n"); py64(igps_rcv_badqueries, "\t%ju membership quer%s received with invalid field(s)\n"); py64(igps_rcv_gen_queries, "\t%ju general quer%s received\n"); py64(igps_rcv_group_queries, "\t%ju group quer%s received\n"); py64(igps_rcv_gsr_queries, "\t%ju group-source quer%s received\n"); py64(igps_drop_gsr_queries, "\t%ju group-source quer%s dropped\n"); p64(igps_rcv_reports, "\t%ju membership report%s received\n"); p64(igps_rcv_badreports, "\t%ju membership report%s received with invalid field(s)\n"); p64(igps_rcv_ourreports, "\t%ju membership report%s received for groups to which we belong\n"); p64(igps_rcv_nora, "\t%ju V3 report%s received without Router Alert\n"); p64(igps_snd_reports, "\t%ju membership report%s sent\n"); #undef p64 #undef py64 } /* * Dump PIM statistics structure. */ void pim_stats(u_long off __unused, const char *name, int af1 __unused, int proto __unused) { - struct pimstat pimstat, zerostat; - size_t len = sizeof pimstat; + struct pimstat pimstat; - if (live) { - if (zflag) - memset(&zerostat, 0, len); - if (sysctlbyname("net.inet.pim.stats", &pimstat, &len, - zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { - if (errno != ENOENT) - warn("sysctl: net.inet.pim.stats"); - return; - } - } else { - if (off == 0) - return; - kread_counters(off, &pimstat, len); - } + if (fetch_stats("net.inet.pim.stats", off, &pimstat, + sizeof(pimstat), kread_counters) != 0) + return; printf("%s:\n", name); #define p(f, m) if (pimstat.f || sflag <= 1) \ printf(m, (uintmax_t)pimstat.f, plural(pimstat.f)) #define py(f, m) if (pimstat.f || sflag <= 1) \ printf(m, (uintmax_t)pimstat.f, pimstat.f != 1 ? "ies" : "y") p(pims_rcv_total_msgs, "\t%ju message%s received\n"); p(pims_rcv_total_bytes, "\t%ju byte%s received\n"); p(pims_rcv_tooshort, "\t%ju message%s received with too few bytes\n"); p(pims_rcv_badsum, "\t%ju message%s received with bad checksum\n"); p(pims_rcv_badversion, "\t%ju message%s received with bad version\n"); p(pims_rcv_registers_msgs, "\t%ju data register message%s received\n"); p(pims_rcv_registers_bytes, "\t%ju data register byte%s received\n"); p(pims_rcv_registers_wrongiif, "\t%ju data register message%s received on wrong iif\n"); p(pims_rcv_badregisters, "\t%ju bad register%s received\n"); p(pims_snd_registers_msgs, "\t%ju data register message%s sent\n"); p(pims_snd_registers_bytes, "\t%ju data register byte%s sent\n"); #undef p #undef py } /* * Pretty print an Internet address (net address + port). */ void inetprint(struct in_addr *in, int port, const char *proto, int num_port) { struct servent *sp = 0; char line[80], *cp; int width; if (Wflag) sprintf(line, "%s.", inetname(in)); else sprintf(line, "%.*s.", (Aflag && !num_port) ? 12 : 16, inetname(in)); cp = strchr(line, '\0'); if (!num_port && port) sp = getservbyport((int)port, proto); if (sp || port == 0) sprintf(cp, "%.15s ", sp ? sp->s_name : "*"); else sprintf(cp, "%d ", ntohs((u_short)port)); width = (Aflag && !Wflag) ? 18 : 22; if (Wflag) printf("%-*s ", width, line); else printf("%-*.*s ", width, width, line); } /* * Construct an Internet address representation. * If numeric_addr has been supplied, give * numeric value, otherwise try for symbolic name. */ char * inetname(struct in_addr *inp) { char *cp; static char line[MAXHOSTNAMELEN]; struct hostent *hp; struct netent *np; cp = 0; if (!numeric_addr && inp->s_addr != INADDR_ANY) { int net = inet_netof(*inp); int lna = inet_lnaof(*inp); if (lna == INADDR_ANY) { np = getnetbyaddr(net, AF_INET); if (np) cp = np->n_name; } if (cp == 0) { hp = gethostbyaddr((char *)inp, sizeof (*inp), AF_INET); if (hp) { cp = hp->h_name; trimdomain(cp, strlen(cp)); } } } if (inp->s_addr == INADDR_ANY) strcpy(line, "*"); else if (cp) { strlcpy(line, cp, sizeof(line)); } else { inp->s_addr = ntohl(inp->s_addr); #define C(x) ((u_int)((x) & 0xff)) sprintf(line, "%u.%u.%u.%u", C(inp->s_addr >> 24), C(inp->s_addr >> 16), C(inp->s_addr >> 8), C(inp->s_addr)); } return (line); } Index: stable/10/usr.bin/netstat/inet6.c =================================================================== --- stable/10/usr.bin/netstat/inet6.c (revision 293306) +++ stable/10/usr.bin/netstat/inet6.c (revision 293307) @@ -1,1164 +1,1119 @@ /* BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp */ /*- * Copyright (c) 1983, 1988, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if 0 #ifndef lint static char sccsid[] = "@(#)inet6.c 8.4 (Berkeley) 4/20/94"; #endif /* not lint */ #endif #include __FBSDID("$FreeBSD$"); #ifdef INET6 #include #include #include #include #include #include -#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "netstat.h" struct socket sockb; char *inet6name(struct in6_addr *); static char ntop_buf[INET6_ADDRSTRLEN]; static const char *ip6nh[] = { "hop by hop", "ICMP", "IGMP", "#3", "IP", "#5", "TCP", "#7", "#8", "#9", "#10", "#11", "#12", "#13", "#14", "#15", "#16", "UDP", "#18", "#19", "#20", "#21", "IDP", "#23", "#24", "#25", "#26", "#27", "#28", "TP", "#30", "#31", "#32", "#33", "#34", "#35", "#36", "#37", "#38", "#39", "#40", "IP6", "#42", "routing", "fragment", "#45", "#46", "#47", "#48", "#49", "ESP", "AH", "#52", "#53", "#54", "#55", "#56", "#57", "ICMP6", "no next header", "destination option", "#61", "mobility", "#63", "#64", "#65", "#66", "#67", "#68", "#69", "#70", "#71", "#72", "#73", "#74", "#75", "#76", "#77", "#78", "#79", "ISOIP", "#81", "#82", "#83", "#84", "#85", "#86", "#87", "#88", "OSPF", "#80", "#91", "#92", "#93", "#94", "#95", "#96", "Ethernet", "#98", "#99", "#100", "#101", "#102", "PIM", "#104", "#105", "#106", "#107", "#108", "#109", "#110", "#111", "#112", "#113", "#114", "#115", "#116", "#117", "#118", "#119", "#120", "#121", "#122", "#123", "#124", "#125", "#126", "#127", "#128", "#129", "#130", "#131", "#132", "#133", "#134", "#135", "#136", "#137", "#138", "#139", "#140", "#141", "#142", "#143", "#144", "#145", "#146", "#147", "#148", "#149", "#150", "#151", "#152", "#153", "#154", "#155", "#156", "#157", "#158", "#159", "#160", "#161", "#162", "#163", "#164", "#165", "#166", "#167", "#168", "#169", "#170", "#171", "#172", "#173", "#174", "#175", "#176", "#177", "#178", "#179", "#180", "#181", "#182", "#183", "#184", "#185", "#186", "#187", "#188", "#189", "#180", "#191", "#192", "#193", "#194", "#195", "#196", "#197", "#198", "#199", "#200", "#201", "#202", "#203", "#204", "#205", "#206", "#207", "#208", "#209", "#210", "#211", "#212", "#213", "#214", "#215", "#216", "#217", "#218", "#219", "#220", "#221", "#222", "#223", "#224", "#225", "#226", "#227", "#228", "#229", "#230", "#231", "#232", "#233", "#234", "#235", "#236", "#237", "#238", "#239", "#240", "#241", "#242", "#243", "#244", "#245", "#246", "#247", "#248", "#249", "#250", "#251", "#252", "#253", "#254", "#255", }; static const char *srcrule_str[] = { "first candidate", "same address", "appropriate scope", "deprecated address", "home address", "outgoing interface", "matching label", "public/temporary address", "alive interface", "better virtual status", "preferred source", "rule #11", "rule #12", "rule #13", "longest match", "rule #15", }; /* * Dump IP6 statistics structure. */ void ip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { - struct ip6stat ip6stat, zerostat; + struct ip6stat ip6stat; int first, i; - size_t len; - len = sizeof ip6stat; - if (live) { - memset(&ip6stat, 0, len); - if (zflag) - memset(&zerostat, 0, len); - if (sysctlbyname("net.inet6.ip6.stats", &ip6stat, &len, - zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { - if (errno != ENOENT) - warn("sysctl: net.inet6.ip6.stats"); - return; - } - } else - kread_counters(off, &ip6stat, len); + if (fetch_stats("net.inet6.ip6.stats", off, &ip6stat, + sizeof(ip6stat), kread_counters) != 0) + return; printf("%s:\n", name); #define p(f, m) if (ip6stat.f || sflag <= 1) \ printf(m, (uintmax_t)ip6stat.f, plural(ip6stat.f)) #define p1a(f, m) if (ip6stat.f || sflag <= 1) \ printf(m, (uintmax_t)ip6stat.f) p(ip6s_total, "\t%ju total packet%s received\n"); p1a(ip6s_toosmall, "\t%ju with size smaller than minimum\n"); p1a(ip6s_tooshort, "\t%ju with data size < data length\n"); p1a(ip6s_badoptions, "\t%ju with bad options\n"); p1a(ip6s_badvers, "\t%ju with incorrect version number\n"); p(ip6s_fragments, "\t%ju fragment%s received\n"); p(ip6s_fragdropped, "\t%ju fragment%s dropped (dup or out of space)\n"); p(ip6s_fragtimeout, "\t%ju fragment%s dropped after timeout\n"); p(ip6s_fragoverflow, "\t%ju fragment%s that exceeded limit\n"); p(ip6s_reassembled, "\t%ju packet%s reassembled ok\n"); p(ip6s_delivered, "\t%ju packet%s for this host\n"); p(ip6s_forward, "\t%ju packet%s forwarded\n"); p(ip6s_cantforward, "\t%ju packet%s not forwardable\n"); p(ip6s_redirectsent, "\t%ju redirect%s sent\n"); p(ip6s_localout, "\t%ju packet%s sent from this host\n"); p(ip6s_rawout, "\t%ju packet%s sent with fabricated ip header\n"); p(ip6s_odropped, "\t%ju output packet%s dropped due to no bufs, etc.\n"); p(ip6s_noroute, "\t%ju output packet%s discarded due to no route\n"); p(ip6s_fragmented, "\t%ju output datagram%s fragmented\n"); p(ip6s_ofragments, "\t%ju fragment%s created\n"); p(ip6s_cantfrag, "\t%ju datagram%s that can't be fragmented\n"); p(ip6s_badscope, "\t%ju packet%s that violated scope rules\n"); p(ip6s_notmember, "\t%ju multicast packet%s which we don't join\n"); for (first = 1, i = 0; i < IP6S_HDRCNT; i++) if (ip6stat.ip6s_nxthist[i] != 0) { if (first) { printf("\tInput histogram:\n"); first = 0; } printf("\t\t%s: %ju\n", ip6nh[i], (uintmax_t)ip6stat.ip6s_nxthist[i]); } printf("\tMbuf statistics:\n"); printf("\t\t%ju one mbuf\n", (uintmax_t)ip6stat.ip6s_m1); for (first = 1, i = 0; i < IP6S_M2MMAX; i++) { char ifbuf[IFNAMSIZ]; if (ip6stat.ip6s_m2m[i] != 0) { if (first) { printf("\t\ttwo or more mbuf:\n"); first = 0; } printf("\t\t\t%s= %ju\n", if_indextoname(i, ifbuf), (uintmax_t)ip6stat.ip6s_m2m[i]); } } printf("\t\t%ju one ext mbuf\n", (uintmax_t)ip6stat.ip6s_mext1); printf("\t\t%ju two or more ext mbuf\n", (uintmax_t)ip6stat.ip6s_mext2m); p(ip6s_exthdrtoolong, "\t%ju packet%s whose headers are not contiguous\n"); p(ip6s_nogif, "\t%ju tunneling packet%s that can't find gif\n"); p(ip6s_toomanyhdr, "\t%ju packet%s discarded because of too many headers\n"); /* for debugging source address selection */ #define PRINT_SCOPESTAT(s,i) do {\ switch(i) { /* XXX hardcoding in each case */\ case 1:\ p(s, "\t\t%ju interface-local%s\n");\ break;\ case 2:\ p(s,"\t\t%ju link-local%s\n");\ break;\ case 5:\ p(s,"\t\t%ju site-local%s\n");\ break;\ case 14:\ p(s,"\t\t%ju global%s\n");\ break;\ default:\ printf("\t\t%ju addresses scope=%x\n",\ (uintmax_t)ip6stat.s, i);\ }\ } while (0); p(ip6s_sources_none, "\t%ju failure%s of source address selection\n"); for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) { if (ip6stat.ip6s_sources_sameif[i]) { if (first) { printf("\tsource addresses on an outgoing I/F\n"); first = 0; } PRINT_SCOPESTAT(ip6s_sources_sameif[i], i); } } for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) { if (ip6stat.ip6s_sources_otherif[i]) { if (first) { printf("\tsource addresses on a non-outgoing I/F\n"); first = 0; } PRINT_SCOPESTAT(ip6s_sources_otherif[i], i); } } for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) { if (ip6stat.ip6s_sources_samescope[i]) { if (first) { printf("\tsource addresses of same scope\n"); first = 0; } PRINT_SCOPESTAT(ip6s_sources_samescope[i], i); } } for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) { if (ip6stat.ip6s_sources_otherscope[i]) { if (first) { printf("\tsource addresses of a different scope\n"); first = 0; } PRINT_SCOPESTAT(ip6s_sources_otherscope[i], i); } } for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) { if (ip6stat.ip6s_sources_deprecated[i]) { if (first) { printf("\tdeprecated source addresses\n"); first = 0; } PRINT_SCOPESTAT(ip6s_sources_deprecated[i], i); } } printf("\tSource addresses selection rule applied:\n"); for (i = 0; i < IP6S_RULESMAX; i++) { if (ip6stat.ip6s_sources_rule[i]) printf("\t\t%ju %s\n", (uintmax_t)ip6stat.ip6s_sources_rule[i], srcrule_str[i]); } #undef p #undef p1a } /* * Dump IPv6 per-interface statistics based on RFC 2465. */ void ip6_ifstats(char *ifname) { struct in6_ifreq ifr; int s; #define p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \ printf(m, (uintmax_t)ifr.ifr_ifru.ifru_stat.f, plural(ifr.ifr_ifru.ifru_stat.f)) #define p_5(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \ printf(m, (uintmax_t)ip6stat.f) if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { perror("Warning: socket(AF_INET6)"); return; } strcpy(ifr.ifr_name, ifname); if (ioctl(s, SIOCGIFSTAT_IN6, (char *)&ifr) < 0) { if (errno != EPFNOSUPPORT) perror("Warning: ioctl(SIOCGIFSTAT_IN6)"); goto end; } printf("ip6 on %s:\n", ifr.ifr_name); p(ifs6_in_receive, "\t%ju total input datagram%s\n"); p(ifs6_in_hdrerr, "\t%ju datagram%s with invalid header received\n"); p(ifs6_in_toobig, "\t%ju datagram%s exceeded MTU received\n"); p(ifs6_in_noroute, "\t%ju datagram%s with no route received\n"); p(ifs6_in_addrerr, "\t%ju datagram%s with invalid dst received\n"); p(ifs6_in_protounknown, "\t%ju datagram%s with unknown proto received\n"); p(ifs6_in_truncated, "\t%ju truncated datagram%s received\n"); p(ifs6_in_discard, "\t%ju input datagram%s discarded\n"); p(ifs6_in_deliver, "\t%ju datagram%s delivered to an upper layer protocol\n"); p(ifs6_out_forward, "\t%ju datagram%s forwarded to this interface\n"); p(ifs6_out_request, "\t%ju datagram%s sent from an upper layer protocol\n"); p(ifs6_out_discard, "\t%ju total discarded output datagram%s\n"); p(ifs6_out_fragok, "\t%ju output datagram%s fragmented\n"); p(ifs6_out_fragfail, "\t%ju output datagram%s failed on fragment\n"); p(ifs6_out_fragcreat, "\t%ju output datagram%s succeeded on fragment\n"); p(ifs6_reass_reqd, "\t%ju incoming datagram%s fragmented\n"); p(ifs6_reass_ok, "\t%ju datagram%s reassembled\n"); p(ifs6_reass_fail, "\t%ju datagram%s failed on reassembly\n"); p(ifs6_in_mcast, "\t%ju multicast datagram%s received\n"); p(ifs6_out_mcast, "\t%ju multicast datagram%s sent\n"); end: close(s); #undef p #undef p_5 } static const char *icmp6names[] = { "#0", "unreach", "packet too big", "time exceed", "parameter problem", "#5", "#6", "#7", "#8", "#9", "#10", "#11", "#12", "#13", "#14", "#15", "#16", "#17", "#18", "#19", "#20", "#21", "#22", "#23", "#24", "#25", "#26", "#27", "#28", "#29", "#30", "#31", "#32", "#33", "#34", "#35", "#36", "#37", "#38", "#39", "#40", "#41", "#42", "#43", "#44", "#45", "#46", "#47", "#48", "#49", "#50", "#51", "#52", "#53", "#54", "#55", "#56", "#57", "#58", "#59", "#60", "#61", "#62", "#63", "#64", "#65", "#66", "#67", "#68", "#69", "#70", "#71", "#72", "#73", "#74", "#75", "#76", "#77", "#78", "#79", "#80", "#81", "#82", "#83", "#84", "#85", "#86", "#87", "#88", "#89", "#80", "#91", "#92", "#93", "#94", "#95", "#96", "#97", "#98", "#99", "#100", "#101", "#102", "#103", "#104", "#105", "#106", "#107", "#108", "#109", "#110", "#111", "#112", "#113", "#114", "#115", "#116", "#117", "#118", "#119", "#120", "#121", "#122", "#123", "#124", "#125", "#126", "#127", "echo", "echo reply", "multicast listener query", "MLDv1 listener report", "MLDv1 listener done", "router solicitation", "router advertisement", "neighbor solicitation", "neighbor advertisement", "redirect", "router renumbering", "node information request", "node information reply", "inverse neighbor solicitation", "inverse neighbor advertisement", "MLDv2 listener report", "#144", "#145", "#146", "#147", "#148", "#149", "#150", "#151", "#152", "#153", "#154", "#155", "#156", "#157", "#158", "#159", "#160", "#161", "#162", "#163", "#164", "#165", "#166", "#167", "#168", "#169", "#170", "#171", "#172", "#173", "#174", "#175", "#176", "#177", "#178", "#179", "#180", "#181", "#182", "#183", "#184", "#185", "#186", "#187", "#188", "#189", "#180", "#191", "#192", "#193", "#194", "#195", "#196", "#197", "#198", "#199", "#200", "#201", "#202", "#203", "#204", "#205", "#206", "#207", "#208", "#209", "#210", "#211", "#212", "#213", "#214", "#215", "#216", "#217", "#218", "#219", "#220", "#221", "#222", "#223", "#224", "#225", "#226", "#227", "#228", "#229", "#230", "#231", "#232", "#233", "#234", "#235", "#236", "#237", "#238", "#239", "#240", "#241", "#242", "#243", "#244", "#245", "#246", "#247", "#248", "#249", "#250", "#251", "#252", "#253", "#254", "#255", }; /* * Dump ICMP6 statistics. */ void icmp6_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { - struct icmp6stat icmp6stat, zerostat; + struct icmp6stat icmp6stat; int i, first; - size_t len; - len = sizeof icmp6stat; - if (live) { - memset(&icmp6stat, 0, len); - if (zflag) - memset(&zerostat, 0, len); - if (sysctlbyname("net.inet6.icmp6.stats", &icmp6stat, &len, - zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { - if (errno != ENOENT) - warn("sysctl: net.inet6.icmp6.stats"); - return; - } - } else - kread_counters(off, &icmp6stat, len); + if (fetch_stats("net.inet6.icmp6.stats", off, &icmp6stat, + sizeof(icmp6stat), kread_counters) != 0) + return; printf("%s:\n", name); #define p(f, m) if (icmp6stat.f || sflag <= 1) \ printf(m, (uintmax_t)icmp6stat.f, plural(icmp6stat.f)) #define p_5(f, m) if (icmp6stat.f || sflag <= 1) \ printf(m, (uintmax_t)icmp6stat.f) p(icp6s_error, "\t%ju call%s to icmp6_error\n"); p(icp6s_canterror, "\t%ju error%s not generated in response to an icmp6 message\n"); p(icp6s_toofreq, "\t%ju error%s not generated because of rate limitation\n"); #define NELEM (int)(sizeof(icmp6stat.icp6s_outhist)/sizeof(icmp6stat.icp6s_outhist[0])) for (first = 1, i = 0; i < NELEM; i++) if (icmp6stat.icp6s_outhist[i] != 0) { if (first) { printf("\tOutput histogram:\n"); first = 0; } printf("\t\t%s: %ju\n", icmp6names[i], (uintmax_t)icmp6stat.icp6s_outhist[i]); } #undef NELEM p(icp6s_badcode, "\t%ju message%s with bad code fields\n"); p(icp6s_tooshort, "\t%ju message%s < minimum length\n"); p(icp6s_checksum, "\t%ju bad checksum%s\n"); p(icp6s_badlen, "\t%ju message%s with bad length\n"); #define NELEM (int)(sizeof(icmp6stat.icp6s_inhist)/sizeof(icmp6stat.icp6s_inhist[0])) for (first = 1, i = 0; i < NELEM; i++) if (icmp6stat.icp6s_inhist[i] != 0) { if (first) { printf("\tInput histogram:\n"); first = 0; } printf("\t\t%s: %ju\n", icmp6names[i], (uintmax_t)icmp6stat.icp6s_inhist[i]); } #undef NELEM printf("\tHistogram of error messages to be generated:\n"); p_5(icp6s_odst_unreach_noroute, "\t\t%ju no route\n"); p_5(icp6s_odst_unreach_admin, "\t\t%ju administratively prohibited\n"); p_5(icp6s_odst_unreach_beyondscope, "\t\t%ju beyond scope\n"); p_5(icp6s_odst_unreach_addr, "\t\t%ju address unreachable\n"); p_5(icp6s_odst_unreach_noport, "\t\t%ju port unreachable\n"); p_5(icp6s_opacket_too_big, "\t\t%ju packet too big\n"); p_5(icp6s_otime_exceed_transit, "\t\t%ju time exceed transit\n"); p_5(icp6s_otime_exceed_reassembly, "\t\t%ju time exceed reassembly\n"); p_5(icp6s_oparamprob_header, "\t\t%ju erroneous header field\n"); p_5(icp6s_oparamprob_nextheader, "\t\t%ju unrecognized next header\n"); p_5(icp6s_oparamprob_option, "\t\t%ju unrecognized option\n"); p_5(icp6s_oredirect, "\t\t%ju redirect\n"); p_5(icp6s_ounknown, "\t\t%ju unknown\n"); p(icp6s_reflect, "\t%ju message response%s generated\n"); p(icp6s_nd_toomanyopt, "\t%ju message%s with too many ND options\n"); p(icp6s_nd_badopt, "\t%ju message%s with bad ND options\n"); p(icp6s_badns, "\t%ju bad neighbor solicitation message%s\n"); p(icp6s_badna, "\t%ju bad neighbor advertisement message%s\n"); p(icp6s_badrs, "\t%ju bad router solicitation message%s\n"); p(icp6s_badra, "\t%ju bad router advertisement message%s\n"); p(icp6s_badredirect, "\t%ju bad redirect message%s\n"); p(icp6s_pmtuchg, "\t%ju path MTU change%s\n"); #undef p #undef p_5 } /* * Dump ICMPv6 per-interface statistics based on RFC 2466. */ void icmp6_ifstats(char *ifname) { struct in6_ifreq ifr; int s; #define p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \ printf(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f, plural(ifr.ifr_ifru.ifru_icmp6stat.f)) #define p2(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \ printf(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f, pluralies(ifr.ifr_ifru.ifru_icmp6stat.f)) if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { perror("Warning: socket(AF_INET6)"); return; } strcpy(ifr.ifr_name, ifname); if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) { if (errno != EPFNOSUPPORT) perror("Warning: ioctl(SIOCGIFSTAT_ICMP6)"); goto end; } printf("icmp6 on %s:\n", ifr.ifr_name); p(ifs6_in_msg, "\t%ju total input message%s\n"); p(ifs6_in_error, "\t%ju total input error message%s\n"); p(ifs6_in_dstunreach, "\t%ju input destination unreachable error%s\n"); p(ifs6_in_adminprohib, "\t%ju input administratively prohibited error%s\n"); p(ifs6_in_timeexceed, "\t%ju input time exceeded error%s\n"); p(ifs6_in_paramprob, "\t%ju input parameter problem error%s\n"); p(ifs6_in_pkttoobig, "\t%ju input packet too big error%s\n"); p(ifs6_in_echo, "\t%ju input echo request%s\n"); p2(ifs6_in_echoreply, "\t%ju input echo repl%s\n"); p(ifs6_in_routersolicit, "\t%ju input router solicitation%s\n"); p(ifs6_in_routeradvert, "\t%ju input router advertisement%s\n"); p(ifs6_in_neighborsolicit, "\t%ju input neighbor solicitation%s\n"); p(ifs6_in_neighboradvert, "\t%ju input neighbor advertisement%s\n"); p(ifs6_in_redirect, "\t%ju input redirect%s\n"); p2(ifs6_in_mldquery, "\t%ju input MLD quer%s\n"); p(ifs6_in_mldreport, "\t%ju input MLD report%s\n"); p(ifs6_in_mlddone, "\t%ju input MLD done%s\n"); p(ifs6_out_msg, "\t%ju total output message%s\n"); p(ifs6_out_error, "\t%ju total output error message%s\n"); p(ifs6_out_dstunreach, "\t%ju output destination unreachable error%s\n"); p(ifs6_out_adminprohib, "\t%ju output administratively prohibited error%s\n"); p(ifs6_out_timeexceed, "\t%ju output time exceeded error%s\n"); p(ifs6_out_paramprob, "\t%ju output parameter problem error%s\n"); p(ifs6_out_pkttoobig, "\t%ju output packet too big error%s\n"); p(ifs6_out_echo, "\t%ju output echo request%s\n"); p2(ifs6_out_echoreply, "\t%ju output echo repl%s\n"); p(ifs6_out_routersolicit, "\t%ju output router solicitation%s\n"); p(ifs6_out_routeradvert, "\t%ju output router advertisement%s\n"); p(ifs6_out_neighborsolicit, "\t%ju output neighbor solicitation%s\n"); p(ifs6_out_neighboradvert, "\t%ju output neighbor advertisement%s\n"); p(ifs6_out_redirect, "\t%ju output redirect%s\n"); p2(ifs6_out_mldquery, "\t%ju output MLD quer%s\n"); p(ifs6_out_mldreport, "\t%ju output MLD report%s\n"); p(ifs6_out_mlddone, "\t%ju output MLD done%s\n"); end: close(s); #undef p } /* * Dump PIM statistics structure. */ void pim6_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { - struct pim6stat pim6stat, zerostat; - size_t len = sizeof pim6stat; + struct pim6stat pim6stat; - if (live) { - if (zflag) - memset(&zerostat, 0, len); - if (sysctlbyname("net.inet6.pim.stats", &pim6stat, &len, - zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { - if (errno != ENOENT) - warn("sysctl: net.inet6.pim.stats"); - return; - } - } else { - if (off == 0) - return; - kread(off, &pim6stat, len); - } + if (fetch_stats("net.inet6.pim.stats", off, &pim6stat, + sizeof(pim6stat), kread) != 0) + return; printf("%s:\n", name); #define p(f, m) if (pim6stat.f || sflag <= 1) \ printf(m, (uintmax_t)pim6stat.f, plural(pim6stat.f)) p(pim6s_rcv_total, "\t%ju message%s received\n"); p(pim6s_rcv_tooshort, "\t%ju message%s received with too few bytes\n"); p(pim6s_rcv_badsum, "\t%ju message%s received with bad checksum\n"); p(pim6s_rcv_badversion, "\t%ju message%s received with bad version\n"); p(pim6s_rcv_registers, "\t%ju register%s received\n"); p(pim6s_rcv_badregisters, "\t%ju bad register%s received\n"); p(pim6s_snd_registers, "\t%ju register%s sent\n"); #undef p } /* * Dump raw ip6 statistics structure. */ void rip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { - struct rip6stat rip6stat, zerostat; + struct rip6stat rip6stat; u_quad_t delivered; - size_t len; - len = sizeof(rip6stat); - if (live) { - if (zflag) - memset(&zerostat, 0, len); - if (sysctlbyname("net.inet6.ip6.rip6stats", &rip6stat, &len, - zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { - if (errno != ENOENT) - warn("sysctl: net.inet6.ip6.rip6stats"); - return; - } - } else - kread_counters(off, &rip6stat, len); + if (fetch_stats("net.inet6.ip6.rip6stats", off, &rip6stat, + sizeof(rip6stat), kread_counters) != 0) + return; printf("%s:\n", name); #define p(f, m) if (rip6stat.f || sflag <= 1) \ printf(m, (uintmax_t)rip6stat.f, plural(rip6stat.f)) p(rip6s_ipackets, "\t%ju message%s received\n"); p(rip6s_isum, "\t%ju checksum calculation%s on inbound\n"); p(rip6s_badsum, "\t%ju message%s with bad checksum\n"); p(rip6s_nosock, "\t%ju message%s dropped due to no socket\n"); p(rip6s_nosockmcast, "\t%ju multicast message%s dropped due to no socket\n"); p(rip6s_fullsock, "\t%ju message%s dropped due to full socket buffers\n"); delivered = rip6stat.rip6s_ipackets - rip6stat.rip6s_badsum - rip6stat.rip6s_nosock - rip6stat.rip6s_nosockmcast - rip6stat.rip6s_fullsock; if (delivered || sflag <= 1) printf("\t%ju delivered\n", (uintmax_t)delivered); p(rip6s_opackets, "\t%ju datagram%s output\n"); #undef p } /* * Pretty print an Internet address (net address + port). * Take numeric_addr and numeric_port into consideration. */ #define GETSERVBYPORT6(port, proto, ret)\ {\ if (strcmp((proto), "tcp6") == 0)\ (ret) = getservbyport((int)(port), "tcp");\ else if (strcmp((proto), "udp6") == 0)\ (ret) = getservbyport((int)(port), "udp");\ else\ (ret) = getservbyport((int)(port), (proto));\ }; void inet6print(struct in6_addr *in6, int port, const char *proto, int numeric) { struct servent *sp = 0; char line[80], *cp; int width; sprintf(line, "%.*s.", Wflag ? 39 : (Aflag && !numeric) ? 12 : 16, inet6name(in6)); cp = strchr(line, '\0'); if (!numeric && port) GETSERVBYPORT6(port, proto, sp); if (sp || port == 0) sprintf(cp, "%.15s", sp ? sp->s_name : "*"); else sprintf(cp, "%d", ntohs((u_short)port)); width = Wflag ? 45 : Aflag ? 18 : 22; printf("%-*.*s ", width, width, line); } /* * Construct an Internet address representation. * If the numeric_addr has been supplied, give * numeric value, otherwise try for symbolic name. */ char * inet6name(struct in6_addr *in6p) { struct sockaddr_in6 sin6; char hbuf[NI_MAXHOST], *cp; static char line[50]; static char domain[MAXHOSTNAMELEN]; static int first = 1; int flags, error; if (IN6_IS_ADDR_UNSPECIFIED(in6p)) { strcpy(line, "*"); return (line); } if (first && !numeric_addr) { first = 0; if (gethostname(domain, MAXHOSTNAMELEN) == 0 && (cp = strchr(domain, '.'))) (void) strcpy(domain, cp + 1); else domain[0] = 0; } memset(&sin6, 0, sizeof(sin6)); memcpy(&sin6.sin6_addr, in6p, sizeof(*in6p)); sin6.sin6_family = AF_INET6; /* XXX: in6p.s6_addr[2] can contain scopeid. */ in6_fillscopeid(&sin6); flags = (numeric_addr) ? NI_NUMERICHOST : 0; error = getnameinfo((struct sockaddr *)&sin6, sizeof(sin6), hbuf, sizeof(hbuf), NULL, 0, flags); if (error == 0) { if ((flags & NI_NUMERICHOST) == 0 && (cp = strchr(hbuf, '.')) && !strcmp(cp + 1, domain)) *cp = 0; strcpy(line, hbuf); } else { /* XXX: this should not happen. */ sprintf(line, "%s", inet_ntop(AF_INET6, (void *)&sin6.sin6_addr, ntop_buf, sizeof(ntop_buf))); } return (line); } #endif /*INET6*/ Index: stable/10/usr.bin/netstat/main.c =================================================================== --- stable/10/usr.bin/netstat/main.c (revision 293306) +++ stable/10/usr.bin/netstat/main.c (revision 293307) @@ -1,900 +1,924 @@ /*- * Copyright (c) 1983, 1988, 1993 * Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint char const copyright[] = "@(#) Copyright (c) 1983, 1988, 1993\n\ Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #if 0 #ifndef lint static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 3/1/94"; #endif /* not lint */ #endif #include __FBSDID("$FreeBSD$"); #include #include #include #include #include +#include #include #ifdef NETGRAPH #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include "netstat.h" static struct nlist nl[] = { #define N_IFNET 0 { .n_name = "_ifnet" }, /* XXXGL: can be deleted */ #define N_RTSTAT 1 { .n_name = "_rtstat" }, #define N_RTREE 2 { .n_name = "_rt_tables"}, #define N_MRTSTAT 3 { .n_name = "_mrtstat" }, #define N_MFCHASHTBL 4 { .n_name = "_mfchashtbl" }, #define N_VIFTABLE 5 { .n_name = "_viftable" }, #define N_IPX 6 { .n_name = "_ipxpcb_list"}, #define N_IPXSTAT 7 { .n_name = "_ipxstat"}, #define N_SPXSTAT 8 { .n_name = "_spx_istat"}, #define N_DDPSTAT 9 { .n_name = "_ddpstat"}, #define N_DDPCB 10 { .n_name = "_ddpcb"}, #define N_NGSOCKS 11 { .n_name = "_ngsocklist"}, #define N_IP6STAT 12 { .n_name = "_ip6stat" }, #define N_ICMP6STAT 13 { .n_name = "_icmp6stat" }, #define N_IPSECSTAT 14 { .n_name = "_ipsec4stat" }, #define N_IPSEC6STAT 15 { .n_name = "_ipsec6stat" }, #define N_PIM6STAT 16 { .n_name = "_pim6stat" }, #define N_MRT6STAT 17 { .n_name = "_mrt6stat" }, #define N_MF6CTABLE 18 { .n_name = "_mf6ctable" }, #define N_MIF6TABLE 19 { .n_name = "_mif6table" }, #define N_PFKEYSTAT 20 { .n_name = "_pfkeystat" }, #define N_RTTRASH 21 { .n_name = "_rttrash" }, #define N_CARPSTAT 22 { .n_name = "_carpstats" }, #define N_PFSYNCSTAT 23 { .n_name = "_pfsyncstats" }, #define N_AHSTAT 24 { .n_name = "_ahstat" }, #define N_ESPSTAT 25 { .n_name = "_espstat" }, #define N_IPCOMPSTAT 26 { .n_name = "_ipcompstat" }, #define N_TCPSTAT 27 { .n_name = "_tcpstat" }, #define N_UDPSTAT 28 { .n_name = "_udpstat" }, #define N_IPSTAT 29 { .n_name = "_ipstat" }, #define N_ICMPSTAT 30 { .n_name = "_icmpstat" }, #define N_IGMPSTAT 31 { .n_name = "_igmpstat" }, #define N_PIMSTAT 32 { .n_name = "_pimstat" }, #define N_TCBINFO 33 { .n_name = "_tcbinfo" }, #define N_UDBINFO 34 { .n_name = "_udbinfo" }, #define N_DIVCBINFO 35 { .n_name = "_divcbinfo" }, #define N_RIPCBINFO 36 { .n_name = "_ripcbinfo" }, #define N_UNP_COUNT 37 { .n_name = "_unp_count" }, #define N_UNP_GENCNT 38 { .n_name = "_unp_gencnt" }, #define N_UNP_DHEAD 39 { .n_name = "_unp_dhead" }, #define N_UNP_SHEAD 40 { .n_name = "_unp_shead" }, #define N_RIP6STAT 41 { .n_name = "_rip6stat" }, #define N_SCTPSTAT 42 { .n_name = "_sctpstat" }, #define N_MFCTABLESIZE 43 { .n_name = "_mfctablesize" }, #define N_ARPSTAT 44 { .n_name = "_arpstat" }, #define N_UNP_SPHEAD 45 { .n_name = "unp_sphead" }, #define N_SFSTAT 46 { .n_name = "_sfstat"}, { .n_name = NULL }, }; struct protox { int pr_index; /* index into nlist of cb head */ int pr_sindex; /* index into nlist of stat block */ u_char pr_wanted; /* 1 if wanted, 0 otherwise */ void (*pr_cblocks)(u_long, const char *, int, int); /* control blocks printing routine */ void (*pr_stats)(u_long, const char *, int, int); /* statistics printing routine */ void (*pr_istats)(char *); /* per/if statistics printing routine */ const char *pr_name; /* well-known name */ int pr_usesysctl; /* non-zero if we use sysctl, not kvm */ int pr_protocol; } protox[] = { { N_TCBINFO, N_TCPSTAT, 1, protopr, tcp_stats, NULL, "tcp", 1, IPPROTO_TCP }, { N_UDBINFO, N_UDPSTAT, 1, protopr, udp_stats, NULL, "udp", 1, IPPROTO_UDP }, #ifdef SCTP { -1, N_SCTPSTAT, 1, sctp_protopr, sctp_stats, NULL, "sctp", 1, IPPROTO_SCTP }, #endif #ifdef SDP { -1, -1, 1, protopr, NULL, NULL, "sdp", 1, IPPROTO_TCP }, #endif { N_DIVCBINFO, -1, 1, protopr, NULL, NULL, "divert", 1, IPPROTO_DIVERT }, { N_RIPCBINFO, N_IPSTAT, 1, protopr, ip_stats, NULL, "ip", 1, IPPROTO_RAW }, { N_RIPCBINFO, N_ICMPSTAT, 1, protopr, icmp_stats, NULL, "icmp", 1, IPPROTO_ICMP }, { N_RIPCBINFO, N_IGMPSTAT, 1, protopr, igmp_stats, NULL, "igmp", 1, IPPROTO_IGMP }, #ifdef IPSEC { -1, N_IPSECSTAT, 1, NULL, /* keep as compat */ ipsec_stats, NULL, "ipsec", 0, 0}, { -1, N_AHSTAT, 1, NULL, ah_stats, NULL, "ah", 0, 0}, { -1, N_ESPSTAT, 1, NULL, esp_stats, NULL, "esp", 0, 0}, { -1, N_IPCOMPSTAT, 1, NULL, ipcomp_stats, NULL, "ipcomp", 0, 0}, #endif { N_RIPCBINFO, N_PIMSTAT, 1, protopr, pim_stats, NULL, "pim", 1, IPPROTO_PIM }, { -1, N_CARPSTAT, 1, NULL, carp_stats, NULL, "carp", 1, 0 }, #ifdef PF { -1, N_PFSYNCSTAT, 1, NULL, pfsync_stats, NULL, "pfsync", 1, 0 }, #endif { -1, N_ARPSTAT, 1, NULL, arp_stats, NULL, "arp", 1, 0 }, { -1, -1, 0, NULL, NULL, NULL, NULL, 0, 0 } }; #ifdef INET6 struct protox ip6protox[] = { { N_TCBINFO, N_TCPSTAT, 1, protopr, tcp_stats, NULL, "tcp", 1, IPPROTO_TCP }, { N_UDBINFO, N_UDPSTAT, 1, protopr, udp_stats, NULL, "udp", 1, IPPROTO_UDP }, { N_RIPCBINFO, N_IP6STAT, 1, protopr, ip6_stats, ip6_ifstats, "ip6", 1, IPPROTO_RAW }, { N_RIPCBINFO, N_ICMP6STAT, 1, protopr, icmp6_stats, icmp6_ifstats, "icmp6", 1, IPPROTO_ICMPV6 }, #ifdef SDP { -1, -1, 1, protopr, NULL, NULL, "sdp", 1, IPPROTO_TCP }, #endif #ifdef IPSEC { -1, N_IPSEC6STAT, 1, NULL, ipsec_stats, NULL, "ipsec6", 0, 0 }, #endif #ifdef notyet { -1, N_PIM6STAT, 1, NULL, pim6_stats, NULL, "pim6", 1, 0 }, #endif { -1, N_RIP6STAT, 1, NULL, rip6_stats, NULL, "rip6", 1, 0 }, { -1, -1, 0, NULL, NULL, NULL, NULL, 0, 0 } }; #endif /*INET6*/ #ifdef IPSEC struct protox pfkeyprotox[] = { { -1, N_PFKEYSTAT, 1, NULL, pfkey_stats, NULL, "pfkey", 0, 0 }, { -1, -1, 0, NULL, NULL, NULL, NULL, 0, 0 } }; #endif struct protox atalkprotox[] = { { N_DDPCB, N_DDPSTAT, 1, atalkprotopr, ddp_stats, NULL, "ddp", 0, 0 }, { -1, -1, 0, NULL, NULL, NULL, NULL, 0, 0 } }; #ifdef NETGRAPH struct protox netgraphprotox[] = { { N_NGSOCKS, -1, 1, netgraphprotopr, NULL, NULL, "ctrl", 0, 0 }, { N_NGSOCKS, -1, 1, netgraphprotopr, NULL, NULL, "data", 0, 0 }, { -1, -1, 0, NULL, NULL, NULL, NULL, 0, 0 } }; #endif #ifdef IPX struct protox ipxprotox[] = { { N_IPX, N_IPXSTAT, 1, ipxprotopr, ipx_stats, NULL, "ipx", 0, 0 }, { N_IPX, N_SPXSTAT, 1, ipxprotopr, spx_stats, NULL, "spx", 0, 0 }, { -1, -1, 0, NULL, NULL, NULL, 0, 0, 0 } }; #endif struct protox *protoprotox[] = { protox, #ifdef INET6 ip6protox, #endif #ifdef IPSEC pfkeyprotox, #endif #ifdef IPX ipxprotox, #endif atalkprotox, NULL }; static void printproto(struct protox *, const char *); static void usage(void); static struct protox *name2protox(const char *); static struct protox *knownname(const char *); static kvm_t *kvmd; static char *nlistf = NULL, *memf = NULL; int Aflag; /* show addresses of protocol control block */ int aflag; /* show all sockets (including servers) */ int Bflag; /* show information about bpf consumers */ int bflag; /* show i/f total bytes in/out */ int dflag; /* show i/f dropped packets */ int gflag; /* show group (multicast) routing or stats */ int hflag; /* show counters in human readable format */ int iflag; /* show interfaces */ int Lflag; /* show size of listen queues */ int mflag; /* show memory stats */ int noutputs = 0; /* how much outputs before we exit */ int numeric_addr; /* show addresses numerically */ int numeric_port; /* show ports numerically */ static int pflag; /* show given protocol */ int Qflag; /* show netisr information */ int rflag; /* show routing tables (or routing stats) */ int Rflag; /* show flow / RSS statistics */ int sflag; /* show protocol statistics */ int Wflag; /* wide display */ int Tflag; /* TCP Information */ int xflag; /* extra information, includes all socket buffer info */ int zflag; /* zero stats */ int interval; /* repeat interval for i/f stats */ char *interface; /* desired i/f for stats, or NULL for all i/fs */ int unit; /* unit number for above */ int af; /* address family */ int live; /* true if we are examining a live system */ int main(int argc, char *argv[]) { struct protox *tp = NULL; /* for printing cblocks & stats */ int ch; int fib = -1; char *endptr; af = AF_UNSPEC; while ((ch = getopt(argc, argv, "46AaBbdF:f:ghI:iLlM:mN:np:Qq:RrSTsuWw:xz")) != -1) switch(ch) { case '4': #ifdef INET af = AF_INET; #else errx(1, "IPv4 support is not compiled in"); #endif break; case '6': #ifdef INET6 af = AF_INET6; #else errx(1, "IPv6 support is not compiled in"); #endif break; case 'A': Aflag = 1; break; case 'a': aflag = 1; break; case 'B': Bflag = 1; break; case 'b': bflag = 1; break; case 'd': dflag = 1; break; case 'F': fib = strtol(optarg, &endptr, 0); if (*endptr != '\0' || (fib == 0 && (errno == EINVAL || errno == ERANGE))) errx(1, "%s: invalid fib", optarg); break; case 'f': if (strcmp(optarg, "ipx") == 0) af = AF_IPX; else if (strcmp(optarg, "inet") == 0) af = AF_INET; #ifdef INET6 else if (strcmp(optarg, "inet6") == 0) af = AF_INET6; #endif #ifdef IPSEC else if (strcmp(optarg, "pfkey") == 0) af = PF_KEY; #endif else if (strcmp(optarg, "unix") == 0) af = AF_UNIX; else if (strcmp(optarg, "atalk") == 0) af = AF_APPLETALK; #ifdef NETGRAPH else if (strcmp(optarg, "ng") == 0 || strcmp(optarg, "netgraph") == 0) af = AF_NETGRAPH; #endif else if (strcmp(optarg, "link") == 0) af = AF_LINK; else { errx(1, "%s: unknown address family", optarg); } break; case 'g': gflag = 1; break; case 'h': hflag = 1; break; case 'I': { char *cp; iflag = 1; for (cp = interface = optarg; isalpha(*cp); cp++) continue; unit = atoi(cp); break; } case 'i': iflag = 1; break; case 'L': Lflag = 1; break; case 'M': memf = optarg; break; case 'm': mflag = 1; break; case 'N': nlistf = optarg; break; case 'n': numeric_addr = numeric_port = 1; break; case 'p': if ((tp = name2protox(optarg)) == NULL) { errx(1, "%s: unknown or uninstrumented protocol", optarg); } pflag = 1; break; case 'Q': Qflag = 1; break; case 'q': noutputs = atoi(optarg); if (noutputs != 0) noutputs++; break; case 'r': rflag = 1; break; case 'R': Rflag = 1; break; case 's': ++sflag; break; case 'S': numeric_addr = 1; break; case 'u': af = AF_UNIX; break; case 'W': case 'l': Wflag = 1; break; case 'w': interval = atoi(optarg); iflag = 1; break; case 'T': Tflag = 1; break; case 'x': xflag = 1; break; case 'z': zflag = 1; break; case '?': default: usage(); } argv += optind; argc -= optind; #define BACKWARD_COMPATIBILITY #ifdef BACKWARD_COMPATIBILITY if (*argv) { if (isdigit(**argv)) { interval = atoi(*argv); if (interval <= 0) usage(); ++argv; iflag = 1; } if (*argv) { nlistf = *argv; if (*++argv) memf = *argv; } } #endif /* * Discard setgid privileges if not the running kernel so that bad * guys can't print interesting stuff from kernel memory. */ live = (nlistf == NULL && memf == NULL); if (!live) setgid(getgid()); if (xflag && Tflag) errx(1, "-x and -T are incompatible, pick one."); if (Bflag) { if (!live) usage(); bpf_stats(interface); exit(0); } if (mflag) { if (!live) { if (kread(0, NULL, 0) == 0) mbpr(kvmd, nl[N_SFSTAT].n_value); } else mbpr(NULL, 0); exit(0); } if (Qflag) { if (!live) { if (kread(0, NULL, 0) == 0) netisr_stats(kvmd); } else netisr_stats(NULL); exit(0); } #if 0 /* * Keep file descriptors open to avoid overhead * of open/close on each call to get* routines. */ sethostent(1); setnetent(1); #else /* * This does not make sense any more with DNS being default over * the files. Doing a setXXXXent(1) causes a tcp connection to be * used for the queries, which is slower. */ #endif if (iflag && !sflag) { intpr(interval, NULL, af); exit(0); } if (rflag) { if (sflag) { rt_stats(); flowtable_stats(); } else routepr(fib, af); exit(0); } if (gflag) { if (sflag) { if (af == AF_INET || af == AF_UNSPEC) mrt_stats(); #ifdef INET6 if (af == AF_INET6 || af == AF_UNSPEC) mrt6_stats(); #endif } else { if (af == AF_INET || af == AF_UNSPEC) mroutepr(); #ifdef INET6 if (af == AF_INET6 || af == AF_UNSPEC) mroute6pr(); #endif } exit(0); } /* Load all necessary kvm symbols */ kresolve_list(nl); if (tp) { printproto(tp, tp->pr_name); exit(0); } if (af == AF_INET || af == AF_UNSPEC) for (tp = protox; tp->pr_name; tp++) printproto(tp, tp->pr_name); #ifdef INET6 if (af == AF_INET6 || af == AF_UNSPEC) for (tp = ip6protox; tp->pr_name; tp++) printproto(tp, tp->pr_name); #endif /*INET6*/ #ifdef IPSEC if (af == PF_KEY || af == AF_UNSPEC) for (tp = pfkeyprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name); #endif /*IPSEC*/ #ifdef IPX if (af == AF_IPX || af == AF_UNSPEC) { for (tp = ipxprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name); } #endif /* IPX */ if (af == AF_APPLETALK || af == AF_UNSPEC) for (tp = atalkprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name); #ifdef NETGRAPH if (af == AF_NETGRAPH || af == AF_UNSPEC) for (tp = netgraphprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name); #endif /* NETGRAPH */ if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag) unixpr(nl[N_UNP_COUNT].n_value, nl[N_UNP_GENCNT].n_value, nl[N_UNP_DHEAD].n_value, nl[N_UNP_SHEAD].n_value, nl[N_UNP_SPHEAD].n_value); exit(0); +} + +int +fetch_stats(const char *sysctlname, u_long off, void *stats, size_t len, + int (*kreadfn)(u_long, void *, size_t)) +{ + int error; + + if (live) { + memset(stats, 0, len); + if (zflag) + error = sysctlbyname(sysctlname, NULL, NULL, stats, + len); + else + error = sysctlbyname(sysctlname, stats, &len, NULL, 0); + if (error == -1 && errno != ENOENT) + warn("sysctl %s", sysctlname); + } else { + if (off == 0) + return (1); + error = kreadfn(off, stats, len); + } + return (error); } /* * Print out protocol statistics or control blocks (per sflag). * If the interface was not specifically requested, and the symbol * is not in the namelist, ignore this one. */ static void printproto(struct protox *tp, const char *name) { void (*pr)(u_long, const char *, int, int); u_long off; if (sflag) { if (iflag) { if (tp->pr_istats) intpr(interval, tp->pr_istats, af); else if (pflag) printf("%s: no per-interface stats routine\n", tp->pr_name); return; } else { pr = tp->pr_stats; if (!pr) { if (pflag) printf("%s: no stats routine\n", tp->pr_name); return; } if (tp->pr_usesysctl && live) off = 0; else if (tp->pr_sindex < 0) { if (pflag) printf( "%s: stats routine doesn't work on cores\n", tp->pr_name); return; } else off = nl[tp->pr_sindex].n_value; } } else { pr = tp->pr_cblocks; if (!pr) { if (pflag) printf("%s: no PCB routine\n", tp->pr_name); return; } if (tp->pr_usesysctl && live) off = 0; else if (tp->pr_index < 0) { if (pflag) printf( "%s: PCB routine doesn't work on cores\n", tp->pr_name); return; } else off = nl[tp->pr_index].n_value; } if (pr != NULL && (off || (live && tp->pr_usesysctl) || af != AF_UNSPEC)) (*pr)(off, name, af, tp->pr_protocol); } static int kvmd_init(void) { char errbuf[_POSIX2_LINE_MAX]; if (kvmd != NULL) return (0); kvmd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf); setgid(getgid()); if (kvmd == NULL) { warnx("kvm not available: %s", errbuf); return (-1); } return (0); } /* * Resolve symbol list, return 0 on success. */ int kresolve_list(struct nlist *_nl) { if ((kvmd == NULL) && (kvmd_init() != 0)) return (-1); if (_nl[0].n_type != 0) return (0); if (kvm_nlist(kvmd, _nl) < 0) { if (nlistf) errx(1, "%s: kvm_nlist: %s", nlistf, kvm_geterr(kvmd)); else errx(1, "kvm_nlist: %s", kvm_geterr(kvmd)); } return (0); } /* * Read kernel memory, return 0 on success. */ int kread(u_long addr, void *buf, size_t size) { if (kvmd_init() < 0) return (-1); if (!buf) return (0); if (kvm_read(kvmd, addr, buf, size) != (ssize_t)size) { warnx("%s", kvm_geterr(kvmd)); return (-1); } return (0); } /* * Read single counter(9). */ uint64_t kread_counter(u_long addr) { if (kvmd_init() < 0) return (-1); return (kvm_counter_u64_fetch(kvmd, addr)); } /* * Read an array of N counters in kernel memory into array of N uint64_t's. */ int kread_counters(u_long addr, void *buf, size_t size) { uint64_t *c; u_long *counters; size_t i, n; if (kvmd_init() < 0) return (-1); if (size % sizeof(uint64_t) != 0) { warnx("kread_counters: invalid counter set size"); return (-1); } n = size / sizeof(uint64_t); if ((counters = malloc(n * sizeof(u_long))) == NULL) err(-1, "malloc"); if (kread(addr, counters, n * sizeof(u_long)) < 0) { free(counters); return (-1); } c = buf; for (i = 0; i < n; i++) c[i] = kvm_counter_u64_fetch(kvmd, counters[i]); free(counters); return (0); } const char * plural(uintmax_t n) { return (n != 1 ? "s" : ""); } const char * plurales(uintmax_t n) { return (n != 1 ? "es" : ""); } const char * pluralies(uintmax_t n) { return (n != 1 ? "ies" : "y"); } /* * Find the protox for the given "well-known" name. */ static struct protox * knownname(const char *name) { struct protox **tpp, *tp; for (tpp = protoprotox; *tpp; tpp++) for (tp = *tpp; tp->pr_name; tp++) if (strcmp(tp->pr_name, name) == 0) return (tp); return (NULL); } /* * Find the protox corresponding to name. */ static struct protox * name2protox(const char *name) { struct protox *tp; char **alias; /* alias from p->aliases */ struct protoent *p; /* * Try to find the name in the list of "well-known" names. If that * fails, check if name is an alias for an Internet protocol. */ if ((tp = knownname(name)) != NULL) return (tp); setprotoent(1); /* make protocol lookup cheaper */ while ((p = getprotoent()) != NULL) { /* assert: name not same as p->name */ for (alias = p->p_aliases; *alias; alias++) if (strcmp(name, *alias) == 0) { endprotoent(); return (knownname(p->p_name)); } } endprotoent(); return (NULL); } static void usage(void) { (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", "usage: netstat [-46AaLnRSTWx] [-f protocol_family | -p protocol]\n" " [-M core] [-N system]", " netstat -i | -I interface [-46abdhnW] [-f address_family]\n" " [-M core] [-N system]", " netstat -w wait [-I interface] [-46d] [-M core] [-N system] [-q howmany]", " netstat -s [-s] [-46z] [-f protocol_family | -p protocol]\n" " [-M core] [-N system]", " netstat -i | -I interface [-46s] [-f protocol_family | -p protocol]\n" " [-M core] [-N system]", " netstat -m [-M core] [-N system]", " netstat -B [-I interface]", " netstat -r [-46AanW] [-f address_family] [-M core] [-N system]", " netstat -rs [-s] [-M core] [-N system]", " netstat -g [-46W] [-f address_family] [-M core] [-N system]", " netstat -gs [-46s] [-f address_family] [-M core] [-N system]", " netstat -Q"); exit(1); } Index: stable/10/usr.bin/netstat/mbuf.c =================================================================== --- stable/10/usr.bin/netstat/mbuf.c (revision 293306) +++ stable/10/usr.bin/netstat/mbuf.c (revision 293307) @@ -1,324 +1,319 @@ /*- * Copyright (c) 1983, 1988, 1993 * The Regents of the University of California. * Copyright (c) 2005 Robert N. M. Watson * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if 0 #ifndef lint static char sccsid[] = "@(#)mbuf.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ #endif #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "netstat.h" /* * Print mbuf statistics. */ void mbpr(void *kvmd, u_long mbaddr) { struct memory_type_list *mtlp; struct memory_type *mtp; uintmax_t mbuf_count, mbuf_bytes, mbuf_free, mbuf_failures, mbuf_size; uintmax_t mbuf_sleeps; uintmax_t cluster_count, cluster_limit, cluster_free; uintmax_t cluster_failures, cluster_size, cluster_sleeps; uintmax_t packet_count, packet_bytes, packet_free, packet_failures; uintmax_t packet_sleeps; uintmax_t tag_bytes; uintmax_t jumbop_count, jumbop_limit, jumbop_free; uintmax_t jumbop_failures, jumbop_sleeps, jumbop_size; uintmax_t jumbo9_count, jumbo9_limit, jumbo9_free; uintmax_t jumbo9_failures, jumbo9_sleeps, jumbo9_size; uintmax_t jumbo16_count, jumbo16_limit, jumbo16_free; uintmax_t jumbo16_failures, jumbo16_sleeps, jumbo16_size; uintmax_t bytes_inuse, bytes_incache, bytes_total; int nsfbufs, nsfbufspeak, nsfbufsused; struct sfstat sfstat; size_t mlen; int error; mtlp = memstat_mtl_alloc(); if (mtlp == NULL) { warn("memstat_mtl_alloc"); return; } /* * Use memstat_*_all() because some mbuf-related memory is in uma(9), * and some malloc(9). */ if (live) { if (memstat_sysctl_all(mtlp, 0) < 0) { warnx("memstat_sysctl_all: %s", memstat_strerror(memstat_mtl_geterror(mtlp))); goto out; } } else { if (memstat_kvm_all(mtlp, kvmd) < 0) { error = memstat_mtl_geterror(mtlp); if (error == MEMSTAT_ERROR_KVM) warnx("memstat_kvm_all: %s", kvm_geterr(kvmd)); else warnx("memstat_kvm_all: %s", memstat_strerror(error)); goto out; } } mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_MEM_NAME); if (mtp == NULL) { warnx("memstat_mtl_find: zone %s not found", MBUF_MEM_NAME); goto out; } mbuf_count = memstat_get_count(mtp); mbuf_bytes = memstat_get_bytes(mtp); mbuf_free = memstat_get_free(mtp); mbuf_failures = memstat_get_failures(mtp); mbuf_sleeps = memstat_get_sleeps(mtp); mbuf_size = memstat_get_size(mtp); mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_PACKET_MEM_NAME); if (mtp == NULL) { warnx("memstat_mtl_find: zone %s not found", MBUF_PACKET_MEM_NAME); goto out; } packet_count = memstat_get_count(mtp); packet_bytes = memstat_get_bytes(mtp); packet_free = memstat_get_free(mtp); packet_sleeps = memstat_get_sleeps(mtp); packet_failures = memstat_get_failures(mtp); mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_CLUSTER_MEM_NAME); if (mtp == NULL) { warnx("memstat_mtl_find: zone %s not found", MBUF_CLUSTER_MEM_NAME); goto out; } cluster_count = memstat_get_count(mtp); cluster_limit = memstat_get_countlimit(mtp); cluster_free = memstat_get_free(mtp); cluster_failures = memstat_get_failures(mtp); cluster_sleeps = memstat_get_sleeps(mtp); cluster_size = memstat_get_size(mtp); mtp = memstat_mtl_find(mtlp, ALLOCATOR_MALLOC, MBUF_TAG_MEM_NAME); if (mtp == NULL) { warnx("memstat_mtl_find: malloc type %s not found", MBUF_TAG_MEM_NAME); goto out; } tag_bytes = memstat_get_bytes(mtp); mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_JUMBOP_MEM_NAME); if (mtp == NULL) { warnx("memstat_mtl_find: zone %s not found", MBUF_JUMBOP_MEM_NAME); goto out; } jumbop_count = memstat_get_count(mtp); jumbop_limit = memstat_get_countlimit(mtp); jumbop_free = memstat_get_free(mtp); jumbop_failures = memstat_get_failures(mtp); jumbop_sleeps = memstat_get_sleeps(mtp); jumbop_size = memstat_get_size(mtp); mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_JUMBO9_MEM_NAME); if (mtp == NULL) { warnx("memstat_mtl_find: zone %s not found", MBUF_JUMBO9_MEM_NAME); goto out; } jumbo9_count = memstat_get_count(mtp); jumbo9_limit = memstat_get_countlimit(mtp); jumbo9_free = memstat_get_free(mtp); jumbo9_failures = memstat_get_failures(mtp); jumbo9_sleeps = memstat_get_sleeps(mtp); jumbo9_size = memstat_get_size(mtp); mtp = memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_JUMBO16_MEM_NAME); if (mtp == NULL) { warnx("memstat_mtl_find: zone %s not found", MBUF_JUMBO16_MEM_NAME); goto out; } jumbo16_count = memstat_get_count(mtp); jumbo16_limit = memstat_get_countlimit(mtp); jumbo16_free = memstat_get_free(mtp); jumbo16_failures = memstat_get_failures(mtp); jumbo16_sleeps = memstat_get_sleeps(mtp); jumbo16_size = memstat_get_size(mtp); printf("%ju/%ju/%ju mbufs in use (current/cache/total)\n", mbuf_count + packet_count, mbuf_free + packet_free, mbuf_count + packet_count + mbuf_free + packet_free); printf("%ju/%ju/%ju/%ju mbuf clusters in use " "(current/cache/total/max)\n", cluster_count - packet_free, cluster_free + packet_free, cluster_count + cluster_free, cluster_limit); printf("%ju/%ju mbuf+clusters out of packet secondary zone in use " "(current/cache)\n", packet_count, packet_free); printf("%ju/%ju/%ju/%ju %juk (page size) jumbo clusters in use " "(current/cache/total/max)\n", jumbop_count, jumbop_free, jumbop_count + jumbop_free, jumbop_limit, jumbop_size / 1024); printf("%ju/%ju/%ju/%ju 9k jumbo clusters in use " "(current/cache/total/max)\n", jumbo9_count, jumbo9_free, jumbo9_count + jumbo9_free, jumbo9_limit); printf("%ju/%ju/%ju/%ju 16k jumbo clusters in use " "(current/cache/total/max)\n", jumbo16_count, jumbo16_free, jumbo16_count + jumbo16_free, jumbo16_limit); #if 0 printf("%ju mbuf tags in use\n", tag_count); #endif /*- * Calculate in-use bytes as: * - straight mbuf memory * - mbuf memory in packets * - the clusters attached to packets * - and the rest of the non-packet-attached clusters. * - m_tag memory * This avoids counting the clusters attached to packets in the cache. * This currently excludes sf_buf space. */ bytes_inuse = mbuf_bytes + /* straight mbuf memory */ packet_bytes + /* mbufs in packets */ (packet_count * cluster_size) + /* clusters in packets */ /* other clusters */ ((cluster_count - packet_count - packet_free) * cluster_size) + tag_bytes + (jumbop_count * jumbop_size) + /* jumbo clusters */ (jumbo9_count * jumbo9_size) + (jumbo16_count * jumbo16_size); /* * Calculate in-cache bytes as: * - cached straught mbufs * - cached packet mbufs * - cached packet clusters * - cached straight clusters * This currently excludes sf_buf space. */ bytes_incache = (mbuf_free * mbuf_size) + /* straight free mbufs */ (packet_free * mbuf_size) + /* mbufs in free packets */ (packet_free * cluster_size) + /* clusters in free packets */ (cluster_free * cluster_size) + /* free clusters */ (jumbop_free * jumbop_size) + /* jumbo clusters */ (jumbo9_free * jumbo9_size) + (jumbo16_free * jumbo16_size); /* * Total is bytes in use + bytes in cache. This doesn't take into * account various other misc data structures, overhead, etc, but * gives the user something useful despite that. */ bytes_total = bytes_inuse + bytes_incache; printf("%juK/%juK/%juK bytes allocated to network " "(current/cache/total)\n", bytes_inuse / 1024, bytes_incache / 1024, bytes_total / 1024); printf("%ju/%ju/%ju requests for mbufs denied (mbufs/clusters/" "mbuf+clusters)\n", mbuf_failures, cluster_failures, packet_failures); printf("%ju/%ju/%ju requests for mbufs delayed (mbufs/clusters/" "mbuf+clusters)\n", mbuf_sleeps, cluster_sleeps, packet_sleeps); printf("%ju/%ju/%ju requests for jumbo clusters delayed " "(%juk/9k/16k)\n", jumbop_sleeps, jumbo9_sleeps, jumbo16_sleeps, jumbop_size / 1024); printf("%ju/%ju/%ju requests for jumbo clusters denied " "(%juk/9k/16k)\n", jumbop_failures, jumbo9_failures, jumbo16_failures, jumbop_size / 1024); - if (live) { - mlen = sizeof(nsfbufs); - if (!sysctlbyname("kern.ipc.nsfbufs", &nsfbufs, &mlen, NULL, - 0) && - !sysctlbyname("kern.ipc.nsfbufsused", &nsfbufsused, - &mlen, NULL, 0) && - !sysctlbyname("kern.ipc.nsfbufspeak", &nsfbufspeak, - &mlen, NULL, 0)) - printf("%d/%d/%d sfbufs in use (current/peak/max)\n", - nsfbufsused, nsfbufspeak, nsfbufs); - mlen = sizeof(sfstat); - if (sysctlbyname("kern.ipc.sfstat", &sfstat, &mlen, NULL, 0)) { - warn("kern.ipc.sfstat"); - goto out; - } - } else { - if (kread_counters(mbaddr, (char *)&sfstat, sizeof sfstat) != 0) - goto out; - } + mlen = sizeof(nsfbufs); + if (live && + sysctlbyname("kern.ipc.nsfbufs", &nsfbufs, &mlen, NULL, 0) == 0 && + sysctlbyname("kern.ipc.nsfbufsused", &nsfbufsused, &mlen, + NULL, 0) == 0 && + sysctlbyname("kern.ipc.nsfbufspeak", &nsfbufspeak, &mlen, + NULL, 0) == 0) + printf("%d/%d/%d sfbufs in use (current/peak/max)\n", + nsfbufsused, nsfbufspeak, nsfbufs); + + if (fetch_stats("kern.ipc.sfstat", mbaddr, &sfstat, sizeof(sfstat), + kread_counters) != 0) + goto out; + printf("%ju requests for sfbufs denied\n", (uintmax_t)sfstat.sf_allocfail); printf("%ju requests for sfbufs delayed\n", (uintmax_t)sfstat.sf_allocwait); printf("%ju requests for I/O initiated by sendfile\n", (uintmax_t)sfstat.sf_iocnt); out: memstat_mtl_free(mtlp); } Index: stable/10/usr.bin/netstat/mroute.c =================================================================== --- stable/10/usr.bin/netstat/mroute.c (revision 293306) +++ stable/10/usr.bin/netstat/mroute.c (revision 293307) @@ -1,416 +1,410 @@ /*- * Copyright (c) 1989 Stephen Deering * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Stephen Deering of Stanford University. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)mroute.c 8.2 (Berkeley) 4/28/95 */ #include __FBSDID("$FreeBSD$"); /* * Print multicast routing structures and statistics. * * MROUTING 1.0 */ #include #include #include #include #include #include #include #include #include #include #include #include #define _KERNEL 1 #include #undef _KERNEL #include #include #include #include #include #include "netstat.h" /* * kvm(3) bindings for every needed symbol */ static struct nlist mrl[] = { #define N_MRTSTAT 0 { .n_name = "_mrtstat" }, #define N_MFCHASHTBL 1 { .n_name = "_mfchashtbl" }, #define N_VIFTABLE 2 { .n_name = "_viftable" }, #define N_MFCTABLESIZE 3 { .n_name = "_mfctablesize" }, { .n_name = NULL }, }; static void print_bw_meter(struct bw_meter *, int *); static void print_mfc(struct mfc *, int, int *); static void print_bw_meter(struct bw_meter *bw_meter, int *banner_printed) { char s0[256], s1[256], s2[256], s3[256]; struct timeval now, end, delta; gettimeofday(&now, NULL); if (! *banner_printed) { printf(" Bandwidth Meters\n"); printf(" %-30s", "Measured(Start|Packets|Bytes)"); printf(" %s", "Type"); printf(" %-30s", "Thresh(Interval|Packets|Bytes)"); printf(" Remain"); printf("\n"); *banner_printed = 1; } /* The measured values */ if (bw_meter->bm_flags & BW_METER_UNIT_PACKETS) sprintf(s1, "%ju", (uintmax_t)bw_meter->bm_measured.b_packets); else sprintf(s1, "?"); if (bw_meter->bm_flags & BW_METER_UNIT_BYTES) sprintf(s2, "%ju", (uintmax_t)bw_meter->bm_measured.b_bytes); else sprintf(s2, "?"); sprintf(s0, "%lu.%lu|%s|%s", (u_long)bw_meter->bm_start_time.tv_sec, (u_long)bw_meter->bm_start_time.tv_usec, s1, s2); printf(" %-30s", s0); /* The type of entry */ sprintf(s0, "%s", "?"); if (bw_meter->bm_flags & BW_METER_GEQ) sprintf(s0, "%s", ">="); else if (bw_meter->bm_flags & BW_METER_LEQ) sprintf(s0, "%s", "<="); printf(" %-3s", s0); /* The threshold values */ if (bw_meter->bm_flags & BW_METER_UNIT_PACKETS) sprintf(s1, "%ju", (uintmax_t)bw_meter->bm_threshold.b_packets); else sprintf(s1, "?"); if (bw_meter->bm_flags & BW_METER_UNIT_BYTES) sprintf(s2, "%ju", (uintmax_t)bw_meter->bm_threshold.b_bytes); else sprintf(s2, "?"); sprintf(s0, "%lu.%lu|%s|%s", (u_long)bw_meter->bm_threshold.b_time.tv_sec, (u_long)bw_meter->bm_threshold.b_time.tv_usec, s1, s2); printf(" %-30s", s0); /* Remaining time */ timeradd(&bw_meter->bm_start_time, &bw_meter->bm_threshold.b_time, &end); if (timercmp(&now, &end, <=)) { timersub(&end, &now, &delta); sprintf(s3, "%lu.%lu", (u_long)delta.tv_sec, (u_long)delta.tv_usec); } else { /* Negative time */ timersub(&now, &end, &delta); sprintf(s3, "-%lu.%lu", (u_long)delta.tv_sec, (u_long)delta.tv_usec); } printf(" %s", s3); printf("\n"); } static void print_mfc(struct mfc *m, int maxvif, int *banner_printed) { struct bw_meter bw_meter, *bwm; int bw_banner_printed; int error; vifi_t vifi; bw_banner_printed = 0; if (! *banner_printed) { printf("\nIPv4 Multicast Forwarding Table\n" " Origin Group " " Packets In-Vif Out-Vifs:Ttls\n"); *banner_printed = 1; } printf(" %-15.15s", routename(m->mfc_origin.s_addr)); printf(" %-15.15s", routename(m->mfc_mcastgrp.s_addr)); printf(" %9lu", m->mfc_pkt_cnt); printf(" %3d ", m->mfc_parent); for (vifi = 0; vifi <= maxvif; vifi++) { if (m->mfc_ttls[vifi] > 0) printf(" %u:%u", vifi, m->mfc_ttls[vifi]); } printf("\n"); /* * XXX We break the rules and try to use KVM to read the * bandwidth meters, they are not retrievable via sysctl yet. */ bwm = m->mfc_bw_meter; while (bwm != NULL) { error = kread((u_long)bwm, (char *)&bw_meter, sizeof(bw_meter)); if (error) break; print_bw_meter(&bw_meter, &bw_banner_printed); bwm = bw_meter.bm_mfc_next; } } void mroutepr() { struct vif viftable[MAXVIFS]; struct vif *v; struct mfc *m; u_long pmfchashtbl, pmfctablesize, pviftbl; int banner_printed; int saved_numeric_addr; size_t len; vifi_t vifi, maxvif; saved_numeric_addr = numeric_addr; numeric_addr = 1; /* * TODO: * The VIF table will move to hanging off the struct if_info for * each IPv4 configured interface. Currently it is statically * allocated, and retrieved either using KVM or an opaque SYSCTL. * * This can't happen until the API documented in multicast(4) * is itself refactored. The historical reason why VIFs use * a separate ifindex space is entirely due to the legacy * capability of the MROUTING code to create IPIP tunnels on * the fly to support DVMRP. When gif(4) became available, this * functionality was deprecated, as PIM does not use it. */ maxvif = 0; pmfchashtbl = pmfctablesize = pviftbl = 0; len = sizeof(viftable); if (live) { if (sysctlbyname("net.inet.ip.viftable", viftable, &len, NULL, 0) < 0) { warn("sysctl: net.inet.ip.viftable"); return; } } else { kresolve_list(mrl); pmfchashtbl = mrl[N_MFCHASHTBL].n_value; pmfctablesize = mrl[N_MFCTABLESIZE].n_value; pviftbl = mrl[N_VIFTABLE].n_value; if (pmfchashtbl == 0 || pmfctablesize == 0 || pviftbl == 0) { fprintf(stderr, "No IPv4 MROUTING kernel support.\n"); return; } kread(pviftbl, (char *)viftable, sizeof(viftable)); } banner_printed = 0; for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) { if (v->v_lcl_addr.s_addr == 0) continue; maxvif = vifi; if (!banner_printed) { printf("\nIPv4 Virtual Interface Table\n" " Vif Thresh Local-Address " "Remote-Address Pkts-In Pkts-Out\n"); banner_printed = 1; } printf(" %2u %6u %-15.15s", /* opposite math of add_vif() */ vifi, v->v_threshold, routename(v->v_lcl_addr.s_addr)); printf(" %-15.15s", (v->v_flags & VIFF_TUNNEL) ? routename(v->v_rmt_addr.s_addr) : ""); printf(" %9lu %9lu\n", v->v_pkt_in, v->v_pkt_out); } if (!banner_printed) printf("\nIPv4 Virtual Interface Table is empty\n"); banner_printed = 0; /* * TODO: * The MFC table will move into the AF_INET radix trie in future. * In 8.x, it becomes a dynamically allocated structure referenced * by a hashed LIST, allowing more than 256 entries w/o kernel tuning. * * If retrieved via opaque SYSCTL, the kernel will coalesce it into * a static table for us. * If retrieved via KVM, the hash list pointers must be followed. */ if (live) { struct mfc *mfctable; len = 0; if (sysctlbyname("net.inet.ip.mfctable", NULL, &len, NULL, 0) < 0) { warn("sysctl: net.inet.ip.mfctable"); return; } mfctable = malloc(len); if (mfctable == NULL) { warnx("malloc %lu bytes", (u_long)len); return; } if (sysctlbyname("net.inet.ip.mfctable", mfctable, &len, NULL, 0) < 0) { free(mfctable); warn("sysctl: net.inet.ip.mfctable"); return; } m = mfctable; while (len >= sizeof(*m)) { print_mfc(m++, maxvif, &banner_printed); len -= sizeof(*m); } if (len != 0) warnx("print_mfc: %lu trailing bytes", (u_long)len); free(mfctable); } else { LIST_HEAD(, mfc) *mfchashtbl; u_long i, mfctablesize; struct mfc mfc; int error; error = kread(pmfctablesize, (char *)&mfctablesize, sizeof(u_long)); if (error) { warn("kread: mfctablesize"); return; } len = sizeof(*mfchashtbl) * mfctablesize; mfchashtbl = malloc(len); if (mfchashtbl == NULL) { warnx("malloc %lu bytes", (u_long)len); return; } kread(pmfchashtbl, (char *)&mfchashtbl, len); for (i = 0; i < mfctablesize; i++) { LIST_FOREACH(m, &mfchashtbl[i], mfc_hash) { kread((u_long)m, (char *)&mfc, sizeof(mfc)); print_mfc(m, maxvif, &banner_printed); } } free(mfchashtbl); } if (!banner_printed) printf("\nIPv4 Multicast Forwarding Table is empty\n"); printf("\n"); numeric_addr = saved_numeric_addr; } void mrt_stats() { struct mrtstat mrtstat; u_long mstaddr; - size_t len = sizeof(mrtstat); kresolve_list(mrl); mstaddr = mrl[N_MRTSTAT].n_value; if (mstaddr == 0) { fprintf(stderr, "No IPv4 MROUTING kernel support.\n"); return; } - if (live) { - if (sysctlbyname("net.inet.ip.mrtstat", &mrtstat, &len, NULL, - 0) < 0) { - warn("sysctl: net.inet.ip.mrtstat failed."); - return; - } - } else - kread_counters(mstaddr, &mrtstat, len); + if (fetch_stats("net.inet.ip.mrtstat", mstaddr, &mrtstat, + sizeof(mrtstat), kread_counters) != 0) + return; printf("IPv4 multicast forwarding:\n"); #define p(f, m) if (mrtstat.f || sflag <= 1) \ printf(m, (uintmax_t)mrtstat.f, plural(mrtstat.f)) #define p2(f, m) if (mrtstat.f || sflag <= 1) \ printf(m, (uintmax_t)mrtstat.f, plurales(mrtstat.f)) p(mrts_mfc_lookups, "\t%ju multicast forwarding cache lookup%s\n"); p2(mrts_mfc_misses, "\t%ju multicast forwarding cache miss%s\n"); p(mrts_upcalls, "\t%ju upcall%s to multicast routing daemon\n"); p(mrts_upq_ovflw, "\t%ju upcall queue overflow%s\n"); p(mrts_upq_sockfull, "\t%ju upcall%s dropped due to full socket buffer\n"); p(mrts_cache_cleanups, "\t%ju cache cleanup%s\n"); p(mrts_no_route, "\t%ju datagram%s with no route for origin\n"); p(mrts_bad_tunnel, "\t%ju datagram%s arrived with bad tunneling\n"); p(mrts_cant_tunnel, "\t%ju datagram%s could not be tunneled\n"); p(mrts_wrong_if, "\t%ju datagram%s arrived on wrong interface\n"); p(mrts_drop_sel, "\t%ju datagram%s selectively dropped\n"); p(mrts_q_overflow, "\t%ju datagram%s dropped due to queue overflow\n"); p(mrts_pkt2large, "\t%ju datagram%s dropped for being too large\n"); #undef p2 #undef p } Index: stable/10/usr.bin/netstat/mroute6.c =================================================================== --- stable/10/usr.bin/netstat/mroute6.c (revision 293306) +++ stable/10/usr.bin/netstat/mroute6.c (revision 293307) @@ -1,294 +1,287 @@ /*- * Copyright (C) 1998 WIDE Project. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the project nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /*- * Copyright (c) 1989 Stephen Deering * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Stephen Deering of Stanford University. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)mroute.c 8.2 (Berkeley) 4/28/95 */ #include __FBSDID("$FreeBSD$"); #ifdef INET6 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define KERNEL 1 #include #undef KERNEL #include "netstat.h" /* * kvm(3) bindings for every needed symbol */ static struct nlist mrl[] = { #define N_MF6CTABLE 0 { .n_name = "_mf6ctable" }, #define N_MIF6TABLE 1 { .n_name = "_mif6table" }, #define N_MRT6STAT 2 { .n_name = "_mrt6stat" }, { .n_name = NULL }, }; #define WID_ORG (Wflag ? 39 : (numeric_addr ? 29 : 18)) /* width of origin column */ #define WID_GRP (Wflag ? 18 : (numeric_addr ? 16 : 18)) /* width of group column */ void mroute6pr() { struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp; struct mif6 mif6table[MAXMIFS]; struct mf6c mfc; struct rtdetq rte, *rtep; struct mif6 *mifp; u_long mfcaddr, mifaddr; mifi_t mifi; int i; int banner_printed; int saved_numeric_addr; mifi_t maxmif = 0; long int waitings; size_t len; kresolve_list(mrl); mfcaddr = mrl[N_MF6CTABLE].n_value; mifaddr = mrl[N_MIF6TABLE].n_value; if (mfcaddr == 0 || mifaddr == 0) { fprintf(stderr, "No IPv6 MROUTING kernel support.\n"); return; } len = sizeof(mif6table); if (live) { if (sysctlbyname("net.inet6.ip6.mif6table", mif6table, &len, NULL, 0) < 0) { warn("sysctl: net.inet6.ip6.mif6table"); return; } } else kread(mifaddr, (char *)mif6table, sizeof(mif6table)); saved_numeric_addr = numeric_addr; numeric_addr = 1; banner_printed = 0; for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) { struct ifnet ifnet; char ifname[IFNAMSIZ]; if (mifp->m6_ifp == NULL) continue; /* XXX KVM */ kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet)); maxmif = mifi; if (!banner_printed) { printf("\nIPv6 Multicast Interface Table\n" " Mif Rate PhyIF " "Pkts-In Pkts-Out\n"); banner_printed = 1; } printf(" %2u %4d", mifi, mifp->m6_rate_limit); printf(" %5s", (mifp->m6_flags & MIFF_REGISTER) ? "reg0" : if_indextoname(ifnet.if_index, ifname)); printf(" %9ju %9ju\n", (uintmax_t)mifp->m6_pkt_in, (uintmax_t)mifp->m6_pkt_out); } if (!banner_printed) printf("\nIPv6 Multicast Interface Table is empty\n"); len = sizeof(mf6ctable); if (live) { if (sysctlbyname("net.inet6.ip6.mf6ctable", mf6ctable, &len, NULL, 0) < 0) { warn("sysctl: net.inet6.ip6.mf6ctable"); return; } } else kread(mfcaddr, (char *)mf6ctable, sizeof(mf6ctable)); banner_printed = 0; for (i = 0; i < MF6CTBLSIZ; ++i) { mfcp = mf6ctable[i]; while(mfcp) { kread((u_long)mfcp, (char *)&mfc, sizeof(mfc)); if (!banner_printed) { printf ("\nIPv6 Multicast Forwarding Cache\n"); printf(" %-*.*s %-*.*s %s", WID_ORG, WID_ORG, "Origin", WID_GRP, WID_GRP, "Group", " Packets Waits In-Mif Out-Mifs\n"); banner_printed = 1; } printf(" %-*.*s", WID_ORG, WID_ORG, routename6(&mfc.mf6c_origin)); printf(" %-*.*s", WID_GRP, WID_GRP, routename6(&mfc.mf6c_mcastgrp)); printf(" %9ju", (uintmax_t)mfc.mf6c_pkt_cnt); for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) { waitings++; /* XXX KVM */ kread((u_long)rtep, (char *)&rte, sizeof(rte)); rtep = rte.next; } printf(" %3ld", waitings); if (mfc.mf6c_parent == MF6C_INCOMPLETE_PARENT) printf(" --- "); else printf(" %3d ", mfc.mf6c_parent); for (mifi = 0; mifi <= maxmif; mifi++) { if (IF_ISSET(mifi, &mfc.mf6c_ifset)) printf(" %u", mifi); } printf("\n"); mfcp = mfc.mf6c_next; } } if (!banner_printed) printf("\nIPv6 Multicast Forwarding Table is empty\n"); printf("\n"); numeric_addr = saved_numeric_addr; } void mrt6_stats() { struct mrt6stat mrtstat; u_long mstaddr; - size_t len = sizeof mrtstat; kresolve_list(mrl); mstaddr = mrl[N_MRT6STAT].n_value; if (mstaddr == 0) { fprintf(stderr, "No IPv6 MROUTING kernel support.\n"); return; } - - if (live) { - if (sysctlbyname("net.inet6.ip6.mrt6stat", &mrtstat, &len, - NULL, 0) < 0) { - warn("sysctl: net.inet6.ip6.mrt6stat"); - return; - } - } else - kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat)); + if (fetch_stats("net.inet6.ip6.mrt6stat", 0, &mrtstat, + sizeof(mrtstat), kread_counters) != 0) + return; printf("IPv6 multicast forwarding:\n"); #define p(f, m) if (mrtstat.f || sflag <= 1) \ printf(m, (uintmax_t)mrtstat.f, plural(mrtstat.f)) #define p2(f, m) if (mrtstat.f || sflag <= 1) \ printf(m, (uintmax_t)mrtstat.f, plurales(mrtstat.f)) p(mrt6s_mfc_lookups, "\t%ju multicast forwarding cache lookup%s\n"); p2(mrt6s_mfc_misses, "\t%ju multicast forwarding cache miss%s\n"); p(mrt6s_upcalls, "\t%ju upcall%s to multicast routing daemon\n"); p(mrt6s_upq_ovflw, "\t%ju upcall queue overflow%s\n"); p(mrt6s_upq_sockfull, "\t%ju upcall%s dropped due to full socket buffer\n"); p(mrt6s_cache_cleanups, "\t%ju cache cleanup%s\n"); p(mrt6s_no_route, "\t%ju datagram%s with no route for origin\n"); p(mrt6s_bad_tunnel, "\t%ju datagram%s arrived with bad tunneling\n"); p(mrt6s_cant_tunnel, "\t%ju datagram%s could not be tunneled\n"); p(mrt6s_wrong_if, "\t%ju datagram%s arrived on wrong interface\n"); p(mrt6s_drop_sel, "\t%ju datagram%s selectively dropped\n"); p(mrt6s_q_overflow, "\t%ju datagram%s dropped due to queue overflow\n"); p(mrt6s_pkt2large, "\t%ju datagram%s dropped for being too large\n"); #undef p2 #undef p } #endif /*INET6*/ Index: stable/10/usr.bin/netstat/netstat.h =================================================================== --- stable/10/usr.bin/netstat/netstat.h (revision 293306) +++ stable/10/usr.bin/netstat/netstat.h (revision 293307) @@ -1,174 +1,176 @@ /*- * Copyright (c) 1992, 1993 * Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)netstat.h 8.2 (Berkeley) 1/4/94 * $FreeBSD$ */ #include extern int Aflag; /* show addresses of protocol control block */ extern int aflag; /* show all sockets (including servers) */ extern int bflag; /* show i/f total bytes in/out */ extern int dflag; /* show i/f dropped packets */ extern int gflag; /* show group (multicast) routing or stats */ extern int hflag; /* show counters in human readable format */ extern int iflag; /* show interfaces */ extern int Lflag; /* show size of listen queues */ extern int mflag; /* show memory stats */ extern int noutputs; /* how much outputs before we exit */ extern int numeric_addr; /* show addresses numerically */ extern int numeric_port; /* show ports numerically */ extern int rflag; /* show routing tables (or routing stats) */ extern int Rflag; /* show flowid / RSS information */ extern int sflag; /* show protocol statistics */ extern int Tflag; /* show TCP control block info */ extern int Wflag; /* wide display */ extern int xflag; /* extended display, includes all socket buffer info */ extern int zflag; /* zero stats */ extern int interval; /* repeat interval for i/f stats */ extern char *interface; /* desired i/f for stats, or NULL for all i/fs */ extern int unit; /* unit number for above */ extern int live; /* true if we are examining a live system */ struct nlist; +int fetch_stats(const char *sysctlname, u_long addr, void *stats, + size_t len, int (*kreadfn)(u_long, void *, size_t)); int kread(u_long addr, void *buf, size_t size); uint64_t kread_counter(u_long addr); int kread_counters(u_long addr, void *buf, size_t size); int kresolve_list(struct nlist *); const char *plural(uintmax_t); const char *plurales(uintmax_t); const char *pluralies(uintmax_t); struct sockaddr; struct socket; struct xsocket; int sotoxsocket(struct socket *, struct xsocket *); void protopr(u_long, const char *, int, int); void tcp_stats(u_long, const char *, int, int); void udp_stats(u_long, const char *, int, int); #ifdef SCTP void sctp_protopr(u_long, const char *, int, int); void sctp_stats(u_long, const char *, int, int); #endif void arp_stats(u_long, const char *, int, int); void ip_stats(u_long, const char *, int, int); void icmp_stats(u_long, const char *, int, int); void igmp_stats(u_long, const char *, int, int); void pim_stats(u_long, const char *, int, int); void carp_stats(u_long, const char *, int, int); void pfsync_stats(u_long, const char *, int, int); #ifdef IPSEC void ipsec_stats(u_long, const char *, int, int); void esp_stats(u_long, const char *, int, int); void ah_stats(u_long, const char *, int, int); void ipcomp_stats(u_long, const char *, int, int); #endif #ifdef INET6 void ip6_stats(u_long, const char *, int, int); void ip6_ifstats(char *); void icmp6_stats(u_long, const char *, int, int); void icmp6_ifstats(char *); void pim6_stats(u_long, const char *, int, int); void rip6_stats(u_long, const char *, int, int); void mroute6pr(void); void mrt6_stats(void); struct sockaddr_in6; struct in6_addr; void in6_fillscopeid(struct sockaddr_in6 *); char *routename6(struct sockaddr_in6 *); const char *netname6(struct sockaddr_in6 *, struct in6_addr *); void inet6print(struct in6_addr *, int, const char *, int); #endif /*INET6*/ #ifdef IPSEC void pfkey_stats(u_long, const char *, int, int); #endif void mbpr(void *, u_long); void netisr_stats(void *); void hostpr(u_long, u_long); void impstats(u_long, u_long); void intpr(int, void (*)(char *), int); void pr_rthdr(int); void pr_family(int); void rt_stats(void); void flowtable_stats(void); char *ipx_pnet(struct sockaddr *); char *ipx_phost(struct sockaddr *); char *ns_phost(struct sockaddr *); void upHex(char *); char *routename(in_addr_t); char *netname(in_addr_t, in_addr_t); char *atalk_print(struct sockaddr *, int); char *atalk_print2(struct sockaddr *, struct sockaddr *, int); char *ipx_print(struct sockaddr *); char *ns_print(struct sockaddr *); void routepr(int, int); void ipxprotopr(u_long, const char *, int, int); void spx_stats(u_long, const char *, int, int); void ipx_stats(u_long, const char *, int, int); void ipxerr_stats(u_long, const char *, int, int); void nsprotopr(u_long, const char *, int, int); void spp_stats(u_long, const char *, int, int); void idp_stats(u_long, const char *, int, int); void nserr_stats(u_long, const char *, int, int); void atalkprotopr(u_long, const char *, int, int); void ddp_stats(u_long, const char *, int, int); #ifdef NETGRAPH void netgraphprotopr(u_long, const char *, int, int); #endif void unixpr(u_long, u_long, u_long, u_long, u_long); void esis_stats(u_long, const char *, int, int); void clnp_stats(u_long, const char *, int, int); void cltp_stats(u_long, const char *, int, int); void iso_protopr(u_long, const char *, int, int); void iso_protopr1(u_long, int); void tp_protopr(u_long, const char *, int, int); void tp_inproto(u_long); void tp_stats(caddr_t, caddr_t); void mroutepr(void); void mrt_stats(void); void bpf_stats(char *); Index: stable/10/usr.bin/netstat/sctp.c =================================================================== --- stable/10/usr.bin/netstat/sctp.c (revision 293306) +++ stable/10/usr.bin/netstat/sctp.c (revision 293307) @@ -1,786 +1,777 @@ /*- * Copyright (c) 2001-2007, by Weongyo Jeong. All rights reserved. * Copyright (c) 2011, by Michael Tuexen. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * a) Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * b) Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the distribution. * * c) Neither the name of Cisco Systems, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ #if 0 #ifndef lint static char sccsid[] = "@(#)sctp.c 0.1 (Berkeley) 4/18/2007"; #endif /* not lint */ #endif #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "netstat.h" #ifdef SCTP static void sctp_statesprint(uint32_t state); #define NETSTAT_SCTP_STATES_CLOSED 0x0 #define NETSTAT_SCTP_STATES_BOUND 0x1 #define NETSTAT_SCTP_STATES_LISTEN 0x2 #define NETSTAT_SCTP_STATES_COOKIE_WAIT 0x3 #define NETSTAT_SCTP_STATES_COOKIE_ECHOED 0x4 #define NETSTAT_SCTP_STATES_ESTABLISHED 0x5 #define NETSTAT_SCTP_STATES_SHUTDOWN_SENT 0x6 #define NETSTAT_SCTP_STATES_SHUTDOWN_RECEIVED 0x7 #define NETSTAT_SCTP_STATES_SHUTDOWN_ACK_SENT 0x8 #define NETSTAT_SCTP_STATES_SHUTDOWN_PENDING 0x9 const char *sctpstates[] = { "CLOSED", "BOUND", "LISTEN", "COOKIE_WAIT", "COOKIE_ECHOED", "ESTABLISHED", "SHUTDOWN_SENT", "SHUTDOWN_RECEIVED", "SHUTDOWN_ACK_SENT", "SHUTDOWN_PENDING" }; LIST_HEAD(xladdr_list, xladdr_entry) xladdr_head; struct xladdr_entry { struct xsctp_laddr *xladdr; LIST_ENTRY(xladdr_entry) xladdr_entries; }; LIST_HEAD(xraddr_list, xraddr_entry) xraddr_head; struct xraddr_entry { struct xsctp_raddr *xraddr; LIST_ENTRY(xraddr_entry) xraddr_entries; }; /* * Construct an Internet address representation. * If numeric_addr has been supplied, give * numeric value, otherwise try for symbolic name. */ #ifdef INET static char * inetname(struct in_addr *inp) { char *cp; static char line[MAXHOSTNAMELEN]; struct hostent *hp; struct netent *np; cp = 0; if (!numeric_addr && inp->s_addr != INADDR_ANY) { int net = inet_netof(*inp); int lna = inet_lnaof(*inp); if (lna == INADDR_ANY) { np = getnetbyaddr(net, AF_INET); if (np) cp = np->n_name; } if (cp == 0) { hp = gethostbyaddr((char *)inp, sizeof (*inp), AF_INET); if (hp) { cp = hp->h_name; trimdomain(cp, strlen(cp)); } } } if (inp->s_addr == INADDR_ANY) strcpy(line, "*"); else if (cp) { strlcpy(line, cp, sizeof(line)); } else { inp->s_addr = ntohl(inp->s_addr); #define C(x) ((u_int)((x) & 0xff)) sprintf(line, "%u.%u.%u.%u", C(inp->s_addr >> 24), C(inp->s_addr >> 16), C(inp->s_addr >> 8), C(inp->s_addr)); inp->s_addr = htonl(inp->s_addr); } return (line); } #endif #ifdef INET6 static char ntop_buf[INET6_ADDRSTRLEN]; static char * inet6name(struct in6_addr *in6p) { char *cp; static char line[50]; struct hostent *hp; static char domain[MAXHOSTNAMELEN]; static int first = 1; if (first && !numeric_addr) { first = 0; if (gethostname(domain, MAXHOSTNAMELEN) == 0 && (cp = strchr(domain, '.'))) (void) strcpy(domain, cp + 1); else domain[0] = 0; } cp = 0; if (!numeric_addr && !IN6_IS_ADDR_UNSPECIFIED(in6p)) { hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6); if (hp) { if ((cp = strchr(hp->h_name, '.')) && !strcmp(cp + 1, domain)) *cp = 0; cp = hp->h_name; } } if (IN6_IS_ADDR_UNSPECIFIED(in6p)) strcpy(line, "*"); else if (cp) strcpy(line, cp); else sprintf(line, "%s", inet_ntop(AF_INET6, (void *)in6p, ntop_buf, sizeof(ntop_buf))); return (line); } #endif static void sctp_print_address(union sctp_sockstore *address, int port, int num_port) { struct servent *sp = 0; char line[80], *cp; int width; switch (address->sa.sa_family) { #ifdef INET case AF_INET: sprintf(line, "%.*s.", Wflag ? 39 : 16, inetname(&address->sin.sin_addr)); break; #endif #ifdef INET6 case AF_INET6: sprintf(line, "%.*s.", Wflag ? 39 : 16, inet6name(&address->sin6.sin6_addr)); break; #endif default: sprintf(line, "%.*s.", Wflag ? 39 : 16, ""); break; } cp = strchr(line, '\0'); if (!num_port && port) sp = getservbyport((int)port, "sctp"); if (sp || port == 0) sprintf(cp, "%.15s ", sp ? sp->s_name : "*"); else sprintf(cp, "%d ", ntohs((u_short)port)); width = Wflag ? 45 : 22; printf("%-*.*s ", width, width, line); } static int sctp_skip_xinpcb_ifneed(char *buf, const size_t buflen, size_t *offset) { int exist_tcb = 0; struct xsctp_tcb *xstcb; struct xsctp_raddr *xraddr; struct xsctp_laddr *xladdr; while (*offset < buflen) { xladdr = (struct xsctp_laddr *)(buf + *offset); *offset += sizeof(struct xsctp_laddr); if (xladdr->last == 1) break; } while (*offset < buflen) { xstcb = (struct xsctp_tcb *)(buf + *offset); *offset += sizeof(struct xsctp_tcb); if (xstcb->last == 1) break; exist_tcb = 1; while (*offset < buflen) { xladdr = (struct xsctp_laddr *)(buf + *offset); *offset += sizeof(struct xsctp_laddr); if (xladdr->last == 1) break; } while (*offset < buflen) { xraddr = (struct xsctp_raddr *)(buf + *offset); *offset += sizeof(struct xsctp_raddr); if (xraddr->last == 1) break; } } /* * If Lflag is set, we don't care about the return value. */ if (Lflag) return 0; return exist_tcb; } static void sctp_process_tcb(struct xsctp_tcb *xstcb, char *buf, const size_t buflen, size_t *offset, int *indent) { int i, xl_total = 0, xr_total = 0, x_max; struct xsctp_raddr *xraddr; struct xsctp_laddr *xladdr; struct xladdr_entry *prev_xl = NULL, *xl = NULL, *xl_tmp; struct xraddr_entry *prev_xr = NULL, *xr = NULL, *xr_tmp; LIST_INIT(&xladdr_head); LIST_INIT(&xraddr_head); /* * Make `struct xladdr_list' list and `struct xraddr_list' list * to handle the address flexibly. */ while (*offset < buflen) { xladdr = (struct xsctp_laddr *)(buf + *offset); *offset += sizeof(struct xsctp_laddr); if (xladdr->last == 1) break; prev_xl = xl; xl = malloc(sizeof(struct xladdr_entry)); if (xl == NULL) { warnx("malloc %lu bytes", (u_long)sizeof(struct xladdr_entry)); goto out; } xl->xladdr = xladdr; if (prev_xl == NULL) LIST_INSERT_HEAD(&xladdr_head, xl, xladdr_entries); else LIST_INSERT_AFTER(prev_xl, xl, xladdr_entries); xl_total++; } while (*offset < buflen) { xraddr = (struct xsctp_raddr *)(buf + *offset); *offset += sizeof(struct xsctp_raddr); if (xraddr->last == 1) break; prev_xr = xr; xr = malloc(sizeof(struct xraddr_entry)); if (xr == NULL) { warnx("malloc %lu bytes", (u_long)sizeof(struct xraddr_entry)); goto out; } xr->xraddr = xraddr; if (prev_xr == NULL) LIST_INSERT_HEAD(&xraddr_head, xr, xraddr_entries); else LIST_INSERT_AFTER(prev_xr, xr, xraddr_entries); xr_total++; } /* * Let's print the address infos. */ xl = LIST_FIRST(&xladdr_head); xr = LIST_FIRST(&xraddr_head); x_max = (xl_total > xr_total) ? xl_total : xr_total; for (i = 0; i < x_max; i++) { if (((*indent == 0) && i > 0) || *indent > 0) printf("%-12s ", " "); if (xl != NULL) { sctp_print_address(&(xl->xladdr->address), htons(xstcb->local_port), numeric_port); } else { if (Wflag) { printf("%-45s ", " "); } else { printf("%-22s ", " "); } } if (xr != NULL && !Lflag) { sctp_print_address(&(xr->xraddr->address), htons(xstcb->remote_port), numeric_port); } if (xl != NULL) xl = LIST_NEXT(xl, xladdr_entries); if (xr != NULL) xr = LIST_NEXT(xr, xraddr_entries); if (i == 0 && !Lflag) sctp_statesprint(xstcb->state); if (i < x_max) putchar('\n'); } out: /* * Free the list which be used to handle the address. */ xl = LIST_FIRST(&xladdr_head); while (xl != NULL) { xl_tmp = LIST_NEXT(xl, xladdr_entries); free(xl); xl = xl_tmp; } xr = LIST_FIRST(&xraddr_head); while (xr != NULL) { xr_tmp = LIST_NEXT(xr, xraddr_entries); free(xr); xr = xr_tmp; } } static void sctp_process_inpcb(struct xsctp_inpcb *xinpcb, char *buf, const size_t buflen, size_t *offset) { int indent = 0, xladdr_total = 0, is_listening = 0; static int first = 1; const char *tname, *pname; struct xsctp_tcb *xstcb; struct xsctp_laddr *xladdr; size_t offset_laddr; int process_closed; if (xinpcb->maxqlen > 0) is_listening = 1; if (first) { if (!Lflag) { printf("Active SCTP associations"); if (aflag) printf(" (including servers)"); } else printf("Current listen queue sizes (qlen/maxqlen)"); putchar('\n'); if (Lflag) printf("%-6.6s %-5.5s %-8.8s %-22.22s\n", "Proto", "Type", "Listen", "Local Address"); else if (Wflag) printf("%-6.6s %-5.5s %-45.45s %-45.45s %s\n", "Proto", "Type", "Local Address", "Foreign Address", "(state)"); else printf("%-6.6s %-5.5s %-22.22s %-22.22s %s\n", "Proto", "Type", "Local Address", "Foreign Address", "(state)"); first = 0; } xladdr = (struct xsctp_laddr *)(buf + *offset); if (Lflag && !is_listening) { sctp_skip_xinpcb_ifneed(buf, buflen, offset); return; } if (xinpcb->flags & SCTP_PCB_FLAGS_BOUND_V6) { /* Can't distinguish between sctp46 and sctp6 */ pname = "sctp46"; } else { pname = "sctp4"; } if (xinpcb->flags & SCTP_PCB_FLAGS_TCPTYPE) tname = "1to1"; else if (xinpcb->flags & SCTP_PCB_FLAGS_UDPTYPE) tname = "1toN"; else tname = "????"; if (Lflag) { char buf1[9]; snprintf(buf1, 9, "%hu/%hu", xinpcb->qlen, xinpcb->maxqlen); printf("%-6.6s %-5.5s ", pname, tname); printf("%-8.8s ", buf1); } offset_laddr = *offset; process_closed = 0; retry: while (*offset < buflen) { xladdr = (struct xsctp_laddr *)(buf + *offset); *offset += sizeof(struct xsctp_laddr); if (xladdr->last) { if (aflag && !Lflag && (xladdr_total == 0) && process_closed) { printf("%-6.6s %-5.5s ", pname, tname); if (Wflag) { printf("%-91.91s CLOSED", " "); } else { printf("%-45.45s CLOSED", " "); } } if (process_closed || is_listening) { putchar('\n'); } break; } if (!Lflag && !is_listening && !process_closed) continue; if (xladdr_total == 0) { printf("%-6.6s %-5.5s ", pname, tname); } else { putchar('\n'); printf((Lflag) ? "%-21.21s " : "%-12.12s ", " "); } sctp_print_address(&(xladdr->address), htons(xinpcb->local_port), numeric_port); if (aflag && !Lflag && xladdr_total == 0) { if (Wflag) { if (process_closed) { printf("%-45.45s CLOSED", " "); } else { printf("%-45.45s LISTEN", " "); } } else { if (process_closed) { printf("%-22.22s CLOSED", " "); } else { printf("%-22.22s LISTEN", " "); } } } xladdr_total++; } xstcb = (struct xsctp_tcb *)(buf + *offset); *offset += sizeof(struct xsctp_tcb); if (aflag && (xladdr_total == 0) && xstcb->last && !process_closed) { process_closed = 1; *offset = offset_laddr; goto retry; } while (xstcb->last == 0 && *offset < buflen) { printf("%-6.6s %-5.5s ", pname, tname); sctp_process_tcb(xstcb, buf, buflen, offset, &indent); indent++; xstcb = (struct xsctp_tcb *)(buf + *offset); *offset += sizeof(struct xsctp_tcb); } } /* * Print a summary of SCTP connections related to an Internet * protocol. */ void sctp_protopr(u_long off __unused, const char *name __unused, int af1 __unused, int proto) { char *buf; const char *mibvar = "net.inet.sctp.assoclist"; size_t offset = 0; size_t len = 0; struct xsctp_inpcb *xinpcb; if (proto != IPPROTO_SCTP) return; if (sysctlbyname(mibvar, 0, &len, 0, 0) < 0) { if (errno != ENOENT) warn("sysctl: %s", mibvar); return; } if ((buf = malloc(len)) == 0) { warnx("malloc %lu bytes", (u_long)len); return; } if (sysctlbyname(mibvar, buf, &len, 0, 0) < 0) { warn("sysctl: %s", mibvar); free(buf); return; } xinpcb = (struct xsctp_inpcb *)(buf + offset); offset += sizeof(struct xsctp_inpcb); while (xinpcb->last == 0 && offset < len) { sctp_process_inpcb(xinpcb, buf, (const size_t)len, &offset); xinpcb = (struct xsctp_inpcb *)(buf + offset); offset += sizeof(struct xsctp_inpcb); } free(buf); } static void sctp_statesprint(uint32_t state) { int idx; switch (state) { case SCTP_STATE_COOKIE_WAIT: idx = NETSTAT_SCTP_STATES_COOKIE_WAIT; break; case SCTP_STATE_COOKIE_ECHOED: idx = NETSTAT_SCTP_STATES_COOKIE_ECHOED; break; case SCTP_STATE_OPEN: idx = NETSTAT_SCTP_STATES_ESTABLISHED; break; case SCTP_STATE_SHUTDOWN_SENT: idx = NETSTAT_SCTP_STATES_SHUTDOWN_SENT; break; case SCTP_STATE_SHUTDOWN_RECEIVED: idx = NETSTAT_SCTP_STATES_SHUTDOWN_RECEIVED; break; case SCTP_STATE_SHUTDOWN_ACK_SENT: idx = NETSTAT_SCTP_STATES_SHUTDOWN_ACK_SENT; break; case SCTP_STATE_SHUTDOWN_PENDING: idx = NETSTAT_SCTP_STATES_SHUTDOWN_PENDING; break; default: printf("UNKNOWN 0x%08x", state); return; } printf("%s", sctpstates[idx]); } /* * Dump SCTP statistics structure. */ void sctp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { - struct sctpstat sctpstat, zerostat; - size_t len = sizeof(sctpstat); + struct sctpstat sctpstat; - if (live) { - if (zflag) - memset(&zerostat, 0, len); - if (sysctlbyname("net.inet.sctp.stats", &sctpstat, &len, - zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { - if (errno != ENOENT) - warn("sysctl: net.inet.sctp.stats"); - return; - } - } else - kread(off, &sctpstat, len); + if (fetch_stats("net.inet.sctp.stats", off, &sctpstat, + sizeof(sctpstat), kread) != 0) + return; printf ("%s:\n", name); #define p(f, m) if (sctpstat.f || sflag <= 1) \ printf(m, (uintmax_t)sctpstat.f, plural(sctpstat.f)) #define p1a(f, m) if (sctpstat.f || sflag <= 1) \ printf(m, (uintmax_t)sctpstat.f) /* * input statistics */ p(sctps_recvpackets, "\t%ju input packet%s\n"); p(sctps_recvdatagrams, "\t\t%ju datagram%s\n"); p(sctps_recvpktwithdata, "\t\t%ju packet%s that had data\n"); p(sctps_recvsacks, "\t\t%ju input SACK chunk%s\n"); p(sctps_recvdata, "\t\t%ju input DATA chunk%s\n"); p(sctps_recvdupdata, "\t\t%ju duplicate DATA chunk%s\n"); p(sctps_recvheartbeat, "\t\t%ju input HB chunk%s\n"); p(sctps_recvheartbeatack, "\t\t%ju HB-ACK chunk%s\n"); p(sctps_recvecne, "\t\t%ju input ECNE chunk%s\n"); p(sctps_recvauth, "\t\t%ju input AUTH chunk%s\n"); p(sctps_recvauthmissing, "\t\t%ju chunk%s missing AUTH\n"); p(sctps_recvivalhmacid, "\t\t%ju invalid HMAC id%s received\n"); p(sctps_recvivalkeyid, "\t\t%ju invalid secret id%s received\n"); p1a(sctps_recvauthfailed, "\t\t%ju auth failed\n"); p1a(sctps_recvexpress, "\t\t%ju fast path receives all one chunk\n"); p1a(sctps_recvexpressm, "\t\t%ju fast path multi-part data\n"); /* * output statistics */ p(sctps_sendpackets, "\t%ju output packet%s\n"); p(sctps_sendsacks, "\t\t%ju output SACK%s\n"); p(sctps_senddata, "\t\t%ju output DATA chunk%s\n"); p(sctps_sendretransdata, "\t\t%ju retransmitted DATA chunk%s\n"); p(sctps_sendfastretrans, "\t\t%ju fast retransmitted DATA chunk%s\n"); p(sctps_sendmultfastretrans, "\t\t%ju FR'%s that happened more " "than once to same chunk\n"); p(sctps_sendheartbeat, "\t\t%ju output HB chunk%s\n"); p(sctps_sendecne, "\t\t%ju output ECNE chunk%s\n"); p(sctps_sendauth, "\t\t%ju output AUTH chunk%s\n"); p1a(sctps_senderrors, "\t\t%ju ip_output error counter\n"); /* * PCKDROPREP statistics */ printf("\tPacket drop statistics:\n"); p1a(sctps_pdrpfmbox, "\t\t%ju from middle box\n"); p1a(sctps_pdrpfehos, "\t\t%ju from end host\n"); p1a(sctps_pdrpmbda, "\t\t%ju with data\n"); p1a(sctps_pdrpmbct, "\t\t%ju non-data, non-endhost\n"); p1a(sctps_pdrpbwrpt, "\t\t%ju non-endhost, bandwidth rep only\n"); p1a(sctps_pdrpcrupt, "\t\t%ju not enough for chunk header\n"); p1a(sctps_pdrpnedat, "\t\t%ju not enough data to confirm\n"); p1a(sctps_pdrppdbrk, "\t\t%ju where process_chunk_drop said break\n"); p1a(sctps_pdrptsnnf, "\t\t%ju failed to find TSN\n"); p1a(sctps_pdrpdnfnd, "\t\t%ju attempt reverse TSN lookup\n"); p1a(sctps_pdrpdiwnp, "\t\t%ju e-host confirms zero-rwnd\n"); p1a(sctps_pdrpdizrw, "\t\t%ju midbox confirms no space\n"); p1a(sctps_pdrpbadd, "\t\t%ju data did not match TSN\n"); p(sctps_pdrpmark, "\t\t%ju TSN'%s marked for Fast Retran\n"); /* * Timeouts */ printf("\tTimeouts:\n"); p(sctps_timoiterator, "\t\t%ju iterator timer%s fired\n"); p(sctps_timodata, "\t\t%ju T3 data time out%s\n"); p(sctps_timowindowprobe, "\t\t%ju window probe (T3) timer%s fired\n"); p(sctps_timoinit, "\t\t%ju INIT timer%s fired\n"); p(sctps_timosack, "\t\t%ju sack timer%s fired\n"); p(sctps_timoshutdown, "\t\t%ju shutdown timer%s fired\n"); p(sctps_timoheartbeat, "\t\t%ju heartbeat timer%s fired\n"); p1a(sctps_timocookie, "\t\t%ju a cookie timeout fired\n"); p1a(sctps_timosecret, "\t\t%ju an endpoint changed its cookie" "secret\n"); p(sctps_timopathmtu, "\t\t%ju PMTU timer%s fired\n"); p(sctps_timoshutdownack, "\t\t%ju shutdown ack timer%s fired\n"); p(sctps_timoshutdownguard, "\t\t%ju shutdown guard timer%s fired\n"); p(sctps_timostrmrst, "\t\t%ju stream reset timer%s fired\n"); p(sctps_timoearlyfr, "\t\t%ju early FR timer%s fired\n"); p1a(sctps_timoasconf, "\t\t%ju an asconf timer fired\n"); p1a(sctps_timoautoclose, "\t\t%ju auto close timer fired\n"); p(sctps_timoassockill, "\t\t%ju asoc free timer%s expired\n"); p(sctps_timoinpkill, "\t\t%ju inp free timer%s expired\n"); #if 0 /* * Early fast retransmission counters */ p(sctps_earlyfrstart, "\t%ju TODO:sctps_earlyfrstart\n"); p(sctps_earlyfrstop, "\t%ju TODO:sctps_earlyfrstop\n"); p(sctps_earlyfrmrkretrans, "\t%ju TODO:sctps_earlyfrmrkretrans\n"); p(sctps_earlyfrstpout, "\t%ju TODO:sctps_earlyfrstpout\n"); p(sctps_earlyfrstpidsck1, "\t%ju TODO:sctps_earlyfrstpidsck1\n"); p(sctps_earlyfrstpidsck2, "\t%ju TODO:sctps_earlyfrstpidsck2\n"); p(sctps_earlyfrstpidsck3, "\t%ju TODO:sctps_earlyfrstpidsck3\n"); p(sctps_earlyfrstpidsck4, "\t%ju TODO:sctps_earlyfrstpidsck4\n"); p(sctps_earlyfrstrid, "\t%ju TODO:sctps_earlyfrstrid\n"); p(sctps_earlyfrstrout, "\t%ju TODO:sctps_earlyfrstrout\n"); p(sctps_earlyfrstrtmr, "\t%ju TODO:sctps_earlyfrstrtmr\n"); #endif /* * Others */ p1a(sctps_hdrops, "\t%ju packet shorter than header\n"); p1a(sctps_badsum, "\t%ju checksum error\n"); p1a(sctps_noport, "\t%ju no endpoint for port\n"); p1a(sctps_badvtag, "\t%ju bad v-tag\n"); p1a(sctps_badsid, "\t%ju bad SID\n"); p1a(sctps_nomem, "\t%ju no memory\n"); p1a(sctps_fastretransinrtt, "\t%ju number of multiple FR in a RTT " "window\n"); #if 0 p(sctps_markedretrans, "\t%ju TODO:sctps_markedretrans\n"); #endif p1a(sctps_naglesent, "\t%ju RFC813 allowed sending\n"); p1a(sctps_naglequeued, "\t%ju RFC813 does not allow sending\n"); p1a(sctps_maxburstqueued, "\t%ju times max burst prohibited sending\n"); p1a(sctps_ifnomemqueued, "\t%ju look ahead tells us no memory in " "interface\n"); p(sctps_windowprobed, "\t%ju number%s of window probes sent\n"); p(sctps_lowlevelerr, "\t%ju time%s an output error to clamp " "down on next user send\n"); p(sctps_lowlevelerrusr, "\t%ju time%s sctp_senderrors were " "caused from a user\n"); p(sctps_datadropchklmt, "\t%ju number of in data drop%s due to " "chunk limit reached\n"); p(sctps_datadroprwnd, "\t%ju number of in data drop%s due to rwnd " "limit reached\n"); p(sctps_ecnereducedcwnd, "\t%ju time%s a ECN reduced " "the cwnd\n"); p1a(sctps_vtagexpress, "\t%ju used express lookup via vtag\n"); p1a(sctps_vtagbogus, "\t%ju collision in express lookup\n"); p(sctps_primary_randry, "\t%ju time%s the sender ran dry " "of user data on primary\n"); p1a(sctps_cmt_randry, "\t%ju same for above\n"); p(sctps_slowpath_sack, "\t%ju sack%s the slow way\n"); p(sctps_wu_sacks_sent, "\t%ju window update only sack%s sent\n"); p(sctps_sends_with_flags, "\t%ju send%s with sinfo_flags !=0\n"); p(sctps_sends_with_unord, "\t%ju unordered send%s\n"); p(sctps_sends_with_eof, "\t%ju send%s with EOF flag set\n"); p(sctps_sends_with_abort, "\t%ju send%s with ABORT flag set\n"); p(sctps_protocol_drain_calls, "\t%ju time%s protocol drain called\n"); p(sctps_protocol_drains_done, "\t%ju time%s we did a protocol " "drain\n"); p(sctps_read_peeks, "\t%ju time%s recv was called with peek\n"); p(sctps_cached_chk, "\t%ju cached chunk%s used\n"); p1a(sctps_cached_strmoq, "\t%ju cached stream oq's used\n"); p(sctps_left_abandon, "\t%ju unread message%s abandonded by close\n"); p1a(sctps_send_burst_avoid, "\t%ju send burst avoidance, already " "max burst inflight to net\n"); p1a(sctps_send_cwnd_avoid, "\t%ju send cwnd full avoidance, already " "max burst inflight to net\n"); p(sctps_fwdtsn_map_over, "\t%ju number of map array over-run%s via " "fwd-tsn's\n"); #undef p #undef p1a } #endif /* SCTP */ Index: stable/10 =================================================================== --- stable/10 (revision 293306) +++ stable/10 (revision 293307) Property changes on: stable/10 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r287649