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