1 /* $NetBSD: ip6.c,v 1.14 2008/04/10 17:14:25 thorpej Exp $ */
4 * Copyright (c) 1999, 2000 Andrew Doran <ad@NetBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
30 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: ip6.c,v 1.14 2008/04/10 17:14:25 thorpej Exp $");
35 #include <sys/param.h>
36 #include <sys/sysctl.h>
38 #include <netinet/in.h>
39 #include <netinet/in_systm.h>
40 #include <netinet/ip6.h>
41 #include <netinet6/ip6_var.h>
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])
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
];
64 static struct nlist namelist
[] = {
65 { .n_name
= "_ip6stat" },
73 return (subwin(stdscr
, -1, 0, 5, 0));
91 wmove(wnd
, 0, 0); wclrtoeol(wnd
);
93 LHD(0, "total packet received");
94 LHD(1, " smaller than minimum");
95 LHD(2, " data size < data length");
96 LHD(3, " bad options");
97 LHD(4, " incorrect version no");
98 LHD(5, " headers not continuous");
99 LHD(6, " packet for this host");
100 LHD(7, " multicast we don't join");
101 LHD(8, " too many headers");
102 LHD(9, " tunneled packet w/o gif");
104 LHD(11, " fragment received");
105 LHD(12, " fragment dropped");
106 LHD(13, " fragment timeout");
107 LHD(14, " fragment exceeded limit");
108 LHD(15, " packet reassembled ok");
112 LHD(18, "one ext mbuf");
113 LHD(19, "two or more ext mbuf");
114 LHD(20, "two or more mbuf");
117 RHD(0, "packet forwarded");
118 RHD(1, " packet not forwardable");
119 RHD(2, " redirect sent");
121 RHD(4, "packet sent from this host");
122 RHD(5, " fabricated ip header");
123 RHD(6, " dropped output (no bufs)");
124 RHD(7, " dropped output (no route)");
125 RHD(8, " output datagram fragmented");
126 RHD(9, " fragment created");
127 RHD(10, " can't be fragmented");
129 RHD(12, "violated scope rules");
140 for (i
= 0; i
< 32; i
++) {
141 m2m
+= curstat
[IP6_STAT_M2M
+ i
];
145 SHOW(IP6_STAT_TOTAL
, 0, 0);
146 SHOW(IP6_STAT_TOOSMALL
, 1, 0);
147 SHOW(IP6_STAT_TOOSHORT
, 2, 0);
148 SHOW(IP6_STAT_BADOPTIONS
, 3, 0);
149 SHOW(IP6_STAT_BADVERS
, 4, 0);
150 SHOW(IP6_STAT_EXTHDRTOOLONG
, 5, 0);
151 SHOW(IP6_STAT_DELIVERED
, 6, 0);
152 SHOW(IP6_STAT_NOTMEMBER
, 7, 0);
153 SHOW(IP6_STAT_TOOMANYHDR
, 8, 0);
154 SHOW(IP6_STAT_NOGIF
, 9, 0);
156 SHOW(IP6_STAT_FRAGMENTS
, 11, 0);
157 SHOW(IP6_STAT_FRAGDROPPED
, 12, 0);
158 SHOW(IP6_STAT_FRAGTIMEOUT
, 13, 0);
159 SHOW(IP6_STAT_FRAGOVERFLOW
, 14, 0);
160 SHOW(IP6_STAT_REASSEMBLED
, 15, 0);
163 SHOW(IP6_STAT_M1
, 17, 0);
164 SHOW(IP6_STAT_MEXT1
, 18, 0);
165 SHOW(IP6_STAT_MEXT2M
, 19, 0);
166 mvwprintw(wnd
, 20, 0, "%9llu", (unsigned long long)m2m
);
169 SHOW(IP6_STAT_FORWARD
, 0, 35);
170 SHOW(IP6_STAT_CANTFORWARD
, 1, 35);
171 SHOW(IP6_STAT_REDIRECTSENT
, 2, 35);
173 SHOW(IP6_STAT_LOCALOUT
, 4, 35);
174 SHOW(IP6_STAT_RAWOUT
, 5, 35);
175 SHOW(IP6_STAT_ODROPPED
, 6, 35);
176 SHOW(IP6_STAT_NOROUTE
, 7, 35);
177 SHOW(IP6_STAT_FRAGMENTED
, 8, 35);
178 SHOW(IP6_STAT_OFRAGMENTS
, 9, 35);
179 SHOW(IP6_STAT_CANTFRAG
, 10, 35);
181 SHOW(IP6_STAT_BADSCOPE
, 12, 35);
190 if (namelist
[0].n_type
== 0) {
191 n
= kvm_nlist(kd
, namelist
);
195 } else if (n
== sizeof(namelist
) / sizeof(namelist
[0]) - 1) {
196 error("No namelist");
210 size_t size
= sizeof(newstat
);
212 if (sysctlbyname("net.inet6.ip6.stats", newstat
, &size
,
216 KREAD((void *)namelist
[0].n_value
, newstat
, sizeof(newstat
));
219 for (i
= 0; i
< IP6_NSTATS
; i
++)
220 xADJINETCTR(curstat
, oldstat
, newstat
, i
);
222 if (update
== UPDATE_TIME
)
223 memcpy(oldstat
, newstat
, sizeof(oldstat
));
230 memset(oldstat
, 0, sizeof(oldstat
));
231 update
= UPDATE_BOOT
;
238 if (update
!= UPDATE_RUN
) {
239 memcpy(oldstat
, newstat
, sizeof(oldstat
));
248 if (update
!= UPDATE_TIME
) {
249 memcpy(oldstat
, newstat
, sizeof(oldstat
));
250 update
= UPDATE_TIME
;
258 if (update
== UPDATE_RUN
)
259 memcpy(oldstat
, newstat
, sizeof(oldstat
));