mroute.c revision 1.17 1 1.17 agc /* $NetBSD: mroute.c,v 1.17 2003/08/07 11:15:21 agc Exp $ */
2 1.9 thorpej
3 1.1 brezak /*
4 1.4 mycroft * Copyright (c) 1992, 1993
5 1.4 mycroft * The Regents of the University of California. All rights reserved.
6 1.4 mycroft *
7 1.4 mycroft * This code is derived from software contributed to Berkeley by
8 1.4 mycroft * Stephen Deering of Stanford University.
9 1.4 mycroft *
10 1.4 mycroft * Redistribution and use in source and binary forms, with or without
11 1.4 mycroft * modification, are permitted provided that the following conditions
12 1.4 mycroft * are met:
13 1.4 mycroft * 1. Redistributions of source code must retain the above copyright
14 1.4 mycroft * notice, this list of conditions and the following disclaimer.
15 1.4 mycroft * 2. Redistributions in binary form must reproduce the above copyright
16 1.4 mycroft * notice, this list of conditions and the following disclaimer in the
17 1.4 mycroft * documentation and/or other materials provided with the distribution.
18 1.17 agc * 3. Neither the name of the University nor the names of its contributors
19 1.17 agc * may be used to endorse or promote products derived from this software
20 1.17 agc * without specific prior written permission.
21 1.17 agc *
22 1.17 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.17 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.17 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.17 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.17 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.17 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.17 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.17 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.17 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.17 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.17 agc * SUCH DAMAGE.
33 1.17 agc *
34 1.17 agc * from: @(#)mroute.c 8.1 (Berkeley) 6/6/93
35 1.17 agc */
36 1.17 agc
37 1.17 agc /*
38 1.17 agc * Copyright (c) 1989 Stephen Deering
39 1.17 agc *
40 1.17 agc * This code is derived from software contributed to Berkeley by
41 1.17 agc * Stephen Deering of Stanford University.
42 1.17 agc *
43 1.17 agc * Redistribution and use in source and binary forms, with or without
44 1.17 agc * modification, are permitted provided that the following conditions
45 1.17 agc * are met:
46 1.17 agc * 1. Redistributions of source code must retain the above copyright
47 1.17 agc * notice, this list of conditions and the following disclaimer.
48 1.17 agc * 2. Redistributions in binary form must reproduce the above copyright
49 1.17 agc * notice, this list of conditions and the following disclaimer in the
50 1.17 agc * documentation and/or other materials provided with the distribution.
51 1.4 mycroft * 3. All advertising materials mentioning features or use of this software
52 1.4 mycroft * must display the following acknowledgement:
53 1.4 mycroft * This product includes software developed by the University of
54 1.4 mycroft * California, Berkeley and its contributors.
55 1.4 mycroft * 4. Neither the name of the University nor the names of its contributors
56 1.4 mycroft * may be used to endorse or promote products derived from this software
57 1.4 mycroft * without specific prior written permission.
58 1.4 mycroft *
59 1.4 mycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 1.4 mycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 1.4 mycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 1.4 mycroft * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 1.4 mycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 1.4 mycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 1.4 mycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 1.4 mycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 1.4 mycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 1.4 mycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 1.4 mycroft * SUCH DAMAGE.
70 1.4 mycroft *
71 1.4 mycroft * from: @(#)mroute.c 8.1 (Berkeley) 6/6/93
72 1.4 mycroft */
73 1.4 mycroft
74 1.12 lukem #include <sys/cdefs.h>
75 1.12 lukem #ifndef lint
76 1.12 lukem #if 0
77 1.12 lukem static char sccsid[] = "from: @(#)mroute.c 8.1 (Berkeley) 6/6/93";
78 1.12 lukem #else
79 1.17 agc __RCSID("$NetBSD: mroute.c,v 1.17 2003/08/07 11:15:21 agc Exp $");
80 1.12 lukem #endif
81 1.12 lukem #endif /* not lint */
82 1.12 lukem
83 1.4 mycroft /*
84 1.1 brezak * Print DVMRP multicast routing structures and statistics.
85 1.1 brezak *
86 1.1 brezak * MROUTING 1.0
87 1.1 brezak */
88 1.1 brezak
89 1.4 mycroft #include <sys/param.h>
90 1.4 mycroft #include <sys/socket.h>
91 1.4 mycroft #include <sys/socketvar.h>
92 1.4 mycroft #include <sys/protosw.h>
93 1.1 brezak
94 1.7 mycroft #include <net/if.h>
95 1.7 mycroft #include <net/route.h>
96 1.1 brezak #include <netinet/in.h>
97 1.1 brezak #include <netinet/igmp.h>
98 1.6 jtc #define _KERNEL
99 1.1 brezak #include <netinet/ip_mroute.h>
100 1.6 jtc #undef _KERNEL
101 1.1 brezak
102 1.4 mycroft #include <stdio.h>
103 1.4 mycroft #include <stdlib.h>
104 1.4 mycroft #include "netstat.h"
105 1.1 brezak
106 1.11 christos static char *pktscale __P((u_long));
107 1.11 christos
108 1.11 christos static char *
109 1.7 mycroft pktscale(n)
110 1.7 mycroft u_long n;
111 1.7 mycroft {
112 1.16 itojun static char buf[20];
113 1.7 mycroft char t;
114 1.7 mycroft
115 1.7 mycroft if (n < 1024)
116 1.7 mycroft t = ' ';
117 1.7 mycroft else if (n < 1024 * 1024) {
118 1.7 mycroft t = 'k';
119 1.7 mycroft n /= 1024;
120 1.7 mycroft } else {
121 1.7 mycroft t = 'm';
122 1.7 mycroft n /= 1048576;
123 1.7 mycroft }
124 1.7 mycroft
125 1.13 mrg (void)snprintf(buf, sizeof buf, "%lu%c", n, t);
126 1.7 mycroft return (buf);
127 1.7 mycroft }
128 1.7 mycroft
129 1.4 mycroft void
130 1.7 mycroft mroutepr(mrpaddr, mfchashtbladdr, mfchashaddr, vifaddr)
131 1.7 mycroft u_long mrpaddr, mfchashtbladdr, mfchashaddr, vifaddr;
132 1.1 brezak {
133 1.1 brezak u_int mrtproto;
134 1.7 mycroft LIST_HEAD(, mfc) *mfchashtbl;
135 1.7 mycroft u_long mfchash;
136 1.1 brezak struct vif viftable[MAXVIFS];
137 1.7 mycroft struct mfc *mfcp, mfc;
138 1.12 lukem struct vif *v;
139 1.12 lukem vifi_t vifi;
140 1.7 mycroft int i;
141 1.7 mycroft int banner_printed;
142 1.14 assar int saved_numeric_addr;
143 1.7 mycroft int numvifs;
144 1.7 mycroft int nmfc; /* No. of cache entries */
145 1.1 brezak
146 1.4 mycroft if (mrpaddr == 0) {
147 1.1 brezak printf("ip_mrtproto: symbol not in namelist\n");
148 1.1 brezak return;
149 1.1 brezak }
150 1.1 brezak
151 1.4 mycroft kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
152 1.1 brezak switch (mrtproto) {
153 1.4 mycroft case 0:
154 1.1 brezak printf("no multicast routing compiled into this system\n");
155 1.1 brezak return;
156 1.1 brezak
157 1.4 mycroft case IGMP_DVMRP:
158 1.1 brezak break;
159 1.1 brezak
160 1.4 mycroft default:
161 1.1 brezak printf("multicast routing protocol %u, unknown\n", mrtproto);
162 1.1 brezak return;
163 1.1 brezak }
164 1.1 brezak
165 1.7 mycroft if (mfchashtbladdr == 0) {
166 1.7 mycroft printf("mfchashtbl: symbol not in namelist\n");
167 1.7 mycroft return;
168 1.7 mycroft }
169 1.7 mycroft if (mfchashaddr == 0) {
170 1.7 mycroft printf("mfchash: symbol not in namelist\n");
171 1.1 brezak return;
172 1.1 brezak }
173 1.1 brezak if (vifaddr == 0) {
174 1.1 brezak printf("viftable: symbol not in namelist\n");
175 1.1 brezak return;
176 1.1 brezak }
177 1.1 brezak
178 1.14 assar saved_numeric_addr = numeric_addr;
179 1.14 assar numeric_addr = 1;
180 1.1 brezak
181 1.4 mycroft kread(vifaddr, (char *)&viftable, sizeof(viftable));
182 1.1 brezak banner_printed = 0;
183 1.7 mycroft numvifs = 0;
184 1.7 mycroft
185 1.1 brezak for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) {
186 1.4 mycroft if (v->v_lcl_addr.s_addr == 0)
187 1.4 mycroft continue;
188 1.7 mycroft numvifs = vifi;
189 1.1 brezak
190 1.1 brezak if (!banner_printed) {
191 1.7 mycroft printf("\nVirtual Interface Table\n %s%s",
192 1.7 mycroft "Vif Thresh Limit Local-Address ",
193 1.7 mycroft "Remote-Address Pkt_in Pkt_out\n");
194 1.1 brezak banner_printed = 1;
195 1.1 brezak }
196 1.1 brezak
197 1.7 mycroft printf(" %3u %3u %5u %-15.15s",
198 1.7 mycroft vifi, v->v_threshold, v->v_rate_limit,
199 1.7 mycroft routename(v->v_lcl_addr.s_addr));
200 1.11 christos printf(" %-15.15s %6lu %7lu\n", (v->v_flags & VIFF_TUNNEL) ?
201 1.7 mycroft routename(v->v_rmt_addr.s_addr) : "",
202 1.7 mycroft v->v_pkt_in, v->v_pkt_out);
203 1.1 brezak }
204 1.4 mycroft if (!banner_printed)
205 1.4 mycroft printf("\nVirtual Interface Table is empty\n");
206 1.1 brezak
207 1.7 mycroft kread(mfchashtbladdr, (char *)&mfchashtbl, sizeof(mfchashtbl));
208 1.7 mycroft kread(mfchashaddr, (char *)&mfchash, sizeof(mfchash));
209 1.1 brezak banner_printed = 0;
210 1.7 mycroft nmfc = 0;
211 1.7 mycroft
212 1.10 mycroft if (mfchashtbl != 0)
213 1.7 mycroft for (i = 0; i <= mfchash; ++i) {
214 1.7 mycroft kread((u_long)&mfchashtbl[i], (char *)&mfcp, sizeof(mfcp));
215 1.7 mycroft
216 1.7 mycroft for (; mfcp != 0; mfcp = mfc.mfc_hash.le_next) {
217 1.4 mycroft if (!banner_printed) {
218 1.7 mycroft printf("\nMulticast Forwarding Cache\n %s%s",
219 1.7 mycroft "Hash Origin Mcastgroup ",
220 1.7 mycroft "Traffic In-Vif Out-Vifs/Forw-ttl\n");
221 1.4 mycroft banner_printed = 1;
222 1.4 mycroft }
223 1.1 brezak
224 1.7 mycroft kread((u_long)mfcp, (char *)&mfc, sizeof(mfc));
225 1.7 mycroft printf(" %3u %-15.15s",
226 1.7 mycroft i, routename(mfc.mfc_origin.s_addr));
227 1.7 mycroft printf(" %-15.15s %7s %3u ",
228 1.7 mycroft routename(mfc.mfc_mcastgrp.s_addr),
229 1.7 mycroft pktscale(mfc.mfc_pkt_cnt), mfc.mfc_parent);
230 1.7 mycroft for (vifi = 0; vifi <= numvifs; ++vifi)
231 1.7 mycroft if (mfc.mfc_ttls[vifi])
232 1.7 mycroft printf(" %u/%u", vifi, mfc.mfc_ttls[vifi]);
233 1.7 mycroft
234 1.4 mycroft printf("\n");
235 1.7 mycroft nmfc++;
236 1.1 brezak }
237 1.1 brezak }
238 1.4 mycroft if (!banner_printed)
239 1.7 mycroft printf("\nMulticast Forwarding Cache is empty\n");
240 1.7 mycroft else
241 1.7 mycroft printf("\nTotal no. of entries in cache: %d\n", nmfc);
242 1.1 brezak
243 1.1 brezak printf("\n");
244 1.14 assar numeric_addr = saved_numeric_addr;
245 1.1 brezak }
246 1.1 brezak
247 1.1 brezak
248 1.4 mycroft void
249 1.1 brezak mrt_stats(mrpaddr, mstaddr)
250 1.3 cgd u_long mrpaddr, mstaddr;
251 1.1 brezak {
252 1.1 brezak u_int mrtproto;
253 1.1 brezak struct mrtstat mrtstat;
254 1.1 brezak
255 1.7 mycroft if (mrpaddr == 0) {
256 1.1 brezak printf("ip_mrtproto: symbol not in namelist\n");
257 1.1 brezak return;
258 1.1 brezak }
259 1.1 brezak
260 1.4 mycroft kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
261 1.1 brezak switch (mrtproto) {
262 1.7 mycroft case 0:
263 1.1 brezak printf("no multicast routing compiled into this system\n");
264 1.1 brezak return;
265 1.1 brezak
266 1.7 mycroft case IGMP_DVMRP:
267 1.1 brezak break;
268 1.1 brezak
269 1.7 mycroft default:
270 1.1 brezak printf("multicast routing protocol %u, unknown\n", mrtproto);
271 1.1 brezak return;
272 1.1 brezak }
273 1.1 brezak
274 1.1 brezak if (mstaddr == 0) {
275 1.1 brezak printf("mrtstat: symbol not in namelist\n");
276 1.1 brezak return;
277 1.1 brezak }
278 1.1 brezak
279 1.4 mycroft kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
280 1.1 brezak printf("multicast routing:\n");
281 1.15 itojun printf("\t%lu datagram%s with no route for origin\n",
282 1.7 mycroft mrtstat.mrts_no_route, plural(mrtstat.mrts_no_route));
283 1.15 itojun printf("\t%lu upcall%s made to mrouted\n",
284 1.7 mycroft mrtstat.mrts_upcalls, plural(mrtstat.mrts_upcalls));
285 1.15 itojun printf("\t%lu datagram%s with malformed tunnel options\n",
286 1.7 mycroft mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel));
287 1.15 itojun printf("\t%lu datagram%s with no room for tunnel options\n",
288 1.7 mycroft mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel));
289 1.15 itojun printf("\t%lu datagram%s arrived on wrong interface\n",
290 1.7 mycroft mrtstat.mrts_wrong_if, plural(mrtstat.mrts_wrong_if));
291 1.15 itojun printf("\t%lu datagram%s dropped due to upcall Q overflow\n",
292 1.7 mycroft mrtstat.mrts_upq_ovflw, plural(mrtstat.mrts_upq_ovflw));
293 1.15 itojun printf("\t%lu datagram%s dropped due to upcall socket overflow\n",
294 1.7 mycroft mrtstat.mrts_upq_sockfull, plural(mrtstat.mrts_upq_sockfull));
295 1.15 itojun printf("\t%lu datagram%s cleaned up by the cache\n",
296 1.7 mycroft mrtstat.mrts_cache_cleanups, plural(mrtstat.mrts_cache_cleanups));
297 1.15 itojun printf("\t%lu datagram%s dropped selectively by ratelimiter\n",
298 1.7 mycroft mrtstat.mrts_drop_sel, plural(mrtstat.mrts_drop_sel));
299 1.15 itojun printf("\t%lu datagram%s dropped - bucket Q overflow\n",
300 1.7 mycroft mrtstat.mrts_q_overflow, plural(mrtstat.mrts_q_overflow));
301 1.15 itojun printf("\t%lu datagram%s dropped - larger than bkt size\n",
302 1.7 mycroft mrtstat.mrts_pkt2large, plural(mrtstat.mrts_pkt2large));
303 1.1 brezak }
304