mroute6.c revision 1.3 1 1.3 bouyer /* $NetBSD: mroute6.c,v 1.3 1999/11/19 10:44:34 bouyer Exp $ */
2 1.2 itojun
3 1.1 itojun /*
4 1.1 itojun * Copyright (C) 1998 WIDE Project.
5 1.1 itojun * All rights reserved.
6 1.1 itojun *
7 1.1 itojun * Redistribution and use in source and binary forms, with or without
8 1.1 itojun * modification, are permitted provided that the following conditions
9 1.1 itojun * are met:
10 1.1 itojun * 1. Redistributions of source code must retain the above copyright
11 1.1 itojun * notice, this list of conditions and the following disclaimer.
12 1.1 itojun * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 itojun * notice, this list of conditions and the following disclaimer in the
14 1.1 itojun * documentation and/or other materials provided with the distribution.
15 1.1 itojun * 3. Neither the name of the project nor the names of its contributors
16 1.1 itojun * may be used to endorse or promote products derived from this software
17 1.1 itojun * without specific prior written permission.
18 1.1 itojun *
19 1.1 itojun * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 1.1 itojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.1 itojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 itojun * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 1.1 itojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 itojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.1 itojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 itojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 itojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 itojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 itojun * SUCH DAMAGE.
30 1.1 itojun */
31 1.1 itojun
32 1.1 itojun /*
33 1.1 itojun * Copyright (c) 1989 Stephen Deering
34 1.1 itojun * Copyright (c) 1992, 1993
35 1.1 itojun * The Regents of the University of California. All rights reserved.
36 1.1 itojun *
37 1.1 itojun * This code is derived from software contributed to Berkeley by
38 1.1 itojun * Stephen Deering of Stanford University.
39 1.1 itojun *
40 1.1 itojun * Redistribution and use in source and binary forms, with or without
41 1.1 itojun * modification, are permitted provided that the following conditions
42 1.1 itojun * are met:
43 1.1 itojun * 1. Redistributions of source code must retain the above copyright
44 1.1 itojun * notice, this list of conditions and the following disclaimer.
45 1.1 itojun * 2. Redistributions in binary form must reproduce the above copyright
46 1.1 itojun * notice, this list of conditions and the following disclaimer in the
47 1.1 itojun * documentation and/or other materials provided with the distribution.
48 1.1 itojun * 3. All advertising materials mentioning features or use of this software
49 1.1 itojun * must display the following acknowledgement:
50 1.1 itojun * This product includes software developed by the University of
51 1.1 itojun * California, Berkeley and its contributors.
52 1.1 itojun * 4. Neither the name of the University nor the names of its contributors
53 1.1 itojun * may be used to endorse or promote products derived from this software
54 1.1 itojun * without specific prior written permission.
55 1.1 itojun *
56 1.1 itojun * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57 1.1 itojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 1.1 itojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59 1.1 itojun * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60 1.1 itojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61 1.1 itojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62 1.1 itojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 1.1 itojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64 1.1 itojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65 1.1 itojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 1.1 itojun * SUCH DAMAGE.
67 1.1 itojun *
68 1.1 itojun * @(#)mroute.c 8.2 (Berkeley) 4/28/95
69 1.1 itojun */
70 1.1 itojun
71 1.1 itojun #include <sys/param.h>
72 1.1 itojun #include <sys/queue.h>
73 1.1 itojun #include <sys/socket.h>
74 1.1 itojun #include <sys/socketvar.h>
75 1.1 itojun #include <sys/protosw.h>
76 1.1 itojun
77 1.1 itojun #include <net/if.h>
78 1.1 itojun
79 1.1 itojun #include <netinet/in.h>
80 1.1 itojun
81 1.1 itojun #define KERNEL 1
82 1.1 itojun #include <netinet6/ip6_mroute.h>
83 1.1 itojun #undef KERNEL
84 1.1 itojun
85 1.1 itojun #include <stdio.h>
86 1.1 itojun #include "netstat.h"
87 1.1 itojun
88 1.1 itojun #ifdef INET6
89 1.1 itojun
90 1.1 itojun #define WID_ORG (lflag ? 39 : (nflag ? 29 : 18)) /* width of origin column */
91 1.1 itojun #define WID_GRP (lflag ? 18 : (nflag ? 16 : 18)) /* width of group column */
92 1.1 itojun
93 1.1 itojun void
94 1.1 itojun mroute6pr(mrpaddr, mfcaddr, mifaddr)
95 1.1 itojun u_long mrpaddr, mfcaddr, mifaddr;
96 1.1 itojun {
97 1.1 itojun u_int mrtproto;
98 1.1 itojun struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp;
99 1.1 itojun struct mif6 mif6table[MAXMIFS];
100 1.1 itojun struct mf6c mfc;
101 1.1 itojun struct rtdetq rte, *rtep;
102 1.1 itojun register struct mif6 *mifp;
103 1.1 itojun register mifi_t mifi;
104 1.1 itojun register int i;
105 1.1 itojun register int banner_printed;
106 1.1 itojun register int saved_nflag;
107 1.1 itojun mifi_t maxmif = 0;
108 1.1 itojun int waitings;
109 1.1 itojun
110 1.1 itojun if (mrpaddr == 0) {
111 1.1 itojun printf("mroute6pr: symbol not in namelist\n");
112 1.1 itojun return;
113 1.1 itojun }
114 1.1 itojun
115 1.1 itojun kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
116 1.1 itojun switch (mrtproto) {
117 1.1 itojun
118 1.1 itojun case 0:
119 1.1 itojun printf("no IPv6 multicast routing compiled into this system\n");
120 1.1 itojun return;
121 1.1 itojun
122 1.1 itojun case IPPROTO_PIM:
123 1.1 itojun break;
124 1.1 itojun
125 1.1 itojun default:
126 1.1 itojun printf("IPv6 multicast routing protocol %u, unknown\n",
127 1.1 itojun mrtproto);
128 1.1 itojun return;
129 1.1 itojun }
130 1.1 itojun
131 1.1 itojun if (mfcaddr == 0) {
132 1.1 itojun printf("mf6ctable: symbol not in namelist\n");
133 1.1 itojun return;
134 1.1 itojun }
135 1.1 itojun if (mifaddr == 0) {
136 1.1 itojun printf("miftable: symbol not in namelist\n");
137 1.1 itojun return;
138 1.1 itojun }
139 1.1 itojun
140 1.1 itojun saved_nflag = nflag;
141 1.1 itojun nflag = 1;
142 1.1 itojun
143 1.1 itojun kread(mifaddr, (char *)&mif6table, sizeof(mif6table));
144 1.1 itojun banner_printed = 0;
145 1.1 itojun for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) {
146 1.1 itojun struct ifnet ifnet;
147 1.1 itojun char ifname[IFNAMSIZ];
148 1.1 itojun
149 1.1 itojun if (mifp->m6_ifp == NULL)
150 1.1 itojun continue;
151 1.1 itojun
152 1.1 itojun kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet));
153 1.1 itojun maxmif = mifi;
154 1.1 itojun if (!banner_printed) {
155 1.1 itojun printf("\nIPv6 Multicast Interface Table\n"
156 1.1 itojun " Mif Rate PhyIF "
157 1.1 itojun "Pkts-In Pkts-Out\n");
158 1.1 itojun banner_printed = 1;
159 1.1 itojun }
160 1.1 itojun
161 1.1 itojun printf(" %2u %4d",
162 1.1 itojun mifi, mifp->m6_rate_limit);
163 1.1 itojun printf(" %5s", (mifp->m6_flags & MIFF_REGISTER) ?
164 1.1 itojun "reg0" : if_indextoname(ifnet.if_index, ifname));
165 1.1 itojun
166 1.1 itojun printf(" %9lu %9lu\n", mifp->m6_pkt_in, mifp->m6_pkt_out);
167 1.1 itojun }
168 1.1 itojun if (!banner_printed)
169 1.1 itojun printf("\nIPv6 Multicast Interface Table is empty\n");
170 1.1 itojun
171 1.1 itojun kread(mfcaddr, (char *)&mf6ctable, sizeof(mf6ctable));
172 1.1 itojun banner_printed = 0;
173 1.1 itojun for (i = 0; i < MF6CTBLSIZ; ++i) {
174 1.1 itojun mfcp = mf6ctable[i];
175 1.1 itojun while(mfcp) {
176 1.1 itojun kread((u_long)mfcp, (char *)&mfc, sizeof(mfc));
177 1.1 itojun if (!banner_printed) {
178 1.1 itojun printf ("\nIPv6 Multicast Forwarding Cache\n");
179 1.1 itojun printf(" %-*.*s %-*.*s %s",
180 1.1 itojun WID_ORG, WID_ORG, "Origin",
181 1.1 itojun WID_GRP, WID_GRP, "Group",
182 1.1 itojun " Packets Waits In-Mif Out-Mifs\n");
183 1.1 itojun banner_printed = 1;
184 1.1 itojun }
185 1.1 itojun
186 1.1 itojun printf(" %-*.*s", WID_ORG, WID_ORG,
187 1.1 itojun routename6((char *)&mfc.mf6c_origin.sin6_addr));
188 1.1 itojun printf(" %-*.*s", WID_GRP, WID_GRP,
189 1.1 itojun routename6((char *)&mfc.mf6c_mcastgrp.sin6_addr));
190 1.1 itojun printf(" %9lu", mfc.mf6c_pkt_cnt);
191 1.1 itojun
192 1.1 itojun for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) {
193 1.1 itojun waitings++;
194 1.1 itojun kread((u_long)rtep, (char *)&rte, sizeof(rte));
195 1.1 itojun rtep = rte.next;
196 1.1 itojun }
197 1.1 itojun printf(" %3d", waitings);
198 1.1 itojun
199 1.1 itojun if (mfc.mf6c_parent == MF6C_INCOMPLETE_PARENT)
200 1.1 itojun printf(" --- ");
201 1.1 itojun else
202 1.1 itojun printf(" %3d ", mfc.mf6c_parent);
203 1.1 itojun for (mifi = 0; mifi <= MAXMIFS; mifi++) {
204 1.1 itojun if (IF_ISSET(mifi, &mfc.mf6c_ifset))
205 1.1 itojun printf(" %u", mifi);
206 1.1 itojun }
207 1.1 itojun printf("\n");
208 1.1 itojun
209 1.1 itojun mfcp = mfc.mf6c_next;
210 1.1 itojun }
211 1.1 itojun }
212 1.1 itojun if (!banner_printed)
213 1.1 itojun printf("\nIPv6 Multicast Routing Table is empty\n");
214 1.1 itojun
215 1.1 itojun printf("\n");
216 1.1 itojun nflag = saved_nflag;
217 1.1 itojun }
218 1.1 itojun
219 1.1 itojun void
220 1.1 itojun mrt6_stats(mrpaddr, mstaddr)
221 1.1 itojun u_long mrpaddr, mstaddr;
222 1.1 itojun {
223 1.1 itojun u_int mrtproto;
224 1.1 itojun struct mrt6stat mrtstat;
225 1.1 itojun
226 1.1 itojun if(mrpaddr == 0) {
227 1.1 itojun printf("mrt6_stats: symbol not in namelist\n");
228 1.1 itojun return;
229 1.1 itojun }
230 1.1 itojun
231 1.1 itojun kread(mrpaddr, (char *)&mrtproto, sizeof(mrtproto));
232 1.1 itojun switch (mrtproto) {
233 1.1 itojun case 0:
234 1.1 itojun printf("no IPv6 multicast routing compiled into this system\n");
235 1.1 itojun return;
236 1.1 itojun
237 1.1 itojun case IPPROTO_PIM:
238 1.1 itojun break;
239 1.1 itojun
240 1.1 itojun default:
241 1.1 itojun printf("IPv6 multicast routing protocol %u, unknown\n",
242 1.1 itojun mrtproto);
243 1.1 itojun return;
244 1.1 itojun }
245 1.1 itojun
246 1.1 itojun if (mstaddr == 0) {
247 1.1 itojun printf("mrt6_stats: symbol not in namelist\n");
248 1.1 itojun return;
249 1.1 itojun }
250 1.1 itojun
251 1.1 itojun kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
252 1.1 itojun printf("multicast forwarding:\n");
253 1.3 bouyer printf(" %10llu multicast forwarding cache lookup%s\n",
254 1.3 bouyer (unsigned long long)mrtstat.mrt6s_mfc_lookups,
255 1.3 bouyer plural(mrtstat.mrt6s_mfc_lookups));
256 1.3 bouyer printf(" %10llu multicast forwarding cache miss%s\n",
257 1.3 bouyer (unsigned long long)mrtstat.mrt6s_mfc_misses,
258 1.3 bouyer plurales(mrtstat.mrt6s_mfc_misses));
259 1.3 bouyer printf(" %10llu upcall%s to mrouted\n",
260 1.3 bouyer (unsigned long long)mrtstat.mrt6s_upcalls,
261 1.3 bouyer plural(mrtstat.mrt6s_upcalls));
262 1.3 bouyer printf(" %10llu upcall queue overflow%s\n",
263 1.3 bouyer (unsigned long long)mrtstat.mrt6s_upq_ovflw,
264 1.3 bouyer plural(mrtstat.mrt6s_upq_ovflw));
265 1.3 bouyer printf(" %10llu upcall%s dropped due to full socket buffer\n",
266 1.3 bouyer (unsigned long long)mrtstat.mrt6s_upq_sockfull,
267 1.3 bouyer plural(mrtstat.mrt6s_upq_sockfull));
268 1.3 bouyer printf(" %10llu cache cleanup%s\n",
269 1.3 bouyer (unsigned long long)mrtstat.mrt6s_cache_cleanups,
270 1.3 bouyer plural(mrtstat.mrt6s_cache_cleanups));
271 1.3 bouyer printf(" %10llu datagram%s with no route for origin\n",
272 1.3 bouyer (unsigned long long)mrtstat.mrt6s_no_route,
273 1.3 bouyer plural(mrtstat.mrt6s_no_route));
274 1.3 bouyer printf(" %10llu datagram%s arrived with bad tunneling\n",
275 1.3 bouyer (unsigned long long)mrtstat.mrt6s_bad_tunnel,
276 1.3 bouyer plural(mrtstat.mrt6s_bad_tunnel));
277 1.3 bouyer printf(" %10llu datagram%s could not be tunneled\n",
278 1.3 bouyer (unsigned long long)mrtstat.mrt6s_cant_tunnel,
279 1.3 bouyer plural(mrtstat.mrt6s_cant_tunnel));
280 1.3 bouyer printf(" %10llu datagram%s arrived on wrong interface\n",
281 1.3 bouyer (unsigned long long)mrtstat.mrt6s_wrong_if,
282 1.3 bouyer plural(mrtstat.mrt6s_wrong_if));
283 1.3 bouyer printf(" %10llu datagram%s selectively dropped\n",
284 1.3 bouyer (unsigned long long)mrtstat.mrt6s_drop_sel,
285 1.3 bouyer plural(mrtstat.mrt6s_drop_sel));
286 1.3 bouyer printf(" %10llu datagram%s dropped due to queue overflow\n",
287 1.3 bouyer (unsigned long long)mrtstat.mrt6s_q_overflow,
288 1.3 bouyer plural(mrtstat.mrt6s_q_overflow));
289 1.3 bouyer printf(" %10llu datagram%s dropped for being too large\n",
290 1.3 bouyer (unsigned long long)mrtstat.mrt6s_pkt2large,
291 1.3 bouyer plural(mrtstat.mrt6s_pkt2large));
292 1.1 itojun }
293 1.1 itojun #endif /*INET6*/
294