Home | History | Annotate | Line # | Download | only in systat
ip6.c revision 1.3
      1 /*	$NetBSD: ip6.c,v 1.3 2000/01/13 12:39:05 ad Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1999 Andy 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.3 2000/01/13 12:39:05 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 struct mystat {
     60 	struct ip6stat i;
     61 };
     62 
     63 static struct mystat curstat;
     64 
     65 static struct nlist namelist[] = {
     66 	{ "_ip6stat" },
     67 	{ "" }
     68 };
     69 
     70 WINDOW *
     71 openip6(void)
     72 {
     73 
     74 	return (subwin(stdscr, LINES-5-1, 0, 5, 0));
     75 }
     76 
     77 void
     78 closeip6(w)
     79 	WINDOW *w;
     80 {
     81 
     82 	if (w != NULL) {
     83 		wclear(w);
     84 		wrefresh(w);
     85 		delwin(w);
     86 	}
     87 }
     88 
     89 void
     90 labelip6(void)
     91 {
     92 
     93 	wmove(wnd, 0, 0); wclrtoeol(wnd);
     94 
     95 	LHD(0,	"total packet received");
     96 	LHD(1,	"  smaller than minimum");
     97 	LHD(2,	"  data size < data length");
     98 	LHD(3,	"  bad options");
     99 	LHD(4,	"  incorrect version no");
    100 	LHD(5,	"  headers not continuous");
    101 	LHD(6,	"  packet for this host");
    102 	LHD(7,	"  multicast we don't join");
    103 	LHD(8,	"  too many headers");
    104 	LHD(9,	"  tunneled packet w/o gif");
    105 
    106 	LHD(11,	"  fragment received");
    107 	LHD(12,	"  fragment dropped");
    108 	LHD(13,	"  fragment timeout");
    109 	LHD(14,	"  fragment exceeded limit");
    110 	LHD(15,	"  packet reassembled ok");
    111 
    112 #if 0
    113 	LHD(17,	"one mbuf");
    114 	LHD(18,	"one ext mbuf");
    115 	LHD(19,	"two or more ext mbuf");
    116 	LHD(20,	"two or more mbuf");
    117 #endif
    118 
    119 	RHD(0,	"packet forwarded");
    120 	RHD(1,	"  packet not forwardable");
    121 	RHD(2,	"  redirect sent");
    122 
    123 	RHD(4,	"packet sent from this host");
    124 	RHD(5,	"  fabricated ip header");
    125 	RHD(6,	"  dropped output (no bufs)");
    126 	RHD(7,	"  dropped output (no route)");
    127 	RHD(8,	"  output datagram fragmented");
    128 	RHD(9,	"  fragment created");
    129 	RHD(10,	"  can't be fragmented");
    130 
    131 	RHD(12,	"violated scope rules");
    132 	RHD(13,	"call to m_pulldown");
    133 	RHD(14,	"mbuf allocation in m_pulldown");
    134 	RHD(15,	"mbuf copy in m_pulldown");
    135 }
    136 
    137 void
    138 showip6(void)
    139 {
    140 #if 0
    141 	u_quad_t m2m;
    142 	int i;
    143 
    144 	m2m = 0;
    145 	for (i = 0;
    146 	     i < sizeof(curstat.i.ip6s_m2m)/sizeof(curstat.i.ip6s_m2m[0]);
    147 	     i++) {
    148 		m2m += curstat.i.ip6s_m2m[i];
    149 	}
    150 #endif
    151 
    152 	SHOW(i.ip6s_total, 0, 0);
    153 	SHOW(i.ip6s_toosmall, 1, 0);
    154 	SHOW(i.ip6s_tooshort, 2, 0);
    155 	SHOW(i.ip6s_badoptions, 3, 0);
    156 	SHOW(i.ip6s_badvers, 4, 0);
    157 	SHOW(i.ip6s_exthdrtoolong, 5, 0);
    158 	SHOW(i.ip6s_delivered, 6, 0);
    159 	SHOW(i.ip6s_notmember, 7, 0);
    160 	SHOW(i.ip6s_toomanyhdr, 8, 0);
    161 	SHOW(i.ip6s_nogif, 9, 0);
    162 
    163 	SHOW(i.ip6s_fragments, 11, 0);
    164 	SHOW(i.ip6s_fragdropped, 12, 0);
    165 	SHOW(i.ip6s_fragtimeout, 13, 0);
    166 	SHOW(i.ip6s_fragoverflow, 14, 0);
    167 	SHOW(i.ip6s_reassembled, 15, 0);
    168 
    169 #if 0
    170 	SHOW(i.ip6s_m1, 17, 0);
    171 	SHOW(i.ip6s_mext1, 18, 0);
    172 	SHOW(i.ip6s_mext2m, 19, 0);
    173 	mvwprintw(wnd, 20, 0, "%9llu", (unsigned long long)m2m);
    174 #endif
    175 
    176 	SHOW(i.ip6s_forward, 0, 35);
    177 	SHOW(i.ip6s_cantforward, 1, 35);
    178 	SHOW(i.ip6s_redirectsent, 2, 35);
    179 
    180 	SHOW(i.ip6s_localout, 4, 35);
    181 	SHOW(i.ip6s_rawout, 5, 35);
    182 	SHOW(i.ip6s_odropped, 6, 35);
    183 	SHOW(i.ip6s_noroute, 7, 35);
    184 	SHOW(i.ip6s_fragmented, 8, 35);
    185 	SHOW(i.ip6s_ofragments, 9, 35);
    186 	SHOW(i.ip6s_cantfrag, 10, 35);
    187 
    188 	SHOW(i.ip6s_badscope, 12, 35);
    189 	SHOW(i.ip6s_pulldown, 13, 35);
    190 	SHOW(i.ip6s_pulldown_alloc, 14, 35);
    191 	SHOW(i.ip6s_pulldown_copy, 15, 35);
    192 }
    193 
    194 int
    195 initip6(void)
    196 {
    197 	int n;
    198 
    199 	if (namelist[0].n_type == 0) {
    200 		n = kvm_nlist(kd, namelist);
    201 		if (n < 0) {
    202 			nlisterr(namelist);
    203 			return(0);
    204 		} else if (n == sizeof(namelist) / sizeof(namelist[0]) - 1) {
    205 			error("No namelist");
    206 			return(0);
    207 		}
    208 	}
    209 	return 1;
    210 }
    211 
    212 void
    213 fetchip6(void)
    214 {
    215 
    216 	KREAD((void *)namelist[0].n_value, &curstat.i, sizeof(curstat.i));
    217 }
    218