165475bc8SDavid E. O'Brien /*- 20fea3d51SYoshinobu Inoue * Copyright (C) 1998 WIDE Project. 30fea3d51SYoshinobu Inoue * All rights reserved. 40fea3d51SYoshinobu Inoue * 50fea3d51SYoshinobu Inoue * Redistribution and use in source and binary forms, with or without 60fea3d51SYoshinobu Inoue * modification, are permitted provided that the following conditions 70fea3d51SYoshinobu Inoue * are met: 80fea3d51SYoshinobu Inoue * 1. Redistributions of source code must retain the above copyright 90fea3d51SYoshinobu Inoue * notice, this list of conditions and the following disclaimer. 100fea3d51SYoshinobu Inoue * 2. Redistributions in binary form must reproduce the above copyright 110fea3d51SYoshinobu Inoue * notice, this list of conditions and the following disclaimer in the 120fea3d51SYoshinobu Inoue * documentation and/or other materials provided with the distribution. 130fea3d51SYoshinobu Inoue * 3. Neither the name of the project nor the names of its contributors 140fea3d51SYoshinobu Inoue * may be used to endorse or promote products derived from this software 150fea3d51SYoshinobu Inoue * without specific prior written permission. 160fea3d51SYoshinobu Inoue * 170fea3d51SYoshinobu Inoue * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 180fea3d51SYoshinobu Inoue * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 190fea3d51SYoshinobu Inoue * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 200fea3d51SYoshinobu Inoue * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 210fea3d51SYoshinobu Inoue * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 220fea3d51SYoshinobu Inoue * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 230fea3d51SYoshinobu Inoue * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 240fea3d51SYoshinobu Inoue * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 250fea3d51SYoshinobu Inoue * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 260fea3d51SYoshinobu Inoue * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 270fea3d51SYoshinobu Inoue * SUCH DAMAGE. 280fea3d51SYoshinobu Inoue */ 2965475bc8SDavid E. O'Brien /*- 300fea3d51SYoshinobu Inoue * Copyright (c) 1989 Stephen Deering 310fea3d51SYoshinobu Inoue * Copyright (c) 1992, 1993 320fea3d51SYoshinobu Inoue * The Regents of the University of California. All rights reserved. 330fea3d51SYoshinobu Inoue * 340fea3d51SYoshinobu Inoue * This code is derived from software contributed to Berkeley by 350fea3d51SYoshinobu Inoue * Stephen Deering of Stanford University. 360fea3d51SYoshinobu Inoue * 370fea3d51SYoshinobu Inoue * Redistribution and use in source and binary forms, with or without 380fea3d51SYoshinobu Inoue * modification, are permitted provided that the following conditions 390fea3d51SYoshinobu Inoue * are met: 400fea3d51SYoshinobu Inoue * 1. Redistributions of source code must retain the above copyright 410fea3d51SYoshinobu Inoue * notice, this list of conditions and the following disclaimer. 420fea3d51SYoshinobu Inoue * 2. Redistributions in binary form must reproduce the above copyright 430fea3d51SYoshinobu Inoue * notice, this list of conditions and the following disclaimer in the 440fea3d51SYoshinobu Inoue * documentation and/or other materials provided with the distribution. 450fea3d51SYoshinobu Inoue * 3. All advertising materials mentioning features or use of this software 460fea3d51SYoshinobu Inoue * must display the following acknowledgement: 470fea3d51SYoshinobu Inoue * This product includes software developed by the University of 480fea3d51SYoshinobu Inoue * California, Berkeley and its contributors. 490fea3d51SYoshinobu Inoue * 4. Neither the name of the University nor the names of its contributors 500fea3d51SYoshinobu Inoue * may be used to endorse or promote products derived from this software 510fea3d51SYoshinobu Inoue * without specific prior written permission. 520fea3d51SYoshinobu Inoue * 530fea3d51SYoshinobu Inoue * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 540fea3d51SYoshinobu Inoue * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 550fea3d51SYoshinobu Inoue * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 560fea3d51SYoshinobu Inoue * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 570fea3d51SYoshinobu Inoue * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 580fea3d51SYoshinobu Inoue * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 590fea3d51SYoshinobu Inoue * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 600fea3d51SYoshinobu Inoue * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 610fea3d51SYoshinobu Inoue * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 620fea3d51SYoshinobu Inoue * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 630fea3d51SYoshinobu Inoue * SUCH DAMAGE. 640fea3d51SYoshinobu Inoue * 650fea3d51SYoshinobu Inoue * @(#)mroute.c 8.2 (Berkeley) 4/28/95 660fea3d51SYoshinobu Inoue */ 670fea3d51SYoshinobu Inoue 686cc6f122SPhilippe Charnier #include <sys/cdefs.h> 696cc6f122SPhilippe Charnier __FBSDID("$FreeBSD$"); 706cc6f122SPhilippe Charnier 71d84a1df4SHajimu UMEMOTO #ifdef INET6 720fea3d51SYoshinobu Inoue #include <sys/param.h> 730fea3d51SYoshinobu Inoue #include <sys/queue.h> 740fea3d51SYoshinobu Inoue #include <sys/socket.h> 750fea3d51SYoshinobu Inoue #include <sys/socketvar.h> 76c15ddad9SBruce M Simpson #include <sys/sysctl.h> 770fea3d51SYoshinobu Inoue #include <sys/protosw.h> 78c15ddad9SBruce M Simpson #include <sys/mbuf.h> 79c15ddad9SBruce M Simpson #include <sys/time.h> 800fea3d51SYoshinobu Inoue 810fea3d51SYoshinobu Inoue #include <net/if.h> 820fea3d51SYoshinobu Inoue #include <net/if_var.h> 8333841545SHajimu UMEMOTO #include <net/route.h> 840fea3d51SYoshinobu Inoue 850fea3d51SYoshinobu Inoue #include <netinet/in.h> 860fea3d51SYoshinobu Inoue 87c15ddad9SBruce M Simpson #include <err.h> 887b95a1ebSYaroslav Tykhiy #include <stdint.h> 890fea3d51SYoshinobu Inoue #include <stdio.h> 90c15ddad9SBruce M Simpson #include <stdlib.h> 910fea3d51SYoshinobu Inoue 920fea3d51SYoshinobu Inoue #define KERNEL 1 930fea3d51SYoshinobu Inoue #include <netinet6/ip6_mroute.h> 940fea3d51SYoshinobu Inoue #undef KERNEL 950fea3d51SYoshinobu Inoue 960fea3d51SYoshinobu Inoue #include "netstat.h" 970fea3d51SYoshinobu Inoue 9870057abfSRuslan Ermilov #define WID_ORG (Wflag ? 39 : (numeric_addr ? 29 : 18)) /* width of origin column */ 9970057abfSRuslan Ermilov #define WID_GRP (Wflag ? 18 : (numeric_addr ? 16 : 18)) /* width of group column */ 1000fea3d51SYoshinobu Inoue 1010fea3d51SYoshinobu Inoue void 1025e051718SAssar Westerlund mroute6pr(u_long mfcaddr, u_long mifaddr) 1030fea3d51SYoshinobu Inoue { 1040fea3d51SYoshinobu Inoue struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp; 1050fea3d51SYoshinobu Inoue struct mif6 mif6table[MAXMIFS]; 1060fea3d51SYoshinobu Inoue struct mf6c mfc; 1070fea3d51SYoshinobu Inoue struct rtdetq rte, *rtep; 108a01e3379SDavid Malone struct mif6 *mifp; 109a01e3379SDavid Malone mifi_t mifi; 110a01e3379SDavid Malone int i; 111a01e3379SDavid Malone int banner_printed; 112a01e3379SDavid Malone int saved_numeric_addr; 1130fea3d51SYoshinobu Inoue mifi_t maxmif = 0; 1140fea3d51SYoshinobu Inoue long int waitings; 115c15ddad9SBruce M Simpson size_t len; 1160fea3d51SYoshinobu Inoue 117c15ddad9SBruce M Simpson len = sizeof(mif6table); 118feda1a43SJohn Baldwin if (live) { 119c15ddad9SBruce M Simpson if (sysctlbyname("net.inet6.ip6.mif6table", mif6table, &len, 120c15ddad9SBruce M Simpson NULL, 0) < 0) { 121c15ddad9SBruce M Simpson warn("sysctl: net.inet6.ip6.mif6table"); 1220fea3d51SYoshinobu Inoue return; 1230fea3d51SYoshinobu Inoue } 124feda1a43SJohn Baldwin } else 125c15ddad9SBruce M Simpson kread(mifaddr, (char *)mif6table, sizeof(mif6table)); 1260fea3d51SYoshinobu Inoue 12765ea0024SAssar Westerlund saved_numeric_addr = numeric_addr; 12865ea0024SAssar Westerlund numeric_addr = 1; 1290fea3d51SYoshinobu Inoue banner_printed = 0; 130c15ddad9SBruce M Simpson 1310fea3d51SYoshinobu Inoue for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) { 1320fea3d51SYoshinobu Inoue struct ifnet ifnet; 1330fea3d51SYoshinobu Inoue char ifname[IFNAMSIZ]; 1340fea3d51SYoshinobu Inoue 1350fea3d51SYoshinobu Inoue if (mifp->m6_ifp == NULL) 1360fea3d51SYoshinobu Inoue continue; 1370fea3d51SYoshinobu Inoue 138c15ddad9SBruce M Simpson /* XXX KVM */ 1390fea3d51SYoshinobu Inoue kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet)); 140c15ddad9SBruce M Simpson 1410fea3d51SYoshinobu Inoue maxmif = mifi; 1420fea3d51SYoshinobu Inoue if (!banner_printed) { 1430fea3d51SYoshinobu Inoue printf("\nIPv6 Multicast Interface Table\n" 1440fea3d51SYoshinobu Inoue " Mif Rate PhyIF " 1450fea3d51SYoshinobu Inoue "Pkts-In Pkts-Out\n"); 1460fea3d51SYoshinobu Inoue banner_printed = 1; 1470fea3d51SYoshinobu Inoue } 1480fea3d51SYoshinobu Inoue 1490fea3d51SYoshinobu Inoue printf(" %2u %4d", 1500fea3d51SYoshinobu Inoue mifi, mifp->m6_rate_limit); 1510fea3d51SYoshinobu Inoue printf(" %5s", (mifp->m6_flags & MIFF_REGISTER) ? 1520fea3d51SYoshinobu Inoue "reg0" : if_indextoname(ifnet.if_index, ifname)); 1530fea3d51SYoshinobu Inoue 1547b95a1ebSYaroslav Tykhiy printf(" %9ju %9ju\n", (uintmax_t)mifp->m6_pkt_in, 1557b95a1ebSYaroslav Tykhiy (uintmax_t)mifp->m6_pkt_out); 1560fea3d51SYoshinobu Inoue } 1570fea3d51SYoshinobu Inoue if (!banner_printed) 1580fea3d51SYoshinobu Inoue printf("\nIPv6 Multicast Interface Table is empty\n"); 1590fea3d51SYoshinobu Inoue 160c15ddad9SBruce M Simpson len = sizeof(mf6ctable); 161feda1a43SJohn Baldwin if (live) { 162c15ddad9SBruce M Simpson if (sysctlbyname("net.inet6.ip6.mf6ctable", mf6ctable, &len, 163c15ddad9SBruce M Simpson NULL, 0) < 0) { 164c15ddad9SBruce M Simpson warn("sysctl: net.inet6.ip6.mf6ctable"); 165c15ddad9SBruce M Simpson return; 166c15ddad9SBruce M Simpson } 167feda1a43SJohn Baldwin } else 168c15ddad9SBruce M Simpson kread(mfcaddr, (char *)mf6ctable, sizeof(mf6ctable)); 169c15ddad9SBruce M Simpson 1700fea3d51SYoshinobu Inoue banner_printed = 0; 171c15ddad9SBruce M Simpson 1720fea3d51SYoshinobu Inoue for (i = 0; i < MF6CTBLSIZ; ++i) { 1730fea3d51SYoshinobu Inoue mfcp = mf6ctable[i]; 1740fea3d51SYoshinobu Inoue while(mfcp) { 1750fea3d51SYoshinobu Inoue kread((u_long)mfcp, (char *)&mfc, sizeof(mfc)); 1760fea3d51SYoshinobu Inoue if (!banner_printed) { 1770fea3d51SYoshinobu Inoue printf ("\nIPv6 Multicast Forwarding Cache\n"); 1780fea3d51SYoshinobu Inoue printf(" %-*.*s %-*.*s %s", 1790fea3d51SYoshinobu Inoue WID_ORG, WID_ORG, "Origin", 1800fea3d51SYoshinobu Inoue WID_GRP, WID_GRP, "Group", 1810fea3d51SYoshinobu Inoue " Packets Waits In-Mif Out-Mifs\n"); 1820fea3d51SYoshinobu Inoue banner_printed = 1; 1830fea3d51SYoshinobu Inoue } 1840fea3d51SYoshinobu Inoue 1850fea3d51SYoshinobu Inoue printf(" %-*.*s", WID_ORG, WID_ORG, 1860fea3d51SYoshinobu Inoue routename6(&mfc.mf6c_origin)); 1870fea3d51SYoshinobu Inoue printf(" %-*.*s", WID_GRP, WID_GRP, 1880fea3d51SYoshinobu Inoue routename6(&mfc.mf6c_mcastgrp)); 1897b95a1ebSYaroslav Tykhiy printf(" %9ju", (uintmax_t)mfc.mf6c_pkt_cnt); 1900fea3d51SYoshinobu Inoue 1910fea3d51SYoshinobu Inoue for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) { 1920fea3d51SYoshinobu Inoue waitings++; 193c15ddad9SBruce M Simpson /* XXX KVM */ 1940fea3d51SYoshinobu Inoue kread((u_long)rtep, (char *)&rte, sizeof(rte)); 1950fea3d51SYoshinobu Inoue rtep = rte.next; 1960fea3d51SYoshinobu Inoue } 1970fea3d51SYoshinobu Inoue printf(" %3ld", waitings); 1980fea3d51SYoshinobu Inoue 1990fea3d51SYoshinobu Inoue if (mfc.mf6c_parent == MF6C_INCOMPLETE_PARENT) 2000fea3d51SYoshinobu Inoue printf(" --- "); 2010fea3d51SYoshinobu Inoue else 2020fea3d51SYoshinobu Inoue printf(" %3d ", mfc.mf6c_parent); 2030fea3d51SYoshinobu Inoue for (mifi = 0; mifi <= maxmif; mifi++) { 2040fea3d51SYoshinobu Inoue if (IF_ISSET(mifi, &mfc.mf6c_ifset)) 2050fea3d51SYoshinobu Inoue printf(" %u", mifi); 2060fea3d51SYoshinobu Inoue } 2070fea3d51SYoshinobu Inoue printf("\n"); 2080fea3d51SYoshinobu Inoue 2090fea3d51SYoshinobu Inoue mfcp = mfc.mf6c_next; 2100fea3d51SYoshinobu Inoue } 2110fea3d51SYoshinobu Inoue } 2120fea3d51SYoshinobu Inoue if (!banner_printed) 213c15ddad9SBruce M Simpson printf("\nIPv6 Multicast Forwarding Table is empty\n"); 2140fea3d51SYoshinobu Inoue 2150fea3d51SYoshinobu Inoue printf("\n"); 21665ea0024SAssar Westerlund numeric_addr = saved_numeric_addr; 2170fea3d51SYoshinobu Inoue } 2180fea3d51SYoshinobu Inoue 2190fea3d51SYoshinobu Inoue void 2205e051718SAssar Westerlund mrt6_stats(u_long mstaddr) 2210fea3d51SYoshinobu Inoue { 2220fea3d51SYoshinobu Inoue struct mrt6stat mrtstat; 223c15ddad9SBruce M Simpson size_t len = sizeof mrtstat; 2240fea3d51SYoshinobu Inoue 225feda1a43SJohn Baldwin if (live) { 226c15ddad9SBruce M Simpson if (sysctlbyname("net.inet6.ip6.mrt6stat", &mrtstat, &len, 227c15ddad9SBruce M Simpson NULL, 0) < 0) { 228c15ddad9SBruce M Simpson warn("sysctl: net.inet6.ip6.mrt6stat"); 2290fea3d51SYoshinobu Inoue return; 2300fea3d51SYoshinobu Inoue } 231feda1a43SJohn Baldwin } else 2320fea3d51SYoshinobu Inoue kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat)); 233feda1a43SJohn Baldwin 2340fea3d51SYoshinobu Inoue printf("IPv6 multicast forwarding:\n"); 23576840ccbSRuslan Ermilov 23676840ccbSRuslan Ermilov #define p(f, m) if (mrtstat.f || sflag <= 1) \ 2377b95a1ebSYaroslav Tykhiy printf(m, (uintmax_t)mrtstat.f, plural(mrtstat.f)) 23876840ccbSRuslan Ermilov #define p2(f, m) if (mrtstat.f || sflag <= 1) \ 2397b95a1ebSYaroslav Tykhiy printf(m, (uintmax_t)mrtstat.f, plurales(mrtstat.f)) 24076840ccbSRuslan Ermilov 2417b95a1ebSYaroslav Tykhiy p(mrt6s_mfc_lookups, "\t%ju multicast forwarding cache lookup%s\n"); 2427b95a1ebSYaroslav Tykhiy p2(mrt6s_mfc_misses, "\t%ju multicast forwarding cache miss%s\n"); 243910e1364SBruce M Simpson p(mrt6s_upcalls, "\t%ju upcall%s to multicast routing daemon\n"); 2447b95a1ebSYaroslav Tykhiy p(mrt6s_upq_ovflw, "\t%ju upcall queue overflow%s\n"); 24576840ccbSRuslan Ermilov p(mrt6s_upq_sockfull, 2467b95a1ebSYaroslav Tykhiy "\t%ju upcall%s dropped due to full socket buffer\n"); 2477b95a1ebSYaroslav Tykhiy p(mrt6s_cache_cleanups, "\t%ju cache cleanup%s\n"); 2487b95a1ebSYaroslav Tykhiy p(mrt6s_no_route, "\t%ju datagram%s with no route for origin\n"); 2497b95a1ebSYaroslav Tykhiy p(mrt6s_bad_tunnel, "\t%ju datagram%s arrived with bad tunneling\n"); 2507b95a1ebSYaroslav Tykhiy p(mrt6s_cant_tunnel, "\t%ju datagram%s could not be tunneled\n"); 2517b95a1ebSYaroslav Tykhiy p(mrt6s_wrong_if, "\t%ju datagram%s arrived on wrong interface\n"); 2527b95a1ebSYaroslav Tykhiy p(mrt6s_drop_sel, "\t%ju datagram%s selectively dropped\n"); 25376840ccbSRuslan Ermilov p(mrt6s_q_overflow, 2547b95a1ebSYaroslav Tykhiy "\t%ju datagram%s dropped due to queue overflow\n"); 2557b95a1ebSYaroslav Tykhiy p(mrt6s_pkt2large, "\t%ju datagram%s dropped for being too large\n"); 25676840ccbSRuslan Ermilov 25776840ccbSRuslan Ermilov #undef p2 25876840ccbSRuslan Ermilov #undef p 2590fea3d51SYoshinobu Inoue } 260d84a1df4SHajimu UMEMOTO #endif /*INET6*/ 261