xref: /freebsd/usr.bin/netstat/inet6.c (revision 5ad497eeada28b33e3fcfec1139652184cfdfc8e)
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  * 4. Neither the name of the University nor the names of its contributors
15cfa1ca9dSYoshinobu Inoue  *    may be used to endorse or promote products derived from this software
16cfa1ca9dSYoshinobu Inoue  *    without specific prior written permission.
17cfa1ca9dSYoshinobu Inoue  *
18cfa1ca9dSYoshinobu Inoue  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19cfa1ca9dSYoshinobu Inoue  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20cfa1ca9dSYoshinobu Inoue  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21cfa1ca9dSYoshinobu Inoue  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22cfa1ca9dSYoshinobu Inoue  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23cfa1ca9dSYoshinobu Inoue  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24cfa1ca9dSYoshinobu Inoue  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25cfa1ca9dSYoshinobu Inoue  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26cfa1ca9dSYoshinobu Inoue  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27cfa1ca9dSYoshinobu Inoue  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28cfa1ca9dSYoshinobu Inoue  * SUCH DAMAGE.
29cfa1ca9dSYoshinobu Inoue  */
30cfa1ca9dSYoshinobu Inoue 
316cc6f122SPhilippe Charnier #if 0
32cfa1ca9dSYoshinobu Inoue #ifndef lint
33cfa1ca9dSYoshinobu Inoue static char sccsid[] = "@(#)inet6.c	8.4 (Berkeley) 4/20/94";
34cfa1ca9dSYoshinobu Inoue #endif /* not lint */
356cc6f122SPhilippe Charnier #endif
366cc6f122SPhilippe Charnier 
376cc6f122SPhilippe Charnier #include <sys/cdefs.h>
386cc6f122SPhilippe Charnier __FBSDID("$FreeBSD$");
39cfa1ca9dSYoshinobu Inoue 
40d84a1df4SHajimu UMEMOTO #ifdef INET6
41cfa1ca9dSYoshinobu Inoue #include <sys/param.h>
42cfa1ca9dSYoshinobu Inoue #include <sys/socket.h>
43cfa1ca9dSYoshinobu Inoue #include <sys/socketvar.h>
44cfa1ca9dSYoshinobu Inoue #include <sys/ioctl.h>
45cfa1ca9dSYoshinobu Inoue #include <sys/mbuf.h>
46cfa1ca9dSYoshinobu Inoue #include <sys/protosw.h>
47cfa1ca9dSYoshinobu Inoue 
48cfa1ca9dSYoshinobu Inoue #include <net/route.h>
49cfa1ca9dSYoshinobu Inoue #include <net/if.h>
50cfa1ca9dSYoshinobu Inoue #include <netinet/in.h>
51cfa1ca9dSYoshinobu Inoue #include <netinet/ip6.h>
52cfa1ca9dSYoshinobu Inoue #include <netinet/icmp6.h>
53cfa1ca9dSYoshinobu Inoue #include <netinet/in_systm.h>
54cfa1ca9dSYoshinobu Inoue #include <netinet6/in6_pcb.h>
55cfa1ca9dSYoshinobu Inoue #include <netinet6/in6_var.h>
56cfa1ca9dSYoshinobu Inoue #include <netinet6/ip6_var.h>
57cfa1ca9dSYoshinobu Inoue #include <netinet6/pim6_var.h>
5833841545SHajimu UMEMOTO #include <netinet6/raw_ip6.h>
59cfa1ca9dSYoshinobu Inoue 
60cfa1ca9dSYoshinobu Inoue #include <arpa/inet.h>
61cfa1ca9dSYoshinobu Inoue #include <netdb.h>
62cfa1ca9dSYoshinobu Inoue 
63c15ddad9SBruce M Simpson #include <err.h>
647b95a1ebSYaroslav Tykhiy #include <stdint.h>
65cfa1ca9dSYoshinobu Inoue #include <stdio.h>
66ade9ccfeSMarcel Moolenaar #include <stdbool.h>
67109dad81SJulian Elischer #include <errno.h>
68cfa1ca9dSYoshinobu Inoue #include <string.h>
69cfa1ca9dSYoshinobu Inoue #include <unistd.h>
70ade9ccfeSMarcel Moolenaar #include <libxo/xo.h>
71cfa1ca9dSYoshinobu Inoue #include "netstat.h"
72cfa1ca9dSYoshinobu Inoue 
735e051718SAssar Westerlund char	*inet6name(struct in6_addr *);
74cfa1ca9dSYoshinobu Inoue 
75cfa1ca9dSYoshinobu Inoue static char ntop_buf[INET6_ADDRSTRLEN];
76cfa1ca9dSYoshinobu Inoue 
77a01e3379SDavid Malone static	const char *ip6nh[] = {
78cfa1ca9dSYoshinobu Inoue 	"hop by hop",
79cfa1ca9dSYoshinobu Inoue 	"ICMP",
80cfa1ca9dSYoshinobu Inoue 	"IGMP",
81cfa1ca9dSYoshinobu Inoue 	"#3",
82cfa1ca9dSYoshinobu Inoue 	"IP",
83cfa1ca9dSYoshinobu Inoue 	"#5",
84cfa1ca9dSYoshinobu Inoue 	"TCP",
85cfa1ca9dSYoshinobu Inoue 	"#7",
86cfa1ca9dSYoshinobu Inoue 	"#8",
87cfa1ca9dSYoshinobu Inoue 	"#9",
88cfa1ca9dSYoshinobu Inoue 	"#10",
89cfa1ca9dSYoshinobu Inoue 	"#11",
90cfa1ca9dSYoshinobu Inoue 	"#12",
91cfa1ca9dSYoshinobu Inoue 	"#13",
92cfa1ca9dSYoshinobu Inoue 	"#14",
93cfa1ca9dSYoshinobu Inoue 	"#15",
94cfa1ca9dSYoshinobu Inoue 	"#16",
95cfa1ca9dSYoshinobu Inoue 	"UDP",
96cfa1ca9dSYoshinobu Inoue 	"#18",
97cfa1ca9dSYoshinobu Inoue 	"#19",
98cfa1ca9dSYoshinobu Inoue 	"#20",
99cfa1ca9dSYoshinobu Inoue 	"#21",
100cfa1ca9dSYoshinobu Inoue 	"IDP",
101cfa1ca9dSYoshinobu Inoue 	"#23",
102cfa1ca9dSYoshinobu Inoue 	"#24",
103cfa1ca9dSYoshinobu Inoue 	"#25",
104cfa1ca9dSYoshinobu Inoue 	"#26",
105cfa1ca9dSYoshinobu Inoue 	"#27",
106cfa1ca9dSYoshinobu Inoue 	"#28",
107cfa1ca9dSYoshinobu Inoue 	"TP",
108cfa1ca9dSYoshinobu Inoue 	"#30",
109cfa1ca9dSYoshinobu Inoue 	"#31",
110cfa1ca9dSYoshinobu Inoue 	"#32",
111cfa1ca9dSYoshinobu Inoue 	"#33",
112cfa1ca9dSYoshinobu Inoue 	"#34",
113cfa1ca9dSYoshinobu Inoue 	"#35",
114cfa1ca9dSYoshinobu Inoue 	"#36",
115cfa1ca9dSYoshinobu Inoue 	"#37",
116cfa1ca9dSYoshinobu Inoue 	"#38",
117cfa1ca9dSYoshinobu Inoue 	"#39",
118cfa1ca9dSYoshinobu Inoue 	"#40",
119cfa1ca9dSYoshinobu Inoue 	"IP6",
120cfa1ca9dSYoshinobu Inoue 	"#42",
121cfa1ca9dSYoshinobu Inoue 	"routing",
122cfa1ca9dSYoshinobu Inoue 	"fragment",
123cfa1ca9dSYoshinobu Inoue 	"#45",
124cfa1ca9dSYoshinobu Inoue 	"#46",
125cfa1ca9dSYoshinobu Inoue 	"#47",
126cfa1ca9dSYoshinobu Inoue 	"#48",
127cfa1ca9dSYoshinobu Inoue 	"#49",
128cfa1ca9dSYoshinobu Inoue 	"ESP",
129cfa1ca9dSYoshinobu Inoue 	"AH",
130cfa1ca9dSYoshinobu Inoue 	"#52",
131cfa1ca9dSYoshinobu Inoue 	"#53",
132cfa1ca9dSYoshinobu Inoue 	"#54",
133cfa1ca9dSYoshinobu Inoue 	"#55",
134cfa1ca9dSYoshinobu Inoue 	"#56",
135cfa1ca9dSYoshinobu Inoue 	"#57",
136cfa1ca9dSYoshinobu Inoue 	"ICMP6",
137cfa1ca9dSYoshinobu Inoue 	"no next header",
138cfa1ca9dSYoshinobu Inoue 	"destination option",
139cfa1ca9dSYoshinobu Inoue 	"#61",
140cb60a8deSHajimu UMEMOTO 	"mobility",
141cfa1ca9dSYoshinobu Inoue 	"#63",
142cfa1ca9dSYoshinobu Inoue 	"#64",
143cfa1ca9dSYoshinobu Inoue 	"#65",
144cfa1ca9dSYoshinobu Inoue 	"#66",
145cfa1ca9dSYoshinobu Inoue 	"#67",
146cfa1ca9dSYoshinobu Inoue 	"#68",
147cfa1ca9dSYoshinobu Inoue 	"#69",
148cfa1ca9dSYoshinobu Inoue 	"#70",
149cfa1ca9dSYoshinobu Inoue 	"#71",
150cfa1ca9dSYoshinobu Inoue 	"#72",
151cfa1ca9dSYoshinobu Inoue 	"#73",
152cfa1ca9dSYoshinobu Inoue 	"#74",
153cfa1ca9dSYoshinobu Inoue 	"#75",
154cfa1ca9dSYoshinobu Inoue 	"#76",
155cfa1ca9dSYoshinobu Inoue 	"#77",
156cfa1ca9dSYoshinobu Inoue 	"#78",
157cfa1ca9dSYoshinobu Inoue 	"#79",
158cfa1ca9dSYoshinobu Inoue 	"ISOIP",
159cfa1ca9dSYoshinobu Inoue 	"#81",
160cfa1ca9dSYoshinobu Inoue 	"#82",
161cfa1ca9dSYoshinobu Inoue 	"#83",
162cfa1ca9dSYoshinobu Inoue 	"#84",
163cfa1ca9dSYoshinobu Inoue 	"#85",
164cfa1ca9dSYoshinobu Inoue 	"#86",
165cfa1ca9dSYoshinobu Inoue 	"#87",
166cfa1ca9dSYoshinobu Inoue 	"#88",
16732cd1d96SJun-ichiro itojun Hagino 	"OSPF",
168cfa1ca9dSYoshinobu Inoue 	"#80",
169cfa1ca9dSYoshinobu Inoue 	"#91",
170cfa1ca9dSYoshinobu Inoue 	"#92",
171cfa1ca9dSYoshinobu Inoue 	"#93",
172cfa1ca9dSYoshinobu Inoue 	"#94",
173cfa1ca9dSYoshinobu Inoue 	"#95",
174cfa1ca9dSYoshinobu Inoue 	"#96",
175cfa1ca9dSYoshinobu Inoue 	"Ethernet",
176cfa1ca9dSYoshinobu Inoue 	"#98",
177cfa1ca9dSYoshinobu Inoue 	"#99",
178cfa1ca9dSYoshinobu Inoue 	"#100",
179cfa1ca9dSYoshinobu Inoue 	"#101",
180cfa1ca9dSYoshinobu Inoue 	"#102",
181cfa1ca9dSYoshinobu Inoue 	"PIM",
182cfa1ca9dSYoshinobu Inoue 	"#104",
183cfa1ca9dSYoshinobu Inoue 	"#105",
184cfa1ca9dSYoshinobu Inoue 	"#106",
185cfa1ca9dSYoshinobu Inoue 	"#107",
186cfa1ca9dSYoshinobu Inoue 	"#108",
187cfa1ca9dSYoshinobu Inoue 	"#109",
188cfa1ca9dSYoshinobu Inoue 	"#110",
189cfa1ca9dSYoshinobu Inoue 	"#111",
190cfa1ca9dSYoshinobu Inoue 	"#112",
191cfa1ca9dSYoshinobu Inoue 	"#113",
192cfa1ca9dSYoshinobu Inoue 	"#114",
193cfa1ca9dSYoshinobu Inoue 	"#115",
194cfa1ca9dSYoshinobu Inoue 	"#116",
195cfa1ca9dSYoshinobu Inoue 	"#117",
196cfa1ca9dSYoshinobu Inoue 	"#118",
197cfa1ca9dSYoshinobu Inoue 	"#119",
198cfa1ca9dSYoshinobu Inoue 	"#120",
199cfa1ca9dSYoshinobu Inoue 	"#121",
200cfa1ca9dSYoshinobu Inoue 	"#122",
201cfa1ca9dSYoshinobu Inoue 	"#123",
202cfa1ca9dSYoshinobu Inoue 	"#124",
203cfa1ca9dSYoshinobu Inoue 	"#125",
204cfa1ca9dSYoshinobu Inoue 	"#126",
205cfa1ca9dSYoshinobu Inoue 	"#127",
206cfa1ca9dSYoshinobu Inoue 	"#128",
207cfa1ca9dSYoshinobu Inoue 	"#129",
208cfa1ca9dSYoshinobu Inoue 	"#130",
209cfa1ca9dSYoshinobu Inoue 	"#131",
210e0694d2fSMichael Tuexen 	"SCTP",
211cfa1ca9dSYoshinobu Inoue 	"#133",
212cfa1ca9dSYoshinobu Inoue 	"#134",
213cfa1ca9dSYoshinobu Inoue 	"#135",
214e0694d2fSMichael Tuexen 	"UDPLite",
215cfa1ca9dSYoshinobu Inoue 	"#137",
216cfa1ca9dSYoshinobu Inoue 	"#138",
217cfa1ca9dSYoshinobu Inoue 	"#139",
218cfa1ca9dSYoshinobu Inoue 	"#140",
219cfa1ca9dSYoshinobu Inoue 	"#141",
220cfa1ca9dSYoshinobu Inoue 	"#142",
221cfa1ca9dSYoshinobu Inoue 	"#143",
222cfa1ca9dSYoshinobu Inoue 	"#144",
223cfa1ca9dSYoshinobu Inoue 	"#145",
224cfa1ca9dSYoshinobu Inoue 	"#146",
225cfa1ca9dSYoshinobu Inoue 	"#147",
226cfa1ca9dSYoshinobu Inoue 	"#148",
227cfa1ca9dSYoshinobu Inoue 	"#149",
228cfa1ca9dSYoshinobu Inoue 	"#150",
229cfa1ca9dSYoshinobu Inoue 	"#151",
230cfa1ca9dSYoshinobu Inoue 	"#152",
231cfa1ca9dSYoshinobu Inoue 	"#153",
232cfa1ca9dSYoshinobu Inoue 	"#154",
233cfa1ca9dSYoshinobu Inoue 	"#155",
234cfa1ca9dSYoshinobu Inoue 	"#156",
235cfa1ca9dSYoshinobu Inoue 	"#157",
236cfa1ca9dSYoshinobu Inoue 	"#158",
237cfa1ca9dSYoshinobu Inoue 	"#159",
238cfa1ca9dSYoshinobu Inoue 	"#160",
239cfa1ca9dSYoshinobu Inoue 	"#161",
240cfa1ca9dSYoshinobu Inoue 	"#162",
241cfa1ca9dSYoshinobu Inoue 	"#163",
242cfa1ca9dSYoshinobu Inoue 	"#164",
243cfa1ca9dSYoshinobu Inoue 	"#165",
244cfa1ca9dSYoshinobu Inoue 	"#166",
245cfa1ca9dSYoshinobu Inoue 	"#167",
246cfa1ca9dSYoshinobu Inoue 	"#168",
247cfa1ca9dSYoshinobu Inoue 	"#169",
248cfa1ca9dSYoshinobu Inoue 	"#170",
249cfa1ca9dSYoshinobu Inoue 	"#171",
250cfa1ca9dSYoshinobu Inoue 	"#172",
251cfa1ca9dSYoshinobu Inoue 	"#173",
252cfa1ca9dSYoshinobu Inoue 	"#174",
253cfa1ca9dSYoshinobu Inoue 	"#175",
254cfa1ca9dSYoshinobu Inoue 	"#176",
255cfa1ca9dSYoshinobu Inoue 	"#177",
256cfa1ca9dSYoshinobu Inoue 	"#178",
257cfa1ca9dSYoshinobu Inoue 	"#179",
258cfa1ca9dSYoshinobu Inoue 	"#180",
259cfa1ca9dSYoshinobu Inoue 	"#181",
260cfa1ca9dSYoshinobu Inoue 	"#182",
261cfa1ca9dSYoshinobu Inoue 	"#183",
262cfa1ca9dSYoshinobu Inoue 	"#184",
263cfa1ca9dSYoshinobu Inoue 	"#185",
264cfa1ca9dSYoshinobu Inoue 	"#186",
265cfa1ca9dSYoshinobu Inoue 	"#187",
266cfa1ca9dSYoshinobu Inoue 	"#188",
267cfa1ca9dSYoshinobu Inoue 	"#189",
268cfa1ca9dSYoshinobu Inoue 	"#180",
269cfa1ca9dSYoshinobu Inoue 	"#191",
270cfa1ca9dSYoshinobu Inoue 	"#192",
271cfa1ca9dSYoshinobu Inoue 	"#193",
272cfa1ca9dSYoshinobu Inoue 	"#194",
273cfa1ca9dSYoshinobu Inoue 	"#195",
274cfa1ca9dSYoshinobu Inoue 	"#196",
275cfa1ca9dSYoshinobu Inoue 	"#197",
276cfa1ca9dSYoshinobu Inoue 	"#198",
277cfa1ca9dSYoshinobu Inoue 	"#199",
278cfa1ca9dSYoshinobu Inoue 	"#200",
279cfa1ca9dSYoshinobu Inoue 	"#201",
280cfa1ca9dSYoshinobu Inoue 	"#202",
281cfa1ca9dSYoshinobu Inoue 	"#203",
282cfa1ca9dSYoshinobu Inoue 	"#204",
283cfa1ca9dSYoshinobu Inoue 	"#205",
284cfa1ca9dSYoshinobu Inoue 	"#206",
285cfa1ca9dSYoshinobu Inoue 	"#207",
286cfa1ca9dSYoshinobu Inoue 	"#208",
287cfa1ca9dSYoshinobu Inoue 	"#209",
288cfa1ca9dSYoshinobu Inoue 	"#210",
289cfa1ca9dSYoshinobu Inoue 	"#211",
290cfa1ca9dSYoshinobu Inoue 	"#212",
291cfa1ca9dSYoshinobu Inoue 	"#213",
292cfa1ca9dSYoshinobu Inoue 	"#214",
293cfa1ca9dSYoshinobu Inoue 	"#215",
294cfa1ca9dSYoshinobu Inoue 	"#216",
295cfa1ca9dSYoshinobu Inoue 	"#217",
296cfa1ca9dSYoshinobu Inoue 	"#218",
297cfa1ca9dSYoshinobu Inoue 	"#219",
298cfa1ca9dSYoshinobu Inoue 	"#220",
299cfa1ca9dSYoshinobu Inoue 	"#221",
300cfa1ca9dSYoshinobu Inoue 	"#222",
301cfa1ca9dSYoshinobu Inoue 	"#223",
302cfa1ca9dSYoshinobu Inoue 	"#224",
303cfa1ca9dSYoshinobu Inoue 	"#225",
304cfa1ca9dSYoshinobu Inoue 	"#226",
305cfa1ca9dSYoshinobu Inoue 	"#227",
306cfa1ca9dSYoshinobu Inoue 	"#228",
307cfa1ca9dSYoshinobu Inoue 	"#229",
308cfa1ca9dSYoshinobu Inoue 	"#230",
309cfa1ca9dSYoshinobu Inoue 	"#231",
310cfa1ca9dSYoshinobu Inoue 	"#232",
311cfa1ca9dSYoshinobu Inoue 	"#233",
312cfa1ca9dSYoshinobu Inoue 	"#234",
313cfa1ca9dSYoshinobu Inoue 	"#235",
314cfa1ca9dSYoshinobu Inoue 	"#236",
315cfa1ca9dSYoshinobu Inoue 	"#237",
316cfa1ca9dSYoshinobu Inoue 	"#238",
317cfa1ca9dSYoshinobu Inoue 	"#239",
318cfa1ca9dSYoshinobu Inoue 	"#240",
319cfa1ca9dSYoshinobu Inoue 	"#241",
320cfa1ca9dSYoshinobu Inoue 	"#242",
321cfa1ca9dSYoshinobu Inoue 	"#243",
322cfa1ca9dSYoshinobu Inoue 	"#244",
323cfa1ca9dSYoshinobu Inoue 	"#245",
324cfa1ca9dSYoshinobu Inoue 	"#246",
325cfa1ca9dSYoshinobu Inoue 	"#247",
326cfa1ca9dSYoshinobu Inoue 	"#248",
327cfa1ca9dSYoshinobu Inoue 	"#249",
328cfa1ca9dSYoshinobu Inoue 	"#250",
329cfa1ca9dSYoshinobu Inoue 	"#251",
330cfa1ca9dSYoshinobu Inoue 	"#252",
331cfa1ca9dSYoshinobu Inoue 	"#253",
332cfa1ca9dSYoshinobu Inoue 	"#254",
333cfa1ca9dSYoshinobu Inoue 	"#255",
334cfa1ca9dSYoshinobu Inoue };
335cfa1ca9dSYoshinobu Inoue 
336321ae07fSPhilippe Charnier static const char *srcrule_str[] = {
3374ef2dc8bSHajimu UMEMOTO 	"first candidate",
3384ef2dc8bSHajimu UMEMOTO 	"same address",
3394ef2dc8bSHajimu UMEMOTO 	"appropriate scope",
3404ef2dc8bSHajimu UMEMOTO 	"deprecated address",
3414ef2dc8bSHajimu UMEMOTO 	"home address",
3424ef2dc8bSHajimu UMEMOTO 	"outgoing interface",
3434ef2dc8bSHajimu UMEMOTO 	"matching label",
3444ef2dc8bSHajimu UMEMOTO 	"public/temporary address",
3454ef2dc8bSHajimu UMEMOTO 	"alive interface",
346ccc53de9SAndrey V. Elsukov 	"better virtual status",
3475dbfa43fSAndrey V. Elsukov 	"preferred source",
3484ef2dc8bSHajimu UMEMOTO 	"rule #11",
3494ef2dc8bSHajimu UMEMOTO 	"rule #12",
3504ef2dc8bSHajimu UMEMOTO 	"rule #13",
3514ef2dc8bSHajimu UMEMOTO 	"longest match",
3524ef2dc8bSHajimu UMEMOTO 	"rule #15",
3534ef2dc8bSHajimu UMEMOTO };
3544ef2dc8bSHajimu UMEMOTO 
355cfa1ca9dSYoshinobu Inoue /*
356cfa1ca9dSYoshinobu Inoue  * Dump IP6 statistics structure.
357cfa1ca9dSYoshinobu Inoue  */
358cfa1ca9dSYoshinobu Inoue void
359feda1a43SJohn Baldwin ip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
360cfa1ca9dSYoshinobu Inoue {
3619eddb899SMark Johnston 	struct ip6stat ip6stat;
362cfa1ca9dSYoshinobu Inoue 	int first, i;
363cfa1ca9dSYoshinobu Inoue 
3649eddb899SMark Johnston 	if (fetch_stats("net.inet6.ip6.stats", off, &ip6stat,
3659eddb899SMark Johnston 	    sizeof(ip6stat), kread_counters) != 0)
3666eec3af9SPoul-Henning Kamp 		return;
3679eddb899SMark Johnston 
368ade9ccfeSMarcel Moolenaar 	xo_open_container(name);
369ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
370cfa1ca9dSYoshinobu Inoue 
371cfa1ca9dSYoshinobu Inoue #define	p(f, m) if (ip6stat.f || sflag <= 1) \
372ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)ip6stat.f, plural(ip6stat.f))
373cfa1ca9dSYoshinobu Inoue #define	p1a(f, m) if (ip6stat.f || sflag <= 1) \
374ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)ip6stat.f)
375cfa1ca9dSYoshinobu Inoue 
376ade9ccfeSMarcel Moolenaar 	p(ip6s_total, "\t{:received-packets/%ju} "
377ade9ccfeSMarcel Moolenaar 	    "{N:/total packet%s received}\n");
378ade9ccfeSMarcel Moolenaar 	p1a(ip6s_toosmall, "\t{:dropped-below-minimum-size/%ju} "
379ade9ccfeSMarcel Moolenaar 	    "{N:/with size smaller than minimum}\n");
380ade9ccfeSMarcel Moolenaar 	p1a(ip6s_tooshort, "\t{:dropped-short-packets/%ju} "
381ade9ccfeSMarcel Moolenaar 	    "{N:/with data size < data length}\n");
382ade9ccfeSMarcel Moolenaar 	p1a(ip6s_badoptions, "\t{:dropped-bad-options/%ju} "
383ade9ccfeSMarcel Moolenaar 	    "{N:/with bad options}\n");
384ade9ccfeSMarcel Moolenaar 	p1a(ip6s_badvers, "\t{:dropped-bad-version/%ju} "
385ade9ccfeSMarcel Moolenaar 	    "{N:/with incorrect version number}\n");
386ade9ccfeSMarcel Moolenaar 	p(ip6s_fragments, "\t{:received-fragments/%ju} "
387ade9ccfeSMarcel Moolenaar 	    "{N:/fragment%s received}\n");
388ade9ccfeSMarcel Moolenaar 	p(ip6s_fragdropped, "\t{:dropped-fragment/%ju} "
389ade9ccfeSMarcel Moolenaar 	    "{N:/fragment%s dropped (dup or out of space)}\n");
390ade9ccfeSMarcel Moolenaar 	p(ip6s_fragtimeout, "\t{:dropped-fragment-after-timeout/%ju} "
391ade9ccfeSMarcel Moolenaar 	    "{N:/fragment%s dropped after timeout}\n");
392ade9ccfeSMarcel Moolenaar 	p(ip6s_fragoverflow, "\t{:dropped-fragments-overflow/%ju} "
393ade9ccfeSMarcel Moolenaar 	    "{N:/fragment%s that exceeded limit}\n");
394ade9ccfeSMarcel Moolenaar 	p(ip6s_reassembled, "\t{:reassembled-packets/%ju} "
395ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s reassembled ok}\n");
396ade9ccfeSMarcel Moolenaar 	p(ip6s_delivered, "\t{:received-local-packets/%ju} "
397ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s for this host}\n");
398ade9ccfeSMarcel Moolenaar 	p(ip6s_forward, "\t{:forwarded-packets/%ju} "
399ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s forwarded}\n");
400ade9ccfeSMarcel Moolenaar 	p(ip6s_cantforward, "\t{:packets-not-forwardable/%ju} "
401ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s not forwardable}\n");
402ade9ccfeSMarcel Moolenaar 	p(ip6s_redirectsent, "\t{:sent-redirects/%ju} "
403ade9ccfeSMarcel Moolenaar 	    "{N:/redirect%s sent}\n");
404ade9ccfeSMarcel Moolenaar 	p(ip6s_localout, "\t{:sent-packets/%ju} "
405ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s sent from this host}\n");
406ade9ccfeSMarcel Moolenaar 	p(ip6s_rawout, "\t{:send-packets-fabricated-header/%ju} "
407ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s sent with fabricated ip header}\n");
408ade9ccfeSMarcel Moolenaar 	p(ip6s_odropped, "\t{:discard-no-mbufs/%ju} "
409ade9ccfeSMarcel Moolenaar 	    "{N:/output packet%s dropped due to no bufs, etc.}\n");
410ade9ccfeSMarcel Moolenaar 	p(ip6s_noroute, "\t{:discard-no-route/%ju} "
411ade9ccfeSMarcel Moolenaar 	    "{N:/output packet%s discarded due to no route}\n");
412ade9ccfeSMarcel Moolenaar 	p(ip6s_fragmented, "\t{:sent-fragments/%ju} "
413ade9ccfeSMarcel Moolenaar 	    "{N:/output datagram%s fragmented}\n");
414ade9ccfeSMarcel Moolenaar 	p(ip6s_ofragments, "\t{:fragments-created/%ju} "
415ade9ccfeSMarcel Moolenaar 	    "{N:/fragment%s created}\n");
416ade9ccfeSMarcel Moolenaar 	p(ip6s_cantfrag, "\t{:discard-cannot-fragment/%ju} "
417ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s that can't be fragmented}\n");
418ade9ccfeSMarcel Moolenaar 	p(ip6s_badscope, "\t{:discard-scope-violations/%ju} "
419ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s that violated scope rules}\n");
420ade9ccfeSMarcel Moolenaar 	p(ip6s_notmember, "\t{:multicast-no-join-packets/%ju} "
421ade9ccfeSMarcel Moolenaar 	    "{N:/multicast packet%s which we don't join}\n");
422b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_HDRCNT; i++)
423cfa1ca9dSYoshinobu Inoue 		if (ip6stat.ip6s_nxthist[i] != 0) {
424cfa1ca9dSYoshinobu Inoue 			if (first) {
425ade9ccfeSMarcel Moolenaar 				xo_emit("\t{T:Input histogram}:\n");
426ade9ccfeSMarcel Moolenaar 				xo_open_list("input-histogram");
427cfa1ca9dSYoshinobu Inoue 				first = 0;
428cfa1ca9dSYoshinobu Inoue 			}
429ade9ccfeSMarcel Moolenaar 			xo_open_instance("input-histogram");
430ade9ccfeSMarcel Moolenaar 			xo_emit("\t\t{k:name/%s}: {:count/%ju}\n", ip6nh[i],
4317b95a1ebSYaroslav Tykhiy 			    (uintmax_t)ip6stat.ip6s_nxthist[i]);
432ade9ccfeSMarcel Moolenaar 			xo_close_instance("input-histogram");
433cfa1ca9dSYoshinobu Inoue 		}
434ade9ccfeSMarcel Moolenaar 	if (!first)
435ade9ccfeSMarcel Moolenaar 		xo_close_list("input-histogram");
436ade9ccfeSMarcel Moolenaar 
437ade9ccfeSMarcel Moolenaar 	xo_open_container("mbuf-statistics");
438ade9ccfeSMarcel Moolenaar 	xo_emit("\t{T:Mbuf statistics}:\n");
439ade9ccfeSMarcel Moolenaar 	xo_emit("\t\t{:one-mbuf/%ju} {N:/one mbuf}\n",
440ade9ccfeSMarcel Moolenaar 	    (uintmax_t)ip6stat.ip6s_m1);
441b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_M2MMAX; i++) {
4427d56d374SYoshinobu Inoue 		char ifbuf[IFNAMSIZ];
443cfa1ca9dSYoshinobu Inoue 		if (ip6stat.ip6s_m2m[i] != 0) {
444cfa1ca9dSYoshinobu Inoue 			if (first) {
445ade9ccfeSMarcel Moolenaar 				xo_emit("\t\t{N:two or more mbuf}:\n");
446ade9ccfeSMarcel Moolenaar 				xo_open_list("mbuf-data");
447cfa1ca9dSYoshinobu Inoue 				first = 0;
448cfa1ca9dSYoshinobu Inoue 			}
449ade9ccfeSMarcel Moolenaar 			xo_open_instance("mbuf-data");
450ade9ccfeSMarcel Moolenaar 			xo_emit("\t\t\t{k:name/%s}= {:count/%ju}\n",
451cfa1ca9dSYoshinobu Inoue 			    if_indextoname(i, ifbuf),
4527b95a1ebSYaroslav Tykhiy 			    (uintmax_t)ip6stat.ip6s_m2m[i]);
453ade9ccfeSMarcel Moolenaar 			xo_close_instance("mbuf-data");
454cfa1ca9dSYoshinobu Inoue 		}
455cfa1ca9dSYoshinobu Inoue 	}
456ade9ccfeSMarcel Moolenaar 	if (!first)
457ade9ccfeSMarcel Moolenaar 		xo_close_list("mbuf-data");
458ade9ccfeSMarcel Moolenaar 	xo_emit("\t\t{:one-extra-mbuf/%ju} {N:one ext mbuf}\n",
4597b95a1ebSYaroslav Tykhiy 	    (uintmax_t)ip6stat.ip6s_mext1);
460ade9ccfeSMarcel Moolenaar 	xo_emit("\t\t{:two-or-more-extra-mbufs/%ju} "
461ade9ccfeSMarcel Moolenaar 	    "{N:/two or more ext mbuf}\n", (uintmax_t)ip6stat.ip6s_mext2m);
462ade9ccfeSMarcel Moolenaar 	xo_close_container("mbuf-statistics");
463ade9ccfeSMarcel Moolenaar 
464ade9ccfeSMarcel Moolenaar 	p(ip6s_exthdrtoolong, "\t{:dropped-header-too-long/%ju} "
465ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s whose headers are not contiguous}\n");
466ade9ccfeSMarcel Moolenaar 	p(ip6s_nogif, "\t{:discard-tunnel-no-gif/%ju} "
467ade9ccfeSMarcel Moolenaar 	    "{N:/tunneling packet%s that can't find gif}\n");
468ade9ccfeSMarcel Moolenaar 	p(ip6s_toomanyhdr, "\t{:dropped-too-many-headers/%ju} "
469ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s discarded because of too many headers}\n");
47032cd1d96SJun-ichiro itojun Hagino 
47132cd1d96SJun-ichiro itojun Hagino 	/* for debugging source address selection */
47232cd1d96SJun-ichiro itojun Hagino #define	PRINT_SCOPESTAT(s,i) do {\
47332cd1d96SJun-ichiro itojun Hagino 		switch(i) { /* XXX hardcoding in each case */\
47432cd1d96SJun-ichiro itojun Hagino 		case 1:\
475ade9ccfeSMarcel Moolenaar 			p(s, "\t\t{ke:name/interface-locals}{:count/%ju} " \
476ade9ccfeSMarcel Moolenaar 			  "{N:/interface-local%s}\n");	\
47732cd1d96SJun-ichiro itojun Hagino 			break;\
47832cd1d96SJun-ichiro itojun Hagino 		case 2:\
479ade9ccfeSMarcel Moolenaar 			p(s,"\t\t{ke:name/link-locals}{:count/%ju} " \
480ade9ccfeSMarcel Moolenaar 			"{N:/link-local%s}\n"); \
48132cd1d96SJun-ichiro itojun Hagino 			break;\
48232cd1d96SJun-ichiro itojun Hagino 		case 5:\
483ade9ccfeSMarcel Moolenaar 			p(s,"\t\t{ke:name/site-locals}{:count/%ju} " \
484ade9ccfeSMarcel Moolenaar 			  "{N:/site-local%s}\n");\
48532cd1d96SJun-ichiro itojun Hagino 			break;\
48632cd1d96SJun-ichiro itojun Hagino 		case 14:\
487ade9ccfeSMarcel Moolenaar 			p(s,"\t\t{ke:name/globals}{:count/%ju} " \
488ade9ccfeSMarcel Moolenaar 			  "{N:/global%s}\n");\
48932cd1d96SJun-ichiro itojun Hagino 			break;\
49032cd1d96SJun-ichiro itojun Hagino 		default:\
491*5ad497eeSMichael Tuexen 			xo_emit("\t\t{qke:name/%#x}{:count/%ju} " \
492*5ad497eeSMichael Tuexen 				"{N:/addresses scope=%#x}\n",\
493ade9ccfeSMarcel Moolenaar 				i, (uintmax_t)ip6stat.s, i);	   \
49432cd1d96SJun-ichiro itojun Hagino 		}\
49532cd1d96SJun-ichiro itojun Hagino 	} while (0);
49632cd1d96SJun-ichiro itojun Hagino 
497ade9ccfeSMarcel Moolenaar 	xo_open_container("source-address-selection");
498ade9ccfeSMarcel Moolenaar 	p(ip6s_sources_none, "\t{:address-selection-failures/%ju} "
499ade9ccfeSMarcel Moolenaar 	    "{N:/failure%s of source address selection}\n");
500ade9ccfeSMarcel Moolenaar 
501b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
50232cd1d96SJun-ichiro itojun Hagino 		if (ip6stat.ip6s_sources_sameif[i]) {
50332cd1d96SJun-ichiro itojun Hagino 			if (first) {
504ade9ccfeSMarcel Moolenaar 				xo_open_list("outgoing-interface");
505ade9ccfeSMarcel Moolenaar 				xo_emit("\tsource addresses on an outgoing "
506ade9ccfeSMarcel Moolenaar 				    "I/F\n");
50732cd1d96SJun-ichiro itojun Hagino 				first = 0;
50832cd1d96SJun-ichiro itojun Hagino 			}
509ade9ccfeSMarcel Moolenaar 			xo_open_instance("outgoing-interface");
51032cd1d96SJun-ichiro itojun Hagino 			PRINT_SCOPESTAT(ip6s_sources_sameif[i], i);
511ade9ccfeSMarcel Moolenaar 			xo_close_instance("outgoing-interface");
51232cd1d96SJun-ichiro itojun Hagino 		}
51332cd1d96SJun-ichiro itojun Hagino 	}
514ade9ccfeSMarcel Moolenaar 	if (!first)
515ade9ccfeSMarcel Moolenaar 		xo_close_list("outgoing-interface");
516ade9ccfeSMarcel Moolenaar 
517b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
51832cd1d96SJun-ichiro itojun Hagino 		if (ip6stat.ip6s_sources_otherif[i]) {
51932cd1d96SJun-ichiro itojun Hagino 			if (first) {
520ade9ccfeSMarcel Moolenaar 				xo_open_list("non-outgoing-interface");
521ade9ccfeSMarcel Moolenaar 				xo_emit("\tsource addresses on a non-outgoing "
522ade9ccfeSMarcel Moolenaar 				    "I/F\n");
52332cd1d96SJun-ichiro itojun Hagino 				first = 0;
52432cd1d96SJun-ichiro itojun Hagino 			}
525ade9ccfeSMarcel Moolenaar 			xo_open_instance("non-outgoing-interface");
52632cd1d96SJun-ichiro itojun Hagino 			PRINT_SCOPESTAT(ip6s_sources_otherif[i], i);
527ade9ccfeSMarcel Moolenaar 			xo_close_instance("non-outgoing-interface");
52832cd1d96SJun-ichiro itojun Hagino 		}
52932cd1d96SJun-ichiro itojun Hagino 	}
530ade9ccfeSMarcel Moolenaar 	if (!first)
531ade9ccfeSMarcel Moolenaar 		xo_close_list("non-outgoing-interface");
532ade9ccfeSMarcel Moolenaar 
533b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
53432cd1d96SJun-ichiro itojun Hagino 		if (ip6stat.ip6s_sources_samescope[i]) {
53532cd1d96SJun-ichiro itojun Hagino 			if (first) {
536ade9ccfeSMarcel Moolenaar 				xo_open_list("same-source");
537ade9ccfeSMarcel Moolenaar 				xo_emit("\tsource addresses of same scope\n");
53832cd1d96SJun-ichiro itojun Hagino 				first = 0;
53932cd1d96SJun-ichiro itojun Hagino 			}
540ade9ccfeSMarcel Moolenaar 			xo_open_instance("same-source");
54132cd1d96SJun-ichiro itojun Hagino 			PRINT_SCOPESTAT(ip6s_sources_samescope[i], i);
542ade9ccfeSMarcel Moolenaar 			xo_close_instance("same-source");
54332cd1d96SJun-ichiro itojun Hagino 		}
54432cd1d96SJun-ichiro itojun Hagino 	}
545ade9ccfeSMarcel Moolenaar 	if (!first)
546ade9ccfeSMarcel Moolenaar 		xo_close_list("same-source");
547ade9ccfeSMarcel Moolenaar 
548b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
54932cd1d96SJun-ichiro itojun Hagino 		if (ip6stat.ip6s_sources_otherscope[i]) {
55032cd1d96SJun-ichiro itojun Hagino 			if (first) {
551ade9ccfeSMarcel Moolenaar 				xo_open_list("different-scope");
552ade9ccfeSMarcel Moolenaar 				xo_emit("\tsource addresses of a different "
553ade9ccfeSMarcel Moolenaar 				    "scope\n");
55432cd1d96SJun-ichiro itojun Hagino 				first = 0;
55532cd1d96SJun-ichiro itojun Hagino 			}
556ade9ccfeSMarcel Moolenaar 			xo_open_instance("different-scope");
55732cd1d96SJun-ichiro itojun Hagino 			PRINT_SCOPESTAT(ip6s_sources_otherscope[i], i);
558ade9ccfeSMarcel Moolenaar 			xo_close_instance("different-scope");
55932cd1d96SJun-ichiro itojun Hagino 		}
56032cd1d96SJun-ichiro itojun Hagino 	}
561ade9ccfeSMarcel Moolenaar 	if (!first)
562ade9ccfeSMarcel Moolenaar 		xo_close_list("different-scope");
563ade9ccfeSMarcel Moolenaar 
564b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
56532cd1d96SJun-ichiro itojun Hagino 		if (ip6stat.ip6s_sources_deprecated[i]) {
56632cd1d96SJun-ichiro itojun Hagino 			if (first) {
567ade9ccfeSMarcel Moolenaar 				xo_open_list("deprecated-source");
568ade9ccfeSMarcel Moolenaar 				xo_emit("\tdeprecated source addresses\n");
56932cd1d96SJun-ichiro itojun Hagino 				first = 0;
57032cd1d96SJun-ichiro itojun Hagino 			}
571ade9ccfeSMarcel Moolenaar 			xo_open_instance("deprecated-source");
57232cd1d96SJun-ichiro itojun Hagino 			PRINT_SCOPESTAT(ip6s_sources_deprecated[i], i);
573ade9ccfeSMarcel Moolenaar 			xo_close_instance("deprecated-source");
57432cd1d96SJun-ichiro itojun Hagino 		}
57532cd1d96SJun-ichiro itojun Hagino 	}
576ade9ccfeSMarcel Moolenaar 	if (!first)
577ade9ccfeSMarcel Moolenaar 		xo_close_list("deprecated-source");
57832cd1d96SJun-ichiro itojun Hagino 
579ade9ccfeSMarcel Moolenaar 	for (first = 1, i = 0; i < IP6S_RULESMAX; i++) {
580ade9ccfeSMarcel Moolenaar 		if (ip6stat.ip6s_sources_rule[i]) {
581ade9ccfeSMarcel Moolenaar 			if (first) {
582ade9ccfeSMarcel Moolenaar 				xo_open_list("rules-applied");
583ade9ccfeSMarcel Moolenaar 				xo_emit("\t{T:Source addresses selection "
584ade9ccfeSMarcel Moolenaar 				    "rule applied}:\n");
585ade9ccfeSMarcel Moolenaar 				first = 0;
586ade9ccfeSMarcel Moolenaar 			}
587ade9ccfeSMarcel Moolenaar 			xo_open_instance("rules-applied");
588ade9ccfeSMarcel Moolenaar 			xo_emit("\t\t{ke:name/%s}{:count/%ju} {d:name/%s}\n",
589ade9ccfeSMarcel Moolenaar 			    srcrule_str[i],
5907b95a1ebSYaroslav Tykhiy 			    (uintmax_t)ip6stat.ip6s_sources_rule[i],
5914ef2dc8bSHajimu UMEMOTO 			    srcrule_str[i]);
592ade9ccfeSMarcel Moolenaar 			xo_close_instance("rules-applied");
5934ef2dc8bSHajimu UMEMOTO 		}
594ade9ccfeSMarcel Moolenaar 	}
595ade9ccfeSMarcel Moolenaar 	if (!first)
596ade9ccfeSMarcel Moolenaar 		xo_close_list("rules-applied");
597ade9ccfeSMarcel Moolenaar 
598ade9ccfeSMarcel Moolenaar 	xo_close_container("source-address-selection");
599ade9ccfeSMarcel Moolenaar 
600cfa1ca9dSYoshinobu Inoue #undef p
60132cd1d96SJun-ichiro itojun Hagino #undef p1a
602ade9ccfeSMarcel Moolenaar 	xo_close_container(name);
603cfa1ca9dSYoshinobu Inoue }
604cfa1ca9dSYoshinobu Inoue 
605cfa1ca9dSYoshinobu Inoue /*
606cfa1ca9dSYoshinobu Inoue  * Dump IPv6 per-interface statistics based on RFC 2465.
607cfa1ca9dSYoshinobu Inoue  */
608cfa1ca9dSYoshinobu Inoue void
6095e051718SAssar Westerlund ip6_ifstats(char *ifname)
610cfa1ca9dSYoshinobu Inoue {
611cfa1ca9dSYoshinobu Inoue 	struct in6_ifreq ifr;
612cfa1ca9dSYoshinobu Inoue 	int s;
613ade9ccfeSMarcel Moolenaar 
614cfa1ca9dSYoshinobu Inoue #define	p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1)	\
615ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)ifr.ifr_ifru.ifru_stat.f,		\
616ade9ccfeSMarcel Moolenaar 	    plural(ifr.ifr_ifru.ifru_stat.f))
617cfa1ca9dSYoshinobu Inoue 
618cfa1ca9dSYoshinobu Inoue 	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
619ade9ccfeSMarcel Moolenaar 		xo_warn("Warning: socket(AF_INET6)");
620cfa1ca9dSYoshinobu Inoue 		return;
621cfa1ca9dSYoshinobu Inoue 	}
622cfa1ca9dSYoshinobu Inoue 
623cfa1ca9dSYoshinobu Inoue 	strcpy(ifr.ifr_name, ifname);
624cfa1ca9dSYoshinobu Inoue 	if (ioctl(s, SIOCGIFSTAT_IN6, (char *)&ifr) < 0) {
625d77e67e4SMark Johnston 		if (errno != EPFNOSUPPORT)
626ade9ccfeSMarcel Moolenaar 			xo_warn("Warning: ioctl(SIOCGIFSTAT_IN6)");
627cfa1ca9dSYoshinobu Inoue 		goto end;
628cfa1ca9dSYoshinobu Inoue 	}
629cfa1ca9dSYoshinobu Inoue 
630ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/ip6 on %s}:\n", ifr.ifr_name);
631ade9ccfeSMarcel Moolenaar 
632ade9ccfeSMarcel Moolenaar 	xo_open_instance("ip6-interface-statistics");
633ade9ccfeSMarcel Moolenaar 	xo_emit("{ke:name/%s}", ifr.ifr_name);
634ade9ccfeSMarcel Moolenaar 
635ade9ccfeSMarcel Moolenaar 	p(ifs6_in_receive, "\t{:received-packets/%ju} "
636ade9ccfeSMarcel Moolenaar 	    "{N:/total input datagram%s}\n");
637ade9ccfeSMarcel Moolenaar 	p(ifs6_in_hdrerr, "\t{:dropped-invalid-header/%ju} "
638ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s with invalid header received}\n");
639ade9ccfeSMarcel Moolenaar 	p(ifs6_in_toobig, "\t{:dropped-mtu-exceeded/%ju} "
640ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s exceeded MTU received}\n");
641ade9ccfeSMarcel Moolenaar 	p(ifs6_in_noroute, "\t{:dropped-no-route/%ju} "
642ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s with no route received}\n");
643ade9ccfeSMarcel Moolenaar 	p(ifs6_in_addrerr, "\t{:dropped-invalid-destination/%ju} "
644ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s with invalid dst received}\n");
645ade9ccfeSMarcel Moolenaar 	p(ifs6_in_protounknown, "\t{:dropped-unknown-protocol/%ju} "
646ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s with unknown proto received}\n");
647ade9ccfeSMarcel Moolenaar 	p(ifs6_in_truncated, "\t{:dropped-truncated/%ju} "
648ade9ccfeSMarcel Moolenaar 	    "{N:/truncated datagram%s received}\n");
649ade9ccfeSMarcel Moolenaar 	p(ifs6_in_discard, "\t{:dropped-discarded/%ju} "
650ade9ccfeSMarcel Moolenaar 	    "{N:/input datagram%s discarded}\n");
651ade9ccfeSMarcel Moolenaar  	p(ifs6_in_deliver, "\t{:received-valid-packets/%ju} "
652ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s delivered to an upper layer protocol}\n");
653ade9ccfeSMarcel Moolenaar 	p(ifs6_out_forward, "\t{:sent-forwarded/%ju} "
654ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s forwarded to this interface}\n");
655ade9ccfeSMarcel Moolenaar  	p(ifs6_out_request, "\t{:sent-packets/%ju} "
656ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s sent from an upper layer protocol}\n");
657ade9ccfeSMarcel Moolenaar 	p(ifs6_out_discard, "\t{:discard-packets/%ju} "
658ade9ccfeSMarcel Moolenaar 	    "{N:/total discarded output datagram%s}\n");
659ade9ccfeSMarcel Moolenaar 	p(ifs6_out_fragok, "\t{:discard-fragments/%ju} "
660ade9ccfeSMarcel Moolenaar 	    "{N:/output datagram%s fragmented}\n");
661ade9ccfeSMarcel Moolenaar 	p(ifs6_out_fragfail, "\t{:fragments-failed/%ju} "
662ade9ccfeSMarcel Moolenaar 	    "{N:/output datagram%s failed on fragment}\n");
663ade9ccfeSMarcel Moolenaar 	p(ifs6_out_fragcreat, "\t{:fragments-created/%ju} "
664ade9ccfeSMarcel Moolenaar 	    "{N:/output datagram%s succeeded on fragment}\n");
665ade9ccfeSMarcel Moolenaar 	p(ifs6_reass_reqd, "\t{:reassembly-required/%ju} "
666ade9ccfeSMarcel Moolenaar 	    "{N:/incoming datagram%s fragmented}\n");
667ade9ccfeSMarcel Moolenaar 	p(ifs6_reass_ok, "\t{:reassembled-packets/%ju} "
668ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s reassembled}\n");
669ade9ccfeSMarcel Moolenaar 	p(ifs6_reass_fail, "\t{:reassembly-failed/%ju} "
670ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s failed on reassembly}\n");
671ade9ccfeSMarcel Moolenaar 	p(ifs6_in_mcast, "\t{:received-multicast/%ju} "
672ade9ccfeSMarcel Moolenaar 	    "{N:/multicast datagram%s received}\n");
673ade9ccfeSMarcel Moolenaar 	p(ifs6_out_mcast, "\t{:sent-multicast/%ju} "
674ade9ccfeSMarcel Moolenaar 	    "{N:/multicast datagram%s sent}\n");
675cfa1ca9dSYoshinobu Inoue 
676cfa1ca9dSYoshinobu Inoue  end:
677ade9ccfeSMarcel Moolenaar 	xo_close_instance("ip6-interface-statistics");
678cfa1ca9dSYoshinobu Inoue  	close(s);
679cfa1ca9dSYoshinobu Inoue 
680cfa1ca9dSYoshinobu Inoue #undef p
681cfa1ca9dSYoshinobu Inoue }
682cfa1ca9dSYoshinobu Inoue 
683a01e3379SDavid Malone static	const char *icmp6names[] = {
684cfa1ca9dSYoshinobu Inoue 	"#0",
685cfa1ca9dSYoshinobu Inoue 	"unreach",
686cfa1ca9dSYoshinobu Inoue 	"packet too big",
687cfa1ca9dSYoshinobu Inoue 	"time exceed",
688cfa1ca9dSYoshinobu Inoue 	"parameter problem",
689cfa1ca9dSYoshinobu Inoue 	"#5",
690cfa1ca9dSYoshinobu Inoue 	"#6",
691cfa1ca9dSYoshinobu Inoue 	"#7",
692cfa1ca9dSYoshinobu Inoue 	"#8",
693cfa1ca9dSYoshinobu Inoue 	"#9",
694cfa1ca9dSYoshinobu Inoue 	"#10",
695cfa1ca9dSYoshinobu Inoue 	"#11",
696cfa1ca9dSYoshinobu Inoue 	"#12",
697cfa1ca9dSYoshinobu Inoue 	"#13",
698cfa1ca9dSYoshinobu Inoue 	"#14",
699cfa1ca9dSYoshinobu Inoue 	"#15",
700cfa1ca9dSYoshinobu Inoue 	"#16",
701cfa1ca9dSYoshinobu Inoue 	"#17",
702cfa1ca9dSYoshinobu Inoue 	"#18",
703cfa1ca9dSYoshinobu Inoue 	"#19",
704cfa1ca9dSYoshinobu Inoue 	"#20",
705cfa1ca9dSYoshinobu Inoue 	"#21",
706cfa1ca9dSYoshinobu Inoue 	"#22",
707cfa1ca9dSYoshinobu Inoue 	"#23",
708cfa1ca9dSYoshinobu Inoue 	"#24",
709cfa1ca9dSYoshinobu Inoue 	"#25",
710cfa1ca9dSYoshinobu Inoue 	"#26",
711cfa1ca9dSYoshinobu Inoue 	"#27",
712cfa1ca9dSYoshinobu Inoue 	"#28",
713cfa1ca9dSYoshinobu Inoue 	"#29",
714cfa1ca9dSYoshinobu Inoue 	"#30",
715cfa1ca9dSYoshinobu Inoue 	"#31",
716cfa1ca9dSYoshinobu Inoue 	"#32",
717cfa1ca9dSYoshinobu Inoue 	"#33",
718cfa1ca9dSYoshinobu Inoue 	"#34",
719cfa1ca9dSYoshinobu Inoue 	"#35",
720cfa1ca9dSYoshinobu Inoue 	"#36",
721cfa1ca9dSYoshinobu Inoue 	"#37",
722cfa1ca9dSYoshinobu Inoue 	"#38",
723cfa1ca9dSYoshinobu Inoue 	"#39",
724cfa1ca9dSYoshinobu Inoue 	"#40",
725cfa1ca9dSYoshinobu Inoue 	"#41",
726cfa1ca9dSYoshinobu Inoue 	"#42",
727cfa1ca9dSYoshinobu Inoue 	"#43",
728cfa1ca9dSYoshinobu Inoue 	"#44",
729cfa1ca9dSYoshinobu Inoue 	"#45",
730cfa1ca9dSYoshinobu Inoue 	"#46",
731cfa1ca9dSYoshinobu Inoue 	"#47",
732cfa1ca9dSYoshinobu Inoue 	"#48",
733cfa1ca9dSYoshinobu Inoue 	"#49",
734cfa1ca9dSYoshinobu Inoue 	"#50",
735cfa1ca9dSYoshinobu Inoue 	"#51",
736cfa1ca9dSYoshinobu Inoue 	"#52",
737cfa1ca9dSYoshinobu Inoue 	"#53",
738cfa1ca9dSYoshinobu Inoue 	"#54",
739cfa1ca9dSYoshinobu Inoue 	"#55",
740cfa1ca9dSYoshinobu Inoue 	"#56",
741cfa1ca9dSYoshinobu Inoue 	"#57",
742cfa1ca9dSYoshinobu Inoue 	"#58",
743cfa1ca9dSYoshinobu Inoue 	"#59",
744cfa1ca9dSYoshinobu Inoue 	"#60",
745cfa1ca9dSYoshinobu Inoue 	"#61",
746cfa1ca9dSYoshinobu Inoue 	"#62",
747cfa1ca9dSYoshinobu Inoue 	"#63",
748cfa1ca9dSYoshinobu Inoue 	"#64",
749cfa1ca9dSYoshinobu Inoue 	"#65",
750cfa1ca9dSYoshinobu Inoue 	"#66",
751cfa1ca9dSYoshinobu Inoue 	"#67",
752cfa1ca9dSYoshinobu Inoue 	"#68",
753cfa1ca9dSYoshinobu Inoue 	"#69",
754cfa1ca9dSYoshinobu Inoue 	"#70",
755cfa1ca9dSYoshinobu Inoue 	"#71",
756cfa1ca9dSYoshinobu Inoue 	"#72",
757cfa1ca9dSYoshinobu Inoue 	"#73",
758cfa1ca9dSYoshinobu Inoue 	"#74",
759cfa1ca9dSYoshinobu Inoue 	"#75",
760cfa1ca9dSYoshinobu Inoue 	"#76",
761cfa1ca9dSYoshinobu Inoue 	"#77",
762cfa1ca9dSYoshinobu Inoue 	"#78",
763cfa1ca9dSYoshinobu Inoue 	"#79",
764cfa1ca9dSYoshinobu Inoue 	"#80",
765cfa1ca9dSYoshinobu Inoue 	"#81",
766cfa1ca9dSYoshinobu Inoue 	"#82",
767cfa1ca9dSYoshinobu Inoue 	"#83",
768cfa1ca9dSYoshinobu Inoue 	"#84",
769cfa1ca9dSYoshinobu Inoue 	"#85",
770cfa1ca9dSYoshinobu Inoue 	"#86",
771cfa1ca9dSYoshinobu Inoue 	"#87",
772cfa1ca9dSYoshinobu Inoue 	"#88",
773cfa1ca9dSYoshinobu Inoue 	"#89",
774cfa1ca9dSYoshinobu Inoue 	"#80",
775cfa1ca9dSYoshinobu Inoue 	"#91",
776cfa1ca9dSYoshinobu Inoue 	"#92",
777cfa1ca9dSYoshinobu Inoue 	"#93",
778cfa1ca9dSYoshinobu Inoue 	"#94",
779cfa1ca9dSYoshinobu Inoue 	"#95",
780cfa1ca9dSYoshinobu Inoue 	"#96",
781cfa1ca9dSYoshinobu Inoue 	"#97",
782cfa1ca9dSYoshinobu Inoue 	"#98",
783cfa1ca9dSYoshinobu Inoue 	"#99",
784cfa1ca9dSYoshinobu Inoue 	"#100",
785cfa1ca9dSYoshinobu Inoue 	"#101",
786cfa1ca9dSYoshinobu Inoue 	"#102",
787cfa1ca9dSYoshinobu Inoue 	"#103",
788cfa1ca9dSYoshinobu Inoue 	"#104",
789cfa1ca9dSYoshinobu Inoue 	"#105",
790cfa1ca9dSYoshinobu Inoue 	"#106",
791cfa1ca9dSYoshinobu Inoue 	"#107",
792cfa1ca9dSYoshinobu Inoue 	"#108",
793cfa1ca9dSYoshinobu Inoue 	"#109",
794cfa1ca9dSYoshinobu Inoue 	"#110",
795cfa1ca9dSYoshinobu Inoue 	"#111",
796cfa1ca9dSYoshinobu Inoue 	"#112",
797cfa1ca9dSYoshinobu Inoue 	"#113",
798cfa1ca9dSYoshinobu Inoue 	"#114",
799cfa1ca9dSYoshinobu Inoue 	"#115",
800cfa1ca9dSYoshinobu Inoue 	"#116",
801cfa1ca9dSYoshinobu Inoue 	"#117",
802cfa1ca9dSYoshinobu Inoue 	"#118",
803cfa1ca9dSYoshinobu Inoue 	"#119",
804cfa1ca9dSYoshinobu Inoue 	"#120",
805cfa1ca9dSYoshinobu Inoue 	"#121",
806cfa1ca9dSYoshinobu Inoue 	"#122",
807cfa1ca9dSYoshinobu Inoue 	"#123",
808cfa1ca9dSYoshinobu Inoue 	"#124",
809cfa1ca9dSYoshinobu Inoue 	"#125",
810cfa1ca9dSYoshinobu Inoue 	"#126",
811cfa1ca9dSYoshinobu Inoue 	"#127",
812cfa1ca9dSYoshinobu Inoue 	"echo",
813cfa1ca9dSYoshinobu Inoue 	"echo reply",
814cfa1ca9dSYoshinobu Inoue 	"multicast listener query",
8157d9d64baSBruce M Simpson 	"MLDv1 listener report",
8167d9d64baSBruce M Simpson 	"MLDv1 listener done",
817cfa1ca9dSYoshinobu Inoue 	"router solicitation",
8186ab55b23SDima Dorfman 	"router advertisement",
819cfa1ca9dSYoshinobu Inoue 	"neighbor solicitation",
8206ab55b23SDima Dorfman 	"neighbor advertisement",
821cfa1ca9dSYoshinobu Inoue 	"redirect",
822cfa1ca9dSYoshinobu Inoue 	"router renumbering",
823cfa1ca9dSYoshinobu Inoue 	"node information request",
824cfa1ca9dSYoshinobu Inoue 	"node information reply",
825fd555639SMunechika SUMIKAWA 	"inverse neighbor solicitation",
826fd555639SMunechika SUMIKAWA 	"inverse neighbor advertisement",
8277d9d64baSBruce M Simpson 	"MLDv2 listener report",
828cfa1ca9dSYoshinobu Inoue 	"#144",
829cfa1ca9dSYoshinobu Inoue 	"#145",
830cfa1ca9dSYoshinobu Inoue 	"#146",
831cfa1ca9dSYoshinobu Inoue 	"#147",
832cfa1ca9dSYoshinobu Inoue 	"#148",
833cfa1ca9dSYoshinobu Inoue 	"#149",
834cfa1ca9dSYoshinobu Inoue 	"#150",
835cfa1ca9dSYoshinobu Inoue 	"#151",
836cfa1ca9dSYoshinobu Inoue 	"#152",
837cfa1ca9dSYoshinobu Inoue 	"#153",
838cfa1ca9dSYoshinobu Inoue 	"#154",
839cfa1ca9dSYoshinobu Inoue 	"#155",
840cfa1ca9dSYoshinobu Inoue 	"#156",
841cfa1ca9dSYoshinobu Inoue 	"#157",
842cfa1ca9dSYoshinobu Inoue 	"#158",
843cfa1ca9dSYoshinobu Inoue 	"#159",
844cfa1ca9dSYoshinobu Inoue 	"#160",
845cfa1ca9dSYoshinobu Inoue 	"#161",
846cfa1ca9dSYoshinobu Inoue 	"#162",
847cfa1ca9dSYoshinobu Inoue 	"#163",
848cfa1ca9dSYoshinobu Inoue 	"#164",
849cfa1ca9dSYoshinobu Inoue 	"#165",
850cfa1ca9dSYoshinobu Inoue 	"#166",
851cfa1ca9dSYoshinobu Inoue 	"#167",
852cfa1ca9dSYoshinobu Inoue 	"#168",
853cfa1ca9dSYoshinobu Inoue 	"#169",
854cfa1ca9dSYoshinobu Inoue 	"#170",
855cfa1ca9dSYoshinobu Inoue 	"#171",
856cfa1ca9dSYoshinobu Inoue 	"#172",
857cfa1ca9dSYoshinobu Inoue 	"#173",
858cfa1ca9dSYoshinobu Inoue 	"#174",
859cfa1ca9dSYoshinobu Inoue 	"#175",
860cfa1ca9dSYoshinobu Inoue 	"#176",
861cfa1ca9dSYoshinobu Inoue 	"#177",
862cfa1ca9dSYoshinobu Inoue 	"#178",
863cfa1ca9dSYoshinobu Inoue 	"#179",
864cfa1ca9dSYoshinobu Inoue 	"#180",
865cfa1ca9dSYoshinobu Inoue 	"#181",
866cfa1ca9dSYoshinobu Inoue 	"#182",
867cfa1ca9dSYoshinobu Inoue 	"#183",
868cfa1ca9dSYoshinobu Inoue 	"#184",
869cfa1ca9dSYoshinobu Inoue 	"#185",
870cfa1ca9dSYoshinobu Inoue 	"#186",
871cfa1ca9dSYoshinobu Inoue 	"#187",
872cfa1ca9dSYoshinobu Inoue 	"#188",
873cfa1ca9dSYoshinobu Inoue 	"#189",
874cfa1ca9dSYoshinobu Inoue 	"#180",
875cfa1ca9dSYoshinobu Inoue 	"#191",
876cfa1ca9dSYoshinobu Inoue 	"#192",
877cfa1ca9dSYoshinobu Inoue 	"#193",
878cfa1ca9dSYoshinobu Inoue 	"#194",
879cfa1ca9dSYoshinobu Inoue 	"#195",
880cfa1ca9dSYoshinobu Inoue 	"#196",
881cfa1ca9dSYoshinobu Inoue 	"#197",
882cfa1ca9dSYoshinobu Inoue 	"#198",
883cfa1ca9dSYoshinobu Inoue 	"#199",
884cfa1ca9dSYoshinobu Inoue 	"#200",
885cfa1ca9dSYoshinobu Inoue 	"#201",
886cfa1ca9dSYoshinobu Inoue 	"#202",
887cfa1ca9dSYoshinobu Inoue 	"#203",
888cfa1ca9dSYoshinobu Inoue 	"#204",
889cfa1ca9dSYoshinobu Inoue 	"#205",
890cfa1ca9dSYoshinobu Inoue 	"#206",
891cfa1ca9dSYoshinobu Inoue 	"#207",
892cfa1ca9dSYoshinobu Inoue 	"#208",
893cfa1ca9dSYoshinobu Inoue 	"#209",
894cfa1ca9dSYoshinobu Inoue 	"#210",
895cfa1ca9dSYoshinobu Inoue 	"#211",
896cfa1ca9dSYoshinobu Inoue 	"#212",
897cfa1ca9dSYoshinobu Inoue 	"#213",
898cfa1ca9dSYoshinobu Inoue 	"#214",
899cfa1ca9dSYoshinobu Inoue 	"#215",
900cfa1ca9dSYoshinobu Inoue 	"#216",
901cfa1ca9dSYoshinobu Inoue 	"#217",
902cfa1ca9dSYoshinobu Inoue 	"#218",
903cfa1ca9dSYoshinobu Inoue 	"#219",
904cfa1ca9dSYoshinobu Inoue 	"#220",
905cfa1ca9dSYoshinobu Inoue 	"#221",
906cfa1ca9dSYoshinobu Inoue 	"#222",
907cfa1ca9dSYoshinobu Inoue 	"#223",
908cfa1ca9dSYoshinobu Inoue 	"#224",
909cfa1ca9dSYoshinobu Inoue 	"#225",
910cfa1ca9dSYoshinobu Inoue 	"#226",
911cfa1ca9dSYoshinobu Inoue 	"#227",
912cfa1ca9dSYoshinobu Inoue 	"#228",
913cfa1ca9dSYoshinobu Inoue 	"#229",
914cfa1ca9dSYoshinobu Inoue 	"#230",
915cfa1ca9dSYoshinobu Inoue 	"#231",
916cfa1ca9dSYoshinobu Inoue 	"#232",
917cfa1ca9dSYoshinobu Inoue 	"#233",
918cfa1ca9dSYoshinobu Inoue 	"#234",
919cfa1ca9dSYoshinobu Inoue 	"#235",
920cfa1ca9dSYoshinobu Inoue 	"#236",
921cfa1ca9dSYoshinobu Inoue 	"#237",
922cfa1ca9dSYoshinobu Inoue 	"#238",
923cfa1ca9dSYoshinobu Inoue 	"#239",
924cfa1ca9dSYoshinobu Inoue 	"#240",
925cfa1ca9dSYoshinobu Inoue 	"#241",
926cfa1ca9dSYoshinobu Inoue 	"#242",
927cfa1ca9dSYoshinobu Inoue 	"#243",
928cfa1ca9dSYoshinobu Inoue 	"#244",
929cfa1ca9dSYoshinobu Inoue 	"#245",
930cfa1ca9dSYoshinobu Inoue 	"#246",
931cfa1ca9dSYoshinobu Inoue 	"#247",
932cfa1ca9dSYoshinobu Inoue 	"#248",
933cfa1ca9dSYoshinobu Inoue 	"#249",
934cfa1ca9dSYoshinobu Inoue 	"#250",
935cfa1ca9dSYoshinobu Inoue 	"#251",
936cfa1ca9dSYoshinobu Inoue 	"#252",
937cfa1ca9dSYoshinobu Inoue 	"#253",
938cfa1ca9dSYoshinobu Inoue 	"#254",
939cfa1ca9dSYoshinobu Inoue 	"#255",
940cfa1ca9dSYoshinobu Inoue };
941cfa1ca9dSYoshinobu Inoue 
942cfa1ca9dSYoshinobu Inoue /*
943cfa1ca9dSYoshinobu Inoue  * Dump ICMP6 statistics.
944cfa1ca9dSYoshinobu Inoue  */
945cfa1ca9dSYoshinobu Inoue void
946feda1a43SJohn Baldwin icmp6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
947cfa1ca9dSYoshinobu Inoue {
9489eddb899SMark Johnston 	struct icmp6stat icmp6stat;
949241667c4SMark Murray 	int i, first;
950cfa1ca9dSYoshinobu Inoue 
9519eddb899SMark Johnston 	if (fetch_stats("net.inet6.icmp6.stats", off, &icmp6stat,
9529eddb899SMark Johnston 	    sizeof(icmp6stat), kread_counters) != 0)
953cfa1ca9dSYoshinobu Inoue 		return;
954feda1a43SJohn Baldwin 
955ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
956ade9ccfeSMarcel Moolenaar 	xo_open_container(name);
957cfa1ca9dSYoshinobu Inoue 
958cfa1ca9dSYoshinobu Inoue #define	p(f, m) if (icmp6stat.f || sflag <= 1) \
959ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)icmp6stat.f, plural(icmp6stat.f))
9603ed817f1SMaxim Konovalov #define	p_5(f, m) if (icmp6stat.f || sflag <= 1) \
961ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)icmp6stat.f)
962cfa1ca9dSYoshinobu Inoue 
963ade9ccfeSMarcel Moolenaar 	p(icp6s_error, "\t{:icmp6-calls/%ju} "
964ade9ccfeSMarcel Moolenaar 	    "{N:/call%s to icmp6_error}\n");
965ade9ccfeSMarcel Moolenaar 	p(icp6s_canterror, "\t{:errors-not-generated-from-message/%ju} "
966ade9ccfeSMarcel Moolenaar 	    "{N:/error%s not generated in response to an icmp6 message}\n");
967ade9ccfeSMarcel Moolenaar 	p(icp6s_toofreq, "\t{:errors-discarded-by-rate-limitation/%ju} "
968ade9ccfeSMarcel Moolenaar 	    "{N:/error%s not generated because of rate limitation}\n");
969241667c4SMark Murray #define	NELEM (int)(sizeof(icmp6stat.icp6s_outhist)/sizeof(icmp6stat.icp6s_outhist[0]))
970fd555639SMunechika SUMIKAWA 	for (first = 1, i = 0; i < NELEM; i++)
971cfa1ca9dSYoshinobu Inoue 		if (icmp6stat.icp6s_outhist[i] != 0) {
972cfa1ca9dSYoshinobu Inoue 			if (first) {
973ade9ccfeSMarcel Moolenaar 				xo_open_list("output-histogram");
974ade9ccfeSMarcel Moolenaar 				xo_emit("\t{T:Output histogram}:\n");
975cfa1ca9dSYoshinobu Inoue 				first = 0;
976cfa1ca9dSYoshinobu Inoue 			}
977ade9ccfeSMarcel Moolenaar 			xo_open_instance("output-histogram");
978ade9ccfeSMarcel Moolenaar 			xo_emit("\t\t{k:name/%s}: {:count/%ju}\n",
979ade9ccfeSMarcel Moolenaar 			    icmp6names[i],
9807b95a1ebSYaroslav Tykhiy 			    (uintmax_t)icmp6stat.icp6s_outhist[i]);
981ade9ccfeSMarcel Moolenaar 			xo_close_instance("output-histogram");
982cfa1ca9dSYoshinobu Inoue 		}
983ade9ccfeSMarcel Moolenaar 	if (!first)
984ade9ccfeSMarcel Moolenaar 		xo_close_list("output-histogram");
985fd555639SMunechika SUMIKAWA #undef NELEM
986ade9ccfeSMarcel Moolenaar 
987ade9ccfeSMarcel Moolenaar 	p(icp6s_badcode, "\t{:dropped-bad-code/%ju} "
988ade9ccfeSMarcel Moolenaar 	    "{N:/message%s with bad code fields}\n");
989ade9ccfeSMarcel Moolenaar 	p(icp6s_tooshort, "\t{:dropped-too-short/%ju} "
990ade9ccfeSMarcel Moolenaar 	    "{N:/message%s < minimum length}\n");
991ade9ccfeSMarcel Moolenaar 	p(icp6s_checksum, "\t{:dropped-bad-checksum/%ju} "
992ade9ccfeSMarcel Moolenaar 	    "{N:/bad checksum%s}\n");
993ade9ccfeSMarcel Moolenaar 	p(icp6s_badlen, "\t{:dropped-bad-length/%ju} "
994ade9ccfeSMarcel Moolenaar 	    "{N:/message%s with bad length}\n");
995241667c4SMark Murray #define	NELEM (int)(sizeof(icmp6stat.icp6s_inhist)/sizeof(icmp6stat.icp6s_inhist[0]))
996fd555639SMunechika SUMIKAWA 	for (first = 1, i = 0; i < NELEM; i++)
997cfa1ca9dSYoshinobu Inoue 		if (icmp6stat.icp6s_inhist[i] != 0) {
998cfa1ca9dSYoshinobu Inoue 			if (first) {
999ade9ccfeSMarcel Moolenaar 				xo_open_list("input-histogram");
1000ade9ccfeSMarcel Moolenaar 				xo_emit("\t{T:Input histogram}:\n");
1001cfa1ca9dSYoshinobu Inoue 				first = 0;
1002cfa1ca9dSYoshinobu Inoue 			}
1003ade9ccfeSMarcel Moolenaar 			xo_open_instance("input-histogram");
1004ade9ccfeSMarcel Moolenaar 			xo_emit("\t\t{k:name/%s}: {:count/%ju}\n",
1005ade9ccfeSMarcel Moolenaar 			    icmp6names[i],
10067b95a1ebSYaroslav Tykhiy 			    (uintmax_t)icmp6stat.icp6s_inhist[i]);
1007ade9ccfeSMarcel Moolenaar 			xo_close_instance("input-histogram");
1008cfa1ca9dSYoshinobu Inoue 		}
1009ade9ccfeSMarcel Moolenaar 	if (!first)
1010ade9ccfeSMarcel Moolenaar 		xo_close_list("input-histogram");
1011fd555639SMunechika SUMIKAWA #undef NELEM
1012ade9ccfeSMarcel Moolenaar 	xo_emit("\t{T:Histogram of error messages to be generated}:\n");
1013ade9ccfeSMarcel Moolenaar 	xo_open_container("errors");
1014ade9ccfeSMarcel Moolenaar 	p_5(icp6s_odst_unreach_noroute, "\t\t{:no-route/%ju} "
1015ade9ccfeSMarcel Moolenaar 	    "{N:/no route}\n");
1016ade9ccfeSMarcel Moolenaar 	p_5(icp6s_odst_unreach_admin, "\t\t{:admin-prohibited/%ju} "
1017ade9ccfeSMarcel Moolenaar 	    "{N:/administratively prohibited}\n");
1018ade9ccfeSMarcel Moolenaar 	p_5(icp6s_odst_unreach_beyondscope, "\t\t{:beyond-scope/%ju} "
1019ade9ccfeSMarcel Moolenaar 	    "{N:/beyond scope}\n");
1020ade9ccfeSMarcel Moolenaar 	p_5(icp6s_odst_unreach_addr, "\t\t{:address-unreachable/%ju} "
1021ade9ccfeSMarcel Moolenaar 	    "{N:/address unreachable}\n");
1022ade9ccfeSMarcel Moolenaar 	p_5(icp6s_odst_unreach_noport, "\t\t{:port-unreachable/%ju} "
1023ade9ccfeSMarcel Moolenaar 	    "{N:/port unreachable}\n");
1024ade9ccfeSMarcel Moolenaar 	p_5(icp6s_opacket_too_big, "\t\t{:packet-too-big/%ju} "
1025ade9ccfeSMarcel Moolenaar 	    "{N:/packet too big}\n");
1026ade9ccfeSMarcel Moolenaar 	p_5(icp6s_otime_exceed_transit, "\t\t{:time-exceed-transmit/%ju} "
1027ade9ccfeSMarcel Moolenaar 	    "{N:/time exceed transit}\n");
1028ade9ccfeSMarcel Moolenaar 	p_5(icp6s_otime_exceed_reassembly, "\t\t{:time-exceed-reassembly/%ju} "
1029ade9ccfeSMarcel Moolenaar 	    "{N:/time exceed reassembly}\n");
1030ade9ccfeSMarcel Moolenaar 	p_5(icp6s_oparamprob_header, "\t\t{:bad-header/%ju} "
1031ade9ccfeSMarcel Moolenaar 	    "{N:/erroneous header field}\n");
1032ade9ccfeSMarcel Moolenaar 	p_5(icp6s_oparamprob_nextheader, "\t\t{:bad-next-header/%ju} "
1033ade9ccfeSMarcel Moolenaar 	    "{N:/unrecognized next header}\n");
1034ade9ccfeSMarcel Moolenaar 	p_5(icp6s_oparamprob_option, "\t\t{:bad-option/%ju} "
1035ade9ccfeSMarcel Moolenaar 	    "{N:/unrecognized option}\n");
1036ade9ccfeSMarcel Moolenaar 	p_5(icp6s_oredirect, "\t\t{:redirects/%ju} "
1037ade9ccfeSMarcel Moolenaar 	    "{N:/redirect}\n");
1038ade9ccfeSMarcel Moolenaar 	p_5(icp6s_ounknown, "\t\t{:unknown/%ju} {N:unknown}\n");
103932cd1d96SJun-ichiro itojun Hagino 
1040ade9ccfeSMarcel Moolenaar 	p(icp6s_reflect, "\t{:reflect/%ju} "
1041ade9ccfeSMarcel Moolenaar 	    "{N:/message response%s generated}\n");
1042ade9ccfeSMarcel Moolenaar 	p(icp6s_nd_toomanyopt, "\t{:too-many-nd-options/%ju} "
1043ade9ccfeSMarcel Moolenaar 	    "{N:/message%s with too many ND options}\n");
1044ade9ccfeSMarcel Moolenaar 	p(icp6s_nd_badopt, "\t{:bad-nd-options/%ju} "
1045ade9ccfeSMarcel Moolenaar 	    "{N:/message%s with bad ND options}\n");
1046ade9ccfeSMarcel Moolenaar 	p(icp6s_badns, "\t{:bad-neighbor-solicitation/%ju} "
1047ade9ccfeSMarcel Moolenaar 	    "{N:/bad neighbor solicitation message%s}\n");
1048ade9ccfeSMarcel Moolenaar 	p(icp6s_badna, "\t{:bad-neighbor-advertisement/%ju} "
1049ade9ccfeSMarcel Moolenaar 	    "{N:/bad neighbor advertisement message%s}\n");
1050ade9ccfeSMarcel Moolenaar 	p(icp6s_badrs, "\t{:bad-router-solicitation/%ju} "
1051ade9ccfeSMarcel Moolenaar 	    "{N:/bad router solicitation message%s}\n");
1052ade9ccfeSMarcel Moolenaar 	p(icp6s_badra, "\t{:bad-router-advertisement/%ju} "
1053ade9ccfeSMarcel Moolenaar 	    "{N:/bad router advertisement message%s}\n");
1054ade9ccfeSMarcel Moolenaar 	p(icp6s_badredirect, "\t{:bad-redirect/%ju} "
1055ade9ccfeSMarcel Moolenaar 	    "{N:/bad redirect message%s}\n");
1056ade9ccfeSMarcel Moolenaar 	xo_close_container("errors");
1057ade9ccfeSMarcel Moolenaar 	p(icp6s_pmtuchg, "\t{:path-mtu-changes/%ju} {N:/path MTU change%s}\n");
1058cfa1ca9dSYoshinobu Inoue #undef p
1059cfa1ca9dSYoshinobu Inoue #undef p_5
1060ade9ccfeSMarcel Moolenaar 	xo_close_container(name);
1061cfa1ca9dSYoshinobu Inoue }
1062cfa1ca9dSYoshinobu Inoue 
1063cfa1ca9dSYoshinobu Inoue /*
1064cfa1ca9dSYoshinobu Inoue  * Dump ICMPv6 per-interface statistics based on RFC 2466.
1065cfa1ca9dSYoshinobu Inoue  */
1066cfa1ca9dSYoshinobu Inoue void
10675e051718SAssar Westerlund icmp6_ifstats(char *ifname)
1068cfa1ca9dSYoshinobu Inoue {
1069cfa1ca9dSYoshinobu Inoue 	struct in6_ifreq ifr;
1070cfa1ca9dSYoshinobu Inoue 	int s;
1071ade9ccfeSMarcel Moolenaar 
1072cfa1ca9dSYoshinobu Inoue #define	p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1)	\
1073ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f,		\
1074ade9ccfeSMarcel Moolenaar 	    plural(ifr.ifr_ifru.ifru_icmp6stat.f))
1075f99a4046SMike Makonnen #define	p2(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1)	\
1076ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f,		\
1077ade9ccfeSMarcel Moolenaar 	    pluralies(ifr.ifr_ifru.ifru_icmp6stat.f))
1078cfa1ca9dSYoshinobu Inoue 
1079cfa1ca9dSYoshinobu Inoue 	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
1080ade9ccfeSMarcel Moolenaar 		xo_warn("Warning: socket(AF_INET6)");
1081cfa1ca9dSYoshinobu Inoue 		return;
1082cfa1ca9dSYoshinobu Inoue 	}
1083cfa1ca9dSYoshinobu Inoue 
1084cfa1ca9dSYoshinobu Inoue 	strcpy(ifr.ifr_name, ifname);
1085cfa1ca9dSYoshinobu Inoue 	if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) {
1086d77e67e4SMark Johnston 		if (errno != EPFNOSUPPORT)
1087ade9ccfeSMarcel Moolenaar 			xo_warn("Warning: ioctl(SIOCGIFSTAT_ICMP6)");
1088cfa1ca9dSYoshinobu Inoue 		goto end;
1089cfa1ca9dSYoshinobu Inoue 	}
1090cfa1ca9dSYoshinobu Inoue 
1091ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/icmp6 on %s}:\n", ifr.ifr_name);
1092cfa1ca9dSYoshinobu Inoue 
1093ade9ccfeSMarcel Moolenaar 	xo_open_instance("icmp6-interface-statistics");
1094ade9ccfeSMarcel Moolenaar 	xo_emit("{ke:name/%s}", ifr.ifr_name);
1095ade9ccfeSMarcel Moolenaar 	p(ifs6_in_msg, "\t{:received-packets/%ju} "
1096ade9ccfeSMarcel Moolenaar 	    "{N:/total input message%s}\n");
1097ade9ccfeSMarcel Moolenaar 	p(ifs6_in_error, "\t{:received-errors/%ju} "
1098ade9ccfeSMarcel Moolenaar 	    "{N:/total input error message%s}\n");
1099ade9ccfeSMarcel Moolenaar 	p(ifs6_in_dstunreach, "\t{:received-destination-unreachable/%ju} "
1100ade9ccfeSMarcel Moolenaar 	    "{N:/input destination unreachable error%s}\n");
1101ade9ccfeSMarcel Moolenaar 	p(ifs6_in_adminprohib, "\t{:received-admin-prohibited/%ju} "
1102ade9ccfeSMarcel Moolenaar 	    "{N:/input administratively prohibited error%s}\n");
1103ade9ccfeSMarcel Moolenaar 	p(ifs6_in_timeexceed, "\t{:received-time-exceeded/%ju} "
1104ade9ccfeSMarcel Moolenaar 	    "{N:/input time exceeded error%s}\n");
1105ade9ccfeSMarcel Moolenaar 	p(ifs6_in_paramprob, "\t{:received-bad-parameter/%ju} "
1106ade9ccfeSMarcel Moolenaar 	    "{N:/input parameter problem error%s}\n");
1107ade9ccfeSMarcel Moolenaar 	p(ifs6_in_pkttoobig, "\t{:received-packet-too-big/%ju} "
1108ade9ccfeSMarcel Moolenaar 	    "{N:/input packet too big error%s}\n");
1109ade9ccfeSMarcel Moolenaar 	p(ifs6_in_echo, "\t{:received-echo-requests/%ju} "
1110ade9ccfeSMarcel Moolenaar 	    "{N:/input echo request%s}\n");
1111ade9ccfeSMarcel Moolenaar 	p2(ifs6_in_echoreply, "\t{:received-echo-replies/%ju} "
1112ade9ccfeSMarcel Moolenaar 	    "{N:/input echo repl%s}\n");
1113ade9ccfeSMarcel Moolenaar 	p(ifs6_in_routersolicit, "\t{:received-router-solicitation/%ju} "
1114ade9ccfeSMarcel Moolenaar 	    "{N:/input router solicitation%s}\n");
1115ade9ccfeSMarcel Moolenaar 	p(ifs6_in_routeradvert, "\t{:received-router-advertisement/%ju} "
1116ade9ccfeSMarcel Moolenaar 	    "{N:/input router advertisement%s}\n");
1117ade9ccfeSMarcel Moolenaar 	p(ifs6_in_neighborsolicit, "\t{:received-neighbor-solicitation/%ju} "
1118ade9ccfeSMarcel Moolenaar 	    "{N:/input neighbor solicitation%s}\n");
1119ade9ccfeSMarcel Moolenaar 	p(ifs6_in_neighboradvert, "\t{:received-neighbor-advertisement/%ju} "
1120ade9ccfeSMarcel Moolenaar 	    "{N:/input neighbor advertisement%s}\n");
1121ade9ccfeSMarcel Moolenaar 	p(ifs6_in_redirect, "\t{received-redirects/%ju} "
1122ade9ccfeSMarcel Moolenaar 	    "{N:/input redirect%s}\n");
1123ade9ccfeSMarcel Moolenaar 	p2(ifs6_in_mldquery, "\t{:received-mld-queries/%ju} "
1124ade9ccfeSMarcel Moolenaar 	    "{N:/input MLD quer%s}\n");
1125ade9ccfeSMarcel Moolenaar 	p(ifs6_in_mldreport, "\t{:received-mld-reports/%ju} "
1126ade9ccfeSMarcel Moolenaar 	    "{N:/input MLD report%s}\n");
1127ade9ccfeSMarcel Moolenaar 	p(ifs6_in_mlddone, "\t{:received-mld-done/%ju} "
1128ade9ccfeSMarcel Moolenaar 	    "{N:/input MLD done%s}\n");
1129ade9ccfeSMarcel Moolenaar 
1130ade9ccfeSMarcel Moolenaar 	p(ifs6_out_msg, "\t{:sent-packets/%ju} "
1131ade9ccfeSMarcel Moolenaar 	    "{N:/total output message%s}\n");
1132ade9ccfeSMarcel Moolenaar 	p(ifs6_out_error, "\t{:sent-errors/%ju} "
1133ade9ccfeSMarcel Moolenaar 	    "{N:/total output error message%s}\n");
1134ade9ccfeSMarcel Moolenaar 	p(ifs6_out_dstunreach, "\t{:sent-destination-unreachable/%ju} "
1135ade9ccfeSMarcel Moolenaar 	    "{N:/output destination unreachable error%s}\n");
1136ade9ccfeSMarcel Moolenaar 	p(ifs6_out_adminprohib, "\t{:sent-admin-prohibited/%ju} "
1137ade9ccfeSMarcel Moolenaar 	    "{N:/output administratively prohibited error%s}\n");
1138ade9ccfeSMarcel Moolenaar 	p(ifs6_out_timeexceed, "\t{:sent-time-exceeded/%ju} "
1139ade9ccfeSMarcel Moolenaar 	    "{N:/output time exceeded error%s}\n");
1140ade9ccfeSMarcel Moolenaar 	p(ifs6_out_paramprob, "\t{:sent-bad-parameter/%ju} "
1141ade9ccfeSMarcel Moolenaar 	    "{N:/output parameter problem error%s}\n");
1142ade9ccfeSMarcel Moolenaar 	p(ifs6_out_pkttoobig, "\t{:sent-packet-too-big/%ju} "
1143ade9ccfeSMarcel Moolenaar 	    "{N:/output packet too big error%s}\n");
1144ade9ccfeSMarcel Moolenaar 	p(ifs6_out_echo, "\t{:sent-echo-requests/%ju} "
1145ade9ccfeSMarcel Moolenaar 	    "{N:/output echo request%s}\n");
1146ade9ccfeSMarcel Moolenaar 	p2(ifs6_out_echoreply, "\t{:sent-echo-replies/%ju} "
1147ade9ccfeSMarcel Moolenaar 	    "{N:/output echo repl%s}\n");
1148ade9ccfeSMarcel Moolenaar 	p(ifs6_out_routersolicit, "\t{:sent-router-solicitation/%ju} "
1149ade9ccfeSMarcel Moolenaar 	    "{N:/output router solicitation%s}\n");
1150ade9ccfeSMarcel Moolenaar 	p(ifs6_out_routeradvert, "\t{:sent-router-advertisement/%ju} "
1151ade9ccfeSMarcel Moolenaar 	    "{N:/output router advertisement%s}\n");
1152ade9ccfeSMarcel Moolenaar 	p(ifs6_out_neighborsolicit, "\t{:sent-neighbor-solicitation/%ju} "
1153ade9ccfeSMarcel Moolenaar 	    "{N:/output neighbor solicitation%s}\n");
1154ade9ccfeSMarcel Moolenaar 	p(ifs6_out_neighboradvert, "\t{:sent-neighbor-advertisement/%ju} "
1155ade9ccfeSMarcel Moolenaar 	    "{N:/output neighbor advertisement%s}\n");
1156ade9ccfeSMarcel Moolenaar 	p(ifs6_out_redirect, "\t{:sent-redirects/%ju} "
1157ade9ccfeSMarcel Moolenaar 	    "{N:/output redirect%s}\n");
1158ade9ccfeSMarcel Moolenaar 	p2(ifs6_out_mldquery, "\t{:sent-mld-queries/%ju} "
1159ade9ccfeSMarcel Moolenaar 	    "{N:/output MLD quer%s}\n");
1160ade9ccfeSMarcel Moolenaar 	p(ifs6_out_mldreport, "\t{:sent-mld-reports/%ju} "
1161ade9ccfeSMarcel Moolenaar 	    "{N:/output MLD report%s}\n");
1162ade9ccfeSMarcel Moolenaar 	p(ifs6_out_mlddone, "\t{:sent-mld-dones/%ju} "
1163ade9ccfeSMarcel Moolenaar 	    "{N:/output MLD done%s}\n");
1164cfa1ca9dSYoshinobu Inoue 
1165cfa1ca9dSYoshinobu Inoue end:
1166ade9ccfeSMarcel Moolenaar 	xo_close_instance("icmp6-interface-statistics");
1167cfa1ca9dSYoshinobu Inoue 	close(s);
1168cfa1ca9dSYoshinobu Inoue #undef p
1169cfa1ca9dSYoshinobu Inoue }
1170cfa1ca9dSYoshinobu Inoue 
1171cfa1ca9dSYoshinobu Inoue /*
1172cfa1ca9dSYoshinobu Inoue  * Dump PIM statistics structure.
1173cfa1ca9dSYoshinobu Inoue  */
1174cfa1ca9dSYoshinobu Inoue void
1175feda1a43SJohn Baldwin pim6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
1176cfa1ca9dSYoshinobu Inoue {
11779eddb899SMark Johnston 	struct pim6stat pim6stat;
1178cfa1ca9dSYoshinobu Inoue 
11799eddb899SMark Johnston 	if (fetch_stats("net.inet6.pim.stats", off, &pim6stat,
11809eddb899SMark Johnston 	    sizeof(pim6stat), kread) != 0)
1181cfa1ca9dSYoshinobu Inoue 		return;
1182feda1a43SJohn Baldwin 
1183ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
1184ade9ccfeSMarcel Moolenaar 	xo_open_container(name);
1185cfa1ca9dSYoshinobu Inoue 
1186cfa1ca9dSYoshinobu Inoue #define	p(f, m) if (pim6stat.f || sflag <= 1) \
1187ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)pim6stat.f, plural(pim6stat.f))
1188ade9ccfeSMarcel Moolenaar 
1189ade9ccfeSMarcel Moolenaar 	p(pim6s_rcv_total, "\t{:received-packets/%ju} "
1190ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received}\n");
1191ade9ccfeSMarcel Moolenaar 	p(pim6s_rcv_tooshort, "\t{:dropped-too-short/%ju} "
1192ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received with too few bytes}\n");
1193ade9ccfeSMarcel Moolenaar 	p(pim6s_rcv_badsum, "\t{:dropped-bad-checksum/%ju} "
1194ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received with bad checksum}\n");
1195ade9ccfeSMarcel Moolenaar 	p(pim6s_rcv_badversion, "\t{:dropped-bad-version/%ju} "
1196ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received with bad version}\n");
1197ade9ccfeSMarcel Moolenaar 	p(pim6s_rcv_registers, "\t{:received-registers/%ju} "
1198ade9ccfeSMarcel Moolenaar 	    "{N:/register%s received}\n");
1199ade9ccfeSMarcel Moolenaar 	p(pim6s_rcv_badregisters, "\t{:received-bad-registers/%ju} "
1200ade9ccfeSMarcel Moolenaar 	    "{N:/bad register%s received}\n");
1201ade9ccfeSMarcel Moolenaar 	p(pim6s_snd_registers, "\t{:sent-registers/%ju} "
1202ade9ccfeSMarcel Moolenaar 	    "{N:/register%s sent}\n");
1203cfa1ca9dSYoshinobu Inoue #undef p
1204ade9ccfeSMarcel Moolenaar 	xo_close_container(name);
1205cfa1ca9dSYoshinobu Inoue }
1206cfa1ca9dSYoshinobu Inoue 
1207cfa1ca9dSYoshinobu Inoue /*
120833841545SHajimu UMEMOTO  * Dump raw ip6 statistics structure.
120933841545SHajimu UMEMOTO  */
121033841545SHajimu UMEMOTO void
1211feda1a43SJohn Baldwin rip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
121233841545SHajimu UMEMOTO {
12139eddb899SMark Johnston 	struct rip6stat rip6stat;
121433841545SHajimu UMEMOTO 	u_quad_t delivered;
121533841545SHajimu UMEMOTO 
12169eddb899SMark Johnston 	if (fetch_stats("net.inet6.ip6.rip6stats", off, &rip6stat,
12179eddb899SMark Johnston 	    sizeof(rip6stat), kread_counters) != 0)
121833841545SHajimu UMEMOTO 		return;
121933841545SHajimu UMEMOTO 
1220ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
1221ade9ccfeSMarcel Moolenaar 	xo_open_container(name);
122233841545SHajimu UMEMOTO 
122333841545SHajimu UMEMOTO #define	p(f, m) if (rip6stat.f || sflag <= 1) \
1224ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)rip6stat.f, plural(rip6stat.f))
1225ade9ccfeSMarcel Moolenaar 
1226ade9ccfeSMarcel Moolenaar 	p(rip6s_ipackets, "\t{:received-packets/%ju} "
1227ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received}\n");
1228ade9ccfeSMarcel Moolenaar 	p(rip6s_isum, "\t{:input-checksum-computation/%ju} "
1229ade9ccfeSMarcel Moolenaar 	    "{N:/checksum calculation%s on inbound}\n");
1230ade9ccfeSMarcel Moolenaar 	p(rip6s_badsum, "\t{:received-bad-checksum/%ju} "
1231ade9ccfeSMarcel Moolenaar 	    "{N:/message%s with bad checksum}\n");
1232ade9ccfeSMarcel Moolenaar 	p(rip6s_nosock, "\t{:dropped-no-socket/%ju} "
1233ade9ccfeSMarcel Moolenaar 	    "{N:/message%s dropped due to no socket}\n");
1234ade9ccfeSMarcel Moolenaar 	p(rip6s_nosockmcast, "\t{:dropped-multicast-no-socket/%ju} "
1235ade9ccfeSMarcel Moolenaar 	    "{N:/multicast message%s dropped due to no socket}\n");
1236ade9ccfeSMarcel Moolenaar 	p(rip6s_fullsock, "\t{:dropped-full-socket-buffer/%ju} "
1237ade9ccfeSMarcel Moolenaar 	    "{N:/message%s dropped due to full socket buffers}\n");
123833841545SHajimu UMEMOTO 	delivered = rip6stat.rip6s_ipackets -
123933841545SHajimu UMEMOTO 		    rip6stat.rip6s_badsum -
124033841545SHajimu UMEMOTO 		    rip6stat.rip6s_nosock -
124133841545SHajimu UMEMOTO 		    rip6stat.rip6s_nosockmcast -
124233841545SHajimu UMEMOTO 		    rip6stat.rip6s_fullsock;
124333841545SHajimu UMEMOTO 	if (delivered || sflag <= 1)
1244ade9ccfeSMarcel Moolenaar 		xo_emit("\t{:delivered-packets/%ju} {N:/delivered}\n",
1245ade9ccfeSMarcel Moolenaar 		    (uintmax_t)delivered);
1246ade9ccfeSMarcel Moolenaar 	p(rip6s_opackets, "\t{:sent-packets/%ju} "
1247ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s output}\n");
124833841545SHajimu UMEMOTO #undef p
1249ade9ccfeSMarcel Moolenaar 	xo_close_container(name);
125033841545SHajimu UMEMOTO }
125133841545SHajimu UMEMOTO 
125233841545SHajimu UMEMOTO /*
1253cfa1ca9dSYoshinobu Inoue  * Pretty print an Internet address (net address + port).
125465ea0024SAssar Westerlund  * Take numeric_addr and numeric_port into consideration.
1255cfa1ca9dSYoshinobu Inoue  */
1256cfa1ca9dSYoshinobu Inoue #define	GETSERVBYPORT6(port, proto, ret)\
1257cfa1ca9dSYoshinobu Inoue {\
1258cfa1ca9dSYoshinobu Inoue 	if (strcmp((proto), "tcp6") == 0)\
1259cfa1ca9dSYoshinobu Inoue 		(ret) = getservbyport((int)(port), "tcp");\
1260cfa1ca9dSYoshinobu Inoue 	else if (strcmp((proto), "udp6") == 0)\
1261cfa1ca9dSYoshinobu Inoue 		(ret) = getservbyport((int)(port), "udp");\
1262cfa1ca9dSYoshinobu Inoue 	else\
1263cfa1ca9dSYoshinobu Inoue 		(ret) = getservbyport((int)(port), (proto));\
1264cfa1ca9dSYoshinobu Inoue };
1265cfa1ca9dSYoshinobu Inoue 
1266cfa1ca9dSYoshinobu Inoue void
1267ade9ccfeSMarcel Moolenaar inet6print(const char *container, struct in6_addr *in6, int port,
1268ade9ccfeSMarcel Moolenaar     const char *proto, int numeric)
1269cfa1ca9dSYoshinobu Inoue {
1270cfa1ca9dSYoshinobu Inoue 	struct servent *sp = 0;
1271cfa1ca9dSYoshinobu Inoue 	char line[80], *cp;
1272cfa1ca9dSYoshinobu Inoue 	int width;
1273cfa1ca9dSYoshinobu Inoue 
1274ade9ccfeSMarcel Moolenaar 	if (container)
1275ade9ccfeSMarcel Moolenaar 		xo_open_container(container);
1276ade9ccfeSMarcel Moolenaar 
1277ade9ccfeSMarcel Moolenaar 	sprintf(line, "%.*s.", Wflag ? 39 : (Aflag && !numeric) ? 12 : 16,
1278ade9ccfeSMarcel Moolenaar 	    inet6name(in6));
1279b3608ae1SEd Schouten 	cp = strchr(line, '\0');
1280cfa1ca9dSYoshinobu Inoue 	if (!numeric && port)
1281cfa1ca9dSYoshinobu Inoue 		GETSERVBYPORT6(port, proto, sp);
1282cfa1ca9dSYoshinobu Inoue 	if (sp || port == 0)
1283bd2327cdSHajimu UMEMOTO 		sprintf(cp, "%.15s", sp ? sp->s_name : "*");
1284cfa1ca9dSYoshinobu Inoue 	else
1285cfa1ca9dSYoshinobu Inoue 		sprintf(cp, "%d", ntohs((u_short)port));
128670057abfSRuslan Ermilov 	width = Wflag ? 45 : Aflag ? 18 : 22;
1287ade9ccfeSMarcel Moolenaar 
1288ade9ccfeSMarcel Moolenaar 	xo_emit("{d:target/%-*.*s} ", width, width, line);
1289ade9ccfeSMarcel Moolenaar 
1290ade9ccfeSMarcel Moolenaar 	int alen = cp - line - 1, plen = strlen(cp) - 1;
1291ade9ccfeSMarcel Moolenaar 	xo_emit("{e:address/%*.*s}{e:port/%*.*s}", alen, alen, line, plen,
1292ade9ccfeSMarcel Moolenaar 	    plen, cp);
1293ade9ccfeSMarcel Moolenaar 
1294ade9ccfeSMarcel Moolenaar 	if (container)
1295ade9ccfeSMarcel Moolenaar 		xo_close_container(container);
1296cfa1ca9dSYoshinobu Inoue }
1297cfa1ca9dSYoshinobu Inoue 
1298cfa1ca9dSYoshinobu Inoue /*
1299cfa1ca9dSYoshinobu Inoue  * Construct an Internet address representation.
130065ea0024SAssar Westerlund  * If the numeric_addr has been supplied, give
1301cfa1ca9dSYoshinobu Inoue  * numeric value, otherwise try for symbolic name.
1302cfa1ca9dSYoshinobu Inoue  */
1303cfa1ca9dSYoshinobu Inoue 
1304cfa1ca9dSYoshinobu Inoue char *
13055e051718SAssar Westerlund inet6name(struct in6_addr *in6p)
1306cfa1ca9dSYoshinobu Inoue {
130784dde578SHiroki Sato 	struct sockaddr_in6 sin6;
130884dde578SHiroki Sato 	char hbuf[NI_MAXHOST], *cp;
1309cfa1ca9dSYoshinobu Inoue 	static char line[50];
1310d121b556SBrian Somers 	static char domain[MAXHOSTNAMELEN];
1311cfa1ca9dSYoshinobu Inoue 	static int first = 1;
131284dde578SHiroki Sato 	int flags, error;
1313cfa1ca9dSYoshinobu Inoue 
131484dde578SHiroki Sato 	if (IN6_IS_ADDR_UNSPECIFIED(in6p)) {
131584dde578SHiroki Sato 		strcpy(line, "*");
131684dde578SHiroki Sato 		return (line);
131784dde578SHiroki Sato 	}
131865ea0024SAssar Westerlund 	if (first && !numeric_addr) {
1319cfa1ca9dSYoshinobu Inoue 		first = 0;
1320cfa1ca9dSYoshinobu Inoue 		if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
1321b3608ae1SEd Schouten 		    (cp = strchr(domain, '.')))
1322cfa1ca9dSYoshinobu Inoue 			(void) strcpy(domain, cp + 1);
1323cfa1ca9dSYoshinobu Inoue 		else
1324cfa1ca9dSYoshinobu Inoue 			domain[0] = 0;
1325cfa1ca9dSYoshinobu Inoue 	}
132684dde578SHiroki Sato 	memset(&sin6, 0, sizeof(sin6));
132784dde578SHiroki Sato 	memcpy(&sin6.sin6_addr, in6p, sizeof(*in6p));
132884dde578SHiroki Sato 	sin6.sin6_family = AF_INET6;
132984dde578SHiroki Sato 	/* XXX: in6p.s6_addr[2] can contain scopeid. */
133084dde578SHiroki Sato 	in6_fillscopeid(&sin6);
133184dde578SHiroki Sato 	flags = (numeric_addr) ? NI_NUMERICHOST : 0;
133284dde578SHiroki Sato 	error = getnameinfo((struct sockaddr *)&sin6, sizeof(sin6), hbuf,
133384dde578SHiroki Sato 	    sizeof(hbuf), NULL, 0, flags);
133484dde578SHiroki Sato 	if (error == 0) {
133584dde578SHiroki Sato 		if ((flags & NI_NUMERICHOST) == 0 &&
133684dde578SHiroki Sato 		    (cp = strchr(hbuf, '.')) &&
1337cfa1ca9dSYoshinobu Inoue 		    !strcmp(cp + 1, domain))
1338cfa1ca9dSYoshinobu Inoue 			*cp = 0;
133984dde578SHiroki Sato 		strcpy(line, hbuf);
134084dde578SHiroki Sato 	} else {
134184dde578SHiroki Sato 		/* XXX: this should not happen. */
1342cfa1ca9dSYoshinobu Inoue 		sprintf(line, "%s",
134384dde578SHiroki Sato 			inet_ntop(AF_INET6, (void *)&sin6.sin6_addr, ntop_buf,
1344cfa1ca9dSYoshinobu Inoue 				sizeof(ntop_buf)));
134584dde578SHiroki Sato 	}
1346cfa1ca9dSYoshinobu Inoue 	return (line);
1347cfa1ca9dSYoshinobu Inoue }
1348d84a1df4SHajimu UMEMOTO #endif /*INET6*/
1349