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 * @(#)mroute.c 8.2 (Berkeley) 4/28/95 38 */ 39 40 /* 41 * Print DVMRP multicast routing structures and statistics. 42 * 43 * MROUTING 1.0 44 */ 45 46 #include <sys/param.h> 47 #include <sys/queue.h> 48 #include <sys/socket.h> 49 #include <sys/socketvar.h> 50 #include <sys/protosw.h> 51 #include <sys/mbuf.h> 52 53 #include <net/if.h> 54 #include <netinet/in.h> 55 #include <netinet/igmp.h> 56 #include <net/route.h> 57 #define KERNEL 1 /* XXX bogus! */ 58 #include <netinet/ip_mroute.h> 59 #undef KERNEL 60 61 #include <stdio.h> 62 #include <stdlib.h> 63 #include "netstat.h" 64 65 void 66 mroutepr(mrpaddr, mfcaddr, vifaddr) 67 u_long mrpaddr, mfcaddr, vifaddr; 68 { 69 u_int mrtproto; 70 struct mbuf *mfctable[MFCTBLSIZ]; 71 struct vif viftable[MAXVIFS]; 72 struct mbuf mb, *m; 73 struct mfc smfc; 74 register struct vif *v; 75 register vifi_t vifi; 76 register struct in_addr *grp; 77 register int i, n; 78 register int banner_printed; 79 register int saved_nflag; 80 vifi_t maxvif; 81 82 if (mrpaddr == 0) { 83 printf("ip_mrtproto: symbol not in namelist\n"); 84 return; 85 } 86 87 kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto)); 88 switch (mrtproto) { 89 90 case 0: 91 printf("no multicast routing compiled into this system\n"); 92 return; 93 94 case IGMP_DVMRP: 95 break; 96 97 default: 98 printf("multicast routing protocol %u, unknown\n", mrtproto); 99 return; 100 } 101 102 if (mfcaddr == 0) { 103 printf("mfctable: symbol not in namelist\n"); 104 return; 105 } 106 if (vifaddr == 0) { 107 printf("viftable: symbol not in namelist\n"); 108 return; 109 } 110 111 saved_nflag = nflag; 112 nflag = 1; 113 114 kread(vifaddr, (char *)&viftable, sizeof(viftable)); 115 banner_printed = 0; 116 for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) { 117 if (v->v_lcl_addr.s_addr == 0) 118 continue; 119 120 maxvif = vifi; 121 if (!banner_printed) { 122 printf("\nVirtual Interface Table\n" 123 " Vif Thresh Rate Local-Address " 124 "Remote-Address Pkts-In Pkts-Out\n"); 125 banner_printed = 1; 126 } 127 128 printf(" %2u %6u %4d %-15.15s", 129 vifi, v->v_threshold, v->v_rate_limit, 130 routename(v->v_lcl_addr.s_addr)); 131 printf(" %-15.15s", (v->v_flags & VIFF_TUNNEL) ? 132 routename(v->v_rmt_addr.s_addr) : ""); 133 134 printf(" %9lu %9lu\n", v->v_pkt_in, v->v_pkt_out); 135 } 136 if (!banner_printed) 137 printf("\nVirtual Interface Table is empty\n"); 138 139 kread(mfcaddr, (char *)&mfctable, sizeof(mfctable)); 140 banner_printed = 0; 141 for (i = 0; i < MFCTBLSIZ; ++i) { 142 m = mfctable[i]; 143 while(m) { 144 kread((u_long)m, (char *)&mb, sizeof mb); 145 m = &mb; 146 147 if (!banner_printed) { 148 printf("\nMulticast Forwarding Cache\n" 149 " Origin Group " 150 " Packets In-Vif Out-Vifs:Ttls\n"); 151 banner_printed = 1; 152 } 153 154 kread((u_long)mtod(m, char *), 155 (char *)&smfc, sizeof smfc); 156 printf(" %-15.15s", routename(smfc.mfc_origin.s_addr)); 157 printf(" %-15.15s", routename(smfc.mfc_mcastgrp.s_addr)); 158 printf(" %9lu", smfc.mfc_pkt_cnt); 159 printf(" %3d ", smfc.mfc_parent); 160 for (vifi = 0; vifi <= maxvif; vifi++) { 161 if (smfc.mfc_ttls[vifi] > 0) 162 printf(" %u:%u", vifi, 163 smfc.mfc_ttls[vifi]); 164 } 165 printf("\n"); 166 m = m->m_act; 167 } 168 } 169 if (!banner_printed) 170 printf("\nMulticast Routing Table is empty\n"); 171 172 printf("\n"); 173 nflag = saved_nflag; 174 } 175 176 177 void 178 mrt_stats(mrpaddr, mstaddr) 179 u_long mrpaddr, mstaddr; 180 { 181 u_int mrtproto; 182 struct mrtstat mrtstat; 183 184 if(mrpaddr == 0) { 185 printf("ip_mrtproto: symbol not in namelist\n"); 186 return; 187 } 188 189 kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto)); 190 switch (mrtproto) { 191 case 0: 192 printf("no multicast routing compiled into this system\n"); 193 return; 194 195 case IGMP_DVMRP: 196 break; 197 198 default: 199 printf("multicast routing protocol %u, unknown\n", mrtproto); 200 return; 201 } 202 203 if (mstaddr == 0) { 204 printf("mrtstat: symbol not in namelist\n"); 205 return; 206 } 207 208 kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat)); 209 printf("multicast forwarding:\n"); 210 printf(" %10u multicast forwarding cache lookup%s\n", 211 mrtstat.mrts_mfc_lookups, plural(mrtstat.mrts_mfc_lookups)); 212 printf(" %10u multicast forwarding cache miss%s\n", 213 mrtstat.mrts_mfc_misses, plurales(mrtstat.mrts_mfc_misses)); 214 printf(" %10u upcall%s to mrouted\n", 215 mrtstat.mrts_upcalls, plural(mrtstat.mrts_upcalls)); 216 printf(" %10u upcall queue overflow%s\n", 217 mrtstat.mrts_upq_ovflw, plural(mrtstat.mrts_upq_ovflw)); 218 printf(" %10u upcall%s dropped due to full socket buffer\n", 219 mrtstat.mrts_upq_sockfull, plural(mrtstat.mrts_upq_sockfull)); 220 printf(" %10u cache cleanup%s\n", 221 mrtstat.mrts_cache_cleanups, plural(mrtstat.mrts_cache_cleanups)); 222 printf(" %10u datagram%s with no route for origin\n", 223 mrtstat.mrts_no_route, plural(mrtstat.mrts_no_route)); 224 printf(" %10u datagram%s arrived with bad tunneling\n", 225 mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel)); 226 printf(" %10u datagram%s could not be tunneled\n", 227 mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel)); 228 printf(" %10u datagram%s arrived on wrong interface\n", 229 mrtstat.mrts_wrong_if, plural(mrtstat.mrts_wrong_if)); 230 printf(" %10u datagram%s selectively dropped\n", 231 mrtstat.mrts_drop_sel, plural(mrtstat.mrts_drop_sel)); 232 printf(" %10u datagram%s dropped due to queue overflow\n", 233 mrtstat.mrts_q_overflow, plural(mrtstat.mrts_q_overflow)); 234 printf(" %10u datagram%s dropped for being too large\n", 235 mrtstat.mrts_pkt2large, plural(mrtstat.mrts_pkt2large)); 236 } 237