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