Annotation of src/usr.bin/netstat/mroute.c, Revision 1.4
1.4 ! millert 1: /* $OpenBSD: mroute.c,v 1.3 1996/06/26 05:37:23 deraadt 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:
62: #include <stdio.h>
63: #include <stdlib.h>
64: #include "netstat.h"
65:
66: char *
67: pktscale(n)
68: u_long n;
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.4 ! millert 83: sprintf(buf, "%lu%c", n, t);
1.1 deraadt 84: return (buf);
85: }
86:
87: void
88: mroutepr(mrpaddr, mfchashtbladdr, mfchashaddr, vifaddr)
89: u_long mrpaddr, mfchashtbladdr, mfchashaddr, vifaddr;
90: {
91: u_int mrtproto;
92: LIST_HEAD(, mfc) *mfchashtbl;
93: u_long mfchash;
94: struct vif viftable[MAXVIFS];
95: struct mfc *mfcp, mfc;
96: register struct vif *v;
97: register vifi_t vifi;
98: int i;
99: int banner_printed;
100: int saved_nflag;
101: int numvifs;
102: int nmfc; /* No. of cache entries */
103:
104: if (mrpaddr == 0) {
105: printf("ip_mrtproto: symbol not in namelist\n");
106: return;
107: }
108:
109: kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
110: switch (mrtproto) {
111: case 0:
112: printf("no multicast routing compiled into this system\n");
113: return;
114:
115: case IGMP_DVMRP:
116: break;
117:
118: default:
119: printf("multicast routing protocol %u, unknown\n", mrtproto);
120: return;
121: }
122:
123: if (mfchashtbladdr == 0) {
124: printf("mfchashtbl: symbol not in namelist\n");
125: return;
126: }
127: if (mfchashaddr == 0) {
128: printf("mfchash: symbol not in namelist\n");
129: return;
130: }
131: if (vifaddr == 0) {
132: printf("viftable: symbol not in namelist\n");
133: return;
134: }
135:
136: saved_nflag = nflag;
137: nflag = 1;
138:
139: kread(vifaddr, (char *)&viftable, sizeof(viftable));
140: banner_printed = 0;
141: numvifs = 0;
142:
143: for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) {
144: if (v->v_lcl_addr.s_addr == 0)
145: continue;
146: numvifs = vifi;
147:
148: if (!banner_printed) {
149: printf("\nVirtual Interface Table\n %s%s",
150: "Vif Thresh Limit Local-Address ",
151: "Remote-Address Pkt_in Pkt_out\n");
152: banner_printed = 1;
153: }
154:
155: printf(" %3u %3u %5u %-15.15s",
156: vifi, v->v_threshold, v->v_rate_limit,
157: routename(v->v_lcl_addr.s_addr));
1.4 ! millert 158: printf(" %-15.15s %6lu %7lu\n", (v->v_flags & VIFF_TUNNEL) ?
1.1 deraadt 159: routename(v->v_rmt_addr.s_addr) : "",
160: v->v_pkt_in, v->v_pkt_out);
161: }
162: if (!banner_printed)
163: printf("\nVirtual Interface Table is empty\n");
164:
165: kread(mfchashtbladdr, (char *)&mfchashtbl, sizeof(mfchashtbl));
166: kread(mfchashaddr, (char *)&mfchash, sizeof(mfchash));
167: banner_printed = 0;
168: nmfc = 0;
169:
1.2 deraadt 170: if (mfchashtbl != 0)
171: for (i = 0; i <= mfchash; ++i) {
172: kread((u_long)&mfchashtbl[i], (char *)&mfcp, sizeof(mfcp));
173:
174: for (; mfcp != 0; mfcp = mfc.mfc_hash.le_next) {
175: if (!banner_printed) {
176: printf("\nMulticast Forwarding Cache\n %s%s",
177: "Hash Origin Mcastgroup ",
178: "Traffic In-Vif Out-Vifs/Forw-ttl\n");
179: banner_printed = 1;
180: }
181:
182: kread((u_long)mfcp, (char *)&mfc, sizeof(mfc));
183: printf(" %3u %-15.15s",
184: i, routename(mfc.mfc_origin.s_addr));
185: printf(" %-15.15s %7s %3u ",
186: routename(mfc.mfc_mcastgrp.s_addr),
187: pktscale(mfc.mfc_pkt_cnt), mfc.mfc_parent);
188: for (vifi = 0; vifi <= numvifs; ++vifi)
189: if (mfc.mfc_ttls[vifi])
190: printf(" %u/%u", vifi,
191: mfc.mfc_ttls[vifi]);
1.1 deraadt 192:
1.2 deraadt 193: printf("\n");
194: nmfc++;
1.1 deraadt 195: }
196: }
197: if (!banner_printed)
198: printf("\nMulticast Forwarding Cache is empty\n");
199: else
200: printf("\nTotal no. of entries in cache: %d\n", nmfc);
201:
202: printf("\n");
203: nflag = saved_nflag;
204: }
205:
206:
207: void
208: mrt_stats(mrpaddr, mstaddr)
209: u_long mrpaddr, mstaddr;
210: {
211: u_int mrtproto;
212: struct mrtstat mrtstat;
213:
214: if (mrpaddr == 0) {
215: printf("ip_mrtproto: symbol not in namelist\n");
216: return;
217: }
218:
219: kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
220: switch (mrtproto) {
221: case 0:
222: printf("no multicast routing compiled into this system\n");
223: return;
224:
225: case IGMP_DVMRP:
226: break;
227:
228: default:
229: printf("multicast routing protocol %u, unknown\n", mrtproto);
230: return;
231: }
232:
233: if (mstaddr == 0) {
234: printf("mrtstat: symbol not in namelist\n");
235: return;
236: }
237:
238: kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
239: printf("multicast routing:\n");
1.4 ! millert 240: printf("\t%ld datagram%s with no route for origin\n",
1.1 deraadt 241: mrtstat.mrts_no_route, plural(mrtstat.mrts_no_route));
1.4 ! millert 242: printf("\t%ld upcall%s made to mrouted\n",
1.1 deraadt 243: mrtstat.mrts_upcalls, plural(mrtstat.mrts_upcalls));
1.4 ! millert 244: printf("\t%ld datagram%s with malformed tunnel options\n",
1.1 deraadt 245: mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel));
1.4 ! millert 246: printf("\t%ld datagram%s with no room for tunnel options\n",
1.1 deraadt 247: mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel));
1.4 ! millert 248: printf("\t%ld datagram%s arrived on wrong interface\n",
1.1 deraadt 249: mrtstat.mrts_wrong_if, plural(mrtstat.mrts_wrong_if));
1.4 ! millert 250: printf("\t%ld datagram%s dropped due to upcall Q overflow\n",
1.1 deraadt 251: mrtstat.mrts_upq_ovflw, plural(mrtstat.mrts_upq_ovflw));
1.4 ! millert 252: printf("\t%ld datagram%s dropped due to upcall socket overflow\n",
1.1 deraadt 253: mrtstat.mrts_upq_sockfull, plural(mrtstat.mrts_upq_sockfull));
1.4 ! millert 254: printf("\t%ld datagram%s cleaned up by the cache\n",
1.1 deraadt 255: mrtstat.mrts_cache_cleanups, plural(mrtstat.mrts_cache_cleanups));
1.4 ! millert 256: printf("\t%ld datagram%s dropped selectively by ratelimiter\n",
1.1 deraadt 257: mrtstat.mrts_drop_sel, plural(mrtstat.mrts_drop_sel));
1.4 ! millert 258: printf("\t%ld datagram%s dropped - bucket Q overflow\n",
1.1 deraadt 259: mrtstat.mrts_q_overflow, plural(mrtstat.mrts_q_overflow));
1.4 ! millert 260: printf("\t%ld datagram%s dropped - larger than bkt size\n",
1.1 deraadt 261: mrtstat.mrts_pkt2large, plural(mrtstat.mrts_pkt2large));
262: }