2 * Copyright (c) 1989 Stephen Deering
3 * Copyright (c) 1992, 1993
4 * The Regents of the University of California. All rights reserved.
6 * This code is derived from software contributed to Berkeley by
7 * Stephen Deering of Stanford University.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * @(#)mroute.c 8.2 (Berkeley) 4/28/95
39 * $FreeBSD: src/usr.bin/netstat/mroute.c,v 1.11.2.4 2001/09/17 14:53:17 ru Exp $
40 * $DragonFly: src/usr.bin/netstat/mroute.c,v 1.2 2003/06/17 04:29:30 dillon Exp $
44 * Print DVMRP multicast routing structures and statistics.
49 #include <sys/param.h>
50 #include <sys/queue.h>
51 #include <sys/socket.h>
52 #include <sys/socketvar.h>
53 #include <sys/protosw.h>
58 #include <netinet/in.h>
59 #include <netinet/igmp.h>
60 #include <net/route.h>
61 #include <netinet/ip_mroute.h>
68 mroutepr(u_long mfcaddr, u_long vifaddr)
70 struct mfc *mfctable[MFCTBLSIZ];
71 struct vif viftable[MAXVIFS];
73 register struct vif *v;
76 register int banner_printed;
77 register int saved_numeric_addr;
80 if (mfcaddr == 0 || vifaddr == 0) {
81 printf("No IPv4 multicast routing compiled into this system.\n");
85 saved_numeric_addr = numeric_addr;
88 kread(vifaddr, (char *)&viftable, sizeof(viftable));
90 for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) {
91 if (v->v_lcl_addr.s_addr == 0)
95 if (!banner_printed) {
96 printf("\nVirtual Interface Table\n"
97 " Vif Thresh Rate Local-Address "
98 "Remote-Address Pkts-In Pkts-Out\n");
102 printf(" %2u %6u %4d %-15.15s",
103 /* opposite math of add_vif() */
104 vifi, v->v_threshold, v->v_rate_limit * 1000 / 1024,
105 routename(v->v_lcl_addr.s_addr));
106 printf(" %-15.15s", (v->v_flags & VIFF_TUNNEL) ?
107 routename(v->v_rmt_addr.s_addr) : "");
109 printf(" %9lu %9lu\n", v->v_pkt_in, v->v_pkt_out);
112 printf("\nVirtual Interface Table is empty\n");
114 kread(mfcaddr, (char *)&mfctable, sizeof(mfctable));
116 for (i = 0; i < MFCTBLSIZ; ++i) {
119 kread((u_long)m, (char *)&mfc, sizeof mfc);
121 if (!banner_printed) {
122 printf("\nIPv4 Multicast Forwarding Cache\n"
124 " Packets In-Vif Out-Vifs:Ttls\n");
128 printf(" %-15.15s", routename(mfc.mfc_origin.s_addr));
129 printf(" %-15.15s", routename(mfc.mfc_mcastgrp.s_addr));
130 printf(" %9lu", mfc.mfc_pkt_cnt);
131 printf(" %3d ", mfc.mfc_parent);
132 for (vifi = 0; vifi <= maxvif; vifi++) {
133 if (mfc.mfc_ttls[vifi] > 0)
134 printf(" %u:%u", vifi,
142 printf("\nMulticast Routing Table is empty\n");
145 numeric_addr = saved_numeric_addr;
150 mrt_stats(u_long mstaddr)
152 struct mrtstat mrtstat;
155 printf("No IPv4 multicast routing compiled into this system.\n");
159 kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
160 printf("IPv4 multicast forwarding:\n");
162 #define p(f, m) if (mrtstat.f || sflag <= 1) \
163 printf(m, mrtstat.f, plural(mrtstat.f))
164 #define p2(f, m) if (mrtstat.f || sflag <= 1) \
165 printf(m, mrtstat.f, plurales(mrtstat.f))
167 p(mrts_mfc_lookups, "\t%lu multicast forwarding cache lookup%s\n");
168 p2(mrts_mfc_misses, "\t%lu multicast forwarding cache miss%s\n");
169 p(mrts_upcalls, "\t%lu upcall%s to mrouted\n");
170 p(mrts_upq_ovflw, "\t%lu upcall queue overflow%s\n");
172 "\t%lu upcall%s dropped due to full socket buffer\n");
173 p(mrts_cache_cleanups, "\t%lu cache cleanup%s\n");
174 p(mrts_no_route, "\t%lu datagram%s with no route for origin\n");
175 p(mrts_bad_tunnel, "\t%lu datagram%s arrived with bad tunneling\n");
176 p(mrts_cant_tunnel, "\t%lu datagram%s could not be tunneled\n");
177 p(mrts_wrong_if, "\t%lu datagram%s arrived on wrong interface\n");
178 p(mrts_drop_sel, "\t%lu datagram%s selectively dropped\n");
179 p(mrts_q_overflow, "\t%lu datagram%s dropped due to queue overflow\n");
180 p(mrts_pkt2large, "\t%lu datagram%s dropped for being too large\n");