1cfa1ca9dSYoshinobu Inoue /* BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp */ 2cfa1ca9dSYoshinobu Inoue /* 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 * $FreeBSD$ 35cfa1ca9dSYoshinobu Inoue */ 36cfa1ca9dSYoshinobu Inoue 37cfa1ca9dSYoshinobu Inoue #ifndef lint 38cfa1ca9dSYoshinobu Inoue /* 39cfa1ca9dSYoshinobu Inoue static char sccsid[] = "@(#)inet6.c 8.4 (Berkeley) 4/20/94"; 40cfa1ca9dSYoshinobu Inoue */ 41cfa1ca9dSYoshinobu Inoue #endif /* not lint */ 42cfa1ca9dSYoshinobu Inoue 43d84a1df4SHajimu UMEMOTO #ifdef INET6 44cfa1ca9dSYoshinobu Inoue #include <sys/param.h> 45cfa1ca9dSYoshinobu Inoue #include <sys/socket.h> 46cfa1ca9dSYoshinobu Inoue #include <sys/socketvar.h> 47cfa1ca9dSYoshinobu Inoue #include <sys/ioctl.h> 48cfa1ca9dSYoshinobu Inoue #include <sys/mbuf.h> 49cfa1ca9dSYoshinobu Inoue #include <sys/protosw.h> 5033841545SHajimu UMEMOTO #include <sys/sysctl.h> 51cfa1ca9dSYoshinobu Inoue 52cfa1ca9dSYoshinobu Inoue #include <net/route.h> 53cfa1ca9dSYoshinobu Inoue #include <net/if.h> 54cfa1ca9dSYoshinobu Inoue #include <net/if_var.h> 55cfa1ca9dSYoshinobu Inoue #include <netinet/in.h> 56cfa1ca9dSYoshinobu Inoue #include <netinet/ip6.h> 57cfa1ca9dSYoshinobu Inoue #include <netinet/icmp6.h> 58cfa1ca9dSYoshinobu Inoue #include <netinet/in_systm.h> 59cfa1ca9dSYoshinobu Inoue #include <netinet6/in6_pcb.h> 60cfa1ca9dSYoshinobu Inoue #include <netinet6/in6_var.h> 61cfa1ca9dSYoshinobu Inoue #include <netinet6/ip6_var.h> 62cfa1ca9dSYoshinobu Inoue #include <netinet6/pim6_var.h> 6333841545SHajimu UMEMOTO #include <netinet6/raw_ip6.h> 64cfa1ca9dSYoshinobu Inoue 65cfa1ca9dSYoshinobu Inoue #include <arpa/inet.h> 66cfa1ca9dSYoshinobu Inoue #include <netdb.h> 67cfa1ca9dSYoshinobu Inoue 68cfa1ca9dSYoshinobu Inoue #include <stdio.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 *); 765e051718SAssar Westerlund void inet6print (struct in6_addr *, int, char *, int); 77cfa1ca9dSYoshinobu Inoue 78cfa1ca9dSYoshinobu Inoue static char ntop_buf[INET6_ADDRSTRLEN]; 79cfa1ca9dSYoshinobu Inoue 80cfa1ca9dSYoshinobu Inoue static char *ip6nh[] = { 81cfa1ca9dSYoshinobu Inoue "hop by hop", 82cfa1ca9dSYoshinobu Inoue "ICMP", 83cfa1ca9dSYoshinobu Inoue "IGMP", 84cfa1ca9dSYoshinobu Inoue "#3", 85cfa1ca9dSYoshinobu Inoue "IP", 86cfa1ca9dSYoshinobu Inoue "#5", 87cfa1ca9dSYoshinobu Inoue "TCP", 88cfa1ca9dSYoshinobu Inoue "#7", 89cfa1ca9dSYoshinobu Inoue "#8", 90cfa1ca9dSYoshinobu Inoue "#9", 91cfa1ca9dSYoshinobu Inoue "#10", 92cfa1ca9dSYoshinobu Inoue "#11", 93cfa1ca9dSYoshinobu Inoue "#12", 94cfa1ca9dSYoshinobu Inoue "#13", 95cfa1ca9dSYoshinobu Inoue "#14", 96cfa1ca9dSYoshinobu Inoue "#15", 97cfa1ca9dSYoshinobu Inoue "#16", 98cfa1ca9dSYoshinobu Inoue "UDP", 99cfa1ca9dSYoshinobu Inoue "#18", 100cfa1ca9dSYoshinobu Inoue "#19", 101cfa1ca9dSYoshinobu Inoue "#20", 102cfa1ca9dSYoshinobu Inoue "#21", 103cfa1ca9dSYoshinobu Inoue "IDP", 104cfa1ca9dSYoshinobu Inoue "#23", 105cfa1ca9dSYoshinobu Inoue "#24", 106cfa1ca9dSYoshinobu Inoue "#25", 107cfa1ca9dSYoshinobu Inoue "#26", 108cfa1ca9dSYoshinobu Inoue "#27", 109cfa1ca9dSYoshinobu Inoue "#28", 110cfa1ca9dSYoshinobu Inoue "TP", 111cfa1ca9dSYoshinobu Inoue "#30", 112cfa1ca9dSYoshinobu Inoue "#31", 113cfa1ca9dSYoshinobu Inoue "#32", 114cfa1ca9dSYoshinobu Inoue "#33", 115cfa1ca9dSYoshinobu Inoue "#34", 116cfa1ca9dSYoshinobu Inoue "#35", 117cfa1ca9dSYoshinobu Inoue "#36", 118cfa1ca9dSYoshinobu Inoue "#37", 119cfa1ca9dSYoshinobu Inoue "#38", 120cfa1ca9dSYoshinobu Inoue "#39", 121cfa1ca9dSYoshinobu Inoue "#40", 122cfa1ca9dSYoshinobu Inoue "IP6", 123cfa1ca9dSYoshinobu Inoue "#42", 124cfa1ca9dSYoshinobu Inoue "routing", 125cfa1ca9dSYoshinobu Inoue "fragment", 126cfa1ca9dSYoshinobu Inoue "#45", 127cfa1ca9dSYoshinobu Inoue "#46", 128cfa1ca9dSYoshinobu Inoue "#47", 129cfa1ca9dSYoshinobu Inoue "#48", 130cfa1ca9dSYoshinobu Inoue "#49", 131cfa1ca9dSYoshinobu Inoue "ESP", 132cfa1ca9dSYoshinobu Inoue "AH", 133cfa1ca9dSYoshinobu Inoue "#52", 134cfa1ca9dSYoshinobu Inoue "#53", 135cfa1ca9dSYoshinobu Inoue "#54", 136cfa1ca9dSYoshinobu Inoue "#55", 137cfa1ca9dSYoshinobu Inoue "#56", 138cfa1ca9dSYoshinobu Inoue "#57", 139cfa1ca9dSYoshinobu Inoue "ICMP6", 140cfa1ca9dSYoshinobu Inoue "no next header", 141cfa1ca9dSYoshinobu Inoue "destination option", 142cfa1ca9dSYoshinobu Inoue "#61", 143cfa1ca9dSYoshinobu Inoue "#62", 144cfa1ca9dSYoshinobu Inoue "#63", 145cfa1ca9dSYoshinobu Inoue "#64", 146cfa1ca9dSYoshinobu Inoue "#65", 147cfa1ca9dSYoshinobu Inoue "#66", 148cfa1ca9dSYoshinobu Inoue "#67", 149cfa1ca9dSYoshinobu Inoue "#68", 150cfa1ca9dSYoshinobu Inoue "#69", 151cfa1ca9dSYoshinobu Inoue "#70", 152cfa1ca9dSYoshinobu Inoue "#71", 153cfa1ca9dSYoshinobu Inoue "#72", 154cfa1ca9dSYoshinobu Inoue "#73", 155cfa1ca9dSYoshinobu Inoue "#74", 156cfa1ca9dSYoshinobu Inoue "#75", 157cfa1ca9dSYoshinobu Inoue "#76", 158cfa1ca9dSYoshinobu Inoue "#77", 159cfa1ca9dSYoshinobu Inoue "#78", 160cfa1ca9dSYoshinobu Inoue "#79", 161cfa1ca9dSYoshinobu Inoue "ISOIP", 162cfa1ca9dSYoshinobu Inoue "#81", 163cfa1ca9dSYoshinobu Inoue "#82", 164cfa1ca9dSYoshinobu Inoue "#83", 165cfa1ca9dSYoshinobu Inoue "#84", 166cfa1ca9dSYoshinobu Inoue "#85", 167cfa1ca9dSYoshinobu Inoue "#86", 168cfa1ca9dSYoshinobu Inoue "#87", 169cfa1ca9dSYoshinobu Inoue "#88", 17032cd1d96SJun-ichiro itojun Hagino "OSPF", 171cfa1ca9dSYoshinobu Inoue "#80", 172cfa1ca9dSYoshinobu Inoue "#91", 173cfa1ca9dSYoshinobu Inoue "#92", 174cfa1ca9dSYoshinobu Inoue "#93", 175cfa1ca9dSYoshinobu Inoue "#94", 176cfa1ca9dSYoshinobu Inoue "#95", 177cfa1ca9dSYoshinobu Inoue "#96", 178cfa1ca9dSYoshinobu Inoue "Ethernet", 179cfa1ca9dSYoshinobu Inoue "#98", 180cfa1ca9dSYoshinobu Inoue "#99", 181cfa1ca9dSYoshinobu Inoue "#100", 182cfa1ca9dSYoshinobu Inoue "#101", 183cfa1ca9dSYoshinobu Inoue "#102", 184cfa1ca9dSYoshinobu Inoue "PIM", 185cfa1ca9dSYoshinobu Inoue "#104", 186cfa1ca9dSYoshinobu Inoue "#105", 187cfa1ca9dSYoshinobu Inoue "#106", 188cfa1ca9dSYoshinobu Inoue "#107", 189cfa1ca9dSYoshinobu Inoue "#108", 190cfa1ca9dSYoshinobu Inoue "#109", 191cfa1ca9dSYoshinobu Inoue "#110", 192cfa1ca9dSYoshinobu Inoue "#111", 193cfa1ca9dSYoshinobu Inoue "#112", 194cfa1ca9dSYoshinobu Inoue "#113", 195cfa1ca9dSYoshinobu Inoue "#114", 196cfa1ca9dSYoshinobu Inoue "#115", 197cfa1ca9dSYoshinobu Inoue "#116", 198cfa1ca9dSYoshinobu Inoue "#117", 199cfa1ca9dSYoshinobu Inoue "#118", 200cfa1ca9dSYoshinobu Inoue "#119", 201cfa1ca9dSYoshinobu Inoue "#120", 202cfa1ca9dSYoshinobu Inoue "#121", 203cfa1ca9dSYoshinobu Inoue "#122", 204cfa1ca9dSYoshinobu Inoue "#123", 205cfa1ca9dSYoshinobu Inoue "#124", 206cfa1ca9dSYoshinobu Inoue "#125", 207cfa1ca9dSYoshinobu Inoue "#126", 208cfa1ca9dSYoshinobu Inoue "#127", 209cfa1ca9dSYoshinobu Inoue "#128", 210cfa1ca9dSYoshinobu Inoue "#129", 211cfa1ca9dSYoshinobu Inoue "#130", 212cfa1ca9dSYoshinobu Inoue "#131", 213cfa1ca9dSYoshinobu Inoue "#132", 214cfa1ca9dSYoshinobu Inoue "#133", 215cfa1ca9dSYoshinobu Inoue "#134", 216cfa1ca9dSYoshinobu Inoue "#135", 217cfa1ca9dSYoshinobu Inoue "#136", 218cfa1ca9dSYoshinobu Inoue "#137", 219cfa1ca9dSYoshinobu Inoue "#138", 220cfa1ca9dSYoshinobu Inoue "#139", 221cfa1ca9dSYoshinobu Inoue "#140", 222cfa1ca9dSYoshinobu Inoue "#141", 223cfa1ca9dSYoshinobu Inoue "#142", 224cfa1ca9dSYoshinobu Inoue "#143", 225cfa1ca9dSYoshinobu Inoue "#144", 226cfa1ca9dSYoshinobu Inoue "#145", 227cfa1ca9dSYoshinobu Inoue "#146", 228cfa1ca9dSYoshinobu Inoue "#147", 229cfa1ca9dSYoshinobu Inoue "#148", 230cfa1ca9dSYoshinobu Inoue "#149", 231cfa1ca9dSYoshinobu Inoue "#150", 232cfa1ca9dSYoshinobu Inoue "#151", 233cfa1ca9dSYoshinobu Inoue "#152", 234cfa1ca9dSYoshinobu Inoue "#153", 235cfa1ca9dSYoshinobu Inoue "#154", 236cfa1ca9dSYoshinobu Inoue "#155", 237cfa1ca9dSYoshinobu Inoue "#156", 238cfa1ca9dSYoshinobu Inoue "#157", 239cfa1ca9dSYoshinobu Inoue "#158", 240cfa1ca9dSYoshinobu Inoue "#159", 241cfa1ca9dSYoshinobu Inoue "#160", 242cfa1ca9dSYoshinobu Inoue "#161", 243cfa1ca9dSYoshinobu Inoue "#162", 244cfa1ca9dSYoshinobu Inoue "#163", 245cfa1ca9dSYoshinobu Inoue "#164", 246cfa1ca9dSYoshinobu Inoue "#165", 247cfa1ca9dSYoshinobu Inoue "#166", 248cfa1ca9dSYoshinobu Inoue "#167", 249cfa1ca9dSYoshinobu Inoue "#168", 250cfa1ca9dSYoshinobu Inoue "#169", 251cfa1ca9dSYoshinobu Inoue "#170", 252cfa1ca9dSYoshinobu Inoue "#171", 253cfa1ca9dSYoshinobu Inoue "#172", 254cfa1ca9dSYoshinobu Inoue "#173", 255cfa1ca9dSYoshinobu Inoue "#174", 256cfa1ca9dSYoshinobu Inoue "#175", 257cfa1ca9dSYoshinobu Inoue "#176", 258cfa1ca9dSYoshinobu Inoue "#177", 259cfa1ca9dSYoshinobu Inoue "#178", 260cfa1ca9dSYoshinobu Inoue "#179", 261cfa1ca9dSYoshinobu Inoue "#180", 262cfa1ca9dSYoshinobu Inoue "#181", 263cfa1ca9dSYoshinobu Inoue "#182", 264cfa1ca9dSYoshinobu Inoue "#183", 265cfa1ca9dSYoshinobu Inoue "#184", 266cfa1ca9dSYoshinobu Inoue "#185", 267cfa1ca9dSYoshinobu Inoue "#186", 268cfa1ca9dSYoshinobu Inoue "#187", 269cfa1ca9dSYoshinobu Inoue "#188", 270cfa1ca9dSYoshinobu Inoue "#189", 271cfa1ca9dSYoshinobu Inoue "#180", 272cfa1ca9dSYoshinobu Inoue "#191", 273cfa1ca9dSYoshinobu Inoue "#192", 274cfa1ca9dSYoshinobu Inoue "#193", 275cfa1ca9dSYoshinobu Inoue "#194", 276cfa1ca9dSYoshinobu Inoue "#195", 277cfa1ca9dSYoshinobu Inoue "#196", 278cfa1ca9dSYoshinobu Inoue "#197", 279cfa1ca9dSYoshinobu Inoue "#198", 280cfa1ca9dSYoshinobu Inoue "#199", 281cfa1ca9dSYoshinobu Inoue "#200", 282cfa1ca9dSYoshinobu Inoue "#201", 283cfa1ca9dSYoshinobu Inoue "#202", 284cfa1ca9dSYoshinobu Inoue "#203", 285cfa1ca9dSYoshinobu Inoue "#204", 286cfa1ca9dSYoshinobu Inoue "#205", 287cfa1ca9dSYoshinobu Inoue "#206", 288cfa1ca9dSYoshinobu Inoue "#207", 289cfa1ca9dSYoshinobu Inoue "#208", 290cfa1ca9dSYoshinobu Inoue "#209", 291cfa1ca9dSYoshinobu Inoue "#210", 292cfa1ca9dSYoshinobu Inoue "#211", 293cfa1ca9dSYoshinobu Inoue "#212", 294cfa1ca9dSYoshinobu Inoue "#213", 295cfa1ca9dSYoshinobu Inoue "#214", 296cfa1ca9dSYoshinobu Inoue "#215", 297cfa1ca9dSYoshinobu Inoue "#216", 298cfa1ca9dSYoshinobu Inoue "#217", 299cfa1ca9dSYoshinobu Inoue "#218", 300cfa1ca9dSYoshinobu Inoue "#219", 301cfa1ca9dSYoshinobu Inoue "#220", 302cfa1ca9dSYoshinobu Inoue "#221", 303cfa1ca9dSYoshinobu Inoue "#222", 304cfa1ca9dSYoshinobu Inoue "#223", 305cfa1ca9dSYoshinobu Inoue "#224", 306cfa1ca9dSYoshinobu Inoue "#225", 307cfa1ca9dSYoshinobu Inoue "#226", 308cfa1ca9dSYoshinobu Inoue "#227", 309cfa1ca9dSYoshinobu Inoue "#228", 310cfa1ca9dSYoshinobu Inoue "#229", 311cfa1ca9dSYoshinobu Inoue "#230", 312cfa1ca9dSYoshinobu Inoue "#231", 313cfa1ca9dSYoshinobu Inoue "#232", 314cfa1ca9dSYoshinobu Inoue "#233", 315cfa1ca9dSYoshinobu Inoue "#234", 316cfa1ca9dSYoshinobu Inoue "#235", 317cfa1ca9dSYoshinobu Inoue "#236", 318cfa1ca9dSYoshinobu Inoue "#237", 319cfa1ca9dSYoshinobu Inoue "#238", 320cfa1ca9dSYoshinobu Inoue "#239", 321cfa1ca9dSYoshinobu Inoue "#240", 322cfa1ca9dSYoshinobu Inoue "#241", 323cfa1ca9dSYoshinobu Inoue "#242", 324cfa1ca9dSYoshinobu Inoue "#243", 325cfa1ca9dSYoshinobu Inoue "#244", 326cfa1ca9dSYoshinobu Inoue "#245", 327cfa1ca9dSYoshinobu Inoue "#246", 328cfa1ca9dSYoshinobu Inoue "#247", 329cfa1ca9dSYoshinobu Inoue "#248", 330cfa1ca9dSYoshinobu Inoue "#249", 331cfa1ca9dSYoshinobu Inoue "#250", 332cfa1ca9dSYoshinobu Inoue "#251", 333cfa1ca9dSYoshinobu Inoue "#252", 334cfa1ca9dSYoshinobu Inoue "#253", 335cfa1ca9dSYoshinobu Inoue "#254", 336cfa1ca9dSYoshinobu Inoue "#255", 337cfa1ca9dSYoshinobu Inoue }; 338cfa1ca9dSYoshinobu Inoue 339cfa1ca9dSYoshinobu Inoue /* 340cfa1ca9dSYoshinobu Inoue * Dump IP6 statistics structure. 341cfa1ca9dSYoshinobu Inoue */ 342cfa1ca9dSYoshinobu Inoue void 343f964d60dSAssar Westerlund ip6_stats(u_long off __unused, char *name, int af __unused) 344cfa1ca9dSYoshinobu Inoue { 345cfa1ca9dSYoshinobu Inoue struct ip6stat ip6stat; 346cfa1ca9dSYoshinobu Inoue int first, i; 347785d213dSHajimu UMEMOTO int mib[4]; 348785d213dSHajimu UMEMOTO size_t len; 349cfa1ca9dSYoshinobu Inoue 350785d213dSHajimu UMEMOTO mib[0] = CTL_NET; 351785d213dSHajimu UMEMOTO mib[1] = PF_INET6; 352785d213dSHajimu UMEMOTO mib[2] = IPPROTO_IPV6; 353785d213dSHajimu UMEMOTO mib[3] = IPV6CTL_STATS; 354cfa1ca9dSYoshinobu Inoue 355785d213dSHajimu UMEMOTO len = sizeof ip6stat; 356785d213dSHajimu UMEMOTO memset(&ip6stat, 0, len); 357785d213dSHajimu UMEMOTO if (sysctl(mib, 4, &ip6stat, &len, (void *)0, 0) < 0) 3586eec3af9SPoul-Henning Kamp return; 359cfa1ca9dSYoshinobu Inoue printf("%s:\n", name); 360cfa1ca9dSYoshinobu Inoue 361cfa1ca9dSYoshinobu Inoue #define p(f, m) if (ip6stat.f || sflag <= 1) \ 36232cd1d96SJun-ichiro itojun Hagino printf(m, (unsigned long long)ip6stat.f, plural(ip6stat.f)) 363cfa1ca9dSYoshinobu Inoue #define p1a(f, m) if (ip6stat.f || sflag <= 1) \ 36432cd1d96SJun-ichiro itojun Hagino printf(m, (unsigned long long)ip6stat.f) 365cfa1ca9dSYoshinobu Inoue 36632cd1d96SJun-ichiro itojun Hagino p(ip6s_total, "\t%llu total packet%s received\n"); 36732cd1d96SJun-ichiro itojun Hagino p1a(ip6s_toosmall, "\t%llu with size smaller than minimum\n"); 36832cd1d96SJun-ichiro itojun Hagino p1a(ip6s_tooshort, "\t%llu with data size < data length\n"); 36932cd1d96SJun-ichiro itojun Hagino p1a(ip6s_badoptions, "\t%llu with bad options\n"); 37032cd1d96SJun-ichiro itojun Hagino p1a(ip6s_badvers, "\t%llu with incorrect version number\n"); 37132cd1d96SJun-ichiro itojun Hagino p(ip6s_fragments, "\t%llu fragment%s received\n"); 37232cd1d96SJun-ichiro itojun Hagino p(ip6s_fragdropped, "\t%llu fragment%s dropped (dup or out of space)\n"); 37332cd1d96SJun-ichiro itojun Hagino p(ip6s_fragtimeout, "\t%llu fragment%s dropped after timeout\n"); 37432cd1d96SJun-ichiro itojun Hagino p(ip6s_fragoverflow, "\t%llu fragment%s that exceeded limit\n"); 37532cd1d96SJun-ichiro itojun Hagino p(ip6s_reassembled, "\t%llu packet%s reassembled ok\n"); 37632cd1d96SJun-ichiro itojun Hagino p(ip6s_delivered, "\t%llu packet%s for this host\n"); 37732cd1d96SJun-ichiro itojun Hagino p(ip6s_forward, "\t%llu packet%s forwarded\n"); 37832cd1d96SJun-ichiro itojun Hagino p(ip6s_cantforward, "\t%llu packet%s not forwardable\n"); 37932cd1d96SJun-ichiro itojun Hagino p(ip6s_redirectsent, "\t%llu redirect%s sent\n"); 38032cd1d96SJun-ichiro itojun Hagino p(ip6s_localout, "\t%llu packet%s sent from this host\n"); 38132cd1d96SJun-ichiro itojun Hagino p(ip6s_rawout, "\t%llu packet%s sent with fabricated ip header\n"); 38232cd1d96SJun-ichiro itojun Hagino p(ip6s_odropped, "\t%llu output packet%s dropped due to no bufs, etc.\n"); 38332cd1d96SJun-ichiro itojun Hagino p(ip6s_noroute, "\t%llu output packet%s discarded due to no route\n"); 38432cd1d96SJun-ichiro itojun Hagino p(ip6s_fragmented, "\t%llu output datagram%s fragmented\n"); 38532cd1d96SJun-ichiro itojun Hagino p(ip6s_ofragments, "\t%llu fragment%s created\n"); 38632cd1d96SJun-ichiro itojun Hagino p(ip6s_cantfrag, "\t%llu datagram%s that can't be fragmented\n"); 38732cd1d96SJun-ichiro itojun Hagino p(ip6s_badscope, "\t%llu packet%s that violated scope rules\n"); 38832cd1d96SJun-ichiro itojun Hagino p(ip6s_notmember, "\t%llu multicast packet%s which we don't join\n"); 389cfa1ca9dSYoshinobu Inoue for (first = 1, i = 0; i < 256; i++) 390cfa1ca9dSYoshinobu Inoue if (ip6stat.ip6s_nxthist[i] != 0) { 391cfa1ca9dSYoshinobu Inoue if (first) { 392cfa1ca9dSYoshinobu Inoue printf("\tInput histogram:\n"); 393cfa1ca9dSYoshinobu Inoue first = 0; 394cfa1ca9dSYoshinobu Inoue } 39532cd1d96SJun-ichiro itojun Hagino printf("\t\t%s: %llu\n", ip6nh[i], 39632cd1d96SJun-ichiro itojun Hagino (unsigned long long)ip6stat.ip6s_nxthist[i]); 397cfa1ca9dSYoshinobu Inoue } 398cfa1ca9dSYoshinobu Inoue printf("\tMbuf statistics:\n"); 39932cd1d96SJun-ichiro itojun Hagino printf("\t\t%llu one mbuf\n", (unsigned long long)ip6stat.ip6s_m1); 400cfa1ca9dSYoshinobu Inoue for (first = 1, i = 0; i < 32; i++) { 4017d56d374SYoshinobu Inoue char ifbuf[IFNAMSIZ]; 402cfa1ca9dSYoshinobu Inoue if (ip6stat.ip6s_m2m[i] != 0) { 403cfa1ca9dSYoshinobu Inoue if (first) { 404cfa1ca9dSYoshinobu Inoue printf("\t\ttwo or more mbuf:\n"); 405cfa1ca9dSYoshinobu Inoue first = 0; 406cfa1ca9dSYoshinobu Inoue } 40732cd1d96SJun-ichiro itojun Hagino printf("\t\t\t%s= %llu\n", 408cfa1ca9dSYoshinobu Inoue if_indextoname(i, ifbuf), 40932cd1d96SJun-ichiro itojun Hagino (unsigned long long)ip6stat.ip6s_m2m[i]); 410cfa1ca9dSYoshinobu Inoue } 411cfa1ca9dSYoshinobu Inoue } 41232cd1d96SJun-ichiro itojun Hagino printf("\t\t%llu one ext mbuf\n", 41332cd1d96SJun-ichiro itojun Hagino (unsigned long long)ip6stat.ip6s_mext1); 41432cd1d96SJun-ichiro itojun Hagino printf("\t\t%llu two or more ext mbuf\n", 41532cd1d96SJun-ichiro itojun Hagino (unsigned long long)ip6stat.ip6s_mext2m); 41632cd1d96SJun-ichiro itojun Hagino p(ip6s_exthdrtoolong, 41732cd1d96SJun-ichiro itojun Hagino "\t%llu packet%s whose headers are not continuous\n"); 41832cd1d96SJun-ichiro itojun Hagino p(ip6s_nogif, "\t%llu tunneling packet%s that can't find gif\n"); 41932cd1d96SJun-ichiro itojun Hagino p(ip6s_toomanyhdr, 42032cd1d96SJun-ichiro itojun Hagino "\t%llu packet%s discarded due to too may headers\n"); 42132cd1d96SJun-ichiro itojun Hagino 42232cd1d96SJun-ichiro itojun Hagino /* for debugging source address selection */ 42332cd1d96SJun-ichiro itojun Hagino #define PRINT_SCOPESTAT(s,i) do {\ 42432cd1d96SJun-ichiro itojun Hagino switch(i) { /* XXX hardcoding in each case */\ 42532cd1d96SJun-ichiro itojun Hagino case 1:\ 42632cd1d96SJun-ichiro itojun Hagino p(s, "\t\t%llu node-local%s\n");\ 42732cd1d96SJun-ichiro itojun Hagino break;\ 42832cd1d96SJun-ichiro itojun Hagino case 2:\ 42932cd1d96SJun-ichiro itojun Hagino p(s,"\t\t%llu link-local%s\n");\ 43032cd1d96SJun-ichiro itojun Hagino break;\ 43132cd1d96SJun-ichiro itojun Hagino case 5:\ 43232cd1d96SJun-ichiro itojun Hagino p(s,"\t\t%llu site-local%s\n");\ 43332cd1d96SJun-ichiro itojun Hagino break;\ 43432cd1d96SJun-ichiro itojun Hagino case 14:\ 43532cd1d96SJun-ichiro itojun Hagino p(s,"\t\t%llu global%s\n");\ 43632cd1d96SJun-ichiro itojun Hagino break;\ 43732cd1d96SJun-ichiro itojun Hagino default:\ 43832cd1d96SJun-ichiro itojun Hagino printf("\t\t%llu addresses scope=%x\n",\ 43932cd1d96SJun-ichiro itojun Hagino (unsigned long long)ip6stat.s, i);\ 44032cd1d96SJun-ichiro itojun Hagino }\ 44132cd1d96SJun-ichiro itojun Hagino } while (0); 44232cd1d96SJun-ichiro itojun Hagino 44332cd1d96SJun-ichiro itojun Hagino p(ip6s_sources_none, 44432cd1d96SJun-ichiro itojun Hagino "\t%llu failure%s of source address selection\n"); 44532cd1d96SJun-ichiro itojun Hagino for (first = 1, i = 0; i < 16; i++) { 44632cd1d96SJun-ichiro itojun Hagino if (ip6stat.ip6s_sources_sameif[i]) { 44732cd1d96SJun-ichiro itojun Hagino if (first) { 44832cd1d96SJun-ichiro itojun Hagino printf("\tsource addresses on an outgoing I/F\n"); 44932cd1d96SJun-ichiro itojun Hagino first = 0; 45032cd1d96SJun-ichiro itojun Hagino } 45132cd1d96SJun-ichiro itojun Hagino PRINT_SCOPESTAT(ip6s_sources_sameif[i], i); 45232cd1d96SJun-ichiro itojun Hagino } 45332cd1d96SJun-ichiro itojun Hagino } 45432cd1d96SJun-ichiro itojun Hagino for (first = 1, i = 0; i < 16; i++) { 45532cd1d96SJun-ichiro itojun Hagino if (ip6stat.ip6s_sources_otherif[i]) { 45632cd1d96SJun-ichiro itojun Hagino if (first) { 45732cd1d96SJun-ichiro itojun Hagino printf("\tsource addresses on a non-outgoing I/F\n"); 45832cd1d96SJun-ichiro itojun Hagino first = 0; 45932cd1d96SJun-ichiro itojun Hagino } 46032cd1d96SJun-ichiro itojun Hagino PRINT_SCOPESTAT(ip6s_sources_otherif[i], i); 46132cd1d96SJun-ichiro itojun Hagino } 46232cd1d96SJun-ichiro itojun Hagino } 46332cd1d96SJun-ichiro itojun Hagino for (first = 1, i = 0; i < 16; i++) { 46432cd1d96SJun-ichiro itojun Hagino if (ip6stat.ip6s_sources_samescope[i]) { 46532cd1d96SJun-ichiro itojun Hagino if (first) { 46632cd1d96SJun-ichiro itojun Hagino printf("\tsource addresses of same scope\n"); 46732cd1d96SJun-ichiro itojun Hagino first = 0; 46832cd1d96SJun-ichiro itojun Hagino } 46932cd1d96SJun-ichiro itojun Hagino PRINT_SCOPESTAT(ip6s_sources_samescope[i], i); 47032cd1d96SJun-ichiro itojun Hagino } 47132cd1d96SJun-ichiro itojun Hagino } 47232cd1d96SJun-ichiro itojun Hagino for (first = 1, i = 0; i < 16; i++) { 47332cd1d96SJun-ichiro itojun Hagino if (ip6stat.ip6s_sources_otherscope[i]) { 47432cd1d96SJun-ichiro itojun Hagino if (first) { 47532cd1d96SJun-ichiro itojun Hagino printf("\tsource addresses of a different scope\n"); 47632cd1d96SJun-ichiro itojun Hagino first = 0; 47732cd1d96SJun-ichiro itojun Hagino } 47832cd1d96SJun-ichiro itojun Hagino PRINT_SCOPESTAT(ip6s_sources_otherscope[i], i); 47932cd1d96SJun-ichiro itojun Hagino } 48032cd1d96SJun-ichiro itojun Hagino } 48132cd1d96SJun-ichiro itojun Hagino for (first = 1, i = 0; i < 16; i++) { 48232cd1d96SJun-ichiro itojun Hagino if (ip6stat.ip6s_sources_deprecated[i]) { 48332cd1d96SJun-ichiro itojun Hagino if (first) { 48432cd1d96SJun-ichiro itojun Hagino printf("\tdeprecated source addresses\n"); 48532cd1d96SJun-ichiro itojun Hagino first = 0; 48632cd1d96SJun-ichiro itojun Hagino } 48732cd1d96SJun-ichiro itojun Hagino PRINT_SCOPESTAT(ip6s_sources_deprecated[i], i); 48832cd1d96SJun-ichiro itojun Hagino } 48932cd1d96SJun-ichiro itojun Hagino } 49032cd1d96SJun-ichiro itojun Hagino 49132cd1d96SJun-ichiro itojun Hagino p1a(ip6s_forward_cachehit, "\t%llu forward cache hit\n"); 49232cd1d96SJun-ichiro itojun Hagino p1a(ip6s_forward_cachemiss, "\t%llu forward cache miss\n"); 493cfa1ca9dSYoshinobu Inoue #undef p 49432cd1d96SJun-ichiro itojun Hagino #undef p1a 495cfa1ca9dSYoshinobu Inoue } 496cfa1ca9dSYoshinobu Inoue 497cfa1ca9dSYoshinobu Inoue /* 498cfa1ca9dSYoshinobu Inoue * Dump IPv6 per-interface statistics based on RFC 2465. 499cfa1ca9dSYoshinobu Inoue */ 500cfa1ca9dSYoshinobu Inoue void 5015e051718SAssar Westerlund ip6_ifstats(char *ifname) 502cfa1ca9dSYoshinobu Inoue { 503cfa1ca9dSYoshinobu Inoue struct in6_ifreq ifr; 504cfa1ca9dSYoshinobu Inoue int s; 505cfa1ca9dSYoshinobu Inoue #define p(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \ 50632cd1d96SJun-ichiro itojun Hagino printf(m, (unsigned long long)ifr.ifr_ifru.ifru_stat.f, plural(ifr.ifr_ifru.ifru_stat.f)) 507cfa1ca9dSYoshinobu Inoue #define p_5(f, m) if (ifr.ifr_ifru.ifru_stat.f || sflag <= 1) \ 50832cd1d96SJun-ichiro itojun Hagino printf(m, (unsigned long long)ip6stat.f) 509cfa1ca9dSYoshinobu Inoue 510cfa1ca9dSYoshinobu Inoue if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { 511cfa1ca9dSYoshinobu Inoue perror("Warning: socket(AF_INET6)"); 512cfa1ca9dSYoshinobu Inoue return; 513cfa1ca9dSYoshinobu Inoue } 514cfa1ca9dSYoshinobu Inoue 515cfa1ca9dSYoshinobu Inoue strcpy(ifr.ifr_name, ifname); 516cfa1ca9dSYoshinobu Inoue printf("ip6 on %s:\n", ifr.ifr_name); 517cfa1ca9dSYoshinobu Inoue 518cfa1ca9dSYoshinobu Inoue if (ioctl(s, SIOCGIFSTAT_IN6, (char *)&ifr) < 0) { 519cfa1ca9dSYoshinobu Inoue perror("Warning: ioctl(SIOCGIFSTAT_IN6)"); 520cfa1ca9dSYoshinobu Inoue goto end; 521cfa1ca9dSYoshinobu Inoue } 522cfa1ca9dSYoshinobu Inoue 52332cd1d96SJun-ichiro itojun Hagino p(ifs6_in_receive, "\t%llu total input datagram%s\n"); 52432cd1d96SJun-ichiro itojun Hagino p(ifs6_in_hdrerr, "\t%llu datagram%s with invalid header received\n"); 52532cd1d96SJun-ichiro itojun Hagino p(ifs6_in_toobig, "\t%llu datagram%s exceeded MTU received\n"); 52632cd1d96SJun-ichiro itojun Hagino p(ifs6_in_noroute, "\t%llu datagram%s with no route received\n"); 52732cd1d96SJun-ichiro itojun Hagino p(ifs6_in_addrerr, "\t%llu datagram%s with invalid dst received\n"); 52832cd1d96SJun-ichiro itojun Hagino p(ifs6_in_protounknown, "\t%llu datagram%s with unknown proto received\n"); 52932cd1d96SJun-ichiro itojun Hagino p(ifs6_in_truncated, "\t%llu truncated datagram%s received\n"); 53032cd1d96SJun-ichiro itojun Hagino p(ifs6_in_discard, "\t%llu input datagram%s discarded\n"); 531cfa1ca9dSYoshinobu Inoue p(ifs6_in_deliver, 53232cd1d96SJun-ichiro itojun Hagino "\t%llu datagram%s delivered to an upper layer protocol\n"); 53332cd1d96SJun-ichiro itojun Hagino p(ifs6_out_forward, "\t%llu datagram%s forwarded to this interface\n"); 534cfa1ca9dSYoshinobu Inoue p(ifs6_out_request, 53532cd1d96SJun-ichiro itojun Hagino "\t%llu datagram%s sent from an upper layer protocol\n"); 53632cd1d96SJun-ichiro itojun Hagino p(ifs6_out_discard, "\t%llu total discarded output datagram%s\n"); 53732cd1d96SJun-ichiro itojun Hagino p(ifs6_out_fragok, "\t%llu output datagram%s fragmented\n"); 53832cd1d96SJun-ichiro itojun Hagino p(ifs6_out_fragfail, "\t%llu output datagram%s failed on fragment\n"); 53932cd1d96SJun-ichiro itojun Hagino p(ifs6_out_fragcreat, "\t%llu output datagram%s succeeded on fragment\n"); 54032cd1d96SJun-ichiro itojun Hagino p(ifs6_reass_reqd, "\t%llu incoming datagram%s fragmented\n"); 54132cd1d96SJun-ichiro itojun Hagino p(ifs6_reass_ok, "\t%llu datagram%s reassembled\n"); 54232cd1d96SJun-ichiro itojun Hagino p(ifs6_reass_fail, "\t%llu datagram%s failed on reassembling\n"); 54332cd1d96SJun-ichiro itojun Hagino p(ifs6_in_mcast, "\t%llu multicast datagram%s received\n"); 54432cd1d96SJun-ichiro itojun Hagino p(ifs6_out_mcast, "\t%llu multicast datagram%s sent\n"); 545cfa1ca9dSYoshinobu Inoue 546cfa1ca9dSYoshinobu Inoue end: 547cfa1ca9dSYoshinobu Inoue close(s); 548cfa1ca9dSYoshinobu Inoue 549cfa1ca9dSYoshinobu Inoue #undef p 550cfa1ca9dSYoshinobu Inoue #undef p_5 551cfa1ca9dSYoshinobu Inoue } 552cfa1ca9dSYoshinobu Inoue 553cfa1ca9dSYoshinobu Inoue static char *icmp6names[] = { 554cfa1ca9dSYoshinobu Inoue "#0", 555cfa1ca9dSYoshinobu Inoue "unreach", 556cfa1ca9dSYoshinobu Inoue "packet too big", 557cfa1ca9dSYoshinobu Inoue "time exceed", 558cfa1ca9dSYoshinobu Inoue "parameter problem", 559cfa1ca9dSYoshinobu Inoue "#5", 560cfa1ca9dSYoshinobu Inoue "#6", 561cfa1ca9dSYoshinobu Inoue "#7", 562cfa1ca9dSYoshinobu Inoue "#8", 563cfa1ca9dSYoshinobu Inoue "#9", 564cfa1ca9dSYoshinobu Inoue "#10", 565cfa1ca9dSYoshinobu Inoue "#11", 566cfa1ca9dSYoshinobu Inoue "#12", 567cfa1ca9dSYoshinobu Inoue "#13", 568cfa1ca9dSYoshinobu Inoue "#14", 569cfa1ca9dSYoshinobu Inoue "#15", 570cfa1ca9dSYoshinobu Inoue "#16", 571cfa1ca9dSYoshinobu Inoue "#17", 572cfa1ca9dSYoshinobu Inoue "#18", 573cfa1ca9dSYoshinobu Inoue "#19", 574cfa1ca9dSYoshinobu Inoue "#20", 575cfa1ca9dSYoshinobu Inoue "#21", 576cfa1ca9dSYoshinobu Inoue "#22", 577cfa1ca9dSYoshinobu Inoue "#23", 578cfa1ca9dSYoshinobu Inoue "#24", 579cfa1ca9dSYoshinobu Inoue "#25", 580cfa1ca9dSYoshinobu Inoue "#26", 581cfa1ca9dSYoshinobu Inoue "#27", 582cfa1ca9dSYoshinobu Inoue "#28", 583cfa1ca9dSYoshinobu Inoue "#29", 584cfa1ca9dSYoshinobu Inoue "#30", 585cfa1ca9dSYoshinobu Inoue "#31", 586cfa1ca9dSYoshinobu Inoue "#32", 587cfa1ca9dSYoshinobu Inoue "#33", 588cfa1ca9dSYoshinobu Inoue "#34", 589cfa1ca9dSYoshinobu Inoue "#35", 590cfa1ca9dSYoshinobu Inoue "#36", 591cfa1ca9dSYoshinobu Inoue "#37", 592cfa1ca9dSYoshinobu Inoue "#38", 593cfa1ca9dSYoshinobu Inoue "#39", 594cfa1ca9dSYoshinobu Inoue "#40", 595cfa1ca9dSYoshinobu Inoue "#41", 596cfa1ca9dSYoshinobu Inoue "#42", 597cfa1ca9dSYoshinobu Inoue "#43", 598cfa1ca9dSYoshinobu Inoue "#44", 599cfa1ca9dSYoshinobu Inoue "#45", 600cfa1ca9dSYoshinobu Inoue "#46", 601cfa1ca9dSYoshinobu Inoue "#47", 602cfa1ca9dSYoshinobu Inoue "#48", 603cfa1ca9dSYoshinobu Inoue "#49", 604cfa1ca9dSYoshinobu Inoue "#50", 605cfa1ca9dSYoshinobu Inoue "#51", 606cfa1ca9dSYoshinobu Inoue "#52", 607cfa1ca9dSYoshinobu Inoue "#53", 608cfa1ca9dSYoshinobu Inoue "#54", 609cfa1ca9dSYoshinobu Inoue "#55", 610cfa1ca9dSYoshinobu Inoue "#56", 611cfa1ca9dSYoshinobu Inoue "#57", 612cfa1ca9dSYoshinobu Inoue "#58", 613cfa1ca9dSYoshinobu Inoue "#59", 614cfa1ca9dSYoshinobu Inoue "#60", 615cfa1ca9dSYoshinobu Inoue "#61", 616cfa1ca9dSYoshinobu Inoue "#62", 617cfa1ca9dSYoshinobu Inoue "#63", 618cfa1ca9dSYoshinobu Inoue "#64", 619cfa1ca9dSYoshinobu Inoue "#65", 620cfa1ca9dSYoshinobu Inoue "#66", 621cfa1ca9dSYoshinobu Inoue "#67", 622cfa1ca9dSYoshinobu Inoue "#68", 623cfa1ca9dSYoshinobu Inoue "#69", 624cfa1ca9dSYoshinobu Inoue "#70", 625cfa1ca9dSYoshinobu Inoue "#71", 626cfa1ca9dSYoshinobu Inoue "#72", 627cfa1ca9dSYoshinobu Inoue "#73", 628cfa1ca9dSYoshinobu Inoue "#74", 629cfa1ca9dSYoshinobu Inoue "#75", 630cfa1ca9dSYoshinobu Inoue "#76", 631cfa1ca9dSYoshinobu Inoue "#77", 632cfa1ca9dSYoshinobu Inoue "#78", 633cfa1ca9dSYoshinobu Inoue "#79", 634cfa1ca9dSYoshinobu Inoue "#80", 635cfa1ca9dSYoshinobu Inoue "#81", 636cfa1ca9dSYoshinobu Inoue "#82", 637cfa1ca9dSYoshinobu Inoue "#83", 638cfa1ca9dSYoshinobu Inoue "#84", 639cfa1ca9dSYoshinobu Inoue "#85", 640cfa1ca9dSYoshinobu Inoue "#86", 641cfa1ca9dSYoshinobu Inoue "#87", 642cfa1ca9dSYoshinobu Inoue "#88", 643cfa1ca9dSYoshinobu Inoue "#89", 644cfa1ca9dSYoshinobu Inoue "#80", 645cfa1ca9dSYoshinobu Inoue "#91", 646cfa1ca9dSYoshinobu Inoue "#92", 647cfa1ca9dSYoshinobu Inoue "#93", 648cfa1ca9dSYoshinobu Inoue "#94", 649cfa1ca9dSYoshinobu Inoue "#95", 650cfa1ca9dSYoshinobu Inoue "#96", 651cfa1ca9dSYoshinobu Inoue "#97", 652cfa1ca9dSYoshinobu Inoue "#98", 653cfa1ca9dSYoshinobu Inoue "#99", 654cfa1ca9dSYoshinobu Inoue "#100", 655cfa1ca9dSYoshinobu Inoue "#101", 656cfa1ca9dSYoshinobu Inoue "#102", 657cfa1ca9dSYoshinobu Inoue "#103", 658cfa1ca9dSYoshinobu Inoue "#104", 659cfa1ca9dSYoshinobu Inoue "#105", 660cfa1ca9dSYoshinobu Inoue "#106", 661cfa1ca9dSYoshinobu Inoue "#107", 662cfa1ca9dSYoshinobu Inoue "#108", 663cfa1ca9dSYoshinobu Inoue "#109", 664cfa1ca9dSYoshinobu Inoue "#110", 665cfa1ca9dSYoshinobu Inoue "#111", 666cfa1ca9dSYoshinobu Inoue "#112", 667cfa1ca9dSYoshinobu Inoue "#113", 668cfa1ca9dSYoshinobu Inoue "#114", 669cfa1ca9dSYoshinobu Inoue "#115", 670cfa1ca9dSYoshinobu Inoue "#116", 671cfa1ca9dSYoshinobu Inoue "#117", 672cfa1ca9dSYoshinobu Inoue "#118", 673cfa1ca9dSYoshinobu Inoue "#119", 674cfa1ca9dSYoshinobu Inoue "#120", 675cfa1ca9dSYoshinobu Inoue "#121", 676cfa1ca9dSYoshinobu Inoue "#122", 677cfa1ca9dSYoshinobu Inoue "#123", 678cfa1ca9dSYoshinobu Inoue "#124", 679cfa1ca9dSYoshinobu Inoue "#125", 680cfa1ca9dSYoshinobu Inoue "#126", 681cfa1ca9dSYoshinobu Inoue "#127", 682cfa1ca9dSYoshinobu Inoue "echo", 683cfa1ca9dSYoshinobu Inoue "echo reply", 684cfa1ca9dSYoshinobu Inoue "multicast listener query", 685cfa1ca9dSYoshinobu Inoue "multicast listener report", 686cfa1ca9dSYoshinobu Inoue "multicast listener done", 687cfa1ca9dSYoshinobu Inoue "router solicitation", 6886ab55b23SDima Dorfman "router advertisement", 689cfa1ca9dSYoshinobu Inoue "neighbor solicitation", 6906ab55b23SDima Dorfman "neighbor advertisement", 691cfa1ca9dSYoshinobu Inoue "redirect", 692cfa1ca9dSYoshinobu Inoue "router renumbering", 693cfa1ca9dSYoshinobu Inoue "node information request", 694cfa1ca9dSYoshinobu Inoue "node information reply", 695fd555639SMunechika SUMIKAWA "inverse neighbor solicitation", 696fd555639SMunechika SUMIKAWA "inverse neighbor advertisement", 697cfa1ca9dSYoshinobu Inoue "#143", 698cfa1ca9dSYoshinobu Inoue "#144", 699cfa1ca9dSYoshinobu Inoue "#145", 700cfa1ca9dSYoshinobu Inoue "#146", 701cfa1ca9dSYoshinobu Inoue "#147", 702cfa1ca9dSYoshinobu Inoue "#148", 703cfa1ca9dSYoshinobu Inoue "#149", 704cfa1ca9dSYoshinobu Inoue "#150", 705cfa1ca9dSYoshinobu Inoue "#151", 706cfa1ca9dSYoshinobu Inoue "#152", 707cfa1ca9dSYoshinobu Inoue "#153", 708cfa1ca9dSYoshinobu Inoue "#154", 709cfa1ca9dSYoshinobu Inoue "#155", 710cfa1ca9dSYoshinobu Inoue "#156", 711cfa1ca9dSYoshinobu Inoue "#157", 712cfa1ca9dSYoshinobu Inoue "#158", 713cfa1ca9dSYoshinobu Inoue "#159", 714cfa1ca9dSYoshinobu Inoue "#160", 715cfa1ca9dSYoshinobu Inoue "#161", 716cfa1ca9dSYoshinobu Inoue "#162", 717cfa1ca9dSYoshinobu Inoue "#163", 718cfa1ca9dSYoshinobu Inoue "#164", 719cfa1ca9dSYoshinobu Inoue "#165", 720cfa1ca9dSYoshinobu Inoue "#166", 721cfa1ca9dSYoshinobu Inoue "#167", 722cfa1ca9dSYoshinobu Inoue "#168", 723cfa1ca9dSYoshinobu Inoue "#169", 724cfa1ca9dSYoshinobu Inoue "#170", 725cfa1ca9dSYoshinobu Inoue "#171", 726cfa1ca9dSYoshinobu Inoue "#172", 727cfa1ca9dSYoshinobu Inoue "#173", 728cfa1ca9dSYoshinobu Inoue "#174", 729cfa1ca9dSYoshinobu Inoue "#175", 730cfa1ca9dSYoshinobu Inoue "#176", 731cfa1ca9dSYoshinobu Inoue "#177", 732cfa1ca9dSYoshinobu Inoue "#178", 733cfa1ca9dSYoshinobu Inoue "#179", 734cfa1ca9dSYoshinobu Inoue "#180", 735cfa1ca9dSYoshinobu Inoue "#181", 736cfa1ca9dSYoshinobu Inoue "#182", 737cfa1ca9dSYoshinobu Inoue "#183", 738cfa1ca9dSYoshinobu Inoue "#184", 739cfa1ca9dSYoshinobu Inoue "#185", 740cfa1ca9dSYoshinobu Inoue "#186", 741cfa1ca9dSYoshinobu Inoue "#187", 742cfa1ca9dSYoshinobu Inoue "#188", 743cfa1ca9dSYoshinobu Inoue "#189", 744cfa1ca9dSYoshinobu Inoue "#180", 745cfa1ca9dSYoshinobu Inoue "#191", 746cfa1ca9dSYoshinobu Inoue "#192", 747cfa1ca9dSYoshinobu Inoue "#193", 748cfa1ca9dSYoshinobu Inoue "#194", 749cfa1ca9dSYoshinobu Inoue "#195", 750cfa1ca9dSYoshinobu Inoue "#196", 751cfa1ca9dSYoshinobu Inoue "#197", 752cfa1ca9dSYoshinobu Inoue "#198", 753cfa1ca9dSYoshinobu Inoue "#199", 754cfa1ca9dSYoshinobu Inoue "#200", 755cfa1ca9dSYoshinobu Inoue "#201", 756cfa1ca9dSYoshinobu Inoue "#202", 757cfa1ca9dSYoshinobu Inoue "#203", 758cfa1ca9dSYoshinobu Inoue "#204", 759cfa1ca9dSYoshinobu Inoue "#205", 760cfa1ca9dSYoshinobu Inoue "#206", 761cfa1ca9dSYoshinobu Inoue "#207", 762cfa1ca9dSYoshinobu Inoue "#208", 763cfa1ca9dSYoshinobu Inoue "#209", 764cfa1ca9dSYoshinobu Inoue "#210", 765cfa1ca9dSYoshinobu Inoue "#211", 766cfa1ca9dSYoshinobu Inoue "#212", 767cfa1ca9dSYoshinobu Inoue "#213", 768cfa1ca9dSYoshinobu Inoue "#214", 769cfa1ca9dSYoshinobu Inoue "#215", 770cfa1ca9dSYoshinobu Inoue "#216", 771cfa1ca9dSYoshinobu Inoue "#217", 772cfa1ca9dSYoshinobu Inoue "#218", 773cfa1ca9dSYoshinobu Inoue "#219", 774cfa1ca9dSYoshinobu Inoue "#220", 775cfa1ca9dSYoshinobu Inoue "#221", 776cfa1ca9dSYoshinobu Inoue "#222", 777cfa1ca9dSYoshinobu Inoue "#223", 778cfa1ca9dSYoshinobu Inoue "#224", 779cfa1ca9dSYoshinobu Inoue "#225", 780cfa1ca9dSYoshinobu Inoue "#226", 781cfa1ca9dSYoshinobu Inoue "#227", 782cfa1ca9dSYoshinobu Inoue "#228", 783cfa1ca9dSYoshinobu Inoue "#229", 784cfa1ca9dSYoshinobu Inoue "#230", 785cfa1ca9dSYoshinobu Inoue "#231", 786cfa1ca9dSYoshinobu Inoue "#232", 787cfa1ca9dSYoshinobu Inoue "#233", 788cfa1ca9dSYoshinobu Inoue "#234", 789cfa1ca9dSYoshinobu Inoue "#235", 790cfa1ca9dSYoshinobu Inoue "#236", 791cfa1ca9dSYoshinobu Inoue "#237", 792cfa1ca9dSYoshinobu Inoue "#238", 793cfa1ca9dSYoshinobu Inoue "#239", 794cfa1ca9dSYoshinobu Inoue "#240", 795cfa1ca9dSYoshinobu Inoue "#241", 796cfa1ca9dSYoshinobu Inoue "#242", 797cfa1ca9dSYoshinobu Inoue "#243", 798cfa1ca9dSYoshinobu Inoue "#244", 799cfa1ca9dSYoshinobu Inoue "#245", 800cfa1ca9dSYoshinobu Inoue "#246", 801cfa1ca9dSYoshinobu Inoue "#247", 802cfa1ca9dSYoshinobu Inoue "#248", 803cfa1ca9dSYoshinobu Inoue "#249", 804cfa1ca9dSYoshinobu Inoue "#250", 805cfa1ca9dSYoshinobu Inoue "#251", 806cfa1ca9dSYoshinobu Inoue "#252", 807cfa1ca9dSYoshinobu Inoue "#253", 808cfa1ca9dSYoshinobu Inoue "#254", 809cfa1ca9dSYoshinobu Inoue "#255", 810cfa1ca9dSYoshinobu Inoue }; 811cfa1ca9dSYoshinobu Inoue 812cfa1ca9dSYoshinobu Inoue /* 813cfa1ca9dSYoshinobu Inoue * Dump ICMP6 statistics. 814cfa1ca9dSYoshinobu Inoue */ 815cfa1ca9dSYoshinobu Inoue void 816f964d60dSAssar Westerlund icmp6_stats(u_long off __unused, char *name, int af __unused) 817cfa1ca9dSYoshinobu Inoue { 818cfa1ca9dSYoshinobu Inoue struct icmp6stat icmp6stat; 819cfa1ca9dSYoshinobu Inoue register int i, first; 820785d213dSHajimu UMEMOTO int mib[4]; 821785d213dSHajimu UMEMOTO size_t len; 822cfa1ca9dSYoshinobu Inoue 823785d213dSHajimu UMEMOTO mib[0] = CTL_NET; 824785d213dSHajimu UMEMOTO mib[1] = PF_INET6; 825785d213dSHajimu UMEMOTO mib[2] = IPPROTO_ICMPV6; 826785d213dSHajimu UMEMOTO mib[3] = ICMPV6CTL_STATS; 827785d213dSHajimu UMEMOTO 828785d213dSHajimu UMEMOTO len = sizeof icmp6stat; 829785d213dSHajimu UMEMOTO memset(&icmp6stat, 0, len); 830785d213dSHajimu UMEMOTO if (sysctl(mib, 4, &icmp6stat, &len, (void *)0, 0) < 0) 831cfa1ca9dSYoshinobu Inoue return; 832cfa1ca9dSYoshinobu Inoue printf("%s:\n", name); 833cfa1ca9dSYoshinobu Inoue 834cfa1ca9dSYoshinobu Inoue #define p(f, m) if (icmp6stat.f || sflag <= 1) \ 83532cd1d96SJun-ichiro itojun Hagino printf(m, (unsigned long long)icmp6stat.f, plural(icmp6stat.f)) 83632cd1d96SJun-ichiro itojun Hagino #define p_5(f, m) printf(m, (unsigned long long)icmp6stat.f) 837cfa1ca9dSYoshinobu Inoue 83832cd1d96SJun-ichiro itojun Hagino p(icp6s_error, "\t%llu call%s to icmp_error\n"); 839cfa1ca9dSYoshinobu Inoue p(icp6s_canterror, 84032cd1d96SJun-ichiro itojun Hagino "\t%llu error%s not generated because old message was icmp error or so\n"); 841cfa1ca9dSYoshinobu Inoue p(icp6s_toofreq, 84232cd1d96SJun-ichiro itojun Hagino "\t%llu error%s not generated because rate limitation\n"); 843fd555639SMunechika SUMIKAWA #define NELEM (sizeof(icmp6stat.icp6s_outhist)/sizeof(icmp6stat.icp6s_outhist[0])) 844fd555639SMunechika SUMIKAWA for (first = 1, i = 0; i < NELEM; i++) 845cfa1ca9dSYoshinobu Inoue if (icmp6stat.icp6s_outhist[i] != 0) { 846cfa1ca9dSYoshinobu Inoue if (first) { 847cfa1ca9dSYoshinobu Inoue printf("\tOutput histogram:\n"); 848cfa1ca9dSYoshinobu Inoue first = 0; 849cfa1ca9dSYoshinobu Inoue } 85032cd1d96SJun-ichiro itojun Hagino printf("\t\t%s: %llu\n", icmp6names[i], 85132cd1d96SJun-ichiro itojun Hagino (unsigned long long)icmp6stat.icp6s_outhist[i]); 852cfa1ca9dSYoshinobu Inoue } 853fd555639SMunechika SUMIKAWA #undef NELEM 85432cd1d96SJun-ichiro itojun Hagino p(icp6s_badcode, "\t%llu message%s with bad code fields\n"); 85532cd1d96SJun-ichiro itojun Hagino p(icp6s_tooshort, "\t%llu message%s < minimum length\n"); 85632cd1d96SJun-ichiro itojun Hagino p(icp6s_checksum, "\t%llu bad checksum%s\n"); 85732cd1d96SJun-ichiro itojun Hagino p(icp6s_badlen, "\t%llu message%s with bad length\n"); 858fd555639SMunechika SUMIKAWA #define NELEM (sizeof(icmp6stat.icp6s_inhist)/sizeof(icmp6stat.icp6s_inhist[0])) 859fd555639SMunechika SUMIKAWA for (first = 1, i = 0; i < NELEM; i++) 860cfa1ca9dSYoshinobu Inoue if (icmp6stat.icp6s_inhist[i] != 0) { 861cfa1ca9dSYoshinobu Inoue if (first) { 862cfa1ca9dSYoshinobu Inoue printf("\tInput histogram:\n"); 863cfa1ca9dSYoshinobu Inoue first = 0; 864cfa1ca9dSYoshinobu Inoue } 86532cd1d96SJun-ichiro itojun Hagino printf("\t\t%s: %llu\n", icmp6names[i], 86632cd1d96SJun-ichiro itojun Hagino (unsigned long long)icmp6stat.icp6s_inhist[i]); 867cfa1ca9dSYoshinobu Inoue } 868fd555639SMunechika SUMIKAWA #undef NELEM 8696ab55b23SDima Dorfman printf("\tHistogram of error messages to be generated:\n"); 87032cd1d96SJun-ichiro itojun Hagino p_5(icp6s_odst_unreach_noroute, "\t\t%llu no route\n"); 87132cd1d96SJun-ichiro itojun Hagino p_5(icp6s_odst_unreach_admin, "\t\t%llu administratively prohibited\n"); 87232cd1d96SJun-ichiro itojun Hagino p_5(icp6s_odst_unreach_beyondscope, "\t\t%llu beyond scope\n"); 87332cd1d96SJun-ichiro itojun Hagino p_5(icp6s_odst_unreach_addr, "\t\t%llu address unreachable\n"); 87432cd1d96SJun-ichiro itojun Hagino p_5(icp6s_odst_unreach_noport, "\t\t%llu port unreachable\n"); 87532cd1d96SJun-ichiro itojun Hagino p_5(icp6s_opacket_too_big, "\t\t%llu packet too big\n"); 87632cd1d96SJun-ichiro itojun Hagino p_5(icp6s_otime_exceed_transit, "\t\t%llu time exceed transit\n"); 87732cd1d96SJun-ichiro itojun Hagino p_5(icp6s_otime_exceed_reassembly, "\t\t%llu time exceed reassembly\n"); 87832cd1d96SJun-ichiro itojun Hagino p_5(icp6s_oparamprob_header, "\t\t%llu erroneous header field\n"); 87932cd1d96SJun-ichiro itojun Hagino p_5(icp6s_oparamprob_nextheader, "\t\t%llu unrecognized next header\n"); 88032cd1d96SJun-ichiro itojun Hagino p_5(icp6s_oparamprob_option, "\t\t%llu unrecognized option\n"); 88132cd1d96SJun-ichiro itojun Hagino p_5(icp6s_oredirect, "\t\t%llu redirect\n"); 88232cd1d96SJun-ichiro itojun Hagino p_5(icp6s_ounknown, "\t\t%llu unknown\n"); 88332cd1d96SJun-ichiro itojun Hagino 88432cd1d96SJun-ichiro itojun Hagino p(icp6s_reflect, "\t%llu message response%s generated\n"); 88532cd1d96SJun-ichiro itojun Hagino p(icp6s_nd_toomanyopt, "\t%llu message%s with too many ND options\n"); 88633841545SHajimu UMEMOTO p(icp6s_nd_badopt, "\t%qu message%s with bad ND options\n"); 88733841545SHajimu UMEMOTO p(icp6s_badns, "\t%qu bad neighbor solicitation message%s\n"); 88833841545SHajimu UMEMOTO p(icp6s_badna, "\t%qu bad neighbor advertisement message%s\n"); 88933841545SHajimu UMEMOTO p(icp6s_badrs, "\t%qu bad router solicitation message%s\n"); 89033841545SHajimu UMEMOTO p(icp6s_badra, "\t%qu bad router advertisement message%s\n"); 89133841545SHajimu UMEMOTO p(icp6s_badredirect, "\t%qu bad redirect message%s\n"); 89233841545SHajimu UMEMOTO p(icp6s_pmtuchg, "\t%llu path MTU change%s\n"); 893cfa1ca9dSYoshinobu Inoue #undef p 894cfa1ca9dSYoshinobu Inoue #undef p_5 895cfa1ca9dSYoshinobu Inoue } 896cfa1ca9dSYoshinobu Inoue 897cfa1ca9dSYoshinobu Inoue /* 898cfa1ca9dSYoshinobu Inoue * Dump ICMPv6 per-interface statistics based on RFC 2466. 899cfa1ca9dSYoshinobu Inoue */ 900cfa1ca9dSYoshinobu Inoue void 9015e051718SAssar Westerlund icmp6_ifstats(char *ifname) 902cfa1ca9dSYoshinobu Inoue { 903cfa1ca9dSYoshinobu Inoue struct in6_ifreq ifr; 904cfa1ca9dSYoshinobu Inoue int s; 905cfa1ca9dSYoshinobu Inoue #define p(f, m) if (ifr.ifr_ifru.ifru_icmp6stat.f || sflag <= 1) \ 90632cd1d96SJun-ichiro itojun Hagino printf(m, (unsigned long long)ifr.ifr_ifru.ifru_icmp6stat.f, plural(ifr.ifr_ifru.ifru_icmp6stat.f)) 907cfa1ca9dSYoshinobu Inoue 908cfa1ca9dSYoshinobu Inoue if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { 909cfa1ca9dSYoshinobu Inoue perror("Warning: socket(AF_INET6)"); 910cfa1ca9dSYoshinobu Inoue return; 911cfa1ca9dSYoshinobu Inoue } 912cfa1ca9dSYoshinobu Inoue 913cfa1ca9dSYoshinobu Inoue strcpy(ifr.ifr_name, ifname); 914cfa1ca9dSYoshinobu Inoue printf("icmp6 on %s:\n", ifr.ifr_name); 915cfa1ca9dSYoshinobu Inoue 916cfa1ca9dSYoshinobu Inoue if (ioctl(s, SIOCGIFSTAT_ICMP6, (char *)&ifr) < 0) { 917cfa1ca9dSYoshinobu Inoue perror("Warning: ioctl(SIOCGIFSTAT_ICMP6)"); 918cfa1ca9dSYoshinobu Inoue goto end; 919cfa1ca9dSYoshinobu Inoue } 920cfa1ca9dSYoshinobu Inoue 92132cd1d96SJun-ichiro itojun Hagino p(ifs6_in_msg, "\t%llu total input message%s\n"); 92232cd1d96SJun-ichiro itojun Hagino p(ifs6_in_error, "\t%llu total input error message%s\n"); 92332cd1d96SJun-ichiro itojun Hagino p(ifs6_in_dstunreach, "\t%llu input destination unreachable error%s\n"); 92432cd1d96SJun-ichiro itojun Hagino p(ifs6_in_adminprohib, "\t%llu input administratively prohibited error%s\n"); 92532cd1d96SJun-ichiro itojun Hagino p(ifs6_in_timeexceed, "\t%llu input time exceeded error%s\n"); 92632cd1d96SJun-ichiro itojun Hagino p(ifs6_in_paramprob, "\t%llu input parameter problem error%s\n"); 92732cd1d96SJun-ichiro itojun Hagino p(ifs6_in_pkttoobig, "\t%llu input packet too big error%s\n"); 92832cd1d96SJun-ichiro itojun Hagino p(ifs6_in_echo, "\t%llu input echo request%s\n"); 92932cd1d96SJun-ichiro itojun Hagino p(ifs6_in_echoreply, "\t%llu input echo reply%s\n"); 93032cd1d96SJun-ichiro itojun Hagino p(ifs6_in_routersolicit, "\t%llu input router solicitation%s\n"); 93132cd1d96SJun-ichiro itojun Hagino p(ifs6_in_routeradvert, "\t%llu input router advertisement%s\n"); 93232cd1d96SJun-ichiro itojun Hagino p(ifs6_in_neighborsolicit, "\t%llu input neighbor solicitation%s\n"); 93332cd1d96SJun-ichiro itojun Hagino p(ifs6_in_neighboradvert, "\t%llu input neighbor advertisement%s\n"); 93432cd1d96SJun-ichiro itojun Hagino p(ifs6_in_redirect, "\t%llu input redirect%s\n"); 93532cd1d96SJun-ichiro itojun Hagino p(ifs6_in_mldquery, "\t%llu input MLD query%s\n"); 93632cd1d96SJun-ichiro itojun Hagino p(ifs6_in_mldreport, "\t%llu input MLD report%s\n"); 93732cd1d96SJun-ichiro itojun Hagino p(ifs6_in_mlddone, "\t%llu input MLD done%s\n"); 938cfa1ca9dSYoshinobu Inoue 93932cd1d96SJun-ichiro itojun Hagino p(ifs6_out_msg, "\t%llu total output message%s\n"); 94032cd1d96SJun-ichiro itojun Hagino p(ifs6_out_error, "\t%llu total output error message%s\n"); 94132cd1d96SJun-ichiro itojun Hagino p(ifs6_out_dstunreach, "\t%llu output destination unreachable error%s\n"); 94232cd1d96SJun-ichiro itojun Hagino p(ifs6_out_adminprohib, "\t%llu output administratively prohibited error%s\n"); 94332cd1d96SJun-ichiro itojun Hagino p(ifs6_out_timeexceed, "\t%llu output time exceeded error%s\n"); 94432cd1d96SJun-ichiro itojun Hagino p(ifs6_out_paramprob, "\t%llu output parameter problem error%s\n"); 94532cd1d96SJun-ichiro itojun Hagino p(ifs6_out_pkttoobig, "\t%llu output packet too big error%s\n"); 94632cd1d96SJun-ichiro itojun Hagino p(ifs6_out_echo, "\t%llu output echo request%s\n"); 94732cd1d96SJun-ichiro itojun Hagino p(ifs6_out_echoreply, "\t%llu output echo reply%s\n"); 94832cd1d96SJun-ichiro itojun Hagino p(ifs6_out_routersolicit, "\t%llu output router solicitation%s\n"); 94932cd1d96SJun-ichiro itojun Hagino p(ifs6_out_routeradvert, "\t%llu output router advertisement%s\n"); 95032cd1d96SJun-ichiro itojun Hagino p(ifs6_out_neighborsolicit, "\t%llu output neighbor solicitation%s\n"); 95132cd1d96SJun-ichiro itojun Hagino p(ifs6_out_neighboradvert, "\t%llu output neighbor advertisement%s\n"); 95232cd1d96SJun-ichiro itojun Hagino p(ifs6_out_redirect, "\t%llu output redirect%s\n"); 95332cd1d96SJun-ichiro itojun Hagino p(ifs6_out_mldquery, "\t%llu output MLD query%s\n"); 95432cd1d96SJun-ichiro itojun Hagino p(ifs6_out_mldreport, "\t%llu output MLD report%s\n"); 95532cd1d96SJun-ichiro itojun Hagino p(ifs6_out_mlddone, "\t%llu output MLD done%s\n"); 956cfa1ca9dSYoshinobu Inoue 957cfa1ca9dSYoshinobu Inoue end: 958cfa1ca9dSYoshinobu Inoue close(s); 959cfa1ca9dSYoshinobu Inoue #undef p 960cfa1ca9dSYoshinobu Inoue } 961cfa1ca9dSYoshinobu Inoue 962cfa1ca9dSYoshinobu Inoue /* 963cfa1ca9dSYoshinobu Inoue * Dump PIM statistics structure. 964cfa1ca9dSYoshinobu Inoue */ 965cfa1ca9dSYoshinobu Inoue void 966f964d60dSAssar Westerlund pim6_stats(u_long off __unused, char *name, int af __unused) 967cfa1ca9dSYoshinobu Inoue { 968cfa1ca9dSYoshinobu Inoue struct pim6stat pim6stat; 969cfa1ca9dSYoshinobu Inoue 970cfa1ca9dSYoshinobu Inoue if (off == 0) 971cfa1ca9dSYoshinobu Inoue return; 972cfa1ca9dSYoshinobu Inoue kread(off, (char *)&pim6stat, sizeof(pim6stat)); 973cfa1ca9dSYoshinobu Inoue printf("%s:\n", name); 974cfa1ca9dSYoshinobu Inoue 975cfa1ca9dSYoshinobu Inoue #define p(f, m) if (pim6stat.f || sflag <= 1) \ 97632cd1d96SJun-ichiro itojun Hagino printf(m, (unsigned long long)pim6stat.f, plural(pim6stat.f)) 97732cd1d96SJun-ichiro itojun Hagino p(pim6s_rcv_total, "\t%llu message%s received\n"); 97832cd1d96SJun-ichiro itojun Hagino p(pim6s_rcv_tooshort, "\t%llu message%s received with too few bytes\n"); 97932cd1d96SJun-ichiro itojun Hagino p(pim6s_rcv_badsum, "\t%llu message%s received with bad checksum\n"); 98032cd1d96SJun-ichiro itojun Hagino p(pim6s_rcv_badversion, "\t%llu message%s received with bad version\n"); 98132cd1d96SJun-ichiro itojun Hagino p(pim6s_rcv_registers, "\t%llu register%s received\n"); 98232cd1d96SJun-ichiro itojun Hagino p(pim6s_rcv_badregisters, "\t%llu bad register%s received\n"); 98332cd1d96SJun-ichiro itojun Hagino p(pim6s_snd_registers, "\t%llu register%s sent\n"); 984cfa1ca9dSYoshinobu Inoue #undef p 985cfa1ca9dSYoshinobu Inoue } 986cfa1ca9dSYoshinobu Inoue 987cfa1ca9dSYoshinobu Inoue /* 98833841545SHajimu UMEMOTO * Dump raw ip6 statistics structure. 98933841545SHajimu UMEMOTO */ 99033841545SHajimu UMEMOTO void 991f964d60dSAssar Westerlund rip6_stats(u_long off __unused, char *name, int af __unused) 99233841545SHajimu UMEMOTO { 99333841545SHajimu UMEMOTO struct rip6stat rip6stat; 99433841545SHajimu UMEMOTO u_quad_t delivered; 99533841545SHajimu UMEMOTO int mib[4]; 99633841545SHajimu UMEMOTO size_t l; 99733841545SHajimu UMEMOTO 99833841545SHajimu UMEMOTO mib[0] = CTL_NET; 99933841545SHajimu UMEMOTO mib[1] = PF_INET6; 100033841545SHajimu UMEMOTO mib[2] = IPPROTO_IPV6; 100133841545SHajimu UMEMOTO mib[3] = IPV6CTL_RIP6STATS; 100233841545SHajimu UMEMOTO l = sizeof(rip6stat); 100333841545SHajimu UMEMOTO if (sysctl(mib, 4, &rip6stat, &l, NULL, 0) < 0) { 100433841545SHajimu UMEMOTO perror("Warning: sysctl(net.inet6.ip6.rip6stats)"); 100533841545SHajimu UMEMOTO return; 100633841545SHajimu UMEMOTO } 100733841545SHajimu UMEMOTO 100833841545SHajimu UMEMOTO printf("%s:\n", name); 100933841545SHajimu UMEMOTO 101033841545SHajimu UMEMOTO #define p(f, m) if (rip6stat.f || sflag <= 1) \ 101133841545SHajimu UMEMOTO printf(m, (unsigned long long)rip6stat.f, plural(rip6stat.f)) 101233841545SHajimu UMEMOTO p(rip6s_ipackets, "\t%llu message%s received\n"); 101333841545SHajimu UMEMOTO p(rip6s_isum, "\t%llu checksum calcuration%s on inbound\n"); 101433841545SHajimu UMEMOTO p(rip6s_badsum, "\t%llu message%s with bad checksum\n"); 101533841545SHajimu UMEMOTO p(rip6s_nosock, "\t%llu message%s dropped due to no socket\n"); 101633841545SHajimu UMEMOTO p(rip6s_nosockmcast, 101733841545SHajimu UMEMOTO "\t%llu multicast message%s dropped due to no socket\n"); 101833841545SHajimu UMEMOTO p(rip6s_fullsock, 101933841545SHajimu UMEMOTO "\t%llu message%s dropped due to full socket buffers\n"); 102033841545SHajimu UMEMOTO delivered = rip6stat.rip6s_ipackets - 102133841545SHajimu UMEMOTO rip6stat.rip6s_badsum - 102233841545SHajimu UMEMOTO rip6stat.rip6s_nosock - 102333841545SHajimu UMEMOTO rip6stat.rip6s_nosockmcast - 102433841545SHajimu UMEMOTO rip6stat.rip6s_fullsock; 102533841545SHajimu UMEMOTO if (delivered || sflag <= 1) 102633841545SHajimu UMEMOTO printf("\t%llu delivered\n", (unsigned long long)delivered); 102733841545SHajimu UMEMOTO p(rip6s_opackets, "\t%llu datagram%s output\n"); 102833841545SHajimu UMEMOTO #undef p 102933841545SHajimu UMEMOTO } 103033841545SHajimu UMEMOTO 103133841545SHajimu UMEMOTO /* 1032cfa1ca9dSYoshinobu Inoue * Pretty print an Internet address (net address + port). 103365ea0024SAssar Westerlund * Take numeric_addr and numeric_port into consideration. 1034cfa1ca9dSYoshinobu Inoue */ 1035cfa1ca9dSYoshinobu Inoue #define GETSERVBYPORT6(port, proto, ret)\ 1036cfa1ca9dSYoshinobu Inoue {\ 1037cfa1ca9dSYoshinobu Inoue if (strcmp((proto), "tcp6") == 0)\ 1038cfa1ca9dSYoshinobu Inoue (ret) = getservbyport((int)(port), "tcp");\ 1039cfa1ca9dSYoshinobu Inoue else if (strcmp((proto), "udp6") == 0)\ 1040cfa1ca9dSYoshinobu Inoue (ret) = getservbyport((int)(port), "udp");\ 1041cfa1ca9dSYoshinobu Inoue else\ 1042cfa1ca9dSYoshinobu Inoue (ret) = getservbyport((int)(port), (proto));\ 1043cfa1ca9dSYoshinobu Inoue }; 1044cfa1ca9dSYoshinobu Inoue 1045cfa1ca9dSYoshinobu Inoue void 10465e051718SAssar Westerlund inet6print(struct in6_addr *in6, int port, char *proto, int numeric) 1047cfa1ca9dSYoshinobu Inoue { 1048cfa1ca9dSYoshinobu Inoue struct servent *sp = 0; 1049cfa1ca9dSYoshinobu Inoue char line[80], *cp; 1050cfa1ca9dSYoshinobu Inoue int width; 1051cfa1ca9dSYoshinobu Inoue 1052cfa1ca9dSYoshinobu Inoue sprintf(line, "%.*s.", lflag ? 39 : 1053cfa1ca9dSYoshinobu Inoue (Aflag && !numeric) ? 12 : 16, inet6name(in6)); 1054cfa1ca9dSYoshinobu Inoue cp = index(line, '\0'); 1055cfa1ca9dSYoshinobu Inoue if (!numeric && port) 1056cfa1ca9dSYoshinobu Inoue GETSERVBYPORT6(port, proto, sp); 1057cfa1ca9dSYoshinobu Inoue if (sp || port == 0) 1058cfa1ca9dSYoshinobu Inoue sprintf(cp, "%.8s", sp ? sp->s_name : "*"); 1059cfa1ca9dSYoshinobu Inoue else 1060cfa1ca9dSYoshinobu Inoue sprintf(cp, "%d", ntohs((u_short)port)); 1061cfa1ca9dSYoshinobu Inoue width = lflag ? 45 : Aflag ? 18 : 22; 1062cfa1ca9dSYoshinobu Inoue printf("%-*.*s ", width, width, line); 1063cfa1ca9dSYoshinobu Inoue } 1064cfa1ca9dSYoshinobu Inoue 1065cfa1ca9dSYoshinobu Inoue /* 1066cfa1ca9dSYoshinobu Inoue * Construct an Internet address representation. 106765ea0024SAssar Westerlund * If the numeric_addr has been supplied, give 1068cfa1ca9dSYoshinobu Inoue * numeric value, otherwise try for symbolic name. 1069cfa1ca9dSYoshinobu Inoue */ 1070cfa1ca9dSYoshinobu Inoue 1071cfa1ca9dSYoshinobu Inoue char * 10725e051718SAssar Westerlund inet6name(struct in6_addr *in6p) 1073cfa1ca9dSYoshinobu Inoue { 1074cfa1ca9dSYoshinobu Inoue register char *cp; 1075cfa1ca9dSYoshinobu Inoue static char line[50]; 1076cfa1ca9dSYoshinobu Inoue struct hostent *hp; 1077d121b556SBrian Somers static char domain[MAXHOSTNAMELEN]; 1078cfa1ca9dSYoshinobu Inoue static int first = 1; 1079cfa1ca9dSYoshinobu Inoue 108065ea0024SAssar Westerlund if (first && !numeric_addr) { 1081cfa1ca9dSYoshinobu Inoue first = 0; 1082cfa1ca9dSYoshinobu Inoue if (gethostname(domain, MAXHOSTNAMELEN) == 0 && 1083cfa1ca9dSYoshinobu Inoue (cp = index(domain, '.'))) 1084cfa1ca9dSYoshinobu Inoue (void) strcpy(domain, cp + 1); 1085cfa1ca9dSYoshinobu Inoue else 1086cfa1ca9dSYoshinobu Inoue domain[0] = 0; 1087cfa1ca9dSYoshinobu Inoue } 1088cfa1ca9dSYoshinobu Inoue cp = 0; 108965ea0024SAssar Westerlund if (!numeric_addr && !IN6_IS_ADDR_UNSPECIFIED(in6p)) { 1090cfa1ca9dSYoshinobu Inoue hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6); 1091cfa1ca9dSYoshinobu Inoue if (hp) { 1092cfa1ca9dSYoshinobu Inoue if ((cp = index(hp->h_name, '.')) && 1093cfa1ca9dSYoshinobu Inoue !strcmp(cp + 1, domain)) 1094cfa1ca9dSYoshinobu Inoue *cp = 0; 1095cfa1ca9dSYoshinobu Inoue cp = hp->h_name; 1096cfa1ca9dSYoshinobu Inoue } 1097cfa1ca9dSYoshinobu Inoue } 1098cfa1ca9dSYoshinobu Inoue if (IN6_IS_ADDR_UNSPECIFIED(in6p)) 1099cfa1ca9dSYoshinobu Inoue strcpy(line, "*"); 1100cfa1ca9dSYoshinobu Inoue else if (cp) 1101cfa1ca9dSYoshinobu Inoue strcpy(line, cp); 1102cfa1ca9dSYoshinobu Inoue else 1103cfa1ca9dSYoshinobu Inoue sprintf(line, "%s", 1104cfa1ca9dSYoshinobu Inoue inet_ntop(AF_INET6, (void *)in6p, ntop_buf, 1105cfa1ca9dSYoshinobu Inoue sizeof(ntop_buf))); 1106cfa1ca9dSYoshinobu Inoue return (line); 1107cfa1ca9dSYoshinobu Inoue } 1108d84a1df4SHajimu UMEMOTO #endif /*INET6*/ 1109