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