Add support for Protocol Independent Multicast.
authorJeffrey Hsu <hsu@dragonflybsd.org>
Sun, 24 Aug 2003 23:16:53 +0000 (23:16 +0000)
committerJeffrey Hsu <hsu@dragonflybsd.org>
Sun, 24 Aug 2003 23:16:53 +0000 (23:16 +0000)
Submitted to FreeBSD by: Pavlin Radoslavov <pavlin@icir.org>

usr.bin/netstat/inet.c
usr.bin/netstat/main.c
usr.bin/netstat/mroute.c
usr.bin/netstat/netstat.1
usr.bin/netstat/netstat.h

index 99d693a..fc7641f 100644 (file)
@@ -32,7 +32,7 @@
  *
  * @(#)inet.c  8.5 (Berkeley) 5/24/95
  * $FreeBSD: src/usr.bin/netstat/inet.c,v 1.37.2.9 2001/12/17 20:03:59 jlemon Exp $
- * $DragonFly: src/usr.bin/netstat/inet.c,v 1.4 2003/08/14 23:11:33 hsu Exp $
+ * $DragonFly: src/usr.bin/netstat/inet.c,v 1.5 2003/08/24 23:16:53 hsu Exp $
  */
 
 #include <sys/param.h>
@@ -54,6 +54,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>
@@ -704,6 +705,44 @@ igmp_stats(u_long off __unused, char *name, int af __unused)
 #undef py
 }
 
+/*
+ * Dump PIM statistics structure.
+ */
+void
+pim_stats(u_long off __unused, 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).
  */
index b1a8945..0c20ac1 100644 (file)
@@ -33,7 +33,7 @@
  * @(#) Copyright (c) 1983, 1988, 1993 Regents of the University of California.  All rights reserved.
  * @(#)main.c  8.4 (Berkeley) 3/1/94
  * $FreeBSD: src/usr.bin/netstat/main.c,v 1.34.2.12 2001/09/17 15:17:46 ru Exp $
- * $DragonFly: src/usr.bin/netstat/main.c,v 1.3 2003/08/08 04:18:43 dillon Exp $
+ * $DragonFly: src/usr.bin/netstat/main.c,v 1.4 2003/08/24 23:16:53 hsu Exp $
  */
 
 #include <sys/param.h>
@@ -205,6 +205,8 @@ struct protox ip6protox[] = {
          rip6_stats,   NULL,           "rip6", 0 },
        { -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 }
 };
index 18053f2..78dca95 100644 (file)
  *     @(#)mroute.c    8.2 (Berkeley) 4/28/95
  *
  * $FreeBSD: src/usr.bin/netstat/mroute.c,v 1.11.2.4 2001/09/17 14:53:17 ru Exp $
- * $DragonFly: src/usr.bin/netstat/mroute.c,v 1.3 2003/08/08 04:18:43 dillon Exp $
+ * $DragonFly: src/usr.bin/netstat/mroute.c,v 1.4 2003/08/24 23:16:53 hsu Exp $
  */
 
 /*
- * Print DVMRP multicast routing structures and statistics.
+ * Print multicast routing structures and statistics.
  *
  * MROUTING 1.0
  */
@@ -64,6 +64,8 @@
 #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)
 {
@@ -135,6 +137,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;
                }
        }
@@ -145,6 +167,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)
index 05e2eb6..71eba1c 100644 (file)
@@ -31,7 +31,7 @@
 .\"
 .\"    @(#)netstat.1   8.8 (Berkeley) 4/18/94
 .\" $FreeBSD: src/usr.bin/netstat/netstat.1,v 1.22.2.13 2003/05/03 22:10:02 keramida Exp $
-.\" $DragonFly: src/usr.bin/netstat/netstat.1,v 1.2 2003/06/17 04:29:30 dillon Exp $
+.\" $DragonFly: src/usr.bin/netstat/netstat.1,v 1.3 2003/08/24 23:16:53 hsu Exp $
 .\"
 .Dd September 7, 2001
 .Dt NETSTAT 1
@@ -274,7 +274,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
index b192ac2..8ffc141 100644 (file)
@@ -32,7 +32,7 @@
  *
  *     @(#)netstat.h   8.2 (Berkeley) 1/4/94
  * $FreeBSD: src/usr.bin/netstat/netstat.h,v 1.16.2.7 2001/09/17 15:17:46 ru Exp $
- * $DragonFly: src/usr.bin/netstat/netstat.h,v 1.2 2003/06/17 04:29:30 dillon Exp $
+ * $DragonFly: src/usr.bin/netstat/netstat.h,v 1.3 2003/08/24 23:16:53 hsu Exp $
  */
 
 #include <sys/cdefs.h>
@@ -70,6 +70,7 @@ void  udp_stats (u_long, char *, int);
 void   ip_stats (u_long, char *, int);
 void   icmp_stats (u_long, char *, int);
 void   igmp_stats (u_long, char *, int);
+void   pim_stats (u_long, char *, int);
 #ifdef IPSEC
 void   ipsec_stats (u_long, char *, int);
 #endif