From 81c2958581d0f7600f3a40a42bec20bc11ab594d Mon Sep 17 00:00:00 2001 From: mycroft Date: Mon, 12 Jun 1995 03:03:07 +0000 Subject: [PATCH] Update to match kernel changes. --- usr.bin/netstat/if.c | 28 +++++-- usr.bin/netstat/inet.c | 27 +++--- usr.bin/netstat/main.c | 25 +++--- usr.bin/netstat/mroute.c | 168 +++++++++++++++++++++++--------------- usr.bin/netstat/netstat.h | 4 +- 5 files changed, 149 insertions(+), 103 deletions(-) diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c index b875c3b3ed25..a360677f46e4 100644 --- a/usr.bin/netstat/if.c +++ b/usr.bin/netstat/if.c @@ -33,7 +33,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)if.c 8.2 (Berkeley) 2/21/94";*/ -static char *rcsid = "$Id: if.c,v 1.9 1994/09/17 00:14:20 mycroft Exp $"; +static char *rcsid = "$Id: if.c,v 1.10 1995/06/12 03:03:07 mycroft Exp $"; #endif /* not lint */ #include @@ -112,16 +112,16 @@ intpr(interval, ifnetaddr) kread((u_long)ifnet.if_name, name, 16)) return; name[15] = '\0'; - ifnetaddr = (u_long)ifnet.if_next; + ifnetaddr = (u_long)ifnet.if_list.tqe_next; if (interface != 0 && (strcmp(name, interface) != 0 || unit != ifnet.if_unit)) continue; cp = index(name, '\0'); cp += sprintf(cp, "%d", ifnet.if_unit); - if ((ifnet.if_flags&IFF_UP) == 0) + if ((ifnet.if_flags & IFF_UP) == 0) *cp++ = '*'; *cp = '\0'; - ifaddraddr = (u_long)ifnet.if_addrlist; + ifaddraddr = (u_long)ifnet.if_addrlist.tqh_first; } printf("%-5.5s %-5d ", name, ifnet.if_mtu); if (ifaddraddr == 0) { @@ -157,6 +157,20 @@ intpr(interval, ifnetaddr) #endif printf("%-15.15s ", routename(sin->sin_addr.s_addr)); + + if (aflag) { + u_long multiaddr; + struct in_multi inm; + + multiaddr = (u_long)ifaddr.in.ia_multiaddrs.lh_first; + while (multiaddr != 0) { + kread(multiaddr, (char *)&inm, + sizeof inm); + printf("\n%23s %-15.15s ", "", + routename(inm.inm_addr.s_addr)); + multiaddr = (u_long)inm.inm_list.le_next; + } + } break; case AF_NS: { @@ -197,7 +211,7 @@ intpr(interval, ifnetaddr) putchar(' '); break; } - ifaddraddr = (u_long)ifaddr.ifa.ifa_next; + ifaddraddr = (u_long)ifaddr.ifa.ifa_list.tqe_next; } printf("%8d %5d %8d %5d %5d", ifnet.if_ipackets, ifnet.if_ierrors, @@ -265,7 +279,7 @@ sidewaysintpr(interval, off) ip++; if (ip >= iftot + MAXIF - 2) break; - off = (u_long) ifnet.if_next; + off = (u_long)ifnet.if_list.tqe_next; } lastif = ip; @@ -335,7 +349,7 @@ loop: sum->ift_oe += ip->ift_oe; sum->ift_co += ip->ift_co; sum->ift_dr += ip->ift_dr; - off = (u_long) ifnet.if_next; + off = (u_long)ifnet.if_list.tqe_next; } if (lastif - iftot > 0) { printf(" %8d %5d %8d %5d %5d", diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index 8e823b06fd33..40366e1b4c09 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -33,7 +33,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)inet.c 8.4 (Berkeley) 4/20/94";*/ -static char *rcsid = "$Id: inet.c,v 1.11 1995/05/14 08:20:16 cgd Exp $"; +static char *rcsid = "$Id: inet.c,v 1.12 1995/06/12 03:03:10 mycroft Exp $"; #endif /* not lint */ #include @@ -88,31 +88,27 @@ protopr(off, name) u_long off; char *name; { - struct inpcb cb; - register struct inpcb *prev, *next; + struct inpcbtable table; + register struct inpcb *next, **prev; int istcp; static int first = 1; if (off == 0) return; istcp = strcmp(name, "tcp") == 0; - kread(off, (char *)&cb, sizeof (struct inpcb)); - inpcb = cb; - prev = (struct inpcb *)off; - if (inpcb.inp_next == (struct inpcb *)off) - return; - while (inpcb.inp_next != (struct inpcb *)off) { - next = inpcb.inp_next; - kread((u_long)next, (char *)&inpcb, sizeof (inpcb)); - if (inpcb.inp_prev != prev) { + kread(off, (char *)&table, sizeof table); + prev = &((struct inpcbtable *)off)->inpt_list.lh_first; + while (inpcb.inp_list.le_next != 0) { + next = inpcb.inp_list.le_next; + kread((u_long)next, (char *)&inpcb, sizeof inpcb); + if (inpcb.inp_list.le_prev != prev) { printf("???\n"); break; } + prev = &next->inp_list.le_next; if (!aflag && - inet_lnaof(inpcb.inp_laddr) == INADDR_ANY) { - prev = next; + inet_lnaof(inpcb.inp_laddr) == INADDR_ANY) continue; - } kread((u_long)inpcb.inp_socket, (char *)&sockb, sizeof (sockb)); if (istcp) { kread((u_long)inpcb.inp_ppcb, @@ -148,7 +144,6 @@ protopr(off, name) printf(" %s", tcpstates[tcpcb.t_state]); } putchar('\n'); - prev = next; } } diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index 6999563936e8..35a649e00bf1 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -39,7 +39,7 @@ char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)main.c 8.4 (Berkeley) 3/1/94";*/ -static char *rcsid = "$Id: main.c,v 1.6 1994/05/13 08:08:14 mycroft Exp $"; +static char *rcsid = "$Id: main.c,v 1.7 1995/06/12 03:03:11 mycroft Exp $"; #endif /* not lint */ #include @@ -67,12 +67,12 @@ struct nlist nl[] = { { "_mbstat" }, #define N_IPSTAT 1 { "_ipstat" }, -#define N_TCB 2 - { "_tcb" }, +#define N_TCBTABLE 2 + { "_tcbtable" }, #define N_TCPSTAT 3 { "_tcpstat" }, -#define N_UDB 4 - { "_udb" }, +#define N_UDBTABLE 4 + { "_udbtable" }, #define N_UDPSTAT 5 { "_udpstat" }, #define N_IFNET 6 @@ -121,9 +121,11 @@ struct nlist nl[] = { { "_ip_mrtproto" }, #define N_MRTSTAT 28 { "_mrtstat" }, -#define N_MRTTABLE 29 - { "_mrttable" }, -#define N_VIFTABLE 30 +#define N_MFCHASHTBL 29 + { "_mfchashtbl" }, +#define N_MFCHASH 30 + { "_mfchash" }, +#define N_VIFTABLE 31 { "_viftable" }, "", }; @@ -136,9 +138,9 @@ struct protox { void (*pr_stats)(); /* statistics printing routine */ char *pr_name; /* well-known name */ } protox[] = { - { N_TCB, N_TCPSTAT, 1, protopr, + { N_TCBTABLE, N_TCPSTAT, 1, protopr, tcp_stats, "tcp" }, - { N_UDB, N_UDPSTAT, 1, protopr, + { N_UDBTABLE, N_UDPSTAT, 1, protopr, udp_stats, "udp" }, { -1, N_IPSTAT, 1, 0, ip_stats, "ip" }, @@ -361,7 +363,8 @@ main(argc, argv) nl[N_MRTSTAT].n_value); else mroutepr(nl[N_MRTPROTO].n_value, - nl[N_MRTTABLE].n_value, + nl[N_MFCHASHTBL].n_value, + nl[N_MFCHASH].n_value, nl[N_VIFTABLE].n_value); exit(0); } diff --git a/usr.bin/netstat/mroute.c b/usr.bin/netstat/mroute.c index db167a3074ad..cbff02ac3db7 100644 --- a/usr.bin/netstat/mroute.c +++ b/usr.bin/netstat/mroute.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)mroute.c 8.1 (Berkeley) 6/6/93 - * $Id: mroute.c,v 1.6 1995/03/28 17:26:42 jtc Exp $ + * $Id: mroute.c,v 1.7 1995/06/12 03:03:13 mycroft Exp $ */ /* @@ -49,6 +49,8 @@ #include #include +#include +#include #include #include #define _KERNEL @@ -59,21 +61,44 @@ #include #include "netstat.h" +char * +pktscale(n) + u_long n; +{ + static char buf[8]; + char t; + + if (n < 1024) + t = ' '; + else if (n < 1024 * 1024) { + t = 'k'; + n /= 1024; + } else { + t = 'm'; + n /= 1048576; + } + + sprintf(buf, "%u%c", n, t); + return (buf); +} + void -mroutepr(mrpaddr, mrtaddr, vifaddr) - u_long mrpaddr, mrtaddr, vifaddr; +mroutepr(mrpaddr, mfchashtbladdr, mfchashaddr, vifaddr) + u_long mrpaddr, mfchashtbladdr, mfchashaddr, vifaddr; { u_int mrtproto; - struct mrt *mrttable[MRTHASHSIZ]; + LIST_HEAD(, mfc) *mfchashtbl; + u_long mfchash; struct vif viftable[MAXVIFS]; - register struct mrt *mrt; - struct mrt smrt; + struct mfc *mfcp, mfc; register struct vif *v; register vifi_t vifi; - register struct in_addr *grp; - register int i, n; - register int banner_printed; - register int saved_nflag; + struct in_addr *grp; + int i; + int banner_printed; + int saved_nflag; + int numvifs; + int nmfc; /* No. of cache entries */ if (mrpaddr == 0) { printf("ip_mrtproto: symbol not in namelist\n"); @@ -82,7 +107,6 @@ mroutepr(mrpaddr, mrtaddr, vifaddr) kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto)); switch (mrtproto) { - case 0: printf("no multicast routing compiled into this system\n"); return; @@ -95,8 +119,12 @@ mroutepr(mrpaddr, mrtaddr, vifaddr) return; } - if (mrtaddr == 0) { - printf("mrttable: symbol not in namelist\n"); + if (mfchashtbladdr == 0) { + printf("mfchashtbl: symbol not in namelist\n"); + return; + } + if (mfchashaddr == 0) { + printf("mfchash: symbol not in namelist\n"); return; } if (vifaddr == 0) { @@ -109,64 +137,64 @@ mroutepr(mrpaddr, mrtaddr, vifaddr) kread(vifaddr, (char *)&viftable, sizeof(viftable)); banner_printed = 0; + numvifs = 0; + for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) { if (v->v_lcl_addr.s_addr == 0) continue; + numvifs = vifi; if (!banner_printed) { - printf("\nVirtual Interface Table\n%s%s", - " Vif Threshold Local-Address ", - "Remote-Address Groups\n"); + printf("\nVirtual Interface Table\n %s%s", + "Vif Thresh Limit Local-Address ", + "Remote-Address Pkt_in Pkt_out\n"); banner_printed = 1; } - printf(" %2u %3u %-15.15s", - vifi, v->v_threshold, routename(v->v_lcl_addr.s_addr)); - printf(" %-15.15s\n", (v->v_flags & VIFF_TUNNEL) ? - routename(v->v_rmt_addr.s_addr) : ""); - - n = v->v_lcl_grps_n; - grp = (struct in_addr *)malloc(n * sizeof(*grp)); - if (grp == NULL) { - printf("v_lcl_grps_n: malloc failed\n"); - return; - } - kread((u_long)v->v_lcl_grps, (caddr_t)grp, n * sizeof(*grp)); - for (i = 0; i < n; ++i) - printf("%51s %-15.15s\n", - "", routename((grp++)->s_addr)); - free(grp); + printf(" %3u %3u %5u %-15.15s", + vifi, v->v_threshold, v->v_rate_limit, + routename(v->v_lcl_addr.s_addr)); + printf(" %-15.15s %6u %7u\n", (v->v_flags & VIFF_TUNNEL) ? + routename(v->v_rmt_addr.s_addr) : "", + v->v_pkt_in, v->v_pkt_out); } if (!banner_printed) printf("\nVirtual Interface Table is empty\n"); - kread(mrtaddr, (char *)&mrttable, sizeof(mrttable)); + kread(mfchashtbladdr, (char *)&mfchashtbl, sizeof(mfchashtbl)); + kread(mfchashaddr, (char *)&mfchash, sizeof(mfchash)); banner_printed = 0; - for (i = 0; i < MRTHASHSIZ; ++i) { - for (mrt = mrttable[i]; mrt != NULL; mrt = mrt->mrt_next) { + nmfc = 0; + + for (i = 0; i <= mfchash; ++i) { + kread((u_long)&mfchashtbl[i], (char *)&mfcp, sizeof(mfcp)); + + for (; mfcp != 0; mfcp = mfc.mfc_hash.le_next) { if (!banner_printed) { - printf("\nMulticast Routing Table\n%s", - " Hash Origin-Subnet In-Vif Out-Vifs\n"); + printf("\nMulticast Forwarding Cache\n %s%s", + "Hash Origin Mcastgroup ", + "Traffic In-Vif Out-Vifs/Forw-ttl\n"); banner_printed = 1; } - kread((u_long)mrt, (char *)&smrt, sizeof(*mrt)); - mrt = &smrt; - 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 (VIFM_ISSET(vifi, mrt->mrt_children)) - printf(" %u%c", - vifi, - VIFM_ISSET(vifi, mrt->mrt_leaves) ? - '*' : ' '); + kread((u_long)mfcp, (char *)&mfc, sizeof(mfc)); + printf(" %3u %-15.15s", + i, routename(mfc.mfc_origin.s_addr)); + printf(" %-15.15s %7s %3u ", + routename(mfc.mfc_mcastgrp.s_addr), + pktscale(mfc.mfc_pkt_cnt), mfc.mfc_parent); + for (vifi = 0; vifi <= numvifs; ++vifi) + if (mfc.mfc_ttls[vifi]) + printf(" %u/%u", vifi, mfc.mfc_ttls[vifi]); + printf("\n"); + nmfc++; } } if (!banner_printed) - printf("\nMulticast Routing Table is empty\n"); + printf("\nMulticast Forwarding Cache is empty\n"); + else + printf("\nTotal no. of entries in cache: %d\n", nmfc); printf("\n"); nflag = saved_nflag; @@ -180,21 +208,21 @@ mrt_stats(mrpaddr, mstaddr) u_int mrtproto; struct mrtstat mrtstat; - if(mrpaddr == 0) { + if (mrpaddr == 0) { printf("ip_mrtproto: symbol not in namelist\n"); return; } kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto)); switch (mrtproto) { - case 0: + case 0: printf("no multicast routing compiled into this system\n"); return; - case IGMP_DVMRP: + case IGMP_DVMRP: break; - default: + default: printf("multicast routing protocol %u, unknown\n", mrtproto); return; } @@ -206,20 +234,26 @@ mrt_stats(mrpaddr, mstaddr) kread(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)); + mrtstat.mrts_no_route, plural(mrtstat.mrts_no_route)); + printf(" %10u upcall%s made to mrouted\n", + mrtstat.mrts_upcalls, plural(mrtstat.mrts_upcalls)); printf(" %10u datagram%s with malformed tunnel options\n", - mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel)); + 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 the wrong interface\n", - mrtstat.mrts_wrong_if, plural(mrtstat.mrts_wrong_if)); + 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)); + printf(" %10u datagram%s dropped due to upcall Q overflow\n", + mrtstat.mrts_upq_ovflw, plural(mrtstat.mrts_upq_ovflw)); + printf(" %10u datagram%s dropped due to upcall socket overflow\n", + mrtstat.mrts_upq_sockfull, plural(mrtstat.mrts_upq_sockfull)); + printf(" %10u datagram%s cleaned up by the cache\n", + mrtstat.mrts_cache_cleanups, plural(mrtstat.mrts_cache_cleanups)); + printf(" %10u datagram%s dropped selectively by ratelimiter\n", + mrtstat.mrts_drop_sel, plural(mrtstat.mrts_drop_sel)); + printf(" %10u datagram%s dropped - bucket Q overflow\n", + mrtstat.mrts_q_overflow, plural(mrtstat.mrts_q_overflow)); + printf(" %10u datagram%s dropped - larger than bkt size\n", + mrtstat.mrts_pkt2large, plural(mrtstat.mrts_pkt2large)); } diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index d514b985de09..38df96cc9b5f 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * from: @(#)netstat.h 8.2 (Berkeley) 1/4/94 - * $Id: netstat.h,v 1.2 1994/05/13 08:08:20 mycroft Exp $ + * $Id: netstat.h,v 1.3 1995/06/12 03:03:14 mycroft Exp $ */ #include @@ -106,5 +106,5 @@ void tp_protopr __P((u_long, char *)); void tp_inproto __P((u_long)); void tp_stats __P((caddr_t, caddr_t)); -void mroutepr __P((u_long, u_long, u_long)); +void mroutepr __P((u_long, u_long, u_long, u_long)); void mrt_stats __P((u_long, u_long));