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 */ 68 69 #include <sys/cdefs.h> 70 __FBSDID("$FreeBSD$"); 71 72 #ifdef INET6 73 #include <sys/param.h> 74 #include <sys/queue.h> 75 #include <sys/socket.h> 76 #include <sys/socketvar.h> 77 #include <sys/sysctl.h> 78 #include <sys/protosw.h> 79 #include <sys/mbuf.h> 80 #include <sys/time.h> 81 82 #include <net/if.h> 83 #include <net/if_var.h> 84 #include <net/route.h> 85 86 #include <netinet/in.h> 87 88 #include <err.h> 89 #include <stdint.h> 90 #include <stdio.h> 91 #include <stdlib.h> 92 93 #define KERNEL 1 94 #include <netinet6/ip6_mroute.h> 95 #undef KERNEL 96 97 #include "netstat.h" 98 99 #define WID_ORG (Wflag ? 39 : (numeric_addr ? 29 : 18)) /* width of origin column */ 100 #define WID_GRP (Wflag ? 18 : (numeric_addr ? 16 : 18)) /* width of group column */ 101 102 void 103 mroute6pr(u_long mfcaddr, u_long mifaddr) 104 { 105 struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp; 106 struct mif6 mif6table[MAXMIFS]; 107 struct mf6c mfc; 108 struct rtdetq rte, *rtep; 109 struct mif6 *mifp; 110 mifi_t mifi; 111 int i; 112 int banner_printed; 113 int saved_numeric_addr; 114 mifi_t maxmif = 0; 115 long int waitings; 116 size_t len; 117 118 len = sizeof(mif6table); 119 if (sysctlbyname("net.inet6.ip6.mif6table", mif6table, &len, 120 NULL, 0) < 0) { 121 warn("sysctl: net.inet6.ip6.mif6table"); 122 if (mifaddr == 0) { 123 printf("No IPv6 multicast forwarding configured in " 124 "the running system.\n"); 125 return; 126 } 127 kread(mifaddr, (char *)mif6table, sizeof(mif6table)); 128 } 129 130 saved_numeric_addr = numeric_addr; 131 numeric_addr = 1; 132 banner_printed = 0; 133 134 for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) { 135 struct ifnet ifnet; 136 char ifname[IFNAMSIZ]; 137 138 if (mifp->m6_ifp == NULL) 139 continue; 140 141 /* XXX KVM */ 142 kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet)); 143 144 maxmif = mifi; 145 if (!banner_printed) { 146 printf("\nIPv6 Multicast Interface Table\n" 147 " Mif Rate PhyIF " 148 "Pkts-In Pkts-Out\n"); 149 banner_printed = 1; 150 } 151 152 printf(" %2u %4d", 153 mifi, mifp->m6_rate_limit); 154 printf(" %5s", (mifp->m6_flags & MIFF_REGISTER) ? 155 "reg0" : if_indextoname(ifnet.if_index, ifname)); 156 157 printf(" %9ju %9ju\n", (uintmax_t)mifp->m6_pkt_in, 158 (uintmax_t)mifp->m6_pkt_out); 159 } 160 if (!banner_printed) 161 printf("\nIPv6 Multicast Interface Table is empty\n"); 162 163 len = sizeof(mf6ctable); 164 if (sysctlbyname("net.inet6.ip6.mf6ctable", mf6ctable, &len, 165 NULL, 0) < 0) { 166 warn("sysctl: net.inet6.ip6.mf6ctable"); 167 if (mfcaddr == 0) { 168 printf("No IPv6 multicast forwarding configured in " 169 "the running system.\n"); 170 return; 171 } 172 /* 173 * XXX: Try KVM if the module is neither compiled nor loaded. 174 * The correct behaviour would be to always use KVM if 175 * the -M option is specified to netstat(1). 176 */ 177 kread(mfcaddr, (char *)mf6ctable, sizeof(mf6ctable)); 178 } 179 180 banner_printed = 0; 181 182 for (i = 0; i < MF6CTBLSIZ; ++i) { 183 mfcp = mf6ctable[i]; 184 while(mfcp) { 185 kread((u_long)mfcp, (char *)&mfc, sizeof(mfc)); 186 if (!banner_printed) { 187 printf ("\nIPv6 Multicast Forwarding Cache\n"); 188 printf(" %-*.*s %-*.*s %s", 189 WID_ORG, WID_ORG, "Origin", 190 WID_GRP, WID_GRP, "Group", 191 " Packets Waits In-Mif Out-Mifs\n"); 192 banner_printed = 1; 193 } 194 195 printf(" %-*.*s", WID_ORG, WID_ORG, 196 routename6(&mfc.mf6c_origin)); 197 printf(" %-*.*s", WID_GRP, WID_GRP, 198 routename6(&mfc.mf6c_mcastgrp)); 199 printf(" %9ju", (uintmax_t)mfc.mf6c_pkt_cnt); 200 201 for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) { 202 waitings++; 203 /* XXX KVM */ 204 kread((u_long)rtep, (char *)&rte, sizeof(rte)); 205 rtep = rte.next; 206 } 207 printf(" %3ld", waitings); 208 209 if (mfc.mf6c_parent == MF6C_INCOMPLETE_PARENT) 210 printf(" --- "); 211 else 212 printf(" %3d ", mfc.mf6c_parent); 213 for (mifi = 0; mifi <= maxmif; mifi++) { 214 if (IF_ISSET(mifi, &mfc.mf6c_ifset)) 215 printf(" %u", mifi); 216 } 217 printf("\n"); 218 219 mfcp = mfc.mf6c_next; 220 } 221 } 222 if (!banner_printed) 223 printf("\nIPv6 Multicast Forwarding Table is empty\n"); 224 225 printf("\n"); 226 numeric_addr = saved_numeric_addr; 227 } 228 229 void 230 mrt6_stats(u_long mstaddr) 231 { 232 struct mrt6stat mrtstat; 233 size_t len = sizeof mrtstat; 234 235 if (sysctlbyname("net.inet6.ip6.mrt6stat", &mrtstat, &len, 236 NULL, 0) < 0) { 237 warn("sysctl: net.inet6.ip6.mrt6stat"); 238 if (mstaddr == 0) { 239 printf("No IPv6 multicast forwarding configured in the " 240 "running system.\n"); 241 return; 242 } 243 kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat)); 244 } 245 printf("IPv6 multicast forwarding:\n"); 246 247 #define p(f, m) if (mrtstat.f || sflag <= 1) \ 248 printf(m, (uintmax_t)mrtstat.f, plural(mrtstat.f)) 249 #define p2(f, m) if (mrtstat.f || sflag <= 1) \ 250 printf(m, (uintmax_t)mrtstat.f, plurales(mrtstat.f)) 251 252 p(mrt6s_mfc_lookups, "\t%ju multicast forwarding cache lookup%s\n"); 253 p2(mrt6s_mfc_misses, "\t%ju multicast forwarding cache miss%s\n"); 254 p(mrt6s_upcalls, "\t%ju upcall%s to multicast routing daemon\n"); 255 p(mrt6s_upq_ovflw, "\t%ju upcall queue overflow%s\n"); 256 p(mrt6s_upq_sockfull, 257 "\t%ju upcall%s dropped due to full socket buffer\n"); 258 p(mrt6s_cache_cleanups, "\t%ju cache cleanup%s\n"); 259 p(mrt6s_no_route, "\t%ju datagram%s with no route for origin\n"); 260 p(mrt6s_bad_tunnel, "\t%ju datagram%s arrived with bad tunneling\n"); 261 p(mrt6s_cant_tunnel, "\t%ju datagram%s could not be tunneled\n"); 262 p(mrt6s_wrong_if, "\t%ju datagram%s arrived on wrong interface\n"); 263 p(mrt6s_drop_sel, "\t%ju datagram%s selectively dropped\n"); 264 p(mrt6s_q_overflow, 265 "\t%ju datagram%s dropped due to queue overflow\n"); 266 p(mrt6s_pkt2large, "\t%ju datagram%s dropped for being too large\n"); 267 268 #undef p2 269 #undef p 270 } 271 #endif /*INET6*/ 272