mroute6.c revision 78064
1/* 2 * Copyright (C) 1998 WIDE Project. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the project nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30/* 31 * Copyright (c) 1989 Stephen Deering 32 * Copyright (c) 1992, 1993 33 * The Regents of the University of California. All rights reserved. 34 * 35 * This code is derived from software contributed to Berkeley by 36 * Stephen Deering of Stanford University. 37 * 38 * Redistribution and use in source and binary forms, with or without 39 * modification, are permitted provided that the following conditions 40 * are met: 41 * 1. Redistributions of source code must retain the above copyright 42 * notice, this list of conditions and the following disclaimer. 43 * 2. Redistributions in binary form must reproduce the above copyright 44 * notice, this list of conditions and the following disclaimer in the 45 * documentation and/or other materials provided with the distribution. 46 * 3. All advertising materials mentioning features or use of this software 47 * must display the following acknowledgement: 48 * This product includes software developed by the University of 49 * California, Berkeley and its contributors. 50 * 4. Neither the name of the University nor the names of its contributors 51 * may be used to endorse or promote products derived from this software 52 * without specific prior written permission. 53 * 54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 64 * SUCH DAMAGE. 65 * 66 * @(#)mroute.c 8.2 (Berkeley) 4/28/95 67 * $FreeBSD: head/usr.bin/netstat/mroute6.c 78064 2001-06-11 12:39:29Z ume $ 68 */ 69 70#ifdef INET6 71#include <sys/param.h> 72#include <sys/queue.h> 73#include <sys/socket.h> 74#include <sys/socketvar.h> 75#include <sys/protosw.h> 76 77#include <net/if.h> 78#include <net/if_var.h> 79#include <net/route.h> 80 81#include <netinet/in.h> 82 83#include <stdio.h> 84 85#define KERNEL 1 86#include <netinet6/ip6_mroute.h> 87#undef KERNEL 88 89#include "netstat.h" 90 91#define WID_ORG (lflag ? 39 : (nflag ? 29 : 18)) /* width of origin column */ 92#define WID_GRP (lflag ? 18 : (nflag ? 16 : 18)) /* width of group column */ 93 94extern char *routename6 __P((struct sockaddr_in6 *)); 95 96void 97mroute6pr(mfcaddr, mifaddr) 98 u_long mfcaddr, mifaddr; 99{ 100 struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp; 101 struct mif6 mif6table[MAXMIFS]; 102 struct mf6c mfc; 103 struct rtdetq rte, *rtep; 104 register struct mif6 *mifp; 105 register mifi_t mifi; 106 register int i; 107 register int banner_printed; 108 register int saved_nflag; 109 mifi_t maxmif = 0; 110 long int waitings; 111 112 if (mfcaddr == 0 || mifaddr == 0) { 113 printf("No IPv6 multicast routing compiled into this" 114 " system.\n"); 115 return; 116 } 117 118 saved_nflag = nflag; 119 nflag = 1; 120 121 kread(mifaddr, (char *)&mif6table, sizeof(mif6table)); 122 banner_printed = 0; 123 for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) { 124 struct ifnet ifnet; 125 char ifname[IFNAMSIZ]; 126 127 if (mifp->m6_ifp == NULL) 128 continue; 129 130 kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet)); 131 maxmif = mifi; 132 if (!banner_printed) { 133 printf("\nIPv6 Multicast Interface Table\n" 134 " Mif Rate PhyIF " 135 "Pkts-In Pkts-Out\n"); 136 banner_printed = 1; 137 } 138 139 printf(" %2u %4d", 140 mifi, mifp->m6_rate_limit); 141 printf(" %5s", (mifp->m6_flags & MIFF_REGISTER) ? 142 "reg0" : if_indextoname(ifnet.if_index, ifname)); 143 144 printf(" %9llu %9llu\n", (unsigned long long)mifp->m6_pkt_in, 145 (unsigned long long)mifp->m6_pkt_out); 146 } 147 if (!banner_printed) 148 printf("\nIPv6 Multicast Interface Table is empty\n"); 149 150 kread(mfcaddr, (char *)&mf6ctable, sizeof(mf6ctable)); 151 banner_printed = 0; 152 for (i = 0; i < MF6CTBLSIZ; ++i) { 153 mfcp = mf6ctable[i]; 154 while(mfcp) { 155 kread((u_long)mfcp, (char *)&mfc, sizeof(mfc)); 156 if (!banner_printed) { 157 printf ("\nIPv6 Multicast Forwarding Cache\n"); 158 printf(" %-*.*s %-*.*s %s", 159 WID_ORG, WID_ORG, "Origin", 160 WID_GRP, WID_GRP, "Group", 161 " Packets Waits In-Mif Out-Mifs\n"); 162 banner_printed = 1; 163 } 164 165 printf(" %-*.*s", WID_ORG, WID_ORG, 166 routename6(&mfc.mf6c_origin)); 167 printf(" %-*.*s", WID_GRP, WID_GRP, 168 routename6(&mfc.mf6c_mcastgrp)); 169 printf(" %9llu", (unsigned long long)mfc.mf6c_pkt_cnt); 170 171 for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) { 172 waitings++; 173 kread((u_long)rtep, (char *)&rte, sizeof(rte)); 174 rtep = rte.next; 175 } 176 printf(" %3ld", waitings); 177 178 if (mfc.mf6c_parent == MF6C_INCOMPLETE_PARENT) 179 printf(" --- "); 180 else 181 printf(" %3d ", mfc.mf6c_parent); 182 for (mifi = 0; mifi <= maxmif; mifi++) { 183 if (IF_ISSET(mifi, &mfc.mf6c_ifset)) 184 printf(" %u", mifi); 185 } 186 printf("\n"); 187 188 mfcp = mfc.mf6c_next; 189 } 190 } 191 if (!banner_printed) 192 printf("\nIPv6 Multicast Routing Table is empty\n"); 193 194 printf("\n"); 195 nflag = saved_nflag; 196} 197 198void 199mrt6_stats(mstaddr) 200 u_long mstaddr; 201{ 202 struct mrt6stat mrtstat; 203 204 if (mstaddr == 0) { 205 printf("No IPv6 multicast routing compiled into this" 206 "system.\n"); 207 return; 208 } 209 210 kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat)); 211 printf("IPv6 multicast forwarding:\n"); 212 printf(" %10llu multicast forwarding cache lookup%s\n", 213 (unsigned long long)mrtstat.mrt6s_mfc_lookups, 214 plural(mrtstat.mrt6s_mfc_lookups)); 215 printf(" %10llu multicast forwarding cache miss%s\n", 216 (unsigned long long)mrtstat.mrt6s_mfc_misses, 217 plurales(mrtstat.mrt6s_mfc_misses)); 218 printf(" %10llu upcall%s to mrouted\n", 219 (unsigned long long)mrtstat.mrt6s_upcalls, 220 plural(mrtstat.mrt6s_upcalls)); 221 printf(" %10llu upcall llueue overflow%s\n", 222 (unsigned long long)mrtstat.mrt6s_upq_ovflw, 223 plural(mrtstat.mrt6s_upq_ovflw)); 224 printf(" %10llu upcall%s dropped due to full socket buffer\n", 225 (unsigned long long)mrtstat.mrt6s_upq_sockfull, 226 plural(mrtstat.mrt6s_upq_sockfull)); 227 printf(" %10llu cache cleanup%s\n", 228 (unsigned long long)mrtstat.mrt6s_cache_cleanups, 229 plural(mrtstat.mrt6s_cache_cleanups)); 230 printf(" %10llu datagram%s with no route for origin\n", 231 (unsigned long long)mrtstat.mrt6s_no_route, 232 plural(mrtstat.mrt6s_no_route)); 233 printf(" %10llu datagram%s arrived with bad tunneling\n", 234 (unsigned long long)mrtstat.mrt6s_bad_tunnel, 235 plural(mrtstat.mrt6s_bad_tunnel)); 236 printf(" %10llu datagram%s could not be tunneled\n", 237 (unsigned long long)mrtstat.mrt6s_cant_tunnel, 238 plural(mrtstat.mrt6s_cant_tunnel)); 239 printf(" %10llu datagram%s arrived on wrong interface\n", 240 (unsigned long long)mrtstat.mrt6s_wrong_if, 241 plural(mrtstat.mrt6s_wrong_if)); 242 printf(" %10llu datagram%s selectively dropped\n", 243 (unsigned long long)mrtstat.mrt6s_drop_sel, 244 plural(mrtstat.mrt6s_drop_sel)); 245 printf(" %10llu datagram%s dropped due to llueue overflow\n", 246 (unsigned long long)mrtstat.mrt6s_q_overflow, 247 plural(mrtstat.mrt6s_q_overflow)); 248 printf(" %10llu datagram%s dropped for being too large\n", 249 (unsigned long long)mrtstat.mrt6s_pkt2large, 250 plural(mrtstat.mrt6s_pkt2large)); 251} 252#endif /*INET6*/ 253