Index: route.c =================================================================== --- route.c (revision 225135) +++ route.c (working copy) @@ -1010,14 +1010,18 @@ rt_stats(u_long rtsaddr, u_long rttaddr) kread(rttaddr, (char *)&rttrash, sizeof (rttrash)); printf("routing:\n"); -#define p(f, m) if (rtstat.f || sflag <= 1) \ - printf(m, rtstat.f, plural(rtstat.f)) +#define p(f, m) \ + if (rtstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), rtstat.f); \ + printf(m, buf, plural(rtstat.f)); \ + } - p(rts_badredirect, "\t%hu bad routing redirect%s\n"); - p(rts_dynamic, "\t%hu dynamically created route%s\n"); - p(rts_newgateway, "\t%hu new gateway%s due to redirects\n"); - p(rts_unreach, "\t%hu destination%s found unreachable\n"); - p(rts_wildcard, "\t%hu use%s of a wildcard route\n"); + p(rts_badredirect, "\t%s bad routing redirect%s\n"); + p(rts_dynamic, "\t%s dynamically created route%s\n"); + p(rts_newgateway, "\t%s new gateway%s due to redirects\n"); + p(rts_unreach, "\t%s destination%s found unreachable\n"); + p(rts_wildcard, "\t%s use%s of a wildcard route\n"); #undef p if (rttrash || sflag <= 1) Index: if.c =================================================================== --- if.c (revision 225135) +++ if.c (working copy) @@ -104,27 +104,35 @@ pfsync_stats(u_long off, const char *name, int af1 printf("%s:\n", name); -#define p(f, m) if (pfsyncstat.f || sflag <= 1) \ - printf(m, (uintmax_t)pfsyncstat.f, plural(pfsyncstat.f)) -#define p2(f, m) if (pfsyncstat.f || sflag <= 1) \ - printf(m, (uintmax_t)pfsyncstat.f) +#define p(f, m) \ + if (pfsyncstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), pfsyncstat.f); \ + printf(m, buf, plural(pfsyncstat.f)); \ + } +#define p2(f, m) \ + if (pfsyncstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), pfsyncstat.f); \ + printf(m, buf); \ + } - p(pfsyncs_ipackets, "\t%ju packet%s received (IPv4)\n"); - p(pfsyncs_ipackets6, "\t%ju packet%s received (IPv6)\n"); - p(pfsyncs_badif, "\t\t%ju packet%s discarded for bad interface\n"); - p(pfsyncs_badttl, "\t\t%ju packet%s discarded for bad ttl\n"); - p(pfsyncs_hdrops, "\t\t%ju packet%s shorter than header\n"); - p(pfsyncs_badver, "\t\t%ju packet%s discarded for bad version\n"); - p(pfsyncs_badauth, "\t\t%ju packet%s discarded for bad HMAC\n"); - p(pfsyncs_badact,"\t\t%ju packet%s discarded for bad action\n"); - p(pfsyncs_badlen, "\t\t%ju packet%s discarded for short packet\n"); - p(pfsyncs_badval, "\t\t%ju state%s discarded for bad values\n"); - p(pfsyncs_stale, "\t\t%ju stale state%s\n"); - p(pfsyncs_badstate, "\t\t%ju failed state lookup/insert%s\n"); - p(pfsyncs_opackets, "\t%ju packet%s sent (IPv4)\n"); - p(pfsyncs_opackets6, "\t%ju packet%s sent (IPv6)\n"); - p2(pfsyncs_onomem, "\t\t%ju send failed due to mbuf memory error\n"); - p2(pfsyncs_oerrors, "\t\t%ju send error\n"); + p(pfsyncs_ipackets, "\t%s packet%s received (IPv4)\n"); + p(pfsyncs_ipackets6, "\t%s packet%s received (IPv6)\n"); + p(pfsyncs_badif, "\t\t%s packet%s discarded for bad interface\n"); + p(pfsyncs_badttl, "\t\t%s packet%s discarded for bad ttl\n"); + p(pfsyncs_hdrops, "\t\t%s packet%s shorter than header\n"); + p(pfsyncs_badver, "\t\t%s packet%s discarded for bad version\n"); + p(pfsyncs_badauth, "\t\t%s packet%s discarded for bad HMAC\n"); + p(pfsyncs_badact,"\t\t%s packet%s discarded for bad action\n"); + p(pfsyncs_badlen, "\t\t%s packet%s discarded for short packet\n"); + p(pfsyncs_badval, "\t\t%s state%s discarded for bad values\n"); + p(pfsyncs_stale, "\t\t%s stale state%s\n"); + p(pfsyncs_badstate, "\t\t%s failed state lookup/insert%s\n"); + p(pfsyncs_opackets, "\t%s packet%s sent (IPv4)\n"); + p(pfsyncs_opackets6, "\t%s packet%s sent (IPv6)\n"); + p2(pfsyncs_onomem, "\t\t%s send failed due to mbuf memory error\n"); + p2(pfsyncs_oerrors, "\t\t%s send error\n"); #undef p #undef p2 } Index: inet.c =================================================================== --- inet.c (revision 225135) +++ inet.c (working copy) @@ -605,115 +605,138 @@ tcp_stats(u_long off, const char *name, int af1 __ printf ("%s:\n", name); -#define p(f, m) if (tcpstat.f || sflag <= 1) \ - printf(m, tcpstat.f, plural(tcpstat.f)) -#define p1a(f, m) if (tcpstat.f || sflag <= 1) \ - printf(m, tcpstat.f) -#define p2(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) \ - printf(m, tcpstat.f1, plural(tcpstat.f1), tcpstat.f2, plural(tcpstat.f2)) -#define p2a(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) \ - printf(m, tcpstat.f1, plural(tcpstat.f1), tcpstat.f2) -#define p3(f, m) if (tcpstat.f || sflag <= 1) \ - printf(m, tcpstat.f, pluralies(tcpstat.f)) +#define p(f, m) \ + if (tcpstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), tcpstat.f); \ + printf(m, buf, plural(tcpstat.f)); \ + } +#define p1a(f, m) \ + if (tcpstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), tcpstat.f); \ + printf(m, buf); \ + } +#define p2(f1, f2, m) \ + if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) { \ + char buf1[15], buf2[15]; /* XXX */ \ + humanized(buf1, sizeof(buf1), tcpstat.f1); \ + humanized(buf2, sizeof(buf2), tcpstat.f2); \ + printf(m, buf1, plural(tcpstat.f1), \ + buf2, plural(tcpstat.f2)); \ + } +#define p2a(f1, f2, m) \ + if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) { \ + char buf1[15], buf2[15]; /* XXX */ \ + humanized(buf1, sizeof(buf1), tcpstat.f1); \ + humanized(buf2, sizeof(buf2), tcpstat.f2); \ + printf(m, buf1, plural(tcpstat.f1), buf2); \ + } +#define p3(f, m) \ + if (tcpstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), tcpstat.f); \ + printf(m, buf, pluralies(tcpstat.f)); \ + } - p(tcps_sndtotal, "\t%lu packet%s sent\n"); - p2(tcps_sndpack,tcps_sndbyte, "\t\t%lu data packet%s (%lu byte%s)\n"); + p(tcps_sndtotal, "\t%s packet%s sent\n"); + p2(tcps_sndpack,tcps_sndbyte, "\t\t%s data packet%s (%s byte%s)\n"); p2(tcps_sndrexmitpack, tcps_sndrexmitbyte, - "\t\t%lu data packet%s (%lu byte%s) retransmitted\n"); + "\t\t%s data packet%s (%s byte%s) retransmitted\n"); p(tcps_sndrexmitbad, - "\t\t%lu data packet%s unnecessarily retransmitted\n"); - p(tcps_mturesent, "\t\t%lu resend%s initiated by MTU discovery\n"); + "\t\t%s data packet%s unnecessarily retransmitted\n"); + p(tcps_mturesent, "\t\t%s resend%s initiated by MTU discovery\n"); p2a(tcps_sndacks, tcps_delack, - "\t\t%lu ack-only packet%s (%lu delayed)\n"); - p(tcps_sndurg, "\t\t%lu URG only packet%s\n"); - p(tcps_sndprobe, "\t\t%lu window probe packet%s\n"); - p(tcps_sndwinup, "\t\t%lu window update packet%s\n"); - p(tcps_sndctrl, "\t\t%lu control packet%s\n"); - p(tcps_rcvtotal, "\t%lu packet%s received\n"); + "\t\t%s ack-only packet%s (%s delayed)\n"); + p(tcps_sndurg, "\t\t%s URG only packet%s\n"); + p(tcps_sndprobe, "\t\t%s window probe packet%s\n"); + p(tcps_sndwinup, "\t\t%s window update packet%s\n"); + p(tcps_sndctrl, "\t\t%s control packet%s\n"); + p(tcps_rcvtotal, "\t%s packet%s received\n"); p2(tcps_rcvackpack, tcps_rcvackbyte, - "\t\t%lu ack%s (for %lu byte%s)\n"); - p(tcps_rcvdupack, "\t\t%lu duplicate ack%s\n"); - p(tcps_rcvacktoomuch, "\t\t%lu ack%s for unsent data\n"); + "\t\t%s ack%s (for %s byte%s)\n"); + p(tcps_rcvdupack, "\t\t%s duplicate ack%s\n"); + p(tcps_rcvacktoomuch, "\t\t%s ack%s for unsent data\n"); p2(tcps_rcvpack, tcps_rcvbyte, - "\t\t%lu packet%s (%lu byte%s) received in-sequence\n"); + "\t\t%s packet%s (%s byte%s) received in-sequence\n"); p2(tcps_rcvduppack, tcps_rcvdupbyte, - "\t\t%lu completely duplicate packet%s (%lu byte%s)\n"); - p(tcps_pawsdrop, "\t\t%lu old duplicate packet%s\n"); + "\t\t%s completely duplicate packet%s (%s byte%s)\n"); + p(tcps_pawsdrop, "\t\t%s old duplicate packet%s\n"); p2(tcps_rcvpartduppack, tcps_rcvpartdupbyte, - "\t\t%lu packet%s with some dup. data (%lu byte%s duped)\n"); + "\t\t%s packet%s with some dup. data (%s byte%s duped)\n"); p2(tcps_rcvoopack, tcps_rcvoobyte, - "\t\t%lu out-of-order packet%s (%lu byte%s)\n"); + "\t\t%s out-of-order packet%s (%s byte%s)\n"); p2(tcps_rcvpackafterwin, tcps_rcvbyteafterwin, - "\t\t%lu packet%s (%lu byte%s) of data after window\n"); - p(tcps_rcvwinprobe, "\t\t%lu window probe%s\n"); - p(tcps_rcvwinupd, "\t\t%lu window update packet%s\n"); - p(tcps_rcvafterclose, "\t\t%lu packet%s received after close\n"); - p(tcps_rcvbadsum, "\t\t%lu discarded for bad checksum%s\n"); - p(tcps_rcvbadoff, "\t\t%lu discarded for bad header offset field%s\n"); - p1a(tcps_rcvshort, "\t\t%lu discarded because packet too short\n"); - p1a(tcps_rcvmemdrop, "\t\t%lu discarded due to memory problems\n"); - p(tcps_connattempt, "\t%lu connection request%s\n"); - p(tcps_accepts, "\t%lu connection accept%s\n"); - p(tcps_badsyn, "\t%lu bad connection attempt%s\n"); - p(tcps_listendrop, "\t%lu listen queue overflow%s\n"); - p(tcps_badrst, "\t%lu ignored RSTs in the window%s\n"); - p(tcps_connects, "\t%lu connection%s established (including accepts)\n"); + "\t\t%s packet%s (%s byte%s) of data after window\n"); + p(tcps_rcvwinprobe, "\t\t%s window probe%s\n"); + p(tcps_rcvwinupd, "\t\t%s window update packet%s\n"); + p(tcps_rcvafterclose, "\t\t%s packet%s received after close\n"); + p(tcps_rcvbadsum, "\t\t%s discarded for bad checksum%s\n"); + p(tcps_rcvbadoff, "\t\t%s discarded for bad header offset field%s\n"); + p1a(tcps_rcvshort, "\t\t%s discarded because packet too short\n"); + p1a(tcps_rcvmemdrop, "\t\t%s discarded due to memory problems\n"); + p(tcps_connattempt, "\t%s connection request%s\n"); + p(tcps_accepts, "\t%s connection accept%s\n"); + p(tcps_badsyn, "\t%s bad connection attempt%s\n"); + p(tcps_listendrop, "\t%s listen queue overflow%s\n"); + p(tcps_badrst, "\t%s ignored RSTs in the window%s\n"); + p(tcps_connects, "\t%s connection%s established (including accepts)\n"); p2(tcps_closed, tcps_drops, - "\t%lu connection%s closed (including %lu drop%s)\n"); - p(tcps_cachedrtt, "\t\t%lu connection%s updated cached RTT on close\n"); + "\t%s connection%s closed (including %s drop%s)\n"); + p(tcps_cachedrtt, "\t\t%s connection%s updated cached RTT on close\n"); p(tcps_cachedrttvar, - "\t\t%lu connection%s updated cached RTT variance on close\n"); + "\t\t%s connection%s updated cached RTT variance on close\n"); p(tcps_cachedssthresh, - "\t\t%lu connection%s updated cached ssthresh on close\n"); - p(tcps_conndrops, "\t%lu embryonic connection%s dropped\n"); + "\t\t%s connection%s updated cached ssthresh on close\n"); + p(tcps_conndrops, "\t%s embryonic connection%s dropped\n"); p2(tcps_rttupdated, tcps_segstimed, - "\t%lu segment%s updated rtt (of %lu attempt%s)\n"); - p(tcps_rexmttimeo, "\t%lu retransmit timeout%s\n"); - p(tcps_timeoutdrop, "\t\t%lu connection%s dropped by rexmit timeout\n"); - p(tcps_persisttimeo, "\t%lu persist timeout%s\n"); - p(tcps_persistdrop, "\t\t%lu connection%s dropped by persist timeout\n"); + "\t%s segment%s updated rtt (of %s attempt%s)\n"); + p(tcps_rexmttimeo, "\t%s retransmit timeout%s\n"); + p(tcps_timeoutdrop, "\t\t%s connection%s dropped by rexmit timeout\n"); + p(tcps_persisttimeo, "\t%s persist timeout%s\n"); + p(tcps_persistdrop, "\t\t%s connection%s dropped by persist timeout\n"); p(tcps_finwait2_drops, - "\t%lu Connection%s (fin_wait_2) dropped because of timeout\n"); - p(tcps_keeptimeo, "\t%lu keepalive timeout%s\n"); - p(tcps_keepprobe, "\t\t%lu keepalive probe%s sent\n"); - p(tcps_keepdrops, "\t\t%lu connection%s dropped by keepalive\n"); - p(tcps_predack, "\t%lu correct ACK header prediction%s\n"); - p(tcps_preddat, "\t%lu correct data packet header prediction%s\n"); + "\t%s Connection%s (fin_wait_2) dropped because of timeout\n"); + p(tcps_keeptimeo, "\t%s keepalive timeout%s\n"); + p(tcps_keepprobe, "\t\t%s keepalive probe%s sent\n"); + p(tcps_keepdrops, "\t\t%s connection%s dropped by keepalive\n"); + p(tcps_predack, "\t%s correct ACK header prediction%s\n"); + p(tcps_preddat, "\t%s correct data packet header prediction%s\n"); - p3(tcps_sc_added, "\t%lu syncache entr%s added\n"); - p1a(tcps_sc_retransmitted, "\t\t%lu retransmitted\n"); - p1a(tcps_sc_dupsyn, "\t\t%lu dupsyn\n"); - p1a(tcps_sc_dropped, "\t\t%lu dropped\n"); - p1a(tcps_sc_completed, "\t\t%lu completed\n"); - p1a(tcps_sc_bucketoverflow, "\t\t%lu bucket overflow\n"); - p1a(tcps_sc_cacheoverflow, "\t\t%lu cache overflow\n"); - p1a(tcps_sc_reset, "\t\t%lu reset\n"); - p1a(tcps_sc_stale, "\t\t%lu stale\n"); - p1a(tcps_sc_aborted, "\t\t%lu aborted\n"); - p1a(tcps_sc_badack, "\t\t%lu badack\n"); - p1a(tcps_sc_unreach, "\t\t%lu unreach\n"); - p(tcps_sc_zonefail, "\t\t%lu zone failure%s\n"); - p(tcps_sc_sendcookie, "\t%lu cookie%s sent\n"); - p(tcps_sc_recvcookie, "\t%lu cookie%s received\n"); + p3(tcps_sc_added, "\t%s syncache entr%s added\n"); + p1a(tcps_sc_retransmitted, "\t\t%s retransmitted\n"); + p1a(tcps_sc_dupsyn, "\t\t%s dupsyn\n"); + p1a(tcps_sc_dropped, "\t\t%s dropped\n"); + p1a(tcps_sc_completed, "\t\t%s completed\n"); + p1a(tcps_sc_bucketoverflow, "\t\t%s bucket overflow\n"); + p1a(tcps_sc_cacheoverflow, "\t\t%s cache overflow\n"); + p1a(tcps_sc_reset, "\t\t%s reset\n"); + p1a(tcps_sc_stale, "\t\t%s stale\n"); + p1a(tcps_sc_aborted, "\t\t%s aborted\n"); + p1a(tcps_sc_badack, "\t\t%s badack\n"); + p1a(tcps_sc_unreach, "\t\t%s unreach\n"); + p(tcps_sc_zonefail, "\t\t%s zone failure%s\n"); + p(tcps_sc_sendcookie, "\t%s cookie%s sent\n"); + p(tcps_sc_recvcookie, "\t%s cookie%s received\n"); - p(tcps_hc_added, "\t%lu hostcache entrie%s added\n"); - p1a(tcps_hc_bucketoverflow, "\t\t%lu bucket overflow\n"); + p(tcps_hc_added, "\t%s hostcache entrie%s added\n"); + p1a(tcps_hc_bucketoverflow, "\t\t%s bucket overflow\n"); - p(tcps_sack_recovery_episode, "\t%lu SACK recovery episode%s\n"); + p(tcps_sack_recovery_episode, "\t%s SACK recovery episode%s\n"); p(tcps_sack_rexmits, - "\t%lu segment rexmit%s in SACK recovery episodes\n"); + "\t%s segment rexmit%s in SACK recovery episodes\n"); p(tcps_sack_rexmit_bytes, - "\t%lu byte rexmit%s in SACK recovery episodes\n"); + "\t%s byte rexmit%s in SACK recovery episodes\n"); p(tcps_sack_rcv_blocks, - "\t%lu SACK option%s (SACK blocks) received\n"); - p(tcps_sack_send_blocks, "\t%lu SACK option%s (SACK blocks) sent\n"); - p1a(tcps_sack_sboverflow, "\t%lu SACK scoreboard overflow\n"); + "\t%s SACK option%s (SACK blocks) received\n"); + p(tcps_sack_send_blocks, "\t%s SACK option%s (SACK blocks) sent\n"); + p1a(tcps_sack_sboverflow, "\t%s SACK scoreboard overflow\n"); - p(tcps_ecn_ce, "\t%lu packet%s with ECN CE bit set\n"); - p(tcps_ecn_ect0, "\t%lu packet%s with ECN ECT(0) bit set\n"); - p(tcps_ecn_ect1, "\t%lu packet%s with ECN ECT(1) bit set\n"); - p(tcps_ecn_shs, "\t%lu successful ECN handshake%s\n"); - p(tcps_ecn_rcwnd, "\t%lu time%s ECN reduced the congestion window\n"); + p(tcps_ecn_ce, "\t%s packet%s with ECN CE bit set\n"); + p(tcps_ecn_ect0, "\t%s packet%s with ECN ECT(0) bit set\n"); + p(tcps_ecn_ect1, "\t%s packet%s with ECN ECT(1) bit set\n"); + p(tcps_ecn_shs, "\t%s successful ECN handshake%s\n"); + p(tcps_ecn_rcwnd, "\t%s time%s ECN reduced the congestion window\n"); #undef p #undef p1a #undef p2 @@ -750,20 +773,29 @@ udp_stats(u_long off, const char *name, int af1 __ kread(off, &udpstat, len); printf("%s:\n", name); -#define p(f, m) if (udpstat.f || sflag <= 1) \ - printf(m, udpstat.f, plural(udpstat.f)) -#define p1a(f, m) if (udpstat.f || sflag <= 1) \ - printf(m, udpstat.f) - p(udps_ipackets, "\t%lu datagram%s received\n"); - p1a(udps_hdrops, "\t%lu with incomplete header\n"); - p1a(udps_badlen, "\t%lu with bad data length field\n"); - p1a(udps_badsum, "\t%lu with bad checksum\n"); - p1a(udps_nosum, "\t%lu with no checksum\n"); - p1a(udps_noport, "\t%lu dropped due to no socket\n"); +#define p(f, m) \ + if (udpstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), udpstat.f); \ + printf(m, buf, plural(udpstat.f)); \ + } +#define p1a(f, m) \ + if (udpstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), udpstat.f); \ + printf(m, buf); \ + } + + p(udps_ipackets, "\t%s datagram%s received\n"); + p1a(udps_hdrops, "\t%s with incomplete header\n"); + p1a(udps_badlen, "\t%s with bad data length field\n"); + p1a(udps_badsum, "\t%s with bad checksum\n"); + p1a(udps_nosum, "\t%s with no checksum\n"); + p1a(udps_noport, "\t%s dropped due to no socket\n"); p(udps_noportbcast, - "\t%lu broadcast/multicast datagram%s undelivered\n"); - p1a(udps_fullsock, "\t%lu dropped due to full socket buffers\n"); - p1a(udpps_pcbhashmiss, "\t%lu not for hashed pcb\n"); + "\t%s broadcast/multicast datagram%s undelivered\n"); + p1a(udps_fullsock, "\t%s dropped due to full socket buffers\n"); + p1a(udpps_pcbhashmiss, "\t%s not for hashed pcb\n"); delivered = udpstat.udps_ipackets - udpstat.udps_hdrops - udpstat.udps_badlen - @@ -772,11 +804,11 @@ udp_stats(u_long off, const char *name, int af1 __ udpstat.udps_noportbcast - udpstat.udps_fullsock; if (delivered || sflag <= 1) - printf("\t%lu delivered\n", delivered); - p(udps_opackets, "\t%lu datagram%s output\n"); + printf("\t%ju delivered\n", delivered); + p(udps_opackets, "\t%s datagram%s output\n"); /* the next statistic is cumulative in udps_noportbcast */ p(udps_filtermcast, - "\t%lu time%s multicast source filter matched\n"); + "\t%s time%s multicast source filter matched\n"); #undef p #undef p1a } @@ -807,24 +839,32 @@ carp_stats(u_long off, const char *name, int af1 _ printf("%s:\n", name); -#define p(f, m) if (carpstat.f || sflag <= 1) \ - printf(m, (uintmax_t)carpstat.f, plural(carpstat.f)) -#define p2(f, m) if (carpstat.f || sflag <= 1) \ - printf(m, (uintmax_t)carpstat.f) +#define p(f, m) \ + if (carpstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), carpstat.f); \ + printf(m, buf, plural(carpstat.f)); \ + } +#define p2(f, m) \ + if (carpstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), carpstat.f); \ + printf(m, buf); \ + } - p(carps_ipackets, "\t%ju packet%s received (IPv4)\n"); - p(carps_ipackets6, "\t%ju packet%s received (IPv6)\n"); - p(carps_badttl, "\t\t%ju packet%s discarded for wrong TTL\n"); - p(carps_hdrops, "\t\t%ju packet%s shorter than header\n"); - p(carps_badsum, "\t\t%ju discarded for bad checksum%s\n"); - p(carps_badver, "\t\t%ju discarded packet%s with a bad version\n"); - p2(carps_badlen, "\t\t%ju discarded because packet too short\n"); - p2(carps_badauth, "\t\t%ju discarded for bad authentication\n"); - p2(carps_badvhid, "\t\t%ju discarded for bad vhid\n"); - p2(carps_badaddrs, "\t\t%ju discarded because of a bad address list\n"); - p(carps_opackets, "\t%ju packet%s sent (IPv4)\n"); - p(carps_opackets6, "\t%ju packet%s sent (IPv6)\n"); - p2(carps_onomem, "\t\t%ju send failed due to mbuf memory error\n"); + p(carps_ipackets, "\t%s packet%s received (IPv4)\n"); + p(carps_ipackets6, "\t%s packet%s received (IPv6)\n"); + p(carps_badttl, "\t\t%s packet%s discarded for wrong TTL\n"); + p(carps_hdrops, "\t\t%s packet%s shorter than header\n"); + p(carps_badsum, "\t\t%s discarded for bad checksum%s\n"); + p(carps_badver, "\t\t%s discarded packet%s with a bad version\n"); + p2(carps_badlen, "\t\t%s discarded because packet too short\n"); + p2(carps_badauth, "\t\t%s discarded for bad authentication\n"); + p2(carps_badvhid, "\t\t%s discarded for bad vhid\n"); + p2(carps_badaddrs, "\t\t%s discarded because of a bad address list\n"); + p(carps_opackets, "\t%s packet%s sent (IPv4)\n"); + p(carps_opackets6, "\t%s packet%s sent (IPv6)\n"); + p2(carps_onomem, "\t\t%s send failed due to mbuf memory error\n"); #if notyet p(carps_ostates, "\t\t%s state update%s sent\n"); #endif @@ -854,44 +894,52 @@ ip_stats(u_long off, const char *name, int af1 __u printf("%s:\n", name); -#define p(f, m) if (ipstat.f || sflag <= 1) \ - printf(m, ipstat.f, plural(ipstat.f)) -#define p1a(f, m) if (ipstat.f || sflag <= 1) \ - printf(m, ipstat.f) +#define p(f, m) \ + if (ipstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), ipstat.f); \ + printf(m, buf, plural(ipstat.f)); \ + } +#define p1a(f, m) \ + if (ipstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), ipstat.f); \ + printf(m, buf); \ + } - p(ips_total, "\t%lu total packet%s received\n"); - p(ips_badsum, "\t%lu bad header checksum%s\n"); - p1a(ips_toosmall, "\t%lu with size smaller than minimum\n"); - p1a(ips_tooshort, "\t%lu with data size < data length\n"); - p1a(ips_toolong, "\t%lu with ip length > max ip packet size\n"); - p1a(ips_badhlen, "\t%lu with header length < data size\n"); - p1a(ips_badlen, "\t%lu with data length < header length\n"); - p1a(ips_badoptions, "\t%lu with bad options\n"); - p1a(ips_badvers, "\t%lu with incorrect version number\n"); - p(ips_fragments, "\t%lu fragment%s received\n"); - p(ips_fragdropped, "\t%lu fragment%s dropped (dup or out of space)\n"); - p(ips_fragtimeout, "\t%lu fragment%s dropped after timeout\n"); - p(ips_reassembled, "\t%lu packet%s reassembled ok\n"); - p(ips_delivered, "\t%lu packet%s for this host\n"); - p(ips_noproto, "\t%lu packet%s for unknown/unsupported protocol\n"); - p(ips_forward, "\t%lu packet%s forwarded"); - p(ips_fastforward, " (%lu packet%s fast forwarded)"); + p(ips_total, "\t%s total packet%s received\n"); + p(ips_badsum, "\t%s bad header checksum%s\n"); + p1a(ips_toosmall, "\t%s with size smaller than minimum\n"); + p1a(ips_tooshort, "\t%s with data size < data length\n"); + p1a(ips_toolong, "\t%s with ip length > max ip packet size\n"); + p1a(ips_badhlen, "\t%s with header length < data size\n"); + p1a(ips_badlen, "\t%s with data length < header length\n"); + p1a(ips_badoptions, "\t%s with bad options\n"); + p1a(ips_badvers, "\t%s with incorrect version number\n"); + p(ips_fragments, "\t%s fragment%s received\n"); + p(ips_fragdropped, "\t%s fragment%s dropped (dup or out of space)\n"); + p(ips_fragtimeout, "\t%s fragment%s dropped after timeout\n"); + p(ips_reassembled, "\t%s packet%s reassembled ok\n"); + p(ips_delivered, "\t%s packet%s for this host\n"); + p(ips_noproto, "\t%s packet%s for unknown/unsupported protocol\n"); + p(ips_forward, "\t%s packet%s forwarded"); + p(ips_fastforward, " (%s packet%s fast forwarded)"); if (ipstat.ips_forward || sflag <= 1) putchar('\n'); - p(ips_cantforward, "\t%lu packet%s not forwardable\n"); + p(ips_cantforward, "\t%s packet%s not forwardable\n"); p(ips_notmember, - "\t%lu packet%s received for unknown multicast group\n"); - p(ips_redirectsent, "\t%lu redirect%s sent\n"); - p(ips_localout, "\t%lu packet%s sent from this host\n"); - p(ips_rawout, "\t%lu packet%s sent with fabricated ip header\n"); + "\t%s packet%s received for unknown multicast group\n"); + p(ips_redirectsent, "\t%s redirect%s sent\n"); + p(ips_localout, "\t%s packet%s sent from this host\n"); + p(ips_rawout, "\t%s packet%s sent with fabricated ip header\n"); p(ips_odropped, - "\t%lu output packet%s dropped due to no bufs, etc.\n"); - p(ips_noroute, "\t%lu output packet%s discarded due to no route\n"); - p(ips_fragmented, "\t%lu output datagram%s fragmented\n"); - p(ips_ofragments, "\t%lu fragment%s created\n"); - p(ips_cantfrag, "\t%lu datagram%s that can't be fragmented\n"); - p(ips_nogif, "\t%lu tunneling packet%s that can't find gif\n"); - p(ips_badaddr, "\t%lu datagram%s with bad address in header\n"); + "\t%s output packet%s dropped due to no bufs, etc.\n"); + p(ips_noroute, "\t%s output packet%s discarded due to no route\n"); + p(ips_fragmented, "\t%s output datagram%s fragmented\n"); + p(ips_ofragments, "\t%s fragment%s created\n"); + p(ips_cantfrag, "\t%s datagram%s that can't be fragmented\n"); + p(ips_nogif, "\t%s tunneling packet%s that can't find gif\n"); + p(ips_badaddr, "\t%s datagram%s with bad address in header\n"); #undef p #undef p1a } @@ -917,20 +965,27 @@ arp_stats(u_long off, const char *name, int af1 __ kread(off, &arpstat, len); printf("%s:\n", name); +#define p(f, m) \ + if (arpstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), arpstat.f); \ + printf(m, buf, plural(arpstat.f)); \ + } +#define p2(f, m) \ + if (arpstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), arpstat.f); \ + printf(m, buf, pluralies(arpstat.f)); \ + } -#define p(f, m) if (arpstat.f || sflag <= 1) \ - printf(m, arpstat.f, plural(arpstat.f)) -#define p2(f, m) if (arpstat.f || sflag <= 1) \ - printf(m, arpstat.f, pluralies(arpstat.f)) - - p(txrequests, "\t%lu ARP request%s sent\n"); - p2(txreplies, "\t%lu ARP repl%s sent\n"); - p(rxrequests, "\t%lu ARP request%s received\n"); - p2(rxreplies, "\t%lu ARP repl%s received\n"); - p(received, "\t%lu ARP packet%s received\n"); - p(dropped, "\t%lu total packet%s dropped due to no ARP entry\n"); - p(timeouts, "\t%lu ARP entry%s timed out\n"); - p(dupips, "\t%lu Duplicate IP%s seen\n"); + p(txrequests, "\t%s ARP request%s sent\n"); + p2(txreplies, "\t%s ARP repl%s sent\n"); + p(rxrequests, "\t%s ARP request%s received\n"); + p2(rxreplies, "\t%s ARP repl%s received\n"); + p(received, "\t%s ARP packet%s received\n"); + p(dropped, "\t%s total packet%s dropped due to no ARP entry\n"); + p(timeouts, "\t%s ARP entry%s timed out\n"); + p(dupips, "\t%s Duplicate IP%s seen\n"); #undef p #undef p2 } @@ -990,6 +1045,7 @@ icmp_stats(u_long off, const char *name, int af1 _ struct icmpstat icmpstat, zerostat; int i, first; size_t len; + char buf[15]; /* XXX */ len = sizeof icmpstat; if (live) { @@ -1004,52 +1060,58 @@ icmp_stats(u_long off, const char *name, int af1 _ kread(off, &icmpstat, len); printf("%s:\n", name); +#define p(f, m) \ + if (icmpstat.f || sflag <= 1) { \ + humanized(buf, sizeof(buf), icmpstat.f); \ + printf(m, buf, plural(icmpstat.f)); \ + } +#define p1a(f, m) \ + if (icmpstat.f || sflag <= 1) { \ + humanized(buf, sizeof(buf), icmpstat.f); \ + printf(m, buf); \ + } +#define p2(f, m) \ + if (icmpstat.f || sflag <= 1) { \ + humanized(buf, sizeof(buf), icmpstat.f); \ + printf(m, buf, pluralies(icmpstat.f)); \ + } -#define p(f, m) if (icmpstat.f || sflag <= 1) \ - printf(m, icmpstat.f, plural(icmpstat.f)) -#define p1a(f, m) if (icmpstat.f || sflag <= 1) \ - printf(m, icmpstat.f) -#define p2(f, m) if (icmpstat.f || sflag <= 1) \ - printf(m, icmpstat.f, plurales(icmpstat.f)) - - p(icps_error, "\t%lu call%s to icmp_error\n"); + p(icps_error, "\t%s call%s to icmp_error\n"); p(icps_oldicmp, - "\t%lu error%s not generated in response to an icmp message\n"); + "\t%s error%s not generated in response to an icmp message\n"); for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++) if (icmpstat.icps_outhist[i] != 0) { if (first) { printf("\tOutput histogram:\n"); first = 0; } + humanized(buf, sizeof(buf), icmpstat.icps_outhist[i]); if (icmpnames[i] != NULL) - printf("\t\t%s: %lu\n", icmpnames[i], - icmpstat.icps_outhist[i]); + printf("\t\t%s: %s\n", icmpnames[i], buf); else - printf("\t\tunknown ICMP #%d: %lu\n", i, - icmpstat.icps_outhist[i]); + printf("\t\tunknown ICMP #%d: %s\n", i, buf); } - p(icps_badcode, "\t%lu message%s with bad code fields\n"); - p(icps_tooshort, "\t%lu message%s less than the minimum length\n"); - p(icps_checksum, "\t%lu message%s with bad checksum\n"); - p(icps_badlen, "\t%lu message%s with bad length\n"); - p1a(icps_bmcastecho, "\t%lu multicast echo requests ignored\n"); - p1a(icps_bmcasttstamp, "\t%lu multicast timestamp requests ignored\n"); + p(icps_badcode, "\t%s message%s with bad code fields\n"); + p(icps_tooshort, "\t%s message%s less than the minimum length\n"); + p(icps_checksum, "\t%s message%s with bad checksum\n"); + p(icps_badlen, "\t%s message%s with bad length\n"); + p1a(icps_bmcastecho, "\t%s multicast echo requests ignored\n"); + p1a(icps_bmcasttstamp, "\t%s multicast timestamp requests ignored\n"); for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++) if (icmpstat.icps_inhist[i] != 0) { if (first) { printf("\tInput histogram:\n"); first = 0; } + humanized(buf, sizeof(buf), icmpstat.icps_inhist[i]); if (icmpnames[i] != NULL) - printf("\t\t%s: %lu\n", icmpnames[i], - icmpstat.icps_inhist[i]); + printf("\t\t%s: %s\n", icmpnames[i], buf); else - printf("\t\tunknown ICMP #%d: %lu\n", i, - icmpstat.icps_inhist[i]); + printf("\t\tunknown ICMP #%d: %s\n", i, buf); } - p(icps_reflect, "\t%lu message response%s generated\n"); - p2(icps_badaddr, "\t%lu invalid return address%s\n"); - p(icps_noroute, "\t%lu no return route%s\n"); + p(icps_reflect, "\t%s message response%s generated\n"); + p2(icps_badaddr, "\t%s invalid return address%s\n"); + p(icps_noroute, "\t%s no return route%s\n"); #undef p #undef p1a #undef p2 @@ -1083,22 +1145,31 @@ igmp_stats_live_old(u_long off, const char *name) printf("%s:\n", name); -#define p(f, m) if (oigmpstat.f || sflag <= 1) \ - printf(m, oigmpstat.f, plural(oigmpstat.f)) -#define py(f, m) if (oigmpstat.f || sflag <= 1) \ - printf(m, oigmpstat.f, oigmpstat.f != 1 ? "ies" : "y") - p(igps_rcv_total, "\t%u message%s received\n"); - p(igps_rcv_tooshort, "\t%u message%s received with too few bytes\n"); - p(igps_rcv_badsum, "\t%u message%s received with bad checksum\n"); - py(igps_rcv_queries, "\t%u membership quer%s received\n"); +#define p(f, m) \ + if (oigmpstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), oigmpstat.f); \ + printf(m, buf, plural(oigmpstat.f)); \ + } +#define py(f, m) \ + if (oigmpstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), oigmpstat.f); \ + printf(m, buf, oigmpstat.f != 1 ? "ies" : "y"); \ + } + + p(igps_rcv_total, "\t%s message%s received\n"); + p(igps_rcv_tooshort, "\t%s message%s received with too few bytes\n"); + p(igps_rcv_badsum, "\t%s message%s received with bad checksum\n"); + py(igps_rcv_queries, "\t%s membership quer%s received\n"); py(igps_rcv_badqueries, - "\t%u membership quer%s received with invalid field(s)\n"); - p(igps_rcv_reports, "\t%u membership report%s received\n"); + "\t%s membership quer%s received with invalid field(s)\n"); + p(igps_rcv_reports, "\t%s membership report%s received\n"); p(igps_rcv_badreports, - "\t%u membership report%s received with invalid field(s)\n"); + "\t%s membership report%s received with invalid field(s)\n"); p(igps_rcv_ourreports, -"\t%u membership report%s received for groups to which we belong\n"); - p(igps_snd_reports, "\t%u membership report%s sent\n"); +"\t%s membership report%s received for groups to which we belong\n"); + p(igps_snd_reports, "\t%s membership report%s sent\n"); #undef p #undef py } @@ -1159,29 +1230,38 @@ igmp_stats(u_long off, const char *name, int af1 _ printf("%s:\n", name); -#define p64(f, m) if (igmpstat.f || sflag <= 1) \ - printf(m, (uintmax_t) igmpstat.f, plural(igmpstat.f)) -#define py64(f, m) if (igmpstat.f || sflag <= 1) \ - printf(m, (uintmax_t) igmpstat.f, pluralies(igmpstat.f)) - p64(igps_rcv_total, "\t%ju message%s received\n"); - p64(igps_rcv_tooshort, "\t%ju message%s received with too few bytes\n"); - p64(igps_rcv_badttl, "\t%ju message%s received with wrong TTL\n"); - p64(igps_rcv_badsum, "\t%ju message%s received with bad checksum\n"); - py64(igps_rcv_v1v2_queries, "\t%ju V1/V2 membership quer%s received\n"); - py64(igps_rcv_v3_queries, "\t%ju V3 membership quer%s received\n"); +#define p64(f, m) \ + if (igmpstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), igmpstat.f); \ + printf(m, buf, plural(igmpstat.f)); \ + } +#define py64(f, m) \ + if (igmpstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), igmpstat.f); \ + printf(m, buf, pluralies(igmpstat.f)); \ + } + + p64(igps_rcv_total, "\t%s message%s received\n"); + p64(igps_rcv_tooshort, "\t%s message%s received with too few bytes\n"); + p64(igps_rcv_badttl, "\t%s message%s received with wrong TTL\n"); + p64(igps_rcv_badsum, "\t%s message%s received with bad checksum\n"); + py64(igps_rcv_v1v2_queries, "\t%s V1/V2 membership quer%s received\n"); + py64(igps_rcv_v3_queries, "\t%s V3 membership quer%s received\n"); py64(igps_rcv_badqueries, - "\t%ju membership quer%s received with invalid field(s)\n"); - py64(igps_rcv_gen_queries, "\t%ju general quer%s received\n"); - py64(igps_rcv_group_queries, "\t%ju group quer%s received\n"); - py64(igps_rcv_gsr_queries, "\t%ju group-source quer%s received\n"); - py64(igps_drop_gsr_queries, "\t%ju group-source quer%s dropped\n"); - p64(igps_rcv_reports, "\t%ju membership report%s received\n"); + "\t%s membership quer%s received with invalid field(s)\n"); + py64(igps_rcv_gen_queries, "\t%s general quer%s received\n"); + py64(igps_rcv_group_queries, "\t%s group quer%s received\n"); + py64(igps_rcv_gsr_queries, "\t%s group-source quer%s received\n"); + py64(igps_drop_gsr_queries, "\t%s group-source quer%s dropped\n"); + p64(igps_rcv_reports, "\t%s membership report%s received\n"); p64(igps_rcv_badreports, - "\t%ju membership report%s received with invalid field(s)\n"); + "\t%s membership report%s received with invalid field(s)\n"); p64(igps_rcv_ourreports, -"\t%ju membership report%s received for groups to which we belong\n"); - p64(igps_rcv_nora, "\t%ju V3 report%s received without Router Alert\n"); - p64(igps_snd_reports, "\t%ju membership report%s sent\n"); +"\t%s membership report%s received for groups to which we belong\n"); + p64(igps_rcv_nora, "\t%s V3 report%s received without Router Alert\n"); + p64(igps_snd_reports, "\t%s membership report%s sent\n"); #undef p64 #undef py64 } @@ -1213,22 +1293,32 @@ pim_stats(u_long off __unused, const char *name, i printf("%s:\n", name); -#define p(f, m) if (pimstat.f || sflag <= 1) \ - printf(m, (uintmax_t)pimstat.f, plural(pimstat.f)) -#define py(f, m) if (pimstat.f || sflag <= 1) \ - printf(m, (uintmax_t)pimstat.f, pimstat.f != 1 ? "ies" : "y") - p(pims_rcv_total_msgs, "\t%ju message%s received\n"); - p(pims_rcv_total_bytes, "\t%ju byte%s received\n"); - p(pims_rcv_tooshort, "\t%ju message%s received with too few bytes\n"); - p(pims_rcv_badsum, "\t%ju message%s received with bad checksum\n"); - p(pims_rcv_badversion, "\t%ju message%s received with bad version\n"); - p(pims_rcv_registers_msgs, "\t%ju data register message%s received\n"); - p(pims_rcv_registers_bytes, "\t%ju data register byte%s received\n"); +#define p(f, m) \ + if (pimstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), pimstat.f); \ + printf(m, buf, plural(pimstat.f)); \ + } +#define py(f, m) \ + if (pimstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), pimstat.f); \ + printf(m, buf); \ + printf(m, buf, pimstat.f != 1 ? "ies" : "y"); \ + } + + p(pims_rcv_total_msgs, "\t%s message%s received\n"); + p(pims_rcv_total_bytes, "\t%s byte%s received\n"); + p(pims_rcv_tooshort, "\t%s message%s received with too few bytes\n"); + p(pims_rcv_badsum, "\t%s message%s received with bad checksum\n"); + p(pims_rcv_badversion, "\t%s message%s received with bad version\n"); + p(pims_rcv_registers_msgs, "\t%s data register message%s received\n"); + p(pims_rcv_registers_bytes, "\t%s data register byte%s received\n"); p(pims_rcv_registers_wrongiif, - "\t%ju data register message%s received on wrong iif\n"); - p(pims_rcv_badregisters, "\t%ju bad register%s received\n"); - p(pims_snd_registers_msgs, "\t%ju data register message%s sent\n"); - p(pims_snd_registers_bytes, "\t%ju data register byte%s sent\n"); + "\t%s data register message%s received on wrong iif\n"); + p(pims_rcv_badregisters, "\t%s bad register%s received\n"); + p(pims_snd_registers_msgs, "\t%s data register message%s sent\n"); + p(pims_snd_registers_bytes, "\t%s data register byte%s sent\n"); #undef p #undef py } Index: mroute6.c =================================================================== --- mroute6.c (revision 225135) +++ mroute6.c (working copy) @@ -233,26 +233,34 @@ mrt6_stats(u_long mstaddr) printf("IPv6 multicast forwarding:\n"); -#define p(f, m) if (mrtstat.f || sflag <= 1) \ - printf(m, (uintmax_t)mrtstat.f, plural(mrtstat.f)) -#define p2(f, m) if (mrtstat.f || sflag <= 1) \ - printf(m, (uintmax_t)mrtstat.f, plurales(mrtstat.f)) +#define p(f, m) \ + if (mrtstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), mrtstat.f); \ + printf(m, buf, plural(mrtstat.f)); \ + } +#define p2(f, m) \ + if (mrtstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), mrtstat.f); \ + printf(m, buf, plurales(mrtstat.f)); \ + } - p(mrt6s_mfc_lookups, "\t%ju multicast forwarding cache lookup%s\n"); - p2(mrt6s_mfc_misses, "\t%ju multicast forwarding cache miss%s\n"); - p(mrt6s_upcalls, "\t%ju upcall%s to multicast routing daemon\n"); - p(mrt6s_upq_ovflw, "\t%ju upcall queue overflow%s\n"); + p(mrt6s_mfc_lookups, "\t%s multicast forwarding cache lookup%s\n"); + p2(mrt6s_mfc_misses, "\t%s multicast forwarding cache miss%s\n"); + p(mrt6s_upcalls, "\t%s upcall%s to multicast routing daemon\n"); + p(mrt6s_upq_ovflw, "\t%s upcall queue overflow%s\n"); p(mrt6s_upq_sockfull, - "\t%ju upcall%s dropped due to full socket buffer\n"); - p(mrt6s_cache_cleanups, "\t%ju cache cleanup%s\n"); - p(mrt6s_no_route, "\t%ju datagram%s with no route for origin\n"); - p(mrt6s_bad_tunnel, "\t%ju datagram%s arrived with bad tunneling\n"); - p(mrt6s_cant_tunnel, "\t%ju datagram%s could not be tunneled\n"); - p(mrt6s_wrong_if, "\t%ju datagram%s arrived on wrong interface\n"); - p(mrt6s_drop_sel, "\t%ju datagram%s selectively dropped\n"); + "\t%s upcall%s dropped due to full socket buffer\n"); + p(mrt6s_cache_cleanups, "\t%s cache cleanup%s\n"); + p(mrt6s_no_route, "\t%s datagram%s with no route for origin\n"); + p(mrt6s_bad_tunnel, "\t%s datagram%s arrived with bad tunneling\n"); + p(mrt6s_cant_tunnel, "\t%s datagram%s could not be tunneled\n"); + p(mrt6s_wrong_if, "\t%s datagram%s arrived on wrong interface\n"); + p(mrt6s_drop_sel, "\t%s datagram%s selectively dropped\n"); p(mrt6s_q_overflow, - "\t%ju datagram%s dropped due to queue overflow\n"); - p(mrt6s_pkt2large, "\t%ju datagram%s dropped for being too large\n"); + "\t%s datagram%s dropped due to queue overflow\n"); + p(mrt6s_pkt2large, "\t%s datagram%s dropped for being too large\n"); #undef p2 #undef p Index: ipsec.c =================================================================== --- ipsec.c (revision 225135) +++ ipsec.c (working copy) @@ -206,57 +206,65 @@ ipsec_hist(const u_quad_t *hist, size_t histmax, c static void print_ipsecstats(const struct ipsecstat *ipsecstat) { -#define p(f, m) if (ipsecstat->f || sflag <= 1) \ - printf(m, (uintmax_t)ipsecstat->f, plural(ipsecstat->f)) -#define pes(f, m) if (ipsecstat->f || sflag <= 1) \ - printf(m, (uintmax_t)ipsecstat->f, plurales(ipsecstat->f)) +#define p(f, m) \ + if (ipsecstat->f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), ipsecstat->f); \ + printf(m, buf, plural(ipsecstat->f)); \ + } +#define pes(f, m) \ + if (ipsecstat->f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), ipsecstat->f); \ + printf(m, buf, plurales(ipsecstat->f)); \ + } #define hist(f, n, t) \ ipsec_hist((f), sizeof(f)/sizeof(f[0]), (n), (t)); - p(in_success, "\t%ju inbound packet%s processed successfully\n"); - p(in_polvio, "\t%ju inbound packet%s violated process security " + p(in_success, "\t%s inbound packet%s processed successfully\n"); + p(in_polvio, "\t%s inbound packet%s violated process security " "policy\n"); - p(in_nosa, "\t%ju inbound packet%s with no SA available\n"); - p(in_inval, "\t%ju invalid inbound packet%s\n"); - p(in_nomem, "\t%ju inbound packet%s failed due to insufficient memory\n"); - p(in_badspi, "\t%ju inbound packet%s failed getting SPI\n"); - p(in_ahreplay, "\t%ju inbound packet%s failed on AH replay check\n"); - p(in_espreplay, "\t%ju inbound packet%s failed on ESP replay check\n"); - p(in_ahauthsucc, "\t%ju inbound packet%s considered authentic\n"); - p(in_ahauthfail, "\t%ju inbound packet%s failed on authentication\n"); + p(in_nosa, "\t%s inbound packet%s with no SA available\n"); + p(in_inval, "\t%s invalid inbound packet%s\n"); + p(in_nomem, "\t%s inbound packet%s failed due to insufficient memory\n"); + p(in_badspi, "\t%s inbound packet%s failed getting SPI\n"); + p(in_ahreplay, "\t%s inbound packet%s failed on AH replay check\n"); + p(in_espreplay, "\t%s inbound packet%s failed on ESP replay check\n"); + p(in_ahauthsucc, "\t%s inbound packet%s considered authentic\n"); + p(in_ahauthfail, "\t%s inbound packet%s failed on authentication\n"); hist(ipsecstat->in_ahhist, ipsec_ahnames, "AH input"); hist(ipsecstat->in_esphist, ipsec_espnames, "ESP input"); hist(ipsecstat->in_comphist, ipsec_compnames, "IPComp input"); - p(out_success, "\t%ju outbound packet%s processed successfully\n"); - p(out_polvio, "\t%ju outbound packet%s violated process security " + p(out_success, "\t%s outbound packet%s processed successfully\n"); + p(out_polvio, "\t%s outbound packet%s violated process security " "policy\n"); - p(out_nosa, "\t%ju outbound packet%s with no SA available\n"); - p(out_inval, "\t%ju invalid outbound packet%s\n"); - p(out_nomem, "\t%ju outbound packet%s failed due to insufficient memory\n"); - p(out_noroute, "\t%ju outbound packet%s with no route\n"); + p(out_nosa, "\t%s outbound packet%s with no SA available\n"); + p(out_inval, "\t%s invalid outbound packet%s\n"); + p(out_nomem, "\t%s outbound packet%s failed due to insufficient memory\n"); + p(out_noroute, "\t%s outbound packet%s with no route\n"); hist(ipsecstat->out_ahhist, ipsec_ahnames, "AH output"); hist(ipsecstat->out_esphist, ipsec_espnames, "ESP output"); hist(ipsecstat->out_comphist, ipsec_compnames, "IPComp output"); - p(spdcachelookup, "\t%ju SPD cache lookup%s\n"); - pes(spdcachemiss, "\t%ju SPD cache miss%s\n"); + p(spdcachelookup, "\t%s SPD cache lookup%s\n"); + pes(spdcachemiss, "\t%s SPD cache miss%s\n"); #undef pes #undef hist - p(ips_in_polvio, "\t%ju inbound packet%s violated process " + p(ips_in_polvio, "\t%s inbound packet%s violated process " "security policy\n"); - p(ips_out_polvio, "\t%ju outbound packet%s violated process " + p(ips_out_polvio, "\t%s outbound packet%s violated process " "security policy\n"); - p(ips_out_nosa, "\t%ju outbound packet%s with no SA available\n"); - p(ips_out_nomem, "\t%ju outbound packet%s failed due to " + p(ips_out_nosa, "\t%s outbound packet%s with no SA available\n"); + p(ips_out_nomem, "\t%s outbound packet%s failed due to " "insufficient memory\n"); - p(ips_out_noroute, "\t%ju outbound packet%s with no route " + p(ips_out_noroute, "\t%s outbound packet%s with no route " "available\n"); - p(ips_out_inval, "\t%ju invalid outbound packet%s\n"); - p(ips_out_bundlesa, "\t%ju outbound packet%s with bundled SAs\n"); - p(ips_mbcoalesced, "\t%ju mbuf%s coalesced during clone\n"); - p(ips_clcoalesced, "\t%ju cluster%s coalesced during clone\n"); - p(ips_clcopied, "\t%ju cluster%s copied during clone\n"); - p(ips_mbinserted, "\t%ju mbuf%s inserted during makespace\n"); + p(ips_out_inval, "\t%s invalid outbound packet%s\n"); + p(ips_out_bundlesa, "\t%s outbound packet%s with bundled SAs\n"); + p(ips_mbcoalesced, "\t%s mbuf%s coalesced during clone\n"); + p(ips_clcoalesced, "\t%s cluster%s coalesced during clone\n"); + p(ips_clcopied, "\t%s cluster%s copied during clone\n"); + p(ips_mbinserted, "\t%s mbuf%s inserted during makespace\n"); #undef p } @@ -315,36 +323,37 @@ ipsec_hist_new(const u_int32_t *hist, size_t histm static void print_ahstats(const struct ahstat *ahstat) { -#define p32(f, m) if (ahstat->f || sflag <= 1) \ - printf("\t%u" m, (unsigned int)ahstat->f, plural(ahstat->f)) -#define p64(f, m) if (ahstat->f || sflag <= 1) \ - printf("\t%ju" m, (uintmax_t)ahstat->f, plural(ahstat->f)) +#define p(f, m) \ + if (ahstat->f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), ahstat->f); \ + printf("\t%s" m, buf, plural(ahstat->f)); \ + } #define hist(f, n, t) \ ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t)); - p32(ahs_hdrops, " packet%s shorter than header shows\n"); - p32(ahs_nopf, " packet%s dropped; protocol family not supported\n"); - p32(ahs_notdb, " packet%s dropped; no TDB\n"); - p32(ahs_badkcr, " packet%s dropped; bad KCR\n"); - p32(ahs_qfull, " packet%s dropped; queue full\n"); - p32(ahs_noxform, " packet%s dropped; no transform\n"); - p32(ahs_wrap, " replay counter wrap%s\n"); - p32(ahs_badauth, " packet%s dropped; bad authentication detected\n"); - p32(ahs_badauthl, " packet%s dropped; bad authentication length\n"); - p32(ahs_replay, " possible replay packet%s detected\n"); - p32(ahs_input, " packet%s in\n"); - p32(ahs_output, " packet%s out\n"); - p32(ahs_invalid, " packet%s dropped; invalid TDB\n"); - p64(ahs_ibytes, " byte%s in\n"); - p64(ahs_obytes, " byte%s out\n"); - p32(ahs_toobig, " packet%s dropped; larger than IP_MAXPACKET\n"); - p32(ahs_pdrops, " packet%s blocked due to policy\n"); - p32(ahs_crypto, " crypto processing failure%s\n"); - p32(ahs_tunnel, " tunnel sanity check failure%s\n"); + p(ahs_hdrops, " packet%s shorter than header shows\n"); + p(ahs_nopf, " packet%s dropped; protocol family not supported\n"); + p(ahs_notdb, " packet%s dropped; no TDB\n"); + p(ahs_badkcr, " packet%s dropped; bad KCR\n"); + p(ahs_qfull, " packet%s dropped; queue full\n"); + p(ahs_noxform, " packet%s dropped; no transform\n"); + p(ahs_wrap, " replay counter wrap%s\n"); + p(ahs_badauth, " packet%s dropped; bad authentication detected\n"); + p(ahs_badauthl, " packet%s dropped; bad authentication length\n"); + p(ahs_replay, " possible replay packet%s detected\n"); + p(ahs_input, " packet%s in\n"); + p(ahs_output, " packet%s out\n"); + p(ahs_invalid, " packet%s dropped; invalid TDB\n"); + p(ahs_ibytes, " byte%s in\n"); + p(ahs_obytes, " byte%s out\n"); + p(ahs_toobig, " packet%s dropped; larger than IP_MAXPACKET\n"); + p(ahs_pdrops, " packet%s blocked due to policy\n"); + p(ahs_crypto, " crypto processing failure%s\n"); + p(ahs_tunnel, " tunnel sanity check failure%s\n"); hist(ahstat->ahs_hist, ipsec_ahnames, "AH output"); -#undef p32 -#undef p64 +#undef p #undef hist } @@ -364,37 +373,38 @@ ah_stats(u_long off, const char *name, int family static void print_espstats(const struct espstat *espstat) { -#define p32(f, m) if (espstat->f || sflag <= 1) \ - printf("\t%u" m, (unsigned int)espstat->f, plural(espstat->f)) -#define p64(f, m) if (espstat->f || sflag <= 1) \ - printf("\t%ju" m, (uintmax_t)espstat->f, plural(espstat->f)) +#define p(f, m) \ + if (espstat->f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), espstat->f); \ + printf("\t%s" m, buf, plural(espstat->f)); \ + } #define hist(f, n, t) \ ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t)); - p32(esps_hdrops, " packet%s shorter than header shows\n"); - p32(esps_nopf, " packet%s dropped; protocol family not supported\n"); - p32(esps_notdb, " packet%s dropped; no TDB\n"); - p32(esps_badkcr, " packet%s dropped; bad KCR\n"); - p32(esps_qfull, " packet%s dropped; queue full\n"); - p32(esps_noxform, " packet%s dropped; no transform\n"); - p32(esps_badilen, " packet%s dropped; bad ilen\n"); - p32(esps_wrap, " replay counter wrap%s\n"); - p32(esps_badenc, " packet%s dropped; bad encryption detected\n"); - p32(esps_badauth, " packet%s dropped; bad authentication detected\n"); - p32(esps_replay, " possible replay packet%s detected\n"); - p32(esps_input, " packet%s in\n"); - p32(esps_output, " packet%s out\n"); - p32(esps_invalid, " packet%s dropped; invalid TDB\n"); - p64(esps_ibytes, " byte%s in\n"); - p64(esps_obytes, " byte%s out\n"); - p32(esps_toobig, " packet%s dropped; larger than IP_MAXPACKET\n"); - p32(esps_pdrops, " packet%s blocked due to policy\n"); - p32(esps_crypto, " crypto processing failure%s\n"); - p32(esps_tunnel, " tunnel sanity check failure%s\n"); + p(esps_hdrops, " packet%s shorter than header shows\n"); + p(esps_nopf, " packet%s dropped; protocol family not supported\n"); + p(esps_notdb, " packet%s dropped; no TDB\n"); + p(esps_badkcr, " packet%s dropped; bad KCR\n"); + p(esps_qfull, " packet%s dropped; queue full\n"); + p(esps_noxform, " packet%s dropped; no transform\n"); + p(esps_badilen, " packet%s dropped; bad ilen\n"); + p(esps_wrap, " replay counter wrap%s\n"); + p(esps_badenc, " packet%s dropped; bad encryption detected\n"); + p(esps_badauth, " packet%s dropped; bad authentication detected\n"); + p(esps_replay, " possible replay packet%s detected\n"); + p(esps_input, " packet%s in\n"); + p(esps_output, " packet%s out\n"); + p(esps_invalid, " packet%s dropped; invalid TDB\n"); + p(esps_ibytes, " byte%s in\n"); + p(esps_obytes, " byte%s out\n"); + p(esps_toobig, " packet%s dropped; larger than IP_MAXPACKET\n"); + p(esps_pdrops, " packet%s blocked due to policy\n"); + p(esps_crypto, " crypto processing failure%s\n"); + p(esps_tunnel, " tunnel sanity check failure%s\n"); hist(espstat->esps_hist, ipsec_espnames, "ESP output"); -#undef p32 -#undef p64 +#undef p #undef hist } @@ -415,10 +425,12 @@ static void print_ipcompstats(const struct ipcompstat *ipcompstat) { uint32_t version; -#define p32(f, m) if (ipcompstat->f || sflag <= 1) \ - printf("\t%u" m, (unsigned int)ipcompstat->f, plural(ipcompstat->f)) -#define p64(f, m) if (ipcompstat->f || sflag <= 1) \ - printf("\t%ju" m, (uintmax_t)ipcompstat->f, plural(ipcompstat->f)) +#define p(f, m) \ + if (ipcompstat->f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), ipcompstat->f); \ + printf("\t%s" m, buf, plural(ipcompstat->f)); \ + } #define hist(f, n, t) \ ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t)); @@ -427,29 +439,28 @@ print_ipcompstats(const struct ipcompstat *ipcomps #else version = ipcompstat->version; #endif - p32(ipcomps_hdrops, " packet%s shorter than header shows\n"); - p32(ipcomps_nopf, " packet%s dropped; protocol family not supported\n"); - p32(ipcomps_notdb, " packet%s dropped; no TDB\n"); - p32(ipcomps_badkcr, " packet%s dropped; bad KCR\n"); - p32(ipcomps_qfull, " packet%s dropped; queue full\n"); - p32(ipcomps_noxform, " packet%s dropped; no transform\n"); - p32(ipcomps_wrap, " replay counter wrap%s\n"); - p32(ipcomps_input, " packet%s in\n"); - p32(ipcomps_output, " packet%s out\n"); - p32(ipcomps_invalid, " packet%s dropped; invalid TDB\n"); - p64(ipcomps_ibytes, " byte%s in\n"); - p64(ipcomps_obytes, " byte%s out\n"); - p32(ipcomps_toobig, " packet%s dropped; larger than IP_MAXPACKET\n"); - p32(ipcomps_pdrops, " packet%s blocked due to policy\n"); - p32(ipcomps_crypto, " crypto processing failure%s\n"); + p(ipcomps_hdrops, " packet%s shorter than header shows\n"); + p(ipcomps_nopf, " packet%s dropped; protocol family not supported\n"); + p(ipcomps_notdb, " packet%s dropped; no TDB\n"); + p(ipcomps_badkcr, " packet%s dropped; bad KCR\n"); + p(ipcomps_qfull, " packet%s dropped; queue full\n"); + p(ipcomps_noxform, " packet%s dropped; no transform\n"); + p(ipcomps_wrap, " replay counter wrap%s\n"); + p(ipcomps_input, " packet%s in\n"); + p(ipcomps_output, " packet%s out\n"); + p(ipcomps_invalid, " packet%s dropped; invalid TDB\n"); + p(ipcomps_ibytes, " byte%s in\n"); + p(ipcomps_obytes, " byte%s out\n"); + p(ipcomps_toobig, " packet%s dropped; larger than IP_MAXPACKET\n"); + p(ipcomps_pdrops, " packet%s blocked due to policy\n"); + p(ipcomps_crypto, " crypto processing failure%s\n"); hist(ipcompstat->ipcomps_hist, ipsec_compnames, "COMP output"); if (version >= 1) { - p32(ipcomps_threshold, " packet%s sent uncompressed; size < compr. algo. threshold\n"); - p32(ipcomps_uncompr, " packet%s sent uncompressed; compression was useless\n"); + p(ipcomps_threshold, " packet%s sent uncompressed; size < compr. algo. threshold\n"); + p(ipcomps_uncompr, " packet%s sent uncompressed; compression was useless\n"); } -#undef p32 -#undef p64 +#undef p #undef hist } Index: sctp.c =================================================================== --- sctp.c (revision 225135) +++ sctp.c (working copy) @@ -619,159 +619,167 @@ sctp_stats(u_long off, const char *name, int af1 _ printf ("%s:\n", name); -#define p(f, m) if (sctpstat.f || sflag <= 1) \ - printf(m, (uintmax_t)sctpstat.f, plural(sctpstat.f)) -#define p1a(f, m) if (sctpstat.f || sflag <= 1) \ - printf(m, (uintmax_t)sctpstat.f) +#define p(f, m) \ + if (sctpstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), sctpstat.f); \ + printf(m, buf, plural(sctpstat.f)); \ + } +#define p1a(f, m) \ + if (sctpstat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), sctpstat.f); \ + printf(m, buf); \ + } /* * input statistics */ - p(sctps_recvpackets, "\t%ju input packet%s\n"); - p(sctps_recvdatagrams, "\t\t%ju datagram%s\n"); - p(sctps_recvpktwithdata, "\t\t%ju packet%s that had data\n"); - p(sctps_recvsacks, "\t\t%ju input SACK chunk%s\n"); - p(sctps_recvdata, "\t\t%ju input DATA chunk%s\n"); - p(sctps_recvdupdata, "\t\t%ju duplicate DATA chunk%s\n"); - p(sctps_recvheartbeat, "\t\t%ju input HB chunk%s\n"); - p(sctps_recvheartbeatack, "\t\t%ju HB-ACK chunk%s\n"); - p(sctps_recvecne, "\t\t%ju input ECNE chunk%s\n"); - p(sctps_recvauth, "\t\t%ju input AUTH chunk%s\n"); - p(sctps_recvauthmissing, "\t\t%ju chunk%s missing AUTH\n"); - p(sctps_recvivalhmacid, "\t\t%ju invalid HMAC id%s received\n"); - p(sctps_recvivalkeyid, "\t\t%ju invalid secret id%s received\n"); - p1a(sctps_recvauthfailed, "\t\t%ju auth failed\n"); - p1a(sctps_recvexpress, "\t\t%ju fast path receives all one chunk\n"); - p1a(sctps_recvexpressm, "\t\t%ju fast path multi-part data\n"); + p(sctps_recvpackets, "\t%s input packet%s\n"); + p(sctps_recvdatagrams, "\t\t%s datagram%s\n"); + p(sctps_recvpktwithdata, "\t\t%s packet%s that had data\n"); + p(sctps_recvsacks, "\t\t%s input SACK chunk%s\n"); + p(sctps_recvdata, "\t\t%s input DATA chunk%s\n"); + p(sctps_recvdupdata, "\t\t%s duplicate DATA chunk%s\n"); + p(sctps_recvheartbeat, "\t\t%s input HB chunk%s\n"); + p(sctps_recvheartbeatack, "\t\t%s HB-ACK chunk%s\n"); + p(sctps_recvecne, "\t\t%s input ECNE chunk%s\n"); + p(sctps_recvauth, "\t\t%s input AUTH chunk%s\n"); + p(sctps_recvauthmissing, "\t\t%s chunk%s missing AUTH\n"); + p(sctps_recvivalhmacid, "\t\t%s invalid HMAC id%s received\n"); + p(sctps_recvivalkeyid, "\t\t%s invalid secret id%s received\n"); + p1a(sctps_recvauthfailed, "\t\t%s auth failed\n"); + p1a(sctps_recvexpress, "\t\t%s fast path receives all one chunk\n"); + p1a(sctps_recvexpressm, "\t\t%s fast path multi-part data\n"); /* * output statistics */ - p(sctps_sendpackets, "\t%ju output packet%s\n"); - p(sctps_sendsacks, "\t\t%ju output SACK%s\n"); - p(sctps_senddata, "\t\t%ju output DATA chunk%s\n"); - p(sctps_sendretransdata, "\t\t%ju retransmitted DATA chunk%s\n"); - p(sctps_sendfastretrans, "\t\t%ju fast retransmitted DATA chunk%s\n"); - p(sctps_sendmultfastretrans, "\t\t%ju FR'%s that happened more " + p(sctps_sendpackets, "\t%s output packet%s\n"); + p(sctps_sendsacks, "\t\t%s output SACK%s\n"); + p(sctps_senddata, "\t\t%s output DATA chunk%s\n"); + p(sctps_sendretransdata, "\t\t%s retransmitted DATA chunk%s\n"); + p(sctps_sendfastretrans, "\t\t%s fast retransmitted DATA chunk%s\n"); + p(sctps_sendmultfastretrans, "\t\t%s FR'%s that happened more " "than once to same chunk\n"); - p(sctps_sendheartbeat, "\t\t%ju output HB chunk%s\n"); - p(sctps_sendecne, "\t\t%ju output ECNE chunk%s\n"); - p(sctps_sendauth, "\t\t%ju output AUTH chunk%s\n"); - p1a(sctps_senderrors, "\t\t%ju ip_output error counter\n"); + p(sctps_sendheartbeat, "\t\t%s output HB chunk%s\n"); + p(sctps_sendecne, "\t\t%s output ECNE chunk%s\n"); + p(sctps_sendauth, "\t\t%s output AUTH chunk%s\n"); + p1a(sctps_senderrors, "\t\t%s ip_output error counter\n"); /* * PCKDROPREP statistics */ printf("\tPacket drop statistics:\n"); - p1a(sctps_pdrpfmbox, "\t\t%ju from middle box\n"); - p1a(sctps_pdrpfehos, "\t\t%ju from end host\n"); - p1a(sctps_pdrpmbda, "\t\t%ju with data\n"); - p1a(sctps_pdrpmbct, "\t\t%ju non-data, non-endhost\n"); - p1a(sctps_pdrpbwrpt, "\t\t%ju non-endhost, bandwidth rep only\n"); - p1a(sctps_pdrpcrupt, "\t\t%ju not enough for chunk header\n"); - p1a(sctps_pdrpnedat, "\t\t%ju not enough data to confirm\n"); - p1a(sctps_pdrppdbrk, "\t\t%ju where process_chunk_drop said break\n"); - p1a(sctps_pdrptsnnf, "\t\t%ju failed to find TSN\n"); - p1a(sctps_pdrpdnfnd, "\t\t%ju attempt reverse TSN lookup\n"); - p1a(sctps_pdrpdiwnp, "\t\t%ju e-host confirms zero-rwnd\n"); - p1a(sctps_pdrpdizrw, "\t\t%ju midbox confirms no space\n"); - p1a(sctps_pdrpbadd, "\t\t%ju data did not match TSN\n"); - p(sctps_pdrpmark, "\t\t%ju TSN'%s marked for Fast Retran\n"); + p1a(sctps_pdrpfmbox, "\t\t%s from middle box\n"); + p1a(sctps_pdrpfehos, "\t\t%s from end host\n"); + p1a(sctps_pdrpmbda, "\t\t%s with data\n"); + p1a(sctps_pdrpmbct, "\t\t%s non-data, non-endhost\n"); + p1a(sctps_pdrpbwrpt, "\t\t%s non-endhost, bandwidth rep only\n"); + p1a(sctps_pdrpcrupt, "\t\t%s not enough for chunk header\n"); + p1a(sctps_pdrpnedat, "\t\t%s not enough data to confirm\n"); + p1a(sctps_pdrppdbrk, "\t\t%s where process_chunk_drop said break\n"); + p1a(sctps_pdrptsnnf, "\t\t%s failed to find TSN\n"); + p1a(sctps_pdrpdnfnd, "\t\t%s attempt reverse TSN lookup\n"); + p1a(sctps_pdrpdiwnp, "\t\t%s e-host confirms zero-rwnd\n"); + p1a(sctps_pdrpdizrw, "\t\t%s midbox confirms no space\n"); + p1a(sctps_pdrpbadd, "\t\t%s data did not match TSN\n"); + p(sctps_pdrpmark, "\t\t%s TSN'%s marked for Fast Retran\n"); /* * Timeouts */ printf("\tTimeouts:\n"); - p(sctps_timoiterator, "\t\t%ju iterator timer%s fired\n"); - p(sctps_timodata, "\t\t%ju T3 data time out%s\n"); - p(sctps_timowindowprobe, "\t\t%ju window probe (T3) timer%s fired\n"); - p(sctps_timoinit, "\t\t%ju INIT timer%s fired\n"); - p(sctps_timosack, "\t\t%ju sack timer%s fired\n"); - p(sctps_timoshutdown, "\t\t%ju shutdown timer%s fired\n"); - p(sctps_timoheartbeat, "\t\t%ju heartbeat timer%s fired\n"); - p1a(sctps_timocookie, "\t\t%ju a cookie timeout fired\n"); - p1a(sctps_timosecret, "\t\t%ju an endpoint changed its cookie" + p(sctps_timoiterator, "\t\t%s iterator timer%s fired\n"); + p(sctps_timodata, "\t\t%s T3 data time out%s\n"); + p(sctps_timowindowprobe, "\t\t%s window probe (T3) timer%s fired\n"); + p(sctps_timoinit, "\t\t%s INIT timer%s fired\n"); + p(sctps_timosack, "\t\t%s sack timer%s fired\n"); + p(sctps_timoshutdown, "\t\t%s shutdown timer%s fired\n"); + p(sctps_timoheartbeat, "\t\t%s heartbeat timer%s fired\n"); + p1a(sctps_timocookie, "\t\t%s a cookie timeout fired\n"); + p1a(sctps_timosecret, "\t\t%s an endpoint changed its cookie" "secret\n"); - p(sctps_timopathmtu, "\t\t%ju PMTU timer%s fired\n"); - p(sctps_timoshutdownack, "\t\t%ju shutdown ack timer%s fired\n"); - p(sctps_timoshutdownguard, "\t\t%ju shutdown guard timer%s fired\n"); - p(sctps_timostrmrst, "\t\t%ju stream reset timer%s fired\n"); - p(sctps_timoearlyfr, "\t\t%ju early FR timer%s fired\n"); - p1a(sctps_timoasconf, "\t\t%ju an asconf timer fired\n"); - p1a(sctps_timoautoclose, "\t\t%ju auto close timer fired\n"); - p(sctps_timoassockill, "\t\t%ju asoc free timer%s expired\n"); - p(sctps_timoinpkill, "\t\t%ju inp free timer%s expired\n"); + p(sctps_timopathmtu, "\t\t%s PMTU timer%s fired\n"); + p(sctps_timoshutdownack, "\t\t%s shutdown ack timer%s fired\n"); + p(sctps_timoshutdownguard, "\t\t%s shutdown guard timer%s fired\n"); + p(sctps_timostrmrst, "\t\t%s stream reset timer%s fired\n"); + p(sctps_timoearlyfr, "\t\t%s early FR timer%s fired\n"); + p1a(sctps_timoasconf, "\t\t%s an asconf timer fired\n"); + p1a(sctps_timoautoclose, "\t\t%s auto close timer fired\n"); + p(sctps_timoassockill, "\t\t%s asoc free timer%s expired\n"); + p(sctps_timoinpkill, "\t\t%s inp free timer%s expired\n"); #if 0 /* * Early fast retransmission counters */ - p(sctps_earlyfrstart, "\t%ju TODO:sctps_earlyfrstart\n"); - p(sctps_earlyfrstop, "\t%ju TODO:sctps_earlyfrstop\n"); - p(sctps_earlyfrmrkretrans, "\t%ju TODO:sctps_earlyfrmrkretrans\n"); - p(sctps_earlyfrstpout, "\t%ju TODO:sctps_earlyfrstpout\n"); - p(sctps_earlyfrstpidsck1, "\t%ju TODO:sctps_earlyfrstpidsck1\n"); - p(sctps_earlyfrstpidsck2, "\t%ju TODO:sctps_earlyfrstpidsck2\n"); - p(sctps_earlyfrstpidsck3, "\t%ju TODO:sctps_earlyfrstpidsck3\n"); - p(sctps_earlyfrstpidsck4, "\t%ju TODO:sctps_earlyfrstpidsck4\n"); - p(sctps_earlyfrstrid, "\t%ju TODO:sctps_earlyfrstrid\n"); - p(sctps_earlyfrstrout, "\t%ju TODO:sctps_earlyfrstrout\n"); - p(sctps_earlyfrstrtmr, "\t%ju TODO:sctps_earlyfrstrtmr\n"); + p(sctps_earlyfrstart, "\t%s TODO:sctps_earlyfrstart\n"); + p(sctps_earlyfrstop, "\t%s TODO:sctps_earlyfrstop\n"); + p(sctps_earlyfrmrkretrans, "\t%s TODO:sctps_earlyfrmrkretrans\n"); + p(sctps_earlyfrstpout, "\t%s TODO:sctps_earlyfrstpout\n"); + p(sctps_earlyfrstpidsck1, "\t%s TODO:sctps_earlyfrstpidsck1\n"); + p(sctps_earlyfrstpidsck2, "\t%s TODO:sctps_earlyfrstpidsck2\n"); + p(sctps_earlyfrstpidsck3, "\t%s TODO:sctps_earlyfrstpidsck3\n"); + p(sctps_earlyfrstpidsck4, "\t%s TODO:sctps_earlyfrstpidsck4\n"); + p(sctps_earlyfrstrid, "\t%s TODO:sctps_earlyfrstrid\n"); + p(sctps_earlyfrstrout, "\t%s TODO:sctps_earlyfrstrout\n"); + p(sctps_earlyfrstrtmr, "\t%s TODO:sctps_earlyfrstrtmr\n"); #endif /* * Others */ - p1a(sctps_hdrops, "\t%ju packet shorter than header\n"); - p1a(sctps_badsum, "\t%ju checksum error\n"); - p1a(sctps_noport, "\t%ju no endpoint for port\n"); - p1a(sctps_badvtag, "\t%ju bad v-tag\n"); - p1a(sctps_badsid, "\t%ju bad SID\n"); - p1a(sctps_nomem, "\t%ju no memory\n"); - p1a(sctps_fastretransinrtt, "\t%ju number of multiple FR in a RTT " + p1a(sctps_hdrops, "\t%s packet shorter than header\n"); + p1a(sctps_badsum, "\t%s checksum error\n"); + p1a(sctps_noport, "\t%s no endpoint for port\n"); + p1a(sctps_badvtag, "\t%s bad v-tag\n"); + p1a(sctps_badsid, "\t%s bad SID\n"); + p1a(sctps_nomem, "\t%s no memory\n"); + p1a(sctps_fastretransinrtt, "\t%s number of multiple FR in a RTT " "window\n"); #if 0 - p(sctps_markedretrans, "\t%ju TODO:sctps_markedretrans\n"); + p(sctps_markedretrans, "\t%s TODO:sctps_markedretrans\n"); #endif - p1a(sctps_naglesent, "\t%ju RFC813 allowed sending\n"); - p1a(sctps_naglequeued, "\t%ju RFC813 does not allow sending\n"); - p1a(sctps_maxburstqueued, "\t%ju times max burst prohibited sending\n"); - p1a(sctps_ifnomemqueued, "\t%ju look ahead tells us no memory in " + p1a(sctps_naglesent, "\t%s RFC813 allowed sending\n"); + p1a(sctps_naglequeued, "\t%s RFC813 does not allow sending\n"); + p1a(sctps_maxburstqueued, "\t%s times max burst prohibited sending\n"); + p1a(sctps_ifnomemqueued, "\t%s look ahead tells us no memory in " "interface\n"); - p(sctps_windowprobed, "\t%ju number%s of window probes sent\n"); - p(sctps_lowlevelerr, "\t%ju time%s an output error to clamp " + p(sctps_windowprobed, "\t%s number%s of window probes sent\n"); + p(sctps_lowlevelerr, "\t%s time%s an output error to clamp " "down on next user send\n"); - p(sctps_lowlevelerrusr, "\t%ju time%s sctp_senderrors were " + p(sctps_lowlevelerrusr, "\t%s time%s sctp_senderrors were " "caused from a user\n"); - p(sctps_datadropchklmt, "\t%ju number of in data drop%s due to " + p(sctps_datadropchklmt, "\t%s number of in data drop%s due to " "chunk limit reached\n"); - p(sctps_datadroprwnd, "\t%ju number of in data drop%s due to rwnd " + p(sctps_datadroprwnd, "\t%s number of in data drop%s due to rwnd " "limit reached\n"); - p(sctps_ecnereducedcwnd, "\t%ju time%s a ECN reduced " + p(sctps_ecnereducedcwnd, "\t%s time%s a ECN reduced " "the cwnd\n"); - p1a(sctps_vtagexpress, "\t%ju used express lookup via vtag\n"); - p1a(sctps_vtagbogus, "\t%ju collision in express lookup\n"); - p(sctps_primary_randry, "\t%ju time%s the sender ran dry " + p1a(sctps_vtagexpress, "\t%s used express lookup via vtag\n"); + p1a(sctps_vtagbogus, "\t%s collision in express lookup\n"); + p(sctps_primary_randry, "\t%s time%s the sender ran dry " "of user data on primary\n"); - p1a(sctps_cmt_randry, "\t%ju same for above\n"); - p(sctps_slowpath_sack, "\t%ju sack%s the slow way\n"); - p(sctps_wu_sacks_sent, "\t%ju window update only sack%s sent\n"); - p(sctps_sends_with_flags, "\t%ju send%s with sinfo_flags !=0\n"); - p(sctps_sends_with_unord, "\t%ju unordered send%s\n"); - p(sctps_sends_with_eof, "\t%ju send%s with EOF flag set\n"); - p(sctps_sends_with_abort, "\t%ju send%s with ABORT flag set\n"); - p(sctps_protocol_drain_calls, "\t%ju time%s protocol drain called\n"); - p(sctps_protocol_drains_done, "\t%ju time%s we did a protocol " + p1a(sctps_cmt_randry, "\t%s same for above\n"); + p(sctps_slowpath_sack, "\t%s sack%s the slow way\n"); + p(sctps_wu_sacks_sent, "\t%s window update only sack%s sent\n"); + p(sctps_sends_with_flags, "\t%s send%s with sinfo_flags !=0\n"); + p(sctps_sends_with_unord, "\t%s unordered send%s\n"); + p(sctps_sends_with_eof, "\t%s send%s with EOF flag set\n"); + p(sctps_sends_with_abort, "\t%s send%s with ABORT flag set\n"); + p(sctps_protocol_drain_calls, "\t%s time%s protocol drain called\n"); + p(sctps_protocol_drains_done, "\t%s time%s we did a protocol " "drain\n"); - p(sctps_read_peeks, "\t%ju time%s recv was called with peek\n"); - p(sctps_cached_chk, "\t%ju cached chunk%s used\n"); - p1a(sctps_cached_strmoq, "\t%ju cached stream oq's used\n"); - p(sctps_left_abandon, "\t%ju unread message%s abandonded by close\n"); - p1a(sctps_send_burst_avoid, "\t%ju send burst avoidance, already " + p(sctps_read_peeks, "\t%s time%s recv was called with peek\n"); + p(sctps_cached_chk, "\t%s cached chunk%s used\n"); + p1a(sctps_cached_strmoq, "\t%s cached stream oq's used\n"); + p(sctps_left_abandon, "\t%s unread message%s abandonded by close\n"); + p1a(sctps_send_burst_avoid, "\t%s send burst avoidance, already " "max burst inflight to net\n"); - p1a(sctps_send_cwnd_avoid, "\t%ju send cwnd full avoidance, already " + p1a(sctps_send_cwnd_avoid, "\t%s send cwnd full avoidance, already " "max burst inflight to net\n"); - p(sctps_fwdtsn_map_over, "\t%ju number of map array over-run%s via " + p(sctps_fwdtsn_map_over, "\t%s number of map array over-run%s via " "fwd-tsn's\n"); #undef p Index: pfkey.c =================================================================== --- pfkey.c (revision 225135) +++ pfkey.c (working copy) @@ -121,12 +121,16 @@ pfkey_stats(u_long off, const char *name, int fami printf ("%s:\n", name); kread(off, (char *)&pfkeystat, sizeof(pfkeystat)); -#define p(f, m) if (pfkeystat.f || sflag <= 1) \ - printf(m, (uintmax_t)pfkeystat.f, plural(pfkeystat.f)) +#define p(f, m) \ + if (pfkeystat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), pfkeystat.f); \ + printf(m, buf, plural(pfkeystat.f)); \ + } /* userland -> kernel */ - p(out_total, "\t%ju request%s sent from userland\n"); - p(out_bytes, "\t%ju byte%s sent from userland\n"); + p(out_total, "\t%s request%s sent from userland\n"); + p(out_bytes, "\t%s byte%s sent from userland\n"); for (first = 1, type = 0; type < sizeof(pfkeystat.out_msgtype)/sizeof(pfkeystat.out_msgtype[0]); type++) { @@ -139,19 +143,19 @@ pfkey_stats(u_long off, const char *name, int fami printf("\t\t%s: %ju\n", pfkey_msgtype_names(type), (uintmax_t)pfkeystat.out_msgtype[type]); } - p(out_invlen, "\t%ju message%s with invalid length field\n"); - p(out_invver, "\t%ju message%s with invalid version field\n"); - p(out_invmsgtype, "\t%ju message%s with invalid message type field\n"); - p(out_tooshort, "\t%ju message%s too short\n"); - p(out_nomem, "\t%ju message%s with memory allocation failure\n"); - p(out_dupext, "\t%ju message%s with duplicate extension\n"); - p(out_invexttype, "\t%ju message%s with invalid extension type\n"); - p(out_invsatype, "\t%ju message%s with invalid sa type\n"); - p(out_invaddr, "\t%ju message%s with invalid address extension\n"); + p(out_invlen, "\t%s message%s with invalid length field\n"); + p(out_invver, "\t%s message%s with invalid version field\n"); + p(out_invmsgtype, "\t%s message%s with invalid message type field\n"); + p(out_tooshort, "\t%s message%s too short\n"); + p(out_nomem, "\t%s message%s with memory allocation failure\n"); + p(out_dupext, "\t%s message%s with duplicate extension\n"); + p(out_invexttype, "\t%s message%s with invalid extension type\n"); + p(out_invsatype, "\t%s message%s with invalid sa type\n"); + p(out_invaddr, "\t%s message%s with invalid address extension\n"); /* kernel -> userland */ - p(in_total, "\t%ju request%s sent to userland\n"); - p(in_bytes, "\t%ju byte%s sent to userland\n"); + p(in_total, "\t%s request%s sent to userland\n"); + p(in_bytes, "\t%s byte%s sent to userland\n"); for (first = 1, type = 0; type < sizeof(pfkeystat.in_msgtype)/sizeof(pfkeystat.in_msgtype[0]); type++) { @@ -165,12 +169,12 @@ pfkey_stats(u_long off, const char *name, int fami (uintmax_t)pfkeystat.in_msgtype[type]); } p(in_msgtarget[KEY_SENDUP_ONE], - "\t%ju message%s toward single socket\n"); + "\t%s message%s toward single socket\n"); p(in_msgtarget[KEY_SENDUP_ALL], - "\t%ju message%s toward all sockets\n"); + "\t%s message%s toward all sockets\n"); p(in_msgtarget[KEY_SENDUP_REGISTERED], - "\t%ju message%s toward registered sockets\n"); - p(in_nomem, "\t%ju message%s with memory allocation failure\n"); + "\t%s message%s toward registered sockets\n"); + p(in_nomem, "\t%s message%s with memory allocation failure\n"); #undef p } #endif /* IPSEC */ Index: main.c =================================================================== --- main.c (revision 225135) +++ main.c (working copy) @@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -756,6 +757,17 @@ pluralies(uintmax_t n) return (n != 1 ? "ies" : "y"); } +void +humanized(char *buf, size_t buflen, int64_t val) +{ + + if (hflag) + humanize_number(buf, 5, val, "", + HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL); + else + snprintf(buf, sizeof(buf), "%ld", val); +} + /* * Find the protox for the given "well-known" name. */ Index: inet6.c =================================================================== --- inet6.c (revision 225135) +++ inet6.c (working copy) @@ -363,6 +363,7 @@ ip6_stats(u_long off, const char *name, int af1 __ struct ip6stat ip6stat; int first, i; size_t len; + char buf[15]; /* XXX */ len = sizeof ip6stat; if (live) { @@ -378,42 +379,48 @@ ip6_stats(u_long off, const char *name, int af1 __ printf("%s:\n", name); -#define p(f, m) if (ip6stat.f || sflag <= 1) \ - printf(m, (uintmax_t)ip6stat.f, plural(ip6stat.f)) -#define p1a(f, m) if (ip6stat.f || sflag <= 1) \ - printf(m, (uintmax_t)ip6stat.f) +#define p(f, m) \ + if (ip6stat.f || sflag <= 1) { \ + humanized(buf, sizeof(buf), ip6stat.f); \ + printf(m, buf, plural(ip6stat.f)); \ + } +#define p1a(f, m) \ + if (ip6stat.f || sflag <= 1) { \ + humanized(buf, sizeof(buf), ip6stat.f); \ + printf(m, buf); \ + } - p(ip6s_total, "\t%ju total packet%s received\n"); - p1a(ip6s_toosmall, "\t%ju with size smaller than minimum\n"); - p1a(ip6s_tooshort, "\t%ju with data size < data length\n"); - p1a(ip6s_badoptions, "\t%ju with bad options\n"); - p1a(ip6s_badvers, "\t%ju with incorrect version number\n"); - p(ip6s_fragments, "\t%ju fragment%s received\n"); - p(ip6s_fragdropped, "\t%ju fragment%s dropped (dup or out of space)\n"); - p(ip6s_fragtimeout, "\t%ju fragment%s dropped after timeout\n"); - p(ip6s_fragoverflow, "\t%ju fragment%s that exceeded limit\n"); - p(ip6s_reassembled, "\t%ju packet%s reassembled ok\n"); - p(ip6s_delivered, "\t%ju packet%s for this host\n"); - p(ip6s_forward, "\t%ju packet%s forwarded\n"); - p(ip6s_cantforward, "\t%ju packet%s not forwardable\n"); - p(ip6s_redirectsent, "\t%ju redirect%s sent\n"); - p(ip6s_localout, "\t%ju packet%s sent from this host\n"); - p(ip6s_rawout, "\t%ju packet%s sent with fabricated ip header\n"); - p(ip6s_odropped, "\t%ju output packet%s dropped due to no bufs, etc.\n"); - p(ip6s_noroute, "\t%ju output packet%s discarded due to no route\n"); - p(ip6s_fragmented, "\t%ju output datagram%s fragmented\n"); - p(ip6s_ofragments, "\t%ju fragment%s created\n"); - p(ip6s_cantfrag, "\t%ju datagram%s that can't be fragmented\n"); - p(ip6s_badscope, "\t%ju packet%s that violated scope rules\n"); - p(ip6s_notmember, "\t%ju multicast packet%s which we don't join\n"); + p(ip6s_total, "\t%s total packet%s received\n"); + p1a(ip6s_toosmall, "\t%s with size smaller than minimum\n"); + p1a(ip6s_tooshort, "\t%s with data size < data length\n"); + p1a(ip6s_badoptions, "\t%s with bad options\n"); + p1a(ip6s_badvers, "\t%s with incorrect version number\n"); + p(ip6s_fragments, "\t%s fragment%s received\n"); + p(ip6s_fragdropped, "\t%s fragment%s dropped (dup or out of space)\n"); + p(ip6s_fragtimeout, "\t%s fragment%s dropped after timeout\n"); + p(ip6s_fragoverflow, "\t%s fragment%s that exceeded limit\n"); + p(ip6s_reassembled, "\t%s packet%s reassembled ok\n"); + p(ip6s_delivered, "\t%s packet%s for this host\n"); + p(ip6s_forward, "\t%s packet%s forwarded\n"); + p(ip6s_cantforward, "\t%s packet%s not forwardable\n"); + p(ip6s_redirectsent, "\t%s redirect%s sent\n"); + p(ip6s_localout, "\t%s packet%s sent from this host\n"); + p(ip6s_rawout, "\t%s packet%s sent with fabricated ip header\n"); + p(ip6s_odropped, "\t%s output packet%s dropped due to no bufs, etc.\n"); + p(ip6s_noroute, "\t%s output packet%s discarded due to no route\n"); + p(ip6s_fragmented, "\t%s output datagram%s fragmented\n"); + p(ip6s_ofragments, "\t%s fragment%s created\n"); + p(ip6s_cantfrag, "\t%s datagram%s that can't be fragmented\n"); + p(ip6s_badscope, "\t%s packet%s that violated scope rules\n"); + p(ip6s_notmember, "\t%s multicast packet%s which we don't join\n"); for (first = 1, i = 0; i < 256; i++) if (ip6stat.ip6s_nxthist[i] != 0) { if (first) { printf("\tInput histogram:\n"); first = 0; } - printf("\t\t%s: %ju\n", ip6nh[i], - (uintmax_t)ip6stat.ip6s_nxthist[i]); + humanized(buf, sizeof(buf), ip6stat.ip6s_nxthist[i]); + printf("\t\t%s: %s\n", ip6nh[i], buf); } printf("\tMbuf statistics:\n"); printf("\t\t%ju one mbuf\n", (uintmax_t)ip6stat.ip6s_m1); @@ -424,9 +431,9 @@ ip6_stats(u_long off, const char *name, int af1 __ printf("\t\ttwo or more mbuf:\n"); first = 0; } - printf("\t\t\t%s= %ju\n", - if_indextoname(i, ifbuf), - (uintmax_t)ip6stat.ip6s_m2m[i]); + humanized(buf, sizeof(buf), ip6stat.ip6s_m2m[i]); + printf("\t\t\t%s = %s\n", + if_indextoname(i, ifbuf), buf); } } printf("\t\t%ju one ext mbuf\n", @@ -434,34 +441,34 @@ ip6_stats(u_long off, const char *name, int af1 __ printf("\t\t%ju two or more ext mbuf\n", (uintmax_t)ip6stat.ip6s_mext2m); p(ip6s_exthdrtoolong, - "\t%ju packet%s whose headers are not contiguous\n"); - p(ip6s_nogif, "\t%ju tunneling packet%s that can't find gif\n"); + "\t%s packet%s whose headers are not contiguous\n"); + p(ip6s_nogif, "\t%s tunneling packet%s that can't find gif\n"); p(ip6s_toomanyhdr, - "\t%ju packet%s discarded because of too many headers\n"); + "\t%s packet%s discarded because of too many headers\n"); /* for debugging source address selection */ #define PRINT_SCOPESTAT(s,i) do {\ switch(i) { /* XXX hardcoding in each case */\ case 1:\ - p(s, "\t\t%ju node-local%s\n");\ + p(s, "\t\t%s node-local%s\n");\ break;\ case 2:\ - p(s,"\t\t%ju link-local%s\n");\ + p(s,"\t\t%s link-local%s\n");\ break;\ case 5:\ - p(s,"\t\t%ju site-local%s\n");\ + p(s,"\t\t%s site-local%s\n");\ break;\ case 14:\ - p(s,"\t\t%ju global%s\n");\ + p(s,"\t\t%s global%s\n");\ break;\ default:\ - printf("\t\t%ju addresses scope=%x\n",\ - (uintmax_t)ip6stat.s, i);\ + humanized(buf, sizeof(buf), ip6stat.s); \ + printf("\t\t%s addresses scope=%x\n", buf, i);\ }\ } while (0); p(ip6s_sources_none, - "\t%ju failure%s of source address selection\n"); + "\t%s failure%s of source address selection\n"); for (first = 1, i = 0; i < 16; i++) { if (ip6stat.ip6s_sources_sameif[i]) { if (first) { @@ -527,10 +534,18 @@ ip6_ifstats(char *ifname) { struct in6_ifreq ifr; int s; -#define p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \ - printf(m, (uintmax_t)ifr.ifr_ifru.ifru_stat.f, plural(ifr.ifr_ifru.ifru_stat.f)) -#define p_5(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \ - printf(m, (uintmax_t)ip6stat.f) +#define p(f, m) \ + if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), ifr.ifr_ifru.ifru_stat.f); \ + printf(m, buf, plural(ifr.ifr_ifru.ifru_stat.f)); \ + } +#define p_5(f, m) \ + if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), ifr.ifr_ifru.ifru_stat.f); \ + printf(m, buf); \ + } if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { perror("Warning: socket(AF_INET6)"); @@ -545,28 +560,28 @@ ip6_ifstats(char *ifname) goto end; } - p(ifs6_in_receive, "\t%ju total input datagram%s\n"); - p(ifs6_in_hdrerr, "\t%ju datagram%s with invalid header received\n"); - p(ifs6_in_toobig, "\t%ju datagram%s exceeded MTU received\n"); - p(ifs6_in_noroute, "\t%ju datagram%s with no route received\n"); - p(ifs6_in_addrerr, "\t%ju datagram%s with invalid dst received\n"); - p(ifs6_in_protounknown, "\t%ju datagram%s with unknown proto received\n"); - p(ifs6_in_truncated, "\t%ju truncated datagram%s received\n"); - p(ifs6_in_discard, "\t%ju input datagram%s discarded\n"); + p(ifs6_in_receive, "\t%s total input datagram%s\n"); + p(ifs6_in_hdrerr, "\t%s datagram%s with invalid header received\n"); + p(ifs6_in_toobig, "\t%s datagram%s exceeded MTU received\n"); + p(ifs6_in_noroute, "\t%s datagram%s with no route received\n"); + p(ifs6_in_addrerr, "\t%s datagram%s with invalid dst received\n"); + p(ifs6_in_protounknown, "\t%s datagram%s with unknown proto received\n"); + p(ifs6_in_truncated, "\t%s truncated datagram%s received\n"); + p(ifs6_in_discard, "\t%s input datagram%s discarded\n"); p(ifs6_in_deliver, - "\t%ju datagram%s delivered to an upper layer protocol\n"); - p(ifs6_out_forward, "\t%ju datagram%s forwarded to this interface\n"); + "\t%s datagram%s delivered to an upper layer protocol\n"); + p(ifs6_out_forward, "\t%s datagram%s forwarded to this interface\n"); p(ifs6_out_request, - "\t%ju datagram%s sent from an upper layer protocol\n"); - p(ifs6_out_discard, "\t%ju total discarded output datagram%s\n"); - p(ifs6_out_fragok, "\t%ju output datagram%s fragmented\n"); - p(ifs6_out_fragfail, "\t%ju output datagram%s failed on fragment\n"); - p(ifs6_out_fragcreat, "\t%ju output datagram%s succeeded on fragment\n"); - p(ifs6_reass_reqd, "\t%ju incoming datagram%s fragmented\n"); - p(ifs6_reass_ok, "\t%ju datagram%s reassembled\n"); - p(ifs6_reass_fail, "\t%ju datagram%s failed on reassembly\n"); - p(ifs6_in_mcast, "\t%ju multicast datagram%s received\n"); - p(ifs6_out_mcast, "\t%ju multicast datagram%s sent\n"); + "\t%s datagram%s sent from an upper layer protocol\n"); + p(ifs6_out_discard, "\t%s total discarded output datagram%s\n"); + p(ifs6_out_fragok, "\t%s output datagram%s fragmented\n"); + p(ifs6_out_fragfail, "\t%s output datagram%s failed on fragment\n"); + p(ifs6_out_fragcreat, "\t%s output datagram%s succeeded on fragment\n"); + p(ifs6_reass_reqd, "\t%s incoming datagram%s fragmented\n"); + p(ifs6_reass_ok, "\t%s datagram%s reassembled\n"); + p(ifs6_reass_fail, "\t%s datagram%s failed on reassembly\n"); + p(ifs6_in_mcast, "\t%s multicast datagram%s received\n"); + p(ifs6_out_mcast, "\t%s multicast datagram%s sent\n"); end: close(s); @@ -843,6 +858,7 @@ icmp6_stats(u_long off, const char *name, int af1 struct icmp6stat icmp6stat; int i, first; size_t len; + char buf[15]; /* XXX */ len = sizeof icmp6stat; if (live) { @@ -858,16 +874,22 @@ icmp6_stats(u_long off, const char *name, int af1 printf("%s:\n", name); -#define p(f, m) if (icmp6stat.f || sflag <= 1) \ - printf(m, (uintmax_t)icmp6stat.f, plural(icmp6stat.f)) -#define p_5(f, m) if (icmp6stat.f || sflag <= 1) \ - printf(m, (uintmax_t)icmp6stat.f) +#define p(f, m) \ + if (icmp6stat.f || sflag <= 1) { \ + humanized(buf, sizeof(buf), icmp6stat.f); \ + printf(m, buf, plural(icmp6stat.f)); \ + } +#define p_5(f, m) \ + if (icmp6stat.f || sflag <= 1) { \ + humanized(buf, sizeof(buf), icmp6stat.f); \ + printf(m, buf); \ + } - p(icp6s_error, "\t%ju call%s to icmp6_error\n"); + p(icp6s_error, "\t%s call%s to icmp6_error\n"); p(icp6s_canterror, - "\t%ju error%s not generated in response to an icmp6 message\n"); + "\t%s error%s not generated in response to an icmp6 message\n"); p(icp6s_toofreq, - "\t%ju error%s not generated because of rate limitation\n"); + "\t%s error%s not generated because of rate limitation\n"); #define NELEM (int)(sizeof(icmp6stat.icp6s_outhist)/sizeof(icmp6stat.icp6s_outhist[0])) for (first = 1, i = 0; i < NELEM; i++) if (icmp6stat.icp6s_outhist[i] != 0) { @@ -875,14 +897,14 @@ icmp6_stats(u_long off, const char *name, int af1 printf("\tOutput histogram:\n"); first = 0; } - printf("\t\t%s: %ju\n", icmp6names[i], - (uintmax_t)icmp6stat.icp6s_outhist[i]); + humanized(buf, sizeof(buf), icmp6stat.icp6s_outhist[i]); + printf("\t\t%s: %s\n", icmp6names[i], buf); } #undef NELEM - p(icp6s_badcode, "\t%ju message%s with bad code fields\n"); - p(icp6s_tooshort, "\t%ju message%s < minimum length\n"); - p(icp6s_checksum, "\t%ju bad checksum%s\n"); - p(icp6s_badlen, "\t%ju message%s with bad length\n"); + p(icp6s_badcode, "\t%s message%s with bad code fields\n"); + p(icp6s_tooshort, "\t%s message%s < minimum length\n"); + p(icp6s_checksum, "\t%s bad checksum%s\n"); + p(icp6s_badlen, "\t%s message%s with bad length\n"); #define NELEM (int)(sizeof(icmp6stat.icp6s_inhist)/sizeof(icmp6stat.icp6s_inhist[0])) for (first = 1, i = 0; i < NELEM; i++) if (icmp6stat.icp6s_inhist[i] != 0) { @@ -890,34 +912,34 @@ icmp6_stats(u_long off, const char *name, int af1 printf("\tInput histogram:\n"); first = 0; } - printf("\t\t%s: %ju\n", icmp6names[i], - (uintmax_t)icmp6stat.icp6s_inhist[i]); + humanized(buf, sizeof(buf), icmp6stat.icp6s_inhist[i]); + printf("\t\t%s: %s\n", icmp6names[i], buf); } #undef NELEM printf("\tHistogram of error messages to be generated:\n"); - p_5(icp6s_odst_unreach_noroute, "\t\t%ju no route\n"); - p_5(icp6s_odst_unreach_admin, "\t\t%ju administratively prohibited\n"); - p_5(icp6s_odst_unreach_beyondscope, "\t\t%ju beyond scope\n"); - p_5(icp6s_odst_unreach_addr, "\t\t%ju address unreachable\n"); - p_5(icp6s_odst_unreach_noport, "\t\t%ju port unreachable\n"); - p_5(icp6s_opacket_too_big, "\t\t%ju packet too big\n"); - p_5(icp6s_otime_exceed_transit, "\t\t%ju time exceed transit\n"); - p_5(icp6s_otime_exceed_reassembly, "\t\t%ju time exceed reassembly\n"); - p_5(icp6s_oparamprob_header, "\t\t%ju erroneous header field\n"); - p_5(icp6s_oparamprob_nextheader, "\t\t%ju unrecognized next header\n"); - p_5(icp6s_oparamprob_option, "\t\t%ju unrecognized option\n"); - p_5(icp6s_oredirect, "\t\t%ju redirect\n"); - p_5(icp6s_ounknown, "\t\t%ju unknown\n"); + p_5(icp6s_odst_unreach_noroute, "\t\t%s no route\n"); + p_5(icp6s_odst_unreach_admin, "\t\t%s administratively prohibited\n"); + p_5(icp6s_odst_unreach_beyondscope, "\t\t%s beyond scope\n"); + p_5(icp6s_odst_unreach_addr, "\t\t%s address unreachable\n"); + p_5(icp6s_odst_unreach_noport, "\t\t%s port unreachable\n"); + p_5(icp6s_opacket_too_big, "\t\t%s packet too big\n"); + p_5(icp6s_otime_exceed_transit, "\t\t%s time exceed transit\n"); + p_5(icp6s_otime_exceed_reassembly, "\t\t%s time exceed reassembly\n"); + p_5(icp6s_oparamprob_header, "\t\t%s erroneous header field\n"); + p_5(icp6s_oparamprob_nextheader, "\t\t%s unrecognized next header\n"); + p_5(icp6s_oparamprob_option, "\t\t%s unrecognized option\n"); + p_5(icp6s_oredirect, "\t\t%s redirect\n"); + p_5(icp6s_ounknown, "\t\t%s unknown\n"); - p(icp6s_reflect, "\t%ju message response%s generated\n"); - p(icp6s_nd_toomanyopt, "\t%ju message%s with too many ND options\n"); - p(icp6s_nd_badopt, "\t%ju message%s with bad ND options\n"); - p(icp6s_badns, "\t%ju bad neighbor solicitation message%s\n"); - p(icp6s_badna, "\t%ju bad neighbor advertisement message%s\n"); - p(icp6s_badrs, "\t%ju bad router solicitation message%s\n"); - p(icp6s_badra, "\t%ju bad router advertisement message%s\n"); - p(icp6s_badredirect, "\t%ju bad redirect message%s\n"); - p(icp6s_pmtuchg, "\t%ju path MTU change%s\n"); + p(icp6s_reflect, "\t%s message response%s generated\n"); + p(icp6s_nd_toomanyopt, "\t%s message%s with too many ND options\n"); + p(icp6s_nd_badopt, "\t%s message%s with bad ND options\n"); + p(icp6s_badns, "\t%s bad neighbor solicitation message%s\n"); + p(icp6s_badna, "\t%s bad neighbor advertisement message%s\n"); + p(icp6s_badrs, "\t%s bad router solicitation message%s\n"); + p(icp6s_badra, "\t%s bad router advertisement message%s\n"); + p(icp6s_badredirect, "\t%s bad redirect message%s\n"); + p(icp6s_pmtuchg, "\t%s path MTU change%s\n"); #undef p #undef p_5 } @@ -930,11 +952,20 @@ icmp6_ifstats(char *ifname) { struct in6_ifreq ifr; int s; -#define p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \ - printf(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f, plural(ifr.ifr_ifru.ifru_icmp6stat.f)) -#define p2(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \ - printf(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f, pluralies(ifr.ifr_ifru.ifru_icmp6stat.f)) +#define p(f, m) \ + if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), ifr.ifr_ifru.ifru_icmp6stat.f); \ + printf(m, buf, plural(ifr.ifr_ifru.ifru_icmp6stat.f)); \ + } +#define p2(f, m) \ + if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), ifr.ifr_ifru.ifru_icmp6stat.f); \ + printf(m, buf, pluralies(ifr.ifr_ifru.ifru_icmp6stat.f)); \ + } + if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { perror("Warning: socket(AF_INET6)"); return; @@ -948,41 +979,41 @@ icmp6_ifstats(char *ifname) goto end; } - p(ifs6_in_msg, "\t%ju total input message%s\n"); - p(ifs6_in_error, "\t%ju total input error message%s\n"); - p(ifs6_in_dstunreach, "\t%ju input destination unreachable error%s\n"); - p(ifs6_in_adminprohib, "\t%ju input administratively prohibited error%s\n"); - p(ifs6_in_timeexceed, "\t%ju input time exceeded error%s\n"); - p(ifs6_in_paramprob, "\t%ju input parameter problem error%s\n"); - p(ifs6_in_pkttoobig, "\t%ju input packet too big error%s\n"); - p(ifs6_in_echo, "\t%ju input echo request%s\n"); - p2(ifs6_in_echoreply, "\t%ju input echo repl%s\n"); - p(ifs6_in_routersolicit, "\t%ju input router solicitation%s\n"); - p(ifs6_in_routeradvert, "\t%ju input router advertisement%s\n"); - p(ifs6_in_neighborsolicit, "\t%ju input neighbor solicitation%s\n"); - p(ifs6_in_neighboradvert, "\t%ju input neighbor advertisement%s\n"); - p(ifs6_in_redirect, "\t%ju input redirect%s\n"); - p2(ifs6_in_mldquery, "\t%ju input MLD quer%s\n"); - p(ifs6_in_mldreport, "\t%ju input MLD report%s\n"); - p(ifs6_in_mlddone, "\t%ju input MLD done%s\n"); + p(ifs6_in_msg, "\t%s total input message%s\n"); + p(ifs6_in_error, "\t%s total input error message%s\n"); + p(ifs6_in_dstunreach, "\t%s input destination unreachable error%s\n"); + p(ifs6_in_adminprohib, "\t%s input administratively prohibited error%s\n"); + p(ifs6_in_timeexceed, "\t%s input time exceeded error%s\n"); + p(ifs6_in_paramprob, "\t%s input parameter problem error%s\n"); + p(ifs6_in_pkttoobig, "\t%s input packet too big error%s\n"); + p(ifs6_in_echo, "\t%s input echo request%s\n"); + p2(ifs6_in_echoreply, "\t%s input echo repl%s\n"); + p(ifs6_in_routersolicit, "\t%s input router solicitation%s\n"); + p(ifs6_in_routeradvert, "\t%s input router advertisement%s\n"); + p(ifs6_in_neighborsolicit, "\t%s input neighbor solicitation%s\n"); + p(ifs6_in_neighboradvert, "\t%s input neighbor advertisement%s\n"); + p(ifs6_in_redirect, "\t%s input redirect%s\n"); + p2(ifs6_in_mldquery, "\t%s input MLD quer%s\n"); + p(ifs6_in_mldreport, "\t%s input MLD report%s\n"); + p(ifs6_in_mlddone, "\t%s input MLD done%s\n"); - p(ifs6_out_msg, "\t%ju total output message%s\n"); - p(ifs6_out_error, "\t%ju total output error message%s\n"); - p(ifs6_out_dstunreach, "\t%ju output destination unreachable error%s\n"); - p(ifs6_out_adminprohib, "\t%ju output administratively prohibited error%s\n"); - p(ifs6_out_timeexceed, "\t%ju output time exceeded error%s\n"); - p(ifs6_out_paramprob, "\t%ju output parameter problem error%s\n"); - p(ifs6_out_pkttoobig, "\t%ju output packet too big error%s\n"); - p(ifs6_out_echo, "\t%ju output echo request%s\n"); - p2(ifs6_out_echoreply, "\t%ju output echo repl%s\n"); - p(ifs6_out_routersolicit, "\t%ju output router solicitation%s\n"); - p(ifs6_out_routeradvert, "\t%ju output router advertisement%s\n"); - p(ifs6_out_neighborsolicit, "\t%ju output neighbor solicitation%s\n"); - p(ifs6_out_neighboradvert, "\t%ju output neighbor advertisement%s\n"); - p(ifs6_out_redirect, "\t%ju output redirect%s\n"); - p2(ifs6_out_mldquery, "\t%ju output MLD quer%s\n"); - p(ifs6_out_mldreport, "\t%ju output MLD report%s\n"); - p(ifs6_out_mlddone, "\t%ju output MLD done%s\n"); + p(ifs6_out_msg, "\t%s total output message%s\n"); + p(ifs6_out_error, "\t%s total output error message%s\n"); + p(ifs6_out_dstunreach, "\t%s output destination unreachable error%s\n"); + p(ifs6_out_adminprohib, "\t%s output administratively prohibited error%s\n"); + p(ifs6_out_timeexceed, "\t%s output time exceeded error%s\n"); + p(ifs6_out_paramprob, "\t%s output parameter problem error%s\n"); + p(ifs6_out_pkttoobig, "\t%s output packet too big error%s\n"); + p(ifs6_out_echo, "\t%s output echo request%s\n"); + p2(ifs6_out_echoreply, "\t%s output echo repl%s\n"); + p(ifs6_out_routersolicit, "\t%s output router solicitation%s\n"); + p(ifs6_out_routeradvert, "\t%s output router advertisement%s\n"); + p(ifs6_out_neighborsolicit, "\t%s output neighbor solicitation%s\n"); + p(ifs6_out_neighboradvert, "\t%s output neighbor advertisement%s\n"); + p(ifs6_out_redirect, "\t%s output redirect%s\n"); + p2(ifs6_out_mldquery, "\t%s output MLD quer%s\n"); + p(ifs6_out_mldreport, "\t%s output MLD report%s\n"); + p(ifs6_out_mlddone, "\t%s output MLD done%s\n"); end: close(s); @@ -1015,15 +1046,20 @@ pim6_stats(u_long off, const char *name, int af1 _ printf("%s:\n", name); -#define p(f, m) if (pim6stat.f || sflag <= 1) \ - printf(m, (uintmax_t)pim6stat.f, plural(pim6stat.f)) - p(pim6s_rcv_total, "\t%ju message%s received\n"); - p(pim6s_rcv_tooshort, "\t%ju message%s received with too few bytes\n"); - p(pim6s_rcv_badsum, "\t%ju message%s received with bad checksum\n"); - p(pim6s_rcv_badversion, "\t%ju message%s received with bad version\n"); - p(pim6s_rcv_registers, "\t%ju register%s received\n"); - p(pim6s_rcv_badregisters, "\t%ju bad register%s received\n"); - p(pim6s_snd_registers, "\t%ju register%s sent\n"); +#define p(f, m) \ + if (pim6stat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), pim6stat.f); \ + printf(m, buf, plural(pim6stat.f)); \ + } + + p(pim6s_rcv_total, "\t%s message%s received\n"); + p(pim6s_rcv_tooshort, "\t%s message%s received with too few bytes\n"); + p(pim6s_rcv_badsum, "\t%s message%s received with bad checksum\n"); + p(pim6s_rcv_badversion, "\t%s message%s received with bad version\n"); + p(pim6s_rcv_registers, "\t%s register%s received\n"); + p(pim6s_rcv_badregisters, "\t%s bad register%s received\n"); + p(pim6s_snd_registers, "\t%s register%s sent\n"); #undef p } @@ -1050,16 +1086,21 @@ rip6_stats(u_long off, const char *name, int af1 _ printf("%s:\n", name); -#define p(f, m) if (rip6stat.f || sflag <= 1) \ - printf(m, (uintmax_t)rip6stat.f, plural(rip6stat.f)) - p(rip6s_ipackets, "\t%ju message%s received\n"); - p(rip6s_isum, "\t%ju checksum calculation%s on inbound\n"); - p(rip6s_badsum, "\t%ju message%s with bad checksum\n"); - p(rip6s_nosock, "\t%ju message%s dropped due to no socket\n"); +#define p(f, m) \ + if (rip6stat.f || sflag <= 1) { \ + char buf[15]; /* XXX */ \ + humanized(buf, sizeof(buf), rip6stat.f); \ + printf(m, buf, plural(rip6stat.f)); \ + } + + p(rip6s_ipackets, "\t%s message%s received\n"); + p(rip6s_isum, "\t%s checksum calculation%s on inbound\n"); + p(rip6s_badsum, "\t%s message%s with bad checksum\n"); + p(rip6s_nosock, "\t%s message%s dropped due to no socket\n"); p(rip6s_nosockmcast, - "\t%ju multicast message%s dropped due to no socket\n"); + "\t%s multicast message%s dropped due to no socket\n"); p(rip6s_fullsock, - "\t%ju message%s dropped due to full socket buffers\n"); + "\t%s message%s dropped due to full socket buffers\n"); delivered = rip6stat.rip6s_ipackets - rip6stat.rip6s_badsum - rip6stat.rip6s_nosock - @@ -1067,7 +1108,7 @@ rip6_stats(u_long off, const char *name, int af1 _ rip6stat.rip6s_fullsock; if (delivered || sflag <= 1) printf("\t%ju delivered\n", (uintmax_t)delivered); - p(rip6s_opackets, "\t%ju datagram%s output\n"); + p(rip6s_opackets, "\t%s datagram%s output\n"); #undef p } Index: netstat.h =================================================================== --- netstat.h (revision 225135) +++ netstat.h (working copy) @@ -63,6 +63,7 @@ int kread(u_long addr, void *buf, size_t size); const char *plural(uintmax_t); const char *plurales(uintmax_t); const char *pluralies(uintmax_t); +void humanized(char *, size_t, int64_t); struct sockaddr; struct socket;