Incorporate changes for IP mcast and IGMP from cmaeda@cs.washington.edu.

This commit is contained in:
brezak 1994-01-11 19:42:48 +00:00
parent 65f742625b
commit 4b860495c5
5 changed files with 306 additions and 19 deletions

View File

@ -1,9 +1,9 @@
# from: @(#)Makefile 5.14 (Berkeley) 6/18/90
# $Id: Makefile,v 1.4 1993/09/25 13:19:49 pk Exp $
# $Id: Makefile,v 1.5 1994/01/11 19:42:48 brezak Exp $
CFLAGS+=-I${DESTDIR}/sys
PROG= netstat
SRCS= inet.c if.c main.c mbuf.c route.c unix.c
SRCS= inet.c if.c main.c mbuf.c mroute.c route.c unix.c
#
#SRCS+= host.c
#CFLAGS+= -DIMP

View File

@ -32,8 +32,8 @@
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)inet.c 5.15 (Berkeley) 6/18/90";*/
static char rcsid[] = "$Id: inet.c,v 1.5 1993/08/01 18:10:52 mycroft Exp $";
/* from: static char sccsid[] = "@(#)inet.c 5.15 (Berkeley) 6/18/90"; */
static char rcsid[] = "inet.c,v 1.4 1993/05/20 12:03:49 cgd Exp";
#endif /* not lint */
#include <sys/param.h>
@ -49,6 +49,7 @@ static char rcsid[] = "$Id: inet.c,v 1.5 1993/08/01 18:10:52 mycroft Exp $";
#include <netinet/in_pcb.h>
#include <netinet/ip_icmp.h>
#include <netinet/icmp_var.h>
#include <netinet/igmp_var.h>
#include <netinet/ip_var.h>
#include <netinet/tcp.h>
#include <netinet/tcpip.h>
@ -352,6 +353,47 @@ icmp_stats(off, name)
printf("\t%u message response%s generated\n",
icmpstat.icps_reflect, plural(icmpstat.icps_reflect));
}
char*
pluraly(n)
{
return (n == 1? "y" : "ies");
}
/*
* Dump IGMP statistics.
*/
void
igmp_stats(off, name)
off_t off;
char *name;
{
struct igmpstat igmpstat;
register int i, first;
if (off == 0)
return;
kvm_read(off, (char *)&igmpstat, sizeof (igmpstat));
printf("%s:\n", name );
printf("\t%u message%s received\n",
igmpstat.igps_rcv_total, plural(igmpstat.igps_rcv_total));
printf("\t%u message%s received with too few bytes\n",
igmpstat.igps_rcv_tooshort, plural(igmpstat.igps_rcv_tooshort));
printf("\t%u message%s received with bad checksum\n",
igmpstat.igps_rcv_badsum, plural(igmpstat.igps_rcv_badsum));
printf("\t%u membership quer%s received\n",
igmpstat.igps_rcv_queries, pluraly(igmpstat.igps_rcv_queries));
printf("\t%u membership quer%s received with invalid field(s)\n",
igmpstat.igps_rcv_badqueries, pluraly(igmpstat.igps_rcv_badqueries));
printf("\t%u membership report%s received\n",
igmpstat.igps_rcv_reports, plural(igmpstat.igps_rcv_reports));
printf("\t%u membership report%s received with invalid field(s)\n",
igmpstat.igps_rcv_badreports, plural(igmpstat.igps_rcv_badreports));
printf("\t%u membership report%s received for groups to which we belong\n",
igmpstat.igps_rcv_ourreports, plural(igmpstat.igps_rcv_ourreports));
printf("\t%u membership report%s sent\n",
igmpstat.igps_snd_reports, plural(igmpstat.igps_snd_reports));
}
/*
* Pretty print an Internet address (net address + port).

View File

@ -39,7 +39,7 @@ char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)main.c 5.23 (Berkeley) 7/1/91";*/
static char rcsid[] = "$Id: main.c,v 1.3 1993/12/22 04:00:31 cgd Exp $";
static char rcsid[] = "$Id: main.c,v 1.4 1994/01/11 19:42:53 brezak Exp $";
#endif /* not lint */
#include <sys/param.h>
@ -114,12 +114,23 @@ struct nlist nl[] = {
{ "_cltb"},
#define N_CLTPSTAT 28
{ "_cltpstat"},
#define N_IGMPSTAT 29
{ "_igmpstat" },
#define N_MRTPROTO 30
{ "_ip_mrtproto" },
#define N_MRTSTAT 31
{ "_mrtstat" },
#define N_MRTTABLE 32
{ "_mrttable" },
#define N_VIFTABLE 33
{ "_viftable" },
"",
};
/* internet protocols */
extern int protopr();
extern int tcp_stats(), udp_stats(), ip_stats(), icmp_stats();
extern int igmp_stats();
#ifdef NS
/* ns protocols */
extern int nsprotopr();
@ -151,6 +162,8 @@ struct protox {
ip_stats, "ip" },
{ -1, N_ICMPSTAT, 1, 0,
icmp_stats, "icmp" },
{ -1, N_IGMPSTAT, 1, 0,
igmp_stats, "igmp" },
{ -1, -1, 0, 0,
0, 0 }
};
@ -203,6 +216,7 @@ int Aflag;
int aflag;
int hflag;
int iflag;
int Mflag;
int mflag;
int nflag;
int pflag;
@ -228,7 +242,7 @@ main(argc, argv)
int ch;
void usage();
while ((ch = getopt(argc, argv, "Aadf:hI:iM:mN:np:rstuw:")) != EOF)
while ((ch = getopt(argc, argv, "Aac:df:hI:iMmN:np:rstuw:")) != EOF)
switch((char)ch) {
case 'A':
Aflag = 1;
@ -236,6 +250,10 @@ main(argc, argv)
case 'a':
aflag = 1;
break;
case 'c':
kmemf = optarg;
kflag = 1;
break;
case 'd':
dflag = 1;
break;
@ -270,8 +288,7 @@ main(argc, argv)
iflag = 1;
break;
case 'M':
kmemf = optarg;
kflag = 1;
Mflag++;
break;
case 'm':
mflag = 1;
@ -305,7 +322,6 @@ main(argc, argv)
break;
case 'w':
interval = atoi(optarg);
iflag = 1;
break;
case '?':
default:
@ -381,6 +397,17 @@ main(argc, argv)
(off_t)nl[N_RTREE].n_value);
exit(0);
}
if (Mflag) {
if (sflag)
mrt_stats((off_t)nl[N_MRTPROTO].n_value,
(off_t)nl[N_MRTSTAT].n_value);
else
mroutepr((off_t)nl[N_MRTPROTO].n_value,
(off_t)nl[N_MRTTABLE].n_value,
(off_t)nl[N_VIFTABLE].n_value);
exit(0);
}
if (af == AF_INET || af == AF_UNSPEC) {
setprotoent(1);
setservent(1);
@ -498,12 +525,12 @@ void
usage()
{
(void)fprintf(stderr,
"usage: netstat [-Aan] [-f address_family] [-M core] [-N system]\n");
"usage: netstat [-Aan] [-f address_family] [-c core] [-N system]\n");
(void)fprintf(stderr,
" [-himnrs] [-f address_family] [-M core] [-N system]\n");
" [-himnrs] [-f address_family] [-c core] [-N system]\n");
(void)fprintf(stderr,
" [-n] [-I interface] [-M core] [-N system] [-w wait]\n");
" [-n] [-I interface] [-c core] [-N system] [-w wait]\n");
(void)fprintf(stderr,
" [-M core] [-N system] [-p protocol]\n");
" [-c core] [-N system] [-p protocol]\n");
exit(1);
}

216
usr.bin/netstat/mroute.c Normal file
View File

@ -0,0 +1,216 @@
/*
* Print DVMRP multicast routing structures and statistics.
*
* MROUTING 1.0
*/
#ifndef lint
static char rcsid[] = "$Id: mroute.c,v 1.1 1994/01/11 19:42:55 brezak Exp $";
#endif /* not lint */
#include <stdio.h>
#include <sys/param.h>
#include <sys/mbuf.h>
#include <netinet/in.h>
#include <netinet/igmp.h>
#define KERNEL 1
struct socket; /* shut up warning */
struct ip;
#include <netinet/ip_mroute.h>
#undef KERNEL
extern int kmem;
extern int nflag;
extern char *routename();
extern char *netname();
extern char *plural();
char *plurales(n)
int n;
{
return (n == 1? "" : "es");
}
mroutepr(mrpaddr, mrtaddr, vifaddr)
off_t mrpaddr, mrtaddr, vifaddr;
{
u_int mrtproto;
#if BSD >= 199006
struct mrt *mrttable[MRTHASHSIZ];
struct mrt *mp;
struct mrt mb;
struct mrt *mrt = &mb;
#else
struct mbuf *mrttable[MRTHASHSIZ];
struct mbuf *mp;
struct mbuf mb;
struct mrt *mrt = mtod(&mb, struct mrt *);
#endif
struct vif viftable[MAXVIFS];
register struct vif *v;
register vifi_t vifi;
struct in_addr *grp;
int i, n;
int banner_printed;
int saved_nflag;
if(mrpaddr == 0) {
printf("ip_mrtproto: symbol not in namelist\n");
return;
}
kvm_read(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
switch (mrtproto) {
case 0:
printf("no multicast routing compiled into this system\n");
return;
case IGMP_DVMRP:
break;
default:
printf("multicast routing protocol %u, unknown\n", mrtproto);
return;
}
if (mrtaddr == 0) {
printf("mrttable: symbol not in namelist\n");
return;
}
if (vifaddr == 0) {
printf("viftable: symbol not in namelist\n");
return;
}
saved_nflag = nflag;
nflag = 1;
kvm_read(vifaddr, (char *)viftable, sizeof(viftable));
banner_printed = 0;
for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) {
struct in_addr v_lcl_grps[1024];
if (v->v_lcl_addr.s_addr == 0) continue;
if (!banner_printed) {
printf("\nVirtual Interface Table\n%s%s",
" Vif Threshold Local-Address ",
"Remote-Address Groups\n");
banner_printed = 1;
}
printf(" %2u %3u %-15.15s",
vifi, v->v_threshold, routename(v->v_lcl_addr));
printf(" %-15.15s\n",
(v->v_flags & VIFF_TUNNEL) ?
routename(v->v_rmt_addr) : "");
n = v->v_lcl_grps_n;
if (n == 0)
continue;
if (n < 0 || n > 1024)
printf("[v_lcl_grps_n = %d!]\n", n);
kvm_read(v->v_lcl_grps, (char *)v_lcl_grps,
n * sizeof(struct in_addr));
for (i = 0; i < n; ++i)
printf("%51s %-15.15s\n", "",
routename(v_lcl_grps[i]));
}
if (!banner_printed) printf("\nVirtual Interface Table is empty\n");
kvm_read(mrtaddr, (char *)mrttable, sizeof(mrttable));
banner_printed = 0;
for (i = 0; i < MRTHASHSIZ; ++i) {
for (mp = mrttable[i]; mp != NULL;
#if BSD >= 199006
mp = mb.mrt_next
#else
mp = mb.m_next
#endif
) {
if (!banner_printed) {
printf("\nMulticast Routing Table\n%s",
" Hash Origin-Subnet In-Vif Out-Vifs\n");
banner_printed = 1;
}
kvm_read(mp, (char *)&mb, sizeof(mb));
printf(" %3u %-15.15s %2u ",
i,
netname(mrt->mrt_origin.s_addr,
ntohl(mrt->mrt_originmask.s_addr)),
mrt->mrt_parent);
for (vifi = 0; vifi < MAXVIFS; ++vifi) {
if (viftable[vifi].v_lcl_addr.s_addr) {
if (VIFM_ISSET(vifi, mrt->mrt_children)) {
printf(" %u%c",
vifi,
VIFM_ISSET(vifi,
mrt->mrt_leaves) ?
'*' : ' ');
} else
printf(" ");
}
}
printf("\n");
}
}
if (!banner_printed) printf("\nMulticast Routing Table is empty\n");
printf("\n");
nflag = saved_nflag;
}
mrt_stats(mrpaddr, mstaddr)
off_t mrpaddr, mstaddr;
{
u_int mrtproto;
struct mrtstat mrtstat;
if(mrpaddr == 0) {
printf("ip_mrtproto: symbol not in namelist\n");
return;
}
kvm_read(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
switch (mrtproto) {
case 0:
printf("no multicast routing compiled into this system\n");
return;
case IGMP_DVMRP:
break;
default:
printf("multicast routing protocol %u, unknown\n", mrtproto);
return;
}
if (mstaddr == 0) {
printf("mrtstat: symbol not in namelist\n");
return;
}
kvm_read(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
printf("multicast routing:\n");
printf(" %10u multicast route lookup%s\n",
mrtstat.mrts_mrt_lookups, plural(mrtstat.mrts_mrt_lookups));
printf(" %10u multicast route cache miss%s\n",
mrtstat.mrts_mrt_misses, plurales(mrtstat.mrts_mrt_misses));
printf(" %10u group address lookup%s\n",
mrtstat.mrts_grp_lookups, plural(mrtstat.mrts_grp_lookups));
printf(" %10u group address cache miss%s\n",
mrtstat.mrts_grp_misses, plurales(mrtstat.mrts_grp_misses));
printf(" %10u datagram%s with no route for origin\n",
mrtstat.mrts_no_route, plural(mrtstat.mrts_no_route));
printf(" %10u datagram%s with malformed tunnel options\n",
mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel));
printf(" %10u datagram%s with no room for tunnel options\n",
mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel));
printf(" %10u datagram%s arrived on wrong interface\n",
mrtstat.mrts_wrong_if, plural(mrtstat.mrts_wrong_if));
}

View File

@ -29,8 +29,8 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" from: @(#)netstat.1 6.14 (Berkeley) 7/27/91
.\" $Id: netstat.1,v 1.2 1993/08/01 07:30:27 mycroft Exp $
.\" from: @(#)netstat.1 6.14 (Berkeley) 7/27/91
.\" $Id: netstat.1,v 1.3 1994/01/11 19:42:56 brezak Exp $
.\"
.Dd July 27, 1991
.Dt NETSTAT 1
@ -47,17 +47,17 @@
.Nm netstat
.Op Fl himnrs
.Op Fl f Ar address_family
.Op Fl M Ar core
.Op Fl c Ar core
.Op Fl N Ar system
.Nm netstat
.Op Fl n
.Op Fl I Op Ar interface
.Op Fl M Ar core
.Op Fl c Ar core
.Op Fl N Ar system
.Op Fl w Ar wait
.Nm netstat
.Op Fl p Ar protocol
.Op Fl M Ar core
.Op Fl c Ar core
.Op Fl N Ar system
.Sh DESCRIPTION
The
@ -106,13 +106,15 @@ Show information only about this interface;
used with an
.Ar wait
interval as described below.
.It Fl M
.It Fl c
Extract values associated with the name list from the specified core
instead of the default
.Pa /dev/kmem .
.It Fl m
Show statistics recorded by the memory management routines
(the network manages a private pool of memory buffers).
.It Fl M
Show multicast routing statistics.
.It Fl N
Extract the name list from the specified system instead of the default
.Pa /vmunix .