1 /* $NetBSD: ip6.c,v 1.11 2005/02/26 22:12:33 dsl Exp $ */ 2 3 /* 4 * Copyright (c) 1999, 2000 Andrew Doran <ad@NetBSD.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 */ 29 30 #include <sys/cdefs.h> 31 #ifndef lint 32 __RCSID("$NetBSD: ip6.c,v 1.11 2005/02/26 22:12:33 dsl Exp $"); 33 #endif /* not lint */ 34 35 #include <sys/param.h> 36 #include <sys/sysctl.h> 37 38 #include <netinet/in.h> 39 #include <netinet/in_systm.h> 40 #include <netinet/ip6.h> 41 #include <netinet6/ip6_var.h> 42 43 #include <string.h> 44 45 #include "systat.h" 46 #include "extern.h" 47 48 #define LHD(row, str) mvwprintw(wnd, row, 10, str) 49 #define RHD(row, str) mvwprintw(wnd, row, 45, str); 50 #define SHOW(stat, row, col) \ 51 mvwprintw(wnd, row, col, "%9llu", (unsigned long long)curstat.stat) 52 53 enum update { 54 UPDATE_TIME, 55 UPDATE_BOOT, 56 UPDATE_RUN, 57 }; 58 59 static enum update update = UPDATE_TIME; 60 static struct ip6stat curstat; 61 static struct ip6stat newstat; 62 static struct ip6stat oldstat; 63 64 static struct nlist namelist[] = { 65 { "_ip6stat" }, 66 { "" } 67 }; 68 69 WINDOW * 70 openip6(void) 71 { 72 73 return (subwin(stdscr, -1, 0, 5, 0)); 74 } 75 76 void 77 closeip6(WINDOW *w) 78 { 79 80 if (w != NULL) { 81 wclear(w); 82 wrefresh(w); 83 delwin(w); 84 } 85 } 86 87 void 88 labelip6(void) 89 { 90 91 wmove(wnd, 0, 0); wclrtoeol(wnd); 92 93 LHD(0, "total packet received"); 94 LHD(1, " smaller than minimum"); 95 LHD(2, " data size < data length"); 96 LHD(3, " bad options"); 97 LHD(4, " incorrect version no"); 98 LHD(5, " headers not continuous"); 99 LHD(6, " packet for this host"); 100 LHD(7, " multicast we don't join"); 101 LHD(8, " too many headers"); 102 LHD(9, " tunneled packet w/o gif"); 103 104 LHD(11, " fragment received"); 105 LHD(12, " fragment dropped"); 106 LHD(13, " fragment timeout"); 107 LHD(14, " fragment exceeded limit"); 108 LHD(15, " packet reassembled ok"); 109 110 #if 0 111 LHD(17, "one mbuf"); 112 LHD(18, "one ext mbuf"); 113 LHD(19, "two or more ext mbuf"); 114 LHD(20, "two or more mbuf"); 115 #endif 116 117 RHD(0, "packet forwarded"); 118 RHD(1, " packet not forwardable"); 119 RHD(2, " redirect sent"); 120 121 RHD(4, "packet sent from this host"); 122 RHD(5, " fabricated ip header"); 123 RHD(6, " dropped output (no bufs)"); 124 RHD(7, " dropped output (no route)"); 125 RHD(8, " output datagram fragmented"); 126 RHD(9, " fragment created"); 127 RHD(10, " can't be fragmented"); 128 129 RHD(12, "violated scope rules"); 130 } 131 132 void 133 showip6(void) 134 { 135 #if 0 136 u_quad_t m2m; 137 int i; 138 139 m2m = 0; 140 for (i = 0; 141 i < sizeof(curstat.ip6s_m2m)/sizeof(curstat.ip6s_m2m[0]); 142 i++) { 143 m2m += curstat.ip6s_m2m[i]; 144 } 145 #endif 146 147 SHOW(ip6s_total, 0, 0); 148 SHOW(ip6s_toosmall, 1, 0); 149 SHOW(ip6s_tooshort, 2, 0); 150 SHOW(ip6s_badoptions, 3, 0); 151 SHOW(ip6s_badvers, 4, 0); 152 SHOW(ip6s_exthdrtoolong, 5, 0); 153 SHOW(ip6s_delivered, 6, 0); 154 SHOW(ip6s_notmember, 7, 0); 155 SHOW(ip6s_toomanyhdr, 8, 0); 156 SHOW(ip6s_nogif, 9, 0); 157 158 SHOW(ip6s_fragments, 11, 0); 159 SHOW(ip6s_fragdropped, 12, 0); 160 SHOW(ip6s_fragtimeout, 13, 0); 161 SHOW(ip6s_fragoverflow, 14, 0); 162 SHOW(ip6s_reassembled, 15, 0); 163 164 #if 0 165 SHOW(ip6s_m1, 17, 0); 166 SHOW(ip6s_mext1, 18, 0); 167 SHOW(ip6s_mext2m, 19, 0); 168 mvwprintw(wnd, 20, 0, "%9llu", (unsigned long long)m2m); 169 #endif 170 171 SHOW(ip6s_forward, 0, 35); 172 SHOW(ip6s_cantforward, 1, 35); 173 SHOW(ip6s_redirectsent, 2, 35); 174 175 SHOW(ip6s_localout, 4, 35); 176 SHOW(ip6s_rawout, 5, 35); 177 SHOW(ip6s_odropped, 6, 35); 178 SHOW(ip6s_noroute, 7, 35); 179 SHOW(ip6s_fragmented, 8, 35); 180 SHOW(ip6s_ofragments, 9, 35); 181 SHOW(ip6s_cantfrag, 10, 35); 182 183 SHOW(ip6s_badscope, 12, 35); 184 } 185 186 int 187 initip6(void) 188 { 189 int n; 190 191 if (namelist[0].n_type == 0) { 192 n = kvm_nlist(kd, namelist); 193 if (n < 0) { 194 nlisterr(namelist); 195 return(0); 196 } else if (n == sizeof(namelist) / sizeof(namelist[0]) - 1) { 197 error("No namelist"); 198 return(0); 199 } 200 } 201 return 1; 202 } 203 204 void 205 fetchip6(void) 206 { 207 208 KREAD((void *)namelist[0].n_value, &newstat, sizeof(newstat)); 209 210 ADJINETCTR(curstat, oldstat, newstat, ip6s_total); 211 ADJINETCTR(curstat, oldstat, newstat, ip6s_toosmall); 212 ADJINETCTR(curstat, oldstat, newstat, ip6s_tooshort); 213 ADJINETCTR(curstat, oldstat, newstat, ip6s_badoptions); 214 ADJINETCTR(curstat, oldstat, newstat, ip6s_badvers); 215 ADJINETCTR(curstat, oldstat, newstat, ip6s_exthdrtoolong); 216 ADJINETCTR(curstat, oldstat, newstat, ip6s_delivered); 217 ADJINETCTR(curstat, oldstat, newstat, ip6s_notmember); 218 ADJINETCTR(curstat, oldstat, newstat, ip6s_toomanyhdr); 219 ADJINETCTR(curstat, oldstat, newstat, ip6s_nogif); 220 ADJINETCTR(curstat, oldstat, newstat, ip6s_fragments); 221 ADJINETCTR(curstat, oldstat, newstat, ip6s_fragdropped); 222 ADJINETCTR(curstat, oldstat, newstat, ip6s_fragtimeout); 223 ADJINETCTR(curstat, oldstat, newstat, ip6s_fragoverflow); 224 ADJINETCTR(curstat, oldstat, newstat, ip6s_reassembled); 225 ADJINETCTR(curstat, oldstat, newstat, ip6s_m1); 226 ADJINETCTR(curstat, oldstat, newstat, ip6s_mext1); 227 ADJINETCTR(curstat, oldstat, newstat, ip6s_mext2m); 228 ADJINETCTR(curstat, oldstat, newstat, ip6s_forward); 229 ADJINETCTR(curstat, oldstat, newstat, ip6s_cantforward); 230 ADJINETCTR(curstat, oldstat, newstat, ip6s_redirectsent); 231 ADJINETCTR(curstat, oldstat, newstat, ip6s_localout); 232 ADJINETCTR(curstat, oldstat, newstat, ip6s_rawout); 233 ADJINETCTR(curstat, oldstat, newstat, ip6s_odropped); 234 ADJINETCTR(curstat, oldstat, newstat, ip6s_noroute); 235 ADJINETCTR(curstat, oldstat, newstat, ip6s_fragmented); 236 ADJINETCTR(curstat, oldstat, newstat, ip6s_ofragments); 237 ADJINETCTR(curstat, oldstat, newstat, ip6s_cantfrag); 238 ADJINETCTR(curstat, oldstat, newstat, ip6s_badscope); 239 240 if (update == UPDATE_TIME) 241 memcpy(&oldstat, &newstat, sizeof(oldstat)); 242 } 243 244 void 245 ip6_boot(char *args) 246 { 247 248 memset(&oldstat, 0, sizeof(oldstat)); 249 update = UPDATE_BOOT; 250 } 251 252 void 253 ip6_run(char *args) 254 { 255 256 if (update != UPDATE_RUN) { 257 memcpy(&oldstat, &newstat, sizeof(oldstat)); 258 update = UPDATE_RUN; 259 } 260 } 261 262 void 263 ip6_time(char *args) 264 { 265 266 if (update != UPDATE_TIME) { 267 memcpy(&oldstat, &newstat, sizeof(oldstat)); 268 update = UPDATE_TIME; 269 } 270 } 271 272 void 273 ip6_zero(char *args) 274 { 275 276 if (update == UPDATE_RUN) 277 memcpy(&oldstat, &newstat, sizeof(oldstat)); 278 } 279