1175061Sobrien/*- 256722Sshin * Copyright (C) 1998 WIDE Project. 356722Sshin * All rights reserved. 456722Sshin * 556722Sshin * Redistribution and use in source and binary forms, with or without 656722Sshin * modification, are permitted provided that the following conditions 756722Sshin * are met: 856722Sshin * 1. Redistributions of source code must retain the above copyright 956722Sshin * notice, this list of conditions and the following disclaimer. 1056722Sshin * 2. Redistributions in binary form must reproduce the above copyright 1156722Sshin * notice, this list of conditions and the following disclaimer in the 1256722Sshin * documentation and/or other materials provided with the distribution. 1356722Sshin * 3. Neither the name of the project nor the names of its contributors 1456722Sshin * may be used to endorse or promote products derived from this software 1556722Sshin * without specific prior written permission. 1656722Sshin * 1756722Sshin * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 1856722Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1956722Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2056722Sshin * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 2156722Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2256722Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2356722Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2456722Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2556722Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2656722Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2756722Sshin * SUCH DAMAGE. 2856722Sshin */ 29175061Sobrien/*- 3056722Sshin * Copyright (c) 1989 Stephen Deering 3156722Sshin * Copyright (c) 1992, 1993 3256722Sshin * The Regents of the University of California. All rights reserved. 3356722Sshin * 3456722Sshin * This code is derived from software contributed to Berkeley by 3556722Sshin * Stephen Deering of Stanford University. 3656722Sshin * 3756722Sshin * Redistribution and use in source and binary forms, with or without 3856722Sshin * modification, are permitted provided that the following conditions 3956722Sshin * are met: 4056722Sshin * 1. Redistributions of source code must retain the above copyright 4156722Sshin * notice, this list of conditions and the following disclaimer. 4256722Sshin * 2. Redistributions in binary form must reproduce the above copyright 4356722Sshin * notice, this list of conditions and the following disclaimer in the 4456722Sshin * documentation and/or other materials provided with the distribution. 4556722Sshin * 3. All advertising materials mentioning features or use of this software 4656722Sshin * must display the following acknowledgement: 4756722Sshin * This product includes software developed by the University of 4856722Sshin * California, Berkeley and its contributors. 4956722Sshin * 4. Neither the name of the University nor the names of its contributors 5056722Sshin * may be used to endorse or promote products derived from this software 5156722Sshin * without specific prior written permission. 5256722Sshin * 5356722Sshin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 5456722Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 5556722Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 5656722Sshin * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 5756722Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 5856722Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 5956722Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 6056722Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 6156722Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 6256722Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 6356722Sshin * SUCH DAMAGE. 6456722Sshin * 6556722Sshin * @(#)mroute.c 8.2 (Berkeley) 4/28/95 6656722Sshin */ 6756722Sshin 68132671Scharnier#include <sys/cdefs.h> 69132671Scharnier__FBSDID("$FreeBSD$"); 70132671Scharnier 7164342Sume#ifdef INET6 7256722Sshin#include <sys/param.h> 7356722Sshin#include <sys/queue.h> 7456722Sshin#include <sys/socket.h> 7556722Sshin#include <sys/socketvar.h> 76166952Sbms#include <sys/sysctl.h> 7756722Sshin#include <sys/protosw.h> 78166952Sbms#include <sys/mbuf.h> 79166952Sbms#include <sys/time.h> 8056722Sshin 8156722Sshin#include <net/if.h> 8256722Sshin#include <net/if_var.h> 8378064Sume#include <net/route.h> 8456722Sshin 8556722Sshin#include <netinet/in.h> 8656722Sshin 87166952Sbms#include <err.h> 88160787Syar#include <stdint.h> 8956722Sshin#include <stdio.h> 90166952Sbms#include <stdlib.h> 9156722Sshin 9256722Sshin#define KERNEL 1 9356722Sshin#include <netinet6/ip6_mroute.h> 9456722Sshin#undef KERNEL 9556722Sshin 9656722Sshin#include "netstat.h" 9756722Sshin 9883200Sru#define WID_ORG (Wflag ? 39 : (numeric_addr ? 29 : 18)) /* width of origin column */ 9983200Sru#define WID_GRP (Wflag ? 18 : (numeric_addr ? 16 : 18)) /* width of group column */ 10056722Sshin 10156722Sshinvoid 10278314Sassarmroute6pr(u_long mfcaddr, u_long mifaddr) 10356722Sshin{ 10456722Sshin struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp; 10556722Sshin struct mif6 mif6table[MAXMIFS]; 10656722Sshin struct mf6c mfc; 10756722Sshin struct rtdetq rte, *rtep; 108102975Sdwmalone struct mif6 *mifp; 109102975Sdwmalone mifi_t mifi; 110102975Sdwmalone int i; 111102975Sdwmalone int banner_printed; 112102975Sdwmalone int saved_numeric_addr; 11356722Sshin mifi_t maxmif = 0; 11456722Sshin long int waitings; 115166952Sbms size_t len; 11656722Sshin 117166952Sbms len = sizeof(mif6table); 118171465Sjhb if (live) { 119171465Sjhb if (sysctlbyname("net.inet6.ip6.mif6table", mif6table, &len, 120171465Sjhb NULL, 0) < 0) { 121171465Sjhb warn("sysctl: net.inet6.ip6.mif6table"); 122166952Sbms return; 123166952Sbms } 124171465Sjhb } else 125166952Sbms kread(mifaddr, (char *)mif6table, sizeof(mif6table)); 12656722Sshin 12778238Sassar saved_numeric_addr = numeric_addr; 12878238Sassar numeric_addr = 1; 129166952Sbms banner_printed = 0; 13056722Sshin 13156722Sshin for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) { 13256722Sshin struct ifnet ifnet; 13356722Sshin char ifname[IFNAMSIZ]; 13456722Sshin 13556722Sshin if (mifp->m6_ifp == NULL) 13656722Sshin continue; 13756722Sshin 138166952Sbms /* XXX KVM */ 13956722Sshin kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet)); 140166952Sbms 14156722Sshin maxmif = mifi; 14256722Sshin if (!banner_printed) { 14356722Sshin printf("\nIPv6 Multicast Interface Table\n" 14456722Sshin " Mif Rate PhyIF " 14556722Sshin "Pkts-In Pkts-Out\n"); 14656722Sshin banner_printed = 1; 14756722Sshin } 14856722Sshin 14956722Sshin printf(" %2u %4d", 15056722Sshin mifi, mifp->m6_rate_limit); 15156722Sshin printf(" %5s", (mifp->m6_flags & MIFF_REGISTER) ? 15256722Sshin "reg0" : if_indextoname(ifnet.if_index, ifname)); 15356722Sshin 154160787Syar printf(" %9ju %9ju\n", (uintmax_t)mifp->m6_pkt_in, 155160787Syar (uintmax_t)mifp->m6_pkt_out); 15656722Sshin } 15756722Sshin if (!banner_printed) 15856722Sshin printf("\nIPv6 Multicast Interface Table is empty\n"); 15956722Sshin 160166952Sbms len = sizeof(mf6ctable); 161171465Sjhb if (live) { 162171465Sjhb if (sysctlbyname("net.inet6.ip6.mf6ctable", mf6ctable, &len, 163171465Sjhb NULL, 0) < 0) { 164171465Sjhb warn("sysctl: net.inet6.ip6.mf6ctable"); 165166952Sbms return; 166166952Sbms } 167171465Sjhb } else 168166952Sbms kread(mfcaddr, (char *)mf6ctable, sizeof(mf6ctable)); 169166952Sbms 17056722Sshin banner_printed = 0; 171166952Sbms 17256722Sshin for (i = 0; i < MF6CTBLSIZ; ++i) { 17356722Sshin mfcp = mf6ctable[i]; 17456722Sshin while(mfcp) { 17556722Sshin kread((u_long)mfcp, (char *)&mfc, sizeof(mfc)); 17656722Sshin if (!banner_printed) { 17756722Sshin printf ("\nIPv6 Multicast Forwarding Cache\n"); 17856722Sshin printf(" %-*.*s %-*.*s %s", 17956722Sshin WID_ORG, WID_ORG, "Origin", 18056722Sshin WID_GRP, WID_GRP, "Group", 18156722Sshin " Packets Waits In-Mif Out-Mifs\n"); 18256722Sshin banner_printed = 1; 18356722Sshin } 18456722Sshin 18556722Sshin printf(" %-*.*s", WID_ORG, WID_ORG, 18656722Sshin routename6(&mfc.mf6c_origin)); 18756722Sshin printf(" %-*.*s", WID_GRP, WID_GRP, 18856722Sshin routename6(&mfc.mf6c_mcastgrp)); 189160787Syar printf(" %9ju", (uintmax_t)mfc.mf6c_pkt_cnt); 19056722Sshin 19156722Sshin for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) { 19256722Sshin waitings++; 193166952Sbms /* XXX KVM */ 19456722Sshin kread((u_long)rtep, (char *)&rte, sizeof(rte)); 19556722Sshin rtep = rte.next; 19656722Sshin } 19756722Sshin printf(" %3ld", waitings); 19856722Sshin 19956722Sshin if (mfc.mf6c_parent == MF6C_INCOMPLETE_PARENT) 20056722Sshin printf(" --- "); 20156722Sshin else 20256722Sshin printf(" %3d ", mfc.mf6c_parent); 20356722Sshin for (mifi = 0; mifi <= maxmif; mifi++) { 20456722Sshin if (IF_ISSET(mifi, &mfc.mf6c_ifset)) 20556722Sshin printf(" %u", mifi); 20656722Sshin } 20756722Sshin printf("\n"); 20856722Sshin 20956722Sshin mfcp = mfc.mf6c_next; 21056722Sshin } 21156722Sshin } 21256722Sshin if (!banner_printed) 213166952Sbms printf("\nIPv6 Multicast Forwarding Table is empty\n"); 21456722Sshin 21556722Sshin printf("\n"); 21678238Sassar numeric_addr = saved_numeric_addr; 21756722Sshin} 21856722Sshin 21956722Sshinvoid 22078314Sassarmrt6_stats(u_long mstaddr) 22156722Sshin{ 22256722Sshin struct mrt6stat mrtstat; 223166952Sbms size_t len = sizeof mrtstat; 22456722Sshin 225171465Sjhb if (live) { 226171465Sjhb if (sysctlbyname("net.inet6.ip6.mrt6stat", &mrtstat, &len, 227171465Sjhb NULL, 0) < 0) { 228171465Sjhb warn("sysctl: net.inet6.ip6.mrt6stat"); 229166952Sbms return; 230166952Sbms } 231171465Sjhb } else 232166952Sbms kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat)); 233171465Sjhb 23456722Sshin printf("IPv6 multicast forwarding:\n"); 23583204Sru 23683204Sru#define p(f, m) if (mrtstat.f || sflag <= 1) \ 237160787Syar printf(m, (uintmax_t)mrtstat.f, plural(mrtstat.f)) 23883204Sru#define p2(f, m) if (mrtstat.f || sflag <= 1) \ 239160787Syar printf(m, (uintmax_t)mrtstat.f, plurales(mrtstat.f)) 24083204Sru 241160787Syar p(mrt6s_mfc_lookups, "\t%ju multicast forwarding cache lookup%s\n"); 242160787Syar p2(mrt6s_mfc_misses, "\t%ju multicast forwarding cache miss%s\n"); 243162797Sbms p(mrt6s_upcalls, "\t%ju upcall%s to multicast routing daemon\n"); 244160787Syar p(mrt6s_upq_ovflw, "\t%ju upcall queue overflow%s\n"); 24583204Sru p(mrt6s_upq_sockfull, 246160787Syar "\t%ju upcall%s dropped due to full socket buffer\n"); 247160787Syar p(mrt6s_cache_cleanups, "\t%ju cache cleanup%s\n"); 248160787Syar p(mrt6s_no_route, "\t%ju datagram%s with no route for origin\n"); 249160787Syar p(mrt6s_bad_tunnel, "\t%ju datagram%s arrived with bad tunneling\n"); 250160787Syar p(mrt6s_cant_tunnel, "\t%ju datagram%s could not be tunneled\n"); 251160787Syar p(mrt6s_wrong_if, "\t%ju datagram%s arrived on wrong interface\n"); 252160787Syar p(mrt6s_drop_sel, "\t%ju datagram%s selectively dropped\n"); 25383204Sru p(mrt6s_q_overflow, 254160787Syar "\t%ju datagram%s dropped due to queue overflow\n"); 255160787Syar p(mrt6s_pkt2large, "\t%ju datagram%s dropped for being too large\n"); 25683204Sru 25783204Sru#undef p2 25883204Sru#undef p 25956722Sshin} 26064342Sume#endif /*INET6*/ 261