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