1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate /* 28*0Sstevel@tonic-gate * Copyright (c) 1990 Mentat Inc. 29*0Sstevel@tonic-gate * netstat.c 2.2, last change 9/9/91 30*0Sstevel@tonic-gate * MROUTING Revision 3.5 31*0Sstevel@tonic-gate */ 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 34*0Sstevel@tonic-gate 35*0Sstevel@tonic-gate /* 36*0Sstevel@tonic-gate * simple netstat based on snmp/mib-2 interface to the TCP/IP stack 37*0Sstevel@tonic-gate * 38*0Sstevel@tonic-gate * NOTES: 39*0Sstevel@tonic-gate * 1. A comment "LINTED: (note 1)" appears before certain lines where 40*0Sstevel@tonic-gate * lint would have complained, "pointer cast may result in improper 41*0Sstevel@tonic-gate * alignment". These are lines where lint had suspected potential 42*0Sstevel@tonic-gate * improper alignment of a data structure; in each such situation 43*0Sstevel@tonic-gate * we have relied on the kernel guaranteeing proper alignment. 44*0Sstevel@tonic-gate * 2. Some 'for' loops have been commented as "'for' loop 1", etc 45*0Sstevel@tonic-gate * because they have 'continue' or 'break' statements in their 46*0Sstevel@tonic-gate * bodies. 'continue' statements have been used inside some loops 47*0Sstevel@tonic-gate * where avoiding them would have led to deep levels of indentation. 48*0Sstevel@tonic-gate * 49*0Sstevel@tonic-gate * TODO: 50*0Sstevel@tonic-gate * Add ability to request subsets from kernel (with level = MIB2_IP; 51*0Sstevel@tonic-gate * name = 0 meaning everything for compatibility) 52*0Sstevel@tonic-gate */ 53*0Sstevel@tonic-gate 54*0Sstevel@tonic-gate #include <stdio.h> 55*0Sstevel@tonic-gate #include <stdlib.h> 56*0Sstevel@tonic-gate #include <stdarg.h> 57*0Sstevel@tonic-gate #include <unistd.h> 58*0Sstevel@tonic-gate #include <strings.h> 59*0Sstevel@tonic-gate #include <string.h> 60*0Sstevel@tonic-gate #include <errno.h> 61*0Sstevel@tonic-gate #include <ctype.h> 62*0Sstevel@tonic-gate #include <kstat.h> 63*0Sstevel@tonic-gate #include <assert.h> 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate #include <sys/types.h> 66*0Sstevel@tonic-gate #include <sys/stream.h> 67*0Sstevel@tonic-gate #include <stropts.h> 68*0Sstevel@tonic-gate #include <sys/strstat.h> 69*0Sstevel@tonic-gate #include <sys/sysmacros.h> 70*0Sstevel@tonic-gate #include <sys/tihdr.h> 71*0Sstevel@tonic-gate 72*0Sstevel@tonic-gate #include <sys/socket.h> 73*0Sstevel@tonic-gate #include <sys/sockio.h> 74*0Sstevel@tonic-gate #include <netinet/in.h> 75*0Sstevel@tonic-gate #include <net/if.h> 76*0Sstevel@tonic-gate #include <net/route.h> 77*0Sstevel@tonic-gate 78*0Sstevel@tonic-gate #include <inet/common.h> 79*0Sstevel@tonic-gate #include <inet/mib2.h> 80*0Sstevel@tonic-gate #include <inet/ip.h> 81*0Sstevel@tonic-gate #include <inet/arp.h> 82*0Sstevel@tonic-gate #include <inet/tcp.h> 83*0Sstevel@tonic-gate #include <netinet/igmp_var.h> 84*0Sstevel@tonic-gate #include <netinet/ip_mroute.h> 85*0Sstevel@tonic-gate 86*0Sstevel@tonic-gate #include <arpa/inet.h> 87*0Sstevel@tonic-gate #include <netdb.h> 88*0Sstevel@tonic-gate #include <fcntl.h> 89*0Sstevel@tonic-gate #include <sys/systeminfo.h> 90*0Sstevel@tonic-gate #include <arpa/inet.h> 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate #include <netinet/dhcp.h> 93*0Sstevel@tonic-gate #include <dhcpagent_ipc.h> 94*0Sstevel@tonic-gate #include <dhcpagent_util.h> 95*0Sstevel@tonic-gate #include <compat.h> 96*0Sstevel@tonic-gate 97*0Sstevel@tonic-gate extern void unixpr(kstat_ctl_t *kc); 98*0Sstevel@tonic-gate extern void setifdhcp(const char *caller, const char *ifname, 99*0Sstevel@tonic-gate int argc, char *argv[]); 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gate #define STR_EXPAND 4 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate #define V4MASK_TO_V6(v4, v6) ((v6)._S6_un._S6_u32[0] = 0xfffffffful, \ 104*0Sstevel@tonic-gate (v6)._S6_un._S6_u32[1] = 0xfffffffful, \ 105*0Sstevel@tonic-gate (v6)._S6_un._S6_u32[2] = 0xfffffffful, \ 106*0Sstevel@tonic-gate (v6)._S6_un._S6_u32[3] = (v4)) 107*0Sstevel@tonic-gate 108*0Sstevel@tonic-gate #define IN6_IS_V4MASK(v6) ((v6)._S6_un._S6_u32[0] == 0xfffffffful && \ 109*0Sstevel@tonic-gate (v6)._S6_un._S6_u32[1] == 0xfffffffful && \ 110*0Sstevel@tonic-gate (v6)._S6_un._S6_u32[2] == 0xfffffffful) 111*0Sstevel@tonic-gate 112*0Sstevel@tonic-gate typedef struct mib_item_s { 113*0Sstevel@tonic-gate struct mib_item_s *next_item; 114*0Sstevel@tonic-gate int group; 115*0Sstevel@tonic-gate int mib_id; 116*0Sstevel@tonic-gate int length; 117*0Sstevel@tonic-gate void *valp; 118*0Sstevel@tonic-gate } mib_item_t; 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate struct ifstat { 121*0Sstevel@tonic-gate uint64_t ipackets; 122*0Sstevel@tonic-gate uint64_t ierrors; 123*0Sstevel@tonic-gate uint64_t opackets; 124*0Sstevel@tonic-gate uint64_t oerrors; 125*0Sstevel@tonic-gate uint64_t collisions; 126*0Sstevel@tonic-gate }; 127*0Sstevel@tonic-gate 128*0Sstevel@tonic-gate struct iflist { 129*0Sstevel@tonic-gate struct iflist *next_if; 130*0Sstevel@tonic-gate char ifname[LIFNAMSIZ]; 131*0Sstevel@tonic-gate struct ifstat tot; 132*0Sstevel@tonic-gate }; 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate static mib_item_t *mibget(int sd); 135*0Sstevel@tonic-gate static void mibfree(mib_item_t *firstitem); 136*0Sstevel@tonic-gate static int mibopen(void); 137*0Sstevel@tonic-gate static void mib_get_constants(mib_item_t *item); 138*0Sstevel@tonic-gate static mib_item_t *mib_item_dup(mib_item_t *item); 139*0Sstevel@tonic-gate static mib_item_t *mib_item_diff(mib_item_t *item1, 140*0Sstevel@tonic-gate mib_item_t *item2); 141*0Sstevel@tonic-gate static void mib_item_destroy(mib_item_t **item); 142*0Sstevel@tonic-gate 143*0Sstevel@tonic-gate static boolean_t octetstrmatch(const Octet_t *a, const Octet_t *b); 144*0Sstevel@tonic-gate static char *octetstr(Octet_t *op, int code, 145*0Sstevel@tonic-gate char *dst, uint_t dstlen); 146*0Sstevel@tonic-gate static char *pr_addr(uint_t addr, 147*0Sstevel@tonic-gate char *dst, uint_t dstlen); 148*0Sstevel@tonic-gate static char *pr_addrnz(ipaddr_t addr, char *dst, uint_t dstlen); 149*0Sstevel@tonic-gate static char *pr_addr6(const in6_addr_t *addr, 150*0Sstevel@tonic-gate char *dst, uint_t dstlen); 151*0Sstevel@tonic-gate static char *pr_mask(uint_t addr, 152*0Sstevel@tonic-gate char *dst, uint_t dstlen); 153*0Sstevel@tonic-gate static char *pr_prefix6(struct in6_addr *addr, uint_t prefixlen, 154*0Sstevel@tonic-gate char *dst, uint_t dstlen); 155*0Sstevel@tonic-gate static char *pr_ap(uint_t addr, uint_t port, 156*0Sstevel@tonic-gate char *proto, char *dst, uint_t dstlen); 157*0Sstevel@tonic-gate static char *pr_ap6(const in6_addr_t *addr, uint_t port, 158*0Sstevel@tonic-gate char *proto, char *dst, uint_t dstlen); 159*0Sstevel@tonic-gate static char *pr_net(uint_t addr, uint_t mask, 160*0Sstevel@tonic-gate char *dst, uint_t dstlen); 161*0Sstevel@tonic-gate static char *pr_netaddr(uint_t addr, uint_t mask, 162*0Sstevel@tonic-gate char *dst, uint_t dstlen); 163*0Sstevel@tonic-gate static char *pr_netclassless(ipaddr_t addr, ipaddr_t mask, 164*0Sstevel@tonic-gate char *dst, size_t dstlen); 165*0Sstevel@tonic-gate static char *fmodestr(uint_t fmode); 166*0Sstevel@tonic-gate static char *portname(uint_t port, char *proto, 167*0Sstevel@tonic-gate char *dst, uint_t dstlen); 168*0Sstevel@tonic-gate 169*0Sstevel@tonic-gate static char *mitcp_state(int code); 170*0Sstevel@tonic-gate 171*0Sstevel@tonic-gate static void stat_report(mib_item_t *item); 172*0Sstevel@tonic-gate static void mrt_stat_report(mib_item_t *item); 173*0Sstevel@tonic-gate static void arp_report(mib_item_t *item); 174*0Sstevel@tonic-gate static void ndp_report(mib_item_t *item); 175*0Sstevel@tonic-gate static void mrt_report(mib_item_t *item); 176*0Sstevel@tonic-gate static void if_stat_total(struct ifstat *oldstats, 177*0Sstevel@tonic-gate struct ifstat *newstats, struct ifstat *sumstats); 178*0Sstevel@tonic-gate static void if_report(mib_item_t *item, char *ifname, 179*0Sstevel@tonic-gate int Iflag_only, boolean_t once_only); 180*0Sstevel@tonic-gate static void if_report_ip4(mib2_ipAddrEntry_t *ap, 181*0Sstevel@tonic-gate char ifname[], char logintname[], 182*0Sstevel@tonic-gate struct ifstat *statptr, boolean_t ksp_not_null); 183*0Sstevel@tonic-gate static void if_report_ip6(mib2_ipv6AddrEntry_t *ap6, 184*0Sstevel@tonic-gate char ifname[], char logintname[], 185*0Sstevel@tonic-gate struct ifstat *statptr, boolean_t ksp_not_null); 186*0Sstevel@tonic-gate static void ire_report(mib_item_t *item); 187*0Sstevel@tonic-gate static void tcp_report(mib_item_t *item); 188*0Sstevel@tonic-gate static void udp_report(mib_item_t *item); 189*0Sstevel@tonic-gate static void group_report(mib_item_t *item); 190*0Sstevel@tonic-gate static void print_ip_stats(mib2_ip_t *ip); 191*0Sstevel@tonic-gate static void print_icmp_stats(mib2_icmp_t *icmp); 192*0Sstevel@tonic-gate static void print_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6); 193*0Sstevel@tonic-gate static void print_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6); 194*0Sstevel@tonic-gate static void print_sctp_stats(mib2_sctp_t *tcp); 195*0Sstevel@tonic-gate static void print_tcp_stats(mib2_tcp_t *tcp); 196*0Sstevel@tonic-gate static void print_udp_stats(mib2_udp_t *udp); 197*0Sstevel@tonic-gate static void print_rawip_stats(mib2_rawip_t *rawip); 198*0Sstevel@tonic-gate static void print_igmp_stats(struct igmpstat *igps); 199*0Sstevel@tonic-gate static void print_mrt_stats(struct mrtstat *mrts); 200*0Sstevel@tonic-gate static void sctp_report(mib_item_t *item); 201*0Sstevel@tonic-gate static void sum_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6, 202*0Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t *sum6); 203*0Sstevel@tonic-gate static void sum_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6, 204*0Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t *sum6); 205*0Sstevel@tonic-gate static void m_report(void); 206*0Sstevel@tonic-gate static void dhcp_report(char *); 207*0Sstevel@tonic-gate 208*0Sstevel@tonic-gate void fail(int, char *, ...); 209*0Sstevel@tonic-gate static uint64_t kstat_named_value(kstat_t *, char *); 210*0Sstevel@tonic-gate static kid_t safe_kstat_read(kstat_ctl_t *, kstat_t *, void *); 211*0Sstevel@tonic-gate static int isnum(char *); 212*0Sstevel@tonic-gate static char *plural(int n); 213*0Sstevel@tonic-gate static char *pluraly(int n); 214*0Sstevel@tonic-gate static char *plurales(int n); 215*0Sstevel@tonic-gate static void process_filter(char *arg); 216*0Sstevel@tonic-gate static boolean_t family_selected(int family); 217*0Sstevel@tonic-gate 218*0Sstevel@tonic-gate static void usage(char *); 219*0Sstevel@tonic-gate static void fatal(int errcode, char *str1, ...); 220*0Sstevel@tonic-gate 221*0Sstevel@tonic-gate #define PLURAL(n) plural((int)n) 222*0Sstevel@tonic-gate #define PLURALY(n) pluraly((int)n) 223*0Sstevel@tonic-gate #define PLURALES(n) plurales((int)n) 224*0Sstevel@tonic-gate #define IFLAGMOD(flg, val1, val2) if (flg == val1) flg = val2 225*0Sstevel@tonic-gate #define MDIFF(diff, elem2, elem1, member) (diff)->member = \ 226*0Sstevel@tonic-gate (elem2)->member - (elem1)->member 227*0Sstevel@tonic-gate 228*0Sstevel@tonic-gate 229*0Sstevel@tonic-gate static boolean_t Aflag = B_FALSE; /* All sockets/ifs/rtng-tbls */ 230*0Sstevel@tonic-gate static boolean_t Dflag = B_FALSE; /* Debug Info */ 231*0Sstevel@tonic-gate static boolean_t Iflag = B_FALSE; /* IP Traffic Interfaces */ 232*0Sstevel@tonic-gate static boolean_t Mflag = B_FALSE; /* STREAMS Memory Statistics */ 233*0Sstevel@tonic-gate static boolean_t Nflag = B_FALSE; /* Numeric Network Addresses */ 234*0Sstevel@tonic-gate static boolean_t Rflag = B_FALSE; /* Routing Tables */ 235*0Sstevel@tonic-gate static boolean_t Sflag = B_FALSE; /* Per-protocol Statistics */ 236*0Sstevel@tonic-gate static boolean_t Vflag = B_FALSE; /* Verbose */ 237*0Sstevel@tonic-gate static boolean_t Pflag = B_FALSE; /* Net to Media Tables */ 238*0Sstevel@tonic-gate static boolean_t Gflag = B_FALSE; /* Multicast group membership */ 239*0Sstevel@tonic-gate static boolean_t MMflag = B_FALSE; /* Multicast routing table */ 240*0Sstevel@tonic-gate static boolean_t DHCPflag = B_FALSE; /* DHCP statistics */ 241*0Sstevel@tonic-gate 242*0Sstevel@tonic-gate static int v4compat = 0; /* Compatible printing format for status */ 243*0Sstevel@tonic-gate 244*0Sstevel@tonic-gate static int proto = IPPROTO_MAX; /* all protocols */ 245*0Sstevel@tonic-gate kstat_ctl_t *kc = NULL; 246*0Sstevel@tonic-gate 247*0Sstevel@tonic-gate /* 248*0Sstevel@tonic-gate * Sizes of data structures extracted from the base mib. 249*0Sstevel@tonic-gate * This allows the size of the tables entries to grow while preserving 250*0Sstevel@tonic-gate * binary compatibility. 251*0Sstevel@tonic-gate */ 252*0Sstevel@tonic-gate static int ipAddrEntrySize; 253*0Sstevel@tonic-gate static int ipRouteEntrySize; 254*0Sstevel@tonic-gate static int ipNetToMediaEntrySize; 255*0Sstevel@tonic-gate static int ipMemberEntrySize; 256*0Sstevel@tonic-gate static int ipGroupSourceEntrySize; 257*0Sstevel@tonic-gate static int vifctlSize; 258*0Sstevel@tonic-gate static int mfcctlSize; 259*0Sstevel@tonic-gate 260*0Sstevel@tonic-gate static int ipv6IfStatsEntrySize; 261*0Sstevel@tonic-gate static int ipv6IfIcmpEntrySize; 262*0Sstevel@tonic-gate static int ipv6AddrEntrySize; 263*0Sstevel@tonic-gate static int ipv6RouteEntrySize; 264*0Sstevel@tonic-gate static int ipv6NetToMediaEntrySize; 265*0Sstevel@tonic-gate static int ipv6MemberEntrySize; 266*0Sstevel@tonic-gate static int ipv6GroupSourceEntrySize; 267*0Sstevel@tonic-gate 268*0Sstevel@tonic-gate static int tcpConnEntrySize; 269*0Sstevel@tonic-gate static int tcp6ConnEntrySize; 270*0Sstevel@tonic-gate static int udpEntrySize; 271*0Sstevel@tonic-gate static int udp6EntrySize; 272*0Sstevel@tonic-gate static int sctpEntrySize; 273*0Sstevel@tonic-gate static int sctpLocalEntrySize; 274*0Sstevel@tonic-gate static int sctpRemoteEntrySize; 275*0Sstevel@tonic-gate 276*0Sstevel@tonic-gate #define protocol_selected(p) (proto == IPPROTO_MAX || proto == (p)) 277*0Sstevel@tonic-gate 278*0Sstevel@tonic-gate /* Machinery used for -f (filter) option */ 279*0Sstevel@tonic-gate #define FK_AF 0 280*0Sstevel@tonic-gate #define FK_INIF 1 281*0Sstevel@tonic-gate #define FK_OUTIF 2 282*0Sstevel@tonic-gate #define FK_SRC 3 283*0Sstevel@tonic-gate #define FK_DST 4 284*0Sstevel@tonic-gate #define FK_FLAGS 5 285*0Sstevel@tonic-gate #define NFILTERKEYS 6 286*0Sstevel@tonic-gate 287*0Sstevel@tonic-gate static const char *filter_keys[NFILTERKEYS] = { 288*0Sstevel@tonic-gate "af", "inif", "outif", "src", "dst", "flags" 289*0Sstevel@tonic-gate }; 290*0Sstevel@tonic-gate 291*0Sstevel@tonic-gate /* Flags on routes */ 292*0Sstevel@tonic-gate #define FLF_A 0x00000001 293*0Sstevel@tonic-gate #define FLF_B 0x00000002 294*0Sstevel@tonic-gate #define FLF_D 0x00000004 295*0Sstevel@tonic-gate #define FLF_G 0x00000008 296*0Sstevel@tonic-gate #define FLF_H 0x00000010 297*0Sstevel@tonic-gate #define FLF_L 0x00000020 298*0Sstevel@tonic-gate #define FLF_U 0x00000040 299*0Sstevel@tonic-gate #define FLF_M 0x00000080 300*0Sstevel@tonic-gate #define FLF_S 0x00000100 301*0Sstevel@tonic-gate static const char flag_list[] = "ABDGHLUMS"; 302*0Sstevel@tonic-gate 303*0Sstevel@tonic-gate typedef struct filter_rule filter_t; 304*0Sstevel@tonic-gate 305*0Sstevel@tonic-gate struct filter_rule { 306*0Sstevel@tonic-gate filter_t *f_next; 307*0Sstevel@tonic-gate union { 308*0Sstevel@tonic-gate int f_family; 309*0Sstevel@tonic-gate const char *f_ifname; 310*0Sstevel@tonic-gate struct { 311*0Sstevel@tonic-gate struct hostent *f_address; 312*0Sstevel@tonic-gate in6_addr_t f_mask; 313*0Sstevel@tonic-gate } a; 314*0Sstevel@tonic-gate struct { 315*0Sstevel@tonic-gate uint_t f_flagset; 316*0Sstevel@tonic-gate uint_t f_flagclear; 317*0Sstevel@tonic-gate } f; 318*0Sstevel@tonic-gate } u; 319*0Sstevel@tonic-gate }; 320*0Sstevel@tonic-gate 321*0Sstevel@tonic-gate /* 322*0Sstevel@tonic-gate * The user-specified filters are linked into lists separated by 323*0Sstevel@tonic-gate * keyword (type of filter). Thus, the matching algorithm is: 324*0Sstevel@tonic-gate * For each non-empty filter list 325*0Sstevel@tonic-gate * If no filters in the list match 326*0Sstevel@tonic-gate * then stop here; route doesn't match 327*0Sstevel@tonic-gate * If loop above completes, then route does match and will be 328*0Sstevel@tonic-gate * displayed. 329*0Sstevel@tonic-gate */ 330*0Sstevel@tonic-gate static filter_t *filters[NFILTERKEYS]; 331*0Sstevel@tonic-gate 332*0Sstevel@tonic-gate int 333*0Sstevel@tonic-gate main(int argc, char **argv) 334*0Sstevel@tonic-gate { 335*0Sstevel@tonic-gate char *name; 336*0Sstevel@tonic-gate mib_item_t *item = NULL; 337*0Sstevel@tonic-gate mib_item_t *previtem = NULL; 338*0Sstevel@tonic-gate int sd = -1; 339*0Sstevel@tonic-gate char *ifname = NULL; 340*0Sstevel@tonic-gate int interval = 0; /* Single time by default */ 341*0Sstevel@tonic-gate int count = -1; /* Forever */ 342*0Sstevel@tonic-gate int c; 343*0Sstevel@tonic-gate int d; 344*0Sstevel@tonic-gate /* 345*0Sstevel@tonic-gate * Possible values of 'Iflag_only': 346*0Sstevel@tonic-gate * -1, no feature-flags; 347*0Sstevel@tonic-gate * 0, IFlag and other feature-flags enabled 348*0Sstevel@tonic-gate * 1, IFlag is the only feature-flag enabled 349*0Sstevel@tonic-gate * : trinary variable, modified using IFLAGMOD() 350*0Sstevel@tonic-gate */ 351*0Sstevel@tonic-gate int Iflag_only = -1; 352*0Sstevel@tonic-gate boolean_t once_only = B_FALSE; /* '-i' with count > 1 */ 353*0Sstevel@tonic-gate extern char *optarg; 354*0Sstevel@tonic-gate extern int optind; 355*0Sstevel@tonic-gate char *default_ip_str = NULL; 356*0Sstevel@tonic-gate 357*0Sstevel@tonic-gate name = argv[0]; 358*0Sstevel@tonic-gate 359*0Sstevel@tonic-gate v4compat = get_compat_flag(&default_ip_str); 360*0Sstevel@tonic-gate if (v4compat == DEFAULT_PROT_BAD_VALUE) 361*0Sstevel@tonic-gate fatal(2, "%s: %s: Bad value for %s in %s\n", name, 362*0Sstevel@tonic-gate default_ip_str, DEFAULT_IP, INET_DEFAULT_FILE); 363*0Sstevel@tonic-gate free(default_ip_str); 364*0Sstevel@tonic-gate 365*0Sstevel@tonic-gate while ((c = getopt(argc, argv, "adimnrspMgvf:P:I:D")) != -1) { 366*0Sstevel@tonic-gate switch ((char)c) { 367*0Sstevel@tonic-gate case 'a': /* all connections */ 368*0Sstevel@tonic-gate Aflag = B_TRUE; 369*0Sstevel@tonic-gate break; 370*0Sstevel@tonic-gate 371*0Sstevel@tonic-gate case 'd': /* turn on debugging */ 372*0Sstevel@tonic-gate Dflag = B_TRUE; 373*0Sstevel@tonic-gate break; 374*0Sstevel@tonic-gate 375*0Sstevel@tonic-gate case 'i': /* interface (ill/ipif report) */ 376*0Sstevel@tonic-gate Iflag = B_TRUE; 377*0Sstevel@tonic-gate IFLAGMOD(Iflag_only, -1, 1); /* '-i' exists */ 378*0Sstevel@tonic-gate break; 379*0Sstevel@tonic-gate 380*0Sstevel@tonic-gate case 'm': /* streams msg report */ 381*0Sstevel@tonic-gate Mflag = B_TRUE; 382*0Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */ 383*0Sstevel@tonic-gate break; 384*0Sstevel@tonic-gate 385*0Sstevel@tonic-gate case 'n': /* numeric format */ 386*0Sstevel@tonic-gate Nflag = B_TRUE; 387*0Sstevel@tonic-gate break; 388*0Sstevel@tonic-gate 389*0Sstevel@tonic-gate case 'r': /* route tables */ 390*0Sstevel@tonic-gate Rflag = B_TRUE; 391*0Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */ 392*0Sstevel@tonic-gate break; 393*0Sstevel@tonic-gate 394*0Sstevel@tonic-gate case 's': /* per-protocol statistics */ 395*0Sstevel@tonic-gate Sflag = B_TRUE; 396*0Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */ 397*0Sstevel@tonic-gate break; 398*0Sstevel@tonic-gate 399*0Sstevel@tonic-gate case 'p': /* arp/ndp table */ 400*0Sstevel@tonic-gate Pflag = B_TRUE; 401*0Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */ 402*0Sstevel@tonic-gate break; 403*0Sstevel@tonic-gate 404*0Sstevel@tonic-gate case 'M': /* multicast routing tables */ 405*0Sstevel@tonic-gate MMflag = B_TRUE; 406*0Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */ 407*0Sstevel@tonic-gate break; 408*0Sstevel@tonic-gate 409*0Sstevel@tonic-gate case 'g': /* multicast group membership */ 410*0Sstevel@tonic-gate Gflag = B_TRUE; 411*0Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */ 412*0Sstevel@tonic-gate break; 413*0Sstevel@tonic-gate 414*0Sstevel@tonic-gate case 'v': /* verbose output format */ 415*0Sstevel@tonic-gate Vflag = B_TRUE; 416*0Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */ 417*0Sstevel@tonic-gate break; 418*0Sstevel@tonic-gate 419*0Sstevel@tonic-gate case 'f': 420*0Sstevel@tonic-gate process_filter(optarg); 421*0Sstevel@tonic-gate break; 422*0Sstevel@tonic-gate 423*0Sstevel@tonic-gate case 'P': 424*0Sstevel@tonic-gate if (strcmp(optarg, "ip") == 0) { 425*0Sstevel@tonic-gate proto = IPPROTO_IP; 426*0Sstevel@tonic-gate } else if (strcmp(optarg, "ipv6") == 0 || 427*0Sstevel@tonic-gate strcmp(optarg, "ip6") == 0) { 428*0Sstevel@tonic-gate v4compat = 0; /* Overridden */ 429*0Sstevel@tonic-gate proto = IPPROTO_IPV6; 430*0Sstevel@tonic-gate } else if (strcmp(optarg, "icmp") == 0) { 431*0Sstevel@tonic-gate proto = IPPROTO_ICMP; 432*0Sstevel@tonic-gate } else if (strcmp(optarg, "icmpv6") == 0 || 433*0Sstevel@tonic-gate strcmp(optarg, "icmp6") == 0) { 434*0Sstevel@tonic-gate v4compat = 0; /* Overridden */ 435*0Sstevel@tonic-gate proto = IPPROTO_ICMPV6; 436*0Sstevel@tonic-gate } else if (strcmp(optarg, "igmp") == 0) { 437*0Sstevel@tonic-gate proto = IPPROTO_IGMP; 438*0Sstevel@tonic-gate } else if (strcmp(optarg, "udp") == 0) { 439*0Sstevel@tonic-gate proto = IPPROTO_UDP; 440*0Sstevel@tonic-gate } else if (strcmp(optarg, "tcp") == 0) { 441*0Sstevel@tonic-gate proto = IPPROTO_TCP; 442*0Sstevel@tonic-gate } else if (strcmp(optarg, "sctp") == 0) { 443*0Sstevel@tonic-gate proto = IPPROTO_SCTP; 444*0Sstevel@tonic-gate } else if (strcmp(optarg, "raw") == 0 || 445*0Sstevel@tonic-gate strcmp(optarg, "rawip") == 0) { 446*0Sstevel@tonic-gate proto = IPPROTO_RAW; 447*0Sstevel@tonic-gate } else { 448*0Sstevel@tonic-gate fatal(1, "%s: unknown protocol.\n", optarg); 449*0Sstevel@tonic-gate } 450*0Sstevel@tonic-gate break; 451*0Sstevel@tonic-gate 452*0Sstevel@tonic-gate case 'I': 453*0Sstevel@tonic-gate ifname = optarg; 454*0Sstevel@tonic-gate Iflag = B_TRUE; 455*0Sstevel@tonic-gate IFLAGMOD(Iflag_only, -1, 1); /* see macro def'n */ 456*0Sstevel@tonic-gate break; 457*0Sstevel@tonic-gate 458*0Sstevel@tonic-gate case 'D': 459*0Sstevel@tonic-gate DHCPflag = B_TRUE; 460*0Sstevel@tonic-gate Iflag_only = 0; 461*0Sstevel@tonic-gate break; 462*0Sstevel@tonic-gate 463*0Sstevel@tonic-gate case '?': 464*0Sstevel@tonic-gate default: 465*0Sstevel@tonic-gate usage(name); 466*0Sstevel@tonic-gate } 467*0Sstevel@tonic-gate } 468*0Sstevel@tonic-gate 469*0Sstevel@tonic-gate /* 470*0Sstevel@tonic-gate * Handle other arguments: find interval, count; the 471*0Sstevel@tonic-gate * flags that accept 'interval' and 'count' are OR'd 472*0Sstevel@tonic-gate * in the outermost 'if'; more flags may be added as 473*0Sstevel@tonic-gate * required 474*0Sstevel@tonic-gate */ 475*0Sstevel@tonic-gate if (Iflag || Sflag || Mflag) { 476*0Sstevel@tonic-gate for (d = optind; d < argc; d++) { 477*0Sstevel@tonic-gate if (isnum(argv[d])) { 478*0Sstevel@tonic-gate interval = atoi(argv[d]); 479*0Sstevel@tonic-gate if (d + 1 < argc && 480*0Sstevel@tonic-gate isnum(argv[d + 1])) { 481*0Sstevel@tonic-gate count = atoi(argv[d + 1]); 482*0Sstevel@tonic-gate optind++; 483*0Sstevel@tonic-gate } 484*0Sstevel@tonic-gate optind++; 485*0Sstevel@tonic-gate if (interval == 0 || count == 0) 486*0Sstevel@tonic-gate usage(name); 487*0Sstevel@tonic-gate break; 488*0Sstevel@tonic-gate } 489*0Sstevel@tonic-gate } 490*0Sstevel@tonic-gate } 491*0Sstevel@tonic-gate if (optind < argc) { 492*0Sstevel@tonic-gate if (Iflag && isnum(argv[optind])) { 493*0Sstevel@tonic-gate count = atoi(argv[optind]); 494*0Sstevel@tonic-gate if (count == 0) 495*0Sstevel@tonic-gate usage(name); 496*0Sstevel@tonic-gate optind++; 497*0Sstevel@tonic-gate } 498*0Sstevel@tonic-gate } 499*0Sstevel@tonic-gate if (optind < argc) { 500*0Sstevel@tonic-gate (void) fprintf(stderr, 501*0Sstevel@tonic-gate "%s: extra arguments\n", name); 502*0Sstevel@tonic-gate usage(name); 503*0Sstevel@tonic-gate } 504*0Sstevel@tonic-gate if (interval) 505*0Sstevel@tonic-gate setbuf(stdout, NULL); 506*0Sstevel@tonic-gate 507*0Sstevel@tonic-gate if (DHCPflag) { 508*0Sstevel@tonic-gate dhcp_report(Iflag ? ifname : NULL); 509*0Sstevel@tonic-gate exit(0); 510*0Sstevel@tonic-gate } 511*0Sstevel@tonic-gate 512*0Sstevel@tonic-gate /* Get data structures: priming before iteration */ 513*0Sstevel@tonic-gate if (family_selected(AF_INET) || family_selected(AF_INET6)) { 514*0Sstevel@tonic-gate sd = mibopen(); 515*0Sstevel@tonic-gate if (sd == -1) 516*0Sstevel@tonic-gate fatal(1, "can't open mib stream\n"); 517*0Sstevel@tonic-gate if ((item = mibget(sd)) == NULL) { 518*0Sstevel@tonic-gate (void) close(sd); 519*0Sstevel@tonic-gate fatal(1, "mibget() failed\n"); 520*0Sstevel@tonic-gate } 521*0Sstevel@tonic-gate /* Extract constant sizes - need do once only */ 522*0Sstevel@tonic-gate mib_get_constants(item); 523*0Sstevel@tonic-gate } 524*0Sstevel@tonic-gate if ((kc = kstat_open()) == NULL) { 525*0Sstevel@tonic-gate mibfree(item); 526*0Sstevel@tonic-gate (void) close(sd); 527*0Sstevel@tonic-gate fail(1, "kstat_open(): can't open /dev/kstat"); 528*0Sstevel@tonic-gate } 529*0Sstevel@tonic-gate 530*0Sstevel@tonic-gate if (interval <= 0) { 531*0Sstevel@tonic-gate count = 1; 532*0Sstevel@tonic-gate once_only = B_TRUE; 533*0Sstevel@tonic-gate } 534*0Sstevel@tonic-gate /* 'for' loop 1: */ 535*0Sstevel@tonic-gate for (;;) { 536*0Sstevel@tonic-gate mib_item_t *curritem = NULL; /* only for -[M]s */ 537*0Sstevel@tonic-gate 538*0Sstevel@tonic-gate /* netstat: AF_INET[6] behaviour */ 539*0Sstevel@tonic-gate if (family_selected(AF_INET) || family_selected(AF_INET6)) { 540*0Sstevel@tonic-gate if (Sflag) { 541*0Sstevel@tonic-gate curritem = mib_item_diff(previtem, item); 542*0Sstevel@tonic-gate if (curritem == NULL) 543*0Sstevel@tonic-gate fatal(1, "can't process mib data, " 544*0Sstevel@tonic-gate "out of memory\n"); 545*0Sstevel@tonic-gate mib_item_destroy(&previtem); 546*0Sstevel@tonic-gate } 547*0Sstevel@tonic-gate 548*0Sstevel@tonic-gate if (!(Iflag || Rflag || Sflag || Mflag || 549*0Sstevel@tonic-gate MMflag || Pflag || Gflag || DHCPflag)) { 550*0Sstevel@tonic-gate if (protocol_selected(IPPROTO_UDP)) 551*0Sstevel@tonic-gate udp_report(item); 552*0Sstevel@tonic-gate if (protocol_selected(IPPROTO_TCP)) 553*0Sstevel@tonic-gate tcp_report(item); 554*0Sstevel@tonic-gate if (protocol_selected(IPPROTO_SCTP)) 555*0Sstevel@tonic-gate sctp_report(item); 556*0Sstevel@tonic-gate } 557*0Sstevel@tonic-gate if (Iflag) 558*0Sstevel@tonic-gate if_report(item, ifname, Iflag_only, once_only); 559*0Sstevel@tonic-gate if (Mflag) 560*0Sstevel@tonic-gate m_report(); 561*0Sstevel@tonic-gate if (Rflag) 562*0Sstevel@tonic-gate ire_report(item); 563*0Sstevel@tonic-gate if (Sflag && MMflag) { 564*0Sstevel@tonic-gate mrt_stat_report(curritem); 565*0Sstevel@tonic-gate } else { 566*0Sstevel@tonic-gate if (Sflag) 567*0Sstevel@tonic-gate stat_report(curritem); 568*0Sstevel@tonic-gate if (MMflag) 569*0Sstevel@tonic-gate mrt_report(item); 570*0Sstevel@tonic-gate } 571*0Sstevel@tonic-gate if (Gflag) 572*0Sstevel@tonic-gate group_report(item); 573*0Sstevel@tonic-gate if (Pflag) { 574*0Sstevel@tonic-gate if (family_selected(AF_INET)) 575*0Sstevel@tonic-gate arp_report(item); 576*0Sstevel@tonic-gate if (family_selected(AF_INET6)) 577*0Sstevel@tonic-gate ndp_report(item); 578*0Sstevel@tonic-gate } 579*0Sstevel@tonic-gate mib_item_destroy(&curritem); 580*0Sstevel@tonic-gate } 581*0Sstevel@tonic-gate 582*0Sstevel@tonic-gate /* netstat: AF_UNIX behaviour */ 583*0Sstevel@tonic-gate if (family_selected(AF_UNIX) && 584*0Sstevel@tonic-gate (!(Iflag || Rflag || Sflag || Mflag || 585*0Sstevel@tonic-gate MMflag || Pflag || Gflag))) 586*0Sstevel@tonic-gate unixpr(kc); 587*0Sstevel@tonic-gate (void) kstat_close(kc); 588*0Sstevel@tonic-gate 589*0Sstevel@tonic-gate /* iteration handling code */ 590*0Sstevel@tonic-gate if (count > 0 && --count == 0) 591*0Sstevel@tonic-gate break; 592*0Sstevel@tonic-gate (void) sleep(interval); 593*0Sstevel@tonic-gate 594*0Sstevel@tonic-gate /* re-populating of data structures */ 595*0Sstevel@tonic-gate if (family_selected(AF_INET) || family_selected(AF_INET6)) { 596*0Sstevel@tonic-gate if (Sflag) { 597*0Sstevel@tonic-gate /* previtem is a cut-down list */ 598*0Sstevel@tonic-gate previtem = mib_item_dup(item); 599*0Sstevel@tonic-gate if (previtem == NULL) 600*0Sstevel@tonic-gate fatal(1, "can't process mib data, " 601*0Sstevel@tonic-gate "out of memory\n"); 602*0Sstevel@tonic-gate } 603*0Sstevel@tonic-gate mibfree(item); 604*0Sstevel@tonic-gate (void) close(sd); 605*0Sstevel@tonic-gate if ((sd = mibopen()) == -1) 606*0Sstevel@tonic-gate fatal(1, "can't open mib stream anymore\n"); 607*0Sstevel@tonic-gate if ((item = mibget(sd)) == NULL) { 608*0Sstevel@tonic-gate (void) close(sd); 609*0Sstevel@tonic-gate fatal(1, "mibget() failed\n"); 610*0Sstevel@tonic-gate } 611*0Sstevel@tonic-gate } 612*0Sstevel@tonic-gate if ((kc = kstat_open()) == NULL) 613*0Sstevel@tonic-gate fail(1, "kstat_open(): can't open /dev/kstat"); 614*0Sstevel@tonic-gate 615*0Sstevel@tonic-gate } /* 'for' loop 1 ends */ 616*0Sstevel@tonic-gate mibfree(item); 617*0Sstevel@tonic-gate (void) close(sd); 618*0Sstevel@tonic-gate 619*0Sstevel@tonic-gate return (0); 620*0Sstevel@tonic-gate } 621*0Sstevel@tonic-gate 622*0Sstevel@tonic-gate 623*0Sstevel@tonic-gate static int 624*0Sstevel@tonic-gate isnum(char *p) 625*0Sstevel@tonic-gate { 626*0Sstevel@tonic-gate int len; 627*0Sstevel@tonic-gate int i; 628*0Sstevel@tonic-gate 629*0Sstevel@tonic-gate len = strlen(p); 630*0Sstevel@tonic-gate for (i = 0; i < len; i++) 631*0Sstevel@tonic-gate if (!isdigit(p[i])) 632*0Sstevel@tonic-gate return (0); 633*0Sstevel@tonic-gate return (1); 634*0Sstevel@tonic-gate } 635*0Sstevel@tonic-gate 636*0Sstevel@tonic-gate 637*0Sstevel@tonic-gate /* --------------------------------- MIBGET -------------------------------- */ 638*0Sstevel@tonic-gate 639*0Sstevel@tonic-gate static mib_item_t * 640*0Sstevel@tonic-gate mibget(int sd) 641*0Sstevel@tonic-gate { 642*0Sstevel@tonic-gate /* 643*0Sstevel@tonic-gate * buf is an automatic for this function, so the 644*0Sstevel@tonic-gate * compiler has complete control over its alignment; 645*0Sstevel@tonic-gate * it is assumed this alignment is satisfactory for 646*0Sstevel@tonic-gate * it to be casted to certain other struct pointers 647*0Sstevel@tonic-gate * here, such as struct T_optmgmt_ack * . 648*0Sstevel@tonic-gate */ 649*0Sstevel@tonic-gate uintptr_t buf[512 / sizeof (uintptr_t)]; 650*0Sstevel@tonic-gate int flags; 651*0Sstevel@tonic-gate int i, j, getcode; 652*0Sstevel@tonic-gate struct strbuf ctlbuf, databuf; 653*0Sstevel@tonic-gate struct T_optmgmt_req *tor = (struct T_optmgmt_req *)buf; 654*0Sstevel@tonic-gate struct T_optmgmt_ack *toa = (struct T_optmgmt_ack *)buf; 655*0Sstevel@tonic-gate struct T_error_ack *tea = (struct T_error_ack *)buf; 656*0Sstevel@tonic-gate struct opthdr *req; 657*0Sstevel@tonic-gate mib_item_t *first_item = NULL; 658*0Sstevel@tonic-gate mib_item_t *last_item = NULL; 659*0Sstevel@tonic-gate mib_item_t *temp; 660*0Sstevel@tonic-gate 661*0Sstevel@tonic-gate tor->PRIM_type = T_SVR4_OPTMGMT_REQ; 662*0Sstevel@tonic-gate tor->OPT_offset = sizeof (struct T_optmgmt_req); 663*0Sstevel@tonic-gate tor->OPT_length = sizeof (struct opthdr); 664*0Sstevel@tonic-gate tor->MGMT_flags = T_CURRENT; 665*0Sstevel@tonic-gate req = (struct opthdr *)&tor[1]; 666*0Sstevel@tonic-gate req->level = MIB2_IP; /* any MIB2_xxx value ok here */ 667*0Sstevel@tonic-gate req->name = 0; 668*0Sstevel@tonic-gate req->len = 0; 669*0Sstevel@tonic-gate 670*0Sstevel@tonic-gate ctlbuf.buf = (char *)buf; 671*0Sstevel@tonic-gate ctlbuf.len = tor->OPT_length + tor->OPT_offset; 672*0Sstevel@tonic-gate flags = 0; 673*0Sstevel@tonic-gate if (putmsg(sd, &ctlbuf, (struct strbuf *)0, flags) == -1) { 674*0Sstevel@tonic-gate perror("mibget: putmsg(ctl) failed"); 675*0Sstevel@tonic-gate goto error_exit; 676*0Sstevel@tonic-gate } 677*0Sstevel@tonic-gate 678*0Sstevel@tonic-gate /* 679*0Sstevel@tonic-gate * Each reply consists of a ctl part for one fixed structure 680*0Sstevel@tonic-gate * or table, as defined in mib2.h. The format is a T_OPTMGMT_ACK, 681*0Sstevel@tonic-gate * containing an opthdr structure. level/name identify the entry, 682*0Sstevel@tonic-gate * len is the size of the data part of the message. 683*0Sstevel@tonic-gate */ 684*0Sstevel@tonic-gate req = (struct opthdr *)&toa[1]; 685*0Sstevel@tonic-gate ctlbuf.maxlen = sizeof (buf); 686*0Sstevel@tonic-gate j = 1; 687*0Sstevel@tonic-gate for (;;) { 688*0Sstevel@tonic-gate flags = 0; 689*0Sstevel@tonic-gate getcode = getmsg(sd, &ctlbuf, (struct strbuf *)0, &flags); 690*0Sstevel@tonic-gate if (getcode == -1) { 691*0Sstevel@tonic-gate perror("mibget getmsg(ctl) failed"); 692*0Sstevel@tonic-gate if (Dflag) { 693*0Sstevel@tonic-gate (void) fputs("# level name len\n", 694*0Sstevel@tonic-gate stderr); 695*0Sstevel@tonic-gate i = 0; 696*0Sstevel@tonic-gate for (last_item = first_item; last_item; 697*0Sstevel@tonic-gate last_item = last_item->next_item) 698*0Sstevel@tonic-gate (void) printf("%d %4d %5d %d\n", 699*0Sstevel@tonic-gate ++i, 700*0Sstevel@tonic-gate last_item->group, 701*0Sstevel@tonic-gate last_item->mib_id, 702*0Sstevel@tonic-gate last_item->length); 703*0Sstevel@tonic-gate } 704*0Sstevel@tonic-gate goto error_exit; 705*0Sstevel@tonic-gate } 706*0Sstevel@tonic-gate if (getcode == 0 && 707*0Sstevel@tonic-gate ctlbuf.len >= sizeof (struct T_optmgmt_ack) && 708*0Sstevel@tonic-gate toa->PRIM_type == T_OPTMGMT_ACK && 709*0Sstevel@tonic-gate toa->MGMT_flags == T_SUCCESS && 710*0Sstevel@tonic-gate req->len == 0) { 711*0Sstevel@tonic-gate if (Dflag) 712*0Sstevel@tonic-gate (void) printf("mibget getmsg() %d returned " 713*0Sstevel@tonic-gate "EOD (level %ld, name %ld)\n", 714*0Sstevel@tonic-gate j, req->level, req->name); 715*0Sstevel@tonic-gate return (first_item); /* this is EOD msg */ 716*0Sstevel@tonic-gate } 717*0Sstevel@tonic-gate 718*0Sstevel@tonic-gate if (ctlbuf.len >= sizeof (struct T_error_ack) && 719*0Sstevel@tonic-gate tea->PRIM_type == T_ERROR_ACK) { 720*0Sstevel@tonic-gate (void) fprintf(stderr, 721*0Sstevel@tonic-gate "mibget %d gives T_ERROR_ACK: TLI_error = 0x%lx, " 722*0Sstevel@tonic-gate "UNIX_error = 0x%lx\n", 723*0Sstevel@tonic-gate j, tea->TLI_error, tea->UNIX_error); 724*0Sstevel@tonic-gate 725*0Sstevel@tonic-gate errno = (tea->TLI_error == TSYSERR) ? 726*0Sstevel@tonic-gate tea->UNIX_error : EPROTO; 727*0Sstevel@tonic-gate goto error_exit; 728*0Sstevel@tonic-gate } 729*0Sstevel@tonic-gate 730*0Sstevel@tonic-gate if (getcode != MOREDATA || 731*0Sstevel@tonic-gate ctlbuf.len < sizeof (struct T_optmgmt_ack) || 732*0Sstevel@tonic-gate toa->PRIM_type != T_OPTMGMT_ACK || 733*0Sstevel@tonic-gate toa->MGMT_flags != T_SUCCESS) { 734*0Sstevel@tonic-gate (void) printf("mibget getmsg(ctl) %d returned %d, " 735*0Sstevel@tonic-gate "ctlbuf.len = %d, PRIM_type = %ld\n", 736*0Sstevel@tonic-gate j, getcode, ctlbuf.len, toa->PRIM_type); 737*0Sstevel@tonic-gate 738*0Sstevel@tonic-gate if (toa->PRIM_type == T_OPTMGMT_ACK) 739*0Sstevel@tonic-gate (void) printf("T_OPTMGMT_ACK: " 740*0Sstevel@tonic-gate "MGMT_flags = 0x%lx, req->len = %ld\n", 741*0Sstevel@tonic-gate toa->MGMT_flags, req->len); 742*0Sstevel@tonic-gate errno = ENOMSG; 743*0Sstevel@tonic-gate goto error_exit; 744*0Sstevel@tonic-gate } 745*0Sstevel@tonic-gate 746*0Sstevel@tonic-gate temp = (mib_item_t *)malloc(sizeof (mib_item_t)); 747*0Sstevel@tonic-gate if (temp == NULL) { 748*0Sstevel@tonic-gate perror("mibget malloc failed"); 749*0Sstevel@tonic-gate goto error_exit; 750*0Sstevel@tonic-gate } 751*0Sstevel@tonic-gate if (last_item != NULL) 752*0Sstevel@tonic-gate last_item->next_item = temp; 753*0Sstevel@tonic-gate else 754*0Sstevel@tonic-gate first_item = temp; 755*0Sstevel@tonic-gate last_item = temp; 756*0Sstevel@tonic-gate last_item->next_item = NULL; 757*0Sstevel@tonic-gate last_item->group = req->level; 758*0Sstevel@tonic-gate last_item->mib_id = req->name; 759*0Sstevel@tonic-gate last_item->length = req->len; 760*0Sstevel@tonic-gate last_item->valp = malloc((int)req->len); 761*0Sstevel@tonic-gate if (last_item->valp == NULL) 762*0Sstevel@tonic-gate goto error_exit; 763*0Sstevel@tonic-gate if (Dflag) 764*0Sstevel@tonic-gate (void) printf("msg %d: group = %4d mib_id = %5d" 765*0Sstevel@tonic-gate "length = %d\n", 766*0Sstevel@tonic-gate j, last_item->group, last_item->mib_id, 767*0Sstevel@tonic-gate last_item->length); 768*0Sstevel@tonic-gate 769*0Sstevel@tonic-gate databuf.maxlen = last_item->length; 770*0Sstevel@tonic-gate databuf.buf = (char *)last_item->valp; 771*0Sstevel@tonic-gate databuf.len = 0; 772*0Sstevel@tonic-gate flags = 0; 773*0Sstevel@tonic-gate getcode = getmsg(sd, (struct strbuf *)0, &databuf, &flags); 774*0Sstevel@tonic-gate if (getcode == -1) { 775*0Sstevel@tonic-gate perror("mibget getmsg(data) failed"); 776*0Sstevel@tonic-gate goto error_exit; 777*0Sstevel@tonic-gate } else if (getcode != 0) { 778*0Sstevel@tonic-gate (void) printf("mibget getmsg(data) returned %d, " 779*0Sstevel@tonic-gate "databuf.maxlen = %d, databuf.len = %d\n", 780*0Sstevel@tonic-gate getcode, databuf.maxlen, databuf.len); 781*0Sstevel@tonic-gate goto error_exit; 782*0Sstevel@tonic-gate } 783*0Sstevel@tonic-gate j++; 784*0Sstevel@tonic-gate } 785*0Sstevel@tonic-gate /* NOTREACHED */ 786*0Sstevel@tonic-gate 787*0Sstevel@tonic-gate error_exit:; 788*0Sstevel@tonic-gate mibfree(first_item); 789*0Sstevel@tonic-gate return (NULL); 790*0Sstevel@tonic-gate } 791*0Sstevel@tonic-gate 792*0Sstevel@tonic-gate /* 793*0Sstevel@tonic-gate * mibfree: frees a linked list of type (mib_item_t *) 794*0Sstevel@tonic-gate * returned by mibget(); this is NOT THE SAME AS 795*0Sstevel@tonic-gate * mib_item_destroy(), so should be used for objects 796*0Sstevel@tonic-gate * returned by mibget() only 797*0Sstevel@tonic-gate */ 798*0Sstevel@tonic-gate static void 799*0Sstevel@tonic-gate mibfree(mib_item_t *firstitem) 800*0Sstevel@tonic-gate { 801*0Sstevel@tonic-gate mib_item_t *lastitem; 802*0Sstevel@tonic-gate 803*0Sstevel@tonic-gate while (firstitem != NULL) { 804*0Sstevel@tonic-gate lastitem = firstitem; 805*0Sstevel@tonic-gate firstitem = firstitem->next_item; 806*0Sstevel@tonic-gate if (lastitem->valp != NULL) 807*0Sstevel@tonic-gate free(lastitem->valp); 808*0Sstevel@tonic-gate free(lastitem); 809*0Sstevel@tonic-gate } 810*0Sstevel@tonic-gate } 811*0Sstevel@tonic-gate 812*0Sstevel@tonic-gate static int 813*0Sstevel@tonic-gate mibopen(void) 814*0Sstevel@tonic-gate { 815*0Sstevel@tonic-gate int sd; 816*0Sstevel@tonic-gate 817*0Sstevel@tonic-gate sd = open("/dev/arp", O_RDWR); 818*0Sstevel@tonic-gate if (sd == -1) { 819*0Sstevel@tonic-gate perror("arp open"); 820*0Sstevel@tonic-gate return (-1); 821*0Sstevel@tonic-gate } 822*0Sstevel@tonic-gate if (ioctl(sd, I_PUSH, "tcp") == -1) { 823*0Sstevel@tonic-gate perror("tcp I_PUSH"); 824*0Sstevel@tonic-gate (void) close(sd); 825*0Sstevel@tonic-gate return (-1); 826*0Sstevel@tonic-gate } 827*0Sstevel@tonic-gate if (ioctl(sd, I_PUSH, "udp") == -1) { 828*0Sstevel@tonic-gate perror("udp I_PUSH"); 829*0Sstevel@tonic-gate (void) close(sd); 830*0Sstevel@tonic-gate return (-1); 831*0Sstevel@tonic-gate } 832*0Sstevel@tonic-gate if (ioctl(sd, I_PUSH, "icmp") == -1) { 833*0Sstevel@tonic-gate perror("icmp I_PUSH"); 834*0Sstevel@tonic-gate (void) close(sd); 835*0Sstevel@tonic-gate return (-1); 836*0Sstevel@tonic-gate } 837*0Sstevel@tonic-gate return (sd); 838*0Sstevel@tonic-gate } 839*0Sstevel@tonic-gate 840*0Sstevel@tonic-gate /* 841*0Sstevel@tonic-gate * mib_item_dup: returns a clean mib_item_t * linked 842*0Sstevel@tonic-gate * list, so that for every element item->mib_id is 0; 843*0Sstevel@tonic-gate * to deallocate this linked list, use mib_item_destroy 844*0Sstevel@tonic-gate */ 845*0Sstevel@tonic-gate static mib_item_t * 846*0Sstevel@tonic-gate mib_item_dup(mib_item_t *item) 847*0Sstevel@tonic-gate { 848*0Sstevel@tonic-gate int c = 0; 849*0Sstevel@tonic-gate mib_item_t *localp; 850*0Sstevel@tonic-gate mib_item_t *tempp; 851*0Sstevel@tonic-gate 852*0Sstevel@tonic-gate for (tempp = item; tempp; tempp = tempp->next_item) 853*0Sstevel@tonic-gate if (tempp->mib_id == 0) 854*0Sstevel@tonic-gate c++; 855*0Sstevel@tonic-gate tempp = NULL; 856*0Sstevel@tonic-gate 857*0Sstevel@tonic-gate localp = (mib_item_t *)malloc(c * sizeof (mib_item_t)); 858*0Sstevel@tonic-gate if (localp == NULL) 859*0Sstevel@tonic-gate return (NULL); 860*0Sstevel@tonic-gate c = 0; 861*0Sstevel@tonic-gate for (; item; item = item->next_item) { 862*0Sstevel@tonic-gate if (item->mib_id == 0) { 863*0Sstevel@tonic-gate /* Replicate item in localp */ 864*0Sstevel@tonic-gate (localp[c]).next_item = NULL; 865*0Sstevel@tonic-gate (localp[c]).group = item->group; 866*0Sstevel@tonic-gate (localp[c]).mib_id = item->mib_id; 867*0Sstevel@tonic-gate (localp[c]).length = item->length; 868*0Sstevel@tonic-gate (localp[c]).valp = (uintptr_t *)malloc( 869*0Sstevel@tonic-gate item->length); 870*0Sstevel@tonic-gate if ((localp[c]).valp == NULL) { 871*0Sstevel@tonic-gate mib_item_destroy(&localp); 872*0Sstevel@tonic-gate return (NULL); 873*0Sstevel@tonic-gate } 874*0Sstevel@tonic-gate (void *) memcpy((localp[c]).valp, 875*0Sstevel@tonic-gate item->valp, 876*0Sstevel@tonic-gate item->length); 877*0Sstevel@tonic-gate tempp = &(localp[c]); 878*0Sstevel@tonic-gate if (c > 0) 879*0Sstevel@tonic-gate (localp[c - 1]).next_item = tempp; 880*0Sstevel@tonic-gate c++; 881*0Sstevel@tonic-gate } 882*0Sstevel@tonic-gate } 883*0Sstevel@tonic-gate return (localp); 884*0Sstevel@tonic-gate } 885*0Sstevel@tonic-gate 886*0Sstevel@tonic-gate /* 887*0Sstevel@tonic-gate * mib_item_diff: takes two (mib_item_t *) linked lists 888*0Sstevel@tonic-gate * item1 and item2 and computes the difference between 889*0Sstevel@tonic-gate * differentiable values in item2 against item1 for every 890*0Sstevel@tonic-gate * given member of item2; returns an mib_item_t * linked 891*0Sstevel@tonic-gate * list of diff's, or a copy of item2 if item1 is NULL; 892*0Sstevel@tonic-gate * will return NULL if system out of memory; works only 893*0Sstevel@tonic-gate * for item->mib_id == 0 894*0Sstevel@tonic-gate */ 895*0Sstevel@tonic-gate static mib_item_t * 896*0Sstevel@tonic-gate mib_item_diff(mib_item_t *item1, mib_item_t *item2) { 897*0Sstevel@tonic-gate int nitems = 0; /* no. of items in item2 */ 898*0Sstevel@tonic-gate mib_item_t *tempp2; /* walking copy of item2 */ 899*0Sstevel@tonic-gate mib_item_t *tempp1; /* walking copy of item1 */ 900*0Sstevel@tonic-gate mib_item_t *diffp; 901*0Sstevel@tonic-gate mib_item_t *diffptr; /* walking copy of diffp */ 902*0Sstevel@tonic-gate mib_item_t *prevp = NULL; 903*0Sstevel@tonic-gate 904*0Sstevel@tonic-gate if (item1 == NULL) { 905*0Sstevel@tonic-gate diffp = mib_item_dup(item2); 906*0Sstevel@tonic-gate return (diffp); 907*0Sstevel@tonic-gate } 908*0Sstevel@tonic-gate 909*0Sstevel@tonic-gate for (tempp2 = item2; 910*0Sstevel@tonic-gate tempp2; 911*0Sstevel@tonic-gate tempp2 = tempp2->next_item) { 912*0Sstevel@tonic-gate if (tempp2->mib_id == 0) 913*0Sstevel@tonic-gate switch (tempp2->group) { 914*0Sstevel@tonic-gate /* 915*0Sstevel@tonic-gate * upon adding a case here, the same 916*0Sstevel@tonic-gate * must also be added in the next 917*0Sstevel@tonic-gate * switch statement, alongwith 918*0Sstevel@tonic-gate * appropriate code 919*0Sstevel@tonic-gate */ 920*0Sstevel@tonic-gate case MIB2_IP: 921*0Sstevel@tonic-gate case MIB2_IP6: 922*0Sstevel@tonic-gate case EXPER_DVMRP: 923*0Sstevel@tonic-gate case EXPER_IGMP: 924*0Sstevel@tonic-gate case MIB2_ICMP: 925*0Sstevel@tonic-gate case MIB2_ICMP6: 926*0Sstevel@tonic-gate case MIB2_TCP: 927*0Sstevel@tonic-gate case MIB2_UDP: 928*0Sstevel@tonic-gate case MIB2_SCTP: 929*0Sstevel@tonic-gate case EXPER_RAWIP: 930*0Sstevel@tonic-gate nitems++; 931*0Sstevel@tonic-gate } 932*0Sstevel@tonic-gate } 933*0Sstevel@tonic-gate tempp2 = NULL; 934*0Sstevel@tonic-gate if (nitems == 0) { 935*0Sstevel@tonic-gate diffp = mib_item_dup(item2); 936*0Sstevel@tonic-gate return (diffp); 937*0Sstevel@tonic-gate } 938*0Sstevel@tonic-gate 939*0Sstevel@tonic-gate diffp = (mib_item_t *)calloc(nitems, sizeof (mib_item_t)); 940*0Sstevel@tonic-gate if (diffp == NULL) 941*0Sstevel@tonic-gate return (NULL); 942*0Sstevel@tonic-gate diffptr = diffp; 943*0Sstevel@tonic-gate /* 'for' loop 1: */ 944*0Sstevel@tonic-gate for (tempp2 = item2; tempp2 != NULL; tempp2 = tempp2->next_item) { 945*0Sstevel@tonic-gate if (tempp2->mib_id != 0) 946*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 947*0Sstevel@tonic-gate /* 'for' loop 2: */ 948*0Sstevel@tonic-gate for (tempp1 = item1; tempp1 != NULL; 949*0Sstevel@tonic-gate tempp1 = tempp1->next_item) { 950*0Sstevel@tonic-gate if (!(tempp1->mib_id == 0 && 951*0Sstevel@tonic-gate tempp1->group == tempp2->group && 952*0Sstevel@tonic-gate tempp1->mib_id == tempp2->mib_id)) 953*0Sstevel@tonic-gate continue; /* 'for' loop 2 */ 954*0Sstevel@tonic-gate /* found comparable data sets */ 955*0Sstevel@tonic-gate if (prevp != NULL) 956*0Sstevel@tonic-gate prevp->next_item = diffptr; 957*0Sstevel@tonic-gate switch (tempp2->group) { 958*0Sstevel@tonic-gate /* 959*0Sstevel@tonic-gate * Indenting note: Because of long variable names 960*0Sstevel@tonic-gate * in cases MIB2_IP6 and MIB2_ICMP6, their contents 961*0Sstevel@tonic-gate * have been indented by one tab space only 962*0Sstevel@tonic-gate */ 963*0Sstevel@tonic-gate case MIB2_IP: { 964*0Sstevel@tonic-gate mib2_ip_t *i2 = (mib2_ip_t *)tempp2->valp; 965*0Sstevel@tonic-gate mib2_ip_t *i1 = (mib2_ip_t *)tempp1->valp; 966*0Sstevel@tonic-gate mib2_ip_t *d; 967*0Sstevel@tonic-gate 968*0Sstevel@tonic-gate diffptr->group = tempp2->group; 969*0Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id; 970*0Sstevel@tonic-gate diffptr->length = tempp2->length; 971*0Sstevel@tonic-gate d = (mib2_ip_t *)calloc(tempp2->length, 1); 972*0Sstevel@tonic-gate if (d == NULL) 973*0Sstevel@tonic-gate goto mibdiff_out_of_memory; 974*0Sstevel@tonic-gate diffptr->valp = d; 975*0Sstevel@tonic-gate d->ipForwarding = i2->ipForwarding; 976*0Sstevel@tonic-gate d->ipDefaultTTL = i2->ipDefaultTTL; 977*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipInReceives); 978*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipInHdrErrors); 979*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipInAddrErrors); 980*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipInCksumErrs); 981*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipForwDatagrams); 982*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipForwProhibits); 983*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipInUnknownProtos); 984*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipInDiscards); 985*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipInDelivers); 986*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipOutRequests); 987*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipOutDiscards); 988*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipOutNoRoutes); 989*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipReasmTimeout); 990*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipReasmReqds); 991*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipReasmOKs); 992*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipReasmFails); 993*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipReasmDuplicates); 994*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipReasmPartDups); 995*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipFragOKs); 996*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipFragFails); 997*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipFragCreates); 998*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipRoutingDiscards); 999*0Sstevel@tonic-gate MDIFF(d, i2, i1, tcpInErrs); 1000*0Sstevel@tonic-gate MDIFF(d, i2, i1, udpNoPorts); 1001*0Sstevel@tonic-gate MDIFF(d, i2, i1, udpInCksumErrs); 1002*0Sstevel@tonic-gate MDIFF(d, i2, i1, udpInOverflows); 1003*0Sstevel@tonic-gate MDIFF(d, i2, i1, rawipInOverflows); 1004*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipsecInSucceeded); 1005*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipsecInFailed); 1006*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipInIPv6); 1007*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipOutIPv6); 1008*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipOutSwitchIPv6); 1009*0Sstevel@tonic-gate prevp = diffptr++; 1010*0Sstevel@tonic-gate break; 1011*0Sstevel@tonic-gate } 1012*0Sstevel@tonic-gate case MIB2_IP6: { 1013*0Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t *i2; 1014*0Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t *i1; 1015*0Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t *d; 1016*0Sstevel@tonic-gate 1017*0Sstevel@tonic-gate i2 = (mib2_ipv6IfStatsEntry_t *)tempp2->valp; 1018*0Sstevel@tonic-gate i1 = (mib2_ipv6IfStatsEntry_t *)tempp1->valp; 1019*0Sstevel@tonic-gate diffptr->group = tempp2->group; 1020*0Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id; 1021*0Sstevel@tonic-gate diffptr->length = tempp2->length; 1022*0Sstevel@tonic-gate d = (mib2_ipv6IfStatsEntry_t *)calloc( 1023*0Sstevel@tonic-gate tempp2->length, 1); 1024*0Sstevel@tonic-gate if (d == NULL) 1025*0Sstevel@tonic-gate goto mibdiff_out_of_memory; 1026*0Sstevel@tonic-gate diffptr->valp = d; 1027*0Sstevel@tonic-gate d->ipv6Forwarding = i2->ipv6Forwarding; 1028*0Sstevel@tonic-gate d->ipv6DefaultHopLimit = 1029*0Sstevel@tonic-gate i2->ipv6DefaultHopLimit; 1030*0Sstevel@tonic-gate 1031*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InReceives); 1032*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InHdrErrors); 1033*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InTooBigErrors); 1034*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InNoRoutes); 1035*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InAddrErrors); 1036*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InUnknownProtos); 1037*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InTruncatedPkts); 1038*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InDiscards); 1039*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InDelivers); 1040*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutForwDatagrams); 1041*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutRequests); 1042*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutDiscards); 1043*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutNoRoutes); 1044*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutFragOKs); 1045*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutFragFails); 1046*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutFragCreates); 1047*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6ReasmReqds); 1048*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6ReasmOKs); 1049*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6ReasmFails); 1050*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InMcastPkts); 1051*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutMcastPkts); 1052*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6ReasmDuplicates); 1053*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6ReasmPartDups); 1054*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6ForwProhibits); 1055*0Sstevel@tonic-gate MDIFF(d, i2, i1, udpInCksumErrs); 1056*0Sstevel@tonic-gate MDIFF(d, i2, i1, udpInOverflows); 1057*0Sstevel@tonic-gate MDIFF(d, i2, i1, rawipInOverflows); 1058*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InIPv4); 1059*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutIPv4); 1060*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutSwitchIPv4); 1061*0Sstevel@tonic-gate prevp = diffptr++; 1062*0Sstevel@tonic-gate break; 1063*0Sstevel@tonic-gate } 1064*0Sstevel@tonic-gate case EXPER_DVMRP: { 1065*0Sstevel@tonic-gate struct mrtstat *m2; 1066*0Sstevel@tonic-gate struct mrtstat *m1; 1067*0Sstevel@tonic-gate struct mrtstat *d; 1068*0Sstevel@tonic-gate 1069*0Sstevel@tonic-gate m2 = (struct mrtstat *)tempp2->valp; 1070*0Sstevel@tonic-gate m1 = (struct mrtstat *)tempp1->valp; 1071*0Sstevel@tonic-gate diffptr->group = tempp2->group; 1072*0Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id; 1073*0Sstevel@tonic-gate diffptr->length = tempp2->length; 1074*0Sstevel@tonic-gate d = (struct mrtstat *)calloc(tempp2->length, 1); 1075*0Sstevel@tonic-gate if (d == NULL) 1076*0Sstevel@tonic-gate goto mibdiff_out_of_memory; 1077*0Sstevel@tonic-gate diffptr->valp = d; 1078*0Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_mfc_hits); 1079*0Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_mfc_misses); 1080*0Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_fwd_in); 1081*0Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_fwd_out); 1082*0Sstevel@tonic-gate d->mrts_upcalls = m2->mrts_upcalls; 1083*0Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_fwd_drop); 1084*0Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_bad_tunnel); 1085*0Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_cant_tunnel); 1086*0Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_wrong_if); 1087*0Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_upq_ovflw); 1088*0Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_cache_cleanups); 1089*0Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_drop_sel); 1090*0Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_q_overflow); 1091*0Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pkt2large); 1092*0Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_badversion); 1093*0Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_rcv_badcsum); 1094*0Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_badregisters); 1095*0Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_regforwards); 1096*0Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_regsend_drops); 1097*0Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_malformed); 1098*0Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_nomemory); 1099*0Sstevel@tonic-gate prevp = diffptr++; 1100*0Sstevel@tonic-gate break; 1101*0Sstevel@tonic-gate } 1102*0Sstevel@tonic-gate case EXPER_IGMP: { 1103*0Sstevel@tonic-gate struct igmpstat *i2; 1104*0Sstevel@tonic-gate struct igmpstat *i1; 1105*0Sstevel@tonic-gate struct igmpstat *d; 1106*0Sstevel@tonic-gate 1107*0Sstevel@tonic-gate i2 = (struct igmpstat *)tempp2->valp; 1108*0Sstevel@tonic-gate i1 = (struct igmpstat *)tempp1->valp; 1109*0Sstevel@tonic-gate diffptr->group = tempp2->group; 1110*0Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id; 1111*0Sstevel@tonic-gate diffptr->length = tempp2->length; 1112*0Sstevel@tonic-gate d = (struct igmpstat *)calloc( 1113*0Sstevel@tonic-gate tempp2->length, 1); 1114*0Sstevel@tonic-gate if (d == NULL) 1115*0Sstevel@tonic-gate goto mibdiff_out_of_memory; 1116*0Sstevel@tonic-gate diffptr->valp = d; 1117*0Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_total); 1118*0Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_tooshort); 1119*0Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_badsum); 1120*0Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_queries); 1121*0Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_badqueries); 1122*0Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_reports); 1123*0Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_badreports); 1124*0Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_ourreports); 1125*0Sstevel@tonic-gate MDIFF(d, i2, i1, igps_snd_reports); 1126*0Sstevel@tonic-gate prevp = diffptr++; 1127*0Sstevel@tonic-gate break; 1128*0Sstevel@tonic-gate } 1129*0Sstevel@tonic-gate case MIB2_ICMP: { 1130*0Sstevel@tonic-gate mib2_icmp_t *i2; 1131*0Sstevel@tonic-gate mib2_icmp_t *i1; 1132*0Sstevel@tonic-gate mib2_icmp_t *d; 1133*0Sstevel@tonic-gate 1134*0Sstevel@tonic-gate i2 = (mib2_icmp_t *)tempp2->valp; 1135*0Sstevel@tonic-gate i1 = (mib2_icmp_t *)tempp1->valp; 1136*0Sstevel@tonic-gate diffptr->group = tempp2->group; 1137*0Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id; 1138*0Sstevel@tonic-gate diffptr->length = tempp2->length; 1139*0Sstevel@tonic-gate d = (mib2_icmp_t *)calloc(tempp2->length, 1); 1140*0Sstevel@tonic-gate if (d == NULL) 1141*0Sstevel@tonic-gate goto mibdiff_out_of_memory; 1142*0Sstevel@tonic-gate diffptr->valp = d; 1143*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInMsgs); 1144*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInErrors); 1145*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInCksumErrs); 1146*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInUnknowns); 1147*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInDestUnreachs); 1148*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInTimeExcds); 1149*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInParmProbs); 1150*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInSrcQuenchs); 1151*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInRedirects); 1152*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInBadRedirects); 1153*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInEchos); 1154*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInEchoReps); 1155*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInTimestamps); 1156*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInAddrMasks); 1157*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInAddrMaskReps); 1158*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInFragNeeded); 1159*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutMsgs); 1160*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutDrops); 1161*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutErrors); 1162*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutDestUnreachs); 1163*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutTimeExcds); 1164*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutParmProbs); 1165*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutSrcQuenchs); 1166*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutRedirects); 1167*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutEchos); 1168*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutEchoReps); 1169*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutTimestamps); 1170*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutTimestampReps); 1171*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutAddrMasks); 1172*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutAddrMaskReps); 1173*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutFragNeeded); 1174*0Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInOverflows); 1175*0Sstevel@tonic-gate prevp = diffptr++; 1176*0Sstevel@tonic-gate break; 1177*0Sstevel@tonic-gate } 1178*0Sstevel@tonic-gate case MIB2_ICMP6: { 1179*0Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t *i2; 1180*0Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t *i1; 1181*0Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t *d; 1182*0Sstevel@tonic-gate 1183*0Sstevel@tonic-gate i2 = (mib2_ipv6IfIcmpEntry_t *)tempp2->valp; 1184*0Sstevel@tonic-gate i1 = (mib2_ipv6IfIcmpEntry_t *)tempp1->valp; 1185*0Sstevel@tonic-gate diffptr->group = tempp2->group; 1186*0Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id; 1187*0Sstevel@tonic-gate diffptr->length = tempp2->length; 1188*0Sstevel@tonic-gate d = (mib2_ipv6IfIcmpEntry_t *)calloc(tempp2->length, 1); 1189*0Sstevel@tonic-gate if (d == NULL) 1190*0Sstevel@tonic-gate goto mibdiff_out_of_memory; 1191*0Sstevel@tonic-gate diffptr->valp = d; 1192*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInMsgs); 1193*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInErrors); 1194*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInDestUnreachs); 1195*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInAdminProhibs); 1196*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInTimeExcds); 1197*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInParmProblems); 1198*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInPktTooBigs); 1199*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInEchos); 1200*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInEchoReplies); 1201*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInRouterSolicits); 1202*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInRouterAdvertisements); 1203*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInNeighborSolicits); 1204*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInNeighborAdvertisements); 1205*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInRedirects); 1206*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInBadRedirects); 1207*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInGroupMembQueries); 1208*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInGroupMembResponses); 1209*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInGroupMembReductions); 1210*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInOverflows); 1211*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutMsgs); 1212*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutErrors); 1213*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutDestUnreachs); 1214*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutAdminProhibs); 1215*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutTimeExcds); 1216*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutParmProblems); 1217*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutPktTooBigs); 1218*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutEchos); 1219*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutEchoReplies); 1220*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutRouterSolicits); 1221*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutRouterAdvertisements); 1222*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutNeighborSolicits); 1223*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutNeighborAdvertisements); 1224*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutRedirects); 1225*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutGroupMembQueries); 1226*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutGroupMembResponses); 1227*0Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutGroupMembReductions); 1228*0Sstevel@tonic-gate prevp = diffptr++; 1229*0Sstevel@tonic-gate break; 1230*0Sstevel@tonic-gate } 1231*0Sstevel@tonic-gate case MIB2_TCP: { 1232*0Sstevel@tonic-gate mib2_tcp_t *t2; 1233*0Sstevel@tonic-gate mib2_tcp_t *t1; 1234*0Sstevel@tonic-gate mib2_tcp_t *d; 1235*0Sstevel@tonic-gate 1236*0Sstevel@tonic-gate t2 = (mib2_tcp_t *)tempp2->valp; 1237*0Sstevel@tonic-gate t1 = (mib2_tcp_t *)tempp1->valp; 1238*0Sstevel@tonic-gate diffptr->group = tempp2->group; 1239*0Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id; 1240*0Sstevel@tonic-gate diffptr->length = tempp2->length; 1241*0Sstevel@tonic-gate d = (mib2_tcp_t *)calloc(tempp2->length, 1); 1242*0Sstevel@tonic-gate if (d == NULL) 1243*0Sstevel@tonic-gate goto mibdiff_out_of_memory; 1244*0Sstevel@tonic-gate diffptr->valp = d; 1245*0Sstevel@tonic-gate d->tcpRtoMin = t2->tcpRtoMin; 1246*0Sstevel@tonic-gate d->tcpRtoMax = t2->tcpRtoMax; 1247*0Sstevel@tonic-gate d->tcpMaxConn = t2->tcpMaxConn; 1248*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpActiveOpens); 1249*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpPassiveOpens); 1250*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpAttemptFails); 1251*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpEstabResets); 1252*0Sstevel@tonic-gate d->tcpCurrEstab = t2->tcpCurrEstab; 1253*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutSegs); 1254*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutDataSegs); 1255*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutDataBytes); 1256*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpRetransSegs); 1257*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpRetransBytes); 1258*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutAck); 1259*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutAckDelayed); 1260*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutUrg); 1261*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutWinUpdate); 1262*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutWinProbe); 1263*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutControl); 1264*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutRsts); 1265*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutFastRetrans); 1266*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInSegs); 1267*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInAckSegs); 1268*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInAckBytes); 1269*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDupAck); 1270*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInAckUnsent); 1271*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataInorderSegs); 1272*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataInorderBytes); 1273*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataUnorderSegs); 1274*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataUnorderBytes); 1275*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataDupSegs); 1276*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataDupBytes); 1277*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataPartDupSegs); 1278*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataPartDupBytes); 1279*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataPastWinSegs); 1280*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataPastWinBytes); 1281*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInWinProbe); 1282*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInWinUpdate); 1283*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInClosed); 1284*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpRttNoUpdate); 1285*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpRttUpdate); 1286*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpTimRetrans); 1287*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpTimRetransDrop); 1288*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpTimKeepalive); 1289*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpTimKeepaliveProbe); 1290*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpTimKeepaliveDrop); 1291*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpListenDrop); 1292*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpListenDropQ0); 1293*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpHalfOpenDrop); 1294*0Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutSackRetransSegs); 1295*0Sstevel@tonic-gate prevp = diffptr++; 1296*0Sstevel@tonic-gate break; 1297*0Sstevel@tonic-gate } 1298*0Sstevel@tonic-gate case MIB2_UDP: { 1299*0Sstevel@tonic-gate mib2_udp_t *u2; 1300*0Sstevel@tonic-gate mib2_udp_t *u1; 1301*0Sstevel@tonic-gate mib2_udp_t *d; 1302*0Sstevel@tonic-gate 1303*0Sstevel@tonic-gate u2 = (mib2_udp_t *)tempp2->valp; 1304*0Sstevel@tonic-gate u1 = (mib2_udp_t *)tempp1->valp; 1305*0Sstevel@tonic-gate diffptr->group = tempp2->group; 1306*0Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id; 1307*0Sstevel@tonic-gate diffptr->length = tempp2->length; 1308*0Sstevel@tonic-gate d = (mib2_udp_t *)calloc(tempp2->length, 1); 1309*0Sstevel@tonic-gate if (d == NULL) 1310*0Sstevel@tonic-gate goto mibdiff_out_of_memory; 1311*0Sstevel@tonic-gate diffptr->valp = d; 1312*0Sstevel@tonic-gate MDIFF(d, u2, u1, udpInDatagrams); 1313*0Sstevel@tonic-gate MDIFF(d, u2, u1, udpInErrors); 1314*0Sstevel@tonic-gate MDIFF(d, u2, u1, udpOutDatagrams); 1315*0Sstevel@tonic-gate MDIFF(d, u2, u1, udpOutErrors); 1316*0Sstevel@tonic-gate prevp = diffptr++; 1317*0Sstevel@tonic-gate break; 1318*0Sstevel@tonic-gate } 1319*0Sstevel@tonic-gate case MIB2_SCTP: { 1320*0Sstevel@tonic-gate mib2_sctp_t *s2; 1321*0Sstevel@tonic-gate mib2_sctp_t *s1; 1322*0Sstevel@tonic-gate mib2_sctp_t *d; 1323*0Sstevel@tonic-gate 1324*0Sstevel@tonic-gate s2 = (mib2_sctp_t *)tempp2->valp; 1325*0Sstevel@tonic-gate s1 = (mib2_sctp_t *)tempp1->valp; 1326*0Sstevel@tonic-gate diffptr->group = tempp2->group; 1327*0Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id; 1328*0Sstevel@tonic-gate diffptr->length = tempp2->length; 1329*0Sstevel@tonic-gate d = (mib2_sctp_t *)calloc(tempp2->length, 1); 1330*0Sstevel@tonic-gate if (d == NULL) 1331*0Sstevel@tonic-gate goto mibdiff_out_of_memory; 1332*0Sstevel@tonic-gate diffptr->valp = d; 1333*0Sstevel@tonic-gate d->sctpRtoAlgorithm = s2->sctpRtoAlgorithm; 1334*0Sstevel@tonic-gate d->sctpRtoMin = s2->sctpRtoMin; 1335*0Sstevel@tonic-gate d->sctpRtoMax = s2->sctpRtoMax; 1336*0Sstevel@tonic-gate d->sctpRtoInitial = s2->sctpRtoInitial; 1337*0Sstevel@tonic-gate d->sctpMaxAssocs = s2->sctpMaxAssocs; 1338*0Sstevel@tonic-gate d->sctpValCookieLife = s2->sctpValCookieLife; 1339*0Sstevel@tonic-gate d->sctpMaxInitRetr = s2->sctpMaxInitRetr; 1340*0Sstevel@tonic-gate d->sctpCurrEstab = s2->sctpCurrEstab; 1341*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpActiveEstab); 1342*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpPassiveEstab); 1343*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpAborted); 1344*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpShutdowns); 1345*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutOfBlue); 1346*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpChecksumError); 1347*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutCtrlChunks); 1348*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutOrderChunks); 1349*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutUnorderChunks); 1350*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpRetransChunks); 1351*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutAck); 1352*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutAckDelayed); 1353*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutWinUpdate); 1354*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutFastRetrans); 1355*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutWinProbe); 1356*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInCtrlChunks); 1357*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInOrderChunks); 1358*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInUnorderChunks); 1359*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInAck); 1360*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInDupAck); 1361*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInAckUnsent); 1362*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpFragUsrMsgs); 1363*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpReasmUsrMsgs); 1364*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutSCTPPkts); 1365*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInSCTPPkts); 1366*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInInvalidCookie); 1367*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpTimRetrans); 1368*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpTimRetransDrop); 1369*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpTimHeartBeatProbe); 1370*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpTimHeartBeatDrop); 1371*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpListenDrop); 1372*0Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInClosed); 1373*0Sstevel@tonic-gate prevp = diffptr++; 1374*0Sstevel@tonic-gate break; 1375*0Sstevel@tonic-gate } 1376*0Sstevel@tonic-gate case EXPER_RAWIP: { 1377*0Sstevel@tonic-gate mib2_rawip_t *r2; 1378*0Sstevel@tonic-gate mib2_rawip_t *r1; 1379*0Sstevel@tonic-gate mib2_rawip_t *d; 1380*0Sstevel@tonic-gate 1381*0Sstevel@tonic-gate r2 = (mib2_rawip_t *)tempp2->valp; 1382*0Sstevel@tonic-gate r1 = (mib2_rawip_t *)tempp1->valp; 1383*0Sstevel@tonic-gate diffptr->group = tempp2->group; 1384*0Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id; 1385*0Sstevel@tonic-gate diffptr->length = tempp2->length; 1386*0Sstevel@tonic-gate d = (mib2_rawip_t *)calloc(tempp2->length, 1); 1387*0Sstevel@tonic-gate if (d == NULL) 1388*0Sstevel@tonic-gate goto mibdiff_out_of_memory; 1389*0Sstevel@tonic-gate diffptr->valp = d; 1390*0Sstevel@tonic-gate MDIFF(d, r2, r1, rawipInDatagrams); 1391*0Sstevel@tonic-gate MDIFF(d, r2, r1, rawipInErrors); 1392*0Sstevel@tonic-gate MDIFF(d, r2, r1, rawipInCksumErrs); 1393*0Sstevel@tonic-gate MDIFF(d, r2, r1, rawipOutDatagrams); 1394*0Sstevel@tonic-gate MDIFF(d, r2, r1, rawipOutErrors); 1395*0Sstevel@tonic-gate prevp = diffptr++; 1396*0Sstevel@tonic-gate break; 1397*0Sstevel@tonic-gate } 1398*0Sstevel@tonic-gate /* 1399*0Sstevel@tonic-gate * there are more "group" types but they aren't 1400*0Sstevel@tonic-gate * required for the -s and -Ms options 1401*0Sstevel@tonic-gate */ 1402*0Sstevel@tonic-gate } 1403*0Sstevel@tonic-gate } /* 'for' loop 2 ends */ 1404*0Sstevel@tonic-gate tempp1 = NULL; 1405*0Sstevel@tonic-gate } /* 'for' loop 1 ends */ 1406*0Sstevel@tonic-gate tempp2 = NULL; 1407*0Sstevel@tonic-gate diffptr--; 1408*0Sstevel@tonic-gate diffptr->next_item = NULL; 1409*0Sstevel@tonic-gate return (diffp); 1410*0Sstevel@tonic-gate 1411*0Sstevel@tonic-gate mibdiff_out_of_memory:; 1412*0Sstevel@tonic-gate mib_item_destroy(&diffp); 1413*0Sstevel@tonic-gate return (NULL); 1414*0Sstevel@tonic-gate } 1415*0Sstevel@tonic-gate 1416*0Sstevel@tonic-gate /* 1417*0Sstevel@tonic-gate * mib_item_destroy: cleans up a mib_item_t * 1418*0Sstevel@tonic-gate * that was created by calling mib_item_dup or 1419*0Sstevel@tonic-gate * mib_item_diff 1420*0Sstevel@tonic-gate */ 1421*0Sstevel@tonic-gate static void 1422*0Sstevel@tonic-gate mib_item_destroy(mib_item_t **itemp) { 1423*0Sstevel@tonic-gate int nitems = 0; 1424*0Sstevel@tonic-gate int c = 0; 1425*0Sstevel@tonic-gate mib_item_t *tempp; 1426*0Sstevel@tonic-gate 1427*0Sstevel@tonic-gate if (itemp == NULL || *itemp == NULL) 1428*0Sstevel@tonic-gate return; 1429*0Sstevel@tonic-gate 1430*0Sstevel@tonic-gate for (tempp = *itemp; tempp != NULL; tempp = tempp->next_item) 1431*0Sstevel@tonic-gate if (tempp->mib_id == 0) 1432*0Sstevel@tonic-gate nitems++; 1433*0Sstevel@tonic-gate else 1434*0Sstevel@tonic-gate return; /* cannot destroy! */ 1435*0Sstevel@tonic-gate 1436*0Sstevel@tonic-gate if (nitems == 0) 1437*0Sstevel@tonic-gate return; /* cannot destroy! */ 1438*0Sstevel@tonic-gate 1439*0Sstevel@tonic-gate for (c = nitems - 1; c >= 0; c--) { 1440*0Sstevel@tonic-gate if ((itemp[0][c]).valp != NULL) 1441*0Sstevel@tonic-gate free((itemp[0][c]).valp); 1442*0Sstevel@tonic-gate } 1443*0Sstevel@tonic-gate free(*itemp); 1444*0Sstevel@tonic-gate 1445*0Sstevel@tonic-gate *itemp = NULL; 1446*0Sstevel@tonic-gate } 1447*0Sstevel@tonic-gate 1448*0Sstevel@tonic-gate /* Compare two Octet_ts. Return B_TRUE if they match, B_FALSE if not. */ 1449*0Sstevel@tonic-gate static boolean_t 1450*0Sstevel@tonic-gate octetstrmatch(const Octet_t *a, const Octet_t *b) 1451*0Sstevel@tonic-gate { 1452*0Sstevel@tonic-gate if (a == NULL || b == NULL) 1453*0Sstevel@tonic-gate return (B_FALSE); 1454*0Sstevel@tonic-gate 1455*0Sstevel@tonic-gate if (a->o_length != b->o_length) 1456*0Sstevel@tonic-gate return (B_FALSE); 1457*0Sstevel@tonic-gate 1458*0Sstevel@tonic-gate return (memcmp(a->o_bytes, b->o_bytes, a->o_length) == 0); 1459*0Sstevel@tonic-gate } 1460*0Sstevel@tonic-gate 1461*0Sstevel@tonic-gate /* If octetstr() changes make an appropriate change to STR_EXPAND */ 1462*0Sstevel@tonic-gate static char * 1463*0Sstevel@tonic-gate octetstr(Octet_t *op, int code, char *dst, uint_t dstlen) 1464*0Sstevel@tonic-gate { 1465*0Sstevel@tonic-gate int i; 1466*0Sstevel@tonic-gate char *cp; 1467*0Sstevel@tonic-gate 1468*0Sstevel@tonic-gate cp = dst; 1469*0Sstevel@tonic-gate if (op) { 1470*0Sstevel@tonic-gate for (i = 0; i < op->o_length; i++) { 1471*0Sstevel@tonic-gate switch (code) { 1472*0Sstevel@tonic-gate case 'd': 1473*0Sstevel@tonic-gate if (cp - dst + 4 > dstlen) { 1474*0Sstevel@tonic-gate *cp = '\0'; 1475*0Sstevel@tonic-gate return (dst); 1476*0Sstevel@tonic-gate } 1477*0Sstevel@tonic-gate (void) snprintf(cp, 5, "%d.", 1478*0Sstevel@tonic-gate 0xff & op->o_bytes[i]); 1479*0Sstevel@tonic-gate cp = strchr(cp, '\0'); 1480*0Sstevel@tonic-gate break; 1481*0Sstevel@tonic-gate case 'a': 1482*0Sstevel@tonic-gate if (cp - dst + 1 > dstlen) { 1483*0Sstevel@tonic-gate *cp = '\0'; 1484*0Sstevel@tonic-gate return (dst); 1485*0Sstevel@tonic-gate } 1486*0Sstevel@tonic-gate *cp++ = op->o_bytes[i]; 1487*0Sstevel@tonic-gate break; 1488*0Sstevel@tonic-gate case 'h': 1489*0Sstevel@tonic-gate default: 1490*0Sstevel@tonic-gate if (cp - dst + 3 > dstlen) { 1491*0Sstevel@tonic-gate *cp = '\0'; 1492*0Sstevel@tonic-gate return (dst); 1493*0Sstevel@tonic-gate } 1494*0Sstevel@tonic-gate (void) snprintf(cp, 4, "%02x:", 1495*0Sstevel@tonic-gate 0xff & op->o_bytes[i]); 1496*0Sstevel@tonic-gate cp += 3; 1497*0Sstevel@tonic-gate break; 1498*0Sstevel@tonic-gate } 1499*0Sstevel@tonic-gate } 1500*0Sstevel@tonic-gate } 1501*0Sstevel@tonic-gate if (code != 'a' && cp != dst) 1502*0Sstevel@tonic-gate cp--; 1503*0Sstevel@tonic-gate *cp = '\0'; 1504*0Sstevel@tonic-gate return (dst); 1505*0Sstevel@tonic-gate } 1506*0Sstevel@tonic-gate 1507*0Sstevel@tonic-gate static char * 1508*0Sstevel@tonic-gate mitcp_state(int state) 1509*0Sstevel@tonic-gate { 1510*0Sstevel@tonic-gate static char tcpsbuf[50]; 1511*0Sstevel@tonic-gate char *cp; 1512*0Sstevel@tonic-gate 1513*0Sstevel@tonic-gate switch (state) { 1514*0Sstevel@tonic-gate case TCPS_CLOSED: 1515*0Sstevel@tonic-gate cp = "CLOSED"; 1516*0Sstevel@tonic-gate break; 1517*0Sstevel@tonic-gate case TCPS_IDLE: 1518*0Sstevel@tonic-gate cp = "IDLE"; 1519*0Sstevel@tonic-gate break; 1520*0Sstevel@tonic-gate case TCPS_BOUND: 1521*0Sstevel@tonic-gate cp = "BOUND"; 1522*0Sstevel@tonic-gate break; 1523*0Sstevel@tonic-gate case TCPS_LISTEN: 1524*0Sstevel@tonic-gate cp = "LISTEN"; 1525*0Sstevel@tonic-gate break; 1526*0Sstevel@tonic-gate case TCPS_SYN_SENT: 1527*0Sstevel@tonic-gate cp = "SYN_SENT"; 1528*0Sstevel@tonic-gate break; 1529*0Sstevel@tonic-gate case TCPS_SYN_RCVD: 1530*0Sstevel@tonic-gate cp = "SYN_RCVD"; 1531*0Sstevel@tonic-gate break; 1532*0Sstevel@tonic-gate case TCPS_ESTABLISHED: 1533*0Sstevel@tonic-gate cp = "ESTABLISHED"; 1534*0Sstevel@tonic-gate break; 1535*0Sstevel@tonic-gate case TCPS_CLOSE_WAIT: 1536*0Sstevel@tonic-gate cp = "CLOSE_WAIT"; 1537*0Sstevel@tonic-gate break; 1538*0Sstevel@tonic-gate case TCPS_FIN_WAIT_1: 1539*0Sstevel@tonic-gate cp = "FIN_WAIT_1"; 1540*0Sstevel@tonic-gate break; 1541*0Sstevel@tonic-gate case TCPS_CLOSING: 1542*0Sstevel@tonic-gate cp = "CLOSING"; 1543*0Sstevel@tonic-gate break; 1544*0Sstevel@tonic-gate case TCPS_LAST_ACK: 1545*0Sstevel@tonic-gate cp = "LAST_ACK"; 1546*0Sstevel@tonic-gate break; 1547*0Sstevel@tonic-gate case TCPS_FIN_WAIT_2: 1548*0Sstevel@tonic-gate cp = "FIN_WAIT_2"; 1549*0Sstevel@tonic-gate break; 1550*0Sstevel@tonic-gate case TCPS_TIME_WAIT: 1551*0Sstevel@tonic-gate cp = "TIME_WAIT"; 1552*0Sstevel@tonic-gate break; 1553*0Sstevel@tonic-gate default: 1554*0Sstevel@tonic-gate (void) snprintf(tcpsbuf, sizeof (tcpsbuf), 1555*0Sstevel@tonic-gate "UnknownState(%d)", state); 1556*0Sstevel@tonic-gate cp = tcpsbuf; 1557*0Sstevel@tonic-gate break; 1558*0Sstevel@tonic-gate } 1559*0Sstevel@tonic-gate return (cp); 1560*0Sstevel@tonic-gate } 1561*0Sstevel@tonic-gate 1562*0Sstevel@tonic-gate static int odd; 1563*0Sstevel@tonic-gate 1564*0Sstevel@tonic-gate static void 1565*0Sstevel@tonic-gate prval_init(void) 1566*0Sstevel@tonic-gate { 1567*0Sstevel@tonic-gate odd = 0; 1568*0Sstevel@tonic-gate } 1569*0Sstevel@tonic-gate 1570*0Sstevel@tonic-gate static void 1571*0Sstevel@tonic-gate prval(char *str, Counter val) 1572*0Sstevel@tonic-gate { 1573*0Sstevel@tonic-gate (void) printf("\t%-20s=%6u", str, val); 1574*0Sstevel@tonic-gate if (odd++ & 1) 1575*0Sstevel@tonic-gate (void) putchar('\n'); 1576*0Sstevel@tonic-gate } 1577*0Sstevel@tonic-gate 1578*0Sstevel@tonic-gate static void 1579*0Sstevel@tonic-gate prval64(char *str, Counter64 val) 1580*0Sstevel@tonic-gate { 1581*0Sstevel@tonic-gate (void) printf("\t%-20s=%6llu", str, val); 1582*0Sstevel@tonic-gate if (odd++ & 1) 1583*0Sstevel@tonic-gate (void) putchar('\n'); 1584*0Sstevel@tonic-gate } 1585*0Sstevel@tonic-gate 1586*0Sstevel@tonic-gate static void 1587*0Sstevel@tonic-gate pr_int_val(char *str, int val) 1588*0Sstevel@tonic-gate { 1589*0Sstevel@tonic-gate (void) printf("\t%-20s=%6d", str, val); 1590*0Sstevel@tonic-gate if (odd++ & 1) 1591*0Sstevel@tonic-gate (void) putchar('\n'); 1592*0Sstevel@tonic-gate } 1593*0Sstevel@tonic-gate 1594*0Sstevel@tonic-gate static void 1595*0Sstevel@tonic-gate pr_sctp_rtoalgo(char *str, int val) 1596*0Sstevel@tonic-gate { 1597*0Sstevel@tonic-gate (void) printf("\t%-20s=", str); 1598*0Sstevel@tonic-gate switch (val) { 1599*0Sstevel@tonic-gate case MIB2_SCTP_RTOALGO_OTHER: 1600*0Sstevel@tonic-gate (void) printf("%6.6s", "other"); 1601*0Sstevel@tonic-gate break; 1602*0Sstevel@tonic-gate 1603*0Sstevel@tonic-gate case MIB2_SCTP_RTOALGO_VANJ: 1604*0Sstevel@tonic-gate (void) printf("%6.6s", "vanj"); 1605*0Sstevel@tonic-gate break; 1606*0Sstevel@tonic-gate 1607*0Sstevel@tonic-gate default: 1608*0Sstevel@tonic-gate (void) printf("%6d", val); 1609*0Sstevel@tonic-gate break; 1610*0Sstevel@tonic-gate } 1611*0Sstevel@tonic-gate if (odd++ & 1) 1612*0Sstevel@tonic-gate (void) putchar('\n'); 1613*0Sstevel@tonic-gate } 1614*0Sstevel@tonic-gate 1615*0Sstevel@tonic-gate static void 1616*0Sstevel@tonic-gate prval_end(void) 1617*0Sstevel@tonic-gate { 1618*0Sstevel@tonic-gate if (odd++ & 1) 1619*0Sstevel@tonic-gate (void) putchar('\n'); 1620*0Sstevel@tonic-gate } 1621*0Sstevel@tonic-gate 1622*0Sstevel@tonic-gate /* Extract constant sizes */ 1623*0Sstevel@tonic-gate static void 1624*0Sstevel@tonic-gate mib_get_constants(mib_item_t *item) 1625*0Sstevel@tonic-gate { 1626*0Sstevel@tonic-gate /* 'for' loop 1: */ 1627*0Sstevel@tonic-gate for (; item; item = item->next_item) { 1628*0Sstevel@tonic-gate if (item->mib_id != 0) 1629*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 1630*0Sstevel@tonic-gate 1631*0Sstevel@tonic-gate switch (item->group) { 1632*0Sstevel@tonic-gate case MIB2_IP: { 1633*0Sstevel@tonic-gate mib2_ip_t *ip = (mib2_ip_t *)item->valp; 1634*0Sstevel@tonic-gate 1635*0Sstevel@tonic-gate ipAddrEntrySize = ip->ipAddrEntrySize; 1636*0Sstevel@tonic-gate ipRouteEntrySize = ip->ipRouteEntrySize; 1637*0Sstevel@tonic-gate ipNetToMediaEntrySize = ip->ipNetToMediaEntrySize; 1638*0Sstevel@tonic-gate ipMemberEntrySize = ip->ipMemberEntrySize; 1639*0Sstevel@tonic-gate ipGroupSourceEntrySize = ip->ipGroupSourceEntrySize; 1640*0Sstevel@tonic-gate assert(IS_P2ALIGNED(ipAddrEntrySize, 1641*0Sstevel@tonic-gate sizeof (mib2_ipAddrEntry_t *)) && 1642*0Sstevel@tonic-gate IS_P2ALIGNED(ipRouteEntrySize, 1643*0Sstevel@tonic-gate sizeof (mib2_ipRouteEntry_t *)) && 1644*0Sstevel@tonic-gate IS_P2ALIGNED(ipNetToMediaEntrySize, 1645*0Sstevel@tonic-gate sizeof (mib2_ipNetToMediaEntry_t *)) && 1646*0Sstevel@tonic-gate IS_P2ALIGNED(ipMemberEntrySize, 1647*0Sstevel@tonic-gate sizeof (ip_member_t *)) && 1648*0Sstevel@tonic-gate IS_P2ALIGNED(ipGroupSourceEntrySize, 1649*0Sstevel@tonic-gate sizeof (ip_grpsrc_t *))); 1650*0Sstevel@tonic-gate break; 1651*0Sstevel@tonic-gate } 1652*0Sstevel@tonic-gate case EXPER_DVMRP: { 1653*0Sstevel@tonic-gate struct mrtstat *mrts = (struct mrtstat *)item->valp; 1654*0Sstevel@tonic-gate 1655*0Sstevel@tonic-gate vifctlSize = mrts->mrts_vifctlSize; 1656*0Sstevel@tonic-gate mfcctlSize = mrts->mrts_mfcctlSize; 1657*0Sstevel@tonic-gate assert(IS_P2ALIGNED(vifctlSize, 1658*0Sstevel@tonic-gate sizeof (struct vifclt *)) && 1659*0Sstevel@tonic-gate IS_P2ALIGNED(mfcctlSize, sizeof (struct mfcctl *))); 1660*0Sstevel@tonic-gate break; 1661*0Sstevel@tonic-gate } 1662*0Sstevel@tonic-gate case MIB2_IP6: { 1663*0Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t *ip6; 1664*0Sstevel@tonic-gate /* Just use the first entry */ 1665*0Sstevel@tonic-gate 1666*0Sstevel@tonic-gate ip6 = (mib2_ipv6IfStatsEntry_t *)item->valp; 1667*0Sstevel@tonic-gate ipv6IfStatsEntrySize = ip6->ipv6IfStatsEntrySize; 1668*0Sstevel@tonic-gate ipv6AddrEntrySize = ip6->ipv6AddrEntrySize; 1669*0Sstevel@tonic-gate ipv6RouteEntrySize = ip6->ipv6RouteEntrySize; 1670*0Sstevel@tonic-gate ipv6NetToMediaEntrySize = ip6->ipv6NetToMediaEntrySize; 1671*0Sstevel@tonic-gate ipv6MemberEntrySize = ip6->ipv6MemberEntrySize; 1672*0Sstevel@tonic-gate ipv6GroupSourceEntrySize = 1673*0Sstevel@tonic-gate ip6->ipv6GroupSourceEntrySize; 1674*0Sstevel@tonic-gate assert(IS_P2ALIGNED(ipv6IfStatsEntrySize, 1675*0Sstevel@tonic-gate sizeof (mib2_ipv6IfStatsEntry_t *)) && 1676*0Sstevel@tonic-gate IS_P2ALIGNED(ipv6AddrEntrySize, 1677*0Sstevel@tonic-gate sizeof (mib2_ipv6AddrEntry_t *)) && 1678*0Sstevel@tonic-gate IS_P2ALIGNED(ipv6RouteEntrySize, 1679*0Sstevel@tonic-gate sizeof (mib2_ipv6RouteEntry_t *)) && 1680*0Sstevel@tonic-gate IS_P2ALIGNED(ipv6NetToMediaEntrySize, 1681*0Sstevel@tonic-gate sizeof (mib2_ipv6NetToMediaEntry_t *)) && 1682*0Sstevel@tonic-gate IS_P2ALIGNED(ipv6MemberEntrySize, 1683*0Sstevel@tonic-gate sizeof (ipv6_member_t *)) && 1684*0Sstevel@tonic-gate IS_P2ALIGNED(ipv6GroupSourceEntrySize, 1685*0Sstevel@tonic-gate sizeof (ipv6_grpsrc_t *))); 1686*0Sstevel@tonic-gate break; 1687*0Sstevel@tonic-gate } 1688*0Sstevel@tonic-gate case MIB2_ICMP6: { 1689*0Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t *icmp6; 1690*0Sstevel@tonic-gate /* Just use the first entry */ 1691*0Sstevel@tonic-gate 1692*0Sstevel@tonic-gate icmp6 = (mib2_ipv6IfIcmpEntry_t *)item->valp; 1693*0Sstevel@tonic-gate ipv6IfIcmpEntrySize = icmp6->ipv6IfIcmpEntrySize; 1694*0Sstevel@tonic-gate assert(IS_P2ALIGNED(ipv6IfIcmpEntrySize, 1695*0Sstevel@tonic-gate sizeof (mib2_ipv6IfIcmpEntry_t *))); 1696*0Sstevel@tonic-gate break; 1697*0Sstevel@tonic-gate } 1698*0Sstevel@tonic-gate case MIB2_TCP: { 1699*0Sstevel@tonic-gate mib2_tcp_t *tcp = (mib2_tcp_t *)item->valp; 1700*0Sstevel@tonic-gate 1701*0Sstevel@tonic-gate tcpConnEntrySize = tcp->tcpConnTableSize; 1702*0Sstevel@tonic-gate tcp6ConnEntrySize = tcp->tcp6ConnTableSize; 1703*0Sstevel@tonic-gate assert(IS_P2ALIGNED(tcpConnEntrySize, 1704*0Sstevel@tonic-gate sizeof (mib2_tcpConnEntry_t *)) && 1705*0Sstevel@tonic-gate IS_P2ALIGNED(tcp6ConnEntrySize, 1706*0Sstevel@tonic-gate sizeof (mib2_tcp6ConnEntry_t *))); 1707*0Sstevel@tonic-gate break; 1708*0Sstevel@tonic-gate } 1709*0Sstevel@tonic-gate case MIB2_UDP: { 1710*0Sstevel@tonic-gate mib2_udp_t *udp = (mib2_udp_t *)item->valp; 1711*0Sstevel@tonic-gate 1712*0Sstevel@tonic-gate udpEntrySize = udp->udpEntrySize; 1713*0Sstevel@tonic-gate udp6EntrySize = udp->udp6EntrySize; 1714*0Sstevel@tonic-gate assert(IS_P2ALIGNED(udpEntrySize, 1715*0Sstevel@tonic-gate sizeof (mib2_udpEntry_t *)) && 1716*0Sstevel@tonic-gate IS_P2ALIGNED(udp6EntrySize, 1717*0Sstevel@tonic-gate sizeof (mib2_udp6Entry_t *))); 1718*0Sstevel@tonic-gate break; 1719*0Sstevel@tonic-gate } 1720*0Sstevel@tonic-gate case MIB2_SCTP: { 1721*0Sstevel@tonic-gate mib2_sctp_t *sctp = (mib2_sctp_t *)item->valp; 1722*0Sstevel@tonic-gate 1723*0Sstevel@tonic-gate sctpEntrySize = sctp->sctpEntrySize; 1724*0Sstevel@tonic-gate sctpLocalEntrySize = sctp->sctpLocalEntrySize; 1725*0Sstevel@tonic-gate sctpRemoteEntrySize = sctp->sctpRemoteEntrySize; 1726*0Sstevel@tonic-gate break; 1727*0Sstevel@tonic-gate } 1728*0Sstevel@tonic-gate } 1729*0Sstevel@tonic-gate } /* 'for' loop 1 ends */ 1730*0Sstevel@tonic-gate 1731*0Sstevel@tonic-gate if (Dflag) { 1732*0Sstevel@tonic-gate (void) puts("mib_get_constants:"); 1733*0Sstevel@tonic-gate (void) printf("\tipv6IfStatsEntrySize %d\n", 1734*0Sstevel@tonic-gate ipv6IfStatsEntrySize); 1735*0Sstevel@tonic-gate (void) printf("\tipAddrEntrySize %d\n", ipAddrEntrySize); 1736*0Sstevel@tonic-gate (void) printf("\tipRouteEntrySize %d\n", ipRouteEntrySize); 1737*0Sstevel@tonic-gate (void) printf("\tipNetToMediaEntrySize %d\n", 1738*0Sstevel@tonic-gate ipNetToMediaEntrySize); 1739*0Sstevel@tonic-gate (void) printf("\tipMemberEntrySize %d\n", ipMemberEntrySize); 1740*0Sstevel@tonic-gate (void) printf("\tvifctlSize %d\n", vifctlSize); 1741*0Sstevel@tonic-gate (void) printf("\tmfcctlSize %d\n", mfcctlSize); 1742*0Sstevel@tonic-gate 1743*0Sstevel@tonic-gate (void) printf("\tipv6AddrEntrySize %d\n", ipv6AddrEntrySize); 1744*0Sstevel@tonic-gate (void) printf("\tipv6RouteEntrySize %d\n", ipv6RouteEntrySize); 1745*0Sstevel@tonic-gate (void) printf("\tipv6NetToMediaEntrySize %d\n", 1746*0Sstevel@tonic-gate ipv6NetToMediaEntrySize); 1747*0Sstevel@tonic-gate (void) printf("\tipv6MemberEntrySize %d\n", 1748*0Sstevel@tonic-gate ipv6MemberEntrySize); 1749*0Sstevel@tonic-gate (void) printf("\tipv6IfIcmpEntrySize %d\n", 1750*0Sstevel@tonic-gate ipv6IfIcmpEntrySize); 1751*0Sstevel@tonic-gate (void) printf("\ttcpConnEntrySize %d\n", tcpConnEntrySize); 1752*0Sstevel@tonic-gate (void) printf("\ttcp6ConnEntrySize %d\n", tcp6ConnEntrySize); 1753*0Sstevel@tonic-gate (void) printf("\tudpEntrySize %d\n", udpEntrySize); 1754*0Sstevel@tonic-gate (void) printf("\tudp6EntrySize %d\n", udp6EntrySize); 1755*0Sstevel@tonic-gate (void) printf("\tsctpEntrySize %d\n", sctpEntrySize); 1756*0Sstevel@tonic-gate (void) printf("\tsctpLocalEntrySize %d\n", sctpLocalEntrySize); 1757*0Sstevel@tonic-gate (void) printf("\tsctpRemoteEntrySize %d\n", 1758*0Sstevel@tonic-gate sctpRemoteEntrySize); 1759*0Sstevel@tonic-gate } 1760*0Sstevel@tonic-gate } 1761*0Sstevel@tonic-gate 1762*0Sstevel@tonic-gate 1763*0Sstevel@tonic-gate /* ----------------------------- STAT_REPORT ------------------------------- */ 1764*0Sstevel@tonic-gate 1765*0Sstevel@tonic-gate static void 1766*0Sstevel@tonic-gate stat_report(mib_item_t *item) 1767*0Sstevel@tonic-gate { 1768*0Sstevel@tonic-gate int jtemp = 0; 1769*0Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 1770*0Sstevel@tonic-gate char *ifnamep; 1771*0Sstevel@tonic-gate 1772*0Sstevel@tonic-gate /* 'for' loop 1: */ 1773*0Sstevel@tonic-gate for (; item; item = item->next_item) { 1774*0Sstevel@tonic-gate if (Dflag) { 1775*0Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp); 1776*0Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, " 1777*0Sstevel@tonic-gate "length = %d, valp = 0x%p\n", 1778*0Sstevel@tonic-gate item->group, item->mib_id, 1779*0Sstevel@tonic-gate item->length, item->valp); 1780*0Sstevel@tonic-gate } 1781*0Sstevel@tonic-gate if (item->mib_id != 0) 1782*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 1783*0Sstevel@tonic-gate 1784*0Sstevel@tonic-gate switch (item->group) { 1785*0Sstevel@tonic-gate case MIB2_IP: { 1786*0Sstevel@tonic-gate mib2_ip_t *ip = (mib2_ip_t *)item->valp; 1787*0Sstevel@tonic-gate 1788*0Sstevel@tonic-gate if (protocol_selected(IPPROTO_IP) && 1789*0Sstevel@tonic-gate family_selected(AF_INET)) { 1790*0Sstevel@tonic-gate (void) fputs(v4compat ? "\nIP" : "\nIPv4", 1791*0Sstevel@tonic-gate stdout); 1792*0Sstevel@tonic-gate print_ip_stats(ip); 1793*0Sstevel@tonic-gate } 1794*0Sstevel@tonic-gate break; 1795*0Sstevel@tonic-gate } 1796*0Sstevel@tonic-gate case MIB2_ICMP: { 1797*0Sstevel@tonic-gate mib2_icmp_t *icmp = 1798*0Sstevel@tonic-gate (mib2_icmp_t *)item->valp; 1799*0Sstevel@tonic-gate 1800*0Sstevel@tonic-gate if (protocol_selected(IPPROTO_ICMP) && 1801*0Sstevel@tonic-gate family_selected(AF_INET)) { 1802*0Sstevel@tonic-gate (void) fputs(v4compat ? "\nICMP" : "\nICMPv4", 1803*0Sstevel@tonic-gate stdout); 1804*0Sstevel@tonic-gate print_icmp_stats(icmp); 1805*0Sstevel@tonic-gate } 1806*0Sstevel@tonic-gate break; 1807*0Sstevel@tonic-gate } 1808*0Sstevel@tonic-gate case MIB2_IP6: { 1809*0Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t *ip6; 1810*0Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t sum6; 1811*0Sstevel@tonic-gate 1812*0Sstevel@tonic-gate if (!(protocol_selected(IPPROTO_IPV6)) || 1813*0Sstevel@tonic-gate !(family_selected(AF_INET6))) 1814*0Sstevel@tonic-gate break; 1815*0Sstevel@tonic-gate bzero(&sum6, sizeof (sum6)); 1816*0Sstevel@tonic-gate /* 'for' loop 2a: */ 1817*0Sstevel@tonic-gate for (ip6 = (mib2_ipv6IfStatsEntry_t *)item->valp; 1818*0Sstevel@tonic-gate (char *)ip6 < (char *)item->valp 1819*0Sstevel@tonic-gate + item->length; 1820*0Sstevel@tonic-gate /* LINTED: (note 1) */ 1821*0Sstevel@tonic-gate ip6 = (mib2_ipv6IfStatsEntry_t *)((char *)ip6 + 1822*0Sstevel@tonic-gate ipv6IfStatsEntrySize)) { 1823*0Sstevel@tonic-gate 1824*0Sstevel@tonic-gate if (ip6->ipv6IfIndex == 0) { 1825*0Sstevel@tonic-gate /* 1826*0Sstevel@tonic-gate * The "unknown interface" ip6 1827*0Sstevel@tonic-gate * mib. Just add to the sum. 1828*0Sstevel@tonic-gate */ 1829*0Sstevel@tonic-gate sum_ip6_stats(ip6, &sum6); 1830*0Sstevel@tonic-gate continue; /* 'for' loop 2a */ 1831*0Sstevel@tonic-gate } 1832*0Sstevel@tonic-gate ifnamep = if_indextoname( 1833*0Sstevel@tonic-gate ip6->ipv6IfIndex, 1834*0Sstevel@tonic-gate ifname); 1835*0Sstevel@tonic-gate if (ifnamep == NULL) { 1836*0Sstevel@tonic-gate (void) printf( 1837*0Sstevel@tonic-gate "Invalid ifindex %d\n", 1838*0Sstevel@tonic-gate ip6->ipv6IfIndex); 1839*0Sstevel@tonic-gate continue; /* 'for' loop 2a */ 1840*0Sstevel@tonic-gate } 1841*0Sstevel@tonic-gate 1842*0Sstevel@tonic-gate if (Aflag) { 1843*0Sstevel@tonic-gate (void) printf("\nIPv6 for %s\n", 1844*0Sstevel@tonic-gate ifnamep); 1845*0Sstevel@tonic-gate print_ip6_stats(ip6); 1846*0Sstevel@tonic-gate } 1847*0Sstevel@tonic-gate sum_ip6_stats(ip6, &sum6); 1848*0Sstevel@tonic-gate } /* 'for' loop 2a ends */ 1849*0Sstevel@tonic-gate (void) fputs("\nIPv6", stdout); 1850*0Sstevel@tonic-gate print_ip6_stats(&sum6); 1851*0Sstevel@tonic-gate break; 1852*0Sstevel@tonic-gate } 1853*0Sstevel@tonic-gate case MIB2_ICMP6: { 1854*0Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t *icmp6; 1855*0Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t sum6; 1856*0Sstevel@tonic-gate 1857*0Sstevel@tonic-gate if (!(protocol_selected(IPPROTO_ICMPV6)) || 1858*0Sstevel@tonic-gate !(family_selected(AF_INET6))) 1859*0Sstevel@tonic-gate break; 1860*0Sstevel@tonic-gate bzero(&sum6, sizeof (sum6)); 1861*0Sstevel@tonic-gate /* 'for' loop 2b: */ 1862*0Sstevel@tonic-gate for (icmp6 = 1863*0Sstevel@tonic-gate (mib2_ipv6IfIcmpEntry_t *)item->valp; 1864*0Sstevel@tonic-gate (char *)icmp6 < (char *)item->valp 1865*0Sstevel@tonic-gate + item->length; 1866*0Sstevel@tonic-gate icmp6 = 1867*0Sstevel@tonic-gate /* LINTED: (note 1) */ 1868*0Sstevel@tonic-gate (mib2_ipv6IfIcmpEntry_t *)((char *)icmp6 1869*0Sstevel@tonic-gate + ipv6IfIcmpEntrySize)) { 1870*0Sstevel@tonic-gate 1871*0Sstevel@tonic-gate if (icmp6->ipv6IfIcmpIfIndex == 0) { 1872*0Sstevel@tonic-gate /* 1873*0Sstevel@tonic-gate * The "unknown interface" icmp6 1874*0Sstevel@tonic-gate * mib. Just add to the sum. 1875*0Sstevel@tonic-gate */ 1876*0Sstevel@tonic-gate sum_icmp6_stats(icmp6, &sum6); 1877*0Sstevel@tonic-gate continue; /* 'for' loop 2b: */ 1878*0Sstevel@tonic-gate } 1879*0Sstevel@tonic-gate ifnamep = if_indextoname( 1880*0Sstevel@tonic-gate icmp6->ipv6IfIcmpIfIndex, ifname); 1881*0Sstevel@tonic-gate if (ifnamep == NULL) { 1882*0Sstevel@tonic-gate (void) printf( 1883*0Sstevel@tonic-gate "Invalid ifindex %d\n", 1884*0Sstevel@tonic-gate icmp6->ipv6IfIcmpIfIndex); 1885*0Sstevel@tonic-gate continue; /* 'for' loop 2b: */ 1886*0Sstevel@tonic-gate } 1887*0Sstevel@tonic-gate 1888*0Sstevel@tonic-gate if (Aflag) { 1889*0Sstevel@tonic-gate (void) printf( 1890*0Sstevel@tonic-gate "\nICMPv6 for %s\n", 1891*0Sstevel@tonic-gate ifnamep); 1892*0Sstevel@tonic-gate print_icmp6_stats(icmp6); 1893*0Sstevel@tonic-gate } 1894*0Sstevel@tonic-gate sum_icmp6_stats(icmp6, &sum6); 1895*0Sstevel@tonic-gate } /* 'for' loop 2b ends */ 1896*0Sstevel@tonic-gate (void) fputs("\nICMPv6", stdout); 1897*0Sstevel@tonic-gate print_icmp6_stats(&sum6); 1898*0Sstevel@tonic-gate break; 1899*0Sstevel@tonic-gate } 1900*0Sstevel@tonic-gate case MIB2_TCP: { 1901*0Sstevel@tonic-gate mib2_tcp_t *tcp = (mib2_tcp_t *)item->valp; 1902*0Sstevel@tonic-gate 1903*0Sstevel@tonic-gate if (protocol_selected(IPPROTO_TCP) && 1904*0Sstevel@tonic-gate (family_selected(AF_INET) || 1905*0Sstevel@tonic-gate family_selected(AF_INET6))) { 1906*0Sstevel@tonic-gate (void) fputs("\nTCP", stdout); 1907*0Sstevel@tonic-gate print_tcp_stats(tcp); 1908*0Sstevel@tonic-gate } 1909*0Sstevel@tonic-gate break; 1910*0Sstevel@tonic-gate } 1911*0Sstevel@tonic-gate case MIB2_UDP: { 1912*0Sstevel@tonic-gate mib2_udp_t *udp = (mib2_udp_t *)item->valp; 1913*0Sstevel@tonic-gate 1914*0Sstevel@tonic-gate if (protocol_selected(IPPROTO_UDP) && 1915*0Sstevel@tonic-gate (family_selected(AF_INET) || 1916*0Sstevel@tonic-gate family_selected(AF_INET6))) { 1917*0Sstevel@tonic-gate (void) fputs("\nUDP", stdout); 1918*0Sstevel@tonic-gate print_udp_stats(udp); 1919*0Sstevel@tonic-gate } 1920*0Sstevel@tonic-gate break; 1921*0Sstevel@tonic-gate } 1922*0Sstevel@tonic-gate case MIB2_SCTP: { 1923*0Sstevel@tonic-gate mib2_sctp_t *sctp = (mib2_sctp_t *)item->valp; 1924*0Sstevel@tonic-gate 1925*0Sstevel@tonic-gate if (protocol_selected(IPPROTO_SCTP) && 1926*0Sstevel@tonic-gate (family_selected(AF_INET) || 1927*0Sstevel@tonic-gate family_selected(AF_INET6))) { 1928*0Sstevel@tonic-gate (void) fputs("\nSCTP", stdout); 1929*0Sstevel@tonic-gate print_sctp_stats(sctp); 1930*0Sstevel@tonic-gate } 1931*0Sstevel@tonic-gate break; 1932*0Sstevel@tonic-gate } 1933*0Sstevel@tonic-gate case EXPER_RAWIP: { 1934*0Sstevel@tonic-gate mib2_rawip_t *rawip = 1935*0Sstevel@tonic-gate (mib2_rawip_t *)item->valp; 1936*0Sstevel@tonic-gate 1937*0Sstevel@tonic-gate if (protocol_selected(IPPROTO_RAW) && 1938*0Sstevel@tonic-gate (family_selected(AF_INET) || 1939*0Sstevel@tonic-gate family_selected(AF_INET6))) { 1940*0Sstevel@tonic-gate (void) fputs("\nRAWIP", stdout); 1941*0Sstevel@tonic-gate print_rawip_stats(rawip); 1942*0Sstevel@tonic-gate } 1943*0Sstevel@tonic-gate break; 1944*0Sstevel@tonic-gate } 1945*0Sstevel@tonic-gate case EXPER_IGMP: { 1946*0Sstevel@tonic-gate struct igmpstat *igps = 1947*0Sstevel@tonic-gate (struct igmpstat *)item->valp; 1948*0Sstevel@tonic-gate 1949*0Sstevel@tonic-gate if (protocol_selected(IPPROTO_IGMP) && 1950*0Sstevel@tonic-gate (family_selected(AF_INET))) { 1951*0Sstevel@tonic-gate (void) fputs("\nIGMP:\n", stdout); 1952*0Sstevel@tonic-gate print_igmp_stats(igps); 1953*0Sstevel@tonic-gate } 1954*0Sstevel@tonic-gate break; 1955*0Sstevel@tonic-gate } 1956*0Sstevel@tonic-gate } 1957*0Sstevel@tonic-gate } /* 'for' loop 1 ends */ 1958*0Sstevel@tonic-gate (void) putchar('\n'); 1959*0Sstevel@tonic-gate (void) fflush(stdout); 1960*0Sstevel@tonic-gate } 1961*0Sstevel@tonic-gate 1962*0Sstevel@tonic-gate static void 1963*0Sstevel@tonic-gate print_ip_stats(mib2_ip_t *ip) 1964*0Sstevel@tonic-gate { 1965*0Sstevel@tonic-gate prval_init(); 1966*0Sstevel@tonic-gate pr_int_val("ipForwarding", ip->ipForwarding); 1967*0Sstevel@tonic-gate pr_int_val("ipDefaultTTL", ip->ipDefaultTTL); 1968*0Sstevel@tonic-gate prval("ipInReceives", ip->ipInReceives); 1969*0Sstevel@tonic-gate prval("ipInHdrErrors", ip->ipInHdrErrors); 1970*0Sstevel@tonic-gate prval("ipInAddrErrors", ip->ipInAddrErrors); 1971*0Sstevel@tonic-gate prval("ipInCksumErrs", ip->ipInCksumErrs); 1972*0Sstevel@tonic-gate prval("ipForwDatagrams", ip->ipForwDatagrams); 1973*0Sstevel@tonic-gate prval("ipForwProhibits", ip->ipForwProhibits); 1974*0Sstevel@tonic-gate prval("ipInUnknownProtos", ip->ipInUnknownProtos); 1975*0Sstevel@tonic-gate prval("ipInDiscards", ip->ipInDiscards); 1976*0Sstevel@tonic-gate prval("ipInDelivers", ip->ipInDelivers); 1977*0Sstevel@tonic-gate prval("ipOutRequests", ip->ipOutRequests); 1978*0Sstevel@tonic-gate prval("ipOutDiscards", ip->ipOutDiscards); 1979*0Sstevel@tonic-gate prval("ipOutNoRoutes", ip->ipOutNoRoutes); 1980*0Sstevel@tonic-gate pr_int_val("ipReasmTimeout", ip->ipReasmTimeout); 1981*0Sstevel@tonic-gate prval("ipReasmReqds", ip->ipReasmReqds); 1982*0Sstevel@tonic-gate prval("ipReasmOKs", ip->ipReasmOKs); 1983*0Sstevel@tonic-gate prval("ipReasmFails", ip->ipReasmFails); 1984*0Sstevel@tonic-gate prval("ipReasmDuplicates", ip->ipReasmDuplicates); 1985*0Sstevel@tonic-gate prval("ipReasmPartDups", ip->ipReasmPartDups); 1986*0Sstevel@tonic-gate prval("ipFragOKs", ip->ipFragOKs); 1987*0Sstevel@tonic-gate prval("ipFragFails", ip->ipFragFails); 1988*0Sstevel@tonic-gate prval("ipFragCreates", ip->ipFragCreates); 1989*0Sstevel@tonic-gate prval("ipRoutingDiscards", ip->ipRoutingDiscards); 1990*0Sstevel@tonic-gate 1991*0Sstevel@tonic-gate prval("tcpInErrs", ip->tcpInErrs); 1992*0Sstevel@tonic-gate prval("udpNoPorts", ip->udpNoPorts); 1993*0Sstevel@tonic-gate prval("udpInCksumErrs", ip->udpInCksumErrs); 1994*0Sstevel@tonic-gate prval("udpInOverflows", ip->udpInOverflows); 1995*0Sstevel@tonic-gate prval("rawipInOverflows", ip->rawipInOverflows); 1996*0Sstevel@tonic-gate prval("ipsecInSucceeded", ip->ipsecInSucceeded); 1997*0Sstevel@tonic-gate prval("ipsecInFailed", ip->ipsecInFailed); 1998*0Sstevel@tonic-gate prval("ipInIPv6", ip->ipInIPv6); 1999*0Sstevel@tonic-gate prval("ipOutIPv6", ip->ipOutIPv6); 2000*0Sstevel@tonic-gate prval("ipOutSwitchIPv6", ip->ipOutSwitchIPv6); 2001*0Sstevel@tonic-gate prval_end(); 2002*0Sstevel@tonic-gate } 2003*0Sstevel@tonic-gate 2004*0Sstevel@tonic-gate static void 2005*0Sstevel@tonic-gate print_icmp_stats(mib2_icmp_t *icmp) 2006*0Sstevel@tonic-gate { 2007*0Sstevel@tonic-gate prval_init(); 2008*0Sstevel@tonic-gate prval("icmpInMsgs", icmp->icmpInMsgs); 2009*0Sstevel@tonic-gate prval("icmpInErrors", icmp->icmpInErrors); 2010*0Sstevel@tonic-gate prval("icmpInCksumErrs", icmp->icmpInCksumErrs); 2011*0Sstevel@tonic-gate prval("icmpInUnknowns", icmp->icmpInUnknowns); 2012*0Sstevel@tonic-gate prval("icmpInDestUnreachs", icmp->icmpInDestUnreachs); 2013*0Sstevel@tonic-gate prval("icmpInTimeExcds", icmp->icmpInTimeExcds); 2014*0Sstevel@tonic-gate prval("icmpInParmProbs", icmp->icmpInParmProbs); 2015*0Sstevel@tonic-gate prval("icmpInSrcQuenchs", icmp->icmpInSrcQuenchs); 2016*0Sstevel@tonic-gate prval("icmpInRedirects", icmp->icmpInRedirects); 2017*0Sstevel@tonic-gate prval("icmpInBadRedirects", icmp->icmpInBadRedirects); 2018*0Sstevel@tonic-gate prval("icmpInEchos", icmp->icmpInEchos); 2019*0Sstevel@tonic-gate prval("icmpInEchoReps", icmp->icmpInEchoReps); 2020*0Sstevel@tonic-gate prval("icmpInTimestamps", icmp->icmpInTimestamps); 2021*0Sstevel@tonic-gate prval("icmpInTimestampReps", icmp->icmpInTimestampReps); 2022*0Sstevel@tonic-gate prval("icmpInAddrMasks", icmp->icmpInAddrMasks); 2023*0Sstevel@tonic-gate prval("icmpInAddrMaskReps", icmp->icmpInAddrMaskReps); 2024*0Sstevel@tonic-gate prval("icmpInFragNeeded", icmp->icmpInFragNeeded); 2025*0Sstevel@tonic-gate prval("icmpOutMsgs", icmp->icmpOutMsgs); 2026*0Sstevel@tonic-gate prval("icmpOutDrops", icmp->icmpOutDrops); 2027*0Sstevel@tonic-gate prval("icmpOutErrors", icmp->icmpOutErrors); 2028*0Sstevel@tonic-gate prval("icmpOutDestUnreachs", icmp->icmpOutDestUnreachs); 2029*0Sstevel@tonic-gate prval("icmpOutTimeExcds", icmp->icmpOutTimeExcds); 2030*0Sstevel@tonic-gate prval("icmpOutParmProbs", icmp->icmpOutParmProbs); 2031*0Sstevel@tonic-gate prval("icmpOutSrcQuenchs", icmp->icmpOutSrcQuenchs); 2032*0Sstevel@tonic-gate prval("icmpOutRedirects", icmp->icmpOutRedirects); 2033*0Sstevel@tonic-gate prval("icmpOutEchos", icmp->icmpOutEchos); 2034*0Sstevel@tonic-gate prval("icmpOutEchoReps", icmp->icmpOutEchoReps); 2035*0Sstevel@tonic-gate prval("icmpOutTimestamps", icmp->icmpOutTimestamps); 2036*0Sstevel@tonic-gate prval("icmpOutTimestampReps", icmp->icmpOutTimestampReps); 2037*0Sstevel@tonic-gate prval("icmpOutAddrMasks", icmp->icmpOutAddrMasks); 2038*0Sstevel@tonic-gate prval("icmpOutAddrMaskReps", icmp->icmpOutAddrMaskReps); 2039*0Sstevel@tonic-gate prval("icmpOutFragNeeded", icmp->icmpOutFragNeeded); 2040*0Sstevel@tonic-gate prval("icmpInOverflows", icmp->icmpInOverflows); 2041*0Sstevel@tonic-gate prval_end(); 2042*0Sstevel@tonic-gate } 2043*0Sstevel@tonic-gate 2044*0Sstevel@tonic-gate static void 2045*0Sstevel@tonic-gate print_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6) 2046*0Sstevel@tonic-gate { 2047*0Sstevel@tonic-gate prval_init(); 2048*0Sstevel@tonic-gate prval("ipv6Forwarding", ip6->ipv6Forwarding); 2049*0Sstevel@tonic-gate prval("ipv6DefaultHopLimit", ip6->ipv6DefaultHopLimit); 2050*0Sstevel@tonic-gate 2051*0Sstevel@tonic-gate prval("ipv6InReceives", ip6->ipv6InReceives); 2052*0Sstevel@tonic-gate prval("ipv6InHdrErrors", ip6->ipv6InHdrErrors); 2053*0Sstevel@tonic-gate prval("ipv6InTooBigErrors", ip6->ipv6InTooBigErrors); 2054*0Sstevel@tonic-gate prval("ipv6InNoRoutes", ip6->ipv6InNoRoutes); 2055*0Sstevel@tonic-gate prval("ipv6InAddrErrors", ip6->ipv6InAddrErrors); 2056*0Sstevel@tonic-gate prval("ipv6InUnknownProtos", ip6->ipv6InUnknownProtos); 2057*0Sstevel@tonic-gate prval("ipv6InTruncatedPkts", ip6->ipv6InTruncatedPkts); 2058*0Sstevel@tonic-gate prval("ipv6InDiscards", ip6->ipv6InDiscards); 2059*0Sstevel@tonic-gate prval("ipv6InDelivers", ip6->ipv6InDelivers); 2060*0Sstevel@tonic-gate prval("ipv6OutForwDatagrams", ip6->ipv6OutForwDatagrams); 2061*0Sstevel@tonic-gate prval("ipv6OutRequests", ip6->ipv6OutRequests); 2062*0Sstevel@tonic-gate prval("ipv6OutDiscards", ip6->ipv6OutDiscards); 2063*0Sstevel@tonic-gate prval("ipv6OutNoRoutes", ip6->ipv6OutNoRoutes); 2064*0Sstevel@tonic-gate prval("ipv6OutFragOKs", ip6->ipv6OutFragOKs); 2065*0Sstevel@tonic-gate prval("ipv6OutFragFails", ip6->ipv6OutFragFails); 2066*0Sstevel@tonic-gate prval("ipv6OutFragCreates", ip6->ipv6OutFragCreates); 2067*0Sstevel@tonic-gate prval("ipv6ReasmReqds", ip6->ipv6ReasmReqds); 2068*0Sstevel@tonic-gate prval("ipv6ReasmOKs", ip6->ipv6ReasmOKs); 2069*0Sstevel@tonic-gate prval("ipv6ReasmFails", ip6->ipv6ReasmFails); 2070*0Sstevel@tonic-gate prval("ipv6InMcastPkts", ip6->ipv6InMcastPkts); 2071*0Sstevel@tonic-gate prval("ipv6OutMcastPkts", ip6->ipv6OutMcastPkts); 2072*0Sstevel@tonic-gate prval("ipv6ReasmDuplicates", ip6->ipv6ReasmDuplicates); 2073*0Sstevel@tonic-gate prval("ipv6ReasmPartDups", ip6->ipv6ReasmPartDups); 2074*0Sstevel@tonic-gate prval("ipv6ForwProhibits", ip6->ipv6ForwProhibits); 2075*0Sstevel@tonic-gate prval("udpInCksumErrs", ip6->udpInCksumErrs); 2076*0Sstevel@tonic-gate prval("udpInOverflows", ip6->udpInOverflows); 2077*0Sstevel@tonic-gate prval("rawipInOverflows", ip6->rawipInOverflows); 2078*0Sstevel@tonic-gate prval("ipv6InIPv4", ip6->ipv6InIPv4); 2079*0Sstevel@tonic-gate prval("ipv6OutIPv4", ip6->ipv6OutIPv4); 2080*0Sstevel@tonic-gate prval("ipv6OutSwitchIPv4", ip6->ipv6OutSwitchIPv4); 2081*0Sstevel@tonic-gate prval_end(); 2082*0Sstevel@tonic-gate } 2083*0Sstevel@tonic-gate 2084*0Sstevel@tonic-gate static void 2085*0Sstevel@tonic-gate print_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6) 2086*0Sstevel@tonic-gate { 2087*0Sstevel@tonic-gate prval_init(); 2088*0Sstevel@tonic-gate prval("icmp6InMsgs", icmp6->ipv6IfIcmpInMsgs); 2089*0Sstevel@tonic-gate prval("icmp6InErrors", icmp6->ipv6IfIcmpInErrors); 2090*0Sstevel@tonic-gate prval("icmp6InDestUnreachs", icmp6->ipv6IfIcmpInDestUnreachs); 2091*0Sstevel@tonic-gate prval("icmp6InAdminProhibs", icmp6->ipv6IfIcmpInAdminProhibs); 2092*0Sstevel@tonic-gate prval("icmp6InTimeExcds", icmp6->ipv6IfIcmpInTimeExcds); 2093*0Sstevel@tonic-gate prval("icmp6InParmProblems", icmp6->ipv6IfIcmpInParmProblems); 2094*0Sstevel@tonic-gate prval("icmp6InPktTooBigs", icmp6->ipv6IfIcmpInPktTooBigs); 2095*0Sstevel@tonic-gate prval("icmp6InEchos", icmp6->ipv6IfIcmpInEchos); 2096*0Sstevel@tonic-gate prval("icmp6InEchoReplies", icmp6->ipv6IfIcmpInEchoReplies); 2097*0Sstevel@tonic-gate prval("icmp6InRouterSols", icmp6->ipv6IfIcmpInRouterSolicits); 2098*0Sstevel@tonic-gate prval("icmp6InRouterAds", 2099*0Sstevel@tonic-gate icmp6->ipv6IfIcmpInRouterAdvertisements); 2100*0Sstevel@tonic-gate prval("icmp6InNeighborSols", icmp6->ipv6IfIcmpInNeighborSolicits); 2101*0Sstevel@tonic-gate prval("icmp6InNeighborAds", 2102*0Sstevel@tonic-gate icmp6->ipv6IfIcmpInNeighborAdvertisements); 2103*0Sstevel@tonic-gate prval("icmp6InRedirects", icmp6->ipv6IfIcmpInRedirects); 2104*0Sstevel@tonic-gate prval("icmp6InBadRedirects", icmp6->ipv6IfIcmpInBadRedirects); 2105*0Sstevel@tonic-gate prval("icmp6InGroupQueries", icmp6->ipv6IfIcmpInGroupMembQueries); 2106*0Sstevel@tonic-gate prval("icmp6InGroupResps", icmp6->ipv6IfIcmpInGroupMembResponses); 2107*0Sstevel@tonic-gate prval("icmp6InGroupReds", icmp6->ipv6IfIcmpInGroupMembReductions); 2108*0Sstevel@tonic-gate prval("icmp6InOverflows", icmp6->ipv6IfIcmpInOverflows); 2109*0Sstevel@tonic-gate prval_end(); 2110*0Sstevel@tonic-gate prval_init(); 2111*0Sstevel@tonic-gate prval("icmp6OutMsgs", icmp6->ipv6IfIcmpOutMsgs); 2112*0Sstevel@tonic-gate prval("icmp6OutErrors", icmp6->ipv6IfIcmpOutErrors); 2113*0Sstevel@tonic-gate prval("icmp6OutDestUnreachs", icmp6->ipv6IfIcmpOutDestUnreachs); 2114*0Sstevel@tonic-gate prval("icmp6OutAdminProhibs", icmp6->ipv6IfIcmpOutAdminProhibs); 2115*0Sstevel@tonic-gate prval("icmp6OutTimeExcds", icmp6->ipv6IfIcmpOutTimeExcds); 2116*0Sstevel@tonic-gate prval("icmp6OutParmProblems", icmp6->ipv6IfIcmpOutParmProblems); 2117*0Sstevel@tonic-gate prval("icmp6OutPktTooBigs", icmp6->ipv6IfIcmpOutPktTooBigs); 2118*0Sstevel@tonic-gate prval("icmp6OutEchos", icmp6->ipv6IfIcmpOutEchos); 2119*0Sstevel@tonic-gate prval("icmp6OutEchoReplies", icmp6->ipv6IfIcmpOutEchoReplies); 2120*0Sstevel@tonic-gate prval("icmp6OutRouterSols", icmp6->ipv6IfIcmpOutRouterSolicits); 2121*0Sstevel@tonic-gate prval("icmp6OutRouterAds", 2122*0Sstevel@tonic-gate icmp6->ipv6IfIcmpOutRouterAdvertisements); 2123*0Sstevel@tonic-gate prval("icmp6OutNeighborSols", icmp6->ipv6IfIcmpOutNeighborSolicits); 2124*0Sstevel@tonic-gate prval("icmp6OutNeighborAds", 2125*0Sstevel@tonic-gate icmp6->ipv6IfIcmpOutNeighborAdvertisements); 2126*0Sstevel@tonic-gate prval("icmp6OutRedirects", icmp6->ipv6IfIcmpOutRedirects); 2127*0Sstevel@tonic-gate prval("icmp6OutGroupQueries", icmp6->ipv6IfIcmpOutGroupMembQueries); 2128*0Sstevel@tonic-gate prval("icmp6OutGroupResps", 2129*0Sstevel@tonic-gate icmp6->ipv6IfIcmpOutGroupMembResponses); 2130*0Sstevel@tonic-gate prval("icmp6OutGroupReds", 2131*0Sstevel@tonic-gate icmp6->ipv6IfIcmpOutGroupMembReductions); 2132*0Sstevel@tonic-gate prval_end(); 2133*0Sstevel@tonic-gate } 2134*0Sstevel@tonic-gate 2135*0Sstevel@tonic-gate static void 2136*0Sstevel@tonic-gate print_sctp_stats(mib2_sctp_t *sctp) 2137*0Sstevel@tonic-gate { 2138*0Sstevel@tonic-gate prval_init(); 2139*0Sstevel@tonic-gate pr_sctp_rtoalgo("sctpRtoAlgorithm", sctp->sctpRtoAlgorithm); 2140*0Sstevel@tonic-gate prval("sctpRtoMin", sctp->sctpRtoMin); 2141*0Sstevel@tonic-gate prval("sctpRtoMax", sctp->sctpRtoMax); 2142*0Sstevel@tonic-gate prval("sctpRtoInitial", sctp->sctpRtoInitial); 2143*0Sstevel@tonic-gate pr_int_val("sctpMaxAssocs", sctp->sctpMaxAssocs); 2144*0Sstevel@tonic-gate prval("sctpValCookieLife", sctp->sctpValCookieLife); 2145*0Sstevel@tonic-gate prval("sctpMaxInitRetr", sctp->sctpMaxInitRetr); 2146*0Sstevel@tonic-gate prval("sctpCurrEstab", sctp->sctpCurrEstab); 2147*0Sstevel@tonic-gate prval("sctpActiveEstab", sctp->sctpActiveEstab); 2148*0Sstevel@tonic-gate prval("sctpPassiveEstab", sctp->sctpPassiveEstab); 2149*0Sstevel@tonic-gate prval("sctpAborted", sctp->sctpAborted); 2150*0Sstevel@tonic-gate prval("sctpShutdowns", sctp->sctpShutdowns); 2151*0Sstevel@tonic-gate prval("sctpOutOfBlue", sctp->sctpOutOfBlue); 2152*0Sstevel@tonic-gate prval("sctpChecksumError", sctp->sctpChecksumError); 2153*0Sstevel@tonic-gate prval64("sctpOutCtrlChunks", sctp->sctpOutCtrlChunks); 2154*0Sstevel@tonic-gate prval64("sctpOutOrderChunks", sctp->sctpOutOrderChunks); 2155*0Sstevel@tonic-gate prval64("sctpOutUnorderChunks", sctp->sctpOutUnorderChunks); 2156*0Sstevel@tonic-gate prval64("sctpRetransChunks", sctp->sctpRetransChunks); 2157*0Sstevel@tonic-gate prval("sctpOutAck", sctp->sctpOutAck); 2158*0Sstevel@tonic-gate prval("sctpOutAckDelayed", sctp->sctpOutAckDelayed); 2159*0Sstevel@tonic-gate prval("sctpOutWinUpdate", sctp->sctpOutWinUpdate); 2160*0Sstevel@tonic-gate prval("sctpOutFastRetrans", sctp->sctpOutFastRetrans); 2161*0Sstevel@tonic-gate prval("sctpOutWinProbe", sctp->sctpOutWinProbe); 2162*0Sstevel@tonic-gate prval64("sctpInCtrlChunks", sctp->sctpInCtrlChunks); 2163*0Sstevel@tonic-gate prval64("sctpInOrderChunks", sctp->sctpInOrderChunks); 2164*0Sstevel@tonic-gate prval64("sctpInUnorderChunks", sctp->sctpInUnorderChunks); 2165*0Sstevel@tonic-gate prval("sctpInAck", sctp->sctpInAck); 2166*0Sstevel@tonic-gate prval("sctpInDupAck", sctp->sctpInDupAck); 2167*0Sstevel@tonic-gate prval("sctpInAckUnsent", sctp->sctpInAckUnsent); 2168*0Sstevel@tonic-gate prval64("sctpFragUsrMsgs", sctp->sctpFragUsrMsgs); 2169*0Sstevel@tonic-gate prval64("sctpReasmUsrMsgs", sctp->sctpReasmUsrMsgs); 2170*0Sstevel@tonic-gate prval64("sctpOutSCTPPkts", sctp->sctpOutSCTPPkts); 2171*0Sstevel@tonic-gate prval64("sctpInSCTPPkts", sctp->sctpInSCTPPkts); 2172*0Sstevel@tonic-gate prval("sctpInInvalidCookie", sctp->sctpInInvalidCookie); 2173*0Sstevel@tonic-gate prval("sctpTimRetrans", sctp->sctpTimRetrans); 2174*0Sstevel@tonic-gate prval("sctpTimRetransDrop", sctp->sctpTimRetransDrop); 2175*0Sstevel@tonic-gate prval("sctpTimHearBeatProbe", sctp->sctpTimHeartBeatProbe); 2176*0Sstevel@tonic-gate prval("sctpTimHearBeatDrop", sctp->sctpTimHeartBeatDrop); 2177*0Sstevel@tonic-gate prval("sctpListenDrop", sctp->sctpListenDrop); 2178*0Sstevel@tonic-gate prval("sctpInClosed", sctp->sctpInClosed); 2179*0Sstevel@tonic-gate prval_end(); 2180*0Sstevel@tonic-gate } 2181*0Sstevel@tonic-gate 2182*0Sstevel@tonic-gate static void 2183*0Sstevel@tonic-gate print_tcp_stats(mib2_tcp_t *tcp) 2184*0Sstevel@tonic-gate { 2185*0Sstevel@tonic-gate prval_init(); 2186*0Sstevel@tonic-gate pr_int_val("tcpRtoAlgorithm", tcp->tcpRtoAlgorithm); 2187*0Sstevel@tonic-gate pr_int_val("tcpRtoMin", tcp->tcpRtoMin); 2188*0Sstevel@tonic-gate pr_int_val("tcpRtoMax", tcp->tcpRtoMax); 2189*0Sstevel@tonic-gate pr_int_val("tcpMaxConn", tcp->tcpMaxConn); 2190*0Sstevel@tonic-gate prval("tcpActiveOpens", tcp->tcpActiveOpens); 2191*0Sstevel@tonic-gate prval("tcpPassiveOpens", tcp->tcpPassiveOpens); 2192*0Sstevel@tonic-gate prval("tcpAttemptFails", tcp->tcpAttemptFails); 2193*0Sstevel@tonic-gate prval("tcpEstabResets", tcp->tcpEstabResets); 2194*0Sstevel@tonic-gate prval("tcpCurrEstab", tcp->tcpCurrEstab); 2195*0Sstevel@tonic-gate prval("tcpOutSegs", tcp->tcpOutSegs); 2196*0Sstevel@tonic-gate prval("tcpOutDataSegs", tcp->tcpOutDataSegs); 2197*0Sstevel@tonic-gate prval("tcpOutDataBytes", tcp->tcpOutDataBytes); 2198*0Sstevel@tonic-gate prval("tcpRetransSegs", tcp->tcpRetransSegs); 2199*0Sstevel@tonic-gate prval("tcpRetransBytes", tcp->tcpRetransBytes); 2200*0Sstevel@tonic-gate prval("tcpOutAck", tcp->tcpOutAck); 2201*0Sstevel@tonic-gate prval("tcpOutAckDelayed", tcp->tcpOutAckDelayed); 2202*0Sstevel@tonic-gate prval("tcpOutUrg", tcp->tcpOutUrg); 2203*0Sstevel@tonic-gate prval("tcpOutWinUpdate", tcp->tcpOutWinUpdate); 2204*0Sstevel@tonic-gate prval("tcpOutWinProbe", tcp->tcpOutWinProbe); 2205*0Sstevel@tonic-gate prval("tcpOutControl", tcp->tcpOutControl); 2206*0Sstevel@tonic-gate prval("tcpOutRsts", tcp->tcpOutRsts); 2207*0Sstevel@tonic-gate prval("tcpOutFastRetrans", tcp->tcpOutFastRetrans); 2208*0Sstevel@tonic-gate prval("tcpInSegs", tcp->tcpInSegs); 2209*0Sstevel@tonic-gate prval_end(); 2210*0Sstevel@tonic-gate prval("tcpInAckSegs", tcp->tcpInAckSegs); 2211*0Sstevel@tonic-gate prval("tcpInAckBytes", tcp->tcpInAckBytes); 2212*0Sstevel@tonic-gate prval("tcpInDupAck", tcp->tcpInDupAck); 2213*0Sstevel@tonic-gate prval("tcpInAckUnsent", tcp->tcpInAckUnsent); 2214*0Sstevel@tonic-gate prval("tcpInInorderSegs", tcp->tcpInDataInorderSegs); 2215*0Sstevel@tonic-gate prval("tcpInInorderBytes", tcp->tcpInDataInorderBytes); 2216*0Sstevel@tonic-gate prval("tcpInUnorderSegs", tcp->tcpInDataUnorderSegs); 2217*0Sstevel@tonic-gate prval("tcpInUnorderBytes", tcp->tcpInDataUnorderBytes); 2218*0Sstevel@tonic-gate prval("tcpInDupSegs", tcp->tcpInDataDupSegs); 2219*0Sstevel@tonic-gate prval("tcpInDupBytes", tcp->tcpInDataDupBytes); 2220*0Sstevel@tonic-gate prval("tcpInPartDupSegs", tcp->tcpInDataPartDupSegs); 2221*0Sstevel@tonic-gate prval("tcpInPartDupBytes", tcp->tcpInDataPartDupBytes); 2222*0Sstevel@tonic-gate prval("tcpInPastWinSegs", tcp->tcpInDataPastWinSegs); 2223*0Sstevel@tonic-gate prval("tcpInPastWinBytes", tcp->tcpInDataPastWinBytes); 2224*0Sstevel@tonic-gate prval("tcpInWinProbe", tcp->tcpInWinProbe); 2225*0Sstevel@tonic-gate prval("tcpInWinUpdate", tcp->tcpInWinUpdate); 2226*0Sstevel@tonic-gate prval("tcpInClosed", tcp->tcpInClosed); 2227*0Sstevel@tonic-gate prval("tcpRttNoUpdate", tcp->tcpRttNoUpdate); 2228*0Sstevel@tonic-gate prval("tcpRttUpdate", tcp->tcpRttUpdate); 2229*0Sstevel@tonic-gate prval("tcpTimRetrans", tcp->tcpTimRetrans); 2230*0Sstevel@tonic-gate prval("tcpTimRetransDrop", tcp->tcpTimRetransDrop); 2231*0Sstevel@tonic-gate prval("tcpTimKeepalive", tcp->tcpTimKeepalive); 2232*0Sstevel@tonic-gate prval("tcpTimKeepaliveProbe", tcp->tcpTimKeepaliveProbe); 2233*0Sstevel@tonic-gate prval("tcpTimKeepaliveDrop", tcp->tcpTimKeepaliveDrop); 2234*0Sstevel@tonic-gate prval("tcpListenDrop", tcp->tcpListenDrop); 2235*0Sstevel@tonic-gate prval("tcpListenDropQ0", tcp->tcpListenDropQ0); 2236*0Sstevel@tonic-gate prval("tcpHalfOpenDrop", tcp->tcpHalfOpenDrop); 2237*0Sstevel@tonic-gate prval("tcpOutSackRetrans", tcp->tcpOutSackRetransSegs); 2238*0Sstevel@tonic-gate prval_end(); 2239*0Sstevel@tonic-gate 2240*0Sstevel@tonic-gate } 2241*0Sstevel@tonic-gate 2242*0Sstevel@tonic-gate static void 2243*0Sstevel@tonic-gate print_udp_stats(mib2_udp_t *udp) 2244*0Sstevel@tonic-gate { 2245*0Sstevel@tonic-gate prval_init(); 2246*0Sstevel@tonic-gate prval("udpInDatagrams", udp->udpInDatagrams); 2247*0Sstevel@tonic-gate prval("udpInErrors", udp->udpInErrors); 2248*0Sstevel@tonic-gate prval("udpOutDatagrams", udp->udpOutDatagrams); 2249*0Sstevel@tonic-gate prval("udpOutErrors", udp->udpOutErrors); 2250*0Sstevel@tonic-gate prval_end(); 2251*0Sstevel@tonic-gate } 2252*0Sstevel@tonic-gate 2253*0Sstevel@tonic-gate static void 2254*0Sstevel@tonic-gate print_rawip_stats(mib2_rawip_t *rawip) 2255*0Sstevel@tonic-gate { 2256*0Sstevel@tonic-gate prval_init(); 2257*0Sstevel@tonic-gate prval("rawipInDatagrams", rawip->rawipInDatagrams); 2258*0Sstevel@tonic-gate prval("rawipInErrors", rawip->rawipInErrors); 2259*0Sstevel@tonic-gate prval("rawipInCksumErrs", rawip->rawipInCksumErrs); 2260*0Sstevel@tonic-gate prval("rawipOutDatagrams", rawip->rawipOutDatagrams); 2261*0Sstevel@tonic-gate prval("rawipOutErrors", rawip->rawipOutErrors); 2262*0Sstevel@tonic-gate prval_end(); 2263*0Sstevel@tonic-gate } 2264*0Sstevel@tonic-gate 2265*0Sstevel@tonic-gate void 2266*0Sstevel@tonic-gate print_igmp_stats(struct igmpstat *igps) 2267*0Sstevel@tonic-gate { 2268*0Sstevel@tonic-gate (void) printf(" %10u message%s received\n", 2269*0Sstevel@tonic-gate igps->igps_rcv_total, PLURAL(igps->igps_rcv_total)); 2270*0Sstevel@tonic-gate (void) printf(" %10u message%s received with too few bytes\n", 2271*0Sstevel@tonic-gate igps->igps_rcv_tooshort, PLURAL(igps->igps_rcv_tooshort)); 2272*0Sstevel@tonic-gate (void) printf(" %10u message%s received with bad checksum\n", 2273*0Sstevel@tonic-gate igps->igps_rcv_badsum, PLURAL(igps->igps_rcv_badsum)); 2274*0Sstevel@tonic-gate (void) printf(" %10u membership quer%s received\n", 2275*0Sstevel@tonic-gate igps->igps_rcv_queries, PLURALY(igps->igps_rcv_queries)); 2276*0Sstevel@tonic-gate (void) printf(" %10u membership quer%s received with invalid " 2277*0Sstevel@tonic-gate "field(s)\n", 2278*0Sstevel@tonic-gate igps->igps_rcv_badqueries, PLURALY(igps->igps_rcv_badqueries)); 2279*0Sstevel@tonic-gate (void) printf(" %10u membership report%s received\n", 2280*0Sstevel@tonic-gate igps->igps_rcv_reports, PLURAL(igps->igps_rcv_reports)); 2281*0Sstevel@tonic-gate (void) printf(" %10u membership report%s received with invalid " 2282*0Sstevel@tonic-gate "field(s)\n", 2283*0Sstevel@tonic-gate igps->igps_rcv_badreports, PLURAL(igps->igps_rcv_badreports)); 2284*0Sstevel@tonic-gate (void) printf(" %10u membership report%s received for groups to " 2285*0Sstevel@tonic-gate "which we belong\n", 2286*0Sstevel@tonic-gate igps->igps_rcv_ourreports, PLURAL(igps->igps_rcv_ourreports)); 2287*0Sstevel@tonic-gate (void) printf(" %10u membership report%s sent\n", 2288*0Sstevel@tonic-gate igps->igps_snd_reports, PLURAL(igps->igps_snd_reports)); 2289*0Sstevel@tonic-gate } 2290*0Sstevel@tonic-gate 2291*0Sstevel@tonic-gate static void 2292*0Sstevel@tonic-gate print_mrt_stats(struct mrtstat *mrts) 2293*0Sstevel@tonic-gate { 2294*0Sstevel@tonic-gate (void) puts("DVMRP multicast routing:"); 2295*0Sstevel@tonic-gate (void) printf(" %10u hit%s - kernel forwarding cache hits\n", 2296*0Sstevel@tonic-gate mrts->mrts_mfc_hits, PLURAL(mrts->mrts_mfc_hits)); 2297*0Sstevel@tonic-gate (void) printf(" %10u miss%s - kernel forwarding cache misses\n", 2298*0Sstevel@tonic-gate mrts->mrts_mfc_misses, PLURALES(mrts->mrts_mfc_misses)); 2299*0Sstevel@tonic-gate (void) printf(" %10u packet%s potentially forwarded\n", 2300*0Sstevel@tonic-gate mrts->mrts_fwd_in, PLURAL(mrts->mrts_fwd_in)); 2301*0Sstevel@tonic-gate (void) printf(" %10u packet%s actually sent out\n", 2302*0Sstevel@tonic-gate mrts->mrts_fwd_out, PLURAL(mrts->mrts_fwd_out)); 2303*0Sstevel@tonic-gate (void) printf(" %10u upcall%s - upcalls made to mrouted\n", 2304*0Sstevel@tonic-gate mrts->mrts_upcalls, PLURAL(mrts->mrts_upcalls)); 2305*0Sstevel@tonic-gate (void) printf(" %10u packet%s not sent out due to lack of resources\n", 2306*0Sstevel@tonic-gate mrts->mrts_fwd_drop, PLURAL(mrts->mrts_fwd_drop)); 2307*0Sstevel@tonic-gate (void) printf(" %10u datagram%s with malformed tunnel options\n", 2308*0Sstevel@tonic-gate mrts->mrts_bad_tunnel, PLURAL(mrts->mrts_bad_tunnel)); 2309*0Sstevel@tonic-gate (void) printf(" %10u datagram%s with no room for tunnel options\n", 2310*0Sstevel@tonic-gate mrts->mrts_cant_tunnel, PLURAL(mrts->mrts_cant_tunnel)); 2311*0Sstevel@tonic-gate (void) printf(" %10u datagram%s arrived on wrong interface\n", 2312*0Sstevel@tonic-gate mrts->mrts_wrong_if, PLURAL(mrts->mrts_wrong_if)); 2313*0Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped due to upcall Q overflow\n", 2314*0Sstevel@tonic-gate mrts->mrts_upq_ovflw, PLURAL(mrts->mrts_upq_ovflw)); 2315*0Sstevel@tonic-gate (void) printf(" %10u datagram%s cleaned up by the cache\n", 2316*0Sstevel@tonic-gate mrts->mrts_cache_cleanups, PLURAL(mrts->mrts_cache_cleanups)); 2317*0Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped selectively by ratelimiter\n", 2318*0Sstevel@tonic-gate mrts->mrts_drop_sel, PLURAL(mrts->mrts_drop_sel)); 2319*0Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - bucket Q overflow\n", 2320*0Sstevel@tonic-gate mrts->mrts_q_overflow, PLURAL(mrts->mrts_q_overflow)); 2321*0Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - larger than bkt size\n", 2322*0Sstevel@tonic-gate mrts->mrts_pkt2large, PLURAL(mrts->mrts_pkt2large)); 2323*0Sstevel@tonic-gate (void) printf("\nPIM multicast routing:\n"); 2324*0Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - bad version number\n", 2325*0Sstevel@tonic-gate mrts->mrts_pim_badversion, PLURAL(mrts->mrts_pim_badversion)); 2326*0Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - bad checksum\n", 2327*0Sstevel@tonic-gate mrts->mrts_pim_rcv_badcsum, PLURAL(mrts->mrts_pim_rcv_badcsum)); 2328*0Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - bad register packets\n", 2329*0Sstevel@tonic-gate mrts->mrts_pim_badregisters, 2330*0Sstevel@tonic-gate PLURAL(mrts->mrts_pim_badregisters)); 2331*0Sstevel@tonic-gate (void) printf( 2332*0Sstevel@tonic-gate " %10u datagram%s potentially forwarded - register packets\n", 2333*0Sstevel@tonic-gate mrts->mrts_pim_regforwards, PLURAL(mrts->mrts_pim_regforwards)); 2334*0Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - register send drops\n", 2335*0Sstevel@tonic-gate mrts->mrts_pim_regsend_drops, 2336*0Sstevel@tonic-gate PLURAL(mrts->mrts_pim_regsend_drops)); 2337*0Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - packet malformed\n", 2338*0Sstevel@tonic-gate mrts->mrts_pim_malformed, PLURAL(mrts->mrts_pim_malformed)); 2339*0Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - no memory to forward\n", 2340*0Sstevel@tonic-gate mrts->mrts_pim_nomemory, PLURAL(mrts->mrts_pim_nomemory)); 2341*0Sstevel@tonic-gate } 2342*0Sstevel@tonic-gate 2343*0Sstevel@tonic-gate static void 2344*0Sstevel@tonic-gate sum_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6, mib2_ipv6IfStatsEntry_t *sum6) 2345*0Sstevel@tonic-gate { 2346*0Sstevel@tonic-gate /* First few are not additive */ 2347*0Sstevel@tonic-gate sum6->ipv6Forwarding = ip6->ipv6Forwarding; 2348*0Sstevel@tonic-gate sum6->ipv6DefaultHopLimit = ip6->ipv6DefaultHopLimit; 2349*0Sstevel@tonic-gate 2350*0Sstevel@tonic-gate sum6->ipv6InReceives += ip6->ipv6InReceives; 2351*0Sstevel@tonic-gate sum6->ipv6InHdrErrors += ip6->ipv6InHdrErrors; 2352*0Sstevel@tonic-gate sum6->ipv6InTooBigErrors += ip6->ipv6InTooBigErrors; 2353*0Sstevel@tonic-gate sum6->ipv6InNoRoutes += ip6->ipv6InNoRoutes; 2354*0Sstevel@tonic-gate sum6->ipv6InAddrErrors += ip6->ipv6InAddrErrors; 2355*0Sstevel@tonic-gate sum6->ipv6InUnknownProtos += ip6->ipv6InUnknownProtos; 2356*0Sstevel@tonic-gate sum6->ipv6InTruncatedPkts += ip6->ipv6InTruncatedPkts; 2357*0Sstevel@tonic-gate sum6->ipv6InDiscards += ip6->ipv6InDiscards; 2358*0Sstevel@tonic-gate sum6->ipv6InDelivers += ip6->ipv6InDelivers; 2359*0Sstevel@tonic-gate sum6->ipv6OutForwDatagrams += ip6->ipv6OutForwDatagrams; 2360*0Sstevel@tonic-gate sum6->ipv6OutRequests += ip6->ipv6OutRequests; 2361*0Sstevel@tonic-gate sum6->ipv6OutDiscards += ip6->ipv6OutDiscards; 2362*0Sstevel@tonic-gate sum6->ipv6OutFragOKs += ip6->ipv6OutFragOKs; 2363*0Sstevel@tonic-gate sum6->ipv6OutFragFails += ip6->ipv6OutFragFails; 2364*0Sstevel@tonic-gate sum6->ipv6OutFragCreates += ip6->ipv6OutFragCreates; 2365*0Sstevel@tonic-gate sum6->ipv6ReasmReqds += ip6->ipv6ReasmReqds; 2366*0Sstevel@tonic-gate sum6->ipv6ReasmOKs += ip6->ipv6ReasmOKs; 2367*0Sstevel@tonic-gate sum6->ipv6ReasmFails += ip6->ipv6ReasmFails; 2368*0Sstevel@tonic-gate sum6->ipv6InMcastPkts += ip6->ipv6InMcastPkts; 2369*0Sstevel@tonic-gate sum6->ipv6OutMcastPkts += ip6->ipv6OutMcastPkts; 2370*0Sstevel@tonic-gate sum6->ipv6OutNoRoutes += ip6->ipv6OutNoRoutes; 2371*0Sstevel@tonic-gate sum6->ipv6ReasmDuplicates += ip6->ipv6ReasmDuplicates; 2372*0Sstevel@tonic-gate sum6->ipv6ReasmPartDups += ip6->ipv6ReasmPartDups; 2373*0Sstevel@tonic-gate sum6->ipv6ForwProhibits += ip6->ipv6ForwProhibits; 2374*0Sstevel@tonic-gate sum6->udpInCksumErrs += ip6->udpInCksumErrs; 2375*0Sstevel@tonic-gate sum6->udpInOverflows += ip6->udpInOverflows; 2376*0Sstevel@tonic-gate sum6->rawipInOverflows += ip6->rawipInOverflows; 2377*0Sstevel@tonic-gate } 2378*0Sstevel@tonic-gate 2379*0Sstevel@tonic-gate static void 2380*0Sstevel@tonic-gate sum_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6, mib2_ipv6IfIcmpEntry_t *sum6) 2381*0Sstevel@tonic-gate { 2382*0Sstevel@tonic-gate sum6->ipv6IfIcmpInMsgs += icmp6->ipv6IfIcmpInMsgs; 2383*0Sstevel@tonic-gate sum6->ipv6IfIcmpInErrors += icmp6->ipv6IfIcmpInErrors; 2384*0Sstevel@tonic-gate sum6->ipv6IfIcmpInDestUnreachs += icmp6->ipv6IfIcmpInDestUnreachs; 2385*0Sstevel@tonic-gate sum6->ipv6IfIcmpInAdminProhibs += icmp6->ipv6IfIcmpInAdminProhibs; 2386*0Sstevel@tonic-gate sum6->ipv6IfIcmpInTimeExcds += icmp6->ipv6IfIcmpInTimeExcds; 2387*0Sstevel@tonic-gate sum6->ipv6IfIcmpInParmProblems += icmp6->ipv6IfIcmpInParmProblems; 2388*0Sstevel@tonic-gate sum6->ipv6IfIcmpInPktTooBigs += icmp6->ipv6IfIcmpInPktTooBigs; 2389*0Sstevel@tonic-gate sum6->ipv6IfIcmpInEchos += icmp6->ipv6IfIcmpInEchos; 2390*0Sstevel@tonic-gate sum6->ipv6IfIcmpInEchoReplies += icmp6->ipv6IfIcmpInEchoReplies; 2391*0Sstevel@tonic-gate sum6->ipv6IfIcmpInRouterSolicits += icmp6->ipv6IfIcmpInRouterSolicits; 2392*0Sstevel@tonic-gate sum6->ipv6IfIcmpInRouterAdvertisements += 2393*0Sstevel@tonic-gate icmp6->ipv6IfIcmpInRouterAdvertisements; 2394*0Sstevel@tonic-gate sum6->ipv6IfIcmpInNeighborSolicits += 2395*0Sstevel@tonic-gate icmp6->ipv6IfIcmpInNeighborSolicits; 2396*0Sstevel@tonic-gate sum6->ipv6IfIcmpInNeighborAdvertisements += 2397*0Sstevel@tonic-gate icmp6->ipv6IfIcmpInNeighborAdvertisements; 2398*0Sstevel@tonic-gate sum6->ipv6IfIcmpInRedirects += icmp6->ipv6IfIcmpInRedirects; 2399*0Sstevel@tonic-gate sum6->ipv6IfIcmpInGroupMembQueries += 2400*0Sstevel@tonic-gate icmp6->ipv6IfIcmpInGroupMembQueries; 2401*0Sstevel@tonic-gate sum6->ipv6IfIcmpInGroupMembResponses += 2402*0Sstevel@tonic-gate icmp6->ipv6IfIcmpInGroupMembResponses; 2403*0Sstevel@tonic-gate sum6->ipv6IfIcmpInGroupMembReductions += 2404*0Sstevel@tonic-gate icmp6->ipv6IfIcmpInGroupMembReductions; 2405*0Sstevel@tonic-gate sum6->ipv6IfIcmpOutMsgs += icmp6->ipv6IfIcmpOutMsgs; 2406*0Sstevel@tonic-gate sum6->ipv6IfIcmpOutErrors += icmp6->ipv6IfIcmpOutErrors; 2407*0Sstevel@tonic-gate sum6->ipv6IfIcmpOutDestUnreachs += icmp6->ipv6IfIcmpOutDestUnreachs; 2408*0Sstevel@tonic-gate sum6->ipv6IfIcmpOutAdminProhibs += icmp6->ipv6IfIcmpOutAdminProhibs; 2409*0Sstevel@tonic-gate sum6->ipv6IfIcmpOutTimeExcds += icmp6->ipv6IfIcmpOutTimeExcds; 2410*0Sstevel@tonic-gate sum6->ipv6IfIcmpOutParmProblems += icmp6->ipv6IfIcmpOutParmProblems; 2411*0Sstevel@tonic-gate sum6->ipv6IfIcmpOutPktTooBigs += icmp6->ipv6IfIcmpOutPktTooBigs; 2412*0Sstevel@tonic-gate sum6->ipv6IfIcmpOutEchos += icmp6->ipv6IfIcmpOutEchos; 2413*0Sstevel@tonic-gate sum6->ipv6IfIcmpOutEchoReplies += icmp6->ipv6IfIcmpOutEchoReplies; 2414*0Sstevel@tonic-gate sum6->ipv6IfIcmpOutRouterSolicits += 2415*0Sstevel@tonic-gate icmp6->ipv6IfIcmpOutRouterSolicits; 2416*0Sstevel@tonic-gate sum6->ipv6IfIcmpOutRouterAdvertisements += 2417*0Sstevel@tonic-gate icmp6->ipv6IfIcmpOutRouterAdvertisements; 2418*0Sstevel@tonic-gate sum6->ipv6IfIcmpOutNeighborSolicits += 2419*0Sstevel@tonic-gate icmp6->ipv6IfIcmpOutNeighborSolicits; 2420*0Sstevel@tonic-gate sum6->ipv6IfIcmpOutNeighborAdvertisements += 2421*0Sstevel@tonic-gate icmp6->ipv6IfIcmpOutNeighborAdvertisements; 2422*0Sstevel@tonic-gate sum6->ipv6IfIcmpOutRedirects += icmp6->ipv6IfIcmpOutRedirects; 2423*0Sstevel@tonic-gate sum6->ipv6IfIcmpOutGroupMembQueries += 2424*0Sstevel@tonic-gate icmp6->ipv6IfIcmpOutGroupMembQueries; 2425*0Sstevel@tonic-gate sum6->ipv6IfIcmpOutGroupMembResponses += 2426*0Sstevel@tonic-gate icmp6->ipv6IfIcmpOutGroupMembResponses; 2427*0Sstevel@tonic-gate sum6->ipv6IfIcmpOutGroupMembReductions += 2428*0Sstevel@tonic-gate icmp6->ipv6IfIcmpOutGroupMembReductions; 2429*0Sstevel@tonic-gate sum6->ipv6IfIcmpInOverflows += icmp6->ipv6IfIcmpInOverflows; 2430*0Sstevel@tonic-gate } 2431*0Sstevel@tonic-gate 2432*0Sstevel@tonic-gate /* ----------------------------- MRT_STAT_REPORT --------------------------- */ 2433*0Sstevel@tonic-gate 2434*0Sstevel@tonic-gate static void 2435*0Sstevel@tonic-gate mrt_stat_report(mib_item_t *curritem) 2436*0Sstevel@tonic-gate { 2437*0Sstevel@tonic-gate int jtemp = 0; 2438*0Sstevel@tonic-gate mib_item_t *tempitem; 2439*0Sstevel@tonic-gate 2440*0Sstevel@tonic-gate if (!(family_selected(AF_INET))) 2441*0Sstevel@tonic-gate return; 2442*0Sstevel@tonic-gate 2443*0Sstevel@tonic-gate (void) putchar('\n'); 2444*0Sstevel@tonic-gate /* 'for' loop 1: */ 2445*0Sstevel@tonic-gate for (tempitem = curritem; 2446*0Sstevel@tonic-gate tempitem; 2447*0Sstevel@tonic-gate tempitem = tempitem->next_item) { 2448*0Sstevel@tonic-gate if (Dflag) { 2449*0Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp); 2450*0Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, " 2451*0Sstevel@tonic-gate "length = %d, valp = 0x%p\n", 2452*0Sstevel@tonic-gate tempitem->group, tempitem->mib_id, 2453*0Sstevel@tonic-gate tempitem->length, tempitem->valp); 2454*0Sstevel@tonic-gate } 2455*0Sstevel@tonic-gate 2456*0Sstevel@tonic-gate if (tempitem->mib_id == 0) { 2457*0Sstevel@tonic-gate switch (tempitem->group) { 2458*0Sstevel@tonic-gate case EXPER_DVMRP: { 2459*0Sstevel@tonic-gate struct mrtstat *mrts; 2460*0Sstevel@tonic-gate mrts = (struct mrtstat *)tempitem->valp; 2461*0Sstevel@tonic-gate 2462*0Sstevel@tonic-gate if (!(family_selected(AF_INET))) 2463*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 2464*0Sstevel@tonic-gate 2465*0Sstevel@tonic-gate print_mrt_stats(mrts); 2466*0Sstevel@tonic-gate break; 2467*0Sstevel@tonic-gate } 2468*0Sstevel@tonic-gate } 2469*0Sstevel@tonic-gate } 2470*0Sstevel@tonic-gate } /* 'for' loop 1 ends */ 2471*0Sstevel@tonic-gate (void) putchar('\n'); 2472*0Sstevel@tonic-gate (void) fflush(stdout); 2473*0Sstevel@tonic-gate } 2474*0Sstevel@tonic-gate 2475*0Sstevel@tonic-gate /* 2476*0Sstevel@tonic-gate * if_stat_total() - Computes totals for interface statistics 2477*0Sstevel@tonic-gate * and returns result by updating sumstats. 2478*0Sstevel@tonic-gate */ 2479*0Sstevel@tonic-gate static void 2480*0Sstevel@tonic-gate if_stat_total(struct ifstat *oldstats, struct ifstat *newstats, 2481*0Sstevel@tonic-gate struct ifstat *sumstats) 2482*0Sstevel@tonic-gate { 2483*0Sstevel@tonic-gate sumstats->ipackets += newstats->ipackets - oldstats->ipackets; 2484*0Sstevel@tonic-gate sumstats->opackets += newstats->opackets - oldstats->opackets; 2485*0Sstevel@tonic-gate sumstats->ierrors += newstats->ierrors - oldstats->ierrors; 2486*0Sstevel@tonic-gate sumstats->oerrors += newstats->oerrors - oldstats->oerrors; 2487*0Sstevel@tonic-gate sumstats->collisions += newstats->collisions - oldstats->collisions; 2488*0Sstevel@tonic-gate } 2489*0Sstevel@tonic-gate 2490*0Sstevel@tonic-gate /* --------------------- IF_REPORT (netstat -i) -------------------------- */ 2491*0Sstevel@tonic-gate 2492*0Sstevel@tonic-gate static struct ifstat zerostat = { 2493*0Sstevel@tonic-gate 0LL, 0LL, 0LL, 0LL, 0LL 2494*0Sstevel@tonic-gate }; 2495*0Sstevel@tonic-gate 2496*0Sstevel@tonic-gate static void 2497*0Sstevel@tonic-gate if_report(mib_item_t *item, char *matchname, 2498*0Sstevel@tonic-gate int Iflag_only, boolean_t once_only) 2499*0Sstevel@tonic-gate { 2500*0Sstevel@tonic-gate static boolean_t reentry = B_FALSE; 2501*0Sstevel@tonic-gate boolean_t alreadydone = B_FALSE; 2502*0Sstevel@tonic-gate int jtemp = 0; 2503*0Sstevel@tonic-gate uint32_t ifindex_v4 = 0; 2504*0Sstevel@tonic-gate uint32_t ifindex_v6 = 0; 2505*0Sstevel@tonic-gate 2506*0Sstevel@tonic-gate /* 'for' loop 1: */ 2507*0Sstevel@tonic-gate for (; item; item = item->next_item) { 2508*0Sstevel@tonic-gate if (Dflag) { 2509*0Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp); 2510*0Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, " 2511*0Sstevel@tonic-gate "length = %d, valp = 0x%p\n", 2512*0Sstevel@tonic-gate item->group, item->mib_id, item->length, 2513*0Sstevel@tonic-gate item->valp); 2514*0Sstevel@tonic-gate } 2515*0Sstevel@tonic-gate 2516*0Sstevel@tonic-gate switch (item->group) { 2517*0Sstevel@tonic-gate case MIB2_IP: 2518*0Sstevel@tonic-gate if (item->mib_id != MIB2_IP_ADDR || 2519*0Sstevel@tonic-gate !family_selected(AF_INET)) 2520*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 2521*0Sstevel@tonic-gate { 2522*0Sstevel@tonic-gate static struct ifstat old = {0L, 0L, 0L, 0L, 0L}; 2523*0Sstevel@tonic-gate static struct ifstat new = {0L, 0L, 0L, 0L, 0L}; 2524*0Sstevel@tonic-gate struct ifstat sum; 2525*0Sstevel@tonic-gate struct iflist *newlist = NULL; 2526*0Sstevel@tonic-gate static struct iflist *oldlist = NULL; 2527*0Sstevel@tonic-gate kstat_t *ksp; 2528*0Sstevel@tonic-gate 2529*0Sstevel@tonic-gate if (once_only) { 2530*0Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 2531*0Sstevel@tonic-gate char logintname[LIFNAMSIZ + 1]; 2532*0Sstevel@tonic-gate mib2_ipAddrEntry_t *ap; 2533*0Sstevel@tonic-gate struct ifstat stat = {0L, 0L, 0L, 0L, 0L}; 2534*0Sstevel@tonic-gate boolean_t first = B_TRUE; 2535*0Sstevel@tonic-gate uint32_t new_ifindex; 2536*0Sstevel@tonic-gate 2537*0Sstevel@tonic-gate if (Dflag) 2538*0Sstevel@tonic-gate (void) printf("if_report: %d items\n", 2539*0Sstevel@tonic-gate (item->length) 2540*0Sstevel@tonic-gate / sizeof (mib2_ipAddrEntry_t)); 2541*0Sstevel@tonic-gate 2542*0Sstevel@tonic-gate /* 'for' loop 2a: */ 2543*0Sstevel@tonic-gate for (ap = (mib2_ipAddrEntry_t *)item->valp; 2544*0Sstevel@tonic-gate (char *)ap < (char *)item->valp 2545*0Sstevel@tonic-gate + item->length; 2546*0Sstevel@tonic-gate ap++) { 2547*0Sstevel@tonic-gate (void) octetstr(&ap->ipAdEntIfIndex, 2548*0Sstevel@tonic-gate 'a', logintname, 2549*0Sstevel@tonic-gate sizeof (logintname)); 2550*0Sstevel@tonic-gate (void) strcpy(ifname, logintname); 2551*0Sstevel@tonic-gate (void) strtok(ifname, ":"); 2552*0Sstevel@tonic-gate if (matchname != NULL && 2553*0Sstevel@tonic-gate strcmp(matchname, ifname) != 0 && 2554*0Sstevel@tonic-gate strcmp(matchname, logintname) != 0) 2555*0Sstevel@tonic-gate continue; /* 'for' loop 2a */ 2556*0Sstevel@tonic-gate new_ifindex = 2557*0Sstevel@tonic-gate if_nametoindex(logintname); 2558*0Sstevel@tonic-gate if (new_ifindex != ifindex_v4 && 2559*0Sstevel@tonic-gate (ksp = kstat_lookup(kc, NULL, -1, 2560*0Sstevel@tonic-gate ifname)) != NULL) { 2561*0Sstevel@tonic-gate (void) safe_kstat_read(kc, ksp, 2562*0Sstevel@tonic-gate NULL); 2563*0Sstevel@tonic-gate stat.ipackets = 2564*0Sstevel@tonic-gate kstat_named_value(ksp, 2565*0Sstevel@tonic-gate "ipackets"); 2566*0Sstevel@tonic-gate stat.ierrors = 2567*0Sstevel@tonic-gate kstat_named_value(ksp, 2568*0Sstevel@tonic-gate "ierrors"); 2569*0Sstevel@tonic-gate stat.opackets = 2570*0Sstevel@tonic-gate kstat_named_value(ksp, 2571*0Sstevel@tonic-gate "opackets"); 2572*0Sstevel@tonic-gate stat.oerrors = 2573*0Sstevel@tonic-gate kstat_named_value(ksp, 2574*0Sstevel@tonic-gate "oerrors"); 2575*0Sstevel@tonic-gate stat.collisions = 2576*0Sstevel@tonic-gate kstat_named_value(ksp, 2577*0Sstevel@tonic-gate "collisions"); 2578*0Sstevel@tonic-gate if (first) { 2579*0Sstevel@tonic-gate (void) printf( 2580*0Sstevel@tonic-gate "%-5.5s %-5.5s%-13.13s " 2581*0Sstevel@tonic-gate "%-14.14s %-6.6s %-5.5s " 2582*0Sstevel@tonic-gate "%-6.6s %-5.5s %-6.6s " 2583*0Sstevel@tonic-gate "%-6.6s\n", 2584*0Sstevel@tonic-gate "Name", "Mtu", "Net/Dest", 2585*0Sstevel@tonic-gate "Address", "Ipkts", 2586*0Sstevel@tonic-gate "Ierrs", "Opkts", "Oerrs", 2587*0Sstevel@tonic-gate "Collis", "Queue"); 2588*0Sstevel@tonic-gate first = B_FALSE; 2589*0Sstevel@tonic-gate } 2590*0Sstevel@tonic-gate if_report_ip4(ap, ifname, 2591*0Sstevel@tonic-gate logintname, &stat, B_TRUE); 2592*0Sstevel@tonic-gate ifindex_v4 = new_ifindex; 2593*0Sstevel@tonic-gate } else { 2594*0Sstevel@tonic-gate if_report_ip4(ap, ifname, 2595*0Sstevel@tonic-gate logintname, &stat, B_FALSE); 2596*0Sstevel@tonic-gate } 2597*0Sstevel@tonic-gate } /* 'for' loop 2a ends */ 2598*0Sstevel@tonic-gate if (!first) 2599*0Sstevel@tonic-gate (void) putchar('\n'); 2600*0Sstevel@tonic-gate } else if (!alreadydone) { 2601*0Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 2602*0Sstevel@tonic-gate char buf[LIFNAMSIZ + 1]; 2603*0Sstevel@tonic-gate mib2_ipAddrEntry_t *ap; 2604*0Sstevel@tonic-gate struct ifstat t; 2605*0Sstevel@tonic-gate struct iflist *tlp; 2606*0Sstevel@tonic-gate struct iflist **nextnew = &newlist; 2607*0Sstevel@tonic-gate struct iflist *walkold; 2608*0Sstevel@tonic-gate struct iflist *cleanlist; 2609*0Sstevel@tonic-gate 2610*0Sstevel@tonic-gate alreadydone = B_TRUE; /* ignore other case */ 2611*0Sstevel@tonic-gate /* 2612*0Sstevel@tonic-gate * 'for' loop 2b: find the "right" entry 2613*0Sstevel@tonic-gate */ 2614*0Sstevel@tonic-gate for (ap = (mib2_ipAddrEntry_t *)item->valp; 2615*0Sstevel@tonic-gate (char *)ap < (char *)item->valp 2616*0Sstevel@tonic-gate + item->length; 2617*0Sstevel@tonic-gate ap++) { 2618*0Sstevel@tonic-gate (void) octetstr(&ap->ipAdEntIfIndex, 2619*0Sstevel@tonic-gate 'a', ifname, sizeof (ifname)); 2620*0Sstevel@tonic-gate (void) strtok(ifname, ":"); 2621*0Sstevel@tonic-gate 2622*0Sstevel@tonic-gate if (matchname) { 2623*0Sstevel@tonic-gate if (strcmp(matchname, 2624*0Sstevel@tonic-gate ifname) == 0) 2625*0Sstevel@tonic-gate /* 'for' loop 2b */ 2626*0Sstevel@tonic-gate break; 2627*0Sstevel@tonic-gate } else if (strcmp(ifname, "lo0") != 0) { 2628*0Sstevel@tonic-gate matchname = ifname; 2629*0Sstevel@tonic-gate break; /* 'for' loop 2b */ 2630*0Sstevel@tonic-gate } 2631*0Sstevel@tonic-gate } /* 'for' loop 2b ends */ 2632*0Sstevel@tonic-gate 2633*0Sstevel@tonic-gate if (Iflag_only == 0 || !reentry) { 2634*0Sstevel@tonic-gate (void) printf(" input %-6.6s " 2635*0Sstevel@tonic-gate "output ", 2636*0Sstevel@tonic-gate matchname); 2637*0Sstevel@tonic-gate (void) printf(" input (Total) " 2638*0Sstevel@tonic-gate "output\n"); 2639*0Sstevel@tonic-gate (void) printf("%-7.7s %-5.5s %-7.7s " 2640*0Sstevel@tonic-gate "%-5.5s %-6.6s ", 2641*0Sstevel@tonic-gate "packets", "errs", "packets", 2642*0Sstevel@tonic-gate "errs", "colls"); 2643*0Sstevel@tonic-gate (void) printf("%-7.7s %-5.5s %-7.7s " 2644*0Sstevel@tonic-gate "%-5.5s %-6.6s\n", 2645*0Sstevel@tonic-gate "packets", "errs", "packets", 2646*0Sstevel@tonic-gate "errs", "colls"); 2647*0Sstevel@tonic-gate } 2648*0Sstevel@tonic-gate 2649*0Sstevel@tonic-gate sum = zerostat; 2650*0Sstevel@tonic-gate 2651*0Sstevel@tonic-gate /* 'for' loop 2c: */ 2652*0Sstevel@tonic-gate for (ap = (mib2_ipAddrEntry_t *)item->valp; 2653*0Sstevel@tonic-gate (char *)ap < (char *)item->valp 2654*0Sstevel@tonic-gate + item->length; 2655*0Sstevel@tonic-gate ap++) { 2656*0Sstevel@tonic-gate (void) octetstr(&ap->ipAdEntIfIndex, 2657*0Sstevel@tonic-gate 'a', buf, sizeof (buf)); 2658*0Sstevel@tonic-gate (void) strtok(buf, ":"); 2659*0Sstevel@tonic-gate ksp = kstat_lookup(kc, NULL, -1, buf); 2660*0Sstevel@tonic-gate if (ksp && 2661*0Sstevel@tonic-gate ksp->ks_type == KSTAT_TYPE_NAMED) 2662*0Sstevel@tonic-gate (void) safe_kstat_read(kc, ksp, 2663*0Sstevel@tonic-gate NULL); 2664*0Sstevel@tonic-gate 2665*0Sstevel@tonic-gate t.ipackets = kstat_named_value(ksp, 2666*0Sstevel@tonic-gate "ipackets"); 2667*0Sstevel@tonic-gate t.ierrors = kstat_named_value(ksp, 2668*0Sstevel@tonic-gate "ierrors"); 2669*0Sstevel@tonic-gate t.opackets = kstat_named_value(ksp, 2670*0Sstevel@tonic-gate "opackets"); 2671*0Sstevel@tonic-gate t.oerrors = kstat_named_value(ksp, 2672*0Sstevel@tonic-gate "oerrors"); 2673*0Sstevel@tonic-gate t.collisions = kstat_named_value(ksp, 2674*0Sstevel@tonic-gate "collisions"); 2675*0Sstevel@tonic-gate 2676*0Sstevel@tonic-gate if (strcmp(buf, matchname) == 0) 2677*0Sstevel@tonic-gate new = t; 2678*0Sstevel@tonic-gate 2679*0Sstevel@tonic-gate /* Build the interface list */ 2680*0Sstevel@tonic-gate 2681*0Sstevel@tonic-gate tlp = malloc(sizeof (struct iflist)); 2682*0Sstevel@tonic-gate (void) strlcpy(tlp->ifname, buf, 2683*0Sstevel@tonic-gate sizeof (tlp->ifname)); 2684*0Sstevel@tonic-gate tlp->tot = t; 2685*0Sstevel@tonic-gate *nextnew = tlp; 2686*0Sstevel@tonic-gate nextnew = &tlp->next_if; 2687*0Sstevel@tonic-gate 2688*0Sstevel@tonic-gate /* 2689*0Sstevel@tonic-gate * First time through. 2690*0Sstevel@tonic-gate * Just add up the interface stats. 2691*0Sstevel@tonic-gate */ 2692*0Sstevel@tonic-gate 2693*0Sstevel@tonic-gate if (oldlist == NULL) { 2694*0Sstevel@tonic-gate if_stat_total(&zerostat, 2695*0Sstevel@tonic-gate &t, &sum); 2696*0Sstevel@tonic-gate continue; 2697*0Sstevel@tonic-gate } 2698*0Sstevel@tonic-gate 2699*0Sstevel@tonic-gate /* 2700*0Sstevel@tonic-gate * Walk old list for the interface. 2701*0Sstevel@tonic-gate * 2702*0Sstevel@tonic-gate * If found, add difference to total. 2703*0Sstevel@tonic-gate * 2704*0Sstevel@tonic-gate * If not, an interface has been plumbed 2705*0Sstevel@tonic-gate * up. In this case, we will simply 2706*0Sstevel@tonic-gate * ignore the new interface until the 2707*0Sstevel@tonic-gate * next interval; as there's no easy way 2708*0Sstevel@tonic-gate * to acquire statistics between time 2709*0Sstevel@tonic-gate * of the plumb and the next interval 2710*0Sstevel@tonic-gate * boundary. This results in inaccurate 2711*0Sstevel@tonic-gate * total values for current interval. 2712*0Sstevel@tonic-gate * 2713*0Sstevel@tonic-gate * Note the case when an interface is 2714*0Sstevel@tonic-gate * unplumbed; as similar problems exist. 2715*0Sstevel@tonic-gate * The unplumbed interface is not in the 2716*0Sstevel@tonic-gate * current list, and there's no easy way 2717*0Sstevel@tonic-gate * to account for the statistics between 2718*0Sstevel@tonic-gate * the previous interval and time of the 2719*0Sstevel@tonic-gate * unplumb. Therefore, we (in a sense) 2720*0Sstevel@tonic-gate * ignore the removed interface by only 2721*0Sstevel@tonic-gate * involving "current" interfaces when 2722*0Sstevel@tonic-gate * computing the total statistics. 2723*0Sstevel@tonic-gate * Unfortunately, this also results in 2724*0Sstevel@tonic-gate * inaccurate values for interval total. 2725*0Sstevel@tonic-gate */ 2726*0Sstevel@tonic-gate 2727*0Sstevel@tonic-gate for (walkold = oldlist; 2728*0Sstevel@tonic-gate walkold != NULL; 2729*0Sstevel@tonic-gate walkold = walkold->next_if) { 2730*0Sstevel@tonic-gate if (strcmp(walkold->ifname, 2731*0Sstevel@tonic-gate buf) == 0) { 2732*0Sstevel@tonic-gate if_stat_total( 2733*0Sstevel@tonic-gate &walkold->tot, 2734*0Sstevel@tonic-gate &t, &sum); 2735*0Sstevel@tonic-gate break; 2736*0Sstevel@tonic-gate } 2737*0Sstevel@tonic-gate } 2738*0Sstevel@tonic-gate 2739*0Sstevel@tonic-gate } /* 'for' loop 2c ends */ 2740*0Sstevel@tonic-gate 2741*0Sstevel@tonic-gate *nextnew = NULL; 2742*0Sstevel@tonic-gate 2743*0Sstevel@tonic-gate (void) printf("%-7llu %-5llu %-7llu " 2744*0Sstevel@tonic-gate "%-5llu %-6llu ", 2745*0Sstevel@tonic-gate new.ipackets - old.ipackets, 2746*0Sstevel@tonic-gate new.ierrors - old.ierrors, 2747*0Sstevel@tonic-gate new.opackets - old.opackets, 2748*0Sstevel@tonic-gate new.oerrors - old.oerrors, 2749*0Sstevel@tonic-gate new.collisions - old.collisions); 2750*0Sstevel@tonic-gate 2751*0Sstevel@tonic-gate (void) printf("%-7llu %-5llu %-7llu " 2752*0Sstevel@tonic-gate "%-5llu %-6llu\n", sum.ipackets, 2753*0Sstevel@tonic-gate sum.ierrors, sum.opackets, 2754*0Sstevel@tonic-gate sum.oerrors, sum.collisions); 2755*0Sstevel@tonic-gate 2756*0Sstevel@tonic-gate /* 2757*0Sstevel@tonic-gate * Tidy things up once finished. 2758*0Sstevel@tonic-gate */ 2759*0Sstevel@tonic-gate 2760*0Sstevel@tonic-gate old = new; 2761*0Sstevel@tonic-gate cleanlist = oldlist; 2762*0Sstevel@tonic-gate oldlist = newlist; 2763*0Sstevel@tonic-gate while (cleanlist != NULL) { 2764*0Sstevel@tonic-gate tlp = cleanlist->next_if; 2765*0Sstevel@tonic-gate free(cleanlist); 2766*0Sstevel@tonic-gate cleanlist = tlp; 2767*0Sstevel@tonic-gate } 2768*0Sstevel@tonic-gate } 2769*0Sstevel@tonic-gate break; 2770*0Sstevel@tonic-gate } 2771*0Sstevel@tonic-gate case MIB2_IP6: 2772*0Sstevel@tonic-gate if (item->mib_id != MIB2_IP6_ADDR || 2773*0Sstevel@tonic-gate !family_selected(AF_INET6)) 2774*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 2775*0Sstevel@tonic-gate { 2776*0Sstevel@tonic-gate static struct ifstat old6 = {0L, 0L, 0L, 0L, 0L}; 2777*0Sstevel@tonic-gate static struct ifstat new6 = {0L, 0L, 0L, 0L, 0L}; 2778*0Sstevel@tonic-gate struct ifstat sum6; 2779*0Sstevel@tonic-gate struct iflist *newlist6 = NULL; 2780*0Sstevel@tonic-gate static struct iflist *oldlist6 = NULL; 2781*0Sstevel@tonic-gate kstat_t *ksp; 2782*0Sstevel@tonic-gate 2783*0Sstevel@tonic-gate if (once_only) { 2784*0Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 2785*0Sstevel@tonic-gate char logintname[LIFNAMSIZ + 1]; 2786*0Sstevel@tonic-gate mib2_ipv6AddrEntry_t *ap6; 2787*0Sstevel@tonic-gate struct ifstat stat = {0L, 0L, 0L, 0L, 0L}; 2788*0Sstevel@tonic-gate boolean_t first = B_TRUE; 2789*0Sstevel@tonic-gate uint32_t new_ifindex; 2790*0Sstevel@tonic-gate 2791*0Sstevel@tonic-gate if (Dflag) 2792*0Sstevel@tonic-gate (void) printf("if_report: %d items\n", 2793*0Sstevel@tonic-gate (item->length) 2794*0Sstevel@tonic-gate / sizeof (mib2_ipv6AddrEntry_t)); 2795*0Sstevel@tonic-gate /* 'for' loop 2d: */ 2796*0Sstevel@tonic-gate for (ap6 = (mib2_ipv6AddrEntry_t *)item->valp; 2797*0Sstevel@tonic-gate (char *)ap6 < (char *)item->valp 2798*0Sstevel@tonic-gate + item->length; 2799*0Sstevel@tonic-gate ap6++) { 2800*0Sstevel@tonic-gate (void) octetstr(&ap6->ipv6AddrIfIndex, 2801*0Sstevel@tonic-gate 'a', logintname, 2802*0Sstevel@tonic-gate sizeof (logintname)); 2803*0Sstevel@tonic-gate (void) strcpy(ifname, logintname); 2804*0Sstevel@tonic-gate (void) strtok(ifname, ":"); 2805*0Sstevel@tonic-gate if (matchname != NULL && 2806*0Sstevel@tonic-gate strcmp(matchname, ifname) != 0 && 2807*0Sstevel@tonic-gate strcmp(matchname, logintname) != 0) 2808*0Sstevel@tonic-gate continue; /* 'for' loop 2d */ 2809*0Sstevel@tonic-gate new_ifindex = 2810*0Sstevel@tonic-gate if_nametoindex(logintname); 2811*0Sstevel@tonic-gate if (new_ifindex != ifindex_v6 && 2812*0Sstevel@tonic-gate (ksp = kstat_lookup(kc, NULL, -1, 2813*0Sstevel@tonic-gate ifname)) != NULL) { 2814*0Sstevel@tonic-gate (void) safe_kstat_read(kc, ksp, 2815*0Sstevel@tonic-gate NULL); 2816*0Sstevel@tonic-gate stat.ipackets = 2817*0Sstevel@tonic-gate kstat_named_value(ksp, 2818*0Sstevel@tonic-gate "ipackets"); 2819*0Sstevel@tonic-gate stat.ierrors = 2820*0Sstevel@tonic-gate kstat_named_value(ksp, 2821*0Sstevel@tonic-gate "ierrors"); 2822*0Sstevel@tonic-gate stat.opackets = 2823*0Sstevel@tonic-gate kstat_named_value(ksp, 2824*0Sstevel@tonic-gate "opackets"); 2825*0Sstevel@tonic-gate stat.oerrors = 2826*0Sstevel@tonic-gate kstat_named_value(ksp, 2827*0Sstevel@tonic-gate "oerrors"); 2828*0Sstevel@tonic-gate stat.collisions = 2829*0Sstevel@tonic-gate kstat_named_value(ksp, 2830*0Sstevel@tonic-gate "collisions"); 2831*0Sstevel@tonic-gate if (first) { 2832*0Sstevel@tonic-gate (void) printf( 2833*0Sstevel@tonic-gate "%-5.5s %-5.5s%" 2834*0Sstevel@tonic-gate "-27.27s %-27.27s " 2835*0Sstevel@tonic-gate "%-6.6s %-5.5s " 2836*0Sstevel@tonic-gate "%-6.6s %-5.5s " 2837*0Sstevel@tonic-gate "%-6.6s\n", 2838*0Sstevel@tonic-gate "Name", "Mtu", 2839*0Sstevel@tonic-gate "Net/Dest", 2840*0Sstevel@tonic-gate "Address", "Ipkts", 2841*0Sstevel@tonic-gate "Ierrs", "Opkts", 2842*0Sstevel@tonic-gate "Oerrs", "Collis"); 2843*0Sstevel@tonic-gate first = B_FALSE; 2844*0Sstevel@tonic-gate } 2845*0Sstevel@tonic-gate if_report_ip6(ap6, ifname, 2846*0Sstevel@tonic-gate logintname, &stat, B_TRUE); 2847*0Sstevel@tonic-gate ifindex_v6 = new_ifindex; 2848*0Sstevel@tonic-gate } else { 2849*0Sstevel@tonic-gate if_report_ip6(ap6, ifname, 2850*0Sstevel@tonic-gate logintname, &stat, B_FALSE); 2851*0Sstevel@tonic-gate } 2852*0Sstevel@tonic-gate } /* 'for' loop 2d ends */ 2853*0Sstevel@tonic-gate if (!first) 2854*0Sstevel@tonic-gate (void) putchar('\n'); 2855*0Sstevel@tonic-gate } else if (!alreadydone) { 2856*0Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 2857*0Sstevel@tonic-gate char buf[IFNAMSIZ + 1]; 2858*0Sstevel@tonic-gate mib2_ipv6AddrEntry_t *ap6; 2859*0Sstevel@tonic-gate struct ifstat t; 2860*0Sstevel@tonic-gate struct iflist *tlp; 2861*0Sstevel@tonic-gate struct iflist **nextnew = &newlist6; 2862*0Sstevel@tonic-gate struct iflist *walkold; 2863*0Sstevel@tonic-gate struct iflist *cleanlist; 2864*0Sstevel@tonic-gate 2865*0Sstevel@tonic-gate alreadydone = B_TRUE; /* ignore other case */ 2866*0Sstevel@tonic-gate /* 2867*0Sstevel@tonic-gate * 'for' loop 2e: find the "right" entry 2868*0Sstevel@tonic-gate */ 2869*0Sstevel@tonic-gate for (ap6 = (mib2_ipv6AddrEntry_t *)item->valp; 2870*0Sstevel@tonic-gate (char *)ap6 < (char *)item->valp 2871*0Sstevel@tonic-gate + item->length; 2872*0Sstevel@tonic-gate ap6++) { 2873*0Sstevel@tonic-gate (void) octetstr(&ap6->ipv6AddrIfIndex, 2874*0Sstevel@tonic-gate 'a', ifname, sizeof (ifname)); 2875*0Sstevel@tonic-gate (void) strtok(ifname, ":"); 2876*0Sstevel@tonic-gate 2877*0Sstevel@tonic-gate if (matchname) { 2878*0Sstevel@tonic-gate if (strcmp(matchname, ifname) == 2879*0Sstevel@tonic-gate 0) 2880*0Sstevel@tonic-gate /* 'for' loop 2e */ 2881*0Sstevel@tonic-gate break; 2882*0Sstevel@tonic-gate } else if (strcmp(ifname, "lo0") != 0) { 2883*0Sstevel@tonic-gate matchname = ifname; 2884*0Sstevel@tonic-gate break; /* 'for' loop 2e */ 2885*0Sstevel@tonic-gate } 2886*0Sstevel@tonic-gate } /* 'for' loop 2e ends */ 2887*0Sstevel@tonic-gate 2888*0Sstevel@tonic-gate if (Iflag_only == 0 || !reentry) { 2889*0Sstevel@tonic-gate (void) printf( 2890*0Sstevel@tonic-gate " input %-6.6s" 2891*0Sstevel@tonic-gate " output ", 2892*0Sstevel@tonic-gate matchname); 2893*0Sstevel@tonic-gate (void) printf(" input (Total)" 2894*0Sstevel@tonic-gate " output\n"); 2895*0Sstevel@tonic-gate (void) printf("%-7.7s %-5.5s %-7.7s " 2896*0Sstevel@tonic-gate "%-5.5s %-6.6s ", 2897*0Sstevel@tonic-gate "packets", "errs", "packets", 2898*0Sstevel@tonic-gate "errs", "colls"); 2899*0Sstevel@tonic-gate (void) printf("%-7.7s %-5.5s %-7.7s " 2900*0Sstevel@tonic-gate "%-5.5s %-6.6s\n", 2901*0Sstevel@tonic-gate "packets", "errs", "packets", 2902*0Sstevel@tonic-gate "errs", "colls"); 2903*0Sstevel@tonic-gate } 2904*0Sstevel@tonic-gate 2905*0Sstevel@tonic-gate sum6 = zerostat; 2906*0Sstevel@tonic-gate 2907*0Sstevel@tonic-gate /* 'for' loop 2f: */ 2908*0Sstevel@tonic-gate for (ap6 = (mib2_ipv6AddrEntry_t *)item->valp; 2909*0Sstevel@tonic-gate (char *)ap6 < (char *)item->valp 2910*0Sstevel@tonic-gate + item->length; 2911*0Sstevel@tonic-gate ap6++) { 2912*0Sstevel@tonic-gate (void) octetstr(&ap6->ipv6AddrIfIndex, 2913*0Sstevel@tonic-gate 'a', buf, sizeof (buf)); 2914*0Sstevel@tonic-gate (void) strtok(buf, ":"); 2915*0Sstevel@tonic-gate ksp = kstat_lookup(kc, NULL, -1, buf); 2916*0Sstevel@tonic-gate if (ksp && ksp->ks_type == 2917*0Sstevel@tonic-gate KSTAT_TYPE_NAMED) 2918*0Sstevel@tonic-gate (void) safe_kstat_read(kc, 2919*0Sstevel@tonic-gate ksp, NULL); 2920*0Sstevel@tonic-gate 2921*0Sstevel@tonic-gate t.ipackets = kstat_named_value(ksp, 2922*0Sstevel@tonic-gate "ipackets"); 2923*0Sstevel@tonic-gate t.ierrors = kstat_named_value(ksp, 2924*0Sstevel@tonic-gate "ierrors"); 2925*0Sstevel@tonic-gate t.opackets = kstat_named_value(ksp, 2926*0Sstevel@tonic-gate "opackets"); 2927*0Sstevel@tonic-gate t.oerrors = kstat_named_value(ksp, 2928*0Sstevel@tonic-gate "oerrors"); 2929*0Sstevel@tonic-gate t.collisions = kstat_named_value(ksp, 2930*0Sstevel@tonic-gate "collisions"); 2931*0Sstevel@tonic-gate 2932*0Sstevel@tonic-gate if (strcmp(buf, matchname) == 0) 2933*0Sstevel@tonic-gate new6 = t; 2934*0Sstevel@tonic-gate 2935*0Sstevel@tonic-gate /* Build the interface list */ 2936*0Sstevel@tonic-gate 2937*0Sstevel@tonic-gate tlp = malloc(sizeof (struct iflist)); 2938*0Sstevel@tonic-gate (void) strlcpy(tlp->ifname, buf, 2939*0Sstevel@tonic-gate sizeof (tlp->ifname)); 2940*0Sstevel@tonic-gate tlp->tot = t; 2941*0Sstevel@tonic-gate *nextnew = tlp; 2942*0Sstevel@tonic-gate nextnew = &tlp->next_if; 2943*0Sstevel@tonic-gate 2944*0Sstevel@tonic-gate /* 2945*0Sstevel@tonic-gate * First time through. 2946*0Sstevel@tonic-gate * Just add up the interface stats. 2947*0Sstevel@tonic-gate */ 2948*0Sstevel@tonic-gate 2949*0Sstevel@tonic-gate if (oldlist6 == NULL) { 2950*0Sstevel@tonic-gate if_stat_total(&zerostat, 2951*0Sstevel@tonic-gate &t, &sum6); 2952*0Sstevel@tonic-gate continue; 2953*0Sstevel@tonic-gate } 2954*0Sstevel@tonic-gate 2955*0Sstevel@tonic-gate /* 2956*0Sstevel@tonic-gate * Walk old list for the interface. 2957*0Sstevel@tonic-gate * 2958*0Sstevel@tonic-gate * If found, add difference to total. 2959*0Sstevel@tonic-gate * 2960*0Sstevel@tonic-gate * If not, an interface has been plumbed 2961*0Sstevel@tonic-gate * up. In this case, we will simply 2962*0Sstevel@tonic-gate * ignore the new interface until the 2963*0Sstevel@tonic-gate * next interval; as there's no easy way 2964*0Sstevel@tonic-gate * to acquire statistics between time 2965*0Sstevel@tonic-gate * of the plumb and the next interval 2966*0Sstevel@tonic-gate * boundary. This results in inaccurate 2967*0Sstevel@tonic-gate * total values for current interval. 2968*0Sstevel@tonic-gate * 2969*0Sstevel@tonic-gate * Note the case when an interface is 2970*0Sstevel@tonic-gate * unplumbed; as similar problems exist. 2971*0Sstevel@tonic-gate * The unplumbed interface is not in the 2972*0Sstevel@tonic-gate * current list, and there's no easy way 2973*0Sstevel@tonic-gate * to account for the statistics between 2974*0Sstevel@tonic-gate * the previous interval and time of the 2975*0Sstevel@tonic-gate * unplumb. Therefore, we (in a sense) 2976*0Sstevel@tonic-gate * ignore the removed interface by only 2977*0Sstevel@tonic-gate * involving "current" interfaces when 2978*0Sstevel@tonic-gate * computing the total statistics. 2979*0Sstevel@tonic-gate * Unfortunately, this also results in 2980*0Sstevel@tonic-gate * inaccurate values for interval total. 2981*0Sstevel@tonic-gate */ 2982*0Sstevel@tonic-gate 2983*0Sstevel@tonic-gate for (walkold = oldlist6; 2984*0Sstevel@tonic-gate walkold != NULL; 2985*0Sstevel@tonic-gate walkold = walkold->next_if) { 2986*0Sstevel@tonic-gate if (strcmp(walkold->ifname, 2987*0Sstevel@tonic-gate buf) == 0) { 2988*0Sstevel@tonic-gate if_stat_total( 2989*0Sstevel@tonic-gate &walkold->tot, 2990*0Sstevel@tonic-gate &t, &sum6); 2991*0Sstevel@tonic-gate break; 2992*0Sstevel@tonic-gate } 2993*0Sstevel@tonic-gate } 2994*0Sstevel@tonic-gate 2995*0Sstevel@tonic-gate } /* 'for' loop 2f ends */ 2996*0Sstevel@tonic-gate 2997*0Sstevel@tonic-gate *nextnew = NULL; 2998*0Sstevel@tonic-gate 2999*0Sstevel@tonic-gate (void) printf("%-7llu %-5llu %-7llu " 3000*0Sstevel@tonic-gate "%-5llu %-6llu ", 3001*0Sstevel@tonic-gate new6.ipackets - old6.ipackets, 3002*0Sstevel@tonic-gate new6.ierrors - old6.ierrors, 3003*0Sstevel@tonic-gate new6.opackets - old6.opackets, 3004*0Sstevel@tonic-gate new6.oerrors - old6.oerrors, 3005*0Sstevel@tonic-gate new6.collisions - old6.collisions); 3006*0Sstevel@tonic-gate 3007*0Sstevel@tonic-gate (void) printf("%-7llu %-5llu %-7llu " 3008*0Sstevel@tonic-gate "%-5llu %-6llu\n", sum6.ipackets, 3009*0Sstevel@tonic-gate sum6.ierrors, sum6.opackets, 3010*0Sstevel@tonic-gate sum6.oerrors, sum6.collisions); 3011*0Sstevel@tonic-gate 3012*0Sstevel@tonic-gate /* 3013*0Sstevel@tonic-gate * Tidy things up once finished. 3014*0Sstevel@tonic-gate */ 3015*0Sstevel@tonic-gate 3016*0Sstevel@tonic-gate old6 = new6; 3017*0Sstevel@tonic-gate cleanlist = oldlist6; 3018*0Sstevel@tonic-gate oldlist6 = newlist6; 3019*0Sstevel@tonic-gate while (cleanlist != NULL) { 3020*0Sstevel@tonic-gate tlp = cleanlist->next_if; 3021*0Sstevel@tonic-gate free(cleanlist); 3022*0Sstevel@tonic-gate cleanlist = tlp; 3023*0Sstevel@tonic-gate } 3024*0Sstevel@tonic-gate } 3025*0Sstevel@tonic-gate break; 3026*0Sstevel@tonic-gate } 3027*0Sstevel@tonic-gate } 3028*0Sstevel@tonic-gate if (Iflag_only == 0) 3029*0Sstevel@tonic-gate (void) putchar('\n'); 3030*0Sstevel@tonic-gate (void) fflush(stdout); 3031*0Sstevel@tonic-gate } /* 'for' loop 1 ends */ 3032*0Sstevel@tonic-gate reentry = B_TRUE; 3033*0Sstevel@tonic-gate } 3034*0Sstevel@tonic-gate 3035*0Sstevel@tonic-gate static void 3036*0Sstevel@tonic-gate if_report_ip4(mib2_ipAddrEntry_t *ap, 3037*0Sstevel@tonic-gate char ifname[], char logintname[], struct ifstat *statptr, 3038*0Sstevel@tonic-gate boolean_t ksp_not_null) { 3039*0Sstevel@tonic-gate 3040*0Sstevel@tonic-gate char abuf[MAXHOSTNAMELEN + 1]; 3041*0Sstevel@tonic-gate char dstbuf[MAXHOSTNAMELEN + 1]; 3042*0Sstevel@tonic-gate 3043*0Sstevel@tonic-gate if (ksp_not_null) { 3044*0Sstevel@tonic-gate (void) printf("%-5s %-5u", 3045*0Sstevel@tonic-gate ifname, ap->ipAdEntInfo.ae_mtu); 3046*0Sstevel@tonic-gate if (ap->ipAdEntInfo.ae_flags & IFF_POINTOPOINT) 3047*0Sstevel@tonic-gate (void) pr_addr(ap->ipAdEntInfo.ae_pp_dst_addr, 3048*0Sstevel@tonic-gate abuf, sizeof (abuf)); 3049*0Sstevel@tonic-gate else 3050*0Sstevel@tonic-gate (void) pr_netaddr(ap->ipAdEntAddr, 3051*0Sstevel@tonic-gate ap->ipAdEntNetMask, abuf, sizeof (abuf)); 3052*0Sstevel@tonic-gate (void) printf("%-13s %-14s %-6llu %-5llu %-6llu %-5llu " 3053*0Sstevel@tonic-gate "%-6llu %-6llu\n", 3054*0Sstevel@tonic-gate abuf, pr_addr(ap->ipAdEntAddr, dstbuf, sizeof (dstbuf)), 3055*0Sstevel@tonic-gate statptr->ipackets, statptr->ierrors, 3056*0Sstevel@tonic-gate statptr->opackets, statptr->oerrors, 3057*0Sstevel@tonic-gate statptr->collisions, 0LL); 3058*0Sstevel@tonic-gate } 3059*0Sstevel@tonic-gate /* 3060*0Sstevel@tonic-gate * Print logical interface info if Aflag set (including logical unit 0) 3061*0Sstevel@tonic-gate */ 3062*0Sstevel@tonic-gate if (Aflag) { 3063*0Sstevel@tonic-gate *statptr = zerostat; 3064*0Sstevel@tonic-gate statptr->ipackets = ap->ipAdEntInfo.ae_ibcnt; 3065*0Sstevel@tonic-gate statptr->opackets = ap->ipAdEntInfo.ae_obcnt; 3066*0Sstevel@tonic-gate 3067*0Sstevel@tonic-gate (void) printf("%-5s %-5u", logintname, ap->ipAdEntInfo.ae_mtu); 3068*0Sstevel@tonic-gate if (ap->ipAdEntInfo.ae_flags & IFF_POINTOPOINT) 3069*0Sstevel@tonic-gate (void) pr_addr(ap->ipAdEntInfo.ae_pp_dst_addr, abuf, 3070*0Sstevel@tonic-gate sizeof (abuf)); 3071*0Sstevel@tonic-gate else 3072*0Sstevel@tonic-gate (void) pr_netaddr(ap->ipAdEntAddr, ap->ipAdEntNetMask, 3073*0Sstevel@tonic-gate abuf, sizeof (abuf)); 3074*0Sstevel@tonic-gate 3075*0Sstevel@tonic-gate (void) printf("%-13s %-14s %-6llu %-5s %-6llu " 3076*0Sstevel@tonic-gate "%-5s %-6s %-6llu\n", abuf, 3077*0Sstevel@tonic-gate pr_addr(ap->ipAdEntAddr, dstbuf, sizeof (dstbuf)), 3078*0Sstevel@tonic-gate statptr->ipackets, "N/A", statptr->opackets, "N/A", "N/A", 3079*0Sstevel@tonic-gate 0LL); 3080*0Sstevel@tonic-gate } 3081*0Sstevel@tonic-gate } 3082*0Sstevel@tonic-gate 3083*0Sstevel@tonic-gate static void 3084*0Sstevel@tonic-gate if_report_ip6(mib2_ipv6AddrEntry_t *ap6, 3085*0Sstevel@tonic-gate char ifname[], char logintname[], struct ifstat *statptr, 3086*0Sstevel@tonic-gate boolean_t ksp_not_null) { 3087*0Sstevel@tonic-gate 3088*0Sstevel@tonic-gate char abuf[MAXHOSTNAMELEN + 1]; 3089*0Sstevel@tonic-gate char dstbuf[MAXHOSTNAMELEN + 1]; 3090*0Sstevel@tonic-gate 3091*0Sstevel@tonic-gate if (ksp_not_null) { 3092*0Sstevel@tonic-gate (void) printf("%-5s %-5u", ifname, ap6->ipv6AddrInfo.ae_mtu); 3093*0Sstevel@tonic-gate if (ap6->ipv6AddrInfo.ae_flags & 3094*0Sstevel@tonic-gate IFF_POINTOPOINT) { 3095*0Sstevel@tonic-gate (void) pr_addr6(&ap6->ipv6AddrInfo.ae_pp_dst_addr, 3096*0Sstevel@tonic-gate abuf, sizeof (abuf)); 3097*0Sstevel@tonic-gate } else { 3098*0Sstevel@tonic-gate (void) pr_prefix6(&ap6->ipv6AddrAddress, 3099*0Sstevel@tonic-gate ap6->ipv6AddrPfxLength, abuf, 3100*0Sstevel@tonic-gate sizeof (abuf)); 3101*0Sstevel@tonic-gate } 3102*0Sstevel@tonic-gate (void) printf("%-27s %-27s %-6llu %-5llu " 3103*0Sstevel@tonic-gate "%-6llu %-5llu %-6llu\n", 3104*0Sstevel@tonic-gate abuf, pr_addr6(&ap6->ipv6AddrAddress, dstbuf, 3105*0Sstevel@tonic-gate sizeof (dstbuf)), 3106*0Sstevel@tonic-gate statptr->ipackets, statptr->ierrors, statptr->opackets, 3107*0Sstevel@tonic-gate statptr->oerrors, statptr->collisions); 3108*0Sstevel@tonic-gate } 3109*0Sstevel@tonic-gate /* 3110*0Sstevel@tonic-gate * Print logical interface info if Aflag set (including logical unit 0) 3111*0Sstevel@tonic-gate */ 3112*0Sstevel@tonic-gate if (Aflag) { 3113*0Sstevel@tonic-gate *statptr = zerostat; 3114*0Sstevel@tonic-gate statptr->ipackets = ap6->ipv6AddrInfo.ae_ibcnt; 3115*0Sstevel@tonic-gate statptr->opackets = ap6->ipv6AddrInfo.ae_obcnt; 3116*0Sstevel@tonic-gate 3117*0Sstevel@tonic-gate (void) printf("%-5s %-5u", logintname, 3118*0Sstevel@tonic-gate ap6->ipv6AddrInfo.ae_mtu); 3119*0Sstevel@tonic-gate if (ap6->ipv6AddrInfo.ae_flags & IFF_POINTOPOINT) 3120*0Sstevel@tonic-gate (void) pr_addr6(&ap6->ipv6AddrInfo.ae_pp_dst_addr, 3121*0Sstevel@tonic-gate abuf, sizeof (abuf)); 3122*0Sstevel@tonic-gate else 3123*0Sstevel@tonic-gate (void) pr_prefix6(&ap6->ipv6AddrAddress, 3124*0Sstevel@tonic-gate ap6->ipv6AddrPfxLength, abuf, sizeof (abuf)); 3125*0Sstevel@tonic-gate (void) printf("%-27s %-27s %-6llu %-5s %-6llu %-5s %-6s\n", 3126*0Sstevel@tonic-gate abuf, pr_addr6(&ap6->ipv6AddrAddress, dstbuf, 3127*0Sstevel@tonic-gate sizeof (dstbuf)), 3128*0Sstevel@tonic-gate statptr->ipackets, "N/A", 3129*0Sstevel@tonic-gate statptr->opackets, "N/A", "N/A"); 3130*0Sstevel@tonic-gate } 3131*0Sstevel@tonic-gate } 3132*0Sstevel@tonic-gate 3133*0Sstevel@tonic-gate /* --------------------- DHCP_REPORT (netstat -D) ------------------------- */ 3134*0Sstevel@tonic-gate 3135*0Sstevel@tonic-gate dhcp_ipc_reply_t * 3136*0Sstevel@tonic-gate dhcp_do_ipc(dhcp_ipc_type_t type, const char *ifname) 3137*0Sstevel@tonic-gate { 3138*0Sstevel@tonic-gate dhcp_ipc_request_t *request; 3139*0Sstevel@tonic-gate dhcp_ipc_reply_t *reply; 3140*0Sstevel@tonic-gate int error; 3141*0Sstevel@tonic-gate 3142*0Sstevel@tonic-gate request = dhcp_ipc_alloc_request(type, ifname, NULL, 0, DHCP_TYPE_NONE); 3143*0Sstevel@tonic-gate if (request == NULL) 3144*0Sstevel@tonic-gate fail(0, "dhcp_do_ipc: out of memory"); 3145*0Sstevel@tonic-gate 3146*0Sstevel@tonic-gate error = dhcp_ipc_make_request(request, &reply, DHCP_IPC_WAIT_DEFAULT); 3147*0Sstevel@tonic-gate if (error != 0) { 3148*0Sstevel@tonic-gate free(request); 3149*0Sstevel@tonic-gate fail(0, "dhcp_do_ipc: %s", dhcp_ipc_strerror(error)); 3150*0Sstevel@tonic-gate } 3151*0Sstevel@tonic-gate 3152*0Sstevel@tonic-gate free(request); 3153*0Sstevel@tonic-gate error = reply->return_code; 3154*0Sstevel@tonic-gate if (error != 0) { 3155*0Sstevel@tonic-gate free(reply); 3156*0Sstevel@tonic-gate fail(0, "dhcp_do_ipc: %s", dhcp_ipc_strerror(error)); 3157*0Sstevel@tonic-gate } 3158*0Sstevel@tonic-gate 3159*0Sstevel@tonic-gate return (reply); 3160*0Sstevel@tonic-gate } 3161*0Sstevel@tonic-gate 3162*0Sstevel@tonic-gate /* 3163*0Sstevel@tonic-gate * get_ifnames: return a dynamically allocated string of all interface 3164*0Sstevel@tonic-gate * names which have all of the IFF_* flags listed in `flags_on' on and 3165*0Sstevel@tonic-gate * all of the IFF_* flags in `flags_off' off. If no such interfaces 3166*0Sstevel@tonic-gate * are found, "" is returned. If an unexpected failure occurs, NULL 3167*0Sstevel@tonic-gate * is returned. 3168*0Sstevel@tonic-gate */ 3169*0Sstevel@tonic-gate static char * 3170*0Sstevel@tonic-gate get_ifnames(int flags_on, int flags_off) 3171*0Sstevel@tonic-gate { 3172*0Sstevel@tonic-gate struct ifconf ifc; 3173*0Sstevel@tonic-gate int n_ifs, i, sock_fd; 3174*0Sstevel@tonic-gate char *ifnames; 3175*0Sstevel@tonic-gate 3176*0Sstevel@tonic-gate sock_fd = socket(AF_INET, SOCK_DGRAM, 0); 3177*0Sstevel@tonic-gate if (sock_fd == -1) 3178*0Sstevel@tonic-gate return (NULL); 3179*0Sstevel@tonic-gate 3180*0Sstevel@tonic-gate if ((ioctl(sock_fd, SIOCGIFNUM, &n_ifs) == -1) || (n_ifs <= 0)) { 3181*0Sstevel@tonic-gate (void) close(sock_fd); 3182*0Sstevel@tonic-gate return (NULL); 3183*0Sstevel@tonic-gate } 3184*0Sstevel@tonic-gate 3185*0Sstevel@tonic-gate ifnames = calloc(1, n_ifs * (IFNAMSIZ + 1)); 3186*0Sstevel@tonic-gate ifc.ifc_len = n_ifs * sizeof (struct ifreq); 3187*0Sstevel@tonic-gate ifc.ifc_req = calloc(n_ifs, sizeof (struct ifreq)); 3188*0Sstevel@tonic-gate if (ifc.ifc_req != NULL && ifnames != NULL) { 3189*0Sstevel@tonic-gate 3190*0Sstevel@tonic-gate if (ioctl(sock_fd, SIOCGIFCONF, &ifc) == -1) { 3191*0Sstevel@tonic-gate (void) close(sock_fd); 3192*0Sstevel@tonic-gate free(ifnames); 3193*0Sstevel@tonic-gate free(ifc.ifc_req); 3194*0Sstevel@tonic-gate return (NULL); 3195*0Sstevel@tonic-gate } 3196*0Sstevel@tonic-gate 3197*0Sstevel@tonic-gate /* 'for' loop 1: */ 3198*0Sstevel@tonic-gate for (i = 0; i < n_ifs; i++) { 3199*0Sstevel@tonic-gate 3200*0Sstevel@tonic-gate if (ioctl(sock_fd, SIOCGIFFLAGS, &ifc.ifc_req[i]) == 0) 3201*0Sstevel@tonic-gate if ((ifc.ifc_req[i].ifr_flags & 3202*0Sstevel@tonic-gate (flags_on | flags_off)) != flags_on) 3203*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 3204*0Sstevel@tonic-gate 3205*0Sstevel@tonic-gate (void) strcat(ifnames, ifc.ifc_req[i].ifr_name); 3206*0Sstevel@tonic-gate (void) strcat(ifnames, " "); 3207*0Sstevel@tonic-gate } /* 'for' loop 1 ends */ 3208*0Sstevel@tonic-gate 3209*0Sstevel@tonic-gate if (strlen(ifnames) > 1) 3210*0Sstevel@tonic-gate ifnames[strlen(ifnames) - 1] = '\0'; 3211*0Sstevel@tonic-gate } 3212*0Sstevel@tonic-gate 3213*0Sstevel@tonic-gate (void) close(sock_fd); 3214*0Sstevel@tonic-gate if (ifc.ifc_req != NULL) 3215*0Sstevel@tonic-gate free(ifc.ifc_req); 3216*0Sstevel@tonic-gate return (ifnames); 3217*0Sstevel@tonic-gate } 3218*0Sstevel@tonic-gate 3219*0Sstevel@tonic-gate static void 3220*0Sstevel@tonic-gate dhcp_report(char *ifname) 3221*0Sstevel@tonic-gate { 3222*0Sstevel@tonic-gate int did_alloc = 0; 3223*0Sstevel@tonic-gate dhcp_ipc_reply_t *reply; 3224*0Sstevel@tonic-gate 3225*0Sstevel@tonic-gate if (!(family_selected(AF_INET))) 3226*0Sstevel@tonic-gate return; 3227*0Sstevel@tonic-gate 3228*0Sstevel@tonic-gate if (ifname == NULL) { 3229*0Sstevel@tonic-gate ifname = get_ifnames(IFF_DHCPRUNNING, 0); 3230*0Sstevel@tonic-gate if (ifname == NULL) 3231*0Sstevel@tonic-gate fail(0, "dhcp_report: unable to retrieve list of" 3232*0Sstevel@tonic-gate " interfaces using DHCP"); 3233*0Sstevel@tonic-gate did_alloc++; 3234*0Sstevel@tonic-gate } 3235*0Sstevel@tonic-gate 3236*0Sstevel@tonic-gate (void) printf("%s", dhcp_status_hdr_string()); 3237*0Sstevel@tonic-gate 3238*0Sstevel@tonic-gate for (ifname = strtok(ifname, " "); 3239*0Sstevel@tonic-gate ifname != NULL; 3240*0Sstevel@tonic-gate ifname = strtok(NULL, " ")) { 3241*0Sstevel@tonic-gate reply = dhcp_do_ipc(DHCP_STATUS, ifname); 3242*0Sstevel@tonic-gate (void) printf("%s", dhcp_status_reply_to_string(reply)); 3243*0Sstevel@tonic-gate free(reply); 3244*0Sstevel@tonic-gate } 3245*0Sstevel@tonic-gate 3246*0Sstevel@tonic-gate if (did_alloc) 3247*0Sstevel@tonic-gate free(ifname); 3248*0Sstevel@tonic-gate } 3249*0Sstevel@tonic-gate 3250*0Sstevel@tonic-gate /* --------------------- GROUP_REPORT (netstat -g) ------------------------- */ 3251*0Sstevel@tonic-gate 3252*0Sstevel@tonic-gate static void 3253*0Sstevel@tonic-gate group_report(mib_item_t *item) 3254*0Sstevel@tonic-gate { 3255*0Sstevel@tonic-gate mib_item_t *v4grp = NULL, *v4src = NULL; 3256*0Sstevel@tonic-gate mib_item_t *v6grp = NULL, *v6src = NULL; 3257*0Sstevel@tonic-gate int jtemp = 0; 3258*0Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 3259*0Sstevel@tonic-gate char abuf[MAXHOSTNAMELEN + 1]; 3260*0Sstevel@tonic-gate ip_member_t *ipmp; 3261*0Sstevel@tonic-gate ip_grpsrc_t *ips; 3262*0Sstevel@tonic-gate ipv6_member_t *ipmp6; 3263*0Sstevel@tonic-gate ipv6_grpsrc_t *ips6; 3264*0Sstevel@tonic-gate char *ifnamep; 3265*0Sstevel@tonic-gate boolean_t first, first_src; 3266*0Sstevel@tonic-gate 3267*0Sstevel@tonic-gate /* 'for' loop 1: */ 3268*0Sstevel@tonic-gate for (; item; item = item->next_item) { 3269*0Sstevel@tonic-gate if (Dflag) { 3270*0Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp); 3271*0Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, " 3272*0Sstevel@tonic-gate "length = %d, valp = 0x%p\n", 3273*0Sstevel@tonic-gate item->group, item->mib_id, item->length, 3274*0Sstevel@tonic-gate item->valp); 3275*0Sstevel@tonic-gate } 3276*0Sstevel@tonic-gate if (item->group == MIB2_IP && family_selected(AF_INET)) { 3277*0Sstevel@tonic-gate switch (item->mib_id) { 3278*0Sstevel@tonic-gate case EXPER_IP_GROUP_MEMBERSHIP: 3279*0Sstevel@tonic-gate v4grp = item; 3280*0Sstevel@tonic-gate if (Dflag) 3281*0Sstevel@tonic-gate (void) printf("item is v4grp info\n"); 3282*0Sstevel@tonic-gate break; 3283*0Sstevel@tonic-gate case EXPER_IP_GROUP_SOURCES: 3284*0Sstevel@tonic-gate v4src = item; 3285*0Sstevel@tonic-gate if (Dflag) 3286*0Sstevel@tonic-gate (void) printf("item is v4src info\n"); 3287*0Sstevel@tonic-gate break; 3288*0Sstevel@tonic-gate default: 3289*0Sstevel@tonic-gate continue; 3290*0Sstevel@tonic-gate } 3291*0Sstevel@tonic-gate continue; 3292*0Sstevel@tonic-gate } 3293*0Sstevel@tonic-gate if (item->group == MIB2_IP6 && family_selected(AF_INET6)) { 3294*0Sstevel@tonic-gate switch (item->mib_id) { 3295*0Sstevel@tonic-gate case EXPER_IP6_GROUP_MEMBERSHIP: 3296*0Sstevel@tonic-gate v6grp = item; 3297*0Sstevel@tonic-gate if (Dflag) 3298*0Sstevel@tonic-gate (void) printf("item is v6grp info\n"); 3299*0Sstevel@tonic-gate break; 3300*0Sstevel@tonic-gate case EXPER_IP6_GROUP_SOURCES: 3301*0Sstevel@tonic-gate v6src = item; 3302*0Sstevel@tonic-gate if (Dflag) 3303*0Sstevel@tonic-gate (void) printf("item is v6src info\n"); 3304*0Sstevel@tonic-gate break; 3305*0Sstevel@tonic-gate default: 3306*0Sstevel@tonic-gate continue; 3307*0Sstevel@tonic-gate } 3308*0Sstevel@tonic-gate } 3309*0Sstevel@tonic-gate } 3310*0Sstevel@tonic-gate 3311*0Sstevel@tonic-gate if (family_selected(AF_INET) && v4grp != NULL) { 3312*0Sstevel@tonic-gate if (Dflag) 3313*0Sstevel@tonic-gate (void) printf("%u records for ipGroupMember:\n", 3314*0Sstevel@tonic-gate v4grp->length / sizeof (ip_member_t)); 3315*0Sstevel@tonic-gate 3316*0Sstevel@tonic-gate first = B_TRUE; 3317*0Sstevel@tonic-gate for (ipmp = (ip_member_t *)v4grp->valp; 3318*0Sstevel@tonic-gate (char *)ipmp < (char *)v4grp->valp + v4grp->length; 3319*0Sstevel@tonic-gate /* LINTED: (note 1) */ 3320*0Sstevel@tonic-gate ipmp = (ip_member_t *)((char *)ipmp + ipMemberEntrySize)) { 3321*0Sstevel@tonic-gate if (first) { 3322*0Sstevel@tonic-gate (void) puts(v4compat ? 3323*0Sstevel@tonic-gate "Group Memberships" : 3324*0Sstevel@tonic-gate "Group Memberships: IPv4"); 3325*0Sstevel@tonic-gate (void) puts("Interface " 3326*0Sstevel@tonic-gate "Group RefCnt"); 3327*0Sstevel@tonic-gate (void) puts("--------- " 3328*0Sstevel@tonic-gate "-------------------- ------"); 3329*0Sstevel@tonic-gate first = B_FALSE; 3330*0Sstevel@tonic-gate } 3331*0Sstevel@tonic-gate 3332*0Sstevel@tonic-gate (void) printf("%-9s %-20s %6u\n", 3333*0Sstevel@tonic-gate octetstr(&ipmp->ipGroupMemberIfIndex, 'a', 3334*0Sstevel@tonic-gate ifname, sizeof (ifname)), 3335*0Sstevel@tonic-gate pr_addr(ipmp->ipGroupMemberAddress, 3336*0Sstevel@tonic-gate abuf, sizeof (abuf)), 3337*0Sstevel@tonic-gate ipmp->ipGroupMemberRefCnt); 3338*0Sstevel@tonic-gate 3339*0Sstevel@tonic-gate 3340*0Sstevel@tonic-gate if (!Vflag || v4src == NULL) 3341*0Sstevel@tonic-gate continue; 3342*0Sstevel@tonic-gate 3343*0Sstevel@tonic-gate if (Dflag) 3344*0Sstevel@tonic-gate (void) printf("scanning %u ipGroupSource " 3345*0Sstevel@tonic-gate "records...\n", 3346*0Sstevel@tonic-gate v4src->length/sizeof (ip_grpsrc_t)); 3347*0Sstevel@tonic-gate 3348*0Sstevel@tonic-gate first_src = B_TRUE; 3349*0Sstevel@tonic-gate for (ips = (ip_grpsrc_t *)v4src->valp; 3350*0Sstevel@tonic-gate (char *)ips < (char *)v4src->valp + v4src->length; 3351*0Sstevel@tonic-gate /* LINTED: (note 1) */ 3352*0Sstevel@tonic-gate ips = (ip_grpsrc_t *)((char *)ips + 3353*0Sstevel@tonic-gate ipGroupSourceEntrySize)) { 3354*0Sstevel@tonic-gate /* 3355*0Sstevel@tonic-gate * We assume that all source addrs for a given 3356*0Sstevel@tonic-gate * interface/group pair are contiguous, so on 3357*0Sstevel@tonic-gate * the first non-match after we've found at 3358*0Sstevel@tonic-gate * least one, we bail. 3359*0Sstevel@tonic-gate */ 3360*0Sstevel@tonic-gate if ((ipmp->ipGroupMemberAddress != 3361*0Sstevel@tonic-gate ips->ipGroupSourceGroup) || 3362*0Sstevel@tonic-gate (!octetstrmatch(&ipmp->ipGroupMemberIfIndex, 3363*0Sstevel@tonic-gate &ips->ipGroupSourceIfIndex))) { 3364*0Sstevel@tonic-gate if (first_src) 3365*0Sstevel@tonic-gate continue; 3366*0Sstevel@tonic-gate else 3367*0Sstevel@tonic-gate break; 3368*0Sstevel@tonic-gate } 3369*0Sstevel@tonic-gate if (first_src) { 3370*0Sstevel@tonic-gate (void) printf("\t%s: %s\n", 3371*0Sstevel@tonic-gate fmodestr( 3372*0Sstevel@tonic-gate ipmp->ipGroupMemberFilterMode), 3373*0Sstevel@tonic-gate pr_addr(ips->ipGroupSourceAddress, 3374*0Sstevel@tonic-gate abuf, sizeof (abuf))); 3375*0Sstevel@tonic-gate first_src = B_FALSE; 3376*0Sstevel@tonic-gate continue; 3377*0Sstevel@tonic-gate } 3378*0Sstevel@tonic-gate 3379*0Sstevel@tonic-gate (void) printf("\t %s\n", 3380*0Sstevel@tonic-gate pr_addr(ips->ipGroupSourceAddress, abuf, 3381*0Sstevel@tonic-gate sizeof (abuf))); 3382*0Sstevel@tonic-gate } 3383*0Sstevel@tonic-gate } 3384*0Sstevel@tonic-gate (void) putchar('\n'); 3385*0Sstevel@tonic-gate } 3386*0Sstevel@tonic-gate 3387*0Sstevel@tonic-gate if (family_selected(AF_INET6) && v6grp != NULL) { 3388*0Sstevel@tonic-gate if (Dflag) 3389*0Sstevel@tonic-gate (void) printf("%u records for ipv6GroupMember:\n", 3390*0Sstevel@tonic-gate v6grp->length / sizeof (ipv6_member_t)); 3391*0Sstevel@tonic-gate 3392*0Sstevel@tonic-gate first = B_TRUE; 3393*0Sstevel@tonic-gate for (ipmp6 = (ipv6_member_t *)v6grp->valp; 3394*0Sstevel@tonic-gate (char *)ipmp6 < (char *)v6grp->valp + v6grp->length; 3395*0Sstevel@tonic-gate /* LINTED: (note 1) */ 3396*0Sstevel@tonic-gate ipmp6 = (ipv6_member_t *)((char *)ipmp6 + 3397*0Sstevel@tonic-gate ipv6MemberEntrySize)) { 3398*0Sstevel@tonic-gate if (first) { 3399*0Sstevel@tonic-gate (void) puts("Group Memberships: " 3400*0Sstevel@tonic-gate "IPv6"); 3401*0Sstevel@tonic-gate (void) puts(" If " 3402*0Sstevel@tonic-gate "Group RefCnt"); 3403*0Sstevel@tonic-gate (void) puts("----- " 3404*0Sstevel@tonic-gate "--------------------------- ------"); 3405*0Sstevel@tonic-gate first = B_FALSE; 3406*0Sstevel@tonic-gate } 3407*0Sstevel@tonic-gate 3408*0Sstevel@tonic-gate ifnamep = if_indextoname( 3409*0Sstevel@tonic-gate ipmp6->ipv6GroupMemberIfIndex, ifname); 3410*0Sstevel@tonic-gate if (ifnamep == NULL) { 3411*0Sstevel@tonic-gate (void) printf("Invalid ifindex %d\n", 3412*0Sstevel@tonic-gate ipmp6->ipv6GroupMemberIfIndex); 3413*0Sstevel@tonic-gate continue; 3414*0Sstevel@tonic-gate } 3415*0Sstevel@tonic-gate (void) printf("%-5s %-27s %5u\n", 3416*0Sstevel@tonic-gate ifnamep, 3417*0Sstevel@tonic-gate pr_addr6(&ipmp6->ipv6GroupMemberAddress, 3418*0Sstevel@tonic-gate abuf, sizeof (abuf)), 3419*0Sstevel@tonic-gate ipmp6->ipv6GroupMemberRefCnt); 3420*0Sstevel@tonic-gate 3421*0Sstevel@tonic-gate if (!Vflag || v6src == NULL) 3422*0Sstevel@tonic-gate continue; 3423*0Sstevel@tonic-gate 3424*0Sstevel@tonic-gate if (Dflag) 3425*0Sstevel@tonic-gate (void) printf("scanning %u ipv6GroupSource " 3426*0Sstevel@tonic-gate "records...\n", 3427*0Sstevel@tonic-gate v6src->length/sizeof (ipv6_grpsrc_t)); 3428*0Sstevel@tonic-gate 3429*0Sstevel@tonic-gate first_src = B_TRUE; 3430*0Sstevel@tonic-gate for (ips6 = (ipv6_grpsrc_t *)v6src->valp; 3431*0Sstevel@tonic-gate (char *)ips6 < (char *)v6src->valp + v6src->length; 3432*0Sstevel@tonic-gate /* LINTED: (note 1) */ 3433*0Sstevel@tonic-gate ips6 = (ipv6_grpsrc_t *)((char *)ips6 + 3434*0Sstevel@tonic-gate ipv6GroupSourceEntrySize)) { 3435*0Sstevel@tonic-gate /* same assumption as in the v4 case above */ 3436*0Sstevel@tonic-gate if ((ipmp6->ipv6GroupMemberIfIndex != 3437*0Sstevel@tonic-gate ips6->ipv6GroupSourceIfIndex) || 3438*0Sstevel@tonic-gate (!IN6_ARE_ADDR_EQUAL( 3439*0Sstevel@tonic-gate &ipmp6->ipv6GroupMemberAddress, 3440*0Sstevel@tonic-gate &ips6->ipv6GroupSourceGroup))) { 3441*0Sstevel@tonic-gate if (first_src) 3442*0Sstevel@tonic-gate continue; 3443*0Sstevel@tonic-gate else 3444*0Sstevel@tonic-gate break; 3445*0Sstevel@tonic-gate } 3446*0Sstevel@tonic-gate if (first_src) { 3447*0Sstevel@tonic-gate (void) printf("\t%s: %s\n", 3448*0Sstevel@tonic-gate fmodestr( 3449*0Sstevel@tonic-gate ipmp6->ipv6GroupMemberFilterMode), 3450*0Sstevel@tonic-gate pr_addr6( 3451*0Sstevel@tonic-gate &ips6->ipv6GroupSourceAddress, 3452*0Sstevel@tonic-gate abuf, sizeof (abuf))); 3453*0Sstevel@tonic-gate first_src = B_FALSE; 3454*0Sstevel@tonic-gate continue; 3455*0Sstevel@tonic-gate } 3456*0Sstevel@tonic-gate 3457*0Sstevel@tonic-gate (void) printf("\t %s\n", 3458*0Sstevel@tonic-gate pr_addr6(&ips6->ipv6GroupSourceAddress, 3459*0Sstevel@tonic-gate abuf, sizeof (abuf))); 3460*0Sstevel@tonic-gate } 3461*0Sstevel@tonic-gate } 3462*0Sstevel@tonic-gate (void) putchar('\n'); 3463*0Sstevel@tonic-gate } 3464*0Sstevel@tonic-gate 3465*0Sstevel@tonic-gate (void) putchar('\n'); 3466*0Sstevel@tonic-gate (void) fflush(stdout); 3467*0Sstevel@tonic-gate } 3468*0Sstevel@tonic-gate 3469*0Sstevel@tonic-gate /* --------------------- ARP_REPORT (netstat -p) -------------------------- */ 3470*0Sstevel@tonic-gate 3471*0Sstevel@tonic-gate static void 3472*0Sstevel@tonic-gate arp_report(mib_item_t *item) 3473*0Sstevel@tonic-gate { 3474*0Sstevel@tonic-gate int jtemp = 0; 3475*0Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 3476*0Sstevel@tonic-gate char abuf[MAXHOSTNAMELEN + 1]; 3477*0Sstevel@tonic-gate char maskbuf[STR_EXPAND * OCTET_LENGTH + 1]; 3478*0Sstevel@tonic-gate char flbuf[32]; /* ACE_F_ flags */ 3479*0Sstevel@tonic-gate char xbuf[STR_EXPAND * OCTET_LENGTH + 1]; 3480*0Sstevel@tonic-gate mib2_ipNetToMediaEntry_t *np; 3481*0Sstevel@tonic-gate int flags; 3482*0Sstevel@tonic-gate boolean_t first; 3483*0Sstevel@tonic-gate 3484*0Sstevel@tonic-gate if (!(family_selected(AF_INET))) 3485*0Sstevel@tonic-gate return; 3486*0Sstevel@tonic-gate 3487*0Sstevel@tonic-gate /* 'for' loop 1: */ 3488*0Sstevel@tonic-gate for (; item; item = item->next_item) { 3489*0Sstevel@tonic-gate if (Dflag) { 3490*0Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp); 3491*0Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, " 3492*0Sstevel@tonic-gate "length = %d, valp = 0x%p\n", 3493*0Sstevel@tonic-gate item->group, item->mib_id, item->length, 3494*0Sstevel@tonic-gate item->valp); 3495*0Sstevel@tonic-gate } 3496*0Sstevel@tonic-gate if (!(item->group == MIB2_IP && item->mib_id == MIB2_IP_MEDIA)) 3497*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 3498*0Sstevel@tonic-gate 3499*0Sstevel@tonic-gate if (Dflag) 3500*0Sstevel@tonic-gate (void) printf("%u records for " 3501*0Sstevel@tonic-gate "ipNetToMediaEntryTable:\n", 3502*0Sstevel@tonic-gate item->length/sizeof (mib2_ipNetToMediaEntry_t)); 3503*0Sstevel@tonic-gate 3504*0Sstevel@tonic-gate first = B_TRUE; 3505*0Sstevel@tonic-gate /* 'for' loop 2: */ 3506*0Sstevel@tonic-gate for (np = (mib2_ipNetToMediaEntry_t *)item->valp; 3507*0Sstevel@tonic-gate (char *)np < (char *)item->valp + item->length; 3508*0Sstevel@tonic-gate /* LINTED: (note 1) */ 3509*0Sstevel@tonic-gate np = (mib2_ipNetToMediaEntry_t *)((char *)np + 3510*0Sstevel@tonic-gate ipNetToMediaEntrySize)) { 3511*0Sstevel@tonic-gate if (first) { 3512*0Sstevel@tonic-gate (void) puts(v4compat ? 3513*0Sstevel@tonic-gate "Net to Media Table" : 3514*0Sstevel@tonic-gate "Net to Media Table: IPv4"); 3515*0Sstevel@tonic-gate (void) fputs("Device " 3516*0Sstevel@tonic-gate "IP Address Mask ", 3517*0Sstevel@tonic-gate stdout); 3518*0Sstevel@tonic-gate (void) puts("Flags Phys Addr "); 3519*0Sstevel@tonic-gate (void) puts("------ -------------------- " 3520*0Sstevel@tonic-gate "--------------- ----- ---------------"); 3521*0Sstevel@tonic-gate first = B_FALSE; 3522*0Sstevel@tonic-gate } 3523*0Sstevel@tonic-gate 3524*0Sstevel@tonic-gate flbuf[0] = '\0'; 3525*0Sstevel@tonic-gate flags = np->ipNetToMediaInfo.ntm_flags; 3526*0Sstevel@tonic-gate if (flags & ACE_F_PERMANENT) 3527*0Sstevel@tonic-gate (void) strcat(flbuf, "S"); 3528*0Sstevel@tonic-gate if (flags & ACE_F_PUBLISH) 3529*0Sstevel@tonic-gate (void) strcat(flbuf, "P"); 3530*0Sstevel@tonic-gate if (flags & ACE_F_DYING) 3531*0Sstevel@tonic-gate (void) strcat(flbuf, "D"); 3532*0Sstevel@tonic-gate if (!(flags & ACE_F_RESOLVED)) 3533*0Sstevel@tonic-gate (void) strcat(flbuf, "U"); 3534*0Sstevel@tonic-gate if (flags & ACE_F_MAPPING) 3535*0Sstevel@tonic-gate (void) strcat(flbuf, "M"); 3536*0Sstevel@tonic-gate (void) printf("%-6s %-20s %-15s %-5s %s\n", 3537*0Sstevel@tonic-gate octetstr(&np->ipNetToMediaIfIndex, 'a', 3538*0Sstevel@tonic-gate ifname, sizeof (ifname)), 3539*0Sstevel@tonic-gate pr_addr(np->ipNetToMediaNetAddress, 3540*0Sstevel@tonic-gate abuf, sizeof (abuf)), 3541*0Sstevel@tonic-gate octetstr(&np->ipNetToMediaInfo.ntm_mask, 'd', 3542*0Sstevel@tonic-gate maskbuf, sizeof (maskbuf)), 3543*0Sstevel@tonic-gate flbuf, 3544*0Sstevel@tonic-gate octetstr(&np->ipNetToMediaPhysAddress, 'h', 3545*0Sstevel@tonic-gate xbuf, sizeof (xbuf))); 3546*0Sstevel@tonic-gate } /* 'for' loop 2 ends */ 3547*0Sstevel@tonic-gate } /* 'for' loop 1 ends */ 3548*0Sstevel@tonic-gate (void) fflush(stdout); 3549*0Sstevel@tonic-gate } 3550*0Sstevel@tonic-gate 3551*0Sstevel@tonic-gate /* --------------------- NDP_REPORT (netstat -p) -------------------------- */ 3552*0Sstevel@tonic-gate 3553*0Sstevel@tonic-gate static void 3554*0Sstevel@tonic-gate ndp_report(mib_item_t *item) 3555*0Sstevel@tonic-gate { 3556*0Sstevel@tonic-gate int jtemp = 0; 3557*0Sstevel@tonic-gate char abuf[MAXHOSTNAMELEN + 1]; 3558*0Sstevel@tonic-gate char *state; 3559*0Sstevel@tonic-gate char *type; 3560*0Sstevel@tonic-gate char xbuf[STR_EXPAND * OCTET_LENGTH + 1]; 3561*0Sstevel@tonic-gate mib2_ipv6NetToMediaEntry_t *np6; 3562*0Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 3563*0Sstevel@tonic-gate char *ifnamep; 3564*0Sstevel@tonic-gate boolean_t first; 3565*0Sstevel@tonic-gate 3566*0Sstevel@tonic-gate if (!(family_selected(AF_INET6))) 3567*0Sstevel@tonic-gate return; 3568*0Sstevel@tonic-gate 3569*0Sstevel@tonic-gate /* 'for' loop 1: */ 3570*0Sstevel@tonic-gate for (; item; item = item->next_item) { 3571*0Sstevel@tonic-gate if (Dflag) { 3572*0Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp); 3573*0Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, " 3574*0Sstevel@tonic-gate "length = %d, valp = 0x%p\n", 3575*0Sstevel@tonic-gate item->group, item->mib_id, item->length, 3576*0Sstevel@tonic-gate item->valp); 3577*0Sstevel@tonic-gate } 3578*0Sstevel@tonic-gate if (!(item->group == MIB2_IP6 && 3579*0Sstevel@tonic-gate item->mib_id == MIB2_IP6_MEDIA)) 3580*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 3581*0Sstevel@tonic-gate 3582*0Sstevel@tonic-gate first = B_TRUE; 3583*0Sstevel@tonic-gate /* 'for' loop 2: */ 3584*0Sstevel@tonic-gate for (np6 = (mib2_ipv6NetToMediaEntry_t *)item->valp; 3585*0Sstevel@tonic-gate (char *)np6 < (char *)item->valp + item->length; 3586*0Sstevel@tonic-gate /* LINTED: (note 1) */ 3587*0Sstevel@tonic-gate np6 = (mib2_ipv6NetToMediaEntry_t *)((char *)np6 + 3588*0Sstevel@tonic-gate ipv6NetToMediaEntrySize)) { 3589*0Sstevel@tonic-gate if (first) { 3590*0Sstevel@tonic-gate (void) puts("\nNet to Media Table: IPv6"); 3591*0Sstevel@tonic-gate (void) puts(" If Physical Address " 3592*0Sstevel@tonic-gate " Type State Destination/Mask"); 3593*0Sstevel@tonic-gate (void) puts("----- ----------------- " 3594*0Sstevel@tonic-gate "------- ------------ " 3595*0Sstevel@tonic-gate "---------------------------"); 3596*0Sstevel@tonic-gate first = B_FALSE; 3597*0Sstevel@tonic-gate } 3598*0Sstevel@tonic-gate 3599*0Sstevel@tonic-gate ifnamep = if_indextoname(np6->ipv6NetToMediaIfIndex, 3600*0Sstevel@tonic-gate ifname); 3601*0Sstevel@tonic-gate if (ifnamep == NULL) { 3602*0Sstevel@tonic-gate (void) printf("Invalid ifindex %d\n", 3603*0Sstevel@tonic-gate np6->ipv6NetToMediaIfIndex); 3604*0Sstevel@tonic-gate continue; /* 'for' loop 2 */ 3605*0Sstevel@tonic-gate } 3606*0Sstevel@tonic-gate switch (np6->ipv6NetToMediaState) { 3607*0Sstevel@tonic-gate case ND_INCOMPLETE: 3608*0Sstevel@tonic-gate state = "INCOMPLETE"; 3609*0Sstevel@tonic-gate break; 3610*0Sstevel@tonic-gate case ND_REACHABLE: 3611*0Sstevel@tonic-gate state = "REACHABLE"; 3612*0Sstevel@tonic-gate break; 3613*0Sstevel@tonic-gate case ND_STALE: 3614*0Sstevel@tonic-gate state = "STALE"; 3615*0Sstevel@tonic-gate break; 3616*0Sstevel@tonic-gate case ND_DELAY: 3617*0Sstevel@tonic-gate state = "DELAY"; 3618*0Sstevel@tonic-gate break; 3619*0Sstevel@tonic-gate case ND_PROBE: 3620*0Sstevel@tonic-gate state = "PROBE"; 3621*0Sstevel@tonic-gate break; 3622*0Sstevel@tonic-gate case ND_UNREACHABLE: 3623*0Sstevel@tonic-gate state = "UNREACHABLE"; 3624*0Sstevel@tonic-gate break; 3625*0Sstevel@tonic-gate default: 3626*0Sstevel@tonic-gate state = "UNKNOWN"; 3627*0Sstevel@tonic-gate } 3628*0Sstevel@tonic-gate 3629*0Sstevel@tonic-gate switch (np6->ipv6NetToMediaType) { 3630*0Sstevel@tonic-gate case 1: 3631*0Sstevel@tonic-gate type = "other"; 3632*0Sstevel@tonic-gate break; 3633*0Sstevel@tonic-gate case 2: 3634*0Sstevel@tonic-gate type = "dynamic"; 3635*0Sstevel@tonic-gate break; 3636*0Sstevel@tonic-gate case 3: 3637*0Sstevel@tonic-gate type = "static"; 3638*0Sstevel@tonic-gate break; 3639*0Sstevel@tonic-gate case 4: 3640*0Sstevel@tonic-gate type = "local"; 3641*0Sstevel@tonic-gate break; 3642*0Sstevel@tonic-gate } 3643*0Sstevel@tonic-gate (void) printf("%-5s %-17s %-7s %-12s %-27s\n", 3644*0Sstevel@tonic-gate ifnamep, 3645*0Sstevel@tonic-gate octetstr(&np6->ipv6NetToMediaPhysAddress, 'h', 3646*0Sstevel@tonic-gate xbuf, sizeof (xbuf)), 3647*0Sstevel@tonic-gate type, 3648*0Sstevel@tonic-gate state, 3649*0Sstevel@tonic-gate pr_addr6(&np6->ipv6NetToMediaNetAddress, 3650*0Sstevel@tonic-gate abuf, sizeof (abuf))); 3651*0Sstevel@tonic-gate } /* 'for' loop 2 ends */ 3652*0Sstevel@tonic-gate } /* 'for' loop 1 ends */ 3653*0Sstevel@tonic-gate (void) putchar('\n'); 3654*0Sstevel@tonic-gate (void) fflush(stdout); 3655*0Sstevel@tonic-gate } 3656*0Sstevel@tonic-gate 3657*0Sstevel@tonic-gate /* ------------------------- ire_report (netstat -r) ------------------------ */ 3658*0Sstevel@tonic-gate 3659*0Sstevel@tonic-gate static boolean_t ire_report_item_v4(mib2_ipRouteEntry_t *rp, boolean_t first); 3660*0Sstevel@tonic-gate static boolean_t ire_report_item_v4src(mib2_ipRouteEntry_t *rp, 3661*0Sstevel@tonic-gate boolean_t first); 3662*0Sstevel@tonic-gate static boolean_t ire_report_item_v6(mib2_ipv6RouteEntry_t *rp6, 3663*0Sstevel@tonic-gate boolean_t first); 3664*0Sstevel@tonic-gate 3665*0Sstevel@tonic-gate static void 3666*0Sstevel@tonic-gate ire_report(mib_item_t *item) 3667*0Sstevel@tonic-gate { 3668*0Sstevel@tonic-gate int jtemp = 0; 3669*0Sstevel@tonic-gate boolean_t print_hdr_once_v4 = B_TRUE; 3670*0Sstevel@tonic-gate boolean_t print_hdr_once_v6 = B_TRUE; 3671*0Sstevel@tonic-gate mib2_ipRouteEntry_t *rp; 3672*0Sstevel@tonic-gate mib2_ipv6RouteEntry_t *rp6; 3673*0Sstevel@tonic-gate 3674*0Sstevel@tonic-gate /* 'for' loop 1: */ 3675*0Sstevel@tonic-gate for (; item; item = item->next_item) { 3676*0Sstevel@tonic-gate if (Dflag) { 3677*0Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp); 3678*0Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, " 3679*0Sstevel@tonic-gate "length = %d, valp = 0x%p\n", 3680*0Sstevel@tonic-gate item->group, item->mib_id, 3681*0Sstevel@tonic-gate item->length, item->valp); 3682*0Sstevel@tonic-gate } 3683*0Sstevel@tonic-gate if (!((item->group == MIB2_IP && 3684*0Sstevel@tonic-gate item->mib_id == MIB2_IP_ROUTE) || 3685*0Sstevel@tonic-gate (item->group == MIB2_IP6 && 3686*0Sstevel@tonic-gate item->mib_id == MIB2_IP6_ROUTE))) 3687*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 3688*0Sstevel@tonic-gate 3689*0Sstevel@tonic-gate if (item->group == MIB2_IP && !family_selected(AF_INET)) 3690*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 3691*0Sstevel@tonic-gate else if (item->group == MIB2_IP6 && !family_selected(AF_INET6)) 3692*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 3693*0Sstevel@tonic-gate 3694*0Sstevel@tonic-gate if (Dflag) { 3695*0Sstevel@tonic-gate if (item->group == MIB2_IP) { 3696*0Sstevel@tonic-gate (void) printf("%u records for " 3697*0Sstevel@tonic-gate "ipRouteEntryTable:\n", 3698*0Sstevel@tonic-gate item->length/sizeof (mib2_ipRouteEntry_t)); 3699*0Sstevel@tonic-gate } else { 3700*0Sstevel@tonic-gate (void) printf("%u records for " 3701*0Sstevel@tonic-gate "ipv6RouteEntryTable:\n", 3702*0Sstevel@tonic-gate item->length/ 3703*0Sstevel@tonic-gate sizeof (mib2_ipv6RouteEntry_t)); 3704*0Sstevel@tonic-gate } 3705*0Sstevel@tonic-gate } 3706*0Sstevel@tonic-gate 3707*0Sstevel@tonic-gate if (item->group == MIB2_IP) { 3708*0Sstevel@tonic-gate for (rp = (mib2_ipRouteEntry_t *)item->valp; 3709*0Sstevel@tonic-gate (char *)rp < (char *)item->valp + item->length; 3710*0Sstevel@tonic-gate /* LINTED: (note 1) */ 3711*0Sstevel@tonic-gate rp = (mib2_ipRouteEntry_t *)((char *)rp + 3712*0Sstevel@tonic-gate ipRouteEntrySize)) { 3713*0Sstevel@tonic-gate print_hdr_once_v4 = ire_report_item_v4(rp, 3714*0Sstevel@tonic-gate print_hdr_once_v4); 3715*0Sstevel@tonic-gate } 3716*0Sstevel@tonic-gate print_hdr_once_v4 = B_TRUE; 3717*0Sstevel@tonic-gate for (rp = (mib2_ipRouteEntry_t *)item->valp; 3718*0Sstevel@tonic-gate (char *)rp < (char *)item->valp + item->length; 3719*0Sstevel@tonic-gate /* LINTED: (note 1) */ 3720*0Sstevel@tonic-gate rp = (mib2_ipRouteEntry_t *)((char *)rp + 3721*0Sstevel@tonic-gate ipRouteEntrySize)) { 3722*0Sstevel@tonic-gate print_hdr_once_v4 = ire_report_item_v4src(rp, 3723*0Sstevel@tonic-gate print_hdr_once_v4); 3724*0Sstevel@tonic-gate } 3725*0Sstevel@tonic-gate } else { 3726*0Sstevel@tonic-gate for (rp6 = (mib2_ipv6RouteEntry_t *)item->valp; 3727*0Sstevel@tonic-gate (char *)rp6 < (char *)item->valp + item->length; 3728*0Sstevel@tonic-gate /* LINTED: (note 1) */ 3729*0Sstevel@tonic-gate rp6 = (mib2_ipv6RouteEntry_t *)((char *)rp6 + 3730*0Sstevel@tonic-gate ipv6RouteEntrySize)) { 3731*0Sstevel@tonic-gate print_hdr_once_v6 = ire_report_item_v6(rp6, 3732*0Sstevel@tonic-gate print_hdr_once_v6); 3733*0Sstevel@tonic-gate } 3734*0Sstevel@tonic-gate } 3735*0Sstevel@tonic-gate } /* 'for' loop 1 ends */ 3736*0Sstevel@tonic-gate (void) fflush(stdout); 3737*0Sstevel@tonic-gate } 3738*0Sstevel@tonic-gate 3739*0Sstevel@tonic-gate /* 3740*0Sstevel@tonic-gate * Match a user-supplied device name. We do this by string because 3741*0Sstevel@tonic-gate * the MIB2 interface gives us interface name strings rather than 3742*0Sstevel@tonic-gate * ifIndex numbers. The "none" rule matches only routes with no 3743*0Sstevel@tonic-gate * interface. The "any" rule matches routes with any non-blank 3744*0Sstevel@tonic-gate * interface. A base name ("hme0") matches all aliases as well 3745*0Sstevel@tonic-gate * ("hme0:1"). 3746*0Sstevel@tonic-gate */ 3747*0Sstevel@tonic-gate static boolean_t 3748*0Sstevel@tonic-gate dev_name_match(const DeviceName *devnam, const char *ifname) 3749*0Sstevel@tonic-gate { 3750*0Sstevel@tonic-gate int iflen; 3751*0Sstevel@tonic-gate 3752*0Sstevel@tonic-gate if (ifname == NULL) 3753*0Sstevel@tonic-gate return (devnam->o_length == 0); /* "none" */ 3754*0Sstevel@tonic-gate if (*ifname == '\0') 3755*0Sstevel@tonic-gate return (devnam->o_length != 0); /* "any" */ 3756*0Sstevel@tonic-gate iflen = strlen(ifname); 3757*0Sstevel@tonic-gate /* The check for ':' here supports interface aliases. */ 3758*0Sstevel@tonic-gate if (iflen > devnam->o_length || 3759*0Sstevel@tonic-gate (iflen < devnam->o_length && devnam->o_bytes[iflen] != ':')) 3760*0Sstevel@tonic-gate return (B_FALSE); 3761*0Sstevel@tonic-gate return (strncmp(ifname, devnam->o_bytes, iflen) == 0); 3762*0Sstevel@tonic-gate } 3763*0Sstevel@tonic-gate 3764*0Sstevel@tonic-gate /* 3765*0Sstevel@tonic-gate * Match a user-supplied IP address list. The "any" rule matches any 3766*0Sstevel@tonic-gate * non-zero address. The "none" rule matches only the zero address. 3767*0Sstevel@tonic-gate * IPv6 addresses supplied by the user are ignored. If the user 3768*0Sstevel@tonic-gate * supplies a subnet mask, then match routes that are at least that 3769*0Sstevel@tonic-gate * specific (use the user's mask). If the user supplies only an 3770*0Sstevel@tonic-gate * address, then select any routes that would match (use the route's 3771*0Sstevel@tonic-gate * mask). 3772*0Sstevel@tonic-gate */ 3773*0Sstevel@tonic-gate static boolean_t 3774*0Sstevel@tonic-gate v4_addr_match(IpAddress addr, IpAddress mask, const filter_t *fp) 3775*0Sstevel@tonic-gate { 3776*0Sstevel@tonic-gate char **app; 3777*0Sstevel@tonic-gate char *aptr; 3778*0Sstevel@tonic-gate in_addr_t faddr, fmask; 3779*0Sstevel@tonic-gate 3780*0Sstevel@tonic-gate if (fp->u.a.f_address == NULL) { 3781*0Sstevel@tonic-gate if (IN6_IS_ADDR_UNSPECIFIED(&fp->u.a.f_mask)) 3782*0Sstevel@tonic-gate return (addr != INADDR_ANY); /* "any" */ 3783*0Sstevel@tonic-gate else 3784*0Sstevel@tonic-gate return (addr == INADDR_ANY); /* "none" */ 3785*0Sstevel@tonic-gate } 3786*0Sstevel@tonic-gate if (!IN6_IS_V4MASK(fp->u.a.f_mask)) 3787*0Sstevel@tonic-gate return (B_FALSE); 3788*0Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&fp->u.a.f_mask, fmask); 3789*0Sstevel@tonic-gate if (fmask != IP_HOST_MASK) { 3790*0Sstevel@tonic-gate if (fmask > mask) 3791*0Sstevel@tonic-gate return (B_FALSE); 3792*0Sstevel@tonic-gate mask = fmask; 3793*0Sstevel@tonic-gate } 3794*0Sstevel@tonic-gate for (app = fp->u.a.f_address->h_addr_list; (aptr = *app) != NULL; app++) 3795*0Sstevel@tonic-gate /* LINTED: (note 1) */ 3796*0Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED((in6_addr_t *)aptr)) { 3797*0Sstevel@tonic-gate /* LINTED: (note 1) */ 3798*0Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR((in6_addr_t *)aptr, faddr); 3799*0Sstevel@tonic-gate if (((faddr ^ addr) & mask) == 0) 3800*0Sstevel@tonic-gate return (B_TRUE); 3801*0Sstevel@tonic-gate } 3802*0Sstevel@tonic-gate return (B_FALSE); 3803*0Sstevel@tonic-gate } 3804*0Sstevel@tonic-gate 3805*0Sstevel@tonic-gate /* 3806*0Sstevel@tonic-gate * Run through the filter list for an IPv4 MIB2 route entry. If all 3807*0Sstevel@tonic-gate * filters of a given type fail to match, then the route is filtered 3808*0Sstevel@tonic-gate * out (not displayed). If no filter is given or at least one filter 3809*0Sstevel@tonic-gate * of each type matches, then display the route. 3810*0Sstevel@tonic-gate */ 3811*0Sstevel@tonic-gate static boolean_t 3812*0Sstevel@tonic-gate ire_filter_match_v4(mib2_ipRouteEntry_t *rp, uint_t flag_b) 3813*0Sstevel@tonic-gate { 3814*0Sstevel@tonic-gate filter_t *fp; 3815*0Sstevel@tonic-gate int idx; 3816*0Sstevel@tonic-gate 3817*0Sstevel@tonic-gate /* 'for' loop 1: */ 3818*0Sstevel@tonic-gate for (idx = 0; idx < NFILTERKEYS; idx++) 3819*0Sstevel@tonic-gate if ((fp = filters[idx]) != NULL) { 3820*0Sstevel@tonic-gate /* 'for' loop 2: */ 3821*0Sstevel@tonic-gate for (; fp != NULL; fp = fp->f_next) { 3822*0Sstevel@tonic-gate switch (idx) { 3823*0Sstevel@tonic-gate case FK_AF: 3824*0Sstevel@tonic-gate if (fp->u.f_family != AF_INET) 3825*0Sstevel@tonic-gate continue; /* 'for' loop 2 */ 3826*0Sstevel@tonic-gate break; 3827*0Sstevel@tonic-gate case FK_INIF: 3828*0Sstevel@tonic-gate if (!dev_name_match(&rp->ipRouteInfo. 3829*0Sstevel@tonic-gate re_in_ill, fp->u.f_ifname)) 3830*0Sstevel@tonic-gate continue; /* 'for' loop 2 */ 3831*0Sstevel@tonic-gate break; 3832*0Sstevel@tonic-gate case FK_OUTIF: 3833*0Sstevel@tonic-gate if (!dev_name_match(&rp->ipRouteIfIndex, 3834*0Sstevel@tonic-gate fp->u.f_ifname)) 3835*0Sstevel@tonic-gate continue; /* 'for' loop 2 */ 3836*0Sstevel@tonic-gate break; 3837*0Sstevel@tonic-gate case FK_SRC: 3838*0Sstevel@tonic-gate if (!v4_addr_match(rp->ipRouteInfo. 3839*0Sstevel@tonic-gate re_in_src_addr, IP_HOST_MASK, fp)) 3840*0Sstevel@tonic-gate continue; /* 'for' loop 2 */ 3841*0Sstevel@tonic-gate break; 3842*0Sstevel@tonic-gate case FK_DST: 3843*0Sstevel@tonic-gate if (!v4_addr_match(rp->ipRouteDest, 3844*0Sstevel@tonic-gate rp->ipRouteMask, fp)) 3845*0Sstevel@tonic-gate continue; /* 'for' loop 2 */ 3846*0Sstevel@tonic-gate break; 3847*0Sstevel@tonic-gate case FK_FLAGS: 3848*0Sstevel@tonic-gate if ((flag_b & fp->u.f.f_flagset) != 3849*0Sstevel@tonic-gate fp->u.f.f_flagset || 3850*0Sstevel@tonic-gate (flag_b & fp->u.f.f_flagclear)) 3851*0Sstevel@tonic-gate continue; /* 'for' loop 2 */ 3852*0Sstevel@tonic-gate break; 3853*0Sstevel@tonic-gate } 3854*0Sstevel@tonic-gate break; 3855*0Sstevel@tonic-gate } /* 'for' loop 2 ends */ 3856*0Sstevel@tonic-gate if (fp == NULL) 3857*0Sstevel@tonic-gate return (B_FALSE); 3858*0Sstevel@tonic-gate } 3859*0Sstevel@tonic-gate /* 'for' loop 1 ends */ 3860*0Sstevel@tonic-gate return (B_TRUE); 3861*0Sstevel@tonic-gate } 3862*0Sstevel@tonic-gate 3863*0Sstevel@tonic-gate /* 3864*0Sstevel@tonic-gate * Given an IPv4 MIB2 route entry, form the list of flags for the 3865*0Sstevel@tonic-gate * route. 3866*0Sstevel@tonic-gate */ 3867*0Sstevel@tonic-gate static uint_t 3868*0Sstevel@tonic-gate form_v4_route_flags(mib2_ipRouteEntry_t *rp, char *flags) 3869*0Sstevel@tonic-gate { 3870*0Sstevel@tonic-gate uint_t flag_b; 3871*0Sstevel@tonic-gate 3872*0Sstevel@tonic-gate flag_b = FLF_U; 3873*0Sstevel@tonic-gate (void) strcpy(flags, "U"); 3874*0Sstevel@tonic-gate if (rp->ipRouteInfo.re_ire_type == IRE_DEFAULT || 3875*0Sstevel@tonic-gate rp->ipRouteInfo.re_ire_type == IRE_PREFIX || 3876*0Sstevel@tonic-gate rp->ipRouteInfo.re_ire_type == IRE_HOST || 3877*0Sstevel@tonic-gate rp->ipRouteInfo.re_ire_type == IRE_HOST_REDIRECT) { 3878*0Sstevel@tonic-gate (void) strcat(flags, "G"); 3879*0Sstevel@tonic-gate flag_b |= FLF_G; 3880*0Sstevel@tonic-gate } 3881*0Sstevel@tonic-gate if (rp->ipRouteMask == IP_HOST_MASK) { 3882*0Sstevel@tonic-gate (void) strcat(flags, "H"); 3883*0Sstevel@tonic-gate flag_b |= FLF_H; 3884*0Sstevel@tonic-gate } 3885*0Sstevel@tonic-gate if (rp->ipRouteInfo.re_ire_type == IRE_HOST_REDIRECT) { 3886*0Sstevel@tonic-gate (void) strcat(flags, "D"); 3887*0Sstevel@tonic-gate flag_b |= FLF_D; 3888*0Sstevel@tonic-gate } 3889*0Sstevel@tonic-gate if (rp->ipRouteInfo.re_ire_type == IRE_CACHE) { 3890*0Sstevel@tonic-gate /* Address resolution */ 3891*0Sstevel@tonic-gate (void) strcat(flags, "A"); 3892*0Sstevel@tonic-gate flag_b |= FLF_A; 3893*0Sstevel@tonic-gate } 3894*0Sstevel@tonic-gate if (rp->ipRouteInfo.re_ire_type == IRE_BROADCAST) { /* Broadcast */ 3895*0Sstevel@tonic-gate (void) strcat(flags, "B"); 3896*0Sstevel@tonic-gate flag_b |= FLF_B; 3897*0Sstevel@tonic-gate } 3898*0Sstevel@tonic-gate if (rp->ipRouteInfo.re_ire_type == IRE_LOCAL) { /* Local */ 3899*0Sstevel@tonic-gate (void) strcat(flags, "L"); 3900*0Sstevel@tonic-gate flag_b |= FLF_L; 3901*0Sstevel@tonic-gate } 3902*0Sstevel@tonic-gate if (rp->ipRouteInfo.re_flags & RTF_MULTIRT) { 3903*0Sstevel@tonic-gate (void) strcat(flags, "M"); /* Multiroute */ 3904*0Sstevel@tonic-gate flag_b |= FLF_M; 3905*0Sstevel@tonic-gate } 3906*0Sstevel@tonic-gate if (rp->ipRouteInfo.re_flags & RTF_SETSRC) { 3907*0Sstevel@tonic-gate (void) strcat(flags, "S"); /* Setsrc */ 3908*0Sstevel@tonic-gate flag_b |= FLF_S; 3909*0Sstevel@tonic-gate } 3910*0Sstevel@tonic-gate return (flag_b); 3911*0Sstevel@tonic-gate } 3912*0Sstevel@tonic-gate 3913*0Sstevel@tonic-gate static boolean_t 3914*0Sstevel@tonic-gate ire_report_item_v4(mib2_ipRouteEntry_t *rp, boolean_t first) 3915*0Sstevel@tonic-gate { 3916*0Sstevel@tonic-gate char dstbuf[MAXHOSTNAMELEN + 1]; 3917*0Sstevel@tonic-gate char maskbuf[MAXHOSTNAMELEN + 1]; 3918*0Sstevel@tonic-gate char gwbuf[MAXHOSTNAMELEN + 1]; 3919*0Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 3920*0Sstevel@tonic-gate char flags[10]; /* RTF_ flags */ 3921*0Sstevel@tonic-gate uint_t flag_b; 3922*0Sstevel@tonic-gate 3923*0Sstevel@tonic-gate if (rp->ipRouteInfo.re_in_src_addr != 0 || 3924*0Sstevel@tonic-gate rp->ipRouteInfo.re_in_ill.o_length != 0 || 3925*0Sstevel@tonic-gate !(Aflag || (rp->ipRouteInfo.re_ire_type != IRE_CACHE && 3926*0Sstevel@tonic-gate rp->ipRouteInfo.re_ire_type != IRE_BROADCAST && 3927*0Sstevel@tonic-gate rp->ipRouteInfo.re_ire_type != IRE_LOCAL))) { 3928*0Sstevel@tonic-gate return (first); 3929*0Sstevel@tonic-gate } 3930*0Sstevel@tonic-gate 3931*0Sstevel@tonic-gate flag_b = form_v4_route_flags(rp, flags); 3932*0Sstevel@tonic-gate 3933*0Sstevel@tonic-gate if (!ire_filter_match_v4(rp, flag_b)) 3934*0Sstevel@tonic-gate return (first); 3935*0Sstevel@tonic-gate 3936*0Sstevel@tonic-gate if (first) { 3937*0Sstevel@tonic-gate if (Vflag) { 3938*0Sstevel@tonic-gate (void) puts(v4compat ? 3939*0Sstevel@tonic-gate "\nIRE Table:" : 3940*0Sstevel@tonic-gate "\nIRE Table: IPv4"); 3941*0Sstevel@tonic-gate (void) puts(" Destination Mask " 3942*0Sstevel@tonic-gate " Gateway " 3943*0Sstevel@tonic-gate "Device Mxfrg Rtt Ref Flg Out " 3944*0Sstevel@tonic-gate "In/Fwd"); 3945*0Sstevel@tonic-gate (void) puts("-------------------- --------------- " 3946*0Sstevel@tonic-gate "-------------------- " 3947*0Sstevel@tonic-gate "------ ----- ----- --- --- ----- " 3948*0Sstevel@tonic-gate "------"); 3949*0Sstevel@tonic-gate } else { 3950*0Sstevel@tonic-gate (void) puts(v4compat ? 3951*0Sstevel@tonic-gate "\nRouting Table:" : 3952*0Sstevel@tonic-gate "\nRouting Table: IPv4"); 3953*0Sstevel@tonic-gate (void) puts(" Destination " 3954*0Sstevel@tonic-gate " Gateway Flags Ref Use " 3955*0Sstevel@tonic-gate "Interface"); 3956*0Sstevel@tonic-gate (void) puts("-------------------- " 3957*0Sstevel@tonic-gate "-------------------- ----- ----- ------ " 3958*0Sstevel@tonic-gate "---------"); 3959*0Sstevel@tonic-gate } 3960*0Sstevel@tonic-gate first = B_FALSE; 3961*0Sstevel@tonic-gate } 3962*0Sstevel@tonic-gate 3963*0Sstevel@tonic-gate if (flag_b & FLF_H) { 3964*0Sstevel@tonic-gate (void) pr_addr(rp->ipRouteDest, dstbuf, sizeof (dstbuf)); 3965*0Sstevel@tonic-gate } else { 3966*0Sstevel@tonic-gate (void) pr_net(rp->ipRouteDest, rp->ipRouteMask, 3967*0Sstevel@tonic-gate dstbuf, sizeof (dstbuf)); 3968*0Sstevel@tonic-gate } 3969*0Sstevel@tonic-gate if (Vflag) { 3970*0Sstevel@tonic-gate (void) printf("%-20s %-15s %-20s %-6s %5u%c %4u %3u " 3971*0Sstevel@tonic-gate "%-4s%6u%6u\n", 3972*0Sstevel@tonic-gate dstbuf, 3973*0Sstevel@tonic-gate pr_mask(rp->ipRouteMask, maskbuf, sizeof (maskbuf)), 3974*0Sstevel@tonic-gate pr_addrnz(rp->ipRouteNextHop, gwbuf, sizeof (gwbuf)), 3975*0Sstevel@tonic-gate octetstr(&rp->ipRouteIfIndex, 'a', ifname, sizeof (ifname)), 3976*0Sstevel@tonic-gate rp->ipRouteInfo.re_max_frag, 3977*0Sstevel@tonic-gate rp->ipRouteInfo.re_frag_flag ? '*' : ' ', 3978*0Sstevel@tonic-gate rp->ipRouteInfo.re_rtt, 3979*0Sstevel@tonic-gate rp->ipRouteInfo.re_ref, 3980*0Sstevel@tonic-gate flags, 3981*0Sstevel@tonic-gate rp->ipRouteInfo.re_obpkt, 3982*0Sstevel@tonic-gate rp->ipRouteInfo.re_ibpkt); 3983*0Sstevel@tonic-gate } else { 3984*0Sstevel@tonic-gate (void) printf("%-20s %-20s %-5s %4u%7u %s\n", 3985*0Sstevel@tonic-gate dstbuf, 3986*0Sstevel@tonic-gate pr_addrnz(rp->ipRouteNextHop, gwbuf, sizeof (gwbuf)), 3987*0Sstevel@tonic-gate flags, 3988*0Sstevel@tonic-gate rp->ipRouteInfo.re_ref, 3989*0Sstevel@tonic-gate rp->ipRouteInfo.re_obpkt + rp->ipRouteInfo.re_ibpkt, 3990*0Sstevel@tonic-gate octetstr(&rp->ipRouteIfIndex, 'a', 3991*0Sstevel@tonic-gate ifname, sizeof (ifname))); 3992*0Sstevel@tonic-gate } 3993*0Sstevel@tonic-gate return (first); 3994*0Sstevel@tonic-gate } 3995*0Sstevel@tonic-gate 3996*0Sstevel@tonic-gate /* 3997*0Sstevel@tonic-gate * Report a source-specific route. 3998*0Sstevel@tonic-gate */ 3999*0Sstevel@tonic-gate static boolean_t 4000*0Sstevel@tonic-gate ire_report_item_v4src(mib2_ipRouteEntry_t *rp, boolean_t first) 4001*0Sstevel@tonic-gate { 4002*0Sstevel@tonic-gate char dstbuf[MAXHOSTNAMELEN + 1]; 4003*0Sstevel@tonic-gate char srcbuf[MAXHOSTNAMELEN + 1]; 4004*0Sstevel@tonic-gate char gwbuf[MAXHOSTNAMELEN + 1]; 4005*0Sstevel@tonic-gate char inif[LIFNAMSIZ + 1]; 4006*0Sstevel@tonic-gate char outif[LIFNAMSIZ + 1]; 4007*0Sstevel@tonic-gate uint_t flag_b; 4008*0Sstevel@tonic-gate char flags[10]; 4009*0Sstevel@tonic-gate 4010*0Sstevel@tonic-gate /* 4011*0Sstevel@tonic-gate * If this isn't a source specific route, or if it's filtered 4012*0Sstevel@tonic-gate * out, then ignore it. 4013*0Sstevel@tonic-gate */ 4014*0Sstevel@tonic-gate if ((rp->ipRouteInfo.re_in_src_addr == 0 && 4015*0Sstevel@tonic-gate rp->ipRouteInfo.re_in_ill.o_length == 0) || 4016*0Sstevel@tonic-gate !(Aflag || (rp->ipRouteInfo.re_ire_type != IRE_CACHE && 4017*0Sstevel@tonic-gate rp->ipRouteInfo.re_ire_type != IRE_BROADCAST && 4018*0Sstevel@tonic-gate rp->ipRouteInfo.re_ire_type != IRE_LOCAL))) { 4019*0Sstevel@tonic-gate return (first); 4020*0Sstevel@tonic-gate } 4021*0Sstevel@tonic-gate 4022*0Sstevel@tonic-gate flag_b = form_v4_route_flags(rp, flags); 4023*0Sstevel@tonic-gate 4024*0Sstevel@tonic-gate if (!ire_filter_match_v4(rp, flag_b)) 4025*0Sstevel@tonic-gate return (first); 4026*0Sstevel@tonic-gate 4027*0Sstevel@tonic-gate if (first) { 4028*0Sstevel@tonic-gate if (Vflag) { 4029*0Sstevel@tonic-gate (void) printf("\nIRE Table: %sSource-Specific\n", 4030*0Sstevel@tonic-gate v4compat ? "" : "IPv4 "); 4031*0Sstevel@tonic-gate (void) puts(" Destination In If " 4032*0Sstevel@tonic-gate " Source Gateway " 4033*0Sstevel@tonic-gate " Out If Mxfrg Rtt Ref Flg Out In/Fwd"); 4034*0Sstevel@tonic-gate (void) puts("------------------ ----------- " 4035*0Sstevel@tonic-gate "----------------- ----------------- " 4036*0Sstevel@tonic-gate "----------- ----- ----- --- --- ----- ------"); 4037*0Sstevel@tonic-gate } else { 4038*0Sstevel@tonic-gate (void) printf("\nRouting Table: %sSource-Specific\n", 4039*0Sstevel@tonic-gate v4compat ? "" : "IPv4 "); 4040*0Sstevel@tonic-gate (void) puts(" Destination In If " 4041*0Sstevel@tonic-gate " Source Gateway Flags Use " 4042*0Sstevel@tonic-gate " Out If"); 4043*0Sstevel@tonic-gate (void) puts("--------------- -------- " 4044*0Sstevel@tonic-gate "--------------- --------------- ----- ------ " 4045*0Sstevel@tonic-gate "--------"); 4046*0Sstevel@tonic-gate } 4047*0Sstevel@tonic-gate first = B_FALSE; 4048*0Sstevel@tonic-gate } 4049*0Sstevel@tonic-gate 4050*0Sstevel@tonic-gate /* 4051*0Sstevel@tonic-gate * This is special-cased here because the kernel doesn't actually 4052*0Sstevel@tonic-gate * pay any attention to the destination address on mrtun entries. 4053*0Sstevel@tonic-gate * Saying "default" would be misleading, though technically correct. 4054*0Sstevel@tonic-gate */ 4055*0Sstevel@tonic-gate if (rp->ipRouteInfo.re_in_src_addr != 0 && rp->ipRouteDest == 0 && 4056*0Sstevel@tonic-gate rp->ipRouteMask == 0) 4057*0Sstevel@tonic-gate (void) strlcpy(dstbuf, " --", sizeof (dstbuf)); 4058*0Sstevel@tonic-gate else 4059*0Sstevel@tonic-gate (void) pr_netclassless(rp->ipRouteDest, rp->ipRouteMask, 4060*0Sstevel@tonic-gate dstbuf, sizeof (dstbuf)); 4061*0Sstevel@tonic-gate (void) octetstr(&rp->ipRouteInfo.re_in_ill, 'a', inif, sizeof (inif)); 4062*0Sstevel@tonic-gate (void) pr_addrnz(rp->ipRouteInfo.re_in_src_addr, srcbuf, 4063*0Sstevel@tonic-gate sizeof (srcbuf)); 4064*0Sstevel@tonic-gate (void) octetstr(&rp->ipRouteIfIndex, 'a', outif, sizeof (outif)); 4065*0Sstevel@tonic-gate (void) pr_addrnz(rp->ipRouteNextHop, gwbuf, sizeof (gwbuf)); 4066*0Sstevel@tonic-gate if (Vflag) { 4067*0Sstevel@tonic-gate (void) printf("%-18s %-11s %-17s %-17s %-11s %4u%c %5u %3u " 4068*0Sstevel@tonic-gate "%-3s %5u %6u\n", 4069*0Sstevel@tonic-gate dstbuf, inif, srcbuf, gwbuf, outif, 4070*0Sstevel@tonic-gate rp->ipRouteInfo.re_max_frag, 4071*0Sstevel@tonic-gate rp->ipRouteInfo.re_frag_flag ? '*' : ' ', 4072*0Sstevel@tonic-gate rp->ipRouteInfo.re_rtt, rp->ipRouteInfo.re_ref, flags, 4073*0Sstevel@tonic-gate rp->ipRouteInfo.re_obpkt, rp->ipRouteInfo.re_ibpkt); 4074*0Sstevel@tonic-gate } else { 4075*0Sstevel@tonic-gate (void) printf("%-15s %-8s %-15s %-15s %-5s %6u %-8s\n", dstbuf, 4076*0Sstevel@tonic-gate inif, srcbuf, gwbuf, flags, 4077*0Sstevel@tonic-gate rp->ipRouteInfo.re_obpkt + rp->ipRouteInfo.re_ibpkt, 4078*0Sstevel@tonic-gate outif); 4079*0Sstevel@tonic-gate } 4080*0Sstevel@tonic-gate return (first); 4081*0Sstevel@tonic-gate } 4082*0Sstevel@tonic-gate 4083*0Sstevel@tonic-gate /* 4084*0Sstevel@tonic-gate * Match a user-supplied IP address list against an IPv6 route entry. 4085*0Sstevel@tonic-gate * If the user specified "any," then any non-zero address matches. If 4086*0Sstevel@tonic-gate * the user specified "none," then only the zero address matches. If 4087*0Sstevel@tonic-gate * the user specified a subnet mask length, then use that in matching 4088*0Sstevel@tonic-gate * routes (select routes that are at least as specific). If the user 4089*0Sstevel@tonic-gate * specified only an address, then use the route's mask (select routes 4090*0Sstevel@tonic-gate * that would match that address). IPv4 addresses are ignored. 4091*0Sstevel@tonic-gate */ 4092*0Sstevel@tonic-gate static boolean_t 4093*0Sstevel@tonic-gate v6_addr_match(const Ip6Address *addr, int masklen, const filter_t *fp) 4094*0Sstevel@tonic-gate { 4095*0Sstevel@tonic-gate const uint8_t *ucp; 4096*0Sstevel@tonic-gate int fmasklen; 4097*0Sstevel@tonic-gate int i; 4098*0Sstevel@tonic-gate char **app; 4099*0Sstevel@tonic-gate char *aptr; 4100*0Sstevel@tonic-gate 4101*0Sstevel@tonic-gate if (fp->u.a.f_address == NULL) { 4102*0Sstevel@tonic-gate if (IN6_IS_ADDR_UNSPECIFIED(&fp->u.a.f_mask)) /* any */ 4103*0Sstevel@tonic-gate return (!IN6_IS_ADDR_UNSPECIFIED(addr)); 4104*0Sstevel@tonic-gate return (IN6_IS_ADDR_UNSPECIFIED(addr)); /* "none" */ 4105*0Sstevel@tonic-gate } 4106*0Sstevel@tonic-gate fmasklen = 0; 4107*0Sstevel@tonic-gate /* 'for' loop 1a: */ 4108*0Sstevel@tonic-gate for (ucp = fp->u.a.f_mask.s6_addr; 4109*0Sstevel@tonic-gate ucp < fp->u.a.f_mask.s6_addr + sizeof (fp->u.a.f_mask.s6_addr); 4110*0Sstevel@tonic-gate ucp++) { 4111*0Sstevel@tonic-gate if (*ucp != 0xff) { 4112*0Sstevel@tonic-gate if (*ucp != 0) 4113*0Sstevel@tonic-gate fmasklen += 9 - ffs(*ucp); 4114*0Sstevel@tonic-gate break; /* 'for' loop 1a */ 4115*0Sstevel@tonic-gate } 4116*0Sstevel@tonic-gate fmasklen += 8; 4117*0Sstevel@tonic-gate } /* 'for' loop 1a ends */ 4118*0Sstevel@tonic-gate if (fmasklen != IPV6_ABITS) { 4119*0Sstevel@tonic-gate if (fmasklen > masklen) 4120*0Sstevel@tonic-gate return (B_FALSE); 4121*0Sstevel@tonic-gate masklen = fmasklen; 4122*0Sstevel@tonic-gate } 4123*0Sstevel@tonic-gate /* 'for' loop 1b: */ 4124*0Sstevel@tonic-gate for (app = fp->u.a.f_address->h_addr_list; (aptr = *app) != NULL; 4125*0Sstevel@tonic-gate app++) { 4126*0Sstevel@tonic-gate /* LINTED: (note 1) */ 4127*0Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED((in6_addr_t *)aptr)) 4128*0Sstevel@tonic-gate continue; /* 'for' loop 1b */ 4129*0Sstevel@tonic-gate ucp = addr->s6_addr; 4130*0Sstevel@tonic-gate for (i = masklen; i >= 8; i -= 8) 4131*0Sstevel@tonic-gate if (*ucp++ != *aptr++) 4132*0Sstevel@tonic-gate break; /* 'for' loop 1b */ 4133*0Sstevel@tonic-gate if (i == 0 || 4134*0Sstevel@tonic-gate (i < 8 && ((*ucp ^ *aptr) & ~(0xff >> i)) == 0)) 4135*0Sstevel@tonic-gate return (B_TRUE); 4136*0Sstevel@tonic-gate } /* 'for' loop 1b ends */ 4137*0Sstevel@tonic-gate return (B_FALSE); 4138*0Sstevel@tonic-gate } 4139*0Sstevel@tonic-gate 4140*0Sstevel@tonic-gate /* 4141*0Sstevel@tonic-gate * Run through the filter list for an IPv6 MIB2 IRE. For a given 4142*0Sstevel@tonic-gate * type, if there's at least one filter and all filters of that type 4143*0Sstevel@tonic-gate * fail to match, then the route doesn't match and isn't displayed. 4144*0Sstevel@tonic-gate * If at least one matches, or none are specified, for each of the 4145*0Sstevel@tonic-gate * types, then the route is selected and displayed. 4146*0Sstevel@tonic-gate */ 4147*0Sstevel@tonic-gate static boolean_t 4148*0Sstevel@tonic-gate ire_filter_match_v6(mib2_ipv6RouteEntry_t *rp6, uint_t flag_b) 4149*0Sstevel@tonic-gate { 4150*0Sstevel@tonic-gate filter_t *fp; 4151*0Sstevel@tonic-gate int idx; 4152*0Sstevel@tonic-gate 4153*0Sstevel@tonic-gate /* 'for' loop 1: */ 4154*0Sstevel@tonic-gate for (idx = 0; idx < NFILTERKEYS; idx++) 4155*0Sstevel@tonic-gate if ((fp = filters[idx]) != NULL) { 4156*0Sstevel@tonic-gate /* 'for' loop 2: */ 4157*0Sstevel@tonic-gate for (; fp != NULL; fp = fp->f_next) { 4158*0Sstevel@tonic-gate switch (idx) { 4159*0Sstevel@tonic-gate case FK_AF: 4160*0Sstevel@tonic-gate if (fp->u.f_family != AF_INET6) 4161*0Sstevel@tonic-gate /* 'for' loop 2 */ 4162*0Sstevel@tonic-gate continue; 4163*0Sstevel@tonic-gate break; 4164*0Sstevel@tonic-gate case FK_INIF: 4165*0Sstevel@tonic-gate if (fp->u.f_ifname != NULL) 4166*0Sstevel@tonic-gate /* 'for' loop 2 */ 4167*0Sstevel@tonic-gate continue; 4168*0Sstevel@tonic-gate break; 4169*0Sstevel@tonic-gate case FK_OUTIF: 4170*0Sstevel@tonic-gate if (!dev_name_match(&rp6-> 4171*0Sstevel@tonic-gate ipv6RouteIfIndex, fp->u.f_ifname)) 4172*0Sstevel@tonic-gate /* 'for' loop 2 */ 4173*0Sstevel@tonic-gate continue; 4174*0Sstevel@tonic-gate break; 4175*0Sstevel@tonic-gate case FK_SRC: 4176*0Sstevel@tonic-gate if (!v6_addr_match(&rp6->ipv6RouteInfo. 4177*0Sstevel@tonic-gate re_src_addr, IPV6_ABITS, fp)) 4178*0Sstevel@tonic-gate /* 'for' loop 2 */ 4179*0Sstevel@tonic-gate continue; 4180*0Sstevel@tonic-gate break; 4181*0Sstevel@tonic-gate case FK_DST: 4182*0Sstevel@tonic-gate if (!v6_addr_match(&rp6->ipv6RouteDest, 4183*0Sstevel@tonic-gate rp6->ipv6RoutePfxLength, fp)) 4184*0Sstevel@tonic-gate /* 'for' loop 2 */ 4185*0Sstevel@tonic-gate continue; 4186*0Sstevel@tonic-gate break; 4187*0Sstevel@tonic-gate case FK_FLAGS: 4188*0Sstevel@tonic-gate if ((flag_b & fp->u.f.f_flagset) != 4189*0Sstevel@tonic-gate fp->u.f.f_flagset || 4190*0Sstevel@tonic-gate (flag_b & fp->u.f.f_flagclear)) 4191*0Sstevel@tonic-gate /* 'for' loop 2 */ 4192*0Sstevel@tonic-gate continue; 4193*0Sstevel@tonic-gate break; 4194*0Sstevel@tonic-gate } 4195*0Sstevel@tonic-gate break; 4196*0Sstevel@tonic-gate } /* 'for' loop 2 ends */ 4197*0Sstevel@tonic-gate if (fp == NULL) 4198*0Sstevel@tonic-gate return (B_FALSE); 4199*0Sstevel@tonic-gate } 4200*0Sstevel@tonic-gate /* 'for' loop 1 ends */ 4201*0Sstevel@tonic-gate return (B_TRUE); 4202*0Sstevel@tonic-gate } 4203*0Sstevel@tonic-gate 4204*0Sstevel@tonic-gate static boolean_t 4205*0Sstevel@tonic-gate ire_report_item_v6(mib2_ipv6RouteEntry_t *rp6, boolean_t first) 4206*0Sstevel@tonic-gate { 4207*0Sstevel@tonic-gate char dstbuf[MAXHOSTNAMELEN + 1]; 4208*0Sstevel@tonic-gate char gwbuf[MAXHOSTNAMELEN + 1]; 4209*0Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 4210*0Sstevel@tonic-gate char flags[10]; /* RTF_ flags */ 4211*0Sstevel@tonic-gate uint_t flag_b; 4212*0Sstevel@tonic-gate 4213*0Sstevel@tonic-gate if (!(Aflag || (rp6->ipv6RouteInfo.re_ire_type != IRE_CACHE && 4214*0Sstevel@tonic-gate rp6->ipv6RouteInfo.re_ire_type != IRE_LOCAL))) { 4215*0Sstevel@tonic-gate return (first); 4216*0Sstevel@tonic-gate } 4217*0Sstevel@tonic-gate 4218*0Sstevel@tonic-gate flag_b = FLF_U; 4219*0Sstevel@tonic-gate (void) strcpy(flags, "U"); 4220*0Sstevel@tonic-gate if (rp6->ipv6RouteInfo.re_ire_type == IRE_DEFAULT || 4221*0Sstevel@tonic-gate rp6->ipv6RouteInfo.re_ire_type == IRE_PREFIX || 4222*0Sstevel@tonic-gate rp6->ipv6RouteInfo.re_ire_type == IRE_HOST || 4223*0Sstevel@tonic-gate rp6->ipv6RouteInfo.re_ire_type == IRE_HOST_REDIRECT) { 4224*0Sstevel@tonic-gate (void) strcat(flags, "G"); 4225*0Sstevel@tonic-gate flag_b |= FLF_G; 4226*0Sstevel@tonic-gate } 4227*0Sstevel@tonic-gate 4228*0Sstevel@tonic-gate if (rp6->ipv6RoutePfxLength == IPV6_ABITS) { 4229*0Sstevel@tonic-gate (void) strcat(flags, "H"); 4230*0Sstevel@tonic-gate flag_b |= FLF_H; 4231*0Sstevel@tonic-gate } 4232*0Sstevel@tonic-gate 4233*0Sstevel@tonic-gate if (rp6->ipv6RouteInfo.re_ire_type == IRE_HOST_REDIRECT) { 4234*0Sstevel@tonic-gate (void) strcat(flags, "D"); 4235*0Sstevel@tonic-gate flag_b |= FLF_D; 4236*0Sstevel@tonic-gate } 4237*0Sstevel@tonic-gate if (rp6->ipv6RouteInfo.re_ire_type == IRE_CACHE) { 4238*0Sstevel@tonic-gate /* Address resolution */ 4239*0Sstevel@tonic-gate (void) strcat(flags, "A"); 4240*0Sstevel@tonic-gate flag_b |= FLF_A; 4241*0Sstevel@tonic-gate } 4242*0Sstevel@tonic-gate if (rp6->ipv6RouteInfo.re_ire_type == IRE_LOCAL) { /* Local */ 4243*0Sstevel@tonic-gate (void) strcat(flags, "L"); 4244*0Sstevel@tonic-gate flag_b |= FLF_L; 4245*0Sstevel@tonic-gate } 4246*0Sstevel@tonic-gate if (rp6->ipv6RouteInfo.re_flags & RTF_MULTIRT) { 4247*0Sstevel@tonic-gate (void) strcat(flags, "M"); /* Multiroute */ 4248*0Sstevel@tonic-gate flag_b |= FLF_M; 4249*0Sstevel@tonic-gate } 4250*0Sstevel@tonic-gate if (rp6->ipv6RouteInfo.re_flags & RTF_SETSRC) { 4251*0Sstevel@tonic-gate (void) strcat(flags, "S"); /* Setsrc */ 4252*0Sstevel@tonic-gate flag_b |= FLF_S; 4253*0Sstevel@tonic-gate } 4254*0Sstevel@tonic-gate 4255*0Sstevel@tonic-gate if (!ire_filter_match_v6(rp6, flag_b)) 4256*0Sstevel@tonic-gate return (first); 4257*0Sstevel@tonic-gate 4258*0Sstevel@tonic-gate if (first) { 4259*0Sstevel@tonic-gate if (Vflag) { 4260*0Sstevel@tonic-gate (void) puts("\nIRE Table: IPv6"); 4261*0Sstevel@tonic-gate (void) puts(" Destination/Mask " 4262*0Sstevel@tonic-gate " Gateway " 4263*0Sstevel@tonic-gate " If PMTU Rtt Ref Flags Out In/Fwd"); 4264*0Sstevel@tonic-gate (void) puts("--------------------------- " 4265*0Sstevel@tonic-gate "--------------------------- " 4266*0Sstevel@tonic-gate "----- ------ ----- --- ----- ------ ------"); 4267*0Sstevel@tonic-gate } else { 4268*0Sstevel@tonic-gate (void) puts("\nRouting Table: IPv6"); 4269*0Sstevel@tonic-gate (void) puts(" Destination/Mask " 4270*0Sstevel@tonic-gate " Gateway Flags Ref Use " 4271*0Sstevel@tonic-gate " If "); 4272*0Sstevel@tonic-gate (void) puts("--------------------------- " 4273*0Sstevel@tonic-gate "--------------------------- ----- --- ------ " 4274*0Sstevel@tonic-gate "-----"); 4275*0Sstevel@tonic-gate } 4276*0Sstevel@tonic-gate first = B_FALSE; 4277*0Sstevel@tonic-gate } 4278*0Sstevel@tonic-gate 4279*0Sstevel@tonic-gate if (Vflag) { 4280*0Sstevel@tonic-gate (void) printf("%-27s %-27s %-5s %5u%c %5u %3u " 4281*0Sstevel@tonic-gate "%-5s %6u %6u\n", 4282*0Sstevel@tonic-gate pr_prefix6(&rp6->ipv6RouteDest, 4283*0Sstevel@tonic-gate rp6->ipv6RoutePfxLength, dstbuf, sizeof (dstbuf)), 4284*0Sstevel@tonic-gate IN6_IS_ADDR_UNSPECIFIED(&rp6->ipv6RouteNextHop) ? 4285*0Sstevel@tonic-gate " --" : 4286*0Sstevel@tonic-gate pr_addr6(&rp6->ipv6RouteNextHop, gwbuf, sizeof (gwbuf)), 4287*0Sstevel@tonic-gate octetstr(&rp6->ipv6RouteIfIndex, 'a', 4288*0Sstevel@tonic-gate ifname, sizeof (ifname)), 4289*0Sstevel@tonic-gate rp6->ipv6RouteInfo.re_max_frag, 4290*0Sstevel@tonic-gate rp6->ipv6RouteInfo.re_frag_flag ? '*' : ' ', 4291*0Sstevel@tonic-gate rp6->ipv6RouteInfo.re_rtt, 4292*0Sstevel@tonic-gate rp6->ipv6RouteInfo.re_ref, 4293*0Sstevel@tonic-gate flags, 4294*0Sstevel@tonic-gate rp6->ipv6RouteInfo.re_obpkt, 4295*0Sstevel@tonic-gate rp6->ipv6RouteInfo.re_ibpkt); 4296*0Sstevel@tonic-gate } else { 4297*0Sstevel@tonic-gate (void) printf("%-27s %-27s %-5s %3u %6u %-5s\n", 4298*0Sstevel@tonic-gate pr_prefix6(&rp6->ipv6RouteDest, 4299*0Sstevel@tonic-gate rp6->ipv6RoutePfxLength, dstbuf, sizeof (dstbuf)), 4300*0Sstevel@tonic-gate IN6_IS_ADDR_UNSPECIFIED(&rp6->ipv6RouteNextHop) ? 4301*0Sstevel@tonic-gate " --" : 4302*0Sstevel@tonic-gate pr_addr6(&rp6->ipv6RouteNextHop, gwbuf, sizeof (gwbuf)), 4303*0Sstevel@tonic-gate flags, 4304*0Sstevel@tonic-gate rp6->ipv6RouteInfo.re_ref, 4305*0Sstevel@tonic-gate rp6->ipv6RouteInfo.re_obpkt + rp6->ipv6RouteInfo.re_ibpkt, 4306*0Sstevel@tonic-gate octetstr(&rp6->ipv6RouteIfIndex, 'a', 4307*0Sstevel@tonic-gate ifname, sizeof (ifname))); 4308*0Sstevel@tonic-gate } 4309*0Sstevel@tonic-gate return (first); 4310*0Sstevel@tonic-gate } 4311*0Sstevel@tonic-gate 4312*0Sstevel@tonic-gate /* ------------------------------ TCP_REPORT------------------------------- */ 4313*0Sstevel@tonic-gate 4314*0Sstevel@tonic-gate static const char tcp_hdr_v4[] = 4315*0Sstevel@tonic-gate "\nTCP: IPv4\n"; 4316*0Sstevel@tonic-gate static const char tcp_hdr_v4_compat[] = 4317*0Sstevel@tonic-gate "\nTCP\n"; 4318*0Sstevel@tonic-gate static const char tcp_hdr_v4_verbose[] = 4319*0Sstevel@tonic-gate "Local/Remote Address Swind Snext Suna Rwind Rnext Rack " 4320*0Sstevel@tonic-gate " Rto Mss State\n" 4321*0Sstevel@tonic-gate "-------------------- ----- -------- -------- ----- -------- -------- " 4322*0Sstevel@tonic-gate "----- ----- -----\n"; 4323*0Sstevel@tonic-gate static const char tcp_hdr_v4_normal[] = 4324*0Sstevel@tonic-gate " Local Address Remote Address Swind Send-Q Rwind Recv-Q State\n" 4325*0Sstevel@tonic-gate "-------------------- -------------------- ----- ------ ----- ------ -------\n"; 4326*0Sstevel@tonic-gate 4327*0Sstevel@tonic-gate static const char tcp_hdr_v6[] = 4328*0Sstevel@tonic-gate "\nTCP: IPv6\n"; 4329*0Sstevel@tonic-gate static const char tcp_hdr_v6_verbose[] = 4330*0Sstevel@tonic-gate "Local/Remote Address Swind Snext Suna Rwind Rnext " 4331*0Sstevel@tonic-gate " Rack Rto Mss State If \n" 4332*0Sstevel@tonic-gate "--------------------------------- ----- -------- -------- ----- -------- " 4333*0Sstevel@tonic-gate "-------- ----- ----- ----------- -----\n"; 4334*0Sstevel@tonic-gate static const char tcp_hdr_v6_normal[] = 4335*0Sstevel@tonic-gate " Local Address Remote Address " 4336*0Sstevel@tonic-gate "Swind Send-Q Rwind Recv-Q State If \n" 4337*0Sstevel@tonic-gate "--------------------------------- --------------------------------- " 4338*0Sstevel@tonic-gate "----- ------ ----- ------ ----------- -----\n"; 4339*0Sstevel@tonic-gate 4340*0Sstevel@tonic-gate static boolean_t tcp_report_item_v4(mib2_tcpConnEntry_t *tp, boolean_t first); 4341*0Sstevel@tonic-gate static boolean_t tcp_report_item_v6(mib2_tcp6ConnEntry_t *tp6, boolean_t first); 4342*0Sstevel@tonic-gate 4343*0Sstevel@tonic-gate static void 4344*0Sstevel@tonic-gate tcp_report(mib_item_t *item) 4345*0Sstevel@tonic-gate { 4346*0Sstevel@tonic-gate int jtemp = 0; 4347*0Sstevel@tonic-gate boolean_t print_hdr_once_v4 = B_TRUE; 4348*0Sstevel@tonic-gate boolean_t print_hdr_once_v6 = B_TRUE; 4349*0Sstevel@tonic-gate mib2_tcpConnEntry_t *tp; 4350*0Sstevel@tonic-gate mib2_tcp6ConnEntry_t *tp6; 4351*0Sstevel@tonic-gate 4352*0Sstevel@tonic-gate if (!protocol_selected(IPPROTO_TCP)) 4353*0Sstevel@tonic-gate return; 4354*0Sstevel@tonic-gate 4355*0Sstevel@tonic-gate /* 'for' loop 1: */ 4356*0Sstevel@tonic-gate for (; item; item = item->next_item) { 4357*0Sstevel@tonic-gate if (Dflag) { 4358*0Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp); 4359*0Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, " 4360*0Sstevel@tonic-gate "length = %d, valp = 0x%p\n", 4361*0Sstevel@tonic-gate item->group, item->mib_id, 4362*0Sstevel@tonic-gate item->length, item->valp); 4363*0Sstevel@tonic-gate } 4364*0Sstevel@tonic-gate 4365*0Sstevel@tonic-gate if (!((item->group == MIB2_TCP && 4366*0Sstevel@tonic-gate item->mib_id == MIB2_TCP_CONN) || 4367*0Sstevel@tonic-gate (item->group == MIB2_TCP6 && 4368*0Sstevel@tonic-gate item->mib_id == MIB2_TCP6_CONN))) 4369*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 4370*0Sstevel@tonic-gate 4371*0Sstevel@tonic-gate if (item->group == MIB2_TCP && !family_selected(AF_INET)) 4372*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 4373*0Sstevel@tonic-gate else if (item->group == MIB2_TCP6 && !family_selected(AF_INET6)) 4374*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 4375*0Sstevel@tonic-gate 4376*0Sstevel@tonic-gate if (item->group == MIB2_TCP) { 4377*0Sstevel@tonic-gate for (tp = (mib2_tcpConnEntry_t *)item->valp; 4378*0Sstevel@tonic-gate (char *)tp < (char *)item->valp + item->length; 4379*0Sstevel@tonic-gate /* LINTED: (note 1) */ 4380*0Sstevel@tonic-gate tp = (mib2_tcpConnEntry_t *)((char *)tp + 4381*0Sstevel@tonic-gate tcpConnEntrySize)) { 4382*0Sstevel@tonic-gate print_hdr_once_v4 = tcp_report_item_v4(tp, 4383*0Sstevel@tonic-gate print_hdr_once_v4); 4384*0Sstevel@tonic-gate } 4385*0Sstevel@tonic-gate } else { 4386*0Sstevel@tonic-gate for (tp6 = (mib2_tcp6ConnEntry_t *)item->valp; 4387*0Sstevel@tonic-gate (char *)tp6 < (char *)item->valp + item->length; 4388*0Sstevel@tonic-gate /* LINTED: (note 1) */ 4389*0Sstevel@tonic-gate tp6 = (mib2_tcp6ConnEntry_t *)((char *)tp6 + 4390*0Sstevel@tonic-gate tcp6ConnEntrySize)) { 4391*0Sstevel@tonic-gate print_hdr_once_v6 = tcp_report_item_v6(tp6, 4392*0Sstevel@tonic-gate print_hdr_once_v6); 4393*0Sstevel@tonic-gate } 4394*0Sstevel@tonic-gate } 4395*0Sstevel@tonic-gate } /* 'for' loop 1 ends */ 4396*0Sstevel@tonic-gate (void) fflush(stdout); 4397*0Sstevel@tonic-gate } 4398*0Sstevel@tonic-gate 4399*0Sstevel@tonic-gate static boolean_t 4400*0Sstevel@tonic-gate tcp_report_item_v4(mib2_tcpConnEntry_t *tp, boolean_t first) 4401*0Sstevel@tonic-gate { 4402*0Sstevel@tonic-gate /* 4403*0Sstevel@tonic-gate * lname and fname below are for the hostname as well as the portname 4404*0Sstevel@tonic-gate * There is no limit on portname length so we assume MAXHOSTNAMELEN 4405*0Sstevel@tonic-gate * as the limit 4406*0Sstevel@tonic-gate */ 4407*0Sstevel@tonic-gate char lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1]; 4408*0Sstevel@tonic-gate char fname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1]; 4409*0Sstevel@tonic-gate 4410*0Sstevel@tonic-gate if (!(Aflag || tp->tcpConnEntryInfo.ce_state >= TCPS_ESTABLISHED)) 4411*0Sstevel@tonic-gate return (first); /* Nothing to print */ 4412*0Sstevel@tonic-gate 4413*0Sstevel@tonic-gate if (first) { 4414*0Sstevel@tonic-gate (void) fputs(v4compat ? tcp_hdr_v4_compat : tcp_hdr_v4, stdout); 4415*0Sstevel@tonic-gate (void) fputs(Vflag ? tcp_hdr_v4_verbose : tcp_hdr_v4_normal, 4416*0Sstevel@tonic-gate stdout); 4417*0Sstevel@tonic-gate first = B_FALSE; 4418*0Sstevel@tonic-gate } 4419*0Sstevel@tonic-gate 4420*0Sstevel@tonic-gate if (Vflag) { 4421*0Sstevel@tonic-gate (void) printf("%-20s\n%-20s %5u %08x %08x %5u %08x %08x " 4422*0Sstevel@tonic-gate "%5u %5u %s\n", 4423*0Sstevel@tonic-gate pr_ap(tp->tcpConnLocalAddress, 4424*0Sstevel@tonic-gate tp->tcpConnLocalPort, "tcp", lname, sizeof (lname)), 4425*0Sstevel@tonic-gate pr_ap(tp->tcpConnRemAddress, 4426*0Sstevel@tonic-gate tp->tcpConnRemPort, "tcp", fname, sizeof (fname)), 4427*0Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_swnd, 4428*0Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_snxt, 4429*0Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_suna, 4430*0Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_rwnd, 4431*0Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_rnxt, 4432*0Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_rack, 4433*0Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_rto, 4434*0Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_mss, 4435*0Sstevel@tonic-gate mitcp_state(tp->tcpConnEntryInfo.ce_state)); 4436*0Sstevel@tonic-gate } else { 4437*0Sstevel@tonic-gate int sq = (int)tp->tcpConnEntryInfo.ce_snxt - 4438*0Sstevel@tonic-gate (int)tp->tcpConnEntryInfo.ce_suna - 1; 4439*0Sstevel@tonic-gate int rq = (int)tp->tcpConnEntryInfo.ce_rnxt - 4440*0Sstevel@tonic-gate (int)tp->tcpConnEntryInfo.ce_rack; 4441*0Sstevel@tonic-gate 4442*0Sstevel@tonic-gate (void) printf("%-20s %-20s %5u %6d %5u %6d %s\n", 4443*0Sstevel@tonic-gate pr_ap(tp->tcpConnLocalAddress, 4444*0Sstevel@tonic-gate tp->tcpConnLocalPort, "tcp", lname, sizeof (lname)), 4445*0Sstevel@tonic-gate pr_ap(tp->tcpConnRemAddress, 4446*0Sstevel@tonic-gate tp->tcpConnRemPort, "tcp", fname, sizeof (fname)), 4447*0Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_swnd, 4448*0Sstevel@tonic-gate (sq >= 0) ? sq : 0, 4449*0Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_rwnd, 4450*0Sstevel@tonic-gate (rq >= 0) ? rq : 0, 4451*0Sstevel@tonic-gate mitcp_state(tp->tcpConnEntryInfo.ce_state)); 4452*0Sstevel@tonic-gate } 4453*0Sstevel@tonic-gate return (first); 4454*0Sstevel@tonic-gate } 4455*0Sstevel@tonic-gate 4456*0Sstevel@tonic-gate static boolean_t 4457*0Sstevel@tonic-gate tcp_report_item_v6(mib2_tcp6ConnEntry_t *tp6, boolean_t first) 4458*0Sstevel@tonic-gate { 4459*0Sstevel@tonic-gate /* 4460*0Sstevel@tonic-gate * lname and fname below are for the hostname as well as the portname 4461*0Sstevel@tonic-gate * There is no limit on portname length so we assume MAXHOSTNAMELEN 4462*0Sstevel@tonic-gate * as the limit 4463*0Sstevel@tonic-gate */ 4464*0Sstevel@tonic-gate char lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1]; 4465*0Sstevel@tonic-gate char fname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1]; 4466*0Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 4467*0Sstevel@tonic-gate char *ifnamep; 4468*0Sstevel@tonic-gate 4469*0Sstevel@tonic-gate if (!(Aflag || tp6->tcp6ConnEntryInfo.ce_state >= TCPS_ESTABLISHED)) 4470*0Sstevel@tonic-gate return (first); /* Nothing to print */ 4471*0Sstevel@tonic-gate 4472*0Sstevel@tonic-gate if (first) { 4473*0Sstevel@tonic-gate (void) fputs(tcp_hdr_v6, stdout); 4474*0Sstevel@tonic-gate (void) fputs(Vflag ? tcp_hdr_v6_verbose : tcp_hdr_v6_normal, 4475*0Sstevel@tonic-gate stdout); 4476*0Sstevel@tonic-gate first = B_FALSE; 4477*0Sstevel@tonic-gate } 4478*0Sstevel@tonic-gate 4479*0Sstevel@tonic-gate ifnamep = (tp6->tcp6ConnIfIndex != 0) ? 4480*0Sstevel@tonic-gate if_indextoname(tp6->tcp6ConnIfIndex, ifname) : NULL; 4481*0Sstevel@tonic-gate 4482*0Sstevel@tonic-gate if (Vflag) { 4483*0Sstevel@tonic-gate (void) printf("%-33s\n%-33s %5u %08x %08x %5u %08x %08x " 4484*0Sstevel@tonic-gate "%5u %5u %-11s %-5s\n", 4485*0Sstevel@tonic-gate pr_ap6(&tp6->tcp6ConnLocalAddress, 4486*0Sstevel@tonic-gate tp6->tcp6ConnLocalPort, "tcp", lname, sizeof (lname)), 4487*0Sstevel@tonic-gate pr_ap6(&tp6->tcp6ConnRemAddress, 4488*0Sstevel@tonic-gate tp6->tcp6ConnRemPort, "tcp", fname, sizeof (fname)), 4489*0Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_swnd, 4490*0Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_snxt, 4491*0Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_suna, 4492*0Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_rwnd, 4493*0Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_rnxt, 4494*0Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_rack, 4495*0Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_rto, 4496*0Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_mss, 4497*0Sstevel@tonic-gate mitcp_state(tp6->tcp6ConnEntryInfo.ce_state), 4498*0Sstevel@tonic-gate (ifnamep == NULL) ? "" : ifnamep); 4499*0Sstevel@tonic-gate } else { 4500*0Sstevel@tonic-gate int sq = (int)tp6->tcp6ConnEntryInfo.ce_snxt - 4501*0Sstevel@tonic-gate (int)tp6->tcp6ConnEntryInfo.ce_suna - 1; 4502*0Sstevel@tonic-gate int rq = (int)tp6->tcp6ConnEntryInfo.ce_rnxt - 4503*0Sstevel@tonic-gate (int)tp6->tcp6ConnEntryInfo.ce_rack; 4504*0Sstevel@tonic-gate 4505*0Sstevel@tonic-gate (void) printf("%-33s %-33s %5u %6d %5u %6d %-11s %-5s\n", 4506*0Sstevel@tonic-gate pr_ap6(&tp6->tcp6ConnLocalAddress, 4507*0Sstevel@tonic-gate tp6->tcp6ConnLocalPort, "tcp", lname, sizeof (lname)), 4508*0Sstevel@tonic-gate pr_ap6(&tp6->tcp6ConnRemAddress, 4509*0Sstevel@tonic-gate tp6->tcp6ConnRemPort, "tcp", fname, sizeof (fname)), 4510*0Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_swnd, 4511*0Sstevel@tonic-gate (sq >= 0) ? sq : 0, 4512*0Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_rwnd, 4513*0Sstevel@tonic-gate (rq >= 0) ? rq : 0, 4514*0Sstevel@tonic-gate mitcp_state(tp6->tcp6ConnEntryInfo.ce_state), 4515*0Sstevel@tonic-gate (ifnamep == NULL) ? "" : ifnamep); 4516*0Sstevel@tonic-gate } 4517*0Sstevel@tonic-gate return (first); 4518*0Sstevel@tonic-gate } 4519*0Sstevel@tonic-gate 4520*0Sstevel@tonic-gate /* ------------------------------- UDP_REPORT------------------------------- */ 4521*0Sstevel@tonic-gate 4522*0Sstevel@tonic-gate static boolean_t udp_report_item_v4(mib2_udpEntry_t *ude, boolean_t first); 4523*0Sstevel@tonic-gate static boolean_t udp_report_item_v6(mib2_udp6Entry_t *ude6, boolean_t first); 4524*0Sstevel@tonic-gate 4525*0Sstevel@tonic-gate static char *udp_hdr_v6 = 4526*0Sstevel@tonic-gate " Local Address Remote Address " 4527*0Sstevel@tonic-gate " State If \n" 4528*0Sstevel@tonic-gate "--------------------------------- --------------------------------- " 4529*0Sstevel@tonic-gate "---------- -----\n"; 4530*0Sstevel@tonic-gate 4531*0Sstevel@tonic-gate static void 4532*0Sstevel@tonic-gate udp_report(mib_item_t *item) 4533*0Sstevel@tonic-gate { 4534*0Sstevel@tonic-gate int jtemp = 0; 4535*0Sstevel@tonic-gate boolean_t print_hdr_once_v4 = B_TRUE; 4536*0Sstevel@tonic-gate boolean_t print_hdr_once_v6 = B_TRUE; 4537*0Sstevel@tonic-gate mib2_udpEntry_t *ude; 4538*0Sstevel@tonic-gate mib2_udp6Entry_t *ude6; 4539*0Sstevel@tonic-gate 4540*0Sstevel@tonic-gate if (!protocol_selected(IPPROTO_UDP)) 4541*0Sstevel@tonic-gate return; 4542*0Sstevel@tonic-gate 4543*0Sstevel@tonic-gate /* 'for' loop 1: */ 4544*0Sstevel@tonic-gate for (; item; item = item->next_item) { 4545*0Sstevel@tonic-gate if (Dflag) { 4546*0Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp); 4547*0Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, " 4548*0Sstevel@tonic-gate "length = %d, valp = 0x%p\n", 4549*0Sstevel@tonic-gate item->group, item->mib_id, 4550*0Sstevel@tonic-gate item->length, item->valp); 4551*0Sstevel@tonic-gate } 4552*0Sstevel@tonic-gate if (!((item->group == MIB2_UDP && 4553*0Sstevel@tonic-gate item->mib_id == MIB2_UDP_ENTRY) || 4554*0Sstevel@tonic-gate (item->group == MIB2_UDP6 && 4555*0Sstevel@tonic-gate item->mib_id == MIB2_UDP6_ENTRY))) 4556*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 4557*0Sstevel@tonic-gate 4558*0Sstevel@tonic-gate if (item->group == MIB2_UDP && !family_selected(AF_INET)) 4559*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 4560*0Sstevel@tonic-gate else if (item->group == MIB2_UDP6 && !family_selected(AF_INET6)) 4561*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 4562*0Sstevel@tonic-gate 4563*0Sstevel@tonic-gate /* xxx.xxx.xxx.xxx,pppp sss... */ 4564*0Sstevel@tonic-gate if (item->group == MIB2_UDP) { 4565*0Sstevel@tonic-gate for (ude = (mib2_udpEntry_t *)item->valp; 4566*0Sstevel@tonic-gate (char *)ude < (char *)item->valp + item->length; 4567*0Sstevel@tonic-gate /* LINTED: (note 1) */ 4568*0Sstevel@tonic-gate ude = (mib2_udpEntry_t *)((char *)ude + 4569*0Sstevel@tonic-gate udpEntrySize)) { 4570*0Sstevel@tonic-gate print_hdr_once_v4 = udp_report_item_v4(ude, 4571*0Sstevel@tonic-gate print_hdr_once_v4); 4572*0Sstevel@tonic-gate } 4573*0Sstevel@tonic-gate } else { 4574*0Sstevel@tonic-gate for (ude6 = (mib2_udp6Entry_t *)item->valp; 4575*0Sstevel@tonic-gate (char *)ude6 < (char *)item->valp + item->length; 4576*0Sstevel@tonic-gate /* LINTED: (note 1) */ 4577*0Sstevel@tonic-gate ude6 = (mib2_udp6Entry_t *)((char *)ude6 + 4578*0Sstevel@tonic-gate udp6EntrySize)) { 4579*0Sstevel@tonic-gate print_hdr_once_v6 = udp_report_item_v6(ude6, 4580*0Sstevel@tonic-gate print_hdr_once_v6); 4581*0Sstevel@tonic-gate } 4582*0Sstevel@tonic-gate } 4583*0Sstevel@tonic-gate } /* 'for' loop 1 ends */ 4584*0Sstevel@tonic-gate (void) fflush(stdout); 4585*0Sstevel@tonic-gate } 4586*0Sstevel@tonic-gate 4587*0Sstevel@tonic-gate static boolean_t 4588*0Sstevel@tonic-gate udp_report_item_v4(mib2_udpEntry_t *ude, boolean_t first) 4589*0Sstevel@tonic-gate { 4590*0Sstevel@tonic-gate char lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1]; 4591*0Sstevel@tonic-gate /* hostname + portname */ 4592*0Sstevel@tonic-gate char *cp; 4593*0Sstevel@tonic-gate 4594*0Sstevel@tonic-gate if (!(Aflag || ude->udpEntryInfo.ue_state >= MIB2_UDP_connected)) 4595*0Sstevel@tonic-gate return (first); /* Nothing to print */ 4596*0Sstevel@tonic-gate 4597*0Sstevel@tonic-gate if (first) { 4598*0Sstevel@tonic-gate (void) puts(v4compat ? "\nUDP" : "\nUDP: IPv4"); 4599*0Sstevel@tonic-gate (void) puts( 4600*0Sstevel@tonic-gate " Local Address Remote Address State"); 4601*0Sstevel@tonic-gate (void) puts( 4602*0Sstevel@tonic-gate "-------------------- -------------------- -------"); 4603*0Sstevel@tonic-gate first = B_FALSE; 4604*0Sstevel@tonic-gate } 4605*0Sstevel@tonic-gate 4606*0Sstevel@tonic-gate switch (ude->udpEntryInfo.ue_state) { 4607*0Sstevel@tonic-gate case MIB2_UDP_unbound: 4608*0Sstevel@tonic-gate cp = "Unbound"; 4609*0Sstevel@tonic-gate break; 4610*0Sstevel@tonic-gate case MIB2_UDP_idle: 4611*0Sstevel@tonic-gate cp = "Idle"; 4612*0Sstevel@tonic-gate break; 4613*0Sstevel@tonic-gate case MIB2_UDP_connected: 4614*0Sstevel@tonic-gate cp = "Connected"; 4615*0Sstevel@tonic-gate break; 4616*0Sstevel@tonic-gate default: 4617*0Sstevel@tonic-gate cp = "Unknown"; 4618*0Sstevel@tonic-gate break; 4619*0Sstevel@tonic-gate } 4620*0Sstevel@tonic-gate (void) printf("%-20s ", 4621*0Sstevel@tonic-gate pr_ap(ude->udpLocalAddress, ude->udpLocalPort, "udp", 4622*0Sstevel@tonic-gate lname, sizeof (lname))); 4623*0Sstevel@tonic-gate if (ude->udpEntryInfo.ue_state == MIB2_UDP_connected) { 4624*0Sstevel@tonic-gate (void) printf("%-20s ", 4625*0Sstevel@tonic-gate pr_ap(ude->udpEntryInfo.ue_RemoteAddress, 4626*0Sstevel@tonic-gate ude->udpEntryInfo.ue_RemotePort, "udp", 4627*0Sstevel@tonic-gate lname, sizeof (lname))); 4628*0Sstevel@tonic-gate } else { 4629*0Sstevel@tonic-gate (void) printf("%-20s ", ""); 4630*0Sstevel@tonic-gate } 4631*0Sstevel@tonic-gate (void) printf(" %s\n", cp); 4632*0Sstevel@tonic-gate return (first); 4633*0Sstevel@tonic-gate } 4634*0Sstevel@tonic-gate 4635*0Sstevel@tonic-gate static boolean_t 4636*0Sstevel@tonic-gate udp_report_item_v6(mib2_udp6Entry_t *ude6, boolean_t first) 4637*0Sstevel@tonic-gate { 4638*0Sstevel@tonic-gate char lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1]; 4639*0Sstevel@tonic-gate /* hostname + portname */ 4640*0Sstevel@tonic-gate char *cp; 4641*0Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 4642*0Sstevel@tonic-gate 4643*0Sstevel@tonic-gate if (!(Aflag || ude6->udp6EntryInfo.ue_state >= MIB2_UDP_connected)) 4644*0Sstevel@tonic-gate return (first); /* Nothing to print */ 4645*0Sstevel@tonic-gate 4646*0Sstevel@tonic-gate if (first) { 4647*0Sstevel@tonic-gate (void) printf("\nUDP: IPv6\n%s", udp_hdr_v6); 4648*0Sstevel@tonic-gate first = B_FALSE; 4649*0Sstevel@tonic-gate } 4650*0Sstevel@tonic-gate 4651*0Sstevel@tonic-gate switch (ude6->udp6EntryInfo.ue_state) { 4652*0Sstevel@tonic-gate case MIB2_UDP_unbound: 4653*0Sstevel@tonic-gate cp = "Unbound"; 4654*0Sstevel@tonic-gate break; 4655*0Sstevel@tonic-gate case MIB2_UDP_idle: 4656*0Sstevel@tonic-gate cp = "Idle"; 4657*0Sstevel@tonic-gate break; 4658*0Sstevel@tonic-gate case MIB2_UDP_connected: 4659*0Sstevel@tonic-gate cp = "Connected"; 4660*0Sstevel@tonic-gate break; 4661*0Sstevel@tonic-gate default: 4662*0Sstevel@tonic-gate cp = "Unknown"; 4663*0Sstevel@tonic-gate break; 4664*0Sstevel@tonic-gate } 4665*0Sstevel@tonic-gate (void) printf("%-33s ", 4666*0Sstevel@tonic-gate pr_ap6(&ude6->udp6LocalAddress, 4667*0Sstevel@tonic-gate ude6->udp6LocalPort, "udp", lname, sizeof (lname))); 4668*0Sstevel@tonic-gate if (ude6->udp6EntryInfo.ue_state == MIB2_UDP_connected) { 4669*0Sstevel@tonic-gate (void) printf("%-33s ", 4670*0Sstevel@tonic-gate pr_ap6(&ude6->udp6EntryInfo.ue_RemoteAddress, 4671*0Sstevel@tonic-gate ude6->udp6EntryInfo.ue_RemotePort, "udp", 4672*0Sstevel@tonic-gate lname, sizeof (lname))); 4673*0Sstevel@tonic-gate } else { 4674*0Sstevel@tonic-gate (void) printf("%-33s ", ""); 4675*0Sstevel@tonic-gate } 4676*0Sstevel@tonic-gate if (ude6->udp6IfIndex != 0 && 4677*0Sstevel@tonic-gate (if_indextoname(ude6->udp6IfIndex, ifname) != NULL)) { 4678*0Sstevel@tonic-gate (void) printf("%-10s %-5s\n", cp, ifname); 4679*0Sstevel@tonic-gate } else { 4680*0Sstevel@tonic-gate (void) printf("%-10s\n", cp); 4681*0Sstevel@tonic-gate } 4682*0Sstevel@tonic-gate return (first); 4683*0Sstevel@tonic-gate } 4684*0Sstevel@tonic-gate 4685*0Sstevel@tonic-gate /* ------------------------------ SCTP_REPORT------------------------------- */ 4686*0Sstevel@tonic-gate 4687*0Sstevel@tonic-gate static const char sctp_hdr[] = 4688*0Sstevel@tonic-gate "\nSCTP:"; 4689*0Sstevel@tonic-gate static const char sctp_hdr_normal[] = 4690*0Sstevel@tonic-gate " Local Address Remote Address " 4691*0Sstevel@tonic-gate "Swind Send-Q Rwind Recv-Q StrsI/O State\n" 4692*0Sstevel@tonic-gate "------------------------------- ------------------------------- " 4693*0Sstevel@tonic-gate "------ ------ ------ ------ ------- -----------"; 4694*0Sstevel@tonic-gate 4695*0Sstevel@tonic-gate static const char * 4696*0Sstevel@tonic-gate nssctp_state(int state) 4697*0Sstevel@tonic-gate { 4698*0Sstevel@tonic-gate switch (state) { 4699*0Sstevel@tonic-gate case MIB2_SCTP_closed: 4700*0Sstevel@tonic-gate return ("CLOSED"); 4701*0Sstevel@tonic-gate case MIB2_SCTP_cookieWait: 4702*0Sstevel@tonic-gate return ("COOKIE_WAIT"); 4703*0Sstevel@tonic-gate case MIB2_SCTP_cookieEchoed: 4704*0Sstevel@tonic-gate return ("COOKIE_ECHOED"); 4705*0Sstevel@tonic-gate case MIB2_SCTP_established: 4706*0Sstevel@tonic-gate return ("ESTABLISHED"); 4707*0Sstevel@tonic-gate case MIB2_SCTP_shutdownPending: 4708*0Sstevel@tonic-gate return ("SHUTDOWN_PENDING"); 4709*0Sstevel@tonic-gate case MIB2_SCTP_shutdownSent: 4710*0Sstevel@tonic-gate return ("SHUTDOWN_SENT"); 4711*0Sstevel@tonic-gate case MIB2_SCTP_shutdownReceived: 4712*0Sstevel@tonic-gate return ("SHUTDOWN_RECEIVED"); 4713*0Sstevel@tonic-gate case MIB2_SCTP_shutdownAckSent: 4714*0Sstevel@tonic-gate return ("SHUTDOWN_ACK_SENT"); 4715*0Sstevel@tonic-gate case MIB2_SCTP_listen: 4716*0Sstevel@tonic-gate return ("LISTEN"); 4717*0Sstevel@tonic-gate default: 4718*0Sstevel@tonic-gate return ("UNKNOWN STATE"); 4719*0Sstevel@tonic-gate } 4720*0Sstevel@tonic-gate } 4721*0Sstevel@tonic-gate 4722*0Sstevel@tonic-gate static mib2_sctpConnRemoteEntry_t * 4723*0Sstevel@tonic-gate sctp_getnext_rem(mib_item_t **itemp, mib2_sctpConnRemoteEntry_t *current, 4724*0Sstevel@tonic-gate uint32_t associd) 4725*0Sstevel@tonic-gate { 4726*0Sstevel@tonic-gate mib_item_t *item = *itemp; 4727*0Sstevel@tonic-gate mib2_sctpConnRemoteEntry_t *sre; 4728*0Sstevel@tonic-gate 4729*0Sstevel@tonic-gate for (; item != NULL; item = item->next_item, current = NULL) { 4730*0Sstevel@tonic-gate if (!(item->group == MIB2_SCTP && 4731*0Sstevel@tonic-gate item->mib_id == MIB2_SCTP_CONN_REMOTE)) { 4732*0Sstevel@tonic-gate continue; 4733*0Sstevel@tonic-gate } 4734*0Sstevel@tonic-gate 4735*0Sstevel@tonic-gate if (current != NULL) { 4736*0Sstevel@tonic-gate /* LINTED: (note 1) */ 4737*0Sstevel@tonic-gate sre = (mib2_sctpConnRemoteEntry_t *)((char *)current + 4738*0Sstevel@tonic-gate sctpRemoteEntrySize); 4739*0Sstevel@tonic-gate } else { 4740*0Sstevel@tonic-gate sre = item->valp; 4741*0Sstevel@tonic-gate } 4742*0Sstevel@tonic-gate for (; (char *)sre < (char *)item->valp + item->length; 4743*0Sstevel@tonic-gate /* LINTED: (note 1) */ 4744*0Sstevel@tonic-gate sre = (mib2_sctpConnRemoteEntry_t *)((char *)sre + 4745*0Sstevel@tonic-gate sctpRemoteEntrySize)) { 4746*0Sstevel@tonic-gate if (sre->sctpAssocId != associd) { 4747*0Sstevel@tonic-gate continue; 4748*0Sstevel@tonic-gate } 4749*0Sstevel@tonic-gate *itemp = item; 4750*0Sstevel@tonic-gate return (sre); 4751*0Sstevel@tonic-gate } 4752*0Sstevel@tonic-gate } 4753*0Sstevel@tonic-gate *itemp = NULL; 4754*0Sstevel@tonic-gate return (NULL); 4755*0Sstevel@tonic-gate } 4756*0Sstevel@tonic-gate 4757*0Sstevel@tonic-gate static mib2_sctpConnLocalEntry_t * 4758*0Sstevel@tonic-gate sctp_getnext_local(mib_item_t **itemp, mib2_sctpConnLocalEntry_t *current, 4759*0Sstevel@tonic-gate uint32_t associd) 4760*0Sstevel@tonic-gate { 4761*0Sstevel@tonic-gate mib_item_t *item = *itemp; 4762*0Sstevel@tonic-gate mib2_sctpConnLocalEntry_t *sle; 4763*0Sstevel@tonic-gate 4764*0Sstevel@tonic-gate for (; item != NULL; item = item->next_item, current = NULL) { 4765*0Sstevel@tonic-gate if (!(item->group == MIB2_SCTP && 4766*0Sstevel@tonic-gate item->mib_id == MIB2_SCTP_CONN_LOCAL)) { 4767*0Sstevel@tonic-gate continue; 4768*0Sstevel@tonic-gate } 4769*0Sstevel@tonic-gate 4770*0Sstevel@tonic-gate if (current != NULL) { 4771*0Sstevel@tonic-gate /* LINTED: (note 1) */ 4772*0Sstevel@tonic-gate sle = (mib2_sctpConnLocalEntry_t *)((char *)current + 4773*0Sstevel@tonic-gate sctpLocalEntrySize); 4774*0Sstevel@tonic-gate } else { 4775*0Sstevel@tonic-gate sle = item->valp; 4776*0Sstevel@tonic-gate } 4777*0Sstevel@tonic-gate for (; (char *)sle < (char *)item->valp + item->length; 4778*0Sstevel@tonic-gate /* LINTED: (note 1) */ 4779*0Sstevel@tonic-gate sle = (mib2_sctpConnLocalEntry_t *)((char *)sle + 4780*0Sstevel@tonic-gate sctpLocalEntrySize)) { 4781*0Sstevel@tonic-gate if (sle->sctpAssocId != associd) { 4782*0Sstevel@tonic-gate continue; 4783*0Sstevel@tonic-gate } 4784*0Sstevel@tonic-gate *itemp = item; 4785*0Sstevel@tonic-gate return (sle); 4786*0Sstevel@tonic-gate } 4787*0Sstevel@tonic-gate } 4788*0Sstevel@tonic-gate *itemp = NULL; 4789*0Sstevel@tonic-gate return (NULL); 4790*0Sstevel@tonic-gate } 4791*0Sstevel@tonic-gate 4792*0Sstevel@tonic-gate static void 4793*0Sstevel@tonic-gate sctp_pr_addr(int type, char *name, int namelen, const in6_addr_t *addr, 4794*0Sstevel@tonic-gate int port) 4795*0Sstevel@tonic-gate { 4796*0Sstevel@tonic-gate ipaddr_t v4addr; 4797*0Sstevel@tonic-gate in6_addr_t v6addr; 4798*0Sstevel@tonic-gate 4799*0Sstevel@tonic-gate /* 4800*0Sstevel@tonic-gate * Address is either a v4 mapped or v6 addr. If 4801*0Sstevel@tonic-gate * it's a v4 mapped, convert to v4 before 4802*0Sstevel@tonic-gate * displaying. 4803*0Sstevel@tonic-gate */ 4804*0Sstevel@tonic-gate switch (type) { 4805*0Sstevel@tonic-gate case MIB2_SCTP_ADDR_V4: 4806*0Sstevel@tonic-gate /* v4 */ 4807*0Sstevel@tonic-gate v6addr = *addr; 4808*0Sstevel@tonic-gate 4809*0Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&v6addr, v4addr); 4810*0Sstevel@tonic-gate if (port > 0) { 4811*0Sstevel@tonic-gate (void) pr_ap(v4addr, port, "sctp", name, namelen); 4812*0Sstevel@tonic-gate } else { 4813*0Sstevel@tonic-gate (void) pr_addr(v4addr, name, namelen); 4814*0Sstevel@tonic-gate } 4815*0Sstevel@tonic-gate break; 4816*0Sstevel@tonic-gate 4817*0Sstevel@tonic-gate case MIB2_SCTP_ADDR_V6: 4818*0Sstevel@tonic-gate /* v6 */ 4819*0Sstevel@tonic-gate if (port > 0) { 4820*0Sstevel@tonic-gate (void) pr_ap6(addr, port, "sctp", name, namelen); 4821*0Sstevel@tonic-gate } else { 4822*0Sstevel@tonic-gate (void) pr_addr6(addr, name, namelen); 4823*0Sstevel@tonic-gate } 4824*0Sstevel@tonic-gate break; 4825*0Sstevel@tonic-gate 4826*0Sstevel@tonic-gate default: 4827*0Sstevel@tonic-gate (void) snprintf(name, namelen, "<unknown addr type>"); 4828*0Sstevel@tonic-gate break; 4829*0Sstevel@tonic-gate } 4830*0Sstevel@tonic-gate } 4831*0Sstevel@tonic-gate 4832*0Sstevel@tonic-gate static void 4833*0Sstevel@tonic-gate sctp_conn_report_item(mib_item_t *head, mib2_sctpConnEntry_t *sp) 4834*0Sstevel@tonic-gate { 4835*0Sstevel@tonic-gate char lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1]; 4836*0Sstevel@tonic-gate char fname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1]; 4837*0Sstevel@tonic-gate mib2_sctpConnRemoteEntry_t *sre = NULL; 4838*0Sstevel@tonic-gate mib2_sctpConnLocalEntry_t *sle = NULL; 4839*0Sstevel@tonic-gate mib_item_t *local = head; 4840*0Sstevel@tonic-gate mib_item_t *remote = head; 4841*0Sstevel@tonic-gate uint32_t id = sp->sctpAssocId; 4842*0Sstevel@tonic-gate boolean_t printfirst = B_TRUE; 4843*0Sstevel@tonic-gate 4844*0Sstevel@tonic-gate sctp_pr_addr(sp->sctpAssocRemPrimAddrType, fname, sizeof (fname), 4845*0Sstevel@tonic-gate &sp->sctpAssocRemPrimAddr, sp->sctpAssocRemPort); 4846*0Sstevel@tonic-gate sctp_pr_addr(sp->sctpAssocRemPrimAddrType, lname, sizeof (lname), 4847*0Sstevel@tonic-gate &sp->sctpAssocLocPrimAddr, sp->sctpAssocLocalPort); 4848*0Sstevel@tonic-gate 4849*0Sstevel@tonic-gate (void) printf("%-31s %-31s %6u %6d %6u %6d %3d/%-3d %s\n", 4850*0Sstevel@tonic-gate lname, fname, 4851*0Sstevel@tonic-gate sp->sctpConnEntryInfo.ce_swnd, 4852*0Sstevel@tonic-gate sp->sctpConnEntryInfo.ce_sendq, 4853*0Sstevel@tonic-gate sp->sctpConnEntryInfo.ce_rwnd, 4854*0Sstevel@tonic-gate sp->sctpConnEntryInfo.ce_recvq, 4855*0Sstevel@tonic-gate sp->sctpAssocInStreams, sp->sctpAssocOutStreams, 4856*0Sstevel@tonic-gate nssctp_state(sp->sctpAssocState)); 4857*0Sstevel@tonic-gate 4858*0Sstevel@tonic-gate if (!Vflag) { 4859*0Sstevel@tonic-gate return; 4860*0Sstevel@tonic-gate } 4861*0Sstevel@tonic-gate 4862*0Sstevel@tonic-gate /* Print remote addresses/local addresses on following lines */ 4863*0Sstevel@tonic-gate while ((sre = sctp_getnext_rem(&remote, sre, id)) != NULL) { 4864*0Sstevel@tonic-gate if (!IN6_ARE_ADDR_EQUAL(&sre->sctpAssocRemAddr, 4865*0Sstevel@tonic-gate &sp->sctpAssocRemPrimAddr)) { 4866*0Sstevel@tonic-gate if (printfirst == B_TRUE) { 4867*0Sstevel@tonic-gate (void) fputs("\t<Remote: ", stdout); 4868*0Sstevel@tonic-gate printfirst = B_FALSE; 4869*0Sstevel@tonic-gate } else { 4870*0Sstevel@tonic-gate (void) fputs(", ", stdout); 4871*0Sstevel@tonic-gate } 4872*0Sstevel@tonic-gate sctp_pr_addr(sre->sctpAssocRemAddrType, fname, 4873*0Sstevel@tonic-gate sizeof (fname), &sre->sctpAssocRemAddr, -1); 4874*0Sstevel@tonic-gate if (sre->sctpAssocRemAddrActive == MIB2_SCTP_ACTIVE) { 4875*0Sstevel@tonic-gate (void) fputs(fname, stdout); 4876*0Sstevel@tonic-gate } else { 4877*0Sstevel@tonic-gate (void) printf("(%s)", fname); 4878*0Sstevel@tonic-gate } 4879*0Sstevel@tonic-gate } 4880*0Sstevel@tonic-gate } 4881*0Sstevel@tonic-gate if (printfirst == B_FALSE) { 4882*0Sstevel@tonic-gate (void) puts(">"); 4883*0Sstevel@tonic-gate printfirst = B_TRUE; 4884*0Sstevel@tonic-gate } 4885*0Sstevel@tonic-gate while ((sle = sctp_getnext_local(&local, sle, id)) != NULL) { 4886*0Sstevel@tonic-gate if (!IN6_ARE_ADDR_EQUAL(&sle->sctpAssocLocalAddr, 4887*0Sstevel@tonic-gate &sp->sctpAssocLocPrimAddr)) { 4888*0Sstevel@tonic-gate if (printfirst == B_TRUE) { 4889*0Sstevel@tonic-gate (void) fputs("\t<Local: ", stdout); 4890*0Sstevel@tonic-gate printfirst = B_FALSE; 4891*0Sstevel@tonic-gate } else { 4892*0Sstevel@tonic-gate (void) fputs(", ", stdout); 4893*0Sstevel@tonic-gate } 4894*0Sstevel@tonic-gate sctp_pr_addr(sle->sctpAssocLocalAddrType, lname, 4895*0Sstevel@tonic-gate sizeof (lname), &sle->sctpAssocLocalAddr, -1); 4896*0Sstevel@tonic-gate (void) fputs(lname, stdout); 4897*0Sstevel@tonic-gate } 4898*0Sstevel@tonic-gate } 4899*0Sstevel@tonic-gate if (printfirst == B_FALSE) { 4900*0Sstevel@tonic-gate (void) puts(">"); 4901*0Sstevel@tonic-gate } 4902*0Sstevel@tonic-gate } 4903*0Sstevel@tonic-gate 4904*0Sstevel@tonic-gate static void 4905*0Sstevel@tonic-gate sctp_report(mib_item_t *item) 4906*0Sstevel@tonic-gate { 4907*0Sstevel@tonic-gate mib_item_t *head; 4908*0Sstevel@tonic-gate mib2_sctpConnEntry_t *sp; 4909*0Sstevel@tonic-gate boolean_t first = B_TRUE; 4910*0Sstevel@tonic-gate 4911*0Sstevel@tonic-gate head = item; 4912*0Sstevel@tonic-gate for (; item != NULL; item = item->next_item) { 4913*0Sstevel@tonic-gate 4914*0Sstevel@tonic-gate if (!(item->group == MIB2_SCTP && 4915*0Sstevel@tonic-gate item->mib_id == MIB2_SCTP_CONN)) 4916*0Sstevel@tonic-gate continue; 4917*0Sstevel@tonic-gate 4918*0Sstevel@tonic-gate for (sp = item->valp; 4919*0Sstevel@tonic-gate (char *)sp < (char *)item->valp + item->length; 4920*0Sstevel@tonic-gate /* LINTED: (note 1) */ 4921*0Sstevel@tonic-gate sp = (mib2_sctpConnEntry_t *)((char *)sp + 4922*0Sstevel@tonic-gate sctpEntrySize)) { 4923*0Sstevel@tonic-gate 4924*0Sstevel@tonic-gate if (Aflag || 4925*0Sstevel@tonic-gate sp->sctpAssocState >= MIB2_SCTP_established) { 4926*0Sstevel@tonic-gate if (first == B_TRUE) { 4927*0Sstevel@tonic-gate (void) puts(sctp_hdr); 4928*0Sstevel@tonic-gate (void) puts(sctp_hdr_normal); 4929*0Sstevel@tonic-gate first = B_FALSE; 4930*0Sstevel@tonic-gate } 4931*0Sstevel@tonic-gate sctp_conn_report_item(head, sp); 4932*0Sstevel@tonic-gate } 4933*0Sstevel@tonic-gate } 4934*0Sstevel@tonic-gate } 4935*0Sstevel@tonic-gate } 4936*0Sstevel@tonic-gate 4937*0Sstevel@tonic-gate static char * 4938*0Sstevel@tonic-gate plural(int n) 4939*0Sstevel@tonic-gate { 4940*0Sstevel@tonic-gate return (n != 1 ? "s" : ""); 4941*0Sstevel@tonic-gate } 4942*0Sstevel@tonic-gate 4943*0Sstevel@tonic-gate static char * 4944*0Sstevel@tonic-gate pluraly(int n) 4945*0Sstevel@tonic-gate { 4946*0Sstevel@tonic-gate return (n != 1 ? "ies" : "y"); 4947*0Sstevel@tonic-gate } 4948*0Sstevel@tonic-gate 4949*0Sstevel@tonic-gate static char * 4950*0Sstevel@tonic-gate plurales(int n) 4951*0Sstevel@tonic-gate { 4952*0Sstevel@tonic-gate return (n != 1 ? "es" : ""); 4953*0Sstevel@tonic-gate } 4954*0Sstevel@tonic-gate 4955*0Sstevel@tonic-gate static char * 4956*0Sstevel@tonic-gate pktscale(n) 4957*0Sstevel@tonic-gate int n; 4958*0Sstevel@tonic-gate { 4959*0Sstevel@tonic-gate static char buf[6]; 4960*0Sstevel@tonic-gate char t; 4961*0Sstevel@tonic-gate 4962*0Sstevel@tonic-gate if (n < 1024) { 4963*0Sstevel@tonic-gate t = ' '; 4964*0Sstevel@tonic-gate } else if (n < 1024 * 1024) { 4965*0Sstevel@tonic-gate t = 'k'; 4966*0Sstevel@tonic-gate n /= 1024; 4967*0Sstevel@tonic-gate } else if (n < 1024 * 1024 * 1024) { 4968*0Sstevel@tonic-gate t = 'm'; 4969*0Sstevel@tonic-gate n /= 1024 * 1024; 4970*0Sstevel@tonic-gate } else { 4971*0Sstevel@tonic-gate t = 'g'; 4972*0Sstevel@tonic-gate n /= 1024 * 1024 * 1024; 4973*0Sstevel@tonic-gate } 4974*0Sstevel@tonic-gate 4975*0Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%4u%c", n, t); 4976*0Sstevel@tonic-gate return (buf); 4977*0Sstevel@tonic-gate } 4978*0Sstevel@tonic-gate 4979*0Sstevel@tonic-gate /* --------------------- mrt_report (netstat -m) -------------------------- */ 4980*0Sstevel@tonic-gate 4981*0Sstevel@tonic-gate static void 4982*0Sstevel@tonic-gate mrt_report(mib_item_t *item) 4983*0Sstevel@tonic-gate { 4984*0Sstevel@tonic-gate int jtemp = 0; 4985*0Sstevel@tonic-gate struct vifctl *vip; 4986*0Sstevel@tonic-gate vifi_t vifi; 4987*0Sstevel@tonic-gate struct mfcctl *mfccp; 4988*0Sstevel@tonic-gate int numvifs = 0; 4989*0Sstevel@tonic-gate int nmfc = 0; 4990*0Sstevel@tonic-gate char abuf[MAXHOSTNAMELEN + 1]; 4991*0Sstevel@tonic-gate 4992*0Sstevel@tonic-gate if (!(family_selected(AF_INET))) 4993*0Sstevel@tonic-gate return; 4994*0Sstevel@tonic-gate 4995*0Sstevel@tonic-gate /* 'for' loop 1: */ 4996*0Sstevel@tonic-gate for (; item; item = item->next_item) { 4997*0Sstevel@tonic-gate if (Dflag) { 4998*0Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp); 4999*0Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, " 5000*0Sstevel@tonic-gate "length = %d, valp = 0x%p\n", 5001*0Sstevel@tonic-gate item->group, item->mib_id, item->length, 5002*0Sstevel@tonic-gate item->valp); 5003*0Sstevel@tonic-gate } 5004*0Sstevel@tonic-gate if (item->group != EXPER_DVMRP) 5005*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 5006*0Sstevel@tonic-gate 5007*0Sstevel@tonic-gate switch (item->mib_id) { 5008*0Sstevel@tonic-gate 5009*0Sstevel@tonic-gate case EXPER_DVMRP_VIF: 5010*0Sstevel@tonic-gate if (Dflag) 5011*0Sstevel@tonic-gate (void) printf("%u records for ipVifTable:\n", 5012*0Sstevel@tonic-gate item->length/sizeof (struct vifctl)); 5013*0Sstevel@tonic-gate if (item->length/sizeof (struct vifctl) == 0) { 5014*0Sstevel@tonic-gate (void) puts("\nVirtual Interface Table is " 5015*0Sstevel@tonic-gate "empty"); 5016*0Sstevel@tonic-gate break; 5017*0Sstevel@tonic-gate } 5018*0Sstevel@tonic-gate 5019*0Sstevel@tonic-gate (void) puts("\nVirtual Interface Table\n" 5020*0Sstevel@tonic-gate " Vif Threshold Rate_Limit Local-Address" 5021*0Sstevel@tonic-gate " Remote-Address Pkt_in Pkt_out"); 5022*0Sstevel@tonic-gate 5023*0Sstevel@tonic-gate /* 'for' loop 2: */ 5024*0Sstevel@tonic-gate for (vip = (struct vifctl *)item->valp; 5025*0Sstevel@tonic-gate (char *)vip < (char *)item->valp + item->length; 5026*0Sstevel@tonic-gate /* LINTED: (note 1) */ 5027*0Sstevel@tonic-gate vip = (struct vifctl *)((char *)vip + 5028*0Sstevel@tonic-gate vifctlSize)) { 5029*0Sstevel@tonic-gate if (vip->vifc_lcl_addr.s_addr == 0) 5030*0Sstevel@tonic-gate continue; /* 'for' loop 2 */ 5031*0Sstevel@tonic-gate /* numvifs = vip->vifc_vifi; */ 5032*0Sstevel@tonic-gate 5033*0Sstevel@tonic-gate numvifs++; 5034*0Sstevel@tonic-gate (void) printf(" %2u %3u " 5035*0Sstevel@tonic-gate "%4u %-15.15s", 5036*0Sstevel@tonic-gate vip->vifc_vifi, 5037*0Sstevel@tonic-gate vip->vifc_threshold, 5038*0Sstevel@tonic-gate vip->vifc_rate_limit, 5039*0Sstevel@tonic-gate pr_addr(vip->vifc_lcl_addr.s_addr, 5040*0Sstevel@tonic-gate abuf, sizeof (abuf))); 5041*0Sstevel@tonic-gate (void) printf(" %-15.15s %8u %8u\n", 5042*0Sstevel@tonic-gate (vip->vifc_flags & VIFF_TUNNEL) ? 5043*0Sstevel@tonic-gate pr_addr(vip->vifc_rmt_addr.s_addr, 5044*0Sstevel@tonic-gate abuf, sizeof (abuf)) : "", 5045*0Sstevel@tonic-gate vip->vifc_pkt_in, 5046*0Sstevel@tonic-gate vip->vifc_pkt_out); 5047*0Sstevel@tonic-gate } /* 'for' loop 2 ends */ 5048*0Sstevel@tonic-gate 5049*0Sstevel@tonic-gate (void) printf("Numvifs: %d\n", numvifs); 5050*0Sstevel@tonic-gate break; 5051*0Sstevel@tonic-gate 5052*0Sstevel@tonic-gate case EXPER_DVMRP_MRT: 5053*0Sstevel@tonic-gate if (Dflag) 5054*0Sstevel@tonic-gate (void) printf("%u records for ipMfcTable:\n", 5055*0Sstevel@tonic-gate item->length/sizeof (struct vifctl)); 5056*0Sstevel@tonic-gate if (item->length/sizeof (struct vifctl) == 0) { 5057*0Sstevel@tonic-gate (void) puts("\nMulticast Forwarding Cache is " 5058*0Sstevel@tonic-gate "empty"); 5059*0Sstevel@tonic-gate break; 5060*0Sstevel@tonic-gate } 5061*0Sstevel@tonic-gate 5062*0Sstevel@tonic-gate (void) puts("\nMulticast Forwarding Cache\n" 5063*0Sstevel@tonic-gate " Origin-Subnet Mcastgroup " 5064*0Sstevel@tonic-gate "# Pkts In-Vif Out-vifs/Forw-ttl"); 5065*0Sstevel@tonic-gate 5066*0Sstevel@tonic-gate for (mfccp = (struct mfcctl *)item->valp; 5067*0Sstevel@tonic-gate (char *)mfccp < (char *)item->valp + item->length; 5068*0Sstevel@tonic-gate /* LINTED: (note 1) */ 5069*0Sstevel@tonic-gate mfccp = (struct mfcctl *)((char *)mfccp + 5070*0Sstevel@tonic-gate mfcctlSize)) { 5071*0Sstevel@tonic-gate 5072*0Sstevel@tonic-gate nmfc++; 5073*0Sstevel@tonic-gate (void) printf(" %-30.15s", 5074*0Sstevel@tonic-gate pr_addr(mfccp->mfcc_origin.s_addr, 5075*0Sstevel@tonic-gate abuf, sizeof (abuf))); 5076*0Sstevel@tonic-gate (void) printf("%-15.15s %6s %3u ", 5077*0Sstevel@tonic-gate pr_net(mfccp->mfcc_mcastgrp.s_addr, 5078*0Sstevel@tonic-gate mfccp->mfcc_mcastgrp.s_addr, 5079*0Sstevel@tonic-gate abuf, sizeof (abuf)), 5080*0Sstevel@tonic-gate pktscale((int)mfccp->mfcc_pkt_cnt), 5081*0Sstevel@tonic-gate mfccp->mfcc_parent); 5082*0Sstevel@tonic-gate 5083*0Sstevel@tonic-gate for (vifi = 0; vifi < MAXVIFS; ++vifi) { 5084*0Sstevel@tonic-gate if (mfccp->mfcc_ttls[vifi]) { 5085*0Sstevel@tonic-gate (void) printf(" %u (%u)", 5086*0Sstevel@tonic-gate vifi, 5087*0Sstevel@tonic-gate mfccp->mfcc_ttls[vifi]); 5088*0Sstevel@tonic-gate } 5089*0Sstevel@tonic-gate 5090*0Sstevel@tonic-gate } 5091*0Sstevel@tonic-gate (void) putchar('\n'); 5092*0Sstevel@tonic-gate } 5093*0Sstevel@tonic-gate (void) printf("\nTotal no. of entries in cache: %d\n", 5094*0Sstevel@tonic-gate nmfc); 5095*0Sstevel@tonic-gate break; 5096*0Sstevel@tonic-gate } 5097*0Sstevel@tonic-gate } /* 'for' loop 1 ends */ 5098*0Sstevel@tonic-gate (void) putchar('\n'); 5099*0Sstevel@tonic-gate (void) fflush(stdout); 5100*0Sstevel@tonic-gate } 5101*0Sstevel@tonic-gate 5102*0Sstevel@tonic-gate /* 5103*0Sstevel@tonic-gate * Get the stats for the cache named 'name'. If prefix != 0, then 5104*0Sstevel@tonic-gate * interpret the name as a prefix, and sum up stats for all caches 5105*0Sstevel@tonic-gate * named 'name*'. 5106*0Sstevel@tonic-gate */ 5107*0Sstevel@tonic-gate static void 5108*0Sstevel@tonic-gate kmem_cache_stats(char *title, char *name, int prefix, int64_t *total_bytes) 5109*0Sstevel@tonic-gate { 5110*0Sstevel@tonic-gate int len; 5111*0Sstevel@tonic-gate int alloc; 5112*0Sstevel@tonic-gate int64_t total_alloc = 0; 5113*0Sstevel@tonic-gate int alloc_fail, total_alloc_fail = 0; 5114*0Sstevel@tonic-gate int buf_size = 0; 5115*0Sstevel@tonic-gate int buf_avail; 5116*0Sstevel@tonic-gate int buf_total; 5117*0Sstevel@tonic-gate int buf_max, total_buf_max = 0; 5118*0Sstevel@tonic-gate int buf_inuse, total_buf_inuse = 0; 5119*0Sstevel@tonic-gate kstat_t *ksp; 5120*0Sstevel@tonic-gate char buf[256]; 5121*0Sstevel@tonic-gate 5122*0Sstevel@tonic-gate len = prefix ? strlen(name) : 256; 5123*0Sstevel@tonic-gate 5124*0Sstevel@tonic-gate /* 'for' loop 1: */ 5125*0Sstevel@tonic-gate for (ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next) { 5126*0Sstevel@tonic-gate 5127*0Sstevel@tonic-gate if (strcmp(ksp->ks_class, "kmem_cache") != 0) 5128*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 5129*0Sstevel@tonic-gate 5130*0Sstevel@tonic-gate /* 5131*0Sstevel@tonic-gate * Hack alert: because of the way streams messages are 5132*0Sstevel@tonic-gate * allocated, every constructed free dblk has an associated 5133*0Sstevel@tonic-gate * mblk. From the allocator's viewpoint those mblks are 5134*0Sstevel@tonic-gate * allocated (because they haven't been freed), but from 5135*0Sstevel@tonic-gate * our viewpoint they're actually free (because they're 5136*0Sstevel@tonic-gate * not currently in use). To account for this caching 5137*0Sstevel@tonic-gate * effect we subtract the total constructed free dblks 5138*0Sstevel@tonic-gate * from the total allocated mblks to derive mblks in use. 5139*0Sstevel@tonic-gate */ 5140*0Sstevel@tonic-gate if (strcmp(name, "streams_mblk") == 0 && 5141*0Sstevel@tonic-gate strncmp(ksp->ks_name, "streams_dblk", 12) == 0) { 5142*0Sstevel@tonic-gate (void) safe_kstat_read(kc, ksp, NULL); 5143*0Sstevel@tonic-gate total_buf_inuse -= 5144*0Sstevel@tonic-gate kstat_named_value(ksp, "buf_constructed"); 5145*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 5146*0Sstevel@tonic-gate } 5147*0Sstevel@tonic-gate 5148*0Sstevel@tonic-gate if (strncmp(ksp->ks_name, name, len) != 0) 5149*0Sstevel@tonic-gate continue; /* 'for' loop 1 */ 5150*0Sstevel@tonic-gate 5151*0Sstevel@tonic-gate (void) safe_kstat_read(kc, ksp, NULL); 5152*0Sstevel@tonic-gate 5153*0Sstevel@tonic-gate alloc = kstat_named_value(ksp, "alloc"); 5154*0Sstevel@tonic-gate alloc_fail = kstat_named_value(ksp, "alloc_fail"); 5155*0Sstevel@tonic-gate buf_size = kstat_named_value(ksp, "buf_size"); 5156*0Sstevel@tonic-gate buf_avail = kstat_named_value(ksp, "buf_avail"); 5157*0Sstevel@tonic-gate buf_total = kstat_named_value(ksp, "buf_total"); 5158*0Sstevel@tonic-gate buf_max = kstat_named_value(ksp, "buf_max"); 5159*0Sstevel@tonic-gate buf_inuse = buf_total - buf_avail; 5160*0Sstevel@tonic-gate 5161*0Sstevel@tonic-gate if (Vflag && prefix) { 5162*0Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s%s", title, 5163*0Sstevel@tonic-gate ksp->ks_name + len); 5164*0Sstevel@tonic-gate (void) printf(" %-18s %6u %9u %11u %11u\n", 5165*0Sstevel@tonic-gate buf, buf_inuse, buf_max, alloc, alloc_fail); 5166*0Sstevel@tonic-gate } 5167*0Sstevel@tonic-gate 5168*0Sstevel@tonic-gate total_alloc += alloc; 5169*0Sstevel@tonic-gate total_alloc_fail += alloc_fail; 5170*0Sstevel@tonic-gate total_buf_max += buf_max; 5171*0Sstevel@tonic-gate total_buf_inuse += buf_inuse; 5172*0Sstevel@tonic-gate *total_bytes += (int64_t)buf_inuse * buf_size; 5173*0Sstevel@tonic-gate } /* 'for' loop 1 ends */ 5174*0Sstevel@tonic-gate 5175*0Sstevel@tonic-gate if (buf_size == 0) { 5176*0Sstevel@tonic-gate (void) printf("%-22s [couldn't find statistics for %s]\n", 5177*0Sstevel@tonic-gate title, name); 5178*0Sstevel@tonic-gate return; 5179*0Sstevel@tonic-gate } 5180*0Sstevel@tonic-gate 5181*0Sstevel@tonic-gate if (Vflag && prefix) 5182*0Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s_total", title); 5183*0Sstevel@tonic-gate else 5184*0Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s", title); 5185*0Sstevel@tonic-gate 5186*0Sstevel@tonic-gate (void) printf("%-22s %6d %9d %11lld %11d\n", buf, 5187*0Sstevel@tonic-gate total_buf_inuse, total_buf_max, total_alloc, total_alloc_fail); 5188*0Sstevel@tonic-gate } 5189*0Sstevel@tonic-gate 5190*0Sstevel@tonic-gate static void 5191*0Sstevel@tonic-gate m_report(void) 5192*0Sstevel@tonic-gate { 5193*0Sstevel@tonic-gate int64_t total_bytes = 0; 5194*0Sstevel@tonic-gate 5195*0Sstevel@tonic-gate (void) puts("streams allocation:"); 5196*0Sstevel@tonic-gate (void) printf("%63s\n", "cumulative allocation"); 5197*0Sstevel@tonic-gate (void) printf("%63s\n", 5198*0Sstevel@tonic-gate "current maximum total failures"); 5199*0Sstevel@tonic-gate 5200*0Sstevel@tonic-gate kmem_cache_stats("streams", 5201*0Sstevel@tonic-gate "stream_head_cache", 0, &total_bytes); 5202*0Sstevel@tonic-gate kmem_cache_stats("queues", "queue_cache", 0, &total_bytes); 5203*0Sstevel@tonic-gate kmem_cache_stats("mblk", "streams_mblk", 0, &total_bytes); 5204*0Sstevel@tonic-gate kmem_cache_stats("dblk", "streams_dblk", 1, &total_bytes); 5205*0Sstevel@tonic-gate kmem_cache_stats("linkblk", "linkinfo_cache", 0, &total_bytes); 5206*0Sstevel@tonic-gate kmem_cache_stats("syncq", "syncq_cache", 0, &total_bytes); 5207*0Sstevel@tonic-gate kmem_cache_stats("qband", "qband_cache", 0, &total_bytes); 5208*0Sstevel@tonic-gate 5209*0Sstevel@tonic-gate (void) printf("\n%lld Kbytes allocated for streams data\n", 5210*0Sstevel@tonic-gate total_bytes / 1024); 5211*0Sstevel@tonic-gate 5212*0Sstevel@tonic-gate (void) putchar('\n'); 5213*0Sstevel@tonic-gate (void) fflush(stdout); 5214*0Sstevel@tonic-gate } 5215*0Sstevel@tonic-gate 5216*0Sstevel@tonic-gate /* --------------------------------- */ 5217*0Sstevel@tonic-gate 5218*0Sstevel@tonic-gate /* 5219*0Sstevel@tonic-gate * Print an IPv4 address. Remove the matching part of the domain name 5220*0Sstevel@tonic-gate * from the returned name. 5221*0Sstevel@tonic-gate */ 5222*0Sstevel@tonic-gate static char * 5223*0Sstevel@tonic-gate pr_addr(uint_t addr, char *dst, uint_t dstlen) 5224*0Sstevel@tonic-gate { 5225*0Sstevel@tonic-gate char *cp; 5226*0Sstevel@tonic-gate struct hostent *hp = NULL; 5227*0Sstevel@tonic-gate static char domain[MAXHOSTNAMELEN + 1]; 5228*0Sstevel@tonic-gate static boolean_t first = B_TRUE; 5229*0Sstevel@tonic-gate int error_num; 5230*0Sstevel@tonic-gate 5231*0Sstevel@tonic-gate if (first) { 5232*0Sstevel@tonic-gate first = B_FALSE; 5233*0Sstevel@tonic-gate if (sysinfo(SI_HOSTNAME, domain, MAXHOSTNAMELEN) != -1 && 5234*0Sstevel@tonic-gate (cp = strchr(domain, '.'))) { 5235*0Sstevel@tonic-gate (void) strncpy(domain, cp + 1, sizeof (domain)); 5236*0Sstevel@tonic-gate } else 5237*0Sstevel@tonic-gate domain[0] = 0; 5238*0Sstevel@tonic-gate } 5239*0Sstevel@tonic-gate cp = NULL; 5240*0Sstevel@tonic-gate if (!Nflag) { 5241*0Sstevel@tonic-gate hp = getipnodebyaddr((char *)&addr, sizeof (uint_t), AF_INET, 5242*0Sstevel@tonic-gate &error_num); 5243*0Sstevel@tonic-gate if (hp) { 5244*0Sstevel@tonic-gate if ((cp = strchr(hp->h_name, '.')) != NULL && 5245*0Sstevel@tonic-gate strcasecmp(cp + 1, domain) == 0) 5246*0Sstevel@tonic-gate *cp = 0; 5247*0Sstevel@tonic-gate cp = hp->h_name; 5248*0Sstevel@tonic-gate } 5249*0Sstevel@tonic-gate } 5250*0Sstevel@tonic-gate if (cp != NULL) { 5251*0Sstevel@tonic-gate (void) strncpy(dst, cp, dstlen); 5252*0Sstevel@tonic-gate dst[dstlen - 1] = 0; 5253*0Sstevel@tonic-gate } else { 5254*0Sstevel@tonic-gate (void) inet_ntop(AF_INET, (char *)&addr, dst, dstlen); 5255*0Sstevel@tonic-gate } 5256*0Sstevel@tonic-gate if (hp != NULL) 5257*0Sstevel@tonic-gate freehostent(hp); 5258*0Sstevel@tonic-gate return (dst); 5259*0Sstevel@tonic-gate } 5260*0Sstevel@tonic-gate 5261*0Sstevel@tonic-gate /* 5262*0Sstevel@tonic-gate * Print a non-zero IPv4 address. Print " --" if the address is zero. 5263*0Sstevel@tonic-gate */ 5264*0Sstevel@tonic-gate static char * 5265*0Sstevel@tonic-gate pr_addrnz(ipaddr_t addr, char *dst, uint_t dstlen) 5266*0Sstevel@tonic-gate { 5267*0Sstevel@tonic-gate if (addr == INADDR_ANY) { 5268*0Sstevel@tonic-gate (void) strlcpy(dst, " --", dstlen); 5269*0Sstevel@tonic-gate return (dst); 5270*0Sstevel@tonic-gate } 5271*0Sstevel@tonic-gate return (pr_addr(addr, dst, dstlen)); 5272*0Sstevel@tonic-gate } 5273*0Sstevel@tonic-gate 5274*0Sstevel@tonic-gate /* 5275*0Sstevel@tonic-gate * Print an IPv6 address. Remove the matching part of the domain name 5276*0Sstevel@tonic-gate * from the returned name. 5277*0Sstevel@tonic-gate */ 5278*0Sstevel@tonic-gate static char * 5279*0Sstevel@tonic-gate pr_addr6(const struct in6_addr *addr, char *dst, uint_t dstlen) 5280*0Sstevel@tonic-gate { 5281*0Sstevel@tonic-gate char *cp; 5282*0Sstevel@tonic-gate struct hostent *hp = NULL; 5283*0Sstevel@tonic-gate static char domain[MAXHOSTNAMELEN + 1]; 5284*0Sstevel@tonic-gate static boolean_t first = B_TRUE; 5285*0Sstevel@tonic-gate int error_num; 5286*0Sstevel@tonic-gate 5287*0Sstevel@tonic-gate if (first) { 5288*0Sstevel@tonic-gate first = B_FALSE; 5289*0Sstevel@tonic-gate if (sysinfo(SI_HOSTNAME, domain, MAXHOSTNAMELEN) != -1 && 5290*0Sstevel@tonic-gate (cp = strchr(domain, '.'))) { 5291*0Sstevel@tonic-gate (void) strncpy(domain, cp + 1, sizeof (domain)); 5292*0Sstevel@tonic-gate } else 5293*0Sstevel@tonic-gate domain[0] = 0; 5294*0Sstevel@tonic-gate } 5295*0Sstevel@tonic-gate cp = NULL; 5296*0Sstevel@tonic-gate if (!Nflag) { 5297*0Sstevel@tonic-gate hp = getipnodebyaddr((char *)addr, 5298*0Sstevel@tonic-gate sizeof (struct in6_addr), AF_INET6, &error_num); 5299*0Sstevel@tonic-gate if (hp) { 5300*0Sstevel@tonic-gate if ((cp = strchr(hp->h_name, '.')) != NULL && 5301*0Sstevel@tonic-gate strcasecmp(cp + 1, domain) == 0) 5302*0Sstevel@tonic-gate *cp = 0; 5303*0Sstevel@tonic-gate cp = hp->h_name; 5304*0Sstevel@tonic-gate } 5305*0Sstevel@tonic-gate } 5306*0Sstevel@tonic-gate if (cp != NULL) { 5307*0Sstevel@tonic-gate (void) strncpy(dst, cp, dstlen); 5308*0Sstevel@tonic-gate dst[dstlen - 1] = 0; 5309*0Sstevel@tonic-gate } else { 5310*0Sstevel@tonic-gate (void) inet_ntop(AF_INET6, (void *)addr, dst, dstlen); 5311*0Sstevel@tonic-gate } 5312*0Sstevel@tonic-gate if (hp != NULL) 5313*0Sstevel@tonic-gate freehostent(hp); 5314*0Sstevel@tonic-gate return (dst); 5315*0Sstevel@tonic-gate } 5316*0Sstevel@tonic-gate 5317*0Sstevel@tonic-gate /* For IPv4 masks */ 5318*0Sstevel@tonic-gate static char * 5319*0Sstevel@tonic-gate pr_mask(uint_t addr, char *dst, uint_t dstlen) 5320*0Sstevel@tonic-gate { 5321*0Sstevel@tonic-gate uint8_t *ip_addr = (uint8_t *)&addr; 5322*0Sstevel@tonic-gate 5323*0Sstevel@tonic-gate (void) snprintf(dst, dstlen, "%d.%d.%d.%d", 5324*0Sstevel@tonic-gate ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3]); 5325*0Sstevel@tonic-gate return (dst); 5326*0Sstevel@tonic-gate } 5327*0Sstevel@tonic-gate 5328*0Sstevel@tonic-gate /* 5329*0Sstevel@tonic-gate * For ipv6 masks format is : dest/mask 5330*0Sstevel@tonic-gate * Does not print /128 to save space in printout. H flag carries this notion. 5331*0Sstevel@tonic-gate */ 5332*0Sstevel@tonic-gate static char * 5333*0Sstevel@tonic-gate pr_prefix6(struct in6_addr *addr, uint_t prefixlen, char *dst, uint_t dstlen) 5334*0Sstevel@tonic-gate { 5335*0Sstevel@tonic-gate char *cp; 5336*0Sstevel@tonic-gate 5337*0Sstevel@tonic-gate if (IN6_IS_ADDR_UNSPECIFIED(addr) && prefixlen == 0) { 5338*0Sstevel@tonic-gate (void) strncpy(dst, "default", dstlen); 5339*0Sstevel@tonic-gate dst[dstlen - 1] = 0; 5340*0Sstevel@tonic-gate return (dst); 5341*0Sstevel@tonic-gate } 5342*0Sstevel@tonic-gate 5343*0Sstevel@tonic-gate (void) pr_addr6(addr, dst, dstlen); 5344*0Sstevel@tonic-gate if (prefixlen != IPV6_ABITS) { 5345*0Sstevel@tonic-gate /* How much room is left? */ 5346*0Sstevel@tonic-gate cp = strchr(dst, '\0'); 5347*0Sstevel@tonic-gate if (dst + dstlen > cp) { 5348*0Sstevel@tonic-gate dstlen -= (cp - dst); 5349*0Sstevel@tonic-gate (void) snprintf(cp, dstlen, "/%d", prefixlen); 5350*0Sstevel@tonic-gate } 5351*0Sstevel@tonic-gate } 5352*0Sstevel@tonic-gate return (dst); 5353*0Sstevel@tonic-gate } 5354*0Sstevel@tonic-gate 5355*0Sstevel@tonic-gate /* Print IPv4 address and port */ 5356*0Sstevel@tonic-gate static char * 5357*0Sstevel@tonic-gate pr_ap(uint_t addr, uint_t port, char *proto, 5358*0Sstevel@tonic-gate char *dst, uint_t dstlen) 5359*0Sstevel@tonic-gate { 5360*0Sstevel@tonic-gate char *cp; 5361*0Sstevel@tonic-gate 5362*0Sstevel@tonic-gate if (addr == INADDR_ANY) { 5363*0Sstevel@tonic-gate (void) strncpy(dst, " *", dstlen); 5364*0Sstevel@tonic-gate dst[dstlen - 1] = 0; 5365*0Sstevel@tonic-gate } else { 5366*0Sstevel@tonic-gate (void) pr_addr(addr, dst, dstlen); 5367*0Sstevel@tonic-gate } 5368*0Sstevel@tonic-gate /* How much room is left? */ 5369*0Sstevel@tonic-gate cp = strchr(dst, '\0'); 5370*0Sstevel@tonic-gate if (dst + dstlen > cp + 1) { 5371*0Sstevel@tonic-gate *cp++ = '.'; 5372*0Sstevel@tonic-gate dstlen -= (cp - dst); 5373*0Sstevel@tonic-gate dstlen--; 5374*0Sstevel@tonic-gate (void) portname(port, proto, cp, dstlen); 5375*0Sstevel@tonic-gate } 5376*0Sstevel@tonic-gate return (dst); 5377*0Sstevel@tonic-gate } 5378*0Sstevel@tonic-gate 5379*0Sstevel@tonic-gate /* Print IPv6 address and port */ 5380*0Sstevel@tonic-gate static char * 5381*0Sstevel@tonic-gate pr_ap6(const in6_addr_t *addr, uint_t port, char *proto, 5382*0Sstevel@tonic-gate char *dst, uint_t dstlen) 5383*0Sstevel@tonic-gate { 5384*0Sstevel@tonic-gate char *cp; 5385*0Sstevel@tonic-gate 5386*0Sstevel@tonic-gate if (IN6_IS_ADDR_UNSPECIFIED(addr)) { 5387*0Sstevel@tonic-gate (void) strncpy(dst, " *", dstlen); 5388*0Sstevel@tonic-gate dst[dstlen - 1] = 0; 5389*0Sstevel@tonic-gate } else { 5390*0Sstevel@tonic-gate (void) pr_addr6(addr, dst, dstlen); 5391*0Sstevel@tonic-gate } 5392*0Sstevel@tonic-gate /* How much room is left? */ 5393*0Sstevel@tonic-gate cp = strchr(dst, '\0'); 5394*0Sstevel@tonic-gate if (dst + dstlen + 1 > cp) { 5395*0Sstevel@tonic-gate *cp++ = '.'; 5396*0Sstevel@tonic-gate dstlen -= (cp - dst); 5397*0Sstevel@tonic-gate dstlen--; 5398*0Sstevel@tonic-gate (void) portname(port, proto, cp, dstlen); 5399*0Sstevel@tonic-gate } 5400*0Sstevel@tonic-gate return (dst); 5401*0Sstevel@tonic-gate } 5402*0Sstevel@tonic-gate 5403*0Sstevel@tonic-gate /* 5404*0Sstevel@tonic-gate * Return the name of the network whose address is given. The address is 5405*0Sstevel@tonic-gate * assumed to be that of a net or subnet, not a host. 5406*0Sstevel@tonic-gate */ 5407*0Sstevel@tonic-gate static char * 5408*0Sstevel@tonic-gate pr_net(uint_t addr, uint_t mask, char *dst, uint_t dstlen) 5409*0Sstevel@tonic-gate { 5410*0Sstevel@tonic-gate char *cp = NULL; 5411*0Sstevel@tonic-gate struct netent *np = NULL; 5412*0Sstevel@tonic-gate struct hostent *hp = NULL; 5413*0Sstevel@tonic-gate uint_t net; 5414*0Sstevel@tonic-gate int subnetshift; 5415*0Sstevel@tonic-gate int error_num; 5416*0Sstevel@tonic-gate 5417*0Sstevel@tonic-gate if (addr == INADDR_ANY && mask == INADDR_ANY) { 5418*0Sstevel@tonic-gate (void) strncpy(dst, "default", dstlen); 5419*0Sstevel@tonic-gate dst[dstlen - 1] = 0; 5420*0Sstevel@tonic-gate return (dst); 5421*0Sstevel@tonic-gate } 5422*0Sstevel@tonic-gate 5423*0Sstevel@tonic-gate if (!Nflag && addr) { 5424*0Sstevel@tonic-gate if (mask == 0) { 5425*0Sstevel@tonic-gate if (IN_CLASSA(addr)) { 5426*0Sstevel@tonic-gate mask = (uint_t)IN_CLASSA_NET; 5427*0Sstevel@tonic-gate subnetshift = 8; 5428*0Sstevel@tonic-gate } else if (IN_CLASSB(addr)) { 5429*0Sstevel@tonic-gate mask = (uint_t)IN_CLASSB_NET; 5430*0Sstevel@tonic-gate subnetshift = 8; 5431*0Sstevel@tonic-gate } else { 5432*0Sstevel@tonic-gate mask = (uint_t)IN_CLASSC_NET; 5433*0Sstevel@tonic-gate subnetshift = 4; 5434*0Sstevel@tonic-gate } 5435*0Sstevel@tonic-gate /* 5436*0Sstevel@tonic-gate * If there are more bits than the standard mask 5437*0Sstevel@tonic-gate * would suggest, subnets must be in use. Guess at 5438*0Sstevel@tonic-gate * the subnet mask, assuming reasonable width subnet 5439*0Sstevel@tonic-gate * fields. 5440*0Sstevel@tonic-gate */ 5441*0Sstevel@tonic-gate while (addr & ~mask) 5442*0Sstevel@tonic-gate /* compiler doesn't sign extend! */ 5443*0Sstevel@tonic-gate mask = (mask | ((int)mask >> subnetshift)); 5444*0Sstevel@tonic-gate } 5445*0Sstevel@tonic-gate net = addr & mask; 5446*0Sstevel@tonic-gate while ((mask & 1) == 0) 5447*0Sstevel@tonic-gate mask >>= 1, net >>= 1; 5448*0Sstevel@tonic-gate np = getnetbyaddr(net, AF_INET); 5449*0Sstevel@tonic-gate if (np && np->n_net == net) 5450*0Sstevel@tonic-gate cp = np->n_name; 5451*0Sstevel@tonic-gate else { 5452*0Sstevel@tonic-gate /* 5453*0Sstevel@tonic-gate * Look for subnets in hosts map. 5454*0Sstevel@tonic-gate */ 5455*0Sstevel@tonic-gate hp = getipnodebyaddr((char *)&addr, sizeof (uint_t), 5456*0Sstevel@tonic-gate AF_INET, &error_num); 5457*0Sstevel@tonic-gate if (hp) 5458*0Sstevel@tonic-gate cp = hp->h_name; 5459*0Sstevel@tonic-gate } 5460*0Sstevel@tonic-gate } 5461*0Sstevel@tonic-gate if (cp != NULL) { 5462*0Sstevel@tonic-gate (void) strncpy(dst, cp, dstlen); 5463*0Sstevel@tonic-gate dst[dstlen - 1] = 0; 5464*0Sstevel@tonic-gate } else { 5465*0Sstevel@tonic-gate (void) inet_ntop(AF_INET, (char *)&addr, dst, dstlen); 5466*0Sstevel@tonic-gate } 5467*0Sstevel@tonic-gate if (hp != NULL) 5468*0Sstevel@tonic-gate freehostent(hp); 5469*0Sstevel@tonic-gate return (dst); 5470*0Sstevel@tonic-gate } 5471*0Sstevel@tonic-gate 5472*0Sstevel@tonic-gate /* 5473*0Sstevel@tonic-gate * Return the name of the network whose address is given. 5474*0Sstevel@tonic-gate * The address is assumed to be a host address. 5475*0Sstevel@tonic-gate */ 5476*0Sstevel@tonic-gate static char * 5477*0Sstevel@tonic-gate pr_netaddr(uint_t addr, uint_t mask, char *dst, uint_t dstlen) 5478*0Sstevel@tonic-gate { 5479*0Sstevel@tonic-gate char *cp = NULL; 5480*0Sstevel@tonic-gate struct netent *np = NULL; 5481*0Sstevel@tonic-gate struct hostent *hp = NULL; 5482*0Sstevel@tonic-gate uint_t net; 5483*0Sstevel@tonic-gate uint_t netshifted; 5484*0Sstevel@tonic-gate int subnetshift; 5485*0Sstevel@tonic-gate struct in_addr in; 5486*0Sstevel@tonic-gate int error_num; 5487*0Sstevel@tonic-gate uint_t nbo_addr = addr; /* network byte order */ 5488*0Sstevel@tonic-gate 5489*0Sstevel@tonic-gate addr = ntohl(addr); 5490*0Sstevel@tonic-gate mask = ntohl(mask); 5491*0Sstevel@tonic-gate if (addr == INADDR_ANY && mask == INADDR_ANY) { 5492*0Sstevel@tonic-gate (void) strncpy(dst, "default", dstlen); 5493*0Sstevel@tonic-gate dst[dstlen - 1] = 0; 5494*0Sstevel@tonic-gate return (dst); 5495*0Sstevel@tonic-gate } 5496*0Sstevel@tonic-gate 5497*0Sstevel@tonic-gate /* Figure out network portion of address (with host portion = 0) */ 5498*0Sstevel@tonic-gate if (addr) { 5499*0Sstevel@tonic-gate /* Try figuring out mask if unknown (all 0s). */ 5500*0Sstevel@tonic-gate if (mask == 0) { 5501*0Sstevel@tonic-gate if (IN_CLASSA(addr)) { 5502*0Sstevel@tonic-gate mask = (uint_t)IN_CLASSA_NET; 5503*0Sstevel@tonic-gate subnetshift = 8; 5504*0Sstevel@tonic-gate } else if (IN_CLASSB(addr)) { 5505*0Sstevel@tonic-gate mask = (uint_t)IN_CLASSB_NET; 5506*0Sstevel@tonic-gate subnetshift = 8; 5507*0Sstevel@tonic-gate } else { 5508*0Sstevel@tonic-gate mask = (uint_t)IN_CLASSC_NET; 5509*0Sstevel@tonic-gate subnetshift = 4; 5510*0Sstevel@tonic-gate } 5511*0Sstevel@tonic-gate /* 5512*0Sstevel@tonic-gate * If there are more bits than the standard mask 5513*0Sstevel@tonic-gate * would suggest, subnets must be in use. Guess at 5514*0Sstevel@tonic-gate * the subnet mask, assuming reasonable width subnet 5515*0Sstevel@tonic-gate * fields. 5516*0Sstevel@tonic-gate */ 5517*0Sstevel@tonic-gate while (addr & ~mask) 5518*0Sstevel@tonic-gate /* compiler doesn't sign extend! */ 5519*0Sstevel@tonic-gate mask = (mask | ((int)mask >> subnetshift)); 5520*0Sstevel@tonic-gate } 5521*0Sstevel@tonic-gate net = netshifted = addr & mask; 5522*0Sstevel@tonic-gate while ((mask & 1) == 0) 5523*0Sstevel@tonic-gate mask >>= 1, netshifted >>= 1; 5524*0Sstevel@tonic-gate } 5525*0Sstevel@tonic-gate else 5526*0Sstevel@tonic-gate net = netshifted = 0; 5527*0Sstevel@tonic-gate 5528*0Sstevel@tonic-gate /* Try looking up name unless -n was specified. */ 5529*0Sstevel@tonic-gate if (!Nflag) { 5530*0Sstevel@tonic-gate np = getnetbyaddr(netshifted, AF_INET); 5531*0Sstevel@tonic-gate if (np && np->n_net == netshifted) 5532*0Sstevel@tonic-gate cp = np->n_name; 5533*0Sstevel@tonic-gate else { 5534*0Sstevel@tonic-gate /* 5535*0Sstevel@tonic-gate * Look for subnets in hosts map. 5536*0Sstevel@tonic-gate */ 5537*0Sstevel@tonic-gate hp = getipnodebyaddr((char *)&nbo_addr, sizeof (uint_t), 5538*0Sstevel@tonic-gate AF_INET, &error_num); 5539*0Sstevel@tonic-gate if (hp) 5540*0Sstevel@tonic-gate cp = hp->h_name; 5541*0Sstevel@tonic-gate } 5542*0Sstevel@tonic-gate 5543*0Sstevel@tonic-gate if (cp != NULL) { 5544*0Sstevel@tonic-gate (void) strncpy(dst, cp, dstlen); 5545*0Sstevel@tonic-gate dst[dstlen - 1] = 0; 5546*0Sstevel@tonic-gate if (hp != NULL) 5547*0Sstevel@tonic-gate freehostent(hp); 5548*0Sstevel@tonic-gate return (dst); 5549*0Sstevel@tonic-gate } 5550*0Sstevel@tonic-gate /* 5551*0Sstevel@tonic-gate * No name found for net: fallthru and return in decimal 5552*0Sstevel@tonic-gate * dot notation. 5553*0Sstevel@tonic-gate */ 5554*0Sstevel@tonic-gate } 5555*0Sstevel@tonic-gate 5556*0Sstevel@tonic-gate in.s_addr = htonl(net); 5557*0Sstevel@tonic-gate (void) inet_ntop(AF_INET, (char *)&in, dst, dstlen); 5558*0Sstevel@tonic-gate if (hp != NULL) 5559*0Sstevel@tonic-gate freehostent(hp); 5560*0Sstevel@tonic-gate return (dst); 5561*0Sstevel@tonic-gate } 5562*0Sstevel@tonic-gate 5563*0Sstevel@tonic-gate 5564*0Sstevel@tonic-gate /* 5565*0Sstevel@tonic-gate * Return the standard IPv4 classess host or network identifier. 5566*0Sstevel@tonic-gate * 5567*0Sstevel@tonic-gate * Returns "default" for the default route. 5568*0Sstevel@tonic-gate * Returns "x.x.x.x" or host name if mask is 255.255.255.255. 5569*0Sstevel@tonic-gate * Returns "x.x.x.x/y" (y is bit count) if mask is contiguous. 5570*0Sstevel@tonic-gate * Otherwise, returns "x.x.x.x/m.m.m.m" (undesirable mask). 5571*0Sstevel@tonic-gate * 5572*0Sstevel@tonic-gate * Can also return "****" if inet_ntop fails -- insufficient dst space 5573*0Sstevel@tonic-gate * available. (Shouldn't happen otherwise.) 5574*0Sstevel@tonic-gate */ 5575*0Sstevel@tonic-gate static char * 5576*0Sstevel@tonic-gate pr_netclassless(ipaddr_t addr, ipaddr_t mask, char *dst, size_t dstlen) 5577*0Sstevel@tonic-gate { 5578*0Sstevel@tonic-gate struct hostent *hp; 5579*0Sstevel@tonic-gate int error_num; 5580*0Sstevel@tonic-gate struct in_addr in; 5581*0Sstevel@tonic-gate char *cp; 5582*0Sstevel@tonic-gate int slen; 5583*0Sstevel@tonic-gate 5584*0Sstevel@tonic-gate if (addr == INADDR_ANY && mask == INADDR_ANY) { 5585*0Sstevel@tonic-gate (void) strlcpy(dst, "default", dstlen); 5586*0Sstevel@tonic-gate return (dst); 5587*0Sstevel@tonic-gate } 5588*0Sstevel@tonic-gate if (mask == IP_HOST_MASK && !Nflag && 5589*0Sstevel@tonic-gate (hp = getipnodebyaddr(&addr, sizeof (addr), AF_INET, 5590*0Sstevel@tonic-gate &error_num)) != NULL) { 5591*0Sstevel@tonic-gate (void) strlcpy(dst, hp->h_name, dstlen); 5592*0Sstevel@tonic-gate freehostent(hp); 5593*0Sstevel@tonic-gate return (dst); 5594*0Sstevel@tonic-gate } 5595*0Sstevel@tonic-gate in.s_addr = addr; 5596*0Sstevel@tonic-gate if (inet_ntop(AF_INET, &in, dst, dstlen) == NULL) { 5597*0Sstevel@tonic-gate (void) strlcpy(dst, "****", dstlen); 5598*0Sstevel@tonic-gate return (dst); 5599*0Sstevel@tonic-gate } 5600*0Sstevel@tonic-gate if (mask != IP_HOST_MASK) { 5601*0Sstevel@tonic-gate slen = strlen(dst); 5602*0Sstevel@tonic-gate cp = dst + slen; 5603*0Sstevel@tonic-gate dstlen -= slen; 5604*0Sstevel@tonic-gate if (mask == 0) { 5605*0Sstevel@tonic-gate /* Illegal on non-zero addresses */ 5606*0Sstevel@tonic-gate (void) strlcpy(cp, "/0", dstlen); 5607*0Sstevel@tonic-gate } else if ((mask | (mask - 1)) == IP_HOST_MASK) { 5608*0Sstevel@tonic-gate (void) snprintf(cp, dstlen, "/%d", 5609*0Sstevel@tonic-gate IP_ABITS - ffs(mask) + 1); 5610*0Sstevel@tonic-gate } else { 5611*0Sstevel@tonic-gate /* Ungood; non-contiguous mask */ 5612*0Sstevel@tonic-gate (void) pr_mask(mask, cp, dstlen); 5613*0Sstevel@tonic-gate } 5614*0Sstevel@tonic-gate } 5615*0Sstevel@tonic-gate return (dst); 5616*0Sstevel@tonic-gate } 5617*0Sstevel@tonic-gate 5618*0Sstevel@tonic-gate /* 5619*0Sstevel@tonic-gate * Return the filter mode as a string: 5620*0Sstevel@tonic-gate * 1 => "INCLUDE" 5621*0Sstevel@tonic-gate * 2 => "EXCLUDE" 5622*0Sstevel@tonic-gate * otherwise "<unknown>" 5623*0Sstevel@tonic-gate */ 5624*0Sstevel@tonic-gate static char * 5625*0Sstevel@tonic-gate fmodestr(uint_t fmode) 5626*0Sstevel@tonic-gate { 5627*0Sstevel@tonic-gate switch (fmode) { 5628*0Sstevel@tonic-gate case 1: 5629*0Sstevel@tonic-gate return ("INCLUDE"); 5630*0Sstevel@tonic-gate case 2: 5631*0Sstevel@tonic-gate return ("EXCLUDE"); 5632*0Sstevel@tonic-gate default: 5633*0Sstevel@tonic-gate return ("<unknown>"); 5634*0Sstevel@tonic-gate } 5635*0Sstevel@tonic-gate } 5636*0Sstevel@tonic-gate 5637*0Sstevel@tonic-gate /* 5638*0Sstevel@tonic-gate * Pretty print a port number. If the Nflag was 5639*0Sstevel@tonic-gate * specified, use numbers instead of names. 5640*0Sstevel@tonic-gate */ 5641*0Sstevel@tonic-gate static char * 5642*0Sstevel@tonic-gate portname(uint_t port, char *proto, char *dst, uint_t dstlen) 5643*0Sstevel@tonic-gate { 5644*0Sstevel@tonic-gate struct servent *sp = NULL; 5645*0Sstevel@tonic-gate 5646*0Sstevel@tonic-gate if (!Nflag && port) 5647*0Sstevel@tonic-gate sp = getservbyport(htons(port), proto); 5648*0Sstevel@tonic-gate if (sp || port == 0) 5649*0Sstevel@tonic-gate (void) snprintf(dst, dstlen, "%.*s", MAXHOSTNAMELEN, 5650*0Sstevel@tonic-gate sp ? sp->s_name : "*"); 5651*0Sstevel@tonic-gate else 5652*0Sstevel@tonic-gate (void) snprintf(dst, dstlen, "%d", port); 5653*0Sstevel@tonic-gate dst[dstlen - 1] = 0; 5654*0Sstevel@tonic-gate return (dst); 5655*0Sstevel@tonic-gate } 5656*0Sstevel@tonic-gate 5657*0Sstevel@tonic-gate /*PRINTFLIKE2*/ 5658*0Sstevel@tonic-gate void 5659*0Sstevel@tonic-gate fail(int do_perror, char *message, ...) 5660*0Sstevel@tonic-gate { 5661*0Sstevel@tonic-gate va_list args; 5662*0Sstevel@tonic-gate 5663*0Sstevel@tonic-gate va_start(args, message); 5664*0Sstevel@tonic-gate (void) fputs("netstat: ", stderr); 5665*0Sstevel@tonic-gate (void) vfprintf(stderr, message, args); 5666*0Sstevel@tonic-gate va_end(args); 5667*0Sstevel@tonic-gate if (do_perror) 5668*0Sstevel@tonic-gate (void) fprintf(stderr, ": %s", strerror(errno)); 5669*0Sstevel@tonic-gate (void) fputc('\n', stderr); 5670*0Sstevel@tonic-gate exit(2); 5671*0Sstevel@tonic-gate } 5672*0Sstevel@tonic-gate 5673*0Sstevel@tonic-gate /* 5674*0Sstevel@tonic-gate * Return value of named statistic for given kstat_named kstat; 5675*0Sstevel@tonic-gate * return 0LL if named statistic is not in list (use "ll" as a 5676*0Sstevel@tonic-gate * type qualifier when printing 64-bit int's with printf() ) 5677*0Sstevel@tonic-gate */ 5678*0Sstevel@tonic-gate static uint64_t 5679*0Sstevel@tonic-gate kstat_named_value(kstat_t *ksp, char *name) 5680*0Sstevel@tonic-gate { 5681*0Sstevel@tonic-gate kstat_named_t *knp; 5682*0Sstevel@tonic-gate uint64_t value; 5683*0Sstevel@tonic-gate 5684*0Sstevel@tonic-gate if (ksp == NULL) 5685*0Sstevel@tonic-gate return (0LL); 5686*0Sstevel@tonic-gate 5687*0Sstevel@tonic-gate knp = kstat_data_lookup(ksp, name); 5688*0Sstevel@tonic-gate if (knp == NULL) 5689*0Sstevel@tonic-gate return (0LL); 5690*0Sstevel@tonic-gate 5691*0Sstevel@tonic-gate switch (knp->data_type) { 5692*0Sstevel@tonic-gate case KSTAT_DATA_INT32: 5693*0Sstevel@tonic-gate case KSTAT_DATA_UINT32: 5694*0Sstevel@tonic-gate value = (uint64_t)(knp->value.ui32); 5695*0Sstevel@tonic-gate break; 5696*0Sstevel@tonic-gate case KSTAT_DATA_INT64: 5697*0Sstevel@tonic-gate case KSTAT_DATA_UINT64: 5698*0Sstevel@tonic-gate value = knp->value.ui64; 5699*0Sstevel@tonic-gate break; 5700*0Sstevel@tonic-gate default: 5701*0Sstevel@tonic-gate value = 0LL; 5702*0Sstevel@tonic-gate break; 5703*0Sstevel@tonic-gate } 5704*0Sstevel@tonic-gate 5705*0Sstevel@tonic-gate return (value); 5706*0Sstevel@tonic-gate } 5707*0Sstevel@tonic-gate 5708*0Sstevel@tonic-gate kid_t 5709*0Sstevel@tonic-gate safe_kstat_read(kstat_ctl_t *kc, kstat_t *ksp, void *data) 5710*0Sstevel@tonic-gate { 5711*0Sstevel@tonic-gate kid_t kstat_chain_id = kstat_read(kc, ksp, data); 5712*0Sstevel@tonic-gate 5713*0Sstevel@tonic-gate if (kstat_chain_id == -1) 5714*0Sstevel@tonic-gate fail(1, "kstat_read(%p, '%s') failed", (void *)kc, 5715*0Sstevel@tonic-gate ksp->ks_name); 5716*0Sstevel@tonic-gate return (kstat_chain_id); 5717*0Sstevel@tonic-gate } 5718*0Sstevel@tonic-gate 5719*0Sstevel@tonic-gate /* 5720*0Sstevel@tonic-gate * Parse a list of IRE flag characters into a bit field. 5721*0Sstevel@tonic-gate */ 5722*0Sstevel@tonic-gate static uint_t 5723*0Sstevel@tonic-gate flag_bits(const char *arg) 5724*0Sstevel@tonic-gate { 5725*0Sstevel@tonic-gate const char *cp; 5726*0Sstevel@tonic-gate uint_t val; 5727*0Sstevel@tonic-gate 5728*0Sstevel@tonic-gate if (*arg == '\0') 5729*0Sstevel@tonic-gate fatal(1, "missing flag list\n"); 5730*0Sstevel@tonic-gate 5731*0Sstevel@tonic-gate val = 0; 5732*0Sstevel@tonic-gate while (*arg != '\0') { 5733*0Sstevel@tonic-gate if ((cp = strchr(flag_list, *arg)) == NULL) 5734*0Sstevel@tonic-gate fatal(1, "%c: illegal flag\n", *arg); 5735*0Sstevel@tonic-gate val |= 1 << (cp - flag_list); 5736*0Sstevel@tonic-gate arg++; 5737*0Sstevel@tonic-gate } 5738*0Sstevel@tonic-gate return (val); 5739*0Sstevel@tonic-gate } 5740*0Sstevel@tonic-gate 5741*0Sstevel@tonic-gate /* 5742*0Sstevel@tonic-gate * Handle -f argument. Validate input format, sort by keyword, and 5743*0Sstevel@tonic-gate * save off digested results. 5744*0Sstevel@tonic-gate */ 5745*0Sstevel@tonic-gate static void 5746*0Sstevel@tonic-gate process_filter(char *arg) 5747*0Sstevel@tonic-gate { 5748*0Sstevel@tonic-gate int idx; 5749*0Sstevel@tonic-gate int klen = 0; 5750*0Sstevel@tonic-gate char *cp, *cp2; 5751*0Sstevel@tonic-gate int val; 5752*0Sstevel@tonic-gate filter_t *newf; 5753*0Sstevel@tonic-gate struct hostent *hp; 5754*0Sstevel@tonic-gate int error_num; 5755*0Sstevel@tonic-gate uint8_t *ucp; 5756*0Sstevel@tonic-gate int maxv; 5757*0Sstevel@tonic-gate 5758*0Sstevel@tonic-gate /* Look up the keyword first */ 5759*0Sstevel@tonic-gate if (strchr(arg, ':') == NULL) { 5760*0Sstevel@tonic-gate idx = FK_AF; 5761*0Sstevel@tonic-gate } else { 5762*0Sstevel@tonic-gate for (idx = 0; idx < NFILTERKEYS; idx++) { 5763*0Sstevel@tonic-gate klen = strlen(filter_keys[idx]); 5764*0Sstevel@tonic-gate if (strncmp(filter_keys[idx], arg, klen) == 0 && 5765*0Sstevel@tonic-gate arg[klen] == ':') 5766*0Sstevel@tonic-gate break; 5767*0Sstevel@tonic-gate } 5768*0Sstevel@tonic-gate if (idx >= NFILTERKEYS) 5769*0Sstevel@tonic-gate fatal(1, "%s: unknown filter keyword\n", arg); 5770*0Sstevel@tonic-gate 5771*0Sstevel@tonic-gate /* Advance past keyword and separator. */ 5772*0Sstevel@tonic-gate arg += klen + 1; 5773*0Sstevel@tonic-gate } 5774*0Sstevel@tonic-gate 5775*0Sstevel@tonic-gate if ((newf = malloc(sizeof (*newf))) == NULL) { 5776*0Sstevel@tonic-gate perror("filter"); 5777*0Sstevel@tonic-gate exit(1); 5778*0Sstevel@tonic-gate } 5779*0Sstevel@tonic-gate switch (idx) { 5780*0Sstevel@tonic-gate case FK_AF: 5781*0Sstevel@tonic-gate if (strcmp(arg, "inet") == 0) { 5782*0Sstevel@tonic-gate newf->u.f_family = AF_INET; 5783*0Sstevel@tonic-gate } else if (strcmp(arg, "inet6") == 0) { 5784*0Sstevel@tonic-gate newf->u.f_family = AF_INET6; 5785*0Sstevel@tonic-gate } else if (strcmp(arg, "unix") == 0) { 5786*0Sstevel@tonic-gate newf->u.f_family = AF_UNIX; 5787*0Sstevel@tonic-gate } else { 5788*0Sstevel@tonic-gate newf->u.f_family = strtol(arg, &cp, 0); 5789*0Sstevel@tonic-gate if (arg == cp || *cp != '\0') 5790*0Sstevel@tonic-gate fatal(1, "%s: unknown address family.\n", arg); 5791*0Sstevel@tonic-gate } 5792*0Sstevel@tonic-gate break; 5793*0Sstevel@tonic-gate 5794*0Sstevel@tonic-gate case FK_INIF: 5795*0Sstevel@tonic-gate case FK_OUTIF: 5796*0Sstevel@tonic-gate if (strcmp(arg, "none") == 0) { 5797*0Sstevel@tonic-gate newf->u.f_ifname = NULL; 5798*0Sstevel@tonic-gate break; 5799*0Sstevel@tonic-gate } 5800*0Sstevel@tonic-gate if (strcmp(arg, "any") == 0) { 5801*0Sstevel@tonic-gate newf->u.f_ifname = ""; 5802*0Sstevel@tonic-gate break; 5803*0Sstevel@tonic-gate } 5804*0Sstevel@tonic-gate val = strtol(arg, &cp, 0); 5805*0Sstevel@tonic-gate if (val <= 0 || arg == cp || cp[0] != '\0') { 5806*0Sstevel@tonic-gate if ((val = if_nametoindex(arg)) == 0) { 5807*0Sstevel@tonic-gate perror(arg); 5808*0Sstevel@tonic-gate exit(1); 5809*0Sstevel@tonic-gate } 5810*0Sstevel@tonic-gate } 5811*0Sstevel@tonic-gate newf->u.f_ifname = arg; 5812*0Sstevel@tonic-gate break; 5813*0Sstevel@tonic-gate 5814*0Sstevel@tonic-gate case FK_SRC: 5815*0Sstevel@tonic-gate case FK_DST: 5816*0Sstevel@tonic-gate V4MASK_TO_V6(IP_HOST_MASK, newf->u.a.f_mask); 5817*0Sstevel@tonic-gate if (strcmp(arg, "any") == 0) { 5818*0Sstevel@tonic-gate /* Special semantics; any address *but* zero */ 5819*0Sstevel@tonic-gate newf->u.a.f_address = NULL; 5820*0Sstevel@tonic-gate (void) memset(&newf->u.a.f_mask, 0, 5821*0Sstevel@tonic-gate sizeof (newf->u.a.f_mask)); 5822*0Sstevel@tonic-gate break; 5823*0Sstevel@tonic-gate } 5824*0Sstevel@tonic-gate if (strcmp(arg, "none") == 0) { 5825*0Sstevel@tonic-gate newf->u.a.f_address = NULL; 5826*0Sstevel@tonic-gate break; 5827*0Sstevel@tonic-gate } 5828*0Sstevel@tonic-gate if ((cp = strrchr(arg, '/')) != NULL) 5829*0Sstevel@tonic-gate *cp++ = '\0'; 5830*0Sstevel@tonic-gate hp = getipnodebyname(arg, AF_INET6, AI_V4MAPPED|AI_ALL, 5831*0Sstevel@tonic-gate &error_num); 5832*0Sstevel@tonic-gate if (hp == NULL) 5833*0Sstevel@tonic-gate fatal(1, "%s: invalid or unknown host address\n", arg); 5834*0Sstevel@tonic-gate newf->u.a.f_address = hp; 5835*0Sstevel@tonic-gate if (cp == NULL) { 5836*0Sstevel@tonic-gate V4MASK_TO_V6(IP_HOST_MASK, newf->u.a.f_mask); 5837*0Sstevel@tonic-gate } else { 5838*0Sstevel@tonic-gate val = strtol(cp, &cp2, 0); 5839*0Sstevel@tonic-gate if (cp != cp2 && cp2[0] == '\0') { 5840*0Sstevel@tonic-gate /* 5841*0Sstevel@tonic-gate * If decode as "/n" works, then translate 5842*0Sstevel@tonic-gate * into a mask. 5843*0Sstevel@tonic-gate */ 5844*0Sstevel@tonic-gate if (hp->h_addr_list[0] != NULL && 5845*0Sstevel@tonic-gate /* LINTED: (note 1) */ 5846*0Sstevel@tonic-gate IN6_IS_ADDR_V4MAPPED((in6_addr_t 5847*0Sstevel@tonic-gate *)hp->h_addr_list[0])) { 5848*0Sstevel@tonic-gate maxv = IP_ABITS; 5849*0Sstevel@tonic-gate } else { 5850*0Sstevel@tonic-gate maxv = IPV6_ABITS; 5851*0Sstevel@tonic-gate } 5852*0Sstevel@tonic-gate if (val < 0 || val >= maxv) 5853*0Sstevel@tonic-gate fatal(1, "%d: not in range 0 to %d\n", 5854*0Sstevel@tonic-gate val, maxv - 1); 5855*0Sstevel@tonic-gate if (maxv == IP_ABITS) 5856*0Sstevel@tonic-gate val += IPV6_ABITS - IP_ABITS; 5857*0Sstevel@tonic-gate ucp = newf->u.a.f_mask.s6_addr; 5858*0Sstevel@tonic-gate while (val >= 8) 5859*0Sstevel@tonic-gate *ucp++ = 0xff, val -= 8; 5860*0Sstevel@tonic-gate *ucp++ = (0xff << (8 - val)) & 0xff; 5861*0Sstevel@tonic-gate while (ucp < newf->u.a.f_mask.s6_addr + 5862*0Sstevel@tonic-gate sizeof (newf->u.a.f_mask.s6_addr)) 5863*0Sstevel@tonic-gate *ucp++ = 0; 5864*0Sstevel@tonic-gate /* Otherwise, try as numeric address */ 5865*0Sstevel@tonic-gate } else if (inet_pton(AF_INET6, 5866*0Sstevel@tonic-gate cp, &newf->u.a.f_mask) <= 0) { 5867*0Sstevel@tonic-gate fatal(1, "%s: illegal mask format\n", cp); 5868*0Sstevel@tonic-gate } 5869*0Sstevel@tonic-gate } 5870*0Sstevel@tonic-gate break; 5871*0Sstevel@tonic-gate 5872*0Sstevel@tonic-gate case FK_FLAGS: 5873*0Sstevel@tonic-gate if (*arg == '+') { 5874*0Sstevel@tonic-gate newf->u.f.f_flagset = flag_bits(arg + 1); 5875*0Sstevel@tonic-gate newf->u.f.f_flagclear = 0; 5876*0Sstevel@tonic-gate } else if (*arg == '-') { 5877*0Sstevel@tonic-gate newf->u.f.f_flagset = 0; 5878*0Sstevel@tonic-gate newf->u.f.f_flagclear = flag_bits(arg + 1); 5879*0Sstevel@tonic-gate } else { 5880*0Sstevel@tonic-gate newf->u.f.f_flagset = flag_bits(arg); 5881*0Sstevel@tonic-gate newf->u.f.f_flagclear = ~newf->u.f.f_flagset; 5882*0Sstevel@tonic-gate } 5883*0Sstevel@tonic-gate break; 5884*0Sstevel@tonic-gate 5885*0Sstevel@tonic-gate default: 5886*0Sstevel@tonic-gate assert(0); 5887*0Sstevel@tonic-gate } 5888*0Sstevel@tonic-gate newf->f_next = filters[idx]; 5889*0Sstevel@tonic-gate filters[idx] = newf; 5890*0Sstevel@tonic-gate } 5891*0Sstevel@tonic-gate 5892*0Sstevel@tonic-gate /* Determine if user wants this address family printed. */ 5893*0Sstevel@tonic-gate static boolean_t 5894*0Sstevel@tonic-gate family_selected(int family) 5895*0Sstevel@tonic-gate { 5896*0Sstevel@tonic-gate const filter_t *fp; 5897*0Sstevel@tonic-gate 5898*0Sstevel@tonic-gate if (v4compat && family == AF_INET6) 5899*0Sstevel@tonic-gate return (B_FALSE); 5900*0Sstevel@tonic-gate if ((fp = filters[FK_AF]) == NULL) 5901*0Sstevel@tonic-gate return (B_TRUE); 5902*0Sstevel@tonic-gate while (fp != NULL) { 5903*0Sstevel@tonic-gate if (fp->u.f_family == family) 5904*0Sstevel@tonic-gate return (B_TRUE); 5905*0Sstevel@tonic-gate fp = fp->f_next; 5906*0Sstevel@tonic-gate } 5907*0Sstevel@tonic-gate return (B_FALSE); 5908*0Sstevel@tonic-gate } 5909*0Sstevel@tonic-gate 5910*0Sstevel@tonic-gate /* 5911*0Sstevel@tonic-gate * print the usage line 5912*0Sstevel@tonic-gate */ 5913*0Sstevel@tonic-gate static void 5914*0Sstevel@tonic-gate usage(char *cmdname) 5915*0Sstevel@tonic-gate { 5916*0Sstevel@tonic-gate (void) fprintf(stderr, "usage: %s [-anv] [-f address_family]\n", 5917*0Sstevel@tonic-gate cmdname); 5918*0Sstevel@tonic-gate (void) fprintf(stderr, " %s [-n] [-f address_family] " 5919*0Sstevel@tonic-gate "[-P protocol] [-g | -p | -s [interval [count]]]\n", cmdname); 5920*0Sstevel@tonic-gate (void) fprintf(stderr, " %s -m [-v] " 5921*0Sstevel@tonic-gate "[interval [count]]\n", cmdname); 5922*0Sstevel@tonic-gate (void) fprintf(stderr, " %s -i [-I interface] [-an] " 5923*0Sstevel@tonic-gate "[-f address_family] [interval [count]]\n", cmdname); 5924*0Sstevel@tonic-gate (void) fprintf(stderr, " %s -r [-anv] " 5925*0Sstevel@tonic-gate "[-f address_family|filter]\n", cmdname); 5926*0Sstevel@tonic-gate (void) fprintf(stderr, " %s -M [-ns] [-f address_family]\n", 5927*0Sstevel@tonic-gate cmdname); 5928*0Sstevel@tonic-gate (void) fprintf(stderr, " %s -D [-I interface] " 5929*0Sstevel@tonic-gate "[-f address_family]\n", cmdname); 5930*0Sstevel@tonic-gate exit(EXIT_FAILURE); 5931*0Sstevel@tonic-gate } 5932*0Sstevel@tonic-gate 5933*0Sstevel@tonic-gate /* 5934*0Sstevel@tonic-gate * fatal: print error message to stderr and 5935*0Sstevel@tonic-gate * call exit(errcode) 5936*0Sstevel@tonic-gate */ 5937*0Sstevel@tonic-gate /*PRINTFLIKE2*/ 5938*0Sstevel@tonic-gate static void 5939*0Sstevel@tonic-gate fatal(int errcode, char *format, ...) { 5940*0Sstevel@tonic-gate va_list argp; 5941*0Sstevel@tonic-gate 5942*0Sstevel@tonic-gate if (format == NULL) 5943*0Sstevel@tonic-gate return; 5944*0Sstevel@tonic-gate 5945*0Sstevel@tonic-gate va_start(argp, format); 5946*0Sstevel@tonic-gate (void) vfprintf(stderr, format, argp); 5947*0Sstevel@tonic-gate va_end(argp); 5948*0Sstevel@tonic-gate 5949*0Sstevel@tonic-gate exit(errcode); 5950*0Sstevel@tonic-gate } 5951