165475bc8SDavid E. O'Brien /*-
2df57947fSPedro F. Giffuni * SPDX-License-Identifier: BSD-4-Clause AND BSD-3-Clause
3df57947fSPedro F. Giffuni *
40fea3d51SYoshinobu Inoue * Copyright (C) 1998 WIDE Project.
50fea3d51SYoshinobu Inoue * All rights reserved.
60fea3d51SYoshinobu Inoue *
70fea3d51SYoshinobu Inoue * Redistribution and use in source and binary forms, with or without
80fea3d51SYoshinobu Inoue * modification, are permitted provided that the following conditions
90fea3d51SYoshinobu Inoue * are met:
100fea3d51SYoshinobu Inoue * 1. Redistributions of source code must retain the above copyright
110fea3d51SYoshinobu Inoue * notice, this list of conditions and the following disclaimer.
120fea3d51SYoshinobu Inoue * 2. Redistributions in binary form must reproduce the above copyright
130fea3d51SYoshinobu Inoue * notice, this list of conditions and the following disclaimer in the
140fea3d51SYoshinobu Inoue * documentation and/or other materials provided with the distribution.
150fea3d51SYoshinobu Inoue * 3. Neither the name of the project nor the names of its contributors
160fea3d51SYoshinobu Inoue * may be used to endorse or promote products derived from this software
170fea3d51SYoshinobu Inoue * without specific prior written permission.
180fea3d51SYoshinobu Inoue *
190fea3d51SYoshinobu Inoue * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
200fea3d51SYoshinobu Inoue * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
210fea3d51SYoshinobu Inoue * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
220fea3d51SYoshinobu Inoue * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
230fea3d51SYoshinobu Inoue * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
240fea3d51SYoshinobu Inoue * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
250fea3d51SYoshinobu Inoue * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
260fea3d51SYoshinobu Inoue * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
270fea3d51SYoshinobu Inoue * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
280fea3d51SYoshinobu Inoue * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
290fea3d51SYoshinobu Inoue * SUCH DAMAGE.
300fea3d51SYoshinobu Inoue */
3165475bc8SDavid E. O'Brien /*-
320fea3d51SYoshinobu Inoue * Copyright (c) 1989 Stephen Deering
330fea3d51SYoshinobu Inoue * Copyright (c) 1992, 1993
340fea3d51SYoshinobu Inoue * The Regents of the University of California. All rights reserved.
350fea3d51SYoshinobu Inoue *
360fea3d51SYoshinobu Inoue * This code is derived from software contributed to Berkeley by
370fea3d51SYoshinobu Inoue * Stephen Deering of Stanford University.
380fea3d51SYoshinobu Inoue *
390fea3d51SYoshinobu Inoue * Redistribution and use in source and binary forms, with or without
400fea3d51SYoshinobu Inoue * modification, are permitted provided that the following conditions
410fea3d51SYoshinobu Inoue * are met:
420fea3d51SYoshinobu Inoue * 1. Redistributions of source code must retain the above copyright
430fea3d51SYoshinobu Inoue * notice, this list of conditions and the following disclaimer.
440fea3d51SYoshinobu Inoue * 2. Redistributions in binary form must reproduce the above copyright
450fea3d51SYoshinobu Inoue * notice, this list of conditions and the following disclaimer in the
460fea3d51SYoshinobu Inoue * documentation and/or other materials provided with the distribution.
470fea3d51SYoshinobu Inoue * 3. All advertising materials mentioning features or use of this software
480fea3d51SYoshinobu Inoue * must display the following acknowledgement:
490fea3d51SYoshinobu Inoue * This product includes software developed by the University of
500fea3d51SYoshinobu Inoue * California, Berkeley and its contributors.
510fea3d51SYoshinobu Inoue * 4. Neither the name of the University nor the names of its contributors
520fea3d51SYoshinobu Inoue * may be used to endorse or promote products derived from this software
530fea3d51SYoshinobu Inoue * without specific prior written permission.
540fea3d51SYoshinobu Inoue *
550fea3d51SYoshinobu Inoue * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
560fea3d51SYoshinobu Inoue * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
570fea3d51SYoshinobu Inoue * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
580fea3d51SYoshinobu Inoue * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
590fea3d51SYoshinobu Inoue * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
600fea3d51SYoshinobu Inoue * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
610fea3d51SYoshinobu Inoue * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
620fea3d51SYoshinobu Inoue * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
630fea3d51SYoshinobu Inoue * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
640fea3d51SYoshinobu Inoue * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
650fea3d51SYoshinobu Inoue * SUCH DAMAGE.
660fea3d51SYoshinobu Inoue */
670fea3d51SYoshinobu Inoue
686cc6f122SPhilippe Charnier #include <sys/cdefs.h>
69d84a1df4SHajimu UMEMOTO #ifdef INET6
700fea3d51SYoshinobu Inoue #include <sys/param.h>
710fea3d51SYoshinobu Inoue #include <sys/queue.h>
720fea3d51SYoshinobu Inoue #include <sys/socket.h>
73c15ddad9SBruce M Simpson #include <sys/sysctl.h>
74c15ddad9SBruce M Simpson #include <sys/mbuf.h>
75c15ddad9SBruce M Simpson #include <sys/time.h>
760fea3d51SYoshinobu Inoue
770fea3d51SYoshinobu Inoue #include <net/if.h>
7833841545SHajimu UMEMOTO #include <net/route.h>
790fea3d51SYoshinobu Inoue
800fea3d51SYoshinobu Inoue #include <netinet/in.h>
810fea3d51SYoshinobu Inoue
827b95a1ebSYaroslav Tykhiy #include <stdint.h>
830fea3d51SYoshinobu Inoue #include <stdio.h>
84c15ddad9SBruce M Simpson #include <stdlib.h>
85ade9ccfeSMarcel Moolenaar #include <stdbool.h>
86ade9ccfeSMarcel Moolenaar #include <libxo/xo.h>
870fea3d51SYoshinobu Inoue
880fea3d51SYoshinobu Inoue #define KERNEL 1
89*bf3338e7SGleb Smirnoff struct sockopt;
900fea3d51SYoshinobu Inoue #include <netinet6/ip6_mroute.h>
910fea3d51SYoshinobu Inoue #undef KERNEL
920fea3d51SYoshinobu Inoue
930fea3d51SYoshinobu Inoue #include "netstat.h"
940fea3d51SYoshinobu Inoue
9570057abfSRuslan Ermilov #define WID_ORG (Wflag ? 39 : (numeric_addr ? 29 : 18)) /* width of origin column */
9670057abfSRuslan Ermilov #define WID_GRP (Wflag ? 18 : (numeric_addr ? 16 : 18)) /* width of group column */
970fea3d51SYoshinobu Inoue
980fea3d51SYoshinobu Inoue void
mroute6pr(void)994640fd28SJohn Baldwin mroute6pr(void)
1000fea3d51SYoshinobu Inoue {
1010fea3d51SYoshinobu Inoue struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp;
102c151f24dSGleb Smirnoff struct mif6_sctl mif6table[MAXMIFS];
1030fea3d51SYoshinobu Inoue struct mf6c mfc;
1040fea3d51SYoshinobu Inoue struct rtdetq rte, *rtep;
105c151f24dSGleb Smirnoff struct mif6_sctl *mifp;
106a01e3379SDavid Malone mifi_t mifi;
107a01e3379SDavid Malone int i;
108a01e3379SDavid Malone int banner_printed;
109a01e3379SDavid Malone int saved_numeric_addr;
1100fea3d51SYoshinobu Inoue mifi_t maxmif = 0;
1110fea3d51SYoshinobu Inoue long int waitings;
112c15ddad9SBruce M Simpson size_t len;
1130fea3d51SYoshinobu Inoue
114c151f24dSGleb Smirnoff if (live == 0)
115fc47e028SAlexander V. Chernikov return;
116fc47e028SAlexander V. Chernikov
117c15ddad9SBruce M Simpson len = sizeof(mif6table);
118c151f24dSGleb Smirnoff if (sysctlbyname("net.inet6.ip6.mif6table", mif6table, &len, NULL, 0) <
119c151f24dSGleb Smirnoff 0) {
120ade9ccfeSMarcel Moolenaar xo_warn("sysctl: net.inet6.ip6.mif6table");
1210fea3d51SYoshinobu Inoue return;
1220fea3d51SYoshinobu Inoue }
1230fea3d51SYoshinobu Inoue
12465ea0024SAssar Westerlund saved_numeric_addr = numeric_addr;
12565ea0024SAssar Westerlund numeric_addr = 1;
1260fea3d51SYoshinobu Inoue banner_printed = 0;
127c15ddad9SBruce M Simpson
1280fea3d51SYoshinobu Inoue for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) {
1290fea3d51SYoshinobu Inoue char ifname[IFNAMSIZ];
1300fea3d51SYoshinobu Inoue
131c151f24dSGleb Smirnoff if (mifp->m6_ifp == 0)
1320fea3d51SYoshinobu Inoue continue;
1330fea3d51SYoshinobu Inoue
1340fea3d51SYoshinobu Inoue maxmif = mifi;
1350fea3d51SYoshinobu Inoue if (!banner_printed) {
136ade9ccfeSMarcel Moolenaar xo_open_list("multicast-interface");
137ade9ccfeSMarcel Moolenaar xo_emit("\n{T:IPv6 Multicast Interface Table}\n"
138ade9ccfeSMarcel Moolenaar "{T: Mif Rate PhyIF Pkts-In Pkts-Out}\n");
1390fea3d51SYoshinobu Inoue banner_printed = 1;
1400fea3d51SYoshinobu Inoue }
1410fea3d51SYoshinobu Inoue
142ade9ccfeSMarcel Moolenaar xo_open_instance("multicast-interface");
143ade9ccfeSMarcel Moolenaar xo_emit(" {:mif/%2u} {:rate-limit/%4d}",
1440fea3d51SYoshinobu Inoue mifi, mifp->m6_rate_limit);
145ade9ccfeSMarcel Moolenaar xo_emit(" {:ifname/%5s}", (mifp->m6_flags & MIFF_REGISTER) ?
146c151f24dSGleb Smirnoff "reg0" : if_indextoname(mifp->m6_ifp, ifname));
1470fea3d51SYoshinobu Inoue
148ade9ccfeSMarcel Moolenaar xo_emit(" {:received-packets/%9ju} {:sent-packets/%9ju}\n",
149ade9ccfeSMarcel Moolenaar (uintmax_t)mifp->m6_pkt_in,
1507b95a1ebSYaroslav Tykhiy (uintmax_t)mifp->m6_pkt_out);
151ade9ccfeSMarcel Moolenaar xo_close_instance("multicast-interface");
1520fea3d51SYoshinobu Inoue }
153ade9ccfeSMarcel Moolenaar if (banner_printed)
154ade9ccfeSMarcel Moolenaar xo_open_list("multicast-interface");
155ade9ccfeSMarcel Moolenaar else
156ade9ccfeSMarcel Moolenaar xo_emit("\n{T:IPv6 Multicast Interface Table is empty}\n");
1570fea3d51SYoshinobu Inoue
158c15ddad9SBruce M Simpson len = sizeof(mf6ctable);
159c151f24dSGleb Smirnoff if (sysctlbyname("net.inet6.ip6.mf6ctable", mf6ctable, &len, NULL, 0) <
160c151f24dSGleb Smirnoff 0) {
161ade9ccfeSMarcel Moolenaar xo_warn("sysctl: net.inet6.ip6.mf6ctable");
162c15ddad9SBruce M Simpson return;
163c15ddad9SBruce M Simpson }
164c15ddad9SBruce M Simpson
1650fea3d51SYoshinobu Inoue banner_printed = 0;
166c15ddad9SBruce M Simpson
1670fea3d51SYoshinobu Inoue for (i = 0; i < MF6CTBLSIZ; ++i) {
1680fea3d51SYoshinobu Inoue mfcp = mf6ctable[i];
1690fea3d51SYoshinobu Inoue while(mfcp) {
1700fea3d51SYoshinobu Inoue kread((u_long)mfcp, (char *)&mfc, sizeof(mfc));
1710fea3d51SYoshinobu Inoue if (!banner_printed) {
172ade9ccfeSMarcel Moolenaar xo_open_list("multicast-forwarding-cache");
173ade9ccfeSMarcel Moolenaar xo_emit("\n"
174ade9ccfeSMarcel Moolenaar "{T:IPv6 Multicast Forwarding Cache}\n");
175ade9ccfeSMarcel Moolenaar xo_emit(" {T:%-*.*s} {T:%-*.*s} {T:%s}",
1760fea3d51SYoshinobu Inoue WID_ORG, WID_ORG, "Origin",
1770fea3d51SYoshinobu Inoue WID_GRP, WID_GRP, "Group",
1780fea3d51SYoshinobu Inoue " Packets Waits In-Mif Out-Mifs\n");
1790fea3d51SYoshinobu Inoue banner_printed = 1;
1800fea3d51SYoshinobu Inoue }
1810fea3d51SYoshinobu Inoue
182ade9ccfeSMarcel Moolenaar xo_open_instance("multicast-forwarding-cache");
183ade9ccfeSMarcel Moolenaar
184ade9ccfeSMarcel Moolenaar xo_emit(" {:origin/%-*.*s}", WID_ORG, WID_ORG,
18510d5269fSHiroki Sato routename(sin6tosa(&mfc.mf6c_origin),
18610d5269fSHiroki Sato numeric_addr));
187ade9ccfeSMarcel Moolenaar xo_emit(" {:group/%-*.*s}", WID_GRP, WID_GRP,
18810d5269fSHiroki Sato routename(sin6tosa(&mfc.mf6c_mcastgrp),
18910d5269fSHiroki Sato numeric_addr));
190ade9ccfeSMarcel Moolenaar xo_emit(" {:total-packets/%9ju}",
191ade9ccfeSMarcel Moolenaar (uintmax_t)mfc.mf6c_pkt_cnt);
1920fea3d51SYoshinobu Inoue
1930fea3d51SYoshinobu Inoue for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) {
1940fea3d51SYoshinobu Inoue waitings++;
195c15ddad9SBruce M Simpson /* XXX KVM */
1960fea3d51SYoshinobu Inoue kread((u_long)rtep, (char *)&rte, sizeof(rte));
1970fea3d51SYoshinobu Inoue rtep = rte.next;
1980fea3d51SYoshinobu Inoue }
199ade9ccfeSMarcel Moolenaar xo_emit(" {:waitings/%3ld}", waitings);
2000fea3d51SYoshinobu Inoue
2010fea3d51SYoshinobu Inoue if (mfc.mf6c_parent == MF6C_INCOMPLETE_PARENT)
202ade9ccfeSMarcel Moolenaar xo_emit(" --- ");
2030fea3d51SYoshinobu Inoue else
204ade9ccfeSMarcel Moolenaar xo_emit(" {:parent/%3d} ", mfc.mf6c_parent);
205ade9ccfeSMarcel Moolenaar xo_open_list("mif");
2060fea3d51SYoshinobu Inoue for (mifi = 0; mifi <= maxmif; mifi++) {
2070fea3d51SYoshinobu Inoue if (IF_ISSET(mifi, &mfc.mf6c_ifset))
208ade9ccfeSMarcel Moolenaar xo_emit(" {l:%u}", mifi);
2090fea3d51SYoshinobu Inoue }
210ade9ccfeSMarcel Moolenaar xo_close_list("mif");
211ade9ccfeSMarcel Moolenaar xo_emit("\n");
2120fea3d51SYoshinobu Inoue
2130fea3d51SYoshinobu Inoue mfcp = mfc.mf6c_next;
214ade9ccfeSMarcel Moolenaar xo_close_instance("multicast-forwarding-cache");
2150fea3d51SYoshinobu Inoue }
2160fea3d51SYoshinobu Inoue }
217ade9ccfeSMarcel Moolenaar if (banner_printed)
218ade9ccfeSMarcel Moolenaar xo_close_list("multicast-forwarding-cache");
219ade9ccfeSMarcel Moolenaar else
220ade9ccfeSMarcel Moolenaar xo_emit("\n{T:IPv6 Multicast Forwarding Table is empty}\n");
2210fea3d51SYoshinobu Inoue
222ade9ccfeSMarcel Moolenaar xo_emit("\n");
22365ea0024SAssar Westerlund numeric_addr = saved_numeric_addr;
2240fea3d51SYoshinobu Inoue }
2250fea3d51SYoshinobu Inoue
2260fea3d51SYoshinobu Inoue void
mrt6_stats(void)2274640fd28SJohn Baldwin mrt6_stats(void)
2280fea3d51SYoshinobu Inoue {
2290fea3d51SYoshinobu Inoue struct mrt6stat mrtstat;
2300fea3d51SYoshinobu Inoue
2319eddb899SMark Johnston if (fetch_stats("net.inet6.ip6.mrt6stat", 0, &mrtstat,
2329eddb899SMark Johnston sizeof(mrtstat), kread_counters) != 0)
2330fea3d51SYoshinobu Inoue return;
234feda1a43SJohn Baldwin
235ade9ccfeSMarcel Moolenaar xo_open_container("multicast-statistics");
236ade9ccfeSMarcel Moolenaar xo_emit("{T:IPv6 multicast forwarding}:\n");
23776840ccbSRuslan Ermilov
23876840ccbSRuslan Ermilov #define p(f, m) if (mrtstat.f || sflag <= 1) \
239ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t)mrtstat.f, plural(mrtstat.f))
24076840ccbSRuslan Ermilov #define p2(f, m) if (mrtstat.f || sflag <= 1) \
241ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t)mrtstat.f, plurales(mrtstat.f))
24276840ccbSRuslan Ermilov
243ade9ccfeSMarcel Moolenaar p(mrt6s_mfc_lookups, "\t{:cache-lookups/%ju} "
244ade9ccfeSMarcel Moolenaar "{N:/multicast forwarding cache lookup%s}\n");
245ade9ccfeSMarcel Moolenaar p2(mrt6s_mfc_misses, "\t{:cache-misses/%ju} "
246ade9ccfeSMarcel Moolenaar "{N:/multicast forwarding cache miss%s}\n");
247ade9ccfeSMarcel Moolenaar p(mrt6s_upcalls, "\t{:upcalls/%ju} "
248ade9ccfeSMarcel Moolenaar "{N:/upcall%s to multicast routing daemon}\n");
249ade9ccfeSMarcel Moolenaar p(mrt6s_upq_ovflw, "\t{:upcall-overflows/%ju} "
250ade9ccfeSMarcel Moolenaar "{N:/upcall queue overflow%s}\n");
251ade9ccfeSMarcel Moolenaar p(mrt6s_upq_sockfull, "\t{:upcalls-dropped-full-buffer/%ju} "
252ade9ccfeSMarcel Moolenaar "{N:/upcall%s dropped due to full socket buffer}\n");
253ade9ccfeSMarcel Moolenaar p(mrt6s_cache_cleanups, "\t{:cache-cleanups/%ju} "
254ade9ccfeSMarcel Moolenaar "{N:/cache cleanup%s}\n");
255ade9ccfeSMarcel Moolenaar p(mrt6s_no_route, "\t{:dropped-no-origin/%ju} "
256ade9ccfeSMarcel Moolenaar "{N:/datagram%s with no route for origin}\n");
257ade9ccfeSMarcel Moolenaar p(mrt6s_bad_tunnel, "\t{:dropped-bad-tunnel/%ju} "
258ade9ccfeSMarcel Moolenaar "{N:/datagram%s arrived with bad tunneling}\n");
259ade9ccfeSMarcel Moolenaar p(mrt6s_cant_tunnel, "\t{:dropped-could-not-tunnel/%ju} "
260ade9ccfeSMarcel Moolenaar "{N:/datagram%s could not be tunneled}\n");
261ade9ccfeSMarcel Moolenaar p(mrt6s_wrong_if, "\t{:dropped-wrong-incoming-interface/%ju} "
262ade9ccfeSMarcel Moolenaar "{N:/datagram%s arrived on wrong interface}\n");
263ade9ccfeSMarcel Moolenaar p(mrt6s_drop_sel, "\t{:dropped-selectively/%ju} "
264ade9ccfeSMarcel Moolenaar "{N:/datagram%s selectively dropped}\n");
265ade9ccfeSMarcel Moolenaar p(mrt6s_q_overflow, "\t{:dropped-queue-overflow/%ju} "
266ade9ccfeSMarcel Moolenaar "{N:/datagram%s dropped due to queue overflow}\n");
267ade9ccfeSMarcel Moolenaar p(mrt6s_pkt2large, "\t{:dropped-too-large/%ju} "
268ade9ccfeSMarcel Moolenaar "{N:/datagram%s dropped for being too large}\n");
26976840ccbSRuslan Ermilov
27076840ccbSRuslan Ermilov #undef p2
27176840ccbSRuslan Ermilov #undef p
272ade9ccfeSMarcel Moolenaar xo_close_container("multicast-statistics");
2730fea3d51SYoshinobu Inoue }
274d84a1df4SHajimu UMEMOTO #endif /*INET6*/
275