ip6.c revision 1.1 1 1.1 itojun /* $NetBSD: ip6.c,v 1.1 2000/01/08 23:12:37 itojun 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.1 itojun __RCSID("$NetBSD: ip6.c,v 1.1 2000/01/08 23:12:37 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.1 itojun #include "systat.h"
51 1.1 itojun #include "extern.h"
52 1.1 itojun
53 1.1 itojun #define LHD(row, str) mvwprintw(wnd, row, 10, str)
54 1.1 itojun #define RHD(row, str) mvwprintw(wnd, row, 45, str);
55 1.1 itojun #define SHOW(stat, row, col) \
56 1.1 itojun mvwprintw(wnd, row, col, "%9llu", (unsigned long long)curstat.stat)
57 1.1 itojun
58 1.1 itojun struct mystat {
59 1.1 itojun struct ip6stat i;
60 1.1 itojun };
61 1.1 itojun
62 1.1 itojun static struct mystat curstat;
63 1.1 itojun
64 1.1 itojun static struct nlist namelist[] = {
65 1.1 itojun { "_ip6stat" },
66 1.1 itojun { "" }
67 1.1 itojun };
68 1.1 itojun
69 1.1 itojun WINDOW *
70 1.1 itojun openip6(void)
71 1.1 itojun {
72 1.1 itojun
73 1.1 itojun return (subwin(stdscr, LINES-5-1, 0, 5, 0));
74 1.1 itojun }
75 1.1 itojun
76 1.1 itojun void
77 1.1 itojun closeip6(w)
78 1.1 itojun 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 RHD(13, "call to m_pulldown");
132 1.1 itojun RHD(14, "mbuf allocation in m_pulldown");
133 1.1 itojun RHD(15, "mbuf copy in m_pulldown");
134 1.1 itojun }
135 1.1 itojun
136 1.1 itojun void
137 1.1 itojun showip6(void)
138 1.1 itojun {
139 1.1 itojun #if 0
140 1.1 itojun u_quad_t m2m;
141 1.1 itojun int i;
142 1.1 itojun
143 1.1 itojun m2m = 0;
144 1.1 itojun for (i = 0;
145 1.1 itojun i < sizeof(curstat.i.ip6s_m2m)/sizeof(curstat.i.ip6s_m2m[0]);
146 1.1 itojun i++) {
147 1.1 itojun m2m += curstat.i.ip6s_m2m[i];
148 1.1 itojun }
149 1.1 itojun #endif
150 1.1 itojun
151 1.1 itojun SHOW(i.ip6s_total, 0, 0);
152 1.1 itojun SHOW(i.ip6s_toosmall, 1, 0);
153 1.1 itojun SHOW(i.ip6s_tooshort, 2, 0);
154 1.1 itojun SHOW(i.ip6s_badoptions, 3, 0);
155 1.1 itojun SHOW(i.ip6s_badvers, 4, 0);
156 1.1 itojun SHOW(i.ip6s_exthdrtoolong, 5, 0);
157 1.1 itojun SHOW(i.ip6s_delivered, 6, 0);
158 1.1 itojun SHOW(i.ip6s_notmember, 7, 0);
159 1.1 itojun SHOW(i.ip6s_toomanyhdr, 8, 0);
160 1.1 itojun SHOW(i.ip6s_nogif, 9, 0);
161 1.1 itojun
162 1.1 itojun SHOW(i.ip6s_fragments, 11, 0);
163 1.1 itojun SHOW(i.ip6s_fragdropped, 12, 0);
164 1.1 itojun SHOW(i.ip6s_fragtimeout, 13, 0);
165 1.1 itojun SHOW(i.ip6s_fragoverflow, 14, 0);
166 1.1 itojun SHOW(i.ip6s_reassembled, 15, 0);
167 1.1 itojun
168 1.1 itojun #if 0
169 1.1 itojun SHOW(i.ip6s_m1, 17, 0);
170 1.1 itojun SHOW(i.ip6s_mext1, 18, 0);
171 1.1 itojun SHOW(i.ip6s_mext2m, 19, 0);
172 1.1 itojun mvwprintw(wnd, 20, 0, "%9llu", (unsigned long long)m2m);
173 1.1 itojun #endif
174 1.1 itojun
175 1.1 itojun SHOW(i.ip6s_forward, 0, 35);
176 1.1 itojun SHOW(i.ip6s_cantforward, 1, 35);
177 1.1 itojun SHOW(i.ip6s_redirectsent, 2, 35);
178 1.1 itojun
179 1.1 itojun SHOW(i.ip6s_localout, 4, 35);
180 1.1 itojun SHOW(i.ip6s_rawout, 5, 35);
181 1.1 itojun SHOW(i.ip6s_odropped, 6, 35);
182 1.1 itojun SHOW(i.ip6s_noroute, 7, 35);
183 1.1 itojun SHOW(i.ip6s_fragmented, 8, 35);
184 1.1 itojun SHOW(i.ip6s_ofragments, 9, 35);
185 1.1 itojun SHOW(i.ip6s_cantfrag, 10, 35);
186 1.1 itojun
187 1.1 itojun SHOW(i.ip6s_badscope, 12, 35);
188 1.1 itojun SHOW(i.ip6s_pulldown, 13, 35);
189 1.1 itojun SHOW(i.ip6s_pulldown_alloc, 14, 35);
190 1.1 itojun SHOW(i.ip6s_pulldown_copy, 15, 35);
191 1.1 itojun }
192 1.1 itojun
193 1.1 itojun int
194 1.1 itojun initip6(void)
195 1.1 itojun {
196 1.1 itojun
197 1.1 itojun if (namelist[0].n_type == 0) {
198 1.1 itojun if (kvm_nlist(kd, namelist)) {
199 1.1 itojun nlisterr(namelist);
200 1.1 itojun return(0);
201 1.1 itojun }
202 1.1 itojun if (namelist[0].n_type == 0) {
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.1 itojun
214 1.1 itojun KREAD((void *)namelist[0].n_value, &curstat.i, sizeof(curstat.i));
215 1.1 itojun }
216