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 * @(#)mroute.c 8.2 (Berkeley) 4/28/95 680fea3d51SYoshinobu Inoue */ 690fea3d51SYoshinobu Inoue 706cc6f122SPhilippe Charnier #include <sys/cdefs.h> 716cc6f122SPhilippe Charnier __FBSDID("$FreeBSD$"); 726cc6f122SPhilippe Charnier 73d84a1df4SHajimu UMEMOTO #ifdef INET6 740fea3d51SYoshinobu Inoue #include <sys/param.h> 750fea3d51SYoshinobu Inoue #include <sys/queue.h> 760fea3d51SYoshinobu Inoue #include <sys/socket.h> 770fea3d51SYoshinobu Inoue #include <sys/socketvar.h> 78c15ddad9SBruce M Simpson #include <sys/sysctl.h> 790fea3d51SYoshinobu Inoue #include <sys/protosw.h> 80c15ddad9SBruce M Simpson #include <sys/mbuf.h> 81c15ddad9SBruce M Simpson #include <sys/time.h> 820fea3d51SYoshinobu Inoue 830fea3d51SYoshinobu Inoue #include <net/if.h> 8433841545SHajimu UMEMOTO #include <net/route.h> 850fea3d51SYoshinobu Inoue 860fea3d51SYoshinobu Inoue #include <netinet/in.h> 870fea3d51SYoshinobu Inoue 88c15ddad9SBruce M Simpson #include <err.h> 897b95a1ebSYaroslav Tykhiy #include <stdint.h> 900fea3d51SYoshinobu Inoue #include <stdio.h> 91c15ddad9SBruce M Simpson #include <stdlib.h> 92ade9ccfeSMarcel Moolenaar #include <stdbool.h> 93ade9ccfeSMarcel Moolenaar #include <libxo/xo.h> 940fea3d51SYoshinobu Inoue 950fea3d51SYoshinobu Inoue #define KERNEL 1 960fea3d51SYoshinobu Inoue #include <netinet6/ip6_mroute.h> 970fea3d51SYoshinobu Inoue #undef KERNEL 980fea3d51SYoshinobu Inoue 990fea3d51SYoshinobu Inoue #include "netstat.h" 1000fea3d51SYoshinobu Inoue 10170057abfSRuslan Ermilov #define WID_ORG (Wflag ? 39 : (numeric_addr ? 29 : 18)) /* width of origin column */ 10270057abfSRuslan Ermilov #define WID_GRP (Wflag ? 18 : (numeric_addr ? 16 : 18)) /* width of group column */ 1030fea3d51SYoshinobu Inoue 1040fea3d51SYoshinobu Inoue void 105*4640fd28SJohn Baldwin mroute6pr(void) 1060fea3d51SYoshinobu Inoue { 1070fea3d51SYoshinobu Inoue struct mf6c *mf6ctable[MF6CTBLSIZ], *mfcp; 108c151f24dSGleb Smirnoff struct mif6_sctl mif6table[MAXMIFS]; 1090fea3d51SYoshinobu Inoue struct mf6c mfc; 1100fea3d51SYoshinobu Inoue struct rtdetq rte, *rtep; 111c151f24dSGleb Smirnoff struct mif6_sctl *mifp; 112a01e3379SDavid Malone mifi_t mifi; 113a01e3379SDavid Malone int i; 114a01e3379SDavid Malone int banner_printed; 115a01e3379SDavid Malone int saved_numeric_addr; 1160fea3d51SYoshinobu Inoue mifi_t maxmif = 0; 1170fea3d51SYoshinobu Inoue long int waitings; 118c15ddad9SBruce M Simpson size_t len; 1190fea3d51SYoshinobu Inoue 120c151f24dSGleb Smirnoff if (live == 0) 121fc47e028SAlexander V. Chernikov return; 122fc47e028SAlexander V. Chernikov 123c15ddad9SBruce M Simpson len = sizeof(mif6table); 124c151f24dSGleb Smirnoff if (sysctlbyname("net.inet6.ip6.mif6table", mif6table, &len, NULL, 0) < 125c151f24dSGleb Smirnoff 0) { 126ade9ccfeSMarcel Moolenaar xo_warn("sysctl: net.inet6.ip6.mif6table"); 1270fea3d51SYoshinobu Inoue return; 1280fea3d51SYoshinobu Inoue } 1290fea3d51SYoshinobu Inoue 13065ea0024SAssar Westerlund saved_numeric_addr = numeric_addr; 13165ea0024SAssar Westerlund numeric_addr = 1; 1320fea3d51SYoshinobu Inoue banner_printed = 0; 133c15ddad9SBruce M Simpson 1340fea3d51SYoshinobu Inoue for (mifi = 0, mifp = mif6table; mifi < MAXMIFS; ++mifi, ++mifp) { 1350fea3d51SYoshinobu Inoue char ifname[IFNAMSIZ]; 1360fea3d51SYoshinobu Inoue 137c151f24dSGleb Smirnoff if (mifp->m6_ifp == 0) 1380fea3d51SYoshinobu Inoue continue; 1390fea3d51SYoshinobu Inoue 1400fea3d51SYoshinobu Inoue maxmif = mifi; 1410fea3d51SYoshinobu Inoue if (!banner_printed) { 142ade9ccfeSMarcel Moolenaar xo_open_list("multicast-interface"); 143ade9ccfeSMarcel Moolenaar xo_emit("\n{T:IPv6 Multicast Interface Table}\n" 144ade9ccfeSMarcel Moolenaar "{T: Mif Rate PhyIF Pkts-In Pkts-Out}\n"); 1450fea3d51SYoshinobu Inoue banner_printed = 1; 1460fea3d51SYoshinobu Inoue } 1470fea3d51SYoshinobu Inoue 148ade9ccfeSMarcel Moolenaar xo_open_instance("multicast-interface"); 149ade9ccfeSMarcel Moolenaar xo_emit(" {:mif/%2u} {:rate-limit/%4d}", 1500fea3d51SYoshinobu Inoue mifi, mifp->m6_rate_limit); 151ade9ccfeSMarcel Moolenaar xo_emit(" {:ifname/%5s}", (mifp->m6_flags & MIFF_REGISTER) ? 152c151f24dSGleb Smirnoff "reg0" : if_indextoname(mifp->m6_ifp, ifname)); 1530fea3d51SYoshinobu Inoue 154ade9ccfeSMarcel Moolenaar xo_emit(" {:received-packets/%9ju} {:sent-packets/%9ju}\n", 155ade9ccfeSMarcel Moolenaar (uintmax_t)mifp->m6_pkt_in, 1567b95a1ebSYaroslav Tykhiy (uintmax_t)mifp->m6_pkt_out); 157ade9ccfeSMarcel Moolenaar xo_close_instance("multicast-interface"); 1580fea3d51SYoshinobu Inoue } 159ade9ccfeSMarcel Moolenaar if (banner_printed) 160ade9ccfeSMarcel Moolenaar xo_open_list("multicast-interface"); 161ade9ccfeSMarcel Moolenaar else 162ade9ccfeSMarcel Moolenaar xo_emit("\n{T:IPv6 Multicast Interface Table is empty}\n"); 1630fea3d51SYoshinobu Inoue 164c15ddad9SBruce M Simpson len = sizeof(mf6ctable); 165c151f24dSGleb Smirnoff if (sysctlbyname("net.inet6.ip6.mf6ctable", mf6ctable, &len, NULL, 0) < 166c151f24dSGleb Smirnoff 0) { 167ade9ccfeSMarcel Moolenaar xo_warn("sysctl: net.inet6.ip6.mf6ctable"); 168c15ddad9SBruce M Simpson return; 169c15ddad9SBruce M Simpson } 170c15ddad9SBruce M Simpson 1710fea3d51SYoshinobu Inoue banner_printed = 0; 172c15ddad9SBruce M Simpson 1730fea3d51SYoshinobu Inoue for (i = 0; i < MF6CTBLSIZ; ++i) { 1740fea3d51SYoshinobu Inoue mfcp = mf6ctable[i]; 1750fea3d51SYoshinobu Inoue while(mfcp) { 1760fea3d51SYoshinobu Inoue kread((u_long)mfcp, (char *)&mfc, sizeof(mfc)); 1770fea3d51SYoshinobu Inoue if (!banner_printed) { 178ade9ccfeSMarcel Moolenaar xo_open_list("multicast-forwarding-cache"); 179ade9ccfeSMarcel Moolenaar xo_emit("\n" 180ade9ccfeSMarcel Moolenaar "{T:IPv6 Multicast Forwarding Cache}\n"); 181ade9ccfeSMarcel Moolenaar xo_emit(" {T:%-*.*s} {T:%-*.*s} {T:%s}", 1820fea3d51SYoshinobu Inoue WID_ORG, WID_ORG, "Origin", 1830fea3d51SYoshinobu Inoue WID_GRP, WID_GRP, "Group", 1840fea3d51SYoshinobu Inoue " Packets Waits In-Mif Out-Mifs\n"); 1850fea3d51SYoshinobu Inoue banner_printed = 1; 1860fea3d51SYoshinobu Inoue } 1870fea3d51SYoshinobu Inoue 188ade9ccfeSMarcel Moolenaar xo_open_instance("multicast-forwarding-cache"); 189ade9ccfeSMarcel Moolenaar 190ade9ccfeSMarcel Moolenaar xo_emit(" {:origin/%-*.*s}", WID_ORG, WID_ORG, 19110d5269fSHiroki Sato routename(sin6tosa(&mfc.mf6c_origin), 19210d5269fSHiroki Sato numeric_addr)); 193ade9ccfeSMarcel Moolenaar xo_emit(" {:group/%-*.*s}", WID_GRP, WID_GRP, 19410d5269fSHiroki Sato routename(sin6tosa(&mfc.mf6c_mcastgrp), 19510d5269fSHiroki Sato numeric_addr)); 196ade9ccfeSMarcel Moolenaar xo_emit(" {:total-packets/%9ju}", 197ade9ccfeSMarcel Moolenaar (uintmax_t)mfc.mf6c_pkt_cnt); 1980fea3d51SYoshinobu Inoue 1990fea3d51SYoshinobu Inoue for (waitings = 0, rtep = mfc.mf6c_stall; rtep; ) { 2000fea3d51SYoshinobu Inoue waitings++; 201c15ddad9SBruce M Simpson /* XXX KVM */ 2020fea3d51SYoshinobu Inoue kread((u_long)rtep, (char *)&rte, sizeof(rte)); 2030fea3d51SYoshinobu Inoue rtep = rte.next; 2040fea3d51SYoshinobu Inoue } 205ade9ccfeSMarcel Moolenaar xo_emit(" {:waitings/%3ld}", waitings); 2060fea3d51SYoshinobu Inoue 2070fea3d51SYoshinobu Inoue if (mfc.mf6c_parent == MF6C_INCOMPLETE_PARENT) 208ade9ccfeSMarcel Moolenaar xo_emit(" --- "); 2090fea3d51SYoshinobu Inoue else 210ade9ccfeSMarcel Moolenaar xo_emit(" {:parent/%3d} ", mfc.mf6c_parent); 211ade9ccfeSMarcel Moolenaar xo_open_list("mif"); 2120fea3d51SYoshinobu Inoue for (mifi = 0; mifi <= maxmif; mifi++) { 2130fea3d51SYoshinobu Inoue if (IF_ISSET(mifi, &mfc.mf6c_ifset)) 214ade9ccfeSMarcel Moolenaar xo_emit(" {l:%u}", mifi); 2150fea3d51SYoshinobu Inoue } 216ade9ccfeSMarcel Moolenaar xo_close_list("mif"); 217ade9ccfeSMarcel Moolenaar xo_emit("\n"); 2180fea3d51SYoshinobu Inoue 2190fea3d51SYoshinobu Inoue mfcp = mfc.mf6c_next; 220ade9ccfeSMarcel Moolenaar xo_close_instance("multicast-forwarding-cache"); 2210fea3d51SYoshinobu Inoue } 2220fea3d51SYoshinobu Inoue } 223ade9ccfeSMarcel Moolenaar if (banner_printed) 224ade9ccfeSMarcel Moolenaar xo_close_list("multicast-forwarding-cache"); 225ade9ccfeSMarcel Moolenaar else 226ade9ccfeSMarcel Moolenaar xo_emit("\n{T:IPv6 Multicast Forwarding Table is empty}\n"); 2270fea3d51SYoshinobu Inoue 228ade9ccfeSMarcel Moolenaar xo_emit("\n"); 22965ea0024SAssar Westerlund numeric_addr = saved_numeric_addr; 2300fea3d51SYoshinobu Inoue } 2310fea3d51SYoshinobu Inoue 2320fea3d51SYoshinobu Inoue void 233*4640fd28SJohn Baldwin mrt6_stats(void) 2340fea3d51SYoshinobu Inoue { 2350fea3d51SYoshinobu Inoue struct mrt6stat mrtstat; 2360fea3d51SYoshinobu Inoue 2379eddb899SMark Johnston if (fetch_stats("net.inet6.ip6.mrt6stat", 0, &mrtstat, 2389eddb899SMark Johnston sizeof(mrtstat), kread_counters) != 0) 2390fea3d51SYoshinobu Inoue return; 240feda1a43SJohn Baldwin 241ade9ccfeSMarcel Moolenaar xo_open_container("multicast-statistics"); 242ade9ccfeSMarcel Moolenaar xo_emit("{T:IPv6 multicast forwarding}:\n"); 24376840ccbSRuslan Ermilov 24476840ccbSRuslan Ermilov #define p(f, m) if (mrtstat.f || sflag <= 1) \ 245ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t)mrtstat.f, plural(mrtstat.f)) 24676840ccbSRuslan Ermilov #define p2(f, m) if (mrtstat.f || sflag <= 1) \ 247ade9ccfeSMarcel Moolenaar xo_emit(m, (uintmax_t)mrtstat.f, plurales(mrtstat.f)) 24876840ccbSRuslan Ermilov 249ade9ccfeSMarcel Moolenaar p(mrt6s_mfc_lookups, "\t{:cache-lookups/%ju} " 250ade9ccfeSMarcel Moolenaar "{N:/multicast forwarding cache lookup%s}\n"); 251ade9ccfeSMarcel Moolenaar p2(mrt6s_mfc_misses, "\t{:cache-misses/%ju} " 252ade9ccfeSMarcel Moolenaar "{N:/multicast forwarding cache miss%s}\n"); 253ade9ccfeSMarcel Moolenaar p(mrt6s_upcalls, "\t{:upcalls/%ju} " 254ade9ccfeSMarcel Moolenaar "{N:/upcall%s to multicast routing daemon}\n"); 255ade9ccfeSMarcel Moolenaar p(mrt6s_upq_ovflw, "\t{:upcall-overflows/%ju} " 256ade9ccfeSMarcel Moolenaar "{N:/upcall queue overflow%s}\n"); 257ade9ccfeSMarcel Moolenaar p(mrt6s_upq_sockfull, "\t{:upcalls-dropped-full-buffer/%ju} " 258ade9ccfeSMarcel Moolenaar "{N:/upcall%s dropped due to full socket buffer}\n"); 259ade9ccfeSMarcel Moolenaar p(mrt6s_cache_cleanups, "\t{:cache-cleanups/%ju} " 260ade9ccfeSMarcel Moolenaar "{N:/cache cleanup%s}\n"); 261ade9ccfeSMarcel Moolenaar p(mrt6s_no_route, "\t{:dropped-no-origin/%ju} " 262ade9ccfeSMarcel Moolenaar "{N:/datagram%s with no route for origin}\n"); 263ade9ccfeSMarcel Moolenaar p(mrt6s_bad_tunnel, "\t{:dropped-bad-tunnel/%ju} " 264ade9ccfeSMarcel Moolenaar "{N:/datagram%s arrived with bad tunneling}\n"); 265ade9ccfeSMarcel Moolenaar p(mrt6s_cant_tunnel, "\t{:dropped-could-not-tunnel/%ju} " 266ade9ccfeSMarcel Moolenaar "{N:/datagram%s could not be tunneled}\n"); 267ade9ccfeSMarcel Moolenaar p(mrt6s_wrong_if, "\t{:dropped-wrong-incoming-interface/%ju} " 268ade9ccfeSMarcel Moolenaar "{N:/datagram%s arrived on wrong interface}\n"); 269ade9ccfeSMarcel Moolenaar p(mrt6s_drop_sel, "\t{:dropped-selectively/%ju} " 270ade9ccfeSMarcel Moolenaar "{N:/datagram%s selectively dropped}\n"); 271ade9ccfeSMarcel Moolenaar p(mrt6s_q_overflow, "\t{:dropped-queue-overflow/%ju} " 272ade9ccfeSMarcel Moolenaar "{N:/datagram%s dropped due to queue overflow}\n"); 273ade9ccfeSMarcel Moolenaar p(mrt6s_pkt2large, "\t{:dropped-too-large/%ju} " 274ade9ccfeSMarcel Moolenaar "{N:/datagram%s dropped for being too large}\n"); 27576840ccbSRuslan Ermilov 27676840ccbSRuslan Ermilov #undef p2 27776840ccbSRuslan Ermilov #undef p 278ade9ccfeSMarcel Moolenaar xo_close_container("multicast-statistics"); 2790fea3d51SYoshinobu Inoue } 280d84a1df4SHajimu UMEMOTO #endif /*INET6*/ 281