1/*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 1992, 1993 5 * Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of the University nor the names of its contributors 16 * may be used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32#include <sys/cdefs.h> 33 34#define satosin(sa) ((struct sockaddr_in *)(sa)) 35#define satosin6(sa) ((struct sockaddr_in6 *)(sa)) 36#define sin6tosa(sin6) ((struct sockaddr *)(sin6)) 37 38extern int Aflag; /* show addresses of protocol control block */ 39extern int aflag; /* show all sockets (including servers) */ 40extern int bflag; /* show i/f total bytes in/out */ 41extern int cflag; /* show congestion control stats */ 42extern int Cflag; /* show congestion control algo and stack */ 43extern int dflag; /* show i/f dropped packets */ 44extern int gflag; /* show group (multicast) routing or stats */ 45extern int hflag; /* show counters in human readable format */ 46extern int iflag; /* show interfaces */ 47extern int Lflag; /* show size of listen queues */ 48extern int mflag; /* show memory stats */ 49extern int noutputs; /* how much outputs before we exit */ 50extern int numeric_addr; /* show addresses numerically */ 51extern int numeric_port; /* show ports numerically */ 52extern int Pflag; /* show TCP log ID */ 53extern int rflag; /* show routing tables (or routing stats) */ 54extern int Rflag; /* show flowid / RSS information */ 55extern int sflag; /* show protocol statistics */ 56extern int Tflag; /* show TCP control block info */ 57extern int Wflag; /* wide display */ 58extern int xflag; /* extended display, includes all socket buffer info */ 59extern int zflag; /* zero stats */ 60 61extern int interval; /* repeat interval for i/f stats */ 62 63extern char *interface; /* desired i/f for stats, or NULL for all i/fs */ 64extern int unit; /* unit number for above */ 65 66extern int live; /* true if we are examining a live system */ 67 68typedef int kreadfn_t(u_long, void *, size_t); 69int fetch_stats(const char *, u_long, void *, size_t, kreadfn_t); 70int fetch_stats_ro(const char *, u_long, void *, size_t, kreadfn_t); 71 72int kread(u_long addr, void *buf, size_t size); 73uint64_t kread_counter(u_long addr); 74int kread_counters(u_long addr, void *buf, size_t size); 75void kset_dpcpu(u_int); 76const char *plural(uintmax_t); 77const char *plurales(uintmax_t); 78const char *pluralies(uintmax_t); 79 80struct sockaddr; 81struct socket; 82struct xsocket; 83int sotoxsocket(struct socket *, struct xsocket *); 84void protopr(u_long, const char *, int, int); 85void tcp_stats(u_long, const char *, int, int); 86void udp_stats(u_long, const char *, int, int); 87#ifdef SCTP 88void sctp_protopr(u_long, const char *, int, int); 89void sctp_stats(u_long, const char *, int, int); 90#endif 91void arp_stats(u_long, const char *, int, int); 92void divert_stats(u_long, const char *, int, int); 93void ip_stats(u_long, const char *, int, int); 94void icmp_stats(u_long, const char *, int, int); 95void igmp_stats(u_long, const char *, int, int); 96void pim_stats(u_long, const char *, int, int); 97void carp_stats(u_long, const char *, int, int); 98void pfsync_stats(u_long, const char *, int, int); 99void pflow_stats(u_long, const char *, int, int); 100#ifdef IPSEC 101void ipsec_stats(u_long, const char *, int, int); 102void esp_stats(u_long, const char *, int, int); 103void ah_stats(u_long, const char *, int, int); 104void ipcomp_stats(u_long, const char *, int, int); 105#endif 106 107#ifdef INET 108struct in_addr; 109 110char *inetname(struct in_addr *); 111#endif 112 113#ifdef INET6 114struct in6_addr; 115 116char *inet6name(struct in6_addr *); 117void ip6_stats(u_long, const char *, int, int); 118void ip6_ifstats(char *); 119void icmp6_stats(u_long, const char *, int, int); 120void icmp6_ifstats(char *); 121void pim6_stats(u_long, const char *, int, int); 122void rip6_stats(u_long, const char *, int, int); 123void mroute6pr(void); 124void mrt6_stats(void); 125 126struct sockaddr_in6; 127struct in6_addr; 128void in6_fillscopeid(struct sockaddr_in6 *); 129void inet6print(const char *, struct in6_addr *, int, const char *, int); 130#endif /*INET6*/ 131 132#ifdef IPSEC 133void pfkey_stats(u_long, const char *, int, int); 134#endif 135 136void mbpr(void *, u_long); 137 138void netisr_stats(void); 139 140void hostpr(u_long, u_long); 141void impstats(u_long, u_long); 142 143void intpr(void (*)(char *), int); 144 145void pr_family(int); 146void rt_stats(void); 147 148char *routename(struct sockaddr *, int); 149const char *netname(struct sockaddr *, struct sockaddr *); 150void routepr(int, int); 151int p_sockaddr(const char *name, struct sockaddr *sa, 152 struct sockaddr *mask, int flags, int width); 153const char *fmt_sockaddr(struct sockaddr *sa, struct sockaddr *mask, 154 int flags); 155 156#ifdef NETGRAPH 157void netgraphprotopr(u_long, const char *, int, int); 158#endif 159 160void unixpr(u_long, u_long, u_long, u_long, u_long, bool *); 161 162void mroutepr(void); 163void mrt_stats(void); 164void bpf_stats(char *); 165void nhops_print(int fibnum, int af); 166void nhgrp_print(int fibnum, int af); 167