inet6.c (160373) | inet6.c (160787) |
---|---|
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: --- 25 unchanged lines hidden (view full) --- 34 35#if 0 36#ifndef lint 37static char sccsid[] = "@(#)inet6.c 8.4 (Berkeley) 4/20/94"; 38#endif /* not lint */ 39#endif 40 41#include <sys/cdefs.h> | 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: --- 25 unchanged lines hidden (view full) --- 34 35#if 0 36#ifndef lint 37static char sccsid[] = "@(#)inet6.c 8.4 (Berkeley) 4/20/94"; 38#endif /* not lint */ 39#endif 40 41#include <sys/cdefs.h> |
42__FBSDID("$FreeBSD: head/usr.bin/netstat/inet6.c 160373 2006-07-14 23:32:43Z julian $"); | 42__FBSDID("$FreeBSD: head/usr.bin/netstat/inet6.c 160787 2006-07-28 16:09:19Z yar $"); |
43 44#ifdef INET6 45#include <sys/param.h> 46#include <sys/socket.h> 47#include <sys/socketvar.h> 48#include <sys/ioctl.h> 49#include <sys/mbuf.h> 50#include <sys/protosw.h> --- 10 unchanged lines hidden (view full) --- 61#include <netinet6/in6_var.h> 62#include <netinet6/ip6_var.h> 63#include <netinet6/pim6_var.h> 64#include <netinet6/raw_ip6.h> 65 66#include <arpa/inet.h> 67#include <netdb.h> 68 | 43 44#ifdef INET6 45#include <sys/param.h> 46#include <sys/socket.h> 47#include <sys/socketvar.h> 48#include <sys/ioctl.h> 49#include <sys/mbuf.h> 50#include <sys/protosw.h> --- 10 unchanged lines hidden (view full) --- 61#include <netinet6/in6_var.h> 62#include <netinet6/ip6_var.h> 63#include <netinet6/pim6_var.h> 64#include <netinet6/raw_ip6.h> 65 66#include <arpa/inet.h> 67#include <netdb.h> 68 |
69#include <stdint.h> |
|
69#include <stdio.h> 70#include <errno.h> 71#include <string.h> 72#include <unistd.h> 73#include "netstat.h" 74 75struct socket sockb; 76 77char *inet6name(struct in6_addr *); | 70#include <stdio.h> 71#include <errno.h> 72#include <string.h> 73#include <unistd.h> 74#include "netstat.h" 75 76struct socket sockb; 77 78char *inet6name(struct in6_addr *); |
78const char *pluralies(int); | |
79 80static char ntop_buf[INET6_ADDRSTRLEN]; 81 82static const char *ip6nh[] = { 83 "hop by hop", 84 "ICMP", 85 "IGMP", 86 "#3", --- 288 unchanged lines hidden (view full) --- 375 376 len = sizeof ip6stat; 377 memset(&ip6stat, 0, len); 378 if (sysctl(mib, 4, &ip6stat, &len, (void *)0, 0) < 0) 379 return; 380 printf("%s:\n", name); 381 382#define p(f, m) if (ip6stat.f || sflag <= 1) \ | 79 80static char ntop_buf[INET6_ADDRSTRLEN]; 81 82static const char *ip6nh[] = { 83 "hop by hop", 84 "ICMP", 85 "IGMP", 86 "#3", --- 288 unchanged lines hidden (view full) --- 375 376 len = sizeof ip6stat; 377 memset(&ip6stat, 0, len); 378 if (sysctl(mib, 4, &ip6stat, &len, (void *)0, 0) < 0) 379 return; 380 printf("%s:\n", name); 381 382#define p(f, m) if (ip6stat.f || sflag <= 1) \ |
383 printf(m, (unsigned long long)ip6stat.f, plural(ip6stat.f)) | 383 printf(m, (uintmax_t)ip6stat.f, plural(ip6stat.f)) |
384#define p1a(f, m) if (ip6stat.f || sflag <= 1) \ | 384#define p1a(f, m) if (ip6stat.f || sflag <= 1) \ |
385 printf(m, (unsigned long long)ip6stat.f) | 385 printf(m, (uintmax_t)ip6stat.f) |
386 | 386 |
387 p(ip6s_total, "\t%llu total packet%s received\n"); 388 p1a(ip6s_toosmall, "\t%llu with size smaller than minimum\n"); 389 p1a(ip6s_tooshort, "\t%llu with data size < data length\n"); 390 p1a(ip6s_badoptions, "\t%llu with bad options\n"); 391 p1a(ip6s_badvers, "\t%llu with incorrect version number\n"); 392 p(ip6s_fragments, "\t%llu fragment%s received\n"); 393 p(ip6s_fragdropped, "\t%llu fragment%s dropped (dup or out of space)\n"); 394 p(ip6s_fragtimeout, "\t%llu fragment%s dropped after timeout\n"); 395 p(ip6s_fragoverflow, "\t%llu fragment%s that exceeded limit\n"); 396 p(ip6s_reassembled, "\t%llu packet%s reassembled ok\n"); 397 p(ip6s_delivered, "\t%llu packet%s for this host\n"); 398 p(ip6s_forward, "\t%llu packet%s forwarded\n"); 399 p(ip6s_cantforward, "\t%llu packet%s not forwardable\n"); 400 p(ip6s_redirectsent, "\t%llu redirect%s sent\n"); 401 p(ip6s_localout, "\t%llu packet%s sent from this host\n"); 402 p(ip6s_rawout, "\t%llu packet%s sent with fabricated ip header\n"); 403 p(ip6s_odropped, "\t%llu output packet%s dropped due to no bufs, etc.\n"); 404 p(ip6s_noroute, "\t%llu output packet%s discarded due to no route\n"); 405 p(ip6s_fragmented, "\t%llu output datagram%s fragmented\n"); 406 p(ip6s_ofragments, "\t%llu fragment%s created\n"); 407 p(ip6s_cantfrag, "\t%llu datagram%s that can't be fragmented\n"); 408 p(ip6s_badscope, "\t%llu packet%s that violated scope rules\n"); 409 p(ip6s_notmember, "\t%llu multicast packet%s which we don't join\n"); | 387 p(ip6s_total, "\t%ju total packet%s received\n"); 388 p1a(ip6s_toosmall, "\t%ju with size smaller than minimum\n"); 389 p1a(ip6s_tooshort, "\t%ju with data size < data length\n"); 390 p1a(ip6s_badoptions, "\t%ju with bad options\n"); 391 p1a(ip6s_badvers, "\t%ju with incorrect version number\n"); 392 p(ip6s_fragments, "\t%ju fragment%s received\n"); 393 p(ip6s_fragdropped, "\t%ju fragment%s dropped (dup or out of space)\n"); 394 p(ip6s_fragtimeout, "\t%ju fragment%s dropped after timeout\n"); 395 p(ip6s_fragoverflow, "\t%ju fragment%s that exceeded limit\n"); 396 p(ip6s_reassembled, "\t%ju packet%s reassembled ok\n"); 397 p(ip6s_delivered, "\t%ju packet%s for this host\n"); 398 p(ip6s_forward, "\t%ju packet%s forwarded\n"); 399 p(ip6s_cantforward, "\t%ju packet%s not forwardable\n"); 400 p(ip6s_redirectsent, "\t%ju redirect%s sent\n"); 401 p(ip6s_localout, "\t%ju packet%s sent from this host\n"); 402 p(ip6s_rawout, "\t%ju packet%s sent with fabricated ip header\n"); 403 p(ip6s_odropped, "\t%ju output packet%s dropped due to no bufs, etc.\n"); 404 p(ip6s_noroute, "\t%ju output packet%s discarded due to no route\n"); 405 p(ip6s_fragmented, "\t%ju output datagram%s fragmented\n"); 406 p(ip6s_ofragments, "\t%ju fragment%s created\n"); 407 p(ip6s_cantfrag, "\t%ju datagram%s that can't be fragmented\n"); 408 p(ip6s_badscope, "\t%ju packet%s that violated scope rules\n"); 409 p(ip6s_notmember, "\t%ju multicast packet%s which we don't join\n"); |
410 for (first = 1, i = 0; i < 256; i++) 411 if (ip6stat.ip6s_nxthist[i] != 0) { 412 if (first) { 413 printf("\tInput histogram:\n"); 414 first = 0; 415 } | 410 for (first = 1, i = 0; i < 256; i++) 411 if (ip6stat.ip6s_nxthist[i] != 0) { 412 if (first) { 413 printf("\tInput histogram:\n"); 414 first = 0; 415 } |
416 printf("\t\t%s: %llu\n", ip6nh[i], 417 (unsigned long long)ip6stat.ip6s_nxthist[i]); | 416 printf("\t\t%s: %ju\n", ip6nh[i], 417 (uintmax_t)ip6stat.ip6s_nxthist[i]); |
418 } 419 printf("\tMbuf statistics:\n"); | 418 } 419 printf("\tMbuf statistics:\n"); |
420 printf("\t\t%llu one mbuf\n", (unsigned long long)ip6stat.ip6s_m1); | 420 printf("\t\t%ju one mbuf\n", (uintmax_t)ip6stat.ip6s_m1); |
421 for (first = 1, i = 0; i < 32; i++) { 422 char ifbuf[IFNAMSIZ]; 423 if (ip6stat.ip6s_m2m[i] != 0) { 424 if (first) { 425 printf("\t\ttwo or more mbuf:\n"); 426 first = 0; 427 } | 421 for (first = 1, i = 0; i < 32; i++) { 422 char ifbuf[IFNAMSIZ]; 423 if (ip6stat.ip6s_m2m[i] != 0) { 424 if (first) { 425 printf("\t\ttwo or more mbuf:\n"); 426 first = 0; 427 } |
428 printf("\t\t\t%s= %llu\n", | 428 printf("\t\t\t%s= %ju\n", |
429 if_indextoname(i, ifbuf), | 429 if_indextoname(i, ifbuf), |
430 (unsigned long long)ip6stat.ip6s_m2m[i]); | 430 (uintmax_t)ip6stat.ip6s_m2m[i]); |
431 } 432 } | 431 } 432 } |
433 printf("\t\t%llu one ext mbuf\n", 434 (unsigned long long)ip6stat.ip6s_mext1); 435 printf("\t\t%llu two or more ext mbuf\n", 436 (unsigned long long)ip6stat.ip6s_mext2m); | 433 printf("\t\t%ju one ext mbuf\n", 434 (uintmax_t)ip6stat.ip6s_mext1); 435 printf("\t\t%ju two or more ext mbuf\n", 436 (uintmax_t)ip6stat.ip6s_mext2m); |
437 p(ip6s_exthdrtoolong, | 437 p(ip6s_exthdrtoolong, |
438 "\t%llu packet%s whose headers are not continuous\n"); 439 p(ip6s_nogif, "\t%llu tunneling packet%s that can't find gif\n"); | 438 "\t%ju packet%s whose headers are not continuous\n"); 439 p(ip6s_nogif, "\t%ju tunneling packet%s that can't find gif\n"); |
440 p(ip6s_toomanyhdr, | 440 p(ip6s_toomanyhdr, |
441 "\t%llu packet%s discarded because of too many headers\n"); | 441 "\t%ju packet%s discarded because of too many headers\n"); |
442 443 /* for debugging source address selection */ 444#define PRINT_SCOPESTAT(s,i) do {\ 445 switch(i) { /* XXX hardcoding in each case */\ 446 case 1:\ | 442 443 /* for debugging source address selection */ 444#define PRINT_SCOPESTAT(s,i) do {\ 445 switch(i) { /* XXX hardcoding in each case */\ 446 case 1:\ |
447 p(s, "\t\t%llu node-local%s\n");\ | 447 p(s, "\t\t%ju node-local%s\n");\ |
448 break;\ 449 case 2:\ | 448 break;\ 449 case 2:\ |
450 p(s,"\t\t%llu link-local%s\n");\ | 450 p(s,"\t\t%ju link-local%s\n");\ |
451 break;\ 452 case 5:\ | 451 break;\ 452 case 5:\ |
453 p(s,"\t\t%llu site-local%s\n");\ | 453 p(s,"\t\t%ju site-local%s\n");\ |
454 break;\ 455 case 14:\ | 454 break;\ 455 case 14:\ |
456 p(s,"\t\t%llu global%s\n");\ | 456 p(s,"\t\t%ju global%s\n");\ |
457 break;\ 458 default:\ | 457 break;\ 458 default:\ |
459 printf("\t\t%llu addresses scope=%x\n",\ 460 (unsigned long long)ip6stat.s, i);\ | 459 printf("\t\t%ju addresses scope=%x\n",\ 460 (uintmax_t)ip6stat.s, i);\ |
461 }\ 462 } while (0); 463 464 p(ip6s_sources_none, | 461 }\ 462 } while (0); 463 464 p(ip6s_sources_none, |
465 "\t%llu failure%s of source address selection\n"); | 465 "\t%ju failure%s of source address selection\n"); |
466 for (first = 1, i = 0; i < 16; i++) { 467 if (ip6stat.ip6s_sources_sameif[i]) { 468 if (first) { 469 printf("\tsource addresses on an outgoing I/F\n"); 470 first = 0; 471 } 472 PRINT_SCOPESTAT(ip6s_sources_sameif[i], i); 473 } --- 30 unchanged lines hidden (view full) --- 504 if (first) { 505 printf("\tdeprecated source addresses\n"); 506 first = 0; 507 } 508 PRINT_SCOPESTAT(ip6s_sources_deprecated[i], i); 509 } 510 } 511 | 466 for (first = 1, i = 0; i < 16; i++) { 467 if (ip6stat.ip6s_sources_sameif[i]) { 468 if (first) { 469 printf("\tsource addresses on an outgoing I/F\n"); 470 first = 0; 471 } 472 PRINT_SCOPESTAT(ip6s_sources_sameif[i], i); 473 } --- 30 unchanged lines hidden (view full) --- 504 if (first) { 505 printf("\tdeprecated source addresses\n"); 506 first = 0; 507 } 508 PRINT_SCOPESTAT(ip6s_sources_deprecated[i], i); 509 } 510 } 511 |
512 p1a(ip6s_forward_cachehit, "\t%llu forward cache hit\n"); 513 p1a(ip6s_forward_cachemiss, "\t%llu forward cache miss\n"); | 512 p1a(ip6s_forward_cachehit, "\t%ju forward cache hit\n"); 513 p1a(ip6s_forward_cachemiss, "\t%ju forward cache miss\n"); |
514 printf("\tSource addresses selection rule applied:\n"); 515 for (i = 0; i < 16; i++) { 516 if (ip6stat.ip6s_sources_rule[i]) | 514 printf("\tSource addresses selection rule applied:\n"); 515 for (i = 0; i < 16; i++) { 516 if (ip6stat.ip6s_sources_rule[i]) |
517 printf("\t\t%llu %s\n", ip6stat.ip6s_sources_rule[i], | 517 printf("\t\t%ju %s\n", 518 (uintmax_t)ip6stat.ip6s_sources_rule[i], |
518 srcrule_str[i]); 519 } 520#undef p 521#undef p1a 522} 523 524/* 525 * Dump IPv6 per-interface statistics based on RFC 2465. 526 */ 527void 528ip6_ifstats(char *ifname) 529{ 530 struct in6_ifreq ifr; 531 int s; 532#define p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \ | 519 srcrule_str[i]); 520 } 521#undef p 522#undef p1a 523} 524 525/* 526 * Dump IPv6 per-interface statistics based on RFC 2465. 527 */ 528void 529ip6_ifstats(char *ifname) 530{ 531 struct in6_ifreq ifr; 532 int s; 533#define p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \ |
533 printf(m, (unsigned long long)ifr.ifr_ifru.ifru_stat.f, plural(ifr.ifr_ifru.ifru_stat.f)) | 534 printf(m, (uintmax_t)ifr.ifr_ifru.ifru_stat.f, plural(ifr.ifr_ifru.ifru_stat.f)) |
534#define p_5(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \ | 535#define p_5(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \ |
535 printf(m, (unsigned long long)ip6stat.f) | 536 printf(m, (uintmax_t)ip6stat.f) |
536 537 if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { 538 perror("Warning: socket(AF_INET6)"); 539 return; 540 } 541 542 strcpy(ifr.ifr_name, ifname); 543 printf("ip6 on %s:\n", ifr.ifr_name); 544 545 if (ioctl(s, SIOCGIFSTAT_IN6, (char *)&ifr) < 0) { 546 perror("Warning: ioctl(SIOCGIFSTAT_IN6)"); 547 goto end; 548 } 549 | 537 538 if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { 539 perror("Warning: socket(AF_INET6)"); 540 return; 541 } 542 543 strcpy(ifr.ifr_name, ifname); 544 printf("ip6 on %s:\n", ifr.ifr_name); 545 546 if (ioctl(s, SIOCGIFSTAT_IN6, (char *)&ifr) < 0) { 547 perror("Warning: ioctl(SIOCGIFSTAT_IN6)"); 548 goto end; 549 } 550 |
550 p(ifs6_in_receive, "\t%llu total input datagram%s\n"); 551 p(ifs6_in_hdrerr, "\t%llu datagram%s with invalid header received\n"); 552 p(ifs6_in_toobig, "\t%llu datagram%s exceeded MTU received\n"); 553 p(ifs6_in_noroute, "\t%llu datagram%s with no route received\n"); 554 p(ifs6_in_addrerr, "\t%llu datagram%s with invalid dst received\n"); 555 p(ifs6_in_protounknown, "\t%llu datagram%s with unknown proto received\n"); 556 p(ifs6_in_truncated, "\t%llu truncated datagram%s received\n"); 557 p(ifs6_in_discard, "\t%llu input datagram%s discarded\n"); | 551 p(ifs6_in_receive, "\t%ju total input datagram%s\n"); 552 p(ifs6_in_hdrerr, "\t%ju datagram%s with invalid header received\n"); 553 p(ifs6_in_toobig, "\t%ju datagram%s exceeded MTU received\n"); 554 p(ifs6_in_noroute, "\t%ju datagram%s with no route received\n"); 555 p(ifs6_in_addrerr, "\t%ju datagram%s with invalid dst received\n"); 556 p(ifs6_in_protounknown, "\t%ju datagram%s with unknown proto received\n"); 557 p(ifs6_in_truncated, "\t%ju truncated datagram%s received\n"); 558 p(ifs6_in_discard, "\t%ju input datagram%s discarded\n"); |
558 p(ifs6_in_deliver, | 559 p(ifs6_in_deliver, |
559 "\t%llu datagram%s delivered to an upper layer protocol\n"); 560 p(ifs6_out_forward, "\t%llu datagram%s forwarded to this interface\n"); | 560 "\t%ju datagram%s delivered to an upper layer protocol\n"); 561 p(ifs6_out_forward, "\t%ju datagram%s forwarded to this interface\n"); |
561 p(ifs6_out_request, | 562 p(ifs6_out_request, |
562 "\t%llu datagram%s sent from an upper layer protocol\n"); 563 p(ifs6_out_discard, "\t%llu total discarded output datagram%s\n"); 564 p(ifs6_out_fragok, "\t%llu output datagram%s fragmented\n"); 565 p(ifs6_out_fragfail, "\t%llu output datagram%s failed on fragment\n"); 566 p(ifs6_out_fragcreat, "\t%llu output datagram%s succeeded on fragment\n"); 567 p(ifs6_reass_reqd, "\t%llu incoming datagram%s fragmented\n"); 568 p(ifs6_reass_ok, "\t%llu datagram%s reassembled\n"); 569 p(ifs6_reass_fail, "\t%llu datagram%s failed on reassembly\n"); 570 p(ifs6_in_mcast, "\t%llu multicast datagram%s received\n"); 571 p(ifs6_out_mcast, "\t%llu multicast datagram%s sent\n"); | 563 "\t%ju datagram%s sent from an upper layer protocol\n"); 564 p(ifs6_out_discard, "\t%ju total discarded output datagram%s\n"); 565 p(ifs6_out_fragok, "\t%ju output datagram%s fragmented\n"); 566 p(ifs6_out_fragfail, "\t%ju output datagram%s failed on fragment\n"); 567 p(ifs6_out_fragcreat, "\t%ju output datagram%s succeeded on fragment\n"); 568 p(ifs6_reass_reqd, "\t%ju incoming datagram%s fragmented\n"); 569 p(ifs6_reass_ok, "\t%ju datagram%s reassembled\n"); 570 p(ifs6_reass_fail, "\t%ju datagram%s failed on reassembly\n"); 571 p(ifs6_in_mcast, "\t%ju multicast datagram%s received\n"); 572 p(ifs6_out_mcast, "\t%ju multicast datagram%s sent\n"); |
572 573 end: 574 close(s); 575 576#undef p 577#undef p_5 578} 579 --- 274 unchanged lines hidden (view full) --- 854 855 len = sizeof icmp6stat; 856 memset(&icmp6stat, 0, len); 857 if (sysctl(mib, 4, &icmp6stat, &len, (void *)0, 0) < 0) 858 return; 859 printf("%s:\n", name); 860 861#define p(f, m) if (icmp6stat.f || sflag <= 1) \ | 573 574 end: 575 close(s); 576 577#undef p 578#undef p_5 579} 580 --- 274 unchanged lines hidden (view full) --- 855 856 len = sizeof icmp6stat; 857 memset(&icmp6stat, 0, len); 858 if (sysctl(mib, 4, &icmp6stat, &len, (void *)0, 0) < 0) 859 return; 860 printf("%s:\n", name); 861 862#define p(f, m) if (icmp6stat.f || sflag <= 1) \ |
862 printf(m, (unsigned long long)icmp6stat.f, plural(icmp6stat.f)) 863#define p_5(f, m) printf(m, (unsigned long long)icmp6stat.f) | 863 printf(m, (uintmax_t)icmp6stat.f, plural(icmp6stat.f)) 864#define p_5(f, m) printf(m, (uintmax_t)icmp6stat.f) |
864 | 865 |
865 p(icp6s_error, "\t%llu call%s to icmp6_error\n"); | 866 p(icp6s_error, "\t%ju call%s to icmp6_error\n"); |
866 p(icp6s_canterror, | 867 p(icp6s_canterror, |
867 "\t%llu error%s not generated in response to an icmp6 message\n"); | 868 "\t%ju error%s not generated in response to an icmp6 message\n"); |
868 p(icp6s_toofreq, | 869 p(icp6s_toofreq, |
869 "\t%llu error%s not generated because of rate limitation\n"); | 870 "\t%ju error%s not generated because of rate limitation\n"); |
870#define NELEM (int)(sizeof(icmp6stat.icp6s_outhist)/sizeof(icmp6stat.icp6s_outhist[0])) 871 for (first = 1, i = 0; i < NELEM; i++) 872 if (icmp6stat.icp6s_outhist[i] != 0) { 873 if (first) { 874 printf("\tOutput histogram:\n"); 875 first = 0; 876 } | 871#define NELEM (int)(sizeof(icmp6stat.icp6s_outhist)/sizeof(icmp6stat.icp6s_outhist[0])) 872 for (first = 1, i = 0; i < NELEM; i++) 873 if (icmp6stat.icp6s_outhist[i] != 0) { 874 if (first) { 875 printf("\tOutput histogram:\n"); 876 first = 0; 877 } |
877 printf("\t\t%s: %llu\n", icmp6names[i], 878 (unsigned long long)icmp6stat.icp6s_outhist[i]); | 878 printf("\t\t%s: %ju\n", icmp6names[i], 879 (uintmax_t)icmp6stat.icp6s_outhist[i]); |
879 } 880#undef NELEM | 880 } 881#undef NELEM |
881 p(icp6s_badcode, "\t%llu message%s with bad code fields\n"); 882 p(icp6s_tooshort, "\t%llu message%s < minimum length\n"); 883 p(icp6s_checksum, "\t%llu bad checksum%s\n"); 884 p(icp6s_badlen, "\t%llu message%s with bad length\n"); | 882 p(icp6s_badcode, "\t%ju message%s with bad code fields\n"); 883 p(icp6s_tooshort, "\t%ju message%s < minimum length\n"); 884 p(icp6s_checksum, "\t%ju bad checksum%s\n"); 885 p(icp6s_badlen, "\t%ju message%s with bad length\n"); |
885#define NELEM (int)(sizeof(icmp6stat.icp6s_inhist)/sizeof(icmp6stat.icp6s_inhist[0])) 886 for (first = 1, i = 0; i < NELEM; i++) 887 if (icmp6stat.icp6s_inhist[i] != 0) { 888 if (first) { 889 printf("\tInput histogram:\n"); 890 first = 0; 891 } | 886#define NELEM (int)(sizeof(icmp6stat.icp6s_inhist)/sizeof(icmp6stat.icp6s_inhist[0])) 887 for (first = 1, i = 0; i < NELEM; i++) 888 if (icmp6stat.icp6s_inhist[i] != 0) { 889 if (first) { 890 printf("\tInput histogram:\n"); 891 first = 0; 892 } |
892 printf("\t\t%s: %llu\n", icmp6names[i], 893 (unsigned long long)icmp6stat.icp6s_inhist[i]); | 893 printf("\t\t%s: %ju\n", icmp6names[i], 894 (uintmax_t)icmp6stat.icp6s_inhist[i]); |
894 } 895#undef NELEM 896 printf("\tHistogram of error messages to be generated:\n"); | 895 } 896#undef NELEM 897 printf("\tHistogram of error messages to be generated:\n"); |
897 p_5(icp6s_odst_unreach_noroute, "\t\t%llu no route\n"); 898 p_5(icp6s_odst_unreach_admin, "\t\t%llu administratively prohibited\n"); 899 p_5(icp6s_odst_unreach_beyondscope, "\t\t%llu beyond scope\n"); 900 p_5(icp6s_odst_unreach_addr, "\t\t%llu address unreachable\n"); 901 p_5(icp6s_odst_unreach_noport, "\t\t%llu port unreachable\n"); 902 p_5(icp6s_opacket_too_big, "\t\t%llu packet too big\n"); 903 p_5(icp6s_otime_exceed_transit, "\t\t%llu time exceed transit\n"); 904 p_5(icp6s_otime_exceed_reassembly, "\t\t%llu time exceed reassembly\n"); 905 p_5(icp6s_oparamprob_header, "\t\t%llu erroneous header field\n"); 906 p_5(icp6s_oparamprob_nextheader, "\t\t%llu unrecognized next header\n"); 907 p_5(icp6s_oparamprob_option, "\t\t%llu unrecognized option\n"); 908 p_5(icp6s_oredirect, "\t\t%llu redirect\n"); 909 p_5(icp6s_ounknown, "\t\t%llu unknown\n"); | 898 p_5(icp6s_odst_unreach_noroute, "\t\t%ju no route\n"); 899 p_5(icp6s_odst_unreach_admin, "\t\t%ju administratively prohibited\n"); 900 p_5(icp6s_odst_unreach_beyondscope, "\t\t%ju beyond scope\n"); 901 p_5(icp6s_odst_unreach_addr, "\t\t%ju address unreachable\n"); 902 p_5(icp6s_odst_unreach_noport, "\t\t%ju port unreachable\n"); 903 p_5(icp6s_opacket_too_big, "\t\t%ju packet too big\n"); 904 p_5(icp6s_otime_exceed_transit, "\t\t%ju time exceed transit\n"); 905 p_5(icp6s_otime_exceed_reassembly, "\t\t%ju time exceed reassembly\n"); 906 p_5(icp6s_oparamprob_header, "\t\t%ju erroneous header field\n"); 907 p_5(icp6s_oparamprob_nextheader, "\t\t%ju unrecognized next header\n"); 908 p_5(icp6s_oparamprob_option, "\t\t%ju unrecognized option\n"); 909 p_5(icp6s_oredirect, "\t\t%ju redirect\n"); 910 p_5(icp6s_ounknown, "\t\t%ju unknown\n"); |
910 | 911 |
911 p(icp6s_reflect, "\t%llu message response%s generated\n"); 912 p(icp6s_nd_toomanyopt, "\t%llu message%s with too many ND options\n"); 913 p(icp6s_nd_badopt, "\t%llu message%s with bad ND options\n"); 914 p(icp6s_badns, "\t%llu bad neighbor solicitation message%s\n"); 915 p(icp6s_badna, "\t%llu bad neighbor advertisement message%s\n"); 916 p(icp6s_badrs, "\t%llu bad router solicitation message%s\n"); 917 p(icp6s_badra, "\t%llu bad router advertisement message%s\n"); 918 p(icp6s_badredirect, "\t%llu bad redirect message%s\n"); 919 p(icp6s_pmtuchg, "\t%llu path MTU change%s\n"); | 912 p(icp6s_reflect, "\t%ju message response%s generated\n"); 913 p(icp6s_nd_toomanyopt, "\t%ju message%s with too many ND options\n"); 914 p(icp6s_nd_badopt, "\t%ju message%s with bad ND options\n"); 915 p(icp6s_badns, "\t%ju bad neighbor solicitation message%s\n"); 916 p(icp6s_badna, "\t%ju bad neighbor advertisement message%s\n"); 917 p(icp6s_badrs, "\t%ju bad router solicitation message%s\n"); 918 p(icp6s_badra, "\t%ju bad router advertisement message%s\n"); 919 p(icp6s_badredirect, "\t%ju bad redirect message%s\n"); 920 p(icp6s_pmtuchg, "\t%ju path MTU change%s\n"); |
920#undef p 921#undef p_5 922} 923 924/* 925 * Dump ICMPv6 per-interface statistics based on RFC 2466. 926 */ 927void 928icmp6_ifstats(char *ifname) 929{ 930 struct in6_ifreq ifr; 931 int s; 932#define p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \ | 921#undef p 922#undef p_5 923} 924 925/* 926 * Dump ICMPv6 per-interface statistics based on RFC 2466. 927 */ 928void 929icmp6_ifstats(char *ifname) 930{ 931 struct in6_ifreq ifr; 932 int s; 933#define p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \ |
933 printf(m, (unsigned long long)ifr.ifr_ifru.ifru_icmp6stat.f, plural(ifr.ifr_ifru.ifru_icmp6stat.f)) | 934 printf(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f, plural(ifr.ifr_ifru.ifru_icmp6stat.f)) |
934#define p2(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \ | 935#define p2(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \ |
935 printf(m, (unsigned long long)ifr.ifr_ifru.ifru_icmp6stat.f, pluralies(ifr.ifr_ifru.ifru_icmp6stat.f)) | 936 printf(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f, pluralies(ifr.ifr_ifru.ifru_icmp6stat.f)) |
936 937 if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { 938 perror("Warning: socket(AF_INET6)"); 939 return; 940 } 941 942 strcpy(ifr.ifr_name, ifname); 943 printf("icmp6 on %s:\n", ifr.ifr_name); 944 945 if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) { 946 perror("Warning: ioctl(SIOCGIFSTAT_ICMP6)"); 947 goto end; 948 } 949 | 937 938 if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { 939 perror("Warning: socket(AF_INET6)"); 940 return; 941 } 942 943 strcpy(ifr.ifr_name, ifname); 944 printf("icmp6 on %s:\n", ifr.ifr_name); 945 946 if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) { 947 perror("Warning: ioctl(SIOCGIFSTAT_ICMP6)"); 948 goto end; 949 } 950 |
950 p(ifs6_in_msg, "\t%llu total input message%s\n"); 951 p(ifs6_in_error, "\t%llu total input error message%s\n"); 952 p(ifs6_in_dstunreach, "\t%llu input destination unreachable error%s\n"); 953 p(ifs6_in_adminprohib, "\t%llu input administratively prohibited error%s\n"); 954 p(ifs6_in_timeexceed, "\t%llu input time exceeded error%s\n"); 955 p(ifs6_in_paramprob, "\t%llu input parameter problem error%s\n"); 956 p(ifs6_in_pkttoobig, "\t%llu input packet too big error%s\n"); 957 p(ifs6_in_echo, "\t%llu input echo request%s\n"); 958 p2(ifs6_in_echoreply, "\t%llu input echo repl%s\n"); 959 p(ifs6_in_routersolicit, "\t%llu input router solicitation%s\n"); 960 p(ifs6_in_routeradvert, "\t%llu input router advertisement%s\n"); 961 p(ifs6_in_neighborsolicit, "\t%llu input neighbor solicitation%s\n"); 962 p(ifs6_in_neighboradvert, "\t%llu input neighbor advertisement%s\n"); 963 p(ifs6_in_redirect, "\t%llu input redirect%s\n"); 964 p2(ifs6_in_mldquery, "\t%llu input MLD quer%s\n"); 965 p(ifs6_in_mldreport, "\t%llu input MLD report%s\n"); 966 p(ifs6_in_mlddone, "\t%llu input MLD done%s\n"); | 951 p(ifs6_in_msg, "\t%ju total input message%s\n"); 952 p(ifs6_in_error, "\t%ju total input error message%s\n"); 953 p(ifs6_in_dstunreach, "\t%ju input destination unreachable error%s\n"); 954 p(ifs6_in_adminprohib, "\t%ju input administratively prohibited error%s\n"); 955 p(ifs6_in_timeexceed, "\t%ju input time exceeded error%s\n"); 956 p(ifs6_in_paramprob, "\t%ju input parameter problem error%s\n"); 957 p(ifs6_in_pkttoobig, "\t%ju input packet too big error%s\n"); 958 p(ifs6_in_echo, "\t%ju input echo request%s\n"); 959 p2(ifs6_in_echoreply, "\t%ju input echo repl%s\n"); 960 p(ifs6_in_routersolicit, "\t%ju input router solicitation%s\n"); 961 p(ifs6_in_routeradvert, "\t%ju input router advertisement%s\n"); 962 p(ifs6_in_neighborsolicit, "\t%ju input neighbor solicitation%s\n"); 963 p(ifs6_in_neighboradvert, "\t%ju input neighbor advertisement%s\n"); 964 p(ifs6_in_redirect, "\t%ju input redirect%s\n"); 965 p2(ifs6_in_mldquery, "\t%ju input MLD quer%s\n"); 966 p(ifs6_in_mldreport, "\t%ju input MLD report%s\n"); 967 p(ifs6_in_mlddone, "\t%ju input MLD done%s\n"); |
967 | 968 |
968 p(ifs6_out_msg, "\t%llu total output message%s\n"); 969 p(ifs6_out_error, "\t%llu total output error message%s\n"); 970 p(ifs6_out_dstunreach, "\t%llu output destination unreachable error%s\n"); 971 p(ifs6_out_adminprohib, "\t%llu output administratively prohibited error%s\n"); 972 p(ifs6_out_timeexceed, "\t%llu output time exceeded error%s\n"); 973 p(ifs6_out_paramprob, "\t%llu output parameter problem error%s\n"); 974 p(ifs6_out_pkttoobig, "\t%llu output packet too big error%s\n"); 975 p(ifs6_out_echo, "\t%llu output echo request%s\n"); 976 p2(ifs6_out_echoreply, "\t%llu output echo repl%s\n"); 977 p(ifs6_out_routersolicit, "\t%llu output router solicitation%s\n"); 978 p(ifs6_out_routeradvert, "\t%llu output router advertisement%s\n"); 979 p(ifs6_out_neighborsolicit, "\t%llu output neighbor solicitation%s\n"); 980 p(ifs6_out_neighboradvert, "\t%llu output neighbor advertisement%s\n"); 981 p(ifs6_out_redirect, "\t%llu output redirect%s\n"); 982 p2(ifs6_out_mldquery, "\t%llu output MLD quer%s\n"); 983 p(ifs6_out_mldreport, "\t%llu output MLD report%s\n"); 984 p(ifs6_out_mlddone, "\t%llu output MLD done%s\n"); | 969 p(ifs6_out_msg, "\t%ju total output message%s\n"); 970 p(ifs6_out_error, "\t%ju total output error message%s\n"); 971 p(ifs6_out_dstunreach, "\t%ju output destination unreachable error%s\n"); 972 p(ifs6_out_adminprohib, "\t%ju output administratively prohibited error%s\n"); 973 p(ifs6_out_timeexceed, "\t%ju output time exceeded error%s\n"); 974 p(ifs6_out_paramprob, "\t%ju output parameter problem error%s\n"); 975 p(ifs6_out_pkttoobig, "\t%ju output packet too big error%s\n"); 976 p(ifs6_out_echo, "\t%ju output echo request%s\n"); 977 p2(ifs6_out_echoreply, "\t%ju output echo repl%s\n"); 978 p(ifs6_out_routersolicit, "\t%ju output router solicitation%s\n"); 979 p(ifs6_out_routeradvert, "\t%ju output router advertisement%s\n"); 980 p(ifs6_out_neighborsolicit, "\t%ju output neighbor solicitation%s\n"); 981 p(ifs6_out_neighboradvert, "\t%ju output neighbor advertisement%s\n"); 982 p(ifs6_out_redirect, "\t%ju output redirect%s\n"); 983 p2(ifs6_out_mldquery, "\t%ju output MLD quer%s\n"); 984 p(ifs6_out_mldreport, "\t%ju output MLD report%s\n"); 985 p(ifs6_out_mlddone, "\t%ju output MLD done%s\n"); |
985 986 end: 987 close(s); 988#undef p 989} 990 991/* 992 * Dump PIM statistics structure. --- 5 unchanged lines hidden (view full) --- 998 999 if (off == 0) 1000 return; 1001 if (kread(off, (char *)&pim6stat, sizeof(pim6stat))) 1002 return; 1003 printf("%s:\n", name); 1004 1005#define p(f, m) if (pim6stat.f || sflag <= 1) \ | 986 987 end: 988 close(s); 989#undef p 990} 991 992/* 993 * Dump PIM statistics structure. --- 5 unchanged lines hidden (view full) --- 999 1000 if (off == 0) 1001 return; 1002 if (kread(off, (char *)&pim6stat, sizeof(pim6stat))) 1003 return; 1004 printf("%s:\n", name); 1005 1006#define p(f, m) if (pim6stat.f || sflag <= 1) \ |
1006 printf(m, (unsigned long long)pim6stat.f, plural(pim6stat.f)) 1007 p(pim6s_rcv_total, "\t%llu message%s received\n"); 1008 p(pim6s_rcv_tooshort, "\t%llu message%s received with too few bytes\n"); 1009 p(pim6s_rcv_badsum, "\t%llu message%s received with bad checksum\n"); 1010 p(pim6s_rcv_badversion, "\t%llu message%s received with bad version\n"); 1011 p(pim6s_rcv_registers, "\t%llu register%s received\n"); 1012 p(pim6s_rcv_badregisters, "\t%llu bad register%s received\n"); 1013 p(pim6s_snd_registers, "\t%llu register%s sent\n"); | 1007 printf(m, (uintmax_t)pim6stat.f, plural(pim6stat.f)) 1008 p(pim6s_rcv_total, "\t%ju message%s received\n"); 1009 p(pim6s_rcv_tooshort, "\t%ju message%s received with too few bytes\n"); 1010 p(pim6s_rcv_badsum, "\t%ju message%s received with bad checksum\n"); 1011 p(pim6s_rcv_badversion, "\t%ju message%s received with bad version\n"); 1012 p(pim6s_rcv_registers, "\t%ju register%s received\n"); 1013 p(pim6s_rcv_badregisters, "\t%ju bad register%s received\n"); 1014 p(pim6s_snd_registers, "\t%ju register%s sent\n"); |
1014#undef p 1015} 1016 1017/* 1018 * Dump raw ip6 statistics structure. 1019 */ 1020void 1021rip6_stats(u_long off __unused, const char *name, int af1 __unused) --- 13 unchanged lines hidden (view full) --- 1035 if (errno != ENOENT) 1036 perror("Warning: sysctl(net.inet6.ip6.rip6stats)"); 1037 return; 1038 } 1039 1040 printf("%s:\n", name); 1041 1042#define p(f, m) if (rip6stat.f || sflag <= 1) \ | 1015#undef p 1016} 1017 1018/* 1019 * Dump raw ip6 statistics structure. 1020 */ 1021void 1022rip6_stats(u_long off __unused, const char *name, int af1 __unused) --- 13 unchanged lines hidden (view full) --- 1036 if (errno != ENOENT) 1037 perror("Warning: sysctl(net.inet6.ip6.rip6stats)"); 1038 return; 1039 } 1040 1041 printf("%s:\n", name); 1042 1043#define p(f, m) if (rip6stat.f || sflag <= 1) \ |
1043 printf(m, (unsigned long long)rip6stat.f, plural(rip6stat.f)) 1044 p(rip6s_ipackets, "\t%llu message%s received\n"); 1045 p(rip6s_isum, "\t%llu checksum calcuration%s on inbound\n"); 1046 p(rip6s_badsum, "\t%llu message%s with bad checksum\n"); 1047 p(rip6s_nosock, "\t%llu message%s dropped due to no socket\n"); | 1044 printf(m, (uintmax_t)rip6stat.f, plural(rip6stat.f)) 1045 p(rip6s_ipackets, "\t%ju message%s received\n"); 1046 p(rip6s_isum, "\t%ju checksum calcuration%s on inbound\n"); 1047 p(rip6s_badsum, "\t%ju message%s with bad checksum\n"); 1048 p(rip6s_nosock, "\t%ju message%s dropped due to no socket\n"); |
1048 p(rip6s_nosockmcast, | 1049 p(rip6s_nosockmcast, |
1049 "\t%llu multicast message%s dropped due to no socket\n"); | 1050 "\t%ju multicast message%s dropped due to no socket\n"); |
1050 p(rip6s_fullsock, | 1051 p(rip6s_fullsock, |
1051 "\t%llu message%s dropped due to full socket buffers\n"); | 1052 "\t%ju message%s dropped due to full socket buffers\n"); |
1052 delivered = rip6stat.rip6s_ipackets - 1053 rip6stat.rip6s_badsum - 1054 rip6stat.rip6s_nosock - 1055 rip6stat.rip6s_nosockmcast - 1056 rip6stat.rip6s_fullsock; 1057 if (delivered || sflag <= 1) | 1053 delivered = rip6stat.rip6s_ipackets - 1054 rip6stat.rip6s_badsum - 1055 rip6stat.rip6s_nosock - 1056 rip6stat.rip6s_nosockmcast - 1057 rip6stat.rip6s_fullsock; 1058 if (delivered || sflag <= 1) |
1058 printf("\t%llu delivered\n", (unsigned long long)delivered); 1059 p(rip6s_opackets, "\t%llu datagram%s output\n"); | 1059 printf("\t%ju delivered\n", (uintmax_t)delivered); 1060 p(rip6s_opackets, "\t%ju datagram%s output\n"); |
1060#undef p 1061} 1062 1063/* 1064 * Pretty print an Internet address (net address + port). 1065 * Take numeric_addr and numeric_port into consideration. 1066 */ 1067#define GETSERVBYPORT6(port, proto, ret)\ --- 73 unchanged lines hidden --- | 1061#undef p 1062} 1063 1064/* 1065 * Pretty print an Internet address (net address + port). 1066 * Take numeric_addr and numeric_port into consideration. 1067 */ 1068#define GETSERVBYPORT6(port, proto, ret)\ --- 73 unchanged lines hidden --- |