1f29d8c1aSDavid Malone /*- 2f29d8c1aSDavid Malone * Copyright (c) 1980, 1992, 1993 3f29d8c1aSDavid Malone * The Regents of the University of California. All rights reserved. 4f29d8c1aSDavid Malone * 5f29d8c1aSDavid Malone * Redistribution and use in source and binary forms, with or without 6f29d8c1aSDavid Malone * modification, are permitted provided that the following conditions 7f29d8c1aSDavid Malone * are met: 8f29d8c1aSDavid Malone * 1. Redistributions of source code must retain the above copyright 9f29d8c1aSDavid Malone * notice, this list of conditions and the following disclaimer. 10f29d8c1aSDavid Malone * 2. Redistributions in binary form must reproduce the above copyright 11f29d8c1aSDavid Malone * notice, this list of conditions and the following disclaimer in the 12f29d8c1aSDavid Malone * documentation and/or other materials provided with the distribution. 13*fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 14f29d8c1aSDavid Malone * may be used to endorse or promote products derived from this software 15f29d8c1aSDavid Malone * without specific prior written permission. 16f29d8c1aSDavid Malone * 17f29d8c1aSDavid Malone * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18f29d8c1aSDavid Malone * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19f29d8c1aSDavid Malone * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20f29d8c1aSDavid Malone * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21f29d8c1aSDavid Malone * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22f29d8c1aSDavid Malone * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23f29d8c1aSDavid Malone * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24f29d8c1aSDavid Malone * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25f29d8c1aSDavid Malone * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26f29d8c1aSDavid Malone * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27f29d8c1aSDavid Malone * SUCH DAMAGE. 28f29d8c1aSDavid Malone */ 29f29d8c1aSDavid Malone 30f29d8c1aSDavid Malone #include <sys/cdefs.h> 31f29d8c1aSDavid Malone 32f29d8c1aSDavid Malone __FBSDID("$FreeBSD$"); 33f29d8c1aSDavid Malone 34f29d8c1aSDavid Malone #ifdef lint 35f29d8c1aSDavid Malone static const char sccsid[] = "@(#)mbufs.c 8.1 (Berkeley) 6/6/93"; 36f29d8c1aSDavid Malone #endif 37f29d8c1aSDavid Malone 38f29d8c1aSDavid Malone /* From: 39f29d8c1aSDavid Malone "Id: mbufs.c,v 1.5 1997/02/24 20:59:03 wollman Exp" 40f29d8c1aSDavid Malone */ 41f29d8c1aSDavid Malone 42f29d8c1aSDavid Malone #ifdef INET6 43f29d8c1aSDavid Malone #include <sys/param.h> 44f29d8c1aSDavid Malone #include <sys/types.h> 45f29d8c1aSDavid Malone #include <sys/socket.h> 46f29d8c1aSDavid Malone #include <sys/sysctl.h> 47f29d8c1aSDavid Malone 48f29d8c1aSDavid Malone #include <netinet/in.h> 49f29d8c1aSDavid Malone #include <netinet/in_systm.h> 50f29d8c1aSDavid Malone #include <netinet/ip.h> 51f29d8c1aSDavid Malone #include <netinet6/ip6_var.h> 52f29d8c1aSDavid Malone 53f29d8c1aSDavid Malone #include <stdlib.h> 54f29d8c1aSDavid Malone #include <string.h> 55f29d8c1aSDavid Malone #include <paths.h> 56f29d8c1aSDavid Malone 57f29d8c1aSDavid Malone #include "systat.h" 58f29d8c1aSDavid Malone #include "extern.h" 59f29d8c1aSDavid Malone #include "mode.h" 60f29d8c1aSDavid Malone 61f29d8c1aSDavid Malone static struct ip6stat curstat, initstat, oldstat; 62f29d8c1aSDavid Malone 63f29d8c1aSDavid Malone /*- 64f29d8c1aSDavid Malone --0 1 2 3 4 5 6 7 65f29d8c1aSDavid Malone --0123456789012345678901234567890123456789012345678901234567890123456789012345 668aa22952SBruce Evans 00 IPv6 Input IPv6 Output 678aa22952SBruce Evans 019999999 total packets received 999999999 total packets sent 688aa22952SBruce Evans 029999999 - too short for header 999999999 - generated locally 698aa22952SBruce Evans 039999999 - too short for data 999999999 - output drops 708aa22952SBruce Evans 049999999 - with invalid version 999999999 output fragments generated 718aa22952SBruce Evans 059999999 total fragments received 999999999 - fragmentation failed 728aa22952SBruce Evans 069999999 - fragments dropped 999999999 destinations unreachable 738aa22952SBruce Evans 079999999 - fragments timed out 999999999 packets output via raw IP 748aa22952SBruce Evans 089999999 - fragments overflown 758aa22952SBruce Evans 099999999 - packets reassembled ok Input next-header histogram 768aa22952SBruce Evans 109999999 packets forwarded 999999999 - destination options 778aa22952SBruce Evans 119999999 - unreachable dests 999999999 - hop-by-hop options 788aa22952SBruce Evans 129999999 - redirects generated 999999999 - IPv4 798aa22952SBruce Evans 139999999 option errors 999999999 - TCP 808aa22952SBruce Evans 149999999 unwanted multicasts 999999999 - UDP 818aa22952SBruce Evans 159999999 delivered to upper layer 999999999 - IPv6 828aa22952SBruce Evans 169999999 bad scope packets 999999999 - routing header 838aa22952SBruce Evans 179999999 address selection failed 999999999 - fragmentation header 848aa22952SBruce Evans 18 999999999 - ICMP6 858aa22952SBruce Evans 19 999999999 - none 86f29d8c1aSDavid Malone --0123456789012345678901234567890123456789012345678901234567890123456789012345 87f29d8c1aSDavid Malone --0 1 2 3 4 5 6 7 88f29d8c1aSDavid Malone */ 89f29d8c1aSDavid Malone 90f29d8c1aSDavid Malone WINDOW * 91f29d8c1aSDavid Malone openip6(void) 92f29d8c1aSDavid Malone { 938aa22952SBruce Evans return (subwin(stdscr, LINES-3-1, 0, MAINWIN_ROW, 0)); 94f29d8c1aSDavid Malone } 95f29d8c1aSDavid Malone 96f29d8c1aSDavid Malone void 9793b9f504SXin LI closeip6(WINDOW *w) 98f29d8c1aSDavid Malone { 99f29d8c1aSDavid Malone if (w == NULL) 100f29d8c1aSDavid Malone return; 101f29d8c1aSDavid Malone wclear(w); 102f29d8c1aSDavid Malone wrefresh(w); 103f29d8c1aSDavid Malone delwin(w); 104f29d8c1aSDavid Malone } 105f29d8c1aSDavid Malone 106f29d8c1aSDavid Malone void 107f29d8c1aSDavid Malone labelip6(void) 108f29d8c1aSDavid Malone { 109f29d8c1aSDavid Malone wmove(wnd, 0, 0); wclrtoeol(wnd); 110f29d8c1aSDavid Malone #define L(row, str) mvwprintw(wnd, row, 10, str) 111f29d8c1aSDavid Malone #define R(row, str) mvwprintw(wnd, row, 45, str); 1128aa22952SBruce Evans L(0, "IPv6 Input"); R(0, "IPv6 Output"); 1138aa22952SBruce Evans L(1, "total packets received"); R(1, "total packets sent"); 1148aa22952SBruce Evans L(2, "- too short for header"); R(2, "- generated locally"); 1158aa22952SBruce Evans L(3, "- too short for data"); R(3, "- output drops"); 1168aa22952SBruce Evans L(4, "- with invalid version"); R(4, "output fragments generated"); 1178aa22952SBruce Evans L(5, "total fragments received"); R(5, "- fragmentation failed"); 1188aa22952SBruce Evans L(6, "- fragments dropped"); R(6, "destinations unreachable"); 1198aa22952SBruce Evans L(7, "- fragments timed out"); R(7, "packets output via raw IP"); 1208aa22952SBruce Evans L(8, "- fragments overflown"); 1218aa22952SBruce Evans L(9, "- packets reassembled ok"); R(9, "Input next-header histogram"); 1228aa22952SBruce Evans L(10, "packets forwarded"); R(10, " - destination options"); 1238aa22952SBruce Evans L(11, "- unreachable dests"); R(11, " - hop-by-hop options"); 1248aa22952SBruce Evans L(12, "- redirects generated"); R(12, " - IPv4"); 1258aa22952SBruce Evans L(13, "option errors"); R(13, " - TCP"); 1268aa22952SBruce Evans L(14, "unwanted multicasts"); R(14, " - UDP"); 1278aa22952SBruce Evans L(15, "delivered to upper layer"); R(15, " - IPv6"); 1288aa22952SBruce Evans L(16, "bad scope packets"); R(16, " - routing header"); 1298aa22952SBruce Evans L(17, "address selection failed"); R(17, " - fragmentation header"); 1308aa22952SBruce Evans R(18, " - ICMP6"); 1318aa22952SBruce Evans R(19, " - none"); 132f29d8c1aSDavid Malone #undef L 133f29d8c1aSDavid Malone #undef R 134f29d8c1aSDavid Malone } 135f29d8c1aSDavid Malone 136f29d8c1aSDavid Malone static void 137f29d8c1aSDavid Malone domode(struct ip6stat *ret) 138f29d8c1aSDavid Malone { 139f29d8c1aSDavid Malone const struct ip6stat *sub; 140f29d8c1aSDavid Malone int divisor = 1, i; 141f29d8c1aSDavid Malone 142f29d8c1aSDavid Malone switch(currentmode) { 143f29d8c1aSDavid Malone case display_RATE: 144f29d8c1aSDavid Malone sub = &oldstat; 1458b3daf89SAlexander V. Chernikov divisor = (delay > 1000000) ? delay / 1000000 : 1; 146f29d8c1aSDavid Malone break; 147f29d8c1aSDavid Malone case display_DELTA: 148f29d8c1aSDavid Malone sub = &oldstat; 149f29d8c1aSDavid Malone break; 150f29d8c1aSDavid Malone case display_SINCE: 151f29d8c1aSDavid Malone sub = &initstat; 152f29d8c1aSDavid Malone break; 153f29d8c1aSDavid Malone default: 154f29d8c1aSDavid Malone *ret = curstat; 155f29d8c1aSDavid Malone return; 156f29d8c1aSDavid Malone } 157f29d8c1aSDavid Malone #define DO(stat) ret->stat = (curstat.stat - sub->stat) / divisor 158f29d8c1aSDavid Malone DO(ip6s_total); 159f29d8c1aSDavid Malone DO(ip6s_tooshort); 160f29d8c1aSDavid Malone DO(ip6s_toosmall); 161f29d8c1aSDavid Malone DO(ip6s_fragments); 162f29d8c1aSDavid Malone DO(ip6s_fragdropped); 163f29d8c1aSDavid Malone DO(ip6s_fragtimeout); 164f29d8c1aSDavid Malone DO(ip6s_fragoverflow); 165f29d8c1aSDavid Malone DO(ip6s_forward); 166f29d8c1aSDavid Malone DO(ip6s_cantforward); 167f29d8c1aSDavid Malone DO(ip6s_redirectsent); 168f29d8c1aSDavid Malone DO(ip6s_delivered); 169f29d8c1aSDavid Malone DO(ip6s_localout); 170f29d8c1aSDavid Malone DO(ip6s_odropped); 171f29d8c1aSDavid Malone DO(ip6s_reassembled); 172f29d8c1aSDavid Malone DO(ip6s_fragmented); 173f29d8c1aSDavid Malone DO(ip6s_ofragments); 174f29d8c1aSDavid Malone DO(ip6s_cantfrag); 175f29d8c1aSDavid Malone DO(ip6s_badoptions); 176f29d8c1aSDavid Malone DO(ip6s_noroute); 177f29d8c1aSDavid Malone DO(ip6s_badvers); 178f29d8c1aSDavid Malone DO(ip6s_rawout); 179f29d8c1aSDavid Malone DO(ip6s_notmember); 180f29d8c1aSDavid Malone for (i = 0; i < 256; i++) 181f29d8c1aSDavid Malone DO(ip6s_nxthist[i]); 182f29d8c1aSDavid Malone DO(ip6s_badscope); 183f29d8c1aSDavid Malone DO(ip6s_sources_none); 184f29d8c1aSDavid Malone #undef DO 185f29d8c1aSDavid Malone } 186f29d8c1aSDavid Malone 187f29d8c1aSDavid Malone void 188f29d8c1aSDavid Malone showip6(void) 189f29d8c1aSDavid Malone { 190f29d8c1aSDavid Malone struct ip6stat stats; 191f29d8c1aSDavid Malone u_long totalout; 192f29d8c1aSDavid Malone 193f29d8c1aSDavid Malone domode(&stats); 194f29d8c1aSDavid Malone totalout = stats.ip6s_forward + stats.ip6s_localout; 195f29d8c1aSDavid Malone 196f29d8c1aSDavid Malone #define DO(stat, row, col) \ 197f29d8c1aSDavid Malone mvwprintw(wnd, row, col, "%9lu", stats.stat) 198f29d8c1aSDavid Malone 1998aa22952SBruce Evans DO(ip6s_total, 1, 0); 2008aa22952SBruce Evans mvwprintw(wnd, 1, 35, "%9lu", totalout); 2018aa22952SBruce Evans DO(ip6s_tooshort, 2, 0); 2028aa22952SBruce Evans DO(ip6s_localout, 2, 35); 2038aa22952SBruce Evans DO(ip6s_toosmall, 3, 0); 2048aa22952SBruce Evans DO(ip6s_odropped, 3, 35); 2058aa22952SBruce Evans DO(ip6s_badvers, 4, 0); 2068aa22952SBruce Evans DO(ip6s_ofragments, 4, 35); 2078aa22952SBruce Evans DO(ip6s_fragments, 5, 0); 2088aa22952SBruce Evans DO(ip6s_cantfrag, 5, 35); 2098aa22952SBruce Evans DO(ip6s_fragdropped, 6, 0); 2108aa22952SBruce Evans DO(ip6s_noroute, 6, 35); 2118aa22952SBruce Evans DO(ip6s_fragtimeout, 7, 0); 2128aa22952SBruce Evans DO(ip6s_rawout, 7, 35); 2138aa22952SBruce Evans DO(ip6s_fragoverflow, 8, 0); 2148aa22952SBruce Evans DO(ip6s_reassembled, 9, 0); 2158aa22952SBruce Evans DO(ip6s_forward, 10, 0); 216f29d8c1aSDavid Malone DO(ip6s_nxthist[IPPROTO_DSTOPTS], 10, 35); 2178aa22952SBruce Evans DO(ip6s_cantforward, 11, 0); 218f29d8c1aSDavid Malone DO(ip6s_nxthist[IPPROTO_HOPOPTS], 11, 35); 2198aa22952SBruce Evans DO(ip6s_redirectsent, 12, 0); 220f29d8c1aSDavid Malone DO(ip6s_nxthist[IPPROTO_IPV4], 12, 35); 2218aa22952SBruce Evans DO(ip6s_badoptions, 13, 0); 222f29d8c1aSDavid Malone DO(ip6s_nxthist[IPPROTO_TCP], 13, 35); 2238aa22952SBruce Evans DO(ip6s_notmember, 14, 0); 224f29d8c1aSDavid Malone DO(ip6s_nxthist[IPPROTO_UDP], 14, 35); 2258aa22952SBruce Evans DO(ip6s_delivered, 15, 0); 226f29d8c1aSDavid Malone DO(ip6s_nxthist[IPPROTO_IPV6], 15, 35); 2278aa22952SBruce Evans DO(ip6s_badscope, 16, 0); 228f29d8c1aSDavid Malone DO(ip6s_nxthist[IPPROTO_ROUTING], 16, 35); 2298aa22952SBruce Evans DO(ip6s_sources_none, 17, 0); 230f29d8c1aSDavid Malone DO(ip6s_nxthist[IPPROTO_FRAGMENT], 17, 35); 231f29d8c1aSDavid Malone DO(ip6s_nxthist[IPPROTO_ICMPV6], 18, 35); 232f29d8c1aSDavid Malone DO(ip6s_nxthist[IPPROTO_NONE], 19, 35); 233f29d8c1aSDavid Malone #undef DO 234f29d8c1aSDavid Malone } 235f29d8c1aSDavid Malone 236f29d8c1aSDavid Malone int 237f29d8c1aSDavid Malone initip6(void) 238f29d8c1aSDavid Malone { 239f29d8c1aSDavid Malone size_t len; 240f29d8c1aSDavid Malone int name[4]; 241f29d8c1aSDavid Malone 242f29d8c1aSDavid Malone name[0] = CTL_NET; 243f29d8c1aSDavid Malone name[1] = PF_INET6; 244f29d8c1aSDavid Malone name[2] = IPPROTO_IPV6; 245f29d8c1aSDavid Malone name[3] = IPV6CTL_STATS; 246f29d8c1aSDavid Malone 247f29d8c1aSDavid Malone len = 0; 248f29d8c1aSDavid Malone if (sysctl(name, 4, 0, &len, 0, 0) < 0) { 249f29d8c1aSDavid Malone error("sysctl getting ip6stat size failed"); 250f29d8c1aSDavid Malone return 0; 251f29d8c1aSDavid Malone } 252f29d8c1aSDavid Malone if (len > sizeof curstat) { 253f29d8c1aSDavid Malone error("ip6stat structure has grown--recompile systat!"); 254f29d8c1aSDavid Malone return 0; 255f29d8c1aSDavid Malone } 256f29d8c1aSDavid Malone if (sysctl(name, 4, &initstat, &len, 0, 0) < 0) { 257f29d8c1aSDavid Malone error("sysctl getting ip6stat failed"); 258f29d8c1aSDavid Malone return 0; 259f29d8c1aSDavid Malone } 260f29d8c1aSDavid Malone oldstat = initstat; 261f29d8c1aSDavid Malone return 1; 262f29d8c1aSDavid Malone } 263f29d8c1aSDavid Malone 264f29d8c1aSDavid Malone void 265f29d8c1aSDavid Malone resetip6(void) 266f29d8c1aSDavid Malone { 267f29d8c1aSDavid Malone size_t len; 268f29d8c1aSDavid Malone int name[4]; 269f29d8c1aSDavid Malone 270f29d8c1aSDavid Malone name[0] = CTL_NET; 271f29d8c1aSDavid Malone name[1] = PF_INET6; 272f29d8c1aSDavid Malone name[2] = IPPROTO_IPV6; 273f29d8c1aSDavid Malone name[3] = IPV6CTL_STATS; 274f29d8c1aSDavid Malone 275f29d8c1aSDavid Malone len = sizeof initstat; 276f29d8c1aSDavid Malone if (sysctl(name, 4, &initstat, &len, 0, 0) < 0) { 277f29d8c1aSDavid Malone error("sysctl getting ipstat failed"); 278f29d8c1aSDavid Malone } 279f29d8c1aSDavid Malone 280f29d8c1aSDavid Malone oldstat = initstat; 281f29d8c1aSDavid Malone } 282f29d8c1aSDavid Malone 283f29d8c1aSDavid Malone void 284f29d8c1aSDavid Malone fetchip6(void) 285f29d8c1aSDavid Malone { 286f29d8c1aSDavid Malone int name[4]; 287f29d8c1aSDavid Malone size_t len; 288f29d8c1aSDavid Malone 289f29d8c1aSDavid Malone oldstat = curstat; 290f29d8c1aSDavid Malone name[0] = CTL_NET; 291f29d8c1aSDavid Malone name[1] = PF_INET6; 292f29d8c1aSDavid Malone name[2] = IPPROTO_IPV6; 293f29d8c1aSDavid Malone name[3] = IPV6CTL_STATS; 294f29d8c1aSDavid Malone len = sizeof curstat; 295f29d8c1aSDavid Malone 296f29d8c1aSDavid Malone if (sysctl(name, 4, &curstat, &len, 0, 0) < 0) 297f29d8c1aSDavid Malone return; 298f29d8c1aSDavid Malone } 299f29d8c1aSDavid Malone 300f29d8c1aSDavid Malone #endif 301