1cfa1ca9dSYoshinobu Inoue /* BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp */ 265475bc8SDavid E. O'Brien /*- 3cfa1ca9dSYoshinobu Inoue * Copyright (c) 1983, 1988, 1993 4cfa1ca9dSYoshinobu Inoue * The Regents of the University of California. All rights reserved. 5cfa1ca9dSYoshinobu Inoue * 6cfa1ca9dSYoshinobu Inoue * Redistribution and use in source and binary forms, with or without 7cfa1ca9dSYoshinobu Inoue * modification, are permitted provided that the following conditions 8cfa1ca9dSYoshinobu Inoue * are met: 9cfa1ca9dSYoshinobu Inoue * 1. Redistributions of source code must retain the above copyright 10cfa1ca9dSYoshinobu Inoue * notice, this list of conditions and the following disclaimer. 11cfa1ca9dSYoshinobu Inoue * 2. Redistributions in binary form must reproduce the above copyright 12cfa1ca9dSYoshinobu Inoue * notice, this list of conditions and the following disclaimer in the 13cfa1ca9dSYoshinobu Inoue * documentation and/or other materials provided with the distribution. 14cfa1ca9dSYoshinobu Inoue * 4. Neither the name of the University nor the names of its contributors 15cfa1ca9dSYoshinobu Inoue * may be used to endorse or promote products derived from this software 16cfa1ca9dSYoshinobu Inoue * without specific prior written permission. 17cfa1ca9dSYoshinobu Inoue * 18cfa1ca9dSYoshinobu Inoue * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19cfa1ca9dSYoshinobu Inoue * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20cfa1ca9dSYoshinobu Inoue * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21cfa1ca9dSYoshinobu Inoue * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22cfa1ca9dSYoshinobu Inoue * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23cfa1ca9dSYoshinobu Inoue * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24cfa1ca9dSYoshinobu Inoue * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25cfa1ca9dSYoshinobu Inoue * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26cfa1ca9dSYoshinobu Inoue * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27cfa1ca9dSYoshinobu Inoue * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28cfa1ca9dSYoshinobu Inoue * SUCH DAMAGE. 29cfa1ca9dSYoshinobu Inoue */ 30cfa1ca9dSYoshinobu Inoue 316cc6f122SPhilippe Charnier #if 0 32cfa1ca9dSYoshinobu Inoue #ifndef lint 33cfa1ca9dSYoshinobu Inoue static char sccsid[] = "@(#)inet6.c 8.4 (Berkeley) 4/20/94"; 34cfa1ca9dSYoshinobu Inoue #endif /* not lint */ 356cc6f122SPhilippe Charnier #endif 366cc6f122SPhilippe Charnier 376cc6f122SPhilippe Charnier #include <sys/cdefs.h> 386cc6f122SPhilippe Charnier __FBSDID("$FreeBSD$"); 39cfa1ca9dSYoshinobu Inoue 40d84a1df4SHajimu UMEMOTO #ifdef INET6 41cfa1ca9dSYoshinobu Inoue #include <sys/param.h> 42cfa1ca9dSYoshinobu Inoue #include <sys/socket.h> 43cfa1ca9dSYoshinobu Inoue #include <sys/socketvar.h> 44cfa1ca9dSYoshinobu Inoue #include <sys/ioctl.h> 45cfa1ca9dSYoshinobu Inoue #include <sys/mbuf.h> 46cfa1ca9dSYoshinobu Inoue #include <sys/protosw.h> 4733841545SHajimu UMEMOTO #include <sys/sysctl.h> 48cfa1ca9dSYoshinobu Inoue 49cfa1ca9dSYoshinobu Inoue #include <net/route.h> 50cfa1ca9dSYoshinobu Inoue #include <net/if.h> 51cfa1ca9dSYoshinobu Inoue #include <net/if_var.h> 52cfa1ca9dSYoshinobu Inoue #include <netinet/in.h> 53cfa1ca9dSYoshinobu Inoue #include <netinet/ip6.h> 54cfa1ca9dSYoshinobu Inoue #include <netinet/icmp6.h> 55cfa1ca9dSYoshinobu Inoue #include <netinet/in_systm.h> 56cfa1ca9dSYoshinobu Inoue #include <netinet6/in6_pcb.h> 57cfa1ca9dSYoshinobu Inoue #include <netinet6/in6_var.h> 58cfa1ca9dSYoshinobu Inoue #include <netinet6/ip6_var.h> 59cfa1ca9dSYoshinobu Inoue #include <netinet6/pim6_var.h> 6033841545SHajimu UMEMOTO #include <netinet6/raw_ip6.h> 61cfa1ca9dSYoshinobu Inoue 62cfa1ca9dSYoshinobu Inoue #include <arpa/inet.h> 63cfa1ca9dSYoshinobu Inoue #include <netdb.h> 64cfa1ca9dSYoshinobu Inoue 65c15ddad9SBruce M Simpson #include <err.h> 667b95a1ebSYaroslav Tykhiy #include <stdint.h> 67cfa1ca9dSYoshinobu Inoue #include <stdio.h> 68109dad81SJulian Elischer #include <errno.h> 69cfa1ca9dSYoshinobu Inoue #include <string.h> 70cfa1ca9dSYoshinobu Inoue #include <unistd.h> 71cfa1ca9dSYoshinobu Inoue #include "netstat.h" 72cfa1ca9dSYoshinobu Inoue 73cfa1ca9dSYoshinobu Inoue struct socket sockb; 74cfa1ca9dSYoshinobu Inoue 755e051718SAssar Westerlund char *inet6name(struct in6_addr *); 76cfa1ca9dSYoshinobu Inoue 77cfa1ca9dSYoshinobu Inoue static char ntop_buf[INET6_ADDRSTRLEN]; 78cfa1ca9dSYoshinobu Inoue 79a01e3379SDavid Malone static const char *ip6nh[] = { 80cfa1ca9dSYoshinobu Inoue "hop by hop", 81cfa1ca9dSYoshinobu Inoue "ICMP", 82cfa1ca9dSYoshinobu Inoue "IGMP", 83cfa1ca9dSYoshinobu Inoue "#3", 84cfa1ca9dSYoshinobu Inoue "IP", 85cfa1ca9dSYoshinobu Inoue "#5", 86cfa1ca9dSYoshinobu Inoue "TCP", 87cfa1ca9dSYoshinobu Inoue "#7", 88cfa1ca9dSYoshinobu Inoue "#8", 89cfa1ca9dSYoshinobu Inoue "#9", 90cfa1ca9dSYoshinobu Inoue "#10", 91cfa1ca9dSYoshinobu Inoue "#11", 92cfa1ca9dSYoshinobu Inoue "#12", 93cfa1ca9dSYoshinobu Inoue "#13", 94cfa1ca9dSYoshinobu Inoue "#14", 95cfa1ca9dSYoshinobu Inoue "#15", 96cfa1ca9dSYoshinobu Inoue "#16", 97cfa1ca9dSYoshinobu Inoue "UDP", 98cfa1ca9dSYoshinobu Inoue "#18", 99cfa1ca9dSYoshinobu Inoue "#19", 100cfa1ca9dSYoshinobu Inoue "#20", 101cfa1ca9dSYoshinobu Inoue "#21", 102cfa1ca9dSYoshinobu Inoue "IDP", 103cfa1ca9dSYoshinobu Inoue "#23", 104cfa1ca9dSYoshinobu Inoue "#24", 105cfa1ca9dSYoshinobu Inoue "#25", 106cfa1ca9dSYoshinobu Inoue "#26", 107cfa1ca9dSYoshinobu Inoue "#27", 108cfa1ca9dSYoshinobu Inoue "#28", 109cfa1ca9dSYoshinobu Inoue "TP", 110cfa1ca9dSYoshinobu Inoue "#30", 111cfa1ca9dSYoshinobu Inoue "#31", 112cfa1ca9dSYoshinobu Inoue "#32", 113cfa1ca9dSYoshinobu Inoue "#33", 114cfa1ca9dSYoshinobu Inoue "#34", 115cfa1ca9dSYoshinobu Inoue "#35", 116cfa1ca9dSYoshinobu Inoue "#36", 117cfa1ca9dSYoshinobu Inoue "#37", 118cfa1ca9dSYoshinobu Inoue "#38", 119cfa1ca9dSYoshinobu Inoue "#39", 120cfa1ca9dSYoshinobu Inoue "#40", 121cfa1ca9dSYoshinobu Inoue "IP6", 122cfa1ca9dSYoshinobu Inoue "#42", 123cfa1ca9dSYoshinobu Inoue "routing", 124cfa1ca9dSYoshinobu Inoue "fragment", 125cfa1ca9dSYoshinobu Inoue "#45", 126cfa1ca9dSYoshinobu Inoue "#46", 127cfa1ca9dSYoshinobu Inoue "#47", 128cfa1ca9dSYoshinobu Inoue "#48", 129cfa1ca9dSYoshinobu Inoue "#49", 130cfa1ca9dSYoshinobu Inoue "ESP", 131cfa1ca9dSYoshinobu Inoue "AH", 132cfa1ca9dSYoshinobu Inoue "#52", 133cfa1ca9dSYoshinobu Inoue "#53", 134cfa1ca9dSYoshinobu Inoue "#54", 135cfa1ca9dSYoshinobu Inoue "#55", 136cfa1ca9dSYoshinobu Inoue "#56", 137cfa1ca9dSYoshinobu Inoue "#57", 138cfa1ca9dSYoshinobu Inoue "ICMP6", 139cfa1ca9dSYoshinobu Inoue "no next header", 140cfa1ca9dSYoshinobu Inoue "destination option", 141cfa1ca9dSYoshinobu Inoue "#61", 142cb60a8deSHajimu UMEMOTO "mobility", 143cfa1ca9dSYoshinobu Inoue "#63", 144cfa1ca9dSYoshinobu Inoue "#64", 145cfa1ca9dSYoshinobu Inoue "#65", 146cfa1ca9dSYoshinobu Inoue "#66", 147cfa1ca9dSYoshinobu Inoue "#67", 148cfa1ca9dSYoshinobu Inoue "#68", 149cfa1ca9dSYoshinobu Inoue "#69", 150cfa1ca9dSYoshinobu Inoue "#70", 151cfa1ca9dSYoshinobu Inoue "#71", 152cfa1ca9dSYoshinobu Inoue "#72", 153cfa1ca9dSYoshinobu Inoue "#73", 154cfa1ca9dSYoshinobu Inoue "#74", 155cfa1ca9dSYoshinobu Inoue "#75", 156cfa1ca9dSYoshinobu Inoue "#76", 157cfa1ca9dSYoshinobu Inoue "#77", 158cfa1ca9dSYoshinobu Inoue "#78", 159cfa1ca9dSYoshinobu Inoue "#79", 160cfa1ca9dSYoshinobu Inoue "ISOIP", 161cfa1ca9dSYoshinobu Inoue "#81", 162cfa1ca9dSYoshinobu Inoue "#82", 163cfa1ca9dSYoshinobu Inoue "#83", 164cfa1ca9dSYoshinobu Inoue "#84", 165cfa1ca9dSYoshinobu Inoue "#85", 166cfa1ca9dSYoshinobu Inoue "#86", 167cfa1ca9dSYoshinobu Inoue "#87", 168cfa1ca9dSYoshinobu Inoue "#88", 16932cd1d96SJun-ichiro itojun Hagino "OSPF", 170cfa1ca9dSYoshinobu Inoue "#80", 171cfa1ca9dSYoshinobu Inoue "#91", 172cfa1ca9dSYoshinobu Inoue "#92", 173cfa1ca9dSYoshinobu Inoue "#93", 174cfa1ca9dSYoshinobu Inoue "#94", 175cfa1ca9dSYoshinobu Inoue "#95", 176cfa1ca9dSYoshinobu Inoue "#96", 177cfa1ca9dSYoshinobu Inoue "Ethernet", 178cfa1ca9dSYoshinobu Inoue "#98", 179cfa1ca9dSYoshinobu Inoue "#99", 180cfa1ca9dSYoshinobu Inoue "#100", 181cfa1ca9dSYoshinobu Inoue "#101", 182cfa1ca9dSYoshinobu Inoue "#102", 183cfa1ca9dSYoshinobu Inoue "PIM", 184cfa1ca9dSYoshinobu Inoue "#104", 185cfa1ca9dSYoshinobu Inoue "#105", 186cfa1ca9dSYoshinobu Inoue "#106", 187cfa1ca9dSYoshinobu Inoue "#107", 188cfa1ca9dSYoshinobu Inoue "#108", 189cfa1ca9dSYoshinobu Inoue "#109", 190cfa1ca9dSYoshinobu Inoue "#110", 191cfa1ca9dSYoshinobu Inoue "#111", 192cfa1ca9dSYoshinobu Inoue "#112", 193cfa1ca9dSYoshinobu Inoue "#113", 194cfa1ca9dSYoshinobu Inoue "#114", 195cfa1ca9dSYoshinobu Inoue "#115", 196cfa1ca9dSYoshinobu Inoue "#116", 197cfa1ca9dSYoshinobu Inoue "#117", 198cfa1ca9dSYoshinobu Inoue "#118", 199cfa1ca9dSYoshinobu Inoue "#119", 200cfa1ca9dSYoshinobu Inoue "#120", 201cfa1ca9dSYoshinobu Inoue "#121", 202cfa1ca9dSYoshinobu Inoue "#122", 203cfa1ca9dSYoshinobu Inoue "#123", 204cfa1ca9dSYoshinobu Inoue "#124", 205cfa1ca9dSYoshinobu Inoue "#125", 206cfa1ca9dSYoshinobu Inoue "#126", 207cfa1ca9dSYoshinobu Inoue "#127", 208cfa1ca9dSYoshinobu Inoue "#128", 209cfa1ca9dSYoshinobu Inoue "#129", 210cfa1ca9dSYoshinobu Inoue "#130", 211cfa1ca9dSYoshinobu Inoue "#131", 212cfa1ca9dSYoshinobu Inoue "#132", 213cfa1ca9dSYoshinobu Inoue "#133", 214cfa1ca9dSYoshinobu Inoue "#134", 215cfa1ca9dSYoshinobu Inoue "#135", 216cfa1ca9dSYoshinobu Inoue "#136", 217cfa1ca9dSYoshinobu Inoue "#137", 218cfa1ca9dSYoshinobu Inoue "#138", 219cfa1ca9dSYoshinobu Inoue "#139", 220cfa1ca9dSYoshinobu Inoue "#140", 221cfa1ca9dSYoshinobu Inoue "#141", 222cfa1ca9dSYoshinobu Inoue "#142", 223cfa1ca9dSYoshinobu Inoue "#143", 224cfa1ca9dSYoshinobu Inoue "#144", 225cfa1ca9dSYoshinobu Inoue "#145", 226cfa1ca9dSYoshinobu Inoue "#146", 227cfa1ca9dSYoshinobu Inoue "#147", 228cfa1ca9dSYoshinobu Inoue "#148", 229cfa1ca9dSYoshinobu Inoue "#149", 230cfa1ca9dSYoshinobu Inoue "#150", 231cfa1ca9dSYoshinobu Inoue "#151", 232cfa1ca9dSYoshinobu Inoue "#152", 233cfa1ca9dSYoshinobu Inoue "#153", 234cfa1ca9dSYoshinobu Inoue "#154", 235cfa1ca9dSYoshinobu Inoue "#155", 236cfa1ca9dSYoshinobu Inoue "#156", 237cfa1ca9dSYoshinobu Inoue "#157", 238cfa1ca9dSYoshinobu Inoue "#158", 239cfa1ca9dSYoshinobu Inoue "#159", 240cfa1ca9dSYoshinobu Inoue "#160", 241cfa1ca9dSYoshinobu Inoue "#161", 242cfa1ca9dSYoshinobu Inoue "#162", 243cfa1ca9dSYoshinobu Inoue "#163", 244cfa1ca9dSYoshinobu Inoue "#164", 245cfa1ca9dSYoshinobu Inoue "#165", 246cfa1ca9dSYoshinobu Inoue "#166", 247cfa1ca9dSYoshinobu Inoue "#167", 248cfa1ca9dSYoshinobu Inoue "#168", 249cfa1ca9dSYoshinobu Inoue "#169", 250cfa1ca9dSYoshinobu Inoue "#170", 251cfa1ca9dSYoshinobu Inoue "#171", 252cfa1ca9dSYoshinobu Inoue "#172", 253cfa1ca9dSYoshinobu Inoue "#173", 254cfa1ca9dSYoshinobu Inoue "#174", 255cfa1ca9dSYoshinobu Inoue "#175", 256cfa1ca9dSYoshinobu Inoue "#176", 257cfa1ca9dSYoshinobu Inoue "#177", 258cfa1ca9dSYoshinobu Inoue "#178", 259cfa1ca9dSYoshinobu Inoue "#179", 260cfa1ca9dSYoshinobu Inoue "#180", 261cfa1ca9dSYoshinobu Inoue "#181", 262cfa1ca9dSYoshinobu Inoue "#182", 263cfa1ca9dSYoshinobu Inoue "#183", 264cfa1ca9dSYoshinobu Inoue "#184", 265cfa1ca9dSYoshinobu Inoue "#185", 266cfa1ca9dSYoshinobu Inoue "#186", 267cfa1ca9dSYoshinobu Inoue "#187", 268cfa1ca9dSYoshinobu Inoue "#188", 269cfa1ca9dSYoshinobu Inoue "#189", 270cfa1ca9dSYoshinobu Inoue "#180", 271cfa1ca9dSYoshinobu Inoue "#191", 272cfa1ca9dSYoshinobu Inoue "#192", 273cfa1ca9dSYoshinobu Inoue "#193", 274cfa1ca9dSYoshinobu Inoue "#194", 275cfa1ca9dSYoshinobu Inoue "#195", 276cfa1ca9dSYoshinobu Inoue "#196", 277cfa1ca9dSYoshinobu Inoue "#197", 278cfa1ca9dSYoshinobu Inoue "#198", 279cfa1ca9dSYoshinobu Inoue "#199", 280cfa1ca9dSYoshinobu Inoue "#200", 281cfa1ca9dSYoshinobu Inoue "#201", 282cfa1ca9dSYoshinobu Inoue "#202", 283cfa1ca9dSYoshinobu Inoue "#203", 284cfa1ca9dSYoshinobu Inoue "#204", 285cfa1ca9dSYoshinobu Inoue "#205", 286cfa1ca9dSYoshinobu Inoue "#206", 287cfa1ca9dSYoshinobu Inoue "#207", 288cfa1ca9dSYoshinobu Inoue "#208", 289cfa1ca9dSYoshinobu Inoue "#209", 290cfa1ca9dSYoshinobu Inoue "#210", 291cfa1ca9dSYoshinobu Inoue "#211", 292cfa1ca9dSYoshinobu Inoue "#212", 293cfa1ca9dSYoshinobu Inoue "#213", 294cfa1ca9dSYoshinobu Inoue "#214", 295cfa1ca9dSYoshinobu Inoue "#215", 296cfa1ca9dSYoshinobu Inoue "#216", 297cfa1ca9dSYoshinobu Inoue "#217", 298cfa1ca9dSYoshinobu Inoue "#218", 299cfa1ca9dSYoshinobu Inoue "#219", 300cfa1ca9dSYoshinobu Inoue "#220", 301cfa1ca9dSYoshinobu Inoue "#221", 302cfa1ca9dSYoshinobu Inoue "#222", 303cfa1ca9dSYoshinobu Inoue "#223", 304cfa1ca9dSYoshinobu Inoue "#224", 305cfa1ca9dSYoshinobu Inoue "#225", 306cfa1ca9dSYoshinobu Inoue "#226", 307cfa1ca9dSYoshinobu Inoue "#227", 308cfa1ca9dSYoshinobu Inoue "#228", 309cfa1ca9dSYoshinobu Inoue "#229", 310cfa1ca9dSYoshinobu Inoue "#230", 311cfa1ca9dSYoshinobu Inoue "#231", 312cfa1ca9dSYoshinobu Inoue "#232", 313cfa1ca9dSYoshinobu Inoue "#233", 314cfa1ca9dSYoshinobu Inoue "#234", 315cfa1ca9dSYoshinobu Inoue "#235", 316cfa1ca9dSYoshinobu Inoue "#236", 317cfa1ca9dSYoshinobu Inoue "#237", 318cfa1ca9dSYoshinobu Inoue "#238", 319cfa1ca9dSYoshinobu Inoue "#239", 320cfa1ca9dSYoshinobu Inoue "#240", 321cfa1ca9dSYoshinobu Inoue "#241", 322cfa1ca9dSYoshinobu Inoue "#242", 323cfa1ca9dSYoshinobu Inoue "#243", 324cfa1ca9dSYoshinobu Inoue "#244", 325cfa1ca9dSYoshinobu Inoue "#245", 326cfa1ca9dSYoshinobu Inoue "#246", 327cfa1ca9dSYoshinobu Inoue "#247", 328cfa1ca9dSYoshinobu Inoue "#248", 329cfa1ca9dSYoshinobu Inoue "#249", 330cfa1ca9dSYoshinobu Inoue "#250", 331cfa1ca9dSYoshinobu Inoue "#251", 332cfa1ca9dSYoshinobu Inoue "#252", 333cfa1ca9dSYoshinobu Inoue "#253", 334cfa1ca9dSYoshinobu Inoue "#254", 335cfa1ca9dSYoshinobu Inoue "#255", 336cfa1ca9dSYoshinobu Inoue }; 337cfa1ca9dSYoshinobu Inoue 3384ef2dc8bSHajimu UMEMOTO static char *srcrule_str[] = { 3394ef2dc8bSHajimu UMEMOTO "first candidate", 3404ef2dc8bSHajimu UMEMOTO "same address", 3414ef2dc8bSHajimu UMEMOTO "appropriate scope", 3424ef2dc8bSHajimu UMEMOTO "deprecated address", 3434ef2dc8bSHajimu UMEMOTO "home address", 3444ef2dc8bSHajimu UMEMOTO "outgoing interface", 3454ef2dc8bSHajimu UMEMOTO "matching label", 3464ef2dc8bSHajimu UMEMOTO "public/temporary address", 3474ef2dc8bSHajimu UMEMOTO "alive interface", 3484ef2dc8bSHajimu UMEMOTO "preferred interface", 3494ef2dc8bSHajimu UMEMOTO "rule #10", 3504ef2dc8bSHajimu UMEMOTO "rule #11", 3514ef2dc8bSHajimu UMEMOTO "rule #12", 3524ef2dc8bSHajimu UMEMOTO "rule #13", 3534ef2dc8bSHajimu UMEMOTO "longest match", 3544ef2dc8bSHajimu UMEMOTO "rule #15", 3554ef2dc8bSHajimu UMEMOTO }; 3564ef2dc8bSHajimu UMEMOTO 357cfa1ca9dSYoshinobu Inoue /* 358cfa1ca9dSYoshinobu Inoue * Dump IP6 statistics structure. 359cfa1ca9dSYoshinobu Inoue */ 360cfa1ca9dSYoshinobu Inoue void 361feda1a43SJohn Baldwin ip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused) 362cfa1ca9dSYoshinobu Inoue { 363*d96ea877SMaxim Konovalov struct ip6stat ip6stat, zerostat; 364cfa1ca9dSYoshinobu Inoue int first, i; 365785d213dSHajimu UMEMOTO size_t len; 366cfa1ca9dSYoshinobu Inoue 367785d213dSHajimu UMEMOTO len = sizeof ip6stat; 368feda1a43SJohn Baldwin if (live) { 369785d213dSHajimu UMEMOTO memset(&ip6stat, 0, len); 370*d96ea877SMaxim Konovalov if (zflag) 371*d96ea877SMaxim Konovalov memset(&zerostat, 0, len); 372*d96ea877SMaxim Konovalov if (sysctlbyname("net.inet6.ip6.stats", &ip6stat, &len, 373*d96ea877SMaxim Konovalov zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { 374feda1a43SJohn Baldwin if (errno != ENOENT) 375feda1a43SJohn Baldwin warn("sysctl: net.inet6.ip6.stats"); 3766eec3af9SPoul-Henning Kamp return; 377feda1a43SJohn Baldwin } 378feda1a43SJohn Baldwin } else 379feda1a43SJohn Baldwin kread(off, &ip6stat, len); 380feda1a43SJohn Baldwin 381cfa1ca9dSYoshinobu Inoue printf("%s:\n", name); 382cfa1ca9dSYoshinobu Inoue 383cfa1ca9dSYoshinobu Inoue #define p(f, m) if (ip6stat.f || sflag <= 1) \ 3847b95a1ebSYaroslav Tykhiy printf(m, (uintmax_t)ip6stat.f, plural(ip6stat.f)) 385cfa1ca9dSYoshinobu Inoue #define p1a(f, m) if (ip6stat.f || sflag <= 1) \ 3867b95a1ebSYaroslav Tykhiy printf(m, (uintmax_t)ip6stat.f) 387cfa1ca9dSYoshinobu Inoue 3887b95a1ebSYaroslav Tykhiy p(ip6s_total, "\t%ju total packet%s received\n"); 3897b95a1ebSYaroslav Tykhiy p1a(ip6s_toosmall, "\t%ju with size smaller than minimum\n"); 3907b95a1ebSYaroslav Tykhiy p1a(ip6s_tooshort, "\t%ju with data size < data length\n"); 3917b95a1ebSYaroslav Tykhiy p1a(ip6s_badoptions, "\t%ju with bad options\n"); 3927b95a1ebSYaroslav Tykhiy p1a(ip6s_badvers, "\t%ju with incorrect version number\n"); 3937b95a1ebSYaroslav Tykhiy p(ip6s_fragments, "\t%ju fragment%s received\n"); 3947b95a1ebSYaroslav Tykhiy p(ip6s_fragdropped, "\t%ju fragment%s dropped (dup or out of space)\n"); 3957b95a1ebSYaroslav Tykhiy p(ip6s_fragtimeout, "\t%ju fragment%s dropped after timeout\n"); 3967b95a1ebSYaroslav Tykhiy p(ip6s_fragoverflow, "\t%ju fragment%s that exceeded limit\n"); 3977b95a1ebSYaroslav Tykhiy p(ip6s_reassembled, "\t%ju packet%s reassembled ok\n"); 3987b95a1ebSYaroslav Tykhiy p(ip6s_delivered, "\t%ju packet%s for this host\n"); 3997b95a1ebSYaroslav Tykhiy p(ip6s_forward, "\t%ju packet%s forwarded\n"); 4007b95a1ebSYaroslav Tykhiy p(ip6s_cantforward, "\t%ju packet%s not forwardable\n"); 4017b95a1ebSYaroslav Tykhiy p(ip6s_redirectsent, "\t%ju redirect%s sent\n"); 4027b95a1ebSYaroslav Tykhiy p(ip6s_localout, "\t%ju packet%s sent from this host\n"); 4037b95a1ebSYaroslav Tykhiy p(ip6s_rawout, "\t%ju packet%s sent with fabricated ip header\n"); 4047b95a1ebSYaroslav Tykhiy p(ip6s_odropped, "\t%ju output packet%s dropped due to no bufs, etc.\n"); 4057b95a1ebSYaroslav Tykhiy p(ip6s_noroute, "\t%ju output packet%s discarded due to no route\n"); 4067b95a1ebSYaroslav Tykhiy p(ip6s_fragmented, "\t%ju output datagram%s fragmented\n"); 4077b95a1ebSYaroslav Tykhiy p(ip6s_ofragments, "\t%ju fragment%s created\n"); 4087b95a1ebSYaroslav Tykhiy p(ip6s_cantfrag, "\t%ju datagram%s that can't be fragmented\n"); 4097b95a1ebSYaroslav Tykhiy p(ip6s_badscope, "\t%ju packet%s that violated scope rules\n"); 4107b95a1ebSYaroslav Tykhiy p(ip6s_notmember, "\t%ju multicast packet%s which we don't join\n"); 411cfa1ca9dSYoshinobu Inoue for (first = 1, i = 0; i < 256; i++) 412cfa1ca9dSYoshinobu Inoue if (ip6stat.ip6s_nxthist[i] != 0) { 413cfa1ca9dSYoshinobu Inoue if (first) { 414cfa1ca9dSYoshinobu Inoue printf("\tInput histogram:\n"); 415cfa1ca9dSYoshinobu Inoue first = 0; 416cfa1ca9dSYoshinobu Inoue } 4177b95a1ebSYaroslav Tykhiy printf("\t\t%s: %ju\n", ip6nh[i], 4187b95a1ebSYaroslav Tykhiy (uintmax_t)ip6stat.ip6s_nxthist[i]); 419cfa1ca9dSYoshinobu Inoue } 420cfa1ca9dSYoshinobu Inoue printf("\tMbuf statistics:\n"); 4217b95a1ebSYaroslav Tykhiy printf("\t\t%ju one mbuf\n", (uintmax_t)ip6stat.ip6s_m1); 422cfa1ca9dSYoshinobu Inoue for (first = 1, i = 0; i < 32; i++) { 4237d56d374SYoshinobu Inoue char ifbuf[IFNAMSIZ]; 424cfa1ca9dSYoshinobu Inoue if (ip6stat.ip6s_m2m[i] != 0) { 425cfa1ca9dSYoshinobu Inoue if (first) { 426cfa1ca9dSYoshinobu Inoue printf("\t\ttwo or more mbuf:\n"); 427cfa1ca9dSYoshinobu Inoue first = 0; 428cfa1ca9dSYoshinobu Inoue } 4297b95a1ebSYaroslav Tykhiy printf("\t\t\t%s= %ju\n", 430cfa1ca9dSYoshinobu Inoue if_indextoname(i, ifbuf), 4317b95a1ebSYaroslav Tykhiy (uintmax_t)ip6stat.ip6s_m2m[i]); 432cfa1ca9dSYoshinobu Inoue } 433cfa1ca9dSYoshinobu Inoue } 4347b95a1ebSYaroslav Tykhiy printf("\t\t%ju one ext mbuf\n", 4357b95a1ebSYaroslav Tykhiy (uintmax_t)ip6stat.ip6s_mext1); 4367b95a1ebSYaroslav Tykhiy printf("\t\t%ju two or more ext mbuf\n", 4377b95a1ebSYaroslav Tykhiy (uintmax_t)ip6stat.ip6s_mext2m); 43832cd1d96SJun-ichiro itojun Hagino p(ip6s_exthdrtoolong, 439a709913fSRebecca Cran "\t%ju packet%s whose headers are not contiguous\n"); 4407b95a1ebSYaroslav Tykhiy p(ip6s_nogif, "\t%ju tunneling packet%s that can't find gif\n"); 44132cd1d96SJun-ichiro itojun Hagino p(ip6s_toomanyhdr, 4427b95a1ebSYaroslav Tykhiy "\t%ju packet%s discarded because of too many headers\n"); 44332cd1d96SJun-ichiro itojun Hagino 44432cd1d96SJun-ichiro itojun Hagino /* for debugging source address selection */ 44532cd1d96SJun-ichiro itojun Hagino #define PRINT_SCOPESTAT(s,i) do {\ 44632cd1d96SJun-ichiro itojun Hagino switch(i) { /* XXX hardcoding in each case */\ 44732cd1d96SJun-ichiro itojun Hagino case 1:\ 4487b95a1ebSYaroslav Tykhiy p(s, "\t\t%ju node-local%s\n");\ 44932cd1d96SJun-ichiro itojun Hagino break;\ 45032cd1d96SJun-ichiro itojun Hagino case 2:\ 4517b95a1ebSYaroslav Tykhiy p(s,"\t\t%ju link-local%s\n");\ 45232cd1d96SJun-ichiro itojun Hagino break;\ 45332cd1d96SJun-ichiro itojun Hagino case 5:\ 4547b95a1ebSYaroslav Tykhiy p(s,"\t\t%ju site-local%s\n");\ 45532cd1d96SJun-ichiro itojun Hagino break;\ 45632cd1d96SJun-ichiro itojun Hagino case 14:\ 4577b95a1ebSYaroslav Tykhiy p(s,"\t\t%ju global%s\n");\ 45832cd1d96SJun-ichiro itojun Hagino break;\ 45932cd1d96SJun-ichiro itojun Hagino default:\ 4607b95a1ebSYaroslav Tykhiy printf("\t\t%ju addresses scope=%x\n",\ 4617b95a1ebSYaroslav Tykhiy (uintmax_t)ip6stat.s, i);\ 46232cd1d96SJun-ichiro itojun Hagino }\ 46332cd1d96SJun-ichiro itojun Hagino } while (0); 46432cd1d96SJun-ichiro itojun Hagino 46532cd1d96SJun-ichiro itojun Hagino p(ip6s_sources_none, 4667b95a1ebSYaroslav Tykhiy "\t%ju failure%s of source address selection\n"); 46732cd1d96SJun-ichiro itojun Hagino for (first = 1, i = 0; i < 16; i++) { 46832cd1d96SJun-ichiro itojun Hagino if (ip6stat.ip6s_sources_sameif[i]) { 46932cd1d96SJun-ichiro itojun Hagino if (first) { 47032cd1d96SJun-ichiro itojun Hagino printf("\tsource addresses on an outgoing I/F\n"); 47132cd1d96SJun-ichiro itojun Hagino first = 0; 47232cd1d96SJun-ichiro itojun Hagino } 47332cd1d96SJun-ichiro itojun Hagino PRINT_SCOPESTAT(ip6s_sources_sameif[i], i); 47432cd1d96SJun-ichiro itojun Hagino } 47532cd1d96SJun-ichiro itojun Hagino } 47632cd1d96SJun-ichiro itojun Hagino for (first = 1, i = 0; i < 16; i++) { 47732cd1d96SJun-ichiro itojun Hagino if (ip6stat.ip6s_sources_otherif[i]) { 47832cd1d96SJun-ichiro itojun Hagino if (first) { 47932cd1d96SJun-ichiro itojun Hagino printf("\tsource addresses on a non-outgoing I/F\n"); 48032cd1d96SJun-ichiro itojun Hagino first = 0; 48132cd1d96SJun-ichiro itojun Hagino } 48232cd1d96SJun-ichiro itojun Hagino PRINT_SCOPESTAT(ip6s_sources_otherif[i], i); 48332cd1d96SJun-ichiro itojun Hagino } 48432cd1d96SJun-ichiro itojun Hagino } 48532cd1d96SJun-ichiro itojun Hagino for (first = 1, i = 0; i < 16; i++) { 48632cd1d96SJun-ichiro itojun Hagino if (ip6stat.ip6s_sources_samescope[i]) { 48732cd1d96SJun-ichiro itojun Hagino if (first) { 48832cd1d96SJun-ichiro itojun Hagino printf("\tsource addresses of same scope\n"); 48932cd1d96SJun-ichiro itojun Hagino first = 0; 49032cd1d96SJun-ichiro itojun Hagino } 49132cd1d96SJun-ichiro itojun Hagino PRINT_SCOPESTAT(ip6s_sources_samescope[i], i); 49232cd1d96SJun-ichiro itojun Hagino } 49332cd1d96SJun-ichiro itojun Hagino } 49432cd1d96SJun-ichiro itojun Hagino for (first = 1, i = 0; i < 16; i++) { 49532cd1d96SJun-ichiro itojun Hagino if (ip6stat.ip6s_sources_otherscope[i]) { 49632cd1d96SJun-ichiro itojun Hagino if (first) { 49732cd1d96SJun-ichiro itojun Hagino printf("\tsource addresses of a different scope\n"); 49832cd1d96SJun-ichiro itojun Hagino first = 0; 49932cd1d96SJun-ichiro itojun Hagino } 50032cd1d96SJun-ichiro itojun Hagino PRINT_SCOPESTAT(ip6s_sources_otherscope[i], i); 50132cd1d96SJun-ichiro itojun Hagino } 50232cd1d96SJun-ichiro itojun Hagino } 50332cd1d96SJun-ichiro itojun Hagino for (first = 1, i = 0; i < 16; i++) { 50432cd1d96SJun-ichiro itojun Hagino if (ip6stat.ip6s_sources_deprecated[i]) { 50532cd1d96SJun-ichiro itojun Hagino if (first) { 50632cd1d96SJun-ichiro itojun Hagino printf("\tdeprecated source addresses\n"); 50732cd1d96SJun-ichiro itojun Hagino first = 0; 50832cd1d96SJun-ichiro itojun Hagino } 50932cd1d96SJun-ichiro itojun Hagino PRINT_SCOPESTAT(ip6s_sources_deprecated[i], i); 51032cd1d96SJun-ichiro itojun Hagino } 51132cd1d96SJun-ichiro itojun Hagino } 51232cd1d96SJun-ichiro itojun Hagino 5134ef2dc8bSHajimu UMEMOTO printf("\tSource addresses selection rule applied:\n"); 5144ef2dc8bSHajimu UMEMOTO for (i = 0; i < 16; i++) { 5154ef2dc8bSHajimu UMEMOTO if (ip6stat.ip6s_sources_rule[i]) 5167b95a1ebSYaroslav Tykhiy printf("\t\t%ju %s\n", 5177b95a1ebSYaroslav Tykhiy (uintmax_t)ip6stat.ip6s_sources_rule[i], 5184ef2dc8bSHajimu UMEMOTO srcrule_str[i]); 5194ef2dc8bSHajimu UMEMOTO } 520cfa1ca9dSYoshinobu Inoue #undef p 52132cd1d96SJun-ichiro itojun Hagino #undef p1a 522cfa1ca9dSYoshinobu Inoue } 523cfa1ca9dSYoshinobu Inoue 524cfa1ca9dSYoshinobu Inoue /* 525cfa1ca9dSYoshinobu Inoue * Dump IPv6 per-interface statistics based on RFC 2465. 526cfa1ca9dSYoshinobu Inoue */ 527cfa1ca9dSYoshinobu Inoue void 5285e051718SAssar Westerlund ip6_ifstats(char *ifname) 529cfa1ca9dSYoshinobu Inoue { 530cfa1ca9dSYoshinobu Inoue struct in6_ifreq ifr; 531cfa1ca9dSYoshinobu Inoue int s; 532cfa1ca9dSYoshinobu Inoue #define p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \ 5337b95a1ebSYaroslav Tykhiy printf(m, (uintmax_t)ifr.ifr_ifru.ifru_stat.f, plural(ifr.ifr_ifru.ifru_stat.f)) 534cfa1ca9dSYoshinobu Inoue #define p_5(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \ 5357b95a1ebSYaroslav Tykhiy printf(m, (uintmax_t)ip6stat.f) 536cfa1ca9dSYoshinobu Inoue 537cfa1ca9dSYoshinobu Inoue if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { 538cfa1ca9dSYoshinobu Inoue perror("Warning: socket(AF_INET6)"); 539cfa1ca9dSYoshinobu Inoue return; 540cfa1ca9dSYoshinobu Inoue } 541cfa1ca9dSYoshinobu Inoue 542cfa1ca9dSYoshinobu Inoue strcpy(ifr.ifr_name, ifname); 543cfa1ca9dSYoshinobu Inoue printf("ip6 on %s:\n", ifr.ifr_name); 544cfa1ca9dSYoshinobu Inoue 545cfa1ca9dSYoshinobu Inoue if (ioctl(s, SIOCGIFSTAT_IN6, (char *)&ifr) < 0) { 546cfa1ca9dSYoshinobu Inoue perror("Warning: ioctl(SIOCGIFSTAT_IN6)"); 547cfa1ca9dSYoshinobu Inoue goto end; 548cfa1ca9dSYoshinobu Inoue } 549cfa1ca9dSYoshinobu Inoue 5507b95a1ebSYaroslav Tykhiy p(ifs6_in_receive, "\t%ju total input datagram%s\n"); 5517b95a1ebSYaroslav Tykhiy p(ifs6_in_hdrerr, "\t%ju datagram%s with invalid header received\n"); 5527b95a1ebSYaroslav Tykhiy p(ifs6_in_toobig, "\t%ju datagram%s exceeded MTU received\n"); 5537b95a1ebSYaroslav Tykhiy p(ifs6_in_noroute, "\t%ju datagram%s with no route received\n"); 5547b95a1ebSYaroslav Tykhiy p(ifs6_in_addrerr, "\t%ju datagram%s with invalid dst received\n"); 5557b95a1ebSYaroslav Tykhiy p(ifs6_in_protounknown, "\t%ju datagram%s with unknown proto received\n"); 5567b95a1ebSYaroslav Tykhiy p(ifs6_in_truncated, "\t%ju truncated datagram%s received\n"); 5577b95a1ebSYaroslav Tykhiy p(ifs6_in_discard, "\t%ju input datagram%s discarded\n"); 558cfa1ca9dSYoshinobu Inoue p(ifs6_in_deliver, 5597b95a1ebSYaroslav Tykhiy "\t%ju datagram%s delivered to an upper layer protocol\n"); 5607b95a1ebSYaroslav Tykhiy p(ifs6_out_forward, "\t%ju datagram%s forwarded to this interface\n"); 561cfa1ca9dSYoshinobu Inoue p(ifs6_out_request, 5627b95a1ebSYaroslav Tykhiy "\t%ju datagram%s sent from an upper layer protocol\n"); 5637b95a1ebSYaroslav Tykhiy p(ifs6_out_discard, "\t%ju total discarded output datagram%s\n"); 5647b95a1ebSYaroslav Tykhiy p(ifs6_out_fragok, "\t%ju output datagram%s fragmented\n"); 5657b95a1ebSYaroslav Tykhiy p(ifs6_out_fragfail, "\t%ju output datagram%s failed on fragment\n"); 5667b95a1ebSYaroslav Tykhiy p(ifs6_out_fragcreat, "\t%ju output datagram%s succeeded on fragment\n"); 5677b95a1ebSYaroslav Tykhiy p(ifs6_reass_reqd, "\t%ju incoming datagram%s fragmented\n"); 5687b95a1ebSYaroslav Tykhiy p(ifs6_reass_ok, "\t%ju datagram%s reassembled\n"); 5697b95a1ebSYaroslav Tykhiy p(ifs6_reass_fail, "\t%ju datagram%s failed on reassembly\n"); 5707b95a1ebSYaroslav Tykhiy p(ifs6_in_mcast, "\t%ju multicast datagram%s received\n"); 5717b95a1ebSYaroslav Tykhiy p(ifs6_out_mcast, "\t%ju multicast datagram%s sent\n"); 572cfa1ca9dSYoshinobu Inoue 573cfa1ca9dSYoshinobu Inoue end: 574cfa1ca9dSYoshinobu Inoue close(s); 575cfa1ca9dSYoshinobu Inoue 576cfa1ca9dSYoshinobu Inoue #undef p 577cfa1ca9dSYoshinobu Inoue #undef p_5 578cfa1ca9dSYoshinobu Inoue } 579cfa1ca9dSYoshinobu Inoue 580a01e3379SDavid Malone static const char *icmp6names[] = { 581cfa1ca9dSYoshinobu Inoue "#0", 582cfa1ca9dSYoshinobu Inoue "unreach", 583cfa1ca9dSYoshinobu Inoue "packet too big", 584cfa1ca9dSYoshinobu Inoue "time exceed", 585cfa1ca9dSYoshinobu Inoue "parameter problem", 586cfa1ca9dSYoshinobu Inoue "#5", 587cfa1ca9dSYoshinobu Inoue "#6", 588cfa1ca9dSYoshinobu Inoue "#7", 589cfa1ca9dSYoshinobu Inoue "#8", 590cfa1ca9dSYoshinobu Inoue "#9", 591cfa1ca9dSYoshinobu Inoue "#10", 592cfa1ca9dSYoshinobu Inoue "#11", 593cfa1ca9dSYoshinobu Inoue "#12", 594cfa1ca9dSYoshinobu Inoue "#13", 595cfa1ca9dSYoshinobu Inoue "#14", 596cfa1ca9dSYoshinobu Inoue "#15", 597cfa1ca9dSYoshinobu Inoue "#16", 598cfa1ca9dSYoshinobu Inoue "#17", 599cfa1ca9dSYoshinobu Inoue "#18", 600cfa1ca9dSYoshinobu Inoue "#19", 601cfa1ca9dSYoshinobu Inoue "#20", 602cfa1ca9dSYoshinobu Inoue "#21", 603cfa1ca9dSYoshinobu Inoue "#22", 604cfa1ca9dSYoshinobu Inoue "#23", 605cfa1ca9dSYoshinobu Inoue "#24", 606cfa1ca9dSYoshinobu Inoue "#25", 607cfa1ca9dSYoshinobu Inoue "#26", 608cfa1ca9dSYoshinobu Inoue "#27", 609cfa1ca9dSYoshinobu Inoue "#28", 610cfa1ca9dSYoshinobu Inoue "#29", 611cfa1ca9dSYoshinobu Inoue "#30", 612cfa1ca9dSYoshinobu Inoue "#31", 613cfa1ca9dSYoshinobu Inoue "#32", 614cfa1ca9dSYoshinobu Inoue "#33", 615cfa1ca9dSYoshinobu Inoue "#34", 616cfa1ca9dSYoshinobu Inoue "#35", 617cfa1ca9dSYoshinobu Inoue "#36", 618cfa1ca9dSYoshinobu Inoue "#37", 619cfa1ca9dSYoshinobu Inoue "#38", 620cfa1ca9dSYoshinobu Inoue "#39", 621cfa1ca9dSYoshinobu Inoue "#40", 622cfa1ca9dSYoshinobu Inoue "#41", 623cfa1ca9dSYoshinobu Inoue "#42", 624cfa1ca9dSYoshinobu Inoue "#43", 625cfa1ca9dSYoshinobu Inoue "#44", 626cfa1ca9dSYoshinobu Inoue "#45", 627cfa1ca9dSYoshinobu Inoue "#46", 628cfa1ca9dSYoshinobu Inoue "#47", 629cfa1ca9dSYoshinobu Inoue "#48", 630cfa1ca9dSYoshinobu Inoue "#49", 631cfa1ca9dSYoshinobu Inoue "#50", 632cfa1ca9dSYoshinobu Inoue "#51", 633cfa1ca9dSYoshinobu Inoue "#52", 634cfa1ca9dSYoshinobu Inoue "#53", 635cfa1ca9dSYoshinobu Inoue "#54", 636cfa1ca9dSYoshinobu Inoue "#55", 637cfa1ca9dSYoshinobu Inoue "#56", 638cfa1ca9dSYoshinobu Inoue "#57", 639cfa1ca9dSYoshinobu Inoue "#58", 640cfa1ca9dSYoshinobu Inoue "#59", 641cfa1ca9dSYoshinobu Inoue "#60", 642cfa1ca9dSYoshinobu Inoue "#61", 643cfa1ca9dSYoshinobu Inoue "#62", 644cfa1ca9dSYoshinobu Inoue "#63", 645cfa1ca9dSYoshinobu Inoue "#64", 646cfa1ca9dSYoshinobu Inoue "#65", 647cfa1ca9dSYoshinobu Inoue "#66", 648cfa1ca9dSYoshinobu Inoue "#67", 649cfa1ca9dSYoshinobu Inoue "#68", 650cfa1ca9dSYoshinobu Inoue "#69", 651cfa1ca9dSYoshinobu Inoue "#70", 652cfa1ca9dSYoshinobu Inoue "#71", 653cfa1ca9dSYoshinobu Inoue "#72", 654cfa1ca9dSYoshinobu Inoue "#73", 655cfa1ca9dSYoshinobu Inoue "#74", 656cfa1ca9dSYoshinobu Inoue "#75", 657cfa1ca9dSYoshinobu Inoue "#76", 658cfa1ca9dSYoshinobu Inoue "#77", 659cfa1ca9dSYoshinobu Inoue "#78", 660cfa1ca9dSYoshinobu Inoue "#79", 661cfa1ca9dSYoshinobu Inoue "#80", 662cfa1ca9dSYoshinobu Inoue "#81", 663cfa1ca9dSYoshinobu Inoue "#82", 664cfa1ca9dSYoshinobu Inoue "#83", 665cfa1ca9dSYoshinobu Inoue "#84", 666cfa1ca9dSYoshinobu Inoue "#85", 667cfa1ca9dSYoshinobu Inoue "#86", 668cfa1ca9dSYoshinobu Inoue "#87", 669cfa1ca9dSYoshinobu Inoue "#88", 670cfa1ca9dSYoshinobu Inoue "#89", 671cfa1ca9dSYoshinobu Inoue "#80", 672cfa1ca9dSYoshinobu Inoue "#91", 673cfa1ca9dSYoshinobu Inoue "#92", 674cfa1ca9dSYoshinobu Inoue "#93", 675cfa1ca9dSYoshinobu Inoue "#94", 676cfa1ca9dSYoshinobu Inoue "#95", 677cfa1ca9dSYoshinobu Inoue "#96", 678cfa1ca9dSYoshinobu Inoue "#97", 679cfa1ca9dSYoshinobu Inoue "#98", 680cfa1ca9dSYoshinobu Inoue "#99", 681cfa1ca9dSYoshinobu Inoue "#100", 682cfa1ca9dSYoshinobu Inoue "#101", 683cfa1ca9dSYoshinobu Inoue "#102", 684cfa1ca9dSYoshinobu Inoue "#103", 685cfa1ca9dSYoshinobu Inoue "#104", 686cfa1ca9dSYoshinobu Inoue "#105", 687cfa1ca9dSYoshinobu Inoue "#106", 688cfa1ca9dSYoshinobu Inoue "#107", 689cfa1ca9dSYoshinobu Inoue "#108", 690cfa1ca9dSYoshinobu Inoue "#109", 691cfa1ca9dSYoshinobu Inoue "#110", 692cfa1ca9dSYoshinobu Inoue "#111", 693cfa1ca9dSYoshinobu Inoue "#112", 694cfa1ca9dSYoshinobu Inoue "#113", 695cfa1ca9dSYoshinobu Inoue "#114", 696cfa1ca9dSYoshinobu Inoue "#115", 697cfa1ca9dSYoshinobu Inoue "#116", 698cfa1ca9dSYoshinobu Inoue "#117", 699cfa1ca9dSYoshinobu Inoue "#118", 700cfa1ca9dSYoshinobu Inoue "#119", 701cfa1ca9dSYoshinobu Inoue "#120", 702cfa1ca9dSYoshinobu Inoue "#121", 703cfa1ca9dSYoshinobu Inoue "#122", 704cfa1ca9dSYoshinobu Inoue "#123", 705cfa1ca9dSYoshinobu Inoue "#124", 706cfa1ca9dSYoshinobu Inoue "#125", 707cfa1ca9dSYoshinobu Inoue "#126", 708cfa1ca9dSYoshinobu Inoue "#127", 709cfa1ca9dSYoshinobu Inoue "echo", 710cfa1ca9dSYoshinobu Inoue "echo reply", 711cfa1ca9dSYoshinobu Inoue "multicast listener query", 7127d9d64baSBruce M Simpson "MLDv1 listener report", 7137d9d64baSBruce M Simpson "MLDv1 listener done", 714cfa1ca9dSYoshinobu Inoue "router solicitation", 7156ab55b23SDima Dorfman "router advertisement", 716cfa1ca9dSYoshinobu Inoue "neighbor solicitation", 7176ab55b23SDima Dorfman "neighbor advertisement", 718cfa1ca9dSYoshinobu Inoue "redirect", 719cfa1ca9dSYoshinobu Inoue "router renumbering", 720cfa1ca9dSYoshinobu Inoue "node information request", 721cfa1ca9dSYoshinobu Inoue "node information reply", 722fd555639SMunechika SUMIKAWA "inverse neighbor solicitation", 723fd555639SMunechika SUMIKAWA "inverse neighbor advertisement", 7247d9d64baSBruce M Simpson "MLDv2 listener report", 725cfa1ca9dSYoshinobu Inoue "#144", 726cfa1ca9dSYoshinobu Inoue "#145", 727cfa1ca9dSYoshinobu Inoue "#146", 728cfa1ca9dSYoshinobu Inoue "#147", 729cfa1ca9dSYoshinobu Inoue "#148", 730cfa1ca9dSYoshinobu Inoue "#149", 731cfa1ca9dSYoshinobu Inoue "#150", 732cfa1ca9dSYoshinobu Inoue "#151", 733cfa1ca9dSYoshinobu Inoue "#152", 734cfa1ca9dSYoshinobu Inoue "#153", 735cfa1ca9dSYoshinobu Inoue "#154", 736cfa1ca9dSYoshinobu Inoue "#155", 737cfa1ca9dSYoshinobu Inoue "#156", 738cfa1ca9dSYoshinobu Inoue "#157", 739cfa1ca9dSYoshinobu Inoue "#158", 740cfa1ca9dSYoshinobu Inoue "#159", 741cfa1ca9dSYoshinobu Inoue "#160", 742cfa1ca9dSYoshinobu Inoue "#161", 743cfa1ca9dSYoshinobu Inoue "#162", 744cfa1ca9dSYoshinobu Inoue "#163", 745cfa1ca9dSYoshinobu Inoue "#164", 746cfa1ca9dSYoshinobu Inoue "#165", 747cfa1ca9dSYoshinobu Inoue "#166", 748cfa1ca9dSYoshinobu Inoue "#167", 749cfa1ca9dSYoshinobu Inoue "#168", 750cfa1ca9dSYoshinobu Inoue "#169", 751cfa1ca9dSYoshinobu Inoue "#170", 752cfa1ca9dSYoshinobu Inoue "#171", 753cfa1ca9dSYoshinobu Inoue "#172", 754cfa1ca9dSYoshinobu Inoue "#173", 755cfa1ca9dSYoshinobu Inoue "#174", 756cfa1ca9dSYoshinobu Inoue "#175", 757cfa1ca9dSYoshinobu Inoue "#176", 758cfa1ca9dSYoshinobu Inoue "#177", 759cfa1ca9dSYoshinobu Inoue "#178", 760cfa1ca9dSYoshinobu Inoue "#179", 761cfa1ca9dSYoshinobu Inoue "#180", 762cfa1ca9dSYoshinobu Inoue "#181", 763cfa1ca9dSYoshinobu Inoue "#182", 764cfa1ca9dSYoshinobu Inoue "#183", 765cfa1ca9dSYoshinobu Inoue "#184", 766cfa1ca9dSYoshinobu Inoue "#185", 767cfa1ca9dSYoshinobu Inoue "#186", 768cfa1ca9dSYoshinobu Inoue "#187", 769cfa1ca9dSYoshinobu Inoue "#188", 770cfa1ca9dSYoshinobu Inoue "#189", 771cfa1ca9dSYoshinobu Inoue "#180", 772cfa1ca9dSYoshinobu Inoue "#191", 773cfa1ca9dSYoshinobu Inoue "#192", 774cfa1ca9dSYoshinobu Inoue "#193", 775cfa1ca9dSYoshinobu Inoue "#194", 776cfa1ca9dSYoshinobu Inoue "#195", 777cfa1ca9dSYoshinobu Inoue "#196", 778cfa1ca9dSYoshinobu Inoue "#197", 779cfa1ca9dSYoshinobu Inoue "#198", 780cfa1ca9dSYoshinobu Inoue "#199", 781cfa1ca9dSYoshinobu Inoue "#200", 782cfa1ca9dSYoshinobu Inoue "#201", 783cfa1ca9dSYoshinobu Inoue "#202", 784cfa1ca9dSYoshinobu Inoue "#203", 785cfa1ca9dSYoshinobu Inoue "#204", 786cfa1ca9dSYoshinobu Inoue "#205", 787cfa1ca9dSYoshinobu Inoue "#206", 788cfa1ca9dSYoshinobu Inoue "#207", 789cfa1ca9dSYoshinobu Inoue "#208", 790cfa1ca9dSYoshinobu Inoue "#209", 791cfa1ca9dSYoshinobu Inoue "#210", 792cfa1ca9dSYoshinobu Inoue "#211", 793cfa1ca9dSYoshinobu Inoue "#212", 794cfa1ca9dSYoshinobu Inoue "#213", 795cfa1ca9dSYoshinobu Inoue "#214", 796cfa1ca9dSYoshinobu Inoue "#215", 797cfa1ca9dSYoshinobu Inoue "#216", 798cfa1ca9dSYoshinobu Inoue "#217", 799cfa1ca9dSYoshinobu Inoue "#218", 800cfa1ca9dSYoshinobu Inoue "#219", 801cfa1ca9dSYoshinobu Inoue "#220", 802cfa1ca9dSYoshinobu Inoue "#221", 803cfa1ca9dSYoshinobu Inoue "#222", 804cfa1ca9dSYoshinobu Inoue "#223", 805cfa1ca9dSYoshinobu Inoue "#224", 806cfa1ca9dSYoshinobu Inoue "#225", 807cfa1ca9dSYoshinobu Inoue "#226", 808cfa1ca9dSYoshinobu Inoue "#227", 809cfa1ca9dSYoshinobu Inoue "#228", 810cfa1ca9dSYoshinobu Inoue "#229", 811cfa1ca9dSYoshinobu Inoue "#230", 812cfa1ca9dSYoshinobu Inoue "#231", 813cfa1ca9dSYoshinobu Inoue "#232", 814cfa1ca9dSYoshinobu Inoue "#233", 815cfa1ca9dSYoshinobu Inoue "#234", 816cfa1ca9dSYoshinobu Inoue "#235", 817cfa1ca9dSYoshinobu Inoue "#236", 818cfa1ca9dSYoshinobu Inoue "#237", 819cfa1ca9dSYoshinobu Inoue "#238", 820cfa1ca9dSYoshinobu Inoue "#239", 821cfa1ca9dSYoshinobu Inoue "#240", 822cfa1ca9dSYoshinobu Inoue "#241", 823cfa1ca9dSYoshinobu Inoue "#242", 824cfa1ca9dSYoshinobu Inoue "#243", 825cfa1ca9dSYoshinobu Inoue "#244", 826cfa1ca9dSYoshinobu Inoue "#245", 827cfa1ca9dSYoshinobu Inoue "#246", 828cfa1ca9dSYoshinobu Inoue "#247", 829cfa1ca9dSYoshinobu Inoue "#248", 830cfa1ca9dSYoshinobu Inoue "#249", 831cfa1ca9dSYoshinobu Inoue "#250", 832cfa1ca9dSYoshinobu Inoue "#251", 833cfa1ca9dSYoshinobu Inoue "#252", 834cfa1ca9dSYoshinobu Inoue "#253", 835cfa1ca9dSYoshinobu Inoue "#254", 836cfa1ca9dSYoshinobu Inoue "#255", 837cfa1ca9dSYoshinobu Inoue }; 838cfa1ca9dSYoshinobu Inoue 839cfa1ca9dSYoshinobu Inoue /* 840cfa1ca9dSYoshinobu Inoue * Dump ICMP6 statistics. 841cfa1ca9dSYoshinobu Inoue */ 842cfa1ca9dSYoshinobu Inoue void 843feda1a43SJohn Baldwin icmp6_stats(u_long off, const char *name, int af1 __unused, int proto __unused) 844cfa1ca9dSYoshinobu Inoue { 845*d96ea877SMaxim Konovalov struct icmp6stat icmp6stat, zerostat; 846241667c4SMark Murray int i, first; 847785d213dSHajimu UMEMOTO size_t len; 848cfa1ca9dSYoshinobu Inoue 849785d213dSHajimu UMEMOTO len = sizeof icmp6stat; 850feda1a43SJohn Baldwin if (live) { 851785d213dSHajimu UMEMOTO memset(&icmp6stat, 0, len); 852*d96ea877SMaxim Konovalov if (zflag) 853*d96ea877SMaxim Konovalov memset(&zerostat, 0, len); 854feda1a43SJohn Baldwin if (sysctlbyname("net.inet6.icmp6.stats", &icmp6stat, &len, 855*d96ea877SMaxim Konovalov zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { 856feda1a43SJohn Baldwin if (errno != ENOENT) 857feda1a43SJohn Baldwin warn("sysctl: net.inet6.icmp6.stats"); 858cfa1ca9dSYoshinobu Inoue return; 859feda1a43SJohn Baldwin } 860feda1a43SJohn Baldwin } else 861feda1a43SJohn Baldwin kread(off, &icmp6stat, len); 862feda1a43SJohn Baldwin 863cfa1ca9dSYoshinobu Inoue printf("%s:\n", name); 864cfa1ca9dSYoshinobu Inoue 865cfa1ca9dSYoshinobu Inoue #define p(f, m) if (icmp6stat.f || sflag <= 1) \ 8667b95a1ebSYaroslav Tykhiy printf(m, (uintmax_t)icmp6stat.f, plural(icmp6stat.f)) 8673ed817f1SMaxim Konovalov #define p_5(f, m) if (icmp6stat.f || sflag <= 1) \ 8683ed817f1SMaxim Konovalov printf(m, (uintmax_t)icmp6stat.f) 869cfa1ca9dSYoshinobu Inoue 8707b95a1ebSYaroslav Tykhiy p(icp6s_error, "\t%ju call%s to icmp6_error\n"); 871cfa1ca9dSYoshinobu Inoue p(icp6s_canterror, 8727b95a1ebSYaroslav Tykhiy "\t%ju error%s not generated in response to an icmp6 message\n"); 873cfa1ca9dSYoshinobu Inoue p(icp6s_toofreq, 8747b95a1ebSYaroslav Tykhiy "\t%ju error%s not generated because of rate limitation\n"); 875241667c4SMark Murray #define NELEM (int)(sizeof(icmp6stat.icp6s_outhist)/sizeof(icmp6stat.icp6s_outhist[0])) 876fd555639SMunechika SUMIKAWA for (first = 1, i = 0; i < NELEM; i++) 877cfa1ca9dSYoshinobu Inoue if (icmp6stat.icp6s_outhist[i] != 0) { 878cfa1ca9dSYoshinobu Inoue if (first) { 879cfa1ca9dSYoshinobu Inoue printf("\tOutput histogram:\n"); 880cfa1ca9dSYoshinobu Inoue first = 0; 881cfa1ca9dSYoshinobu Inoue } 8827b95a1ebSYaroslav Tykhiy printf("\t\t%s: %ju\n", icmp6names[i], 8837b95a1ebSYaroslav Tykhiy (uintmax_t)icmp6stat.icp6s_outhist[i]); 884cfa1ca9dSYoshinobu Inoue } 885fd555639SMunechika SUMIKAWA #undef NELEM 8867b95a1ebSYaroslav Tykhiy p(icp6s_badcode, "\t%ju message%s with bad code fields\n"); 8877b95a1ebSYaroslav Tykhiy p(icp6s_tooshort, "\t%ju message%s < minimum length\n"); 8887b95a1ebSYaroslav Tykhiy p(icp6s_checksum, "\t%ju bad checksum%s\n"); 8897b95a1ebSYaroslav Tykhiy p(icp6s_badlen, "\t%ju message%s with bad length\n"); 890241667c4SMark Murray #define NELEM (int)(sizeof(icmp6stat.icp6s_inhist)/sizeof(icmp6stat.icp6s_inhist[0])) 891fd555639SMunechika SUMIKAWA for (first = 1, i = 0; i < NELEM; i++) 892cfa1ca9dSYoshinobu Inoue if (icmp6stat.icp6s_inhist[i] != 0) { 893cfa1ca9dSYoshinobu Inoue if (first) { 894cfa1ca9dSYoshinobu Inoue printf("\tInput histogram:\n"); 895cfa1ca9dSYoshinobu Inoue first = 0; 896cfa1ca9dSYoshinobu Inoue } 8977b95a1ebSYaroslav Tykhiy printf("\t\t%s: %ju\n", icmp6names[i], 8987b95a1ebSYaroslav Tykhiy (uintmax_t)icmp6stat.icp6s_inhist[i]); 899cfa1ca9dSYoshinobu Inoue } 900fd555639SMunechika SUMIKAWA #undef NELEM 9016ab55b23SDima Dorfman printf("\tHistogram of error messages to be generated:\n"); 9027b95a1ebSYaroslav Tykhiy p_5(icp6s_odst_unreach_noroute, "\t\t%ju no route\n"); 9037b95a1ebSYaroslav Tykhiy p_5(icp6s_odst_unreach_admin, "\t\t%ju administratively prohibited\n"); 9047b95a1ebSYaroslav Tykhiy p_5(icp6s_odst_unreach_beyondscope, "\t\t%ju beyond scope\n"); 9057b95a1ebSYaroslav Tykhiy p_5(icp6s_odst_unreach_addr, "\t\t%ju address unreachable\n"); 9067b95a1ebSYaroslav Tykhiy p_5(icp6s_odst_unreach_noport, "\t\t%ju port unreachable\n"); 9077b95a1ebSYaroslav Tykhiy p_5(icp6s_opacket_too_big, "\t\t%ju packet too big\n"); 9087b95a1ebSYaroslav Tykhiy p_5(icp6s_otime_exceed_transit, "\t\t%ju time exceed transit\n"); 9097b95a1ebSYaroslav Tykhiy p_5(icp6s_otime_exceed_reassembly, "\t\t%ju time exceed reassembly\n"); 9107b95a1ebSYaroslav Tykhiy p_5(icp6s_oparamprob_header, "\t\t%ju erroneous header field\n"); 9117b95a1ebSYaroslav Tykhiy p_5(icp6s_oparamprob_nextheader, "\t\t%ju unrecognized next header\n"); 9127b95a1ebSYaroslav Tykhiy p_5(icp6s_oparamprob_option, "\t\t%ju unrecognized option\n"); 9137b95a1ebSYaroslav Tykhiy p_5(icp6s_oredirect, "\t\t%ju redirect\n"); 9147b95a1ebSYaroslav Tykhiy p_5(icp6s_ounknown, "\t\t%ju unknown\n"); 91532cd1d96SJun-ichiro itojun Hagino 9167b95a1ebSYaroslav Tykhiy p(icp6s_reflect, "\t%ju message response%s generated\n"); 9177b95a1ebSYaroslav Tykhiy p(icp6s_nd_toomanyopt, "\t%ju message%s with too many ND options\n"); 9187b95a1ebSYaroslav Tykhiy p(icp6s_nd_badopt, "\t%ju message%s with bad ND options\n"); 9197b95a1ebSYaroslav Tykhiy p(icp6s_badns, "\t%ju bad neighbor solicitation message%s\n"); 9207b95a1ebSYaroslav Tykhiy p(icp6s_badna, "\t%ju bad neighbor advertisement message%s\n"); 9217b95a1ebSYaroslav Tykhiy p(icp6s_badrs, "\t%ju bad router solicitation message%s\n"); 9227b95a1ebSYaroslav Tykhiy p(icp6s_badra, "\t%ju bad router advertisement message%s\n"); 9237b95a1ebSYaroslav Tykhiy p(icp6s_badredirect, "\t%ju bad redirect message%s\n"); 9247b95a1ebSYaroslav Tykhiy p(icp6s_pmtuchg, "\t%ju path MTU change%s\n"); 925cfa1ca9dSYoshinobu Inoue #undef p 926cfa1ca9dSYoshinobu Inoue #undef p_5 927cfa1ca9dSYoshinobu Inoue } 928cfa1ca9dSYoshinobu Inoue 929cfa1ca9dSYoshinobu Inoue /* 930cfa1ca9dSYoshinobu Inoue * Dump ICMPv6 per-interface statistics based on RFC 2466. 931cfa1ca9dSYoshinobu Inoue */ 932cfa1ca9dSYoshinobu Inoue void 9335e051718SAssar Westerlund icmp6_ifstats(char *ifname) 934cfa1ca9dSYoshinobu Inoue { 935cfa1ca9dSYoshinobu Inoue struct in6_ifreq ifr; 936cfa1ca9dSYoshinobu Inoue int s; 937cfa1ca9dSYoshinobu Inoue #define p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \ 9387b95a1ebSYaroslav Tykhiy printf(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f, plural(ifr.ifr_ifru.ifru_icmp6stat.f)) 939f99a4046SMike Makonnen #define p2(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \ 9407b95a1ebSYaroslav Tykhiy printf(m, (uintmax_t)ifr.ifr_ifru.ifru_icmp6stat.f, pluralies(ifr.ifr_ifru.ifru_icmp6stat.f)) 941cfa1ca9dSYoshinobu Inoue 942cfa1ca9dSYoshinobu Inoue if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { 943cfa1ca9dSYoshinobu Inoue perror("Warning: socket(AF_INET6)"); 944cfa1ca9dSYoshinobu Inoue return; 945cfa1ca9dSYoshinobu Inoue } 946cfa1ca9dSYoshinobu Inoue 947cfa1ca9dSYoshinobu Inoue strcpy(ifr.ifr_name, ifname); 948cfa1ca9dSYoshinobu Inoue printf("icmp6 on %s:\n", ifr.ifr_name); 949cfa1ca9dSYoshinobu Inoue 950cfa1ca9dSYoshinobu Inoue if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) { 951cfa1ca9dSYoshinobu Inoue perror("Warning: ioctl(SIOCGIFSTAT_ICMP6)"); 952cfa1ca9dSYoshinobu Inoue goto end; 953cfa1ca9dSYoshinobu Inoue } 954cfa1ca9dSYoshinobu Inoue 9557b95a1ebSYaroslav Tykhiy p(ifs6_in_msg, "\t%ju total input message%s\n"); 9567b95a1ebSYaroslav Tykhiy p(ifs6_in_error, "\t%ju total input error message%s\n"); 9577b95a1ebSYaroslav Tykhiy p(ifs6_in_dstunreach, "\t%ju input destination unreachable error%s\n"); 9587b95a1ebSYaroslav Tykhiy p(ifs6_in_adminprohib, "\t%ju input administratively prohibited error%s\n"); 9597b95a1ebSYaroslav Tykhiy p(ifs6_in_timeexceed, "\t%ju input time exceeded error%s\n"); 9607b95a1ebSYaroslav Tykhiy p(ifs6_in_paramprob, "\t%ju input parameter problem error%s\n"); 9617b95a1ebSYaroslav Tykhiy p(ifs6_in_pkttoobig, "\t%ju input packet too big error%s\n"); 9627b95a1ebSYaroslav Tykhiy p(ifs6_in_echo, "\t%ju input echo request%s\n"); 9637b95a1ebSYaroslav Tykhiy p2(ifs6_in_echoreply, "\t%ju input echo repl%s\n"); 9647b95a1ebSYaroslav Tykhiy p(ifs6_in_routersolicit, "\t%ju input router solicitation%s\n"); 9657b95a1ebSYaroslav Tykhiy p(ifs6_in_routeradvert, "\t%ju input router advertisement%s\n"); 9667b95a1ebSYaroslav Tykhiy p(ifs6_in_neighborsolicit, "\t%ju input neighbor solicitation%s\n"); 9677b95a1ebSYaroslav Tykhiy p(ifs6_in_neighboradvert, "\t%ju input neighbor advertisement%s\n"); 9687b95a1ebSYaroslav Tykhiy p(ifs6_in_redirect, "\t%ju input redirect%s\n"); 9697b95a1ebSYaroslav Tykhiy p2(ifs6_in_mldquery, "\t%ju input MLD quer%s\n"); 9707b95a1ebSYaroslav Tykhiy p(ifs6_in_mldreport, "\t%ju input MLD report%s\n"); 9717b95a1ebSYaroslav Tykhiy p(ifs6_in_mlddone, "\t%ju input MLD done%s\n"); 972cfa1ca9dSYoshinobu Inoue 9737b95a1ebSYaroslav Tykhiy p(ifs6_out_msg, "\t%ju total output message%s\n"); 9747b95a1ebSYaroslav Tykhiy p(ifs6_out_error, "\t%ju total output error message%s\n"); 9757b95a1ebSYaroslav Tykhiy p(ifs6_out_dstunreach, "\t%ju output destination unreachable error%s\n"); 9767b95a1ebSYaroslav Tykhiy p(ifs6_out_adminprohib, "\t%ju output administratively prohibited error%s\n"); 9777b95a1ebSYaroslav Tykhiy p(ifs6_out_timeexceed, "\t%ju output time exceeded error%s\n"); 9787b95a1ebSYaroslav Tykhiy p(ifs6_out_paramprob, "\t%ju output parameter problem error%s\n"); 9797b95a1ebSYaroslav Tykhiy p(ifs6_out_pkttoobig, "\t%ju output packet too big error%s\n"); 9807b95a1ebSYaroslav Tykhiy p(ifs6_out_echo, "\t%ju output echo request%s\n"); 9817b95a1ebSYaroslav Tykhiy p2(ifs6_out_echoreply, "\t%ju output echo repl%s\n"); 9827b95a1ebSYaroslav Tykhiy p(ifs6_out_routersolicit, "\t%ju output router solicitation%s\n"); 9837b95a1ebSYaroslav Tykhiy p(ifs6_out_routeradvert, "\t%ju output router advertisement%s\n"); 9847b95a1ebSYaroslav Tykhiy p(ifs6_out_neighborsolicit, "\t%ju output neighbor solicitation%s\n"); 9857b95a1ebSYaroslav Tykhiy p(ifs6_out_neighboradvert, "\t%ju output neighbor advertisement%s\n"); 9867b95a1ebSYaroslav Tykhiy p(ifs6_out_redirect, "\t%ju output redirect%s\n"); 9877b95a1ebSYaroslav Tykhiy p2(ifs6_out_mldquery, "\t%ju output MLD quer%s\n"); 9887b95a1ebSYaroslav Tykhiy p(ifs6_out_mldreport, "\t%ju output MLD report%s\n"); 9897b95a1ebSYaroslav Tykhiy p(ifs6_out_mlddone, "\t%ju output MLD done%s\n"); 990cfa1ca9dSYoshinobu Inoue 991cfa1ca9dSYoshinobu Inoue end: 992cfa1ca9dSYoshinobu Inoue close(s); 993cfa1ca9dSYoshinobu Inoue #undef p 994cfa1ca9dSYoshinobu Inoue } 995cfa1ca9dSYoshinobu Inoue 996cfa1ca9dSYoshinobu Inoue /* 997cfa1ca9dSYoshinobu Inoue * Dump PIM statistics structure. 998cfa1ca9dSYoshinobu Inoue */ 999cfa1ca9dSYoshinobu Inoue void 1000feda1a43SJohn Baldwin pim6_stats(u_long off, const char *name, int af1 __unused, int proto __unused) 1001cfa1ca9dSYoshinobu Inoue { 1002c15ddad9SBruce M Simpson struct pim6stat pim6stat, zerostat; 1003c15ddad9SBruce M Simpson size_t len = sizeof pim6stat; 1004cfa1ca9dSYoshinobu Inoue 1005feda1a43SJohn Baldwin if (live) { 1006c15ddad9SBruce M Simpson if (zflag) 1007c15ddad9SBruce M Simpson memset(&zerostat, 0, len); 1008c15ddad9SBruce M Simpson if (sysctlbyname("net.inet6.pim.stats", &pim6stat, &len, 1009c15ddad9SBruce M Simpson zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { 1010c15ddad9SBruce M Simpson if (errno != ENOENT) 1011c15ddad9SBruce M Simpson warn("sysctl: net.inet6.pim.stats"); 1012cfa1ca9dSYoshinobu Inoue return; 1013c15ddad9SBruce M Simpson } 1014feda1a43SJohn Baldwin } else { 1015feda1a43SJohn Baldwin if (off == 0) 1016feda1a43SJohn Baldwin return; 1017feda1a43SJohn Baldwin kread(off, &pim6stat, len); 1018feda1a43SJohn Baldwin } 1019feda1a43SJohn Baldwin 1020cfa1ca9dSYoshinobu Inoue printf("%s:\n", name); 1021cfa1ca9dSYoshinobu Inoue 1022cfa1ca9dSYoshinobu Inoue #define p(f, m) if (pim6stat.f || sflag <= 1) \ 10237b95a1ebSYaroslav Tykhiy printf(m, (uintmax_t)pim6stat.f, plural(pim6stat.f)) 10247b95a1ebSYaroslav Tykhiy p(pim6s_rcv_total, "\t%ju message%s received\n"); 10257b95a1ebSYaroslav Tykhiy p(pim6s_rcv_tooshort, "\t%ju message%s received with too few bytes\n"); 10267b95a1ebSYaroslav Tykhiy p(pim6s_rcv_badsum, "\t%ju message%s received with bad checksum\n"); 10277b95a1ebSYaroslav Tykhiy p(pim6s_rcv_badversion, "\t%ju message%s received with bad version\n"); 10287b95a1ebSYaroslav Tykhiy p(pim6s_rcv_registers, "\t%ju register%s received\n"); 10297b95a1ebSYaroslav Tykhiy p(pim6s_rcv_badregisters, "\t%ju bad register%s received\n"); 10307b95a1ebSYaroslav Tykhiy p(pim6s_snd_registers, "\t%ju register%s sent\n"); 1031cfa1ca9dSYoshinobu Inoue #undef p 1032cfa1ca9dSYoshinobu Inoue } 1033cfa1ca9dSYoshinobu Inoue 1034cfa1ca9dSYoshinobu Inoue /* 103533841545SHajimu UMEMOTO * Dump raw ip6 statistics structure. 103633841545SHajimu UMEMOTO */ 103733841545SHajimu UMEMOTO void 1038feda1a43SJohn Baldwin rip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused) 103933841545SHajimu UMEMOTO { 1040*d96ea877SMaxim Konovalov struct rip6stat rip6stat, zerostat; 104133841545SHajimu UMEMOTO u_quad_t delivered; 1042feda1a43SJohn Baldwin size_t len; 104333841545SHajimu UMEMOTO 1044feda1a43SJohn Baldwin len = sizeof(rip6stat); 1045feda1a43SJohn Baldwin if (live) { 1046*d96ea877SMaxim Konovalov if (zflag) 1047*d96ea877SMaxim Konovalov memset(&zerostat, 0, len); 1048feda1a43SJohn Baldwin if (sysctlbyname("net.inet6.ip6.rip6stats", &rip6stat, &len, 1049*d96ea877SMaxim Konovalov zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { 1050109dad81SJulian Elischer if (errno != ENOENT) 1051feda1a43SJohn Baldwin warn("sysctl: net.inet6.ip6.rip6stats"); 105233841545SHajimu UMEMOTO return; 105333841545SHajimu UMEMOTO } 1054feda1a43SJohn Baldwin } else 1055feda1a43SJohn Baldwin kread(off, &rip6stat, len); 105633841545SHajimu UMEMOTO 105733841545SHajimu UMEMOTO printf("%s:\n", name); 105833841545SHajimu UMEMOTO 105933841545SHajimu UMEMOTO #define p(f, m) if (rip6stat.f || sflag <= 1) \ 10607b95a1ebSYaroslav Tykhiy printf(m, (uintmax_t)rip6stat.f, plural(rip6stat.f)) 10617b95a1ebSYaroslav Tykhiy p(rip6s_ipackets, "\t%ju message%s received\n"); 1062c0c66013SMaxim Konovalov p(rip6s_isum, "\t%ju checksum calculation%s on inbound\n"); 10637b95a1ebSYaroslav Tykhiy p(rip6s_badsum, "\t%ju message%s with bad checksum\n"); 10647b95a1ebSYaroslav Tykhiy p(rip6s_nosock, "\t%ju message%s dropped due to no socket\n"); 106533841545SHajimu UMEMOTO p(rip6s_nosockmcast, 10667b95a1ebSYaroslav Tykhiy "\t%ju multicast message%s dropped due to no socket\n"); 106733841545SHajimu UMEMOTO p(rip6s_fullsock, 10687b95a1ebSYaroslav Tykhiy "\t%ju message%s dropped due to full socket buffers\n"); 106933841545SHajimu UMEMOTO delivered = rip6stat.rip6s_ipackets - 107033841545SHajimu UMEMOTO rip6stat.rip6s_badsum - 107133841545SHajimu UMEMOTO rip6stat.rip6s_nosock - 107233841545SHajimu UMEMOTO rip6stat.rip6s_nosockmcast - 107333841545SHajimu UMEMOTO rip6stat.rip6s_fullsock; 107433841545SHajimu UMEMOTO if (delivered || sflag <= 1) 10757b95a1ebSYaroslav Tykhiy printf("\t%ju delivered\n", (uintmax_t)delivered); 10767b95a1ebSYaroslav Tykhiy p(rip6s_opackets, "\t%ju datagram%s output\n"); 107733841545SHajimu UMEMOTO #undef p 107833841545SHajimu UMEMOTO } 107933841545SHajimu UMEMOTO 108033841545SHajimu UMEMOTO /* 1081cfa1ca9dSYoshinobu Inoue * Pretty print an Internet address (net address + port). 108265ea0024SAssar Westerlund * Take numeric_addr and numeric_port into consideration. 1083cfa1ca9dSYoshinobu Inoue */ 1084cfa1ca9dSYoshinobu Inoue #define GETSERVBYPORT6(port, proto, ret)\ 1085cfa1ca9dSYoshinobu Inoue {\ 1086cfa1ca9dSYoshinobu Inoue if (strcmp((proto), "tcp6") == 0)\ 1087cfa1ca9dSYoshinobu Inoue (ret) = getservbyport((int)(port), "tcp");\ 1088cfa1ca9dSYoshinobu Inoue else if (strcmp((proto), "udp6") == 0)\ 1089cfa1ca9dSYoshinobu Inoue (ret) = getservbyport((int)(port), "udp");\ 1090cfa1ca9dSYoshinobu Inoue else\ 1091cfa1ca9dSYoshinobu Inoue (ret) = getservbyport((int)(port), (proto));\ 1092cfa1ca9dSYoshinobu Inoue }; 1093cfa1ca9dSYoshinobu Inoue 1094cfa1ca9dSYoshinobu Inoue void 1095a01e3379SDavid Malone inet6print(struct in6_addr *in6, int port, const char *proto, int numeric) 1096cfa1ca9dSYoshinobu Inoue { 1097cfa1ca9dSYoshinobu Inoue struct servent *sp = 0; 1098cfa1ca9dSYoshinobu Inoue char line[80], *cp; 1099cfa1ca9dSYoshinobu Inoue int width; 1100cfa1ca9dSYoshinobu Inoue 110170057abfSRuslan Ermilov sprintf(line, "%.*s.", Wflag ? 39 : 1102cfa1ca9dSYoshinobu Inoue (Aflag && !numeric) ? 12 : 16, inet6name(in6)); 1103cfa1ca9dSYoshinobu Inoue cp = index(line, '\0'); 1104cfa1ca9dSYoshinobu Inoue if (!numeric && port) 1105cfa1ca9dSYoshinobu Inoue GETSERVBYPORT6(port, proto, sp); 1106cfa1ca9dSYoshinobu Inoue if (sp || port == 0) 1107bd2327cdSHajimu UMEMOTO sprintf(cp, "%.15s", sp ? sp->s_name : "*"); 1108cfa1ca9dSYoshinobu Inoue else 1109cfa1ca9dSYoshinobu Inoue sprintf(cp, "%d", ntohs((u_short)port)); 111070057abfSRuslan Ermilov width = Wflag ? 45 : Aflag ? 18 : 22; 1111cfa1ca9dSYoshinobu Inoue printf("%-*.*s ", width, width, line); 1112cfa1ca9dSYoshinobu Inoue } 1113cfa1ca9dSYoshinobu Inoue 1114cfa1ca9dSYoshinobu Inoue /* 1115cfa1ca9dSYoshinobu Inoue * Construct an Internet address representation. 111665ea0024SAssar Westerlund * If the numeric_addr has been supplied, give 1117cfa1ca9dSYoshinobu Inoue * numeric value, otherwise try for symbolic name. 1118cfa1ca9dSYoshinobu Inoue */ 1119cfa1ca9dSYoshinobu Inoue 1120cfa1ca9dSYoshinobu Inoue char * 11215e051718SAssar Westerlund inet6name(struct in6_addr *in6p) 1122cfa1ca9dSYoshinobu Inoue { 1123a01e3379SDavid Malone char *cp; 1124cfa1ca9dSYoshinobu Inoue static char line[50]; 1125cfa1ca9dSYoshinobu Inoue struct hostent *hp; 1126d121b556SBrian Somers static char domain[MAXHOSTNAMELEN]; 1127cfa1ca9dSYoshinobu Inoue static int first = 1; 1128cfa1ca9dSYoshinobu Inoue 112965ea0024SAssar Westerlund if (first && !numeric_addr) { 1130cfa1ca9dSYoshinobu Inoue first = 0; 1131cfa1ca9dSYoshinobu Inoue if (gethostname(domain, MAXHOSTNAMELEN) == 0 && 1132cfa1ca9dSYoshinobu Inoue (cp = index(domain, '.'))) 1133cfa1ca9dSYoshinobu Inoue (void) strcpy(domain, cp + 1); 1134cfa1ca9dSYoshinobu Inoue else 1135cfa1ca9dSYoshinobu Inoue domain[0] = 0; 1136cfa1ca9dSYoshinobu Inoue } 1137cfa1ca9dSYoshinobu Inoue cp = 0; 113865ea0024SAssar Westerlund if (!numeric_addr && !IN6_IS_ADDR_UNSPECIFIED(in6p)) { 1139cfa1ca9dSYoshinobu Inoue hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6); 1140cfa1ca9dSYoshinobu Inoue if (hp) { 1141cfa1ca9dSYoshinobu Inoue if ((cp = index(hp->h_name, '.')) && 1142cfa1ca9dSYoshinobu Inoue !strcmp(cp + 1, domain)) 1143cfa1ca9dSYoshinobu Inoue *cp = 0; 1144cfa1ca9dSYoshinobu Inoue cp = hp->h_name; 1145cfa1ca9dSYoshinobu Inoue } 1146cfa1ca9dSYoshinobu Inoue } 1147cfa1ca9dSYoshinobu Inoue if (IN6_IS_ADDR_UNSPECIFIED(in6p)) 1148cfa1ca9dSYoshinobu Inoue strcpy(line, "*"); 1149cfa1ca9dSYoshinobu Inoue else if (cp) 1150cfa1ca9dSYoshinobu Inoue strcpy(line, cp); 1151cfa1ca9dSYoshinobu Inoue else 1152cfa1ca9dSYoshinobu Inoue sprintf(line, "%s", 1153cfa1ca9dSYoshinobu Inoue inet_ntop(AF_INET6, (void *)in6p, ntop_buf, 1154cfa1ca9dSYoshinobu Inoue sizeof(ntop_buf))); 1155cfa1ca9dSYoshinobu Inoue return (line); 1156cfa1ca9dSYoshinobu Inoue } 1157d84a1df4SHajimu UMEMOTO #endif /*INET6*/ 1158