1 /* 2 * Copyright (c) 1989 Stephen Deering 3 * Copyright (c) 1992, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Stephen Deering of Stanford University. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by the University of 20 * California, Berkeley and its contributors. 21 * 4. Neither the name of the University nor the names of its contributors 22 * may be used to endorse or promote products derived from this software 23 * without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 * 37 * from: @(#)mroute.c 8.1 (Berkeley) 6/6/93 38 * $Id: mroute.c,v 1.5 1994/06/09 16:08:46 brezak Exp $ 39 */ 40 41 /* 42 * Print DVMRP multicast routing structures and statistics. 43 * 44 * MROUTING 1.0 45 */ 46 47 #include <sys/param.h> 48 #include <sys/socket.h> 49 #include <sys/socketvar.h> 50 #include <sys/protosw.h> 51 52 #include <netinet/in.h> 53 #include <netinet/igmp.h> 54 #define KERNEL 1 55 #include <netinet/ip_mroute.h> 56 #undef KERNEL 57 58 #include <stdio.h> 59 #include <stdlib.h> 60 #include "netstat.h" 61 62 void 63 mroutepr(mrpaddr, mrtaddr, vifaddr) 64 u_long mrpaddr, mrtaddr, vifaddr; 65 { 66 u_int mrtproto; 67 struct mrt *mrttable[MRTHASHSIZ]; 68 struct vif viftable[MAXVIFS]; 69 register struct mrt *mrt; 70 struct mrt smrt; 71 register struct vif *v; 72 register vifi_t vifi; 73 register struct in_addr *grp; 74 register int i, n; 75 register int banner_printed; 76 register int saved_nflag; 77 78 if (mrpaddr == 0) { 79 printf("ip_mrtproto: symbol not in namelist\n"); 80 return; 81 } 82 83 kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto)); 84 switch (mrtproto) { 85 86 case 0: 87 printf("no multicast routing compiled into this system\n"); 88 return; 89 90 case IGMP_DVMRP: 91 break; 92 93 default: 94 printf("multicast routing protocol %u, unknown\n", mrtproto); 95 return; 96 } 97 98 if (mrtaddr == 0) { 99 printf("mrttable: symbol not in namelist\n"); 100 return; 101 } 102 if (vifaddr == 0) { 103 printf("viftable: symbol not in namelist\n"); 104 return; 105 } 106 107 saved_nflag = nflag; 108 nflag = 1; 109 110 kread(vifaddr, (char *)&viftable, sizeof(viftable)); 111 banner_printed = 0; 112 for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) { 113 if (v->v_lcl_addr.s_addr == 0) 114 continue; 115 116 if (!banner_printed) { 117 printf("\nVirtual Interface Table\n%s%s", 118 " Vif Threshold Local-Address ", 119 "Remote-Address Groups\n"); 120 banner_printed = 1; 121 } 122 123 printf(" %2u %3u %-15.15s", 124 vifi, v->v_threshold, routename(v->v_lcl_addr.s_addr)); 125 printf(" %-15.15s\n", (v->v_flags & VIFF_TUNNEL) ? 126 routename(v->v_rmt_addr.s_addr) : ""); 127 128 n = v->v_lcl_grps_n; 129 grp = (struct in_addr *)malloc(n * sizeof(*grp)); 130 if (grp == NULL) { 131 printf("v_lcl_grps_n: malloc failed\n"); 132 return; 133 } 134 kread((u_long)v->v_lcl_grps, (caddr_t)grp, n * sizeof(*grp)); 135 for (i = 0; i < n; ++i) 136 printf("%51s %-15.15s\n", 137 "", routename((grp++)->s_addr)); 138 free(grp); 139 } 140 if (!banner_printed) 141 printf("\nVirtual Interface Table is empty\n"); 142 143 kread(mrtaddr, (char *)&mrttable, sizeof(mrttable)); 144 banner_printed = 0; 145 for (i = 0; i < MRTHASHSIZ; ++i) { 146 for (mrt = mrttable[i]; mrt != NULL; mrt = mrt->mrt_next) { 147 if (!banner_printed) { 148 printf("\nMulticast Routing Table\n%s", 149 " Hash Origin-Subnet In-Vif Out-Vifs\n"); 150 banner_printed = 1; 151 } 152 153 kread((u_long)mrt, (char *)&smrt, sizeof(*mrt)); 154 mrt = &smrt; 155 printf(" %3u %-15.15s %2u ", 156 i, netname(mrt->mrt_origin.s_addr, 157 ntohl(mrt->mrt_originmask.s_addr)), 158 mrt->mrt_parent); 159 for (vifi = 0; vifi < MAXVIFS; ++vifi) 160 if (VIFM_ISSET(vifi, mrt->mrt_children)) 161 printf(" %u%c", 162 vifi, 163 VIFM_ISSET(vifi, mrt->mrt_leaves) ? 164 '*' : ' '); 165 printf("\n"); 166 } 167 } 168 if (!banner_printed) 169 printf("\nMulticast Routing Table is empty\n"); 170 171 printf("\n"); 172 nflag = saved_nflag; 173 } 174 175 176 void 177 mrt_stats(mrpaddr, mstaddr) 178 u_long mrpaddr, mstaddr; 179 { 180 u_int mrtproto; 181 struct mrtstat mrtstat; 182 183 if(mrpaddr == 0) { 184 printf("ip_mrtproto: symbol not in namelist\n"); 185 return; 186 } 187 188 kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto)); 189 switch (mrtproto) { 190 case 0: 191 printf("no multicast routing compiled into this system\n"); 192 return; 193 194 case IGMP_DVMRP: 195 break; 196 197 default: 198 printf("multicast routing protocol %u, unknown\n", mrtproto); 199 return; 200 } 201 202 if (mstaddr == 0) { 203 printf("mrtstat: symbol not in namelist\n"); 204 return; 205 } 206 207 kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat)); 208 printf("multicast routing:\n"); 209 printf(" %10u multicast route lookup%s\n", 210 mrtstat.mrts_mrt_lookups, plural(mrtstat.mrts_mrt_lookups)); 211 printf(" %10u multicast route cache miss%s\n", 212 mrtstat.mrts_mrt_misses, plurales(mrtstat.mrts_mrt_misses)); 213 printf(" %10u group address lookup%s\n", 214 mrtstat.mrts_grp_lookups, plural(mrtstat.mrts_grp_lookups)); 215 printf(" %10u group address cache miss%s\n", 216 mrtstat.mrts_grp_misses, plurales(mrtstat.mrts_grp_misses)); 217 printf(" %10u datagram%s with no route for origin\n", 218 mrtstat.mrts_no_route, plural(mrtstat.mrts_no_route)); 219 printf(" %10u datagram%s with malformed tunnel options\n", 220 mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel)); 221 printf(" %10u datagram%s with no room for tunnel options\n", 222 mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel)); 223 printf(" %10u datagram%s arrived on the wrong interface\n", 224 mrtstat.mrts_wrong_if, plural(mrtstat.mrts_wrong_if)); 225 } 226