summaryrefslogtreecommitdiffstats
path: root/usr.bin/netstat/mroute.c
diff options
context:
space:
mode:
authorhsu <hsu@FreeBSD.org>2003-08-07 18:21:21 +0000
committerhsu <hsu@FreeBSD.org>2003-08-07 18:21:21 +0000
commit27325403c64a9b3337b47535dc2680886c4064fe (patch)
treea145ae69f3bb698396cff2cc32af61aad54348e1 /usr.bin/netstat/mroute.c
parent61eb7602bf1a4b7c495cf4c605e2345b1f8dfa61 (diff)
downloadFreeBSD-src-27325403c64a9b3337b47535dc2680886c4064fe.zip
FreeBSD-src-27325403c64a9b3337b47535dc2680886c4064fe.tar.gz
1. Add support for printing PIM-related statistics with
netstat -s -p pim 2. Print information about the bandwidth meters installed in the kernel with netstat -g Submitted by: Pavlin Radoslavov <pavlin@icir.org>
Diffstat (limited to 'usr.bin/netstat/mroute.c')
-rw-r--r--usr.bin/netstat/mroute.c93
1 files changed, 93 insertions, 0 deletions
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)
OpenPOWER on IntegriCloud