Home | History | Annotate | Line # | Download | only in systat
      1 /*	$NetBSD: ip6.c,v 1.16 2014/06/03 22:22:41 joerg 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.16 2014/06/03 22:22:41 joerg 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 uint64_t curstat[IP6_NSTATS];
     61 static uint64_t newstat[IP6_NSTATS];
     62 static uint64_t oldstat[IP6_NSTATS];
     63 
     64 WINDOW *
     65 openip6(void)
     66 {
     67 
     68 	return (subwin(stdscr, -1, 0, 5, 0));
     69 }
     70 
     71 void
     72 closeip6(WINDOW *w)
     73 {
     74 
     75 	if (w != NULL) {
     76 		wclear(w);
     77 		wrefresh(w);
     78 		delwin(w);
     79 	}
     80 }
     81 
     82 void
     83 labelip6(void)
     84 {
     85 
     86 	wmove(wnd, 0, 0); wclrtoeol(wnd);
     87 
     88 	LHD(0,	"total packet received");
     89 	LHD(1,	"  smaller than minimum");
     90 	LHD(2,	"  data size < data length");
     91 	LHD(3,	"  bad options");
     92 	LHD(4,	"  incorrect version no");
     93 	LHD(5,	"  headers not continuous");
     94 	LHD(6,	"  packet for this host");
     95 	LHD(7,	"  multicast we don't join");
     96 	LHD(8,	"  too many headers");
     97 	LHD(9,	"  tunneled packet w/o gif");
     98 
     99 	LHD(11,	"  fragment received");
    100 	LHD(12,	"  fragment dropped");
    101 	LHD(13,	"  fragment timeout");
    102 	LHD(14,	"  fragment exceeded limit");
    103 	LHD(15,	"  packet reassembled ok");
    104 
    105 #if 0
    106 	LHD(17,	"one mbuf");
    107 	LHD(18,	"one ext mbuf");
    108 	LHD(19,	"two or more ext mbuf");
    109 	LHD(20,	"two or more mbuf");
    110 #endif
    111 
    112 	RHD(0,	"packet forwarded");
    113 	RHD(1,	"  packet not forwardable");
    114 	RHD(2,	"  redirect sent");
    115 
    116 	RHD(4,	"packet sent from this host");
    117 	RHD(5,	"  fabricated ip header");
    118 	RHD(6,	"  dropped output (no bufs)");
    119 	RHD(7,	"  dropped output (no route)");
    120 	RHD(8,	"  output datagram fragmented");
    121 	RHD(9,	"  fragment created");
    122 	RHD(10,	"  can't be fragmented");
    123 
    124 	RHD(12,	"violated scope rules");
    125 }
    126 
    127 void
    128 showip6(void)
    129 {
    130 #if 0
    131 	u_quad_t m2m;
    132 	int i;
    133 
    134 	m2m = 0;
    135 	for (i = 0; i < 32; i++) {
    136 		m2m += curstat[IP6_STAT_M2M + i];
    137 	}
    138 #endif
    139 
    140 	SHOW(IP6_STAT_TOTAL, 0, 0);
    141 	SHOW(IP6_STAT_TOOSMALL, 1, 0);
    142 	SHOW(IP6_STAT_TOOSHORT, 2, 0);
    143 	SHOW(IP6_STAT_BADOPTIONS, 3, 0);
    144 	SHOW(IP6_STAT_BADVERS, 4, 0);
    145 	SHOW(IP6_STAT_EXTHDRTOOLONG, 5, 0);
    146 	SHOW(IP6_STAT_DELIVERED, 6, 0);
    147 	SHOW(IP6_STAT_NOTMEMBER, 7, 0);
    148 	SHOW(IP6_STAT_TOOMANYHDR, 8, 0);
    149 	SHOW(IP6_STAT_NOGIF, 9, 0);
    150 
    151 	SHOW(IP6_STAT_FRAGMENTS, 11, 0);
    152 	SHOW(IP6_STAT_FRAGDROPPED, 12, 0);
    153 	SHOW(IP6_STAT_FRAGTIMEOUT, 13, 0);
    154 	SHOW(IP6_STAT_FRAGOVERFLOW, 14, 0);
    155 	SHOW(IP6_STAT_REASSEMBLED, 15, 0);
    156 
    157 #if 0
    158 	SHOW(IP6_STAT_M1, 17, 0);
    159 	SHOW(IP6_STAT_MEXT1, 18, 0);
    160 	SHOW(IP6_STAT_MEXT2M, 19, 0);
    161 	mvwprintw(wnd, 20, 0, "%9llu", (unsigned long long)m2m);
    162 #endif
    163 
    164 	SHOW(IP6_STAT_FORWARD, 0, 35);
    165 	SHOW(IP6_STAT_CANTFORWARD, 1, 35);
    166 	SHOW(IP6_STAT_REDIRECTSENT, 2, 35);
    167 
    168 	SHOW(IP6_STAT_LOCALOUT, 4, 35);
    169 	SHOW(IP6_STAT_RAWOUT, 5, 35);
    170 	SHOW(IP6_STAT_ODROPPED, 6, 35);
    171 	SHOW(IP6_STAT_NOROUTE, 7, 35);
    172 	SHOW(IP6_STAT_FRAGMENTED, 8, 35);
    173 	SHOW(IP6_STAT_OFRAGMENTS, 9, 35);
    174 	SHOW(IP6_STAT_CANTFRAG, 10, 35);
    175 
    176 	SHOW(IP6_STAT_BADSCOPE, 12, 35);
    177 }
    178 
    179 int
    180 initip6(void)
    181 {
    182 
    183 	return 1;
    184 }
    185 
    186 void
    187 fetchip6(void)
    188 {
    189 	size_t i, size = sizeof(newstat);
    190 
    191 	if (sysctlbyname("net.inet6.ip6.stats", newstat, &size, NULL, 0) == -1)
    192 		return;
    193 
    194 	for (i = 0; i < IP6_NSTATS; i++)
    195 		xADJINETCTR(curstat, oldstat, newstat, i);
    196 
    197 	if (update == UPDATE_TIME)
    198 		memcpy(oldstat, newstat, sizeof(oldstat));
    199 }
    200 
    201 void
    202 ip6_boot(char *args)
    203 {
    204 
    205 	memset(oldstat, 0, sizeof(oldstat));
    206 	update = UPDATE_BOOT;
    207 }
    208 
    209 void
    210 ip6_run(char *args)
    211 {
    212 
    213 	if (update != UPDATE_RUN) {
    214 		memcpy(oldstat, newstat, sizeof(oldstat));
    215 		update = UPDATE_RUN;
    216 	}
    217 }
    218 
    219 void
    220 ip6_time(char *args)
    221 {
    222 
    223 	if (update != UPDATE_TIME) {
    224 		memcpy(oldstat, newstat, sizeof(oldstat));
    225 		update = UPDATE_TIME;
    226 	}
    227 }
    228 
    229 void
    230 ip6_zero(char *args)
    231 {
    232 
    233 	if (update == UPDATE_RUN)
    234 		memcpy(oldstat, newstat, sizeof(oldstat));
    235 }
    236