diff options
author | Ryan Thomas McBride <mcbride@cvs.openbsd.org> | 2005-01-14 15:00:45 +0000 |
---|---|---|
committer | Ryan Thomas McBride <mcbride@cvs.openbsd.org> | 2005-01-14 15:00:45 +0000 |
commit | 85f83927c10fbc481f918e8b1b06a156a60480b8 (patch) | |
tree | f9cdb4868dca579b7fc52eb8aebef1f4a07e0f90 /usr.bin | |
parent | b17254eef4cb201f6011db0dabe120b5db73eeca (diff) |
Allow netstat to print PIM statistics.
From Pavlin Radoslavov <pavlin@icir.org>
ok deraadt@ brad@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/netstat/inet.c | 42 | ||||
-rw-r--r-- | usr.bin/netstat/main.c | 8 | ||||
-rw-r--r-- | usr.bin/netstat/mroute.c | 103 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.h | 3 |
4 files changed, 149 insertions, 7 deletions
diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index a961e2b86f2..b064dda4302 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: inet.c,v 1.89 2004/11/17 01:09:45 mcbride Exp $ */ +/* $OpenBSD: inet.c,v 1.90 2005/01/14 15:00:44 mcbride Exp $ */ /* $NetBSD: inet.c,v 1.14 1995/10/03 21:42:37 thorpej Exp $ */ /* @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "from: @(#)inet.c 8.4 (Berkeley) 4/20/94"; #else -static const char *rcsid = "$OpenBSD: inet.c,v 1.89 2004/11/17 01:09:45 mcbride Exp $"; +static const char *rcsid = "$OpenBSD: inet.c,v 1.90 2005/01/14 15:00:44 mcbride Exp $"; #endif #endif /* not lint */ @@ -54,6 +54,7 @@ static const char *rcsid = "$OpenBSD: inet.c,v 1.89 2004/11/17 01:09:45 mcbride #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> @@ -575,6 +576,43 @@ igmp_stats(u_long off, char *name) #undef py } +/* + * Dump PIM statistics structure. + */ +void +pim_stats(u_long off, char *name) +{ + struct pimstat pimstat; + + if (off == 0) + return; + if (kread(off, (char *)&pimstat, sizeof (pimstat)) != 0) { + /* XXX: PIM is probably not enabled in the kernel */ + 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 +} + struct rpcnams { struct rpcnams *next; in_port_t port; diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index c8010006912..deecd5161c3 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.49 2004/06/29 08:18:20 henning Exp $ */ +/* $OpenBSD: main.c,v 1.50 2005/01/14 15:00:44 mcbride Exp $ */ /* $NetBSD: main.c,v 1.9 1996/05/07 02:55:02 thorpej Exp $ */ /* @@ -40,7 +40,7 @@ char copyright[] = #if 0 static char sccsid[] = "from: @(#)main.c 8.4 (Berkeley) 3/1/94"; #else -static char *rcsid = "$OpenBSD: main.c,v 1.49 2004/06/29 08:18:20 henning Exp $"; +static char *rcsid = "$OpenBSD: main.c,v 1.50 2005/01/14 15:00:44 mcbride Exp $"; #endif #endif /* not lint */ @@ -183,6 +183,8 @@ struct nlist nl[] = { { "_rawin6pcbtable" }, #define N_PFSYNCSTAT 58 { "_pfsyncstats" }, +#define N_PIMSTAT 59 + { "_pimstat" }, { ""}, }; @@ -218,6 +220,8 @@ struct protox { carp_stats, "carp" }, { -1, N_PFSYNCSTAT, 1, 0, pfsync_stats, "pfsync" }, + { -1, N_PIMSTAT, 1, 0, + pim_stats, "pim" }, { -1, -1, 0, 0, 0, 0 } }; diff --git a/usr.bin/netstat/mroute.c b/usr.bin/netstat/mroute.c index 5eb607fa658..c8055a7b7f7 100644 --- a/usr.bin/netstat/mroute.c +++ b/usr.bin/netstat/mroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mroute.c,v 1.11 2003/07/07 21:36:52 deraadt Exp $ */ +/* $OpenBSD: mroute.c,v 1.12 2005/01/14 15:00:44 mcbride Exp $ */ /* $NetBSD: mroute.c,v 1.10 1996/05/11 13:51:27 mycroft Exp $ */ /* @@ -37,7 +37,7 @@ */ /* - * Print DVMRP multicast routing structures and statistics. + * Print multicast routing structures and statistics. * * MROUTING 1.0 */ @@ -60,6 +60,8 @@ #include <stdlib.h> #include "netstat.h" +static void print_bw_meter(struct bw_meter *bw_meter, int *banner_printed); + static char * pktscale(u_long n) { @@ -186,6 +188,27 @@ mroutepr(u_long mrpaddr, u_long mfchashtbladdr, u_long mfchashaddr, u_long vifad 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 + } + nmfc++; } } @@ -198,6 +221,82 @@ mroutepr(u_long mrpaddr, u_long mfchashtbladdr, u_long mfchashaddr, u_long vifad nflag = saved_nflag; } +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) + snprintf(s1, sizeof s1, "%llu", + bw_meter->bm_measured.b_packets); + else + snprintf(s1, sizeof s1, "?"); + if (bw_meter->bm_flags & BW_METER_UNIT_BYTES) + snprintf(s2, sizeof s2, "%llu", bw_meter->bm_measured.b_bytes); + else + snprintf(s2, sizeof s2, "?"); + snprintf(s0, sizeof 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 */ + snprintf(s0, sizeof s0, "%s", "?"); + if (bw_meter->bm_flags & BW_METER_GEQ) + snprintf(s0, sizeof s0, "%s", ">="); + else if (bw_meter->bm_flags & BW_METER_LEQ) + snprintf(s0, sizeof s0, "%s", "<="); + printf(" %-3s", s0); + + /* The threshold values */ + if (bw_meter->bm_flags & BW_METER_UNIT_PACKETS) + snprintf(s1, sizeof s1, "%llu", + bw_meter->bm_threshold.b_packets); + else + snprintf(s1, sizeof s1, "?"); + if (bw_meter->bm_flags & BW_METER_UNIT_BYTES) + snprintf(s2, sizeof s2, "%llu", + bw_meter->bm_threshold.b_bytes); + else + snprintf(s2, sizeof s2, "?"); + snprintf(s0, sizeof 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); + snprintf(s3, sizeof s3, "%lu.%lu", + delta.tv_sec, delta.tv_usec); + } else { + /* Negative time */ + timersub(&now, &end, &delta); + snprintf(s3, sizeof s3, "-%lu.%lu", + delta.tv_sec, delta.tv_usec); + } + printf(" %s", s3); + + printf("\n"); +} void mrt_stats(u_long mrpaddr, u_long mstaddr) diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index e7041800418..eebea3a406e 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -1,4 +1,4 @@ -/* $OpenBSD: netstat.h,v 1.28 2004/06/06 16:55:31 cedric Exp $ */ +/* $OpenBSD: netstat.h,v 1.29 2005/01/14 15:00:44 mcbride Exp $ */ /* $NetBSD: netstat.h,v 1.6 1996/05/07 02:55:05 thorpej Exp $ */ /* @@ -76,6 +76,7 @@ void udp_stats(u_long, char *); void ip_stats(u_long, char *); void icmp_stats(u_long, char *); void igmp_stats(u_long, char *); +void pim_stats(u_long, char *); void ah_stats(u_long, char *); void esp_stats(u_long, char *); void ipip_stats(u_long, char *); |