1 1.16 joerg /* $NetBSD: ip6.c,v 1.16 2014/06/03 22:22:41 joerg Exp $ */ 2 1.1 itojun 3 1.1 itojun /* 4 1.5 ad * Copyright (c) 1999, 2000 Andrew Doran <ad (at) NetBSD.org> 5 1.1 itojun * All rights reserved. 6 1.1 itojun * 7 1.1 itojun * Redistribution and use in source and binary forms, with or without 8 1.1 itojun * modification, are permitted provided that the following conditions 9 1.1 itojun * are met: 10 1.1 itojun * 1. Redistributions of source code must retain the above copyright 11 1.1 itojun * notice, this list of conditions and the following disclaimer. 12 1.1 itojun * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 itojun * notice, this list of conditions and the following disclaimer in the 14 1.1 itojun * documentation and/or other materials provided with the distribution. 15 1.1 itojun * 16 1.1 itojun * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 1.1 itojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 1.1 itojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 1.1 itojun * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 1.1 itojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 1.1 itojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 1.1 itojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 1.1 itojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 1.1 itojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 1.1 itojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 1.1 itojun * SUCH DAMAGE. 27 1.1 itojun * 28 1.1 itojun */ 29 1.1 itojun 30 1.1 itojun #include <sys/cdefs.h> 31 1.1 itojun #ifndef lint 32 1.16 joerg __RCSID("$NetBSD: ip6.c,v 1.16 2014/06/03 22:22:41 joerg Exp $"); 33 1.1 itojun #endif /* not lint */ 34 1.1 itojun 35 1.1 itojun #include <sys/param.h> 36 1.1 itojun #include <sys/sysctl.h> 37 1.1 itojun 38 1.1 itojun #include <netinet/in.h> 39 1.1 itojun #include <netinet/in_systm.h> 40 1.1 itojun #include <netinet/ip6.h> 41 1.1 itojun #include <netinet6/ip6_var.h> 42 1.1 itojun 43 1.1 itojun #include <string.h> 44 1.3 ad 45 1.1 itojun #include "systat.h" 46 1.1 itojun #include "extern.h" 47 1.1 itojun 48 1.1 itojun #define LHD(row, str) mvwprintw(wnd, row, 10, str) 49 1.1 itojun #define RHD(row, str) mvwprintw(wnd, row, 45, str); 50 1.1 itojun #define SHOW(stat, row, col) \ 51 1.13 thorpej mvwprintw(wnd, row, col, "%9llu", (unsigned long long)curstat[stat]) 52 1.1 itojun 53 1.5 ad enum update { 54 1.5 ad UPDATE_TIME, 55 1.5 ad UPDATE_BOOT, 56 1.5 ad UPDATE_RUN, 57 1.1 itojun }; 58 1.1 itojun 59 1.5 ad static enum update update = UPDATE_TIME; 60 1.13 thorpej static uint64_t curstat[IP6_NSTATS]; 61 1.13 thorpej static uint64_t newstat[IP6_NSTATS]; 62 1.13 thorpej static uint64_t oldstat[IP6_NSTATS]; 63 1.1 itojun 64 1.1 itojun WINDOW * 65 1.1 itojun openip6(void) 66 1.1 itojun { 67 1.1 itojun 68 1.10 dsl return (subwin(stdscr, -1, 0, 5, 0)); 69 1.1 itojun } 70 1.1 itojun 71 1.1 itojun void 72 1.5 ad closeip6(WINDOW *w) 73 1.1 itojun { 74 1.1 itojun 75 1.1 itojun if (w != NULL) { 76 1.1 itojun wclear(w); 77 1.1 itojun wrefresh(w); 78 1.1 itojun delwin(w); 79 1.1 itojun } 80 1.1 itojun } 81 1.1 itojun 82 1.1 itojun void 83 1.1 itojun labelip6(void) 84 1.1 itojun { 85 1.1 itojun 86 1.1 itojun wmove(wnd, 0, 0); wclrtoeol(wnd); 87 1.1 itojun 88 1.1 itojun LHD(0, "total packet received"); 89 1.1 itojun LHD(1, " smaller than minimum"); 90 1.1 itojun LHD(2, " data size < data length"); 91 1.1 itojun LHD(3, " bad options"); 92 1.1 itojun LHD(4, " incorrect version no"); 93 1.1 itojun LHD(5, " headers not continuous"); 94 1.1 itojun LHD(6, " packet for this host"); 95 1.1 itojun LHD(7, " multicast we don't join"); 96 1.1 itojun LHD(8, " too many headers"); 97 1.1 itojun LHD(9, " tunneled packet w/o gif"); 98 1.1 itojun 99 1.1 itojun LHD(11, " fragment received"); 100 1.1 itojun LHD(12, " fragment dropped"); 101 1.1 itojun LHD(13, " fragment timeout"); 102 1.1 itojun LHD(14, " fragment exceeded limit"); 103 1.1 itojun LHD(15, " packet reassembled ok"); 104 1.1 itojun 105 1.1 itojun #if 0 106 1.1 itojun LHD(17, "one mbuf"); 107 1.1 itojun LHD(18, "one ext mbuf"); 108 1.1 itojun LHD(19, "two or more ext mbuf"); 109 1.1 itojun LHD(20, "two or more mbuf"); 110 1.1 itojun #endif 111 1.1 itojun 112 1.1 itojun RHD(0, "packet forwarded"); 113 1.1 itojun RHD(1, " packet not forwardable"); 114 1.1 itojun RHD(2, " redirect sent"); 115 1.1 itojun 116 1.1 itojun RHD(4, "packet sent from this host"); 117 1.1 itojun RHD(5, " fabricated ip header"); 118 1.1 itojun RHD(6, " dropped output (no bufs)"); 119 1.1 itojun RHD(7, " dropped output (no route)"); 120 1.1 itojun RHD(8, " output datagram fragmented"); 121 1.1 itojun RHD(9, " fragment created"); 122 1.1 itojun RHD(10, " can't be fragmented"); 123 1.1 itojun 124 1.1 itojun RHD(12, "violated scope rules"); 125 1.1 itojun } 126 1.1 itojun 127 1.1 itojun void 128 1.1 itojun showip6(void) 129 1.1 itojun { 130 1.1 itojun #if 0 131 1.1 itojun u_quad_t m2m; 132 1.1 itojun int i; 133 1.1 itojun 134 1.1 itojun m2m = 0; 135 1.13 thorpej for (i = 0; i < 32; i++) { 136 1.13 thorpej m2m += curstat[IP6_STAT_M2M + i]; 137 1.1 itojun } 138 1.1 itojun #endif 139 1.1 itojun 140 1.13 thorpej SHOW(IP6_STAT_TOTAL, 0, 0); 141 1.13 thorpej SHOW(IP6_STAT_TOOSMALL, 1, 0); 142 1.13 thorpej SHOW(IP6_STAT_TOOSHORT, 2, 0); 143 1.13 thorpej SHOW(IP6_STAT_BADOPTIONS, 3, 0); 144 1.13 thorpej SHOW(IP6_STAT_BADVERS, 4, 0); 145 1.13 thorpej SHOW(IP6_STAT_EXTHDRTOOLONG, 5, 0); 146 1.13 thorpej SHOW(IP6_STAT_DELIVERED, 6, 0); 147 1.13 thorpej SHOW(IP6_STAT_NOTMEMBER, 7, 0); 148 1.13 thorpej SHOW(IP6_STAT_TOOMANYHDR, 8, 0); 149 1.13 thorpej SHOW(IP6_STAT_NOGIF, 9, 0); 150 1.13 thorpej 151 1.13 thorpej SHOW(IP6_STAT_FRAGMENTS, 11, 0); 152 1.13 thorpej SHOW(IP6_STAT_FRAGDROPPED, 12, 0); 153 1.13 thorpej SHOW(IP6_STAT_FRAGTIMEOUT, 13, 0); 154 1.13 thorpej SHOW(IP6_STAT_FRAGOVERFLOW, 14, 0); 155 1.13 thorpej SHOW(IP6_STAT_REASSEMBLED, 15, 0); 156 1.1 itojun 157 1.1 itojun #if 0 158 1.13 thorpej SHOW(IP6_STAT_M1, 17, 0); 159 1.13 thorpej SHOW(IP6_STAT_MEXT1, 18, 0); 160 1.13 thorpej SHOW(IP6_STAT_MEXT2M, 19, 0); 161 1.1 itojun mvwprintw(wnd, 20, 0, "%9llu", (unsigned long long)m2m); 162 1.1 itojun #endif 163 1.1 itojun 164 1.13 thorpej SHOW(IP6_STAT_FORWARD, 0, 35); 165 1.13 thorpej SHOW(IP6_STAT_CANTFORWARD, 1, 35); 166 1.13 thorpej SHOW(IP6_STAT_REDIRECTSENT, 2, 35); 167 1.13 thorpej 168 1.13 thorpej SHOW(IP6_STAT_LOCALOUT, 4, 35); 169 1.13 thorpej SHOW(IP6_STAT_RAWOUT, 5, 35); 170 1.13 thorpej SHOW(IP6_STAT_ODROPPED, 6, 35); 171 1.13 thorpej SHOW(IP6_STAT_NOROUTE, 7, 35); 172 1.13 thorpej SHOW(IP6_STAT_FRAGMENTED, 8, 35); 173 1.13 thorpej SHOW(IP6_STAT_OFRAGMENTS, 9, 35); 174 1.13 thorpej SHOW(IP6_STAT_CANTFRAG, 10, 35); 175 1.5 ad 176 1.13 thorpej SHOW(IP6_STAT_BADSCOPE, 12, 35); 177 1.1 itojun } 178 1.1 itojun 179 1.1 itojun int 180 1.1 itojun initip6(void) 181 1.1 itojun { 182 1.1 itojun 183 1.1 itojun return 1; 184 1.1 itojun } 185 1.1 itojun 186 1.1 itojun void 187 1.1 itojun fetchip6(void) 188 1.1 itojun { 189 1.16 joerg size_t i, size = sizeof(newstat); 190 1.14 thorpej 191 1.16 joerg if (sysctlbyname("net.inet6.ip6.stats", newstat, &size, NULL, 0) == -1) 192 1.16 joerg return; 193 1.1 itojun 194 1.13 thorpej for (i = 0; i < IP6_NSTATS; i++) 195 1.13 thorpej xADJINETCTR(curstat, oldstat, newstat, i); 196 1.5 ad 197 1.5 ad if (update == UPDATE_TIME) 198 1.13 thorpej memcpy(oldstat, newstat, sizeof(oldstat)); 199 1.5 ad } 200 1.5 ad 201 1.5 ad void 202 1.5 ad ip6_boot(char *args) 203 1.5 ad { 204 1.5 ad 205 1.13 thorpej memset(oldstat, 0, sizeof(oldstat)); 206 1.5 ad update = UPDATE_BOOT; 207 1.5 ad } 208 1.5 ad 209 1.5 ad void 210 1.5 ad ip6_run(char *args) 211 1.5 ad { 212 1.5 ad 213 1.5 ad if (update != UPDATE_RUN) { 214 1.13 thorpej memcpy(oldstat, newstat, sizeof(oldstat)); 215 1.5 ad update = UPDATE_RUN; 216 1.5 ad } 217 1.5 ad } 218 1.5 ad 219 1.5 ad void 220 1.5 ad ip6_time(char *args) 221 1.5 ad { 222 1.5 ad 223 1.5 ad if (update != UPDATE_TIME) { 224 1.13 thorpej memcpy(oldstat, newstat, sizeof(oldstat)); 225 1.5 ad update = UPDATE_TIME; 226 1.5 ad } 227 1.5 ad } 228 1.5 ad 229 1.5 ad void 230 1.5 ad ip6_zero(char *args) 231 1.5 ad { 232 1.5 ad 233 1.5 ad if (update == UPDATE_RUN) 234 1.13 thorpej memcpy(oldstat, newstat, sizeof(oldstat)); 235 1.1 itojun } 236