Home | History | Annotate | Line # | Download | only in netstat
mroute.c revision 1.11
      1 /*	$NetBSD: mroute.c,v 1.11 1997/04/03 04:46:50 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1989 Stephen Deering
      5  * Copyright (c) 1992, 1993
      6  *	The Regents of the University of California.  All rights reserved.
      7  *
      8  * This code is derived from software contributed to Berkeley by
      9  * Stephen Deering of Stanford University.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the University of
     22  *	California, Berkeley and its contributors.
     23  * 4. Neither the name of the University nor the names of its contributors
     24  *    may be used to endorse or promote products derived from this software
     25  *    without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     37  * SUCH DAMAGE.
     38  *
     39  *	from: @(#)mroute.c	8.1 (Berkeley) 6/6/93
     40  */
     41 
     42 /*
     43  * Print DVMRP multicast routing structures and statistics.
     44  *
     45  * MROUTING 1.0
     46  */
     47 
     48 #include <sys/param.h>
     49 #include <sys/socket.h>
     50 #include <sys/socketvar.h>
     51 #include <sys/protosw.h>
     52 
     53 #include <net/if.h>
     54 #include <net/route.h>
     55 #include <netinet/in.h>
     56 #include <netinet/igmp.h>
     57 #define _KERNEL
     58 #include <netinet/ip_mroute.h>
     59 #undef _KERNEL
     60 
     61 #include <stdio.h>
     62 #include <stdlib.h>
     63 #include "netstat.h"
     64 
     65 static char *pktscale __P((u_long));
     66 
     67 static char *
     68 pktscale(n)
     69 	u_long n;
     70 {
     71 	static char buf[8];
     72 	char t;
     73 
     74 	if (n < 1024)
     75 		t = ' ';
     76 	else if (n < 1024 * 1024) {
     77 		t = 'k';
     78 		n /= 1024;
     79 	} else {
     80 		t = 'm';
     81 		n /= 1048576;
     82 	}
     83 
     84 	sprintf(buf, "%lu%c", n, t);
     85 	return (buf);
     86 }
     87 
     88 void
     89 mroutepr(mrpaddr, mfchashtbladdr, mfchashaddr, vifaddr)
     90 	u_long mrpaddr, mfchashtbladdr, mfchashaddr, vifaddr;
     91 {
     92 	u_int mrtproto;
     93 	LIST_HEAD(, mfc) *mfchashtbl;
     94 	u_long mfchash;
     95 	struct vif viftable[MAXVIFS];
     96 	struct mfc *mfcp, mfc;
     97 	register struct vif *v;
     98 	register vifi_t vifi;
     99 	int i;
    100 	int banner_printed;
    101 	int saved_nflag;
    102 	int numvifs;
    103 	int nmfc;		/* No. of cache entries */
    104 
    105 	if (mrpaddr == 0) {
    106 		printf("ip_mrtproto: symbol not in namelist\n");
    107 		return;
    108 	}
    109 
    110 	kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
    111 	switch (mrtproto) {
    112 	case 0:
    113 		printf("no multicast routing compiled into this system\n");
    114 		return;
    115 
    116 	case IGMP_DVMRP:
    117 		break;
    118 
    119 	default:
    120 		printf("multicast routing protocol %u, unknown\n", mrtproto);
    121 		return;
    122 	}
    123 
    124 	if (mfchashtbladdr == 0) {
    125 		printf("mfchashtbl: symbol not in namelist\n");
    126 		return;
    127 	}
    128 	if (mfchashaddr == 0) {
    129 		printf("mfchash: symbol not in namelist\n");
    130 		return;
    131 	}
    132 	if (vifaddr == 0) {
    133 		printf("viftable: symbol not in namelist\n");
    134 		return;
    135 	}
    136 
    137 	saved_nflag = nflag;
    138 	nflag = 1;
    139 
    140 	kread(vifaddr, (char *)&viftable, sizeof(viftable));
    141 	banner_printed = 0;
    142 	numvifs = 0;
    143 
    144 	for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) {
    145 		if (v->v_lcl_addr.s_addr == 0)
    146 			continue;
    147 		numvifs = vifi;
    148 
    149 		if (!banner_printed) {
    150 			printf("\nVirtual Interface Table\n %s%s",
    151 			    "Vif  Thresh  Limit  Local-Address    ",
    152 			    "Remote-Address   Pkt_in  Pkt_out\n");
    153 			banner_printed = 1;
    154 		}
    155 
    156 		printf(" %3u     %3u  %5u  %-15.15s",
    157 		    vifi, v->v_threshold, v->v_rate_limit,
    158 		    routename(v->v_lcl_addr.s_addr));
    159 		printf("  %-15.15s  %6lu  %7lu\n", (v->v_flags & VIFF_TUNNEL) ?
    160 		    routename(v->v_rmt_addr.s_addr) : "",
    161 		    v->v_pkt_in, v->v_pkt_out);
    162 	}
    163 	if (!banner_printed)
    164 		printf("\nVirtual Interface Table is empty\n");
    165 
    166 	kread(mfchashtbladdr, (char *)&mfchashtbl, sizeof(mfchashtbl));
    167 	kread(mfchashaddr, (char *)&mfchash, sizeof(mfchash));
    168 	banner_printed = 0;
    169 	nmfc = 0;
    170 
    171 	if (mfchashtbl != 0)
    172 	for (i = 0; i <= mfchash; ++i) {
    173 		kread((u_long)&mfchashtbl[i], (char *)&mfcp, sizeof(mfcp));
    174 
    175 		for (; mfcp != 0; mfcp = mfc.mfc_hash.le_next) {
    176 			if (!banner_printed) {
    177 				printf("\nMulticast Forwarding Cache\n %s%s",
    178 				    "Hash  Origin           Mcastgroup       ",
    179 				    "Traffic  In-Vif  Out-Vifs/Forw-ttl\n");
    180 				banner_printed = 1;
    181 			}
    182 
    183 			kread((u_long)mfcp, (char *)&mfc, sizeof(mfc));
    184 			printf("  %3u  %-15.15s",
    185 			    i, routename(mfc.mfc_origin.s_addr));
    186 			printf("  %-15.15s  %7s     %3u ",
    187 			    routename(mfc.mfc_mcastgrp.s_addr),
    188 			    pktscale(mfc.mfc_pkt_cnt), mfc.mfc_parent);
    189 			for (vifi = 0; vifi <= numvifs; ++vifi)
    190 				if (mfc.mfc_ttls[vifi])
    191 					printf(" %u/%u", vifi, mfc.mfc_ttls[vifi]);
    192 
    193 			printf("\n");
    194 			nmfc++;
    195 		}
    196 	}
    197 	if (!banner_printed)
    198 		printf("\nMulticast Forwarding Cache is empty\n");
    199 	else
    200 		printf("\nTotal no. of entries in cache: %d\n", nmfc);
    201 
    202 	printf("\n");
    203 	nflag = saved_nflag;
    204 }
    205 
    206 
    207 void
    208 mrt_stats(mrpaddr, mstaddr)
    209 	u_long mrpaddr, mstaddr;
    210 {
    211 	u_int mrtproto;
    212 	struct mrtstat mrtstat;
    213 
    214 	if (mrpaddr == 0) {
    215 		printf("ip_mrtproto: symbol not in namelist\n");
    216 		return;
    217 	}
    218 
    219 	kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
    220 	switch (mrtproto) {
    221 	case 0:
    222 		printf("no multicast routing compiled into this system\n");
    223 		return;
    224 
    225 	case IGMP_DVMRP:
    226 		break;
    227 
    228 	default:
    229 		printf("multicast routing protocol %u, unknown\n", mrtproto);
    230 		return;
    231 	}
    232 
    233 	if (mstaddr == 0) {
    234 		printf("mrtstat: symbol not in namelist\n");
    235 		return;
    236 	}
    237 
    238 	kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
    239 	printf("multicast routing:\n");
    240 	printf("\t%ld datagram%s with no route for origin\n",
    241 	    mrtstat.mrts_no_route, plural(mrtstat.mrts_no_route));
    242 	printf("\t%ld upcall%s made to mrouted\n",
    243 	    mrtstat.mrts_upcalls, plural(mrtstat.mrts_upcalls));
    244 	printf("\t%ld datagram%s with malformed tunnel options\n",
    245 	    mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel));
    246 	printf("\t%ld datagram%s with no room for tunnel options\n",
    247 	    mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel));
    248 	printf("\t%ld datagram%s arrived on wrong interface\n",
    249 	    mrtstat.mrts_wrong_if, plural(mrtstat.mrts_wrong_if));
    250 	printf("\t%ld datagram%s dropped due to upcall Q overflow\n",
    251 	    mrtstat.mrts_upq_ovflw, plural(mrtstat.mrts_upq_ovflw));
    252 	printf("\t%ld datagram%s dropped due to upcall socket overflow\n",
    253 	    mrtstat.mrts_upq_sockfull, plural(mrtstat.mrts_upq_sockfull));
    254 	printf("\t%ld datagram%s cleaned up by the cache\n",
    255 	    mrtstat.mrts_cache_cleanups, plural(mrtstat.mrts_cache_cleanups));
    256 	printf("\t%ld datagram%s dropped selectively by ratelimiter\n",
    257 	    mrtstat.mrts_drop_sel, plural(mrtstat.mrts_drop_sel));
    258 	printf("\t%ld datagram%s dropped - bucket Q overflow\n",
    259 	    mrtstat.mrts_q_overflow, plural(mrtstat.mrts_q_overflow));
    260 	printf("\t%ld datagram%s dropped - larger than bkt size\n",
    261 	    mrtstat.mrts_pkt2large, plural(mrtstat.mrts_pkt2large));
    262 }
    263