1 /* $NetBSD: mroute.c,v 1.15 2002/06/02 15:45:58 itojun 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 #include <sys/cdefs.h> 43 #ifndef lint 44 #if 0 45 static char sccsid[] = "from: @(#)mroute.c 8.1 (Berkeley) 6/6/93"; 46 #else 47 __RCSID("$NetBSD: mroute.c,v 1.15 2002/06/02 15:45:58 itojun Exp $"); 48 #endif 49 #endif /* not lint */ 50 51 /* 52 * Print DVMRP multicast routing structures and statistics. 53 * 54 * MROUTING 1.0 55 */ 56 57 #include <sys/param.h> 58 #include <sys/socket.h> 59 #include <sys/socketvar.h> 60 #include <sys/protosw.h> 61 62 #include <net/if.h> 63 #include <net/route.h> 64 #include <netinet/in.h> 65 #include <netinet/igmp.h> 66 #define _KERNEL 67 #include <netinet/ip_mroute.h> 68 #undef _KERNEL 69 70 #include <stdio.h> 71 #include <stdlib.h> 72 #include "netstat.h" 73 74 static char *pktscale __P((u_long)); 75 76 static char * 77 pktscale(n) 78 u_long n; 79 { 80 static char buf[8]; 81 char t; 82 83 if (n < 1024) 84 t = ' '; 85 else if (n < 1024 * 1024) { 86 t = 'k'; 87 n /= 1024; 88 } else { 89 t = 'm'; 90 n /= 1048576; 91 } 92 93 (void)snprintf(buf, sizeof buf, "%lu%c", n, t); 94 return (buf); 95 } 96 97 void 98 mroutepr(mrpaddr, mfchashtbladdr, mfchashaddr, vifaddr) 99 u_long mrpaddr, mfchashtbladdr, mfchashaddr, vifaddr; 100 { 101 u_int mrtproto; 102 LIST_HEAD(, mfc) *mfchashtbl; 103 u_long mfchash; 104 struct vif viftable[MAXVIFS]; 105 struct mfc *mfcp, mfc; 106 struct vif *v; 107 vifi_t vifi; 108 int i; 109 int banner_printed; 110 int saved_numeric_addr; 111 int numvifs; 112 int nmfc; /* No. of cache entries */ 113 114 if (mrpaddr == 0) { 115 printf("ip_mrtproto: symbol not in namelist\n"); 116 return; 117 } 118 119 kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto)); 120 switch (mrtproto) { 121 case 0: 122 printf("no multicast routing compiled into this system\n"); 123 return; 124 125 case IGMP_DVMRP: 126 break; 127 128 default: 129 printf("multicast routing protocol %u, unknown\n", mrtproto); 130 return; 131 } 132 133 if (mfchashtbladdr == 0) { 134 printf("mfchashtbl: symbol not in namelist\n"); 135 return; 136 } 137 if (mfchashaddr == 0) { 138 printf("mfchash: symbol not in namelist\n"); 139 return; 140 } 141 if (vifaddr == 0) { 142 printf("viftable: symbol not in namelist\n"); 143 return; 144 } 145 146 saved_numeric_addr = numeric_addr; 147 numeric_addr = 1; 148 149 kread(vifaddr, (char *)&viftable, sizeof(viftable)); 150 banner_printed = 0; 151 numvifs = 0; 152 153 for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) { 154 if (v->v_lcl_addr.s_addr == 0) 155 continue; 156 numvifs = vifi; 157 158 if (!banner_printed) { 159 printf("\nVirtual Interface Table\n %s%s", 160 "Vif Thresh Limit Local-Address ", 161 "Remote-Address Pkt_in Pkt_out\n"); 162 banner_printed = 1; 163 } 164 165 printf(" %3u %3u %5u %-15.15s", 166 vifi, v->v_threshold, v->v_rate_limit, 167 routename(v->v_lcl_addr.s_addr)); 168 printf(" %-15.15s %6lu %7lu\n", (v->v_flags & VIFF_TUNNEL) ? 169 routename(v->v_rmt_addr.s_addr) : "", 170 v->v_pkt_in, v->v_pkt_out); 171 } 172 if (!banner_printed) 173 printf("\nVirtual Interface Table is empty\n"); 174 175 kread(mfchashtbladdr, (char *)&mfchashtbl, sizeof(mfchashtbl)); 176 kread(mfchashaddr, (char *)&mfchash, sizeof(mfchash)); 177 banner_printed = 0; 178 nmfc = 0; 179 180 if (mfchashtbl != 0) 181 for (i = 0; i <= mfchash; ++i) { 182 kread((u_long)&mfchashtbl[i], (char *)&mfcp, sizeof(mfcp)); 183 184 for (; mfcp != 0; mfcp = mfc.mfc_hash.le_next) { 185 if (!banner_printed) { 186 printf("\nMulticast Forwarding Cache\n %s%s", 187 "Hash Origin Mcastgroup ", 188 "Traffic In-Vif Out-Vifs/Forw-ttl\n"); 189 banner_printed = 1; 190 } 191 192 kread((u_long)mfcp, (char *)&mfc, sizeof(mfc)); 193 printf(" %3u %-15.15s", 194 i, routename(mfc.mfc_origin.s_addr)); 195 printf(" %-15.15s %7s %3u ", 196 routename(mfc.mfc_mcastgrp.s_addr), 197 pktscale(mfc.mfc_pkt_cnt), mfc.mfc_parent); 198 for (vifi = 0; vifi <= numvifs; ++vifi) 199 if (mfc.mfc_ttls[vifi]) 200 printf(" %u/%u", vifi, mfc.mfc_ttls[vifi]); 201 202 printf("\n"); 203 nmfc++; 204 } 205 } 206 if (!banner_printed) 207 printf("\nMulticast Forwarding Cache is empty\n"); 208 else 209 printf("\nTotal no. of entries in cache: %d\n", nmfc); 210 211 printf("\n"); 212 numeric_addr = saved_numeric_addr; 213 } 214 215 216 void 217 mrt_stats(mrpaddr, mstaddr) 218 u_long mrpaddr, mstaddr; 219 { 220 u_int mrtproto; 221 struct mrtstat mrtstat; 222 223 if (mrpaddr == 0) { 224 printf("ip_mrtproto: symbol not in namelist\n"); 225 return; 226 } 227 228 kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto)); 229 switch (mrtproto) { 230 case 0: 231 printf("no multicast routing compiled into this system\n"); 232 return; 233 234 case IGMP_DVMRP: 235 break; 236 237 default: 238 printf("multicast routing protocol %u, unknown\n", mrtproto); 239 return; 240 } 241 242 if (mstaddr == 0) { 243 printf("mrtstat: symbol not in namelist\n"); 244 return; 245 } 246 247 kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat)); 248 printf("multicast routing:\n"); 249 printf("\t%lu datagram%s with no route for origin\n", 250 mrtstat.mrts_no_route, plural(mrtstat.mrts_no_route)); 251 printf("\t%lu upcall%s made to mrouted\n", 252 mrtstat.mrts_upcalls, plural(mrtstat.mrts_upcalls)); 253 printf("\t%lu datagram%s with malformed tunnel options\n", 254 mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel)); 255 printf("\t%lu datagram%s with no room for tunnel options\n", 256 mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel)); 257 printf("\t%lu datagram%s arrived on wrong interface\n", 258 mrtstat.mrts_wrong_if, plural(mrtstat.mrts_wrong_if)); 259 printf("\t%lu datagram%s dropped due to upcall Q overflow\n", 260 mrtstat.mrts_upq_ovflw, plural(mrtstat.mrts_upq_ovflw)); 261 printf("\t%lu datagram%s dropped due to upcall socket overflow\n", 262 mrtstat.mrts_upq_sockfull, plural(mrtstat.mrts_upq_sockfull)); 263 printf("\t%lu datagram%s cleaned up by the cache\n", 264 mrtstat.mrts_cache_cleanups, plural(mrtstat.mrts_cache_cleanups)); 265 printf("\t%lu datagram%s dropped selectively by ratelimiter\n", 266 mrtstat.mrts_drop_sel, plural(mrtstat.mrts_drop_sel)); 267 printf("\t%lu datagram%s dropped - bucket Q overflow\n", 268 mrtstat.mrts_q_overflow, plural(mrtstat.mrts_q_overflow)); 269 printf("\t%lu datagram%s dropped - larger than bkt size\n", 270 mrtstat.mrts_pkt2large, plural(mrtstat.mrts_pkt2large)); 271 } 272