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 #ifndef lint 41 static const char rcsid[] = 42 "$FreeBSD$"; 43 #endif /* not lint */ 44 45 /* 46 * Print DVMRP multicast routing structures and statistics. 47 * 48 * MROUTING 1.0 49 */ 50 51 #include <sys/param.h> 52 #include <sys/queue.h> 53 #include <sys/socket.h> 54 #include <sys/socketvar.h> 55 #include <sys/protosw.h> 56 #include <sys/mbuf.h> 57 #include <sys/time.h> 58 59 #include <net/if.h> 60 #include <netinet/in.h> 61 #include <netinet/igmp.h> 62 #include <net/route.h> 63 #include <netinet/ip_mroute.h> 64 65 #include <stdio.h> 66 #include <stdlib.h> 67 #include "netstat.h" 68 69 void 70 mroutepr(u_long mfcaddr, u_long vifaddr) 71 { 72 struct mfc *mfctable[MFCTBLSIZ]; 73 struct vif viftable[MAXVIFS]; 74 struct mfc mfc, *m; 75 register struct vif *v; 76 register vifi_t vifi; 77 register int i; 78 register int banner_printed; 79 register int saved_numeric_addr; 80 vifi_t maxvif = 0; 81 82 if (mfcaddr == 0 || vifaddr == 0) { 83 printf("No IPv4 multicast routing compiled into this system.\n"); 84 return; 85 } 86 87 saved_numeric_addr = numeric_addr; 88 numeric_addr = 1; 89 90 kread(vifaddr, (char *)&viftable, sizeof(viftable)); 91 banner_printed = 0; 92 for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) { 93 if (v->v_lcl_addr.s_addr == 0) 94 continue; 95 96 maxvif = vifi; 97 if (!banner_printed) { 98 printf("\nVirtual Interface Table\n" 99 " Vif Thresh Rate Local-Address " 100 "Remote-Address Pkts-In Pkts-Out\n"); 101 banner_printed = 1; 102 } 103 104 printf(" %2u %6u %4d %-15.15s", 105 /* opposite math of add_vif() */ 106 vifi, v->v_threshold, v->v_rate_limit * 1000 / 1024, 107 routename(v->v_lcl_addr.s_addr)); 108 printf(" %-15.15s", (v->v_flags & VIFF_TUNNEL) ? 109 routename(v->v_rmt_addr.s_addr) : ""); 110 111 printf(" %9lu %9lu\n", v->v_pkt_in, v->v_pkt_out); 112 } 113 if (!banner_printed) 114 printf("\nVirtual Interface Table is empty\n"); 115 116 kread(mfcaddr, (char *)&mfctable, sizeof(mfctable)); 117 banner_printed = 0; 118 for (i = 0; i < MFCTBLSIZ; ++i) { 119 m = mfctable[i]; 120 while(m) { 121 kread((u_long)m, (char *)&mfc, sizeof mfc); 122 123 if (!banner_printed) { 124 printf("\nIPv4 Multicast Forwarding Cache\n" 125 " Origin Group " 126 " Packets In-Vif Out-Vifs:Ttls\n"); 127 banner_printed = 1; 128 } 129 130 printf(" %-15.15s", routename(mfc.mfc_origin.s_addr)); 131 printf(" %-15.15s", routename(mfc.mfc_mcastgrp.s_addr)); 132 printf(" %9lu", mfc.mfc_pkt_cnt); 133 printf(" %3d ", mfc.mfc_parent); 134 for (vifi = 0; vifi <= maxvif; vifi++) { 135 if (mfc.mfc_ttls[vifi] > 0) 136 printf(" %u:%u", vifi, 137 mfc.mfc_ttls[vifi]); 138 } 139 printf("\n"); 140 m = mfc.mfc_next; 141 } 142 } 143 if (!banner_printed) 144 printf("\nMulticast Routing Table is empty\n"); 145 146 printf("\n"); 147 numeric_addr = saved_numeric_addr; 148 } 149 150 151 void 152 mrt_stats(u_long mstaddr) 153 { 154 struct mrtstat mrtstat; 155 156 if (mstaddr == 0) { 157 printf("No IPv4 multicast routing compiled into this system.\n"); 158 return; 159 } 160 161 kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat)); 162 printf("IPv4 multicast forwarding:\n"); 163 printf(" %10lu multicast forwarding cache lookup%s\n", 164 mrtstat.mrts_mfc_lookups, plural(mrtstat.mrts_mfc_lookups)); 165 printf(" %10lu multicast forwarding cache miss%s\n", 166 mrtstat.mrts_mfc_misses, plurales(mrtstat.mrts_mfc_misses)); 167 printf(" %10lu upcall%s to mrouted\n", 168 mrtstat.mrts_upcalls, plural(mrtstat.mrts_upcalls)); 169 printf(" %10lu upcall queue overflow%s\n", 170 mrtstat.mrts_upq_ovflw, plural(mrtstat.mrts_upq_ovflw)); 171 printf(" %10lu upcall%s dropped due to full socket buffer\n", 172 mrtstat.mrts_upq_sockfull, plural(mrtstat.mrts_upq_sockfull)); 173 printf(" %10lu cache cleanup%s\n", 174 mrtstat.mrts_cache_cleanups, plural(mrtstat.mrts_cache_cleanups)); 175 printf(" %10lu datagram%s with no route for origin\n", 176 mrtstat.mrts_no_route, plural(mrtstat.mrts_no_route)); 177 printf(" %10lu datagram%s arrived with bad tunneling\n", 178 mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel)); 179 printf(" %10lu datagram%s could not be tunneled\n", 180 mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel)); 181 printf(" %10lu datagram%s arrived on wrong interface\n", 182 mrtstat.mrts_wrong_if, plural(mrtstat.mrts_wrong_if)); 183 printf(" %10lu datagram%s selectively dropped\n", 184 mrtstat.mrts_drop_sel, plural(mrtstat.mrts_drop_sel)); 185 printf(" %10lu datagram%s dropped due to queue overflow\n", 186 mrtstat.mrts_q_overflow, plural(mrtstat.mrts_q_overflow)); 187 printf(" %10lu datagram%s dropped for being too large\n", 188 mrtstat.mrts_pkt2large, plural(mrtstat.mrts_pkt2large)); 189 } 190