sys/subr_rman: fix some issues
[dragonfly.git] / usr.bin / netstat / mroute6.c
blobf75d94423c05b2d97b1873f4cee8ebebfd5771ff
1 /*
2 * Copyright (C) 1998 WIDE Project.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
31 * Copyright (c) 1989 Stephen Deering
32 * Copyright (c) 1992, 1993
33 * The Regents of the University of California. All rights reserved.
35 * This code is derived from software contributed to Berkeley by
36 * Stephen Deering of Stanford University.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * SUCH DAMAGE.
62 * @(#)mroute.c 8.2 (Berkeley) 4/28/95
63 * $FreeBSD: src/usr.bin/netstat/mroute6.c,v 1.1.2.9 2002/07/09 04:05:20 suz Exp $
64 * $DragonFly: src/usr.bin/netstat/mroute6.c,v 1.3 2005/08/04 17:31:23 drhodus Exp $
67 #define _KERNEL_STRUCTURES
68 #ifdef INET6
69 #include <sys/param.h>
70 #include <sys/queue.h>
71 #include <sys/socket.h>
72 #include <sys/socketvar.h>
73 #include <sys/protosw.h>
75 #include <net/if.h>
76 #include <net/if_var.h>
77 #include <net/route.h>
79 #include <netinet/in.h>
81 #include <stdio.h>
83 #include <netinet6/ip6_mroute.h>
85 #include "netstat.h"
87 #define WID_ORG (Wflag ? 39 : (numeric_addr ? 29 : 18)) /* width of origin column */
88 #define WID_GRP (Wflag ? 18 : (numeric_addr ? 16 : 18)) /* width of group column */
90 void
91 mroute6pr(u_long mfcaddr, u_long mifaddr)
93 struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp;
94 struct mif6 mif6table[MAXMIFS];
95 struct mf6c mfc;
96 struct rtdetq rte, *rtep;
97 struct mif6 *mifp;
98 mifi_t mifi;
99 int i;
100 int banner_printed;
101 int saved_numeric_addr;
102 mifi_t maxmif = 0;
103 long int waitings;
105 if (mfcaddr == 0 || mifaddr == 0) {
106 printf("No IPv6 multicast routing compiled into this"
107 " system.\n");
108 return;
111 saved_numeric_addr = numeric_addr;
112 numeric_addr = 1;
114 kread(mifaddr, (char *)&mif6table, sizeof(mif6table));
115 banner_printed = 0;
116 for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) {
117 struct ifnet ifnet;
118 char ifname[IFNAMSIZ];
120 if (mifp->m6_ifp == NULL)
121 continue;
123 kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet));
124 maxmif = mifi;
125 if (!banner_printed) {
126 printf("\nIPv6 Multicast Interface Table\n"
127 " Mif Rate PhyIF "
128 "Pkts-In Pkts-Out\n");
129 banner_printed = 1;
132 printf(" %2u %4d",
133 mifi, mifp->m6_rate_limit);
134 printf(" %5s", (mifp->m6_flags & MIFF_REGISTER) ?
135 "reg0" : if_indextoname(ifnet.if_index, ifname));
137 printf(" %9llu %9llu\n", (unsigned long long)mifp->m6_pkt_in,
138 (unsigned long long)mifp->m6_pkt_out);
140 if (!banner_printed)
141 printf("\nIPv6 Multicast Interface Table is empty\n");
143 kread(mfcaddr, (char *)&mf6ctable, sizeof(mf6ctable));
144 banner_printed = 0;
145 for (i = 0; i < MF6CTBLSIZ; ++i) {
146 mfcp = mf6ctable[i];
147 while(mfcp) {
148 kread((u_long)mfcp, (char *)&mfc, sizeof(mfc));
149 if (!banner_printed) {
150 printf ("\nIPv6 Multicast Forwarding Cache\n");
151 printf(" %-*.*s %-*.*s %s",
152 WID_ORG, WID_ORG, "Origin",
153 WID_GRP, WID_GRP, "Group",
154 " Packets Waits In-Mif Out-Mifs\n");
155 banner_printed = 1;
158 printf(" %-*.*s", WID_ORG, WID_ORG,
159 routename6(&mfc.mf6c_origin));
160 printf(" %-*.*s", WID_GRP, WID_GRP,
161 routename6(&mfc.mf6c_mcastgrp));
162 printf(" %9llu", (unsigned long long)mfc.mf6c_pkt_cnt);
164 for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) {
165 waitings++;
166 kread((u_long)rtep, (char *)&rte, sizeof(rte));
167 rtep = rte.next;
169 printf(" %3ld", waitings);
171 if (mfc.mf6c_parent == MF6C_INCOMPLETE_PARENT)
172 printf(" --- ");
173 else
174 printf(" %3d ", mfc.mf6c_parent);
175 for (mifi = 0; mifi <= maxmif; mifi++) {
176 if (IF_ISSET(mifi, &mfc.mf6c_ifset))
177 printf(" %u", mifi);
179 printf("\n");
181 mfcp = mfc.mf6c_next;
184 if (!banner_printed)
185 printf("\nIPv6 Multicast Routing Table is empty\n");
187 printf("\n");
188 numeric_addr = saved_numeric_addr;
191 void
192 mrt6_stats(u_long mstaddr)
194 struct mrt6stat mrtstat;
196 if (mstaddr == 0) {
197 printf("No IPv6 multicast routing compiled into this"
198 " system.\n");
199 return;
202 kread(mstaddr, (char *)&mrtstat, sizeof(mrtstat));
203 printf("IPv6 multicast forwarding:\n");
205 #define p(f, m) if (mrtstat.f || sflag <= 1) \
206 printf(m, (unsigned long long)mrtstat.f, plural(mrtstat.f))
207 #define p2(f, m) if (mrtstat.f || sflag <= 1) \
208 printf(m, (unsigned long long)mrtstat.f, plurales(mrtstat.f))
210 p(mrt6s_mfc_lookups, "\t%llu multicast forwarding cache lookup%s\n");
211 p2(mrt6s_mfc_misses, "\t%llu multicast forwarding cache miss%s\n");
212 p(mrt6s_upcalls, "\t%llu upcall%s to mrouted\n");
213 p(mrt6s_upq_ovflw, "\t%llu upcall queue overflow%s\n");
214 p(mrt6s_upq_sockfull,
215 "\t%llu upcall%s dropped due to full socket buffer\n");
216 p(mrt6s_cache_cleanups, "\t%llu cache cleanup%s\n");
217 p(mrt6s_no_route, "\t%llu datagram%s with no route for origin\n");
218 p(mrt6s_bad_tunnel, "\t%llu datagram%s arrived with bad tunneling\n");
219 p(mrt6s_cant_tunnel, "\t%llu datagram%s could not be tunneled\n");
220 p(mrt6s_wrong_if, "\t%llu datagram%s arrived on wrong interface\n");
221 p(mrt6s_drop_sel, "\t%llu datagram%s selectively dropped\n");
222 p(mrt6s_q_overflow,
223 "\t%llu datagram%s dropped due to queue overflow\n");
224 p(mrt6s_pkt2large, "\t%llu datagram%s dropped for being too large\n");
226 #undef p2
227 #undef p
229 #endif /*INET6*/