]> git.saurik.com Git - apple/network_cmds.git/blob - netstat.tproj/mroute.c
network_cmds-176.4.1.tar.gz
[apple/network_cmds.git] / netstat.tproj / mroute.c
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License."
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24 /*
25 * Copyright (c) 1989 Stephen Deering
26 * Copyright (c) 1992, 1993
27 * The Regents of the University of California. All rights reserved.
28 *
29 * This code is derived from software contributed to Berkeley by
30 * Stephen Deering of Stanford University.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 *
60 * @(#)mroute.c 8.2 (Berkeley) 4/28/95
61 */
62
63 /*
64 * Print DVMRP multicast routing structures and statistics.
65 *
66 * MROUTING 1.0
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 #include <sys/mbuf.h>
75 #include <sys/time.h>
76
77 #include <net/if.h>
78 #include <netinet/in.h>
79 #include <netinet/igmp.h>
80 #include <net/route.h>
81 #include <netinet/ip_mroute.h>
82
83 #include <stdio.h>
84 #include <stdlib.h>
85 #include "netstat.h"
86
87 void
88 mroutepr(mfcaddr, vifaddr)
89 u_long mfcaddr, vifaddr;
90 {
91 u_int mrtproto;
92 struct mfc *mfctable[MFCTBLSIZ];
93 struct vif viftable[MAXVIFS];
94 struct mfc mfc, *m;
95 register struct vif *v;
96 register vifi_t vifi;
97 register int i;
98 register int banner_printed;
99 register int saved_nflag;
100 vifi_t maxvif = 0;
101
102 if (mfcaddr == 0 || vifaddr == 0) {
103 printf("No IPv4 multicast routing compiled into this system.\n");
104 return;
105 }
106
107 saved_nflag = nflag;
108 nflag = 1;
109
110 kread(vifaddr, (char *)&viftable, sizeof(viftable));
111 banner_printed = 0;
112 for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) {
113 if (v->v_lcl_addr.s_addr == 0)
114 continue;
115
116 maxvif = vifi;
117 if (!banner_printed) {
118 printf("\nVirtual Interface Table\n"
119 " Vif Thresh Rate Local-Address "
120 "Remote-Address Pkts-In Pkts-Out\n");
121 banner_printed = 1;
122 }
123
124 printf(" %2u %6u %4d %-15.15s",
125 /* opposite math of add_vif() */
126 vifi, v->v_threshold, v->v_rate_limit * 1000 / 1024,
127 routename(v->v_lcl_addr.s_addr));
128 printf(" %-15.15s", (v->v_flags & VIFF_TUNNEL) ?
129 routename(v->v_rmt_addr.s_addr) : "");
130
131 printf(" %9lu %9lu\n", v->v_pkt_in, v->v_pkt_out);
132 }
133 if (!banner_printed)
134 printf("\nVirtual Interface Table is empty\n");
135
136 kread(mfcaddr, (char *)&mfctable, sizeof(mfctable));
137 banner_printed = 0;
138 for (i = 0; i < MFCTBLSIZ; ++i) {
139 m = mfctable[i];
140 while(m) {
141 kread((u_long)m, (char *)&mfc, sizeof mfc);
142
143 if (!banner_printed) {
144 printf("\nIPv4 Multicast Forwarding Cache\n"
145 " Origin Group "
146 " Packets In-Vif Out-Vifs:Ttls\n");
147 banner_printed = 1;
148 }
149
150 printf(" %-15.15s", routename(mfc.mfc_origin.s_addr));
151 printf(" %-15.15s", routename(mfc.mfc_mcastgrp.s_addr));
152 printf(" %9lu", mfc.mfc_pkt_cnt);
153 printf(" %3d ", mfc.mfc_parent);
154 for (vifi = 0; vifi <= maxvif; vifi++) {
155 if (mfc.mfc_ttls[vifi] > 0)
156 printf(" %u:%u", vifi,
157 mfc.mfc_ttls[vifi]);
158 }
159 printf("\n");
160 m = mfc.mfc_next;
161 }
162 }
163 if (!banner_printed)
164 printf("\nMulticast Routing Table is empty\n");
165
166 printf("\n");
167 nflag = saved_nflag;
168 }
169
170
171 void
172 mrt_stats(mstaddr)
173 u_long mstaddr;
174 {
175 struct mrtstat mrtstat;
176
177 if (mstaddr == 0) {
178 printf("No IPv4 multicast routing compiled into this system.\n");
179 return;
180 }
181
182 kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
183 printf("IPv4 multicast forwarding:\n");
184 printf(" %10lu multicast forwarding cache lookup%s\n",
185 mrtstat.mrts_mfc_lookups, plural(mrtstat.mrts_mfc_lookups));
186 printf(" %10lu multicast forwarding cache miss%s\n",
187 mrtstat.mrts_mfc_misses, plurales(mrtstat.mrts_mfc_misses));
188 printf(" %10lu upcall%s to mrouted\n",
189 mrtstat.mrts_upcalls, plural(mrtstat.mrts_upcalls));
190 printf(" %10lu upcall queue overflow%s\n",
191 mrtstat.mrts_upq_ovflw, plural(mrtstat.mrts_upq_ovflw));
192 printf(" %10lu upcall%s dropped due to full socket buffer\n",
193 mrtstat.mrts_upq_sockfull, plural(mrtstat.mrts_upq_sockfull));
194 printf(" %10lu cache cleanup%s\n",
195 mrtstat.mrts_cache_cleanups, plural(mrtstat.mrts_cache_cleanups));
196 printf(" %10lu datagram%s with no route for origin\n",
197 mrtstat.mrts_no_route, plural(mrtstat.mrts_no_route));
198 printf(" %10lu datagram%s arrived with bad tunneling\n",
199 mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel));
200 printf(" %10lu datagram%s could not be tunneled\n",
201 mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel));
202 printf(" %10lu datagram%s arrived on wrong interface\n",
203 mrtstat.mrts_wrong_if, plural(mrtstat.mrts_wrong_if));
204 printf(" %10lu datagram%s selectively dropped\n",
205 mrtstat.mrts_drop_sel, plural(mrtstat.mrts_drop_sel));
206 printf(" %10lu datagram%s dropped due to queue overflow\n",
207 mrtstat.mrts_q_overflow, plural(mrtstat.mrts_q_overflow));
208 printf(" %10lu datagram%s dropped for being too large\n",
209 mrtstat.mrts_pkt2large, plural(mrtstat.mrts_pkt2large));
210 }