xref: /freebsd/usr.bin/netstat/inet6.c (revision a709913fddb6821f257a7dd618bc94b515765f6c)
1cfa1ca9dSYoshinobu Inoue /*	BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp	*/
265475bc8SDavid E. O'Brien /*-
3cfa1ca9dSYoshinobu Inoue  * Copyright (c) 1983, 1988, 1993
4cfa1ca9dSYoshinobu Inoue  *	The Regents of the University of California.  All rights reserved.
5cfa1ca9dSYoshinobu Inoue  *
6cfa1ca9dSYoshinobu Inoue  * Redistribution and use in source and binary forms, with or without
7cfa1ca9dSYoshinobu Inoue  * modification, are permitted provided that the following conditions
8cfa1ca9dSYoshinobu Inoue  * are met:
9cfa1ca9dSYoshinobu Inoue  * 1. Redistributions of source code must retain the above copyright
10cfa1ca9dSYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer.
11cfa1ca9dSYoshinobu Inoue  * 2. Redistributions in binary form must reproduce the above copyright
12cfa1ca9dSYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer in the
13cfa1ca9dSYoshinobu Inoue  *    documentation and/or other materials provided with the distribution.
14cfa1ca9dSYoshinobu Inoue  * 3. All advertising materials mentioning features or use of this software
15cfa1ca9dSYoshinobu Inoue  *    must display the following acknowledgement:
16cfa1ca9dSYoshinobu Inoue  *	This product includes software developed by the University of
17cfa1ca9dSYoshinobu Inoue  *	California, Berkeley and its contributors.
18cfa1ca9dSYoshinobu Inoue  * 4. Neither the name of the University nor the names of its contributors
19cfa1ca9dSYoshinobu Inoue  *    may be used to endorse or promote products derived from this software
20cfa1ca9dSYoshinobu Inoue  *    without specific prior written permission.
21cfa1ca9dSYoshinobu Inoue  *
22cfa1ca9dSYoshinobu Inoue  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23cfa1ca9dSYoshinobu Inoue  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24cfa1ca9dSYoshinobu Inoue  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25cfa1ca9dSYoshinobu Inoue  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26cfa1ca9dSYoshinobu Inoue  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27cfa1ca9dSYoshinobu Inoue  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28cfa1ca9dSYoshinobu Inoue  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29cfa1ca9dSYoshinobu Inoue  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30cfa1ca9dSYoshinobu Inoue  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31cfa1ca9dSYoshinobu Inoue  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32cfa1ca9dSYoshinobu Inoue  * SUCH DAMAGE.
33cfa1ca9dSYoshinobu Inoue  */
34cfa1ca9dSYoshinobu Inoue 
356cc6f122SPhilippe Charnier #if 0
36cfa1ca9dSYoshinobu Inoue #ifndef lint
37cfa1ca9dSYoshinobu Inoue static char sccsid[] = "@(#)inet6.c	8.4 (Berkeley) 4/20/94";
38cfa1ca9dSYoshinobu Inoue #endif /* not lint */
396cc6f122SPhilippe Charnier #endif
406cc6f122SPhilippe Charnier 
416cc6f122SPhilippe Charnier #include <sys/cdefs.h>
426cc6f122SPhilippe Charnier __FBSDID("$FreeBSD$");
43cfa1ca9dSYoshinobu Inoue 
44d84a1df4SHajimu UMEMOTO #ifdef INET6
45cfa1ca9dSYoshinobu Inoue #include <sys/param.h>
46cfa1ca9dSYoshinobu Inoue #include <sys/socket.h>
47cfa1ca9dSYoshinobu Inoue #include <sys/socketvar.h>
48cfa1ca9dSYoshinobu Inoue #include <sys/ioctl.h>
49cfa1ca9dSYoshinobu Inoue #include <sys/mbuf.h>
50cfa1ca9dSYoshinobu Inoue #include <sys/protosw.h>
5133841545SHajimu UMEMOTO #include <sys/sysctl.h>
52cfa1ca9dSYoshinobu Inoue 
53cfa1ca9dSYoshinobu Inoue #include <net/route.h>
54cfa1ca9dSYoshinobu Inoue #include <net/if.h>
55cfa1ca9dSYoshinobu Inoue #include <net/if_var.h>
56cfa1ca9dSYoshinobu Inoue #include <netinet/in.h>
57cfa1ca9dSYoshinobu Inoue #include <netinet/ip6.h>
58cfa1ca9dSYoshinobu Inoue #include <netinet/icmp6.h>
59cfa1ca9dSYoshinobu Inoue #include <netinet/in_systm.h>
60cfa1ca9dSYoshinobu Inoue #include <netinet6/in6_pcb.h>
61cfa1ca9dSYoshinobu Inoue #include <netinet6/in6_var.h>
62cfa1ca9dSYoshinobu Inoue #include <netinet6/ip6_var.h>
63cfa1ca9dSYoshinobu Inoue #include <netinet6/pim6_var.h>
6433841545SHajimu UMEMOTO #include <netinet6/raw_ip6.h>
65cfa1ca9dSYoshinobu Inoue 
66cfa1ca9dSYoshinobu Inoue #include <arpa/inet.h>
67cfa1ca9dSYoshinobu Inoue #include <netdb.h>
68cfa1ca9dSYoshinobu Inoue 
69c15ddad9SBruce M Simpson #include <err.h>
707b95a1ebSYaroslav Tykhiy #include <stdint.h>
71cfa1ca9dSYoshinobu Inoue #include <stdio.h>
72109dad81SJulian Elischer #include <errno.h>
73cfa1ca9dSYoshinobu Inoue #include <string.h>
74cfa1ca9dSYoshinobu Inoue #include <unistd.h>
75cfa1ca9dSYoshinobu Inoue #include "netstat.h"
76cfa1ca9dSYoshinobu Inoue 
77cfa1ca9dSYoshinobu Inoue struct	socket sockb;
78cfa1ca9dSYoshinobu Inoue 
795e051718SAssar Westerlund char	*inet6name(struct in6_addr *);
80cfa1ca9dSYoshinobu Inoue 
81cfa1ca9dSYoshinobu Inoue static char ntop_buf[INET6_ADDRSTRLEN];
82cfa1ca9dSYoshinobu Inoue 
83a01e3379SDavid Malone static	const char *ip6nh[] = {
84cfa1ca9dSYoshinobu Inoue 	"hop by hop",
85cfa1ca9dSYoshinobu Inoue 	"ICMP",
86cfa1ca9dSYoshinobu Inoue 	"IGMP",
87cfa1ca9dSYoshinobu Inoue 	"#3",
88cfa1ca9dSYoshinobu Inoue 	"IP",
89cfa1ca9dSYoshinobu Inoue 	"#5",
90cfa1ca9dSYoshinobu Inoue 	"TCP",
91cfa1ca9dSYoshinobu Inoue 	"#7",
92cfa1ca9dSYoshinobu Inoue 	"#8",
93cfa1ca9dSYoshinobu Inoue 	"#9",
94cfa1ca9dSYoshinobu Inoue 	"#10",
95cfa1ca9dSYoshinobu Inoue 	"#11",
96cfa1ca9dSYoshinobu Inoue 	"#12",
97cfa1ca9dSYoshinobu Inoue 	"#13",
98cfa1ca9dSYoshinobu Inoue 	"#14",
99cfa1ca9dSYoshinobu Inoue 	"#15",
100cfa1ca9dSYoshinobu Inoue 	"#16",
101cfa1ca9dSYoshinobu Inoue 	"UDP",
102cfa1ca9dSYoshinobu Inoue 	"#18",
103cfa1ca9dSYoshinobu Inoue 	"#19",
104cfa1ca9dSYoshinobu Inoue 	"#20",
105cfa1ca9dSYoshinobu Inoue 	"#21",
106cfa1ca9dSYoshinobu Inoue 	"IDP",
107cfa1ca9dSYoshinobu Inoue 	"#23",
108cfa1ca9dSYoshinobu Inoue 	"#24",
109cfa1ca9dSYoshinobu Inoue 	"#25",
110cfa1ca9dSYoshinobu Inoue 	"#26",
111cfa1ca9dSYoshinobu Inoue 	"#27",
112cfa1ca9dSYoshinobu Inoue 	"#28",
113cfa1ca9dSYoshinobu Inoue 	"TP",
114cfa1ca9dSYoshinobu Inoue 	"#30",
115cfa1ca9dSYoshinobu Inoue 	"#31",
116cfa1ca9dSYoshinobu Inoue 	"#32",
117cfa1ca9dSYoshinobu Inoue 	"#33",
118cfa1ca9dSYoshinobu Inoue 	"#34",
119cfa1ca9dSYoshinobu Inoue 	"#35",
120cfa1ca9dSYoshinobu Inoue 	"#36",
121cfa1ca9dSYoshinobu Inoue 	"#37",
122cfa1ca9dSYoshinobu Inoue 	"#38",
123cfa1ca9dSYoshinobu Inoue 	"#39",
124cfa1ca9dSYoshinobu Inoue 	"#40",
125cfa1ca9dSYoshinobu Inoue 	"IP6",
126cfa1ca9dSYoshinobu Inoue 	"#42",
127cfa1ca9dSYoshinobu Inoue 	"routing",
128cfa1ca9dSYoshinobu Inoue 	"fragment",
129cfa1ca9dSYoshinobu Inoue 	"#45",
130cfa1ca9dSYoshinobu Inoue 	"#46",
131cfa1ca9dSYoshinobu Inoue 	"#47",
132cfa1ca9dSYoshinobu Inoue 	"#48",
133cfa1ca9dSYoshinobu Inoue 	"#49",
134cfa1ca9dSYoshinobu Inoue 	"ESP",
135cfa1ca9dSYoshinobu Inoue 	"AH",
136cfa1ca9dSYoshinobu Inoue 	"#52",
137cfa1ca9dSYoshinobu Inoue 	"#53",
138cfa1ca9dSYoshinobu Inoue 	"#54",
139cfa1ca9dSYoshinobu Inoue 	"#55",
140cfa1ca9dSYoshinobu Inoue 	"#56",
141cfa1ca9dSYoshinobu Inoue 	"#57",
142cfa1ca9dSYoshinobu Inoue 	"ICMP6",
143cfa1ca9dSYoshinobu Inoue 	"no next header",
144cfa1ca9dSYoshinobu Inoue 	"destination option",
145cfa1ca9dSYoshinobu Inoue 	"#61",
146cb60a8deSHajimu UMEMOTO 	"mobility",
147cfa1ca9dSYoshinobu Inoue 	"#63",
148cfa1ca9dSYoshinobu Inoue 	"#64",
149cfa1ca9dSYoshinobu Inoue 	"#65",
150cfa1ca9dSYoshinobu Inoue 	"#66",
151cfa1ca9dSYoshinobu Inoue 	"#67",
152cfa1ca9dSYoshinobu Inoue 	"#68",
153cfa1ca9dSYoshinobu Inoue 	"#69",
154cfa1ca9dSYoshinobu Inoue 	"#70",
155cfa1ca9dSYoshinobu Inoue 	"#71",
156cfa1ca9dSYoshinobu Inoue 	"#72",
157cfa1ca9dSYoshinobu Inoue 	"#73",
158cfa1ca9dSYoshinobu Inoue 	"#74",
159cfa1ca9dSYoshinobu Inoue 	"#75",
160cfa1ca9dSYoshinobu Inoue 	"#76",
161cfa1ca9dSYoshinobu Inoue 	"#77",
162cfa1ca9dSYoshinobu Inoue 	"#78",
163cfa1ca9dSYoshinobu Inoue 	"#79",
164cfa1ca9dSYoshinobu Inoue 	"ISOIP",
165cfa1ca9dSYoshinobu Inoue 	"#81",
166cfa1ca9dSYoshinobu Inoue 	"#82",
167cfa1ca9dSYoshinobu Inoue 	"#83",
168cfa1ca9dSYoshinobu Inoue 	"#84",
169cfa1ca9dSYoshinobu Inoue 	"#85",
170cfa1ca9dSYoshinobu Inoue 	"#86",
171cfa1ca9dSYoshinobu Inoue 	"#87",
172cfa1ca9dSYoshinobu Inoue 	"#88",
17332cd1d96SJun-ichiro itojun Hagino 	"OSPF",
174cfa1ca9dSYoshinobu Inoue 	"#80",
175cfa1ca9dSYoshinobu Inoue 	"#91",
176cfa1ca9dSYoshinobu Inoue 	"#92",
177cfa1ca9dSYoshinobu Inoue 	"#93",
178cfa1ca9dSYoshinobu Inoue 	"#94",
179cfa1ca9dSYoshinobu Inoue 	"#95",
180cfa1ca9dSYoshinobu Inoue 	"#96",
181cfa1ca9dSYoshinobu Inoue 	"Ethernet",
182cfa1ca9dSYoshinobu Inoue 	"#98",
183cfa1ca9dSYoshinobu Inoue 	"#99",
184cfa1ca9dSYoshinobu Inoue 	"#100",
185cfa1ca9dSYoshinobu Inoue 	"#101",
186cfa1ca9dSYoshinobu Inoue 	"#102",
187cfa1ca9dSYoshinobu Inoue 	"PIM",
188cfa1ca9dSYoshinobu Inoue 	"#104",
189cfa1ca9dSYoshinobu Inoue 	"#105",
190cfa1ca9dSYoshinobu Inoue 	"#106",
191cfa1ca9dSYoshinobu Inoue 	"#107",
192cfa1ca9dSYoshinobu Inoue 	"#108",
193cfa1ca9dSYoshinobu Inoue 	"#109",
194cfa1ca9dSYoshinobu Inoue 	"#110",
195cfa1ca9dSYoshinobu Inoue 	"#111",
196cfa1ca9dSYoshinobu Inoue 	"#112",
197cfa1ca9dSYoshinobu Inoue 	"#113",
198cfa1ca9dSYoshinobu Inoue 	"#114",
199cfa1ca9dSYoshinobu Inoue 	"#115",
200cfa1ca9dSYoshinobu Inoue 	"#116",
201cfa1ca9dSYoshinobu Inoue 	"#117",
202cfa1ca9dSYoshinobu Inoue 	"#118",
203cfa1ca9dSYoshinobu Inoue 	"#119",
204cfa1ca9dSYoshinobu Inoue 	"#120",
205cfa1ca9dSYoshinobu Inoue 	"#121",
206cfa1ca9dSYoshinobu Inoue 	"#122",
207cfa1ca9dSYoshinobu Inoue 	"#123",
208cfa1ca9dSYoshinobu Inoue 	"#124",
209cfa1ca9dSYoshinobu Inoue 	"#125",
210cfa1ca9dSYoshinobu Inoue 	"#126",
211cfa1ca9dSYoshinobu Inoue 	"#127",
212cfa1ca9dSYoshinobu Inoue 	"#128",
213cfa1ca9dSYoshinobu Inoue 	"#129",
214cfa1ca9dSYoshinobu Inoue 	"#130",
215cfa1ca9dSYoshinobu Inoue 	"#131",
216cfa1ca9dSYoshinobu Inoue 	"#132",
217cfa1ca9dSYoshinobu Inoue 	"#133",
218cfa1ca9dSYoshinobu Inoue 	"#134",
219cfa1ca9dSYoshinobu Inoue 	"#135",
220cfa1ca9dSYoshinobu Inoue 	"#136",
221cfa1ca9dSYoshinobu Inoue 	"#137",
222cfa1ca9dSYoshinobu Inoue 	"#138",
223cfa1ca9dSYoshinobu Inoue 	"#139",
224cfa1ca9dSYoshinobu Inoue 	"#140",
225cfa1ca9dSYoshinobu Inoue 	"#141",
226cfa1ca9dSYoshinobu Inoue 	"#142",
227cfa1ca9dSYoshinobu Inoue 	"#143",
228cfa1ca9dSYoshinobu Inoue 	"#144",
229cfa1ca9dSYoshinobu Inoue 	"#145",
230cfa1ca9dSYoshinobu Inoue 	"#146",
231cfa1ca9dSYoshinobu Inoue 	"#147",
232cfa1ca9dSYoshinobu Inoue 	"#148",
233cfa1ca9dSYoshinobu Inoue 	"#149",
234cfa1ca9dSYoshinobu Inoue 	"#150",
235cfa1ca9dSYoshinobu Inoue 	"#151",
236cfa1ca9dSYoshinobu Inoue 	"#152",
237cfa1ca9dSYoshinobu Inoue 	"#153",
238cfa1ca9dSYoshinobu Inoue 	"#154",
239cfa1ca9dSYoshinobu Inoue 	"#155",
240cfa1ca9dSYoshinobu Inoue 	"#156",
241cfa1ca9dSYoshinobu Inoue 	"#157",
242cfa1ca9dSYoshinobu Inoue 	"#158",
243cfa1ca9dSYoshinobu Inoue 	"#159",
244cfa1ca9dSYoshinobu Inoue 	"#160",
245cfa1ca9dSYoshinobu Inoue 	"#161",
246cfa1ca9dSYoshinobu Inoue 	"#162",
247cfa1ca9dSYoshinobu Inoue 	"#163",
248cfa1ca9dSYoshinobu Inoue 	"#164",
249cfa1ca9dSYoshinobu Inoue 	"#165",
250cfa1ca9dSYoshinobu Inoue 	"#166",
251cfa1ca9dSYoshinobu Inoue 	"#167",
252cfa1ca9dSYoshinobu Inoue 	"#168",
253cfa1ca9dSYoshinobu Inoue 	"#169",
254cfa1ca9dSYoshinobu Inoue 	"#170",
255cfa1ca9dSYoshinobu Inoue 	"#171",
256cfa1ca9dSYoshinobu Inoue 	"#172",
257cfa1ca9dSYoshinobu Inoue 	"#173",
258cfa1ca9dSYoshinobu Inoue 	"#174",
259cfa1ca9dSYoshinobu Inoue 	"#175",
260cfa1ca9dSYoshinobu Inoue 	"#176",
261cfa1ca9dSYoshinobu Inoue 	"#177",
262cfa1ca9dSYoshinobu Inoue 	"#178",
263cfa1ca9dSYoshinobu Inoue 	"#179",
264cfa1ca9dSYoshinobu Inoue 	"#180",
265cfa1ca9dSYoshinobu Inoue 	"#181",
266cfa1ca9dSYoshinobu Inoue 	"#182",
267cfa1ca9dSYoshinobu Inoue 	"#183",
268cfa1ca9dSYoshinobu Inoue 	"#184",
269cfa1ca9dSYoshinobu Inoue 	"#185",
270cfa1ca9dSYoshinobu Inoue 	"#186",
271cfa1ca9dSYoshinobu Inoue 	"#187",
272cfa1ca9dSYoshinobu Inoue 	"#188",
273cfa1ca9dSYoshinobu Inoue 	"#189",
274cfa1ca9dSYoshinobu Inoue 	"#180",
275cfa1ca9dSYoshinobu Inoue 	"#191",
276cfa1ca9dSYoshinobu Inoue 	"#192",
277cfa1ca9dSYoshinobu Inoue 	"#193",
278cfa1ca9dSYoshinobu Inoue 	"#194",
279cfa1ca9dSYoshinobu Inoue 	"#195",
280cfa1ca9dSYoshinobu Inoue 	"#196",
281cfa1ca9dSYoshinobu Inoue 	"#197",
282cfa1ca9dSYoshinobu Inoue 	"#198",
283cfa1ca9dSYoshinobu Inoue 	"#199",
284cfa1ca9dSYoshinobu Inoue 	"#200",
285cfa1ca9dSYoshinobu Inoue 	"#201",
286cfa1ca9dSYoshinobu Inoue 	"#202",
287cfa1ca9dSYoshinobu Inoue 	"#203",
288cfa1ca9dSYoshinobu Inoue 	"#204",
289cfa1ca9dSYoshinobu Inoue 	"#205",
290cfa1ca9dSYoshinobu Inoue 	"#206",
291cfa1ca9dSYoshinobu Inoue 	"#207",
292cfa1ca9dSYoshinobu Inoue 	"#208",
293cfa1ca9dSYoshinobu Inoue 	"#209",
294cfa1ca9dSYoshinobu Inoue 	"#210",
295cfa1ca9dSYoshinobu Inoue 	"#211",
296cfa1ca9dSYoshinobu Inoue 	"#212",
297cfa1ca9dSYoshinobu Inoue 	"#213",
298cfa1ca9dSYoshinobu Inoue 	"#214",
299cfa1ca9dSYoshinobu Inoue 	"#215",
300cfa1ca9dSYoshinobu Inoue 	"#216",
301cfa1ca9dSYoshinobu Inoue 	"#217",
302cfa1ca9dSYoshinobu Inoue 	"#218",
303cfa1ca9dSYoshinobu Inoue 	"#219",
304cfa1ca9dSYoshinobu Inoue 	"#220",
305cfa1ca9dSYoshinobu Inoue 	"#221",
306cfa1ca9dSYoshinobu Inoue 	"#222",
307cfa1ca9dSYoshinobu Inoue 	"#223",
308cfa1ca9dSYoshinobu Inoue 	"#224",
309cfa1ca9dSYoshinobu Inoue 	"#225",
310cfa1ca9dSYoshinobu Inoue 	"#226",
311cfa1ca9dSYoshinobu Inoue 	"#227",
312cfa1ca9dSYoshinobu Inoue 	"#228",
313cfa1ca9dSYoshinobu Inoue 	"#229",
314cfa1ca9dSYoshinobu Inoue 	"#230",
315cfa1ca9dSYoshinobu Inoue 	"#231",
316cfa1ca9dSYoshinobu Inoue 	"#232",
317cfa1ca9dSYoshinobu Inoue 	"#233",
318cfa1ca9dSYoshinobu Inoue 	"#234",
319cfa1ca9dSYoshinobu Inoue 	"#235",
320cfa1ca9dSYoshinobu Inoue 	"#236",
321cfa1ca9dSYoshinobu Inoue 	"#237",
322cfa1ca9dSYoshinobu Inoue 	"#238",
323cfa1ca9dSYoshinobu Inoue 	"#239",
324cfa1ca9dSYoshinobu Inoue 	"#240",
325cfa1ca9dSYoshinobu Inoue 	"#241",
326cfa1ca9dSYoshinobu Inoue 	"#242",
327cfa1ca9dSYoshinobu Inoue 	"#243",
328cfa1ca9dSYoshinobu Inoue 	"#244",
329cfa1ca9dSYoshinobu Inoue 	"#245",
330cfa1ca9dSYoshinobu Inoue 	"#246",
331cfa1ca9dSYoshinobu Inoue 	"#247",
332cfa1ca9dSYoshinobu Inoue 	"#248",
333cfa1ca9dSYoshinobu Inoue 	"#249",
334cfa1ca9dSYoshinobu Inoue 	"#250",
335cfa1ca9dSYoshinobu Inoue 	"#251",
336cfa1ca9dSYoshinobu Inoue 	"#252",
337cfa1ca9dSYoshinobu Inoue 	"#253",
338cfa1ca9dSYoshinobu Inoue 	"#254",
339cfa1ca9dSYoshinobu Inoue 	"#255",
340cfa1ca9dSYoshinobu Inoue };
341cfa1ca9dSYoshinobu Inoue 
3424ef2dc8bSHajimu UMEMOTO static char *srcrule_str[] = {
3434ef2dc8bSHajimu UMEMOTO 	"first candidate",
3444ef2dc8bSHajimu UMEMOTO 	"same address",
3454ef2dc8bSHajimu UMEMOTO 	"appropriate scope",
3464ef2dc8bSHajimu UMEMOTO 	"deprecated address",
3474ef2dc8bSHajimu UMEMOTO 	"home address",
3484ef2dc8bSHajimu UMEMOTO 	"outgoing interface",
3494ef2dc8bSHajimu UMEMOTO 	"matching label",
3504ef2dc8bSHajimu UMEMOTO 	"public/temporary address",
3514ef2dc8bSHajimu UMEMOTO 	"alive interface",
3524ef2dc8bSHajimu UMEMOTO 	"preferred interface",
3534ef2dc8bSHajimu UMEMOTO 	"rule #10",
3544ef2dc8bSHajimu UMEMOTO 	"rule #11",
3554ef2dc8bSHajimu UMEMOTO 	"rule #12",
3564ef2dc8bSHajimu UMEMOTO 	"rule #13",
3574ef2dc8bSHajimu UMEMOTO 	"longest match",
3584ef2dc8bSHajimu UMEMOTO 	"rule #15",
3594ef2dc8bSHajimu UMEMOTO };
3604ef2dc8bSHajimu UMEMOTO 
361cfa1ca9dSYoshinobu Inoue /*
362cfa1ca9dSYoshinobu Inoue  * Dump IP6 statistics structure.
363cfa1ca9dSYoshinobu Inoue  */
364cfa1ca9dSYoshinobu Inoue void
365feda1a43SJohn Baldwin ip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
366cfa1ca9dSYoshinobu Inoue {
367cfa1ca9dSYoshinobu Inoue 	struct ip6stat ip6stat;
368cfa1ca9dSYoshinobu Inoue 	int first, i;
369785d213dSHajimu UMEMOTO 	size_t len;
370cfa1ca9dSYoshinobu Inoue 
371785d213dSHajimu UMEMOTO 	len = sizeof ip6stat;
372feda1a43SJohn Baldwin 	if (live) {
373785d213dSHajimu UMEMOTO 		memset(&ip6stat, 0, len);
374feda1a43SJohn Baldwin 		if (sysctlbyname("net.inet6.ip6.stats", &ip6stat, &len, NULL,
375feda1a43SJohn Baldwin 		    0) < 0) {
376feda1a43SJohn Baldwin 			if (errno != ENOENT)
377feda1a43SJohn Baldwin 				warn("sysctl: net.inet6.ip6.stats");
3786eec3af9SPoul-Henning Kamp 			return;
379feda1a43SJohn Baldwin 		}
380feda1a43SJohn Baldwin 	} else
381feda1a43SJohn Baldwin 		kread(off, &ip6stat, len);
382feda1a43SJohn Baldwin 
383cfa1ca9dSYoshinobu Inoue 	printf("%s:\n", name);
384cfa1ca9dSYoshinobu Inoue 
385cfa1ca9dSYoshinobu Inoue #define	p(f, m) if (ip6stat.f || sflag <= 1) \
3867b95a1ebSYaroslav Tykhiy     printf(m, (uintmax_t)ip6stat.f, plural(ip6stat.f))
387cfa1ca9dSYoshinobu Inoue #define	p1a(f, m) if (ip6stat.f || sflag <= 1) \
3887b95a1ebSYaroslav Tykhiy     printf(m, (uintmax_t)ip6stat.f)
389cfa1ca9dSYoshinobu Inoue 
3907b95a1ebSYaroslav Tykhiy 	p(ip6s_total, "\t%ju total packet%s received\n");
3917b95a1ebSYaroslav Tykhiy 	p1a(ip6s_toosmall, "\t%ju with size smaller than minimum\n");
3927b95a1ebSYaroslav Tykhiy 	p1a(ip6s_tooshort, "\t%ju with data size < data length\n");
3937b95a1ebSYaroslav Tykhiy 	p1a(ip6s_badoptions, "\t%ju with bad options\n");
3947b95a1ebSYaroslav Tykhiy 	p1a(ip6s_badvers, "\t%ju with incorrect version number\n");
3957b95a1ebSYaroslav Tykhiy 	p(ip6s_fragments, "\t%ju fragment%s received\n");
3967b95a1ebSYaroslav Tykhiy 	p(ip6s_fragdropped, "\t%ju fragment%s dropped (dup or out of space)\n");
3977b95a1ebSYaroslav Tykhiy 	p(ip6s_fragtimeout, "\t%ju fragment%s dropped after timeout\n");
3987b95a1ebSYaroslav Tykhiy 	p(ip6s_fragoverflow, "\t%ju fragment%s that exceeded limit\n");
3997b95a1ebSYaroslav Tykhiy 	p(ip6s_reassembled, "\t%ju packet%s reassembled ok\n");
4007b95a1ebSYaroslav Tykhiy 	p(ip6s_delivered, "\t%ju packet%s for this host\n");
4017b95a1ebSYaroslav Tykhiy 	p(ip6s_forward, "\t%ju packet%s forwarded\n");
4027b95a1ebSYaroslav Tykhiy 	p(ip6s_cantforward, "\t%ju packet%s not forwardable\n");
4037b95a1ebSYaroslav Tykhiy 	p(ip6s_redirectsent, "\t%ju redirect%s sent\n");
4047b95a1ebSYaroslav Tykhiy 	p(ip6s_localout, "\t%ju packet%s sent from this host\n");
4057b95a1ebSYaroslav Tykhiy 	p(ip6s_rawout, "\t%ju packet%s sent with fabricated ip header\n");
4067b95a1ebSYaroslav Tykhiy 	p(ip6s_odropped, "\t%ju output packet%s dropped due to no bufs, etc.\n");
4077b95a1ebSYaroslav Tykhiy 	p(ip6s_noroute, "\t%ju output packet%s discarded due to no route\n");
4087b95a1ebSYaroslav Tykhiy 	p(ip6s_fragmented, "\t%ju output datagram%s fragmented\n");
4097b95a1ebSYaroslav Tykhiy 	p(ip6s_ofragments, "\t%ju fragment%s created\n");
4107b95a1ebSYaroslav Tykhiy 	p(ip6s_cantfrag, "\t%ju datagram%s that can't be fragmented\n");
4117b95a1ebSYaroslav Tykhiy 	p(ip6s_badscope, "\t%ju packet%s that violated scope rules\n");
4127b95a1ebSYaroslav Tykhiy 	p(ip6s_notmember, "\t%ju multicast packet%s which we don't join\n");
413cfa1ca9dSYoshinobu Inoue 	for (first = 1, i = 0; i < 256; i++)
414cfa1ca9dSYoshinobu Inoue 		if (ip6stat.ip6s_nxthist[i] != 0) {
415cfa1ca9dSYoshinobu Inoue 			if (first) {
416cfa1ca9dSYoshinobu Inoue 				printf("\tInput histogram:\n");
417cfa1ca9dSYoshinobu Inoue 				first = 0;
418cfa1ca9dSYoshinobu Inoue 			}
4197b95a1ebSYaroslav Tykhiy 			printf("\t\t%s: %ju\n", ip6nh[i],
4207b95a1ebSYaroslav Tykhiy 			    (uintmax_t)ip6stat.ip6s_nxthist[i]);
421cfa1ca9dSYoshinobu Inoue 		}
422cfa1ca9dSYoshinobu Inoue 	printf("\tMbuf statistics:\n");
4237b95a1ebSYaroslav Tykhiy 	printf("\t\t%ju one mbuf\n", (uintmax_t)ip6stat.ip6s_m1);
424cfa1ca9dSYoshinobu Inoue 	for (first = 1, i = 0; i < 32; i++) {
4257d56d374SYoshinobu Inoue 		char ifbuf[IFNAMSIZ];
426cfa1ca9dSYoshinobu Inoue 		if (ip6stat.ip6s_m2m[i] != 0) {
427cfa1ca9dSYoshinobu Inoue 			if (first) {
428cfa1ca9dSYoshinobu Inoue 				printf("\t\ttwo or more mbuf:\n");
429cfa1ca9dSYoshinobu Inoue 				first = 0;
430cfa1ca9dSYoshinobu Inoue 			}
4317b95a1ebSYaroslav Tykhiy 			printf("\t\t\t%s= %ju\n",
432cfa1ca9dSYoshinobu Inoue 			    if_indextoname(i, ifbuf),
4337b95a1ebSYaroslav Tykhiy 			    (uintmax_t)ip6stat.ip6s_m2m[i]);
434cfa1ca9dSYoshinobu Inoue 		}
435cfa1ca9dSYoshinobu Inoue 	}
4367b95a1ebSYaroslav Tykhiy 	printf("\t\t%ju one ext mbuf\n",
4377b95a1ebSYaroslav Tykhiy 	    (uintmax_t)ip6stat.ip6s_mext1);
4387b95a1ebSYaroslav Tykhiy 	printf("\t\t%ju two or more ext mbuf\n",
4397b95a1ebSYaroslav Tykhiy 	    (uintmax_t)ip6stat.ip6s_mext2m);
44032cd1d96SJun-ichiro itojun Hagino 	p(ip6s_exthdrtoolong,
441*a709913fSRebecca Cran 	    "\t%ju packet%s whose headers are not contiguous\n");
4427b95a1ebSYaroslav Tykhiy 	p(ip6s_nogif, "\t%ju tunneling packet%s that can't find gif\n");
44332cd1d96SJun-ichiro itojun Hagino 	p(ip6s_toomanyhdr,
4447b95a1ebSYaroslav Tykhiy 	    "\t%ju packet%s discarded because of too many headers\n");
44532cd1d96SJun-ichiro itojun Hagino 
44632cd1d96SJun-ichiro itojun Hagino 	/* for debugging source address selection */
44732cd1d96SJun-ichiro itojun Hagino #define	PRINT_SCOPESTAT(s,i) do {\
44832cd1d96SJun-ichiro itojun Hagino 		switch(i) { /* XXX hardcoding in each case */\
44932cd1d96SJun-ichiro itojun Hagino 		case 1:\
4507b95a1ebSYaroslav Tykhiy 			p(s, "\t\t%ju node-local%s\n");\
45132cd1d96SJun-ichiro itojun Hagino 			break;\
45232cd1d96SJun-ichiro itojun Hagino 		case 2:\
4537b95a1ebSYaroslav Tykhiy 			p(s,"\t\t%ju link-local%s\n");\
45432cd1d96SJun-ichiro itojun Hagino 			break;\
45532cd1d96SJun-ichiro itojun Hagino 		case 5:\
4567b95a1ebSYaroslav Tykhiy 			p(s,"\t\t%ju site-local%s\n");\
45732cd1d96SJun-ichiro itojun Hagino 			break;\
45832cd1d96SJun-ichiro itojun Hagino 		case 14:\
4597b95a1ebSYaroslav Tykhiy 			p(s,"\t\t%ju global%s\n");\
46032cd1d96SJun-ichiro itojun Hagino 			break;\
46132cd1d96SJun-ichiro itojun Hagino 		default:\
4627b95a1ebSYaroslav Tykhiy 			printf("\t\t%ju addresses scope=%x\n",\
4637b95a1ebSYaroslav Tykhiy 			    (uintmax_t)ip6stat.s, i);\
46432cd1d96SJun-ichiro itojun Hagino 		}\
46532cd1d96SJun-ichiro itojun Hagino 	} while (0);
46632cd1d96SJun-ichiro itojun Hagino 
46732cd1d96SJun-ichiro itojun Hagino 	p(ip6s_sources_none,
4687b95a1ebSYaroslav Tykhiy 	  "\t%ju failure%s of source address selection\n");
46932cd1d96SJun-ichiro itojun Hagino 	for (first = 1, i = 0; i < 16; i++) {
47032cd1d96SJun-ichiro itojun Hagino 		if (ip6stat.ip6s_sources_sameif[i]) {
47132cd1d96SJun-ichiro itojun Hagino 			if (first) {
47232cd1d96SJun-ichiro itojun Hagino 				printf("\tsource addresses on an outgoing I/F\n");
47332cd1d96SJun-ichiro itojun Hagino 				first = 0;
47432cd1d96SJun-ichiro itojun Hagino 			}
47532cd1d96SJun-ichiro itojun Hagino 			PRINT_SCOPESTAT(ip6s_sources_sameif[i], i);
47632cd1d96SJun-ichiro itojun Hagino 		}
47732cd1d96SJun-ichiro itojun Hagino 	}
47832cd1d96SJun-ichiro itojun Hagino 	for (first = 1, i = 0; i < 16; i++) {
47932cd1d96SJun-ichiro itojun Hagino 		if (ip6stat.ip6s_sources_otherif[i]) {
48032cd1d96SJun-ichiro itojun Hagino 			if (first) {
48132cd1d96SJun-ichiro itojun Hagino 				printf("\tsource addresses on a non-outgoing I/F\n");
48232cd1d96SJun-ichiro itojun Hagino 				first = 0;
48332cd1d96SJun-ichiro itojun Hagino 			}
48432cd1d96SJun-ichiro itojun Hagino 			PRINT_SCOPESTAT(ip6s_sources_otherif[i], i);
48532cd1d96SJun-ichiro itojun Hagino 		}
48632cd1d96SJun-ichiro itojun Hagino 	}
48732cd1d96SJun-ichiro itojun Hagino 	for (first = 1, i = 0; i < 16; i++) {
48832cd1d96SJun-ichiro itojun Hagino 		if (ip6stat.ip6s_sources_samescope[i]) {
48932cd1d96SJun-ichiro itojun Hagino 			if (first) {
49032cd1d96SJun-ichiro itojun Hagino 				printf("\tsource addresses of same scope\n");
49132cd1d96SJun-ichiro itojun Hagino 				first = 0;
49232cd1d96SJun-ichiro itojun Hagino 			}
49332cd1d96SJun-ichiro itojun Hagino 			PRINT_SCOPESTAT(ip6s_sources_samescope[i], i);
49432cd1d96SJun-ichiro itojun Hagino 		}
49532cd1d96SJun-ichiro itojun Hagino 	}
49632cd1d96SJun-ichiro itojun Hagino 	for (first = 1, i = 0; i < 16; i++) {
49732cd1d96SJun-ichiro itojun Hagino 		if (ip6stat.ip6s_sources_otherscope[i]) {
49832cd1d96SJun-ichiro itojun Hagino 			if (first) {
49932cd1d96SJun-ichiro itojun Hagino 				printf("\tsource addresses of a different scope\n");
50032cd1d96SJun-ichiro itojun Hagino 				first = 0;
50132cd1d96SJun-ichiro itojun Hagino 			}
50232cd1d96SJun-ichiro itojun Hagino 			PRINT_SCOPESTAT(ip6s_sources_otherscope[i], i);
50332cd1d96SJun-ichiro itojun Hagino 		}
50432cd1d96SJun-ichiro itojun Hagino 	}
50532cd1d96SJun-ichiro itojun Hagino 	for (first = 1, i = 0; i < 16; i++) {
50632cd1d96SJun-ichiro itojun Hagino 		if (ip6stat.ip6s_sources_deprecated[i]) {
50732cd1d96SJun-ichiro itojun Hagino 			if (first) {
50832cd1d96SJun-ichiro itojun Hagino 				printf("\tdeprecated source addresses\n");
50932cd1d96SJun-ichiro itojun Hagino 				first = 0;
51032cd1d96SJun-ichiro itojun Hagino 			}
51132cd1d96SJun-ichiro itojun Hagino 			PRINT_SCOPESTAT(ip6s_sources_deprecated[i], i);
51232cd1d96SJun-ichiro itojun Hagino 		}
51332cd1d96SJun-ichiro itojun Hagino 	}
51432cd1d96SJun-ichiro itojun Hagino 
5154ef2dc8bSHajimu UMEMOTO 	printf("\tSource addresses selection rule applied:\n");
5164ef2dc8bSHajimu UMEMOTO 	for (i = 0; i < 16; i++) {
5174ef2dc8bSHajimu UMEMOTO 		if (ip6stat.ip6s_sources_rule[i])
5187b95a1ebSYaroslav Tykhiy 			printf("\t\t%ju %s\n",
5197b95a1ebSYaroslav Tykhiy 			       (uintmax_t)ip6stat.ip6s_sources_rule[i],
5204ef2dc8bSHajimu UMEMOTO 			       srcrule_str[i]);
5214ef2dc8bSHajimu UMEMOTO 	}
522cfa1ca9dSYoshinobu Inoue #undef p
52332cd1d96SJun-ichiro itojun Hagino #undef p1a
524cfa1ca9dSYoshinobu Inoue }
525cfa1ca9dSYoshinobu Inoue 
526cfa1ca9dSYoshinobu Inoue /*
527cfa1ca9dSYoshinobu Inoue  * Dump IPv6 per-interface statistics based on RFC 2465.
528cfa1ca9dSYoshinobu Inoue  */
529cfa1ca9dSYoshinobu Inoue void
5305e051718SAssar Westerlund ip6_ifstats(char *ifname)
531cfa1ca9dSYoshinobu Inoue {
532cfa1ca9dSYoshinobu Inoue 	struct in6_ifreq ifr;
533cfa1ca9dSYoshinobu Inoue 	int s;
534cfa1ca9dSYoshinobu Inoue #define	p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
5357b95a1ebSYaroslav Tykhiy     printf(m, (uintmax_t)ifr.ifr_ifru.ifru_stat.f, plural(ifr.ifr_ifru.ifru_stat.f))
536cfa1ca9dSYoshinobu Inoue #define	p_5(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \
5377b95a1ebSYaroslav Tykhiy     printf(m, (uintmax_t)ip6stat.f)
538cfa1ca9dSYoshinobu Inoue 
539cfa1ca9dSYoshinobu Inoue 	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
540cfa1ca9dSYoshinobu Inoue 		perror("Warning: socket(AF_INET6)");
541cfa1ca9dSYoshinobu Inoue 		return;
542cfa1ca9dSYoshinobu Inoue 	}
543cfa1ca9dSYoshinobu Inoue 
544cfa1ca9dSYoshinobu Inoue 	strcpy(ifr.ifr_name, ifname);
545cfa1ca9dSYoshinobu Inoue 	printf("ip6 on %s:\n", ifr.ifr_name);
546cfa1ca9dSYoshinobu Inoue 
547cfa1ca9dSYoshinobu Inoue 	if (ioctl(s, SIOCGIFSTAT_IN6, (char *)&ifr) < 0) {
548cfa1ca9dSYoshinobu Inoue 		perror("Warning: ioctl(SIOCGIFSTAT_IN6)");
549cfa1ca9dSYoshinobu Inoue 		goto end;
550cfa1ca9dSYoshinobu Inoue 	}
551cfa1ca9dSYoshinobu Inoue 
5527b95a1ebSYaroslav Tykhiy 	p(ifs6_in_receive, "\t%ju total input datagram%s\n");
5537b95a1ebSYaroslav Tykhiy 	p(ifs6_in_hdrerr, "\t%ju datagram%s with invalid header received\n");
5547b95a1ebSYaroslav Tykhiy 	p(ifs6_in_toobig, "\t%ju datagram%s exceeded MTU received\n");
5557b95a1ebSYaroslav Tykhiy 	p(ifs6_in_noroute, "\t%ju datagram%s with no route received\n");
5567b95a1ebSYaroslav Tykhiy 	p(ifs6_in_addrerr, "\t%ju datagram%s with invalid dst received\n");
5577b95a1ebSYaroslav Tykhiy 	p(ifs6_in_protounknown, "\t%ju datagram%s with unknown proto received\n");
5587b95a1ebSYaroslav Tykhiy 	p(ifs6_in_truncated, "\t%ju truncated datagram%s received\n");
5597b95a1ebSYaroslav Tykhiy 	p(ifs6_in_discard, "\t%ju input datagram%s discarded\n");
560cfa1ca9dSYoshinobu Inoue 	p(ifs6_in_deliver,
5617b95a1ebSYaroslav Tykhiy 	  "\t%ju datagram%s delivered to an upper layer protocol\n");
5627b95a1ebSYaroslav Tykhiy 	p(ifs6_out_forward, "\t%ju datagram%s forwarded to this interface\n");
563cfa1ca9dSYoshinobu Inoue 	p(ifs6_out_request,
5647b95a1ebSYaroslav Tykhiy 	  "\t%ju datagram%s sent from an upper layer protocol\n");
5657b95a1ebSYaroslav Tykhiy 	p(ifs6_out_discard, "\t%ju total discarded output datagram%s\n");
5667b95a1ebSYaroslav Tykhiy 	p(ifs6_out_fragok, "\t%ju output datagram%s fragmented\n");
5677b95a1ebSYaroslav Tykhiy 	p(ifs6_out_fragfail, "\t%ju output datagram%s failed on fragment\n");
5687b95a1ebSYaroslav Tykhiy 	p(ifs6_out_fragcreat, "\t%ju output datagram%s succeeded on fragment\n");
5697b95a1ebSYaroslav Tykhiy 	p(ifs6_reass_reqd, "\t%ju incoming datagram%s fragmented\n");
5707b95a1ebSYaroslav Tykhiy 	p(ifs6_reass_ok, "\t%ju datagram%s reassembled\n");
5717b95a1ebSYaroslav Tykhiy 	p(ifs6_reass_fail, "\t%ju datagram%s failed on reassembly\n");
5727b95a1ebSYaroslav Tykhiy 	p(ifs6_in_mcast, "\t%ju multicast datagram%s received\n");
5737b95a1ebSYaroslav Tykhiy 	p(ifs6_out_mcast, "\t%ju multicast datagram%s sent\n");
574cfa1ca9dSYoshinobu Inoue 
575cfa1ca9dSYoshinobu Inoue   end:
576cfa1ca9dSYoshinobu Inoue 	close(s);
577cfa1ca9dSYoshinobu Inoue 
578cfa1ca9dSYoshinobu Inoue #undef p
579cfa1ca9dSYoshinobu Inoue #undef p_5
580cfa1ca9dSYoshinobu Inoue }
581cfa1ca9dSYoshinobu Inoue 
582a01e3379SDavid Malone static	const char *icmp6names[] = {
583cfa1ca9dSYoshinobu Inoue 	"#0",
584cfa1ca9dSYoshinobu Inoue 	"unreach",
585cfa1ca9dSYoshinobu Inoue 	"packet too big",
586cfa1ca9dSYoshinobu Inoue 	"time exceed",
587cfa1ca9dSYoshinobu Inoue 	"parameter problem",
588cfa1ca9dSYoshinobu Inoue 	"#5",
589cfa1ca9dSYoshinobu Inoue 	"#6",
590cfa1ca9dSYoshinobu Inoue 	"#7",
591cfa1ca9dSYoshinobu Inoue 	"#8",
592cfa1ca9dSYoshinobu Inoue 	"#9",
593cfa1ca9dSYoshinobu Inoue 	"#10",
594cfa1ca9dSYoshinobu Inoue 	"#11",
595cfa1ca9dSYoshinobu Inoue 	"#12",
596cfa1ca9dSYoshinobu Inoue 	"#13",
597cfa1ca9dSYoshinobu Inoue 	"#14",
598cfa1ca9dSYoshinobu Inoue 	"#15",
599cfa1ca9dSYoshinobu Inoue 	"#16",
600cfa1ca9dSYoshinobu Inoue 	"#17",
601cfa1ca9dSYoshinobu Inoue 	"#18",
602cfa1ca9dSYoshinobu Inoue 	"#19",
603cfa1ca9dSYoshinobu Inoue 	"#20",
604cfa1ca9dSYoshinobu Inoue 	"#21",
605cfa1ca9dSYoshinobu Inoue 	"#22",
606cfa1ca9dSYoshinobu Inoue 	"#23",
607cfa1ca9dSYoshinobu Inoue 	"#24",
608cfa1ca9dSYoshinobu Inoue 	"#25",
609cfa1ca9dSYoshinobu Inoue 	"#26",
610cfa1ca9dSYoshinobu Inoue 	"#27",
611cfa1ca9dSYoshinobu Inoue 	"#28",
612cfa1ca9dSYoshinobu Inoue 	"#29",
613cfa1ca9dSYoshinobu Inoue 	"#30",
614cfa1ca9dSYoshinobu Inoue 	"#31",
615cfa1ca9dSYoshinobu Inoue 	"#32",
616cfa1ca9dSYoshinobu Inoue 	"#33",
617cfa1ca9dSYoshinobu Inoue 	"#34",
618cfa1ca9dSYoshinobu Inoue 	"#35",
619cfa1ca9dSYoshinobu Inoue 	"#36",
620cfa1ca9dSYoshinobu Inoue 	"#37",
621cfa1ca9dSYoshinobu Inoue 	"#38",
622cfa1ca9dSYoshinobu Inoue 	"#39",
623cfa1ca9dSYoshinobu Inoue 	"#40",
624cfa1ca9dSYoshinobu Inoue 	"#41",
625cfa1ca9dSYoshinobu Inoue 	"#42",
626cfa1ca9dSYoshinobu Inoue 	"#43",
627cfa1ca9dSYoshinobu Inoue 	"#44",
628cfa1ca9dSYoshinobu Inoue 	"#45",
629cfa1ca9dSYoshinobu Inoue 	"#46",
630cfa1ca9dSYoshinobu Inoue 	"#47",
631cfa1ca9dSYoshinobu Inoue 	"#48",
632cfa1ca9dSYoshinobu Inoue 	"#49",
633cfa1ca9dSYoshinobu Inoue 	"#50",
634cfa1ca9dSYoshinobu Inoue 	"#51",
635cfa1ca9dSYoshinobu Inoue 	"#52",
636cfa1ca9dSYoshinobu Inoue 	"#53",
637cfa1ca9dSYoshinobu Inoue 	"#54",
638cfa1ca9dSYoshinobu Inoue 	"#55",
639cfa1ca9dSYoshinobu Inoue 	"#56",
640cfa1ca9dSYoshinobu Inoue 	"#57",
641cfa1ca9dSYoshinobu Inoue 	"#58",
642cfa1ca9dSYoshinobu Inoue 	"#59",
643cfa1ca9dSYoshinobu Inoue 	"#60",
644cfa1ca9dSYoshinobu Inoue 	"#61",
645cfa1ca9dSYoshinobu Inoue 	"#62",
646cfa1ca9dSYoshinobu Inoue 	"#63",
647cfa1ca9dSYoshinobu Inoue 	"#64",
648cfa1ca9dSYoshinobu Inoue 	"#65",
649cfa1ca9dSYoshinobu Inoue 	"#66",
650cfa1ca9dSYoshinobu Inoue 	"#67",
651cfa1ca9dSYoshinobu Inoue 	"#68",
652cfa1ca9dSYoshinobu Inoue 	"#69",
653cfa1ca9dSYoshinobu Inoue 	"#70",
654cfa1ca9dSYoshinobu Inoue 	"#71",
655cfa1ca9dSYoshinobu Inoue 	"#72",
656cfa1ca9dSYoshinobu Inoue 	"#73",
657cfa1ca9dSYoshinobu Inoue 	"#74",
658cfa1ca9dSYoshinobu Inoue 	"#75",
659cfa1ca9dSYoshinobu Inoue 	"#76",
660cfa1ca9dSYoshinobu Inoue 	"#77",
661cfa1ca9dSYoshinobu Inoue 	"#78",
662cfa1ca9dSYoshinobu Inoue 	"#79",
663cfa1ca9dSYoshinobu Inoue 	"#80",
664cfa1ca9dSYoshinobu Inoue 	"#81",
665cfa1ca9dSYoshinobu Inoue 	"#82",
666cfa1ca9dSYoshinobu Inoue 	"#83",
667cfa1ca9dSYoshinobu Inoue 	"#84",
668cfa1ca9dSYoshinobu Inoue 	"#85",
669cfa1ca9dSYoshinobu Inoue 	"#86",
670cfa1ca9dSYoshinobu Inoue 	"#87",
671cfa1ca9dSYoshinobu Inoue 	"#88",
672cfa1ca9dSYoshinobu Inoue 	"#89",
673cfa1ca9dSYoshinobu Inoue 	"#80",
674cfa1ca9dSYoshinobu Inoue 	"#91",
675cfa1ca9dSYoshinobu Inoue 	"#92",
676cfa1ca9dSYoshinobu Inoue 	"#93",
677cfa1ca9dSYoshinobu Inoue 	"#94",
678cfa1ca9dSYoshinobu Inoue 	"#95",
679cfa1ca9dSYoshinobu Inoue 	"#96",
680cfa1ca9dSYoshinobu Inoue 	"#97",
681cfa1ca9dSYoshinobu Inoue 	"#98",
682cfa1ca9dSYoshinobu Inoue 	"#99",
683cfa1ca9dSYoshinobu Inoue 	"#100",
684cfa1ca9dSYoshinobu Inoue 	"#101",
685cfa1ca9dSYoshinobu Inoue 	"#102",
686cfa1ca9dSYoshinobu Inoue 	"#103",
687cfa1ca9dSYoshinobu Inoue 	"#104",
688cfa1ca9dSYoshinobu Inoue 	"#105",
689cfa1ca9dSYoshinobu Inoue 	"#106",
690cfa1ca9dSYoshinobu Inoue 	"#107",
691cfa1ca9dSYoshinobu Inoue 	"#108",
692cfa1ca9dSYoshinobu Inoue 	"#109",
693cfa1ca9dSYoshinobu Inoue 	"#110",
694cfa1ca9dSYoshinobu Inoue 	"#111",
695cfa1ca9dSYoshinobu Inoue 	"#112",
696cfa1ca9dSYoshinobu Inoue 	"#113",
697cfa1ca9dSYoshinobu Inoue 	"#114",
698cfa1ca9dSYoshinobu Inoue 	"#115",
699cfa1ca9dSYoshinobu Inoue 	"#116",
700cfa1ca9dSYoshinobu Inoue 	"#117",
701cfa1ca9dSYoshinobu Inoue 	"#118",
702cfa1ca9dSYoshinobu Inoue 	"#119",
703cfa1ca9dSYoshinobu Inoue 	"#120",
704cfa1ca9dSYoshinobu Inoue 	"#121",
705cfa1ca9dSYoshinobu Inoue 	"#122",
706cfa1ca9dSYoshinobu Inoue 	"#123",
707cfa1ca9dSYoshinobu Inoue 	"#124",
708cfa1ca9dSYoshinobu Inoue 	"#125",
709cfa1ca9dSYoshinobu Inoue 	"#126",
710cfa1ca9dSYoshinobu Inoue 	"#127",
711cfa1ca9dSYoshinobu Inoue 	"echo",
712cfa1ca9dSYoshinobu Inoue 	"echo reply",
713cfa1ca9dSYoshinobu Inoue 	"multicast listener query",
7147d9d64baSBruce M Simpson 	"MLDv1 listener report",
7157d9d64baSBruce M Simpson 	"MLDv1 listener done",
716cfa1ca9dSYoshinobu Inoue 	"router solicitation",
7176ab55b23SDima Dorfman 	"router advertisement",
718cfa1ca9dSYoshinobu Inoue 	"neighbor solicitation",
7196ab55b23SDima Dorfman 	"neighbor advertisement",
720cfa1ca9dSYoshinobu Inoue 	"redirect",
721cfa1ca9dSYoshinobu Inoue 	"router renumbering",
722cfa1ca9dSYoshinobu Inoue 	"node information request",
723cfa1ca9dSYoshinobu Inoue 	"node information reply",
724fd555639SMunechika SUMIKAWA 	"inverse neighbor solicitation",
725fd555639SMunechika SUMIKAWA 	"inverse neighbor advertisement",
7267d9d64baSBruce M Simpson 	"MLDv2 listener report",
727cfa1ca9dSYoshinobu Inoue 	"#144",
728cfa1ca9dSYoshinobu Inoue 	"#145",
729cfa1ca9dSYoshinobu Inoue 	"#146",
730cfa1ca9dSYoshinobu Inoue 	"#147",
731cfa1ca9dSYoshinobu Inoue 	"#148",
732cfa1ca9dSYoshinobu Inoue 	"#149",
733cfa1ca9dSYoshinobu Inoue 	"#150",
734cfa1ca9dSYoshinobu Inoue 	"#151",
735cfa1ca9dSYoshinobu Inoue 	"#152",
736cfa1ca9dSYoshinobu Inoue 	"#153",
737cfa1ca9dSYoshinobu Inoue 	"#154",
738cfa1ca9dSYoshinobu Inoue 	"#155",
739cfa1ca9dSYoshinobu Inoue 	"#156",
740cfa1ca9dSYoshinobu Inoue 	"#157",
741cfa1ca9dSYoshinobu Inoue 	"#158",
742cfa1ca9dSYoshinobu Inoue 	"#159",
743cfa1ca9dSYoshinobu Inoue 	"#160",
744cfa1ca9dSYoshinobu Inoue 	"#161",
745cfa1ca9dSYoshinobu Inoue 	"#162",
746cfa1ca9dSYoshinobu Inoue 	"#163",
747cfa1ca9dSYoshinobu Inoue 	"#164",
748cfa1ca9dSYoshinobu Inoue 	"#165",
749cfa1ca9dSYoshinobu Inoue 	"#166",
750cfa1ca9dSYoshinobu Inoue 	"#167",
751cfa1ca9dSYoshinobu Inoue 	"#168",
752cfa1ca9dSYoshinobu Inoue 	"#169",
753cfa1ca9dSYoshinobu Inoue 	"#170",
754cfa1ca9dSYoshinobu Inoue 	"#171",
755cfa1ca9dSYoshinobu Inoue 	"#172",
756cfa1ca9dSYoshinobu Inoue 	"#173",
757cfa1ca9dSYoshinobu Inoue 	"#174",
758cfa1ca9dSYoshinobu Inoue 	"#175",
759cfa1ca9dSYoshinobu Inoue 	"#176",
760cfa1ca9dSYoshinobu Inoue 	"#177",
761cfa1ca9dSYoshinobu Inoue 	"#178",
762cfa1ca9dSYoshinobu Inoue 	"#179",
763cfa1ca9dSYoshinobu Inoue 	"#180",
764cfa1ca9dSYoshinobu Inoue 	"#181",
765cfa1ca9dSYoshinobu Inoue 	"#182",
766cfa1ca9dSYoshinobu Inoue 	"#183",
767cfa1ca9dSYoshinobu Inoue 	"#184",
768cfa1ca9dSYoshinobu Inoue 	"#185",
769cfa1ca9dSYoshinobu Inoue 	"#186",
770cfa1ca9dSYoshinobu Inoue 	"#187",
771cfa1ca9dSYoshinobu Inoue 	"#188",
772cfa1ca9dSYoshinobu Inoue 	"#189",
773cfa1ca9dSYoshinobu Inoue 	"#180",
774cfa1ca9dSYoshinobu Inoue 	"#191",
775cfa1ca9dSYoshinobu Inoue 	"#192",
776cfa1ca9dSYoshinobu Inoue 	"#193",
777cfa1ca9dSYoshinobu Inoue 	"#194",
778cfa1ca9dSYoshinobu Inoue 	"#195",
779cfa1ca9dSYoshinobu Inoue 	"#196",
780cfa1ca9dSYoshinobu Inoue 	"#197",
781cfa1ca9dSYoshinobu Inoue 	"#198",
782cfa1ca9dSYoshinobu Inoue 	"#199",
783cfa1ca9dSYoshinobu Inoue 	"#200",
784cfa1ca9dSYoshinobu Inoue 	"#201",
785cfa1ca9dSYoshinobu Inoue 	"#202",
786cfa1ca9dSYoshinobu Inoue 	"#203",
787cfa1ca9dSYoshinobu Inoue 	"#204",
788cfa1ca9dSYoshinobu Inoue 	"#205",
789cfa1ca9dSYoshinobu Inoue 	"#206",
790cfa1ca9dSYoshinobu Inoue 	"#207",
791cfa1ca9dSYoshinobu Inoue 	"#208",
792cfa1ca9dSYoshinobu Inoue 	"#209",
793cfa1ca9dSYoshinobu Inoue 	"#210",
794cfa1ca9dSYoshinobu Inoue 	"#211",
795cfa1ca9dSYoshinobu Inoue 	"#212",
796cfa1ca9dSYoshinobu Inoue 	"#213",
797cfa1ca9dSYoshinobu Inoue 	"#214",
798cfa1ca9dSYoshinobu Inoue 	"#215",
799cfa1ca9dSYoshinobu Inoue 	"#216",
800cfa1ca9dSYoshinobu Inoue 	"#217",
801cfa1ca9dSYoshinobu Inoue 	"#218",
802cfa1ca9dSYoshinobu Inoue 	"#219",
803cfa1ca9dSYoshinobu Inoue 	"#220",
804cfa1ca9dSYoshinobu Inoue 	"#221",
805cfa1ca9dSYoshinobu Inoue 	"#222",
806cfa1ca9dSYoshinobu Inoue 	"#223",
807cfa1ca9dSYoshinobu Inoue 	"#224",
808cfa1ca9dSYoshinobu Inoue 	"#225",
809cfa1ca9dSYoshinobu Inoue 	"#226",
810cfa1ca9dSYoshinobu Inoue 	"#227",
811cfa1ca9dSYoshinobu Inoue 	"#228",
812cfa1ca9dSYoshinobu Inoue 	"#229",
813cfa1ca9dSYoshinobu Inoue 	"#230",
814cfa1ca9dSYoshinobu Inoue 	"#231",
815cfa1ca9dSYoshinobu Inoue 	"#232",
816cfa1ca9dSYoshinobu Inoue 	"#233",
817cfa1ca9dSYoshinobu Inoue 	"#234",
818cfa1ca9dSYoshinobu Inoue 	"#235",
819cfa1ca9dSYoshinobu Inoue 	"#236",
820cfa1ca9dSYoshinobu Inoue 	"#237",
821cfa1ca9dSYoshinobu Inoue 	"#238",
822cfa1ca9dSYoshinobu Inoue 	"#239",
823cfa1ca9dSYoshinobu Inoue 	"#240",
824cfa1ca9dSYoshinobu Inoue 	"#241",
825cfa1ca9dSYoshinobu Inoue 	"#242",
826cfa1ca9dSYoshinobu Inoue 	"#243",
827cfa1ca9dSYoshinobu Inoue 	"#244",
828cfa1ca9dSYoshinobu Inoue 	"#245",
829cfa1ca9dSYoshinobu Inoue 	"#246",
830cfa1ca9dSYoshinobu Inoue 	"#247",
831cfa1ca9dSYoshinobu Inoue 	"#248",
832cfa1ca9dSYoshinobu Inoue 	"#249",
833cfa1ca9dSYoshinobu Inoue 	"#250",
834cfa1ca9dSYoshinobu Inoue 	"#251",
835cfa1ca9dSYoshinobu Inoue 	"#252",
836cfa1ca9dSYoshinobu Inoue 	"#253",
837cfa1ca9dSYoshinobu Inoue 	"#254",
838cfa1ca9dSYoshinobu Inoue 	"#255",
839cfa1ca9dSYoshinobu Inoue };
840cfa1ca9dSYoshinobu Inoue 
841cfa1ca9dSYoshinobu Inoue /*
842cfa1ca9dSYoshinobu Inoue  * Dump ICMP6 statistics.
843cfa1ca9dSYoshinobu Inoue  */
844cfa1ca9dSYoshinobu Inoue void
845feda1a43SJohn Baldwin icmp6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
846cfa1ca9dSYoshinobu Inoue {
847cfa1ca9dSYoshinobu Inoue 	struct icmp6stat icmp6stat;
848241667c4SMark Murray 	int i, first;
849785d213dSHajimu UMEMOTO 	size_t len;
850cfa1ca9dSYoshinobu Inoue 
851785d213dSHajimu UMEMOTO 	len = sizeof icmp6stat;
852feda1a43SJohn Baldwin 	if (live) {
853785d213dSHajimu UMEMOTO 		memset(&icmp6stat, 0, len);
854feda1a43SJohn Baldwin 		if (sysctlbyname("net.inet6.icmp6.stats", &icmp6stat, &len,
855feda1a43SJohn Baldwin 		    NULL, 0) < 0) {
856feda1a43SJohn Baldwin 			if (errno != ENOENT)
857feda1a43SJohn Baldwin 				warn("sysctl: net.inet6.icmp6.stats");
858cfa1ca9dSYoshinobu Inoue 			return;
859feda1a43SJohn Baldwin 		}
860feda1a43SJohn Baldwin 	} else
861feda1a43SJohn Baldwin 		kread(off, &icmp6stat, len);
862feda1a43SJohn Baldwin 
863cfa1ca9dSYoshinobu Inoue 	printf("%s:\n", name);
864cfa1ca9dSYoshinobu Inoue 
865cfa1ca9dSYoshinobu Inoue #define	p(f, m) if (icmp6stat.f || sflag <= 1) \
8667b95a1ebSYaroslav Tykhiy     printf(m, (uintmax_t)icmp6stat.f, plural(icmp6stat.f))
8673ed817f1SMaxim Konovalov #define	p_5(f, m) if (icmp6stat.f || sflag <= 1) \
8683ed817f1SMaxim Konovalov     printf(m, (uintmax_t)icmp6stat.f)
869cfa1ca9dSYoshinobu Inoue 
8707b95a1ebSYaroslav Tykhiy 	p(icp6s_error, "\t%ju call%s to icmp6_error\n");
871cfa1ca9dSYoshinobu Inoue 	p(icp6s_canterror,
8727b95a1ebSYaroslav Tykhiy 	    "\t%ju error%s not generated in response to an icmp6 message\n");
873cfa1ca9dSYoshinobu Inoue 	p(icp6s_toofreq,
8747b95a1ebSYaroslav Tykhiy 	  "\t%ju error%s not generated because of rate limitation\n");
875241667c4SMark Murray #define	NELEM (int)(sizeof(icmp6stat.icp6s_outhist)/sizeof(icmp6stat.icp6s_outhist[0]))
876fd555639SMunechika SUMIKAWA 	for (first = 1, i = 0; i < NELEM; i++)
877cfa1ca9dSYoshinobu Inoue 		if (icmp6stat.icp6s_outhist[i] != 0) {
878cfa1ca9dSYoshinobu Inoue 			if (first) {
879cfa1ca9dSYoshinobu Inoue 				printf("\tOutput histogram:\n");
880cfa1ca9dSYoshinobu Inoue 				first = 0;
881cfa1ca9dSYoshinobu Inoue 			}
8827b95a1ebSYaroslav Tykhiy 			printf("\t\t%s: %ju\n", icmp6names[i],
8837b95a1ebSYaroslav Tykhiy 			    (uintmax_t)icmp6stat.icp6s_outhist[i]);
884cfa1ca9dSYoshinobu Inoue 		}
885fd555639SMunechika SUMIKAWA #undef NELEM
8867b95a1ebSYaroslav Tykhiy 	p(icp6s_badcode, "\t%ju message%s with bad code fields\n");
8877b95a1ebSYaroslav Tykhiy 	p(icp6s_tooshort, "\t%ju message%s < minimum length\n");
8887b95a1ebSYaroslav Tykhiy 	p(icp6s_checksum, "\t%ju bad checksum%s\n");
8897b95a1ebSYaroslav Tykhiy 	p(icp6s_badlen, "\t%ju message%s with bad length\n");
890241667c4SMark Murray #define	NELEM (int)(sizeof(icmp6stat.icp6s_inhist)/sizeof(icmp6stat.icp6s_inhist[0]))
891fd555639SMunechika SUMIKAWA 	for (first = 1, i = 0; i < NELEM; i++)
892cfa1ca9dSYoshinobu Inoue 		if (icmp6stat.icp6s_inhist[i] != 0) {
893cfa1ca9dSYoshinobu Inoue 			if (first) {
894cfa1ca9dSYoshinobu Inoue 				printf("\tInput histogram:\n");
895cfa1ca9dSYoshinobu Inoue 				first = 0;
896cfa1ca9dSYoshinobu Inoue 			}
8977b95a1ebSYaroslav Tykhiy 			printf("\t\t%s: %ju\n", icmp6names[i],
8987b95a1ebSYaroslav Tykhiy 			    (uintmax_t)icmp6stat.icp6s_inhist[i]);
899cfa1ca9dSYoshinobu Inoue 		}
900fd555639SMunechika SUMIKAWA #undef NELEM
9016ab55b23SDima Dorfman 	printf("\tHistogram of error messages to be generated:\n");
9027b95a1ebSYaroslav Tykhiy 	p_5(icp6s_odst_unreach_noroute, "\t\t%ju no route\n");
9037b95a1ebSYaroslav Tykhiy 	p_5(icp6s_odst_unreach_admin, "\t\t%ju administratively prohibited\n");
9047b95a1ebSYaroslav Tykhiy 	p_5(icp6s_odst_unreach_beyondscope, "\t\t%ju beyond scope\n");
9057b95a1ebSYaroslav Tykhiy 	p_5(icp6s_odst_unreach_addr, "\t\t%ju address unreachable\n");
9067b95a1ebSYaroslav Tykhiy 	p_5(icp6s_odst_unreach_noport, "\t\t%ju port unreachable\n");
9077b95a1ebSYaroslav Tykhiy 	p_5(icp6s_opacket_too_big, "\t\t%ju packet too big\n");
9087b95a1ebSYaroslav Tykhiy 	p_5(icp6s_otime_exceed_transit, "\t\t%ju time exceed transit\n");
9097b95a1ebSYaroslav Tykhiy 	p_5(icp6s_otime_exceed_reassembly, "\t\t%ju time exceed reassembly\n");
9107b95a1ebSYaroslav Tykhiy 	p_5(icp6s_oparamprob_header, "\t\t%ju erroneous header field\n");
9117b95a1ebSYaroslav Tykhiy 	p_5(icp6s_oparamprob_nextheader, "\t\t%ju unrecognized next header\n");
9127b95a1ebSYaroslav Tykhiy 	p_5(icp6s_oparamprob_option, "\t\t%ju unrecognized option\n");
9137b95a1ebSYaroslav Tykhiy 	p_5(icp6s_oredirect, "\t\t%ju redirect\n");
9147b95a1ebSYaroslav Tykhiy 	p_5(icp6s_ounknown, "\t\t%ju unknown\n");
91532cd1d96SJun-ichiro itojun Hagino 
9167b95a1ebSYaroslav Tykhiy 	p(icp6s_reflect, "\t%ju message response%s generated\n");
9177b95a1ebSYaroslav Tykhiy 	p(icp6s_nd_toomanyopt, "\t%ju message%s with too many ND options\n");
9187b95a1ebSYaroslav Tykhiy 	p(icp6s_nd_badopt, "\t%ju message%s with bad ND options\n");
9197b95a1ebSYaroslav Tykhiy 	p(icp6s_badns, "\t%ju bad neighbor solicitation message%s\n");
9207b95a1ebSYaroslav Tykhiy 	p(icp6s_badna, "\t%ju bad neighbor advertisement message%s\n");
9217b95a1ebSYaroslav Tykhiy 	p(icp6s_badrs, "\t%ju bad router solicitation message%s\n");
9227b95a1ebSYaroslav Tykhiy 	p(icp6s_badra, "\t%ju bad router advertisement message%s\n");
9237b95a1ebSYaroslav Tykhiy 	p(icp6s_badredirect, "\t%ju bad redirect message%s\n");
9247b95a1ebSYaroslav Tykhiy 	p(icp6s_pmtuchg, "\t%ju path MTU change%s\n");
925cfa1ca9dSYoshinobu Inoue #undef p
926cfa1ca9dSYoshinobu Inoue #undef p_5
927cfa1ca9dSYoshinobu Inoue }
928cfa1ca9dSYoshinobu Inoue 
929cfa1ca9dSYoshinobu Inoue /*
930cfa1ca9dSYoshinobu Inoue  * Dump ICMPv6 per-interface statistics based on RFC 2466.
931cfa1ca9dSYoshinobu Inoue  */
932cfa1ca9dSYoshinobu Inoue void
9335e051718SAssar Westerlund icmp6_ifstats(char *ifname)
934cfa1ca9dSYoshinobu Inoue {
935cfa1ca9dSYoshinobu Inoue 	struct in6_ifreq ifr;
936cfa1ca9dSYoshinobu Inoue 	int s;
937cfa1ca9dSYoshinobu Inoue #define	p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \
9387b95a1ebSYaroslav Tykhiy     printf(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f, plural(ifr.ifr_ifru.ifru_icmp6stat.f))
939f99a4046SMike Makonnen #define	p2(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \
9407b95a1ebSYaroslav Tykhiy     printf(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f, pluralies(ifr.ifr_ifru.ifru_icmp6stat.f))
941cfa1ca9dSYoshinobu Inoue 
942cfa1ca9dSYoshinobu Inoue 	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
943cfa1ca9dSYoshinobu Inoue 		perror("Warning: socket(AF_INET6)");
944cfa1ca9dSYoshinobu Inoue 		return;
945cfa1ca9dSYoshinobu Inoue 	}
946cfa1ca9dSYoshinobu Inoue 
947cfa1ca9dSYoshinobu Inoue 	strcpy(ifr.ifr_name, ifname);
948cfa1ca9dSYoshinobu Inoue 	printf("icmp6 on %s:\n", ifr.ifr_name);
949cfa1ca9dSYoshinobu Inoue 
950cfa1ca9dSYoshinobu Inoue 	if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) {
951cfa1ca9dSYoshinobu Inoue 		perror("Warning: ioctl(SIOCGIFSTAT_ICMP6)");
952cfa1ca9dSYoshinobu Inoue 		goto end;
953cfa1ca9dSYoshinobu Inoue 	}
954cfa1ca9dSYoshinobu Inoue 
9557b95a1ebSYaroslav Tykhiy 	p(ifs6_in_msg, "\t%ju total input message%s\n");
9567b95a1ebSYaroslav Tykhiy 	p(ifs6_in_error, "\t%ju total input error message%s\n");
9577b95a1ebSYaroslav Tykhiy 	p(ifs6_in_dstunreach, "\t%ju input destination unreachable error%s\n");
9587b95a1ebSYaroslav Tykhiy 	p(ifs6_in_adminprohib, "\t%ju input administratively prohibited error%s\n");
9597b95a1ebSYaroslav Tykhiy 	p(ifs6_in_timeexceed, "\t%ju input time exceeded error%s\n");
9607b95a1ebSYaroslav Tykhiy 	p(ifs6_in_paramprob, "\t%ju input parameter problem error%s\n");
9617b95a1ebSYaroslav Tykhiy 	p(ifs6_in_pkttoobig, "\t%ju input packet too big error%s\n");
9627b95a1ebSYaroslav Tykhiy 	p(ifs6_in_echo, "\t%ju input echo request%s\n");
9637b95a1ebSYaroslav Tykhiy 	p2(ifs6_in_echoreply, "\t%ju input echo repl%s\n");
9647b95a1ebSYaroslav Tykhiy 	p(ifs6_in_routersolicit, "\t%ju input router solicitation%s\n");
9657b95a1ebSYaroslav Tykhiy 	p(ifs6_in_routeradvert, "\t%ju input router advertisement%s\n");
9667b95a1ebSYaroslav Tykhiy 	p(ifs6_in_neighborsolicit, "\t%ju input neighbor solicitation%s\n");
9677b95a1ebSYaroslav Tykhiy 	p(ifs6_in_neighboradvert, "\t%ju input neighbor advertisement%s\n");
9687b95a1ebSYaroslav Tykhiy 	p(ifs6_in_redirect, "\t%ju input redirect%s\n");
9697b95a1ebSYaroslav Tykhiy 	p2(ifs6_in_mldquery, "\t%ju input MLD quer%s\n");
9707b95a1ebSYaroslav Tykhiy 	p(ifs6_in_mldreport, "\t%ju input MLD report%s\n");
9717b95a1ebSYaroslav Tykhiy 	p(ifs6_in_mlddone, "\t%ju input MLD done%s\n");
972cfa1ca9dSYoshinobu Inoue 
9737b95a1ebSYaroslav Tykhiy 	p(ifs6_out_msg, "\t%ju total output message%s\n");
9747b95a1ebSYaroslav Tykhiy 	p(ifs6_out_error, "\t%ju total output error message%s\n");
9757b95a1ebSYaroslav Tykhiy 	p(ifs6_out_dstunreach, "\t%ju output destination unreachable error%s\n");
9767b95a1ebSYaroslav Tykhiy 	p(ifs6_out_adminprohib, "\t%ju output administratively prohibited error%s\n");
9777b95a1ebSYaroslav Tykhiy 	p(ifs6_out_timeexceed, "\t%ju output time exceeded error%s\n");
9787b95a1ebSYaroslav Tykhiy 	p(ifs6_out_paramprob, "\t%ju output parameter problem error%s\n");
9797b95a1ebSYaroslav Tykhiy 	p(ifs6_out_pkttoobig, "\t%ju output packet too big error%s\n");
9807b95a1ebSYaroslav Tykhiy 	p(ifs6_out_echo, "\t%ju output echo request%s\n");
9817b95a1ebSYaroslav Tykhiy 	p2(ifs6_out_echoreply, "\t%ju output echo repl%s\n");
9827b95a1ebSYaroslav Tykhiy 	p(ifs6_out_routersolicit, "\t%ju output router solicitation%s\n");
9837b95a1ebSYaroslav Tykhiy 	p(ifs6_out_routeradvert, "\t%ju output router advertisement%s\n");
9847b95a1ebSYaroslav Tykhiy 	p(ifs6_out_neighborsolicit, "\t%ju output neighbor solicitation%s\n");
9857b95a1ebSYaroslav Tykhiy 	p(ifs6_out_neighboradvert, "\t%ju output neighbor advertisement%s\n");
9867b95a1ebSYaroslav Tykhiy 	p(ifs6_out_redirect, "\t%ju output redirect%s\n");
9877b95a1ebSYaroslav Tykhiy 	p2(ifs6_out_mldquery, "\t%ju output MLD quer%s\n");
9887b95a1ebSYaroslav Tykhiy 	p(ifs6_out_mldreport, "\t%ju output MLD report%s\n");
9897b95a1ebSYaroslav Tykhiy 	p(ifs6_out_mlddone, "\t%ju output MLD done%s\n");
990cfa1ca9dSYoshinobu Inoue 
991cfa1ca9dSYoshinobu Inoue   end:
992cfa1ca9dSYoshinobu Inoue 	close(s);
993cfa1ca9dSYoshinobu Inoue #undef p
994cfa1ca9dSYoshinobu Inoue }
995cfa1ca9dSYoshinobu Inoue 
996cfa1ca9dSYoshinobu Inoue /*
997cfa1ca9dSYoshinobu Inoue  * Dump PIM statistics structure.
998cfa1ca9dSYoshinobu Inoue  */
999cfa1ca9dSYoshinobu Inoue void
1000feda1a43SJohn Baldwin pim6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
1001cfa1ca9dSYoshinobu Inoue {
1002c15ddad9SBruce M Simpson 	struct pim6stat pim6stat, zerostat;
1003c15ddad9SBruce M Simpson 	size_t len = sizeof pim6stat;
1004cfa1ca9dSYoshinobu Inoue 
1005feda1a43SJohn Baldwin 	if (live) {
1006c15ddad9SBruce M Simpson 		if (zflag)
1007c15ddad9SBruce M Simpson 			memset(&zerostat, 0, len);
1008c15ddad9SBruce M Simpson 		if (sysctlbyname("net.inet6.pim.stats", &pim6stat, &len,
1009c15ddad9SBruce M Simpson 		    zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
1010c15ddad9SBruce M Simpson 			if (errno != ENOENT)
1011c15ddad9SBruce M Simpson 				warn("sysctl: net.inet6.pim.stats");
1012cfa1ca9dSYoshinobu Inoue 			return;
1013c15ddad9SBruce M Simpson 		}
1014feda1a43SJohn Baldwin 	} else {
1015feda1a43SJohn Baldwin 		if (off == 0)
1016feda1a43SJohn Baldwin 			return;
1017feda1a43SJohn Baldwin 		kread(off, &pim6stat, len);
1018feda1a43SJohn Baldwin 	}
1019feda1a43SJohn Baldwin 
1020cfa1ca9dSYoshinobu Inoue 	printf("%s:\n", name);
1021cfa1ca9dSYoshinobu Inoue 
1022cfa1ca9dSYoshinobu Inoue #define	p(f, m) if (pim6stat.f || sflag <= 1) \
10237b95a1ebSYaroslav Tykhiy     printf(m, (uintmax_t)pim6stat.f, plural(pim6stat.f))
10247b95a1ebSYaroslav Tykhiy 	p(pim6s_rcv_total, "\t%ju message%s received\n");
10257b95a1ebSYaroslav Tykhiy 	p(pim6s_rcv_tooshort, "\t%ju message%s received with too few bytes\n");
10267b95a1ebSYaroslav Tykhiy 	p(pim6s_rcv_badsum, "\t%ju message%s received with bad checksum\n");
10277b95a1ebSYaroslav Tykhiy 	p(pim6s_rcv_badversion, "\t%ju message%s received with bad version\n");
10287b95a1ebSYaroslav Tykhiy 	p(pim6s_rcv_registers, "\t%ju register%s received\n");
10297b95a1ebSYaroslav Tykhiy 	p(pim6s_rcv_badregisters, "\t%ju bad register%s received\n");
10307b95a1ebSYaroslav Tykhiy 	p(pim6s_snd_registers, "\t%ju register%s sent\n");
1031cfa1ca9dSYoshinobu Inoue #undef p
1032cfa1ca9dSYoshinobu Inoue }
1033cfa1ca9dSYoshinobu Inoue 
1034cfa1ca9dSYoshinobu Inoue /*
103533841545SHajimu UMEMOTO  * Dump raw ip6 statistics structure.
103633841545SHajimu UMEMOTO  */
103733841545SHajimu UMEMOTO void
1038feda1a43SJohn Baldwin rip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
103933841545SHajimu UMEMOTO {
104033841545SHajimu UMEMOTO 	struct rip6stat rip6stat;
104133841545SHajimu UMEMOTO 	u_quad_t delivered;
1042feda1a43SJohn Baldwin 	size_t len;
104333841545SHajimu UMEMOTO 
1044feda1a43SJohn Baldwin 	len = sizeof(rip6stat);
1045feda1a43SJohn Baldwin 	if (live) {
1046feda1a43SJohn Baldwin 		if (sysctlbyname("net.inet6.ip6.rip6stats", &rip6stat, &len,
1047feda1a43SJohn Baldwin 		    NULL, 0) < 0) {
1048109dad81SJulian Elischer 			if (errno != ENOENT)
1049feda1a43SJohn Baldwin 				warn("sysctl: net.inet6.ip6.rip6stats");
105033841545SHajimu UMEMOTO 			return;
105133841545SHajimu UMEMOTO 		}
1052feda1a43SJohn Baldwin 	} else
1053feda1a43SJohn Baldwin 		kread(off, &rip6stat, len);
105433841545SHajimu UMEMOTO 
105533841545SHajimu UMEMOTO 	printf("%s:\n", name);
105633841545SHajimu UMEMOTO 
105733841545SHajimu UMEMOTO #define	p(f, m) if (rip6stat.f || sflag <= 1) \
10587b95a1ebSYaroslav Tykhiy     printf(m, (uintmax_t)rip6stat.f, plural(rip6stat.f))
10597b95a1ebSYaroslav Tykhiy 	p(rip6s_ipackets, "\t%ju message%s received\n");
1060c0c66013SMaxim Konovalov 	p(rip6s_isum, "\t%ju checksum calculation%s on inbound\n");
10617b95a1ebSYaroslav Tykhiy 	p(rip6s_badsum, "\t%ju message%s with bad checksum\n");
10627b95a1ebSYaroslav Tykhiy 	p(rip6s_nosock, "\t%ju message%s dropped due to no socket\n");
106333841545SHajimu UMEMOTO 	p(rip6s_nosockmcast,
10647b95a1ebSYaroslav Tykhiy 	    "\t%ju multicast message%s dropped due to no socket\n");
106533841545SHajimu UMEMOTO 	p(rip6s_fullsock,
10667b95a1ebSYaroslav Tykhiy 	    "\t%ju message%s dropped due to full socket buffers\n");
106733841545SHajimu UMEMOTO 	delivered = rip6stat.rip6s_ipackets -
106833841545SHajimu UMEMOTO 		    rip6stat.rip6s_badsum -
106933841545SHajimu UMEMOTO 		    rip6stat.rip6s_nosock -
107033841545SHajimu UMEMOTO 		    rip6stat.rip6s_nosockmcast -
107133841545SHajimu UMEMOTO 		    rip6stat.rip6s_fullsock;
107233841545SHajimu UMEMOTO 	if (delivered || sflag <= 1)
10737b95a1ebSYaroslav Tykhiy 		printf("\t%ju delivered\n", (uintmax_t)delivered);
10747b95a1ebSYaroslav Tykhiy 	p(rip6s_opackets, "\t%ju datagram%s output\n");
107533841545SHajimu UMEMOTO #undef p
107633841545SHajimu UMEMOTO }
107733841545SHajimu UMEMOTO 
107833841545SHajimu UMEMOTO /*
1079cfa1ca9dSYoshinobu Inoue  * Pretty print an Internet address (net address + port).
108065ea0024SAssar Westerlund  * Take numeric_addr and numeric_port into consideration.
1081cfa1ca9dSYoshinobu Inoue  */
1082cfa1ca9dSYoshinobu Inoue #define	GETSERVBYPORT6(port, proto, ret)\
1083cfa1ca9dSYoshinobu Inoue {\
1084cfa1ca9dSYoshinobu Inoue 	if (strcmp((proto), "tcp6") == 0)\
1085cfa1ca9dSYoshinobu Inoue 		(ret) = getservbyport((int)(port), "tcp");\
1086cfa1ca9dSYoshinobu Inoue 	else if (strcmp((proto), "udp6") == 0)\
1087cfa1ca9dSYoshinobu Inoue 		(ret) = getservbyport((int)(port), "udp");\
1088cfa1ca9dSYoshinobu Inoue 	else\
1089cfa1ca9dSYoshinobu Inoue 		(ret) = getservbyport((int)(port), (proto));\
1090cfa1ca9dSYoshinobu Inoue };
1091cfa1ca9dSYoshinobu Inoue 
1092cfa1ca9dSYoshinobu Inoue void
1093a01e3379SDavid Malone inet6print(struct in6_addr *in6, int port, const char *proto, int numeric)
1094cfa1ca9dSYoshinobu Inoue {
1095cfa1ca9dSYoshinobu Inoue 	struct servent *sp = 0;
1096cfa1ca9dSYoshinobu Inoue 	char line[80], *cp;
1097cfa1ca9dSYoshinobu Inoue 	int width;
1098cfa1ca9dSYoshinobu Inoue 
109970057abfSRuslan Ermilov 	sprintf(line, "%.*s.", Wflag ? 39 :
1100cfa1ca9dSYoshinobu Inoue 		(Aflag && !numeric) ? 12 : 16, inet6name(in6));
1101cfa1ca9dSYoshinobu Inoue 	cp = index(line, '\0');
1102cfa1ca9dSYoshinobu Inoue 	if (!numeric && port)
1103cfa1ca9dSYoshinobu Inoue 		GETSERVBYPORT6(port, proto, sp);
1104cfa1ca9dSYoshinobu Inoue 	if (sp || port == 0)
1105bd2327cdSHajimu UMEMOTO 		sprintf(cp, "%.15s", sp ? sp->s_name : "*");
1106cfa1ca9dSYoshinobu Inoue 	else
1107cfa1ca9dSYoshinobu Inoue 		sprintf(cp, "%d", ntohs((u_short)port));
110870057abfSRuslan Ermilov 	width = Wflag ? 45 : Aflag ? 18 : 22;
1109cfa1ca9dSYoshinobu Inoue 	printf("%-*.*s ", width, width, line);
1110cfa1ca9dSYoshinobu Inoue }
1111cfa1ca9dSYoshinobu Inoue 
1112cfa1ca9dSYoshinobu Inoue /*
1113cfa1ca9dSYoshinobu Inoue  * Construct an Internet address representation.
111465ea0024SAssar Westerlund  * If the numeric_addr has been supplied, give
1115cfa1ca9dSYoshinobu Inoue  * numeric value, otherwise try for symbolic name.
1116cfa1ca9dSYoshinobu Inoue  */
1117cfa1ca9dSYoshinobu Inoue 
1118cfa1ca9dSYoshinobu Inoue char *
11195e051718SAssar Westerlund inet6name(struct in6_addr *in6p)
1120cfa1ca9dSYoshinobu Inoue {
1121a01e3379SDavid Malone 	char *cp;
1122cfa1ca9dSYoshinobu Inoue 	static char line[50];
1123cfa1ca9dSYoshinobu Inoue 	struct hostent *hp;
1124d121b556SBrian Somers 	static char domain[MAXHOSTNAMELEN];
1125cfa1ca9dSYoshinobu Inoue 	static int first = 1;
1126cfa1ca9dSYoshinobu Inoue 
112765ea0024SAssar Westerlund 	if (first && !numeric_addr) {
1128cfa1ca9dSYoshinobu Inoue 		first = 0;
1129cfa1ca9dSYoshinobu Inoue 		if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
1130cfa1ca9dSYoshinobu Inoue 		    (cp = index(domain, '.')))
1131cfa1ca9dSYoshinobu Inoue 			(void) strcpy(domain, cp + 1);
1132cfa1ca9dSYoshinobu Inoue 		else
1133cfa1ca9dSYoshinobu Inoue 			domain[0] = 0;
1134cfa1ca9dSYoshinobu Inoue 	}
1135cfa1ca9dSYoshinobu Inoue 	cp = 0;
113665ea0024SAssar Westerlund 	if (!numeric_addr && !IN6_IS_ADDR_UNSPECIFIED(in6p)) {
1137cfa1ca9dSYoshinobu Inoue 		hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6);
1138cfa1ca9dSYoshinobu Inoue 		if (hp) {
1139cfa1ca9dSYoshinobu Inoue 			if ((cp = index(hp->h_name, '.')) &&
1140cfa1ca9dSYoshinobu Inoue 			    !strcmp(cp + 1, domain))
1141cfa1ca9dSYoshinobu Inoue 				*cp = 0;
1142cfa1ca9dSYoshinobu Inoue 			cp = hp->h_name;
1143cfa1ca9dSYoshinobu Inoue 		}
1144cfa1ca9dSYoshinobu Inoue 	}
1145cfa1ca9dSYoshinobu Inoue 	if (IN6_IS_ADDR_UNSPECIFIED(in6p))
1146cfa1ca9dSYoshinobu Inoue 		strcpy(line, "*");
1147cfa1ca9dSYoshinobu Inoue 	else if (cp)
1148cfa1ca9dSYoshinobu Inoue 		strcpy(line, cp);
1149cfa1ca9dSYoshinobu Inoue 	else
1150cfa1ca9dSYoshinobu Inoue 		sprintf(line, "%s",
1151cfa1ca9dSYoshinobu Inoue 			inet_ntop(AF_INET6, (void *)in6p, ntop_buf,
1152cfa1ca9dSYoshinobu Inoue 				sizeof(ntop_buf)));
1153cfa1ca9dSYoshinobu Inoue 	return (line);
1154cfa1ca9dSYoshinobu Inoue }
1155d84a1df4SHajimu UMEMOTO #endif /*INET6*/
1156