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$ 68 */ 69 70 #include <sys/param.h> 71 #include <sys/queue.h> 72 #include <sys/socket.h> 73 #include <sys/socketvar.h> 74 #include <sys/protosw.h> 75 76 #include <net/if.h> 77 #include <net/if_var.h> 78 79 #include <netinet/in.h> 80 81 #include <stdio.h> 82 83 #define KERNEL 1 84 #include <netinet6/ip6_mroute.h> 85 #undef KERNEL 86 87 #include "netstat.h" 88 89 #define WID_ORG (lflag ? 39 : (nflag ? 29 : 18)) /* width of origin column */ 90 #define WID_GRP (lflag ? 18 : (nflag ? 16 : 18)) /* width of group column */ 91 92 extern char *routename6 __P((struct sockaddr_in6 *)); 93 94 void 95 mroute6pr(mfcaddr, mifaddr) 96 u_long mfcaddr, mifaddr; 97 { 98 struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp; 99 struct mif6 mif6table[MAXMIFS]; 100 struct mf6c mfc; 101 struct rtdetq rte, *rtep; 102 register struct mif6 *mifp; 103 register mifi_t mifi; 104 register int i; 105 register int banner_printed; 106 register int saved_nflag; 107 mifi_t maxmif = 0; 108 long int waitings; 109 110 if (mfcaddr == 0 || mifaddr == 0) { 111 printf("No IPv6 multicast routing compiled into this" 112 "system.\n"); 113 return; 114 } 115 116 saved_nflag = nflag; 117 nflag = 1; 118 119 kread(mifaddr, (char *)&mif6table, sizeof(mif6table)); 120 banner_printed = 0; 121 for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) { 122 struct ifnet ifnet; 123 char ifname[IFNAMSIZ]; 124 125 if (mifp->m6_ifp == NULL) 126 continue; 127 128 kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet)); 129 maxmif = mifi; 130 if (!banner_printed) { 131 printf("\nIPv6 Multicast Interface Table\n" 132 " Mif Rate PhyIF " 133 "Pkts-In Pkts-Out\n"); 134 banner_printed = 1; 135 } 136 137 printf(" %2u %4d", 138 mifi, mifp->m6_rate_limit); 139 printf(" %5s", (mifp->m6_flags & MIFF_REGISTER) ? 140 "reg0" : if_indextoname(ifnet.if_index, ifname)); 141 142 printf(" %9qu %9qu\n", mifp->m6_pkt_in, mifp->m6_pkt_out); 143 } 144 if (!banner_printed) 145 printf("\nIPv6 Multicast Interface Table is empty\n"); 146 147 kread(mfcaddr, (char *)&mf6ctable, sizeof(mf6ctable)); 148 banner_printed = 0; 149 for (i = 0; i < MF6CTBLSIZ; ++i) { 150 mfcp = mf6ctable[i]; 151 while(mfcp) { 152 kread((u_long)mfcp, (char *)&mfc, sizeof(mfc)); 153 if (!banner_printed) { 154 printf ("\nIPv6 Multicast Forwarding Cache\n"); 155 printf(" %-*.*s %-*.*s %s", 156 WID_ORG, WID_ORG, "Origin", 157 WID_GRP, WID_GRP, "Group", 158 " Packets Waits In-Mif Out-Mifs\n"); 159 banner_printed = 1; 160 } 161 162 printf(" %-*.*s", WID_ORG, WID_ORG, 163 routename6(&mfc.mf6c_origin)); 164 printf(" %-*.*s", WID_GRP, WID_GRP, 165 routename6(&mfc.mf6c_mcastgrp)); 166 printf(" %9qu", mfc.mf6c_pkt_cnt); 167 168 for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) { 169 waitings++; 170 kread((u_long)rtep, (char *)&rte, sizeof(rte)); 171 rtep = rte.next; 172 } 173 printf(" %3ld", waitings); 174 175 if (mfc.mf6c_parent == MF6C_INCOMPLETE_PARENT) 176 printf(" --- "); 177 else 178 printf(" %3d ", mfc.mf6c_parent); 179 for (mifi = 0; mifi <= maxmif; mifi++) { 180 if (IF_ISSET(mifi, &mfc.mf6c_ifset)) 181 printf(" %u", mifi); 182 } 183 printf("\n"); 184 185 mfcp = mfc.mf6c_next; 186 } 187 } 188 if (!banner_printed) 189 printf("\nIPv6 Multicast Routing Table is empty\n"); 190 191 printf("\n"); 192 nflag = saved_nflag; 193 } 194 195 void 196 mrt6_stats(mstaddr) 197 u_long mstaddr; 198 { 199 struct mrt6stat mrtstat; 200 201 if (mstaddr == 0) { 202 printf("No IPv6 multicast routing compiled into this" 203 "system.\n"); 204 return; 205 } 206 207 kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat)); 208 printf("IPv6 multicast forwarding:\n"); 209 printf(" %10qu multicast forwarding cache lookup%s\n", 210 mrtstat.mrt6s_mfc_lookups, plural(mrtstat.mrt6s_mfc_lookups)); 211 printf(" %10qu multicast forwarding cache miss%s\n", 212 mrtstat.mrt6s_mfc_misses, plurales(mrtstat.mrt6s_mfc_misses)); 213 printf(" %10qu upcall%s to mrouted\n", 214 mrtstat.mrt6s_upcalls, plural(mrtstat.mrt6s_upcalls)); 215 printf(" %10qu upcall queue overflow%s\n", 216 mrtstat.mrt6s_upq_ovflw, plural(mrtstat.mrt6s_upq_ovflw)); 217 printf(" %10qu upcall%s dropped due to full socket buffer\n", 218 mrtstat.mrt6s_upq_sockfull, plural(mrtstat.mrt6s_upq_sockfull)); 219 printf(" %10qu cache cleanup%s\n", 220 mrtstat.mrt6s_cache_cleanups, plural(mrtstat.mrt6s_cache_cleanups)); 221 printf(" %10qu datagram%s with no route for origin\n", 222 mrtstat.mrt6s_no_route, plural(mrtstat.mrt6s_no_route)); 223 printf(" %10qu datagram%s arrived with bad tunneling\n", 224 mrtstat.mrt6s_bad_tunnel, plural(mrtstat.mrt6s_bad_tunnel)); 225 printf(" %10qu datagram%s could not be tunneled\n", 226 mrtstat.mrt6s_cant_tunnel, plural(mrtstat.mrt6s_cant_tunnel)); 227 printf(" %10qu datagram%s arrived on wrong interface\n", 228 mrtstat.mrt6s_wrong_if, plural(mrtstat.mrt6s_wrong_if)); 229 printf(" %10qu datagram%s selectively dropped\n", 230 mrtstat.mrt6s_drop_sel, plural(mrtstat.mrt6s_drop_sel)); 231 printf(" %10qu datagram%s dropped due to queue overflow\n", 232 mrtstat.mrt6s_q_overflow, plural(mrtstat.mrt6s_q_overflow)); 233 printf(" %10qu datagram%s dropped for being too large\n", 234 mrtstat.mrt6s_pkt2large, plural(mrtstat.mrt6s_pkt2large)); 235 } 236