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