]>
git.saurik.com Git - apple/network_cmds.git/blob - netstat.tproj/mroute6.c
c37f176000e102ae1a228ef101da9f05dd5eb6af
2 * Copyright (C) 1998 WIDE Project.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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
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
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. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * @(#)mroute.c 8.2 (Berkeley) 4/28/95
67 * $FreeBSD: src/usr.bin/netstat/mroute6.c,v 1.1.2.5 2001/08/10 09:07:09 ru Exp $
71 #include <sys/param.h>
72 #include <sys/queue.h>
73 #include <sys/socket.h>
74 #include <sys/socketvar.h>
75 #include <sys/sysctl.h>
78 #include <net/if_var.h>
79 #include <net/route.h>
81 #include <netinet/in.h>
88 #include <netinet6/ip6_mroute.h>
93 #define WID_ORG (lflag ? 39 : (nflag ? 29 : 18)) /* width of origin column */
94 #define WID_GRP (lflag ? 18 : (nflag ? 16 : 18)) /* width of group column */
99 struct mf6c
**mf6ctable
= 0, *mfcp
;
100 struct mif6 mif6table
[MAXMIFS
];
103 register struct mif6
*mifp
;
104 register mifi_t mifi
;
106 register int banner_printed
;
107 register int saved_nflag
;
112 len
= sizeof(mif6table
);
113 if (sysctlbyname("net.inet6.ip6.mif6table", mif6table
, &len
, 0, 9) == -1) {
114 printf("No IPv6 multicast routing compiled into this system.\n");
122 for (mifi
= 0, mifp
= mif6table
; mifi
< MAXMIFS
; ++mifi
, ++mifp
) {
124 char ifname
[IFNAMSIZ
];
126 if (mifp
->m6_ifp
== NULL
)
130 * m6_ifp should be ifindex instead of ifnet pointer
132 * kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet));
135 if (!banner_printed
) {
136 printf("\nIPv6 Multicast Interface Table\n"
138 "Pkts-In Pkts-Out\n");
143 mifi
, mifp
->m6_rate_limit
);
144 printf(" %5s", (mifp
->m6_flags
& MIFF_REGISTER
) ?
145 "reg0" : if_indextoname(ifnet
.if_index
, ifname
));
147 printf(" %9llu %9llu\n", (unsigned long long)mifp
->m6_pkt_in
,
148 (unsigned long long)mifp
->m6_pkt_out
);
151 printf("\nIPv6 Multicast Interface Table is empty\n");
153 len
= sizeof(MF6CTBLSIZ
* sizeof(struct mf6c
));
154 mf6ctable
= malloc(len
);
157 if (sysctlbyname("net.inet6.ip6.mf6ctable", mf6ctable
, &len
, 0, 0) == -1) {
158 printf("No IPv6 multicast routing compiled into this system.\n");
163 for (i
= 0; i
< MF6CTBLSIZ
; ++i
) {
166 if (!banner_printed
) {
167 printf ("\nIPv6 Multicast Forwarding Cache\n");
168 printf(" %-*.*s %-*.*s %s",
169 WID_ORG
, WID_ORG
, "Origin",
170 WID_GRP
, WID_GRP
, "Group",
171 " Packets Waits In-Mif Out-Mifs\n");
175 printf(" %-*.*s", WID_ORG
, WID_ORG
,
176 routename6(&mfc
.mf6c_origin
));
177 printf(" %-*.*s", WID_GRP
, WID_GRP
,
178 routename6(&mfc
.mf6c_mcastgrp
));
179 printf(" %9llu", (unsigned long long)mfc
.mf6c_pkt_cnt
);
181 for (waitings
= 0, rtep
= mfc
.mf6c_stall
; rtep
; ) {
182 /* The sysctl should return the number of packet waiting
184 * kread((u_long)rtep, (char *)&rte, sizeof(rte));
189 printf(" %3ld", waitings
);
191 if (mfc
.mf6c_parent
== MF6C_INCOMPLETE_PARENT
)
194 printf(" %3d ", mfc
.mf6c_parent
);
195 for (mifi
= 0; mifi
<= maxmif
; mifi
++) {
196 if (IF_ISSET(mifi
, &mfc
.mf6c_ifset
))
201 mfcp
= mfc
.mf6c_next
;
205 printf("\nIPv6 Multicast Routing Table is empty\n");
216 struct mrt6stat mrtstat
;
219 len
= sizeof(mrtstat
);
220 if (sysctlbyname("net.inet6.ip6.mrt6stat", &mrtstat
, &len
, 0, 0) == -1) {
221 printf("No IPv6 multicast routing compiled into this system\n");
224 printf("IPv6 multicast forwarding:\n");
225 printf(" %10llu multicast forwarding cache lookup%s\n",
226 (unsigned long long)mrtstat
.mrt6s_mfc_lookups
,
227 plural(mrtstat
.mrt6s_mfc_lookups
));
228 printf(" %10llu multicast forwarding cache miss%s\n",
229 (unsigned long long)mrtstat
.mrt6s_mfc_misses
,
230 plurales(mrtstat
.mrt6s_mfc_misses
));
231 printf(" %10llu upcall%s to mrouted\n",
232 (unsigned long long)mrtstat
.mrt6s_upcalls
,
233 plural(mrtstat
.mrt6s_upcalls
));
234 printf(" %10llu upcall llueue overflow%s\n",
235 (unsigned long long)mrtstat
.mrt6s_upq_ovflw
,
236 plural(mrtstat
.mrt6s_upq_ovflw
));
237 printf(" %10llu upcall%s dropped due to full socket buffer\n",
238 (unsigned long long)mrtstat
.mrt6s_upq_sockfull
,
239 plural(mrtstat
.mrt6s_upq_sockfull
));
240 printf(" %10llu cache cleanup%s\n",
241 (unsigned long long)mrtstat
.mrt6s_cache_cleanups
,
242 plural(mrtstat
.mrt6s_cache_cleanups
));
243 printf(" %10llu datagram%s with no route for origin\n",
244 (unsigned long long)mrtstat
.mrt6s_no_route
,
245 plural(mrtstat
.mrt6s_no_route
));
246 printf(" %10llu datagram%s arrived with bad tunneling\n",
247 (unsigned long long)mrtstat
.mrt6s_bad_tunnel
,
248 plural(mrtstat
.mrt6s_bad_tunnel
));
249 printf(" %10llu datagram%s could not be tunneled\n",
250 (unsigned long long)mrtstat
.mrt6s_cant_tunnel
,
251 plural(mrtstat
.mrt6s_cant_tunnel
));
252 printf(" %10llu datagram%s arrived on wrong interface\n",
253 (unsigned long long)mrtstat
.mrt6s_wrong_if
,
254 plural(mrtstat
.mrt6s_wrong_if
));
255 printf(" %10llu datagram%s selectively dropped\n",
256 (unsigned long long)mrtstat
.mrt6s_drop_sel
,
257 plural(mrtstat
.mrt6s_drop_sel
));
258 printf(" %10llu datagram%s dropped due to llueue overflow\n",
259 (unsigned long long)mrtstat
.mrt6s_q_overflow
,
260 plural(mrtstat
.mrt6s_q_overflow
));
261 printf(" %10llu datagram%s dropped for being too large\n",
262 (unsigned long long)mrtstat
.mrt6s_pkt2large
,
263 plural(mrtstat
.mrt6s_pkt2large
));