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