Home | History | Annotate | Line # | Download | only in netstat
mroute.c revision 1.1
      1 /*
      2  * Print DVMRP multicast routing structures and statistics.
      3  *
      4  * MROUTING 1.0
      5  */
      6 
      7 #ifndef lint
      8 static char rcsid[] = "$Id: mroute.c,v 1.1 1994/01/11 19:42:55 brezak Exp $";
      9 #endif /* not lint */
     10 
     11 #include <stdio.h>
     12 #include <sys/param.h>
     13 #include <sys/mbuf.h>
     14 #include <netinet/in.h>
     15 #include <netinet/igmp.h>
     16 #define KERNEL 1
     17 struct socket;	/* shut up warning */
     18 struct ip;
     19 #include <netinet/ip_mroute.h>
     20 #undef KERNEL
     21 
     22 extern int kmem;
     23 extern int nflag;
     24 extern char *routename();
     25 extern char *netname();
     26 extern char *plural();
     27 
     28 char *plurales(n)
     29 	int n;
     30 {
     31 	return (n == 1? "" : "es");
     32 }
     33 
     34 mroutepr(mrpaddr, mrtaddr, vifaddr)
     35 	off_t mrpaddr, mrtaddr, vifaddr;
     36 {
     37 	u_int mrtproto;
     38 #if BSD >= 199006
     39 	struct mrt *mrttable[MRTHASHSIZ];
     40 	struct mrt *mp;
     41 	struct mrt mb;
     42 	struct mrt *mrt = &mb;
     43 #else
     44 	struct mbuf *mrttable[MRTHASHSIZ];
     45 	struct mbuf *mp;
     46 	struct mbuf mb;
     47 	struct mrt *mrt = mtod(&mb, struct mrt *);
     48 #endif
     49 	struct vif viftable[MAXVIFS];
     50 	register struct vif *v;
     51 	register vifi_t vifi;
     52 	struct in_addr *grp;
     53 	int i, n;
     54 	int banner_printed;
     55 	int saved_nflag;
     56 
     57 	if(mrpaddr == 0) {
     58 		printf("ip_mrtproto: symbol not in namelist\n");
     59 		return;
     60 	}
     61 
     62 	kvm_read(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
     63 	switch (mrtproto) {
     64 	    case 0:
     65 		printf("no multicast routing compiled into this system\n");
     66 		return;
     67 
     68 	    case IGMP_DVMRP:
     69 		break;
     70 
     71 	    default:
     72 		printf("multicast routing protocol %u, unknown\n", mrtproto);
     73 		return;
     74 	}
     75 
     76 	if (mrtaddr == 0) {
     77 		printf("mrttable: symbol not in namelist\n");
     78 		return;
     79 	}
     80 	if (vifaddr == 0) {
     81 		printf("viftable: symbol not in namelist\n");
     82 		return;
     83 	}
     84 
     85 	saved_nflag = nflag;
     86 	nflag = 1;
     87 
     88 	kvm_read(vifaddr, (char *)viftable, sizeof(viftable));
     89 	banner_printed = 0;
     90 	for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) {
     91 		struct in_addr v_lcl_grps[1024];
     92 
     93 		if (v->v_lcl_addr.s_addr == 0) continue;
     94 
     95 		if (!banner_printed) {
     96 			printf("\nVirtual Interface Table\n%s%s",
     97 			       " Vif   Threshold   Local-Address   ",
     98 			       "Remote-Address   Groups\n");
     99 			banner_printed = 1;
    100 		}
    101 
    102 		printf(" %2u       %3u      %-15.15s",
    103 			vifi, v->v_threshold, routename(v->v_lcl_addr));
    104 		printf(" %-15.15s\n",
    105 			(v->v_flags & VIFF_TUNNEL) ?
    106 				routename(v->v_rmt_addr) : "");
    107 
    108 		n = v->v_lcl_grps_n;
    109 		if (n == 0)
    110 			continue;
    111 		if (n < 0 || n > 1024)
    112 			printf("[v_lcl_grps_n = %d!]\n", n);
    113 
    114 		kvm_read(v->v_lcl_grps, (char *)v_lcl_grps,
    115 			 n * sizeof(struct in_addr));
    116 		for (i = 0; i < n; ++i)
    117 			printf("%51s %-15.15s\n", "",
    118 			       routename(v_lcl_grps[i]));
    119 	}
    120 	if (!banner_printed) printf("\nVirtual Interface Table is empty\n");
    121 
    122 	kvm_read(mrtaddr, (char *)mrttable, sizeof(mrttable));
    123 	banner_printed = 0;
    124 	for (i = 0; i < MRTHASHSIZ; ++i) {
    125 	    for (mp = mrttable[i]; mp != NULL;
    126 #if BSD >= 199006
    127 		 mp = mb.mrt_next
    128 #else
    129 		 mp = mb.m_next
    130 #endif
    131 		 ) {
    132 
    133 		if (!banner_printed) {
    134 			printf("\nMulticast Routing Table\n%s",
    135 			       " Hash  Origin-Subnet  In-Vif  Out-Vifs\n");
    136 			banner_printed = 1;
    137 		}
    138 		kvm_read(mp, (char *)&mb, sizeof(mb));
    139 
    140 
    141 		printf(" %3u   %-15.15s  %2u   ",
    142 			i,
    143 			netname(mrt->mrt_origin.s_addr,
    144 				ntohl(mrt->mrt_originmask.s_addr)),
    145 			mrt->mrt_parent);
    146 		for (vifi = 0; vifi < MAXVIFS; ++vifi) {
    147 			if (viftable[vifi].v_lcl_addr.s_addr) {
    148 				if (VIFM_ISSET(vifi, mrt->mrt_children)) {
    149 					printf(" %u%c",
    150 						vifi,
    151 						VIFM_ISSET(vifi,
    152 						  mrt->mrt_leaves) ?
    153 						    '*' : ' ');
    154 				} else
    155 					printf("   ");
    156 			}
    157 		}
    158 		printf("\n");
    159 	    }
    160 	}
    161 	if (!banner_printed) printf("\nMulticast Routing Table is empty\n");
    162 
    163 	printf("\n");
    164 	nflag = saved_nflag;
    165 }
    166 
    167 
    168 mrt_stats(mrpaddr, mstaddr)
    169 	off_t mrpaddr, mstaddr;
    170 {
    171 	u_int mrtproto;
    172 	struct mrtstat mrtstat;
    173 
    174 	if(mrpaddr == 0) {
    175 		printf("ip_mrtproto: symbol not in namelist\n");
    176 		return;
    177 	}
    178 
    179 	kvm_read(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
    180 	switch (mrtproto) {
    181 	    case 0:
    182 		printf("no multicast routing compiled into this system\n");
    183 		return;
    184 
    185 	    case IGMP_DVMRP:
    186 		break;
    187 
    188 	    default:
    189 		printf("multicast routing protocol %u, unknown\n", mrtproto);
    190 		return;
    191 	}
    192 
    193 	if (mstaddr == 0) {
    194 		printf("mrtstat: symbol not in namelist\n");
    195 		return;
    196 	}
    197 
    198 	kvm_read(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
    199 	printf("multicast routing:\n");
    200 	printf(" %10u multicast route lookup%s\n",
    201 	  mrtstat.mrts_mrt_lookups, plural(mrtstat.mrts_mrt_lookups));
    202 	printf(" %10u multicast route cache miss%s\n",
    203 	  mrtstat.mrts_mrt_misses, plurales(mrtstat.mrts_mrt_misses));
    204 	printf(" %10u group address lookup%s\n",
    205 	  mrtstat.mrts_grp_lookups, plural(mrtstat.mrts_grp_lookups));
    206 	printf(" %10u group address cache miss%s\n",
    207 	  mrtstat.mrts_grp_misses, plurales(mrtstat.mrts_grp_misses));
    208 	printf(" %10u datagram%s with no route for origin\n",
    209 	  mrtstat.mrts_no_route, plural(mrtstat.mrts_no_route));
    210 	printf(" %10u datagram%s with malformed tunnel options\n",
    211 	  mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel));
    212 	printf(" %10u datagram%s with no room for tunnel options\n",
    213 	  mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel));
    214 	printf(" %10u datagram%s arrived on wrong interface\n",
    215 	  mrtstat.mrts_wrong_if, plural(mrtstat.mrts_wrong_if));
    216 }
    217