xref: /freebsd/usr.bin/netstat/inet6.c (revision 95968ea7ec8f1cd3c1d03cc56c704cb2392d0d25)
1cfa1ca9dSYoshinobu Inoue /*	BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp	*/
265475bc8SDavid E. O'Brien /*-
38a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
48a16b7a1SPedro F. Giffuni  *
5cfa1ca9dSYoshinobu Inoue  * Copyright (c) 1983, 1988, 1993
6cfa1ca9dSYoshinobu Inoue  *	The Regents of the University of California.  All rights reserved.
7cfa1ca9dSYoshinobu Inoue  *
8cfa1ca9dSYoshinobu Inoue  * Redistribution and use in source and binary forms, with or without
9cfa1ca9dSYoshinobu Inoue  * modification, are permitted provided that the following conditions
10cfa1ca9dSYoshinobu Inoue  * are met:
11cfa1ca9dSYoshinobu Inoue  * 1. Redistributions of source code must retain the above copyright
12cfa1ca9dSYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer.
13cfa1ca9dSYoshinobu Inoue  * 2. Redistributions in binary form must reproduce the above copyright
14cfa1ca9dSYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer in the
15cfa1ca9dSYoshinobu Inoue  *    documentation and/or other materials provided with the distribution.
16fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
17cfa1ca9dSYoshinobu Inoue  *    may be used to endorse or promote products derived from this software
18cfa1ca9dSYoshinobu Inoue  *    without specific prior written permission.
19cfa1ca9dSYoshinobu Inoue  *
20cfa1ca9dSYoshinobu Inoue  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21cfa1ca9dSYoshinobu Inoue  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22cfa1ca9dSYoshinobu Inoue  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23cfa1ca9dSYoshinobu Inoue  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24cfa1ca9dSYoshinobu Inoue  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25cfa1ca9dSYoshinobu Inoue  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26cfa1ca9dSYoshinobu Inoue  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27cfa1ca9dSYoshinobu Inoue  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28cfa1ca9dSYoshinobu Inoue  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29cfa1ca9dSYoshinobu Inoue  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30cfa1ca9dSYoshinobu Inoue  * SUCH DAMAGE.
31cfa1ca9dSYoshinobu Inoue  */
32cfa1ca9dSYoshinobu Inoue 
336cc6f122SPhilippe Charnier #include <sys/cdefs.h>
34d84a1df4SHajimu UMEMOTO #ifdef INET6
35cfa1ca9dSYoshinobu Inoue #include <sys/param.h>
36cfa1ca9dSYoshinobu Inoue #include <sys/socket.h>
37cfa1ca9dSYoshinobu Inoue #include <sys/socketvar.h>
38cfa1ca9dSYoshinobu Inoue #include <sys/ioctl.h>
39cfa1ca9dSYoshinobu Inoue #include <sys/mbuf.h>
40cfa1ca9dSYoshinobu Inoue #include <sys/protosw.h>
41cfa1ca9dSYoshinobu Inoue 
42cfa1ca9dSYoshinobu Inoue #include <net/route.h>
43cfa1ca9dSYoshinobu Inoue #include <net/if.h>
44cfa1ca9dSYoshinobu Inoue #include <netinet/in.h>
45cfa1ca9dSYoshinobu Inoue #include <netinet/ip6.h>
46cfa1ca9dSYoshinobu Inoue #include <netinet/icmp6.h>
47cfa1ca9dSYoshinobu Inoue #include <netinet/in_systm.h>
48cfa1ca9dSYoshinobu Inoue #include <netinet6/in6_pcb.h>
49cfa1ca9dSYoshinobu Inoue #include <netinet6/in6_var.h>
50cfa1ca9dSYoshinobu Inoue #include <netinet6/ip6_var.h>
51cfa1ca9dSYoshinobu Inoue #include <netinet6/pim6_var.h>
5233841545SHajimu UMEMOTO #include <netinet6/raw_ip6.h>
53cfa1ca9dSYoshinobu Inoue 
54cfa1ca9dSYoshinobu Inoue #include <arpa/inet.h>
55cfa1ca9dSYoshinobu Inoue #include <netdb.h>
56cfa1ca9dSYoshinobu Inoue 
577b95a1ebSYaroslav Tykhiy #include <stdint.h>
58cfa1ca9dSYoshinobu Inoue #include <stdio.h>
59ade9ccfeSMarcel Moolenaar #include <stdbool.h>
60109dad81SJulian Elischer #include <errno.h>
61cfa1ca9dSYoshinobu Inoue #include <string.h>
62cfa1ca9dSYoshinobu Inoue #include <unistd.h>
63ade9ccfeSMarcel Moolenaar #include <libxo/xo.h>
64cfa1ca9dSYoshinobu Inoue #include "netstat.h"
65cfa1ca9dSYoshinobu Inoue 
66cfa1ca9dSYoshinobu Inoue static char ntop_buf[INET6_ADDRSTRLEN];
67cfa1ca9dSYoshinobu Inoue 
68a01e3379SDavid Malone static	const char *ip6nh[] = {
69cfa1ca9dSYoshinobu Inoue 	"hop by hop",
70cfa1ca9dSYoshinobu Inoue 	"ICMP",
71cfa1ca9dSYoshinobu Inoue 	"IGMP",
72cfa1ca9dSYoshinobu Inoue 	"#3",
73cfa1ca9dSYoshinobu Inoue 	"IP",
74cfa1ca9dSYoshinobu Inoue 	"#5",
75cfa1ca9dSYoshinobu Inoue 	"TCP",
76cfa1ca9dSYoshinobu Inoue 	"#7",
77cfa1ca9dSYoshinobu Inoue 	"#8",
78cfa1ca9dSYoshinobu Inoue 	"#9",
79cfa1ca9dSYoshinobu Inoue 	"#10",
80cfa1ca9dSYoshinobu Inoue 	"#11",
81cfa1ca9dSYoshinobu Inoue 	"#12",
82cfa1ca9dSYoshinobu Inoue 	"#13",
83cfa1ca9dSYoshinobu Inoue 	"#14",
84cfa1ca9dSYoshinobu Inoue 	"#15",
85cfa1ca9dSYoshinobu Inoue 	"#16",
86cfa1ca9dSYoshinobu Inoue 	"UDP",
87cfa1ca9dSYoshinobu Inoue 	"#18",
88cfa1ca9dSYoshinobu Inoue 	"#19",
89cfa1ca9dSYoshinobu Inoue 	"#20",
90cfa1ca9dSYoshinobu Inoue 	"#21",
91cfa1ca9dSYoshinobu Inoue 	"IDP",
92cfa1ca9dSYoshinobu Inoue 	"#23",
93cfa1ca9dSYoshinobu Inoue 	"#24",
94cfa1ca9dSYoshinobu Inoue 	"#25",
95cfa1ca9dSYoshinobu Inoue 	"#26",
96cfa1ca9dSYoshinobu Inoue 	"#27",
97cfa1ca9dSYoshinobu Inoue 	"#28",
98cfa1ca9dSYoshinobu Inoue 	"TP",
99cfa1ca9dSYoshinobu Inoue 	"#30",
100cfa1ca9dSYoshinobu Inoue 	"#31",
101cfa1ca9dSYoshinobu Inoue 	"#32",
102cfa1ca9dSYoshinobu Inoue 	"#33",
103cfa1ca9dSYoshinobu Inoue 	"#34",
104cfa1ca9dSYoshinobu Inoue 	"#35",
105cfa1ca9dSYoshinobu Inoue 	"#36",
106cfa1ca9dSYoshinobu Inoue 	"#37",
107cfa1ca9dSYoshinobu Inoue 	"#38",
108cfa1ca9dSYoshinobu Inoue 	"#39",
109cfa1ca9dSYoshinobu Inoue 	"#40",
110cfa1ca9dSYoshinobu Inoue 	"IP6",
111cfa1ca9dSYoshinobu Inoue 	"#42",
112cfa1ca9dSYoshinobu Inoue 	"routing",
113cfa1ca9dSYoshinobu Inoue 	"fragment",
114cfa1ca9dSYoshinobu Inoue 	"#45",
115cfa1ca9dSYoshinobu Inoue 	"#46",
116cfa1ca9dSYoshinobu Inoue 	"#47",
117cfa1ca9dSYoshinobu Inoue 	"#48",
118cfa1ca9dSYoshinobu Inoue 	"#49",
119cfa1ca9dSYoshinobu Inoue 	"ESP",
120cfa1ca9dSYoshinobu Inoue 	"AH",
121cfa1ca9dSYoshinobu Inoue 	"#52",
122cfa1ca9dSYoshinobu Inoue 	"#53",
123cfa1ca9dSYoshinobu Inoue 	"#54",
124cfa1ca9dSYoshinobu Inoue 	"#55",
125cfa1ca9dSYoshinobu Inoue 	"#56",
126cfa1ca9dSYoshinobu Inoue 	"#57",
127cfa1ca9dSYoshinobu Inoue 	"ICMP6",
128cfa1ca9dSYoshinobu Inoue 	"no next header",
129cfa1ca9dSYoshinobu Inoue 	"destination option",
130cfa1ca9dSYoshinobu Inoue 	"#61",
131cb60a8deSHajimu UMEMOTO 	"mobility",
132cfa1ca9dSYoshinobu Inoue 	"#63",
133cfa1ca9dSYoshinobu Inoue 	"#64",
134cfa1ca9dSYoshinobu Inoue 	"#65",
135cfa1ca9dSYoshinobu Inoue 	"#66",
136cfa1ca9dSYoshinobu Inoue 	"#67",
137cfa1ca9dSYoshinobu Inoue 	"#68",
138cfa1ca9dSYoshinobu Inoue 	"#69",
139cfa1ca9dSYoshinobu Inoue 	"#70",
140cfa1ca9dSYoshinobu Inoue 	"#71",
141cfa1ca9dSYoshinobu Inoue 	"#72",
142cfa1ca9dSYoshinobu Inoue 	"#73",
143cfa1ca9dSYoshinobu Inoue 	"#74",
144cfa1ca9dSYoshinobu Inoue 	"#75",
145cfa1ca9dSYoshinobu Inoue 	"#76",
146cfa1ca9dSYoshinobu Inoue 	"#77",
147cfa1ca9dSYoshinobu Inoue 	"#78",
148cfa1ca9dSYoshinobu Inoue 	"#79",
149cfa1ca9dSYoshinobu Inoue 	"ISOIP",
150cfa1ca9dSYoshinobu Inoue 	"#81",
151cfa1ca9dSYoshinobu Inoue 	"#82",
152cfa1ca9dSYoshinobu Inoue 	"#83",
153cfa1ca9dSYoshinobu Inoue 	"#84",
154cfa1ca9dSYoshinobu Inoue 	"#85",
155cfa1ca9dSYoshinobu Inoue 	"#86",
156cfa1ca9dSYoshinobu Inoue 	"#87",
157cfa1ca9dSYoshinobu Inoue 	"#88",
15832cd1d96SJun-ichiro itojun Hagino 	"OSPF",
159cfa1ca9dSYoshinobu Inoue 	"#80",
160cfa1ca9dSYoshinobu Inoue 	"#91",
161cfa1ca9dSYoshinobu Inoue 	"#92",
162cfa1ca9dSYoshinobu Inoue 	"#93",
163cfa1ca9dSYoshinobu Inoue 	"#94",
164cfa1ca9dSYoshinobu Inoue 	"#95",
165cfa1ca9dSYoshinobu Inoue 	"#96",
166cfa1ca9dSYoshinobu Inoue 	"Ethernet",
167cfa1ca9dSYoshinobu Inoue 	"#98",
168cfa1ca9dSYoshinobu Inoue 	"#99",
169cfa1ca9dSYoshinobu Inoue 	"#100",
170cfa1ca9dSYoshinobu Inoue 	"#101",
171cfa1ca9dSYoshinobu Inoue 	"#102",
172cfa1ca9dSYoshinobu Inoue 	"PIM",
173cfa1ca9dSYoshinobu Inoue 	"#104",
174cfa1ca9dSYoshinobu Inoue 	"#105",
175cfa1ca9dSYoshinobu Inoue 	"#106",
176cfa1ca9dSYoshinobu Inoue 	"#107",
177cfa1ca9dSYoshinobu Inoue 	"#108",
178cfa1ca9dSYoshinobu Inoue 	"#109",
179cfa1ca9dSYoshinobu Inoue 	"#110",
180cfa1ca9dSYoshinobu Inoue 	"#111",
181cfa1ca9dSYoshinobu Inoue 	"#112",
182cfa1ca9dSYoshinobu Inoue 	"#113",
183cfa1ca9dSYoshinobu Inoue 	"#114",
184cfa1ca9dSYoshinobu Inoue 	"#115",
185cfa1ca9dSYoshinobu Inoue 	"#116",
186cfa1ca9dSYoshinobu Inoue 	"#117",
187cfa1ca9dSYoshinobu Inoue 	"#118",
188cfa1ca9dSYoshinobu Inoue 	"#119",
189cfa1ca9dSYoshinobu Inoue 	"#120",
190cfa1ca9dSYoshinobu Inoue 	"#121",
191cfa1ca9dSYoshinobu Inoue 	"#122",
192cfa1ca9dSYoshinobu Inoue 	"#123",
193cfa1ca9dSYoshinobu Inoue 	"#124",
194cfa1ca9dSYoshinobu Inoue 	"#125",
195cfa1ca9dSYoshinobu Inoue 	"#126",
196cfa1ca9dSYoshinobu Inoue 	"#127",
197cfa1ca9dSYoshinobu Inoue 	"#128",
198cfa1ca9dSYoshinobu Inoue 	"#129",
199cfa1ca9dSYoshinobu Inoue 	"#130",
200cfa1ca9dSYoshinobu Inoue 	"#131",
201e0694d2fSMichael Tuexen 	"SCTP",
202cfa1ca9dSYoshinobu Inoue 	"#133",
203cfa1ca9dSYoshinobu Inoue 	"#134",
204cfa1ca9dSYoshinobu Inoue 	"#135",
205e0694d2fSMichael Tuexen 	"UDPLite",
206cfa1ca9dSYoshinobu Inoue 	"#137",
207cfa1ca9dSYoshinobu Inoue 	"#138",
208cfa1ca9dSYoshinobu Inoue 	"#139",
209cfa1ca9dSYoshinobu Inoue 	"#140",
210cfa1ca9dSYoshinobu Inoue 	"#141",
211cfa1ca9dSYoshinobu Inoue 	"#142",
212cfa1ca9dSYoshinobu Inoue 	"#143",
213cfa1ca9dSYoshinobu Inoue 	"#144",
214cfa1ca9dSYoshinobu Inoue 	"#145",
215cfa1ca9dSYoshinobu Inoue 	"#146",
216cfa1ca9dSYoshinobu Inoue 	"#147",
217cfa1ca9dSYoshinobu Inoue 	"#148",
218cfa1ca9dSYoshinobu Inoue 	"#149",
219cfa1ca9dSYoshinobu Inoue 	"#150",
220cfa1ca9dSYoshinobu Inoue 	"#151",
221cfa1ca9dSYoshinobu Inoue 	"#152",
222cfa1ca9dSYoshinobu Inoue 	"#153",
223cfa1ca9dSYoshinobu Inoue 	"#154",
224cfa1ca9dSYoshinobu Inoue 	"#155",
225cfa1ca9dSYoshinobu Inoue 	"#156",
226cfa1ca9dSYoshinobu Inoue 	"#157",
227cfa1ca9dSYoshinobu Inoue 	"#158",
228cfa1ca9dSYoshinobu Inoue 	"#159",
229cfa1ca9dSYoshinobu Inoue 	"#160",
230cfa1ca9dSYoshinobu Inoue 	"#161",
231cfa1ca9dSYoshinobu Inoue 	"#162",
232cfa1ca9dSYoshinobu Inoue 	"#163",
233cfa1ca9dSYoshinobu Inoue 	"#164",
234cfa1ca9dSYoshinobu Inoue 	"#165",
235cfa1ca9dSYoshinobu Inoue 	"#166",
236cfa1ca9dSYoshinobu Inoue 	"#167",
237cfa1ca9dSYoshinobu Inoue 	"#168",
238cfa1ca9dSYoshinobu Inoue 	"#169",
239cfa1ca9dSYoshinobu Inoue 	"#170",
240cfa1ca9dSYoshinobu Inoue 	"#171",
241cfa1ca9dSYoshinobu Inoue 	"#172",
242cfa1ca9dSYoshinobu Inoue 	"#173",
243cfa1ca9dSYoshinobu Inoue 	"#174",
244cfa1ca9dSYoshinobu Inoue 	"#175",
245cfa1ca9dSYoshinobu Inoue 	"#176",
246cfa1ca9dSYoshinobu Inoue 	"#177",
247cfa1ca9dSYoshinobu Inoue 	"#178",
248cfa1ca9dSYoshinobu Inoue 	"#179",
249cfa1ca9dSYoshinobu Inoue 	"#180",
250cfa1ca9dSYoshinobu Inoue 	"#181",
251cfa1ca9dSYoshinobu Inoue 	"#182",
252cfa1ca9dSYoshinobu Inoue 	"#183",
253cfa1ca9dSYoshinobu Inoue 	"#184",
254cfa1ca9dSYoshinobu Inoue 	"#185",
255cfa1ca9dSYoshinobu Inoue 	"#186",
256cfa1ca9dSYoshinobu Inoue 	"#187",
257cfa1ca9dSYoshinobu Inoue 	"#188",
258cfa1ca9dSYoshinobu Inoue 	"#189",
259cfa1ca9dSYoshinobu Inoue 	"#180",
260cfa1ca9dSYoshinobu Inoue 	"#191",
261cfa1ca9dSYoshinobu Inoue 	"#192",
262cfa1ca9dSYoshinobu Inoue 	"#193",
263cfa1ca9dSYoshinobu Inoue 	"#194",
264cfa1ca9dSYoshinobu Inoue 	"#195",
265cfa1ca9dSYoshinobu Inoue 	"#196",
266cfa1ca9dSYoshinobu Inoue 	"#197",
267cfa1ca9dSYoshinobu Inoue 	"#198",
268cfa1ca9dSYoshinobu Inoue 	"#199",
269cfa1ca9dSYoshinobu Inoue 	"#200",
270cfa1ca9dSYoshinobu Inoue 	"#201",
271cfa1ca9dSYoshinobu Inoue 	"#202",
272cfa1ca9dSYoshinobu Inoue 	"#203",
273cfa1ca9dSYoshinobu Inoue 	"#204",
274cfa1ca9dSYoshinobu Inoue 	"#205",
275cfa1ca9dSYoshinobu Inoue 	"#206",
276cfa1ca9dSYoshinobu Inoue 	"#207",
277cfa1ca9dSYoshinobu Inoue 	"#208",
278cfa1ca9dSYoshinobu Inoue 	"#209",
279cfa1ca9dSYoshinobu Inoue 	"#210",
280cfa1ca9dSYoshinobu Inoue 	"#211",
281cfa1ca9dSYoshinobu Inoue 	"#212",
282cfa1ca9dSYoshinobu Inoue 	"#213",
283cfa1ca9dSYoshinobu Inoue 	"#214",
284cfa1ca9dSYoshinobu Inoue 	"#215",
285cfa1ca9dSYoshinobu Inoue 	"#216",
286cfa1ca9dSYoshinobu Inoue 	"#217",
287cfa1ca9dSYoshinobu Inoue 	"#218",
288cfa1ca9dSYoshinobu Inoue 	"#219",
289cfa1ca9dSYoshinobu Inoue 	"#220",
290cfa1ca9dSYoshinobu Inoue 	"#221",
291cfa1ca9dSYoshinobu Inoue 	"#222",
292cfa1ca9dSYoshinobu Inoue 	"#223",
293cfa1ca9dSYoshinobu Inoue 	"#224",
294cfa1ca9dSYoshinobu Inoue 	"#225",
295cfa1ca9dSYoshinobu Inoue 	"#226",
296cfa1ca9dSYoshinobu Inoue 	"#227",
297cfa1ca9dSYoshinobu Inoue 	"#228",
298cfa1ca9dSYoshinobu Inoue 	"#229",
299cfa1ca9dSYoshinobu Inoue 	"#230",
300cfa1ca9dSYoshinobu Inoue 	"#231",
301cfa1ca9dSYoshinobu Inoue 	"#232",
302cfa1ca9dSYoshinobu Inoue 	"#233",
303cfa1ca9dSYoshinobu Inoue 	"#234",
304cfa1ca9dSYoshinobu Inoue 	"#235",
305cfa1ca9dSYoshinobu Inoue 	"#236",
306cfa1ca9dSYoshinobu Inoue 	"#237",
307cfa1ca9dSYoshinobu Inoue 	"#238",
308cfa1ca9dSYoshinobu Inoue 	"#239",
309cfa1ca9dSYoshinobu Inoue 	"#240",
310cfa1ca9dSYoshinobu Inoue 	"#241",
311cfa1ca9dSYoshinobu Inoue 	"#242",
312cfa1ca9dSYoshinobu Inoue 	"#243",
313cfa1ca9dSYoshinobu Inoue 	"#244",
314cfa1ca9dSYoshinobu Inoue 	"#245",
315cfa1ca9dSYoshinobu Inoue 	"#246",
316cfa1ca9dSYoshinobu Inoue 	"#247",
317cfa1ca9dSYoshinobu Inoue 	"#248",
318cfa1ca9dSYoshinobu Inoue 	"#249",
319cfa1ca9dSYoshinobu Inoue 	"#250",
320cfa1ca9dSYoshinobu Inoue 	"#251",
321cfa1ca9dSYoshinobu Inoue 	"#252",
322cfa1ca9dSYoshinobu Inoue 	"#253",
323cfa1ca9dSYoshinobu Inoue 	"#254",
324cfa1ca9dSYoshinobu Inoue 	"#255",
325cfa1ca9dSYoshinobu Inoue };
326cfa1ca9dSYoshinobu Inoue 
327321ae07fSPhilippe Charnier static const char *srcrule_str[] = {
3284ef2dc8bSHajimu UMEMOTO 	"first candidate",
3294ef2dc8bSHajimu UMEMOTO 	"same address",
3304ef2dc8bSHajimu UMEMOTO 	"appropriate scope",
3314ef2dc8bSHajimu UMEMOTO 	"deprecated address",
3324ef2dc8bSHajimu UMEMOTO 	"home address",
3334ef2dc8bSHajimu UMEMOTO 	"outgoing interface",
3344ef2dc8bSHajimu UMEMOTO 	"matching label",
3354ef2dc8bSHajimu UMEMOTO 	"public/temporary address",
3364ef2dc8bSHajimu UMEMOTO 	"alive interface",
337ccc53de9SAndrey V. Elsukov 	"better virtual status",
3385dbfa43fSAndrey V. Elsukov 	"preferred source",
3394ef2dc8bSHajimu UMEMOTO 	"rule #11",
3404ef2dc8bSHajimu UMEMOTO 	"rule #12",
3414ef2dc8bSHajimu UMEMOTO 	"rule #13",
3424ef2dc8bSHajimu UMEMOTO 	"longest match",
3434ef2dc8bSHajimu UMEMOTO 	"rule #15",
3444ef2dc8bSHajimu UMEMOTO };
3454ef2dc8bSHajimu UMEMOTO 
346cfa1ca9dSYoshinobu Inoue /*
347cfa1ca9dSYoshinobu Inoue  * Dump IP6 statistics structure.
348cfa1ca9dSYoshinobu Inoue  */
349cfa1ca9dSYoshinobu Inoue void
ip6_stats(u_long off,const char * name,int af1 __unused,int proto __unused)350feda1a43SJohn Baldwin ip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
351cfa1ca9dSYoshinobu Inoue {
3529eddb899SMark Johnston 	struct ip6stat ip6stat;
353cfa1ca9dSYoshinobu Inoue 	int first, i;
354cfa1ca9dSYoshinobu Inoue 
3559eddb899SMark Johnston 	if (fetch_stats("net.inet6.ip6.stats", off, &ip6stat,
3569eddb899SMark Johnston 	    sizeof(ip6stat), kread_counters) != 0)
3576eec3af9SPoul-Henning Kamp 		return;
3589eddb899SMark Johnston 
359ade9ccfeSMarcel Moolenaar 	xo_open_container(name);
360ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
361cfa1ca9dSYoshinobu Inoue 
362cfa1ca9dSYoshinobu Inoue #define	p(f, m) if (ip6stat.f || sflag <= 1) \
363ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)ip6stat.f, plural(ip6stat.f))
364cfa1ca9dSYoshinobu Inoue #define	p1a(f, m) if (ip6stat.f || sflag <= 1) \
365ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)ip6stat.f)
366cfa1ca9dSYoshinobu Inoue 
367ade9ccfeSMarcel Moolenaar 	p(ip6s_total, "\t{:received-packets/%ju} "
368ade9ccfeSMarcel Moolenaar 	    "{N:/total packet%s received}\n");
369ade9ccfeSMarcel Moolenaar 	p1a(ip6s_toosmall, "\t{:dropped-below-minimum-size/%ju} "
370ade9ccfeSMarcel Moolenaar 	    "{N:/with size smaller than minimum}\n");
371ade9ccfeSMarcel Moolenaar 	p1a(ip6s_tooshort, "\t{:dropped-short-packets/%ju} "
372ade9ccfeSMarcel Moolenaar 	    "{N:/with data size < data length}\n");
373ade9ccfeSMarcel Moolenaar 	p1a(ip6s_badoptions, "\t{:dropped-bad-options/%ju} "
374ade9ccfeSMarcel Moolenaar 	    "{N:/with bad options}\n");
375ade9ccfeSMarcel Moolenaar 	p1a(ip6s_badvers, "\t{:dropped-bad-version/%ju} "
376ade9ccfeSMarcel Moolenaar 	    "{N:/with incorrect version number}\n");
377ade9ccfeSMarcel Moolenaar 	p(ip6s_fragments, "\t{:received-fragments/%ju} "
378ade9ccfeSMarcel Moolenaar 	    "{N:/fragment%s received}\n");
379ade9ccfeSMarcel Moolenaar 	p(ip6s_fragdropped, "\t{:dropped-fragment/%ju} "
380ade9ccfeSMarcel Moolenaar 	    "{N:/fragment%s dropped (dup or out of space)}\n");
381ade9ccfeSMarcel Moolenaar 	p(ip6s_fragtimeout, "\t{:dropped-fragment-after-timeout/%ju} "
382ade9ccfeSMarcel Moolenaar 	    "{N:/fragment%s dropped after timeout}\n");
383ade9ccfeSMarcel Moolenaar 	p(ip6s_fragoverflow, "\t{:dropped-fragments-overflow/%ju} "
384ade9ccfeSMarcel Moolenaar 	    "{N:/fragment%s that exceeded limit}\n");
3852946a941STom Jones 	p(ip6s_atomicfrags, "\t{:atomic-fragments/%ju} "
3862946a941STom Jones 	    "{N:/atomic fragment%s}\n");
387ade9ccfeSMarcel Moolenaar 	p(ip6s_reassembled, "\t{:reassembled-packets/%ju} "
388ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s reassembled ok}\n");
389ade9ccfeSMarcel Moolenaar 	p(ip6s_delivered, "\t{:received-local-packets/%ju} "
390ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s for this host}\n");
391ade9ccfeSMarcel Moolenaar 	p(ip6s_forward, "\t{:forwarded-packets/%ju} "
392ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s forwarded}\n");
393ade9ccfeSMarcel Moolenaar 	p(ip6s_cantforward, "\t{:packets-not-forwardable/%ju} "
394ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s not forwardable}\n");
395ade9ccfeSMarcel Moolenaar 	p(ip6s_redirectsent, "\t{:sent-redirects/%ju} "
396ade9ccfeSMarcel Moolenaar 	    "{N:/redirect%s sent}\n");
397ade9ccfeSMarcel Moolenaar 	p(ip6s_localout, "\t{:sent-packets/%ju} "
398ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s sent from this host}\n");
399ade9ccfeSMarcel Moolenaar 	p(ip6s_rawout, "\t{:send-packets-fabricated-header/%ju} "
400ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s sent with fabricated ip header}\n");
401ade9ccfeSMarcel Moolenaar 	p(ip6s_odropped, "\t{:discard-no-mbufs/%ju} "
402ade9ccfeSMarcel Moolenaar 	    "{N:/output packet%s dropped due to no bufs, etc.}\n");
403ade9ccfeSMarcel Moolenaar 	p(ip6s_noroute, "\t{:discard-no-route/%ju} "
404ade9ccfeSMarcel Moolenaar 	    "{N:/output packet%s discarded due to no route}\n");
405ade9ccfeSMarcel Moolenaar 	p(ip6s_fragmented, "\t{:sent-fragments/%ju} "
406ade9ccfeSMarcel Moolenaar 	    "{N:/output datagram%s fragmented}\n");
407ade9ccfeSMarcel Moolenaar 	p(ip6s_ofragments, "\t{:fragments-created/%ju} "
408ade9ccfeSMarcel Moolenaar 	    "{N:/fragment%s created}\n");
409ade9ccfeSMarcel Moolenaar 	p(ip6s_cantfrag, "\t{:discard-cannot-fragment/%ju} "
410ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s that can't be fragmented}\n");
411ade9ccfeSMarcel Moolenaar 	p(ip6s_badscope, "\t{:discard-scope-violations/%ju} "
412ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s that violated scope rules}\n");
413ade9ccfeSMarcel Moolenaar 	p(ip6s_notmember, "\t{:multicast-no-join-packets/%ju} "
414ade9ccfeSMarcel Moolenaar 	    "{N:/multicast packet%s which we don't join}\n");
415b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_HDRCNT; i++)
416cfa1ca9dSYoshinobu Inoue 		if (ip6stat.ip6s_nxthist[i] != 0) {
417cfa1ca9dSYoshinobu Inoue 			if (first) {
418ade9ccfeSMarcel Moolenaar 				xo_emit("\t{T:Input histogram}:\n");
419ade9ccfeSMarcel Moolenaar 				xo_open_list("input-histogram");
420cfa1ca9dSYoshinobu Inoue 				first = 0;
421cfa1ca9dSYoshinobu Inoue 			}
422ade9ccfeSMarcel Moolenaar 			xo_open_instance("input-histogram");
423ade9ccfeSMarcel Moolenaar 			xo_emit("\t\t{k:name/%s}: {:count/%ju}\n", ip6nh[i],
4247b95a1ebSYaroslav Tykhiy 			    (uintmax_t)ip6stat.ip6s_nxthist[i]);
425ade9ccfeSMarcel Moolenaar 			xo_close_instance("input-histogram");
426cfa1ca9dSYoshinobu Inoue 		}
427ade9ccfeSMarcel Moolenaar 	if (!first)
428ade9ccfeSMarcel Moolenaar 		xo_close_list("input-histogram");
429ade9ccfeSMarcel Moolenaar 
430ade9ccfeSMarcel Moolenaar 	xo_open_container("mbuf-statistics");
431ade9ccfeSMarcel Moolenaar 	xo_emit("\t{T:Mbuf statistics}:\n");
432ade9ccfeSMarcel Moolenaar 	xo_emit("\t\t{:one-mbuf/%ju} {N:/one mbuf}\n",
433ade9ccfeSMarcel Moolenaar 	    (uintmax_t)ip6stat.ip6s_m1);
434b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_M2MMAX; i++) {
4357d56d374SYoshinobu Inoue 		char ifbuf[IFNAMSIZ];
436cfa1ca9dSYoshinobu Inoue 		if (ip6stat.ip6s_m2m[i] != 0) {
437cfa1ca9dSYoshinobu Inoue 			if (first) {
438ade9ccfeSMarcel Moolenaar 				xo_emit("\t\t{N:two or more mbuf}:\n");
439ade9ccfeSMarcel Moolenaar 				xo_open_list("mbuf-data");
440cfa1ca9dSYoshinobu Inoue 				first = 0;
441cfa1ca9dSYoshinobu Inoue 			}
442ade9ccfeSMarcel Moolenaar 			xo_open_instance("mbuf-data");
443ade9ccfeSMarcel Moolenaar 			xo_emit("\t\t\t{k:name/%s}= {:count/%ju}\n",
444cfa1ca9dSYoshinobu Inoue 			    if_indextoname(i, ifbuf),
4457b95a1ebSYaroslav Tykhiy 			    (uintmax_t)ip6stat.ip6s_m2m[i]);
446ade9ccfeSMarcel Moolenaar 			xo_close_instance("mbuf-data");
447cfa1ca9dSYoshinobu Inoue 		}
448cfa1ca9dSYoshinobu Inoue 	}
449ade9ccfeSMarcel Moolenaar 	if (!first)
450ade9ccfeSMarcel Moolenaar 		xo_close_list("mbuf-data");
451ade9ccfeSMarcel Moolenaar 	xo_emit("\t\t{:one-extra-mbuf/%ju} {N:one ext mbuf}\n",
4527b95a1ebSYaroslav Tykhiy 	    (uintmax_t)ip6stat.ip6s_mext1);
453ade9ccfeSMarcel Moolenaar 	xo_emit("\t\t{:two-or-more-extra-mbufs/%ju} "
454ade9ccfeSMarcel Moolenaar 	    "{N:/two or more ext mbuf}\n", (uintmax_t)ip6stat.ip6s_mext2m);
455ade9ccfeSMarcel Moolenaar 	xo_close_container("mbuf-statistics");
456ade9ccfeSMarcel Moolenaar 
457ade9ccfeSMarcel Moolenaar 	p(ip6s_exthdrtoolong, "\t{:dropped-header-too-long/%ju} "
458ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s whose headers are not contiguous}\n");
459ade9ccfeSMarcel Moolenaar 	p(ip6s_nogif, "\t{:discard-tunnel-no-gif/%ju} "
460ade9ccfeSMarcel Moolenaar 	    "{N:/tunneling packet%s that can't find gif}\n");
461ade9ccfeSMarcel Moolenaar 	p(ip6s_toomanyhdr, "\t{:dropped-too-many-headers/%ju} "
462ade9ccfeSMarcel Moolenaar 	    "{N:/packet%s discarded because of too many headers}\n");
46332cd1d96SJun-ichiro itojun Hagino 
46432cd1d96SJun-ichiro itojun Hagino 	/* for debugging source address selection */
46532cd1d96SJun-ichiro itojun Hagino #define	PRINT_SCOPESTAT(s,i) do {\
46632cd1d96SJun-ichiro itojun Hagino 		switch(i) { /* XXX hardcoding in each case */\
46732cd1d96SJun-ichiro itojun Hagino 		case 1:\
468ade9ccfeSMarcel Moolenaar 			p(s, "\t\t{ke:name/interface-locals}{:count/%ju} " \
469ade9ccfeSMarcel Moolenaar 			  "{N:/interface-local%s}\n");	\
47032cd1d96SJun-ichiro itojun Hagino 			break;\
47132cd1d96SJun-ichiro itojun Hagino 		case 2:\
472ade9ccfeSMarcel Moolenaar 			p(s,"\t\t{ke:name/link-locals}{:count/%ju} " \
473ade9ccfeSMarcel Moolenaar 			"{N:/link-local%s}\n"); \
47432cd1d96SJun-ichiro itojun Hagino 			break;\
47532cd1d96SJun-ichiro itojun Hagino 		case 5:\
476ade9ccfeSMarcel Moolenaar 			p(s,"\t\t{ke:name/site-locals}{:count/%ju} " \
477ade9ccfeSMarcel Moolenaar 			  "{N:/site-local%s}\n");\
47832cd1d96SJun-ichiro itojun Hagino 			break;\
47932cd1d96SJun-ichiro itojun Hagino 		case 14:\
480ade9ccfeSMarcel Moolenaar 			p(s,"\t\t{ke:name/globals}{:count/%ju} " \
481ade9ccfeSMarcel Moolenaar 			  "{N:/global%s}\n");\
48232cd1d96SJun-ichiro itojun Hagino 			break;\
48332cd1d96SJun-ichiro itojun Hagino 		default:\
4845ad497eeSMichael Tuexen 			xo_emit("\t\t{qke:name/%#x}{:count/%ju} " \
4855ad497eeSMichael Tuexen 				"{N:/addresses scope=%#x}\n",\
486ade9ccfeSMarcel Moolenaar 				i, (uintmax_t)ip6stat.s, i);	   \
48732cd1d96SJun-ichiro itojun Hagino 		}\
48832cd1d96SJun-ichiro itojun Hagino 	} while (0);
48932cd1d96SJun-ichiro itojun Hagino 
490ade9ccfeSMarcel Moolenaar 	xo_open_container("source-address-selection");
491ade9ccfeSMarcel Moolenaar 	p(ip6s_sources_none, "\t{:address-selection-failures/%ju} "
492ade9ccfeSMarcel Moolenaar 	    "{N:/failure%s of source address selection}\n");
493ade9ccfeSMarcel Moolenaar 
494b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
49532cd1d96SJun-ichiro itojun Hagino 		if (ip6stat.ip6s_sources_sameif[i]) {
49632cd1d96SJun-ichiro itojun Hagino 			if (first) {
497ade9ccfeSMarcel Moolenaar 				xo_open_list("outgoing-interface");
498ade9ccfeSMarcel Moolenaar 				xo_emit("\tsource addresses on an outgoing "
499ade9ccfeSMarcel Moolenaar 				    "I/F\n");
50032cd1d96SJun-ichiro itojun Hagino 				first = 0;
50132cd1d96SJun-ichiro itojun Hagino 			}
502ade9ccfeSMarcel Moolenaar 			xo_open_instance("outgoing-interface");
50332cd1d96SJun-ichiro itojun Hagino 			PRINT_SCOPESTAT(ip6s_sources_sameif[i], i);
504ade9ccfeSMarcel Moolenaar 			xo_close_instance("outgoing-interface");
50532cd1d96SJun-ichiro itojun Hagino 		}
50632cd1d96SJun-ichiro itojun Hagino 	}
507ade9ccfeSMarcel Moolenaar 	if (!first)
508ade9ccfeSMarcel Moolenaar 		xo_close_list("outgoing-interface");
509ade9ccfeSMarcel Moolenaar 
510b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
51132cd1d96SJun-ichiro itojun Hagino 		if (ip6stat.ip6s_sources_otherif[i]) {
51232cd1d96SJun-ichiro itojun Hagino 			if (first) {
513ade9ccfeSMarcel Moolenaar 				xo_open_list("non-outgoing-interface");
514ade9ccfeSMarcel Moolenaar 				xo_emit("\tsource addresses on a non-outgoing "
515ade9ccfeSMarcel Moolenaar 				    "I/F\n");
51632cd1d96SJun-ichiro itojun Hagino 				first = 0;
51732cd1d96SJun-ichiro itojun Hagino 			}
518ade9ccfeSMarcel Moolenaar 			xo_open_instance("non-outgoing-interface");
51932cd1d96SJun-ichiro itojun Hagino 			PRINT_SCOPESTAT(ip6s_sources_otherif[i], i);
520ade9ccfeSMarcel Moolenaar 			xo_close_instance("non-outgoing-interface");
52132cd1d96SJun-ichiro itojun Hagino 		}
52232cd1d96SJun-ichiro itojun Hagino 	}
523ade9ccfeSMarcel Moolenaar 	if (!first)
524ade9ccfeSMarcel Moolenaar 		xo_close_list("non-outgoing-interface");
525ade9ccfeSMarcel Moolenaar 
526b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
52732cd1d96SJun-ichiro itojun Hagino 		if (ip6stat.ip6s_sources_samescope[i]) {
52832cd1d96SJun-ichiro itojun Hagino 			if (first) {
529ade9ccfeSMarcel Moolenaar 				xo_open_list("same-source");
530ade9ccfeSMarcel Moolenaar 				xo_emit("\tsource addresses of same scope\n");
53132cd1d96SJun-ichiro itojun Hagino 				first = 0;
53232cd1d96SJun-ichiro itojun Hagino 			}
533ade9ccfeSMarcel Moolenaar 			xo_open_instance("same-source");
53432cd1d96SJun-ichiro itojun Hagino 			PRINT_SCOPESTAT(ip6s_sources_samescope[i], i);
535ade9ccfeSMarcel Moolenaar 			xo_close_instance("same-source");
53632cd1d96SJun-ichiro itojun Hagino 		}
53732cd1d96SJun-ichiro itojun Hagino 	}
538ade9ccfeSMarcel Moolenaar 	if (!first)
539ade9ccfeSMarcel Moolenaar 		xo_close_list("same-source");
540ade9ccfeSMarcel Moolenaar 
541b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
54232cd1d96SJun-ichiro itojun Hagino 		if (ip6stat.ip6s_sources_otherscope[i]) {
54332cd1d96SJun-ichiro itojun Hagino 			if (first) {
544ade9ccfeSMarcel Moolenaar 				xo_open_list("different-scope");
545ade9ccfeSMarcel Moolenaar 				xo_emit("\tsource addresses of a different "
546ade9ccfeSMarcel Moolenaar 				    "scope\n");
54732cd1d96SJun-ichiro itojun Hagino 				first = 0;
54832cd1d96SJun-ichiro itojun Hagino 			}
549ade9ccfeSMarcel Moolenaar 			xo_open_instance("different-scope");
55032cd1d96SJun-ichiro itojun Hagino 			PRINT_SCOPESTAT(ip6s_sources_otherscope[i], i);
551ade9ccfeSMarcel Moolenaar 			xo_close_instance("different-scope");
55232cd1d96SJun-ichiro itojun Hagino 		}
55332cd1d96SJun-ichiro itojun Hagino 	}
554ade9ccfeSMarcel Moolenaar 	if (!first)
555ade9ccfeSMarcel Moolenaar 		xo_close_list("different-scope");
556ade9ccfeSMarcel Moolenaar 
557b543f3b1SAndrey V. Elsukov 	for (first = 1, i = 0; i < IP6S_SCOPECNT; i++) {
55832cd1d96SJun-ichiro itojun Hagino 		if (ip6stat.ip6s_sources_deprecated[i]) {
55932cd1d96SJun-ichiro itojun Hagino 			if (first) {
560ade9ccfeSMarcel Moolenaar 				xo_open_list("deprecated-source");
561ade9ccfeSMarcel Moolenaar 				xo_emit("\tdeprecated source addresses\n");
56232cd1d96SJun-ichiro itojun Hagino 				first = 0;
56332cd1d96SJun-ichiro itojun Hagino 			}
564ade9ccfeSMarcel Moolenaar 			xo_open_instance("deprecated-source");
56532cd1d96SJun-ichiro itojun Hagino 			PRINT_SCOPESTAT(ip6s_sources_deprecated[i], i);
566ade9ccfeSMarcel Moolenaar 			xo_close_instance("deprecated-source");
56732cd1d96SJun-ichiro itojun Hagino 		}
56832cd1d96SJun-ichiro itojun Hagino 	}
569ade9ccfeSMarcel Moolenaar 	if (!first)
570ade9ccfeSMarcel Moolenaar 		xo_close_list("deprecated-source");
57132cd1d96SJun-ichiro itojun Hagino 
572ade9ccfeSMarcel Moolenaar 	for (first = 1, i = 0; i < IP6S_RULESMAX; i++) {
573ade9ccfeSMarcel Moolenaar 		if (ip6stat.ip6s_sources_rule[i]) {
574ade9ccfeSMarcel Moolenaar 			if (first) {
575ade9ccfeSMarcel Moolenaar 				xo_open_list("rules-applied");
576ade9ccfeSMarcel Moolenaar 				xo_emit("\t{T:Source addresses selection "
577ade9ccfeSMarcel Moolenaar 				    "rule applied}:\n");
578ade9ccfeSMarcel Moolenaar 				first = 0;
579ade9ccfeSMarcel Moolenaar 			}
580ade9ccfeSMarcel Moolenaar 			xo_open_instance("rules-applied");
581ade9ccfeSMarcel Moolenaar 			xo_emit("\t\t{ke:name/%s}{:count/%ju} {d:name/%s}\n",
582ade9ccfeSMarcel Moolenaar 			    srcrule_str[i],
5837b95a1ebSYaroslav Tykhiy 			    (uintmax_t)ip6stat.ip6s_sources_rule[i],
5844ef2dc8bSHajimu UMEMOTO 			    srcrule_str[i]);
585ade9ccfeSMarcel Moolenaar 			xo_close_instance("rules-applied");
5864ef2dc8bSHajimu UMEMOTO 		}
587ade9ccfeSMarcel Moolenaar 	}
588ade9ccfeSMarcel Moolenaar 	if (!first)
589ade9ccfeSMarcel Moolenaar 		xo_close_list("rules-applied");
590ade9ccfeSMarcel Moolenaar 
591ade9ccfeSMarcel Moolenaar 	xo_close_container("source-address-selection");
592ade9ccfeSMarcel Moolenaar 
593cfa1ca9dSYoshinobu Inoue #undef p
59432cd1d96SJun-ichiro itojun Hagino #undef p1a
595ade9ccfeSMarcel Moolenaar 	xo_close_container(name);
596cfa1ca9dSYoshinobu Inoue }
597cfa1ca9dSYoshinobu Inoue 
598cfa1ca9dSYoshinobu Inoue /*
599cfa1ca9dSYoshinobu Inoue  * Dump IPv6 per-interface statistics based on RFC 2465.
600cfa1ca9dSYoshinobu Inoue  */
601cfa1ca9dSYoshinobu Inoue void
ip6_ifstats(char * ifname)6025e051718SAssar Westerlund ip6_ifstats(char *ifname)
603cfa1ca9dSYoshinobu Inoue {
604cfa1ca9dSYoshinobu Inoue 	struct in6_ifreq ifr;
605cfa1ca9dSYoshinobu Inoue 	int s;
606ade9ccfeSMarcel Moolenaar 
607cfa1ca9dSYoshinobu Inoue #define	p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1)	\
608ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)ifr.ifr_ifru.ifru_stat.f,		\
609ade9ccfeSMarcel Moolenaar 	    plural(ifr.ifr_ifru.ifru_stat.f))
610cfa1ca9dSYoshinobu Inoue 
611cfa1ca9dSYoshinobu Inoue 	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
612ade9ccfeSMarcel Moolenaar 		xo_warn("Warning: socket(AF_INET6)");
613cfa1ca9dSYoshinobu Inoue 		return;
614cfa1ca9dSYoshinobu Inoue 	}
615cfa1ca9dSYoshinobu Inoue 
6162b8aaaceSAlan Somers 	strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
617cfa1ca9dSYoshinobu Inoue 	if (ioctl(s, SIOCGIFSTAT_IN6, (char *)&ifr) < 0) {
618d77e67e4SMark Johnston 		if (errno != EPFNOSUPPORT)
619ade9ccfeSMarcel Moolenaar 			xo_warn("Warning: ioctl(SIOCGIFSTAT_IN6)");
620cfa1ca9dSYoshinobu Inoue 		goto end;
621cfa1ca9dSYoshinobu Inoue 	}
622cfa1ca9dSYoshinobu Inoue 
623ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/ip6 on %s}:\n", ifr.ifr_name);
624ade9ccfeSMarcel Moolenaar 
625ade9ccfeSMarcel Moolenaar 	xo_open_instance("ip6-interface-statistics");
626ade9ccfeSMarcel Moolenaar 	xo_emit("{ke:name/%s}", ifr.ifr_name);
627ade9ccfeSMarcel Moolenaar 
628ade9ccfeSMarcel Moolenaar 	p(ifs6_in_receive, "\t{:received-packets/%ju} "
629ade9ccfeSMarcel Moolenaar 	    "{N:/total input datagram%s}\n");
630ade9ccfeSMarcel Moolenaar 	p(ifs6_in_hdrerr, "\t{:dropped-invalid-header/%ju} "
631ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s with invalid header received}\n");
632ade9ccfeSMarcel Moolenaar 	p(ifs6_in_toobig, "\t{:dropped-mtu-exceeded/%ju} "
633ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s exceeded MTU received}\n");
634ade9ccfeSMarcel Moolenaar 	p(ifs6_in_noroute, "\t{:dropped-no-route/%ju} "
635ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s with no route received}\n");
636ade9ccfeSMarcel Moolenaar 	p(ifs6_in_addrerr, "\t{:dropped-invalid-destination/%ju} "
637ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s with invalid dst received}\n");
638ade9ccfeSMarcel Moolenaar 	p(ifs6_in_protounknown, "\t{:dropped-unknown-protocol/%ju} "
639ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s with unknown proto received}\n");
640ade9ccfeSMarcel Moolenaar 	p(ifs6_in_truncated, "\t{:dropped-truncated/%ju} "
641ade9ccfeSMarcel Moolenaar 	    "{N:/truncated datagram%s received}\n");
642ade9ccfeSMarcel Moolenaar 	p(ifs6_in_discard, "\t{:dropped-discarded/%ju} "
643ade9ccfeSMarcel Moolenaar 	    "{N:/input datagram%s discarded}\n");
644ade9ccfeSMarcel Moolenaar  	p(ifs6_in_deliver, "\t{:received-valid-packets/%ju} "
645ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s delivered to an upper layer protocol}\n");
646ade9ccfeSMarcel Moolenaar 	p(ifs6_out_forward, "\t{:sent-forwarded/%ju} "
647ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s forwarded to this interface}\n");
648ade9ccfeSMarcel Moolenaar  	p(ifs6_out_request, "\t{:sent-packets/%ju} "
649ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s sent from an upper layer protocol}\n");
650ade9ccfeSMarcel Moolenaar 	p(ifs6_out_discard, "\t{:discard-packets/%ju} "
651ade9ccfeSMarcel Moolenaar 	    "{N:/total discarded output datagram%s}\n");
652ade9ccfeSMarcel Moolenaar 	p(ifs6_out_fragok, "\t{:discard-fragments/%ju} "
653ade9ccfeSMarcel Moolenaar 	    "{N:/output datagram%s fragmented}\n");
654ade9ccfeSMarcel Moolenaar 	p(ifs6_out_fragfail, "\t{:fragments-failed/%ju} "
655ade9ccfeSMarcel Moolenaar 	    "{N:/output datagram%s failed on fragment}\n");
656ade9ccfeSMarcel Moolenaar 	p(ifs6_out_fragcreat, "\t{:fragments-created/%ju} "
657ade9ccfeSMarcel Moolenaar 	    "{N:/output datagram%s succeeded on fragment}\n");
658ade9ccfeSMarcel Moolenaar 	p(ifs6_reass_reqd, "\t{:reassembly-required/%ju} "
659ade9ccfeSMarcel Moolenaar 	    "{N:/incoming datagram%s fragmented}\n");
660ade9ccfeSMarcel Moolenaar 	p(ifs6_reass_ok, "\t{:reassembled-packets/%ju} "
661ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s reassembled}\n");
662ade9ccfeSMarcel Moolenaar 	p(ifs6_reass_fail, "\t{:reassembly-failed/%ju} "
663ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s failed on reassembly}\n");
664ade9ccfeSMarcel Moolenaar 	p(ifs6_in_mcast, "\t{:received-multicast/%ju} "
665ade9ccfeSMarcel Moolenaar 	    "{N:/multicast datagram%s received}\n");
666ade9ccfeSMarcel Moolenaar 	p(ifs6_out_mcast, "\t{:sent-multicast/%ju} "
667ade9ccfeSMarcel Moolenaar 	    "{N:/multicast datagram%s sent}\n");
668cfa1ca9dSYoshinobu Inoue 
669cfa1ca9dSYoshinobu Inoue  end:
670ade9ccfeSMarcel Moolenaar 	xo_close_instance("ip6-interface-statistics");
671cfa1ca9dSYoshinobu Inoue  	close(s);
672cfa1ca9dSYoshinobu Inoue 
673cfa1ca9dSYoshinobu Inoue #undef p
674cfa1ca9dSYoshinobu Inoue }
675cfa1ca9dSYoshinobu Inoue 
676a01e3379SDavid Malone static	const char *icmp6names[] = {
677cfa1ca9dSYoshinobu Inoue 	"#0",
678cfa1ca9dSYoshinobu Inoue 	"unreach",
679cfa1ca9dSYoshinobu Inoue 	"packet too big",
680cfa1ca9dSYoshinobu Inoue 	"time exceed",
681cfa1ca9dSYoshinobu Inoue 	"parameter problem",
682cfa1ca9dSYoshinobu Inoue 	"#5",
683cfa1ca9dSYoshinobu Inoue 	"#6",
684cfa1ca9dSYoshinobu Inoue 	"#7",
685cfa1ca9dSYoshinobu Inoue 	"#8",
686cfa1ca9dSYoshinobu Inoue 	"#9",
687cfa1ca9dSYoshinobu Inoue 	"#10",
688cfa1ca9dSYoshinobu Inoue 	"#11",
689cfa1ca9dSYoshinobu Inoue 	"#12",
690cfa1ca9dSYoshinobu Inoue 	"#13",
691cfa1ca9dSYoshinobu Inoue 	"#14",
692cfa1ca9dSYoshinobu Inoue 	"#15",
693cfa1ca9dSYoshinobu Inoue 	"#16",
694cfa1ca9dSYoshinobu Inoue 	"#17",
695cfa1ca9dSYoshinobu Inoue 	"#18",
696cfa1ca9dSYoshinobu Inoue 	"#19",
697cfa1ca9dSYoshinobu Inoue 	"#20",
698cfa1ca9dSYoshinobu Inoue 	"#21",
699cfa1ca9dSYoshinobu Inoue 	"#22",
700cfa1ca9dSYoshinobu Inoue 	"#23",
701cfa1ca9dSYoshinobu Inoue 	"#24",
702cfa1ca9dSYoshinobu Inoue 	"#25",
703cfa1ca9dSYoshinobu Inoue 	"#26",
704cfa1ca9dSYoshinobu Inoue 	"#27",
705cfa1ca9dSYoshinobu Inoue 	"#28",
706cfa1ca9dSYoshinobu Inoue 	"#29",
707cfa1ca9dSYoshinobu Inoue 	"#30",
708cfa1ca9dSYoshinobu Inoue 	"#31",
709cfa1ca9dSYoshinobu Inoue 	"#32",
710cfa1ca9dSYoshinobu Inoue 	"#33",
711cfa1ca9dSYoshinobu Inoue 	"#34",
712cfa1ca9dSYoshinobu Inoue 	"#35",
713cfa1ca9dSYoshinobu Inoue 	"#36",
714cfa1ca9dSYoshinobu Inoue 	"#37",
715cfa1ca9dSYoshinobu Inoue 	"#38",
716cfa1ca9dSYoshinobu Inoue 	"#39",
717cfa1ca9dSYoshinobu Inoue 	"#40",
718cfa1ca9dSYoshinobu Inoue 	"#41",
719cfa1ca9dSYoshinobu Inoue 	"#42",
720cfa1ca9dSYoshinobu Inoue 	"#43",
721cfa1ca9dSYoshinobu Inoue 	"#44",
722cfa1ca9dSYoshinobu Inoue 	"#45",
723cfa1ca9dSYoshinobu Inoue 	"#46",
724cfa1ca9dSYoshinobu Inoue 	"#47",
725cfa1ca9dSYoshinobu Inoue 	"#48",
726cfa1ca9dSYoshinobu Inoue 	"#49",
727cfa1ca9dSYoshinobu Inoue 	"#50",
728cfa1ca9dSYoshinobu Inoue 	"#51",
729cfa1ca9dSYoshinobu Inoue 	"#52",
730cfa1ca9dSYoshinobu Inoue 	"#53",
731cfa1ca9dSYoshinobu Inoue 	"#54",
732cfa1ca9dSYoshinobu Inoue 	"#55",
733cfa1ca9dSYoshinobu Inoue 	"#56",
734cfa1ca9dSYoshinobu Inoue 	"#57",
735cfa1ca9dSYoshinobu Inoue 	"#58",
736cfa1ca9dSYoshinobu Inoue 	"#59",
737cfa1ca9dSYoshinobu Inoue 	"#60",
738cfa1ca9dSYoshinobu Inoue 	"#61",
739cfa1ca9dSYoshinobu Inoue 	"#62",
740cfa1ca9dSYoshinobu Inoue 	"#63",
741cfa1ca9dSYoshinobu Inoue 	"#64",
742cfa1ca9dSYoshinobu Inoue 	"#65",
743cfa1ca9dSYoshinobu Inoue 	"#66",
744cfa1ca9dSYoshinobu Inoue 	"#67",
745cfa1ca9dSYoshinobu Inoue 	"#68",
746cfa1ca9dSYoshinobu Inoue 	"#69",
747cfa1ca9dSYoshinobu Inoue 	"#70",
748cfa1ca9dSYoshinobu Inoue 	"#71",
749cfa1ca9dSYoshinobu Inoue 	"#72",
750cfa1ca9dSYoshinobu Inoue 	"#73",
751cfa1ca9dSYoshinobu Inoue 	"#74",
752cfa1ca9dSYoshinobu Inoue 	"#75",
753cfa1ca9dSYoshinobu Inoue 	"#76",
754cfa1ca9dSYoshinobu Inoue 	"#77",
755cfa1ca9dSYoshinobu Inoue 	"#78",
756cfa1ca9dSYoshinobu Inoue 	"#79",
757cfa1ca9dSYoshinobu Inoue 	"#80",
758cfa1ca9dSYoshinobu Inoue 	"#81",
759cfa1ca9dSYoshinobu Inoue 	"#82",
760cfa1ca9dSYoshinobu Inoue 	"#83",
761cfa1ca9dSYoshinobu Inoue 	"#84",
762cfa1ca9dSYoshinobu Inoue 	"#85",
763cfa1ca9dSYoshinobu Inoue 	"#86",
764cfa1ca9dSYoshinobu Inoue 	"#87",
765cfa1ca9dSYoshinobu Inoue 	"#88",
766cfa1ca9dSYoshinobu Inoue 	"#89",
767cfa1ca9dSYoshinobu Inoue 	"#80",
768cfa1ca9dSYoshinobu Inoue 	"#91",
769cfa1ca9dSYoshinobu Inoue 	"#92",
770cfa1ca9dSYoshinobu Inoue 	"#93",
771cfa1ca9dSYoshinobu Inoue 	"#94",
772cfa1ca9dSYoshinobu Inoue 	"#95",
773cfa1ca9dSYoshinobu Inoue 	"#96",
774cfa1ca9dSYoshinobu Inoue 	"#97",
775cfa1ca9dSYoshinobu Inoue 	"#98",
776cfa1ca9dSYoshinobu Inoue 	"#99",
777cfa1ca9dSYoshinobu Inoue 	"#100",
778cfa1ca9dSYoshinobu Inoue 	"#101",
779cfa1ca9dSYoshinobu Inoue 	"#102",
780cfa1ca9dSYoshinobu Inoue 	"#103",
781cfa1ca9dSYoshinobu Inoue 	"#104",
782cfa1ca9dSYoshinobu Inoue 	"#105",
783cfa1ca9dSYoshinobu Inoue 	"#106",
784cfa1ca9dSYoshinobu Inoue 	"#107",
785cfa1ca9dSYoshinobu Inoue 	"#108",
786cfa1ca9dSYoshinobu Inoue 	"#109",
787cfa1ca9dSYoshinobu Inoue 	"#110",
788cfa1ca9dSYoshinobu Inoue 	"#111",
789cfa1ca9dSYoshinobu Inoue 	"#112",
790cfa1ca9dSYoshinobu Inoue 	"#113",
791cfa1ca9dSYoshinobu Inoue 	"#114",
792cfa1ca9dSYoshinobu Inoue 	"#115",
793cfa1ca9dSYoshinobu Inoue 	"#116",
794cfa1ca9dSYoshinobu Inoue 	"#117",
795cfa1ca9dSYoshinobu Inoue 	"#118",
796cfa1ca9dSYoshinobu Inoue 	"#119",
797cfa1ca9dSYoshinobu Inoue 	"#120",
798cfa1ca9dSYoshinobu Inoue 	"#121",
799cfa1ca9dSYoshinobu Inoue 	"#122",
800cfa1ca9dSYoshinobu Inoue 	"#123",
801cfa1ca9dSYoshinobu Inoue 	"#124",
802cfa1ca9dSYoshinobu Inoue 	"#125",
803cfa1ca9dSYoshinobu Inoue 	"#126",
804cfa1ca9dSYoshinobu Inoue 	"#127",
805cfa1ca9dSYoshinobu Inoue 	"echo",
806cfa1ca9dSYoshinobu Inoue 	"echo reply",
807cfa1ca9dSYoshinobu Inoue 	"multicast listener query",
8087d9d64baSBruce M Simpson 	"MLDv1 listener report",
8097d9d64baSBruce M Simpson 	"MLDv1 listener done",
810cfa1ca9dSYoshinobu Inoue 	"router solicitation",
8116ab55b23SDima Dorfman 	"router advertisement",
812cfa1ca9dSYoshinobu Inoue 	"neighbor solicitation",
8136ab55b23SDima Dorfman 	"neighbor advertisement",
814cfa1ca9dSYoshinobu Inoue 	"redirect",
815cfa1ca9dSYoshinobu Inoue 	"router renumbering",
816cfa1ca9dSYoshinobu Inoue 	"node information request",
817cfa1ca9dSYoshinobu Inoue 	"node information reply",
818fd555639SMunechika SUMIKAWA 	"inverse neighbor solicitation",
819fd555639SMunechika SUMIKAWA 	"inverse neighbor advertisement",
8207d9d64baSBruce M Simpson 	"MLDv2 listener report",
821cfa1ca9dSYoshinobu Inoue 	"#144",
822cfa1ca9dSYoshinobu Inoue 	"#145",
823cfa1ca9dSYoshinobu Inoue 	"#146",
824cfa1ca9dSYoshinobu Inoue 	"#147",
825cfa1ca9dSYoshinobu Inoue 	"#148",
826cfa1ca9dSYoshinobu Inoue 	"#149",
827cfa1ca9dSYoshinobu Inoue 	"#150",
828cfa1ca9dSYoshinobu Inoue 	"#151",
829cfa1ca9dSYoshinobu Inoue 	"#152",
830cfa1ca9dSYoshinobu Inoue 	"#153",
831cfa1ca9dSYoshinobu Inoue 	"#154",
832cfa1ca9dSYoshinobu Inoue 	"#155",
833cfa1ca9dSYoshinobu Inoue 	"#156",
834cfa1ca9dSYoshinobu Inoue 	"#157",
835cfa1ca9dSYoshinobu Inoue 	"#158",
836cfa1ca9dSYoshinobu Inoue 	"#159",
837cfa1ca9dSYoshinobu Inoue 	"#160",
838cfa1ca9dSYoshinobu Inoue 	"#161",
839cfa1ca9dSYoshinobu Inoue 	"#162",
840cfa1ca9dSYoshinobu Inoue 	"#163",
841cfa1ca9dSYoshinobu Inoue 	"#164",
842cfa1ca9dSYoshinobu Inoue 	"#165",
843cfa1ca9dSYoshinobu Inoue 	"#166",
844cfa1ca9dSYoshinobu Inoue 	"#167",
845cfa1ca9dSYoshinobu Inoue 	"#168",
846cfa1ca9dSYoshinobu Inoue 	"#169",
847cfa1ca9dSYoshinobu Inoue 	"#170",
848cfa1ca9dSYoshinobu Inoue 	"#171",
849cfa1ca9dSYoshinobu Inoue 	"#172",
850cfa1ca9dSYoshinobu Inoue 	"#173",
851cfa1ca9dSYoshinobu Inoue 	"#174",
852cfa1ca9dSYoshinobu Inoue 	"#175",
853cfa1ca9dSYoshinobu Inoue 	"#176",
854cfa1ca9dSYoshinobu Inoue 	"#177",
855cfa1ca9dSYoshinobu Inoue 	"#178",
856cfa1ca9dSYoshinobu Inoue 	"#179",
857cfa1ca9dSYoshinobu Inoue 	"#180",
858cfa1ca9dSYoshinobu Inoue 	"#181",
859cfa1ca9dSYoshinobu Inoue 	"#182",
860cfa1ca9dSYoshinobu Inoue 	"#183",
861cfa1ca9dSYoshinobu Inoue 	"#184",
862cfa1ca9dSYoshinobu Inoue 	"#185",
863cfa1ca9dSYoshinobu Inoue 	"#186",
864cfa1ca9dSYoshinobu Inoue 	"#187",
865cfa1ca9dSYoshinobu Inoue 	"#188",
866cfa1ca9dSYoshinobu Inoue 	"#189",
867cfa1ca9dSYoshinobu Inoue 	"#180",
868cfa1ca9dSYoshinobu Inoue 	"#191",
869cfa1ca9dSYoshinobu Inoue 	"#192",
870cfa1ca9dSYoshinobu Inoue 	"#193",
871cfa1ca9dSYoshinobu Inoue 	"#194",
872cfa1ca9dSYoshinobu Inoue 	"#195",
873cfa1ca9dSYoshinobu Inoue 	"#196",
874cfa1ca9dSYoshinobu Inoue 	"#197",
875cfa1ca9dSYoshinobu Inoue 	"#198",
876cfa1ca9dSYoshinobu Inoue 	"#199",
877cfa1ca9dSYoshinobu Inoue 	"#200",
878cfa1ca9dSYoshinobu Inoue 	"#201",
879cfa1ca9dSYoshinobu Inoue 	"#202",
880cfa1ca9dSYoshinobu Inoue 	"#203",
881cfa1ca9dSYoshinobu Inoue 	"#204",
882cfa1ca9dSYoshinobu Inoue 	"#205",
883cfa1ca9dSYoshinobu Inoue 	"#206",
884cfa1ca9dSYoshinobu Inoue 	"#207",
885cfa1ca9dSYoshinobu Inoue 	"#208",
886cfa1ca9dSYoshinobu Inoue 	"#209",
887cfa1ca9dSYoshinobu Inoue 	"#210",
888cfa1ca9dSYoshinobu Inoue 	"#211",
889cfa1ca9dSYoshinobu Inoue 	"#212",
890cfa1ca9dSYoshinobu Inoue 	"#213",
891cfa1ca9dSYoshinobu Inoue 	"#214",
892cfa1ca9dSYoshinobu Inoue 	"#215",
893cfa1ca9dSYoshinobu Inoue 	"#216",
894cfa1ca9dSYoshinobu Inoue 	"#217",
895cfa1ca9dSYoshinobu Inoue 	"#218",
896cfa1ca9dSYoshinobu Inoue 	"#219",
897cfa1ca9dSYoshinobu Inoue 	"#220",
898cfa1ca9dSYoshinobu Inoue 	"#221",
899cfa1ca9dSYoshinobu Inoue 	"#222",
900cfa1ca9dSYoshinobu Inoue 	"#223",
901cfa1ca9dSYoshinobu Inoue 	"#224",
902cfa1ca9dSYoshinobu Inoue 	"#225",
903cfa1ca9dSYoshinobu Inoue 	"#226",
904cfa1ca9dSYoshinobu Inoue 	"#227",
905cfa1ca9dSYoshinobu Inoue 	"#228",
906cfa1ca9dSYoshinobu Inoue 	"#229",
907cfa1ca9dSYoshinobu Inoue 	"#230",
908cfa1ca9dSYoshinobu Inoue 	"#231",
909cfa1ca9dSYoshinobu Inoue 	"#232",
910cfa1ca9dSYoshinobu Inoue 	"#233",
911cfa1ca9dSYoshinobu Inoue 	"#234",
912cfa1ca9dSYoshinobu Inoue 	"#235",
913cfa1ca9dSYoshinobu Inoue 	"#236",
914cfa1ca9dSYoshinobu Inoue 	"#237",
915cfa1ca9dSYoshinobu Inoue 	"#238",
916cfa1ca9dSYoshinobu Inoue 	"#239",
917cfa1ca9dSYoshinobu Inoue 	"#240",
918cfa1ca9dSYoshinobu Inoue 	"#241",
919cfa1ca9dSYoshinobu Inoue 	"#242",
920cfa1ca9dSYoshinobu Inoue 	"#243",
921cfa1ca9dSYoshinobu Inoue 	"#244",
922cfa1ca9dSYoshinobu Inoue 	"#245",
923cfa1ca9dSYoshinobu Inoue 	"#246",
924cfa1ca9dSYoshinobu Inoue 	"#247",
925cfa1ca9dSYoshinobu Inoue 	"#248",
926cfa1ca9dSYoshinobu Inoue 	"#249",
927cfa1ca9dSYoshinobu Inoue 	"#250",
928cfa1ca9dSYoshinobu Inoue 	"#251",
929cfa1ca9dSYoshinobu Inoue 	"#252",
930cfa1ca9dSYoshinobu Inoue 	"#253",
931cfa1ca9dSYoshinobu Inoue 	"#254",
932cfa1ca9dSYoshinobu Inoue 	"#255",
933cfa1ca9dSYoshinobu Inoue };
934cfa1ca9dSYoshinobu Inoue 
935cfa1ca9dSYoshinobu Inoue /*
936cfa1ca9dSYoshinobu Inoue  * Dump ICMP6 statistics.
937cfa1ca9dSYoshinobu Inoue  */
938cfa1ca9dSYoshinobu Inoue void
icmp6_stats(u_long off,const char * name,int af1 __unused,int proto __unused)939feda1a43SJohn Baldwin icmp6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
940cfa1ca9dSYoshinobu Inoue {
9419eddb899SMark Johnston 	struct icmp6stat icmp6stat;
942241667c4SMark Murray 	int i, first;
943cfa1ca9dSYoshinobu Inoue 
9449eddb899SMark Johnston 	if (fetch_stats("net.inet6.icmp6.stats", off, &icmp6stat,
9459eddb899SMark Johnston 	    sizeof(icmp6stat), kread_counters) != 0)
946cfa1ca9dSYoshinobu Inoue 		return;
947feda1a43SJohn Baldwin 
948ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
949ade9ccfeSMarcel Moolenaar 	xo_open_container(name);
950cfa1ca9dSYoshinobu Inoue 
951cfa1ca9dSYoshinobu Inoue #define	p(f, m) if (icmp6stat.f || sflag <= 1) \
952ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)icmp6stat.f, plural(icmp6stat.f))
9533ed817f1SMaxim Konovalov #define	p_5(f, m) if (icmp6stat.f || sflag <= 1) \
954ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)icmp6stat.f)
955cfa1ca9dSYoshinobu Inoue 
956ade9ccfeSMarcel Moolenaar 	p(icp6s_error, "\t{:icmp6-calls/%ju} "
957ade9ccfeSMarcel Moolenaar 	    "{N:/call%s to icmp6_error}\n");
958ade9ccfeSMarcel Moolenaar 	p(icp6s_canterror, "\t{:errors-not-generated-from-message/%ju} "
959ade9ccfeSMarcel Moolenaar 	    "{N:/error%s not generated in response to an icmp6 message}\n");
960ade9ccfeSMarcel Moolenaar 	p(icp6s_toofreq, "\t{:errors-discarded-by-rate-limitation/%ju} "
961ade9ccfeSMarcel Moolenaar 	    "{N:/error%s not generated because of rate limitation}\n");
962241667c4SMark Murray #define	NELEM (int)(sizeof(icmp6stat.icp6s_outhist)/sizeof(icmp6stat.icp6s_outhist[0]))
963fd555639SMunechika SUMIKAWA 	for (first = 1, i = 0; i < NELEM; i++)
964cfa1ca9dSYoshinobu Inoue 		if (icmp6stat.icp6s_outhist[i] != 0) {
965cfa1ca9dSYoshinobu Inoue 			if (first) {
966ade9ccfeSMarcel Moolenaar 				xo_open_list("output-histogram");
967ade9ccfeSMarcel Moolenaar 				xo_emit("\t{T:Output histogram}:\n");
968cfa1ca9dSYoshinobu Inoue 				first = 0;
969cfa1ca9dSYoshinobu Inoue 			}
970ade9ccfeSMarcel Moolenaar 			xo_open_instance("output-histogram");
971ade9ccfeSMarcel Moolenaar 			xo_emit("\t\t{k:name/%s}: {:count/%ju}\n",
972ade9ccfeSMarcel Moolenaar 			    icmp6names[i],
9737b95a1ebSYaroslav Tykhiy 			    (uintmax_t)icmp6stat.icp6s_outhist[i]);
974ade9ccfeSMarcel Moolenaar 			xo_close_instance("output-histogram");
975cfa1ca9dSYoshinobu Inoue 		}
976ade9ccfeSMarcel Moolenaar 	if (!first)
977ade9ccfeSMarcel Moolenaar 		xo_close_list("output-histogram");
978fd555639SMunechika SUMIKAWA #undef NELEM
979ade9ccfeSMarcel Moolenaar 
980ade9ccfeSMarcel Moolenaar 	p(icp6s_badcode, "\t{:dropped-bad-code/%ju} "
981ade9ccfeSMarcel Moolenaar 	    "{N:/message%s with bad code fields}\n");
982ade9ccfeSMarcel Moolenaar 	p(icp6s_tooshort, "\t{:dropped-too-short/%ju} "
983ade9ccfeSMarcel Moolenaar 	    "{N:/message%s < minimum length}\n");
984ade9ccfeSMarcel Moolenaar 	p(icp6s_checksum, "\t{:dropped-bad-checksum/%ju} "
985ade9ccfeSMarcel Moolenaar 	    "{N:/bad checksum%s}\n");
986ade9ccfeSMarcel Moolenaar 	p(icp6s_badlen, "\t{:dropped-bad-length/%ju} "
987ade9ccfeSMarcel Moolenaar 	    "{N:/message%s with bad length}\n");
988*4b5634f4SKristof Provost 	p(icp6s_dropped, "\t{:dropped-no-entry/%ju} "
989d18b4becSArseny Smalyuk 	    "{N:/total packet%s dropped due to failed NDP resolution}\n");
990241667c4SMark Murray #define	NELEM (int)(sizeof(icmp6stat.icp6s_inhist)/sizeof(icmp6stat.icp6s_inhist[0]))
991fd555639SMunechika SUMIKAWA 	for (first = 1, i = 0; i < NELEM; i++)
992cfa1ca9dSYoshinobu Inoue 		if (icmp6stat.icp6s_inhist[i] != 0) {
993cfa1ca9dSYoshinobu Inoue 			if (first) {
994ade9ccfeSMarcel Moolenaar 				xo_open_list("input-histogram");
995ade9ccfeSMarcel Moolenaar 				xo_emit("\t{T:Input histogram}:\n");
996cfa1ca9dSYoshinobu Inoue 				first = 0;
997cfa1ca9dSYoshinobu Inoue 			}
998ade9ccfeSMarcel Moolenaar 			xo_open_instance("input-histogram");
999ade9ccfeSMarcel Moolenaar 			xo_emit("\t\t{k:name/%s}: {:count/%ju}\n",
1000ade9ccfeSMarcel Moolenaar 			    icmp6names[i],
10017b95a1ebSYaroslav Tykhiy 			    (uintmax_t)icmp6stat.icp6s_inhist[i]);
1002ade9ccfeSMarcel Moolenaar 			xo_close_instance("input-histogram");
1003cfa1ca9dSYoshinobu Inoue 		}
1004ade9ccfeSMarcel Moolenaar 	if (!first)
1005ade9ccfeSMarcel Moolenaar 		xo_close_list("input-histogram");
1006fd555639SMunechika SUMIKAWA #undef NELEM
1007ade9ccfeSMarcel Moolenaar 	xo_emit("\t{T:Histogram of error messages to be generated}:\n");
1008ade9ccfeSMarcel Moolenaar 	xo_open_container("errors");
1009ade9ccfeSMarcel Moolenaar 	p_5(icp6s_odst_unreach_noroute, "\t\t{:no-route/%ju} "
1010ade9ccfeSMarcel Moolenaar 	    "{N:/no route}\n");
1011ade9ccfeSMarcel Moolenaar 	p_5(icp6s_odst_unreach_admin, "\t\t{:admin-prohibited/%ju} "
1012ade9ccfeSMarcel Moolenaar 	    "{N:/administratively prohibited}\n");
1013ade9ccfeSMarcel Moolenaar 	p_5(icp6s_odst_unreach_beyondscope, "\t\t{:beyond-scope/%ju} "
1014ade9ccfeSMarcel Moolenaar 	    "{N:/beyond scope}\n");
1015ade9ccfeSMarcel Moolenaar 	p_5(icp6s_odst_unreach_addr, "\t\t{:address-unreachable/%ju} "
1016ade9ccfeSMarcel Moolenaar 	    "{N:/address unreachable}\n");
1017ade9ccfeSMarcel Moolenaar 	p_5(icp6s_odst_unreach_noport, "\t\t{:port-unreachable/%ju} "
1018ade9ccfeSMarcel Moolenaar 	    "{N:/port unreachable}\n");
1019ade9ccfeSMarcel Moolenaar 	p_5(icp6s_opacket_too_big, "\t\t{:packet-too-big/%ju} "
1020ade9ccfeSMarcel Moolenaar 	    "{N:/packet too big}\n");
1021ade9ccfeSMarcel Moolenaar 	p_5(icp6s_otime_exceed_transit, "\t\t{:time-exceed-transmit/%ju} "
1022ade9ccfeSMarcel Moolenaar 	    "{N:/time exceed transit}\n");
1023ade9ccfeSMarcel Moolenaar 	p_5(icp6s_otime_exceed_reassembly, "\t\t{:time-exceed-reassembly/%ju} "
1024ade9ccfeSMarcel Moolenaar 	    "{N:/time exceed reassembly}\n");
1025ade9ccfeSMarcel Moolenaar 	p_5(icp6s_oparamprob_header, "\t\t{:bad-header/%ju} "
1026ade9ccfeSMarcel Moolenaar 	    "{N:/erroneous header field}\n");
1027ade9ccfeSMarcel Moolenaar 	p_5(icp6s_oparamprob_nextheader, "\t\t{:bad-next-header/%ju} "
1028ade9ccfeSMarcel Moolenaar 	    "{N:/unrecognized next header}\n");
1029ade9ccfeSMarcel Moolenaar 	p_5(icp6s_oparamprob_option, "\t\t{:bad-option/%ju} "
1030ade9ccfeSMarcel Moolenaar 	    "{N:/unrecognized option}\n");
1031ade9ccfeSMarcel Moolenaar 	p_5(icp6s_oredirect, "\t\t{:redirects/%ju} "
1032ade9ccfeSMarcel Moolenaar 	    "{N:/redirect}\n");
1033ade9ccfeSMarcel Moolenaar 	p_5(icp6s_ounknown, "\t\t{:unknown/%ju} {N:unknown}\n");
103432cd1d96SJun-ichiro itojun Hagino 
1035ade9ccfeSMarcel Moolenaar 	p(icp6s_reflect, "\t{:reflect/%ju} "
1036ade9ccfeSMarcel Moolenaar 	    "{N:/message response%s generated}\n");
1037ade9ccfeSMarcel Moolenaar 	p(icp6s_nd_toomanyopt, "\t{:too-many-nd-options/%ju} "
1038ade9ccfeSMarcel Moolenaar 	    "{N:/message%s with too many ND options}\n");
1039ade9ccfeSMarcel Moolenaar 	p(icp6s_nd_badopt, "\t{:bad-nd-options/%ju} "
1040ade9ccfeSMarcel Moolenaar 	    "{N:/message%s with bad ND options}\n");
1041ade9ccfeSMarcel Moolenaar 	p(icp6s_badns, "\t{:bad-neighbor-solicitation/%ju} "
1042ade9ccfeSMarcel Moolenaar 	    "{N:/bad neighbor solicitation message%s}\n");
1043ade9ccfeSMarcel Moolenaar 	p(icp6s_badna, "\t{:bad-neighbor-advertisement/%ju} "
1044ade9ccfeSMarcel Moolenaar 	    "{N:/bad neighbor advertisement message%s}\n");
1045ade9ccfeSMarcel Moolenaar 	p(icp6s_badrs, "\t{:bad-router-solicitation/%ju} "
1046ade9ccfeSMarcel Moolenaar 	    "{N:/bad router solicitation message%s}\n");
1047ade9ccfeSMarcel Moolenaar 	p(icp6s_badra, "\t{:bad-router-advertisement/%ju} "
1048ade9ccfeSMarcel Moolenaar 	    "{N:/bad router advertisement message%s}\n");
1049ade9ccfeSMarcel Moolenaar 	p(icp6s_badredirect, "\t{:bad-redirect/%ju} "
1050ade9ccfeSMarcel Moolenaar 	    "{N:/bad redirect message%s}\n");
1051d2b8fd0dSBjoern A. Zeeb 	p(icp6s_overflowdefrtr, "\t{:default-routers-overflows/%ju} "
1052d2b8fd0dSBjoern A. Zeeb 	    "{N:/default routers overflow%s}\n");
1053d2b8fd0dSBjoern A. Zeeb 	p(icp6s_overflowprfx, "\t{:prefixes-overflows/%ju} "
1054d2b8fd0dSBjoern A. Zeeb 	    "{N:/prefix overflow%s}\n");
1055d2b8fd0dSBjoern A. Zeeb 	p(icp6s_overflownndp, "\t{:neighbour-entries-overflows/%ju} "
1056d2b8fd0dSBjoern A. Zeeb 	    "{N:/neighbour entries overflow%s}\n");
1057d2b8fd0dSBjoern A. Zeeb 	p(icp6s_overflowredirect, "\t{:redirect-overflows/%ju} "
1058d2b8fd0dSBjoern A. Zeeb 	    "{N:/redirect overflow%s}\n");
10594caea9b1SMark Johnston 	p(icp6s_invlhlim, "\t{:dropped-invalid-hop-limit/%ju} "
10604caea9b1SMark Johnston 	    "{N:/message%s with invalid hop limit}\n");
1061ade9ccfeSMarcel Moolenaar 	xo_close_container("errors");
1062ade9ccfeSMarcel Moolenaar 	p(icp6s_pmtuchg, "\t{:path-mtu-changes/%ju} {N:/path MTU change%s}\n");
1063cfa1ca9dSYoshinobu Inoue #undef p
1064cfa1ca9dSYoshinobu Inoue #undef p_5
1065ade9ccfeSMarcel Moolenaar 	xo_close_container(name);
1066cfa1ca9dSYoshinobu Inoue }
1067cfa1ca9dSYoshinobu Inoue 
1068cfa1ca9dSYoshinobu Inoue /*
1069cfa1ca9dSYoshinobu Inoue  * Dump ICMPv6 per-interface statistics based on RFC 2466.
1070cfa1ca9dSYoshinobu Inoue  */
1071cfa1ca9dSYoshinobu Inoue void
icmp6_ifstats(char * ifname)10725e051718SAssar Westerlund icmp6_ifstats(char *ifname)
1073cfa1ca9dSYoshinobu Inoue {
1074cfa1ca9dSYoshinobu Inoue 	struct in6_ifreq ifr;
1075cfa1ca9dSYoshinobu Inoue 	int s;
1076ade9ccfeSMarcel Moolenaar 
1077cfa1ca9dSYoshinobu Inoue #define	p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1)	\
1078ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f,		\
1079ade9ccfeSMarcel Moolenaar 	    plural(ifr.ifr_ifru.ifru_icmp6stat.f))
1080f99a4046SMike Makonnen #define	p2(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1)	\
1081ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f,		\
1082ade9ccfeSMarcel Moolenaar 	    pluralies(ifr.ifr_ifru.ifru_icmp6stat.f))
1083cfa1ca9dSYoshinobu Inoue 
1084cfa1ca9dSYoshinobu Inoue 	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
1085ade9ccfeSMarcel Moolenaar 		xo_warn("Warning: socket(AF_INET6)");
1086cfa1ca9dSYoshinobu Inoue 		return;
1087cfa1ca9dSYoshinobu Inoue 	}
1088cfa1ca9dSYoshinobu Inoue 
10892b8aaaceSAlan Somers 	strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
1090cfa1ca9dSYoshinobu Inoue 	if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) {
1091d77e67e4SMark Johnston 		if (errno != EPFNOSUPPORT)
1092ade9ccfeSMarcel Moolenaar 			xo_warn("Warning: ioctl(SIOCGIFSTAT_ICMP6)");
1093cfa1ca9dSYoshinobu Inoue 		goto end;
1094cfa1ca9dSYoshinobu Inoue 	}
1095cfa1ca9dSYoshinobu Inoue 
1096ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/icmp6 on %s}:\n", ifr.ifr_name);
1097cfa1ca9dSYoshinobu Inoue 
1098ade9ccfeSMarcel Moolenaar 	xo_open_instance("icmp6-interface-statistics");
1099ade9ccfeSMarcel Moolenaar 	xo_emit("{ke:name/%s}", ifr.ifr_name);
1100ade9ccfeSMarcel Moolenaar 	p(ifs6_in_msg, "\t{:received-packets/%ju} "
1101ade9ccfeSMarcel Moolenaar 	    "{N:/total input message%s}\n");
1102ade9ccfeSMarcel Moolenaar 	p(ifs6_in_error, "\t{:received-errors/%ju} "
1103ade9ccfeSMarcel Moolenaar 	    "{N:/total input error message%s}\n");
1104ade9ccfeSMarcel Moolenaar 	p(ifs6_in_dstunreach, "\t{:received-destination-unreachable/%ju} "
1105ade9ccfeSMarcel Moolenaar 	    "{N:/input destination unreachable error%s}\n");
1106ade9ccfeSMarcel Moolenaar 	p(ifs6_in_adminprohib, "\t{:received-admin-prohibited/%ju} "
1107ade9ccfeSMarcel Moolenaar 	    "{N:/input administratively prohibited error%s}\n");
1108ade9ccfeSMarcel Moolenaar 	p(ifs6_in_timeexceed, "\t{:received-time-exceeded/%ju} "
1109ade9ccfeSMarcel Moolenaar 	    "{N:/input time exceeded error%s}\n");
1110ade9ccfeSMarcel Moolenaar 	p(ifs6_in_paramprob, "\t{:received-bad-parameter/%ju} "
1111ade9ccfeSMarcel Moolenaar 	    "{N:/input parameter problem error%s}\n");
1112ade9ccfeSMarcel Moolenaar 	p(ifs6_in_pkttoobig, "\t{:received-packet-too-big/%ju} "
1113ade9ccfeSMarcel Moolenaar 	    "{N:/input packet too big error%s}\n");
1114ade9ccfeSMarcel Moolenaar 	p(ifs6_in_echo, "\t{:received-echo-requests/%ju} "
1115ade9ccfeSMarcel Moolenaar 	    "{N:/input echo request%s}\n");
1116ade9ccfeSMarcel Moolenaar 	p2(ifs6_in_echoreply, "\t{:received-echo-replies/%ju} "
1117ade9ccfeSMarcel Moolenaar 	    "{N:/input echo repl%s}\n");
1118ade9ccfeSMarcel Moolenaar 	p(ifs6_in_routersolicit, "\t{:received-router-solicitation/%ju} "
1119ade9ccfeSMarcel Moolenaar 	    "{N:/input router solicitation%s}\n");
1120ade9ccfeSMarcel Moolenaar 	p(ifs6_in_routeradvert, "\t{:received-router-advertisement/%ju} "
1121ade9ccfeSMarcel Moolenaar 	    "{N:/input router advertisement%s}\n");
1122ade9ccfeSMarcel Moolenaar 	p(ifs6_in_neighborsolicit, "\t{:received-neighbor-solicitation/%ju} "
1123ade9ccfeSMarcel Moolenaar 	    "{N:/input neighbor solicitation%s}\n");
1124ade9ccfeSMarcel Moolenaar 	p(ifs6_in_neighboradvert, "\t{:received-neighbor-advertisement/%ju} "
1125ade9ccfeSMarcel Moolenaar 	    "{N:/input neighbor advertisement%s}\n");
1126ade9ccfeSMarcel Moolenaar 	p(ifs6_in_redirect, "\t{received-redirects/%ju} "
1127ade9ccfeSMarcel Moolenaar 	    "{N:/input redirect%s}\n");
1128ade9ccfeSMarcel Moolenaar 	p2(ifs6_in_mldquery, "\t{:received-mld-queries/%ju} "
1129ade9ccfeSMarcel Moolenaar 	    "{N:/input MLD quer%s}\n");
1130ade9ccfeSMarcel Moolenaar 	p(ifs6_in_mldreport, "\t{:received-mld-reports/%ju} "
1131ade9ccfeSMarcel Moolenaar 	    "{N:/input MLD report%s}\n");
1132ade9ccfeSMarcel Moolenaar 	p(ifs6_in_mlddone, "\t{:received-mld-done/%ju} "
1133ade9ccfeSMarcel Moolenaar 	    "{N:/input MLD done%s}\n");
1134ade9ccfeSMarcel Moolenaar 
1135ade9ccfeSMarcel Moolenaar 	p(ifs6_out_msg, "\t{:sent-packets/%ju} "
1136ade9ccfeSMarcel Moolenaar 	    "{N:/total output message%s}\n");
1137ade9ccfeSMarcel Moolenaar 	p(ifs6_out_error, "\t{:sent-errors/%ju} "
1138ade9ccfeSMarcel Moolenaar 	    "{N:/total output error message%s}\n");
1139ade9ccfeSMarcel Moolenaar 	p(ifs6_out_dstunreach, "\t{:sent-destination-unreachable/%ju} "
1140ade9ccfeSMarcel Moolenaar 	    "{N:/output destination unreachable error%s}\n");
1141ade9ccfeSMarcel Moolenaar 	p(ifs6_out_adminprohib, "\t{:sent-admin-prohibited/%ju} "
1142ade9ccfeSMarcel Moolenaar 	    "{N:/output administratively prohibited error%s}\n");
1143ade9ccfeSMarcel Moolenaar 	p(ifs6_out_timeexceed, "\t{:sent-time-exceeded/%ju} "
1144ade9ccfeSMarcel Moolenaar 	    "{N:/output time exceeded error%s}\n");
1145ade9ccfeSMarcel Moolenaar 	p(ifs6_out_paramprob, "\t{:sent-bad-parameter/%ju} "
1146ade9ccfeSMarcel Moolenaar 	    "{N:/output parameter problem error%s}\n");
1147ade9ccfeSMarcel Moolenaar 	p(ifs6_out_pkttoobig, "\t{:sent-packet-too-big/%ju} "
1148ade9ccfeSMarcel Moolenaar 	    "{N:/output packet too big error%s}\n");
1149ade9ccfeSMarcel Moolenaar 	p(ifs6_out_echo, "\t{:sent-echo-requests/%ju} "
1150ade9ccfeSMarcel Moolenaar 	    "{N:/output echo request%s}\n");
1151ade9ccfeSMarcel Moolenaar 	p2(ifs6_out_echoreply, "\t{:sent-echo-replies/%ju} "
1152ade9ccfeSMarcel Moolenaar 	    "{N:/output echo repl%s}\n");
1153ade9ccfeSMarcel Moolenaar 	p(ifs6_out_routersolicit, "\t{:sent-router-solicitation/%ju} "
1154ade9ccfeSMarcel Moolenaar 	    "{N:/output router solicitation%s}\n");
1155ade9ccfeSMarcel Moolenaar 	p(ifs6_out_routeradvert, "\t{:sent-router-advertisement/%ju} "
1156ade9ccfeSMarcel Moolenaar 	    "{N:/output router advertisement%s}\n");
1157ade9ccfeSMarcel Moolenaar 	p(ifs6_out_neighborsolicit, "\t{:sent-neighbor-solicitation/%ju} "
1158ade9ccfeSMarcel Moolenaar 	    "{N:/output neighbor solicitation%s}\n");
1159ade9ccfeSMarcel Moolenaar 	p(ifs6_out_neighboradvert, "\t{:sent-neighbor-advertisement/%ju} "
1160ade9ccfeSMarcel Moolenaar 	    "{N:/output neighbor advertisement%s}\n");
1161ade9ccfeSMarcel Moolenaar 	p(ifs6_out_redirect, "\t{:sent-redirects/%ju} "
1162ade9ccfeSMarcel Moolenaar 	    "{N:/output redirect%s}\n");
1163ade9ccfeSMarcel Moolenaar 	p2(ifs6_out_mldquery, "\t{:sent-mld-queries/%ju} "
1164ade9ccfeSMarcel Moolenaar 	    "{N:/output MLD quer%s}\n");
1165ade9ccfeSMarcel Moolenaar 	p(ifs6_out_mldreport, "\t{:sent-mld-reports/%ju} "
1166ade9ccfeSMarcel Moolenaar 	    "{N:/output MLD report%s}\n");
1167ade9ccfeSMarcel Moolenaar 	p(ifs6_out_mlddone, "\t{:sent-mld-dones/%ju} "
1168ade9ccfeSMarcel Moolenaar 	    "{N:/output MLD done%s}\n");
1169cfa1ca9dSYoshinobu Inoue 
1170cfa1ca9dSYoshinobu Inoue end:
1171ade9ccfeSMarcel Moolenaar 	xo_close_instance("icmp6-interface-statistics");
1172cfa1ca9dSYoshinobu Inoue 	close(s);
1173cfa1ca9dSYoshinobu Inoue #undef p
1174cfa1ca9dSYoshinobu Inoue }
1175cfa1ca9dSYoshinobu Inoue 
1176cfa1ca9dSYoshinobu Inoue /*
1177cfa1ca9dSYoshinobu Inoue  * Dump PIM statistics structure.
1178cfa1ca9dSYoshinobu Inoue  */
1179cfa1ca9dSYoshinobu Inoue void
pim6_stats(u_long off,const char * name,int af1 __unused,int proto __unused)1180feda1a43SJohn Baldwin pim6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
1181cfa1ca9dSYoshinobu Inoue {
11829eddb899SMark Johnston 	struct pim6stat pim6stat;
1183cfa1ca9dSYoshinobu Inoue 
11849eddb899SMark Johnston 	if (fetch_stats("net.inet6.pim.stats", off, &pim6stat,
11859eddb899SMark Johnston 	    sizeof(pim6stat), kread) != 0)
1186cfa1ca9dSYoshinobu Inoue 		return;
1187feda1a43SJohn Baldwin 
1188ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
1189ade9ccfeSMarcel Moolenaar 	xo_open_container(name);
1190cfa1ca9dSYoshinobu Inoue 
1191cfa1ca9dSYoshinobu Inoue #define	p(f, m) if (pim6stat.f || sflag <= 1) \
1192ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)pim6stat.f, plural(pim6stat.f))
1193ade9ccfeSMarcel Moolenaar 
1194ade9ccfeSMarcel Moolenaar 	p(pim6s_rcv_total, "\t{:received-packets/%ju} "
1195ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received}\n");
1196ade9ccfeSMarcel Moolenaar 	p(pim6s_rcv_tooshort, "\t{:dropped-too-short/%ju} "
1197ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received with too few bytes}\n");
1198ade9ccfeSMarcel Moolenaar 	p(pim6s_rcv_badsum, "\t{:dropped-bad-checksum/%ju} "
1199ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received with bad checksum}\n");
1200ade9ccfeSMarcel Moolenaar 	p(pim6s_rcv_badversion, "\t{:dropped-bad-version/%ju} "
1201ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received with bad version}\n");
1202ade9ccfeSMarcel Moolenaar 	p(pim6s_rcv_registers, "\t{:received-registers/%ju} "
1203ade9ccfeSMarcel Moolenaar 	    "{N:/register%s received}\n");
1204ade9ccfeSMarcel Moolenaar 	p(pim6s_rcv_badregisters, "\t{:received-bad-registers/%ju} "
1205ade9ccfeSMarcel Moolenaar 	    "{N:/bad register%s received}\n");
1206ade9ccfeSMarcel Moolenaar 	p(pim6s_snd_registers, "\t{:sent-registers/%ju} "
1207ade9ccfeSMarcel Moolenaar 	    "{N:/register%s sent}\n");
1208cfa1ca9dSYoshinobu Inoue #undef p
1209ade9ccfeSMarcel Moolenaar 	xo_close_container(name);
1210cfa1ca9dSYoshinobu Inoue }
1211cfa1ca9dSYoshinobu Inoue 
1212cfa1ca9dSYoshinobu Inoue /*
121333841545SHajimu UMEMOTO  * Dump raw ip6 statistics structure.
121433841545SHajimu UMEMOTO  */
121533841545SHajimu UMEMOTO void
rip6_stats(u_long off,const char * name,int af1 __unused,int proto __unused)1216feda1a43SJohn Baldwin rip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
121733841545SHajimu UMEMOTO {
12189eddb899SMark Johnston 	struct rip6stat rip6stat;
121933841545SHajimu UMEMOTO 	u_quad_t delivered;
122033841545SHajimu UMEMOTO 
12219eddb899SMark Johnston 	if (fetch_stats("net.inet6.ip6.rip6stats", off, &rip6stat,
12229eddb899SMark Johnston 	    sizeof(rip6stat), kread_counters) != 0)
122333841545SHajimu UMEMOTO 		return;
122433841545SHajimu UMEMOTO 
1225ade9ccfeSMarcel Moolenaar 	xo_emit("{T:/%s}:\n", name);
1226ade9ccfeSMarcel Moolenaar 	xo_open_container(name);
122733841545SHajimu UMEMOTO 
122833841545SHajimu UMEMOTO #define	p(f, m) if (rip6stat.f || sflag <= 1) \
1229ade9ccfeSMarcel Moolenaar 	xo_emit(m, (uintmax_t)rip6stat.f, plural(rip6stat.f))
1230ade9ccfeSMarcel Moolenaar 
1231ade9ccfeSMarcel Moolenaar 	p(rip6s_ipackets, "\t{:received-packets/%ju} "
1232ade9ccfeSMarcel Moolenaar 	    "{N:/message%s received}\n");
1233ade9ccfeSMarcel Moolenaar 	p(rip6s_isum, "\t{:input-checksum-computation/%ju} "
1234ade9ccfeSMarcel Moolenaar 	    "{N:/checksum calculation%s on inbound}\n");
1235ade9ccfeSMarcel Moolenaar 	p(rip6s_badsum, "\t{:received-bad-checksum/%ju} "
1236ade9ccfeSMarcel Moolenaar 	    "{N:/message%s with bad checksum}\n");
1237ade9ccfeSMarcel Moolenaar 	p(rip6s_nosock, "\t{:dropped-no-socket/%ju} "
1238ade9ccfeSMarcel Moolenaar 	    "{N:/message%s dropped due to no socket}\n");
1239ade9ccfeSMarcel Moolenaar 	p(rip6s_nosockmcast, "\t{:dropped-multicast-no-socket/%ju} "
1240ade9ccfeSMarcel Moolenaar 	    "{N:/multicast message%s dropped due to no socket}\n");
1241ade9ccfeSMarcel Moolenaar 	p(rip6s_fullsock, "\t{:dropped-full-socket-buffer/%ju} "
1242ade9ccfeSMarcel Moolenaar 	    "{N:/message%s dropped due to full socket buffers}\n");
124333841545SHajimu UMEMOTO 	delivered = rip6stat.rip6s_ipackets -
124433841545SHajimu UMEMOTO 		    rip6stat.rip6s_badsum -
124533841545SHajimu UMEMOTO 		    rip6stat.rip6s_nosock -
124633841545SHajimu UMEMOTO 		    rip6stat.rip6s_nosockmcast -
124733841545SHajimu UMEMOTO 		    rip6stat.rip6s_fullsock;
124833841545SHajimu UMEMOTO 	if (delivered || sflag <= 1)
1249ade9ccfeSMarcel Moolenaar 		xo_emit("\t{:delivered-packets/%ju} {N:/delivered}\n",
1250ade9ccfeSMarcel Moolenaar 		    (uintmax_t)delivered);
1251ade9ccfeSMarcel Moolenaar 	p(rip6s_opackets, "\t{:sent-packets/%ju} "
1252ade9ccfeSMarcel Moolenaar 	    "{N:/datagram%s output}\n");
125333841545SHajimu UMEMOTO #undef p
1254ade9ccfeSMarcel Moolenaar 	xo_close_container(name);
125533841545SHajimu UMEMOTO }
125633841545SHajimu UMEMOTO 
125733841545SHajimu UMEMOTO /*
1258cfa1ca9dSYoshinobu Inoue  * Pretty print an Internet address (net address + port).
125965ea0024SAssar Westerlund  * Take numeric_addr and numeric_port into consideration.
1260cfa1ca9dSYoshinobu Inoue  */
1261cfa1ca9dSYoshinobu Inoue #define	GETSERVBYPORT6(port, proto, ret)\
1262cfa1ca9dSYoshinobu Inoue {\
1263cfa1ca9dSYoshinobu Inoue 	if (strcmp((proto), "tcp6") == 0)\
1264cfa1ca9dSYoshinobu Inoue 		(ret) = getservbyport((int)(port), "tcp");\
1265cfa1ca9dSYoshinobu Inoue 	else if (strcmp((proto), "udp6") == 0)\
1266cfa1ca9dSYoshinobu Inoue 		(ret) = getservbyport((int)(port), "udp");\
1267cfa1ca9dSYoshinobu Inoue 	else\
1268cfa1ca9dSYoshinobu Inoue 		(ret) = getservbyport((int)(port), (proto));\
1269cfa1ca9dSYoshinobu Inoue };
1270cfa1ca9dSYoshinobu Inoue 
1271cfa1ca9dSYoshinobu Inoue void
inet6print(const char * container,struct in6_addr * in6,int port,const char * proto,int numeric)1272ade9ccfeSMarcel Moolenaar inet6print(const char *container, struct in6_addr *in6, int port,
1273ade9ccfeSMarcel Moolenaar     const char *proto, int numeric)
1274cfa1ca9dSYoshinobu Inoue {
1275cfa1ca9dSYoshinobu Inoue 	struct servent *sp = 0;
1276cfa1ca9dSYoshinobu Inoue 	char line[80], *cp;
1277cfa1ca9dSYoshinobu Inoue 	int width;
1278f193c8ceSXin LI 	size_t alen, plen;
1279cfa1ca9dSYoshinobu Inoue 
1280ade9ccfeSMarcel Moolenaar 	if (container)
1281ade9ccfeSMarcel Moolenaar 		xo_open_container(container);
1282ade9ccfeSMarcel Moolenaar 
1283f193c8ceSXin LI 	snprintf(line, sizeof(line), "%.*s.",
1284f193c8ceSXin LI 	    Wflag ? 39 : (Aflag && !numeric) ? 12 : 16,
1285ade9ccfeSMarcel Moolenaar 	    inet6name(in6));
1286f193c8ceSXin LI 	alen = strlen(line);
1287f193c8ceSXin LI 	cp = line + alen;
1288cfa1ca9dSYoshinobu Inoue 	if (!numeric && port)
1289cfa1ca9dSYoshinobu Inoue 		GETSERVBYPORT6(port, proto, sp);
1290cfa1ca9dSYoshinobu Inoue 	if (sp || port == 0)
1291f193c8ceSXin LI 		snprintf(cp, sizeof(line) - alen,
1292f193c8ceSXin LI 		    "%.15s", sp ? sp->s_name : "*");
1293cfa1ca9dSYoshinobu Inoue 	else
1294f193c8ceSXin LI 		snprintf(cp, sizeof(line) - alen,
1295f193c8ceSXin LI 		    "%d", ntohs((u_short)port));
129670057abfSRuslan Ermilov 	width = Wflag ? 45 : Aflag ? 18 : 22;
1297ade9ccfeSMarcel Moolenaar 
1298ade9ccfeSMarcel Moolenaar 	xo_emit("{d:target/%-*.*s} ", width, width, line);
1299ade9ccfeSMarcel Moolenaar 
1300f03f398cSHajimu UMEMOTO 	plen = strlen(cp);
1301f193c8ceSXin LI 	alen--;
1302ade9ccfeSMarcel Moolenaar 	xo_emit("{e:address/%*.*s}{e:port/%*.*s}", alen, alen, line, plen,
1303ade9ccfeSMarcel Moolenaar 	    plen, cp);
1304ade9ccfeSMarcel Moolenaar 
1305ade9ccfeSMarcel Moolenaar 	if (container)
1306ade9ccfeSMarcel Moolenaar 		xo_close_container(container);
1307cfa1ca9dSYoshinobu Inoue }
1308cfa1ca9dSYoshinobu Inoue 
1309cfa1ca9dSYoshinobu Inoue /*
1310cfa1ca9dSYoshinobu Inoue  * Construct an Internet address representation.
131165ea0024SAssar Westerlund  * If the numeric_addr has been supplied, give
1312cfa1ca9dSYoshinobu Inoue  * numeric value, otherwise try for symbolic name.
1313cfa1ca9dSYoshinobu Inoue  */
1314cfa1ca9dSYoshinobu Inoue 
1315cfa1ca9dSYoshinobu Inoue char *
inet6name(struct in6_addr * ia6)131657a44fcdSBjoern A. Zeeb inet6name(struct in6_addr *ia6)
1317cfa1ca9dSYoshinobu Inoue {
131884dde578SHiroki Sato 	struct sockaddr_in6 sin6;
131984dde578SHiroki Sato 	char hbuf[NI_MAXHOST], *cp;
1320f193c8ceSXin LI 	static char line[NI_MAXHOST];
1321d121b556SBrian Somers 	static char domain[MAXHOSTNAMELEN];
1322cfa1ca9dSYoshinobu Inoue 	static int first = 1;
132384dde578SHiroki Sato 	int flags, error;
1324cfa1ca9dSYoshinobu Inoue 
132557a44fcdSBjoern A. Zeeb 	if (IN6_IS_ADDR_UNSPECIFIED(ia6)) {
132684dde578SHiroki Sato 		strcpy(line, "*");
132784dde578SHiroki Sato 		return (line);
132884dde578SHiroki Sato 	}
132965ea0024SAssar Westerlund 	if (first && !numeric_addr) {
1330cfa1ca9dSYoshinobu Inoue 		first = 0;
1331f193c8ceSXin LI 		if (gethostname(domain, sizeof(domain)) == 0 &&
1332b3608ae1SEd Schouten 		    (cp = strchr(domain, '.')))
1333f193c8ceSXin LI 			strlcpy(domain, cp + 1, sizeof(domain));
1334cfa1ca9dSYoshinobu Inoue 		else
1335cfa1ca9dSYoshinobu Inoue 			domain[0] = 0;
1336cfa1ca9dSYoshinobu Inoue 	}
133784dde578SHiroki Sato 	memset(&sin6, 0, sizeof(sin6));
133857a44fcdSBjoern A. Zeeb 	memcpy(&sin6.sin6_addr, ia6, sizeof(*ia6));
133984dde578SHiroki Sato 	sin6.sin6_family = AF_INET6;
134057a44fcdSBjoern A. Zeeb 	/* XXX: ia6.s6_addr[2] can contain scopeid. */
134184dde578SHiroki Sato 	in6_fillscopeid(&sin6);
134284dde578SHiroki Sato 	flags = (numeric_addr) ? NI_NUMERICHOST : 0;
134384dde578SHiroki Sato 	error = getnameinfo((struct sockaddr *)&sin6, sizeof(sin6), hbuf,
134484dde578SHiroki Sato 	    sizeof(hbuf), NULL, 0, flags);
134584dde578SHiroki Sato 	if (error == 0) {
134684dde578SHiroki Sato 		if ((flags & NI_NUMERICHOST) == 0 &&
134784dde578SHiroki Sato 		    (cp = strchr(hbuf, '.')) &&
1348cfa1ca9dSYoshinobu Inoue 		    !strcmp(cp + 1, domain))
1349cfa1ca9dSYoshinobu Inoue 			*cp = 0;
1350f193c8ceSXin LI 		strlcpy(line, hbuf, sizeof(line));
135184dde578SHiroki Sato 	} else {
135284dde578SHiroki Sato 		/* XXX: this should not happen. */
1353f193c8ceSXin LI 		snprintf(line, sizeof(line), "%s",
135484dde578SHiroki Sato 			inet_ntop(AF_INET6, (void *)&sin6.sin6_addr, ntop_buf,
1355cfa1ca9dSYoshinobu Inoue 				sizeof(ntop_buf)));
135684dde578SHiroki Sato 	}
1357cfa1ca9dSYoshinobu Inoue 	return (line);
1358cfa1ca9dSYoshinobu Inoue }
1359d84a1df4SHajimu UMEMOTO #endif /*INET6*/
1360