inet6.c revision 1.6 1 1.6 thorpej /* $NetBSD: inet6.c,v 1.6 1999/12/16 00:58:17 thorpej Exp $ */
2 1.2 itojun
3 1.1 itojun /* BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp */
4 1.1 itojun /*
5 1.1 itojun * Copyright (c) 1983, 1988, 1993
6 1.1 itojun * The Regents of the University of California. All rights reserved.
7 1.1 itojun *
8 1.1 itojun * Redistribution and use in source and binary forms, with or without
9 1.1 itojun * modification, are permitted provided that the following conditions
10 1.1 itojun * are met:
11 1.1 itojun * 1. Redistributions of source code must retain the above copyright
12 1.1 itojun * notice, this list of conditions and the following disclaimer.
13 1.1 itojun * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 itojun * notice, this list of conditions and the following disclaimer in the
15 1.1 itojun * documentation and/or other materials provided with the distribution.
16 1.1 itojun * 3. All advertising materials mentioning features or use of this software
17 1.1 itojun * must display the following acknowledgement:
18 1.1 itojun * This product includes software developed by the University of
19 1.1 itojun * California, Berkeley and its contributors.
20 1.1 itojun * 4. Neither the name of the University nor the names of its contributors
21 1.1 itojun * may be used to endorse or promote products derived from this software
22 1.1 itojun * without specific prior written permission.
23 1.1 itojun *
24 1.1 itojun * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.1 itojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.1 itojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.1 itojun * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.1 itojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.1 itojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.1 itojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.1 itojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.1 itojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.1 itojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.1 itojun * SUCH DAMAGE.
35 1.1 itojun */
36 1.1 itojun
37 1.1 itojun #include <sys/cdefs.h>
38 1.1 itojun #ifndef lint
39 1.1 itojun #if 0
40 1.1 itojun static char sccsid[] = "@(#)inet.c 8.4 (Berkeley) 4/20/94";
41 1.1 itojun #else
42 1.6 thorpej __RCSID("$NetBSD: inet6.c,v 1.6 1999/12/16 00:58:17 thorpej Exp $");
43 1.1 itojun #endif
44 1.1 itojun #endif /* not lint */
45 1.1 itojun
46 1.1 itojun #include <sys/param.h>
47 1.1 itojun #include <sys/socket.h>
48 1.1 itojun #include <sys/socketvar.h>
49 1.5 itojun #include <sys/ioctl.h>
50 1.1 itojun #include <sys/mbuf.h>
51 1.1 itojun #include <sys/protosw.h>
52 1.1 itojun
53 1.1 itojun #include <net/route.h>
54 1.1 itojun #include <net/if.h>
55 1.1 itojun #include <netinet/in.h>
56 1.1 itojun #include <netinet/ip6.h>
57 1.1 itojun #include <netinet/icmp6.h>
58 1.1 itojun #include <netinet/in_systm.h>
59 1.1 itojun #ifndef TCP6
60 1.1 itojun #include <netinet/ip.h>
61 1.1 itojun #include <netinet/ip_var.h>
62 1.1 itojun #endif
63 1.1 itojun #include <netinet6/in6_pcb.h>
64 1.5 itojun #include <netinet6/in6_var.h>
65 1.1 itojun #include <netinet6/ip6_var.h>
66 1.1 itojun #ifdef TCP6
67 1.1 itojun #include <netinet6/tcp6.h>
68 1.1 itojun #include <netinet6/tcp6_seq.h>
69 1.1 itojun #define TCP6STATES
70 1.1 itojun #include <netinet6/tcp6_fsm.h>
71 1.1 itojun #define TCP6TIMERS
72 1.1 itojun #include <netinet6/tcp6_timer.h>
73 1.1 itojun #include <netinet6/tcp6_var.h>
74 1.1 itojun #include <netinet6/tcp6_debug.h>
75 1.1 itojun #else
76 1.1 itojun #include <netinet/tcp.h>
77 1.1 itojun #include <netinet/tcpip.h>
78 1.1 itojun #include <netinet/tcp_seq.h>
79 1.1 itojun /*#define TCPSTATES*/
80 1.1 itojun #include <netinet/tcp_fsm.h>
81 1.1 itojun extern char *tcpstates[];
82 1.1 itojun /*#define TCPTIMERS*/
83 1.1 itojun #include <netinet/tcp_timer.h>
84 1.1 itojun #include <netinet/tcp_var.h>
85 1.1 itojun #include <netinet/tcp_debug.h>
86 1.1 itojun #endif /*TCP6*/
87 1.1 itojun #include <netinet6/udp6.h>
88 1.1 itojun #include <netinet6/udp6_var.h>
89 1.1 itojun #include <netinet6/pim6_var.h>
90 1.1 itojun
91 1.1 itojun #include <arpa/inet.h>
92 1.1 itojun #if 0
93 1.1 itojun #include "gethostbyname2.h"
94 1.1 itojun #endif
95 1.1 itojun #include <netdb.h>
96 1.1 itojun
97 1.1 itojun #include <stdio.h>
98 1.1 itojun #include <string.h>
99 1.1 itojun #include <unistd.h>
100 1.1 itojun #include "netstat.h"
101 1.1 itojun
102 1.1 itojun #ifdef INET6
103 1.1 itojun
104 1.1 itojun struct in6pcb in6pcb;
105 1.1 itojun #ifdef TCP6
106 1.1 itojun struct tcp6cb tcp6cb;
107 1.1 itojun #else
108 1.1 itojun struct tcpcb tcpcb;
109 1.1 itojun #endif
110 1.1 itojun struct socket sockb;
111 1.1 itojun
112 1.1 itojun char *inet6name __P((struct in6_addr *));
113 1.1 itojun void inet6print __P((struct in6_addr *, int, char *));
114 1.1 itojun
115 1.1 itojun /*
116 1.1 itojun * Print a summary of connections related to an Internet
117 1.1 itojun * protocol. For TCP, also give state of connection.
118 1.1 itojun * Listening processes (aflag) are suppressed unless the
119 1.1 itojun * -a (all) flag is specified.
120 1.1 itojun */
121 1.1 itojun void
122 1.1 itojun ip6protopr(off, name)
123 1.1 itojun u_long off;
124 1.1 itojun char *name;
125 1.1 itojun {
126 1.1 itojun struct in6pcb cb;
127 1.1 itojun register struct in6pcb *prev, *next;
128 1.1 itojun int istcp;
129 1.1 itojun static int first = 1;
130 1.1 itojun
131 1.1 itojun if (off == 0)
132 1.1 itojun return;
133 1.1 itojun istcp = strcmp(name, "tcp6") == 0;
134 1.1 itojun kread(off, (char *)&cb, sizeof (struct in6pcb));
135 1.1 itojun in6pcb = cb;
136 1.1 itojun prev = (struct in6pcb *)off;
137 1.1 itojun if (in6pcb.in6p_next == (struct in6pcb *)off)
138 1.1 itojun return;
139 1.1 itojun while (in6pcb.in6p_next != (struct in6pcb *)off) {
140 1.1 itojun next = in6pcb.in6p_next;
141 1.1 itojun kread((u_long)next, (char *)&in6pcb, sizeof (in6pcb));
142 1.1 itojun if (in6pcb.in6p_prev != prev) {
143 1.1 itojun printf("???\n");
144 1.1 itojun break;
145 1.1 itojun }
146 1.5 itojun if (!aflag && IN6_IS_ADDR_UNSPECIFIED(&in6pcb.in6p_laddr)) {
147 1.1 itojun prev = next;
148 1.1 itojun continue;
149 1.1 itojun }
150 1.1 itojun kread((u_long)in6pcb.in6p_socket, (char *)&sockb, sizeof (sockb));
151 1.1 itojun if (istcp) {
152 1.1 itojun #ifdef TCP6
153 1.1 itojun kread((u_long)in6pcb.in6p_ppcb,
154 1.1 itojun (char *)&tcp6cb, sizeof (tcp6cb));
155 1.1 itojun #else
156 1.1 itojun kread((u_long)in6pcb.in6p_ppcb,
157 1.1 itojun (char *)&tcpcb, sizeof (tcpcb));
158 1.1 itojun #endif
159 1.1 itojun }
160 1.1 itojun if (first) {
161 1.1 itojun printf("Active Internet6 connections");
162 1.1 itojun if (aflag)
163 1.1 itojun printf(" (including servers)");
164 1.1 itojun putchar('\n');
165 1.1 itojun if (Aflag)
166 1.1 itojun printf("%-8.8s ", "PCB");
167 1.1 itojun printf(Aflag ?
168 1.1 itojun "%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s %s\n" :
169 1.1 itojun "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n",
170 1.1 itojun "Proto", "Recv-Q", "Send-Q",
171 1.1 itojun "Local Address", "Foreign Address", "(state)");
172 1.1 itojun first = 0;
173 1.1 itojun }
174 1.1 itojun if (Aflag) {
175 1.1 itojun if (istcp)
176 1.1 itojun printf("%8p ", in6pcb.in6p_ppcb);
177 1.1 itojun else
178 1.1 itojun printf("%8p ", next);
179 1.1 itojun }
180 1.1 itojun printf("%-5.5s %6ld %6ld ", name, sockb.so_rcv.sb_cc,
181 1.1 itojun sockb.so_snd.sb_cc);
182 1.1 itojun /* xxx */
183 1.1 itojun inet6print(&in6pcb.in6p_laddr, (int)in6pcb.in6p_lport, name);
184 1.1 itojun inet6print(&in6pcb.in6p_faddr, (int)in6pcb.in6p_fport, name);
185 1.1 itojun if (istcp) {
186 1.1 itojun #ifdef TCP6
187 1.1 itojun if (tcp6cb.t_state < 0 || tcp6cb.t_state >= TCP6_NSTATES)
188 1.1 itojun printf(" %d", tcp6cb.t_state);
189 1.1 itojun else
190 1.1 itojun printf(" %s", tcp6states[tcp6cb.t_state]);
191 1.1 itojun #else
192 1.1 itojun if (tcpcb.t_state < 0 || tcpcb.t_state >= TCP_NSTATES)
193 1.1 itojun printf(" %d", tcpcb.t_state);
194 1.1 itojun else
195 1.1 itojun printf(" %s", tcpstates[tcpcb.t_state]);
196 1.1 itojun #endif
197 1.1 itojun }
198 1.1 itojun putchar('\n');
199 1.1 itojun prev = next;
200 1.1 itojun }
201 1.1 itojun }
202 1.1 itojun
203 1.1 itojun #ifdef TCP6
204 1.1 itojun /*
205 1.1 itojun * Dump TCP6 statistics structure.
206 1.1 itojun */
207 1.1 itojun void
208 1.1 itojun tcp6_stats(off, name)
209 1.1 itojun u_long off;
210 1.1 itojun char *name;
211 1.1 itojun {
212 1.1 itojun struct tcp6stat tcp6stat;
213 1.1 itojun
214 1.1 itojun if (off == 0)
215 1.1 itojun return;
216 1.1 itojun printf ("%s:\n", name);
217 1.1 itojun kread(off, (char *)&tcp6stat, sizeof (tcp6stat));
218 1.1 itojun
219 1.1 itojun #define p(f, m) if (tcp6stat.f || sflag <= 1) \
220 1.1 itojun printf(m, tcp6stat.f, plural(tcp6stat.f))
221 1.1 itojun #define p2(f1, f2, m) if (tcp6stat.f1 || tcp6stat.f2 || sflag <= 1) \
222 1.1 itojun printf(m, tcp6stat.f1, plural(tcp6stat.f1), tcp6stat.f2, plural(tcp6stat.f2))
223 1.1 itojun #define p3(f, m) if (tcp6stat.f || sflag <= 1) \
224 1.1 itojun printf(m, tcp6stat.f, plurales(tcp6stat.f))
225 1.1 itojun
226 1.1 itojun p(tcp6s_sndtotal, "\t%ld packet%s sent\n");
227 1.1 itojun p2(tcp6s_sndpack,tcp6s_sndbyte,
228 1.1 itojun "\t\t%ld data packet%s (%ld byte%s)\n");
229 1.1 itojun p2(tcp6s_sndrexmitpack, tcp6s_sndrexmitbyte,
230 1.1 itojun "\t\t%ld data packet%s (%ld byte%s) retransmitted\n");
231 1.1 itojun p2(tcp6s_sndacks, tcp6s_delack,
232 1.1 itojun "\t\t%ld ack-only packet%s (%ld packet%s delayed)\n");
233 1.1 itojun p(tcp6s_sndurg, "\t\t%ld URG only packet%s\n");
234 1.1 itojun p(tcp6s_sndprobe, "\t\t%ld window probe packet%s\n");
235 1.1 itojun p(tcp6s_sndwinup, "\t\t%ld window update packet%s\n");
236 1.1 itojun p(tcp6s_sndctrl, "\t\t%ld control packet%s\n");
237 1.1 itojun p(tcp6s_rcvtotal, "\t%ld packet%s received\n");
238 1.1 itojun p2(tcp6s_rcvackpack, tcp6s_rcvackbyte, "\t\t%ld ack%s (for %ld byte%s)\n");
239 1.1 itojun p(tcp6s_rcvdupack, "\t\t%ld duplicate ack%s\n");
240 1.1 itojun p(tcp6s_rcvacktoomuch, "\t\t%ld ack%s for unsent data\n");
241 1.1 itojun p2(tcp6s_rcvpack, tcp6s_rcvbyte,
242 1.1 itojun "\t\t%ld packet%s (%ld byte%s) received in-sequence\n");
243 1.1 itojun p2(tcp6s_rcvduppack, tcp6s_rcvdupbyte,
244 1.1 itojun "\t\t%ld completely duplicate packet%s (%ld byte%s)\n");
245 1.1 itojun p(tcp6s_pawsdrop, "\t\t%ld old duplicate packet%s\n");
246 1.1 itojun p2(tcp6s_rcvpartduppack, tcp6s_rcvpartdupbyte,
247 1.1 itojun "\t\t%ld packet%s with some dup. data (%ld byte%s duped)\n");
248 1.1 itojun p2(tcp6s_rcvoopack, tcp6s_rcvoobyte,
249 1.1 itojun "\t\t%ld out-of-order packet%s (%ld byte%s)\n");
250 1.1 itojun p2(tcp6s_rcvpackafterwin, tcp6s_rcvbyteafterwin,
251 1.1 itojun "\t\t%ld packet%s (%ld byte%s) of data after window\n");
252 1.1 itojun p(tcp6s_rcvwinprobe, "\t\t%ld window probe%s\n");
253 1.1 itojun p(tcp6s_rcvwinupd, "\t\t%ld window update packet%s\n");
254 1.1 itojun p(tcp6s_rcvafterclose, "\t\t%ld packet%s received after close\n");
255 1.1 itojun p(tcp6s_rcvbadsum, "\t\t%ld discarded for bad checksum%s\n");
256 1.1 itojun p(tcp6s_rcvbadoff, "\t\t%ld discarded for bad header offset field%s\n");
257 1.1 itojun p(tcp6s_rcvshort, "\t\t%ld discarded because packet%s too short\n");
258 1.1 itojun p(tcp6s_connattempt, "\t%ld connection request%s\n");
259 1.1 itojun p(tcp6s_accepts, "\t%ld connection accept%s\n");
260 1.1 itojun p(tcp6s_badsyn, "\t%ld bad connection attempt%s\n");
261 1.1 itojun p(tcp6s_connects, "\t%ld connection%s established (including accepts)\n");
262 1.1 itojun p2(tcp6s_closed, tcp6s_drops,
263 1.1 itojun "\t%ld connection%s closed (including %ld drop%s)\n");
264 1.1 itojun p(tcp6s_conndrops, "\t%ld embryonic connection%s dropped\n");
265 1.1 itojun p2(tcp6s_rttupdated, tcp6s_segstimed,
266 1.1 itojun "\t%ld segment%s updated rtt (of %ld attempt%s)\n");
267 1.1 itojun p(tcp6s_rexmttimeo, "\t%ld retransmit timeout%s\n");
268 1.1 itojun p(tcp6s_timeoutdrop, "\t\t%ld connection%s dropped by rexmit timeout\n");
269 1.1 itojun p(tcp6s_persisttimeo, "\t%ld persist timeout%s\n");
270 1.1 itojun p(tcp6s_persistdrop, "\t%ld connection%s timed out in persist\n");
271 1.1 itojun p(tcp6s_keeptimeo, "\t%ld keepalive timeout%s\n");
272 1.1 itojun p(tcp6s_keepprobe, "\t\t%ld keepalive probe%s sent\n");
273 1.1 itojun p(tcp6s_keepdrops, "\t\t%ld connection%s dropped by keepalive\n");
274 1.1 itojun p(tcp6s_predack, "\t%ld correct ACK header prediction%s\n");
275 1.1 itojun p(tcp6s_preddat, "\t%ld correct data packet header prediction%s\n");
276 1.1 itojun p3(tcp6s_pcbcachemiss, "\t%ld PCB cache miss%s\n");
277 1.1 itojun #undef p
278 1.1 itojun #undef p2
279 1.1 itojun #undef p3
280 1.1 itojun }
281 1.1 itojun #endif
282 1.1 itojun
283 1.1 itojun /*
284 1.1 itojun * Dump UDP6 statistics structure.
285 1.1 itojun */
286 1.1 itojun void
287 1.1 itojun udp6_stats(off, name)
288 1.1 itojun u_long off;
289 1.1 itojun char *name;
290 1.1 itojun {
291 1.1 itojun struct udp6stat udp6stat;
292 1.4 bouyer u_quad_t delivered;
293 1.1 itojun
294 1.1 itojun if (off == 0)
295 1.1 itojun return;
296 1.1 itojun kread(off, (char *)&udp6stat, sizeof (udp6stat));
297 1.1 itojun printf("%s:\n", name);
298 1.1 itojun #define p(f, m) if (udp6stat.f || sflag <= 1) \
299 1.4 bouyer printf(m, (unsigned long long)udp6stat.f, plural(udp6stat.f))
300 1.1 itojun #define p1(f, m) if (udp6stat.f || sflag <= 1) \
301 1.4 bouyer printf(m, (unsigned long long)udp6stat.f)
302 1.4 bouyer p(udp6s_ipackets, "\t%llu datagram%s received\n");
303 1.4 bouyer p1(udp6s_hdrops, "\t%llu with incomplete header\n");
304 1.4 bouyer p1(udp6s_badlen, "\t%llu with bad data length field\n");
305 1.4 bouyer p1(udp6s_badsum, "\t%llu with bad checksum\n");
306 1.4 bouyer p1(udp6s_nosum, "\t%llu with no checksum\n");
307 1.4 bouyer p1(udp6s_noport, "\t%llu dropped due to no socket\n");
308 1.4 bouyer p(udp6s_noportmcast, "\t%llu multicast datagram%s dropped due to no socket\n");
309 1.4 bouyer p1(udp6s_fullsock, "\t%llu dropped due to full socket buffers\n");
310 1.1 itojun delivered = udp6stat.udp6s_ipackets -
311 1.1 itojun udp6stat.udp6s_hdrops -
312 1.1 itojun udp6stat.udp6s_badlen -
313 1.1 itojun udp6stat.udp6s_badsum -
314 1.1 itojun udp6stat.udp6s_noport -
315 1.1 itojun udp6stat.udp6s_noportmcast -
316 1.1 itojun udp6stat.udp6s_fullsock;
317 1.1 itojun if (delivered || sflag <= 1)
318 1.4 bouyer printf("\t%llu delivered\n", (unsigned long long)delivered);
319 1.4 bouyer p(udp6s_opackets, "\t%llu datagram%s output\n");
320 1.1 itojun #undef p
321 1.1 itojun #undef p1
322 1.1 itojun }
323 1.1 itojun
324 1.1 itojun static char *ip6nh[] = {
325 1.1 itojun "hop by hop",
326 1.1 itojun "ICMP",
327 1.1 itojun "IGMP",
328 1.1 itojun "#3",
329 1.1 itojun "IP",
330 1.1 itojun "#5",
331 1.1 itojun "TCP",
332 1.1 itojun "#7",
333 1.1 itojun "#8",
334 1.1 itojun "#9",
335 1.1 itojun "#10",
336 1.1 itojun "#11",
337 1.1 itojun "#12",
338 1.1 itojun "#13",
339 1.1 itojun "#14",
340 1.1 itojun "#15",
341 1.1 itojun "#16",
342 1.1 itojun "UDP",
343 1.1 itojun "#18",
344 1.1 itojun "#19",
345 1.1 itojun "#20",
346 1.1 itojun "#21",
347 1.1 itojun "IDP",
348 1.1 itojun "#23",
349 1.1 itojun "#24",
350 1.1 itojun "#25",
351 1.1 itojun "#26",
352 1.1 itojun "#27",
353 1.1 itojun "#28",
354 1.1 itojun "TP",
355 1.1 itojun "#30",
356 1.1 itojun "#31",
357 1.1 itojun "#32",
358 1.1 itojun "#33",
359 1.1 itojun "#34",
360 1.1 itojun "#35",
361 1.1 itojun "#36",
362 1.1 itojun "#37",
363 1.1 itojun "#38",
364 1.1 itojun "#39",
365 1.1 itojun "#40",
366 1.1 itojun "IP6",
367 1.1 itojun "#42",
368 1.1 itojun "routing",
369 1.1 itojun "fragment",
370 1.1 itojun "#45",
371 1.1 itojun "#46",
372 1.1 itojun "#47",
373 1.1 itojun "#48",
374 1.1 itojun "#49",
375 1.1 itojun "ESP",
376 1.1 itojun "AH",
377 1.1 itojun "#52",
378 1.1 itojun "#53",
379 1.1 itojun "#54",
380 1.1 itojun "#55",
381 1.1 itojun "#56",
382 1.1 itojun "#57",
383 1.1 itojun "ICMP6",
384 1.1 itojun "no next header",
385 1.1 itojun "destination option",
386 1.1 itojun "#61",
387 1.1 itojun "#62",
388 1.1 itojun "#63",
389 1.1 itojun "#64",
390 1.1 itojun "#65",
391 1.1 itojun "#66",
392 1.1 itojun "#67",
393 1.1 itojun "#68",
394 1.1 itojun "#69",
395 1.1 itojun "#70",
396 1.1 itojun "#71",
397 1.1 itojun "#72",
398 1.1 itojun "#73",
399 1.1 itojun "#74",
400 1.1 itojun "#75",
401 1.1 itojun "#76",
402 1.1 itojun "#77",
403 1.1 itojun "#78",
404 1.1 itojun "#79",
405 1.1 itojun "ISOIP",
406 1.1 itojun "#81",
407 1.1 itojun "#82",
408 1.1 itojun "#83",
409 1.1 itojun "#84",
410 1.1 itojun "#85",
411 1.1 itojun "#86",
412 1.1 itojun "#87",
413 1.1 itojun "#88",
414 1.1 itojun "#89",
415 1.1 itojun "#80",
416 1.1 itojun "#91",
417 1.1 itojun "#92",
418 1.1 itojun "#93",
419 1.1 itojun "#94",
420 1.1 itojun "#95",
421 1.1 itojun "#96",
422 1.1 itojun "Ethernet",
423 1.1 itojun "#98",
424 1.1 itojun "#99",
425 1.1 itojun "#100",
426 1.1 itojun "#101",
427 1.1 itojun "#102",
428 1.1 itojun "PIM",
429 1.1 itojun "#104",
430 1.1 itojun "#105",
431 1.1 itojun "#106",
432 1.1 itojun "#107",
433 1.1 itojun "#108",
434 1.1 itojun "#109",
435 1.1 itojun "#110",
436 1.1 itojun "#111",
437 1.1 itojun "#112",
438 1.1 itojun "#113",
439 1.1 itojun "#114",
440 1.1 itojun "#115",
441 1.1 itojun "#116",
442 1.1 itojun "#117",
443 1.1 itojun "#118",
444 1.1 itojun "#119",
445 1.1 itojun "#120",
446 1.1 itojun "#121",
447 1.1 itojun "#122",
448 1.1 itojun "#123",
449 1.1 itojun "#124",
450 1.1 itojun "#125",
451 1.1 itojun "#126",
452 1.1 itojun "#127",
453 1.1 itojun "#128",
454 1.1 itojun "#129",
455 1.1 itojun "#130",
456 1.1 itojun "#131",
457 1.1 itojun "#132",
458 1.1 itojun "#133",
459 1.1 itojun "#134",
460 1.1 itojun "#135",
461 1.1 itojun "#136",
462 1.1 itojun "#137",
463 1.1 itojun "#138",
464 1.1 itojun "#139",
465 1.1 itojun "#140",
466 1.1 itojun "#141",
467 1.1 itojun "#142",
468 1.1 itojun "#143",
469 1.1 itojun "#144",
470 1.1 itojun "#145",
471 1.1 itojun "#146",
472 1.1 itojun "#147",
473 1.1 itojun "#148",
474 1.1 itojun "#149",
475 1.1 itojun "#150",
476 1.1 itojun "#151",
477 1.1 itojun "#152",
478 1.1 itojun "#153",
479 1.1 itojun "#154",
480 1.1 itojun "#155",
481 1.1 itojun "#156",
482 1.1 itojun "#157",
483 1.1 itojun "#158",
484 1.1 itojun "#159",
485 1.1 itojun "#160",
486 1.1 itojun "#161",
487 1.1 itojun "#162",
488 1.1 itojun "#163",
489 1.1 itojun "#164",
490 1.1 itojun "#165",
491 1.1 itojun "#166",
492 1.1 itojun "#167",
493 1.1 itojun "#168",
494 1.1 itojun "#169",
495 1.1 itojun "#170",
496 1.1 itojun "#171",
497 1.1 itojun "#172",
498 1.1 itojun "#173",
499 1.1 itojun "#174",
500 1.1 itojun "#175",
501 1.1 itojun "#176",
502 1.1 itojun "#177",
503 1.1 itojun "#178",
504 1.1 itojun "#179",
505 1.1 itojun "#180",
506 1.1 itojun "#181",
507 1.1 itojun "#182",
508 1.1 itojun "#183",
509 1.1 itojun "#184",
510 1.1 itojun "#185",
511 1.1 itojun "#186",
512 1.1 itojun "#187",
513 1.1 itojun "#188",
514 1.1 itojun "#189",
515 1.1 itojun "#180",
516 1.1 itojun "#191",
517 1.1 itojun "#192",
518 1.1 itojun "#193",
519 1.1 itojun "#194",
520 1.1 itojun "#195",
521 1.1 itojun "#196",
522 1.1 itojun "#197",
523 1.1 itojun "#198",
524 1.1 itojun "#199",
525 1.1 itojun "#200",
526 1.1 itojun "#201",
527 1.1 itojun "#202",
528 1.1 itojun "#203",
529 1.1 itojun "#204",
530 1.1 itojun "#205",
531 1.1 itojun "#206",
532 1.1 itojun "#207",
533 1.1 itojun "#208",
534 1.1 itojun "#209",
535 1.1 itojun "#210",
536 1.1 itojun "#211",
537 1.1 itojun "#212",
538 1.1 itojun "#213",
539 1.1 itojun "#214",
540 1.1 itojun "#215",
541 1.1 itojun "#216",
542 1.1 itojun "#217",
543 1.1 itojun "#218",
544 1.1 itojun "#219",
545 1.1 itojun "#220",
546 1.1 itojun "#221",
547 1.1 itojun "#222",
548 1.1 itojun "#223",
549 1.1 itojun "#224",
550 1.1 itojun "#225",
551 1.1 itojun "#226",
552 1.1 itojun "#227",
553 1.1 itojun "#228",
554 1.1 itojun "#229",
555 1.1 itojun "#230",
556 1.1 itojun "#231",
557 1.1 itojun "#232",
558 1.1 itojun "#233",
559 1.1 itojun "#234",
560 1.1 itojun "#235",
561 1.1 itojun "#236",
562 1.1 itojun "#237",
563 1.1 itojun "#238",
564 1.1 itojun "#239",
565 1.1 itojun "#240",
566 1.1 itojun "#241",
567 1.1 itojun "#242",
568 1.1 itojun "#243",
569 1.1 itojun "#244",
570 1.1 itojun "#245",
571 1.1 itojun "#246",
572 1.1 itojun "#247",
573 1.1 itojun "#248",
574 1.1 itojun "#249",
575 1.1 itojun "#250",
576 1.1 itojun "#251",
577 1.1 itojun "#252",
578 1.1 itojun "#253",
579 1.1 itojun "#254",
580 1.1 itojun "#255",
581 1.1 itojun };
582 1.1 itojun
583 1.1 itojun /*
584 1.1 itojun * Dump IP6 statistics structure.
585 1.1 itojun */
586 1.1 itojun void
587 1.1 itojun ip6_stats(off, name)
588 1.1 itojun u_long off;
589 1.1 itojun char *name;
590 1.1 itojun {
591 1.1 itojun struct ip6stat ip6stat;
592 1.1 itojun int first, i;
593 1.1 itojun
594 1.1 itojun if (off == 0)
595 1.1 itojun return;
596 1.1 itojun
597 1.1 itojun kread(off, (char *)&ip6stat, sizeof (ip6stat));
598 1.1 itojun printf("%s:\n", name);
599 1.1 itojun
600 1.1 itojun #define p(f, m) if (ip6stat.f || sflag <= 1) \
601 1.4 bouyer printf(m, (unsigned long long)ip6stat.f, plural(ip6stat.f))
602 1.1 itojun #define p1(f, m) if (ip6stat.f || sflag <= 1) \
603 1.4 bouyer printf(m, (unsigned long long)ip6stat.f)
604 1.1 itojun
605 1.4 bouyer p(ip6s_total, "\t%llu total packet%s received\n");
606 1.4 bouyer p1(ip6s_toosmall, "\t%llu with size smaller than minimum\n");
607 1.4 bouyer p1(ip6s_tooshort, "\t%llu with data size < data length\n");
608 1.4 bouyer p1(ip6s_badoptions, "\t%llu with bad options\n");
609 1.4 bouyer p1(ip6s_badvers, "\t%llu with incorrect version number\n");
610 1.4 bouyer p(ip6s_fragments, "\t%llu fragment%s received\n");
611 1.4 bouyer p(ip6s_fragdropped,
612 1.4 bouyer "\t%llu fragment%s dropped (dup or out of space)\n");
613 1.4 bouyer p(ip6s_fragtimeout, "\t%llu fragment%s dropped after timeout\n");
614 1.4 bouyer p(ip6s_fragoverflow, "\t%llu fragment%s that exceeded limit\n");
615 1.4 bouyer p(ip6s_reassembled, "\t%llu packet%s reassembled ok\n");
616 1.4 bouyer p(ip6s_delivered, "\t%llu packet%s for this host\n");
617 1.4 bouyer p(ip6s_forward, "\t%llu packet%s forwarded\n");
618 1.4 bouyer p(ip6s_cantforward, "\t%llu packet%s not forwardable\n");
619 1.4 bouyer p(ip6s_redirectsent, "\t%llu redirect%s sent\n");
620 1.4 bouyer p(ip6s_localout, "\t%llu packet%s sent from this host\n");
621 1.4 bouyer p(ip6s_rawout, "\t%llu packet%s sent with fabricated ip header\n");
622 1.4 bouyer p(ip6s_odropped,
623 1.4 bouyer "\t%llu output packet%s dropped due to no bufs, etc.\n");
624 1.4 bouyer p(ip6s_noroute, "\t%llu output packet%s discarded due to no route\n");
625 1.4 bouyer p(ip6s_fragmented, "\t%llu output datagram%s fragmented\n");
626 1.4 bouyer p(ip6s_ofragments, "\t%llu fragment%s created\n");
627 1.4 bouyer p(ip6s_cantfrag, "\t%llu datagram%s that can't be fragmented\n");
628 1.4 bouyer p(ip6s_badscope, "\t%llu packet%s that violated scope rules\n");
629 1.4 bouyer p(ip6s_notmember, "\t%llu multicast packet%s which we don't join\n");
630 1.1 itojun for (first = 1, i = 0; i < 256; i++)
631 1.1 itojun if (ip6stat.ip6s_nxthist[i] != 0) {
632 1.1 itojun if (first) {
633 1.1 itojun printf("\tInput histogram:\n");
634 1.1 itojun first = 0;
635 1.1 itojun }
636 1.4 bouyer printf("\t\t%s: %llu\n", ip6nh[i],
637 1.4 bouyer (unsigned long long)ip6stat.ip6s_nxthist[i]);
638 1.1 itojun }
639 1.1 itojun printf("\tMbuf statics:\n");
640 1.4 bouyer printf("\t\t%llu one mbuf\n", (unsigned long long)ip6stat.ip6s_m1);
641 1.1 itojun for (first = 1, i = 0; i < 32; i++) {
642 1.1 itojun char ifbuf[IFNAMSIZ];
643 1.1 itojun if (ip6stat.ip6s_m2m[i] != 0) {
644 1.1 itojun if (first) {
645 1.1 itojun printf("\t\ttwo or more mbuf:\n");
646 1.1 itojun first = 0;
647 1.1 itojun }
648 1.4 bouyer printf("\t\t\t%s = %llu\n",
649 1.1 itojun if_indextoname(i, ifbuf),
650 1.4 bouyer (unsigned long long)ip6stat.ip6s_m2m[i]);
651 1.1 itojun }
652 1.1 itojun }
653 1.4 bouyer printf("\t\t%llu one ext mbuf\n",
654 1.4 bouyer (unsigned long long)ip6stat.ip6s_mext1);
655 1.4 bouyer printf("\t\t%llu two or more ext mbuf\n",
656 1.4 bouyer (unsigned long long)ip6stat.ip6s_mext2m);
657 1.4 bouyer p(ip6s_exthdrtoolong,
658 1.4 bouyer "\t%llu packet%s whose headers are not continuous\n");
659 1.4 bouyer p(ip6s_nogif, "\t%llu tunneling packet%s that can't find gif\n");
660 1.5 itojun p(ip6s_toomanyhdr, "\t%qu packet%s discarded due to too many headers\n");
661 1.5 itojun p(ip6s_pulldown, "\t%qu call%s to m_pulldown\n");
662 1.5 itojun p(ip6s_pulldown_alloc, "\t%qu mbuf allocation%s in m_pulldown\n");
663 1.5 itojun if (ip6stat.ip6s_pulldown_copy != 1) {
664 1.5 itojun p1(ip6s_pulldown_copy, "\t%qu mbuf copies in m_pulldown\n");
665 1.5 itojun } else {
666 1.5 itojun p1(ip6s_pulldown_copy, "\t%qu mbuf copy in m_pulldown\n");
667 1.5 itojun }
668 1.1 itojun #undef p
669 1.1 itojun #undef p1
670 1.1 itojun }
671 1.1 itojun
672 1.5 itojun /*
673 1.5 itojun * Dump IPv6 per-interface statistics based on RFC 2465.
674 1.5 itojun */
675 1.5 itojun void
676 1.5 itojun ip6_ifstats(ifname)
677 1.5 itojun char *ifname;
678 1.5 itojun {
679 1.5 itojun struct in6_ifreq ifr;
680 1.5 itojun int s;
681 1.5 itojun #define p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
682 1.6 thorpej printf(m, (unsigned long long)ifr.ifr_ifru.ifru_stat.f, \
683 1.6 thorpej plural(ifr.ifr_ifru.ifru_stat.f))
684 1.5 itojun #define p_5(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
685 1.5 itojun printf(m, ip6stat.f)
686 1.5 itojun
687 1.5 itojun if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
688 1.5 itojun perror("Warning: socket(AF_INET6)");
689 1.5 itojun return;
690 1.5 itojun }
691 1.5 itojun
692 1.5 itojun strcpy(ifr.ifr_name, ifname);
693 1.5 itojun printf("ip6 on %s:\n", ifr.ifr_name);
694 1.5 itojun
695 1.5 itojun if (ioctl(s, SIOCGIFSTAT_IN6, (char *)&ifr) < 0) {
696 1.5 itojun perror("Warning: ioctl(SIOCGIFSTAT_IN6)");
697 1.5 itojun goto end;
698 1.5 itojun }
699 1.5 itojun
700 1.5 itojun p(ifs6_in_receive, "\t%llu total input datagram%s\n");
701 1.5 itojun p(ifs6_in_hdrerr, "\t%llu datagram%s with invalid header received\n");
702 1.5 itojun p(ifs6_in_toobig, "\t%llu datagram%s exceeded MTU received\n");
703 1.5 itojun p(ifs6_in_noroute, "\t%llu datagram%s with no route received\n");
704 1.5 itojun p(ifs6_in_addrerr, "\t%llu datagram%s with invalid dst received\n");
705 1.5 itojun p(ifs6_in_truncated, "\t%llu truncated datagram%s received\n");
706 1.5 itojun p(ifs6_in_protounknown, "\t%llu datagram%s with unknown proto received\n");
707 1.5 itojun p(ifs6_in_discard, "\t%llu input datagram%s discarded\n");
708 1.5 itojun p(ifs6_in_deliver,
709 1.5 itojun "\t%llu datagram%s delivered to an upper layer protocol\n");
710 1.5 itojun p(ifs6_out_forward, "\t%llu datagram%s forwarded to this interface\n");
711 1.5 itojun p(ifs6_out_request,
712 1.5 itojun "\t%llu datagram%s sent from an upper layer protocol\n");
713 1.5 itojun p(ifs6_out_discard, "\t%llu total discarded output datagram%s\n");
714 1.5 itojun p(ifs6_out_fragok, "\t%llu output datagram%s fragmented\n");
715 1.5 itojun p(ifs6_out_fragfail, "\t%llu output datagram%s failed on fragment\n");
716 1.5 itojun p(ifs6_out_fragcreat, "\t%llu output datagram%s succeeded on fragment\n");
717 1.5 itojun p(ifs6_reass_reqd, "\t%llu incoming datagram%s fragmented\n");
718 1.5 itojun p(ifs6_reass_ok, "\t%llu datagram%s reassembled\n");
719 1.5 itojun p(ifs6_reass_fail, "\t%llu datagram%s failed on reassembling\n");
720 1.5 itojun p(ifs6_in_mcast, "\t%llu multicast datagram%s received\n");
721 1.5 itojun p(ifs6_out_mcast, "\t%llu multicast datagram%s sent\n");
722 1.5 itojun
723 1.5 itojun end:
724 1.5 itojun close(s);
725 1.5 itojun
726 1.5 itojun #undef p
727 1.5 itojun #undef p_5
728 1.5 itojun }
729 1.5 itojun
730 1.1 itojun static char *icmp6names[] = {
731 1.1 itojun "#0",
732 1.1 itojun "unreach",
733 1.1 itojun "packet too big",
734 1.1 itojun "time exceed",
735 1.1 itojun "parameter problem",
736 1.1 itojun "#5",
737 1.1 itojun "#6",
738 1.1 itojun "#7",
739 1.1 itojun "#8",
740 1.1 itojun "#9",
741 1.1 itojun "#10",
742 1.1 itojun "#11",
743 1.1 itojun "#12",
744 1.1 itojun "#13",
745 1.1 itojun "#14",
746 1.1 itojun "#15",
747 1.1 itojun "#16",
748 1.1 itojun "#17",
749 1.1 itojun "#18",
750 1.1 itojun "#19",
751 1.1 itojun "#20",
752 1.1 itojun "#21",
753 1.1 itojun "#22",
754 1.1 itojun "#23",
755 1.1 itojun "#24",
756 1.1 itojun "#25",
757 1.1 itojun "#26",
758 1.1 itojun "#27",
759 1.1 itojun "#28",
760 1.1 itojun "#29",
761 1.1 itojun "#30",
762 1.1 itojun "#31",
763 1.1 itojun "#32",
764 1.1 itojun "#33",
765 1.1 itojun "#34",
766 1.1 itojun "#35",
767 1.1 itojun "#36",
768 1.1 itojun "#37",
769 1.1 itojun "#38",
770 1.1 itojun "#39",
771 1.1 itojun "#40",
772 1.1 itojun "#41",
773 1.1 itojun "#42",
774 1.1 itojun "#43",
775 1.1 itojun "#44",
776 1.1 itojun "#45",
777 1.1 itojun "#46",
778 1.1 itojun "#47",
779 1.1 itojun "#48",
780 1.1 itojun "#49",
781 1.1 itojun "#50",
782 1.1 itojun "#51",
783 1.1 itojun "#52",
784 1.1 itojun "#53",
785 1.1 itojun "#54",
786 1.1 itojun "#55",
787 1.1 itojun "#56",
788 1.1 itojun "#57",
789 1.1 itojun "#58",
790 1.1 itojun "#59",
791 1.1 itojun "#60",
792 1.1 itojun "#61",
793 1.1 itojun "#62",
794 1.1 itojun "#63",
795 1.1 itojun "#64",
796 1.1 itojun "#65",
797 1.1 itojun "#66",
798 1.1 itojun "#67",
799 1.1 itojun "#68",
800 1.1 itojun "#69",
801 1.1 itojun "#70",
802 1.1 itojun "#71",
803 1.1 itojun "#72",
804 1.1 itojun "#73",
805 1.1 itojun "#74",
806 1.1 itojun "#75",
807 1.1 itojun "#76",
808 1.1 itojun "#77",
809 1.1 itojun "#78",
810 1.1 itojun "#79",
811 1.1 itojun "#80",
812 1.1 itojun "#81",
813 1.1 itojun "#82",
814 1.1 itojun "#83",
815 1.1 itojun "#84",
816 1.1 itojun "#85",
817 1.1 itojun "#86",
818 1.1 itojun "#87",
819 1.1 itojun "#88",
820 1.1 itojun "#89",
821 1.1 itojun "#80",
822 1.1 itojun "#91",
823 1.1 itojun "#92",
824 1.1 itojun "#93",
825 1.1 itojun "#94",
826 1.1 itojun "#95",
827 1.1 itojun "#96",
828 1.1 itojun "#97",
829 1.1 itojun "#98",
830 1.1 itojun "#99",
831 1.1 itojun "#100",
832 1.1 itojun "#101",
833 1.1 itojun "#102",
834 1.1 itojun "#103",
835 1.1 itojun "#104",
836 1.1 itojun "#105",
837 1.1 itojun "#106",
838 1.1 itojun "#107",
839 1.1 itojun "#108",
840 1.1 itojun "#109",
841 1.1 itojun "#110",
842 1.1 itojun "#111",
843 1.1 itojun "#112",
844 1.1 itojun "#113",
845 1.1 itojun "#114",
846 1.1 itojun "#115",
847 1.1 itojun "#116",
848 1.1 itojun "#117",
849 1.1 itojun "#118",
850 1.1 itojun "#119",
851 1.1 itojun "#120",
852 1.1 itojun "#121",
853 1.1 itojun "#122",
854 1.1 itojun "#123",
855 1.1 itojun "#124",
856 1.1 itojun "#125",
857 1.1 itojun "#126",
858 1.1 itojun "#127",
859 1.1 itojun "echo",
860 1.1 itojun "echo reply",
861 1.5 itojun "multicast listener query",
862 1.5 itojun "multicast listener report",
863 1.5 itojun "multicast listener done",
864 1.1 itojun "router solicitation",
865 1.1 itojun "router advertisment",
866 1.1 itojun "neighbor solicitation",
867 1.1 itojun "neighbor advertisment",
868 1.1 itojun "redirect",
869 1.1 itojun "router renumbering",
870 1.1 itojun "node information request",
871 1.1 itojun "node information reply",
872 1.1 itojun "#141",
873 1.1 itojun "#142",
874 1.1 itojun "#143",
875 1.1 itojun "#144",
876 1.1 itojun "#145",
877 1.1 itojun "#146",
878 1.1 itojun "#147",
879 1.1 itojun "#148",
880 1.1 itojun "#149",
881 1.1 itojun "#150",
882 1.1 itojun "#151",
883 1.1 itojun "#152",
884 1.1 itojun "#153",
885 1.1 itojun "#154",
886 1.1 itojun "#155",
887 1.1 itojun "#156",
888 1.1 itojun "#157",
889 1.1 itojun "#158",
890 1.1 itojun "#159",
891 1.1 itojun "#160",
892 1.1 itojun "#161",
893 1.1 itojun "#162",
894 1.1 itojun "#163",
895 1.1 itojun "#164",
896 1.1 itojun "#165",
897 1.1 itojun "#166",
898 1.1 itojun "#167",
899 1.1 itojun "#168",
900 1.1 itojun "#169",
901 1.1 itojun "#170",
902 1.1 itojun "#171",
903 1.1 itojun "#172",
904 1.1 itojun "#173",
905 1.1 itojun "#174",
906 1.1 itojun "#175",
907 1.1 itojun "#176",
908 1.1 itojun "#177",
909 1.1 itojun "#178",
910 1.1 itojun "#179",
911 1.1 itojun "#180",
912 1.1 itojun "#181",
913 1.1 itojun "#182",
914 1.1 itojun "#183",
915 1.1 itojun "#184",
916 1.1 itojun "#185",
917 1.1 itojun "#186",
918 1.1 itojun "#187",
919 1.1 itojun "#188",
920 1.1 itojun "#189",
921 1.1 itojun "#180",
922 1.1 itojun "#191",
923 1.1 itojun "#192",
924 1.1 itojun "#193",
925 1.1 itojun "#194",
926 1.1 itojun "#195",
927 1.1 itojun "#196",
928 1.1 itojun "#197",
929 1.1 itojun "#198",
930 1.1 itojun "#199",
931 1.1 itojun "#200",
932 1.1 itojun "#201",
933 1.1 itojun "#202",
934 1.1 itojun "#203",
935 1.1 itojun "#204",
936 1.1 itojun "#205",
937 1.1 itojun "#206",
938 1.1 itojun "#207",
939 1.1 itojun "#208",
940 1.1 itojun "#209",
941 1.1 itojun "#210",
942 1.1 itojun "#211",
943 1.1 itojun "#212",
944 1.1 itojun "#213",
945 1.1 itojun "#214",
946 1.1 itojun "#215",
947 1.1 itojun "#216",
948 1.1 itojun "#217",
949 1.1 itojun "#218",
950 1.1 itojun "#219",
951 1.1 itojun "#220",
952 1.1 itojun "#221",
953 1.1 itojun "#222",
954 1.1 itojun "#223",
955 1.1 itojun "#224",
956 1.1 itojun "#225",
957 1.1 itojun "#226",
958 1.1 itojun "#227",
959 1.1 itojun "#228",
960 1.1 itojun "#229",
961 1.1 itojun "#230",
962 1.1 itojun "#231",
963 1.1 itojun "#232",
964 1.1 itojun "#233",
965 1.1 itojun "#234",
966 1.1 itojun "#235",
967 1.1 itojun "#236",
968 1.1 itojun "#237",
969 1.1 itojun "#238",
970 1.1 itojun "#239",
971 1.1 itojun "#240",
972 1.1 itojun "#241",
973 1.1 itojun "#242",
974 1.1 itojun "#243",
975 1.1 itojun "#244",
976 1.1 itojun "#245",
977 1.1 itojun "#246",
978 1.1 itojun "#247",
979 1.1 itojun "#248",
980 1.1 itojun "#249",
981 1.1 itojun "#250",
982 1.1 itojun "#251",
983 1.1 itojun "#252",
984 1.1 itojun "#253",
985 1.1 itojun "#254",
986 1.1 itojun "#255",
987 1.1 itojun };
988 1.1 itojun
989 1.1 itojun /*
990 1.5 itojun * Dump ICMPv6 statistics.
991 1.1 itojun */
992 1.1 itojun void
993 1.1 itojun icmp6_stats(off, name)
994 1.1 itojun u_long off;
995 1.1 itojun char *name;
996 1.1 itojun {
997 1.1 itojun struct icmp6stat icmp6stat;
998 1.1 itojun register int i, first;
999 1.1 itojun
1000 1.1 itojun if (off == 0)
1001 1.1 itojun return;
1002 1.1 itojun kread(off, (char *)&icmp6stat, sizeof (icmp6stat));
1003 1.1 itojun printf("%s:\n", name);
1004 1.1 itojun
1005 1.1 itojun #define p(f, m) if (icmp6stat.f || sflag <= 1) \
1006 1.4 bouyer printf(m, (unsigned long long)icmp6stat.f, plural(icmp6stat.f))
1007 1.1 itojun
1008 1.4 bouyer p(icp6s_error, "\t%llu call%s to icmp_error\n");
1009 1.4 bouyer p(icp6s_canterror, "\t%llu error%s not generated because old message "
1010 1.4 bouyer "was icmp or so\n");
1011 1.1 itojun for (first = 1, i = 0; i < 256; i++)
1012 1.1 itojun if (icmp6stat.icp6s_outhist[i] != 0) {
1013 1.1 itojun if (first) {
1014 1.1 itojun printf("\tOutput histogram:\n");
1015 1.1 itojun first = 0;
1016 1.1 itojun }
1017 1.4 bouyer printf("\t\t%s: %llu\n", icmp6names[i],
1018 1.4 bouyer (unsigned long long)icmp6stat.icp6s_outhist[i]);
1019 1.1 itojun }
1020 1.4 bouyer p(icp6s_badcode, "\t%llu message%s with bad code fields\n");
1021 1.4 bouyer p(icp6s_tooshort, "\t%llu message%s < minimum length\n");
1022 1.4 bouyer p(icp6s_checksum, "\t%llu bad checksum%s\n");
1023 1.4 bouyer p(icp6s_badlen, "\t%llu message%s with bad length\n");
1024 1.1 itojun for (first = 1, i = 0; i < ICMP6_MAXTYPE; i++)
1025 1.1 itojun if (icmp6stat.icp6s_inhist[i] != 0) {
1026 1.1 itojun if (first) {
1027 1.1 itojun printf("\tInput histogram:\n");
1028 1.1 itojun first = 0;
1029 1.1 itojun }
1030 1.4 bouyer printf("\t\t%s: %llu\n", icmp6names[i],
1031 1.4 bouyer (unsigned long long)icmp6stat.icp6s_inhist[i]);
1032 1.1 itojun }
1033 1.4 bouyer p(icp6s_reflect, "\t%llu message response%s generated\n");
1034 1.5 itojun p(icp6s_nd_toomanyopt, "\t%llu message%s with too many ND options\n");
1035 1.5 itojun #undef p
1036 1.5 itojun }
1037 1.5 itojun
1038 1.5 itojun /*
1039 1.5 itojun * Dump ICMPv6 per-interface statistics based on RFC 2466.
1040 1.5 itojun */
1041 1.5 itojun void
1042 1.5 itojun icmp6_ifstats(ifname)
1043 1.5 itojun char *ifname;
1044 1.5 itojun {
1045 1.5 itojun struct in6_ifreq ifr;
1046 1.5 itojun int s;
1047 1.5 itojun #define p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \
1048 1.6 thorpej printf(m, (unsigned long long)ifr.ifr_ifru.ifru_icmp6stat.f, \
1049 1.6 thorpej plural(ifr.ifr_ifru.ifru_icmp6stat.f))
1050 1.5 itojun
1051 1.5 itojun if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
1052 1.5 itojun perror("Warning: socket(AF_INET6)");
1053 1.5 itojun return;
1054 1.5 itojun }
1055 1.5 itojun
1056 1.5 itojun strcpy(ifr.ifr_name, ifname);
1057 1.5 itojun printf("icmp6 on %s:\n", ifr.ifr_name);
1058 1.5 itojun
1059 1.5 itojun if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) {
1060 1.5 itojun perror("Warning: ioctl(SIOCGIFSTAT_ICMP6)");
1061 1.5 itojun goto end;
1062 1.5 itojun }
1063 1.5 itojun
1064 1.5 itojun p(ifs6_in_msg, "\t%llu total input message%s\n");
1065 1.5 itojun p(ifs6_in_error, "\t%llu total input error message%s\n");
1066 1.5 itojun p(ifs6_in_dstunreach, "\t%llu input destination unreachable error%s\n");
1067 1.5 itojun p(ifs6_in_adminprohib, "\t%llu input administratively prohibited error%s\n");
1068 1.5 itojun p(ifs6_in_timeexceed, "\t%llu input time exceeded error%s\n");
1069 1.5 itojun p(ifs6_in_paramprob, "\t%llu input parameter problem error%s\n");
1070 1.5 itojun p(ifs6_in_pkttoobig, "\t%llu input packet too big error%s\n");
1071 1.5 itojun p(ifs6_in_echo, "\t%llu input echo request%s\n");
1072 1.5 itojun p(ifs6_in_echoreply, "\t%llu input echo reply%s\n");
1073 1.5 itojun p(ifs6_in_routersolicit, "\t%llu input router solicitation%s\n");
1074 1.5 itojun p(ifs6_in_routeradvert, "\t%llu input router advertisement%s\n");
1075 1.5 itojun p(ifs6_in_neighborsolicit, "\t%llu input neighbor solicitation%s\n");
1076 1.5 itojun p(ifs6_in_neighboradvert, "\t%llu input neighbor advertisement%s\n");
1077 1.5 itojun p(ifs6_in_redirect, "\t%llu input redirect%s\n");
1078 1.5 itojun p(ifs6_in_mldquery, "\t%llu input MLD query%s\n");
1079 1.5 itojun p(ifs6_in_mldreport, "\t%llu input MLD report%s\n");
1080 1.5 itojun p(ifs6_in_mlddone, "\t%llu input MLD done%s\n");
1081 1.5 itojun
1082 1.5 itojun p(ifs6_out_msg, "\t%llu total output message%s\n");
1083 1.5 itojun p(ifs6_out_error, "\t%llu total output error message%s\n");
1084 1.5 itojun p(ifs6_out_dstunreach, "\t%llu output destination unreachable error%s\n");
1085 1.5 itojun p(ifs6_out_adminprohib, "\t%llu output administratively prohibited error%s\n");
1086 1.5 itojun p(ifs6_out_timeexceed, "\t%llu output time exceeded error%s\n");
1087 1.5 itojun p(ifs6_out_paramprob, "\t%llu output parameter problem error%s\n");
1088 1.5 itojun p(ifs6_out_pkttoobig, "\t%llu output packet too big error%s\n");
1089 1.5 itojun p(ifs6_out_echo, "\t%llu output echo request%s\n");
1090 1.5 itojun p(ifs6_out_echoreply, "\t%llu output echo reply%s\n");
1091 1.5 itojun p(ifs6_out_routersolicit, "\t%llu output router solicitation%s\n");
1092 1.5 itojun p(ifs6_out_routeradvert, "\t%llu output router advertisement%s\n");
1093 1.5 itojun p(ifs6_out_neighborsolicit, "\t%llu output neighbor solicitation%s\n");
1094 1.5 itojun p(ifs6_out_neighboradvert, "\t%llu output neighbor advertisement%s\n");
1095 1.5 itojun p(ifs6_out_redirect, "\t%llu output redirect%s\n");
1096 1.5 itojun p(ifs6_out_mldquery, "\t%llu output MLD query%s\n");
1097 1.5 itojun p(ifs6_out_mldreport, "\t%llu output MLD report%s\n");
1098 1.5 itojun p(ifs6_out_mlddone, "\t%llu output MLD done%s\n");
1099 1.5 itojun
1100 1.5 itojun end:
1101 1.5 itojun close(s);
1102 1.1 itojun #undef p
1103 1.1 itojun }
1104 1.1 itojun
1105 1.1 itojun /*
1106 1.1 itojun * Dump PIM statistics structure.
1107 1.1 itojun */
1108 1.1 itojun void
1109 1.1 itojun pim6_stats(off, name)
1110 1.1 itojun u_long off;
1111 1.1 itojun char *name;
1112 1.1 itojun {
1113 1.1 itojun struct pim6stat pim6stat;
1114 1.1 itojun
1115 1.1 itojun if (off == 0)
1116 1.1 itojun return;
1117 1.1 itojun kread(off, (char *)&pim6stat, sizeof(pim6stat));
1118 1.1 itojun printf("%s:\n", name);
1119 1.1 itojun
1120 1.1 itojun #define p(f, m) if (pim6stat.f || sflag <= 1) \
1121 1.4 bouyer printf(m, (unsigned long long)pim6stat.f, plural(pim6stat.f))
1122 1.4 bouyer p(pim6s_rcv_total, "\t%llu message%s received\n");
1123 1.4 bouyer p(pim6s_rcv_tooshort, "\t%llu message%s received with too few bytes\n");
1124 1.4 bouyer p(pim6s_rcv_badsum, "\t%llu message%s received with bad checksum\n");
1125 1.4 bouyer p(pim6s_rcv_badversion, "\t%llu message%s received with bad version\n");
1126 1.4 bouyer p(pim6s_rcv_registers, "\t%llu register%s received\n");
1127 1.4 bouyer p(pim6s_rcv_badregisters, "\t%llu bad register%s received\n");
1128 1.4 bouyer p(pim6s_snd_registers, "\t%llu register%s sent\n");
1129 1.1 itojun #undef p
1130 1.1 itojun }
1131 1.1 itojun
1132 1.1 itojun /*
1133 1.1 itojun * Pretty print an Internet address (net address + port).
1134 1.1 itojun * If the nflag was specified, use numbers instead of names.
1135 1.1 itojun */
1136 1.1 itojun
1137 1.1 itojun void
1138 1.1 itojun inet6print(in6, port, proto)
1139 1.1 itojun register struct in6_addr *in6;
1140 1.1 itojun int port;
1141 1.1 itojun char *proto;
1142 1.1 itojun {
1143 1.1 itojun #define GETSERVBYPORT6(port, proto, ret)\
1144 1.5 itojun do {\
1145 1.1 itojun if (strcmp((proto), "tcp6") == 0)\
1146 1.1 itojun (ret) = getservbyport((int)(port), "tcp");\
1147 1.1 itojun else if (strcmp((proto), "udp6") == 0)\
1148 1.1 itojun (ret) = getservbyport((int)(port), "udp");\
1149 1.1 itojun else\
1150 1.1 itojun (ret) = getservbyport((int)(port), (proto));\
1151 1.5 itojun } while (0)
1152 1.1 itojun struct servent *sp = 0;
1153 1.1 itojun char line[80], *cp;
1154 1.1 itojun int width;
1155 1.1 itojun
1156 1.5 itojun width = Aflag ? 12 : 16;
1157 1.5 itojun if (vflag && width < strlen(inet6name(in6)))
1158 1.5 itojun width = strlen(inet6name(in6));
1159 1.5 itojun sprintf(line, "%.*s.", width, inet6name(in6));
1160 1.1 itojun cp = index(line, '\0');
1161 1.1 itojun if (!nflag && port)
1162 1.1 itojun GETSERVBYPORT6(port, proto, sp);
1163 1.1 itojun if (sp || port == 0)
1164 1.1 itojun sprintf(cp, "%.8s", sp ? sp->s_name : "*");
1165 1.1 itojun else
1166 1.1 itojun sprintf(cp, "%d", ntohs((u_short)port));
1167 1.1 itojun width = Aflag ? 18 : 22;
1168 1.5 itojun if (vflag && width < strlen(line))
1169 1.5 itojun width = strlen(line);
1170 1.1 itojun printf(" %-*.*s", width, width, line);
1171 1.1 itojun }
1172 1.1 itojun
1173 1.1 itojun /*
1174 1.1 itojun * Construct an Internet address representation.
1175 1.1 itojun * If the nflag has been supplied, give
1176 1.1 itojun * numeric value, otherwise try for symbolic name.
1177 1.1 itojun */
1178 1.1 itojun
1179 1.1 itojun char *
1180 1.1 itojun inet6name(in6p)
1181 1.1 itojun struct in6_addr *in6p;
1182 1.1 itojun {
1183 1.1 itojun register char *cp;
1184 1.1 itojun static char line[50];
1185 1.1 itojun struct hostent *hp;
1186 1.1 itojun static char domain[MAXHOSTNAMELEN + 1];
1187 1.1 itojun static int first = 1;
1188 1.5 itojun char hbuf[NI_MAXHOST];
1189 1.5 itojun struct sockaddr_in6 sin6;
1190 1.5 itojun #ifdef KAME_SCOPEID
1191 1.5 itojun const int niflag = NI_NUMERICHOST | NI_WITHSCOPEID;
1192 1.5 itojun #else
1193 1.5 itojun const int niflag = NI_NUMERICHOST;
1194 1.5 itojun #endif
1195 1.1 itojun
1196 1.1 itojun if (first && !nflag) {
1197 1.1 itojun first = 0;
1198 1.1 itojun if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
1199 1.1 itojun (cp = index(domain, '.')))
1200 1.1 itojun (void) strcpy(domain, cp + 1);
1201 1.1 itojun else
1202 1.1 itojun domain[0] = 0;
1203 1.1 itojun }
1204 1.1 itojun cp = 0;
1205 1.1 itojun if (!nflag && !IN6_IS_ADDR_UNSPECIFIED(in6p)) {
1206 1.1 itojun hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6);
1207 1.1 itojun if (hp) {
1208 1.1 itojun if ((cp = index(hp->h_name, '.')) &&
1209 1.1 itojun !strcmp(cp + 1, domain))
1210 1.1 itojun *cp = 0;
1211 1.1 itojun cp = hp->h_name;
1212 1.1 itojun }
1213 1.1 itojun }
1214 1.1 itojun if (IN6_IS_ADDR_UNSPECIFIED(in6p))
1215 1.1 itojun strcpy(line, "*");
1216 1.1 itojun else if (cp)
1217 1.1 itojun strcpy(line, cp);
1218 1.5 itojun else {
1219 1.5 itojun memset(&sin6, 0, sizeof(sin6));
1220 1.5 itojun sin6.sin6_len = sizeof(sin6);
1221 1.5 itojun sin6.sin6_family = AF_INET6;
1222 1.5 itojun sin6.sin6_addr = *in6p;
1223 1.5 itojun #ifdef KAME_SCOPEID
1224 1.5 itojun if (IN6_IS_ADDR_LINKLOCAL(in6p)) {
1225 1.5 itojun sin6.sin6_scope_id =
1226 1.5 itojun ntohs(*(u_int16_t *)&in6p->s6_addr[2]);
1227 1.5 itojun sin6.sin6_addr.s6_addr[2] = 0;
1228 1.5 itojun sin6.sin6_addr.s6_addr[3] = 0;
1229 1.5 itojun }
1230 1.5 itojun #endif
1231 1.5 itojun if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,
1232 1.5 itojun hbuf, sizeof(hbuf), NULL, 0, niflag))
1233 1.5 itojun strcpy(hbuf, "?");
1234 1.5 itojun sprintf(line, "%s", hbuf);
1235 1.5 itojun }
1236 1.1 itojun return (line);
1237 1.1 itojun }
1238 1.1 itojun
1239 1.1 itojun #ifdef TCP6
1240 1.1 itojun /*
1241 1.1 itojun * Dump the contents of a TCP6 PCB.
1242 1.1 itojun */
1243 1.1 itojun void
1244 1.1 itojun tcp6_dump(pcbaddr)
1245 1.1 itojun u_long pcbaddr;
1246 1.1 itojun {
1247 1.1 itojun struct tcp6cb tcp6cb;
1248 1.1 itojun int i;
1249 1.1 itojun
1250 1.1 itojun kread(pcbaddr, (char *)&tcp6cb, sizeof(tcp6cb));
1251 1.1 itojun
1252 1.1 itojun printf("TCP Protocol Control Block at 0x%08lx:\n\n", pcbaddr);
1253 1.1 itojun
1254 1.1 itojun printf("Timers:\n");
1255 1.1 itojun for (i = 0; i < TCP6T_NTIMERS; i++)
1256 1.1 itojun printf("\t%s: %u", tcp6timers[i], tcp6cb.t_timer[i]);
1257 1.1 itojun printf("\n\n");
1258 1.1 itojun
1259 1.1 itojun if (tcp6cb.t_state < 0 || tcp6cb.t_state >= TCP6_NSTATES)
1260 1.1 itojun printf("State: %d", tcp6cb.t_state);
1261 1.1 itojun else
1262 1.1 itojun printf("State: %s", tcp6states[tcp6cb.t_state]);
1263 1.1 itojun printf(", flags 0x%x, in6pcb 0x%lx\n\n", tcp6cb.t_flags,
1264 1.1 itojun (u_long)tcp6cb.t_in6pcb);
1265 1.1 itojun
1266 1.1 itojun printf("rxtshift %d, rxtcur %d, dupacks %d\n", tcp6cb.t_rxtshift,
1267 1.1 itojun tcp6cb.t_rxtcur, tcp6cb.t_dupacks);
1268 1.1 itojun printf("peermaxseg %u, maxseg %u, force %d\n\n", tcp6cb.t_peermaxseg,
1269 1.1 itojun tcp6cb.t_maxseg, tcp6cb.t_force);
1270 1.1 itojun
1271 1.1 itojun printf("snd_una %u, snd_nxt %u, snd_up %u\n",
1272 1.1 itojun tcp6cb.snd_una, tcp6cb.snd_nxt, tcp6cb.snd_up);
1273 1.4 bouyer printf("snd_wl1 %u, snd_wl2 %u, iss %u, snd_wnd %llu\n\n",
1274 1.4 bouyer tcp6cb.snd_wl1, tcp6cb.snd_wl2, tcp6cb.iss,
1275 1.4 bouyer (unsigned long long)tcp6cb.snd_wnd);
1276 1.4 bouyer
1277 1.4 bouyer printf("rcv_wnd %llu, rcv_nxt %u, rcv_up %u, irs %u\n\n",
1278 1.4 bouyer (unsigned long long)cp6cb.rcv_wnd, tcp6cb.rcv_nxt,
1279 1.4 bouyer tcp6cb.rcv_up, tcp6cb.irs);
1280 1.4 bouyer
1281 1.4 bouyer printf("rcv_adv %u, snd_max %u, snd_cwnd %llu, snd_ssthresh %llu\n",
1282 1.4 bouyer tcp6cb.rcv_adv, tcp6cb.snd_max, (unsigned long long)tcp6cb.snd_cwnd,
1283 1.4 bouyer (unsigned long long)tcp6cb.snd_ssthresh);
1284 1.1 itojun
1285 1.1 itojun printf("idle %d, rtt %d, rtseq %u, srtt %d, rttvar %d, rttmin %d, "
1286 1.4 bouyer "max_sndwnd %llu\n\n", tcp6cb.t_idle, tcp6cb.t_rtt, tcp6cb.t_rtseq,
1287 1.4 bouyer tcp6cb.t_srtt, tcp6cb.t_rttvar, tcp6cb.t_rttmin,
1288 1.4 bouyer (unsigned long long)tcp6cb.max_sndwnd);
1289 1.1 itojun
1290 1.1 itojun printf("oobflags %d, iobc %d, softerror %d\n\n", tcp6cb.t_oobflags,
1291 1.1 itojun tcp6cb.t_iobc, tcp6cb.t_softerror);
1292 1.1 itojun
1293 1.1 itojun printf("snd_scale %d, rcv_scale %d, req_r_scale %d, req_s_scale %d\n",
1294 1.1 itojun tcp6cb.snd_scale, tcp6cb.rcv_scale, tcp6cb.request_r_scale,
1295 1.1 itojun tcp6cb.requested_s_scale);
1296 1.1 itojun printf("ts_recent %u, ts_regent_age %d, last_ack_sent %u\n",
1297 1.1 itojun tcp6cb.ts_recent, tcp6cb.ts_recent_age, tcp6cb.last_ack_sent);
1298 1.1 itojun }
1299 1.1 itojun #endif
1300 1.1 itojun
1301 1.1 itojun #endif /*INET6*/
1302