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