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