Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/netstat IPv4 PIM support, from the submission of Pav...



details:   https://anonhg.NetBSD.org/src/rev/1328c9a25219
branches:  trunk
changeset: 569764:1328c9a25219
user:      manu <manu%NetBSD.org@localhost>
date:      Sat Sep 04 23:35:43 2004 +0000

description:
IPv4 PIM support, from the submission of Pavlin Radoslavov on tech-net@

diffstat:

 usr.bin/netstat/inet.c    |   44 +++++++++++++++++++-
 usr.bin/netstat/main.c    |    8 ++-
 usr.bin/netstat/mroute.c  |  101 ++++++++++++++++++++++++++++++++++++++++++++-
 usr.bin/netstat/netstat.h |    3 +-
 4 files changed, 148 insertions(+), 8 deletions(-)

diffs (265 lines):

diff -r 6a7ea6b0d207 -r 1328c9a25219 usr.bin/netstat/inet.c
--- a/usr.bin/netstat/inet.c    Sat Sep 04 23:33:07 2004 +0000
+++ b/usr.bin/netstat/inet.c    Sat Sep 04 23:35:43 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: inet.c,v 1.61 2004/05/18 14:44:41 itojun Exp $ */
+/*     $NetBSD: inet.c,v 1.62 2004/09/04 23:35:43 manu Exp $   */
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c       8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet.c,v 1.61 2004/05/18 14:44:41 itojun Exp $");
+__RCSID("$NetBSD: inet.c,v 1.62 2004/09/04 23:35:43 manu Exp $");
 #endif
 #endif /* not lint */
 
@@ -60,6 +60,7 @@
 #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>
@@ -515,6 +516,45 @@
 }
 
 /*
+ * Dump PIM statistics structure.
+ */
+void
+pim_stats(off, name)
+       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
+}
+
+/*
  * Dump the ARP statistics structure.
  */
 void
diff -r 6a7ea6b0d207 -r 1328c9a25219 usr.bin/netstat/main.c
--- a/usr.bin/netstat/main.c    Sat Sep 04 23:33:07 2004 +0000
+++ b/usr.bin/netstat/main.c    Sat Sep 04 23:35:43 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.46 2004/06/27 01:10:54 jonathan Exp $       */
+/*     $NetBSD: main.c,v 1.47 2004/09/04 23:35:43 manu Exp $   */
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "from: @(#)main.c       8.4 (Berkeley) 3/1/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.46 2004/06/27 01:10:54 jonathan Exp $");
+__RCSID("$NetBSD: main.c,v 1.47 2004/09/04 23:35:43 manu Exp $");
 #endif
 #endif /* not lint */
 
@@ -202,6 +202,8 @@
        { "_pkintrq" },
 #define        N_HARDCLOCK_TICKS 67
        { "_hardclock_ticks" },
+#define N_PIMSTAT      68
+       { "_pimstat" },
        { "" },
 };
 
@@ -233,6 +235,8 @@
        { -1,           N_IPSECSTAT,    1,      0,
          ipsec_switch, NULL,           0,      "ipsec" },
 #endif
+       { -1,           N_PIMSTAT,      1,      0,
+         pim_stats,    NULL,           0,      "pim" },
        { -1,           -1,             0,      0,
          0,            NULL,           0,      0 }
 };
diff -r 6a7ea6b0d207 -r 1328c9a25219 usr.bin/netstat/mroute.c
--- a/usr.bin/netstat/mroute.c  Sat Sep 04 23:33:07 2004 +0000
+++ b/usr.bin/netstat/mroute.c  Sat Sep 04 23:35:43 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mroute.c,v 1.17 2003/08/07 11:15:21 agc Exp $  */
+/*     $NetBSD: mroute.c,v 1.18 2004/09/04 23:35:43 manu Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -76,12 +76,12 @@
 #if 0
 static char sccsid[] = "from: @(#)mroute.c     8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: mroute.c,v 1.17 2003/08/07 11:15:21 agc Exp $");
+__RCSID("$NetBSD: mroute.c,v 1.18 2004/09/04 23:35:43 manu Exp $");
 #endif
 #endif /* not lint */
 
 /*
- * Print DVMRP multicast routing structures and statistics.
+ * Print multicast routing structures and statistics.
  *
  * MROUTING 1.0
  */
@@ -104,6 +104,7 @@
 #include "netstat.h"
 
 static char *pktscale __P((u_long));
+static void print_bw_meter __P((struct bw_meter *, int *));
 
 static char *
 pktscale(n)
@@ -232,6 +233,27 @@
                                        printf(" %u/%u", vifi, 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++;
                }
        }
@@ -244,6 +266,79 @@
        numeric_addr = saved_numeric_addr;
 }
 
+static void
+print_bw_meter(bw_meter, banner_printed)
+       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(mrpaddr, mstaddr)
diff -r 6a7ea6b0d207 -r 1328c9a25219 usr.bin/netstat/netstat.h
--- a/usr.bin/netstat/netstat.h Sat Sep 04 23:33:07 2004 +0000
+++ b/usr.bin/netstat/netstat.h Sat Sep 04 23:35:43 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netstat.h,v 1.29 2004/05/07 00:55:15 jonathan Exp $    */
+/*     $NetBSD: netstat.h,v 1.30 2004/09/04 23:35:43 manu Exp $        */
 
 /*
  * Copyright (c) 1992, 1993
@@ -74,6 +74,7 @@
 void   ip_stats __P((u_long, char *));
 void   icmp_stats __P((u_long, char *));
 void   igmp_stats __P((u_long, char *));
+void   pim_stats __P((u_long, char *));
 void   arp_stats __P((u_long, char *));
 #ifdef IPSEC
 /* run-time selector for which  implementation (KAME, FAST_IPSEC) to show */



Home | Main Index | Thread Index | Old Index