mroute6.c revision 56722
1121986Sjhb/* 2121986Sjhb * Copyright (C) 1998 WIDE Project. 3121986Sjhb * All rights reserved. 4121986Sjhb * 5121986Sjhb * Redistribution and use in source and binary forms, with or without 6121986Sjhb * modification, are permitted provided that the following conditions 7121986Sjhb * are met: 8121986Sjhb * 1. Redistributions of source code must retain the above copyright 9121986Sjhb * notice, this list of conditions and the following disclaimer. 10121986Sjhb * 2. Redistributions in binary form must reproduce the above copyright 11121986Sjhb * notice, this list of conditions and the following disclaimer in the 12121986Sjhb * documentation and/or other materials provided with the distribution. 13121986Sjhb * 3. Neither the name of the project nor the names of its contributors 14121986Sjhb * may be used to endorse or promote products derived from this software 15121986Sjhb * without specific prior written permission. 16121986Sjhb * 17121986Sjhb * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 18121986Sjhb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19121986Sjhb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20121986Sjhb * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 21121986Sjhb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22121986Sjhb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23121986Sjhb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24121986Sjhb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25121986Sjhb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26121986Sjhb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27121986Sjhb * SUCH DAMAGE. 28121986Sjhb */ 29121986Sjhb 30121986Sjhb/* 31121986Sjhb * Copyright (c) 1989 Stephen Deering 32121986Sjhb * Copyright (c) 1992, 1993 33121986Sjhb * The Regents of the University of California. All rights reserved. 34121986Sjhb * 35121986Sjhb * This code is derived from software contributed to Berkeley by 36121986Sjhb * Stephen Deering of Stanford University. 37147565Speter * 38179277Sjb * Redistribution and use in source and binary forms, with or without 39147565Speter * modification, are permitted provided that the following conditions 40151979Sjhb * are met: 41151979Sjhb * 1. Redistributions of source code must retain the above copyright 42121986Sjhb * notice, this list of conditions and the following disclaimer. 43121986Sjhb * 2. Redistributions in binary form must reproduce the above copyright 44121986Sjhb * notice, this list of conditions and the following disclaimer in the 45121986Sjhb * documentation and/or other materials provided with the distribution. 46151979Sjhb * 3. All advertising materials mentioning features or use of this software 47151979Sjhb * must display the following acknowledgement: 48121986Sjhb * This product includes software developed by the University of 49187880Sjeff * California, Berkeley and its contributors. 50187880Sjeff * 4. Neither the name of the University nor the names of its contributors 51141538Sjhb * may be used to endorse or promote products derived from this software 52209371Smav * without specific prior written permission. 53121986Sjhb * 54121986Sjhb * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 55121986Sjhb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 56121986Sjhb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 57121986Sjhb * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 58153666Sjhb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 59121986Sjhb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 60121986Sjhb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 61121986Sjhb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 62121986Sjhb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 63208507Sjhb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 64121986Sjhb * SUCH DAMAGE. 65121986Sjhb * 66121986Sjhb * @(#)mroute.c 8.2 (Berkeley) 4/28/95 67121986Sjhb * $FreeBSD: head/usr.bin/netstat/mroute6.c 56722 2000-01-28 05:10:56Z shin $ 68151979Sjhb */ 69151979Sjhb 70151979Sjhb#include <sys/param.h> 71151979Sjhb#include <sys/queue.h> 72151979Sjhb#include <sys/socket.h> 73208452Smav#include <sys/socketvar.h> 74208452Smav#include <sys/protosw.h> 75208452Smav 76208452Smav#include <net/if.h> 77208452Smav#include <net/if_var.h> 78208452Smav 79208452Smav#include <netinet/in.h> 80208452Smav 81208452Smav#include <stdio.h> 82208452Smav 83122690Sjhb#define KERNEL 1 84139240Sjhb#include <netinet6/ip6_mroute.h> 85139240Sjhb#undef KERNEL 86139240Sjhb 87122690Sjhb#include "netstat.h" 88122690Sjhb 89151979Sjhb#define WID_ORG (lflag ? 39 : (nflag ? 29 : 18)) /* width of origin column */ 90151979Sjhb#define WID_GRP (lflag ? 18 : (nflag ? 16 : 18)) /* width of group column */ 91151979Sjhb 92151979Sjhbextern char *routename6 __P((struct sockaddr_in6 *)); 93121986Sjhb 94121986Sjhbvoid 95121986Sjhbmroute6pr(mfcaddr, mifaddr) 96121986Sjhb u_long mfcaddr, mifaddr; 97121986Sjhb{ 98121986Sjhb struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp; 99121986Sjhb struct mif6 mif6table[MAXMIFS]; 100121986Sjhb struct mf6c mfc; 101121986Sjhb struct rtdetq rte, *rtep; 102121986Sjhb register struct mif6 *mifp; 103121986Sjhb register mifi_t mifi; 104121986Sjhb register int i; 105121986Sjhb register int banner_printed; 106121986Sjhb register int saved_nflag; 107121986Sjhb mifi_t maxmif = 0; 108121986Sjhb long int waitings; 109121986Sjhb 110121986Sjhb if (mfcaddr == 0 || mifaddr == 0) { 111121986Sjhb printf("No IPv6 multicast routing compiled into this" 112121986Sjhb "system.\n"); 113121986Sjhb return; 114121986Sjhb } 115121986Sjhb 116121986Sjhb saved_nflag = nflag; 117141538Sjhb nflag = 1; 118209371Smav 119209371Smav kread(mifaddr, (char *)&mif6table, sizeof(mif6table)); 120187880Sjeff banner_printed = 0; 121191720Smav for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) { 122169395Sjhb struct ifnet ifnet; 123121986Sjhb char ifname[IFNAMSIZ]; 124121986Sjhb 125121986Sjhb if (mifp->m6_ifp == NULL) 126121986Sjhb continue; 127121986Sjhb 128139245Sjhb kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet)); 129205851Sjhb maxmif = mifi; 130196224Sjhb if (!banner_printed) { 131139245Sjhb printf("\nIPv6 Multicast Interface Table\n" 132208507Sjhb " Mif Rate PhyIF " 133121986Sjhb "Pkts-In Pkts-Out\n"); 134121986Sjhb banner_printed = 1; 135121986Sjhb } 136121986Sjhb 137121986Sjhb printf(" %2u %4d", 138121986Sjhb mifi, mifp->m6_rate_limit); 139121986Sjhb printf(" %5s", (mifp->m6_flags & MIFF_REGISTER) ? 140121986Sjhb "reg0" : if_indextoname(ifnet.if_index, ifname)); 141121986Sjhb 142122690Sjhb printf(" %9qu %9qu\n", mifp->m6_pkt_in, mifp->m6_pkt_out); 143122690Sjhb } 144121986Sjhb if (!banner_printed) 145121986Sjhb printf("\nIPv6 Multicast Interface Table is empty\n"); 146151979Sjhb 147195249Sjhb kread(mfcaddr, (char *)&mf6ctable, sizeof(mf6ctable)); 148141538Sjhb banner_printed = 0; 149141538Sjhb for (i = 0; i < MF6CTBLSIZ; ++i) { 150141538Sjhb mfcp = mf6ctable[i]; 151141538Sjhb while(mfcp) { 152169391Sjhb kread((u_long)mfcp, (char *)&mfc, sizeof(mfc)); 153169391Sjhb if (!banner_printed) { 154121986Sjhb printf ("\nIPv6 Multicast Forwarding Cache\n"); 155167747Sjhb printf(" %-*.*s %-*.*s %s", 156209371Smav WID_ORG, WID_ORG, "Origin", 157209371Smav WID_GRP, WID_GRP, "Group", 158121986Sjhb " Packets Waits In-Mif Out-Mifs\n"); 159139245Sjhb banner_printed = 1; 160163219Sjhb } 161141538Sjhb 162141538Sjhb printf(" %-*.*s", WID_ORG, WID_ORG, 163141538Sjhb routename6(&mfc.mf6c_origin)); 164209371Smav printf(" %-*.*s", WID_GRP, WID_GRP, 165141538Sjhb routename6(&mfc.mf6c_mcastgrp)); 166139245Sjhb printf(" %9qu", mfc.mf6c_pkt_cnt); 167209371Smav 168209371Smav for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) { 169209371Smav waitings++; 170139245Sjhb kread((u_long)rtep, (char *)&rte, sizeof(rte)); 171163219Sjhb rtep = rte.next; 172163219Sjhb } 173121986Sjhb printf(" %3ld", waitings); 174121986Sjhb 175121986Sjhb if (mfc.mf6c_parent == MF6C_INCOMPLETE_PARENT) 176121986Sjhb printf(" --- "); 177121986Sjhb else 178121986Sjhb printf(" %3d ", mfc.mf6c_parent); 179121986Sjhb for (mifi = 0; mifi <= maxmif; mifi++) { 180121986Sjhb if (IF_ISSET(mifi, &mfc.mf6c_ifset)) 181121986Sjhb printf(" %u", mifi); 182121986Sjhb } 183121986Sjhb printf("\n"); 184121986Sjhb 185121986Sjhb mfcp = mfc.mf6c_next; 186121986Sjhb } 187121986Sjhb } 188121986Sjhb if (!banner_printed) 189121986Sjhb printf("\nIPv6 Multicast Routing Table is empty\n"); 190121986Sjhb 191121986Sjhb printf("\n"); 192121986Sjhb nflag = saved_nflag; 193121986Sjhb} 194121986Sjhb 195121986Sjhbvoid 196121986Sjhbmrt6_stats(mstaddr) 197121986Sjhb u_long mstaddr; 198121986Sjhb{ 199121986Sjhb struct mrt6stat mrtstat; 200121986Sjhb 201121986Sjhb if (mstaddr == 0) { 202121986Sjhb printf("No IPv6 multicast routing compiled into this" 203121986Sjhb "system.\n"); 204121986Sjhb return; 205121986Sjhb } 206121986Sjhb 207121986Sjhb kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat)); 208121986Sjhb printf("IPv6 multicast forwarding:\n"); 209121986Sjhb printf(" %10qu multicast forwarding cache lookup%s\n", 210121986Sjhb mrtstat.mrt6s_mfc_lookups, plural(mrtstat.mrt6s_mfc_lookups)); 211121986Sjhb printf(" %10qu multicast forwarding cache miss%s\n", 212121986Sjhb mrtstat.mrt6s_mfc_misses, plurales(mrtstat.mrt6s_mfc_misses)); 213121986Sjhb printf(" %10qu upcall%s to mrouted\n", 214121986Sjhb mrtstat.mrt6s_upcalls, plural(mrtstat.mrt6s_upcalls)); 215121986Sjhb printf(" %10qu upcall queue overflow%s\n", 216121986Sjhb mrtstat.mrt6s_upq_ovflw, plural(mrtstat.mrt6s_upq_ovflw)); 217121986Sjhb printf(" %10qu upcall%s dropped due to full socket buffer\n", 218167247Sjhb mrtstat.mrt6s_upq_sockfull, plural(mrtstat.mrt6s_upq_sockfull)); 219121986Sjhb printf(" %10qu cache cleanup%s\n", 220209371Smav mrtstat.mrt6s_cache_cleanups, plural(mrtstat.mrt6s_cache_cleanups)); 221209371Smav printf(" %10qu datagram%s with no route for origin\n", 222121986Sjhb mrtstat.mrt6s_no_route, plural(mrtstat.mrt6s_no_route)); 223121986Sjhb printf(" %10qu datagram%s arrived with bad tunneling\n", 224121986Sjhb mrtstat.mrt6s_bad_tunnel, plural(mrtstat.mrt6s_bad_tunnel)); 225121986Sjhb printf(" %10qu datagram%s could not be tunneled\n", 226156920Sjhb mrtstat.mrt6s_cant_tunnel, plural(mrtstat.mrt6s_cant_tunnel)); 227167747Sjhb printf(" %10qu datagram%s arrived on wrong interface\n", 228208452Smav mrtstat.mrt6s_wrong_if, plural(mrtstat.mrt6s_wrong_if)); 229208452Smav printf(" %10qu datagram%s selectively dropped\n", 230121986Sjhb mrtstat.mrt6s_drop_sel, plural(mrtstat.mrt6s_drop_sel)); 231121986Sjhb printf(" %10qu datagram%s dropped due to queue overflow\n", 232139245Sjhb mrtstat.mrt6s_q_overflow, plural(mrtstat.mrt6s_q_overflow)); 233121986Sjhb printf(" %10qu datagram%s dropped for being too large\n", 234121986Sjhb mrtstat.mrt6s_pkt2large, plural(mrtstat.mrt6s_pkt2large)); 235121986Sjhb} 236121986Sjhb