]>
Commit | Line | Data |
---|---|---|
9c859447 | 1 | /* |
89c4ed63 | 2 | * Copyright (c) 2008-2015 Apple Inc. All rights reserved. |
9c859447 A |
3 | * |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
27 | */ | |
b8dff150 | 28 | |
7ba0088d A |
29 | /* BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp */ |
30 | /* | |
31 | * Copyright (c) 1983, 1988, 1993 | |
32 | * The Regents of the University of California. All rights reserved. | |
33 | * | |
34 | * Redistribution and use in source and binary forms, with or without | |
35 | * modification, are permitted provided that the following conditions | |
36 | * are met: | |
37 | * 1. Redistributions of source code must retain the above copyright | |
38 | * notice, this list of conditions and the following disclaimer. | |
39 | * 2. Redistributions in binary form must reproduce the above copyright | |
40 | * notice, this list of conditions and the following disclaimer in the | |
41 | * documentation and/or other materials provided with the distribution. | |
42 | * 3. All advertising materials mentioning features or use of this software | |
43 | * must display the following acknowledgement: | |
44 | * This product includes software developed by the University of | |
45 | * California, Berkeley and its contributors. | |
46 | * 4. Neither the name of the University nor the names of its contributors | |
47 | * may be used to endorse or promote products derived from this software | |
48 | * without specific prior written permission. | |
49 | * | |
50 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
51 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
52 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
53 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
54 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
55 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
56 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
57 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
58 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
59 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
60 | * SUCH DAMAGE. | |
61 | * | |
62 | * $FreeBSD: src/usr.bin/netstat/inet6.c,v 1.3.2.9 2001/08/10 09:07:09 ru Exp $ | |
63 | */ | |
64 | ||
7ba0088d A |
65 | #ifdef INET6 |
66 | #include <sys/param.h> | |
67 | #include <sys/socket.h> | |
68 | #include <sys/socketvar.h> | |
69 | #include <sys/ioctl.h> | |
7ba0088d A |
70 | #include <sys/sysctl.h> |
71 | ||
72 | #include <net/route.h> | |
73 | #include <net/if.h> | |
74 | #include <net/if_var.h> | |
89c4ed63 | 75 | #include <net/net_perf.h> |
7ba0088d A |
76 | #include <netinet/in.h> |
77 | #include <netinet/ip6.h> | |
78 | #include <netinet/icmp6.h> | |
79 | #include <netinet/in_systm.h> | |
80 | #include <netinet6/in6_pcb.h> | |
81 | #include <netinet6/in6_var.h> | |
82 | #include <netinet6/ip6_var.h> | |
7ba0088d A |
83 | #include <netinet6/raw_ip6.h> |
84 | ||
85 | #include <arpa/inet.h> | |
86 | #include <netdb.h> | |
87 | ||
88 | #include <stdio.h> | |
89 | #include <string.h> | |
90 | #include <unistd.h> | |
91 | #include "netstat.h" | |
92 | ||
b8dff150 | 93 | #if defined(__APPLE__) && !defined(__unused) |
7ba0088d A |
94 | #define __unused |
95 | #endif | |
7ba0088d A |
96 | |
97 | char *inet6name (struct in6_addr *); | |
98 | void inet6print (struct in6_addr *, int, char *, int); | |
99 | ||
7ba0088d A |
100 | static char *ip6nh[] = { |
101 | "hop by hop", | |
102 | "ICMP", | |
103 | "IGMP", | |
104 | "#3", | |
105 | "IP", | |
106 | "#5", | |
107 | "TCP", | |
108 | "#7", | |
109 | "#8", | |
110 | "#9", | |
111 | "#10", | |
112 | "#11", | |
113 | "#12", | |
114 | "#13", | |
115 | "#14", | |
116 | "#15", | |
117 | "#16", | |
118 | "UDP", | |
119 | "#18", | |
120 | "#19", | |
121 | "#20", | |
122 | "#21", | |
123 | "IDP", | |
124 | "#23", | |
125 | "#24", | |
126 | "#25", | |
127 | "#26", | |
128 | "#27", | |
129 | "#28", | |
130 | "TP", | |
131 | "#30", | |
132 | "#31", | |
133 | "#32", | |
134 | "#33", | |
135 | "#34", | |
136 | "#35", | |
137 | "#36", | |
138 | "#37", | |
139 | "#38", | |
140 | "#39", | |
141 | "#40", | |
142 | "IP6", | |
143 | "#42", | |
144 | "routing", | |
145 | "fragment", | |
146 | "#45", | |
147 | "#46", | |
148 | "#47", | |
149 | "#48", | |
150 | "#49", | |
151 | "ESP", | |
152 | "AH", | |
153 | "#52", | |
154 | "#53", | |
155 | "#54", | |
156 | "#55", | |
157 | "#56", | |
158 | "#57", | |
159 | "ICMP6", | |
160 | "no next header", | |
161 | "destination option", | |
162 | "#61", | |
fdfd5971 | 163 | "mobility", |
7ba0088d A |
164 | "#63", |
165 | "#64", | |
166 | "#65", | |
167 | "#66", | |
168 | "#67", | |
169 | "#68", | |
170 | "#69", | |
171 | "#70", | |
172 | "#71", | |
173 | "#72", | |
174 | "#73", | |
175 | "#74", | |
176 | "#75", | |
177 | "#76", | |
178 | "#77", | |
179 | "#78", | |
180 | "#79", | |
181 | "ISOIP", | |
182 | "#81", | |
183 | "#82", | |
184 | "#83", | |
185 | "#84", | |
186 | "#85", | |
187 | "#86", | |
188 | "#87", | |
189 | "#88", | |
190 | "OSPF", | |
191 | "#80", | |
192 | "#91", | |
193 | "#92", | |
194 | "#93", | |
195 | "#94", | |
196 | "#95", | |
197 | "#96", | |
198 | "Ethernet", | |
199 | "#98", | |
200 | "#99", | |
201 | "#100", | |
202 | "#101", | |
203 | "#102", | |
204 | "PIM", | |
205 | "#104", | |
206 | "#105", | |
207 | "#106", | |
208 | "#107", | |
209 | "#108", | |
210 | "#109", | |
211 | "#110", | |
212 | "#111", | |
213 | "#112", | |
214 | "#113", | |
215 | "#114", | |
216 | "#115", | |
217 | "#116", | |
218 | "#117", | |
219 | "#118", | |
220 | "#119", | |
221 | "#120", | |
222 | "#121", | |
223 | "#122", | |
224 | "#123", | |
225 | "#124", | |
226 | "#125", | |
227 | "#126", | |
228 | "#127", | |
229 | "#128", | |
230 | "#129", | |
231 | "#130", | |
232 | "#131", | |
233 | "#132", | |
234 | "#133", | |
235 | "#134", | |
236 | "#135", | |
237 | "#136", | |
238 | "#137", | |
239 | "#138", | |
240 | "#139", | |
241 | "#140", | |
242 | "#141", | |
243 | "#142", | |
244 | "#143", | |
245 | "#144", | |
246 | "#145", | |
247 | "#146", | |
248 | "#147", | |
249 | "#148", | |
250 | "#149", | |
251 | "#150", | |
252 | "#151", | |
253 | "#152", | |
254 | "#153", | |
255 | "#154", | |
256 | "#155", | |
257 | "#156", | |
258 | "#157", | |
259 | "#158", | |
260 | "#159", | |
261 | "#160", | |
262 | "#161", | |
263 | "#162", | |
264 | "#163", | |
265 | "#164", | |
266 | "#165", | |
267 | "#166", | |
268 | "#167", | |
269 | "#168", | |
270 | "#169", | |
271 | "#170", | |
272 | "#171", | |
273 | "#172", | |
274 | "#173", | |
275 | "#174", | |
276 | "#175", | |
277 | "#176", | |
278 | "#177", | |
279 | "#178", | |
280 | "#179", | |
281 | "#180", | |
282 | "#181", | |
283 | "#182", | |
284 | "#183", | |
285 | "#184", | |
286 | "#185", | |
287 | "#186", | |
288 | "#187", | |
289 | "#188", | |
290 | "#189", | |
291 | "#180", | |
292 | "#191", | |
293 | "#192", | |
294 | "#193", | |
295 | "#194", | |
296 | "#195", | |
297 | "#196", | |
298 | "#197", | |
299 | "#198", | |
300 | "#199", | |
301 | "#200", | |
302 | "#201", | |
303 | "#202", | |
304 | "#203", | |
305 | "#204", | |
306 | "#205", | |
307 | "#206", | |
308 | "#207", | |
309 | "#208", | |
310 | "#209", | |
311 | "#210", | |
312 | "#211", | |
313 | "#212", | |
314 | "#213", | |
315 | "#214", | |
316 | "#215", | |
317 | "#216", | |
318 | "#217", | |
319 | "#218", | |
320 | "#219", | |
321 | "#220", | |
322 | "#221", | |
323 | "#222", | |
324 | "#223", | |
325 | "#224", | |
326 | "#225", | |
327 | "#226", | |
328 | "#227", | |
329 | "#228", | |
330 | "#229", | |
331 | "#230", | |
332 | "#231", | |
333 | "#232", | |
334 | "#233", | |
335 | "#234", | |
336 | "#235", | |
337 | "#236", | |
338 | "#237", | |
339 | "#238", | |
340 | "#239", | |
341 | "#240", | |
342 | "#241", | |
343 | "#242", | |
344 | "#243", | |
345 | "#244", | |
346 | "#245", | |
347 | "#246", | |
348 | "#247", | |
349 | "#248", | |
350 | "#249", | |
351 | "#250", | |
352 | "#251", | |
353 | "#252", | |
354 | "#253", | |
355 | "#254", | |
356 | "#255", | |
357 | }; | |
358 | ||
89c4ed63 A |
359 | |
360 | static const char *srcrulenames[IP6S_SRCRULE_COUNT] = { | |
361 | "default", // IP6S_SRCRULE_0 | |
362 | "prefer same address", // IP6S_SRCRULE_1 | |
363 | "prefer appropriate scope", // IP6S_SRCRULE_2 | |
364 | "avoid deprecated addresses", // IP6S_SRCRULE_3 | |
365 | "prefer home addresses", // IP6S_SRCRULE_4 | |
366 | "prefer outgoing interface", // IP6S_SRCRULE_5 | |
367 | "prefer addresses in a prefix advertised by the next-hop", | |
368 | // IP6S_SRCRULE_5_5 | |
369 | "prefer matching label", // IP6S_SRCRULE_6 | |
370 | "prefer temporary addresses", // IP6S_SRCRULE_7 | |
371 | "prefer addresses on alive interfaces", // IP6S_SRCRULE_7x | |
372 | "use longest matching prefix", // IP6S_SRCRULE_8 | |
373 | NULL, | |
374 | NULL, | |
375 | NULL, | |
376 | NULL, | |
377 | NULL | |
378 | }; | |
379 | ||
7ba0088d A |
380 | /* |
381 | * Dump IP6 statistics structure. | |
382 | */ | |
383 | void | |
9c859447 | 384 | ip6_stats(uint32_t off __unused, char *name, int af __unused) |
7ba0088d | 385 | { |
b8dff150 | 386 | static struct ip6stat pip6stat; |
7ba0088d A |
387 | struct ip6stat ip6stat; |
388 | int first, i; | |
389 | int mib[4]; | |
390 | size_t len; | |
89c4ed63 A |
391 | static net_perf_t pout_net_perf, pin_net_perf; |
392 | net_perf_t out_net_perf, in_net_perf; | |
393 | size_t out_net_perf_len = sizeof (out_net_perf); | |
394 | size_t in_net_perf_len = sizeof (in_net_perf); | |
395 | ||
396 | if (sysctlbyname("net.inet6.ip6.output_perf_data", &out_net_perf, &out_net_perf_len, 0, 0) < 0) { | |
397 | perror("sysctl: net.inet6.ip6.output_perf_data"); | |
398 | return; | |
399 | } | |
400 | ||
401 | if (sysctlbyname("net.inet6.ip6.input_perf_data", &in_net_perf, &in_net_perf_len, 0, 0) < 0) { | |
402 | perror("sysctl: net.inet6.ip6.input_perf_data"); | |
403 | return; | |
404 | } | |
7ba0088d A |
405 | |
406 | mib[0] = CTL_NET; | |
407 | mib[1] = PF_INET6; | |
408 | mib[2] = IPPROTO_IPV6; | |
409 | mib[3] = IPV6CTL_STATS; | |
410 | ||
411 | len = sizeof ip6stat; | |
412 | memset(&ip6stat, 0, len); | |
413 | if (sysctl(mib, 4, &ip6stat, &len, (void *)0, 0) < 0) | |
414 | return; | |
9dc66a05 A |
415 | if (interval && vflag > 0) |
416 | print_time(); | |
7ba0088d A |
417 | printf("%s:\n", name); |
418 | ||
b8dff150 A |
419 | #define IP6DIFF(f) (ip6stat.f - pip6stat.f) |
420 | #define p(f, m) if (IP6DIFF(f) || sflag <= 1) \ | |
421 | printf(m, (unsigned long long)IP6DIFF(f), plural(IP6DIFF(f))) | |
422 | #define p1a(f, m) if (IP6DIFF(f) || sflag <= 1) \ | |
423 | printf(m, (unsigned long long)IP6DIFF(f)) | |
7ba0088d A |
424 | |
425 | p(ip6s_total, "\t%llu total packet%s received\n"); | |
9dc66a05 A |
426 | p1a(ip6s_toosmall, "\t\t%llu with size smaller than minimum\n"); |
427 | p1a(ip6s_tooshort, "\t\t%llu with data size < data length\n"); | |
428 | p1a(ip6s_adj, "\t\t%llu with data size > data length\n"); | |
429 | p(ip6s_adj_hwcsum_clr, | |
430 | "\t\t\t%llu packet%s forced to software checksum\n"); | |
431 | p1a(ip6s_badoptions, "\t\t%llu with bad options\n"); | |
432 | p1a(ip6s_badvers, "\t\t%llu with incorrect version number\n"); | |
433 | p(ip6s_fragments, "\t\t%llu fragment%s received\n"); | |
434 | p1a(ip6s_fragdropped, | |
435 | "\t\t\t%llu dropped (dup or out of space)\n"); | |
436 | p1a(ip6s_fragtimeout, "\t\t\t%llu dropped after timeout\n"); | |
437 | p1a(ip6s_fragoverflow, "\t\t\t%llu exceeded limit\n"); | |
438 | p1a(ip6s_reassembled, "\t\t\t%llu reassembled ok\n"); | |
26c66ce9 | 439 | p1a(ip6s_atmfrag_rcvd, "\t\t\t%llu atomic fragments received\n"); |
9dc66a05 A |
440 | p(ip6s_delivered, "\t\t%llu packet%s for this host\n"); |
441 | p(ip6s_forward, "\t\t%llu packet%s forwarded\n"); | |
442 | p(ip6s_cantforward, "\t\t%llu packet%s not forwardable\n"); | |
443 | p(ip6s_redirectsent, "\t\t%llu redirect%s sent\n"); | |
444 | p(ip6s_notmember, "\t\t%llu multicast packet%s which we don't join\n"); | |
445 | p(ip6s_exthdrtoolong, | |
446 | "\t\t%llu packet%s whose headers are not continuous\n"); | |
447 | p(ip6s_nogif, "\t\t%llu tunneling packet%s that can't find gif\n"); | |
448 | p(ip6s_toomanyhdr, | |
449 | "\t\t%llu packet%s discarded due to too may headers\n"); | |
450 | p1a(ip6s_forward_cachehit, "\t\t%llu forward cache hit\n"); | |
451 | p1a(ip6s_forward_cachemiss, "\t\t%llu forward cache miss\n"); | |
452 | p(ip6s_pktdropcntrl, | |
453 | "\t\t%llu packet%s dropped due to no bufs for control data\n"); | |
89c4ed63 A |
454 | |
455 | #define INPERFDIFF(f) (in_net_perf.f - pin_net_perf.f) | |
456 | if (INPERFDIFF(np_total_pkts) > 0 && in_net_perf.np_total_usecs > 0) { | |
457 | printf("\tInput Performance Stats:\n"); | |
458 | printf("\t\t%llu total packets measured\n", INPERFDIFF(np_total_pkts)); | |
459 | printf("\t\t%llu total usec elapsed\n", INPERFDIFF(np_total_usecs)); | |
460 | printf("\t\t%f usec per packet\n", | |
461 | (double)in_net_perf.np_total_usecs/(double)in_net_perf.np_total_pkts); | |
462 | printf("\t\tPerformance Histogram:\n"); | |
463 | printf("\t\t\t x <= %u: %llu\n", in_net_perf.np_hist_bars[0], | |
464 | INPERFDIFF(np_hist1)); | |
465 | printf("\t\t\t %u < x <= %u: %llu\n", | |
466 | in_net_perf.np_hist_bars[0], in_net_perf.np_hist_bars[1], | |
467 | INPERFDIFF(np_hist2)); | |
468 | printf("\t\t\t %u < x <= %u: %llu\n", | |
469 | in_net_perf.np_hist_bars[1], in_net_perf.np_hist_bars[2], | |
470 | INPERFDIFF(np_hist3)); | |
471 | printf("\t\t\t %u < x <= %u: %llu\n", | |
472 | in_net_perf.np_hist_bars[2], in_net_perf.np_hist_bars[3], | |
473 | INPERFDIFF(np_hist4)); | |
474 | printf("\t\t\t %u < x: %llu\n", | |
475 | in_net_perf.np_hist_bars[3], INPERFDIFF(np_hist5)); | |
476 | } | |
477 | #undef INPERFDIFF | |
478 | ||
7ba0088d | 479 | p(ip6s_localout, "\t%llu packet%s sent from this host\n"); |
9dc66a05 A |
480 | p(ip6s_rawout, "\t\t%llu packet%s sent with fabricated ip header\n"); |
481 | p(ip6s_odropped, | |
482 | "\t\t%llu output packet%s dropped due to no bufs, etc.\n"); | |
483 | p(ip6s_noroute, "\t\t%llu output packet%s discarded due to no route\n"); | |
484 | p(ip6s_fragmented, "\t\t%llu output datagram%s fragmented\n"); | |
485 | p(ip6s_ofragments, "\t\t%llu fragment%s created\n"); | |
486 | p(ip6s_cantfrag, "\t\t%llu datagram%s that can't be fragmented\n"); | |
487 | p(ip6s_badscope, "\t\t%llu packet%s that violated scope rules\n"); | |
89c4ed63 A |
488 | |
489 | #define OUTPERFDIFF(f) (out_net_perf.f - pout_net_perf.f) | |
490 | if (OUTPERFDIFF(np_total_pkts) > 0 && out_net_perf.np_total_usecs > 0) { | |
491 | printf("\tOutput Performance Stats:\n"); | |
492 | printf("\t\t%llu total packets measured\n", OUTPERFDIFF(np_total_pkts)); | |
493 | printf("\t\t%llu total usec elapsed\n", OUTPERFDIFF(np_total_usecs)); | |
494 | printf("\t\t%f usec per packet\n", | |
495 | (double)out_net_perf.np_total_usecs/(double)out_net_perf.np_total_pkts); | |
496 | printf("\t\tHistogram:\n"); | |
497 | printf("\t\t\t x <= %u: %llu\n", out_net_perf.np_hist_bars[0], | |
498 | OUTPERFDIFF(np_hist1)); | |
499 | printf("\t\t\t %u < x <= %u: %llu\n", | |
500 | out_net_perf.np_hist_bars[0], out_net_perf.np_hist_bars[1], | |
501 | OUTPERFDIFF(np_hist2)); | |
502 | printf("\t\t\t %u < x <= %u: %llu\n", | |
503 | out_net_perf.np_hist_bars[1], out_net_perf.np_hist_bars[2], | |
504 | OUTPERFDIFF(np_hist3)); | |
505 | printf("\t\t\t %u < x <= %u: %llu\n", | |
506 | out_net_perf.np_hist_bars[2], out_net_perf.np_hist_bars[3], | |
507 | OUTPERFDIFF(np_hist4)); | |
508 | printf("\t\t\t %u < x: %llu\n", | |
509 | out_net_perf.np_hist_bars[3], OUTPERFDIFF(np_hist5)); | |
510 | } | |
511 | #undef OUTPERFDIFF | |
512 | ||
7ba0088d | 513 | for (first = 1, i = 0; i < 256; i++) |
b8dff150 | 514 | if (IP6DIFF(ip6s_nxthist[i]) != 0) { |
7ba0088d A |
515 | if (first) { |
516 | printf("\tInput histogram:\n"); | |
517 | first = 0; | |
518 | } | |
519 | printf("\t\t%s: %llu\n", ip6nh[i], | |
b8dff150 | 520 | (unsigned long long)IP6DIFF(ip6s_nxthist[i])); |
7ba0088d A |
521 | } |
522 | printf("\tMbuf statistics:\n"); | |
b8dff150 | 523 | printf("\t\t%llu one mbuf\n", (unsigned long long)IP6DIFF(ip6s_m1)); |
7ba0088d A |
524 | for (first = 1, i = 0; i < 32; i++) { |
525 | char ifbuf[IFNAMSIZ]; | |
b8dff150 | 526 | if (IP6DIFF(ip6s_m2m[i]) != 0) { |
7ba0088d A |
527 | if (first) { |
528 | printf("\t\ttwo or more mbuf:\n"); | |
529 | first = 0; | |
530 | } | |
531 | printf("\t\t\t%s= %llu\n", | |
532 | if_indextoname(i, ifbuf), | |
b8dff150 | 533 | (unsigned long long)IP6DIFF(ip6s_m2m[i])); |
7ba0088d A |
534 | } |
535 | } | |
536 | printf("\t\t%llu one ext mbuf\n", | |
b8dff150 | 537 | (unsigned long long)IP6DIFF(ip6s_mext1)); |
7ba0088d | 538 | printf("\t\t%llu two or more ext mbuf\n", |
b8dff150 | 539 | (unsigned long long)IP6DIFF(ip6s_mext2m)); |
7ba0088d A |
540 | |
541 | /* for debugging source address selection */ | |
542 | #define PRINT_SCOPESTAT(s,i) do {\ | |
543 | switch(i) { /* XXX hardcoding in each case */\ | |
544 | case 1:\ | |
9dc66a05 | 545 | p(s, "\t\t\t%llu node-local%s\n");\ |
7ba0088d A |
546 | break;\ |
547 | case 2:\ | |
9dc66a05 | 548 | p(s,"\t\t\t%llu link-local%s\n");\ |
7ba0088d A |
549 | break;\ |
550 | case 5:\ | |
9dc66a05 | 551 | p(s,"\t\t\t%llu site-local%s\n");\ |
7ba0088d A |
552 | break;\ |
553 | case 14:\ | |
9dc66a05 | 554 | p(s,"\t\t\t%llu global%s\n");\ |
7ba0088d A |
555 | break;\ |
556 | default:\ | |
9dc66a05 | 557 | printf("\t\t\t%llu addresses scope=%x\n",\ |
b8dff150 | 558 | (unsigned long long)IP6DIFF(s), i);\ |
7ba0088d A |
559 | }\ |
560 | } while (0); | |
561 | ||
562 | p(ip6s_sources_none, | |
9dc66a05 | 563 | "\t\t%llu failure%s of source address selection\n"); |
89c4ed63 A |
564 | for (first = 1, i = 0; i < SCOPE6_ID_MAX; i++) { |
565 | if (IP6DIFF(ip6s_sources_sameif[i]) || 1) { | |
7ba0088d | 566 | if (first) { |
9dc66a05 | 567 | printf("\t\tsource addresses on an outgoing I/F\n"); |
7ba0088d A |
568 | first = 0; |
569 | } | |
570 | PRINT_SCOPESTAT(ip6s_sources_sameif[i], i); | |
571 | } | |
572 | } | |
89c4ed63 A |
573 | for (first = 1, i = 0; i < SCOPE6_ID_MAX; i++) { |
574 | if (IP6DIFF(ip6s_sources_otherif[i]) || 1) { | |
7ba0088d | 575 | if (first) { |
9dc66a05 | 576 | printf("\t\tsource addresses on a non-outgoing I/F\n"); |
7ba0088d A |
577 | first = 0; |
578 | } | |
579 | PRINT_SCOPESTAT(ip6s_sources_otherif[i], i); | |
580 | } | |
581 | } | |
89c4ed63 A |
582 | for (first = 1, i = 0; i < SCOPE6_ID_MAX; i++) { |
583 | if (IP6DIFF(ip6s_sources_samescope[i]) || 1) { | |
7ba0088d | 584 | if (first) { |
9dc66a05 | 585 | printf("\t\tsource addresses of same scope\n"); |
7ba0088d A |
586 | first = 0; |
587 | } | |
588 | PRINT_SCOPESTAT(ip6s_sources_samescope[i], i); | |
589 | } | |
590 | } | |
89c4ed63 A |
591 | for (first = 1, i = 0; i < SCOPE6_ID_MAX; i++) { |
592 | if (IP6DIFF(ip6s_sources_otherscope[i]) || 1) { | |
7ba0088d | 593 | if (first) { |
9dc66a05 | 594 | printf("\t\tsource addresses of a different scope\n"); |
7ba0088d A |
595 | first = 0; |
596 | } | |
597 | PRINT_SCOPESTAT(ip6s_sources_otherscope[i], i); | |
598 | } | |
599 | } | |
89c4ed63 A |
600 | for (first = 1, i = 0; i < SCOPE6_ID_MAX; i++) { |
601 | if (IP6DIFF(ip6s_sources_deprecated[i]) || 1) { | |
7ba0088d | 602 | if (first) { |
9dc66a05 | 603 | printf("\t\tdeprecated source addresses\n"); |
7ba0088d A |
604 | first = 0; |
605 | } | |
606 | PRINT_SCOPESTAT(ip6s_sources_deprecated[i], i); | |
607 | } | |
608 | } | |
89c4ed63 A |
609 | #define PRINT_SRCRULESTAT(s,i) do {\ |
610 | if (srcrulenames[i] != NULL) \ | |
611 | printf("\t\t\t%llu rule%s %s\n", \ | |
612 | (unsigned long long)IP6DIFF(s), \ | |
613 | plural(IP6DIFF(s)), \ | |
614 | srcrulenames[i]); \ | |
615 | } while (0); | |
7ba0088d | 616 | |
89c4ed63 A |
617 | for (first = 1, i = 0; i < IP6S_SRCRULE_COUNT; i++) { |
618 | if (IP6DIFF(ip6s_sources_rule[i]) || 1) { | |
619 | if (first) { | |
26c66ce9 | 620 | printf("\t\tsource address selection\n"); |
89c4ed63 A |
621 | first = 0; |
622 | } | |
623 | PRINT_SRCRULESTAT(ip6s_sources_rule[i], i); | |
624 | } | |
625 | } | |
626 | ||
627 | p(ip6s_dad_collide, "\t\t%llu duplicate address detection collision%s\n"); | |
26c66ce9 A |
628 | |
629 | p(ip6s_dad_loopcount, "\t\t%llu duplicate address detection NS loop%s\n"); | |
b8dff150 | 630 | |
26c66ce9 | 631 | p(ip6s_sources_skip_expensive_secondary_if, "\t\t%llu time%s ignored source on secondary expensive I/F\n"); |
89c4ed63 A |
632 | |
633 | if (interval > 0) { | |
634 | bcopy(&ip6stat, &pip6stat, len); | |
635 | bcopy(&in_net_perf, &pin_net_perf, in_net_perf_len); | |
636 | bcopy(&out_net_perf, &pout_net_perf, out_net_perf_len); | |
637 | } | |
b8dff150 | 638 | #undef IP6DIFF |
7ba0088d A |
639 | #undef p |
640 | #undef p1a | |
641 | } | |
642 | ||
643 | /* | |
644 | * Dump IPv6 per-interface statistics based on RFC 2465. | |
645 | */ | |
646 | void | |
647 | ip6_ifstats(char *ifname) | |
648 | { | |
649 | struct in6_ifreq ifr; | |
650 | int s; | |
651 | #define p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \ | |
652 | printf(m, (unsigned long long)ifr.ifr_ifru.ifru_stat.f, plural(ifr.ifr_ifru.ifru_stat.f)) | |
653 | #define p_5(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \ | |
654 | printf(m, (unsigned long long)ip6stat.f) | |
655 | ||
656 | if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { | |
657 | perror("Warning: socket(AF_INET6)"); | |
658 | return; | |
659 | } | |
660 | ||
9dc66a05 A |
661 | if (interval && vflag > 0) |
662 | print_time(); | |
fdfd5971 | 663 | strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); |
7ba0088d A |
664 | printf("ip6 on %s:\n", ifr.ifr_name); |
665 | ||
666 | if (ioctl(s, SIOCGIFSTAT_IN6, (char *)&ifr) < 0) { | |
667 | perror("Warning: ioctl(SIOCGIFSTAT_IN6)"); | |
668 | goto end; | |
669 | } | |
670 | ||
671 | p(ifs6_in_receive, "\t%llu total input datagram%s\n"); | |
672 | p(ifs6_in_hdrerr, "\t%llu datagram%s with invalid header received\n"); | |
673 | p(ifs6_in_toobig, "\t%llu datagram%s exceeded MTU received\n"); | |
674 | p(ifs6_in_noroute, "\t%llu datagram%s with no route received\n"); | |
675 | p(ifs6_in_addrerr, "\t%llu datagram%s with invalid dst received\n"); | |
676 | p(ifs6_in_protounknown, "\t%llu datagram%s with unknown proto received\n"); | |
677 | p(ifs6_in_truncated, "\t%llu truncated datagram%s received\n"); | |
678 | p(ifs6_in_discard, "\t%llu input datagram%s discarded\n"); | |
679 | p(ifs6_in_deliver, | |
680 | "\t%llu datagram%s delivered to an upper layer protocol\n"); | |
681 | p(ifs6_out_forward, "\t%llu datagram%s forwarded to this interface\n"); | |
682 | p(ifs6_out_request, | |
683 | "\t%llu datagram%s sent from an upper layer protocol\n"); | |
684 | p(ifs6_out_discard, "\t%llu total discarded output datagram%s\n"); | |
685 | p(ifs6_out_fragok, "\t%llu output datagram%s fragmented\n"); | |
686 | p(ifs6_out_fragfail, "\t%llu output datagram%s failed on fragment\n"); | |
687 | p(ifs6_out_fragcreat, "\t%llu output datagram%s succeeded on fragment\n"); | |
688 | p(ifs6_reass_reqd, "\t%llu incoming datagram%s fragmented\n"); | |
689 | p(ifs6_reass_ok, "\t%llu datagram%s reassembled\n"); | |
26c66ce9 | 690 | p(ifs6_atmfrag_rcvd, "\t%llu atomic fragments%s received\n"); |
7ba0088d A |
691 | p(ifs6_reass_fail, "\t%llu datagram%s failed on reassembling\n"); |
692 | p(ifs6_in_mcast, "\t%llu multicast datagram%s received\n"); | |
693 | p(ifs6_out_mcast, "\t%llu multicast datagram%s sent\n"); | |
694 | ||
695 | end: | |
696 | close(s); | |
697 | ||
698 | #undef p | |
699 | #undef p_5 | |
700 | } | |
701 | ||
702 | static char *icmp6names[] = { | |
703 | "#0", | |
704 | "unreach", | |
705 | "packet too big", | |
706 | "time exceed", | |
707 | "parameter problem", | |
708 | "#5", | |
709 | "#6", | |
710 | "#7", | |
711 | "#8", | |
712 | "#9", | |
713 | "#10", | |
714 | "#11", | |
715 | "#12", | |
716 | "#13", | |
717 | "#14", | |
718 | "#15", | |
719 | "#16", | |
720 | "#17", | |
721 | "#18", | |
722 | "#19", | |
723 | "#20", | |
724 | "#21", | |
725 | "#22", | |
726 | "#23", | |
727 | "#24", | |
728 | "#25", | |
729 | "#26", | |
730 | "#27", | |
731 | "#28", | |
732 | "#29", | |
733 | "#30", | |
734 | "#31", | |
735 | "#32", | |
736 | "#33", | |
737 | "#34", | |
738 | "#35", | |
739 | "#36", | |
740 | "#37", | |
741 | "#38", | |
742 | "#39", | |
743 | "#40", | |
744 | "#41", | |
745 | "#42", | |
746 | "#43", | |
747 | "#44", | |
748 | "#45", | |
749 | "#46", | |
750 | "#47", | |
751 | "#48", | |
752 | "#49", | |
753 | "#50", | |
754 | "#51", | |
755 | "#52", | |
756 | "#53", | |
757 | "#54", | |
758 | "#55", | |
759 | "#56", | |
760 | "#57", | |
761 | "#58", | |
762 | "#59", | |
763 | "#60", | |
764 | "#61", | |
765 | "#62", | |
766 | "#63", | |
767 | "#64", | |
768 | "#65", | |
769 | "#66", | |
770 | "#67", | |
771 | "#68", | |
772 | "#69", | |
773 | "#70", | |
774 | "#71", | |
775 | "#72", | |
776 | "#73", | |
777 | "#74", | |
778 | "#75", | |
779 | "#76", | |
780 | "#77", | |
781 | "#78", | |
782 | "#79", | |
783 | "#80", | |
784 | "#81", | |
785 | "#82", | |
786 | "#83", | |
787 | "#84", | |
788 | "#85", | |
789 | "#86", | |
790 | "#87", | |
791 | "#88", | |
792 | "#89", | |
793 | "#80", | |
794 | "#91", | |
795 | "#92", | |
796 | "#93", | |
797 | "#94", | |
798 | "#95", | |
799 | "#96", | |
800 | "#97", | |
801 | "#98", | |
802 | "#99", | |
803 | "#100", | |
804 | "#101", | |
805 | "#102", | |
806 | "#103", | |
807 | "#104", | |
808 | "#105", | |
809 | "#106", | |
810 | "#107", | |
811 | "#108", | |
812 | "#109", | |
813 | "#110", | |
814 | "#111", | |
815 | "#112", | |
816 | "#113", | |
817 | "#114", | |
818 | "#115", | |
819 | "#116", | |
820 | "#117", | |
821 | "#118", | |
822 | "#119", | |
823 | "#120", | |
824 | "#121", | |
825 | "#122", | |
826 | "#123", | |
827 | "#124", | |
828 | "#125", | |
829 | "#126", | |
830 | "#127", | |
831 | "echo", | |
832 | "echo reply", | |
833 | "multicast listener query", | |
fdfd5971 A |
834 | "MLDv1 listener report", |
835 | "MLDv1 listener done", | |
7ba0088d A |
836 | "router solicitation", |
837 | "router advertisement", | |
838 | "neighbor solicitation", | |
839 | "neighbor advertisement", | |
840 | "redirect", | |
841 | "router renumbering", | |
842 | "node information request", | |
843 | "node information reply", | |
844 | "inverse neighbor solicitation", | |
845 | "inverse neighbor advertisement", | |
fdfd5971 | 846 | "MLDv2 listener report", |
7ba0088d A |
847 | "#144", |
848 | "#145", | |
849 | "#146", | |
850 | "#147", | |
851 | "#148", | |
852 | "#149", | |
853 | "#150", | |
854 | "#151", | |
855 | "#152", | |
856 | "#153", | |
857 | "#154", | |
858 | "#155", | |
859 | "#156", | |
860 | "#157", | |
861 | "#158", | |
862 | "#159", | |
863 | "#160", | |
864 | "#161", | |
865 | "#162", | |
866 | "#163", | |
867 | "#164", | |
868 | "#165", | |
869 | "#166", | |
870 | "#167", | |
871 | "#168", | |
872 | "#169", | |
873 | "#170", | |
874 | "#171", | |
875 | "#172", | |
876 | "#173", | |
877 | "#174", | |
878 | "#175", | |
879 | "#176", | |
880 | "#177", | |
881 | "#178", | |
882 | "#179", | |
883 | "#180", | |
884 | "#181", | |
885 | "#182", | |
886 | "#183", | |
887 | "#184", | |
888 | "#185", | |
889 | "#186", | |
890 | "#187", | |
891 | "#188", | |
892 | "#189", | |
893 | "#180", | |
894 | "#191", | |
895 | "#192", | |
896 | "#193", | |
897 | "#194", | |
898 | "#195", | |
899 | "#196", | |
900 | "#197", | |
901 | "#198", | |
902 | "#199", | |
903 | "#200", | |
904 | "#201", | |
905 | "#202", | |
906 | "#203", | |
907 | "#204", | |
908 | "#205", | |
909 | "#206", | |
910 | "#207", | |
911 | "#208", | |
912 | "#209", | |
913 | "#210", | |
914 | "#211", | |
915 | "#212", | |
916 | "#213", | |
917 | "#214", | |
918 | "#215", | |
919 | "#216", | |
920 | "#217", | |
921 | "#218", | |
922 | "#219", | |
923 | "#220", | |
924 | "#221", | |
925 | "#222", | |
926 | "#223", | |
927 | "#224", | |
928 | "#225", | |
929 | "#226", | |
930 | "#227", | |
931 | "#228", | |
932 | "#229", | |
933 | "#230", | |
934 | "#231", | |
935 | "#232", | |
936 | "#233", | |
937 | "#234", | |
938 | "#235", | |
939 | "#236", | |
940 | "#237", | |
941 | "#238", | |
942 | "#239", | |
943 | "#240", | |
944 | "#241", | |
945 | "#242", | |
946 | "#243", | |
947 | "#244", | |
948 | "#245", | |
949 | "#246", | |
950 | "#247", | |
951 | "#248", | |
952 | "#249", | |
953 | "#250", | |
954 | "#251", | |
955 | "#252", | |
956 | "#253", | |
957 | "#254", | |
958 | "#255", | |
959 | }; | |
960 | ||
961 | /* | |
962 | * Dump ICMP6 statistics. | |
963 | */ | |
964 | void | |
9c859447 | 965 | icmp6_stats(uint32_t off __unused, char *name, int af __unused) |
7ba0088d | 966 | { |
b8dff150 | 967 | static struct icmp6stat picmp6stat; |
7ba0088d A |
968 | struct icmp6stat icmp6stat; |
969 | register int i, first; | |
970 | int mib[4]; | |
971 | size_t len; | |
972 | ||
973 | mib[0] = CTL_NET; | |
974 | mib[1] = PF_INET6; | |
975 | mib[2] = IPPROTO_ICMPV6; | |
976 | mib[3] = ICMPV6CTL_STATS; | |
977 | ||
978 | len = sizeof icmp6stat; | |
979 | memset(&icmp6stat, 0, len); | |
980 | if (sysctl(mib, 4, &icmp6stat, &len, (void *)0, 0) < 0) | |
981 | return; | |
9dc66a05 A |
982 | if (interval && vflag > 0) |
983 | print_time(); | |
7ba0088d A |
984 | printf("%s:\n", name); |
985 | ||
b8dff150 A |
986 | #define ICMP6DIFF(f) (icmp6stat.f - picmp6stat.f) |
987 | #define p(f, m) if (ICMP6DIFF(f) || sflag <= 1) \ | |
988 | printf(m, (unsigned long long)ICMP6DIFF(f), plural(ICMP6DIFF(f))) | |
989 | #define p_5(f, m) printf(m, (unsigned long long)ICMP6DIFF(f)) | |
7ba0088d A |
990 | |
991 | p(icp6s_error, "\t%llu call%s to icmp_error\n"); | |
992 | p(icp6s_canterror, | |
993 | "\t%llu error%s not generated because old message was icmp error or so\n"); | |
994 | p(icp6s_toofreq, | |
995 | "\t%llu error%s not generated because rate limitation\n"); | |
996 | #define NELEM (sizeof(icmp6stat.icp6s_outhist)/sizeof(icmp6stat.icp6s_outhist[0])) | |
997 | for (first = 1, i = 0; i < NELEM; i++) | |
b8dff150 | 998 | if (ICMP6DIFF(icp6s_outhist[i]) != 0) { |
7ba0088d A |
999 | if (first) { |
1000 | printf("\tOutput histogram:\n"); | |
1001 | first = 0; | |
1002 | } | |
1003 | printf("\t\t%s: %llu\n", icmp6names[i], | |
b8dff150 | 1004 | (unsigned long long)ICMP6DIFF(icp6s_outhist[i])); |
7ba0088d A |
1005 | } |
1006 | #undef NELEM | |
1007 | p(icp6s_badcode, "\t%llu message%s with bad code fields\n"); | |
1008 | p(icp6s_tooshort, "\t%llu message%s < minimum length\n"); | |
1009 | p(icp6s_checksum, "\t%llu bad checksum%s\n"); | |
1010 | p(icp6s_badlen, "\t%llu message%s with bad length\n"); | |
1011 | #define NELEM (sizeof(icmp6stat.icp6s_inhist)/sizeof(icmp6stat.icp6s_inhist[0])) | |
1012 | for (first = 1, i = 0; i < NELEM; i++) | |
b8dff150 | 1013 | if (ICMP6DIFF(icp6s_inhist[i]) != 0) { |
7ba0088d A |
1014 | if (first) { |
1015 | printf("\tInput histogram:\n"); | |
1016 | first = 0; | |
1017 | } | |
1018 | printf("\t\t%s: %llu\n", icmp6names[i], | |
b8dff150 | 1019 | (unsigned long long)ICMP6DIFF(icp6s_inhist[i])); |
7ba0088d A |
1020 | } |
1021 | #undef NELEM | |
1022 | printf("\tHistogram of error messages to be generated:\n"); | |
1023 | p_5(icp6s_odst_unreach_noroute, "\t\t%llu no route\n"); | |
1024 | p_5(icp6s_odst_unreach_admin, "\t\t%llu administratively prohibited\n"); | |
1025 | p_5(icp6s_odst_unreach_beyondscope, "\t\t%llu beyond scope\n"); | |
1026 | p_5(icp6s_odst_unreach_addr, "\t\t%llu address unreachable\n"); | |
1027 | p_5(icp6s_odst_unreach_noport, "\t\t%llu port unreachable\n"); | |
1028 | p_5(icp6s_opacket_too_big, "\t\t%llu packet too big\n"); | |
1029 | p_5(icp6s_otime_exceed_transit, "\t\t%llu time exceed transit\n"); | |
1030 | p_5(icp6s_otime_exceed_reassembly, "\t\t%llu time exceed reassembly\n"); | |
1031 | p_5(icp6s_oparamprob_header, "\t\t%llu erroneous header field\n"); | |
1032 | p_5(icp6s_oparamprob_nextheader, "\t\t%llu unrecognized next header\n"); | |
1033 | p_5(icp6s_oparamprob_option, "\t\t%llu unrecognized option\n"); | |
1034 | p_5(icp6s_oredirect, "\t\t%llu redirect\n"); | |
1035 | p_5(icp6s_ounknown, "\t\t%llu unknown\n"); | |
1036 | ||
1037 | p(icp6s_reflect, "\t%llu message response%s generated\n"); | |
1038 | p(icp6s_nd_toomanyopt, "\t%llu message%s with too many ND options\n"); | |
1039 | p(icp6s_nd_badopt, "\t%qu message%s with bad ND options\n"); | |
1040 | p(icp6s_badns, "\t%qu bad neighbor solicitation message%s\n"); | |
1041 | p(icp6s_badna, "\t%qu bad neighbor advertisement message%s\n"); | |
1042 | p(icp6s_badrs, "\t%qu bad router solicitation message%s\n"); | |
1043 | p(icp6s_badra, "\t%qu bad router advertisement message%s\n"); | |
1044 | p(icp6s_badredirect, "\t%qu bad redirect message%s\n"); | |
1045 | p(icp6s_pmtuchg, "\t%llu path MTU change%s\n"); | |
26c66ce9 | 1046 | p(icp6s_rfc6980_drop, "\t%qu dropped fragmented NDP message%s\n"); |
b8dff150 A |
1047 | |
1048 | if (interval > 0) | |
1049 | bcopy(&icmp6stat, &picmp6stat, len); | |
1050 | ||
1051 | #undef ICMP6DIFF | |
7ba0088d A |
1052 | #undef p |
1053 | #undef p_5 | |
1054 | } | |
1055 | ||
1056 | /* | |
1057 | * Dump ICMPv6 per-interface statistics based on RFC 2466. | |
1058 | */ | |
1059 | void | |
1060 | icmp6_ifstats(char *ifname) | |
1061 | { | |
1062 | struct in6_ifreq ifr; | |
1063 | int s; | |
1064 | #define p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \ | |
1065 | printf(m, (unsigned long long)ifr.ifr_ifru.ifru_icmp6stat.f, plural(ifr.ifr_ifru.ifru_icmp6stat.f)) | |
1066 | ||
1067 | if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { | |
1068 | perror("Warning: socket(AF_INET6)"); | |
1069 | return; | |
1070 | } | |
1071 | ||
9dc66a05 A |
1072 | if (interval && vflag > 0) |
1073 | print_time(); | |
fdfd5971 | 1074 | strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); |
7ba0088d A |
1075 | printf("icmp6 on %s:\n", ifr.ifr_name); |
1076 | ||
1077 | if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) { | |
1078 | perror("Warning: ioctl(SIOCGIFSTAT_ICMP6)"); | |
1079 | goto end; | |
1080 | } | |
1081 | ||
1082 | p(ifs6_in_msg, "\t%llu total input message%s\n"); | |
1083 | p(ifs6_in_error, "\t%llu total input error message%s\n"); | |
1084 | p(ifs6_in_dstunreach, "\t%llu input destination unreachable error%s\n"); | |
1085 | p(ifs6_in_adminprohib, "\t%llu input administratively prohibited error%s\n"); | |
1086 | p(ifs6_in_timeexceed, "\t%llu input time exceeded error%s\n"); | |
1087 | p(ifs6_in_paramprob, "\t%llu input parameter problem error%s\n"); | |
1088 | p(ifs6_in_pkttoobig, "\t%llu input packet too big error%s\n"); | |
1089 | p(ifs6_in_echo, "\t%llu input echo request%s\n"); | |
1090 | p(ifs6_in_echoreply, "\t%llu input echo reply%s\n"); | |
1091 | p(ifs6_in_routersolicit, "\t%llu input router solicitation%s\n"); | |
1092 | p(ifs6_in_routeradvert, "\t%llu input router advertisement%s\n"); | |
1093 | p(ifs6_in_neighborsolicit, "\t%llu input neighbor solicitation%s\n"); | |
1094 | p(ifs6_in_neighboradvert, "\t%llu input neighbor advertisement%s\n"); | |
1095 | p(ifs6_in_redirect, "\t%llu input redirect%s\n"); | |
1096 | p(ifs6_in_mldquery, "\t%llu input MLD query%s\n"); | |
1097 | p(ifs6_in_mldreport, "\t%llu input MLD report%s\n"); | |
1098 | p(ifs6_in_mlddone, "\t%llu input MLD done%s\n"); | |
1099 | ||
1100 | p(ifs6_out_msg, "\t%llu total output message%s\n"); | |
1101 | p(ifs6_out_error, "\t%llu total output error message%s\n"); | |
1102 | p(ifs6_out_dstunreach, "\t%llu output destination unreachable error%s\n"); | |
1103 | p(ifs6_out_adminprohib, "\t%llu output administratively prohibited error%s\n"); | |
1104 | p(ifs6_out_timeexceed, "\t%llu output time exceeded error%s\n"); | |
1105 | p(ifs6_out_paramprob, "\t%llu output parameter problem error%s\n"); | |
1106 | p(ifs6_out_pkttoobig, "\t%llu output packet too big error%s\n"); | |
1107 | p(ifs6_out_echo, "\t%llu output echo request%s\n"); | |
1108 | p(ifs6_out_echoreply, "\t%llu output echo reply%s\n"); | |
1109 | p(ifs6_out_routersolicit, "\t%llu output router solicitation%s\n"); | |
1110 | p(ifs6_out_routeradvert, "\t%llu output router advertisement%s\n"); | |
1111 | p(ifs6_out_neighborsolicit, "\t%llu output neighbor solicitation%s\n"); | |
1112 | p(ifs6_out_neighboradvert, "\t%llu output neighbor advertisement%s\n"); | |
1113 | p(ifs6_out_redirect, "\t%llu output redirect%s\n"); | |
1114 | p(ifs6_out_mldquery, "\t%llu output MLD query%s\n"); | |
1115 | p(ifs6_out_mldreport, "\t%llu output MLD report%s\n"); | |
1116 | p(ifs6_out_mlddone, "\t%llu output MLD done%s\n"); | |
1117 | ||
1118 | end: | |
1119 | close(s); | |
1120 | #undef p | |
1121 | } | |
1122 | ||
7ba0088d A |
1123 | /* |
1124 | * Dump raw ip6 statistics structure. | |
1125 | */ | |
1126 | void | |
9c859447 | 1127 | rip6_stats(uint32_t off __unused, char *name, int af __unused) |
7ba0088d | 1128 | { |
b8dff150 | 1129 | static struct rip6stat prip6stat; |
7ba0088d A |
1130 | struct rip6stat rip6stat; |
1131 | u_quad_t delivered; | |
1132 | int mib[4]; | |
1133 | size_t l; | |
1134 | ||
1135 | mib[0] = CTL_NET; | |
1136 | mib[1] = PF_INET6; | |
1137 | mib[2] = IPPROTO_IPV6; | |
1138 | mib[3] = IPV6CTL_RIP6STATS; | |
1139 | l = sizeof(rip6stat); | |
1140 | if (sysctl(mib, 4, &rip6stat, &l, NULL, 0) < 0) { | |
1141 | perror("Warning: sysctl(net.inet6.ip6.rip6stats)"); | |
1142 | return; | |
1143 | } | |
1144 | ||
9dc66a05 A |
1145 | if (interval && vflag > 0) |
1146 | print_time(); | |
7ba0088d A |
1147 | printf("%s:\n", name); |
1148 | ||
b8dff150 A |
1149 | #define RIP6DIFF(f) (rip6stat.f - prip6stat.f) |
1150 | #define p(f, m) if (RIP6DIFF(f) || sflag <= 1) \ | |
1151 | printf(m, (unsigned long long)RIP6DIFF(f), plural(RIP6DIFF(f))) | |
7ba0088d | 1152 | p(rip6s_ipackets, "\t%llu message%s received\n"); |
26c66ce9 | 1153 | p(rip6s_isum, "\t%llu checksum calculation%s on inbound\n"); |
7ba0088d A |
1154 | p(rip6s_badsum, "\t%llu message%s with bad checksum\n"); |
1155 | p(rip6s_nosock, "\t%llu message%s dropped due to no socket\n"); | |
1156 | p(rip6s_nosockmcast, | |
1157 | "\t%llu multicast message%s dropped due to no socket\n"); | |
1158 | p(rip6s_fullsock, | |
1159 | "\t%llu message%s dropped due to full socket buffers\n"); | |
b8dff150 A |
1160 | delivered = RIP6DIFF(rip6s_ipackets) - |
1161 | RIP6DIFF(rip6s_badsum) - | |
1162 | RIP6DIFF(rip6s_nosock) - | |
1163 | RIP6DIFF(rip6s_nosockmcast) - | |
1164 | RIP6DIFF(rip6s_fullsock); | |
7ba0088d A |
1165 | if (delivered || sflag <= 1) |
1166 | printf("\t%llu delivered\n", (unsigned long long)delivered); | |
1167 | p(rip6s_opackets, "\t%llu datagram%s output\n"); | |
b8dff150 A |
1168 | |
1169 | if (interval > 0) | |
1170 | bcopy(&rip6stat, &prip6stat, l); | |
1171 | ||
1172 | #undef RIP6DIFF | |
7ba0088d A |
1173 | #undef p |
1174 | } | |
1175 | ||
1176 | /* | |
1177 | * Pretty print an Internet address (net address + port). | |
1178 | * If the nflag was specified, use numbers instead of names. | |
1179 | */ | |
ac2f15b3 A |
1180 | #ifdef SRVCACHE |
1181 | extern struct servent * _serv_cache_getservbyport(int port, char *proto); | |
1182 | ||
1183 | #define GETSERVBYPORT6(port, proto, ret)\ | |
1184 | {\ | |
1185 | if (strcmp((proto), "tcp6") == 0)\ | |
1186 | (ret) = _serv_cache_getservbyport((int)(port), "tcp");\ | |
1187 | else if (strcmp((proto), "udp6") == 0)\ | |
1188 | (ret) = _serv_cache_getservbyport((int)(port), "udp");\ | |
1189 | else\ | |
1190 | (ret) = _serv_cache_getservbyport((int)(port), (proto));\ | |
1191 | }; | |
1192 | #else | |
7ba0088d A |
1193 | #define GETSERVBYPORT6(port, proto, ret)\ |
1194 | {\ | |
1195 | if (strcmp((proto), "tcp6") == 0)\ | |
1196 | (ret) = getservbyport((int)(port), "tcp");\ | |
1197 | else if (strcmp((proto), "udp6") == 0)\ | |
1198 | (ret) = getservbyport((int)(port), "udp");\ | |
1199 | else\ | |
1200 | (ret) = getservbyport((int)(port), (proto));\ | |
1201 | }; | |
ac2f15b3 | 1202 | #endif |
7ba0088d A |
1203 | void |
1204 | inet6print(struct in6_addr *in6, int port, char *proto, int numeric) | |
1205 | { | |
1206 | struct servent *sp = 0; | |
1207 | char line[80], *cp; | |
1208 | int width; | |
1209 | ||
fdfd5971 | 1210 | snprintf(line, sizeof(line), "%.*s.", lflag ? 39 : |
7ba0088d A |
1211 | (Aflag && !numeric) ? 12 : 16, inet6name(in6)); |
1212 | cp = index(line, '\0'); | |
1213 | if (!numeric && port) | |
1214 | GETSERVBYPORT6(port, proto, sp); | |
1215 | if (sp || port == 0) | |
26c66ce9 | 1216 | snprintf(cp, sizeof(line) - (cp - line), "%.15s", sp ? sp->s_name : "*"); |
7ba0088d | 1217 | else |
fdfd5971 | 1218 | snprintf(cp, sizeof(line) - (cp - line), "%d", ntohs((u_short)port)); |
7ba0088d A |
1219 | width = lflag ? 45 : Aflag ? 18 : 22; |
1220 | printf("%-*.*s ", width, width, line); | |
1221 | } | |
1222 | ||
1223 | /* | |
1224 | * Construct an Internet address representation. | |
1225 | * If the nflag has been supplied, give | |
1226 | * numeric value, otherwise try for symbolic name. | |
1227 | */ | |
1228 | ||
1229 | char * | |
1230 | inet6name(struct in6_addr *in6p) | |
1231 | { | |
1232 | register char *cp; | |
1233 | static char line[50]; | |
1234 | struct hostent *hp; | |
1235 | static char domain[MAXHOSTNAMELEN]; | |
1236 | static int first = 1; | |
b8dff150 A |
1237 | char hbuf[NI_MAXHOST]; |
1238 | struct sockaddr_in6 sin6; | |
1239 | const int niflag = NI_NUMERICHOST; | |
7ba0088d A |
1240 | |
1241 | if (first && !nflag) { | |
1242 | first = 0; | |
1243 | if (gethostname(domain, MAXHOSTNAMELEN) == 0 && | |
1244 | (cp = index(domain, '.'))) | |
9dc66a05 | 1245 | (void) memmove(domain, cp + 1, strlen(cp + 1) + 1); |
7ba0088d A |
1246 | else |
1247 | domain[0] = 0; | |
1248 | } | |
1249 | cp = 0; | |
1250 | if (!nflag && !IN6_IS_ADDR_UNSPECIFIED(in6p)) { | |
1251 | hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6); | |
1252 | if (hp) { | |
1253 | if ((cp = index(hp->h_name, '.')) && | |
1254 | !strcmp(cp + 1, domain)) | |
1255 | *cp = 0; | |
1256 | cp = hp->h_name; | |
1257 | } | |
1258 | } | |
1259 | if (IN6_IS_ADDR_UNSPECIFIED(in6p)) | |
fdfd5971 | 1260 | strlcpy(line, "*", sizeof(line)); |
7ba0088d | 1261 | else if (cp) |
b8dff150 A |
1262 | strlcpy(line, cp, sizeof(line)); |
1263 | else { | |
1264 | memset(&sin6, 0, sizeof(sin6)); | |
1265 | sin6.sin6_len = sizeof(sin6); | |
1266 | sin6.sin6_family = AF_INET6; | |
1267 | sin6.sin6_addr = *in6p; | |
1268 | ||
1269 | if (IN6_IS_ADDR_LINKLOCAL(in6p) || | |
fdfd5971 | 1270 | IN6_IS_ADDR_MC_NODELOCAL(in6p) || |
b8dff150 A |
1271 | IN6_IS_ADDR_MC_LINKLOCAL(in6p)) { |
1272 | sin6.sin6_scope_id = | |
1273 | ntohs(*(u_int16_t *)&in6p->s6_addr[2]); | |
1274 | sin6.sin6_addr.s6_addr[2] = 0; | |
1275 | sin6.sin6_addr.s6_addr[3] = 0; | |
1276 | } | |
1277 | ||
1278 | if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, | |
1279 | hbuf, sizeof(hbuf), NULL, 0, niflag) != 0) | |
1280 | strlcpy(hbuf, "?", sizeof(hbuf)); | |
1281 | strlcpy(line, hbuf, sizeof(line)); | |
1282 | } | |
7ba0088d A |
1283 | return (line); |
1284 | } | |
1285 | #endif /*INET6*/ |