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