xref: /freebsd/usr.bin/netstat/mroute6.c (revision 0fea3d51659b3fd4d015170aa26845ef719a27b9)
10fea3d51SYoshinobu Inoue /*
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  */
290fea3d51SYoshinobu Inoue 
300fea3d51SYoshinobu Inoue /*
310fea3d51SYoshinobu Inoue  * Copyright (c) 1989 Stephen Deering
320fea3d51SYoshinobu Inoue  * Copyright (c) 1992, 1993
330fea3d51SYoshinobu Inoue  *	The Regents of the University of California.  All rights reserved.
340fea3d51SYoshinobu Inoue  *
350fea3d51SYoshinobu Inoue  * This code is derived from software contributed to Berkeley by
360fea3d51SYoshinobu Inoue  * Stephen Deering of Stanford University.
370fea3d51SYoshinobu Inoue  *
380fea3d51SYoshinobu Inoue  * Redistribution and use in source and binary forms, with or without
390fea3d51SYoshinobu Inoue  * modification, are permitted provided that the following conditions
400fea3d51SYoshinobu Inoue  * are met:
410fea3d51SYoshinobu Inoue  * 1. Redistributions of source code must retain the above copyright
420fea3d51SYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer.
430fea3d51SYoshinobu Inoue  * 2. Redistributions in binary form must reproduce the above copyright
440fea3d51SYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer in the
450fea3d51SYoshinobu Inoue  *    documentation and/or other materials provided with the distribution.
460fea3d51SYoshinobu Inoue  * 3. All advertising materials mentioning features or use of this software
470fea3d51SYoshinobu Inoue  *    must display the following acknowledgement:
480fea3d51SYoshinobu Inoue  *	This product includes software developed by the University of
490fea3d51SYoshinobu Inoue  *	California, Berkeley and its contributors.
500fea3d51SYoshinobu Inoue  * 4. Neither the name of the University nor the names of its contributors
510fea3d51SYoshinobu Inoue  *    may be used to endorse or promote products derived from this software
520fea3d51SYoshinobu Inoue  *    without specific prior written permission.
530fea3d51SYoshinobu Inoue  *
540fea3d51SYoshinobu Inoue  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
550fea3d51SYoshinobu Inoue  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
560fea3d51SYoshinobu Inoue  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
570fea3d51SYoshinobu Inoue  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
580fea3d51SYoshinobu Inoue  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
590fea3d51SYoshinobu Inoue  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
600fea3d51SYoshinobu Inoue  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
610fea3d51SYoshinobu Inoue  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
620fea3d51SYoshinobu Inoue  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
630fea3d51SYoshinobu Inoue  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
640fea3d51SYoshinobu Inoue  * SUCH DAMAGE.
650fea3d51SYoshinobu Inoue  *
660fea3d51SYoshinobu Inoue  *	@(#)mroute.c	8.2 (Berkeley) 4/28/95
670fea3d51SYoshinobu Inoue  *	$FreeBSD$
680fea3d51SYoshinobu Inoue  */
690fea3d51SYoshinobu Inoue 
700fea3d51SYoshinobu Inoue #include <sys/param.h>
710fea3d51SYoshinobu Inoue #include <sys/queue.h>
720fea3d51SYoshinobu Inoue #include <sys/socket.h>
730fea3d51SYoshinobu Inoue #include <sys/socketvar.h>
740fea3d51SYoshinobu Inoue #include <sys/protosw.h>
750fea3d51SYoshinobu Inoue 
760fea3d51SYoshinobu Inoue #include <net/if.h>
770fea3d51SYoshinobu Inoue #include <net/if_var.h>
780fea3d51SYoshinobu Inoue 
790fea3d51SYoshinobu Inoue #include <netinet/in.h>
800fea3d51SYoshinobu Inoue 
810fea3d51SYoshinobu Inoue #include <stdio.h>
820fea3d51SYoshinobu Inoue 
830fea3d51SYoshinobu Inoue #define	KERNEL 1
840fea3d51SYoshinobu Inoue #include <netinet6/ip6_mroute.h>
850fea3d51SYoshinobu Inoue #undef KERNEL
860fea3d51SYoshinobu Inoue 
870fea3d51SYoshinobu Inoue #include "netstat.h"
880fea3d51SYoshinobu Inoue 
890fea3d51SYoshinobu Inoue #define	WID_ORG	(lflag ? 39 : (nflag ? 29 : 18)) /* width of origin column */
900fea3d51SYoshinobu Inoue #define	WID_GRP	(lflag ? 18 : (nflag ? 16 : 18)) /* width of group column */
910fea3d51SYoshinobu Inoue 
920fea3d51SYoshinobu Inoue extern char	*routename6 __P((struct sockaddr_in6 *));
930fea3d51SYoshinobu Inoue 
940fea3d51SYoshinobu Inoue void
950fea3d51SYoshinobu Inoue mroute6pr(mfcaddr, mifaddr)
960fea3d51SYoshinobu Inoue 	u_long mfcaddr, mifaddr;
970fea3d51SYoshinobu Inoue {
980fea3d51SYoshinobu Inoue 	struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp;
990fea3d51SYoshinobu Inoue 	struct mif6 mif6table[MAXMIFS];
1000fea3d51SYoshinobu Inoue 	struct mf6c mfc;
1010fea3d51SYoshinobu Inoue 	struct rtdetq rte, *rtep;
1020fea3d51SYoshinobu Inoue 	register struct mif6 *mifp;
1030fea3d51SYoshinobu Inoue 	register mifi_t mifi;
1040fea3d51SYoshinobu Inoue 	register int i;
1050fea3d51SYoshinobu Inoue 	register int banner_printed;
1060fea3d51SYoshinobu Inoue 	register int saved_nflag;
1070fea3d51SYoshinobu Inoue 	mifi_t maxmif = 0;
1080fea3d51SYoshinobu Inoue 	long int waitings;
1090fea3d51SYoshinobu Inoue 
1100fea3d51SYoshinobu Inoue 	if (mfcaddr == 0 || mifaddr == 0) {
1110fea3d51SYoshinobu Inoue 		printf("No IPv6 multicast routing compiled into this"
1120fea3d51SYoshinobu Inoue 		       "system.\n");
1130fea3d51SYoshinobu Inoue 		return;
1140fea3d51SYoshinobu Inoue 	}
1150fea3d51SYoshinobu Inoue 
1160fea3d51SYoshinobu Inoue 	saved_nflag = nflag;
1170fea3d51SYoshinobu Inoue 	nflag = 1;
1180fea3d51SYoshinobu Inoue 
1190fea3d51SYoshinobu Inoue 	kread(mifaddr, (char *)&mif6table, sizeof(mif6table));
1200fea3d51SYoshinobu Inoue 	banner_printed = 0;
1210fea3d51SYoshinobu Inoue 	for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) {
1220fea3d51SYoshinobu Inoue 		struct ifnet ifnet;
1230fea3d51SYoshinobu Inoue 		char ifname[IFNAMSIZ];
1240fea3d51SYoshinobu Inoue 
1250fea3d51SYoshinobu Inoue 		if (mifp->m6_ifp == NULL)
1260fea3d51SYoshinobu Inoue 			continue;
1270fea3d51SYoshinobu Inoue 
1280fea3d51SYoshinobu Inoue 		kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet));
1290fea3d51SYoshinobu Inoue 		maxmif = mifi;
1300fea3d51SYoshinobu Inoue 		if (!banner_printed) {
1310fea3d51SYoshinobu Inoue 			printf("\nIPv6 Multicast Interface Table\n"
1320fea3d51SYoshinobu Inoue 			       " Mif   Rate   PhyIF   "
1330fea3d51SYoshinobu Inoue 			       "Pkts-In   Pkts-Out\n");
1340fea3d51SYoshinobu Inoue 			banner_printed = 1;
1350fea3d51SYoshinobu Inoue 		}
1360fea3d51SYoshinobu Inoue 
1370fea3d51SYoshinobu Inoue 		printf("  %2u   %4d",
1380fea3d51SYoshinobu Inoue 		       mifi, mifp->m6_rate_limit);
1390fea3d51SYoshinobu Inoue 		printf("   %5s", (mifp->m6_flags & MIFF_REGISTER) ?
1400fea3d51SYoshinobu Inoue 		       "reg0" : if_indextoname(ifnet.if_index, ifname));
1410fea3d51SYoshinobu Inoue 
1420fea3d51SYoshinobu Inoue 		printf(" %9qu  %9qu\n", mifp->m6_pkt_in, mifp->m6_pkt_out);
1430fea3d51SYoshinobu Inoue 	}
1440fea3d51SYoshinobu Inoue 	if (!banner_printed)
1450fea3d51SYoshinobu Inoue 		printf("\nIPv6 Multicast Interface Table is empty\n");
1460fea3d51SYoshinobu Inoue 
1470fea3d51SYoshinobu Inoue 	kread(mfcaddr, (char *)&mf6ctable, sizeof(mf6ctable));
1480fea3d51SYoshinobu Inoue 	banner_printed = 0;
1490fea3d51SYoshinobu Inoue 	for (i = 0; i < MF6CTBLSIZ; ++i) {
1500fea3d51SYoshinobu Inoue 		mfcp = mf6ctable[i];
1510fea3d51SYoshinobu Inoue 		while(mfcp) {
1520fea3d51SYoshinobu Inoue 			kread((u_long)mfcp, (char *)&mfc, sizeof(mfc));
1530fea3d51SYoshinobu Inoue 			if (!banner_printed) {
1540fea3d51SYoshinobu Inoue 				printf ("\nIPv6 Multicast Forwarding Cache\n");
1550fea3d51SYoshinobu Inoue 				printf(" %-*.*s %-*.*s %s",
1560fea3d51SYoshinobu Inoue 				       WID_ORG, WID_ORG, "Origin",
1570fea3d51SYoshinobu Inoue 				       WID_GRP, WID_GRP, "Group",
1580fea3d51SYoshinobu Inoue 				       "  Packets Waits In-Mif  Out-Mifs\n");
1590fea3d51SYoshinobu Inoue 				banner_printed = 1;
1600fea3d51SYoshinobu Inoue 			}
1610fea3d51SYoshinobu Inoue 
1620fea3d51SYoshinobu Inoue 			printf(" %-*.*s", WID_ORG, WID_ORG,
1630fea3d51SYoshinobu Inoue 			       routename6(&mfc.mf6c_origin));
1640fea3d51SYoshinobu Inoue 			printf(" %-*.*s", WID_GRP, WID_GRP,
1650fea3d51SYoshinobu Inoue 			       routename6(&mfc.mf6c_mcastgrp));
1660fea3d51SYoshinobu Inoue 			printf(" %9qu", mfc.mf6c_pkt_cnt);
1670fea3d51SYoshinobu Inoue 
1680fea3d51SYoshinobu Inoue 			for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) {
1690fea3d51SYoshinobu Inoue 				waitings++;
1700fea3d51SYoshinobu Inoue 				kread((u_long)rtep, (char *)&rte, sizeof(rte));
1710fea3d51SYoshinobu Inoue 				rtep = rte.next;
1720fea3d51SYoshinobu Inoue 			}
1730fea3d51SYoshinobu Inoue 			printf("   %3ld", waitings);
1740fea3d51SYoshinobu Inoue 
1750fea3d51SYoshinobu Inoue 			if (mfc.mf6c_parent == MF6C_INCOMPLETE_PARENT)
1760fea3d51SYoshinobu Inoue 				printf(" ---   ");
1770fea3d51SYoshinobu Inoue 			else
1780fea3d51SYoshinobu Inoue 				printf("  %3d   ", mfc.mf6c_parent);
1790fea3d51SYoshinobu Inoue 			for (mifi = 0; mifi <= maxmif; mifi++) {
1800fea3d51SYoshinobu Inoue 				if (IF_ISSET(mifi, &mfc.mf6c_ifset))
1810fea3d51SYoshinobu Inoue 					printf(" %u", mifi);
1820fea3d51SYoshinobu Inoue 			}
1830fea3d51SYoshinobu Inoue 			printf("\n");
1840fea3d51SYoshinobu Inoue 
1850fea3d51SYoshinobu Inoue 			mfcp = mfc.mf6c_next;
1860fea3d51SYoshinobu Inoue 		}
1870fea3d51SYoshinobu Inoue 	}
1880fea3d51SYoshinobu Inoue 	if (!banner_printed)
1890fea3d51SYoshinobu Inoue 		printf("\nIPv6 Multicast Routing Table is empty\n");
1900fea3d51SYoshinobu Inoue 
1910fea3d51SYoshinobu Inoue 	printf("\n");
1920fea3d51SYoshinobu Inoue 	nflag = saved_nflag;
1930fea3d51SYoshinobu Inoue }
1940fea3d51SYoshinobu Inoue 
1950fea3d51SYoshinobu Inoue void
1960fea3d51SYoshinobu Inoue mrt6_stats(mstaddr)
1970fea3d51SYoshinobu Inoue 	u_long mstaddr;
1980fea3d51SYoshinobu Inoue {
1990fea3d51SYoshinobu Inoue 	struct mrt6stat mrtstat;
2000fea3d51SYoshinobu Inoue 
2010fea3d51SYoshinobu Inoue 	if (mstaddr == 0) {
2020fea3d51SYoshinobu Inoue 		printf("No IPv6 multicast routing compiled into this"
2030fea3d51SYoshinobu Inoue 		       "system.\n");
2040fea3d51SYoshinobu Inoue 		return;
2050fea3d51SYoshinobu Inoue 	}
2060fea3d51SYoshinobu Inoue 
2070fea3d51SYoshinobu Inoue 	kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
2080fea3d51SYoshinobu Inoue 	printf("IPv6 multicast forwarding:\n");
2090fea3d51SYoshinobu Inoue 	printf(" %10qu multicast forwarding cache lookup%s\n",
2100fea3d51SYoshinobu Inoue 	       mrtstat.mrt6s_mfc_lookups, plural(mrtstat.mrt6s_mfc_lookups));
2110fea3d51SYoshinobu Inoue 	printf(" %10qu multicast forwarding cache miss%s\n",
2120fea3d51SYoshinobu Inoue 	       mrtstat.mrt6s_mfc_misses, plurales(mrtstat.mrt6s_mfc_misses));
2130fea3d51SYoshinobu Inoue 	printf(" %10qu upcall%s to mrouted\n",
2140fea3d51SYoshinobu Inoue 	       mrtstat.mrt6s_upcalls, plural(mrtstat.mrt6s_upcalls));
2150fea3d51SYoshinobu Inoue 	printf(" %10qu upcall queue overflow%s\n",
2160fea3d51SYoshinobu Inoue 	  mrtstat.mrt6s_upq_ovflw, plural(mrtstat.mrt6s_upq_ovflw));
2170fea3d51SYoshinobu Inoue 	printf(" %10qu upcall%s dropped due to full socket buffer\n",
2180fea3d51SYoshinobu Inoue 	  mrtstat.mrt6s_upq_sockfull, plural(mrtstat.mrt6s_upq_sockfull));
2190fea3d51SYoshinobu Inoue 	printf(" %10qu cache cleanup%s\n",
2200fea3d51SYoshinobu Inoue 	  mrtstat.mrt6s_cache_cleanups, plural(mrtstat.mrt6s_cache_cleanups));
2210fea3d51SYoshinobu Inoue 	printf(" %10qu datagram%s with no route for origin\n",
2220fea3d51SYoshinobu Inoue 	  mrtstat.mrt6s_no_route, plural(mrtstat.mrt6s_no_route));
2230fea3d51SYoshinobu Inoue 	printf(" %10qu datagram%s arrived with bad tunneling\n",
2240fea3d51SYoshinobu Inoue 	  mrtstat.mrt6s_bad_tunnel, plural(mrtstat.mrt6s_bad_tunnel));
2250fea3d51SYoshinobu Inoue 	printf(" %10qu datagram%s could not be tunneled\n",
2260fea3d51SYoshinobu Inoue 	  mrtstat.mrt6s_cant_tunnel, plural(mrtstat.mrt6s_cant_tunnel));
2270fea3d51SYoshinobu Inoue 	printf(" %10qu datagram%s arrived on wrong interface\n",
2280fea3d51SYoshinobu Inoue 	  mrtstat.mrt6s_wrong_if, plural(mrtstat.mrt6s_wrong_if));
2290fea3d51SYoshinobu Inoue 	printf(" %10qu datagram%s selectively dropped\n",
2300fea3d51SYoshinobu Inoue 	  mrtstat.mrt6s_drop_sel, plural(mrtstat.mrt6s_drop_sel));
2310fea3d51SYoshinobu Inoue 	printf(" %10qu datagram%s dropped due to queue overflow\n",
2320fea3d51SYoshinobu Inoue 	  mrtstat.mrt6s_q_overflow, plural(mrtstat.mrt6s_q_overflow));
2330fea3d51SYoshinobu Inoue 	printf(" %10qu datagram%s dropped for being too large\n",
2340fea3d51SYoshinobu Inoue 	  mrtstat.mrt6s_pkt2large, plural(mrtstat.mrt6s_pkt2large));
2350fea3d51SYoshinobu Inoue }
236