165475bc8SDavid E. O'Brien /*- 28a16b7a1SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 38a16b7a1SPedro F. Giffuni * 49b50d902SRodney W. Grimes * Copyright (c) 1992, 1993 59b50d902SRodney W. Grimes * Regents of the University of California. All rights reserved. 69b50d902SRodney W. Grimes * 79b50d902SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 89b50d902SRodney W. Grimes * modification, are permitted provided that the following conditions 99b50d902SRodney W. Grimes * are met: 109b50d902SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 119b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 129b50d902SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 139b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 149b50d902SRodney W. Grimes * documentation and/or other materials provided with the distribution. 15fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 169b50d902SRodney W. Grimes * may be used to endorse or promote products derived from this software 179b50d902SRodney W. Grimes * without specific prior written permission. 189b50d902SRodney W. Grimes * 199b50d902SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 209b50d902SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 219b50d902SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 229b50d902SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 239b50d902SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 249b50d902SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 259b50d902SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 269b50d902SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 279b50d902SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 289b50d902SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 299b50d902SRodney W. Grimes * SUCH DAMAGE. 309b50d902SRodney W. Grimes */ 319b50d902SRodney W. Grimes 329b50d902SRodney W. Grimes #include <sys/cdefs.h> 339b50d902SRodney W. Grimes 345c4f64bdSBram #define NETSTAT_XO_VERSION "1" 355c4f64bdSBram 3610d5269fSHiroki Sato #define satosin(sa) ((struct sockaddr_in *)(sa)) 3710d5269fSHiroki Sato #define satosin6(sa) ((struct sockaddr_in6 *)(sa)) 3810d5269fSHiroki Sato #define sin6tosa(sin6) ((struct sockaddr *)(sin6)) 3910d5269fSHiroki Sato 40*c032fb85SEd Maste extern bool Aflag; /* show addresses of protocol control block */ 41*c032fb85SEd Maste extern bool aflag; /* show all sockets (including servers) */ 42*c032fb85SEd Maste extern bool bflag; /* show i/f total bytes in/out */ 43*c032fb85SEd Maste extern bool cflag; /* show congestion control stats */ 44*c032fb85SEd Maste extern bool Cflag; /* show congestion control algo and stack */ 45*c032fb85SEd Maste extern bool dflag; /* show i/f dropped packets */ 46*c032fb85SEd Maste extern bool gflag; /* show group (multicast) routing or stats */ 47*c032fb85SEd Maste extern bool hflag; /* show counters in human readable format */ 48*c032fb85SEd Maste extern bool iflag; /* show interfaces */ 49*c032fb85SEd Maste extern bool Lflag; /* show size of listen queues */ 50*c032fb85SEd Maste extern bool mflag; /* show memory stats */ 51bf10ffe1SXin LI extern int noutputs; /* how much outputs before we exit */ 52c2aa9174SGleb Smirnoff extern u_int numeric_addr; /* show addresses numerically */ 53c2aa9174SGleb Smirnoff extern bool numeric_port; /* show ports numerically */ 54*c032fb85SEd Maste extern bool Pflag; /* show TCP log ID */ 55*c032fb85SEd Maste extern bool rflag; /* show routing tables (or routing stats) */ 56*c032fb85SEd Maste extern bool Rflag; /* show flowid / RSS information */ 57080b7f49SDag-Erling Smørgrav extern int sflag; /* show protocol statistics */ 58*c032fb85SEd Maste extern bool Tflag; /* show TCP control block info */ 59*c032fb85SEd Maste extern bool Wflag; /* wide display */ 60*c032fb85SEd Maste extern bool xflag; /* extended display, includes all socket buffer info */ 61*c032fb85SEd Maste extern bool zflag; /* zero stats */ 629b50d902SRodney W. Grimes 63080b7f49SDag-Erling Smørgrav extern int interval; /* repeat interval for i/f stats */ 649b50d902SRodney W. Grimes 65080b7f49SDag-Erling Smørgrav extern char *interface; /* desired i/f for stats, or NULL for all i/fs */ 66080b7f49SDag-Erling Smørgrav extern int unit; /* unit number for above */ 679b50d902SRodney W. Grimes 68feda1a43SJohn Baldwin extern int live; /* true if we are examining a live system */ 699b50d902SRodney W. Grimes 70dbfd8708SGleb Smirnoff typedef int kreadfn_t(u_long, void *, size_t); 71dbfd8708SGleb Smirnoff int fetch_stats(const char *, u_long, void *, size_t, kreadfn_t); 72dbfd8708SGleb Smirnoff int fetch_stats_ro(const char *, u_long, void *, size_t, kreadfn_t); 73dbfd8708SGleb Smirnoff 74feda1a43SJohn Baldwin int kread(u_long addr, void *buf, size_t size); 75e3a7aa6fSGleb Smirnoff uint64_t kread_counter(u_long addr); 765da0521fSAndrey V. Elsukov int kread_counters(u_long addr, void *buf, size_t size); 7781dacd8bSHiroki Sato void kset_dpcpu(u_int); 787b95a1ebSYaroslav Tykhiy const char *plural(uintmax_t); 797b95a1ebSYaroslav Tykhiy const char *plurales(uintmax_t); 807b95a1ebSYaroslav Tykhiy const char *pluralies(uintmax_t); 819b50d902SRodney W. Grimes 820153eb66SRobert Watson struct sockaddr; 830153eb66SRobert Watson struct socket; 840153eb66SRobert Watson struct xsocket; 85feda1a43SJohn Baldwin int sotoxsocket(struct socket *, struct xsocket *); 86feda1a43SJohn Baldwin void protopr(u_long, const char *, int, int); 87feda1a43SJohn Baldwin void tcp_stats(u_long, const char *, int, int); 88feda1a43SJohn Baldwin void udp_stats(u_long, const char *, int, int); 8974fd40c9SRandall Stewart #ifdef SCTP 90feda1a43SJohn Baldwin void sctp_protopr(u_long, const char *, int, int); 91feda1a43SJohn Baldwin void sctp_stats(u_long, const char *, int, int); 9274fd40c9SRandall Stewart #endif 9354fc657dSGeorge V. Neville-Neil void arp_stats(u_long, const char *, int, int); 942b1c7217SGleb Smirnoff void divert_stats(u_long, const char *, int, int); 95feda1a43SJohn Baldwin void ip_stats(u_long, const char *, int, int); 96feda1a43SJohn Baldwin void icmp_stats(u_long, const char *, int, int); 97feda1a43SJohn Baldwin void igmp_stats(u_long, const char *, int, int); 98feda1a43SJohn Baldwin void pim_stats(u_long, const char *, int, int); 99feda1a43SJohn Baldwin void carp_stats(u_long, const char *, int, int); 100feda1a43SJohn Baldwin void pfsync_stats(u_long, const char *, int, int); 1015dea523bSKristof Provost void pflow_stats(u_long, const char *, int, int); 102cfa1ca9dSYoshinobu Inoue #ifdef IPSEC 103feda1a43SJohn Baldwin void ipsec_stats(u_long, const char *, int, int); 104feda1a43SJohn Baldwin void esp_stats(u_long, const char *, int, int); 105feda1a43SJohn Baldwin void ah_stats(u_long, const char *, int, int); 106feda1a43SJohn Baldwin void ipcomp_stats(u_long, const char *, int, int); 107100b98dbSKelly Yancey #endif 108cfa1ca9dSYoshinobu Inoue 109f193c8ceSXin LI #ifdef INET 110f193c8ceSXin LI struct in_addr; 111f193c8ceSXin LI 112f193c8ceSXin LI char *inetname(struct in_addr *); 113f193c8ceSXin LI #endif 114f193c8ceSXin LI 115cfa1ca9dSYoshinobu Inoue #ifdef INET6 116f193c8ceSXin LI struct in6_addr; 117f193c8ceSXin LI 118f193c8ceSXin LI char *inet6name(struct in6_addr *); 119feda1a43SJohn Baldwin void ip6_stats(u_long, const char *, int, int); 1205e051718SAssar Westerlund void ip6_ifstats(char *); 121feda1a43SJohn Baldwin void icmp6_stats(u_long, const char *, int, int); 1225e051718SAssar Westerlund void icmp6_ifstats(char *); 123feda1a43SJohn Baldwin void pim6_stats(u_long, const char *, int, int); 124feda1a43SJohn Baldwin void rip6_stats(u_long, const char *, int, int); 125fc47e028SAlexander V. Chernikov void mroute6pr(void); 126fc47e028SAlexander V. Chernikov void mrt6_stats(void); 12732cd1d96SJun-ichiro itojun Hagino 12832cd1d96SJun-ichiro itojun Hagino struct sockaddr_in6; 12932cd1d96SJun-ichiro itojun Hagino struct in6_addr; 130cd05232aSHajimu UMEMOTO void in6_fillscopeid(struct sockaddr_in6 *); 131ade9ccfeSMarcel Moolenaar void inet6print(const char *, struct in6_addr *, int, const char *, int); 132cfa1ca9dSYoshinobu Inoue #endif /*INET6*/ 133cfa1ca9dSYoshinobu Inoue 1343b8a8567SJun-ichiro itojun Hagino #ifdef IPSEC 135feda1a43SJohn Baldwin void pfkey_stats(u_long, const char *, int, int); 1363b8a8567SJun-ichiro itojun Hagino #endif 1373b8a8567SJun-ichiro itojun Hagino 138d4426f28SRobert Watson void mbpr(void *, u_long); 1399b50d902SRodney W. Grimes 14081dacd8bSHiroki Sato void netisr_stats(void); 1410153eb66SRobert Watson 1425e051718SAssar Westerlund void hostpr(u_long, u_long); 1435e051718SAssar Westerlund void impstats(u_long, u_long); 1449b50d902SRodney W. Grimes 14510d5269fSHiroki Sato void intpr(void (*)(char *), int); 1469b50d902SRodney W. Grimes 1475e051718SAssar Westerlund void pr_family(int); 148fc47e028SAlexander V. Chernikov void rt_stats(void); 1499b50d902SRodney W. Grimes 15010d5269fSHiroki Sato char *routename(struct sockaddr *, int); 15110d5269fSHiroki Sato const char *netname(struct sockaddr *, struct sockaddr *); 152fc47e028SAlexander V. Chernikov void routepr(int, int); 153a6663252SAlexander V. Chernikov int p_sockaddr(const char *name, struct sockaddr *sa, 154a6663252SAlexander V. Chernikov struct sockaddr *mask, int flags, int width); 155a6663252SAlexander V. Chernikov const char *fmt_sockaddr(struct sockaddr *sa, struct sockaddr *mask, 156a6663252SAlexander V. Chernikov int flags); 1579b50d902SRodney W. Grimes 158690f477dSSam Leffler #ifdef NETGRAPH 159feda1a43SJohn Baldwin void netgraphprotopr(u_long, const char *, int, int); 160690f477dSSam Leffler #endif 1614cf49a43SJulian Elischer 162ade9ccfeSMarcel Moolenaar void unixpr(u_long, u_long, u_long, u_long, u_long, bool *); 1639b50d902SRodney W. Grimes 164fc47e028SAlexander V. Chernikov void mroutepr(void); 165fc47e028SAlexander V. Chernikov void mrt_stats(void); 1666b463eedSChristian S.J. Peron void bpf_stats(char *); 167a6663252SAlexander V. Chernikov void nhops_print(int fibnum, int af); 168fedeb08bSAlexander V. Chernikov void nhgrp_print(int fibnum, int af); 169