xref: /freebsd/usr.bin/netstat/inet6.c (revision fbbd9655e5107c68e4e0146ff22b73d7350475bc)
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.
14*fbbd9655SWarner Losh  * 3. 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 
73cfa1ca9dSYoshinobu Inoue static char ntop_buf[INET6_ADDRSTRLEN];
74cfa1ca9dSYoshinobu Inoue 
75a01e3379SDavid Malone static	const char *ip6nh[] = {
76cfa1ca9dSYoshinobu Inoue 	"hop by hop",
77cfa1ca9dSYoshinobu Inoue 	"ICMP",
78cfa1ca9dSYoshinobu Inoue 	"IGMP",
79cfa1ca9dSYoshinobu Inoue 	"#3",
80cfa1ca9dSYoshinobu Inoue 	"IP",
81cfa1ca9dSYoshinobu Inoue 	"#5",
82cfa1ca9dSYoshinobu Inoue 	"TCP",
83cfa1ca9dSYoshinobu Inoue 	"#7",
84cfa1ca9dSYoshinobu Inoue 	"#8",
85cfa1ca9dSYoshinobu Inoue 	"#9",
86cfa1ca9dSYoshinobu Inoue 	"#10",
87cfa1ca9dSYoshinobu Inoue 	"#11",
88cfa1ca9dSYoshinobu Inoue 	"#12",
89cfa1ca9dSYoshinobu Inoue 	"#13",
90cfa1ca9dSYoshinobu Inoue 	"#14",
91cfa1ca9dSYoshinobu Inoue 	"#15",
92cfa1ca9dSYoshinobu Inoue 	"#16",
93cfa1ca9dSYoshinobu Inoue 	"UDP",
94cfa1ca9dSYoshinobu Inoue 	"#18",
95cfa1ca9dSYoshinobu Inoue 	"#19",
96cfa1ca9dSYoshinobu Inoue 	"#20",
97cfa1ca9dSYoshinobu Inoue 	"#21",
98cfa1ca9dSYoshinobu Inoue 	"IDP",
99cfa1ca9dSYoshinobu Inoue 	"#23",
100cfa1ca9dSYoshinobu Inoue 	"#24",
101cfa1ca9dSYoshinobu Inoue 	"#25",
102cfa1ca9dSYoshinobu Inoue 	"#26",
103cfa1ca9dSYoshinobu Inoue 	"#27",
104cfa1ca9dSYoshinobu Inoue 	"#28",
105cfa1ca9dSYoshinobu Inoue 	"TP",
106cfa1ca9dSYoshinobu Inoue 	"#30",
107cfa1ca9dSYoshinobu Inoue 	"#31",
108cfa1ca9dSYoshinobu Inoue 	"#32",
109cfa1ca9dSYoshinobu Inoue 	"#33",
110cfa1ca9dSYoshinobu Inoue 	"#34",
111cfa1ca9dSYoshinobu Inoue 	"#35",
112cfa1ca9dSYoshinobu Inoue 	"#36",
113cfa1ca9dSYoshinobu Inoue 	"#37",
114cfa1ca9dSYoshinobu Inoue 	"#38",
115cfa1ca9dSYoshinobu Inoue 	"#39",
116cfa1ca9dSYoshinobu Inoue 	"#40",
117cfa1ca9dSYoshinobu Inoue 	"IP6",
118cfa1ca9dSYoshinobu Inoue 	"#42",
119cfa1ca9dSYoshinobu Inoue 	"routing",
120cfa1ca9dSYoshinobu Inoue 	"fragment",
121cfa1ca9dSYoshinobu Inoue 	"#45",
122cfa1ca9dSYoshinobu Inoue 	"#46",
123cfa1ca9dSYoshinobu Inoue 	"#47",
124cfa1ca9dSYoshinobu Inoue 	"#48",
125cfa1ca9dSYoshinobu Inoue 	"#49",
126cfa1ca9dSYoshinobu Inoue 	"ESP",
127cfa1ca9dSYoshinobu Inoue 	"AH",
128cfa1ca9dSYoshinobu Inoue 	"#52",
129cfa1ca9dSYoshinobu Inoue 	"#53",
130cfa1ca9dSYoshinobu Inoue 	"#54",
131cfa1ca9dSYoshinobu Inoue 	"#55",
132cfa1ca9dSYoshinobu Inoue 	"#56",
133cfa1ca9dSYoshinobu Inoue 	"#57",
134cfa1ca9dSYoshinobu Inoue 	"ICMP6",
135cfa1ca9dSYoshinobu Inoue 	"no next header",
136cfa1ca9dSYoshinobu Inoue 	"destination option",
137cfa1ca9dSYoshinobu Inoue 	"#61",
138cb60a8deSHajimu UMEMOTO 	"mobility",
139cfa1ca9dSYoshinobu Inoue 	"#63",
140cfa1ca9dSYoshinobu Inoue 	"#64",
141cfa1ca9dSYoshinobu Inoue 	"#65",
142cfa1ca9dSYoshinobu Inoue 	"#66",
143cfa1ca9dSYoshinobu Inoue 	"#67",
144cfa1ca9dSYoshinobu Inoue 	"#68",
145cfa1ca9dSYoshinobu Inoue 	"#69",
146cfa1ca9dSYoshinobu Inoue 	"#70",
147cfa1ca9dSYoshinobu Inoue 	"#71",
148cfa1ca9dSYoshinobu Inoue 	"#72",
149cfa1ca9dSYoshinobu Inoue 	"#73",
150cfa1ca9dSYoshinobu Inoue 	"#74",
151cfa1ca9dSYoshinobu Inoue 	"#75",
152cfa1ca9dSYoshinobu Inoue 	"#76",
153cfa1ca9dSYoshinobu Inoue 	"#77",
154cfa1ca9dSYoshinobu Inoue 	"#78",
155cfa1ca9dSYoshinobu Inoue 	"#79",
156cfa1ca9dSYoshinobu Inoue 	"ISOIP",
157cfa1ca9dSYoshinobu Inoue 	"#81",
158cfa1ca9dSYoshinobu Inoue 	"#82",
159cfa1ca9dSYoshinobu Inoue 	"#83",
160cfa1ca9dSYoshinobu Inoue 	"#84",
161cfa1ca9dSYoshinobu Inoue 	"#85",
162cfa1ca9dSYoshinobu Inoue 	"#86",
163cfa1ca9dSYoshinobu Inoue 	"#87",
164cfa1ca9dSYoshinobu Inoue 	"#88",
16532cd1d96SJun-ichiro itojun Hagino 	"OSPF",
166cfa1ca9dSYoshinobu Inoue 	"#80",
167cfa1ca9dSYoshinobu Inoue 	"#91",
168cfa1ca9dSYoshinobu Inoue 	"#92",
169cfa1ca9dSYoshinobu Inoue 	"#93",
170cfa1ca9dSYoshinobu Inoue 	"#94",
171cfa1ca9dSYoshinobu Inoue 	"#95",
172cfa1ca9dSYoshinobu Inoue 	"#96",
173cfa1ca9dSYoshinobu Inoue 	"Ethernet",
174cfa1ca9dSYoshinobu Inoue 	"#98",
175cfa1ca9dSYoshinobu Inoue 	"#99",
176cfa1ca9dSYoshinobu Inoue 	"#100",
177cfa1ca9dSYoshinobu Inoue 	"#101",
178cfa1ca9dSYoshinobu Inoue 	"#102",
179cfa1ca9dSYoshinobu Inoue 	"PIM",
180cfa1ca9dSYoshinobu Inoue 	"#104",
181cfa1ca9dSYoshinobu Inoue 	"#105",
182cfa1ca9dSYoshinobu Inoue 	"#106",
183cfa1ca9dSYoshinobu Inoue 	"#107",
184cfa1ca9dSYoshinobu Inoue 	"#108",
185cfa1ca9dSYoshinobu Inoue 	"#109",
186cfa1ca9dSYoshinobu Inoue 	"#110",
187cfa1ca9dSYoshinobu Inoue 	"#111",
188cfa1ca9dSYoshinobu Inoue 	"#112",
189cfa1ca9dSYoshinobu Inoue 	"#113",
190cfa1ca9dSYoshinobu Inoue 	"#114",
191cfa1ca9dSYoshinobu Inoue 	"#115",
192cfa1ca9dSYoshinobu Inoue 	"#116",
193cfa1ca9dSYoshinobu Inoue 	"#117",
194cfa1ca9dSYoshinobu Inoue 	"#118",
195cfa1ca9dSYoshinobu Inoue 	"#119",
196cfa1ca9dSYoshinobu Inoue 	"#120",
197cfa1ca9dSYoshinobu Inoue 	"#121",
198cfa1ca9dSYoshinobu Inoue 	"#122",
199cfa1ca9dSYoshinobu Inoue 	"#123",
200cfa1ca9dSYoshinobu Inoue 	"#124",
201cfa1ca9dSYoshinobu Inoue 	"#125",
202cfa1ca9dSYoshinobu Inoue 	"#126",
203cfa1ca9dSYoshinobu Inoue 	"#127",
204cfa1ca9dSYoshinobu Inoue 	"#128",
205cfa1ca9dSYoshinobu Inoue 	"#129",
206cfa1ca9dSYoshinobu Inoue 	"#130",
207cfa1ca9dSYoshinobu Inoue 	"#131",
208e0694d2fSMichael Tuexen 	"SCTP",
209cfa1ca9dSYoshinobu Inoue 	"#133",
210cfa1ca9dSYoshinobu Inoue 	"#134",
211cfa1ca9dSYoshinobu Inoue 	"#135",
212e0694d2fSMichael Tuexen 	"UDPLite",
213cfa1ca9dSYoshinobu Inoue 	"#137",
214cfa1ca9dSYoshinobu Inoue 	"#138",
215cfa1ca9dSYoshinobu Inoue 	"#139",
216cfa1ca9dSYoshinobu Inoue 	"#140",
217cfa1ca9dSYoshinobu Inoue 	"#141",
218cfa1ca9dSYoshinobu Inoue 	"#142",
219cfa1ca9dSYoshinobu Inoue 	"#143",
220cfa1ca9dSYoshinobu Inoue 	"#144",
221cfa1ca9dSYoshinobu Inoue 	"#145",
222cfa1ca9dSYoshinobu Inoue 	"#146",
223cfa1ca9dSYoshinobu Inoue 	"#147",
224cfa1ca9dSYoshinobu Inoue 	"#148",
225cfa1ca9dSYoshinobu Inoue 	"#149",
226cfa1ca9dSYoshinobu Inoue 	"#150",
227cfa1ca9dSYoshinobu Inoue 	"#151",
228cfa1ca9dSYoshinobu Inoue 	"#152",
229cfa1ca9dSYoshinobu Inoue 	"#153",
230cfa1ca9dSYoshinobu Inoue 	"#154",
231cfa1ca9dSYoshinobu Inoue 	"#155",
232cfa1ca9dSYoshinobu Inoue 	"#156",
233cfa1ca9dSYoshinobu Inoue 	"#157",
234cfa1ca9dSYoshinobu Inoue 	"#158",
235cfa1ca9dSYoshinobu Inoue 	"#159",
236cfa1ca9dSYoshinobu Inoue 	"#160",
237cfa1ca9dSYoshinobu Inoue 	"#161",
238cfa1ca9dSYoshinobu Inoue 	"#162",
239cfa1ca9dSYoshinobu Inoue 	"#163",
240cfa1ca9dSYoshinobu Inoue 	"#164",
241cfa1ca9dSYoshinobu Inoue 	"#165",
242cfa1ca9dSYoshinobu Inoue 	"#166",
243cfa1ca9dSYoshinobu Inoue 	"#167",
244cfa1ca9dSYoshinobu Inoue 	"#168",
245cfa1ca9dSYoshinobu Inoue 	"#169",
246cfa1ca9dSYoshinobu Inoue 	"#170",
247cfa1ca9dSYoshinobu Inoue 	"#171",
248cfa1ca9dSYoshinobu Inoue 	"#172",
249cfa1ca9dSYoshinobu Inoue 	"#173",
250cfa1ca9dSYoshinobu Inoue 	"#174",
251cfa1ca9dSYoshinobu Inoue 	"#175",
252cfa1ca9dSYoshinobu Inoue 	"#176",
253cfa1ca9dSYoshinobu Inoue 	"#177",
254cfa1ca9dSYoshinobu Inoue 	"#178",
255cfa1ca9dSYoshinobu Inoue 	"#179",
256cfa1ca9dSYoshinobu Inoue 	"#180",
257cfa1ca9dSYoshinobu Inoue 	"#181",
258cfa1ca9dSYoshinobu Inoue 	"#182",
259cfa1ca9dSYoshinobu Inoue 	"#183",
260cfa1ca9dSYoshinobu Inoue 	"#184",
261cfa1ca9dSYoshinobu Inoue 	"#185",
262cfa1ca9dSYoshinobu Inoue 	"#186",
263cfa1ca9dSYoshinobu Inoue 	"#187",
264cfa1ca9dSYoshinobu Inoue 	"#188",
265cfa1ca9dSYoshinobu Inoue 	"#189",
266cfa1ca9dSYoshinobu Inoue 	"#180",
267cfa1ca9dSYoshinobu Inoue 	"#191",
268cfa1ca9dSYoshinobu Inoue 	"#192",
269cfa1ca9dSYoshinobu Inoue 	"#193",
270cfa1ca9dSYoshinobu Inoue 	"#194",
271cfa1ca9dSYoshinobu Inoue 	"#195",
272cfa1ca9dSYoshinobu Inoue 	"#196",
273cfa1ca9dSYoshinobu Inoue 	"#197",
274cfa1ca9dSYoshinobu Inoue 	"#198",
275cfa1ca9dSYoshinobu Inoue 	"#199",
276cfa1ca9dSYoshinobu Inoue 	"#200",
277cfa1ca9dSYoshinobu Inoue 	"#201",
278cfa1ca9dSYoshinobu Inoue 	"#202",
279cfa1ca9dSYoshinobu Inoue 	"#203",
280cfa1ca9dSYoshinobu Inoue 	"#204",
281cfa1ca9dSYoshinobu Inoue 	"#205",
282cfa1ca9dSYoshinobu Inoue 	"#206",
283cfa1ca9dSYoshinobu Inoue 	"#207",
284cfa1ca9dSYoshinobu Inoue 	"#208",
285cfa1ca9dSYoshinobu Inoue 	"#209",
286cfa1ca9dSYoshinobu Inoue 	"#210",
287cfa1ca9dSYoshinobu Inoue 	"#211",
288cfa1ca9dSYoshinobu Inoue 	"#212",
289cfa1ca9dSYoshinobu Inoue 	"#213",
290cfa1ca9dSYoshinobu Inoue 	"#214",
291cfa1ca9dSYoshinobu Inoue 	"#215",
292cfa1ca9dSYoshinobu Inoue 	"#216",
293cfa1ca9dSYoshinobu Inoue 	"#217",
294cfa1ca9dSYoshinobu Inoue 	"#218",
295cfa1ca9dSYoshinobu Inoue 	"#219",
296cfa1ca9dSYoshinobu Inoue 	"#220",
297cfa1ca9dSYoshinobu Inoue 	"#221",
298cfa1ca9dSYoshinobu Inoue 	"#222",
299cfa1ca9dSYoshinobu Inoue 	"#223",
300cfa1ca9dSYoshinobu Inoue 	"#224",
301cfa1ca9dSYoshinobu Inoue 	"#225",
302cfa1ca9dSYoshinobu Inoue 	"#226",
303cfa1ca9dSYoshinobu Inoue 	"#227",
304cfa1ca9dSYoshinobu Inoue 	"#228",
305cfa1ca9dSYoshinobu Inoue 	"#229",
306cfa1ca9dSYoshinobu Inoue 	"#230",
307cfa1ca9dSYoshinobu Inoue 	"#231",
308cfa1ca9dSYoshinobu Inoue 	"#232",
309cfa1ca9dSYoshinobu Inoue 	"#233",
310cfa1ca9dSYoshinobu Inoue 	"#234",
311cfa1ca9dSYoshinobu Inoue 	"#235",
312cfa1ca9dSYoshinobu Inoue 	"#236",
313cfa1ca9dSYoshinobu Inoue 	"#237",
314cfa1ca9dSYoshinobu Inoue 	"#238",
315cfa1ca9dSYoshinobu Inoue 	"#239",
316cfa1ca9dSYoshinobu Inoue 	"#240",
317cfa1ca9dSYoshinobu Inoue 	"#241",
318cfa1ca9dSYoshinobu Inoue 	"#242",
319cfa1ca9dSYoshinobu Inoue 	"#243",
320cfa1ca9dSYoshinobu Inoue 	"#244",
321cfa1ca9dSYoshinobu Inoue 	"#245",
322cfa1ca9dSYoshinobu Inoue 	"#246",
323cfa1ca9dSYoshinobu Inoue 	"#247",
324cfa1ca9dSYoshinobu Inoue 	"#248",
325cfa1ca9dSYoshinobu Inoue 	"#249",
326cfa1ca9dSYoshinobu Inoue 	"#250",
327cfa1ca9dSYoshinobu Inoue 	"#251",
328cfa1ca9dSYoshinobu Inoue 	"#252",
329cfa1ca9dSYoshinobu Inoue 	"#253",
330cfa1ca9dSYoshinobu Inoue 	"#254",
331cfa1ca9dSYoshinobu Inoue 	"#255",
332cfa1ca9dSYoshinobu Inoue };
333cfa1ca9dSYoshinobu Inoue 
334321ae07fSPhilippe Charnier static const char *srcrule_str[] = {
3354ef2dc8bSHajimu UMEMOTO 	"first candidate",
3364ef2dc8bSHajimu UMEMOTO 	"same address",
3374ef2dc8bSHajimu UMEMOTO 	"appropriate scope",
3384ef2dc8bSHajimu UMEMOTO 	"deprecated address",
3394ef2dc8bSHajimu UMEMOTO 	"home address",
3404ef2dc8bSHajimu UMEMOTO 	"outgoing interface",
3414ef2dc8bSHajimu UMEMOTO 	"matching label",
3424ef2dc8bSHajimu UMEMOTO 	"public/temporary address",
3434ef2dc8bSHajimu UMEMOTO 	"alive interface",
344ccc53de9SAndrey V. Elsukov 	"better virtual status",
3455dbfa43fSAndrey V. Elsukov 	"preferred source",
3464ef2dc8bSHajimu UMEMOTO 	"rule #11",
3474ef2dc8bSHajimu UMEMOTO 	"rule #12",
3484ef2dc8bSHajimu UMEMOTO 	"rule #13",
3494ef2dc8bSHajimu UMEMOTO 	"longest match",
3504ef2dc8bSHajimu UMEMOTO 	"rule #15",
3514ef2dc8bSHajimu UMEMOTO };
3524ef2dc8bSHajimu UMEMOTO 
353cfa1ca9dSYoshinobu Inoue /*
354cfa1ca9dSYoshinobu Inoue  * Dump IP6 statistics structure.
355cfa1ca9dSYoshinobu Inoue  */
356cfa1ca9dSYoshinobu Inoue void
357feda1a43SJohn Baldwin ip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
358cfa1ca9dSYoshinobu Inoue {
3599eddb899SMark Johnston 	struct ip6stat ip6stat;
360cfa1ca9dSYoshinobu Inoue 	int first, i;
361cfa1ca9dSYoshinobu Inoue 
3629eddb899SMark Johnston 	if (fetch_stats("net.inet6.ip6.stats", off, &ip6stat,
3639eddb899SMark Johnston 	    sizeof(ip6stat), kread_counters) != 0)
3646eec3af9SPoul-Henning Kamp 		return;
3659eddb899SMark Johnston 
366ade9ccfeSMarcel Moolenaar 	xo_open_container(name);
367ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
368cfa1ca9dSYoshinobu Inoue 
369cfa1ca9dSYoshinobu Inoue #define	p(f, m) if (ip6stat.f || sflag <= 1) \
370ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)ip6stat.f, plural(ip6stat.f))
371cfa1ca9dSYoshinobu Inoue #define	p1a(f, m) if (ip6stat.f || sflag <= 1) \
372ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)ip6stat.f)
373cfa1ca9dSYoshinobu Inoue 
374ade9ccfeSMarcel Moolenaar 	p(ip6s_total, "\t{:received-packets/%ju} "
375ade9ccfeSMarcel Moolenaar 	    "{N:/total packet%s received}\n");
376ade9ccfeSMarcel Moolenaar 	p1a(ip6s_toosmall, "\t{:dropped-below-minimum-size/%ju} "
377ade9ccfeSMarcel Moolenaar 	    "{N:/with size smaller than minimum}\n");
378ade9ccfeSMarcel Moolenaar 	p1a(ip6s_tooshort, "\t{:dropped-short-packets/%ju} "
379ade9ccfeSMarcel Moolenaar 	    "{N:/with data size < data length}\n");
380ade9ccfeSMarcel Moolenaar 	p1a(ip6s_badoptions, "\t{:dropped-bad-options/%ju} "
381ade9ccfeSMarcel Moolenaar 	    "{N:/with bad options}\n");
382ade9ccfeSMarcel Moolenaar 	p1a(ip6s_badvers, "\t{:dropped-bad-version/%ju} "
383ade9ccfeSMarcel Moolenaar 	    "{N:/with incorrect version number}\n");
384ade9ccfeSMarcel Moolenaar 	p(ip6s_fragments, "\t{:received-fragments/%ju} "
385ade9ccfeSMarcel Moolenaar 	    "{N:/fragment%s received}\n");
386ade9ccfeSMarcel Moolenaar 	p(ip6s_fragdropped, "\t{:dropped-fragment/%ju} "
387ade9ccfeSMarcel Moolenaar 	    "{N:/fragment%s dropped (dup or out of space)}\n");
388ade9ccfeSMarcel Moolenaar 	p(ip6s_fragtimeout, "\t{:dropped-fragment-after-timeout/%ju} "
389ade9ccfeSMarcel Moolenaar 	    "{N:/fragment%s dropped after timeout}\n");
390ade9ccfeSMarcel Moolenaar 	p(ip6s_fragoverflow, "\t{:dropped-fragments-overflow/%ju} "
391ade9ccfeSMarcel Moolenaar 	    "{N:/fragment%s that exceeded limit}\n");
392ade9ccfeSMarcel Moolenaar 	p(ip6s_reassembled, "\t{:reassembled-packets/%ju} "
393ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s reassembled ok}\n");
394ade9ccfeSMarcel Moolenaar 	p(ip6s_delivered, "\t{:received-local-packets/%ju} "
395ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s for this host}\n");
396ade9ccfeSMarcel Moolenaar 	p(ip6s_forward, "\t{:forwarded-packets/%ju} "
397ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s forwarded}\n");
398ade9ccfeSMarcel Moolenaar 	p(ip6s_cantforward, "\t{:packets-not-forwardable/%ju} "
399ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s not forwardable}\n");
400ade9ccfeSMarcel Moolenaar 	p(ip6s_redirectsent, "\t{:sent-redirects/%ju} "
401ade9ccfeSMarcel Moolenaar 	    "{N:/redirect%s sent}\n");
402ade9ccfeSMarcel Moolenaar 	p(ip6s_localout, "\t{:sent-packets/%ju} "
403ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s sent from this host}\n");
404ade9ccfeSMarcel Moolenaar 	p(ip6s_rawout, "\t{:send-packets-fabricated-header/%ju} "
405ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s sent with fabricated ip header}\n");
406ade9ccfeSMarcel Moolenaar 	p(ip6s_odropped, "\t{:discard-no-mbufs/%ju} "
407ade9ccfeSMarcel Moolenaar 	    "{N:/output packet%s dropped due to no bufs, etc.}\n");
408ade9ccfeSMarcel Moolenaar 	p(ip6s_noroute, "\t{:discard-no-route/%ju} "
409ade9ccfeSMarcel Moolenaar 	    "{N:/output packet%s discarded due to no route}\n");
410ade9ccfeSMarcel Moolenaar 	p(ip6s_fragmented, "\t{:sent-fragments/%ju} "
411ade9ccfeSMarcel Moolenaar 	    "{N:/output datagram%s fragmented}\n");
412ade9ccfeSMarcel Moolenaar 	p(ip6s_ofragments, "\t{:fragments-created/%ju} "
413ade9ccfeSMarcel Moolenaar 	    "{N:/fragment%s created}\n");
414ade9ccfeSMarcel Moolenaar 	p(ip6s_cantfrag, "\t{:discard-cannot-fragment/%ju} "
415ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s that can't be fragmented}\n");
416ade9ccfeSMarcel Moolenaar 	p(ip6s_badscope, "\t{:discard-scope-violations/%ju} "
417ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s that violated scope rules}\n");
418ade9ccfeSMarcel Moolenaar 	p(ip6s_notmember, "\t{:multicast-no-join-packets/%ju} "
419ade9ccfeSMarcel Moolenaar 	    "{N:/multicast packet%s which we don't join}\n");
420b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_HDRCNT; i++)
421cfa1ca9dSYoshinobu Inoue 		if (ip6stat.ip6s_nxthist[i] != 0) {
422cfa1ca9dSYoshinobu Inoue 			if (first) {
423ade9ccfeSMarcel Moolenaar 				xo_emit("\t{T:Input histogram}:\n");
424ade9ccfeSMarcel Moolenaar 				xo_open_list("input-histogram");
425cfa1ca9dSYoshinobu Inoue 				first = 0;
426cfa1ca9dSYoshinobu Inoue 			}
427ade9ccfeSMarcel Moolenaar 			xo_open_instance("input-histogram");
428ade9ccfeSMarcel Moolenaar 			xo_emit("\t\t{k:name/%s}: {:count/%ju}\n", ip6nh[i],
4297b95a1ebSYaroslav Tykhiy 			    (uintmax_t)ip6stat.ip6s_nxthist[i]);
430ade9ccfeSMarcel Moolenaar 			xo_close_instance("input-histogram");
431cfa1ca9dSYoshinobu Inoue 		}
432ade9ccfeSMarcel Moolenaar 	if (!first)
433ade9ccfeSMarcel Moolenaar 		xo_close_list("input-histogram");
434ade9ccfeSMarcel Moolenaar 
435ade9ccfeSMarcel Moolenaar 	xo_open_container("mbuf-statistics");
436ade9ccfeSMarcel Moolenaar 	xo_emit("\t{T:Mbuf statistics}:\n");
437ade9ccfeSMarcel Moolenaar 	xo_emit("\t\t{:one-mbuf/%ju} {N:/one mbuf}\n",
438ade9ccfeSMarcel Moolenaar 	    (uintmax_t)ip6stat.ip6s_m1);
439b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_M2MMAX; i++) {
4407d56d374SYoshinobu Inoue 		char ifbuf[IFNAMSIZ];
441cfa1ca9dSYoshinobu Inoue 		if (ip6stat.ip6s_m2m[i] != 0) {
442cfa1ca9dSYoshinobu Inoue 			if (first) {
443ade9ccfeSMarcel Moolenaar 				xo_emit("\t\t{N:two or more mbuf}:\n");
444ade9ccfeSMarcel Moolenaar 				xo_open_list("mbuf-data");
445cfa1ca9dSYoshinobu Inoue 				first = 0;
446cfa1ca9dSYoshinobu Inoue 			}
447ade9ccfeSMarcel Moolenaar 			xo_open_instance("mbuf-data");
448ade9ccfeSMarcel Moolenaar 			xo_emit("\t\t\t{k:name/%s}= {:count/%ju}\n",
449cfa1ca9dSYoshinobu Inoue 			    if_indextoname(i, ifbuf),
4507b95a1ebSYaroslav Tykhiy 			    (uintmax_t)ip6stat.ip6s_m2m[i]);
451ade9ccfeSMarcel Moolenaar 			xo_close_instance("mbuf-data");
452cfa1ca9dSYoshinobu Inoue 		}
453cfa1ca9dSYoshinobu Inoue 	}
454ade9ccfeSMarcel Moolenaar 	if (!first)
455ade9ccfeSMarcel Moolenaar 		xo_close_list("mbuf-data");
456ade9ccfeSMarcel Moolenaar 	xo_emit("\t\t{:one-extra-mbuf/%ju} {N:one ext mbuf}\n",
4577b95a1ebSYaroslav Tykhiy 	    (uintmax_t)ip6stat.ip6s_mext1);
458ade9ccfeSMarcel Moolenaar 	xo_emit("\t\t{:two-or-more-extra-mbufs/%ju} "
459ade9ccfeSMarcel Moolenaar 	    "{N:/two or more ext mbuf}\n", (uintmax_t)ip6stat.ip6s_mext2m);
460ade9ccfeSMarcel Moolenaar 	xo_close_container("mbuf-statistics");
461ade9ccfeSMarcel Moolenaar 
462ade9ccfeSMarcel Moolenaar 	p(ip6s_exthdrtoolong, "\t{:dropped-header-too-long/%ju} "
463ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s whose headers are not contiguous}\n");
464ade9ccfeSMarcel Moolenaar 	p(ip6s_nogif, "\t{:discard-tunnel-no-gif/%ju} "
465ade9ccfeSMarcel Moolenaar 	    "{N:/tunneling packet%s that can't find gif}\n");
466ade9ccfeSMarcel Moolenaar 	p(ip6s_toomanyhdr, "\t{:dropped-too-many-headers/%ju} "
467ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s discarded because of too many headers}\n");
46832cd1d96SJun-ichiro itojun Hagino 
46932cd1d96SJun-ichiro itojun Hagino 	/* for debugging source address selection */
47032cd1d96SJun-ichiro itojun Hagino #define	PRINT_SCOPESTAT(s,i) do {\
47132cd1d96SJun-ichiro itojun Hagino 		switch(i) { /* XXX hardcoding in each case */\
47232cd1d96SJun-ichiro itojun Hagino 		case 1:\
473ade9ccfeSMarcel Moolenaar 			p(s, "\t\t{ke:name/interface-locals}{:count/%ju} " \
474ade9ccfeSMarcel Moolenaar 			  "{N:/interface-local%s}\n");	\
47532cd1d96SJun-ichiro itojun Hagino 			break;\
47632cd1d96SJun-ichiro itojun Hagino 		case 2:\
477ade9ccfeSMarcel Moolenaar 			p(s,"\t\t{ke:name/link-locals}{:count/%ju} " \
478ade9ccfeSMarcel Moolenaar 			"{N:/link-local%s}\n"); \
47932cd1d96SJun-ichiro itojun Hagino 			break;\
48032cd1d96SJun-ichiro itojun Hagino 		case 5:\
481ade9ccfeSMarcel Moolenaar 			p(s,"\t\t{ke:name/site-locals}{:count/%ju} " \
482ade9ccfeSMarcel Moolenaar 			  "{N:/site-local%s}\n");\
48332cd1d96SJun-ichiro itojun Hagino 			break;\
48432cd1d96SJun-ichiro itojun Hagino 		case 14:\
485ade9ccfeSMarcel Moolenaar 			p(s,"\t\t{ke:name/globals}{:count/%ju} " \
486ade9ccfeSMarcel Moolenaar 			  "{N:/global%s}\n");\
48732cd1d96SJun-ichiro itojun Hagino 			break;\
48832cd1d96SJun-ichiro itojun Hagino 		default:\
4895ad497eeSMichael Tuexen 			xo_emit("\t\t{qke:name/%#x}{:count/%ju} " \
4905ad497eeSMichael Tuexen 				"{N:/addresses scope=%#x}\n",\
491ade9ccfeSMarcel Moolenaar 				i, (uintmax_t)ip6stat.s, i);	   \
49232cd1d96SJun-ichiro itojun Hagino 		}\
49332cd1d96SJun-ichiro itojun Hagino 	} while (0);
49432cd1d96SJun-ichiro itojun Hagino 
495ade9ccfeSMarcel Moolenaar 	xo_open_container("source-address-selection");
496ade9ccfeSMarcel Moolenaar 	p(ip6s_sources_none, "\t{:address-selection-failures/%ju} "
497ade9ccfeSMarcel Moolenaar 	    "{N:/failure%s of source address selection}\n");
498ade9ccfeSMarcel Moolenaar 
499b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
50032cd1d96SJun-ichiro itojun Hagino 		if (ip6stat.ip6s_sources_sameif[i]) {
50132cd1d96SJun-ichiro itojun Hagino 			if (first) {
502ade9ccfeSMarcel Moolenaar 				xo_open_list("outgoing-interface");
503ade9ccfeSMarcel Moolenaar 				xo_emit("\tsource addresses on an outgoing "
504ade9ccfeSMarcel Moolenaar 				    "I/F\n");
50532cd1d96SJun-ichiro itojun Hagino 				first = 0;
50632cd1d96SJun-ichiro itojun Hagino 			}
507ade9ccfeSMarcel Moolenaar 			xo_open_instance("outgoing-interface");
50832cd1d96SJun-ichiro itojun Hagino 			PRINT_SCOPESTAT(ip6s_sources_sameif[i], i);
509ade9ccfeSMarcel Moolenaar 			xo_close_instance("outgoing-interface");
51032cd1d96SJun-ichiro itojun Hagino 		}
51132cd1d96SJun-ichiro itojun Hagino 	}
512ade9ccfeSMarcel Moolenaar 	if (!first)
513ade9ccfeSMarcel Moolenaar 		xo_close_list("outgoing-interface");
514ade9ccfeSMarcel Moolenaar 
515b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
51632cd1d96SJun-ichiro itojun Hagino 		if (ip6stat.ip6s_sources_otherif[i]) {
51732cd1d96SJun-ichiro itojun Hagino 			if (first) {
518ade9ccfeSMarcel Moolenaar 				xo_open_list("non-outgoing-interface");
519ade9ccfeSMarcel Moolenaar 				xo_emit("\tsource addresses on a non-outgoing "
520ade9ccfeSMarcel Moolenaar 				    "I/F\n");
52132cd1d96SJun-ichiro itojun Hagino 				first = 0;
52232cd1d96SJun-ichiro itojun Hagino 			}
523ade9ccfeSMarcel Moolenaar 			xo_open_instance("non-outgoing-interface");
52432cd1d96SJun-ichiro itojun Hagino 			PRINT_SCOPESTAT(ip6s_sources_otherif[i], i);
525ade9ccfeSMarcel Moolenaar 			xo_close_instance("non-outgoing-interface");
52632cd1d96SJun-ichiro itojun Hagino 		}
52732cd1d96SJun-ichiro itojun Hagino 	}
528ade9ccfeSMarcel Moolenaar 	if (!first)
529ade9ccfeSMarcel Moolenaar 		xo_close_list("non-outgoing-interface");
530ade9ccfeSMarcel Moolenaar 
531b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
53232cd1d96SJun-ichiro itojun Hagino 		if (ip6stat.ip6s_sources_samescope[i]) {
53332cd1d96SJun-ichiro itojun Hagino 			if (first) {
534ade9ccfeSMarcel Moolenaar 				xo_open_list("same-source");
535ade9ccfeSMarcel Moolenaar 				xo_emit("\tsource addresses of same scope\n");
53632cd1d96SJun-ichiro itojun Hagino 				first = 0;
53732cd1d96SJun-ichiro itojun Hagino 			}
538ade9ccfeSMarcel Moolenaar 			xo_open_instance("same-source");
53932cd1d96SJun-ichiro itojun Hagino 			PRINT_SCOPESTAT(ip6s_sources_samescope[i], i);
540ade9ccfeSMarcel Moolenaar 			xo_close_instance("same-source");
54132cd1d96SJun-ichiro itojun Hagino 		}
54232cd1d96SJun-ichiro itojun Hagino 	}
543ade9ccfeSMarcel Moolenaar 	if (!first)
544ade9ccfeSMarcel Moolenaar 		xo_close_list("same-source");
545ade9ccfeSMarcel Moolenaar 
546b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
54732cd1d96SJun-ichiro itojun Hagino 		if (ip6stat.ip6s_sources_otherscope[i]) {
54832cd1d96SJun-ichiro itojun Hagino 			if (first) {
549ade9ccfeSMarcel Moolenaar 				xo_open_list("different-scope");
550ade9ccfeSMarcel Moolenaar 				xo_emit("\tsource addresses of a different "
551ade9ccfeSMarcel Moolenaar 				    "scope\n");
55232cd1d96SJun-ichiro itojun Hagino 				first = 0;
55332cd1d96SJun-ichiro itojun Hagino 			}
554ade9ccfeSMarcel Moolenaar 			xo_open_instance("different-scope");
55532cd1d96SJun-ichiro itojun Hagino 			PRINT_SCOPESTAT(ip6s_sources_otherscope[i], i);
556ade9ccfeSMarcel Moolenaar 			xo_close_instance("different-scope");
55732cd1d96SJun-ichiro itojun Hagino 		}
55832cd1d96SJun-ichiro itojun Hagino 	}
559ade9ccfeSMarcel Moolenaar 	if (!first)
560ade9ccfeSMarcel Moolenaar 		xo_close_list("different-scope");
561ade9ccfeSMarcel Moolenaar 
562b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
56332cd1d96SJun-ichiro itojun Hagino 		if (ip6stat.ip6s_sources_deprecated[i]) {
56432cd1d96SJun-ichiro itojun Hagino 			if (first) {
565ade9ccfeSMarcel Moolenaar 				xo_open_list("deprecated-source");
566ade9ccfeSMarcel Moolenaar 				xo_emit("\tdeprecated source addresses\n");
56732cd1d96SJun-ichiro itojun Hagino 				first = 0;
56832cd1d96SJun-ichiro itojun Hagino 			}
569ade9ccfeSMarcel Moolenaar 			xo_open_instance("deprecated-source");
57032cd1d96SJun-ichiro itojun Hagino 			PRINT_SCOPESTAT(ip6s_sources_deprecated[i], i);
571ade9ccfeSMarcel Moolenaar 			xo_close_instance("deprecated-source");
57232cd1d96SJun-ichiro itojun Hagino 		}
57332cd1d96SJun-ichiro itojun Hagino 	}
574ade9ccfeSMarcel Moolenaar 	if (!first)
575ade9ccfeSMarcel Moolenaar 		xo_close_list("deprecated-source");
57632cd1d96SJun-ichiro itojun Hagino 
577ade9ccfeSMarcel Moolenaar 	for (first = 1, i = 0; i < IP6S_RULESMAX; i++) {
578ade9ccfeSMarcel Moolenaar 		if (ip6stat.ip6s_sources_rule[i]) {
579ade9ccfeSMarcel Moolenaar 			if (first) {
580ade9ccfeSMarcel Moolenaar 				xo_open_list("rules-applied");
581ade9ccfeSMarcel Moolenaar 				xo_emit("\t{T:Source addresses selection "
582ade9ccfeSMarcel Moolenaar 				    "rule applied}:\n");
583ade9ccfeSMarcel Moolenaar 				first = 0;
584ade9ccfeSMarcel Moolenaar 			}
585ade9ccfeSMarcel Moolenaar 			xo_open_instance("rules-applied");
586ade9ccfeSMarcel Moolenaar 			xo_emit("\t\t{ke:name/%s}{:count/%ju} {d:name/%s}\n",
587ade9ccfeSMarcel Moolenaar 			    srcrule_str[i],
5887b95a1ebSYaroslav Tykhiy 			    (uintmax_t)ip6stat.ip6s_sources_rule[i],
5894ef2dc8bSHajimu UMEMOTO 			    srcrule_str[i]);
590ade9ccfeSMarcel Moolenaar 			xo_close_instance("rules-applied");
5914ef2dc8bSHajimu UMEMOTO 		}
592ade9ccfeSMarcel Moolenaar 	}
593ade9ccfeSMarcel Moolenaar 	if (!first)
594ade9ccfeSMarcel Moolenaar 		xo_close_list("rules-applied");
595ade9ccfeSMarcel Moolenaar 
596ade9ccfeSMarcel Moolenaar 	xo_close_container("source-address-selection");
597ade9ccfeSMarcel Moolenaar 
598cfa1ca9dSYoshinobu Inoue #undef p
59932cd1d96SJun-ichiro itojun Hagino #undef p1a
600ade9ccfeSMarcel Moolenaar 	xo_close_container(name);
601cfa1ca9dSYoshinobu Inoue }
602cfa1ca9dSYoshinobu Inoue 
603cfa1ca9dSYoshinobu Inoue /*
604cfa1ca9dSYoshinobu Inoue  * Dump IPv6 per-interface statistics based on RFC 2465.
605cfa1ca9dSYoshinobu Inoue  */
606cfa1ca9dSYoshinobu Inoue void
6075e051718SAssar Westerlund ip6_ifstats(char *ifname)
608cfa1ca9dSYoshinobu Inoue {
609cfa1ca9dSYoshinobu Inoue 	struct in6_ifreq ifr;
610cfa1ca9dSYoshinobu Inoue 	int s;
611ade9ccfeSMarcel Moolenaar 
612cfa1ca9dSYoshinobu Inoue #define	p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1)	\
613ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)ifr.ifr_ifru.ifru_stat.f,		\
614ade9ccfeSMarcel Moolenaar 	    plural(ifr.ifr_ifru.ifru_stat.f))
615cfa1ca9dSYoshinobu Inoue 
616cfa1ca9dSYoshinobu Inoue 	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
617ade9ccfeSMarcel Moolenaar 		xo_warn("Warning: socket(AF_INET6)");
618cfa1ca9dSYoshinobu Inoue 		return;
619cfa1ca9dSYoshinobu Inoue 	}
620cfa1ca9dSYoshinobu Inoue 
621cfa1ca9dSYoshinobu Inoue 	strcpy(ifr.ifr_name, ifname);
622cfa1ca9dSYoshinobu Inoue 	if (ioctl(s, SIOCGIFSTAT_IN6, (char *)&ifr) < 0) {
623d77e67e4SMark Johnston 		if (errno != EPFNOSUPPORT)
624ade9ccfeSMarcel Moolenaar 			xo_warn("Warning: ioctl(SIOCGIFSTAT_IN6)");
625cfa1ca9dSYoshinobu Inoue 		goto end;
626cfa1ca9dSYoshinobu Inoue 	}
627cfa1ca9dSYoshinobu Inoue 
628ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/ip6 on %s}:\n", ifr.ifr_name);
629ade9ccfeSMarcel Moolenaar 
630ade9ccfeSMarcel Moolenaar 	xo_open_instance("ip6-interface-statistics");
631ade9ccfeSMarcel Moolenaar 	xo_emit("{ke:name/%s}", ifr.ifr_name);
632ade9ccfeSMarcel Moolenaar 
633ade9ccfeSMarcel Moolenaar 	p(ifs6_in_receive, "\t{:received-packets/%ju} "
634ade9ccfeSMarcel Moolenaar 	    "{N:/total input datagram%s}\n");
635ade9ccfeSMarcel Moolenaar 	p(ifs6_in_hdrerr, "\t{:dropped-invalid-header/%ju} "
636ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s with invalid header received}\n");
637ade9ccfeSMarcel Moolenaar 	p(ifs6_in_toobig, "\t{:dropped-mtu-exceeded/%ju} "
638ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s exceeded MTU received}\n");
639ade9ccfeSMarcel Moolenaar 	p(ifs6_in_noroute, "\t{:dropped-no-route/%ju} "
640ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s with no route received}\n");
641ade9ccfeSMarcel Moolenaar 	p(ifs6_in_addrerr, "\t{:dropped-invalid-destination/%ju} "
642ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s with invalid dst received}\n");
643ade9ccfeSMarcel Moolenaar 	p(ifs6_in_protounknown, "\t{:dropped-unknown-protocol/%ju} "
644ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s with unknown proto received}\n");
645ade9ccfeSMarcel Moolenaar 	p(ifs6_in_truncated, "\t{:dropped-truncated/%ju} "
646ade9ccfeSMarcel Moolenaar 	    "{N:/truncated datagram%s received}\n");
647ade9ccfeSMarcel Moolenaar 	p(ifs6_in_discard, "\t{:dropped-discarded/%ju} "
648ade9ccfeSMarcel Moolenaar 	    "{N:/input datagram%s discarded}\n");
649ade9ccfeSMarcel Moolenaar  	p(ifs6_in_deliver, "\t{:received-valid-packets/%ju} "
650ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s delivered to an upper layer protocol}\n");
651ade9ccfeSMarcel Moolenaar 	p(ifs6_out_forward, "\t{:sent-forwarded/%ju} "
652ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s forwarded to this interface}\n");
653ade9ccfeSMarcel Moolenaar  	p(ifs6_out_request, "\t{:sent-packets/%ju} "
654ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s sent from an upper layer protocol}\n");
655ade9ccfeSMarcel Moolenaar 	p(ifs6_out_discard, "\t{:discard-packets/%ju} "
656ade9ccfeSMarcel Moolenaar 	    "{N:/total discarded output datagram%s}\n");
657ade9ccfeSMarcel Moolenaar 	p(ifs6_out_fragok, "\t{:discard-fragments/%ju} "
658ade9ccfeSMarcel Moolenaar 	    "{N:/output datagram%s fragmented}\n");
659ade9ccfeSMarcel Moolenaar 	p(ifs6_out_fragfail, "\t{:fragments-failed/%ju} "
660ade9ccfeSMarcel Moolenaar 	    "{N:/output datagram%s failed on fragment}\n");
661ade9ccfeSMarcel Moolenaar 	p(ifs6_out_fragcreat, "\t{:fragments-created/%ju} "
662ade9ccfeSMarcel Moolenaar 	    "{N:/output datagram%s succeeded on fragment}\n");
663ade9ccfeSMarcel Moolenaar 	p(ifs6_reass_reqd, "\t{:reassembly-required/%ju} "
664ade9ccfeSMarcel Moolenaar 	    "{N:/incoming datagram%s fragmented}\n");
665ade9ccfeSMarcel Moolenaar 	p(ifs6_reass_ok, "\t{:reassembled-packets/%ju} "
666ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s reassembled}\n");
667ade9ccfeSMarcel Moolenaar 	p(ifs6_reass_fail, "\t{:reassembly-failed/%ju} "
668ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s failed on reassembly}\n");
669ade9ccfeSMarcel Moolenaar 	p(ifs6_in_mcast, "\t{:received-multicast/%ju} "
670ade9ccfeSMarcel Moolenaar 	    "{N:/multicast datagram%s received}\n");
671ade9ccfeSMarcel Moolenaar 	p(ifs6_out_mcast, "\t{:sent-multicast/%ju} "
672ade9ccfeSMarcel Moolenaar 	    "{N:/multicast datagram%s sent}\n");
673cfa1ca9dSYoshinobu Inoue 
674cfa1ca9dSYoshinobu Inoue  end:
675ade9ccfeSMarcel Moolenaar 	xo_close_instance("ip6-interface-statistics");
676cfa1ca9dSYoshinobu Inoue  	close(s);
677cfa1ca9dSYoshinobu Inoue 
678cfa1ca9dSYoshinobu Inoue #undef p
679cfa1ca9dSYoshinobu Inoue }
680cfa1ca9dSYoshinobu Inoue 
681a01e3379SDavid Malone static	const char *icmp6names[] = {
682cfa1ca9dSYoshinobu Inoue 	"#0",
683cfa1ca9dSYoshinobu Inoue 	"unreach",
684cfa1ca9dSYoshinobu Inoue 	"packet too big",
685cfa1ca9dSYoshinobu Inoue 	"time exceed",
686cfa1ca9dSYoshinobu Inoue 	"parameter problem",
687cfa1ca9dSYoshinobu Inoue 	"#5",
688cfa1ca9dSYoshinobu Inoue 	"#6",
689cfa1ca9dSYoshinobu Inoue 	"#7",
690cfa1ca9dSYoshinobu Inoue 	"#8",
691cfa1ca9dSYoshinobu Inoue 	"#9",
692cfa1ca9dSYoshinobu Inoue 	"#10",
693cfa1ca9dSYoshinobu Inoue 	"#11",
694cfa1ca9dSYoshinobu Inoue 	"#12",
695cfa1ca9dSYoshinobu Inoue 	"#13",
696cfa1ca9dSYoshinobu Inoue 	"#14",
697cfa1ca9dSYoshinobu Inoue 	"#15",
698cfa1ca9dSYoshinobu Inoue 	"#16",
699cfa1ca9dSYoshinobu Inoue 	"#17",
700cfa1ca9dSYoshinobu Inoue 	"#18",
701cfa1ca9dSYoshinobu Inoue 	"#19",
702cfa1ca9dSYoshinobu Inoue 	"#20",
703cfa1ca9dSYoshinobu Inoue 	"#21",
704cfa1ca9dSYoshinobu Inoue 	"#22",
705cfa1ca9dSYoshinobu Inoue 	"#23",
706cfa1ca9dSYoshinobu Inoue 	"#24",
707cfa1ca9dSYoshinobu Inoue 	"#25",
708cfa1ca9dSYoshinobu Inoue 	"#26",
709cfa1ca9dSYoshinobu Inoue 	"#27",
710cfa1ca9dSYoshinobu Inoue 	"#28",
711cfa1ca9dSYoshinobu Inoue 	"#29",
712cfa1ca9dSYoshinobu Inoue 	"#30",
713cfa1ca9dSYoshinobu Inoue 	"#31",
714cfa1ca9dSYoshinobu Inoue 	"#32",
715cfa1ca9dSYoshinobu Inoue 	"#33",
716cfa1ca9dSYoshinobu Inoue 	"#34",
717cfa1ca9dSYoshinobu Inoue 	"#35",
718cfa1ca9dSYoshinobu Inoue 	"#36",
719cfa1ca9dSYoshinobu Inoue 	"#37",
720cfa1ca9dSYoshinobu Inoue 	"#38",
721cfa1ca9dSYoshinobu Inoue 	"#39",
722cfa1ca9dSYoshinobu Inoue 	"#40",
723cfa1ca9dSYoshinobu Inoue 	"#41",
724cfa1ca9dSYoshinobu Inoue 	"#42",
725cfa1ca9dSYoshinobu Inoue 	"#43",
726cfa1ca9dSYoshinobu Inoue 	"#44",
727cfa1ca9dSYoshinobu Inoue 	"#45",
728cfa1ca9dSYoshinobu Inoue 	"#46",
729cfa1ca9dSYoshinobu Inoue 	"#47",
730cfa1ca9dSYoshinobu Inoue 	"#48",
731cfa1ca9dSYoshinobu Inoue 	"#49",
732cfa1ca9dSYoshinobu Inoue 	"#50",
733cfa1ca9dSYoshinobu Inoue 	"#51",
734cfa1ca9dSYoshinobu Inoue 	"#52",
735cfa1ca9dSYoshinobu Inoue 	"#53",
736cfa1ca9dSYoshinobu Inoue 	"#54",
737cfa1ca9dSYoshinobu Inoue 	"#55",
738cfa1ca9dSYoshinobu Inoue 	"#56",
739cfa1ca9dSYoshinobu Inoue 	"#57",
740cfa1ca9dSYoshinobu Inoue 	"#58",
741cfa1ca9dSYoshinobu Inoue 	"#59",
742cfa1ca9dSYoshinobu Inoue 	"#60",
743cfa1ca9dSYoshinobu Inoue 	"#61",
744cfa1ca9dSYoshinobu Inoue 	"#62",
745cfa1ca9dSYoshinobu Inoue 	"#63",
746cfa1ca9dSYoshinobu Inoue 	"#64",
747cfa1ca9dSYoshinobu Inoue 	"#65",
748cfa1ca9dSYoshinobu Inoue 	"#66",
749cfa1ca9dSYoshinobu Inoue 	"#67",
750cfa1ca9dSYoshinobu Inoue 	"#68",
751cfa1ca9dSYoshinobu Inoue 	"#69",
752cfa1ca9dSYoshinobu Inoue 	"#70",
753cfa1ca9dSYoshinobu Inoue 	"#71",
754cfa1ca9dSYoshinobu Inoue 	"#72",
755cfa1ca9dSYoshinobu Inoue 	"#73",
756cfa1ca9dSYoshinobu Inoue 	"#74",
757cfa1ca9dSYoshinobu Inoue 	"#75",
758cfa1ca9dSYoshinobu Inoue 	"#76",
759cfa1ca9dSYoshinobu Inoue 	"#77",
760cfa1ca9dSYoshinobu Inoue 	"#78",
761cfa1ca9dSYoshinobu Inoue 	"#79",
762cfa1ca9dSYoshinobu Inoue 	"#80",
763cfa1ca9dSYoshinobu Inoue 	"#81",
764cfa1ca9dSYoshinobu Inoue 	"#82",
765cfa1ca9dSYoshinobu Inoue 	"#83",
766cfa1ca9dSYoshinobu Inoue 	"#84",
767cfa1ca9dSYoshinobu Inoue 	"#85",
768cfa1ca9dSYoshinobu Inoue 	"#86",
769cfa1ca9dSYoshinobu Inoue 	"#87",
770cfa1ca9dSYoshinobu Inoue 	"#88",
771cfa1ca9dSYoshinobu Inoue 	"#89",
772cfa1ca9dSYoshinobu Inoue 	"#80",
773cfa1ca9dSYoshinobu Inoue 	"#91",
774cfa1ca9dSYoshinobu Inoue 	"#92",
775cfa1ca9dSYoshinobu Inoue 	"#93",
776cfa1ca9dSYoshinobu Inoue 	"#94",
777cfa1ca9dSYoshinobu Inoue 	"#95",
778cfa1ca9dSYoshinobu Inoue 	"#96",
779cfa1ca9dSYoshinobu Inoue 	"#97",
780cfa1ca9dSYoshinobu Inoue 	"#98",
781cfa1ca9dSYoshinobu Inoue 	"#99",
782cfa1ca9dSYoshinobu Inoue 	"#100",
783cfa1ca9dSYoshinobu Inoue 	"#101",
784cfa1ca9dSYoshinobu Inoue 	"#102",
785cfa1ca9dSYoshinobu Inoue 	"#103",
786cfa1ca9dSYoshinobu Inoue 	"#104",
787cfa1ca9dSYoshinobu Inoue 	"#105",
788cfa1ca9dSYoshinobu Inoue 	"#106",
789cfa1ca9dSYoshinobu Inoue 	"#107",
790cfa1ca9dSYoshinobu Inoue 	"#108",
791cfa1ca9dSYoshinobu Inoue 	"#109",
792cfa1ca9dSYoshinobu Inoue 	"#110",
793cfa1ca9dSYoshinobu Inoue 	"#111",
794cfa1ca9dSYoshinobu Inoue 	"#112",
795cfa1ca9dSYoshinobu Inoue 	"#113",
796cfa1ca9dSYoshinobu Inoue 	"#114",
797cfa1ca9dSYoshinobu Inoue 	"#115",
798cfa1ca9dSYoshinobu Inoue 	"#116",
799cfa1ca9dSYoshinobu Inoue 	"#117",
800cfa1ca9dSYoshinobu Inoue 	"#118",
801cfa1ca9dSYoshinobu Inoue 	"#119",
802cfa1ca9dSYoshinobu Inoue 	"#120",
803cfa1ca9dSYoshinobu Inoue 	"#121",
804cfa1ca9dSYoshinobu Inoue 	"#122",
805cfa1ca9dSYoshinobu Inoue 	"#123",
806cfa1ca9dSYoshinobu Inoue 	"#124",
807cfa1ca9dSYoshinobu Inoue 	"#125",
808cfa1ca9dSYoshinobu Inoue 	"#126",
809cfa1ca9dSYoshinobu Inoue 	"#127",
810cfa1ca9dSYoshinobu Inoue 	"echo",
811cfa1ca9dSYoshinobu Inoue 	"echo reply",
812cfa1ca9dSYoshinobu Inoue 	"multicast listener query",
8137d9d64baSBruce M Simpson 	"MLDv1 listener report",
8147d9d64baSBruce M Simpson 	"MLDv1 listener done",
815cfa1ca9dSYoshinobu Inoue 	"router solicitation",
8166ab55b23SDima Dorfman 	"router advertisement",
817cfa1ca9dSYoshinobu Inoue 	"neighbor solicitation",
8186ab55b23SDima Dorfman 	"neighbor advertisement",
819cfa1ca9dSYoshinobu Inoue 	"redirect",
820cfa1ca9dSYoshinobu Inoue 	"router renumbering",
821cfa1ca9dSYoshinobu Inoue 	"node information request",
822cfa1ca9dSYoshinobu Inoue 	"node information reply",
823fd555639SMunechika SUMIKAWA 	"inverse neighbor solicitation",
824fd555639SMunechika SUMIKAWA 	"inverse neighbor advertisement",
8257d9d64baSBruce M Simpson 	"MLDv2 listener report",
826cfa1ca9dSYoshinobu Inoue 	"#144",
827cfa1ca9dSYoshinobu Inoue 	"#145",
828cfa1ca9dSYoshinobu Inoue 	"#146",
829cfa1ca9dSYoshinobu Inoue 	"#147",
830cfa1ca9dSYoshinobu Inoue 	"#148",
831cfa1ca9dSYoshinobu Inoue 	"#149",
832cfa1ca9dSYoshinobu Inoue 	"#150",
833cfa1ca9dSYoshinobu Inoue 	"#151",
834cfa1ca9dSYoshinobu Inoue 	"#152",
835cfa1ca9dSYoshinobu Inoue 	"#153",
836cfa1ca9dSYoshinobu Inoue 	"#154",
837cfa1ca9dSYoshinobu Inoue 	"#155",
838cfa1ca9dSYoshinobu Inoue 	"#156",
839cfa1ca9dSYoshinobu Inoue 	"#157",
840cfa1ca9dSYoshinobu Inoue 	"#158",
841cfa1ca9dSYoshinobu Inoue 	"#159",
842cfa1ca9dSYoshinobu Inoue 	"#160",
843cfa1ca9dSYoshinobu Inoue 	"#161",
844cfa1ca9dSYoshinobu Inoue 	"#162",
845cfa1ca9dSYoshinobu Inoue 	"#163",
846cfa1ca9dSYoshinobu Inoue 	"#164",
847cfa1ca9dSYoshinobu Inoue 	"#165",
848cfa1ca9dSYoshinobu Inoue 	"#166",
849cfa1ca9dSYoshinobu Inoue 	"#167",
850cfa1ca9dSYoshinobu Inoue 	"#168",
851cfa1ca9dSYoshinobu Inoue 	"#169",
852cfa1ca9dSYoshinobu Inoue 	"#170",
853cfa1ca9dSYoshinobu Inoue 	"#171",
854cfa1ca9dSYoshinobu Inoue 	"#172",
855cfa1ca9dSYoshinobu Inoue 	"#173",
856cfa1ca9dSYoshinobu Inoue 	"#174",
857cfa1ca9dSYoshinobu Inoue 	"#175",
858cfa1ca9dSYoshinobu Inoue 	"#176",
859cfa1ca9dSYoshinobu Inoue 	"#177",
860cfa1ca9dSYoshinobu Inoue 	"#178",
861cfa1ca9dSYoshinobu Inoue 	"#179",
862cfa1ca9dSYoshinobu Inoue 	"#180",
863cfa1ca9dSYoshinobu Inoue 	"#181",
864cfa1ca9dSYoshinobu Inoue 	"#182",
865cfa1ca9dSYoshinobu Inoue 	"#183",
866cfa1ca9dSYoshinobu Inoue 	"#184",
867cfa1ca9dSYoshinobu Inoue 	"#185",
868cfa1ca9dSYoshinobu Inoue 	"#186",
869cfa1ca9dSYoshinobu Inoue 	"#187",
870cfa1ca9dSYoshinobu Inoue 	"#188",
871cfa1ca9dSYoshinobu Inoue 	"#189",
872cfa1ca9dSYoshinobu Inoue 	"#180",
873cfa1ca9dSYoshinobu Inoue 	"#191",
874cfa1ca9dSYoshinobu Inoue 	"#192",
875cfa1ca9dSYoshinobu Inoue 	"#193",
876cfa1ca9dSYoshinobu Inoue 	"#194",
877cfa1ca9dSYoshinobu Inoue 	"#195",
878cfa1ca9dSYoshinobu Inoue 	"#196",
879cfa1ca9dSYoshinobu Inoue 	"#197",
880cfa1ca9dSYoshinobu Inoue 	"#198",
881cfa1ca9dSYoshinobu Inoue 	"#199",
882cfa1ca9dSYoshinobu Inoue 	"#200",
883cfa1ca9dSYoshinobu Inoue 	"#201",
884cfa1ca9dSYoshinobu Inoue 	"#202",
885cfa1ca9dSYoshinobu Inoue 	"#203",
886cfa1ca9dSYoshinobu Inoue 	"#204",
887cfa1ca9dSYoshinobu Inoue 	"#205",
888cfa1ca9dSYoshinobu Inoue 	"#206",
889cfa1ca9dSYoshinobu Inoue 	"#207",
890cfa1ca9dSYoshinobu Inoue 	"#208",
891cfa1ca9dSYoshinobu Inoue 	"#209",
892cfa1ca9dSYoshinobu Inoue 	"#210",
893cfa1ca9dSYoshinobu Inoue 	"#211",
894cfa1ca9dSYoshinobu Inoue 	"#212",
895cfa1ca9dSYoshinobu Inoue 	"#213",
896cfa1ca9dSYoshinobu Inoue 	"#214",
897cfa1ca9dSYoshinobu Inoue 	"#215",
898cfa1ca9dSYoshinobu Inoue 	"#216",
899cfa1ca9dSYoshinobu Inoue 	"#217",
900cfa1ca9dSYoshinobu Inoue 	"#218",
901cfa1ca9dSYoshinobu Inoue 	"#219",
902cfa1ca9dSYoshinobu Inoue 	"#220",
903cfa1ca9dSYoshinobu Inoue 	"#221",
904cfa1ca9dSYoshinobu Inoue 	"#222",
905cfa1ca9dSYoshinobu Inoue 	"#223",
906cfa1ca9dSYoshinobu Inoue 	"#224",
907cfa1ca9dSYoshinobu Inoue 	"#225",
908cfa1ca9dSYoshinobu Inoue 	"#226",
909cfa1ca9dSYoshinobu Inoue 	"#227",
910cfa1ca9dSYoshinobu Inoue 	"#228",
911cfa1ca9dSYoshinobu Inoue 	"#229",
912cfa1ca9dSYoshinobu Inoue 	"#230",
913cfa1ca9dSYoshinobu Inoue 	"#231",
914cfa1ca9dSYoshinobu Inoue 	"#232",
915cfa1ca9dSYoshinobu Inoue 	"#233",
916cfa1ca9dSYoshinobu Inoue 	"#234",
917cfa1ca9dSYoshinobu Inoue 	"#235",
918cfa1ca9dSYoshinobu Inoue 	"#236",
919cfa1ca9dSYoshinobu Inoue 	"#237",
920cfa1ca9dSYoshinobu Inoue 	"#238",
921cfa1ca9dSYoshinobu Inoue 	"#239",
922cfa1ca9dSYoshinobu Inoue 	"#240",
923cfa1ca9dSYoshinobu Inoue 	"#241",
924cfa1ca9dSYoshinobu Inoue 	"#242",
925cfa1ca9dSYoshinobu Inoue 	"#243",
926cfa1ca9dSYoshinobu Inoue 	"#244",
927cfa1ca9dSYoshinobu Inoue 	"#245",
928cfa1ca9dSYoshinobu Inoue 	"#246",
929cfa1ca9dSYoshinobu Inoue 	"#247",
930cfa1ca9dSYoshinobu Inoue 	"#248",
931cfa1ca9dSYoshinobu Inoue 	"#249",
932cfa1ca9dSYoshinobu Inoue 	"#250",
933cfa1ca9dSYoshinobu Inoue 	"#251",
934cfa1ca9dSYoshinobu Inoue 	"#252",
935cfa1ca9dSYoshinobu Inoue 	"#253",
936cfa1ca9dSYoshinobu Inoue 	"#254",
937cfa1ca9dSYoshinobu Inoue 	"#255",
938cfa1ca9dSYoshinobu Inoue };
939cfa1ca9dSYoshinobu Inoue 
940cfa1ca9dSYoshinobu Inoue /*
941cfa1ca9dSYoshinobu Inoue  * Dump ICMP6 statistics.
942cfa1ca9dSYoshinobu Inoue  */
943cfa1ca9dSYoshinobu Inoue void
944feda1a43SJohn Baldwin icmp6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
945cfa1ca9dSYoshinobu Inoue {
9469eddb899SMark Johnston 	struct icmp6stat icmp6stat;
947241667c4SMark Murray 	int i, first;
948cfa1ca9dSYoshinobu Inoue 
9499eddb899SMark Johnston 	if (fetch_stats("net.inet6.icmp6.stats", off, &icmp6stat,
9509eddb899SMark Johnston 	    sizeof(icmp6stat), kread_counters) != 0)
951cfa1ca9dSYoshinobu Inoue 		return;
952feda1a43SJohn Baldwin 
953ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
954ade9ccfeSMarcel Moolenaar 	xo_open_container(name);
955cfa1ca9dSYoshinobu Inoue 
956cfa1ca9dSYoshinobu Inoue #define	p(f, m) if (icmp6stat.f || sflag <= 1) \
957ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)icmp6stat.f, plural(icmp6stat.f))
9583ed817f1SMaxim Konovalov #define	p_5(f, m) if (icmp6stat.f || sflag <= 1) \
959ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)icmp6stat.f)
960cfa1ca9dSYoshinobu Inoue 
961ade9ccfeSMarcel Moolenaar 	p(icp6s_error, "\t{:icmp6-calls/%ju} "
962ade9ccfeSMarcel Moolenaar 	    "{N:/call%s to icmp6_error}\n");
963ade9ccfeSMarcel Moolenaar 	p(icp6s_canterror, "\t{:errors-not-generated-from-message/%ju} "
964ade9ccfeSMarcel Moolenaar 	    "{N:/error%s not generated in response to an icmp6 message}\n");
965ade9ccfeSMarcel Moolenaar 	p(icp6s_toofreq, "\t{:errors-discarded-by-rate-limitation/%ju} "
966ade9ccfeSMarcel Moolenaar 	    "{N:/error%s not generated because of rate limitation}\n");
967241667c4SMark Murray #define	NELEM (int)(sizeof(icmp6stat.icp6s_outhist)/sizeof(icmp6stat.icp6s_outhist[0]))
968fd555639SMunechika SUMIKAWA 	for (first = 1, i = 0; i < NELEM; i++)
969cfa1ca9dSYoshinobu Inoue 		if (icmp6stat.icp6s_outhist[i] != 0) {
970cfa1ca9dSYoshinobu Inoue 			if (first) {
971ade9ccfeSMarcel Moolenaar 				xo_open_list("output-histogram");
972ade9ccfeSMarcel Moolenaar 				xo_emit("\t{T:Output histogram}:\n");
973cfa1ca9dSYoshinobu Inoue 				first = 0;
974cfa1ca9dSYoshinobu Inoue 			}
975ade9ccfeSMarcel Moolenaar 			xo_open_instance("output-histogram");
976ade9ccfeSMarcel Moolenaar 			xo_emit("\t\t{k:name/%s}: {:count/%ju}\n",
977ade9ccfeSMarcel Moolenaar 			    icmp6names[i],
9787b95a1ebSYaroslav Tykhiy 			    (uintmax_t)icmp6stat.icp6s_outhist[i]);
979ade9ccfeSMarcel Moolenaar 			xo_close_instance("output-histogram");
980cfa1ca9dSYoshinobu Inoue 		}
981ade9ccfeSMarcel Moolenaar 	if (!first)
982ade9ccfeSMarcel Moolenaar 		xo_close_list("output-histogram");
983fd555639SMunechika SUMIKAWA #undef NELEM
984ade9ccfeSMarcel Moolenaar 
985ade9ccfeSMarcel Moolenaar 	p(icp6s_badcode, "\t{:dropped-bad-code/%ju} "
986ade9ccfeSMarcel Moolenaar 	    "{N:/message%s with bad code fields}\n");
987ade9ccfeSMarcel Moolenaar 	p(icp6s_tooshort, "\t{:dropped-too-short/%ju} "
988ade9ccfeSMarcel Moolenaar 	    "{N:/message%s < minimum length}\n");
989ade9ccfeSMarcel Moolenaar 	p(icp6s_checksum, "\t{:dropped-bad-checksum/%ju} "
990ade9ccfeSMarcel Moolenaar 	    "{N:/bad checksum%s}\n");
991ade9ccfeSMarcel Moolenaar 	p(icp6s_badlen, "\t{:dropped-bad-length/%ju} "
992ade9ccfeSMarcel Moolenaar 	    "{N:/message%s with bad length}\n");
993241667c4SMark Murray #define	NELEM (int)(sizeof(icmp6stat.icp6s_inhist)/sizeof(icmp6stat.icp6s_inhist[0]))
994fd555639SMunechika SUMIKAWA 	for (first = 1, i = 0; i < NELEM; i++)
995cfa1ca9dSYoshinobu Inoue 		if (icmp6stat.icp6s_inhist[i] != 0) {
996cfa1ca9dSYoshinobu Inoue 			if (first) {
997ade9ccfeSMarcel Moolenaar 				xo_open_list("input-histogram");
998ade9ccfeSMarcel Moolenaar 				xo_emit("\t{T:Input histogram}:\n");
999cfa1ca9dSYoshinobu Inoue 				first = 0;
1000cfa1ca9dSYoshinobu Inoue 			}
1001ade9ccfeSMarcel Moolenaar 			xo_open_instance("input-histogram");
1002ade9ccfeSMarcel Moolenaar 			xo_emit("\t\t{k:name/%s}: {:count/%ju}\n",
1003ade9ccfeSMarcel Moolenaar 			    icmp6names[i],
10047b95a1ebSYaroslav Tykhiy 			    (uintmax_t)icmp6stat.icp6s_inhist[i]);
1005ade9ccfeSMarcel Moolenaar 			xo_close_instance("input-histogram");
1006cfa1ca9dSYoshinobu Inoue 		}
1007ade9ccfeSMarcel Moolenaar 	if (!first)
1008ade9ccfeSMarcel Moolenaar 		xo_close_list("input-histogram");
1009fd555639SMunechika SUMIKAWA #undef NELEM
1010ade9ccfeSMarcel Moolenaar 	xo_emit("\t{T:Histogram of error messages to be generated}:\n");
1011ade9ccfeSMarcel Moolenaar 	xo_open_container("errors");
1012ade9ccfeSMarcel Moolenaar 	p_5(icp6s_odst_unreach_noroute, "\t\t{:no-route/%ju} "
1013ade9ccfeSMarcel Moolenaar 	    "{N:/no route}\n");
1014ade9ccfeSMarcel Moolenaar 	p_5(icp6s_odst_unreach_admin, "\t\t{:admin-prohibited/%ju} "
1015ade9ccfeSMarcel Moolenaar 	    "{N:/administratively prohibited}\n");
1016ade9ccfeSMarcel Moolenaar 	p_5(icp6s_odst_unreach_beyondscope, "\t\t{:beyond-scope/%ju} "
1017ade9ccfeSMarcel Moolenaar 	    "{N:/beyond scope}\n");
1018ade9ccfeSMarcel Moolenaar 	p_5(icp6s_odst_unreach_addr, "\t\t{:address-unreachable/%ju} "
1019ade9ccfeSMarcel Moolenaar 	    "{N:/address unreachable}\n");
1020ade9ccfeSMarcel Moolenaar 	p_5(icp6s_odst_unreach_noport, "\t\t{:port-unreachable/%ju} "
1021ade9ccfeSMarcel Moolenaar 	    "{N:/port unreachable}\n");
1022ade9ccfeSMarcel Moolenaar 	p_5(icp6s_opacket_too_big, "\t\t{:packet-too-big/%ju} "
1023ade9ccfeSMarcel Moolenaar 	    "{N:/packet too big}\n");
1024ade9ccfeSMarcel Moolenaar 	p_5(icp6s_otime_exceed_transit, "\t\t{:time-exceed-transmit/%ju} "
1025ade9ccfeSMarcel Moolenaar 	    "{N:/time exceed transit}\n");
1026ade9ccfeSMarcel Moolenaar 	p_5(icp6s_otime_exceed_reassembly, "\t\t{:time-exceed-reassembly/%ju} "
1027ade9ccfeSMarcel Moolenaar 	    "{N:/time exceed reassembly}\n");
1028ade9ccfeSMarcel Moolenaar 	p_5(icp6s_oparamprob_header, "\t\t{:bad-header/%ju} "
1029ade9ccfeSMarcel Moolenaar 	    "{N:/erroneous header field}\n");
1030ade9ccfeSMarcel Moolenaar 	p_5(icp6s_oparamprob_nextheader, "\t\t{:bad-next-header/%ju} "
1031ade9ccfeSMarcel Moolenaar 	    "{N:/unrecognized next header}\n");
1032ade9ccfeSMarcel Moolenaar 	p_5(icp6s_oparamprob_option, "\t\t{:bad-option/%ju} "
1033ade9ccfeSMarcel Moolenaar 	    "{N:/unrecognized option}\n");
1034ade9ccfeSMarcel Moolenaar 	p_5(icp6s_oredirect, "\t\t{:redirects/%ju} "
1035ade9ccfeSMarcel Moolenaar 	    "{N:/redirect}\n");
1036ade9ccfeSMarcel Moolenaar 	p_5(icp6s_ounknown, "\t\t{:unknown/%ju} {N:unknown}\n");
103732cd1d96SJun-ichiro itojun Hagino 
1038ade9ccfeSMarcel Moolenaar 	p(icp6s_reflect, "\t{:reflect/%ju} "
1039ade9ccfeSMarcel Moolenaar 	    "{N:/message response%s generated}\n");
1040ade9ccfeSMarcel Moolenaar 	p(icp6s_nd_toomanyopt, "\t{:too-many-nd-options/%ju} "
1041ade9ccfeSMarcel Moolenaar 	    "{N:/message%s with too many ND options}\n");
1042ade9ccfeSMarcel Moolenaar 	p(icp6s_nd_badopt, "\t{:bad-nd-options/%ju} "
1043ade9ccfeSMarcel Moolenaar 	    "{N:/message%s with bad ND options}\n");
1044ade9ccfeSMarcel Moolenaar 	p(icp6s_badns, "\t{:bad-neighbor-solicitation/%ju} "
1045ade9ccfeSMarcel Moolenaar 	    "{N:/bad neighbor solicitation message%s}\n");
1046ade9ccfeSMarcel Moolenaar 	p(icp6s_badna, "\t{:bad-neighbor-advertisement/%ju} "
1047ade9ccfeSMarcel Moolenaar 	    "{N:/bad neighbor advertisement message%s}\n");
1048ade9ccfeSMarcel Moolenaar 	p(icp6s_badrs, "\t{:bad-router-solicitation/%ju} "
1049ade9ccfeSMarcel Moolenaar 	    "{N:/bad router solicitation message%s}\n");
1050ade9ccfeSMarcel Moolenaar 	p(icp6s_badra, "\t{:bad-router-advertisement/%ju} "
1051ade9ccfeSMarcel Moolenaar 	    "{N:/bad router advertisement message%s}\n");
1052ade9ccfeSMarcel Moolenaar 	p(icp6s_badredirect, "\t{:bad-redirect/%ju} "
1053ade9ccfeSMarcel Moolenaar 	    "{N:/bad redirect message%s}\n");
1054ade9ccfeSMarcel Moolenaar 	xo_close_container("errors");
1055ade9ccfeSMarcel Moolenaar 	p(icp6s_pmtuchg, "\t{:path-mtu-changes/%ju} {N:/path MTU change%s}\n");
1056cfa1ca9dSYoshinobu Inoue #undef p
1057cfa1ca9dSYoshinobu Inoue #undef p_5
1058ade9ccfeSMarcel Moolenaar 	xo_close_container(name);
1059cfa1ca9dSYoshinobu Inoue }
1060cfa1ca9dSYoshinobu Inoue 
1061cfa1ca9dSYoshinobu Inoue /*
1062cfa1ca9dSYoshinobu Inoue  * Dump ICMPv6 per-interface statistics based on RFC 2466.
1063cfa1ca9dSYoshinobu Inoue  */
1064cfa1ca9dSYoshinobu Inoue void
10655e051718SAssar Westerlund icmp6_ifstats(char *ifname)
1066cfa1ca9dSYoshinobu Inoue {
1067cfa1ca9dSYoshinobu Inoue 	struct in6_ifreq ifr;
1068cfa1ca9dSYoshinobu Inoue 	int s;
1069ade9ccfeSMarcel Moolenaar 
1070cfa1ca9dSYoshinobu Inoue #define	p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1)	\
1071ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f,		\
1072ade9ccfeSMarcel Moolenaar 	    plural(ifr.ifr_ifru.ifru_icmp6stat.f))
1073f99a4046SMike Makonnen #define	p2(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1)	\
1074ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f,		\
1075ade9ccfeSMarcel Moolenaar 	    pluralies(ifr.ifr_ifru.ifru_icmp6stat.f))
1076cfa1ca9dSYoshinobu Inoue 
1077cfa1ca9dSYoshinobu Inoue 	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
1078ade9ccfeSMarcel Moolenaar 		xo_warn("Warning: socket(AF_INET6)");
1079cfa1ca9dSYoshinobu Inoue 		return;
1080cfa1ca9dSYoshinobu Inoue 	}
1081cfa1ca9dSYoshinobu Inoue 
1082cfa1ca9dSYoshinobu Inoue 	strcpy(ifr.ifr_name, ifname);
1083cfa1ca9dSYoshinobu Inoue 	if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) {
1084d77e67e4SMark Johnston 		if (errno != EPFNOSUPPORT)
1085ade9ccfeSMarcel Moolenaar 			xo_warn("Warning: ioctl(SIOCGIFSTAT_ICMP6)");
1086cfa1ca9dSYoshinobu Inoue 		goto end;
1087cfa1ca9dSYoshinobu Inoue 	}
1088cfa1ca9dSYoshinobu Inoue 
1089ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/icmp6 on %s}:\n", ifr.ifr_name);
1090cfa1ca9dSYoshinobu Inoue 
1091ade9ccfeSMarcel Moolenaar 	xo_open_instance("icmp6-interface-statistics");
1092ade9ccfeSMarcel Moolenaar 	xo_emit("{ke:name/%s}", ifr.ifr_name);
1093ade9ccfeSMarcel Moolenaar 	p(ifs6_in_msg, "\t{:received-packets/%ju} "
1094ade9ccfeSMarcel Moolenaar 	    "{N:/total input message%s}\n");
1095ade9ccfeSMarcel Moolenaar 	p(ifs6_in_error, "\t{:received-errors/%ju} "
1096ade9ccfeSMarcel Moolenaar 	    "{N:/total input error message%s}\n");
1097ade9ccfeSMarcel Moolenaar 	p(ifs6_in_dstunreach, "\t{:received-destination-unreachable/%ju} "
1098ade9ccfeSMarcel Moolenaar 	    "{N:/input destination unreachable error%s}\n");
1099ade9ccfeSMarcel Moolenaar 	p(ifs6_in_adminprohib, "\t{:received-admin-prohibited/%ju} "
1100ade9ccfeSMarcel Moolenaar 	    "{N:/input administratively prohibited error%s}\n");
1101ade9ccfeSMarcel Moolenaar 	p(ifs6_in_timeexceed, "\t{:received-time-exceeded/%ju} "
1102ade9ccfeSMarcel Moolenaar 	    "{N:/input time exceeded error%s}\n");
1103ade9ccfeSMarcel Moolenaar 	p(ifs6_in_paramprob, "\t{:received-bad-parameter/%ju} "
1104ade9ccfeSMarcel Moolenaar 	    "{N:/input parameter problem error%s}\n");
1105ade9ccfeSMarcel Moolenaar 	p(ifs6_in_pkttoobig, "\t{:received-packet-too-big/%ju} "
1106ade9ccfeSMarcel Moolenaar 	    "{N:/input packet too big error%s}\n");
1107ade9ccfeSMarcel Moolenaar 	p(ifs6_in_echo, "\t{:received-echo-requests/%ju} "
1108ade9ccfeSMarcel Moolenaar 	    "{N:/input echo request%s}\n");
1109ade9ccfeSMarcel Moolenaar 	p2(ifs6_in_echoreply, "\t{:received-echo-replies/%ju} "
1110ade9ccfeSMarcel Moolenaar 	    "{N:/input echo repl%s}\n");
1111ade9ccfeSMarcel Moolenaar 	p(ifs6_in_routersolicit, "\t{:received-router-solicitation/%ju} "
1112ade9ccfeSMarcel Moolenaar 	    "{N:/input router solicitation%s}\n");
1113ade9ccfeSMarcel Moolenaar 	p(ifs6_in_routeradvert, "\t{:received-router-advertisement/%ju} "
1114ade9ccfeSMarcel Moolenaar 	    "{N:/input router advertisement%s}\n");
1115ade9ccfeSMarcel Moolenaar 	p(ifs6_in_neighborsolicit, "\t{:received-neighbor-solicitation/%ju} "
1116ade9ccfeSMarcel Moolenaar 	    "{N:/input neighbor solicitation%s}\n");
1117ade9ccfeSMarcel Moolenaar 	p(ifs6_in_neighboradvert, "\t{:received-neighbor-advertisement/%ju} "
1118ade9ccfeSMarcel Moolenaar 	    "{N:/input neighbor advertisement%s}\n");
1119ade9ccfeSMarcel Moolenaar 	p(ifs6_in_redirect, "\t{received-redirects/%ju} "
1120ade9ccfeSMarcel Moolenaar 	    "{N:/input redirect%s}\n");
1121ade9ccfeSMarcel Moolenaar 	p2(ifs6_in_mldquery, "\t{:received-mld-queries/%ju} "
1122ade9ccfeSMarcel Moolenaar 	    "{N:/input MLD quer%s}\n");
1123ade9ccfeSMarcel Moolenaar 	p(ifs6_in_mldreport, "\t{:received-mld-reports/%ju} "
1124ade9ccfeSMarcel Moolenaar 	    "{N:/input MLD report%s}\n");
1125ade9ccfeSMarcel Moolenaar 	p(ifs6_in_mlddone, "\t{:received-mld-done/%ju} "
1126ade9ccfeSMarcel Moolenaar 	    "{N:/input MLD done%s}\n");
1127ade9ccfeSMarcel Moolenaar 
1128ade9ccfeSMarcel Moolenaar 	p(ifs6_out_msg, "\t{:sent-packets/%ju} "
1129ade9ccfeSMarcel Moolenaar 	    "{N:/total output message%s}\n");
1130ade9ccfeSMarcel Moolenaar 	p(ifs6_out_error, "\t{:sent-errors/%ju} "
1131ade9ccfeSMarcel Moolenaar 	    "{N:/total output error message%s}\n");
1132ade9ccfeSMarcel Moolenaar 	p(ifs6_out_dstunreach, "\t{:sent-destination-unreachable/%ju} "
1133ade9ccfeSMarcel Moolenaar 	    "{N:/output destination unreachable error%s}\n");
1134ade9ccfeSMarcel Moolenaar 	p(ifs6_out_adminprohib, "\t{:sent-admin-prohibited/%ju} "
1135ade9ccfeSMarcel Moolenaar 	    "{N:/output administratively prohibited error%s}\n");
1136ade9ccfeSMarcel Moolenaar 	p(ifs6_out_timeexceed, "\t{:sent-time-exceeded/%ju} "
1137ade9ccfeSMarcel Moolenaar 	    "{N:/output time exceeded error%s}\n");
1138ade9ccfeSMarcel Moolenaar 	p(ifs6_out_paramprob, "\t{:sent-bad-parameter/%ju} "
1139ade9ccfeSMarcel Moolenaar 	    "{N:/output parameter problem error%s}\n");
1140ade9ccfeSMarcel Moolenaar 	p(ifs6_out_pkttoobig, "\t{:sent-packet-too-big/%ju} "
1141ade9ccfeSMarcel Moolenaar 	    "{N:/output packet too big error%s}\n");
1142ade9ccfeSMarcel Moolenaar 	p(ifs6_out_echo, "\t{:sent-echo-requests/%ju} "
1143ade9ccfeSMarcel Moolenaar 	    "{N:/output echo request%s}\n");
1144ade9ccfeSMarcel Moolenaar 	p2(ifs6_out_echoreply, "\t{:sent-echo-replies/%ju} "
1145ade9ccfeSMarcel Moolenaar 	    "{N:/output echo repl%s}\n");
1146ade9ccfeSMarcel Moolenaar 	p(ifs6_out_routersolicit, "\t{:sent-router-solicitation/%ju} "
1147ade9ccfeSMarcel Moolenaar 	    "{N:/output router solicitation%s}\n");
1148ade9ccfeSMarcel Moolenaar 	p(ifs6_out_routeradvert, "\t{:sent-router-advertisement/%ju} "
1149ade9ccfeSMarcel Moolenaar 	    "{N:/output router advertisement%s}\n");
1150ade9ccfeSMarcel Moolenaar 	p(ifs6_out_neighborsolicit, "\t{:sent-neighbor-solicitation/%ju} "
1151ade9ccfeSMarcel Moolenaar 	    "{N:/output neighbor solicitation%s}\n");
1152ade9ccfeSMarcel Moolenaar 	p(ifs6_out_neighboradvert, "\t{:sent-neighbor-advertisement/%ju} "
1153ade9ccfeSMarcel Moolenaar 	    "{N:/output neighbor advertisement%s}\n");
1154ade9ccfeSMarcel Moolenaar 	p(ifs6_out_redirect, "\t{:sent-redirects/%ju} "
1155ade9ccfeSMarcel Moolenaar 	    "{N:/output redirect%s}\n");
1156ade9ccfeSMarcel Moolenaar 	p2(ifs6_out_mldquery, "\t{:sent-mld-queries/%ju} "
1157ade9ccfeSMarcel Moolenaar 	    "{N:/output MLD quer%s}\n");
1158ade9ccfeSMarcel Moolenaar 	p(ifs6_out_mldreport, "\t{:sent-mld-reports/%ju} "
1159ade9ccfeSMarcel Moolenaar 	    "{N:/output MLD report%s}\n");
1160ade9ccfeSMarcel Moolenaar 	p(ifs6_out_mlddone, "\t{:sent-mld-dones/%ju} "
1161ade9ccfeSMarcel Moolenaar 	    "{N:/output MLD done%s}\n");
1162cfa1ca9dSYoshinobu Inoue 
1163cfa1ca9dSYoshinobu Inoue end:
1164ade9ccfeSMarcel Moolenaar 	xo_close_instance("icmp6-interface-statistics");
1165cfa1ca9dSYoshinobu Inoue 	close(s);
1166cfa1ca9dSYoshinobu Inoue #undef p
1167cfa1ca9dSYoshinobu Inoue }
1168cfa1ca9dSYoshinobu Inoue 
1169cfa1ca9dSYoshinobu Inoue /*
1170cfa1ca9dSYoshinobu Inoue  * Dump PIM statistics structure.
1171cfa1ca9dSYoshinobu Inoue  */
1172cfa1ca9dSYoshinobu Inoue void
1173feda1a43SJohn Baldwin pim6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
1174cfa1ca9dSYoshinobu Inoue {
11759eddb899SMark Johnston 	struct pim6stat pim6stat;
1176cfa1ca9dSYoshinobu Inoue 
11779eddb899SMark Johnston 	if (fetch_stats("net.inet6.pim.stats", off, &pim6stat,
11789eddb899SMark Johnston 	    sizeof(pim6stat), kread) != 0)
1179cfa1ca9dSYoshinobu Inoue 		return;
1180feda1a43SJohn Baldwin 
1181ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
1182ade9ccfeSMarcel Moolenaar 	xo_open_container(name);
1183cfa1ca9dSYoshinobu Inoue 
1184cfa1ca9dSYoshinobu Inoue #define	p(f, m) if (pim6stat.f || sflag <= 1) \
1185ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)pim6stat.f, plural(pim6stat.f))
1186ade9ccfeSMarcel Moolenaar 
1187ade9ccfeSMarcel Moolenaar 	p(pim6s_rcv_total, "\t{:received-packets/%ju} "
1188ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received}\n");
1189ade9ccfeSMarcel Moolenaar 	p(pim6s_rcv_tooshort, "\t{:dropped-too-short/%ju} "
1190ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received with too few bytes}\n");
1191ade9ccfeSMarcel Moolenaar 	p(pim6s_rcv_badsum, "\t{:dropped-bad-checksum/%ju} "
1192ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received with bad checksum}\n");
1193ade9ccfeSMarcel Moolenaar 	p(pim6s_rcv_badversion, "\t{:dropped-bad-version/%ju} "
1194ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received with bad version}\n");
1195ade9ccfeSMarcel Moolenaar 	p(pim6s_rcv_registers, "\t{:received-registers/%ju} "
1196ade9ccfeSMarcel Moolenaar 	    "{N:/register%s received}\n");
1197ade9ccfeSMarcel Moolenaar 	p(pim6s_rcv_badregisters, "\t{:received-bad-registers/%ju} "
1198ade9ccfeSMarcel Moolenaar 	    "{N:/bad register%s received}\n");
1199ade9ccfeSMarcel Moolenaar 	p(pim6s_snd_registers, "\t{:sent-registers/%ju} "
1200ade9ccfeSMarcel Moolenaar 	    "{N:/register%s sent}\n");
1201cfa1ca9dSYoshinobu Inoue #undef p
1202ade9ccfeSMarcel Moolenaar 	xo_close_container(name);
1203cfa1ca9dSYoshinobu Inoue }
1204cfa1ca9dSYoshinobu Inoue 
1205cfa1ca9dSYoshinobu Inoue /*
120633841545SHajimu UMEMOTO  * Dump raw ip6 statistics structure.
120733841545SHajimu UMEMOTO  */
120833841545SHajimu UMEMOTO void
1209feda1a43SJohn Baldwin rip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
121033841545SHajimu UMEMOTO {
12119eddb899SMark Johnston 	struct rip6stat rip6stat;
121233841545SHajimu UMEMOTO 	u_quad_t delivered;
121333841545SHajimu UMEMOTO 
12149eddb899SMark Johnston 	if (fetch_stats("net.inet6.ip6.rip6stats", off, &rip6stat,
12159eddb899SMark Johnston 	    sizeof(rip6stat), kread_counters) != 0)
121633841545SHajimu UMEMOTO 		return;
121733841545SHajimu UMEMOTO 
1218ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
1219ade9ccfeSMarcel Moolenaar 	xo_open_container(name);
122033841545SHajimu UMEMOTO 
122133841545SHajimu UMEMOTO #define	p(f, m) if (rip6stat.f || sflag <= 1) \
1222ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)rip6stat.f, plural(rip6stat.f))
1223ade9ccfeSMarcel Moolenaar 
1224ade9ccfeSMarcel Moolenaar 	p(rip6s_ipackets, "\t{:received-packets/%ju} "
1225ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received}\n");
1226ade9ccfeSMarcel Moolenaar 	p(rip6s_isum, "\t{:input-checksum-computation/%ju} "
1227ade9ccfeSMarcel Moolenaar 	    "{N:/checksum calculation%s on inbound}\n");
1228ade9ccfeSMarcel Moolenaar 	p(rip6s_badsum, "\t{:received-bad-checksum/%ju} "
1229ade9ccfeSMarcel Moolenaar 	    "{N:/message%s with bad checksum}\n");
1230ade9ccfeSMarcel Moolenaar 	p(rip6s_nosock, "\t{:dropped-no-socket/%ju} "
1231ade9ccfeSMarcel Moolenaar 	    "{N:/message%s dropped due to no socket}\n");
1232ade9ccfeSMarcel Moolenaar 	p(rip6s_nosockmcast, "\t{:dropped-multicast-no-socket/%ju} "
1233ade9ccfeSMarcel Moolenaar 	    "{N:/multicast message%s dropped due to no socket}\n");
1234ade9ccfeSMarcel Moolenaar 	p(rip6s_fullsock, "\t{:dropped-full-socket-buffer/%ju} "
1235ade9ccfeSMarcel Moolenaar 	    "{N:/message%s dropped due to full socket buffers}\n");
123633841545SHajimu UMEMOTO 	delivered = rip6stat.rip6s_ipackets -
123733841545SHajimu UMEMOTO 		    rip6stat.rip6s_badsum -
123833841545SHajimu UMEMOTO 		    rip6stat.rip6s_nosock -
123933841545SHajimu UMEMOTO 		    rip6stat.rip6s_nosockmcast -
124033841545SHajimu UMEMOTO 		    rip6stat.rip6s_fullsock;
124133841545SHajimu UMEMOTO 	if (delivered || sflag <= 1)
1242ade9ccfeSMarcel Moolenaar 		xo_emit("\t{:delivered-packets/%ju} {N:/delivered}\n",
1243ade9ccfeSMarcel Moolenaar 		    (uintmax_t)delivered);
1244ade9ccfeSMarcel Moolenaar 	p(rip6s_opackets, "\t{:sent-packets/%ju} "
1245ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s output}\n");
124633841545SHajimu UMEMOTO #undef p
1247ade9ccfeSMarcel Moolenaar 	xo_close_container(name);
124833841545SHajimu UMEMOTO }
124933841545SHajimu UMEMOTO 
125033841545SHajimu UMEMOTO /*
1251cfa1ca9dSYoshinobu Inoue  * Pretty print an Internet address (net address + port).
125265ea0024SAssar Westerlund  * Take numeric_addr and numeric_port into consideration.
1253cfa1ca9dSYoshinobu Inoue  */
1254cfa1ca9dSYoshinobu Inoue #define	GETSERVBYPORT6(port, proto, ret)\
1255cfa1ca9dSYoshinobu Inoue {\
1256cfa1ca9dSYoshinobu Inoue 	if (strcmp((proto), "tcp6") == 0)\
1257cfa1ca9dSYoshinobu Inoue 		(ret) = getservbyport((int)(port), "tcp");\
1258cfa1ca9dSYoshinobu Inoue 	else if (strcmp((proto), "udp6") == 0)\
1259cfa1ca9dSYoshinobu Inoue 		(ret) = getservbyport((int)(port), "udp");\
1260cfa1ca9dSYoshinobu Inoue 	else\
1261cfa1ca9dSYoshinobu Inoue 		(ret) = getservbyport((int)(port), (proto));\
1262cfa1ca9dSYoshinobu Inoue };
1263cfa1ca9dSYoshinobu Inoue 
1264cfa1ca9dSYoshinobu Inoue void
1265ade9ccfeSMarcel Moolenaar inet6print(const char *container, struct in6_addr *in6, int port,
1266ade9ccfeSMarcel Moolenaar     const char *proto, int numeric)
1267cfa1ca9dSYoshinobu Inoue {
1268cfa1ca9dSYoshinobu Inoue 	struct servent *sp = 0;
1269cfa1ca9dSYoshinobu Inoue 	char line[80], *cp;
1270cfa1ca9dSYoshinobu Inoue 	int width;
1271f193c8ceSXin LI 	size_t alen, plen;
1272cfa1ca9dSYoshinobu Inoue 
1273ade9ccfeSMarcel Moolenaar 	if (container)
1274ade9ccfeSMarcel Moolenaar 		xo_open_container(container);
1275ade9ccfeSMarcel Moolenaar 
1276f193c8ceSXin LI 	snprintf(line, sizeof(line), "%.*s.",
1277f193c8ceSXin LI 	    Wflag ? 39 : (Aflag && !numeric) ? 12 : 16,
1278ade9ccfeSMarcel Moolenaar 	    inet6name(in6));
1279f193c8ceSXin LI 	alen = strlen(line);
1280f193c8ceSXin LI 	cp = line + alen;
1281cfa1ca9dSYoshinobu Inoue 	if (!numeric && port)
1282cfa1ca9dSYoshinobu Inoue 		GETSERVBYPORT6(port, proto, sp);
1283cfa1ca9dSYoshinobu Inoue 	if (sp || port == 0)
1284f193c8ceSXin LI 		snprintf(cp, sizeof(line) - alen,
1285f193c8ceSXin LI 		    "%.15s", sp ? sp->s_name : "*");
1286cfa1ca9dSYoshinobu Inoue 	else
1287f193c8ceSXin LI 		snprintf(cp, sizeof(line) - alen,
1288f193c8ceSXin LI 		    "%d", ntohs((u_short)port));
128970057abfSRuslan Ermilov 	width = Wflag ? 45 : Aflag ? 18 : 22;
1290ade9ccfeSMarcel Moolenaar 
1291ade9ccfeSMarcel Moolenaar 	xo_emit("{d:target/%-*.*s} ", width, width, line);
1292ade9ccfeSMarcel Moolenaar 
1293f03f398cSHajimu UMEMOTO 	plen = strlen(cp);
1294f193c8ceSXin LI 	alen--;
1295ade9ccfeSMarcel Moolenaar 	xo_emit("{e:address/%*.*s}{e:port/%*.*s}", alen, alen, line, plen,
1296ade9ccfeSMarcel Moolenaar 	    plen, cp);
1297ade9ccfeSMarcel Moolenaar 
1298ade9ccfeSMarcel Moolenaar 	if (container)
1299ade9ccfeSMarcel Moolenaar 		xo_close_container(container);
1300cfa1ca9dSYoshinobu Inoue }
1301cfa1ca9dSYoshinobu Inoue 
1302cfa1ca9dSYoshinobu Inoue /*
1303cfa1ca9dSYoshinobu Inoue  * Construct an Internet address representation.
130465ea0024SAssar Westerlund  * If the numeric_addr has been supplied, give
1305cfa1ca9dSYoshinobu Inoue  * numeric value, otherwise try for symbolic name.
1306cfa1ca9dSYoshinobu Inoue  */
1307cfa1ca9dSYoshinobu Inoue 
1308cfa1ca9dSYoshinobu Inoue char *
13095e051718SAssar Westerlund inet6name(struct in6_addr *in6p)
1310cfa1ca9dSYoshinobu Inoue {
131184dde578SHiroki Sato 	struct sockaddr_in6 sin6;
131284dde578SHiroki Sato 	char hbuf[NI_MAXHOST], *cp;
1313f193c8ceSXin LI 	static char line[NI_MAXHOST];
1314d121b556SBrian Somers 	static char domain[MAXHOSTNAMELEN];
1315cfa1ca9dSYoshinobu Inoue 	static int first = 1;
131684dde578SHiroki Sato 	int flags, error;
1317cfa1ca9dSYoshinobu Inoue 
131884dde578SHiroki Sato 	if (IN6_IS_ADDR_UNSPECIFIED(in6p)) {
131984dde578SHiroki Sato 		strcpy(line, "*");
132084dde578SHiroki Sato 		return (line);
132184dde578SHiroki Sato 	}
132265ea0024SAssar Westerlund 	if (first && !numeric_addr) {
1323cfa1ca9dSYoshinobu Inoue 		first = 0;
1324f193c8ceSXin LI 		if (gethostname(domain, sizeof(domain)) == 0 &&
1325b3608ae1SEd Schouten 		    (cp = strchr(domain, '.')))
1326f193c8ceSXin LI 			strlcpy(domain, cp + 1, sizeof(domain));
1327cfa1ca9dSYoshinobu Inoue 		else
1328cfa1ca9dSYoshinobu Inoue 			domain[0] = 0;
1329cfa1ca9dSYoshinobu Inoue 	}
133084dde578SHiroki Sato 	memset(&sin6, 0, sizeof(sin6));
133184dde578SHiroki Sato 	memcpy(&sin6.sin6_addr, in6p, sizeof(*in6p));
133284dde578SHiroki Sato 	sin6.sin6_family = AF_INET6;
133384dde578SHiroki Sato 	/* XXX: in6p.s6_addr[2] can contain scopeid. */
133484dde578SHiroki Sato 	in6_fillscopeid(&sin6);
133584dde578SHiroki Sato 	flags = (numeric_addr) ? NI_NUMERICHOST : 0;
133684dde578SHiroki Sato 	error = getnameinfo((struct sockaddr *)&sin6, sizeof(sin6), hbuf,
133784dde578SHiroki Sato 	    sizeof(hbuf), NULL, 0, flags);
133884dde578SHiroki Sato 	if (error == 0) {
133984dde578SHiroki Sato 		if ((flags & NI_NUMERICHOST) == 0 &&
134084dde578SHiroki Sato 		    (cp = strchr(hbuf, '.')) &&
1341cfa1ca9dSYoshinobu Inoue 		    !strcmp(cp + 1, domain))
1342cfa1ca9dSYoshinobu Inoue 			*cp = 0;
1343f193c8ceSXin LI 		strlcpy(line, hbuf, sizeof(line));
134484dde578SHiroki Sato 	} else {
134584dde578SHiroki Sato 		/* XXX: this should not happen. */
1346f193c8ceSXin LI 		snprintf(line, sizeof(line), "%s",
134784dde578SHiroki Sato 			inet_ntop(AF_INET6, (void *)&sin6.sin6_addr, ntop_buf,
1348cfa1ca9dSYoshinobu Inoue 				sizeof(ntop_buf)));
134984dde578SHiroki Sato 	}
1350cfa1ca9dSYoshinobu Inoue 	return (line);
1351cfa1ca9dSYoshinobu Inoue }
1352d84a1df4SHajimu UMEMOTO #endif /*INET6*/
1353