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