1 |
|
|
/* $OpenBSD: mroute6.c,v 1.20 2015/02/13 13:28:17 dcoppa Exp $ */ |
2 |
|
|
|
3 |
|
|
/* |
4 |
|
|
* Copyright (C) 1998 WIDE Project. |
5 |
|
|
* All rights reserved. |
6 |
|
|
* |
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. |
18 |
|
|
* |
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. Neither the name of the University nor the names of its contributors |
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/types.h> |
68 |
|
|
#include <sys/socket.h> |
69 |
|
|
#include <sys/sysctl.h> |
70 |
|
|
|
71 |
|
|
#include <net/if.h> |
72 |
|
|
#include <netinet/in.h> |
73 |
|
|
#include <netinet6/ip6_mroute.h> |
74 |
|
|
|
75 |
|
|
#include <err.h> |
76 |
|
|
#include <errno.h> |
77 |
|
|
#include <stdio.h> |
78 |
|
|
#include <stdlib.h> |
79 |
|
|
#include <util.h> |
80 |
|
|
#include "netstat.h" |
81 |
|
|
|
82 |
|
|
#define WID_ORG (lflag ? 39 : (nflag ? 29 : 18)) /* width of origin column */ |
83 |
|
|
#define WID_GRP (lflag ? 18 : (nflag ? 16 : 18)) /* width of group column */ |
84 |
|
|
|
85 |
|
|
void |
86 |
|
|
mroute6pr(void) |
87 |
|
|
{ |
88 |
|
|
char *buf = NULL; |
89 |
|
|
char fmtbuf[FMT_SCALED_STRSIZE]; |
90 |
|
|
struct mf6cinfo *mfc; |
91 |
|
|
struct mif6info *mif; |
92 |
|
|
size_t needed, mifi, nummifs, mfci, nummfcs; |
93 |
|
|
int banner_printed, saved_nflag; |
94 |
|
|
mifi_t maxmif = 0; |
95 |
|
|
u_int mrtproto; |
96 |
|
|
int mib[] = { CTL_NET, PF_INET6, IPPROTO_IPV6, IPV6CTL_MRTPROTO }; |
97 |
|
|
size_t len = sizeof(int); |
98 |
|
|
|
99 |
|
|
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), |
100 |
|
|
&mrtproto, &len, NULL, 0) == -1) { |
101 |
|
|
if (errno != ENOPROTOOPT) |
102 |
|
|
warn("mroute"); |
103 |
|
|
return; |
104 |
|
|
} |
105 |
|
|
switch (mrtproto) { |
106 |
|
|
case 0: |
107 |
|
|
printf("no IPv6 multicast routing compiled into this system\n"); |
108 |
|
|
return; |
109 |
|
|
case IPPROTO_PIM: |
110 |
|
|
break; |
111 |
|
|
default: |
112 |
|
|
printf("IPv6 multicast routing protocol %u, unknown\n", |
113 |
|
|
mrtproto); |
114 |
|
|
return; |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
saved_nflag = nflag; |
118 |
|
|
nflag = 1; |
119 |
|
|
|
120 |
|
|
mib[3] = IPV6CTL_MRTMIF; |
121 |
|
|
needed = get_sysctl(mib, sizeof(mib) / sizeof(mib[0]), &buf); |
122 |
|
|
nummifs = needed / sizeof(*mif); |
123 |
|
|
mif = (struct mif6info *)buf; |
124 |
|
|
if (nummifs) |
125 |
|
|
maxmif = mif[nummifs - 1].m6_mifi; |
126 |
|
|
|
127 |
|
|
banner_printed = 0; |
128 |
|
|
for (mifi = 0; mifi < nummifs; ++mifi, ++mif) { |
129 |
|
|
char ifname[IFNAMSIZ]; |
130 |
|
|
|
131 |
|
|
if (mif->m6_ifindex == 0) |
132 |
|
|
continue; |
133 |
|
|
|
134 |
|
|
if (!banner_printed) { |
135 |
|
|
printf("\nIPv6 Multicast Interface Table\n" |
136 |
|
|
" Mif Rate PhyIF " |
137 |
|
|
"Pkts-In Pkts-Out\n"); |
138 |
|
|
banner_printed = 1; |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
printf(" %2u %4d", |
142 |
|
|
mif->m6_mifi, mif->m6_rate_limit); |
143 |
|
|
printf(" %5s", (mif->m6_flags & MIFF_REGISTER) ? |
144 |
|
|
"reg0" : if_indextoname(mif->m6_ifindex, ifname)); |
145 |
|
|
|
146 |
|
|
printf(" %9llu %9llu\n", mif->m6_pkt_in, mif->m6_pkt_out); |
147 |
|
|
} |
148 |
|
|
if (!banner_printed) |
149 |
|
|
printf("IPv6 Multicast Interface Table is empty\n"); |
150 |
|
|
|
151 |
|
|
mib[3] = IPV6CTL_MRTMFC; |
152 |
|
|
needed = get_sysctl(mib, sizeof(mib) / sizeof(mib[0]), &buf); |
153 |
|
|
nummfcs = needed / sizeof(*mfc); |
154 |
|
|
mfc = (struct mf6cinfo *)buf; |
155 |
|
|
|
156 |
|
|
banner_printed = 0; |
157 |
|
|
for (mfci = 0; mfci < nummfcs; ++mfci, ++mfc) { |
158 |
|
|
if (!banner_printed) { |
159 |
|
|
printf("\nIPv6 Multicast Forwarding Cache\n"); |
160 |
|
|
printf(" %-*.*s %-*.*s %s", |
161 |
|
|
WID_ORG, WID_ORG, "Origin", |
162 |
|
|
WID_GRP, WID_GRP, "Group", |
163 |
|
|
" Packets Waits In-Mif Out-Mifs\n"); |
164 |
|
|
banner_printed = 1; |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
printf(" %-*.*s", WID_ORG, WID_ORG, |
168 |
|
|
routename6(&mfc->mf6c_origin)); |
169 |
|
|
printf(" %-*.*s", WID_GRP, WID_GRP, |
170 |
|
|
routename6(&mfc->mf6c_mcastgrp)); |
171 |
|
|
fmt_scaled(mfc->mf6c_pkt_cnt, fmtbuf); |
172 |
|
|
printf(" %9s", fmtbuf); |
173 |
|
|
|
174 |
|
|
printf(" %3llu", mfc->mf6c_stall_cnt); |
175 |
|
|
|
176 |
|
|
if (mfc->mf6c_parent == MF6C_INCOMPLETE_PARENT) |
177 |
|
|
printf(" --- "); |
178 |
|
|
else |
179 |
|
|
printf(" %3d ", mfc->mf6c_parent); |
180 |
|
|
for (mifi = 0; mifi <= MAXMIFS; mifi++) { |
181 |
|
|
if (IF_ISSET(mifi, &mfc->mf6c_ifset)) |
182 |
|
|
printf(" %zu", mifi); |
183 |
|
|
} |
184 |
|
|
printf("\n"); |
185 |
|
|
} |
186 |
|
|
if (!banner_printed) |
187 |
|
|
printf("IPv6 Multicast Routing Table is empty"); |
188 |
|
|
|
189 |
|
|
printf("\n"); |
190 |
|
|
nflag = saved_nflag; |
191 |
|
|
|
192 |
|
|
free(buf); |
193 |
|
|
} |
194 |
|
|
|
195 |
|
|
void |
196 |
|
|
mrt6_stats(void) |
197 |
|
|
{ |
198 |
|
|
struct mrt6stat mrt6stat; |
199 |
|
|
u_int mrt6proto; |
200 |
|
|
int mib[] = { CTL_NET, PF_INET6, IPPROTO_IPV6, IPV6CTL_MRTPROTO }; |
201 |
|
|
int mib2[] = { CTL_NET, PF_INET6, IPPROTO_IPV6, IPV6CTL_MRTSTATS }; |
202 |
|
|
size_t len = sizeof(int); |
203 |
|
|
|
204 |
|
|
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), |
205 |
|
|
&mrt6proto, &len, NULL, 0) == -1) { |
206 |
|
|
if (errno != ENOPROTOOPT) |
207 |
|
|
warn("mroute"); |
208 |
|
|
return; |
209 |
|
|
} |
210 |
|
|
switch (mrt6proto) { |
211 |
|
|
case 0: |
212 |
|
|
printf("no IPv6 multicast routing compiled into this system\n"); |
213 |
|
|
return; |
214 |
|
|
case IPPROTO_PIM: |
215 |
|
|
break; |
216 |
|
|
default: |
217 |
|
|
printf("IPv6 multicast routing protocol %u, unknown\n", |
218 |
|
|
mrt6proto); |
219 |
|
|
return; |
220 |
|
|
} |
221 |
|
|
|
222 |
|
|
len = sizeof(mrt6stat); |
223 |
|
|
if (sysctl(mib2, sizeof(mib2) / sizeof(mib2[0]), |
224 |
|
|
&mrt6stat, &len, NULL, 0) == -1) { |
225 |
|
|
if (errno != ENOPROTOOPT) |
226 |
|
|
warn("mroute"); |
227 |
|
|
return; |
228 |
|
|
} |
229 |
|
|
|
230 |
|
|
printf("multicast forwarding:\n"); |
231 |
|
|
printf("\t%llu multicast forwarding cache lookup%s\n", |
232 |
|
|
mrt6stat.mrt6s_mfc_lookups, plural(mrt6stat.mrt6s_mfc_lookups)); |
233 |
|
|
printf("\t%llu multicast forwarding cache miss%s\n", |
234 |
|
|
mrt6stat.mrt6s_mfc_misses, plurales(mrt6stat.mrt6s_mfc_misses)); |
235 |
|
|
printf("\t%llu upcall%s to mrouted\n", |
236 |
|
|
mrt6stat.mrt6s_upcalls, plural(mrt6stat.mrt6s_upcalls)); |
237 |
|
|
printf("\t%llu upcall queue overflow%s\n", |
238 |
|
|
mrt6stat.mrt6s_upq_ovflw, plural(mrt6stat.mrt6s_upq_ovflw)); |
239 |
|
|
printf("\t%llu upcall%s dropped due to full socket buffer\n", |
240 |
|
|
mrt6stat.mrt6s_upq_sockfull, plural(mrt6stat.mrt6s_upq_sockfull)); |
241 |
|
|
printf("\t%llu cache cleanup%s\n", |
242 |
|
|
mrt6stat.mrt6s_cache_cleanups, plural(mrt6stat.mrt6s_cache_cleanups)); |
243 |
|
|
printf("\t%llu datagram%s with no route for origin\n", |
244 |
|
|
mrt6stat.mrt6s_no_route, plural(mrt6stat.mrt6s_no_route)); |
245 |
|
|
printf("\t%llu datagram%s arrived with bad tunneling\n", |
246 |
|
|
mrt6stat.mrt6s_bad_tunnel, plural(mrt6stat.mrt6s_bad_tunnel)); |
247 |
|
|
printf("\t%llu datagram%s could not be tunneled\n", |
248 |
|
|
mrt6stat.mrt6s_cant_tunnel, plural(mrt6stat.mrt6s_cant_tunnel)); |
249 |
|
|
printf("\t%llu datagram%s arrived on wrong interface\n", |
250 |
|
|
mrt6stat.mrt6s_wrong_if, plural(mrt6stat.mrt6s_wrong_if)); |
251 |
|
|
printf("\t%llu datagram%s selectively dropped\n", |
252 |
|
|
mrt6stat.mrt6s_drop_sel, plural(mrt6stat.mrt6s_drop_sel)); |
253 |
|
|
printf("\t%llu datagram%s dropped due to queue overflow\n", |
254 |
|
|
mrt6stat.mrt6s_q_overflow, plural(mrt6stat.mrt6s_q_overflow)); |
255 |
|
|
printf("\t%llu datagram%s dropped for being too large\n", |
256 |
|
|
mrt6stat.mrt6s_pkt2large, plural(mrt6stat.mrt6s_pkt2large)); |
257 |
|
|
} |