Index: head/usr.bin/netstat/Makefile =================================================================== --- head/usr.bin/netstat/Makefile (revision 62583) +++ head/usr.bin/netstat/Makefile (revision 62584) @@ -1,17 +1,18 @@ # $FreeBSD$ # @(#)Makefile 8.1 (Berkeley) 6/12/93 PROG= netstat SRCS= if.c inet.c inet6.c main.c mbuf.c mroute.c ipx.c route.c \ - unix.c atalk.c netgraph.c mroute6.c # iso.c ns.c tp_astring.c + unix.c atalk.c netgraph.c mroute6.c ipsec.c # iso.c ns.c tp_astring.c CFLAGS+=-Wall +CFLAGS+=-DIPSEC #CFLAGS+=-g #.PATH: ${.CURDIR}/../../sys/netiso BINGRP= kmem BINMODE=2555 DPADD= ${LIBKVM} ${LIBIPX} ${LIBNETGRAPH} LDADD= -lkvm -lipx -lnetgraph CFLAGS+=-DINET6 -DIPSEC .include Index: head/usr.bin/netstat/inet.c =================================================================== --- head/usr.bin/netstat/inet.c (revision 62583) +++ head/usr.bin/netstat/inet.c (revision 62584) @@ -1,858 +1,752 @@ /* * 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. * 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. */ #ifndef lint /* static char sccsid[] = "@(#)inet.c 8.5 (Berkeley) 5/24/95"; */ static const char rcsid[] = "$FreeBSD$"; #endif /* not lint */ #include #include #include #include #include #include #include #include #include #include #ifdef INET6 #include #endif /* INET6 */ #include #include #include #include #include #include #include #include #define TCPSTATES #include #include #include #include #include #include -#ifdef IPSEC -#include -#endif #include #include #include #include #include #include #include #include #include "netstat.h" char *inetname __P((struct in_addr *)); void inetprint __P((struct in_addr *, int, char *, int)); #ifdef INET6 extern void inet6print __P((struct in6_addr *, int, char *, int)); static int udp_done, tcp_done; #endif /* INET6 */ /* * 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(proto, name, af) u_long proto; /* for sysctl version we pass proto # */ char *name; int af; { int istcp; static int first = 1; char *buf; const char *mibvar; struct tcpcb *tp = NULL; struct inpcb *inp; struct xinpgen *xig, *oxig; struct xsocket *so; size_t len; istcp = 0; switch (proto) { case IPPROTO_TCP: #ifdef INET6 if (tcp_done != 0) return; else tcp_done = 1; #endif istcp = 1; mibvar = "net.inet.tcp.pcblist"; break; case IPPROTO_UDP: #ifdef INET6 if (udp_done != 0) return; else udp_done = 1; #endif mibvar = "net.inet.udp.pcblist"; break; case IPPROTO_DIVERT: mibvar = "net.inet.divert.pcblist"; break; default: mibvar = "net.inet.raw.pcblist"; break; } len = 0; if (sysctlbyname(mibvar, 0, &len, 0, 0) < 0) { if (errno != ENOENT) warn("sysctl: %s", mibvar); return; } if ((buf = malloc(len)) == 0) { warn("malloc %lu bytes", (u_long)len); return; } if (sysctlbyname(mibvar, buf, &len, 0, 0) < 0) { warn("sysctl: %s", mibvar); free(buf); 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) { 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; } /* 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 ((af == AF_INET && (inp->inp_vflag & INP_IPV4) == 0) #ifdef INET6 || (af == AF_INET6 && (inp->inp_vflag & INP_IPV6) == 0) #endif /* INET6 */ || (af == AF_UNSPEC && ((inp->inp_vflag & INP_IPV4) == 0 #ifdef INET6 && (inp->inp_vflag & INP_IPV6) == 0 #endif /* INET6 */ )) ) continue; if (!aflag && ( (af == AF_INET && inet_lnaof(inp->inp_laddr) == INADDR_ANY) #ifdef INET6 || (af == AF_INET6 && IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)) #endif /* INET6 */ || (af == 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("%-8.8s ", "Socket"); if (Lflag) printf("%-14.14s %-22.22s\n", "Listen", "Local Address"); else printf(Aflag ? "%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s %s\n" : "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n", "Proto", "Recv-Q", "Send-Q", "Local Address", "Foreign Address", "(state)"); first = 0; } if (Aflag) { if (istcp) printf("%8lx ", (u_long)inp->inp_ppcb); else printf("%8lx ", (u_long)so->so_pcb); } if (Lflag) if (so->so_qlimit) { char buf[15]; snprintf(buf, 15, "%d/%d/%d", so->so_qlen, so->so_incqlen, so->so_qlimit); printf("%-14.14s ", buf); } else continue; else { const u_char *vchar; #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 " : " "; printf("%-3.3s%-2.2s %6ld %6ld ", name, vchar, so->so_rcv.sb_cc, so->so_snd.sb_cc); } if (nflag) { 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 (istcp && !Lflag) { 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) */ } } 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", name); } } free(buf); } /* * Dump TCP statistics structure. */ void tcp_stats(off, name) u_long off; char *name; { struct tcpstat tcpstat; size_t len = sizeof tcpstat; if (sysctlbyname("net.inet.tcp.stats", &tcpstat, &len, 0, 0) < 0) { warn("sysctl: net.inet.tcp.stats"); return; } #ifdef INET6 if (tcp_done != 0) return; else tcp_done = 1; #endif printf ("%s:\n", name); #define p(f, m) if (tcpstat.f || sflag <= 1) \ printf(m, tcpstat.f, plural(tcpstat.f)) #define p1a(f, m) if (tcpstat.f || sflag <= 1) \ printf(m, tcpstat.f) #define p2(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) \ printf(m, tcpstat.f1, plural(tcpstat.f1), tcpstat.f2, plural(tcpstat.f2)) #define p2a(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) \ printf(m, tcpstat.f1, plural(tcpstat.f1), tcpstat.f2) #define p3(f, m) if (tcpstat.f || sflag <= 1) \ printf(m, tcpstat.f, plurales(tcpstat.f)) p(tcps_sndtotal, "\t%lu packet%s sent\n"); p2(tcps_sndpack,tcps_sndbyte, "\t\t%lu data packet%s (%lu byte%s)\n"); p2(tcps_sndrexmitpack, tcps_sndrexmitbyte, "\t\t%lu data packet%s (%lu byte%s) retransmitted\n"); p(tcps_mturesent, "\t\t%lu resend%s initiated by MTU discovery\n"); p2a(tcps_sndacks, tcps_delack, "\t\t%lu ack-only packet%s (%lu delayed)\n"); p(tcps_sndurg, "\t\t%lu URG only packet%s\n"); p(tcps_sndprobe, "\t\t%lu window probe packet%s\n"); p(tcps_sndwinup, "\t\t%lu window update packet%s\n"); p(tcps_sndctrl, "\t\t%lu control packet%s\n"); p(tcps_rcvtotal, "\t%lu packet%s received\n"); p2(tcps_rcvackpack, tcps_rcvackbyte, "\t\t%lu ack%s (for %lu byte%s)\n"); p(tcps_rcvdupack, "\t\t%lu duplicate ack%s\n"); p(tcps_rcvacktoomuch, "\t\t%lu ack%s for unsent data\n"); p2(tcps_rcvpack, tcps_rcvbyte, "\t\t%lu packet%s (%lu byte%s) received in-sequence\n"); p2(tcps_rcvduppack, tcps_rcvdupbyte, "\t\t%lu completely duplicate packet%s (%lu byte%s)\n"); p(tcps_pawsdrop, "\t\t%lu old duplicate packet%s\n"); p2(tcps_rcvpartduppack, tcps_rcvpartdupbyte, "\t\t%lu packet%s with some dup. data (%lu byte%s duped)\n"); p2(tcps_rcvoopack, tcps_rcvoobyte, "\t\t%lu out-of-order packet%s (%lu byte%s)\n"); p2(tcps_rcvpackafterwin, tcps_rcvbyteafterwin, "\t\t%lu packet%s (%lu byte%s) of data after window\n"); p(tcps_rcvwinprobe, "\t\t%lu window probe%s\n"); p(tcps_rcvwinupd, "\t\t%lu window update packet%s\n"); p(tcps_rcvafterclose, "\t\t%lu packet%s received after close\n"); p(tcps_rcvbadsum, "\t\t%lu discarded for bad checksum%s\n"); p(tcps_rcvbadoff, "\t\t%lu discarded for bad header offset field%s\n"); p1a(tcps_rcvshort, "\t\t%lu discarded because packet too short\n"); p(tcps_connattempt, "\t%lu connection request%s\n"); p(tcps_accepts, "\t%lu connection accept%s\n"); p(tcps_badsyn, "\t%lu bad connection attempt%s\n"); p(tcps_listendrop, "\t%lu listen queue overflow%s\n"); p(tcps_connects, "\t%lu connection%s established (including accepts)\n"); p2(tcps_closed, tcps_drops, "\t%lu connection%s closed (including %lu drop%s)\n"); p(tcps_cachedrtt, "\t\t%lu connection%s updated cached RTT on close\n"); p(tcps_cachedrttvar, "\t\t%lu connection%s updated cached RTT variance on close\n"); p(tcps_cachedssthresh, "\t\t%lu connection%s updated cached ssthresh on close\n"); p(tcps_conndrops, "\t%lu embryonic connection%s dropped\n"); p2(tcps_rttupdated, tcps_segstimed, "\t%lu segment%s updated rtt (of %lu attempt%s)\n"); p(tcps_rexmttimeo, "\t%lu retransmit timeout%s\n"); p(tcps_timeoutdrop, "\t\t%lu connection%s dropped by rexmit timeout\n"); p(tcps_persisttimeo, "\t%lu persist timeout%s\n"); p(tcps_persistdrop, "\t\t%lu connection%s dropped by persist timeout\n"); p(tcps_keeptimeo, "\t%lu keepalive timeout%s\n"); p(tcps_keepprobe, "\t\t%lu keepalive probe%s sent\n"); p(tcps_keepdrops, "\t\t%lu connection%s dropped by keepalive\n"); p(tcps_predack, "\t%lu correct ACK header prediction%s\n"); p(tcps_preddat, "\t%lu correct data packet header prediction%s\n"); #undef p #undef p1a #undef p2 #undef p2a #undef p3 } /* * Dump UDP statistics structure. */ void udp_stats(off, name) u_long off; char *name; { struct udpstat udpstat; size_t len = sizeof udpstat; u_long delivered; if (sysctlbyname("net.inet.udp.stats", &udpstat, &len, 0, 0) < 0) { warn("sysctl: net.inet.udp.stats"); return; } #ifdef INET6 if (udp_done != 0) return; else udp_done = 1; #endif printf("%s:\n", name); #define p(f, m) if (udpstat.f || sflag <= 1) \ printf(m, udpstat.f, plural(udpstat.f)) #define p1a(f, m) if (udpstat.f || sflag <= 1) \ printf(m, udpstat.f) p(udps_ipackets, "\t%lu datagram%s received\n"); p1a(udps_hdrops, "\t%lu with incomplete header\n"); p1a(udps_badlen, "\t%lu with bad data length field\n"); p1a(udps_badsum, "\t%lu with bad checksum\n"); p1a(udps_noport, "\t%lu dropped due to no socket\n"); p(udps_noportbcast, "\t%lu broadcast/multicast datagram%s dropped due to no socket\n"); p1a(udps_fullsock, "\t%lu dropped due to full socket buffers\n"); p1a(udpps_pcbhashmiss, "\t%lu 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%lu delivered\n", delivered); p(udps_opackets, "\t%lu datagram%s output\n"); #undef p #undef p1a } /* * Dump IP statistics structure. */ void ip_stats(off, name) u_long off; char *name; { struct ipstat ipstat; size_t len = sizeof ipstat; if (sysctlbyname("net.inet.ip.stats", &ipstat, &len, 0, 0) < 0) { warn("sysctl: net.inet.ip.stats"); return; } printf("%s:\n", name); #define p(f, m) if (ipstat.f || sflag <= 1) \ printf(m, ipstat.f, plural(ipstat.f)) #define p1a(f, m) if (ipstat.f || sflag <= 1) \ printf(m, ipstat.f) p(ips_total, "\t%lu total packet%s received\n"); p(ips_badsum, "\t%lu bad header checksum%s\n"); p1a(ips_toosmall, "\t%lu with size smaller than minimum\n"); p1a(ips_tooshort, "\t%lu with data size < data length\n"); p1a(ips_toolong, "\t%lu with ip length > max ip packet size\n"); p1a(ips_badhlen, "\t%lu with header length < data size\n"); p1a(ips_badlen, "\t%lu with data length < header length\n"); p1a(ips_badoptions, "\t%lu with bad options\n"); p1a(ips_badvers, "\t%lu with incorrect version number\n"); p(ips_fragments, "\t%lu fragment%s received\n"); p(ips_fragdropped, "\t%lu fragment%s dropped (dup or out of space)\n"); p(ips_fragtimeout, "\t%lu fragment%s dropped after timeout\n"); p(ips_reassembled, "\t%lu packet%s reassembled ok\n"); p(ips_delivered, "\t%lu packet%s for this host\n"); p(ips_noproto, "\t%lu packet%s for unknown/unsupported protocol\n"); p(ips_forward, "\t%lu packet%s forwarded"); p(ips_fastforward, " (%lu packet%s fast forwarded)"); if (ipstat.ips_forward || sflag <= 1) putchar('\n'); p(ips_cantforward, "\t%lu packet%s not forwardable\n"); p(ips_notmember, "\t%lu packet%s received for unknown multicast group\n"); p(ips_redirectsent, "\t%lu redirect%s sent\n"); p(ips_localout, "\t%lu packet%s sent from this host\n"); p(ips_rawout, "\t%lu packet%s sent with fabricated ip header\n"); p(ips_odropped, "\t%lu output packet%s dropped due to no bufs, etc.\n"); p(ips_noroute, "\t%lu output packet%s discarded due to no route\n"); p(ips_fragmented, "\t%lu output datagram%s fragmented\n"); p(ips_ofragments, "\t%lu fragment%s created\n"); p(ips_cantfrag, "\t%lu datagram%s that can't be fragmented\n"); p(ips_nogif, "\t%lu tunneling packet%s that can't find gif\n"); #undef p #undef p1a } static char *icmpnames[] = { "echo reply", "#1", "#2", "destination unreachable", "source quench", "routing redirect", "#6", "#7", "echo", "router advertisement", "router solicitation", "time exceeded", "parameter problem", "time stamp", "time stamp reply", "information request", "information request reply", "address mask request", "address mask reply", }; /* * Dump ICMP statistics. */ void icmp_stats(off, name) u_long off; char *name; { struct icmpstat icmpstat; int i, first; int mib[4]; /* CTL_NET + PF_INET + IPPROTO_ICMP + req */ size_t len; mib[0] = CTL_NET; mib[1] = PF_INET; mib[2] = IPPROTO_ICMP; mib[3] = ICMPCTL_STATS; len = sizeof icmpstat; memset(&icmpstat, 0, len); if (sysctl(mib, 4, &icmpstat, &len, (void *)0, 0) < 0) return; /* XXX should complain, but not traditional */ 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) p(icps_error, "\t%lu call%s to icmp_error\n"); p(icps_oldicmp, "\t%lu error%s not generated 'cuz old message was icmp\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; } printf("\t\t%s: %lu\n", icmpnames[i], icmpstat.icps_outhist[i]); } p(icps_badcode, "\t%lu message%s with bad code fields\n"); p(icps_tooshort, "\t%lu message%s < minimum length\n"); p(icps_checksum, "\t%lu bad checksum%s\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; } printf("\t\t%s: %lu\n", icmpnames[i], icmpstat.icps_inhist[i]); } p(icps_reflect, "\t%lu message response%s generated\n"); #undef p #undef p1a mib[3] = ICMPCTL_MASKREPL; len = sizeof i; if (sysctl(mib, 4, &i, &len, (void *)0, 0) < 0) return; printf("\tICMP address mask responses are %sabled\n", i ? "en" : "dis"); } /* * Dump IGMP statistics structure. */ void igmp_stats(off, name) u_long off; char *name; { struct igmpstat igmpstat; size_t len = sizeof igmpstat; if (sysctlbyname("net.inet.igmp.stats", &igmpstat, &len, 0, 0) < 0) { warn("sysctl: net.inet.igmp.stats"); return; } printf("%s:\n", name); #define p(f, m) if (igmpstat.f || sflag <= 1) \ printf(m, igmpstat.f, plural(igmpstat.f)) #define py(f, m) if (igmpstat.f || sflag <= 1) \ printf(m, igmpstat.f, igmpstat.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 } - -#ifdef IPSEC -static char *ipsec_ahnames[] = { - "none", - "hmac MD5", - "hmac SHA1", - "keyed MD5", - "keyed SHA1", - "null", -}; - -static char *ipsec_espnames[] = { - "none", - "DES CBC", - "3DES CBC", - "simple", - "blowfish CBC", - "CAST128 CBC", - "RC5 CBC", -}; - -/* - * Dump IPSEC statistics structure. - */ -void -ipsec_stats(off, name) - u_long off; - char *name; -{ - struct ipsecstat ipsecstat; - int first, proto; - - if (off == 0) - return; - printf ("%s:\n", name); - kread(off, (char *)&ipsecstat, sizeof (ipsecstat)); - -#define p(f, m) if (ipsecstat.f || sflag <= 1) \ - printf(m, ipsecstat.f, plural(ipsecstat.f)) - - p(in_success, "\t%lu inbound packet%s processed successfully\n"); - p(in_polvio, "\t%lu inbound packet%s violated process security " - "policy\n"); - p(in_nosa, "\t%lu inbound packet%s with no SA available\n"); - p(in_inval, "\t%lu inbound packet%s failed processing due to EINVAL\n"); - p(in_badspi, "\t%lu inbound packet%s failed getting SPI\n"); - p(in_ahreplay, "\t%lu inbound packet%s failed on AH replay check\n"); - p(in_espreplay, "\t%lu inbound packet%s failed on ESP replay check\n"); - p(in_ahauthsucc, "\t%lu inbound AH packet%s considered authentic\n"); - p(in_ahauthfail, "\t%lu inbound AH packet%s failed on authentication\n"); - p(in_espauthsucc, "\t%lu inbound ESP packet%s considered authentic\n"); - p(in_espauthfail, "\t%lu inbound ESP packet%s failed on authentication\n"); - for (first = 1, proto = 0; proto < SADB_AALG_MAX; proto++) { - if (ipsecstat.in_ahhist[proto] <= 0) - continue; - if (first) { - printf("\tAH input histogram:\n"); - first = 0; - } - printf("\t\t%s: %lu\n", ipsec_ahnames[proto], - ipsecstat.in_ahhist[proto]); - } - for (first = 1, proto = 0; proto < SADB_EALG_MAX; proto++) { - if (ipsecstat.in_esphist[proto] <= 0) - continue; - if (first) { - printf("\tESP input histogram:\n"); - first = 0; - } - printf("\t\t%s: %lu\n", ipsec_espnames[proto], - ipsecstat.in_esphist[proto]); - } - - p(out_success, "\t%lu outbound packet%s processed successfully\n"); - p(out_polvio, "\t%lu outbound packet%s violated process security " - "policy\n"); - p(out_nosa, "\t%lu outbound packet%s with no SA available\n"); - p(out_inval, "\t%lu outbound packet%s failed processing due to " - "EINVAL\n"); - p(out_noroute, "\t%lu outbound packet%s with no route\n"); - for (first = 1, proto = 0; proto < SADB_AALG_MAX; proto++) { - if (ipsecstat.out_ahhist[proto] <= 0) - continue; - if (first) { - printf("\tAH output histogram:\n"); - first = 0; - } - printf("\t\t%s: %lu\n", ipsec_ahnames[proto], - ipsecstat.out_ahhist[proto]); - } - for (first = 1, proto = 0; proto < SADB_EALG_MAX; proto++) { - if (ipsecstat.out_esphist[proto] <= 0) - continue; - if (first) { - printf("\tESP output histogram:\n"); - first = 0; - } - printf("\t\t%s: %lu\n", ipsec_espnames[proto], - ipsecstat.out_esphist[proto]); - } -#undef p -} -#endif /*IPSEC*/ /* * Pretty print an Internet address (net address + port). */ void inetprint(in, port, proto,numeric) register struct in_addr *in; int port; char *proto; int numeric; { struct servent *sp = 0; char line[80], *cp; int width; sprintf(line, "%.*s.", (Aflag && !numeric) ? 12 : 16, inetname(in)); cp = index(line, '\0'); if (!numeric && 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 ? 18 : 22; printf("%-*.*s ", width, width, line); } /* * Construct an Internet address representation. * If the nflag has been supplied, give * numeric value, otherwise try for symbolic name. */ char * inetname(inp) struct in_addr *inp; { register char *cp; static char line[MAXHOSTNAMELEN + 1]; struct hostent *hp; struct netent *np; cp = 0; if (!nflag && 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); } } } if (inp->s_addr == INADDR_ANY) strcpy(line, "*"); else if (cp) { strncpy(line, cp, sizeof(line) - 1); line[sizeof(line) - 1] = '\0'; } 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: head/usr.bin/netstat/inet6.c =================================================================== --- head/usr.bin/netstat/inet6.c (revision 62583) +++ head/usr.bin/netstat/inet6.c (revision 62584) @@ -1,953 +1,1079 @@ /* 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. * 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. * * $FreeBSD$ */ #ifndef lint /* static char sccsid[] = "@(#)inet6.c 8.4 (Berkeley) 4/20/94"; */ #endif /* not lint */ #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 __P((struct in6_addr *)); void inet6print __P((struct in6_addr *, int, char *, int)); static char ntop_buf[INET6_ADDRSTRLEN]; static 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", "#62", "#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", - "#89", + "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", }; /* * Dump IP6 statistics structure. */ void ip6_stats(off, name) u_long off; char *name; { struct ip6stat ip6stat; int first, i; if (off == 0) return; kread(off, (char *)&ip6stat, sizeof (ip6stat)); printf("%s:\n", name); #define p(f, m) if (ip6stat.f || sflag <= 1) \ - printf(m, ip6stat.f, plural(ip6stat.f)) + printf(m, (unsigned long long)ip6stat.f, plural(ip6stat.f)) #define p1a(f, m) if (ip6stat.f || sflag <= 1) \ - printf(m, ip6stat.f) + printf(m, (unsigned long long)ip6stat.f) - p(ip6s_total, "\t%lu total packet%s received\n"); - p1a(ip6s_toosmall, "\t%lu with size smaller than minimum\n"); - p1a(ip6s_tooshort, "\t%lu with data size < data length\n"); - p1a(ip6s_badoptions, "\t%lu with bad options\n"); - p1a(ip6s_badvers, "\t%lu with incorrect version number\n"); - p(ip6s_fragments, "\t%lu fragment%s received\n"); - p(ip6s_fragdropped, "\t%lu fragment%s dropped (dup or out of space)\n"); - p(ip6s_fragtimeout, "\t%lu fragment%s dropped after timeout\n"); - p(ip6s_fragoverflow, "\t%lu fragment%s that exceeded limit\n"); - p(ip6s_reassembled, "\t%lu packet%s reassembled ok\n"); - p(ip6s_delivered, "\t%lu packet%s for this host\n"); - p(ip6s_forward, "\t%lu packet%s forwarded\n"); - p(ip6s_cantforward, "\t%lu packet%s not forwardable\n"); - p(ip6s_redirectsent, "\t%lu redirect%s sent\n"); - p(ip6s_localout, "\t%lu packet%s sent from this host\n"); - p(ip6s_rawout, "\t%lu packet%s sent with fabricated ip header\n"); - p(ip6s_odropped, "\t%lu output packet%s dropped due to no bufs, etc.\n"); - p(ip6s_noroute, "\t%lu output packet%s discarded due to no route\n"); - p(ip6s_fragmented, "\t%lu output datagram%s fragmented\n"); - p(ip6s_ofragments, "\t%lu fragment%s created\n"); - p(ip6s_cantfrag, "\t%lu datagram%s that can't be fragmented\n"); - p(ip6s_badscope, "\t%lu packet%s that violated scope rules\n"); - p(ip6s_notmember, "\t%lu multicast packet%s which we don't join\n"); + p(ip6s_total, "\t%llu total packet%s received\n"); + p1a(ip6s_toosmall, "\t%llu with size smaller than minimum\n"); + p1a(ip6s_tooshort, "\t%llu with data size < data length\n"); + p1a(ip6s_badoptions, "\t%llu with bad options\n"); + p1a(ip6s_badvers, "\t%llu with incorrect version number\n"); + p(ip6s_fragments, "\t%llu fragment%s received\n"); + p(ip6s_fragdropped, "\t%llu fragment%s dropped (dup or out of space)\n"); + p(ip6s_fragtimeout, "\t%llu fragment%s dropped after timeout\n"); + p(ip6s_fragoverflow, "\t%llu fragment%s that exceeded limit\n"); + p(ip6s_reassembled, "\t%llu packet%s reassembled ok\n"); + p(ip6s_delivered, "\t%llu packet%s for this host\n"); + p(ip6s_forward, "\t%llu packet%s forwarded\n"); + p(ip6s_cantforward, "\t%llu packet%s not forwardable\n"); + p(ip6s_redirectsent, "\t%llu redirect%s sent\n"); + p(ip6s_localout, "\t%llu packet%s sent from this host\n"); + p(ip6s_rawout, "\t%llu packet%s sent with fabricated ip header\n"); + p(ip6s_odropped, "\t%llu output packet%s dropped due to no bufs, etc.\n"); + p(ip6s_noroute, "\t%llu output packet%s discarded due to no route\n"); + p(ip6s_fragmented, "\t%llu output datagram%s fragmented\n"); + p(ip6s_ofragments, "\t%llu fragment%s created\n"); + p(ip6s_cantfrag, "\t%llu datagram%s that can't be fragmented\n"); + p(ip6s_badscope, "\t%llu packet%s that violated scope rules\n"); + p(ip6s_notmember, "\t%llu multicast packet%s which we don't join\n"); for (first = 1, i = 0; i < 256; i++) if (ip6stat.ip6s_nxthist[i] != 0) { if (first) { printf("\tInput histogram:\n"); first = 0; } - printf("\t\t%s: %lu\n", ip6nh[i], - ip6stat.ip6s_nxthist[i]); + printf("\t\t%s: %llu\n", ip6nh[i], + (unsigned long long)ip6stat.ip6s_nxthist[i]); } printf("\tMbuf statistics:\n"); - printf("\t\t%lu one mbuf\n", ip6stat.ip6s_m1); + printf("\t\t%llu one mbuf\n", (unsigned long long)ip6stat.ip6s_m1); for (first = 1, i = 0; i < 32; 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= %ld\n", - if_indextoname(i, ifbuf), - ip6stat.ip6s_m2m[i]); + printf("\t\t\t%s= %llu\n", + if_indextoname(i, ifbuf), + (unsigned long long)ip6stat.ip6s_m2m[i]); } } - printf("\t\t%lu one ext mbuf\n", ip6stat.ip6s_mext1); - printf("\t\t%lu two or more ext mbuf\n", ip6stat.ip6s_mext2m); - p(ip6s_exthdrtoolong, "\t%lu packet%s whose headers are not continuous\n"); - p(ip6s_nogif, "\t%lu tunneling packet%s that can't find gif\n"); - p(ip6s_toomanyhdr, "\t%lu packet%s discarded due to too may headers\n"); + printf("\t\t%llu one ext mbuf\n", + (unsigned long long)ip6stat.ip6s_mext1); + printf("\t\t%llu two or more ext mbuf\n", + (unsigned long long)ip6stat.ip6s_mext2m); + p(ip6s_exthdrtoolong, + "\t%llu packet%s whose headers are not continuous\n"); + p(ip6s_nogif, "\t%llu tunneling packet%s that can't find gif\n"); + p(ip6s_toomanyhdr, + "\t%llu packet%s discarded due to too may headers\n"); + + if (ip6stat.ip6s_exthdrget || ip6stat.ip6s_exthdrget0) { + p(ip6s_exthdrget, "\t%llu use%s of IP6_EXTHDR_GET\n"); + p(ip6s_exthdrget0, "\t%llu use%s of IP6_EXTHDR_GET0\n"); + p(ip6s_pulldown, "\t%llu call%s to m_pulldown\n"); + p(ip6s_pulldown_alloc, + "\t%llu mbuf allocation%s in m_pulldown\n"); + if (ip6stat.ip6s_pulldown_copy != 1) { + p1a(ip6s_pulldown_copy, + "\t%llu mbuf copies in m_pulldown\n"); + } else { + p1a(ip6s_pulldown_copy, + "\t%llu mbuf copy in m_pulldown\n"); + } + p(ip6s_pullup, "\t%llu call%s to m_pullup\n"); + p(ip6s_pullup_alloc, "\t%llu mbuf allocation%s in m_pullup\n"); + if (ip6stat.ip6s_pullup_copy != 1) { + p1a(ip6s_pullup_copy, "\t%llu mbuf copies in m_pullup\n"); + } else { + p1a(ip6s_pullup_copy, "\t%llu mbuf copy in m_pullup\n"); + } + p(ip6s_pullup_fail, "\t%llu failure%s in m_pullup\n"); + p(ip6s_pullup2, "\t%llu call%s to m_pullup2\n"); + p(ip6s_pullup2_alloc, "\t%llu mbuf allocation%s in m_pullup2\n"); + if (ip6stat.ip6s_pullup2_copy != 1) { + p1a(ip6s_pullup2_copy, + "\t%llu mbuf copies in m_pullup2\n"); + } else { + p1a(ip6s_pullup2_copy, "\t%llu mbuf copy in m_pullup2\n"); + } + p(ip6s_pullup2_fail, "\t%llu failure%s in m_pullup2\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%llu node-local%s\n");\ + break;\ + case 2:\ + p(s,"\t\t%llu link-local%s\n");\ + break;\ + case 5:\ + p(s,"\t\t%llu site-local%s\n");\ + break;\ + case 14:\ + p(s,"\t\t%llu global%s\n");\ + break;\ + default:\ + printf("\t\t%llu addresses scope=%x\n",\ + (unsigned long long)ip6stat.s, i);\ + }\ + } while (0); + + p(ip6s_sources_none, + "\t%llu failure%s of source address selection\n"); + for (first = 1, i = 0; i < 16; 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 < 16; 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 < 16; 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 < 16; 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 < 16; i++) { + if (ip6stat.ip6s_sources_deprecated[i]) { + if (first) { + printf("\tdeprecated source addresses\n"); + first = 0; + } + PRINT_SCOPESTAT(ip6s_sources_deprecated[i], i); + } + } + + p1a(ip6s_forward_cachehit, "\t%llu forward cache hit\n"); + p1a(ip6s_forward_cachemiss, "\t%llu forward cache miss\n"); #undef p +#undef p1a } /* * Dump IPv6 per-interface statistics based on RFC 2465. */ void ip6_ifstats(ifname) char *ifname; { struct in6_ifreq ifr; int s; #define p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \ - printf(m, ifr.ifr_ifru.ifru_stat.f, plural(ifr.ifr_ifru.ifru_stat.f)) + printf(m, (unsigned long long)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, ip6stat.f) + printf(m, (unsigned long long)ip6stat.f) if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { perror("Warning: socket(AF_INET6)"); return; } strcpy(ifr.ifr_name, ifname); printf("ip6 on %s:\n", ifr.ifr_name); if (ioctl(s, SIOCGIFSTAT_IN6, (char *)&ifr) < 0) { perror("Warning: ioctl(SIOCGIFSTAT_IN6)"); goto end; } - p(ifs6_in_receive, "\t%qu total input datagram%s\n"); - p(ifs6_in_hdrerr, "\t%qu datagram%s with invalid header received\n"); - p(ifs6_in_toobig, "\t%qu datagram%s exceeded MTU received\n"); - p(ifs6_in_noroute, "\t%qu datagram%s with no route received\n"); - p(ifs6_in_addrerr, "\t%qu datagram%s with invalid dst received\n"); - p(ifs6_in_protounknown, "\t%qu datagram%s with unknown proto received\n"); - p(ifs6_in_truncated, "\t%qu truncated datagram%s received\n"); - p(ifs6_in_discard, "\t%qu input datagram%s discarded\n"); + p(ifs6_in_receive, "\t%llu total input datagram%s\n"); + p(ifs6_in_hdrerr, "\t%llu datagram%s with invalid header received\n"); + p(ifs6_in_toobig, "\t%llu datagram%s exceeded MTU received\n"); + p(ifs6_in_noroute, "\t%llu datagram%s with no route received\n"); + p(ifs6_in_addrerr, "\t%llu datagram%s with invalid dst received\n"); + p(ifs6_in_protounknown, "\t%llu datagram%s with unknown proto received\n"); + p(ifs6_in_truncated, "\t%llu truncated datagram%s received\n"); + p(ifs6_in_discard, "\t%llu input datagram%s discarded\n"); p(ifs6_in_deliver, - "\t%qu datagram%s delivered to an upper layer protocol\n"); - p(ifs6_out_forward, "\t%qu datagram%s forwarded to this interface\n"); + "\t%llu datagram%s delivered to an upper layer protocol\n"); + p(ifs6_out_forward, "\t%llu datagram%s forwarded to this interface\n"); p(ifs6_out_request, - "\t%qu datagram%s sent from an upper layer protocol\n"); - p(ifs6_out_discard, "\t%qu total discarded output datagram%s\n"); - p(ifs6_out_fragok, "\t%qu output datagram%s fragmented\n"); - p(ifs6_out_fragfail, "\t%qu output datagram%s failed on fragment\n"); - p(ifs6_out_fragcreat, "\t%qu output datagram%s succeeded on fragment\n"); - p(ifs6_reass_reqd, "\t%qu incoming datagram%s fragmented\n"); - p(ifs6_reass_ok, "\t%qu datagram%s reassembled\n"); - p(ifs6_reass_fail, "\t%qu datagram%s failed on reassembling\n"); - p(ifs6_in_mcast, "\t%qu multicast datagram%s received\n"); - p(ifs6_out_mcast, "\t%qu multicast datagram%s sent\n"); + "\t%llu datagram%s sent from an upper layer protocol\n"); + p(ifs6_out_discard, "\t%llu total discarded output datagram%s\n"); + p(ifs6_out_fragok, "\t%llu output datagram%s fragmented\n"); + p(ifs6_out_fragfail, "\t%llu output datagram%s failed on fragment\n"); + p(ifs6_out_fragcreat, "\t%llu output datagram%s succeeded on fragment\n"); + p(ifs6_reass_reqd, "\t%llu incoming datagram%s fragmented\n"); + p(ifs6_reass_ok, "\t%llu datagram%s reassembled\n"); + p(ifs6_reass_fail, "\t%llu datagram%s failed on reassembling\n"); + p(ifs6_in_mcast, "\t%llu multicast datagram%s received\n"); + p(ifs6_out_mcast, "\t%llu multicast datagram%s sent\n"); end: close(s); #undef p #undef p_5 } static 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", "multicast listener report", "multicast listener done", "router solicitation", "router advertisment", "neighbor solicitation", "neighbor advertisment", "redirect", "router renumbering", "node information request", "node information reply", "#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", }; /* * Dump ICMP6 statistics. */ void icmp6_stats(off, name) u_long off; char *name; { struct icmp6stat icmp6stat; register int i, first; if (off == 0) return; kread(off, (char *)&icmp6stat, sizeof (icmp6stat)); printf("%s:\n", name); #define p(f, m) if (icmp6stat.f || sflag <= 1) \ - printf(m, icmp6stat.f, plural(icmp6stat.f)) + printf(m, (unsigned long long)icmp6stat.f, plural(icmp6stat.f)) +#define p_5(f, m) printf(m, (unsigned long long)icmp6stat.f) - p(icp6s_error, "\t%lu call%s to icmp_error\n"); + p(icp6s_error, "\t%llu call%s to icmp_error\n"); p(icp6s_canterror, - "\t%lu error%s not generated because old message was icmp error or so\n"); + "\t%llu error%s not generated because old message was icmp error or so\n"); p(icp6s_toofreq, - "\t%lu error%s not generated because rate limitation\n"); + "\t%llu error%s not generated because rate limitation\n"); for (first = 1, i = 0; i < 256; i++) if (icmp6stat.icp6s_outhist[i] != 0) { if (first) { printf("\tOutput histogram:\n"); first = 0; } - printf("\t\t%s: %lu\n", icmp6names[i], - icmp6stat.icp6s_outhist[i]); + printf("\t\t%s: %llu\n", icmp6names[i], + (unsigned long long)icmp6stat.icp6s_outhist[i]); } - p(icp6s_badcode, "\t%lu message%s with bad code fields\n"); - p(icp6s_tooshort, "\t%lu message%s < minimum length\n"); - p(icp6s_checksum, "\t%lu bad checksum%s\n"); - p(icp6s_badlen, "\t%lu message%s with bad length\n"); + p(icp6s_badcode, "\t%llu message%s with bad code fields\n"); + p(icp6s_tooshort, "\t%llu message%s < minimum length\n"); + p(icp6s_checksum, "\t%llu bad checksum%s\n"); + p(icp6s_badlen, "\t%llu message%s with bad length\n"); for (first = 1, i = 0; i < ICMP6_MAXTYPE; i++) if (icmp6stat.icp6s_inhist[i] != 0) { if (first) { printf("\tInput histogram:\n"); first = 0; } - printf("\t\t%s: %lu\n", icmp6names[i], - icmp6stat.icp6s_inhist[i]); + printf("\t\t%s: %llu\n", icmp6names[i], + (unsigned long long)icmp6stat.icp6s_inhist[i]); } - p(icp6s_reflect, "\t%lu message response%s generated\n"); + printf("\tHistgram of error messages to be generated:\n"); + p_5(icp6s_odst_unreach_noroute, "\t\t%llu no route\n"); + p_5(icp6s_odst_unreach_admin, "\t\t%llu administratively prohibited\n"); + p_5(icp6s_odst_unreach_beyondscope, "\t\t%llu beyond scope\n"); + p_5(icp6s_odst_unreach_addr, "\t\t%llu address unreachable\n"); + p_5(icp6s_odst_unreach_noport, "\t\t%llu port unreachable\n"); + p_5(icp6s_opacket_too_big, "\t\t%llu packet too big\n"); + p_5(icp6s_otime_exceed_transit, "\t\t%llu time exceed transit\n"); + p_5(icp6s_otime_exceed_reassembly, "\t\t%llu time exceed reassembly\n"); + p_5(icp6s_oparamprob_header, "\t\t%llu erroneous header field\n"); + p_5(icp6s_oparamprob_nextheader, "\t\t%llu unrecognized next header\n"); + p_5(icp6s_oparamprob_option, "\t\t%llu unrecognized option\n"); + p_5(icp6s_oredirect, "\t\t%llu redirect\n"); + p_5(icp6s_ounknown, "\t\t%llu unknown\n"); + + p(icp6s_reflect, "\t%llu message response%s generated\n"); + p(icp6s_nd_toomanyopt, "\t%llu message%s with too many ND options\n"); #undef p #undef p_5 } /* * Dump ICMPv6 per-interface statistics based on RFC 2466. */ void icmp6_ifstats(ifname) char *ifname; { struct in6_ifreq ifr; int s; #define p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \ - printf(m, (u_quad_t)ifr.ifr_ifru.ifru_icmp6stat.f, plural(ifr.ifr_ifru.ifru_icmp6stat.f)) + printf(m, (unsigned long long)ifr.ifr_ifru.ifru_icmp6stat.f, plural(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); printf("icmp6 on %s:\n", ifr.ifr_name); if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) { perror("Warning: ioctl(SIOCGIFSTAT_ICMP6)"); goto end; } - p(ifs6_in_msg, "\t%qu total input message%s\n"); - p(ifs6_in_error, "\t%qu total input error message%s\n"); - p(ifs6_in_dstunreach, "\t%qu input destination unreachable error%s\n"); - p(ifs6_in_adminprohib, "\t%qu input administratively prohibited error%s\n"); - p(ifs6_in_timeexceed, "\t%qu input time exceeded error%s\n"); - p(ifs6_in_paramprob, "\t%qu input parameter problem error%s\n"); - p(ifs6_in_pkttoobig, "\t%qu input packet too big error%s\n"); - p(ifs6_in_echo, "\t%qu input echo request%s\n"); - p(ifs6_in_echoreply, "\t%qu input echo reply%s\n"); - p(ifs6_in_routersolicit, "\t%qu input router solicitation%s\n"); - p(ifs6_in_routeradvert, "\t%qu input router advertisement%s\n"); - p(ifs6_in_neighborsolicit, "\t%qu input neighbor solicitation%s\n"); - p(ifs6_in_neighboradvert, "\t%qu input neighbor advertisement%s\n"); - p(ifs6_in_redirect, "\t%qu input redirect%s\n"); - p(ifs6_in_mldquery, "\t%qu input MLD query%s\n"); - p(ifs6_in_mldreport, "\t%qu input MLD report%s\n"); - p(ifs6_in_mlddone, "\t%qu input MLD done%s\n"); + p(ifs6_in_msg, "\t%llu total input message%s\n"); + p(ifs6_in_error, "\t%llu total input error message%s\n"); + p(ifs6_in_dstunreach, "\t%llu input destination unreachable error%s\n"); + p(ifs6_in_adminprohib, "\t%llu input administratively prohibited error%s\n"); + p(ifs6_in_timeexceed, "\t%llu input time exceeded error%s\n"); + p(ifs6_in_paramprob, "\t%llu input parameter problem error%s\n"); + p(ifs6_in_pkttoobig, "\t%llu input packet too big error%s\n"); + p(ifs6_in_echo, "\t%llu input echo request%s\n"); + p(ifs6_in_echoreply, "\t%llu input echo reply%s\n"); + p(ifs6_in_routersolicit, "\t%llu input router solicitation%s\n"); + p(ifs6_in_routeradvert, "\t%llu input router advertisement%s\n"); + p(ifs6_in_neighborsolicit, "\t%llu input neighbor solicitation%s\n"); + p(ifs6_in_neighboradvert, "\t%llu input neighbor advertisement%s\n"); + p(ifs6_in_redirect, "\t%llu input redirect%s\n"); + p(ifs6_in_mldquery, "\t%llu input MLD query%s\n"); + p(ifs6_in_mldreport, "\t%llu input MLD report%s\n"); + p(ifs6_in_mlddone, "\t%llu input MLD done%s\n"); - p(ifs6_out_msg, "\t%qu total output message%s\n"); - p(ifs6_out_error, "\t%qu total output error message%s\n"); - p(ifs6_out_dstunreach, "\t%qu output destination unreachable error%s\n"); - p(ifs6_out_adminprohib, "\t%qu output administratively prohibited error%s\n"); - p(ifs6_out_timeexceed, "\t%qu output time exceeded error%s\n"); - p(ifs6_out_paramprob, "\t%qu output parameter problem error%s\n"); - p(ifs6_out_pkttoobig, "\t%qu output packet too big error%s\n"); - p(ifs6_out_echo, "\t%qu output echo request%s\n"); - p(ifs6_out_echoreply, "\t%qu output echo reply%s\n"); - p(ifs6_out_routersolicit, "\t%qu output router solicitation%s\n"); - p(ifs6_out_routeradvert, "\t%qu output router advertisement%s\n"); - p(ifs6_out_neighborsolicit, "\t%qu output neighbor solicitation%s\n"); - p(ifs6_out_neighboradvert, "\t%qu output neighbor advertisement%s\n"); - p(ifs6_out_redirect, "\t%qu output redirect%s\n"); - p(ifs6_out_mldquery, "\t%qu output MLD query%s\n"); - p(ifs6_out_mldreport, "\t%qu output MLD report%s\n"); - p(ifs6_out_mlddone, "\t%qu output MLD done%s\n"); + p(ifs6_out_msg, "\t%llu total output message%s\n"); + p(ifs6_out_error, "\t%llu total output error message%s\n"); + p(ifs6_out_dstunreach, "\t%llu output destination unreachable error%s\n"); + p(ifs6_out_adminprohib, "\t%llu output administratively prohibited error%s\n"); + p(ifs6_out_timeexceed, "\t%llu output time exceeded error%s\n"); + p(ifs6_out_paramprob, "\t%llu output parameter problem error%s\n"); + p(ifs6_out_pkttoobig, "\t%llu output packet too big error%s\n"); + p(ifs6_out_echo, "\t%llu output echo request%s\n"); + p(ifs6_out_echoreply, "\t%llu output echo reply%s\n"); + p(ifs6_out_routersolicit, "\t%llu output router solicitation%s\n"); + p(ifs6_out_routeradvert, "\t%llu output router advertisement%s\n"); + p(ifs6_out_neighborsolicit, "\t%llu output neighbor solicitation%s\n"); + p(ifs6_out_neighboradvert, "\t%llu output neighbor advertisement%s\n"); + p(ifs6_out_redirect, "\t%llu output redirect%s\n"); + p(ifs6_out_mldquery, "\t%llu output MLD query%s\n"); + p(ifs6_out_mldreport, "\t%llu output MLD report%s\n"); + p(ifs6_out_mlddone, "\t%llu output MLD done%s\n"); end: close(s); #undef p } /* * Dump PIM statistics structure. */ void pim6_stats(off, name) u_long off; char *name; { struct pim6stat pim6stat; if (off == 0) return; kread(off, (char *)&pim6stat, sizeof(pim6stat)); printf("%s:\n", name); #define p(f, m) if (pim6stat.f || sflag <= 1) \ - printf(m, pim6stat.f, plural(pim6stat.f)) - p(pim6s_rcv_total, "\t%u message%s received\n"); - p(pim6s_rcv_tooshort, "\t%u message%s received with too few bytes\n"); - p(pim6s_rcv_badsum, "\t%u message%s received with bad checksum\n"); - p(pim6s_rcv_badversion, "\t%u message%s received with bad version\n"); - p(pim6s_rcv_registers, "\t%u register%s received\n"); - p(pim6s_rcv_badregisters, "\t%u bad register%s received\n"); - p(pim6s_snd_registers, "\t%u register%s sent\n"); + printf(m, (unsigned long long)pim6stat.f, plural(pim6stat.f)) + p(pim6s_rcv_total, "\t%llu message%s received\n"); + p(pim6s_rcv_tooshort, "\t%llu message%s received with too few bytes\n"); + p(pim6s_rcv_badsum, "\t%llu message%s received with bad checksum\n"); + p(pim6s_rcv_badversion, "\t%llu message%s received with bad version\n"); + p(pim6s_rcv_registers, "\t%llu register%s received\n"); + p(pim6s_rcv_badregisters, "\t%llu bad register%s received\n"); + p(pim6s_snd_registers, "\t%llu register%s sent\n"); #undef p } /* * Pretty print an Internet address (net address + port). * If the nflag was specified, use numbers instead of names. */ #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(in6, port, proto, numeric) register struct in6_addr *in6; int port; char *proto; int numeric; { struct servent *sp = 0; char line[80], *cp; int width; sprintf(line, "%.*s.", lflag ? 39 : (Aflag && !numeric) ? 12 : 16, inet6name(in6)); cp = index(line, '\0'); if (!numeric && port) GETSERVBYPORT6(port, proto, sp); if (sp || port == 0) sprintf(cp, "%.8s", sp ? sp->s_name : "*"); else sprintf(cp, "%d", ntohs((u_short)port)); width = lflag ? 45 : Aflag ? 18 : 22; printf("%-*.*s ", width, width, line); } /* * Construct an Internet address representation. * If the nflag has been supplied, give * numeric value, otherwise try for symbolic name. */ char * inet6name(in6p) struct in6_addr *in6p; { register char *cp; static char line[50]; struct hostent *hp; static char domain[MAXHOSTNAMELEN + 1]; static int first = 1; if (first && !nflag) { first = 0; if (gethostname(domain, MAXHOSTNAMELEN) == 0 && (cp = index(domain, '.'))) (void) strcpy(domain, cp + 1); else domain[0] = 0; } cp = 0; if (!nflag && !IN6_IS_ADDR_UNSPECIFIED(in6p)) { hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6); if (hp) { if ((cp = index(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); } Index: head/usr.bin/netstat/ipsec.c =================================================================== --- head/usr.bin/netstat/ipsec.c (nonexistent) +++ head/usr.bin/netstat/ipsec.c (revision 62584) @@ -0,0 +1,316 @@ +/* $FreeBSD$ */ +/* $NetBSD: inet.c,v 1.35.2.1 1999/04/29 14:57:08 perry Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, 1998, and 1999 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) 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. + * 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. + */ + +#ifndef lint +/* +static char sccsid[] = "@(#)inet.c 8.5 (Berkeley) 5/24/95"; +*/ +static const char rcsid[] = + "$FreeBSD$"; +#endif /* not lint */ + +#include +#include +#include + +#include + +#ifdef IPSEC +#include +#include +#endif + +#include +#include +#include +#include "netstat.h" + +/* + * portability issues: + * - bsdi[34] uses PLURAL(), not plural(). + * - freebsd2 can't print "unsigned long long" properly. + */ +/* + * XXX see PORTABILITY for the twist + */ +#define LLU "%llu" +#define CAST unsigned long long + +#ifdef IPSEC +static const char *ipsec_ahnames[] = { + "none", + "hmac MD5", + "hmac SHA1", + "keyed MD5", + "keyed SHA1", + "null", +}; + +static const char *ipsec_espnames[] = { + "none", + "DES CBC", + "3DES CBC", + "simple", + "blowfish CBC", + "CAST128 CBC", + "DES derived IV", +}; + +static const char *ipsec_compnames[] = { + "none", + "OUI", + "deflate", + "LZS", +}; + +static const char *pfkey_msgtypenames[] = { + "reserved", "getspi", "update", "add", "delete", + "get", "acquire", "register", "expire", "flush", + "dump", "x_promisc", "x_pchange", "x_spdupdate", "x_spdadd", + "x_spddelete", "x_spdget", "x_spdacquire", "x_spddump", "x_spdflush", + "x_spdsetidx", "x_spdexpire", "x_spddelete2" +}; + +static struct ipsecstat ipsecstat; + +static void print_ipsecstats __P((void)); +static const char *pfkey_msgtype_names __P((int)); +static void ipsec_hist __P((const u_quad_t *, size_t, const char **, size_t, + const char *)); + +/* + * Dump IPSEC statistics structure. + */ +static void +ipsec_hist(hist, histmax, name, namemax, title) + const u_quad_t *hist; + size_t histmax; + const char **name; + size_t namemax; + const char *title; +{ + int first; + size_t proto; + + for (first = 1, proto = 0; proto < histmax; proto++) { + if (hist[proto] <= 0) + continue; + if (first) { + printf("\t%s histogram:\n", title); + first = 0; + } + if (proto < namemax && name[proto]) { + printf("\t\t%s: " LLU "\n", name[proto], + (CAST)hist[proto]); + } else { + printf("\t\t#%ld: " LLU "\n", (long)proto, + (CAST)hist[proto]); + } + } +} + +static void +print_ipsecstats() +{ +#define p(f, m) if (ipsecstat.f || sflag <= 1) \ + printf(m, (CAST)ipsecstat.f, plural(ipsecstat.f)) +#define hist(f, n, t) \ + ipsec_hist((f), sizeof(f)/sizeof(f[0]), (n), sizeof(n)/sizeof(n[0]), (t)); + + p(in_success, "\t" LLU " inbound packet%s processed successfully\n"); + p(in_polvio, "\t" LLU " inbound packet%s violated process security " + "policy\n"); + p(in_nosa, "\t" LLU " inbound packet%s with no SA available\n"); + p(in_inval, "\t" LLU " invalid inbound packet%s\n"); + p(in_nomem, "\t" LLU " inbound packet%s failed due to insufficient memory\n"); + p(in_badspi, "\t" LLU " inbound packet%s failed getting SPI\n"); + p(in_ahreplay, "\t" LLU " inbound packet%s failed on AH replay check\n"); + p(in_espreplay, "\t" LLU " inbound packet%s failed on ESP replay check\n"); + p(in_ahauthsucc, "\t" LLU " inbound packet%s considered authentic\n"); + p(in_ahauthfail, "\t" LLU " inbound packet%s failed on authentication\n"); + hist(ipsecstat.in_ahhist, ipsec_ahnames, "AH input"); + hist(ipsecstat.in_esphist, ipsec_espnames, "ESP input"); + hist(ipsecstat.in_comphist, ipsec_compnames, "IPComp input"); + + p(out_success, "\t" LLU " outbound packet%s processed successfully\n"); + p(out_polvio, "\t" LLU " outbound packet%s violated process security " + "policy\n"); + p(out_nosa, "\t" LLU " outbound packet%s with no SA available\n"); + p(out_inval, "\t" LLU " invalid outbound packet%s\n"); + p(out_nomem, "\t" LLU " outbound packet%s failed due to insufficient memory\n"); + p(out_noroute, "\t" LLU " outbound packet%s with no route\n"); + hist(ipsecstat.out_ahhist, ipsec_ahnames, "AH output"); + hist(ipsecstat.out_esphist, ipsec_espnames, "ESP output"); + hist(ipsecstat.out_comphist, ipsec_compnames, "IPComp output"); +#undef p +#undef hist +} + +void +ipsec_stats(off, name) + u_long off; + char *name; +{ + if (off == 0) + return; + printf ("%s:\n", name); + kread(off, (char *)&ipsecstat, sizeof (ipsecstat)); + + print_ipsecstats(); +} + +#if defined(__bsdi__) && _BSDI_VERSION >= 199802 /* bsdi4 only */ +void +ipsec_stats0(name) + char *name; +{ + printf("%s:\n", name); + + skread(name, &ipsecstat_info); + + print_ipsecstats(); +} +#endif + +static const char * +pfkey_msgtype_names(x) + int x; +{ + const int max = + sizeof(pfkey_msgtypenames)/sizeof(pfkey_msgtypenames[0]); + static char buf[10]; + + if (x < max && pfkey_msgtypenames[x]) + return pfkey_msgtypenames[x]; + snprintf(buf, sizeof(buf), "#%d", x); + return buf; +} + +void +pfkey_stats(off, name) + u_long off; + char *name; +{ + struct pfkeystat pfkeystat; + int first, type; + + if (off == 0) + return; + printf ("%s:\n", name); + kread(off, (char *)&pfkeystat, sizeof(pfkeystat)); + +#define p(f, m) if (pfkeystat.f || sflag <= 1) \ + printf(m, (CAST)pfkeystat.f, plural(pfkeystat.f)) + + /* kernel -> userland */ + p(out_total, "\t" LLU " request%s sent to userland\n"); + p(out_bytes, "\t" LLU " byte%s sent to userland\n"); + for (first = 1, type = 0; + type < sizeof(pfkeystat.out_msgtype)/sizeof(pfkeystat.out_msgtype[0]); + type++) { + if (pfkeystat.out_msgtype[type] <= 0) + continue; + if (first) { + printf("\thistogram by message type:\n"); + first = 0; + } + printf("\t\t%s: " LLU "\n", pfkey_msgtype_names(type), + (CAST)pfkeystat.out_msgtype[type]); + } + p(out_invlen, "\t" LLU " message%s with invalid length field\n"); + p(out_invver, "\t" LLU " message%s with invalid version field\n"); + p(out_invmsgtype, "\t" LLU " message%s with invalid message type field\n"); + p(out_tooshort, "\t" LLU " message%s too short\n"); + p(out_nomem, "\t" LLU " message%s with memory allocation failure\n"); + p(out_dupext, "\t" LLU " message%s with duplicate extension\n"); + p(out_invexttype, "\t" LLU " message%s with invalid extension type\n"); + p(out_invsatype, "\t" LLU " message%s with invalid sa type\n"); + p(out_invaddr, "\t" LLU " message%s with invalid address extension\n"); + + /* userland -> kernel */ + p(in_total, "\t" LLU " request%s sent from userland\n"); + p(in_bytes, "\t" LLU " byte%s sent from userland\n"); + for (first = 1, type = 0; + type < sizeof(pfkeystat.in_msgtype)/sizeof(pfkeystat.in_msgtype[0]); + type++) { + if (pfkeystat.in_msgtype[type] <= 0) + continue; + if (first) { + printf("\thistogram by message type:\n"); + first = 0; + } + printf("\t\t%s: " LLU "\n", pfkey_msgtype_names(type), + (CAST)pfkeystat.in_msgtype[type]); + } + p(in_msgtarget[KEY_SENDUP_ONE], + "\t" LLU " message%s toward single socket\n"); + p(in_msgtarget[KEY_SENDUP_ALL], + "\t" LLU " message%s toward all sockets\n"); + p(in_msgtarget[KEY_SENDUP_REGISTERED], + "\t" LLU " message%s toward registered sockets\n"); + p(in_nomem, "\t" LLU " message%s with memory allocation failure\n"); +#undef p +} +#endif /*IPSEC*/ Property changes on: head/usr.bin/netstat/ipsec.c ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Index: head/usr.bin/netstat/mroute.c =================================================================== --- head/usr.bin/netstat/mroute.c (revision 62583) +++ head/usr.bin/netstat/mroute.c (revision 62584) @@ -1,192 +1,191 @@ /* * 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 */ #ifndef lint static const char rcsid[] = "$FreeBSD$"; #endif /* not lint */ /* * Print DVMRP multicast routing structures and statistics. * * MROUTING 1.0 */ - #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "netstat.h" void mroutepr(mfcaddr, vifaddr) u_long mfcaddr, vifaddr; { struct mfc *mfctable[MFCTBLSIZ]; struct vif viftable[MAXVIFS]; struct mfc mfc, *m; register struct vif *v; register vifi_t vifi; register int i; register int banner_printed; register int saved_nflag; vifi_t maxvif = 0; if (mfcaddr == 0 || vifaddr == 0) { printf("No IPv4 multicast routing compiled into this system.\n"); return; } saved_nflag = nflag; nflag = 1; kread(vifaddr, (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("\nVirtual Interface Table\n" " Vif Thresh Rate Local-Address " "Remote-Address Pkts-In Pkts-Out\n"); banner_printed = 1; } printf(" %2u %6u %4d %-15.15s", /* opposite math of add_vif() */ vifi, v->v_threshold, v->v_rate_limit * 1000 / 1024, 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("\nVirtual Interface Table is empty\n"); kread(mfcaddr, (char *)&mfctable, sizeof(mfctable)); banner_printed = 0; for (i = 0; i < MFCTBLSIZ; ++i) { m = mfctable[i]; while(m) { kread((u_long)m, (char *)&mfc, sizeof mfc); if (!banner_printed) { - printf("\nMulticast Forwarding Cache\n" + printf("\nIPv4 Multicast Forwarding Cache\n" " Origin Group " " Packets In-Vif Out-Vifs:Ttls\n"); banner_printed = 1; } printf(" %-15.15s", routename(mfc.mfc_origin.s_addr)); printf(" %-15.15s", routename(mfc.mfc_mcastgrp.s_addr)); printf(" %9lu", mfc.mfc_pkt_cnt); printf(" %3d ", mfc.mfc_parent); for (vifi = 0; vifi <= maxvif; vifi++) { if (mfc.mfc_ttls[vifi] > 0) printf(" %u:%u", vifi, mfc.mfc_ttls[vifi]); } printf("\n"); m = mfc.mfc_next; } } if (!banner_printed) printf("\nMulticast Routing Table is empty\n"); printf("\n"); nflag = saved_nflag; } void mrt_stats(mstaddr) u_long mstaddr; { struct mrtstat mrtstat; if (mstaddr == 0) { - printf("No multicast routing compiled into this system.\n"); + printf("No IPv4 multicast routing compiled into this system.\n"); return; } kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat)); - printf("multicast forwarding:\n"); + printf("IPv4 multicast forwarding:\n"); printf(" %10lu multicast forwarding cache lookup%s\n", mrtstat.mrts_mfc_lookups, plural(mrtstat.mrts_mfc_lookups)); printf(" %10lu multicast forwarding cache miss%s\n", mrtstat.mrts_mfc_misses, plurales(mrtstat.mrts_mfc_misses)); printf(" %10lu upcall%s to mrouted\n", mrtstat.mrts_upcalls, plural(mrtstat.mrts_upcalls)); printf(" %10lu upcall queue overflow%s\n", mrtstat.mrts_upq_ovflw, plural(mrtstat.mrts_upq_ovflw)); printf(" %10lu upcall%s dropped due to full socket buffer\n", mrtstat.mrts_upq_sockfull, plural(mrtstat.mrts_upq_sockfull)); printf(" %10lu cache cleanup%s\n", mrtstat.mrts_cache_cleanups, plural(mrtstat.mrts_cache_cleanups)); printf(" %10lu datagram%s with no route for origin\n", mrtstat.mrts_no_route, plural(mrtstat.mrts_no_route)); printf(" %10lu datagram%s arrived with bad tunneling\n", mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel)); printf(" %10lu datagram%s could not be tunneled\n", mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel)); printf(" %10lu datagram%s arrived on wrong interface\n", mrtstat.mrts_wrong_if, plural(mrtstat.mrts_wrong_if)); printf(" %10lu datagram%s selectively dropped\n", mrtstat.mrts_drop_sel, plural(mrtstat.mrts_drop_sel)); printf(" %10lu datagram%s dropped due to queue overflow\n", mrtstat.mrts_q_overflow, plural(mrtstat.mrts_q_overflow)); printf(" %10lu datagram%s dropped for being too large\n", mrtstat.mrts_pkt2large, plural(mrtstat.mrts_pkt2large)); } Index: head/usr.bin/netstat/mroute6.c =================================================================== --- head/usr.bin/netstat/mroute6.c (revision 62583) +++ head/usr.bin/netstat/mroute6.c (revision 62584) @@ -1,235 +1,249 @@ /* * 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 * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include #define KERNEL 1 #include #undef KERNEL #include "netstat.h" #define WID_ORG (lflag ? 39 : (nflag ? 29 : 18)) /* width of origin column */ #define WID_GRP (lflag ? 18 : (nflag ? 16 : 18)) /* width of group column */ extern char *routename6 __P((struct sockaddr_in6 *)); void mroute6pr(mfcaddr, mifaddr) u_long mfcaddr, mifaddr; { struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp; struct mif6 mif6table[MAXMIFS]; struct mf6c mfc; struct rtdetq rte, *rtep; register struct mif6 *mifp; register mifi_t mifi; register int i; register int banner_printed; register int saved_nflag; mifi_t maxmif = 0; long int waitings; if (mfcaddr == 0 || mifaddr == 0) { printf("No IPv6 multicast routing compiled into this" "system.\n"); return; } saved_nflag = nflag; nflag = 1; kread(mifaddr, (char *)&mif6table, sizeof(mif6table)); banner_printed = 0; for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) { struct ifnet ifnet; char ifname[IFNAMSIZ]; if (mifp->m6_ifp == NULL) continue; 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(" %9qu %9qu\n", mifp->m6_pkt_in, mifp->m6_pkt_out); + printf(" %9llu %9llu\n", (unsigned long long)mifp->m6_pkt_in, + (unsigned long long)mifp->m6_pkt_out); } if (!banner_printed) printf("\nIPv6 Multicast Interface Table is empty\n"); 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(" %9qu", mfc.mf6c_pkt_cnt); + printf(" %9llu", (unsigned long long)mfc.mf6c_pkt_cnt); for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) { waitings++; 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 Routing Table is empty\n"); printf("\n"); nflag = saved_nflag; } void mrt6_stats(mstaddr) u_long mstaddr; { struct mrt6stat mrtstat; if (mstaddr == 0) { printf("No IPv6 multicast routing compiled into this" "system.\n"); return; } kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat)); printf("IPv6 multicast forwarding:\n"); - printf(" %10qu multicast forwarding cache lookup%s\n", - mrtstat.mrt6s_mfc_lookups, plural(mrtstat.mrt6s_mfc_lookups)); - printf(" %10qu multicast forwarding cache miss%s\n", - mrtstat.mrt6s_mfc_misses, plurales(mrtstat.mrt6s_mfc_misses)); - printf(" %10qu upcall%s to mrouted\n", - mrtstat.mrt6s_upcalls, plural(mrtstat.mrt6s_upcalls)); - printf(" %10qu upcall queue overflow%s\n", - mrtstat.mrt6s_upq_ovflw, plural(mrtstat.mrt6s_upq_ovflw)); - printf(" %10qu upcall%s dropped due to full socket buffer\n", - mrtstat.mrt6s_upq_sockfull, plural(mrtstat.mrt6s_upq_sockfull)); - printf(" %10qu cache cleanup%s\n", - mrtstat.mrt6s_cache_cleanups, plural(mrtstat.mrt6s_cache_cleanups)); - printf(" %10qu datagram%s with no route for origin\n", - mrtstat.mrt6s_no_route, plural(mrtstat.mrt6s_no_route)); - printf(" %10qu datagram%s arrived with bad tunneling\n", - mrtstat.mrt6s_bad_tunnel, plural(mrtstat.mrt6s_bad_tunnel)); - printf(" %10qu datagram%s could not be tunneled\n", - mrtstat.mrt6s_cant_tunnel, plural(mrtstat.mrt6s_cant_tunnel)); - printf(" %10qu datagram%s arrived on wrong interface\n", - mrtstat.mrt6s_wrong_if, plural(mrtstat.mrt6s_wrong_if)); - printf(" %10qu datagram%s selectively dropped\n", - mrtstat.mrt6s_drop_sel, plural(mrtstat.mrt6s_drop_sel)); - printf(" %10qu datagram%s dropped due to queue overflow\n", - mrtstat.mrt6s_q_overflow, plural(mrtstat.mrt6s_q_overflow)); - printf(" %10qu datagram%s dropped for being too large\n", - mrtstat.mrt6s_pkt2large, plural(mrtstat.mrt6s_pkt2large)); + printf(" %10llu multicast forwarding cache lookup%s\n", + (unsigned long long)mrtstat.mrt6s_mfc_lookups, + plural(mrtstat.mrt6s_mfc_lookups)); + printf(" %10llu multicast forwarding cache miss%s\n", + (unsigned long long)mrtstat.mrt6s_mfc_misses, + plurales(mrtstat.mrt6s_mfc_misses)); + printf(" %10llu upcall%s to mrouted\n", + (unsigned long long)mrtstat.mrt6s_upcalls, + plural(mrtstat.mrt6s_upcalls)); + printf(" %10llu upcall llueue overflow%s\n", + (unsigned long long)mrtstat.mrt6s_upq_ovflw, + plural(mrtstat.mrt6s_upq_ovflw)); + printf(" %10llu upcall%s dropped due to full socket buffer\n", + (unsigned long long)mrtstat.mrt6s_upq_sockfull, + plural(mrtstat.mrt6s_upq_sockfull)); + printf(" %10llu cache cleanup%s\n", + (unsigned long long)mrtstat.mrt6s_cache_cleanups, + plural(mrtstat.mrt6s_cache_cleanups)); + printf(" %10llu datagram%s with no route for origin\n", + (unsigned long long)mrtstat.mrt6s_no_route, + plural(mrtstat.mrt6s_no_route)); + printf(" %10llu datagram%s arrived with bad tunneling\n", + (unsigned long long)mrtstat.mrt6s_bad_tunnel, + plural(mrtstat.mrt6s_bad_tunnel)); + printf(" %10llu datagram%s could not be tunneled\n", + (unsigned long long)mrtstat.mrt6s_cant_tunnel, + plural(mrtstat.mrt6s_cant_tunnel)); + printf(" %10llu datagram%s arrived on wrong interface\n", + (unsigned long long)mrtstat.mrt6s_wrong_if, + plural(mrtstat.mrt6s_wrong_if)); + printf(" %10llu datagram%s selectively dropped\n", + (unsigned long long)mrtstat.mrt6s_drop_sel, + plural(mrtstat.mrt6s_drop_sel)); + printf(" %10llu datagram%s dropped due to llueue overflow\n", + (unsigned long long)mrtstat.mrt6s_q_overflow, + plural(mrtstat.mrt6s_q_overflow)); + printf(" %10llu datagram%s dropped for being too large\n", + (unsigned long long)mrtstat.mrt6s_pkt2large, + plural(mrtstat.mrt6s_pkt2large)); } Index: head/usr.bin/netstat/netstat.h =================================================================== --- head/usr.bin/netstat/netstat.h (revision 62583) +++ head/usr.bin/netstat/netstat.h (revision 62584) @@ -1,139 +1,144 @@ /* * 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. * 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. * * @(#)netstat.h 8.2 (Berkeley) 1/4/94 * $FreeBSD$ */ #include int Aflag; /* show addresses of protocol control block */ int aflag; /* show all sockets (including servers) */ 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 iflag; /* show interfaces */ int lflag; /* show routing table with use and ref */ int Lflag; /* show size of listen queues */ int mflag; /* show memory stats */ int nflag; /* show addresses numerically */ int pflag; /* show given protocol */ int rflag; /* show routing tables (or routing stats) */ int sflag; /* show protocol statistics */ int tflag; /* show i/f watchdog timers */ 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 kread __P((u_long addr, char *buf, int size)); char *plural __P((int)); char *plurales __P((int)); void trimdomain __P((char *)); void protopr __P((u_long, char *, int)); void tcp_stats __P((u_long, char *)); void udp_stats __P((u_long, char *)); void ip_stats __P((u_long, char *)); void icmp_stats __P((u_long, char *)); void igmp_stats __P((u_long, char *)); #ifdef IPSEC void ipsec_stats __P((u_long, char *)); #endif #ifdef INET6 void ip6_stats __P((u_long, char *)); void ip6_ifstats __P((char *)); void icmp6_stats __P((u_long, char *)); void icmp6_ifstats __P((char *)); void pim6_stats __P((u_long, char *)); void mroute6pr __P((u_long, u_long)); void mrt6_stats __P((u_long)); + +struct sockaddr_in6; +struct in6_addr; +char *routename6 __P((struct sockaddr_in6 *)); +char *netname6 __P((struct sockaddr_in6 *, struct in6_addr *)); #endif /*INET6*/ void bdg_stats __P((u_long, char *)); void mbpr __P((void)); void hostpr __P((u_long, u_long)); void impstats __P((u_long, u_long)); void intpr __P((int, u_long, void (*) __P((char *)))); void pr_rthdr __P((int)); void pr_family __P((int)); void rt_stats __P((u_long)); char *ipx_pnet __P((struct sockaddr *)); char *ipx_phost __P((struct sockaddr *)); char *ns_phost __P((struct sockaddr *)); void upHex __P((char *)); char *routename __P((u_long)); char *netname __P((u_long, u_long)); char *atalk_print __P((struct sockaddr *, int)); char *atalk_print2 __P((struct sockaddr *, struct sockaddr *, int)); char *ipx_print __P((struct sockaddr *)); char *ns_print __P((struct sockaddr *)); void routepr __P((u_long)); void ipxprotopr __P((u_long, char *)); void spx_stats __P((u_long, char *)); void ipx_stats __P((u_long, char *)); void ipxerr_stats __P((u_long, char *)); void nsprotopr __P((u_long, char *)); void spp_stats __P((u_long, char *)); void idp_stats __P((u_long, char *)); void nserr_stats __P((u_long, char *)); void atalkprotopr __P((u_long, char *)); void ddp_stats __P((u_long, char *)); void netgraphprotopr __P((u_long, char *)); void unixpr __P((void)); void esis_stats __P((u_long, char *)); void clnp_stats __P((u_long, char *)); void cltp_stats __P((u_long, char *)); void iso_protopr __P((u_long, char *)); void iso_protopr1 __P((u_long, int)); void tp_protopr __P((u_long, char *)); void tp_inproto __P((u_long)); void tp_stats __P((caddr_t, caddr_t)); void mroutepr __P((u_long, u_long)); void mrt_stats __P((u_long)); Index: head/usr.bin/netstat/route.c =================================================================== --- head/usr.bin/netstat/route.c (revision 62583) +++ head/usr.bin/netstat/route.c (revision 62584) @@ -1,1052 +1,1044 @@ /* * 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. * 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. */ #ifndef lint #if 0 static char sccsid[] = "From: @(#)route.c 8.6 (Berkeley) 4/28/95"; #endif static const char rcsid[] = "$FreeBSD$"; #endif /* not lint */ #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef NS #include #endif #include #include #include #include #include #include #include #include #include #include "netstat.h" #define kget(p, d) (kread((u_long)(p), (char *)&(d), sizeof (d))) + +/* alignment constraint for routing socket */ +#define ROUNDUP(a) \ + ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) +#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len)) + /* * Definitions for showing gateway flags. */ struct bits { u_long b_mask; char b_val; } bits[] = { { RTF_UP, 'U' }, { RTF_GATEWAY, 'G' }, { RTF_HOST, 'H' }, { RTF_REJECT, 'R' }, { RTF_DYNAMIC, 'D' }, { RTF_MODIFIED, 'M' }, { RTF_DONE, 'd' }, /* Completed -- for routing messages only */ { RTF_CLONING, 'C' }, { RTF_XRESOLVE, 'X' }, { RTF_LLINFO, 'L' }, { RTF_STATIC, 'S' }, { RTF_PROTO1, '1' }, { RTF_PROTO2, '2' }, { RTF_WASCLONED,'W' }, { RTF_PRCLONING,'c' }, { RTF_PROTO3, '3' }, { RTF_BLACKHOLE,'B' }, { RTF_BROADCAST,'b' }, { 0 } }; typedef union { long dummy; /* Helps align structure. */ struct sockaddr u_sa; u_short u_data[128]; } sa_u; static sa_u pt_u; int do_rtent = 0; struct rtentry rtentry; struct radix_node rnode; struct radix_mask rmask; struct radix_node_head *rt_tables[AF_MAX+1]; int NewTree = 0; static struct sockaddr *kgetsa __P((struct sockaddr *)); static void p_tree __P((struct radix_node *)); static void p_rtnode __P((void)); static void ntreestuff __P((void)); static void np_rtentry __P((struct rt_msghdr *)); static void p_sockaddr __P((struct sockaddr *, struct sockaddr *, int, int)); static void p_flags __P((int, char *)); static void p_rtentry __P((struct rtentry *)); static u_long forgemask __P((u_long)); static void domask __P((char *, u_long, u_long)); #ifdef INET6 char *routename6 __P((struct sockaddr_in6 *)); char *netname6 __P((struct sockaddr_in6 *, struct in6_addr *)); #endif /*INET6*/ /* * Print routing tables. */ void routepr(rtree) u_long rtree; { struct radix_node_head *rnh, head; int i; printf("Routing tables\n"); if (Aflag == 0 && NewTree) ntreestuff(); else { if (rtree == 0) { printf("rt_tables: symbol not in namelist\n"); return; } kget(rtree, rt_tables); for (i = 0; i <= AF_MAX; i++) { if ((rnh = rt_tables[i]) == 0) continue; kget(rnh, head); if (i == AF_UNSPEC) { if (Aflag && af == 0) { printf("Netmasks:\n"); p_tree(head.rnh_treetop); } } else if (af == AF_UNSPEC || af == i) { pr_family(i); do_rtent = 1; pr_rthdr(i); p_tree(head.rnh_treetop); } } } } /* * Print address family header before a section of the routing table. */ void pr_family(af) int af; { char *afname; switch (af) { case AF_INET: afname = "Internet"; break; #ifdef INET6 case AF_INET6: afname = "Internet6"; break; #endif /*INET6*/ case AF_IPX: afname = "IPX"; break; #ifdef NS case AF_NS: afname = "XNS"; break; #endif case AF_ISO: afname = "ISO"; break; case AF_APPLETALK: afname = "AppleTalk"; break; case AF_CCITT: afname = "X.25"; break; case AF_NETGRAPH: afname = "Netgraph"; break; default: afname = NULL; break; } if (afname) printf("\n%s:\n", afname); else printf("\nProtocol Family %d:\n", af); } /* column widths; each followed by one space */ -#define WID_DST 18 /* width of destination column */ -#define WID_GW 18 /* width of gateway column */ -#ifdef INET6 -#define WID_DST6 (lflag ? 39 : (nflag ? 33: 18)) /* width of dest column */ -#define WID_GW6 (lflag ? 31 : (nflag ? 29 : 18)) /* width of gateway column */ +#ifndef INET6 +#define WID_DST(af) 18 /* width of destination column */ +#define WID_GW(af) 18 /* width of gateway column */ +#else +#define WID_DST(af) \ + ((af) == AF_INET6 ? (lflag ? 39 : (nflag ? 33: 18)) : 18) +#define WID_GW(af) \ + ((af) == AF_INET6 ? (lflag ? 31 : (nflag ? 29 : 18)) : 18) #endif /*INET6*/ /* * Print header for routing table columns. */ void -pr_rthdr(wid_af) - int wid_af; +pr_rthdr(af) + int af; { - int wid_dst, wid_gw; - wid_dst = -#ifdef INET6 - wid_af == AF_INET6 ? WID_DST6 : -#endif - WID_DST; - wid_gw = -#ifdef INET6 - wid_af == AF_INET6 ? WID_GW6 : -#endif - WID_GW; - if (Aflag) printf("%-8.8s ","Address"); - if (wid_af == AF_INET || lflag) + if (lflag) printf("%-*.*s %-*.*s %-6.6s %6.6s%8.8s %8.8s %6s\n", - wid_dst, wid_dst, "Destination", - wid_gw, wid_gw, "Gateway", + WID_DST(af), WID_DST(af), "Destination", + WID_GW(af), WID_GW(af), "Gateway", "Flags", "Refs", "Use", "Netif", "Expire"); else printf("%-*.*s %-*.*s %-6.6s %8.8s %6s\n", - wid_dst, wid_dst, "Destination", - wid_gw, wid_gw, "Gateway", + WID_DST(af), WID_DST(af), "Destination", + WID_GW(af), WID_GW(af), "Gateway", "Flags", "Netif", "Expire"); } static struct sockaddr * kgetsa(dst) register struct sockaddr *dst; { kget(dst, pt_u.u_sa); if (pt_u.u_sa.sa_len > sizeof (pt_u.u_sa)) kread((u_long)dst, (char *)pt_u.u_data, pt_u.u_sa.sa_len); return (&pt_u.u_sa); } static void p_tree(rn) struct radix_node *rn; { again: kget(rn, rnode); if (rnode.rn_bit < 0) { if (Aflag) printf("%-8.8lx ", (u_long)rn); if (rnode.rn_flags & RNF_ROOT) { if (Aflag) printf("(root node)%s", rnode.rn_dupedkey ? " =>\n" : "\n"); } else if (do_rtent) { kget(rn, rtentry); p_rtentry(&rtentry); if (Aflag) p_rtnode(); } else { p_sockaddr(kgetsa((struct sockaddr *)rnode.rn_key), NULL, 0, 44); putchar('\n'); } if ((rn = rnode.rn_dupedkey)) goto again; } else { if (Aflag && do_rtent) { printf("%-8.8lx ", (u_long)rn); p_rtnode(); } rn = rnode.rn_right; p_tree(rnode.rn_left); p_tree(rn); } } char nbuf[20]; static void p_rtnode() { struct radix_mask *rm = rnode.rn_mklist; if (rnode.rn_bit < 0) { if (rnode.rn_mask) { printf("\t mask "); p_sockaddr(kgetsa((struct sockaddr *)rnode.rn_mask), NULL, 0, -1); } else if (rm == 0) return; } else { sprintf(nbuf, "(%d)", rnode.rn_bit); printf("%6.6s %8.8lx : %8.8lx", nbuf, (u_long)rnode.rn_left, (u_long)rnode.rn_right); } while (rm) { kget(rm, rmask); sprintf(nbuf, " %d refs, ", rmask.rm_refs); printf(" mk = %8.8lx {(%d),%s", (u_long)rm, -1 - rmask.rm_bit, rmask.rm_refs ? nbuf : " "); if (rmask.rm_flags & RNF_NORMAL) { struct radix_node rnode_aux; printf(" , "); kget(rmask.rm_leaf, rnode_aux); p_sockaddr(kgetsa((struct sockaddr *)rnode_aux.rn_mask), NULL, 0, -1); } else p_sockaddr(kgetsa((struct sockaddr *)rmask.rm_mask), NULL, 0, -1); putchar('}'); if ((rm = rmask.rm_mklist)) printf(" ->"); } putchar('\n'); } static void ntreestuff() { size_t needed; int mib[6]; char *buf, *next, *lim; register struct rt_msghdr *rtm; mib[0] = CTL_NET; mib[1] = PF_ROUTE; mib[2] = 0; mib[3] = 0; mib[4] = NET_RT_DUMP; mib[5] = 0; if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) { err(1, "sysctl: net.route.0.0.dump estimate"); } if ((buf = malloc(needed)) == 0) { err(2, "malloc(%lu)", (unsigned long)needed); } if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) { err(1, "sysctl: net.route.0.0.dump"); } lim = buf + needed; for (next = buf; next < lim; next += rtm->rtm_msglen) { rtm = (struct rt_msghdr *)next; np_rtentry(rtm); } } static void np_rtentry(rtm) register struct rt_msghdr *rtm; { register struct sockaddr *sa = (struct sockaddr *)(rtm + 1); #ifdef notdef static int masks_done, banner_printed; #endif static int old_af; int af = 0, interesting = RTF_UP | RTF_GATEWAY | RTF_HOST; #ifdef notdef /* for the moment, netmasks are skipped over */ if (!banner_printed) { printf("Netmasks:\n"); banner_printed = 1; } if (masks_done == 0) { if (rtm->rtm_addrs != RTA_DST ) { masks_done = 1; af = sa->sa_family; } } else #endif af = sa->sa_family; if (af != old_af) { pr_family(af); old_af = af; } if (rtm->rtm_addrs == RTA_DST) p_sockaddr(sa, NULL, 0, 36); else { p_sockaddr(sa, NULL, rtm->rtm_flags, 16); - sa = (struct sockaddr *)(sa->sa_len + (char *)sa); + sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) + (char *)sa); p_sockaddr(sa, NULL, 0, 18); } p_flags(rtm->rtm_flags & interesting, "%-6.6s "); putchar('\n'); } static void p_sockaddr(sa, mask, flags, width) struct sockaddr *sa, *mask; int flags, width; { char workbuf[128], *cplim; register char *cp = workbuf; switch(sa->sa_family) { case AF_INET: { register struct sockaddr_in *sin = (struct sockaddr_in *)sa; if ((sin->sin_addr.s_addr == INADDR_ANY) && mask && ntohl(((struct sockaddr_in *)mask)->sin_addr.s_addr) ==0L) cp = "default" ; else if (flags & RTF_HOST) cp = routename(sin->sin_addr.s_addr); else if (mask) cp = netname(sin->sin_addr.s_addr, ntohl(((struct sockaddr_in *)mask) ->sin_addr.s_addr)); else cp = netname(sin->sin_addr.s_addr, 0L); break; } #ifdef INET6 case AF_INET6: { struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa; struct in6_addr *in6 = &sa6->sin6_addr; /* * XXX: This is a special workaround for KAME kernels. * sin6_scope_id field of SA should be set in the future. */ if (IN6_IS_ADDR_LINKLOCAL(in6) || IN6_IS_ADDR_MC_LINKLOCAL(in6)) { /* XXX: override is ok? */ sa6->sin6_scope_id = (u_int32_t)ntohs(*(u_short *)&in6->s6_addr[2]); *(u_short *)&in6->s6_addr[2] = 0; } if (flags & RTF_HOST) cp = routename6(sa6); else if (mask) cp = netname6(sa6, &((struct sockaddr_in6 *)mask)->sin6_addr); else { cp = netname6(sa6, NULL); } break; } #endif /*INET6*/ case AF_IPX: { struct ipx_addr work = ((struct sockaddr_ipx *)sa)->sipx_addr; if (ipx_nullnet(satoipx_addr(work))) cp = "default"; else cp = ipx_print(sa); break; } case AF_APPLETALK: { if (!(flags & RTF_HOST) && mask) cp = atalk_print2(sa,mask,9); else cp = atalk_print(sa,11); break; } case AF_NETGRAPH: { printf("%s", ((struct sockaddr_ng *)sa)->sg_data); break; } #ifdef NS case AF_NS: cp = ns_print(sa); break; #endif case AF_LINK: { register struct sockaddr_dl *sdl = (struct sockaddr_dl *)sa; if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 && sdl->sdl_slen == 0) (void) sprintf(workbuf, "link#%d", sdl->sdl_index); else switch (sdl->sdl_type) { case IFT_ETHER: { register int i; register u_char *lla = (u_char *)sdl->sdl_data + sdl->sdl_nlen; cplim = ""; for (i = 0; i < sdl->sdl_alen; i++, lla++) { cp += sprintf(cp, "%s%x", cplim, *lla); cplim = ":"; } cp = workbuf; break; } default: cp = link_ntoa(sdl); break; } break; } default: { register u_char *s = (u_char *)sa->sa_data, *slim; slim = sa->sa_len + (u_char *) sa; cplim = cp + sizeof(workbuf) - 6; cp += sprintf(cp, "(%d)", sa->sa_family); while (s < slim && cp < cplim) { cp += sprintf(cp, " %02x", *s++); if (s < slim) cp += sprintf(cp, "%02x", *s++); } cp = workbuf; } } if (width < 0 ) printf("%s ", cp); else { if (nflag) printf("%-*s ", width, cp); else printf("%-*.*s ", width, width, cp); } } static void p_flags(f, format) register int f; char *format; { char name[33], *flags; register struct bits *p = bits; for (flags = name; p->b_mask; p++) if (p->b_mask & f) *flags++ = p->b_val; *flags = '\0'; printf(format, name); } static void p_rtentry(rt) register struct rtentry *rt; { static struct ifnet ifnet, *lastif; static char name[16]; static char prettyname[9]; struct sockaddr *sa; sa_u addr, mask; /* * Don't print protocol-cloned routes unless -a. */ if (rt->rt_parent && !aflag) return; bzero(&addr, sizeof(addr)); if ((sa = kgetsa(rt_key(rt)))) bcopy(sa, &addr, sa->sa_len); bzero(&mask, sizeof(mask)); if (rt_mask(rt) && (sa = kgetsa(rt_mask(rt)))) bcopy(sa, &mask, sa->sa_len); p_sockaddr(&addr.u_sa, &mask.u_sa, rt->rt_flags, -#ifdef INET6 - addr.u_sa.sa_family == AF_INET6 ? WID_DST6 : -#endif - WID_DST); + WID_DST(addr.u_sa.sa_family)); p_sockaddr(kgetsa(rt->rt_gateway), NULL, RTF_HOST, -#ifdef INET6 - addr.u_sa.sa_family == AF_INET6 ? WID_GW6 : -#endif - WID_GW); + WID_GW(addr.u_sa.sa_family)); p_flags(rt->rt_flags, "%-6.6s "); if (addr.u_sa.sa_family == AF_INET || lflag) printf("%6ld %8ld ", rt->rt_refcnt, rt->rt_use); if (rt->rt_ifp) { if (rt->rt_ifp != lastif) { kget(rt->rt_ifp, ifnet); kread((u_long)ifnet.if_name, name, 16); lastif = rt->rt_ifp; snprintf(prettyname, sizeof prettyname, "%s%d", name, ifnet.if_unit); } printf("%8.8s", prettyname); if (rt->rt_rmx.rmx_expire) { time_t expire_time; if ((expire_time = rt->rt_rmx.rmx_expire - time((time_t *)0)) > 0) printf(" %6d%s", (int)expire_time, rt->rt_nodes[0].rn_dupedkey ? " =>" : ""); else goto ifandkey; } else if (rt->rt_nodes[0].rn_dupedkey) { ifandkey:; printf(" =>"); } } putchar('\n'); } char * routename(in) u_long in; { register char *cp; static char line[MAXHOSTNAMELEN + 1]; struct hostent *hp; cp = 0; if (!nflag) { hp = gethostbyaddr((char *)&in, sizeof (struct in_addr), AF_INET); if (hp) { cp = hp->h_name; trimdomain(cp); } } if (cp) { strncpy(line, cp, sizeof(line) - 1); line[sizeof(line) - 1] = '\0'; } else { #define C(x) ((x) & 0xff) in = ntohl(in); sprintf(line, "%lu.%lu.%lu.%lu", C(in >> 24), C(in >> 16), C(in >> 8), C(in)); } return (line); } static u_long forgemask(a) u_long a; { u_long m; if (IN_CLASSA(a)) m = IN_CLASSA_NET; else if (IN_CLASSB(a)) m = IN_CLASSB_NET; else m = IN_CLASSC_NET; return (m); } static void domask(dst, addr, mask) char *dst; u_long addr, mask; { register int b, i; if (!mask || (forgemask(addr) == mask)) { *dst = '\0'; return; } i = 0; for (b = 0; b < 32; b++) if (mask & (1 << b)) { register int bb; i = b; for (bb = b+1; bb < 32; bb++) if (!(mask & (1 << bb))) { i = -1; /* noncontig */ break; } break; } if (i == -1) sprintf(dst, "&0x%lx", mask); else sprintf(dst, "/%d", 32-i); } /* * Return the name of the network whose address is given. * The address is assumed to be that of a net or subnet, not a host. */ char * netname(in, mask) u_long in, mask; { char *cp = 0; static char line[MAXHOSTNAMELEN + 1]; struct netent *np = 0; u_long net, omask, dmask; register u_long i; i = ntohl(in); omask = mask; if (!nflag && i) { dmask = forgemask(i); net = i & dmask; if (!(np = getnetbyaddr(i, AF_INET)) && net != i) np = getnetbyaddr(net, AF_INET); if (np) { cp = np->n_name; trimdomain(cp); } } if (cp) strncpy(line, cp, sizeof(line) - 1); else if ((i & 0xffffff) == 0) sprintf(line, "%lu", C(i >> 24)); else if ((i & 0xffff) == 0) sprintf(line, "%lu.%lu", C(i >> 24) , C(i >> 16)); else if ((i & 0xff) == 0) sprintf(line, "%lu.%lu.%lu", C(i >> 24), C(i >> 16), C(i >> 8)); else sprintf(line, "%lu.%lu.%lu.%lu", C(i >> 24), C(i >> 16), C(i >> 8), C(i)); domask(line+strlen(line), i, omask); return (line); } #ifdef INET6 char * netname6(sa6, mask) struct sockaddr_in6 *sa6; struct in6_addr *mask; { static char line[MAXHOSTNAMELEN + 1]; u_char *p = (u_char *)mask; u_char *lim; - int masklen, illegal = 0; - int flag = NI_WITHSCOPEID; + int masklen, illegal = 0, flag = NI_WITHSCOPEID; if (mask) { for (masklen = 0, lim = p + 16; p < lim; p++) { - if (*p == 0xff) - masklen += 8; - else - break; - } - if (p < lim) { switch (*p) { + case 0xff: + masklen += 8; + break; case 0xfe: masklen += 7; break; case 0xfc: masklen += 6; break; case 0xf8: masklen += 5; break; case 0xf0: masklen += 4; break; case 0xe0: masklen += 3; break; case 0xc0: masklen += 2; break; case 0x80: masklen += 1; break; case 0x00: break; default: illegal ++; break; } } if (illegal) fprintf(stderr, "illegal prefixlen\n"); } else masklen = 128; if (masklen == 0 && IN6_IS_ADDR_UNSPECIFIED(&sa6->sin6_addr)) return("default"); if (nflag) flag |= NI_NUMERICHOST; getnameinfo((struct sockaddr *)sa6, sa6->sin6_len, line, sizeof(line), NULL, 0, flag); if (nflag) sprintf(&line[strlen(line)], "/%d", masklen); return line; } char * routename6(sa6) struct sockaddr_in6 *sa6; { static char line[MAXHOSTNAMELEN + 1]; int flag = NI_WITHSCOPEID; + /* use local variable for safety */ + struct sockaddr_in6 sa6_local = {AF_INET6, sizeof(sa6_local),}; + sa6_local.sin6_addr = sa6->sin6_addr; + sa6_local.sin6_scope_id = sa6->sin6_scope_id; + if (nflag) flag |= NI_NUMERICHOST; - getnameinfo((struct sockaddr *)sa6, sa6->sin6_len, line, sizeof(line), - NULL, 0, flag); + getnameinfo((struct sockaddr *)&sa6_local, sa6_local.sin6_len, + line, sizeof(line), NULL, 0, flag); return line; } #endif /*INET6*/ /* * Print routing statistics */ void rt_stats(off) u_long off; { struct rtstat rtstat; if (off == 0) { printf("rtstat: symbol not in namelist\n"); return; } kread(off, (char *)&rtstat, sizeof (rtstat)); printf("routing:\n"); printf("\t%u bad routing redirect%s\n", rtstat.rts_badredirect, plural(rtstat.rts_badredirect)); printf("\t%u dynamically created route%s\n", rtstat.rts_dynamic, plural(rtstat.rts_dynamic)); printf("\t%u new gateway%s due to redirects\n", rtstat.rts_newgateway, plural(rtstat.rts_newgateway)); printf("\t%u destination%s found unreachable\n", rtstat.rts_unreach, plural(rtstat.rts_unreach)); printf("\t%u use%s of a wildcard route\n", rtstat.rts_wildcard, plural(rtstat.rts_wildcard)); } char * ipx_print(sa) register struct sockaddr *sa; { u_short port; struct servent *sp = 0; char *net = "", *host = ""; register char *p; register u_char *q; struct ipx_addr work = ((struct sockaddr_ipx *)sa)->sipx_addr; static char mybuf[50]; char cport[10], chost[15], cnet[15]; port = ntohs(work.x_port); if (ipx_nullnet(work) && ipx_nullhost(work)) { if (port) { if (sp) sprintf(mybuf, "*.%s", sp->s_name); else sprintf(mybuf, "*.%x", port); } else sprintf(mybuf, "*.*"); return (mybuf); } if (ipx_wildnet(work)) net = "any"; else if (ipx_nullnet(work)) net = "*"; else { q = work.x_net.c_net; sprintf(cnet, "%02x%02x%02x%02x", q[0], q[1], q[2], q[3]); for (p = cnet; *p == '0' && p < cnet + 8; p++) continue; net = p; } if (ipx_wildhost(work)) host = "any"; else if (ipx_nullhost(work)) host = "*"; else { q = work.x_host.c_host; sprintf(chost, "%02x%02x%02x%02x%02x%02x", q[0], q[1], q[2], q[3], q[4], q[5]); for (p = chost; *p == '0' && p < chost + 12; p++) continue; host = p; } if (port) { if (strcmp(host, "*") == 0) host = ""; if (sp) snprintf(cport, sizeof(cport), "%s%s", *host ? "." : "", sp->s_name); else snprintf(cport, sizeof(cport), "%s%x", *host ? "." : "", port); } else *cport = 0; snprintf(mybuf, sizeof(mybuf), "%s.%s%s", net, host, cport); return(mybuf); } char * ipx_phost(sa) struct sockaddr *sa; { register struct sockaddr_ipx *sipx = (struct sockaddr_ipx *)sa; struct sockaddr_ipx work; static union ipx_net ipx_zeronet; char *p; struct ipx_addr in; work = *sipx; in = work.sipx_addr; work.sipx_addr.x_port = 0; work.sipx_addr.x_net = ipx_zeronet; p = ipx_print((struct sockaddr *)&work); if (strncmp("*.", p, 2) == 0) p += 2; return(p); } #ifdef NS short ns_nullh[] = {0,0,0}; short ns_bh[] = {-1,-1,-1}; char * ns_print(sa) register struct sockaddr *sa; { register struct sockaddr_ns *sns = (struct sockaddr_ns*)sa; struct ns_addr work; union { union ns_net net_e; u_long long_e; } net; u_short port; static char mybuf[50], cport[10], chost[25]; char *host = ""; register char *p; register u_char *q; work = sns->sns_addr; port = ntohs(work.x_port); work.x_port = 0; net.net_e = work.x_net; if (ns_nullhost(work) && net.long_e == 0) { if (port ) { sprintf(mybuf, "*.%xH", port); upHex(mybuf); } else sprintf(mybuf, "*.*"); return (mybuf); } if (bcmp(ns_bh, work.x_host.c_host, 6) == 0) { host = "any"; } else if (bcmp(ns_nullh, work.x_host.c_host, 6) == 0) { host = "*"; } else { q = work.x_host.c_host; sprintf(chost, "%02x%02x%02x%02x%02x%02xH", q[0], q[1], q[2], q[3], q[4], q[5]); for (p = chost; *p == '0' && p < chost + 12; p++) continue; host = p; } if (port) sprintf(cport, ".%xH", htons(port)); else *cport = 0; sprintf(mybuf,"%xH.%s%s", ntohl(net.long_e), host, cport); upHex(mybuf); return(mybuf); } char * ns_phost(sa) struct sockaddr *sa; { register struct sockaddr_ns *sns = (struct sockaddr_ns *)sa; struct sockaddr_ns work; static union ns_net ns_zeronet; char *p; work = *sns; work.sns_addr.x_port = 0; work.sns_addr.x_net = ns_zeronet; p = ns_print((struct sockaddr *)&work); if (strncmp("0H.", p, 3) == 0) p += 3; return(p); } #endif void upHex(p0) char *p0; { register char *p = p0; for (; *p; p++) switch (*p) { case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': *p += ('A' - 'a'); break; } }