xref: /freebsd/usr.bin/netstat/mroute.c (revision 17ee9d00bc1ae1e598c38f25826f861e4bc6c3ce)
1 /*
2  * Copyright (c) 1989 Stephen Deering
3  * Copyright (c) 1992, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * Stephen Deering of Stanford University.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *	This product includes software developed by the University of
20  *	California, Berkeley and its contributors.
21  * 4. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  *	@(#)mroute.c	8.1 (Berkeley) 6/6/93
38  */
39 
40 /*
41  * Print DVMRP multicast routing structures and statistics.
42  *
43  * MROUTING 1.0
44  */
45 
46 #include <sys/param.h>
47 #include <sys/socket.h>
48 #include <sys/socketvar.h>
49 #include <sys/protosw.h>
50 
51 #include <net/if.h>
52 #include <netinet/in.h>
53 #include <netinet/igmp.h>
54 #define KERNEL 1
55 #include <netinet/ip_mroute.h>
56 #undef KERNEL
57 
58 #include <stdio.h>
59 #include <stdlib.h>
60 #include "netstat.h"
61 
62 void
63 mroutepr(mrpaddr, mrtaddr, vifaddr)
64 	u_long mrpaddr, mrtaddr, vifaddr;
65 {
66 #if 0
67 	u_int mrtproto;
68 	struct mrt *mrttable[MRTHASHSIZ];
69 	struct vif viftable[MAXVIFS];
70 	register struct mrt *mrt;
71 	struct mrt smrt;
72 	register struct vif *v;
73 	register vifi_t vifi;
74 	register struct in_addr *grp;
75 	register int i, n;
76 	register int banner_printed;
77 	register int saved_nflag;
78 
79 	if (mrpaddr == 0) {
80 		printf("ip_mrtproto: symbol not in namelist\n");
81 		return;
82 	}
83 
84 	kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
85 	switch (mrtproto) {
86 
87 	case 0:
88 		printf("no multicast routing compiled into this system\n");
89 		return;
90 
91 	case IGMP_DVMRP:
92 		break;
93 
94 	default:
95 		printf("multicast routing protocol %u, unknown\n", mrtproto);
96 		return;
97 	}
98 
99 	if (mrtaddr == 0) {
100 		printf("mrttable: symbol not in namelist\n");
101 		return;
102 	}
103 	if (vifaddr == 0) {
104 		printf("viftable: symbol not in namelist\n");
105 		return;
106 	}
107 
108 	saved_nflag = nflag;
109 	nflag = 1;
110 
111 	kread(vifaddr, (char *)&viftable, sizeof(viftable));
112 	banner_printed = 0;
113 	for (vifi = 0, v = viftable; vifi < MAXVIFS; ++vifi, ++v) {
114 		if (v->v_lcl_addr.s_addr == 0)
115 			continue;
116 
117 		if (!banner_printed) {
118 			printf("\nVirtual Interface Table\n%s%s",
119 			    " Vif   Threshold   Local-Address   ",
120 			    "Remote-Address   Groups\n");
121 			banner_printed = 1;
122 		}
123 
124 		printf(" %2u       %3u      %-15.15s",
125 		    vifi, v->v_threshold, routename(v->v_lcl_addr.s_addr));
126 		printf(" %-15.15s\n", (v->v_flags & VIFF_TUNNEL) ?
127 		    routename(v->v_rmt_addr.s_addr) : "");
128 
129 		n = v->v_lcl_grps_n;
130 		grp = (struct in_addr *)malloc(n * sizeof(*grp));
131 		if (grp == NULL) {
132 			printf("v_lcl_grps_n: malloc failed\n");
133 			return;
134 		}
135 		kread((u_long)v->v_lcl_grps, (caddr_t)grp, n * sizeof(*grp));
136 		for (i = 0; i < n; ++i)
137 			printf("%51s %-15.15s\n",
138 			    "", routename((grp++)->s_addr));
139 		free(grp);
140 	}
141 	if (!banner_printed)
142 		printf("\nVirtual Interface Table is empty\n");
143 
144 	kread(mrtaddr, (char *)&mrttable, sizeof(mrttable));
145 	banner_printed = 0;
146 	for (i = 0; i < MRTHASHSIZ; ++i) {
147 		for (mrt = mrttable[i]; mrt != NULL; mrt = mrt->mrt_next) {
148 			if (!banner_printed) {
149 				printf("\nMulticast Routing Table\n%s",
150 				    " Hash  Origin-Subnet  In-Vif  Out-Vifs\n");
151 				banner_printed = 1;
152 			}
153 
154 			kread((u_long)mrt, (char *)&smrt, sizeof(*mrt));
155 			mrt = &smrt;
156 			printf(" %3u   %-15.15s  %2u   ",
157 			    i, netname(mrt->mrt_origin.s_addr,
158 			    ntohl(mrt->mrt_originmask.s_addr)),
159 			    mrt->mrt_parent);
160 			for (vifi = 0; vifi < MAXVIFS; ++vifi)
161 				if (VIFM_ISSET(vifi, mrt->mrt_children))
162 					printf(" %u%c",
163 					    vifi,
164 					    VIFM_ISSET(vifi, mrt->mrt_leaves) ?
165 					    '*' : ' ');
166 			printf("\n");
167 		}
168 	}
169 	if (!banner_printed)
170 		printf("\nMulticast Routing Table is empty\n");
171 
172 	printf("\n");
173 	nflag = saved_nflag;
174 #else
175 	printf("this isn't supported yet\n");
176 #endif
177 }
178 
179 
180 void
181 mrt_stats(mrpaddr, mstaddr)
182 	u_long mrpaddr, mstaddr;
183 {
184 	u_int mrtproto;
185 	struct mrtstat mrtstat;
186 
187 	if(mrpaddr == 0) {
188 		printf("ip_mrtproto: symbol not in namelist\n");
189 		return;
190 	}
191 
192 	kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
193 	switch (mrtproto) {
194 	    case 0:
195 		printf("no multicast routing compiled into this system\n");
196 		return;
197 
198 	    case IGMP_DVMRP:
199 		break;
200 
201 	    default:
202 		printf("multicast routing protocol %u, unknown\n", mrtproto);
203 		return;
204 	}
205 
206 	if (mstaddr == 0) {
207 		printf("mrtstat: symbol not in namelist\n");
208 		return;
209 	}
210 
211 	kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
212 	printf("multicast routing:\n");
213 	printf(" %10u multicast forwarding cache lookup%s\n",
214 	  mrtstat.mrts_mfc_lookups, plural(mrtstat.mrts_mfc_lookups));
215 	printf(" %10u multicast forwarding cache miss%s\n",
216 	  mrtstat.mrts_mfc_misses, plurales(mrtstat.mrts_mfc_misses));
217 	printf(" %10u upcall%s to mrouted\n",
218 	  mrtstat.mrts_upcalls, plural(mrtstat.mrts_upcalls));
219 	printf(" %10u upcall queue overflow%s\n",
220 	  mrtstat.mrts_upq_ovflw, plural(mrtstat.mrts_upq_ovflw));
221 	printf(" %10u cache cleanup%s\n",
222 	  mrtstat.mrts_cache_cleanups, plural(mrtstat.mrts_cache_cleanups));
223 	printf(" %10u datagram%s with no route for origin\n",
224 	  mrtstat.mrts_no_route, plural(mrtstat.mrts_no_route));
225 	printf(" %10u datagram%s with malformed tunnel options\n",
226 	  mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel));
227 	printf(" %10u datagram%s with no room for tunnel options\n",
228 	  mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel));
229 	printf(" %10u datagram%s arrived on wrong interface\n",
230 	  mrtstat.mrts_wrong_if, plural(mrtstat.mrts_wrong_if));
231 	printf(" %10u datagram%s selectively dropped\n",
232 	  mrtstat.mrts_drop_sel, plural(mrtstat.mrts_drop_sel));
233 	printf(" %10u datagram%s dropped due to queue overflow\n",
234 	  mrtstat.mrts_q_overflow, plural(mrtstat.mrts_q_overflow));
235 	printf(" %10u datagram%s dropped for being too large\n",
236 	  mrtstat.mrts_pkt2large, plural(mrtstat.mrts_pkt2large));
237 }
238