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