]>
git.saurik.com Git - apple/network_cmds.git/blob - netstat.tproj/mroute6.c
2 * Copyright (c) 2008 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (C) 1998 WIDE Project.
30 * All rights reserved.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. Neither the name of the project nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
44 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * Copyright (c) 1989 Stephen Deering
59 * Copyright (c) 1992, 1993
60 * The Regents of the University of California. All rights reserved.
62 * This code is derived from software contributed to Berkeley by
63 * Stephen Deering of Stanford University.
65 * Redistribution and use in source and binary forms, with or without
66 * modification, are permitted provided that the following conditions
68 * 1. Redistributions of source code must retain the above copyright
69 * notice, this list of conditions and the following disclaimer.
70 * 2. Redistributions in binary form must reproduce the above copyright
71 * notice, this list of conditions and the following disclaimer in the
72 * documentation and/or other materials provided with the distribution.
73 * 3. All advertising materials mentioning features or use of this software
74 * must display the following acknowledgement:
75 * This product includes software developed by the University of
76 * California, Berkeley and its contributors.
77 * 4. Neither the name of the University nor the names of its contributors
78 * may be used to endorse or promote products derived from this software
79 * without specific prior written permission.
81 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
82 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
83 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
84 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
85 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
86 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
87 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
88 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
89 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
90 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
93 * @(#)mroute.c 8.2 (Berkeley) 4/28/95
94 * $FreeBSD: src/usr.bin/netstat/mroute6.c,v 1.1.2.5 2001/08/10 09:07:09 ru Exp $
98 #include <sys/param.h>
99 #include <sys/queue.h>
100 #include <sys/socket.h>
101 #include <sys/socketvar.h>
102 #include <sys/sysctl.h>
105 #include <net/if_var.h>
106 #include <net/route.h>
108 #include <netinet/in.h>
115 #include <netinet6/ip6_mroute.h>
120 #define WID_ORG (lflag ? 39 : (nflag ? 29 : 18)) /* width of origin column */
121 #define WID_GRP (lflag ? 18 : (nflag ? 16 : 18)) /* width of group column */
126 struct mf6c
**mf6ctable
= 0, *mfcp
;
127 struct mif6 mif6table
[MAXMIFS
];
130 register struct mif6
*mifp
;
131 register mifi_t mifi
;
133 register int banner_printed
;
134 register int saved_nflag
;
139 len
= sizeof(mif6table
);
140 if (sysctlbyname("net.inet6.ip6.mif6table", mif6table
, &len
, 0, 9) == -1) {
141 printf("No IPv6 multicast routing compiled into this system.\n");
149 for (mifi
= 0, mifp
= mif6table
; mifi
< MAXMIFS
; ++mifi
, ++mifp
) {
150 struct ifnet ifnet
= { 0 } ;
151 char ifname
[IFNAMSIZ
];
153 if (mifp
->m6_ifp
== NULL
)
157 * m6_ifp should be ifindex instead of ifnet pointer
159 * kread((u_long)mifp->m6_ifp, (char *)&ifnet, sizeof(ifnet));
162 if (!banner_printed
) {
163 printf("\nIPv6 Multicast Interface Table\n"
165 "Pkts-In Pkts-Out\n");
170 mifi
, mifp
->m6_rate_limit
);
171 printf(" %5s", (mifp
->m6_flags
& MIFF_REGISTER
) ?
172 "reg0" : if_indextoname(ifnet
.if_index
, ifname
));
174 printf(" %9llu %9llu\n", (unsigned long long)mifp
->m6_pkt_in
,
175 (unsigned long long)mifp
->m6_pkt_out
);
178 printf("\nIPv6 Multicast Interface Table is empty\n");
180 len
= sizeof(MF6CTBLSIZ
* sizeof(struct mf6c
));
181 mf6ctable
= malloc(len
);
184 if (sysctlbyname("net.inet6.ip6.mf6ctable", mf6ctable
, &len
, 0, 0) == -1) {
185 printf("No IPv6 multicast routing compiled into this system.\n");
190 for (i
= 0; i
< MF6CTBLSIZ
; ++i
) {
193 if (!banner_printed
) {
194 printf ("\nIPv6 Multicast Forwarding Cache\n");
195 printf(" %-*.*s %-*.*s %s",
196 WID_ORG
, WID_ORG
, "Origin",
197 WID_GRP
, WID_GRP
, "Group",
198 " Packets Waits In-Mif Out-Mifs\n");
202 printf(" %-*.*s", WID_ORG
, WID_ORG
,
203 routename6(&mfc
.mf6c_origin
));
204 printf(" %-*.*s", WID_GRP
, WID_GRP
,
205 routename6(&mfc
.mf6c_mcastgrp
));
206 printf(" %9llu", (unsigned long long)mfc
.mf6c_pkt_cnt
);
208 for (waitings
= 0, rtep
= mfc
.mf6c_stall
; rtep
; ) {
209 /* The sysctl should return the number of packet waiting
211 * kread((u_long)rtep, (char *)&rte, sizeof(rte));
216 printf(" %3ld", waitings
);
218 if (mfc
.mf6c_parent
== MF6C_INCOMPLETE_PARENT
)
221 printf(" %3d ", mfc
.mf6c_parent
);
222 for (mifi
= 0; mifi
<= maxmif
; mifi
++) {
223 if (IF_ISSET(mifi
, &mfc
.mf6c_ifset
))
228 mfcp
= mfc
.mf6c_next
;
232 printf("\nIPv6 Multicast Routing Table is empty\n");
243 struct mrt6stat mrtstat
;
246 len
= sizeof(mrtstat
);
247 if (sysctlbyname("net.inet6.ip6.mrt6stat", &mrtstat
, &len
, 0, 0) == -1) {
248 printf("No IPv6 multicast routing compiled into this system\n");
251 printf("IPv6 multicast forwarding:\n");
252 printf(" %10llu multicast forwarding cache lookup%s\n",
253 (unsigned long long)mrtstat
.mrt6s_mfc_lookups
,
254 plural(mrtstat
.mrt6s_mfc_lookups
));
255 printf(" %10llu multicast forwarding cache miss%s\n",
256 (unsigned long long)mrtstat
.mrt6s_mfc_misses
,
257 plurales(mrtstat
.mrt6s_mfc_misses
));
258 printf(" %10llu upcall%s to mrouted\n",
259 (unsigned long long)mrtstat
.mrt6s_upcalls
,
260 plural(mrtstat
.mrt6s_upcalls
));
261 printf(" %10llu upcall queue overflow%s\n",
262 (unsigned long long)mrtstat
.mrt6s_upq_ovflw
,
263 plural(mrtstat
.mrt6s_upq_ovflw
));
264 printf(" %10llu upcall%s dropped due to full socket buffer\n",
265 (unsigned long long)mrtstat
.mrt6s_upq_sockfull
,
266 plural(mrtstat
.mrt6s_upq_sockfull
));
267 printf(" %10llu cache cleanup%s\n",
268 (unsigned long long)mrtstat
.mrt6s_cache_cleanups
,
269 plural(mrtstat
.mrt6s_cache_cleanups
));
270 printf(" %10llu datagram%s with no route for origin\n",
271 (unsigned long long)mrtstat
.mrt6s_no_route
,
272 plural(mrtstat
.mrt6s_no_route
));
273 printf(" %10llu datagram%s arrived with bad tunneling\n",
274 (unsigned long long)mrtstat
.mrt6s_bad_tunnel
,
275 plural(mrtstat
.mrt6s_bad_tunnel
));
276 printf(" %10llu datagram%s could not be tunneled\n",
277 (unsigned long long)mrtstat
.mrt6s_cant_tunnel
,
278 plural(mrtstat
.mrt6s_cant_tunnel
));
279 printf(" %10llu datagram%s arrived on wrong interface\n",
280 (unsigned long long)mrtstat
.mrt6s_wrong_if
,
281 plural(mrtstat
.mrt6s_wrong_if
));
282 printf(" %10llu datagram%s selectively dropped\n",
283 (unsigned long long)mrtstat
.mrt6s_drop_sel
,
284 plural(mrtstat
.mrt6s_drop_sel
));
285 printf(" %10llu datagram%s dropped due to queue overflow\n",
286 (unsigned long long)mrtstat
.mrt6s_q_overflow
,
287 plural(mrtstat
.mrt6s_q_overflow
));
288 printf(" %10llu datagram%s dropped for being too large\n",
289 (unsigned long long)mrtstat
.mrt6s_pkt2large
,
290 plural(mrtstat
.mrt6s_pkt2large
));