diff options
-rw-r--r-- | usr.bin/netstat/inet.c | 39 | ||||
-rw-r--r-- | usr.bin/netstat/main.c | 2 | ||||
-rw-r--r-- | usr.bin/netstat/mroute.c | 93 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.1 | 2 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.h | 1 |
5 files changed, 136 insertions, 1 deletions
diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index d608e1a..55994a1 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -58,6 +58,7 @@ static const char rcsid[] = #include <netinet/icmp_var.h> #include <netinet/igmp_var.h> #include <netinet/ip_var.h> +#include <netinet/pim_var.h> #include <netinet/tcp.h> #include <netinet/tcpip.h> #include <netinet/tcp_seq.h> @@ -706,6 +707,44 @@ igmp_stats(u_long off __unused, const char *name, int af1 __unused) } /* + * Dump PIM statistics structure. + */ +void +pim_stats(u_long off __unused, const char *name, int af1 __unused) +{ + struct pimstat pimstat, zerostat; + size_t len = sizeof pimstat; + + if (zflag) + memset(&zerostat, 0, len); + if (sysctlbyname("net.inet.pim.stats", &pimstat, &len, + zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { + warn("sysctl: net.inet.pim.stats"); + return; + } + + printf("%s:\n", name); + +#define p(f, m) if (pimstat.f || sflag <= 1) \ + printf(m, pimstat.f, plural(pimstat.f)) +#define py(f, m) if (pimstat.f || sflag <= 1) \ + printf(m, pimstat.f, pimstat.f != 1 ? "ies" : "y") + p(pims_rcv_total_msgs, "\t%llu message%s received\n"); + p(pims_rcv_total_bytes, "\t%llu byte%s received\n"); + p(pims_rcv_tooshort, "\t%llu message%s received with too few bytes\n"); + p(pims_rcv_badsum, "\t%llu message%s received with bad checksum\n"); + p(pims_rcv_badversion, "\t%llu message%s received with bad version\n"); + p(pims_rcv_registers_msgs, "\t%llu data register message%s received\n"); + p(pims_rcv_registers_bytes, "\t%llu data register byte%s received\n"); + p(pims_rcv_registers_wrongiif, "\t%llu data register message%s received on wrong iif\n"); + p(pims_rcv_badregisters, "\t%llu bad register%s received\n"); + p(pims_snd_registers_msgs, "\t%llu data register message%s sent\n"); + p(pims_snd_registers_bytes, "\t%llu data register byte%s sent\n"); +#undef p +#undef py +} + +/* * Pretty print an Internet address (net address + port). */ void diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index ac70c41..145f740 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -168,6 +168,8 @@ struct protox { #endif { -1, -1, 1, 0, bdg_stats, NULL, "bdg", 1 /* bridging... */ }, + { -1, -1, 1, protopr, + pim_stats, NULL, "pim", IPPROTO_PIM }, { -1, -1, 0, 0, 0, NULL, 0, 0 } }; diff --git a/usr.bin/netstat/mroute.c b/usr.bin/netstat/mroute.c index 398e115..3449268 100644 --- a/usr.bin/netstat/mroute.c +++ b/usr.bin/netstat/mroute.c @@ -68,6 +68,8 @@ static const char rcsid[] = #include <stdlib.h> #include "netstat.h" +static void print_bw_meter(struct bw_meter *bw_meter, int *banner_printed); + void mroutepr(u_long mfcaddr, u_long vifaddr) { @@ -157,6 +159,26 @@ mroutepr(u_long mfcaddr, u_long vifaddr) mfc.mfc_ttls[vifi]); } printf("\n"); + + /* Print the bw meter information */ + { + struct bw_meter bw_meter, *bwm; + int banner_printed2 = 0; + + bwm = mfc.mfc_bw_meter; + while (bwm) { + kread((u_long)bwm, (char *)&bw_meter, + sizeof bw_meter); + print_bw_meter(&bw_meter, + &banner_printed2); + bwm = bw_meter.bm_mfc_next; + } +#if 0 /* Don't ever print it? */ + if (! banner_printed2) + printf("\n No Bandwidth Meters\n"); +#endif + } + m = mfc.mfc_next; } } @@ -167,6 +189,77 @@ mroutepr(u_long mfcaddr, u_long vifaddr) numeric_addr = saved_numeric_addr; } +static void +print_bw_meter(struct bw_meter *bw_meter, int *banner_printed) +{ + char s0[256], s1[256], s2[256], s3[256]; + struct timeval now, end, delta; + + gettimeofday(&now, NULL); + + if (! *banner_printed) { + printf(" Bandwidth Meters\n"); + printf(" %-30s", "Measured(Start|Packets|Bytes)"); + printf(" %s", "Type"); + printf(" %-30s", "Thresh(Interval|Packets|Bytes)"); + printf(" Remain"); + printf("\n"); + *banner_printed = 1; + } + + /* The measured values */ + if (bw_meter->bm_flags & BW_METER_UNIT_PACKETS) + sprintf(s1, "%llu", bw_meter->bm_measured.b_packets); + else + sprintf(s1, "?"); + if (bw_meter->bm_flags & BW_METER_UNIT_BYTES) + sprintf(s2, "%llu", bw_meter->bm_measured.b_bytes); + else + sprintf(s2, "?"); + sprintf(s0, "%lu.%lu|%s|%s", + bw_meter->bm_start_time.tv_sec, + bw_meter->bm_start_time.tv_usec, + s1, s2); + printf(" %-30s", s0); + + /* The type of entry */ + sprintf(s0, "%s", "?"); + if (bw_meter->bm_flags & BW_METER_GEQ) + sprintf(s0, "%s", ">="); + else if (bw_meter->bm_flags & BW_METER_LEQ) + sprintf(s0, "%s", "<="); + printf(" %-3s", s0); + + /* The threshold values */ + if (bw_meter->bm_flags & BW_METER_UNIT_PACKETS) + sprintf(s1, "%llu", bw_meter->bm_threshold.b_packets); + else + sprintf(s1, "?"); + if (bw_meter->bm_flags & BW_METER_UNIT_BYTES) + sprintf(s2, "%llu", bw_meter->bm_threshold.b_bytes); + else + sprintf(s2, "?"); + sprintf(s0, "%lu.%lu|%s|%s", + bw_meter->bm_threshold.b_time.tv_sec, + bw_meter->bm_threshold.b_time.tv_usec, + s1, s2); + printf(" %-30s", s0); + + /* Remaining time */ + timeradd(&bw_meter->bm_start_time, + &bw_meter->bm_threshold.b_time, &end); + if (timercmp(&now, &end, <=)) { + timersub(&end, &now, &delta); + sprintf(s3, "%lu.%lu", delta.tv_sec, delta.tv_usec); + } else { + /* Negative time */ + timersub(&now, &end, &delta); + sprintf(s3, "-%lu.%lu", delta.tv_sec, delta.tv_usec); + } + printf(" %s", s3); + + printf("\n"); +} void mrt_stats(u_long mstaddr) diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1 index eca652a..f8e2788 100644 --- a/usr.bin/netstat/netstat.1 +++ b/usr.bin/netstat/netstat.1 @@ -271,7 +271,7 @@ The following address families and protocols are recognized: .It Em Family .Em Protocols .It Cm inet Pq Dv AF_INET -.Cm bdg , divert , icmp , igmp , ip , ipsec , tcp , udp +.Cm bdg , divert , icmp , igmp , ip , ipsec , pim, tcp , udp .It Cm inet6 Pq Dv AF_INET6 .Cm bdg , icmp6 , ip6 , ipsec6 , rip6 , tcp , udp .It Cm pfkey Pq Dv PF_KEY diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index c3cb9d0..ee00124 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -69,6 +69,7 @@ void udp_stats (u_long, const char *, int); void ip_stats (u_long, const char *, int); void icmp_stats (u_long, const char *, int); void igmp_stats (u_long, const char *, int); +void pim_stats (u_long, const char *, int); #ifdef IPSEC void ipsec_stats (u_long, const char *, int); #endif |