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