mroute.c revision 1.21 1 1.21 elad /* $NetBSD: mroute.c,v 1.21 2006/05/28 16:51:40 elad 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.21 elad __RCSID("$NetBSD: mroute.c,v 1.21 2006/05/28 16:51:40 elad Exp $");
80 1.12 lukem #endif
81 1.12 lukem #endif /* not lint */
82 1.12 lukem
83 1.4 mycroft /*
84 1.18 manu * Print 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.20 rpaulo #include <kvm.h>
105 1.4 mycroft #include "netstat.h"
106 1.1 brezak
107 1.11 christos static char *pktscale __P((u_long));
108 1.18 manu static void print_bw_meter __P((struct bw_meter *, int *));
109 1.11 christos
110 1.11 christos static char *
111 1.7 mycroft pktscale(n)
112 1.7 mycroft u_long n;
113 1.7 mycroft {
114 1.16 itojun static char buf[20];
115 1.7 mycroft char t;
116 1.7 mycroft
117 1.7 mycroft if (n < 1024)
118 1.7 mycroft t = ' ';
119 1.7 mycroft else if (n < 1024 * 1024) {
120 1.7 mycroft t = 'k';
121 1.7 mycroft n /= 1024;
122 1.7 mycroft } else {
123 1.7 mycroft t = 'm';
124 1.7 mycroft n /= 1048576;
125 1.7 mycroft }
126 1.7 mycroft
127 1.13 mrg (void)snprintf(buf, sizeof buf, "%lu%c", n, t);
128 1.7 mycroft return (buf);
129 1.7 mycroft }
130 1.7 mycroft
131 1.4 mycroft void
132 1.7 mycroft mroutepr(mrpaddr, mfchashtbladdr, mfchashaddr, vifaddr)
133 1.7 mycroft u_long mrpaddr, mfchashtbladdr, mfchashaddr, vifaddr;
134 1.1 brezak {
135 1.1 brezak u_int mrtproto;
136 1.7 mycroft LIST_HEAD(, mfc) *mfchashtbl;
137 1.7 mycroft u_long mfchash;
138 1.1 brezak struct vif viftable[MAXVIFS];
139 1.7 mycroft struct mfc *mfcp, mfc;
140 1.12 lukem struct vif *v;
141 1.12 lukem vifi_t vifi;
142 1.7 mycroft int i;
143 1.7 mycroft int banner_printed;
144 1.14 assar int saved_numeric_addr;
145 1.7 mycroft int numvifs;
146 1.7 mycroft int nmfc; /* No. of cache entries */
147 1.1 brezak
148 1.4 mycroft if (mrpaddr == 0) {
149 1.1 brezak printf("ip_mrtproto: symbol not in namelist\n");
150 1.1 brezak return;
151 1.1 brezak }
152 1.1 brezak
153 1.4 mycroft kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
154 1.1 brezak switch (mrtproto) {
155 1.4 mycroft case 0:
156 1.1 brezak printf("no multicast routing compiled into this system\n");
157 1.1 brezak return;
158 1.1 brezak
159 1.4 mycroft case IGMP_DVMRP:
160 1.1 brezak break;
161 1.1 brezak
162 1.4 mycroft default:
163 1.1 brezak printf("multicast routing protocol %u, unknown\n", mrtproto);
164 1.1 brezak return;
165 1.1 brezak }
166 1.1 brezak
167 1.7 mycroft if (mfchashtbladdr == 0) {
168 1.7 mycroft printf("mfchashtbl: symbol not in namelist\n");
169 1.7 mycroft return;
170 1.7 mycroft }
171 1.7 mycroft if (mfchashaddr == 0) {
172 1.7 mycroft printf("mfchash: symbol not in namelist\n");
173 1.1 brezak return;
174 1.1 brezak }
175 1.1 brezak if (vifaddr == 0) {
176 1.1 brezak printf("viftable: symbol not in namelist\n");
177 1.1 brezak return;
178 1.1 brezak }
179 1.1 brezak
180 1.14 assar saved_numeric_addr = numeric_addr;
181 1.14 assar numeric_addr = 1;
182 1.1 brezak
183 1.4 mycroft kread(vifaddr, (char *)&viftable, sizeof(viftable));
184 1.1 brezak banner_printed = 0;
185 1.7 mycroft numvifs = 0;
186 1.7 mycroft
187 1.1 brezak for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) {
188 1.4 mycroft if (v->v_lcl_addr.s_addr == 0)
189 1.4 mycroft continue;
190 1.7 mycroft numvifs = vifi;
191 1.1 brezak
192 1.1 brezak if (!banner_printed) {
193 1.7 mycroft printf("\nVirtual Interface Table\n %s%s",
194 1.7 mycroft "Vif Thresh Limit Local-Address ",
195 1.7 mycroft "Remote-Address Pkt_in Pkt_out\n");
196 1.1 brezak banner_printed = 1;
197 1.1 brezak }
198 1.1 brezak
199 1.7 mycroft printf(" %3u %3u %5u %-15.15s",
200 1.7 mycroft vifi, v->v_threshold, v->v_rate_limit,
201 1.21 elad routename4(v->v_lcl_addr.s_addr));
202 1.11 christos printf(" %-15.15s %6lu %7lu\n", (v->v_flags & VIFF_TUNNEL) ?
203 1.21 elad routename4(v->v_rmt_addr.s_addr) : "",
204 1.7 mycroft v->v_pkt_in, v->v_pkt_out);
205 1.1 brezak }
206 1.4 mycroft if (!banner_printed)
207 1.4 mycroft printf("\nVirtual Interface Table is empty\n");
208 1.1 brezak
209 1.7 mycroft kread(mfchashtbladdr, (char *)&mfchashtbl, sizeof(mfchashtbl));
210 1.7 mycroft kread(mfchashaddr, (char *)&mfchash, sizeof(mfchash));
211 1.1 brezak banner_printed = 0;
212 1.7 mycroft nmfc = 0;
213 1.7 mycroft
214 1.10 mycroft if (mfchashtbl != 0)
215 1.7 mycroft for (i = 0; i <= mfchash; ++i) {
216 1.7 mycroft kread((u_long)&mfchashtbl[i], (char *)&mfcp, sizeof(mfcp));
217 1.7 mycroft
218 1.7 mycroft for (; mfcp != 0; mfcp = mfc.mfc_hash.le_next) {
219 1.4 mycroft if (!banner_printed) {
220 1.7 mycroft printf("\nMulticast Forwarding Cache\n %s%s",
221 1.7 mycroft "Hash Origin Mcastgroup ",
222 1.7 mycroft "Traffic In-Vif Out-Vifs/Forw-ttl\n");
223 1.4 mycroft banner_printed = 1;
224 1.4 mycroft }
225 1.1 brezak
226 1.7 mycroft kread((u_long)mfcp, (char *)&mfc, sizeof(mfc));
227 1.7 mycroft printf(" %3u %-15.15s",
228 1.21 elad i, routename4(mfc.mfc_origin.s_addr));
229 1.7 mycroft printf(" %-15.15s %7s %3u ",
230 1.21 elad routename4(mfc.mfc_mcastgrp.s_addr),
231 1.7 mycroft pktscale(mfc.mfc_pkt_cnt), mfc.mfc_parent);
232 1.7 mycroft for (vifi = 0; vifi <= numvifs; ++vifi)
233 1.7 mycroft if (mfc.mfc_ttls[vifi])
234 1.7 mycroft printf(" %u/%u", vifi, mfc.mfc_ttls[vifi]);
235 1.7 mycroft
236 1.4 mycroft printf("\n");
237 1.18 manu
238 1.18 manu /* Print the bw meter information */
239 1.18 manu {
240 1.18 manu struct bw_meter bw_meter, *bwm;
241 1.18 manu int banner_printed2 = 0;
242 1.18 manu
243 1.18 manu bwm = mfc.mfc_bw_meter;
244 1.18 manu while (bwm) {
245 1.18 manu kread((u_long)bwm,
246 1.18 manu (char *)&bw_meter,
247 1.18 manu sizeof bw_meter);
248 1.18 manu print_bw_meter(&bw_meter,
249 1.18 manu &banner_printed2);
250 1.18 manu bwm = bw_meter.bm_mfc_next;
251 1.18 manu }
252 1.18 manu #if 0 /* Don't ever print it? */
253 1.18 manu if (! banner_printed2)
254 1.18 manu printf("\n No Bandwidth Meters\n");
255 1.18 manu #endif
256 1.18 manu }
257 1.18 manu
258 1.7 mycroft nmfc++;
259 1.1 brezak }
260 1.1 brezak }
261 1.4 mycroft if (!banner_printed)
262 1.7 mycroft printf("\nMulticast Forwarding Cache is empty\n");
263 1.7 mycroft else
264 1.7 mycroft printf("\nTotal no. of entries in cache: %d\n", nmfc);
265 1.1 brezak
266 1.1 brezak printf("\n");
267 1.14 assar numeric_addr = saved_numeric_addr;
268 1.1 brezak }
269 1.1 brezak
270 1.18 manu static void
271 1.18 manu print_bw_meter(bw_meter, banner_printed)
272 1.18 manu struct bw_meter *bw_meter;
273 1.18 manu int *banner_printed;
274 1.18 manu {
275 1.18 manu char s0[256], s1[256], s2[256], s3[256];
276 1.18 manu struct timeval now, end, delta;
277 1.18 manu
278 1.18 manu gettimeofday(&now, NULL);
279 1.18 manu
280 1.18 manu if (! *banner_printed) {
281 1.18 manu printf(" Bandwidth Meters\n");
282 1.18 manu printf(" %-30s", "Measured(Start|Packets|Bytes)");
283 1.18 manu printf(" %s", "Type");
284 1.18 manu printf(" %-30s", "Thresh(Interval|Packets|Bytes)");
285 1.18 manu printf(" Remain");
286 1.18 manu printf("\n");
287 1.18 manu *banner_printed = 1;
288 1.18 manu }
289 1.18 manu
290 1.18 manu /* The measured values */
291 1.18 manu if (bw_meter->bm_flags & BW_METER_UNIT_PACKETS)
292 1.19 martin sprintf(s1, "%llu", (unsigned long long)bw_meter->bm_measured.b_packets);
293 1.18 manu else
294 1.18 manu sprintf(s1, "?");
295 1.18 manu if (bw_meter->bm_flags & BW_METER_UNIT_BYTES)
296 1.19 martin sprintf(s2, "%llu", (unsigned long long)bw_meter->bm_measured.b_bytes);
297 1.18 manu else
298 1.18 manu sprintf(s2, "?");
299 1.18 manu sprintf(s0, "%lu.%lu|%s|%s",
300 1.18 manu bw_meter->bm_start_time.tv_sec,
301 1.18 manu bw_meter->bm_start_time.tv_usec,
302 1.18 manu s1, s2);
303 1.18 manu printf(" %-30s", s0);
304 1.18 manu
305 1.18 manu /* The type of entry */
306 1.18 manu sprintf(s0, "%s", "?");
307 1.18 manu if (bw_meter->bm_flags & BW_METER_GEQ)
308 1.18 manu sprintf(s0, "%s", ">=");
309 1.18 manu else if (bw_meter->bm_flags & BW_METER_LEQ)
310 1.18 manu sprintf(s0, "%s", "<=");
311 1.18 manu printf(" %-3s", s0);
312 1.18 manu
313 1.18 manu /* The threshold values */
314 1.18 manu if (bw_meter->bm_flags & BW_METER_UNIT_PACKETS)
315 1.19 martin sprintf(s1, "%llu", (unsigned long long)bw_meter->bm_threshold.b_packets);
316 1.18 manu else
317 1.18 manu sprintf(s1, "?");
318 1.18 manu if (bw_meter->bm_flags & BW_METER_UNIT_BYTES)
319 1.19 martin sprintf(s2, "%llu", (unsigned long long)bw_meter->bm_threshold.b_bytes);
320 1.18 manu else
321 1.18 manu sprintf(s2, "?");
322 1.18 manu sprintf(s0, "%lu.%lu|%s|%s",
323 1.18 manu bw_meter->bm_threshold.b_time.tv_sec,
324 1.18 manu bw_meter->bm_threshold.b_time.tv_usec,
325 1.18 manu s1, s2);
326 1.18 manu printf(" %-30s", s0);
327 1.18 manu
328 1.18 manu /* Remaining time */
329 1.18 manu timeradd(&bw_meter->bm_start_time,
330 1.18 manu &bw_meter->bm_threshold.b_time, &end);
331 1.18 manu if (timercmp(&now, &end, <=)) {
332 1.18 manu timersub(&end, &now, &delta);
333 1.18 manu sprintf(s3, "%lu.%lu", delta.tv_sec, delta.tv_usec);
334 1.18 manu } else {
335 1.18 manu /* Negative time */
336 1.18 manu timersub(&now, &end, &delta);
337 1.18 manu sprintf(s3, "-%lu.%lu", delta.tv_sec, delta.tv_usec);
338 1.18 manu }
339 1.18 manu printf(" %s", s3);
340 1.18 manu
341 1.18 manu printf("\n");
342 1.18 manu }
343 1.1 brezak
344 1.4 mycroft void
345 1.1 brezak mrt_stats(mrpaddr, mstaddr)
346 1.3 cgd u_long mrpaddr, mstaddr;
347 1.1 brezak {
348 1.1 brezak u_int mrtproto;
349 1.1 brezak struct mrtstat mrtstat;
350 1.1 brezak
351 1.7 mycroft if (mrpaddr == 0) {
352 1.1 brezak printf("ip_mrtproto: symbol not in namelist\n");
353 1.1 brezak return;
354 1.1 brezak }
355 1.1 brezak
356 1.4 mycroft kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
357 1.1 brezak switch (mrtproto) {
358 1.7 mycroft case 0:
359 1.1 brezak printf("no multicast routing compiled into this system\n");
360 1.1 brezak return;
361 1.1 brezak
362 1.7 mycroft case IGMP_DVMRP:
363 1.1 brezak break;
364 1.1 brezak
365 1.7 mycroft default:
366 1.1 brezak printf("multicast routing protocol %u, unknown\n", mrtproto);
367 1.1 brezak return;
368 1.1 brezak }
369 1.1 brezak
370 1.1 brezak if (mstaddr == 0) {
371 1.1 brezak printf("mrtstat: symbol not in namelist\n");
372 1.1 brezak return;
373 1.1 brezak }
374 1.1 brezak
375 1.4 mycroft kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
376 1.1 brezak printf("multicast routing:\n");
377 1.15 itojun printf("\t%lu datagram%s with no route for origin\n",
378 1.7 mycroft mrtstat.mrts_no_route, plural(mrtstat.mrts_no_route));
379 1.15 itojun printf("\t%lu upcall%s made to mrouted\n",
380 1.7 mycroft mrtstat.mrts_upcalls, plural(mrtstat.mrts_upcalls));
381 1.15 itojun printf("\t%lu datagram%s with malformed tunnel options\n",
382 1.7 mycroft mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel));
383 1.15 itojun printf("\t%lu datagram%s with no room for tunnel options\n",
384 1.7 mycroft mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel));
385 1.15 itojun printf("\t%lu datagram%s arrived on wrong interface\n",
386 1.7 mycroft mrtstat.mrts_wrong_if, plural(mrtstat.mrts_wrong_if));
387 1.15 itojun printf("\t%lu datagram%s dropped due to upcall Q overflow\n",
388 1.7 mycroft mrtstat.mrts_upq_ovflw, plural(mrtstat.mrts_upq_ovflw));
389 1.15 itojun printf("\t%lu datagram%s dropped due to upcall socket overflow\n",
390 1.7 mycroft mrtstat.mrts_upq_sockfull, plural(mrtstat.mrts_upq_sockfull));
391 1.15 itojun printf("\t%lu datagram%s cleaned up by the cache\n",
392 1.7 mycroft mrtstat.mrts_cache_cleanups, plural(mrtstat.mrts_cache_cleanups));
393 1.15 itojun printf("\t%lu datagram%s dropped selectively by ratelimiter\n",
394 1.7 mycroft mrtstat.mrts_drop_sel, plural(mrtstat.mrts_drop_sel));
395 1.15 itojun printf("\t%lu datagram%s dropped - bucket Q overflow\n",
396 1.7 mycroft mrtstat.mrts_q_overflow, plural(mrtstat.mrts_q_overflow));
397 1.15 itojun printf("\t%lu datagram%s dropped - larger than bkt size\n",
398 1.7 mycroft mrtstat.mrts_pkt2large, plural(mrtstat.mrts_pkt2large));
399 1.1 brezak }
400