Home | History | Annotate | Line # | Download | only in systat
ip6.c revision 1.5
      1 /*	$NetBSD: ip6.c,v 1.5 2000/07/05 11:03:22 ad Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1999, 2000 Andrew Doran <ad (at) 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.5 2000/07/05 11:03:22 ad Exp $");
     33 #endif /* not lint */
     34 
     35 #include <sys/param.h>
     36 #include <sys/types.h>
     37 #include <sys/socket.h>
     38 #include <sys/sysctl.h>
     39 
     40 #include <netinet/in.h>
     41 #include <netinet/in_systm.h>
     42 #include <netinet/ip6.h>
     43 #include <netinet6/ip6_var.h>
     44 
     45 #include <stdlib.h>
     46 #include <string.h>
     47 #include <paths.h>
     48 #include <nlist.h>
     49 #include <kvm.h>
     50 
     51 #include "systat.h"
     52 #include "extern.h"
     53 
     54 #define LHD(row, str)		mvwprintw(wnd, row, 10, str)
     55 #define RHD(row, str)		mvwprintw(wnd, row, 45, str);
     56 #define SHOW(stat, row, col) \
     57     mvwprintw(wnd, row, col, "%9llu", (unsigned long long)curstat.##stat)
     58 
     59 enum update {
     60 	UPDATE_TIME,
     61 	UPDATE_BOOT,
     62 	UPDATE_RUN,
     63 };
     64 
     65 static enum update update = UPDATE_TIME;
     66 static struct ip6stat curstat;
     67 static struct ip6stat newstat;
     68 static struct ip6stat oldstat;
     69 
     70 static struct nlist namelist[] = {
     71 	{ "_ip6stat" },
     72 	{ "" }
     73 };
     74 
     75 WINDOW *
     76 openip6(void)
     77 {
     78 
     79 	return (subwin(stdscr, LINES-5-1, 0, 5, 0));
     80 }
     81 
     82 void
     83 closeip6(WINDOW *w)
     84 {
     85 
     86 	if (w != NULL) {
     87 		wclear(w);
     88 		wrefresh(w);
     89 		delwin(w);
     90 	}
     91 }
     92 
     93 void
     94 labelip6(void)
     95 {
     96 
     97 	wmove(wnd, 0, 0); wclrtoeol(wnd);
     98 
     99 	LHD(0,	"total packet received");
    100 	LHD(1,	"  smaller than minimum");
    101 	LHD(2,	"  data size < data length");
    102 	LHD(3,	"  bad options");
    103 	LHD(4,	"  incorrect version no");
    104 	LHD(5,	"  headers not continuous");
    105 	LHD(6,	"  packet for this host");
    106 	LHD(7,	"  multicast we don't join");
    107 	LHD(8,	"  too many headers");
    108 	LHD(9,	"  tunneled packet w/o gif");
    109 
    110 	LHD(11,	"  fragment received");
    111 	LHD(12,	"  fragment dropped");
    112 	LHD(13,	"  fragment timeout");
    113 	LHD(14,	"  fragment exceeded limit");
    114 	LHD(15,	"  packet reassembled ok");
    115 
    116 #if 0
    117 	LHD(17,	"one mbuf");
    118 	LHD(18,	"one ext mbuf");
    119 	LHD(19,	"two or more ext mbuf");
    120 	LHD(20,	"two or more mbuf");
    121 #endif
    122 
    123 	RHD(0,	"packet forwarded");
    124 	RHD(1,	"  packet not forwardable");
    125 	RHD(2,	"  redirect sent");
    126 
    127 	RHD(4,	"packet sent from this host");
    128 	RHD(5,	"  fabricated ip header");
    129 	RHD(6,	"  dropped output (no bufs)");
    130 	RHD(7,	"  dropped output (no route)");
    131 	RHD(8,	"  output datagram fragmented");
    132 	RHD(9,	"  fragment created");
    133 	RHD(10,	"  can't be fragmented");
    134 
    135 	RHD(12,	"violated scope rules");
    136 	RHD(13,	"call to m_pulldown");
    137 	RHD(14,	"mbuf allocation in m_pulldown");
    138 	RHD(15,	"mbuf copy in m_pulldown");
    139 }
    140 
    141 void
    142 showip6(void)
    143 {
    144 #if 0
    145 	u_quad_t m2m;
    146 	int i;
    147 
    148 	m2m = 0;
    149 	for (i = 0;
    150 	     i < sizeof(curstat.ip6s_m2m)/sizeof(curstat.ip6s_m2m[0]);
    151 	     i++) {
    152 		m2m += curstat.ip6s_m2m[i];
    153 	}
    154 #endif
    155 
    156 	SHOW(ip6s_total, 0, 0);
    157 	SHOW(ip6s_toosmall, 1, 0);
    158 	SHOW(ip6s_tooshort, 2, 0);
    159 	SHOW(ip6s_badoptions, 3, 0);
    160 	SHOW(ip6s_badvers, 4, 0);
    161 	SHOW(ip6s_exthdrtoolong, 5, 0);
    162 	SHOW(ip6s_delivered, 6, 0);
    163 	SHOW(ip6s_notmember, 7, 0);
    164 	SHOW(ip6s_toomanyhdr, 8, 0);
    165 	SHOW(ip6s_nogif, 9, 0);
    166 
    167 	SHOW(ip6s_fragments, 11, 0);
    168 	SHOW(ip6s_fragdropped, 12, 0);
    169 	SHOW(ip6s_fragtimeout, 13, 0);
    170 	SHOW(ip6s_fragoverflow, 14, 0);
    171 	SHOW(ip6s_reassembled, 15, 0);
    172 
    173 #if 0
    174 	SHOW(ip6s_m1, 17, 0);
    175 	SHOW(ip6s_mext1, 18, 0);
    176 	SHOW(ip6s_mext2m, 19, 0);
    177 	mvwprintw(wnd, 20, 0, "%9llu", (unsigned long long)m2m);
    178 #endif
    179 
    180 	SHOW(ip6s_forward, 0, 35);
    181 	SHOW(ip6s_cantforward, 1, 35);
    182 	SHOW(ip6s_redirectsent, 2, 35);
    183 
    184 	SHOW(ip6s_localout, 4, 35);
    185 	SHOW(ip6s_rawout, 5, 35);
    186 	SHOW(ip6s_odropped, 6, 35);
    187 	SHOW(ip6s_noroute, 7, 35);
    188 	SHOW(ip6s_fragmented, 8, 35);
    189 	SHOW(ip6s_ofragments, 9, 35);
    190 	SHOW(ip6s_cantfrag, 10, 35);
    191 
    192 	SHOW(ip6s_badscope, 12, 35);
    193 	SHOW(ip6s_pulldown, 13, 35);
    194 	SHOW(ip6s_pulldown_alloc, 14, 35);
    195 	SHOW(ip6s_pulldown_copy, 15, 35);
    196 }
    197 
    198 int
    199 initip6(void)
    200 {
    201 	int n;
    202 
    203 	if (namelist[0].n_type == 0) {
    204 		n = kvm_nlist(kd, namelist);
    205 		if (n < 0) {
    206 			nlisterr(namelist);
    207 			return(0);
    208 		} else if (n == sizeof(namelist) / sizeof(namelist[0]) - 1) {
    209 			error("No namelist");
    210 			return(0);
    211 		}
    212 	}
    213 	return 1;
    214 }
    215 
    216 void
    217 fetchip6(void)
    218 {
    219 
    220 	ADJINETCTR(curstat, oldstat, newstat, ip6s_total);
    221 	ADJINETCTR(curstat, oldstat, newstat, ip6s_toosmall);
    222 	ADJINETCTR(curstat, oldstat, newstat, ip6s_tooshort);
    223 	ADJINETCTR(curstat, oldstat, newstat, ip6s_badoptions);
    224 	ADJINETCTR(curstat, oldstat, newstat, ip6s_badvers);
    225 	ADJINETCTR(curstat, oldstat, newstat, ip6s_exthdrtoolong);
    226 	ADJINETCTR(curstat, oldstat, newstat, ip6s_delivered);
    227 	ADJINETCTR(curstat, oldstat, newstat, ip6s_notmember);
    228 	ADJINETCTR(curstat, oldstat, newstat, ip6s_toomanyhdr);
    229 	ADJINETCTR(curstat, oldstat, newstat, ip6s_nogif);
    230 	ADJINETCTR(curstat, oldstat, newstat, ip6s_fragments);
    231 	ADJINETCTR(curstat, oldstat, newstat, ip6s_fragdropped);
    232 	ADJINETCTR(curstat, oldstat, newstat, ip6s_fragtimeout);
    233 	ADJINETCTR(curstat, oldstat, newstat, ip6s_fragoverflow);
    234 	ADJINETCTR(curstat, oldstat, newstat, ip6s_reassembled);
    235 	ADJINETCTR(curstat, oldstat, newstat, ip6s_m1);
    236 	ADJINETCTR(curstat, oldstat, newstat, ip6s_mext1);
    237 	ADJINETCTR(curstat, oldstat, newstat, ip6s_mext2m);
    238 	ADJINETCTR(curstat, oldstat, newstat, ip6s_forward);
    239 	ADJINETCTR(curstat, oldstat, newstat, ip6s_cantforward);
    240 	ADJINETCTR(curstat, oldstat, newstat, ip6s_redirectsent);
    241 	ADJINETCTR(curstat, oldstat, newstat, ip6s_localout);
    242 	ADJINETCTR(curstat, oldstat, newstat, ip6s_rawout);
    243 	ADJINETCTR(curstat, oldstat, newstat, ip6s_odropped);
    244 	ADJINETCTR(curstat, oldstat, newstat, ip6s_noroute);
    245 	ADJINETCTR(curstat, oldstat, newstat, ip6s_fragmented);
    246 	ADJINETCTR(curstat, oldstat, newstat, ip6s_ofragments);
    247 	ADJINETCTR(curstat, oldstat, newstat, ip6s_cantfrag);
    248 	ADJINETCTR(curstat, oldstat, newstat, ip6s_badscope);
    249 	ADJINETCTR(curstat, oldstat, newstat, ip6s_pulldown);
    250 	ADJINETCTR(curstat, oldstat, newstat, ip6s_pulldown_alloc);
    251 	ADJINETCTR(curstat, oldstat, newstat, ip6s_pulldown_copy);
    252 
    253 	if (update == UPDATE_TIME)
    254 		memcpy(&oldstat, &newstat, sizeof(oldstat));
    255 }
    256 
    257 void
    258 ip6_boot(char *args)
    259 {
    260 
    261 	memset(&oldstat, 0, sizeof(oldstat));
    262 	update = UPDATE_BOOT;
    263 }
    264 
    265 void
    266 ip6_run(char *args)
    267 {
    268 
    269 	if (update != UPDATE_RUN) {
    270 		memcpy(&oldstat, &newstat, sizeof(oldstat));
    271 		update = UPDATE_RUN;
    272 	}
    273 }
    274 
    275 void
    276 ip6_time(char *args)
    277 {
    278 
    279 	if (update != UPDATE_TIME) {
    280 		memcpy(&oldstat, &newstat, sizeof(oldstat));
    281 		update = UPDATE_TIME;
    282 	}
    283 }
    284 
    285 void
    286 ip6_zero(char *args)
    287 {
    288 
    289 	if (update == UPDATE_RUN)
    290 		memcpy(&oldstat, &newstat, sizeof(oldstat));
    291 }
    292