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