17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 545916cd2Sjpk * Common Development and Distribution License (the "License"). 645916cd2Sjpk * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*e11c3f44Smeem * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 277c478bd9Sstevel@tonic-gate * Copyright (c) 1990 Mentat Inc. 287c478bd9Sstevel@tonic-gate * netstat.c 2.2, last change 9/9/91 297c478bd9Sstevel@tonic-gate * MROUTING Revision 3.5 307c478bd9Sstevel@tonic-gate */ 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate /* 337c478bd9Sstevel@tonic-gate * simple netstat based on snmp/mib-2 interface to the TCP/IP stack 347c478bd9Sstevel@tonic-gate * 357c478bd9Sstevel@tonic-gate * NOTES: 367c478bd9Sstevel@tonic-gate * 1. A comment "LINTED: (note 1)" appears before certain lines where 377c478bd9Sstevel@tonic-gate * lint would have complained, "pointer cast may result in improper 387c478bd9Sstevel@tonic-gate * alignment". These are lines where lint had suspected potential 397c478bd9Sstevel@tonic-gate * improper alignment of a data structure; in each such situation 407c478bd9Sstevel@tonic-gate * we have relied on the kernel guaranteeing proper alignment. 417c478bd9Sstevel@tonic-gate * 2. Some 'for' loops have been commented as "'for' loop 1", etc 427c478bd9Sstevel@tonic-gate * because they have 'continue' or 'break' statements in their 437c478bd9Sstevel@tonic-gate * bodies. 'continue' statements have been used inside some loops 447c478bd9Sstevel@tonic-gate * where avoiding them would have led to deep levels of indentation. 457c478bd9Sstevel@tonic-gate * 467c478bd9Sstevel@tonic-gate * TODO: 477c478bd9Sstevel@tonic-gate * Add ability to request subsets from kernel (with level = MIB2_IP; 487c478bd9Sstevel@tonic-gate * name = 0 meaning everything for compatibility) 497c478bd9Sstevel@tonic-gate */ 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #include <stdio.h> 527c478bd9Sstevel@tonic-gate #include <stdlib.h> 537c478bd9Sstevel@tonic-gate #include <stdarg.h> 547c478bd9Sstevel@tonic-gate #include <unistd.h> 557c478bd9Sstevel@tonic-gate #include <strings.h> 567c478bd9Sstevel@tonic-gate #include <string.h> 577c478bd9Sstevel@tonic-gate #include <errno.h> 587c478bd9Sstevel@tonic-gate #include <ctype.h> 597c478bd9Sstevel@tonic-gate #include <kstat.h> 607c478bd9Sstevel@tonic-gate #include <assert.h> 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate #include <sys/types.h> 637c478bd9Sstevel@tonic-gate #include <sys/stream.h> 647c478bd9Sstevel@tonic-gate #include <stropts.h> 657c478bd9Sstevel@tonic-gate #include <sys/strstat.h> 667c478bd9Sstevel@tonic-gate #include <sys/tihdr.h> 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate #include <sys/socket.h> 697c478bd9Sstevel@tonic-gate #include <sys/sockio.h> 707c478bd9Sstevel@tonic-gate #include <netinet/in.h> 717c478bd9Sstevel@tonic-gate #include <net/if.h> 727c478bd9Sstevel@tonic-gate #include <net/route.h> 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate #include <inet/mib2.h> 757c478bd9Sstevel@tonic-gate #include <inet/ip.h> 767c478bd9Sstevel@tonic-gate #include <inet/arp.h> 777c478bd9Sstevel@tonic-gate #include <inet/tcp.h> 787c478bd9Sstevel@tonic-gate #include <netinet/igmp_var.h> 797c478bd9Sstevel@tonic-gate #include <netinet/ip_mroute.h> 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 827c478bd9Sstevel@tonic-gate #include <netdb.h> 837c478bd9Sstevel@tonic-gate #include <fcntl.h> 847c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h> 857c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate #include <netinet/dhcp.h> 887c478bd9Sstevel@tonic-gate #include <dhcpagent_ipc.h> 897c478bd9Sstevel@tonic-gate #include <dhcpagent_util.h> 907c478bd9Sstevel@tonic-gate #include <compat.h> 917c478bd9Sstevel@tonic-gate 9245916cd2Sjpk #include <libtsnet.h> 9345916cd2Sjpk #include <tsol/label.h> 9445916cd2Sjpk 957c478bd9Sstevel@tonic-gate extern void unixpr(kstat_ctl_t *kc); 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate #define STR_EXPAND 4 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate #define V4MASK_TO_V6(v4, v6) ((v6)._S6_un._S6_u32[0] = 0xfffffffful, \ 1007c478bd9Sstevel@tonic-gate (v6)._S6_un._S6_u32[1] = 0xfffffffful, \ 1017c478bd9Sstevel@tonic-gate (v6)._S6_un._S6_u32[2] = 0xfffffffful, \ 1027c478bd9Sstevel@tonic-gate (v6)._S6_un._S6_u32[3] = (v4)) 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate #define IN6_IS_V4MASK(v6) ((v6)._S6_un._S6_u32[0] == 0xfffffffful && \ 1057c478bd9Sstevel@tonic-gate (v6)._S6_un._S6_u32[1] == 0xfffffffful && \ 1067c478bd9Sstevel@tonic-gate (v6)._S6_un._S6_u32[2] == 0xfffffffful) 1077c478bd9Sstevel@tonic-gate 108d04ccbb3Scarlsonj /* 109d04ccbb3Scarlsonj * This is used as a cushion in the buffer allocation directed by SIOCGLIFNUM. 110d04ccbb3Scarlsonj * Because there's no locking between SIOCGLIFNUM and SIOCGLIFCONF, it's 111d04ccbb3Scarlsonj * possible for an administrator to plumb new interfaces between those two 112d04ccbb3Scarlsonj * calls, resulting in the failure of the latter. This addition makes that 113d04ccbb3Scarlsonj * less likely. 114d04ccbb3Scarlsonj */ 115d04ccbb3Scarlsonj #define LIFN_GUARD_VALUE 10 116d04ccbb3Scarlsonj 1177c478bd9Sstevel@tonic-gate typedef struct mib_item_s { 1187c478bd9Sstevel@tonic-gate struct mib_item_s *next_item; 1197c478bd9Sstevel@tonic-gate int group; 1207c478bd9Sstevel@tonic-gate int mib_id; 1217c478bd9Sstevel@tonic-gate int length; 1227c478bd9Sstevel@tonic-gate void *valp; 1237c478bd9Sstevel@tonic-gate } mib_item_t; 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate struct ifstat { 1267c478bd9Sstevel@tonic-gate uint64_t ipackets; 1277c478bd9Sstevel@tonic-gate uint64_t ierrors; 1287c478bd9Sstevel@tonic-gate uint64_t opackets; 1297c478bd9Sstevel@tonic-gate uint64_t oerrors; 1307c478bd9Sstevel@tonic-gate uint64_t collisions; 1317c478bd9Sstevel@tonic-gate }; 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate struct iflist { 1347c478bd9Sstevel@tonic-gate struct iflist *next_if; 1357c478bd9Sstevel@tonic-gate char ifname[LIFNAMSIZ]; 1367c478bd9Sstevel@tonic-gate struct ifstat tot; 1377c478bd9Sstevel@tonic-gate }; 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate static mib_item_t *mibget(int sd); 1407c478bd9Sstevel@tonic-gate static void mibfree(mib_item_t *firstitem); 1417c478bd9Sstevel@tonic-gate static int mibopen(void); 1427c478bd9Sstevel@tonic-gate static void mib_get_constants(mib_item_t *item); 1437c478bd9Sstevel@tonic-gate static mib_item_t *mib_item_dup(mib_item_t *item); 1447c478bd9Sstevel@tonic-gate static mib_item_t *mib_item_diff(mib_item_t *item1, 1457c478bd9Sstevel@tonic-gate mib_item_t *item2); 1467c478bd9Sstevel@tonic-gate static void mib_item_destroy(mib_item_t **item); 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate static boolean_t octetstrmatch(const Octet_t *a, const Octet_t *b); 14945916cd2Sjpk static char *octetstr(const Octet_t *op, int code, 1507c478bd9Sstevel@tonic-gate char *dst, uint_t dstlen); 1517c478bd9Sstevel@tonic-gate static char *pr_addr(uint_t addr, 1527c478bd9Sstevel@tonic-gate char *dst, uint_t dstlen); 1537c478bd9Sstevel@tonic-gate static char *pr_addrnz(ipaddr_t addr, char *dst, uint_t dstlen); 1547c478bd9Sstevel@tonic-gate static char *pr_addr6(const in6_addr_t *addr, 1557c478bd9Sstevel@tonic-gate char *dst, uint_t dstlen); 1567c478bd9Sstevel@tonic-gate static char *pr_mask(uint_t addr, 1577c478bd9Sstevel@tonic-gate char *dst, uint_t dstlen); 15845916cd2Sjpk static char *pr_prefix6(const struct in6_addr *addr, 15945916cd2Sjpk uint_t prefixlen, char *dst, uint_t dstlen); 1607c478bd9Sstevel@tonic-gate static char *pr_ap(uint_t addr, uint_t port, 1617c478bd9Sstevel@tonic-gate char *proto, char *dst, uint_t dstlen); 1627c478bd9Sstevel@tonic-gate static char *pr_ap6(const in6_addr_t *addr, uint_t port, 1637c478bd9Sstevel@tonic-gate char *proto, char *dst, uint_t dstlen); 1647c478bd9Sstevel@tonic-gate static char *pr_net(uint_t addr, uint_t mask, 1657c478bd9Sstevel@tonic-gate char *dst, uint_t dstlen); 1667c478bd9Sstevel@tonic-gate static char *pr_netaddr(uint_t addr, uint_t mask, 1677c478bd9Sstevel@tonic-gate char *dst, uint_t dstlen); 1687c478bd9Sstevel@tonic-gate static char *fmodestr(uint_t fmode); 1697c478bd9Sstevel@tonic-gate static char *portname(uint_t port, char *proto, 1707c478bd9Sstevel@tonic-gate char *dst, uint_t dstlen); 1717c478bd9Sstevel@tonic-gate 17245916cd2Sjpk static const char *mitcp_state(int code, 17345916cd2Sjpk const mib2_transportMLPEntry_t *attr); 17445916cd2Sjpk static const char *miudp_state(int code, 17545916cd2Sjpk const mib2_transportMLPEntry_t *attr); 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate static void stat_report(mib_item_t *item); 1787c478bd9Sstevel@tonic-gate static void mrt_stat_report(mib_item_t *item); 1797c478bd9Sstevel@tonic-gate static void arp_report(mib_item_t *item); 1807c478bd9Sstevel@tonic-gate static void ndp_report(mib_item_t *item); 1817c478bd9Sstevel@tonic-gate static void mrt_report(mib_item_t *item); 1827c478bd9Sstevel@tonic-gate static void if_stat_total(struct ifstat *oldstats, 1837c478bd9Sstevel@tonic-gate struct ifstat *newstats, struct ifstat *sumstats); 1847c478bd9Sstevel@tonic-gate static void if_report(mib_item_t *item, char *ifname, 1857c478bd9Sstevel@tonic-gate int Iflag_only, boolean_t once_only); 1867c478bd9Sstevel@tonic-gate static void if_report_ip4(mib2_ipAddrEntry_t *ap, 1877c478bd9Sstevel@tonic-gate char ifname[], char logintname[], 1887c478bd9Sstevel@tonic-gate struct ifstat *statptr, boolean_t ksp_not_null); 1897c478bd9Sstevel@tonic-gate static void if_report_ip6(mib2_ipv6AddrEntry_t *ap6, 1907c478bd9Sstevel@tonic-gate char ifname[], char logintname[], 1917c478bd9Sstevel@tonic-gate struct ifstat *statptr, boolean_t ksp_not_null); 19245916cd2Sjpk static void ire_report(const mib_item_t *item); 19345916cd2Sjpk static void tcp_report(const mib_item_t *item); 19445916cd2Sjpk static void udp_report(const mib_item_t *item); 1957c478bd9Sstevel@tonic-gate static void group_report(mib_item_t *item); 1967c478bd9Sstevel@tonic-gate static void print_ip_stats(mib2_ip_t *ip); 1977c478bd9Sstevel@tonic-gate static void print_icmp_stats(mib2_icmp_t *icmp); 1987c478bd9Sstevel@tonic-gate static void print_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6); 1997c478bd9Sstevel@tonic-gate static void print_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6); 2007c478bd9Sstevel@tonic-gate static void print_sctp_stats(mib2_sctp_t *tcp); 2017c478bd9Sstevel@tonic-gate static void print_tcp_stats(mib2_tcp_t *tcp); 2027c478bd9Sstevel@tonic-gate static void print_udp_stats(mib2_udp_t *udp); 2037c478bd9Sstevel@tonic-gate static void print_rawip_stats(mib2_rawip_t *rawip); 2047c478bd9Sstevel@tonic-gate static void print_igmp_stats(struct igmpstat *igps); 2057c478bd9Sstevel@tonic-gate static void print_mrt_stats(struct mrtstat *mrts); 20645916cd2Sjpk static void sctp_report(const mib_item_t *item); 2077c478bd9Sstevel@tonic-gate static void sum_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6, 2087c478bd9Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t *sum6); 2097c478bd9Sstevel@tonic-gate static void sum_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6, 2107c478bd9Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t *sum6); 2117c478bd9Sstevel@tonic-gate static void m_report(void); 2127c478bd9Sstevel@tonic-gate static void dhcp_report(char *); 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate void fail(int, char *, ...); 2157c478bd9Sstevel@tonic-gate static uint64_t kstat_named_value(kstat_t *, char *); 2167c478bd9Sstevel@tonic-gate static kid_t safe_kstat_read(kstat_ctl_t *, kstat_t *, void *); 2177c478bd9Sstevel@tonic-gate static int isnum(char *); 2187c478bd9Sstevel@tonic-gate static char *plural(int n); 2197c478bd9Sstevel@tonic-gate static char *pluraly(int n); 2207c478bd9Sstevel@tonic-gate static char *plurales(int n); 2217c478bd9Sstevel@tonic-gate static void process_filter(char *arg); 222*e11c3f44Smeem static char *ifindex2str(uint_t, char *); 2237c478bd9Sstevel@tonic-gate static boolean_t family_selected(int family); 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate static void usage(char *); 2267c478bd9Sstevel@tonic-gate static void fatal(int errcode, char *str1, ...); 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate #define PLURAL(n) plural((int)n) 2297c478bd9Sstevel@tonic-gate #define PLURALY(n) pluraly((int)n) 2307c478bd9Sstevel@tonic-gate #define PLURALES(n) plurales((int)n) 2317c478bd9Sstevel@tonic-gate #define IFLAGMOD(flg, val1, val2) if (flg == val1) flg = val2 2327c478bd9Sstevel@tonic-gate #define MDIFF(diff, elem2, elem1, member) (diff)->member = \ 2337c478bd9Sstevel@tonic-gate (elem2)->member - (elem1)->member 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate static boolean_t Aflag = B_FALSE; /* All sockets/ifs/rtng-tbls */ 2377c478bd9Sstevel@tonic-gate static boolean_t Dflag = B_FALSE; /* Debug Info */ 2387c478bd9Sstevel@tonic-gate static boolean_t Iflag = B_FALSE; /* IP Traffic Interfaces */ 2397c478bd9Sstevel@tonic-gate static boolean_t Mflag = B_FALSE; /* STREAMS Memory Statistics */ 2407c478bd9Sstevel@tonic-gate static boolean_t Nflag = B_FALSE; /* Numeric Network Addresses */ 2417c478bd9Sstevel@tonic-gate static boolean_t Rflag = B_FALSE; /* Routing Tables */ 24245916cd2Sjpk static boolean_t RSECflag = B_FALSE; /* Security attributes */ 2437c478bd9Sstevel@tonic-gate static boolean_t Sflag = B_FALSE; /* Per-protocol Statistics */ 2447c478bd9Sstevel@tonic-gate static boolean_t Vflag = B_FALSE; /* Verbose */ 2457c478bd9Sstevel@tonic-gate static boolean_t Pflag = B_FALSE; /* Net to Media Tables */ 2467c478bd9Sstevel@tonic-gate static boolean_t Gflag = B_FALSE; /* Multicast group membership */ 2477c478bd9Sstevel@tonic-gate static boolean_t MMflag = B_FALSE; /* Multicast routing table */ 2487c478bd9Sstevel@tonic-gate static boolean_t DHCPflag = B_FALSE; /* DHCP statistics */ 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate static int v4compat = 0; /* Compatible printing format for status */ 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate static int proto = IPPROTO_MAX; /* all protocols */ 2537c478bd9Sstevel@tonic-gate kstat_ctl_t *kc = NULL; 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate /* 2567c478bd9Sstevel@tonic-gate * Sizes of data structures extracted from the base mib. 2577c478bd9Sstevel@tonic-gate * This allows the size of the tables entries to grow while preserving 2587c478bd9Sstevel@tonic-gate * binary compatibility. 2597c478bd9Sstevel@tonic-gate */ 2607c478bd9Sstevel@tonic-gate static int ipAddrEntrySize; 2617c478bd9Sstevel@tonic-gate static int ipRouteEntrySize; 2627c478bd9Sstevel@tonic-gate static int ipNetToMediaEntrySize; 2637c478bd9Sstevel@tonic-gate static int ipMemberEntrySize; 2647c478bd9Sstevel@tonic-gate static int ipGroupSourceEntrySize; 26545916cd2Sjpk static int ipRouteAttributeSize; 2667c478bd9Sstevel@tonic-gate static int vifctlSize; 2677c478bd9Sstevel@tonic-gate static int mfcctlSize; 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate static int ipv6IfStatsEntrySize; 2707c478bd9Sstevel@tonic-gate static int ipv6IfIcmpEntrySize; 2717c478bd9Sstevel@tonic-gate static int ipv6AddrEntrySize; 2727c478bd9Sstevel@tonic-gate static int ipv6RouteEntrySize; 2737c478bd9Sstevel@tonic-gate static int ipv6NetToMediaEntrySize; 2747c478bd9Sstevel@tonic-gate static int ipv6MemberEntrySize; 2757c478bd9Sstevel@tonic-gate static int ipv6GroupSourceEntrySize; 2767c478bd9Sstevel@tonic-gate 27745916cd2Sjpk static int transportMLPSize; 2787c478bd9Sstevel@tonic-gate static int tcpConnEntrySize; 2797c478bd9Sstevel@tonic-gate static int tcp6ConnEntrySize; 2807c478bd9Sstevel@tonic-gate static int udpEntrySize; 2817c478bd9Sstevel@tonic-gate static int udp6EntrySize; 2827c478bd9Sstevel@tonic-gate static int sctpEntrySize; 2837c478bd9Sstevel@tonic-gate static int sctpLocalEntrySize; 2847c478bd9Sstevel@tonic-gate static int sctpRemoteEntrySize; 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate #define protocol_selected(p) (proto == IPPROTO_MAX || proto == (p)) 2877c478bd9Sstevel@tonic-gate 2887c478bd9Sstevel@tonic-gate /* Machinery used for -f (filter) option */ 2895c0b7edeSseb enum { FK_AF = 0, FK_OUTIF, FK_DST, FK_FLAGS, NFILTERKEYS }; 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate static const char *filter_keys[NFILTERKEYS] = { 2925c0b7edeSseb "af", "outif", "dst", "flags" 2937c478bd9Sstevel@tonic-gate }; 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate /* Flags on routes */ 2967c478bd9Sstevel@tonic-gate #define FLF_A 0x00000001 2977c478bd9Sstevel@tonic-gate #define FLF_B 0x00000002 2987c478bd9Sstevel@tonic-gate #define FLF_D 0x00000004 2997c478bd9Sstevel@tonic-gate #define FLF_G 0x00000008 3007c478bd9Sstevel@tonic-gate #define FLF_H 0x00000010 3017c478bd9Sstevel@tonic-gate #define FLF_L 0x00000020 3027c478bd9Sstevel@tonic-gate #define FLF_U 0x00000040 3037c478bd9Sstevel@tonic-gate #define FLF_M 0x00000080 3047c478bd9Sstevel@tonic-gate #define FLF_S 0x00000100 3057c478bd9Sstevel@tonic-gate static const char flag_list[] = "ABDGHLUMS"; 3067c478bd9Sstevel@tonic-gate 3077c478bd9Sstevel@tonic-gate typedef struct filter_rule filter_t; 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate struct filter_rule { 3107c478bd9Sstevel@tonic-gate filter_t *f_next; 3117c478bd9Sstevel@tonic-gate union { 3127c478bd9Sstevel@tonic-gate int f_family; 3137c478bd9Sstevel@tonic-gate const char *f_ifname; 3147c478bd9Sstevel@tonic-gate struct { 3157c478bd9Sstevel@tonic-gate struct hostent *f_address; 3167c478bd9Sstevel@tonic-gate in6_addr_t f_mask; 3177c478bd9Sstevel@tonic-gate } a; 3187c478bd9Sstevel@tonic-gate struct { 3197c478bd9Sstevel@tonic-gate uint_t f_flagset; 3207c478bd9Sstevel@tonic-gate uint_t f_flagclear; 3217c478bd9Sstevel@tonic-gate } f; 3227c478bd9Sstevel@tonic-gate } u; 3237c478bd9Sstevel@tonic-gate }; 3247c478bd9Sstevel@tonic-gate 3257c478bd9Sstevel@tonic-gate /* 3267c478bd9Sstevel@tonic-gate * The user-specified filters are linked into lists separated by 3277c478bd9Sstevel@tonic-gate * keyword (type of filter). Thus, the matching algorithm is: 3287c478bd9Sstevel@tonic-gate * For each non-empty filter list 3297c478bd9Sstevel@tonic-gate * If no filters in the list match 3307c478bd9Sstevel@tonic-gate * then stop here; route doesn't match 3317c478bd9Sstevel@tonic-gate * If loop above completes, then route does match and will be 3327c478bd9Sstevel@tonic-gate * displayed. 3337c478bd9Sstevel@tonic-gate */ 3347c478bd9Sstevel@tonic-gate static filter_t *filters[NFILTERKEYS]; 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate int 3377c478bd9Sstevel@tonic-gate main(int argc, char **argv) 3387c478bd9Sstevel@tonic-gate { 3397c478bd9Sstevel@tonic-gate char *name; 3407c478bd9Sstevel@tonic-gate mib_item_t *item = NULL; 3417c478bd9Sstevel@tonic-gate mib_item_t *previtem = NULL; 3427c478bd9Sstevel@tonic-gate int sd = -1; 3437c478bd9Sstevel@tonic-gate char *ifname = NULL; 3447c478bd9Sstevel@tonic-gate int interval = 0; /* Single time by default */ 3457c478bd9Sstevel@tonic-gate int count = -1; /* Forever */ 3467c478bd9Sstevel@tonic-gate int c; 3477c478bd9Sstevel@tonic-gate int d; 3487c478bd9Sstevel@tonic-gate /* 3497c478bd9Sstevel@tonic-gate * Possible values of 'Iflag_only': 3507c478bd9Sstevel@tonic-gate * -1, no feature-flags; 3517c478bd9Sstevel@tonic-gate * 0, IFlag and other feature-flags enabled 3527c478bd9Sstevel@tonic-gate * 1, IFlag is the only feature-flag enabled 3537c478bd9Sstevel@tonic-gate * : trinary variable, modified using IFLAGMOD() 3547c478bd9Sstevel@tonic-gate */ 3557c478bd9Sstevel@tonic-gate int Iflag_only = -1; 3567c478bd9Sstevel@tonic-gate boolean_t once_only = B_FALSE; /* '-i' with count > 1 */ 3577c478bd9Sstevel@tonic-gate extern char *optarg; 3587c478bd9Sstevel@tonic-gate extern int optind; 3597c478bd9Sstevel@tonic-gate char *default_ip_str = NULL; 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate name = argv[0]; 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate v4compat = get_compat_flag(&default_ip_str); 3647c478bd9Sstevel@tonic-gate if (v4compat == DEFAULT_PROT_BAD_VALUE) 3657c478bd9Sstevel@tonic-gate fatal(2, "%s: %s: Bad value for %s in %s\n", name, 3667c478bd9Sstevel@tonic-gate default_ip_str, DEFAULT_IP, INET_DEFAULT_FILE); 3677c478bd9Sstevel@tonic-gate free(default_ip_str); 3687c478bd9Sstevel@tonic-gate 36945916cd2Sjpk while ((c = getopt(argc, argv, "adimnrspMgvf:P:I:DR")) != -1) { 3707c478bd9Sstevel@tonic-gate switch ((char)c) { 3717c478bd9Sstevel@tonic-gate case 'a': /* all connections */ 3727c478bd9Sstevel@tonic-gate Aflag = B_TRUE; 3737c478bd9Sstevel@tonic-gate break; 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate case 'd': /* turn on debugging */ 3767c478bd9Sstevel@tonic-gate Dflag = B_TRUE; 3777c478bd9Sstevel@tonic-gate break; 3787c478bd9Sstevel@tonic-gate 3797c478bd9Sstevel@tonic-gate case 'i': /* interface (ill/ipif report) */ 3807c478bd9Sstevel@tonic-gate Iflag = B_TRUE; 3817c478bd9Sstevel@tonic-gate IFLAGMOD(Iflag_only, -1, 1); /* '-i' exists */ 3827c478bd9Sstevel@tonic-gate break; 3837c478bd9Sstevel@tonic-gate 3847c478bd9Sstevel@tonic-gate case 'm': /* streams msg report */ 3857c478bd9Sstevel@tonic-gate Mflag = B_TRUE; 3867c478bd9Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */ 3877c478bd9Sstevel@tonic-gate break; 3887c478bd9Sstevel@tonic-gate 3897c478bd9Sstevel@tonic-gate case 'n': /* numeric format */ 3907c478bd9Sstevel@tonic-gate Nflag = B_TRUE; 3917c478bd9Sstevel@tonic-gate break; 3927c478bd9Sstevel@tonic-gate 3937c478bd9Sstevel@tonic-gate case 'r': /* route tables */ 3947c478bd9Sstevel@tonic-gate Rflag = B_TRUE; 3957c478bd9Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */ 3967c478bd9Sstevel@tonic-gate break; 3977c478bd9Sstevel@tonic-gate 39845916cd2Sjpk case 'R': /* security attributes */ 39945916cd2Sjpk RSECflag = B_TRUE; 40045916cd2Sjpk IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */ 40145916cd2Sjpk break; 40245916cd2Sjpk 4037c478bd9Sstevel@tonic-gate case 's': /* per-protocol statistics */ 4047c478bd9Sstevel@tonic-gate Sflag = B_TRUE; 4057c478bd9Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */ 4067c478bd9Sstevel@tonic-gate break; 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate case 'p': /* arp/ndp table */ 4097c478bd9Sstevel@tonic-gate Pflag = B_TRUE; 4107c478bd9Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */ 4117c478bd9Sstevel@tonic-gate break; 4127c478bd9Sstevel@tonic-gate 4137c478bd9Sstevel@tonic-gate case 'M': /* multicast routing tables */ 4147c478bd9Sstevel@tonic-gate MMflag = B_TRUE; 4157c478bd9Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */ 4167c478bd9Sstevel@tonic-gate break; 4177c478bd9Sstevel@tonic-gate 4187c478bd9Sstevel@tonic-gate case 'g': /* multicast group membership */ 4197c478bd9Sstevel@tonic-gate Gflag = B_TRUE; 4207c478bd9Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */ 4217c478bd9Sstevel@tonic-gate break; 4227c478bd9Sstevel@tonic-gate 4237c478bd9Sstevel@tonic-gate case 'v': /* verbose output format */ 4247c478bd9Sstevel@tonic-gate Vflag = B_TRUE; 4257c478bd9Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */ 4267c478bd9Sstevel@tonic-gate break; 4277c478bd9Sstevel@tonic-gate 4287c478bd9Sstevel@tonic-gate case 'f': 4297c478bd9Sstevel@tonic-gate process_filter(optarg); 4307c478bd9Sstevel@tonic-gate break; 4317c478bd9Sstevel@tonic-gate 4327c478bd9Sstevel@tonic-gate case 'P': 4337c478bd9Sstevel@tonic-gate if (strcmp(optarg, "ip") == 0) { 4347c478bd9Sstevel@tonic-gate proto = IPPROTO_IP; 4357c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, "ipv6") == 0 || 4367c478bd9Sstevel@tonic-gate strcmp(optarg, "ip6") == 0) { 4377c478bd9Sstevel@tonic-gate v4compat = 0; /* Overridden */ 4387c478bd9Sstevel@tonic-gate proto = IPPROTO_IPV6; 4397c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, "icmp") == 0) { 4407c478bd9Sstevel@tonic-gate proto = IPPROTO_ICMP; 4417c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, "icmpv6") == 0 || 4427c478bd9Sstevel@tonic-gate strcmp(optarg, "icmp6") == 0) { 4437c478bd9Sstevel@tonic-gate v4compat = 0; /* Overridden */ 4447c478bd9Sstevel@tonic-gate proto = IPPROTO_ICMPV6; 4457c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, "igmp") == 0) { 4467c478bd9Sstevel@tonic-gate proto = IPPROTO_IGMP; 4477c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, "udp") == 0) { 4487c478bd9Sstevel@tonic-gate proto = IPPROTO_UDP; 4497c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, "tcp") == 0) { 4507c478bd9Sstevel@tonic-gate proto = IPPROTO_TCP; 4517c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, "sctp") == 0) { 4527c478bd9Sstevel@tonic-gate proto = IPPROTO_SCTP; 4537c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, "raw") == 0 || 4547c478bd9Sstevel@tonic-gate strcmp(optarg, "rawip") == 0) { 4557c478bd9Sstevel@tonic-gate proto = IPPROTO_RAW; 4567c478bd9Sstevel@tonic-gate } else { 4577c478bd9Sstevel@tonic-gate fatal(1, "%s: unknown protocol.\n", optarg); 4587c478bd9Sstevel@tonic-gate } 4597c478bd9Sstevel@tonic-gate break; 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate case 'I': 4627c478bd9Sstevel@tonic-gate ifname = optarg; 4637c478bd9Sstevel@tonic-gate Iflag = B_TRUE; 4647c478bd9Sstevel@tonic-gate IFLAGMOD(Iflag_only, -1, 1); /* see macro def'n */ 4657c478bd9Sstevel@tonic-gate break; 4667c478bd9Sstevel@tonic-gate 4677c478bd9Sstevel@tonic-gate case 'D': 4687c478bd9Sstevel@tonic-gate DHCPflag = B_TRUE; 4697c478bd9Sstevel@tonic-gate Iflag_only = 0; 4707c478bd9Sstevel@tonic-gate break; 4717c478bd9Sstevel@tonic-gate 4727c478bd9Sstevel@tonic-gate case '?': 4737c478bd9Sstevel@tonic-gate default: 4747c478bd9Sstevel@tonic-gate usage(name); 4757c478bd9Sstevel@tonic-gate } 4767c478bd9Sstevel@tonic-gate } 4777c478bd9Sstevel@tonic-gate 47845916cd2Sjpk /* 47945916cd2Sjpk * Make sure -R option is set only on a labeled system. 48045916cd2Sjpk */ 48145916cd2Sjpk if (RSECflag && !is_system_labeled()) { 48245916cd2Sjpk (void) fprintf(stderr, "-R set but labeling is not enabled\n"); 48345916cd2Sjpk usage(name); 48445916cd2Sjpk } 48545916cd2Sjpk 4867c478bd9Sstevel@tonic-gate /* 4877c478bd9Sstevel@tonic-gate * Handle other arguments: find interval, count; the 4887c478bd9Sstevel@tonic-gate * flags that accept 'interval' and 'count' are OR'd 4897c478bd9Sstevel@tonic-gate * in the outermost 'if'; more flags may be added as 4907c478bd9Sstevel@tonic-gate * required 4917c478bd9Sstevel@tonic-gate */ 4927c478bd9Sstevel@tonic-gate if (Iflag || Sflag || Mflag) { 4937c478bd9Sstevel@tonic-gate for (d = optind; d < argc; d++) { 4947c478bd9Sstevel@tonic-gate if (isnum(argv[d])) { 4957c478bd9Sstevel@tonic-gate interval = atoi(argv[d]); 4967c478bd9Sstevel@tonic-gate if (d + 1 < argc && 4977c478bd9Sstevel@tonic-gate isnum(argv[d + 1])) { 4987c478bd9Sstevel@tonic-gate count = atoi(argv[d + 1]); 4997c478bd9Sstevel@tonic-gate optind++; 5007c478bd9Sstevel@tonic-gate } 5017c478bd9Sstevel@tonic-gate optind++; 5027c478bd9Sstevel@tonic-gate if (interval == 0 || count == 0) 5037c478bd9Sstevel@tonic-gate usage(name); 5047c478bd9Sstevel@tonic-gate break; 5057c478bd9Sstevel@tonic-gate } 5067c478bd9Sstevel@tonic-gate } 5077c478bd9Sstevel@tonic-gate } 5087c478bd9Sstevel@tonic-gate if (optind < argc) { 5097c478bd9Sstevel@tonic-gate if (Iflag && isnum(argv[optind])) { 5107c478bd9Sstevel@tonic-gate count = atoi(argv[optind]); 5117c478bd9Sstevel@tonic-gate if (count == 0) 5127c478bd9Sstevel@tonic-gate usage(name); 5137c478bd9Sstevel@tonic-gate optind++; 5147c478bd9Sstevel@tonic-gate } 5157c478bd9Sstevel@tonic-gate } 5167c478bd9Sstevel@tonic-gate if (optind < argc) { 5177c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 5187c478bd9Sstevel@tonic-gate "%s: extra arguments\n", name); 5197c478bd9Sstevel@tonic-gate usage(name); 5207c478bd9Sstevel@tonic-gate } 5217c478bd9Sstevel@tonic-gate if (interval) 5227c478bd9Sstevel@tonic-gate setbuf(stdout, NULL); 5237c478bd9Sstevel@tonic-gate 5247c478bd9Sstevel@tonic-gate if (DHCPflag) { 5257c478bd9Sstevel@tonic-gate dhcp_report(Iflag ? ifname : NULL); 5267c478bd9Sstevel@tonic-gate exit(0); 5277c478bd9Sstevel@tonic-gate } 5287c478bd9Sstevel@tonic-gate 5297c478bd9Sstevel@tonic-gate /* Get data structures: priming before iteration */ 5307c478bd9Sstevel@tonic-gate if (family_selected(AF_INET) || family_selected(AF_INET6)) { 5317c478bd9Sstevel@tonic-gate sd = mibopen(); 5327c478bd9Sstevel@tonic-gate if (sd == -1) 5337c478bd9Sstevel@tonic-gate fatal(1, "can't open mib stream\n"); 5347c478bd9Sstevel@tonic-gate if ((item = mibget(sd)) == NULL) { 5357c478bd9Sstevel@tonic-gate (void) close(sd); 5367c478bd9Sstevel@tonic-gate fatal(1, "mibget() failed\n"); 5377c478bd9Sstevel@tonic-gate } 5387c478bd9Sstevel@tonic-gate /* Extract constant sizes - need do once only */ 5397c478bd9Sstevel@tonic-gate mib_get_constants(item); 5407c478bd9Sstevel@tonic-gate } 5417c478bd9Sstevel@tonic-gate if ((kc = kstat_open()) == NULL) { 5427c478bd9Sstevel@tonic-gate mibfree(item); 5437c478bd9Sstevel@tonic-gate (void) close(sd); 5447c478bd9Sstevel@tonic-gate fail(1, "kstat_open(): can't open /dev/kstat"); 5457c478bd9Sstevel@tonic-gate } 5467c478bd9Sstevel@tonic-gate 5477c478bd9Sstevel@tonic-gate if (interval <= 0) { 5487c478bd9Sstevel@tonic-gate count = 1; 5497c478bd9Sstevel@tonic-gate once_only = B_TRUE; 5507c478bd9Sstevel@tonic-gate } 5517c478bd9Sstevel@tonic-gate /* 'for' loop 1: */ 5527c478bd9Sstevel@tonic-gate for (;;) { 5537c478bd9Sstevel@tonic-gate mib_item_t *curritem = NULL; /* only for -[M]s */ 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate /* netstat: AF_INET[6] behaviour */ 5567c478bd9Sstevel@tonic-gate if (family_selected(AF_INET) || family_selected(AF_INET6)) { 5577c478bd9Sstevel@tonic-gate if (Sflag) { 5587c478bd9Sstevel@tonic-gate curritem = mib_item_diff(previtem, item); 5597c478bd9Sstevel@tonic-gate if (curritem == NULL) 5607c478bd9Sstevel@tonic-gate fatal(1, "can't process mib data, " 5617c478bd9Sstevel@tonic-gate "out of memory\n"); 5627c478bd9Sstevel@tonic-gate mib_item_destroy(&previtem); 5637c478bd9Sstevel@tonic-gate } 5647c478bd9Sstevel@tonic-gate 5657c478bd9Sstevel@tonic-gate if (!(Iflag || Rflag || Sflag || Mflag || 5667c478bd9Sstevel@tonic-gate MMflag || Pflag || Gflag || DHCPflag)) { 5677c478bd9Sstevel@tonic-gate if (protocol_selected(IPPROTO_UDP)) 5687c478bd9Sstevel@tonic-gate udp_report(item); 5697c478bd9Sstevel@tonic-gate if (protocol_selected(IPPROTO_TCP)) 5707c478bd9Sstevel@tonic-gate tcp_report(item); 5717c478bd9Sstevel@tonic-gate if (protocol_selected(IPPROTO_SCTP)) 5727c478bd9Sstevel@tonic-gate sctp_report(item); 5737c478bd9Sstevel@tonic-gate } 5747c478bd9Sstevel@tonic-gate if (Iflag) 5757c478bd9Sstevel@tonic-gate if_report(item, ifname, Iflag_only, once_only); 5767c478bd9Sstevel@tonic-gate if (Mflag) 5777c478bd9Sstevel@tonic-gate m_report(); 5787c478bd9Sstevel@tonic-gate if (Rflag) 5797c478bd9Sstevel@tonic-gate ire_report(item); 5807c478bd9Sstevel@tonic-gate if (Sflag && MMflag) { 5817c478bd9Sstevel@tonic-gate mrt_stat_report(curritem); 5827c478bd9Sstevel@tonic-gate } else { 5837c478bd9Sstevel@tonic-gate if (Sflag) 5847c478bd9Sstevel@tonic-gate stat_report(curritem); 5857c478bd9Sstevel@tonic-gate if (MMflag) 5867c478bd9Sstevel@tonic-gate mrt_report(item); 5877c478bd9Sstevel@tonic-gate } 5887c478bd9Sstevel@tonic-gate if (Gflag) 5897c478bd9Sstevel@tonic-gate group_report(item); 5907c478bd9Sstevel@tonic-gate if (Pflag) { 5917c478bd9Sstevel@tonic-gate if (family_selected(AF_INET)) 5927c478bd9Sstevel@tonic-gate arp_report(item); 5937c478bd9Sstevel@tonic-gate if (family_selected(AF_INET6)) 5947c478bd9Sstevel@tonic-gate ndp_report(item); 5957c478bd9Sstevel@tonic-gate } 5967c478bd9Sstevel@tonic-gate mib_item_destroy(&curritem); 5977c478bd9Sstevel@tonic-gate } 5987c478bd9Sstevel@tonic-gate 5997c478bd9Sstevel@tonic-gate /* netstat: AF_UNIX behaviour */ 6007c478bd9Sstevel@tonic-gate if (family_selected(AF_UNIX) && 6017c478bd9Sstevel@tonic-gate (!(Iflag || Rflag || Sflag || Mflag || 6027c478bd9Sstevel@tonic-gate MMflag || Pflag || Gflag))) 6037c478bd9Sstevel@tonic-gate unixpr(kc); 6047c478bd9Sstevel@tonic-gate (void) kstat_close(kc); 6057c478bd9Sstevel@tonic-gate 6067c478bd9Sstevel@tonic-gate /* iteration handling code */ 6077c478bd9Sstevel@tonic-gate if (count > 0 && --count == 0) 6087c478bd9Sstevel@tonic-gate break; 6097c478bd9Sstevel@tonic-gate (void) sleep(interval); 6107c478bd9Sstevel@tonic-gate 6117c478bd9Sstevel@tonic-gate /* re-populating of data structures */ 6127c478bd9Sstevel@tonic-gate if (family_selected(AF_INET) || family_selected(AF_INET6)) { 6137c478bd9Sstevel@tonic-gate if (Sflag) { 6147c478bd9Sstevel@tonic-gate /* previtem is a cut-down list */ 6157c478bd9Sstevel@tonic-gate previtem = mib_item_dup(item); 6167c478bd9Sstevel@tonic-gate if (previtem == NULL) 6177c478bd9Sstevel@tonic-gate fatal(1, "can't process mib data, " 6187c478bd9Sstevel@tonic-gate "out of memory\n"); 6197c478bd9Sstevel@tonic-gate } 6207c478bd9Sstevel@tonic-gate mibfree(item); 6217c478bd9Sstevel@tonic-gate (void) close(sd); 6227c478bd9Sstevel@tonic-gate if ((sd = mibopen()) == -1) 6237c478bd9Sstevel@tonic-gate fatal(1, "can't open mib stream anymore\n"); 6247c478bd9Sstevel@tonic-gate if ((item = mibget(sd)) == NULL) { 6257c478bd9Sstevel@tonic-gate (void) close(sd); 6267c478bd9Sstevel@tonic-gate fatal(1, "mibget() failed\n"); 6277c478bd9Sstevel@tonic-gate } 6287c478bd9Sstevel@tonic-gate } 6297c478bd9Sstevel@tonic-gate if ((kc = kstat_open()) == NULL) 6307c478bd9Sstevel@tonic-gate fail(1, "kstat_open(): can't open /dev/kstat"); 6317c478bd9Sstevel@tonic-gate 6327c478bd9Sstevel@tonic-gate } /* 'for' loop 1 ends */ 6337c478bd9Sstevel@tonic-gate mibfree(item); 6347c478bd9Sstevel@tonic-gate (void) close(sd); 6357c478bd9Sstevel@tonic-gate 6367c478bd9Sstevel@tonic-gate return (0); 6377c478bd9Sstevel@tonic-gate } 6387c478bd9Sstevel@tonic-gate 6397c478bd9Sstevel@tonic-gate 6407c478bd9Sstevel@tonic-gate static int 6417c478bd9Sstevel@tonic-gate isnum(char *p) 6427c478bd9Sstevel@tonic-gate { 6437c478bd9Sstevel@tonic-gate int len; 6447c478bd9Sstevel@tonic-gate int i; 6457c478bd9Sstevel@tonic-gate 6467c478bd9Sstevel@tonic-gate len = strlen(p); 6477c478bd9Sstevel@tonic-gate for (i = 0; i < len; i++) 6487c478bd9Sstevel@tonic-gate if (!isdigit(p[i])) 6497c478bd9Sstevel@tonic-gate return (0); 6507c478bd9Sstevel@tonic-gate return (1); 6517c478bd9Sstevel@tonic-gate } 6527c478bd9Sstevel@tonic-gate 6537c478bd9Sstevel@tonic-gate 6547c478bd9Sstevel@tonic-gate /* --------------------------------- MIBGET -------------------------------- */ 6557c478bd9Sstevel@tonic-gate 6567c478bd9Sstevel@tonic-gate static mib_item_t * 6577c478bd9Sstevel@tonic-gate mibget(int sd) 6587c478bd9Sstevel@tonic-gate { 6597c478bd9Sstevel@tonic-gate /* 6607c478bd9Sstevel@tonic-gate * buf is an automatic for this function, so the 6617c478bd9Sstevel@tonic-gate * compiler has complete control over its alignment; 6627c478bd9Sstevel@tonic-gate * it is assumed this alignment is satisfactory for 6637c478bd9Sstevel@tonic-gate * it to be casted to certain other struct pointers 6647c478bd9Sstevel@tonic-gate * here, such as struct T_optmgmt_ack * . 6657c478bd9Sstevel@tonic-gate */ 6667c478bd9Sstevel@tonic-gate uintptr_t buf[512 / sizeof (uintptr_t)]; 6677c478bd9Sstevel@tonic-gate int flags; 6687c478bd9Sstevel@tonic-gate int i, j, getcode; 6697c478bd9Sstevel@tonic-gate struct strbuf ctlbuf, databuf; 6707c478bd9Sstevel@tonic-gate struct T_optmgmt_req *tor = (struct T_optmgmt_req *)buf; 6717c478bd9Sstevel@tonic-gate struct T_optmgmt_ack *toa = (struct T_optmgmt_ack *)buf; 6727c478bd9Sstevel@tonic-gate struct T_error_ack *tea = (struct T_error_ack *)buf; 6737c478bd9Sstevel@tonic-gate struct opthdr *req; 6747c478bd9Sstevel@tonic-gate mib_item_t *first_item = NULL; 6757c478bd9Sstevel@tonic-gate mib_item_t *last_item = NULL; 6767c478bd9Sstevel@tonic-gate mib_item_t *temp; 6777c478bd9Sstevel@tonic-gate 6787c478bd9Sstevel@tonic-gate tor->PRIM_type = T_SVR4_OPTMGMT_REQ; 6797c478bd9Sstevel@tonic-gate tor->OPT_offset = sizeof (struct T_optmgmt_req); 6807c478bd9Sstevel@tonic-gate tor->OPT_length = sizeof (struct opthdr); 6817c478bd9Sstevel@tonic-gate tor->MGMT_flags = T_CURRENT; 682*e11c3f44Smeem 683*e11c3f44Smeem 684*e11c3f44Smeem /* 685*e11c3f44Smeem * Note: we use the special level value below so that IP will return 686*e11c3f44Smeem * us information concerning IRE_MARK_TESTHIDDEN routes. 687*e11c3f44Smeem */ 6887c478bd9Sstevel@tonic-gate req = (struct opthdr *)&tor[1]; 689*e11c3f44Smeem req->level = EXPER_IP_AND_TESTHIDDEN; 6907c478bd9Sstevel@tonic-gate req->name = 0; 6917c478bd9Sstevel@tonic-gate req->len = 0; 6927c478bd9Sstevel@tonic-gate 6937c478bd9Sstevel@tonic-gate ctlbuf.buf = (char *)buf; 6947c478bd9Sstevel@tonic-gate ctlbuf.len = tor->OPT_length + tor->OPT_offset; 6957c478bd9Sstevel@tonic-gate flags = 0; 6967c478bd9Sstevel@tonic-gate if (putmsg(sd, &ctlbuf, (struct strbuf *)0, flags) == -1) { 6977c478bd9Sstevel@tonic-gate perror("mibget: putmsg(ctl) failed"); 6987c478bd9Sstevel@tonic-gate goto error_exit; 6997c478bd9Sstevel@tonic-gate } 7007c478bd9Sstevel@tonic-gate 7017c478bd9Sstevel@tonic-gate /* 7027c478bd9Sstevel@tonic-gate * Each reply consists of a ctl part for one fixed structure 7037c478bd9Sstevel@tonic-gate * or table, as defined in mib2.h. The format is a T_OPTMGMT_ACK, 7047c478bd9Sstevel@tonic-gate * containing an opthdr structure. level/name identify the entry, 7057c478bd9Sstevel@tonic-gate * len is the size of the data part of the message. 7067c478bd9Sstevel@tonic-gate */ 7077c478bd9Sstevel@tonic-gate req = (struct opthdr *)&toa[1]; 7087c478bd9Sstevel@tonic-gate ctlbuf.maxlen = sizeof (buf); 7097c478bd9Sstevel@tonic-gate j = 1; 7107c478bd9Sstevel@tonic-gate for (;;) { 7117c478bd9Sstevel@tonic-gate flags = 0; 7127c478bd9Sstevel@tonic-gate getcode = getmsg(sd, &ctlbuf, (struct strbuf *)0, &flags); 7137c478bd9Sstevel@tonic-gate if (getcode == -1) { 7147c478bd9Sstevel@tonic-gate perror("mibget getmsg(ctl) failed"); 7157c478bd9Sstevel@tonic-gate if (Dflag) { 7167c478bd9Sstevel@tonic-gate (void) fputs("# level name len\n", 7177c478bd9Sstevel@tonic-gate stderr); 7187c478bd9Sstevel@tonic-gate i = 0; 7197c478bd9Sstevel@tonic-gate for (last_item = first_item; last_item; 720*e11c3f44Smeem last_item = last_item->next_item) 7217c478bd9Sstevel@tonic-gate (void) printf("%d %4d %5d %d\n", 7227c478bd9Sstevel@tonic-gate ++i, 7237c478bd9Sstevel@tonic-gate last_item->group, 7247c478bd9Sstevel@tonic-gate last_item->mib_id, 7257c478bd9Sstevel@tonic-gate last_item->length); 7267c478bd9Sstevel@tonic-gate } 7277c478bd9Sstevel@tonic-gate goto error_exit; 7287c478bd9Sstevel@tonic-gate } 7297c478bd9Sstevel@tonic-gate if (getcode == 0 && 7307c478bd9Sstevel@tonic-gate ctlbuf.len >= sizeof (struct T_optmgmt_ack) && 7317c478bd9Sstevel@tonic-gate toa->PRIM_type == T_OPTMGMT_ACK && 7327c478bd9Sstevel@tonic-gate toa->MGMT_flags == T_SUCCESS && 7337c478bd9Sstevel@tonic-gate req->len == 0) { 7347c478bd9Sstevel@tonic-gate if (Dflag) 7357c478bd9Sstevel@tonic-gate (void) printf("mibget getmsg() %d returned " 7367c478bd9Sstevel@tonic-gate "EOD (level %ld, name %ld)\n", 7377c478bd9Sstevel@tonic-gate j, req->level, req->name); 7387c478bd9Sstevel@tonic-gate return (first_item); /* this is EOD msg */ 7397c478bd9Sstevel@tonic-gate } 7407c478bd9Sstevel@tonic-gate 7417c478bd9Sstevel@tonic-gate if (ctlbuf.len >= sizeof (struct T_error_ack) && 7427c478bd9Sstevel@tonic-gate tea->PRIM_type == T_ERROR_ACK) { 7437c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 7447c478bd9Sstevel@tonic-gate "mibget %d gives T_ERROR_ACK: TLI_error = 0x%lx, " 7457c478bd9Sstevel@tonic-gate "UNIX_error = 0x%lx\n", 7467c478bd9Sstevel@tonic-gate j, tea->TLI_error, tea->UNIX_error); 7477c478bd9Sstevel@tonic-gate 7487c478bd9Sstevel@tonic-gate errno = (tea->TLI_error == TSYSERR) ? 7497c478bd9Sstevel@tonic-gate tea->UNIX_error : EPROTO; 7507c478bd9Sstevel@tonic-gate goto error_exit; 7517c478bd9Sstevel@tonic-gate } 7527c478bd9Sstevel@tonic-gate 7537c478bd9Sstevel@tonic-gate if (getcode != MOREDATA || 7547c478bd9Sstevel@tonic-gate ctlbuf.len < sizeof (struct T_optmgmt_ack) || 7557c478bd9Sstevel@tonic-gate toa->PRIM_type != T_OPTMGMT_ACK || 7567c478bd9Sstevel@tonic-gate toa->MGMT_flags != T_SUCCESS) { 7577c478bd9Sstevel@tonic-gate (void) printf("mibget getmsg(ctl) %d returned %d, " 7587c478bd9Sstevel@tonic-gate "ctlbuf.len = %d, PRIM_type = %ld\n", 7597c478bd9Sstevel@tonic-gate j, getcode, ctlbuf.len, toa->PRIM_type); 7607c478bd9Sstevel@tonic-gate 7617c478bd9Sstevel@tonic-gate if (toa->PRIM_type == T_OPTMGMT_ACK) 7627c478bd9Sstevel@tonic-gate (void) printf("T_OPTMGMT_ACK: " 7637c478bd9Sstevel@tonic-gate "MGMT_flags = 0x%lx, req->len = %ld\n", 7647c478bd9Sstevel@tonic-gate toa->MGMT_flags, req->len); 7657c478bd9Sstevel@tonic-gate errno = ENOMSG; 7667c478bd9Sstevel@tonic-gate goto error_exit; 7677c478bd9Sstevel@tonic-gate } 7687c478bd9Sstevel@tonic-gate 7697c478bd9Sstevel@tonic-gate temp = (mib_item_t *)malloc(sizeof (mib_item_t)); 7707c478bd9Sstevel@tonic-gate if (temp == NULL) { 7717c478bd9Sstevel@tonic-gate perror("mibget malloc failed"); 7727c478bd9Sstevel@tonic-gate goto error_exit; 7737c478bd9Sstevel@tonic-gate } 7747c478bd9Sstevel@tonic-gate if (last_item != NULL) 7757c478bd9Sstevel@tonic-gate last_item->next_item = temp; 7767c478bd9Sstevel@tonic-gate else 7777c478bd9Sstevel@tonic-gate first_item = temp; 7787c478bd9Sstevel@tonic-gate last_item = temp; 7797c478bd9Sstevel@tonic-gate last_item->next_item = NULL; 7807c478bd9Sstevel@tonic-gate last_item->group = req->level; 7817c478bd9Sstevel@tonic-gate last_item->mib_id = req->name; 7827c478bd9Sstevel@tonic-gate last_item->length = req->len; 7837c478bd9Sstevel@tonic-gate last_item->valp = malloc((int)req->len); 7847c478bd9Sstevel@tonic-gate if (last_item->valp == NULL) 7857c478bd9Sstevel@tonic-gate goto error_exit; 7867c478bd9Sstevel@tonic-gate if (Dflag) 7877c478bd9Sstevel@tonic-gate (void) printf("msg %d: group = %4d mib_id = %5d" 7887c478bd9Sstevel@tonic-gate "length = %d\n", 7897c478bd9Sstevel@tonic-gate j, last_item->group, last_item->mib_id, 7907c478bd9Sstevel@tonic-gate last_item->length); 7917c478bd9Sstevel@tonic-gate 7927c478bd9Sstevel@tonic-gate databuf.maxlen = last_item->length; 7937c478bd9Sstevel@tonic-gate databuf.buf = (char *)last_item->valp; 7947c478bd9Sstevel@tonic-gate databuf.len = 0; 7957c478bd9Sstevel@tonic-gate flags = 0; 7967c478bd9Sstevel@tonic-gate getcode = getmsg(sd, (struct strbuf *)0, &databuf, &flags); 7977c478bd9Sstevel@tonic-gate if (getcode == -1) { 7987c478bd9Sstevel@tonic-gate perror("mibget getmsg(data) failed"); 7997c478bd9Sstevel@tonic-gate goto error_exit; 8007c478bd9Sstevel@tonic-gate } else if (getcode != 0) { 8017c478bd9Sstevel@tonic-gate (void) printf("mibget getmsg(data) returned %d, " 8027c478bd9Sstevel@tonic-gate "databuf.maxlen = %d, databuf.len = %d\n", 8037c478bd9Sstevel@tonic-gate getcode, databuf.maxlen, databuf.len); 8047c478bd9Sstevel@tonic-gate goto error_exit; 8057c478bd9Sstevel@tonic-gate } 8067c478bd9Sstevel@tonic-gate j++; 8077c478bd9Sstevel@tonic-gate } 8087c478bd9Sstevel@tonic-gate /* NOTREACHED */ 8097c478bd9Sstevel@tonic-gate 8107c478bd9Sstevel@tonic-gate error_exit:; 8117c478bd9Sstevel@tonic-gate mibfree(first_item); 8127c478bd9Sstevel@tonic-gate return (NULL); 8137c478bd9Sstevel@tonic-gate } 8147c478bd9Sstevel@tonic-gate 8157c478bd9Sstevel@tonic-gate /* 8167c478bd9Sstevel@tonic-gate * mibfree: frees a linked list of type (mib_item_t *) 8177c478bd9Sstevel@tonic-gate * returned by mibget(); this is NOT THE SAME AS 8187c478bd9Sstevel@tonic-gate * mib_item_destroy(), so should be used for objects 8197c478bd9Sstevel@tonic-gate * returned by mibget() only 8207c478bd9Sstevel@tonic-gate */ 8217c478bd9Sstevel@tonic-gate static void 8227c478bd9Sstevel@tonic-gate mibfree(mib_item_t *firstitem) 8237c478bd9Sstevel@tonic-gate { 8247c478bd9Sstevel@tonic-gate mib_item_t *lastitem; 8257c478bd9Sstevel@tonic-gate 8267c478bd9Sstevel@tonic-gate while (firstitem != NULL) { 8277c478bd9Sstevel@tonic-gate lastitem = firstitem; 8287c478bd9Sstevel@tonic-gate firstitem = firstitem->next_item; 8297c478bd9Sstevel@tonic-gate if (lastitem->valp != NULL) 8307c478bd9Sstevel@tonic-gate free(lastitem->valp); 8317c478bd9Sstevel@tonic-gate free(lastitem); 8327c478bd9Sstevel@tonic-gate } 8337c478bd9Sstevel@tonic-gate } 8347c478bd9Sstevel@tonic-gate 8357c478bd9Sstevel@tonic-gate static int 8367c478bd9Sstevel@tonic-gate mibopen(void) 8377c478bd9Sstevel@tonic-gate { 8387c478bd9Sstevel@tonic-gate int sd; 8397c478bd9Sstevel@tonic-gate 8407c478bd9Sstevel@tonic-gate sd = open("/dev/arp", O_RDWR); 8417c478bd9Sstevel@tonic-gate if (sd == -1) { 8427c478bd9Sstevel@tonic-gate perror("arp open"); 8437c478bd9Sstevel@tonic-gate return (-1); 8447c478bd9Sstevel@tonic-gate } 8457c478bd9Sstevel@tonic-gate if (ioctl(sd, I_PUSH, "tcp") == -1) { 8467c478bd9Sstevel@tonic-gate perror("tcp I_PUSH"); 8477c478bd9Sstevel@tonic-gate (void) close(sd); 8487c478bd9Sstevel@tonic-gate return (-1); 8497c478bd9Sstevel@tonic-gate } 8507c478bd9Sstevel@tonic-gate if (ioctl(sd, I_PUSH, "udp") == -1) { 8517c478bd9Sstevel@tonic-gate perror("udp I_PUSH"); 8527c478bd9Sstevel@tonic-gate (void) close(sd); 8537c478bd9Sstevel@tonic-gate return (-1); 8547c478bd9Sstevel@tonic-gate } 8557c478bd9Sstevel@tonic-gate if (ioctl(sd, I_PUSH, "icmp") == -1) { 8567c478bd9Sstevel@tonic-gate perror("icmp I_PUSH"); 8577c478bd9Sstevel@tonic-gate (void) close(sd); 8587c478bd9Sstevel@tonic-gate return (-1); 8597c478bd9Sstevel@tonic-gate } 8607c478bd9Sstevel@tonic-gate return (sd); 8617c478bd9Sstevel@tonic-gate } 8627c478bd9Sstevel@tonic-gate 8637c478bd9Sstevel@tonic-gate /* 8647c478bd9Sstevel@tonic-gate * mib_item_dup: returns a clean mib_item_t * linked 8657c478bd9Sstevel@tonic-gate * list, so that for every element item->mib_id is 0; 8667c478bd9Sstevel@tonic-gate * to deallocate this linked list, use mib_item_destroy 8677c478bd9Sstevel@tonic-gate */ 8687c478bd9Sstevel@tonic-gate static mib_item_t * 8697c478bd9Sstevel@tonic-gate mib_item_dup(mib_item_t *item) 8707c478bd9Sstevel@tonic-gate { 8717c478bd9Sstevel@tonic-gate int c = 0; 8727c478bd9Sstevel@tonic-gate mib_item_t *localp; 8737c478bd9Sstevel@tonic-gate mib_item_t *tempp; 8747c478bd9Sstevel@tonic-gate 8757c478bd9Sstevel@tonic-gate for (tempp = item; tempp; tempp = tempp->next_item) 8767c478bd9Sstevel@tonic-gate if (tempp->mib_id == 0) 8777c478bd9Sstevel@tonic-gate c++; 8787c478bd9Sstevel@tonic-gate tempp = NULL; 8797c478bd9Sstevel@tonic-gate 8807c478bd9Sstevel@tonic-gate localp = (mib_item_t *)malloc(c * sizeof (mib_item_t)); 8817c478bd9Sstevel@tonic-gate if (localp == NULL) 8827c478bd9Sstevel@tonic-gate return (NULL); 8837c478bd9Sstevel@tonic-gate c = 0; 8847c478bd9Sstevel@tonic-gate for (; item; item = item->next_item) { 8857c478bd9Sstevel@tonic-gate if (item->mib_id == 0) { 8867c478bd9Sstevel@tonic-gate /* Replicate item in localp */ 8877c478bd9Sstevel@tonic-gate (localp[c]).next_item = NULL; 8887c478bd9Sstevel@tonic-gate (localp[c]).group = item->group; 8897c478bd9Sstevel@tonic-gate (localp[c]).mib_id = item->mib_id; 8907c478bd9Sstevel@tonic-gate (localp[c]).length = item->length; 8917c478bd9Sstevel@tonic-gate (localp[c]).valp = (uintptr_t *)malloc( 8927c478bd9Sstevel@tonic-gate item->length); 8937c478bd9Sstevel@tonic-gate if ((localp[c]).valp == NULL) { 8947c478bd9Sstevel@tonic-gate mib_item_destroy(&localp); 8957c478bd9Sstevel@tonic-gate return (NULL); 8967c478bd9Sstevel@tonic-gate } 8977c478bd9Sstevel@tonic-gate (void *) memcpy((localp[c]).valp, 8987c478bd9Sstevel@tonic-gate item->valp, 8997c478bd9Sstevel@tonic-gate item->length); 9007c478bd9Sstevel@tonic-gate tempp = &(localp[c]); 9017c478bd9Sstevel@tonic-gate if (c > 0) 9027c478bd9Sstevel@tonic-gate (localp[c - 1]).next_item = tempp; 9037c478bd9Sstevel@tonic-gate c++; 9047c478bd9Sstevel@tonic-gate } 9057c478bd9Sstevel@tonic-gate } 9067c478bd9Sstevel@tonic-gate return (localp); 9077c478bd9Sstevel@tonic-gate } 9087c478bd9Sstevel@tonic-gate 9097c478bd9Sstevel@tonic-gate /* 9107c478bd9Sstevel@tonic-gate * mib_item_diff: takes two (mib_item_t *) linked lists 9117c478bd9Sstevel@tonic-gate * item1 and item2 and computes the difference between 9127c478bd9Sstevel@tonic-gate * differentiable values in item2 against item1 for every 9137c478bd9Sstevel@tonic-gate * given member of item2; returns an mib_item_t * linked 9147c478bd9Sstevel@tonic-gate * list of diff's, or a copy of item2 if item1 is NULL; 9157c478bd9Sstevel@tonic-gate * will return NULL if system out of memory; works only 9167c478bd9Sstevel@tonic-gate * for item->mib_id == 0 9177c478bd9Sstevel@tonic-gate */ 9187c478bd9Sstevel@tonic-gate static mib_item_t * 9197c478bd9Sstevel@tonic-gate mib_item_diff(mib_item_t *item1, mib_item_t *item2) { 9207c478bd9Sstevel@tonic-gate int nitems = 0; /* no. of items in item2 */ 9217c478bd9Sstevel@tonic-gate mib_item_t *tempp2; /* walking copy of item2 */ 9227c478bd9Sstevel@tonic-gate mib_item_t *tempp1; /* walking copy of item1 */ 9237c478bd9Sstevel@tonic-gate mib_item_t *diffp; 9247c478bd9Sstevel@tonic-gate mib_item_t *diffptr; /* walking copy of diffp */ 9257c478bd9Sstevel@tonic-gate mib_item_t *prevp = NULL; 9267c478bd9Sstevel@tonic-gate 9277c478bd9Sstevel@tonic-gate if (item1 == NULL) { 9287c478bd9Sstevel@tonic-gate diffp = mib_item_dup(item2); 9297c478bd9Sstevel@tonic-gate return (diffp); 9307c478bd9Sstevel@tonic-gate } 9317c478bd9Sstevel@tonic-gate 9327c478bd9Sstevel@tonic-gate for (tempp2 = item2; 9337c478bd9Sstevel@tonic-gate tempp2; 9347c478bd9Sstevel@tonic-gate tempp2 = tempp2->next_item) { 9357c478bd9Sstevel@tonic-gate if (tempp2->mib_id == 0) 9367c478bd9Sstevel@tonic-gate switch (tempp2->group) { 9377c478bd9Sstevel@tonic-gate /* 9387c478bd9Sstevel@tonic-gate * upon adding a case here, the same 9397c478bd9Sstevel@tonic-gate * must also be added in the next 9407c478bd9Sstevel@tonic-gate * switch statement, alongwith 9417c478bd9Sstevel@tonic-gate * appropriate code 9427c478bd9Sstevel@tonic-gate */ 9437c478bd9Sstevel@tonic-gate case MIB2_IP: 9447c478bd9Sstevel@tonic-gate case MIB2_IP6: 9457c478bd9Sstevel@tonic-gate case EXPER_DVMRP: 9467c478bd9Sstevel@tonic-gate case EXPER_IGMP: 9477c478bd9Sstevel@tonic-gate case MIB2_ICMP: 9487c478bd9Sstevel@tonic-gate case MIB2_ICMP6: 9497c478bd9Sstevel@tonic-gate case MIB2_TCP: 9507c478bd9Sstevel@tonic-gate case MIB2_UDP: 9517c478bd9Sstevel@tonic-gate case MIB2_SCTP: 9527c478bd9Sstevel@tonic-gate case EXPER_RAWIP: 9537c478bd9Sstevel@tonic-gate nitems++; 9547c478bd9Sstevel@tonic-gate } 9557c478bd9Sstevel@tonic-gate } 9567c478bd9Sstevel@tonic-gate tempp2 = NULL; 9577c478bd9Sstevel@tonic-gate if (nitems == 0) { 9587c478bd9Sstevel@tonic-gate diffp = mib_item_dup(item2); 9597c478bd9Sstevel@tonic-gate return (diffp); 9607c478bd9Sstevel@tonic-gate } 9617c478bd9Sstevel@tonic-gate 9627c478bd9Sstevel@tonic-gate diffp = (mib_item_t *)calloc(nitems, sizeof (mib_item_t)); 9637c478bd9Sstevel@tonic-gate if (diffp == NULL) 9647c478bd9Sstevel@tonic-gate return (NULL); 9657c478bd9Sstevel@tonic-gate diffptr = diffp; 9667c478bd9Sstevel@tonic-gate /* 'for' loop 1: */ 9677c478bd9Sstevel@tonic-gate for (tempp2 = item2; tempp2 != NULL; tempp2 = tempp2->next_item) { 9687c478bd9Sstevel@tonic-gate if (tempp2->mib_id != 0) 9697c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 9707c478bd9Sstevel@tonic-gate /* 'for' loop 2: */ 9717c478bd9Sstevel@tonic-gate for (tempp1 = item1; tempp1 != NULL; 9727c478bd9Sstevel@tonic-gate tempp1 = tempp1->next_item) { 9737c478bd9Sstevel@tonic-gate if (!(tempp1->mib_id == 0 && 9747c478bd9Sstevel@tonic-gate tempp1->group == tempp2->group && 9757c478bd9Sstevel@tonic-gate tempp1->mib_id == tempp2->mib_id)) 9767c478bd9Sstevel@tonic-gate continue; /* 'for' loop 2 */ 9777c478bd9Sstevel@tonic-gate /* found comparable data sets */ 9787c478bd9Sstevel@tonic-gate if (prevp != NULL) 9797c478bd9Sstevel@tonic-gate prevp->next_item = diffptr; 9807c478bd9Sstevel@tonic-gate switch (tempp2->group) { 9817c478bd9Sstevel@tonic-gate /* 9827c478bd9Sstevel@tonic-gate * Indenting note: Because of long variable names 9837c478bd9Sstevel@tonic-gate * in cases MIB2_IP6 and MIB2_ICMP6, their contents 9847c478bd9Sstevel@tonic-gate * have been indented by one tab space only 9857c478bd9Sstevel@tonic-gate */ 9867c478bd9Sstevel@tonic-gate case MIB2_IP: { 9877c478bd9Sstevel@tonic-gate mib2_ip_t *i2 = (mib2_ip_t *)tempp2->valp; 9887c478bd9Sstevel@tonic-gate mib2_ip_t *i1 = (mib2_ip_t *)tempp1->valp; 9897c478bd9Sstevel@tonic-gate mib2_ip_t *d; 9907c478bd9Sstevel@tonic-gate 9917c478bd9Sstevel@tonic-gate diffptr->group = tempp2->group; 9927c478bd9Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id; 9937c478bd9Sstevel@tonic-gate diffptr->length = tempp2->length; 9947c478bd9Sstevel@tonic-gate d = (mib2_ip_t *)calloc(tempp2->length, 1); 9957c478bd9Sstevel@tonic-gate if (d == NULL) 9967c478bd9Sstevel@tonic-gate goto mibdiff_out_of_memory; 9977c478bd9Sstevel@tonic-gate diffptr->valp = d; 9987c478bd9Sstevel@tonic-gate d->ipForwarding = i2->ipForwarding; 9997c478bd9Sstevel@tonic-gate d->ipDefaultTTL = i2->ipDefaultTTL; 10007c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipInReceives); 10017c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipInHdrErrors); 10027c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipInAddrErrors); 10037c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipInCksumErrs); 10047c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipForwDatagrams); 10057c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipForwProhibits); 10067c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipInUnknownProtos); 10077c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipInDiscards); 10087c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipInDelivers); 10097c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipOutRequests); 10107c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipOutDiscards); 10117c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipOutNoRoutes); 10127c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipReasmTimeout); 10137c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipReasmReqds); 10147c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipReasmOKs); 10157c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipReasmFails); 10167c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipReasmDuplicates); 10177c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipReasmPartDups); 10187c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipFragOKs); 10197c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipFragFails); 10207c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipFragCreates); 10217c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipRoutingDiscards); 10227c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, tcpInErrs); 10237c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, udpNoPorts); 10247c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, udpInCksumErrs); 10257c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, udpInOverflows); 10267c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, rawipInOverflows); 10277c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipsecInSucceeded); 10287c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipsecInFailed); 10297c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipInIPv6); 10307c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipOutIPv6); 10317c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipOutSwitchIPv6); 10327c478bd9Sstevel@tonic-gate prevp = diffptr++; 10337c478bd9Sstevel@tonic-gate break; 10347c478bd9Sstevel@tonic-gate } 10357c478bd9Sstevel@tonic-gate case MIB2_IP6: { 10367c478bd9Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t *i2; 10377c478bd9Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t *i1; 10387c478bd9Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t *d; 10397c478bd9Sstevel@tonic-gate 10407c478bd9Sstevel@tonic-gate i2 = (mib2_ipv6IfStatsEntry_t *)tempp2->valp; 10417c478bd9Sstevel@tonic-gate i1 = (mib2_ipv6IfStatsEntry_t *)tempp1->valp; 10427c478bd9Sstevel@tonic-gate diffptr->group = tempp2->group; 10437c478bd9Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id; 10447c478bd9Sstevel@tonic-gate diffptr->length = tempp2->length; 10457c478bd9Sstevel@tonic-gate d = (mib2_ipv6IfStatsEntry_t *)calloc( 10467c478bd9Sstevel@tonic-gate tempp2->length, 1); 10477c478bd9Sstevel@tonic-gate if (d == NULL) 10487c478bd9Sstevel@tonic-gate goto mibdiff_out_of_memory; 10497c478bd9Sstevel@tonic-gate diffptr->valp = d; 10507c478bd9Sstevel@tonic-gate d->ipv6Forwarding = i2->ipv6Forwarding; 10517c478bd9Sstevel@tonic-gate d->ipv6DefaultHopLimit = 10527c478bd9Sstevel@tonic-gate i2->ipv6DefaultHopLimit; 10537c478bd9Sstevel@tonic-gate 10547c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InReceives); 10557c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InHdrErrors); 10567c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InTooBigErrors); 10577c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InNoRoutes); 10587c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InAddrErrors); 10597c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InUnknownProtos); 10607c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InTruncatedPkts); 10617c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InDiscards); 10627c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InDelivers); 10637c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutForwDatagrams); 10647c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutRequests); 10657c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutDiscards); 10667c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutNoRoutes); 10677c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutFragOKs); 10687c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutFragFails); 10697c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutFragCreates); 10707c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6ReasmReqds); 10717c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6ReasmOKs); 10727c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6ReasmFails); 10737c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InMcastPkts); 10747c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutMcastPkts); 10757c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6ReasmDuplicates); 10767c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6ReasmPartDups); 10777c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6ForwProhibits); 10787c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, udpInCksumErrs); 10797c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, udpInOverflows); 10807c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, rawipInOverflows); 10817c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InIPv4); 10827c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutIPv4); 10837c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutSwitchIPv4); 10847c478bd9Sstevel@tonic-gate prevp = diffptr++; 10857c478bd9Sstevel@tonic-gate break; 10867c478bd9Sstevel@tonic-gate } 10877c478bd9Sstevel@tonic-gate case EXPER_DVMRP: { 10887c478bd9Sstevel@tonic-gate struct mrtstat *m2; 10897c478bd9Sstevel@tonic-gate struct mrtstat *m1; 10907c478bd9Sstevel@tonic-gate struct mrtstat *d; 10917c478bd9Sstevel@tonic-gate 10927c478bd9Sstevel@tonic-gate m2 = (struct mrtstat *)tempp2->valp; 10937c478bd9Sstevel@tonic-gate m1 = (struct mrtstat *)tempp1->valp; 10947c478bd9Sstevel@tonic-gate diffptr->group = tempp2->group; 10957c478bd9Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id; 10967c478bd9Sstevel@tonic-gate diffptr->length = tempp2->length; 10977c478bd9Sstevel@tonic-gate d = (struct mrtstat *)calloc(tempp2->length, 1); 10987c478bd9Sstevel@tonic-gate if (d == NULL) 10997c478bd9Sstevel@tonic-gate goto mibdiff_out_of_memory; 11007c478bd9Sstevel@tonic-gate diffptr->valp = d; 11017c478bd9Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_mfc_hits); 11027c478bd9Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_mfc_misses); 11037c478bd9Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_fwd_in); 11047c478bd9Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_fwd_out); 11057c478bd9Sstevel@tonic-gate d->mrts_upcalls = m2->mrts_upcalls; 11067c478bd9Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_fwd_drop); 11077c478bd9Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_bad_tunnel); 11087c478bd9Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_cant_tunnel); 11097c478bd9Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_wrong_if); 11107c478bd9Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_upq_ovflw); 11117c478bd9Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_cache_cleanups); 11127c478bd9Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_drop_sel); 11137c478bd9Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_q_overflow); 11147c478bd9Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pkt2large); 11157c478bd9Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_badversion); 11167c478bd9Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_rcv_badcsum); 11177c478bd9Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_badregisters); 11187c478bd9Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_regforwards); 11197c478bd9Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_regsend_drops); 11207c478bd9Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_malformed); 11217c478bd9Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_nomemory); 11227c478bd9Sstevel@tonic-gate prevp = diffptr++; 11237c478bd9Sstevel@tonic-gate break; 11247c478bd9Sstevel@tonic-gate } 11257c478bd9Sstevel@tonic-gate case EXPER_IGMP: { 11267c478bd9Sstevel@tonic-gate struct igmpstat *i2; 11277c478bd9Sstevel@tonic-gate struct igmpstat *i1; 11287c478bd9Sstevel@tonic-gate struct igmpstat *d; 11297c478bd9Sstevel@tonic-gate 11307c478bd9Sstevel@tonic-gate i2 = (struct igmpstat *)tempp2->valp; 11317c478bd9Sstevel@tonic-gate i1 = (struct igmpstat *)tempp1->valp; 11327c478bd9Sstevel@tonic-gate diffptr->group = tempp2->group; 11337c478bd9Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id; 11347c478bd9Sstevel@tonic-gate diffptr->length = tempp2->length; 11357c478bd9Sstevel@tonic-gate d = (struct igmpstat *)calloc( 11367c478bd9Sstevel@tonic-gate tempp2->length, 1); 11377c478bd9Sstevel@tonic-gate if (d == NULL) 11387c478bd9Sstevel@tonic-gate goto mibdiff_out_of_memory; 11397c478bd9Sstevel@tonic-gate diffptr->valp = d; 11407c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_total); 11417c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_tooshort); 11427c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_badsum); 11437c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_queries); 11447c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_badqueries); 11457c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_reports); 11467c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_badreports); 11477c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_ourreports); 11487c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, igps_snd_reports); 11497c478bd9Sstevel@tonic-gate prevp = diffptr++; 11507c478bd9Sstevel@tonic-gate break; 11517c478bd9Sstevel@tonic-gate } 11527c478bd9Sstevel@tonic-gate case MIB2_ICMP: { 11537c478bd9Sstevel@tonic-gate mib2_icmp_t *i2; 11547c478bd9Sstevel@tonic-gate mib2_icmp_t *i1; 11557c478bd9Sstevel@tonic-gate mib2_icmp_t *d; 11567c478bd9Sstevel@tonic-gate 11577c478bd9Sstevel@tonic-gate i2 = (mib2_icmp_t *)tempp2->valp; 11587c478bd9Sstevel@tonic-gate i1 = (mib2_icmp_t *)tempp1->valp; 11597c478bd9Sstevel@tonic-gate diffptr->group = tempp2->group; 11607c478bd9Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id; 11617c478bd9Sstevel@tonic-gate diffptr->length = tempp2->length; 11627c478bd9Sstevel@tonic-gate d = (mib2_icmp_t *)calloc(tempp2->length, 1); 11637c478bd9Sstevel@tonic-gate if (d == NULL) 11647c478bd9Sstevel@tonic-gate goto mibdiff_out_of_memory; 11657c478bd9Sstevel@tonic-gate diffptr->valp = d; 11667c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInMsgs); 11677c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInErrors); 11687c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInCksumErrs); 11697c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInUnknowns); 11707c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInDestUnreachs); 11717c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInTimeExcds); 11727c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInParmProbs); 11737c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInSrcQuenchs); 11747c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInRedirects); 11757c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInBadRedirects); 11767c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInEchos); 11777c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInEchoReps); 11787c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInTimestamps); 11797c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInAddrMasks); 11807c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInAddrMaskReps); 11817c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInFragNeeded); 11827c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutMsgs); 11837c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutDrops); 11847c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutErrors); 11857c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutDestUnreachs); 11867c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutTimeExcds); 11877c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutParmProbs); 11887c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutSrcQuenchs); 11897c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutRedirects); 11907c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutEchos); 11917c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutEchoReps); 11927c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutTimestamps); 11937c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutTimestampReps); 11947c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutAddrMasks); 11957c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutAddrMaskReps); 11967c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutFragNeeded); 11977c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInOverflows); 11987c478bd9Sstevel@tonic-gate prevp = diffptr++; 11997c478bd9Sstevel@tonic-gate break; 12007c478bd9Sstevel@tonic-gate } 12017c478bd9Sstevel@tonic-gate case MIB2_ICMP6: { 12027c478bd9Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t *i2; 12037c478bd9Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t *i1; 12047c478bd9Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t *d; 12057c478bd9Sstevel@tonic-gate 12067c478bd9Sstevel@tonic-gate i2 = (mib2_ipv6IfIcmpEntry_t *)tempp2->valp; 12077c478bd9Sstevel@tonic-gate i1 = (mib2_ipv6IfIcmpEntry_t *)tempp1->valp; 12087c478bd9Sstevel@tonic-gate diffptr->group = tempp2->group; 12097c478bd9Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id; 12107c478bd9Sstevel@tonic-gate diffptr->length = tempp2->length; 12117c478bd9Sstevel@tonic-gate d = (mib2_ipv6IfIcmpEntry_t *)calloc(tempp2->length, 1); 12127c478bd9Sstevel@tonic-gate if (d == NULL) 12137c478bd9Sstevel@tonic-gate goto mibdiff_out_of_memory; 12147c478bd9Sstevel@tonic-gate diffptr->valp = d; 12157c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInMsgs); 12167c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInErrors); 12177c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInDestUnreachs); 12187c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInAdminProhibs); 12197c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInTimeExcds); 12207c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInParmProblems); 12217c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInPktTooBigs); 12227c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInEchos); 12237c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInEchoReplies); 12247c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInRouterSolicits); 12257c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInRouterAdvertisements); 12267c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInNeighborSolicits); 12277c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInNeighborAdvertisements); 12287c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInRedirects); 12297c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInBadRedirects); 12307c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInGroupMembQueries); 12317c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInGroupMembResponses); 12327c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInGroupMembReductions); 12337c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInOverflows); 12347c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutMsgs); 12357c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutErrors); 12367c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutDestUnreachs); 12377c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutAdminProhibs); 12387c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutTimeExcds); 12397c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutParmProblems); 12407c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutPktTooBigs); 12417c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutEchos); 12427c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutEchoReplies); 12437c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutRouterSolicits); 12447c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutRouterAdvertisements); 12457c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutNeighborSolicits); 12467c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutNeighborAdvertisements); 12477c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutRedirects); 12487c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutGroupMembQueries); 12497c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutGroupMembResponses); 12507c478bd9Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutGroupMembReductions); 12517c478bd9Sstevel@tonic-gate prevp = diffptr++; 12527c478bd9Sstevel@tonic-gate break; 12537c478bd9Sstevel@tonic-gate } 12547c478bd9Sstevel@tonic-gate case MIB2_TCP: { 12557c478bd9Sstevel@tonic-gate mib2_tcp_t *t2; 12567c478bd9Sstevel@tonic-gate mib2_tcp_t *t1; 12577c478bd9Sstevel@tonic-gate mib2_tcp_t *d; 12587c478bd9Sstevel@tonic-gate 12597c478bd9Sstevel@tonic-gate t2 = (mib2_tcp_t *)tempp2->valp; 12607c478bd9Sstevel@tonic-gate t1 = (mib2_tcp_t *)tempp1->valp; 12617c478bd9Sstevel@tonic-gate diffptr->group = tempp2->group; 12627c478bd9Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id; 12637c478bd9Sstevel@tonic-gate diffptr->length = tempp2->length; 12647c478bd9Sstevel@tonic-gate d = (mib2_tcp_t *)calloc(tempp2->length, 1); 12657c478bd9Sstevel@tonic-gate if (d == NULL) 12667c478bd9Sstevel@tonic-gate goto mibdiff_out_of_memory; 12677c478bd9Sstevel@tonic-gate diffptr->valp = d; 12687c478bd9Sstevel@tonic-gate d->tcpRtoMin = t2->tcpRtoMin; 12697c478bd9Sstevel@tonic-gate d->tcpRtoMax = t2->tcpRtoMax; 12707c478bd9Sstevel@tonic-gate d->tcpMaxConn = t2->tcpMaxConn; 12717c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpActiveOpens); 12727c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpPassiveOpens); 12737c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpAttemptFails); 12747c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpEstabResets); 12757c478bd9Sstevel@tonic-gate d->tcpCurrEstab = t2->tcpCurrEstab; 12763173664eSapersson MDIFF(d, t2, t1, tcpHCOutSegs); 12777c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutDataSegs); 12787c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutDataBytes); 12797c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpRetransSegs); 12807c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpRetransBytes); 12817c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutAck); 12827c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutAckDelayed); 12837c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutUrg); 12847c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutWinUpdate); 12857c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutWinProbe); 12867c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutControl); 12877c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutRsts); 12887c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutFastRetrans); 12893173664eSapersson MDIFF(d, t2, t1, tcpHCInSegs); 12907c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInAckSegs); 12917c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInAckBytes); 12927c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDupAck); 12937c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInAckUnsent); 12947c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataInorderSegs); 12957c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataInorderBytes); 12967c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataUnorderSegs); 12977c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataUnorderBytes); 12987c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataDupSegs); 12997c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataDupBytes); 13007c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataPartDupSegs); 13017c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataPartDupBytes); 13027c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataPastWinSegs); 13037c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataPastWinBytes); 13047c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInWinProbe); 13057c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInWinUpdate); 13067c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInClosed); 13077c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpRttNoUpdate); 13087c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpRttUpdate); 13097c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpTimRetrans); 13107c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpTimRetransDrop); 13117c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpTimKeepalive); 13127c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpTimKeepaliveProbe); 13137c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpTimKeepaliveDrop); 13147c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpListenDrop); 13157c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpListenDropQ0); 13167c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpHalfOpenDrop); 13177c478bd9Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutSackRetransSegs); 13187c478bd9Sstevel@tonic-gate prevp = diffptr++; 13197c478bd9Sstevel@tonic-gate break; 13207c478bd9Sstevel@tonic-gate } 13217c478bd9Sstevel@tonic-gate case MIB2_UDP: { 13227c478bd9Sstevel@tonic-gate mib2_udp_t *u2; 13237c478bd9Sstevel@tonic-gate mib2_udp_t *u1; 13247c478bd9Sstevel@tonic-gate mib2_udp_t *d; 13257c478bd9Sstevel@tonic-gate 13267c478bd9Sstevel@tonic-gate u2 = (mib2_udp_t *)tempp2->valp; 13277c478bd9Sstevel@tonic-gate u1 = (mib2_udp_t *)tempp1->valp; 13287c478bd9Sstevel@tonic-gate diffptr->group = tempp2->group; 13297c478bd9Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id; 13307c478bd9Sstevel@tonic-gate diffptr->length = tempp2->length; 13317c478bd9Sstevel@tonic-gate d = (mib2_udp_t *)calloc(tempp2->length, 1); 13327c478bd9Sstevel@tonic-gate if (d == NULL) 13337c478bd9Sstevel@tonic-gate goto mibdiff_out_of_memory; 13347c478bd9Sstevel@tonic-gate diffptr->valp = d; 13353173664eSapersson MDIFF(d, u2, u1, udpHCInDatagrams); 13367c478bd9Sstevel@tonic-gate MDIFF(d, u2, u1, udpInErrors); 13373173664eSapersson MDIFF(d, u2, u1, udpHCOutDatagrams); 13387c478bd9Sstevel@tonic-gate MDIFF(d, u2, u1, udpOutErrors); 13397c478bd9Sstevel@tonic-gate prevp = diffptr++; 13407c478bd9Sstevel@tonic-gate break; 13417c478bd9Sstevel@tonic-gate } 13427c478bd9Sstevel@tonic-gate case MIB2_SCTP: { 13437c478bd9Sstevel@tonic-gate mib2_sctp_t *s2; 13447c478bd9Sstevel@tonic-gate mib2_sctp_t *s1; 13457c478bd9Sstevel@tonic-gate mib2_sctp_t *d; 13467c478bd9Sstevel@tonic-gate 13477c478bd9Sstevel@tonic-gate s2 = (mib2_sctp_t *)tempp2->valp; 13487c478bd9Sstevel@tonic-gate s1 = (mib2_sctp_t *)tempp1->valp; 13497c478bd9Sstevel@tonic-gate diffptr->group = tempp2->group; 13507c478bd9Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id; 13517c478bd9Sstevel@tonic-gate diffptr->length = tempp2->length; 13527c478bd9Sstevel@tonic-gate d = (mib2_sctp_t *)calloc(tempp2->length, 1); 13537c478bd9Sstevel@tonic-gate if (d == NULL) 13547c478bd9Sstevel@tonic-gate goto mibdiff_out_of_memory; 13557c478bd9Sstevel@tonic-gate diffptr->valp = d; 13567c478bd9Sstevel@tonic-gate d->sctpRtoAlgorithm = s2->sctpRtoAlgorithm; 13577c478bd9Sstevel@tonic-gate d->sctpRtoMin = s2->sctpRtoMin; 13587c478bd9Sstevel@tonic-gate d->sctpRtoMax = s2->sctpRtoMax; 13597c478bd9Sstevel@tonic-gate d->sctpRtoInitial = s2->sctpRtoInitial; 13607c478bd9Sstevel@tonic-gate d->sctpMaxAssocs = s2->sctpMaxAssocs; 13617c478bd9Sstevel@tonic-gate d->sctpValCookieLife = s2->sctpValCookieLife; 13627c478bd9Sstevel@tonic-gate d->sctpMaxInitRetr = s2->sctpMaxInitRetr; 13637c478bd9Sstevel@tonic-gate d->sctpCurrEstab = s2->sctpCurrEstab; 13647c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpActiveEstab); 13657c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpPassiveEstab); 13667c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpAborted); 13677c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpShutdowns); 13687c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutOfBlue); 13697c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpChecksumError); 13707c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutCtrlChunks); 13717c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutOrderChunks); 13727c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutUnorderChunks); 13737c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpRetransChunks); 13747c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutAck); 13757c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutAckDelayed); 13767c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutWinUpdate); 13777c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutFastRetrans); 13787c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutWinProbe); 13797c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInCtrlChunks); 13807c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInOrderChunks); 13817c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInUnorderChunks); 13827c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInAck); 13837c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInDupAck); 13847c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInAckUnsent); 13857c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpFragUsrMsgs); 13867c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpReasmUsrMsgs); 13877c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutSCTPPkts); 13887c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInSCTPPkts); 13897c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInInvalidCookie); 13907c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpTimRetrans); 13917c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpTimRetransDrop); 13927c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpTimHeartBeatProbe); 13937c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpTimHeartBeatDrop); 13947c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpListenDrop); 13957c478bd9Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInClosed); 13967c478bd9Sstevel@tonic-gate prevp = diffptr++; 13977c478bd9Sstevel@tonic-gate break; 13987c478bd9Sstevel@tonic-gate } 13997c478bd9Sstevel@tonic-gate case EXPER_RAWIP: { 14007c478bd9Sstevel@tonic-gate mib2_rawip_t *r2; 14017c478bd9Sstevel@tonic-gate mib2_rawip_t *r1; 14027c478bd9Sstevel@tonic-gate mib2_rawip_t *d; 14037c478bd9Sstevel@tonic-gate 14047c478bd9Sstevel@tonic-gate r2 = (mib2_rawip_t *)tempp2->valp; 14057c478bd9Sstevel@tonic-gate r1 = (mib2_rawip_t *)tempp1->valp; 14067c478bd9Sstevel@tonic-gate diffptr->group = tempp2->group; 14077c478bd9Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id; 14087c478bd9Sstevel@tonic-gate diffptr->length = tempp2->length; 14097c478bd9Sstevel@tonic-gate d = (mib2_rawip_t *)calloc(tempp2->length, 1); 14107c478bd9Sstevel@tonic-gate if (d == NULL) 14117c478bd9Sstevel@tonic-gate goto mibdiff_out_of_memory; 14127c478bd9Sstevel@tonic-gate diffptr->valp = d; 14137c478bd9Sstevel@tonic-gate MDIFF(d, r2, r1, rawipInDatagrams); 14147c478bd9Sstevel@tonic-gate MDIFF(d, r2, r1, rawipInErrors); 14157c478bd9Sstevel@tonic-gate MDIFF(d, r2, r1, rawipInCksumErrs); 14167c478bd9Sstevel@tonic-gate MDIFF(d, r2, r1, rawipOutDatagrams); 14177c478bd9Sstevel@tonic-gate MDIFF(d, r2, r1, rawipOutErrors); 14187c478bd9Sstevel@tonic-gate prevp = diffptr++; 14197c478bd9Sstevel@tonic-gate break; 14207c478bd9Sstevel@tonic-gate } 14217c478bd9Sstevel@tonic-gate /* 14227c478bd9Sstevel@tonic-gate * there are more "group" types but they aren't 14237c478bd9Sstevel@tonic-gate * required for the -s and -Ms options 14247c478bd9Sstevel@tonic-gate */ 14257c478bd9Sstevel@tonic-gate } 14267c478bd9Sstevel@tonic-gate } /* 'for' loop 2 ends */ 14277c478bd9Sstevel@tonic-gate tempp1 = NULL; 14287c478bd9Sstevel@tonic-gate } /* 'for' loop 1 ends */ 14297c478bd9Sstevel@tonic-gate tempp2 = NULL; 14307c478bd9Sstevel@tonic-gate diffptr--; 14317c478bd9Sstevel@tonic-gate diffptr->next_item = NULL; 14327c478bd9Sstevel@tonic-gate return (diffp); 14337c478bd9Sstevel@tonic-gate 14347c478bd9Sstevel@tonic-gate mibdiff_out_of_memory:; 14357c478bd9Sstevel@tonic-gate mib_item_destroy(&diffp); 14367c478bd9Sstevel@tonic-gate return (NULL); 14377c478bd9Sstevel@tonic-gate } 14387c478bd9Sstevel@tonic-gate 14397c478bd9Sstevel@tonic-gate /* 14407c478bd9Sstevel@tonic-gate * mib_item_destroy: cleans up a mib_item_t * 14417c478bd9Sstevel@tonic-gate * that was created by calling mib_item_dup or 14427c478bd9Sstevel@tonic-gate * mib_item_diff 14437c478bd9Sstevel@tonic-gate */ 14447c478bd9Sstevel@tonic-gate static void 14457c478bd9Sstevel@tonic-gate mib_item_destroy(mib_item_t **itemp) { 14467c478bd9Sstevel@tonic-gate int nitems = 0; 14477c478bd9Sstevel@tonic-gate int c = 0; 14487c478bd9Sstevel@tonic-gate mib_item_t *tempp; 14497c478bd9Sstevel@tonic-gate 14507c478bd9Sstevel@tonic-gate if (itemp == NULL || *itemp == NULL) 14517c478bd9Sstevel@tonic-gate return; 14527c478bd9Sstevel@tonic-gate 14537c478bd9Sstevel@tonic-gate for (tempp = *itemp; tempp != NULL; tempp = tempp->next_item) 14547c478bd9Sstevel@tonic-gate if (tempp->mib_id == 0) 14557c478bd9Sstevel@tonic-gate nitems++; 14567c478bd9Sstevel@tonic-gate else 14577c478bd9Sstevel@tonic-gate return; /* cannot destroy! */ 14587c478bd9Sstevel@tonic-gate 14597c478bd9Sstevel@tonic-gate if (nitems == 0) 14607c478bd9Sstevel@tonic-gate return; /* cannot destroy! */ 14617c478bd9Sstevel@tonic-gate 14627c478bd9Sstevel@tonic-gate for (c = nitems - 1; c >= 0; c--) { 14637c478bd9Sstevel@tonic-gate if ((itemp[0][c]).valp != NULL) 14647c478bd9Sstevel@tonic-gate free((itemp[0][c]).valp); 14657c478bd9Sstevel@tonic-gate } 14667c478bd9Sstevel@tonic-gate free(*itemp); 14677c478bd9Sstevel@tonic-gate 14687c478bd9Sstevel@tonic-gate *itemp = NULL; 14697c478bd9Sstevel@tonic-gate } 14707c478bd9Sstevel@tonic-gate 14717c478bd9Sstevel@tonic-gate /* Compare two Octet_ts. Return B_TRUE if they match, B_FALSE if not. */ 14727c478bd9Sstevel@tonic-gate static boolean_t 14737c478bd9Sstevel@tonic-gate octetstrmatch(const Octet_t *a, const Octet_t *b) 14747c478bd9Sstevel@tonic-gate { 14757c478bd9Sstevel@tonic-gate if (a == NULL || b == NULL) 14767c478bd9Sstevel@tonic-gate return (B_FALSE); 14777c478bd9Sstevel@tonic-gate 14787c478bd9Sstevel@tonic-gate if (a->o_length != b->o_length) 14797c478bd9Sstevel@tonic-gate return (B_FALSE); 14807c478bd9Sstevel@tonic-gate 14817c478bd9Sstevel@tonic-gate return (memcmp(a->o_bytes, b->o_bytes, a->o_length) == 0); 14827c478bd9Sstevel@tonic-gate } 14837c478bd9Sstevel@tonic-gate 14847c478bd9Sstevel@tonic-gate /* If octetstr() changes make an appropriate change to STR_EXPAND */ 14857c478bd9Sstevel@tonic-gate static char * 148645916cd2Sjpk octetstr(const Octet_t *op, int code, char *dst, uint_t dstlen) 14877c478bd9Sstevel@tonic-gate { 14887c478bd9Sstevel@tonic-gate int i; 14897c478bd9Sstevel@tonic-gate char *cp; 14907c478bd9Sstevel@tonic-gate 14917c478bd9Sstevel@tonic-gate cp = dst; 14927c478bd9Sstevel@tonic-gate if (op) { 14937c478bd9Sstevel@tonic-gate for (i = 0; i < op->o_length; i++) { 14947c478bd9Sstevel@tonic-gate switch (code) { 14957c478bd9Sstevel@tonic-gate case 'd': 14967c478bd9Sstevel@tonic-gate if (cp - dst + 4 > dstlen) { 14977c478bd9Sstevel@tonic-gate *cp = '\0'; 14987c478bd9Sstevel@tonic-gate return (dst); 14997c478bd9Sstevel@tonic-gate } 15007c478bd9Sstevel@tonic-gate (void) snprintf(cp, 5, "%d.", 15017c478bd9Sstevel@tonic-gate 0xff & op->o_bytes[i]); 15027c478bd9Sstevel@tonic-gate cp = strchr(cp, '\0'); 15037c478bd9Sstevel@tonic-gate break; 15047c478bd9Sstevel@tonic-gate case 'a': 15057c478bd9Sstevel@tonic-gate if (cp - dst + 1 > dstlen) { 15067c478bd9Sstevel@tonic-gate *cp = '\0'; 15077c478bd9Sstevel@tonic-gate return (dst); 15087c478bd9Sstevel@tonic-gate } 15097c478bd9Sstevel@tonic-gate *cp++ = op->o_bytes[i]; 15107c478bd9Sstevel@tonic-gate break; 15117c478bd9Sstevel@tonic-gate case 'h': 15127c478bd9Sstevel@tonic-gate default: 15137c478bd9Sstevel@tonic-gate if (cp - dst + 3 > dstlen) { 15147c478bd9Sstevel@tonic-gate *cp = '\0'; 15157c478bd9Sstevel@tonic-gate return (dst); 15167c478bd9Sstevel@tonic-gate } 15177c478bd9Sstevel@tonic-gate (void) snprintf(cp, 4, "%02x:", 15187c478bd9Sstevel@tonic-gate 0xff & op->o_bytes[i]); 15197c478bd9Sstevel@tonic-gate cp += 3; 15207c478bd9Sstevel@tonic-gate break; 15217c478bd9Sstevel@tonic-gate } 15227c478bd9Sstevel@tonic-gate } 15237c478bd9Sstevel@tonic-gate } 15247c478bd9Sstevel@tonic-gate if (code != 'a' && cp != dst) 15257c478bd9Sstevel@tonic-gate cp--; 15267c478bd9Sstevel@tonic-gate *cp = '\0'; 15277c478bd9Sstevel@tonic-gate return (dst); 15287c478bd9Sstevel@tonic-gate } 15297c478bd9Sstevel@tonic-gate 153045916cd2Sjpk static const char * 153145916cd2Sjpk mitcp_state(int state, const mib2_transportMLPEntry_t *attr) 15327c478bd9Sstevel@tonic-gate { 153345916cd2Sjpk static char tcpsbuf[50]; 153445916cd2Sjpk const char *cp; 15357c478bd9Sstevel@tonic-gate 15367c478bd9Sstevel@tonic-gate switch (state) { 15377c478bd9Sstevel@tonic-gate case TCPS_CLOSED: 15387c478bd9Sstevel@tonic-gate cp = "CLOSED"; 15397c478bd9Sstevel@tonic-gate break; 15407c478bd9Sstevel@tonic-gate case TCPS_IDLE: 15417c478bd9Sstevel@tonic-gate cp = "IDLE"; 15427c478bd9Sstevel@tonic-gate break; 15437c478bd9Sstevel@tonic-gate case TCPS_BOUND: 15447c478bd9Sstevel@tonic-gate cp = "BOUND"; 15457c478bd9Sstevel@tonic-gate break; 15467c478bd9Sstevel@tonic-gate case TCPS_LISTEN: 15477c478bd9Sstevel@tonic-gate cp = "LISTEN"; 15487c478bd9Sstevel@tonic-gate break; 15497c478bd9Sstevel@tonic-gate case TCPS_SYN_SENT: 15507c478bd9Sstevel@tonic-gate cp = "SYN_SENT"; 15517c478bd9Sstevel@tonic-gate break; 15527c478bd9Sstevel@tonic-gate case TCPS_SYN_RCVD: 15537c478bd9Sstevel@tonic-gate cp = "SYN_RCVD"; 15547c478bd9Sstevel@tonic-gate break; 15557c478bd9Sstevel@tonic-gate case TCPS_ESTABLISHED: 15567c478bd9Sstevel@tonic-gate cp = "ESTABLISHED"; 15577c478bd9Sstevel@tonic-gate break; 15587c478bd9Sstevel@tonic-gate case TCPS_CLOSE_WAIT: 15597c478bd9Sstevel@tonic-gate cp = "CLOSE_WAIT"; 15607c478bd9Sstevel@tonic-gate break; 15617c478bd9Sstevel@tonic-gate case TCPS_FIN_WAIT_1: 15627c478bd9Sstevel@tonic-gate cp = "FIN_WAIT_1"; 15637c478bd9Sstevel@tonic-gate break; 15647c478bd9Sstevel@tonic-gate case TCPS_CLOSING: 15657c478bd9Sstevel@tonic-gate cp = "CLOSING"; 15667c478bd9Sstevel@tonic-gate break; 15677c478bd9Sstevel@tonic-gate case TCPS_LAST_ACK: 15687c478bd9Sstevel@tonic-gate cp = "LAST_ACK"; 15697c478bd9Sstevel@tonic-gate break; 15707c478bd9Sstevel@tonic-gate case TCPS_FIN_WAIT_2: 15717c478bd9Sstevel@tonic-gate cp = "FIN_WAIT_2"; 15727c478bd9Sstevel@tonic-gate break; 15737c478bd9Sstevel@tonic-gate case TCPS_TIME_WAIT: 15747c478bd9Sstevel@tonic-gate cp = "TIME_WAIT"; 15757c478bd9Sstevel@tonic-gate break; 15767c478bd9Sstevel@tonic-gate default: 15777c478bd9Sstevel@tonic-gate (void) snprintf(tcpsbuf, sizeof (tcpsbuf), 15787c478bd9Sstevel@tonic-gate "UnknownState(%d)", state); 15797c478bd9Sstevel@tonic-gate cp = tcpsbuf; 15807c478bd9Sstevel@tonic-gate break; 15817c478bd9Sstevel@tonic-gate } 158245916cd2Sjpk 158345916cd2Sjpk if (RSECflag && attr != NULL && attr->tme_flags != 0) { 158445916cd2Sjpk if (cp != tcpsbuf) { 158545916cd2Sjpk (void) strlcpy(tcpsbuf, cp, sizeof (tcpsbuf)); 158645916cd2Sjpk cp = tcpsbuf; 158745916cd2Sjpk } 158845916cd2Sjpk if (attr->tme_flags & MIB2_TMEF_PRIVATE) 158945916cd2Sjpk (void) strlcat(tcpsbuf, " P", sizeof (tcpsbuf)); 159045916cd2Sjpk if (attr->tme_flags & MIB2_TMEF_SHARED) 159145916cd2Sjpk (void) strlcat(tcpsbuf, " S", sizeof (tcpsbuf)); 159245916cd2Sjpk } 159345916cd2Sjpk 159445916cd2Sjpk return (cp); 159545916cd2Sjpk } 159645916cd2Sjpk 159745916cd2Sjpk static const char * 159845916cd2Sjpk miudp_state(int state, const mib2_transportMLPEntry_t *attr) 159945916cd2Sjpk { 160045916cd2Sjpk static char udpsbuf[50]; 160145916cd2Sjpk const char *cp; 160245916cd2Sjpk 160345916cd2Sjpk switch (state) { 160445916cd2Sjpk case MIB2_UDP_unbound: 160545916cd2Sjpk cp = "Unbound"; 160645916cd2Sjpk break; 160745916cd2Sjpk case MIB2_UDP_idle: 160845916cd2Sjpk cp = "Idle"; 160945916cd2Sjpk break; 161045916cd2Sjpk case MIB2_UDP_connected: 161145916cd2Sjpk cp = "Connected"; 161245916cd2Sjpk break; 161345916cd2Sjpk default: 161445916cd2Sjpk (void) snprintf(udpsbuf, sizeof (udpsbuf), 161545916cd2Sjpk "Unknown State(%d)", state); 161645916cd2Sjpk cp = udpsbuf; 161745916cd2Sjpk break; 161845916cd2Sjpk } 161945916cd2Sjpk 162045916cd2Sjpk if (RSECflag && attr != NULL && attr->tme_flags != 0) { 162145916cd2Sjpk if (cp != udpsbuf) { 162245916cd2Sjpk (void) strlcpy(udpsbuf, cp, sizeof (udpsbuf)); 162345916cd2Sjpk cp = udpsbuf; 162445916cd2Sjpk } 162545916cd2Sjpk if (attr->tme_flags & MIB2_TMEF_PRIVATE) 162645916cd2Sjpk (void) strlcat(udpsbuf, " P", sizeof (udpsbuf)); 162745916cd2Sjpk if (attr->tme_flags & MIB2_TMEF_SHARED) 162845916cd2Sjpk (void) strlcat(udpsbuf, " S", sizeof (udpsbuf)); 162945916cd2Sjpk } 163045916cd2Sjpk 16317c478bd9Sstevel@tonic-gate return (cp); 16327c478bd9Sstevel@tonic-gate } 16337c478bd9Sstevel@tonic-gate 16347c478bd9Sstevel@tonic-gate static int odd; 16357c478bd9Sstevel@tonic-gate 16367c478bd9Sstevel@tonic-gate static void 16377c478bd9Sstevel@tonic-gate prval_init(void) 16387c478bd9Sstevel@tonic-gate { 16397c478bd9Sstevel@tonic-gate odd = 0; 16407c478bd9Sstevel@tonic-gate } 16417c478bd9Sstevel@tonic-gate 16427c478bd9Sstevel@tonic-gate static void 16437c478bd9Sstevel@tonic-gate prval(char *str, Counter val) 16447c478bd9Sstevel@tonic-gate { 16457c478bd9Sstevel@tonic-gate (void) printf("\t%-20s=%6u", str, val); 16467c478bd9Sstevel@tonic-gate if (odd++ & 1) 16477c478bd9Sstevel@tonic-gate (void) putchar('\n'); 16487c478bd9Sstevel@tonic-gate } 16497c478bd9Sstevel@tonic-gate 16507c478bd9Sstevel@tonic-gate static void 16517c478bd9Sstevel@tonic-gate prval64(char *str, Counter64 val) 16527c478bd9Sstevel@tonic-gate { 16537c478bd9Sstevel@tonic-gate (void) printf("\t%-20s=%6llu", str, val); 16547c478bd9Sstevel@tonic-gate if (odd++ & 1) 16557c478bd9Sstevel@tonic-gate (void) putchar('\n'); 16567c478bd9Sstevel@tonic-gate } 16577c478bd9Sstevel@tonic-gate 16587c478bd9Sstevel@tonic-gate static void 16597c478bd9Sstevel@tonic-gate pr_int_val(char *str, int val) 16607c478bd9Sstevel@tonic-gate { 16617c478bd9Sstevel@tonic-gate (void) printf("\t%-20s=%6d", str, val); 16627c478bd9Sstevel@tonic-gate if (odd++ & 1) 16637c478bd9Sstevel@tonic-gate (void) putchar('\n'); 16647c478bd9Sstevel@tonic-gate } 16657c478bd9Sstevel@tonic-gate 16667c478bd9Sstevel@tonic-gate static void 16677c478bd9Sstevel@tonic-gate pr_sctp_rtoalgo(char *str, int val) 16687c478bd9Sstevel@tonic-gate { 16697c478bd9Sstevel@tonic-gate (void) printf("\t%-20s=", str); 16707c478bd9Sstevel@tonic-gate switch (val) { 16717c478bd9Sstevel@tonic-gate case MIB2_SCTP_RTOALGO_OTHER: 16727c478bd9Sstevel@tonic-gate (void) printf("%6.6s", "other"); 16737c478bd9Sstevel@tonic-gate break; 16747c478bd9Sstevel@tonic-gate 16757c478bd9Sstevel@tonic-gate case MIB2_SCTP_RTOALGO_VANJ: 16767c478bd9Sstevel@tonic-gate (void) printf("%6.6s", "vanj"); 16777c478bd9Sstevel@tonic-gate break; 16787c478bd9Sstevel@tonic-gate 16797c478bd9Sstevel@tonic-gate default: 16807c478bd9Sstevel@tonic-gate (void) printf("%6d", val); 16817c478bd9Sstevel@tonic-gate break; 16827c478bd9Sstevel@tonic-gate } 16837c478bd9Sstevel@tonic-gate if (odd++ & 1) 16847c478bd9Sstevel@tonic-gate (void) putchar('\n'); 16857c478bd9Sstevel@tonic-gate } 16867c478bd9Sstevel@tonic-gate 16877c478bd9Sstevel@tonic-gate static void 16887c478bd9Sstevel@tonic-gate prval_end(void) 16897c478bd9Sstevel@tonic-gate { 16907c478bd9Sstevel@tonic-gate if (odd++ & 1) 16917c478bd9Sstevel@tonic-gate (void) putchar('\n'); 16927c478bd9Sstevel@tonic-gate } 16937c478bd9Sstevel@tonic-gate 16947c478bd9Sstevel@tonic-gate /* Extract constant sizes */ 16957c478bd9Sstevel@tonic-gate static void 16967c478bd9Sstevel@tonic-gate mib_get_constants(mib_item_t *item) 16977c478bd9Sstevel@tonic-gate { 16987c478bd9Sstevel@tonic-gate /* 'for' loop 1: */ 16997c478bd9Sstevel@tonic-gate for (; item; item = item->next_item) { 17007c478bd9Sstevel@tonic-gate if (item->mib_id != 0) 17017c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 17027c478bd9Sstevel@tonic-gate 17037c478bd9Sstevel@tonic-gate switch (item->group) { 17047c478bd9Sstevel@tonic-gate case MIB2_IP: { 17057c478bd9Sstevel@tonic-gate mib2_ip_t *ip = (mib2_ip_t *)item->valp; 17067c478bd9Sstevel@tonic-gate 17077c478bd9Sstevel@tonic-gate ipAddrEntrySize = ip->ipAddrEntrySize; 17087c478bd9Sstevel@tonic-gate ipRouteEntrySize = ip->ipRouteEntrySize; 17097c478bd9Sstevel@tonic-gate ipNetToMediaEntrySize = ip->ipNetToMediaEntrySize; 17107c478bd9Sstevel@tonic-gate ipMemberEntrySize = ip->ipMemberEntrySize; 17117c478bd9Sstevel@tonic-gate ipGroupSourceEntrySize = ip->ipGroupSourceEntrySize; 171245916cd2Sjpk ipRouteAttributeSize = ip->ipRouteAttributeSize; 171345916cd2Sjpk transportMLPSize = ip->transportMLPSize; 17147c478bd9Sstevel@tonic-gate assert(IS_P2ALIGNED(ipAddrEntrySize, 1715*e11c3f44Smeem sizeof (mib2_ipAddrEntry_t *))); 1716*e11c3f44Smeem assert(IS_P2ALIGNED(ipRouteEntrySize, 1717*e11c3f44Smeem sizeof (mib2_ipRouteEntry_t *))); 1718*e11c3f44Smeem assert(IS_P2ALIGNED(ipNetToMediaEntrySize, 1719*e11c3f44Smeem sizeof (mib2_ipNetToMediaEntry_t *))); 1720*e11c3f44Smeem assert(IS_P2ALIGNED(ipMemberEntrySize, 1721*e11c3f44Smeem sizeof (ip_member_t *))); 1722*e11c3f44Smeem assert(IS_P2ALIGNED(ipGroupSourceEntrySize, 1723*e11c3f44Smeem sizeof (ip_grpsrc_t *))); 1724*e11c3f44Smeem assert(IS_P2ALIGNED(ipRouteAttributeSize, 1725*e11c3f44Smeem sizeof (mib2_ipAttributeEntry_t *))); 1726*e11c3f44Smeem assert(IS_P2ALIGNED(transportMLPSize, 1727*e11c3f44Smeem sizeof (mib2_transportMLPEntry_t *))); 17287c478bd9Sstevel@tonic-gate break; 17297c478bd9Sstevel@tonic-gate } 17307c478bd9Sstevel@tonic-gate case EXPER_DVMRP: { 17317c478bd9Sstevel@tonic-gate struct mrtstat *mrts = (struct mrtstat *)item->valp; 17327c478bd9Sstevel@tonic-gate 17337c478bd9Sstevel@tonic-gate vifctlSize = mrts->mrts_vifctlSize; 17347c478bd9Sstevel@tonic-gate mfcctlSize = mrts->mrts_mfcctlSize; 17357c478bd9Sstevel@tonic-gate assert(IS_P2ALIGNED(vifctlSize, 1736*e11c3f44Smeem sizeof (struct vifclt *))); 1737*e11c3f44Smeem assert(IS_P2ALIGNED(mfcctlSize, 1738*e11c3f44Smeem sizeof (struct mfcctl *))); 17397c478bd9Sstevel@tonic-gate break; 17407c478bd9Sstevel@tonic-gate } 17417c478bd9Sstevel@tonic-gate case MIB2_IP6: { 17427c478bd9Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t *ip6; 17437c478bd9Sstevel@tonic-gate /* Just use the first entry */ 17447c478bd9Sstevel@tonic-gate 17457c478bd9Sstevel@tonic-gate ip6 = (mib2_ipv6IfStatsEntry_t *)item->valp; 17467c478bd9Sstevel@tonic-gate ipv6IfStatsEntrySize = ip6->ipv6IfStatsEntrySize; 17477c478bd9Sstevel@tonic-gate ipv6AddrEntrySize = ip6->ipv6AddrEntrySize; 17487c478bd9Sstevel@tonic-gate ipv6RouteEntrySize = ip6->ipv6RouteEntrySize; 17497c478bd9Sstevel@tonic-gate ipv6NetToMediaEntrySize = ip6->ipv6NetToMediaEntrySize; 17507c478bd9Sstevel@tonic-gate ipv6MemberEntrySize = ip6->ipv6MemberEntrySize; 17517c478bd9Sstevel@tonic-gate ipv6GroupSourceEntrySize = 17527c478bd9Sstevel@tonic-gate ip6->ipv6GroupSourceEntrySize; 17537c478bd9Sstevel@tonic-gate assert(IS_P2ALIGNED(ipv6IfStatsEntrySize, 1754*e11c3f44Smeem sizeof (mib2_ipv6IfStatsEntry_t *))); 1755*e11c3f44Smeem assert(IS_P2ALIGNED(ipv6AddrEntrySize, 1756*e11c3f44Smeem sizeof (mib2_ipv6AddrEntry_t *))); 1757*e11c3f44Smeem assert(IS_P2ALIGNED(ipv6RouteEntrySize, 1758*e11c3f44Smeem sizeof (mib2_ipv6RouteEntry_t *))); 1759*e11c3f44Smeem assert(IS_P2ALIGNED(ipv6NetToMediaEntrySize, 1760*e11c3f44Smeem sizeof (mib2_ipv6NetToMediaEntry_t *))); 1761*e11c3f44Smeem assert(IS_P2ALIGNED(ipv6MemberEntrySize, 1762*e11c3f44Smeem sizeof (ipv6_member_t *))); 1763*e11c3f44Smeem assert(IS_P2ALIGNED(ipv6GroupSourceEntrySize, 1764*e11c3f44Smeem sizeof (ipv6_grpsrc_t *))); 17657c478bd9Sstevel@tonic-gate break; 17667c478bd9Sstevel@tonic-gate } 17677c478bd9Sstevel@tonic-gate case MIB2_ICMP6: { 17687c478bd9Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t *icmp6; 17697c478bd9Sstevel@tonic-gate /* Just use the first entry */ 17707c478bd9Sstevel@tonic-gate 17717c478bd9Sstevel@tonic-gate icmp6 = (mib2_ipv6IfIcmpEntry_t *)item->valp; 17727c478bd9Sstevel@tonic-gate ipv6IfIcmpEntrySize = icmp6->ipv6IfIcmpEntrySize; 17737c478bd9Sstevel@tonic-gate assert(IS_P2ALIGNED(ipv6IfIcmpEntrySize, 17747c478bd9Sstevel@tonic-gate sizeof (mib2_ipv6IfIcmpEntry_t *))); 17757c478bd9Sstevel@tonic-gate break; 17767c478bd9Sstevel@tonic-gate } 17777c478bd9Sstevel@tonic-gate case MIB2_TCP: { 17787c478bd9Sstevel@tonic-gate mib2_tcp_t *tcp = (mib2_tcp_t *)item->valp; 17797c478bd9Sstevel@tonic-gate 17807c478bd9Sstevel@tonic-gate tcpConnEntrySize = tcp->tcpConnTableSize; 17817c478bd9Sstevel@tonic-gate tcp6ConnEntrySize = tcp->tcp6ConnTableSize; 17827c478bd9Sstevel@tonic-gate assert(IS_P2ALIGNED(tcpConnEntrySize, 1783*e11c3f44Smeem sizeof (mib2_tcpConnEntry_t *))); 1784*e11c3f44Smeem assert(IS_P2ALIGNED(tcp6ConnEntrySize, 1785*e11c3f44Smeem sizeof (mib2_tcp6ConnEntry_t *))); 17867c478bd9Sstevel@tonic-gate break; 17877c478bd9Sstevel@tonic-gate } 17887c478bd9Sstevel@tonic-gate case MIB2_UDP: { 17897c478bd9Sstevel@tonic-gate mib2_udp_t *udp = (mib2_udp_t *)item->valp; 17907c478bd9Sstevel@tonic-gate 17917c478bd9Sstevel@tonic-gate udpEntrySize = udp->udpEntrySize; 17927c478bd9Sstevel@tonic-gate udp6EntrySize = udp->udp6EntrySize; 17937c478bd9Sstevel@tonic-gate assert(IS_P2ALIGNED(udpEntrySize, 1794*e11c3f44Smeem sizeof (mib2_udpEntry_t *))); 1795*e11c3f44Smeem assert(IS_P2ALIGNED(udp6EntrySize, 1796*e11c3f44Smeem sizeof (mib2_udp6Entry_t *))); 17977c478bd9Sstevel@tonic-gate break; 17987c478bd9Sstevel@tonic-gate } 17997c478bd9Sstevel@tonic-gate case MIB2_SCTP: { 18007c478bd9Sstevel@tonic-gate mib2_sctp_t *sctp = (mib2_sctp_t *)item->valp; 18017c478bd9Sstevel@tonic-gate 18027c478bd9Sstevel@tonic-gate sctpEntrySize = sctp->sctpEntrySize; 18037c478bd9Sstevel@tonic-gate sctpLocalEntrySize = sctp->sctpLocalEntrySize; 18047c478bd9Sstevel@tonic-gate sctpRemoteEntrySize = sctp->sctpRemoteEntrySize; 18057c478bd9Sstevel@tonic-gate break; 18067c478bd9Sstevel@tonic-gate } 18077c478bd9Sstevel@tonic-gate } 18087c478bd9Sstevel@tonic-gate } /* 'for' loop 1 ends */ 18097c478bd9Sstevel@tonic-gate 18107c478bd9Sstevel@tonic-gate if (Dflag) { 18117c478bd9Sstevel@tonic-gate (void) puts("mib_get_constants:"); 18127c478bd9Sstevel@tonic-gate (void) printf("\tipv6IfStatsEntrySize %d\n", 18137c478bd9Sstevel@tonic-gate ipv6IfStatsEntrySize); 18147c478bd9Sstevel@tonic-gate (void) printf("\tipAddrEntrySize %d\n", ipAddrEntrySize); 18157c478bd9Sstevel@tonic-gate (void) printf("\tipRouteEntrySize %d\n", ipRouteEntrySize); 18167c478bd9Sstevel@tonic-gate (void) printf("\tipNetToMediaEntrySize %d\n", 18177c478bd9Sstevel@tonic-gate ipNetToMediaEntrySize); 18187c478bd9Sstevel@tonic-gate (void) printf("\tipMemberEntrySize %d\n", ipMemberEntrySize); 181945916cd2Sjpk (void) printf("\tipRouteAttributeSize %d\n", 182045916cd2Sjpk ipRouteAttributeSize); 18217c478bd9Sstevel@tonic-gate (void) printf("\tvifctlSize %d\n", vifctlSize); 18227c478bd9Sstevel@tonic-gate (void) printf("\tmfcctlSize %d\n", mfcctlSize); 18237c478bd9Sstevel@tonic-gate 18247c478bd9Sstevel@tonic-gate (void) printf("\tipv6AddrEntrySize %d\n", ipv6AddrEntrySize); 18257c478bd9Sstevel@tonic-gate (void) printf("\tipv6RouteEntrySize %d\n", ipv6RouteEntrySize); 18267c478bd9Sstevel@tonic-gate (void) printf("\tipv6NetToMediaEntrySize %d\n", 18277c478bd9Sstevel@tonic-gate ipv6NetToMediaEntrySize); 18287c478bd9Sstevel@tonic-gate (void) printf("\tipv6MemberEntrySize %d\n", 18297c478bd9Sstevel@tonic-gate ipv6MemberEntrySize); 18307c478bd9Sstevel@tonic-gate (void) printf("\tipv6IfIcmpEntrySize %d\n", 18317c478bd9Sstevel@tonic-gate ipv6IfIcmpEntrySize); 183245916cd2Sjpk (void) printf("\ttransportMLPSize %d\n", transportMLPSize); 18337c478bd9Sstevel@tonic-gate (void) printf("\ttcpConnEntrySize %d\n", tcpConnEntrySize); 18347c478bd9Sstevel@tonic-gate (void) printf("\ttcp6ConnEntrySize %d\n", tcp6ConnEntrySize); 18357c478bd9Sstevel@tonic-gate (void) printf("\tudpEntrySize %d\n", udpEntrySize); 18367c478bd9Sstevel@tonic-gate (void) printf("\tudp6EntrySize %d\n", udp6EntrySize); 18377c478bd9Sstevel@tonic-gate (void) printf("\tsctpEntrySize %d\n", sctpEntrySize); 18387c478bd9Sstevel@tonic-gate (void) printf("\tsctpLocalEntrySize %d\n", sctpLocalEntrySize); 18397c478bd9Sstevel@tonic-gate (void) printf("\tsctpRemoteEntrySize %d\n", 18407c478bd9Sstevel@tonic-gate sctpRemoteEntrySize); 18417c478bd9Sstevel@tonic-gate } 18427c478bd9Sstevel@tonic-gate } 18437c478bd9Sstevel@tonic-gate 18447c478bd9Sstevel@tonic-gate 18457c478bd9Sstevel@tonic-gate /* ----------------------------- STAT_REPORT ------------------------------- */ 18467c478bd9Sstevel@tonic-gate 18477c478bd9Sstevel@tonic-gate static void 18487c478bd9Sstevel@tonic-gate stat_report(mib_item_t *item) 18497c478bd9Sstevel@tonic-gate { 18507c478bd9Sstevel@tonic-gate int jtemp = 0; 18517c478bd9Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 18527c478bd9Sstevel@tonic-gate 18537c478bd9Sstevel@tonic-gate /* 'for' loop 1: */ 18547c478bd9Sstevel@tonic-gate for (; item; item = item->next_item) { 18557c478bd9Sstevel@tonic-gate if (Dflag) { 18567c478bd9Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp); 18577c478bd9Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, " 18587c478bd9Sstevel@tonic-gate "length = %d, valp = 0x%p\n", 18597c478bd9Sstevel@tonic-gate item->group, item->mib_id, 18607c478bd9Sstevel@tonic-gate item->length, item->valp); 18617c478bd9Sstevel@tonic-gate } 18627c478bd9Sstevel@tonic-gate if (item->mib_id != 0) 18637c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 18647c478bd9Sstevel@tonic-gate 18657c478bd9Sstevel@tonic-gate switch (item->group) { 18667c478bd9Sstevel@tonic-gate case MIB2_IP: { 18677c478bd9Sstevel@tonic-gate mib2_ip_t *ip = (mib2_ip_t *)item->valp; 18687c478bd9Sstevel@tonic-gate 18697c478bd9Sstevel@tonic-gate if (protocol_selected(IPPROTO_IP) && 18707c478bd9Sstevel@tonic-gate family_selected(AF_INET)) { 18717c478bd9Sstevel@tonic-gate (void) fputs(v4compat ? "\nIP" : "\nIPv4", 18727c478bd9Sstevel@tonic-gate stdout); 18737c478bd9Sstevel@tonic-gate print_ip_stats(ip); 18747c478bd9Sstevel@tonic-gate } 18757c478bd9Sstevel@tonic-gate break; 18767c478bd9Sstevel@tonic-gate } 18777c478bd9Sstevel@tonic-gate case MIB2_ICMP: { 18787c478bd9Sstevel@tonic-gate mib2_icmp_t *icmp = 18797c478bd9Sstevel@tonic-gate (mib2_icmp_t *)item->valp; 18807c478bd9Sstevel@tonic-gate 18817c478bd9Sstevel@tonic-gate if (protocol_selected(IPPROTO_ICMP) && 18827c478bd9Sstevel@tonic-gate family_selected(AF_INET)) { 18837c478bd9Sstevel@tonic-gate (void) fputs(v4compat ? "\nICMP" : "\nICMPv4", 18847c478bd9Sstevel@tonic-gate stdout); 18857c478bd9Sstevel@tonic-gate print_icmp_stats(icmp); 18867c478bd9Sstevel@tonic-gate } 18877c478bd9Sstevel@tonic-gate break; 18887c478bd9Sstevel@tonic-gate } 18897c478bd9Sstevel@tonic-gate case MIB2_IP6: { 18907c478bd9Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t *ip6; 18917c478bd9Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t sum6; 18927c478bd9Sstevel@tonic-gate 18937c478bd9Sstevel@tonic-gate if (!(protocol_selected(IPPROTO_IPV6)) || 18947c478bd9Sstevel@tonic-gate !(family_selected(AF_INET6))) 18957c478bd9Sstevel@tonic-gate break; 18967c478bd9Sstevel@tonic-gate bzero(&sum6, sizeof (sum6)); 18977c478bd9Sstevel@tonic-gate /* 'for' loop 2a: */ 18987c478bd9Sstevel@tonic-gate for (ip6 = (mib2_ipv6IfStatsEntry_t *)item->valp; 1899*e11c3f44Smeem (char *)ip6 < (char *)item->valp + item->length; 19007c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 19017c478bd9Sstevel@tonic-gate ip6 = (mib2_ipv6IfStatsEntry_t *)((char *)ip6 + 19027c478bd9Sstevel@tonic-gate ipv6IfStatsEntrySize)) { 19037c478bd9Sstevel@tonic-gate if (ip6->ipv6IfIndex == 0) { 19047c478bd9Sstevel@tonic-gate /* 19057c478bd9Sstevel@tonic-gate * The "unknown interface" ip6 19067c478bd9Sstevel@tonic-gate * mib. Just add to the sum. 19077c478bd9Sstevel@tonic-gate */ 19087c478bd9Sstevel@tonic-gate sum_ip6_stats(ip6, &sum6); 19097c478bd9Sstevel@tonic-gate continue; /* 'for' loop 2a */ 19107c478bd9Sstevel@tonic-gate } 19117c478bd9Sstevel@tonic-gate if (Aflag) { 19127c478bd9Sstevel@tonic-gate (void) printf("\nIPv6 for %s\n", 1913*e11c3f44Smeem ifindex2str(ip6->ipv6IfIndex, 1914*e11c3f44Smeem ifname)); 19157c478bd9Sstevel@tonic-gate print_ip6_stats(ip6); 19167c478bd9Sstevel@tonic-gate } 19177c478bd9Sstevel@tonic-gate sum_ip6_stats(ip6, &sum6); 19187c478bd9Sstevel@tonic-gate } /* 'for' loop 2a ends */ 19197c478bd9Sstevel@tonic-gate (void) fputs("\nIPv6", stdout); 19207c478bd9Sstevel@tonic-gate print_ip6_stats(&sum6); 19217c478bd9Sstevel@tonic-gate break; 19227c478bd9Sstevel@tonic-gate } 19237c478bd9Sstevel@tonic-gate case MIB2_ICMP6: { 19247c478bd9Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t *icmp6; 19257c478bd9Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t sum6; 19267c478bd9Sstevel@tonic-gate 19277c478bd9Sstevel@tonic-gate if (!(protocol_selected(IPPROTO_ICMPV6)) || 19287c478bd9Sstevel@tonic-gate !(family_selected(AF_INET6))) 19297c478bd9Sstevel@tonic-gate break; 19307c478bd9Sstevel@tonic-gate bzero(&sum6, sizeof (sum6)); 19317c478bd9Sstevel@tonic-gate /* 'for' loop 2b: */ 1932*e11c3f44Smeem for (icmp6 = (mib2_ipv6IfIcmpEntry_t *)item->valp; 1933*e11c3f44Smeem (char *)icmp6 < (char *)item->valp + item->length; 1934*e11c3f44Smeem icmp6 = (void *)((char *)icmp6 + 1935*e11c3f44Smeem ipv6IfIcmpEntrySize)) { 19367c478bd9Sstevel@tonic-gate if (icmp6->ipv6IfIcmpIfIndex == 0) { 19377c478bd9Sstevel@tonic-gate /* 19387c478bd9Sstevel@tonic-gate * The "unknown interface" icmp6 19397c478bd9Sstevel@tonic-gate * mib. Just add to the sum. 19407c478bd9Sstevel@tonic-gate */ 19417c478bd9Sstevel@tonic-gate sum_icmp6_stats(icmp6, &sum6); 19427c478bd9Sstevel@tonic-gate continue; /* 'for' loop 2b: */ 19437c478bd9Sstevel@tonic-gate } 19447c478bd9Sstevel@tonic-gate if (Aflag) { 1945*e11c3f44Smeem (void) printf("\nICMPv6 for %s\n", 1946*e11c3f44Smeem ifindex2str( 1947*e11c3f44Smeem icmp6->ipv6IfIcmpIfIndex, ifname)); 19487c478bd9Sstevel@tonic-gate print_icmp6_stats(icmp6); 19497c478bd9Sstevel@tonic-gate } 19507c478bd9Sstevel@tonic-gate sum_icmp6_stats(icmp6, &sum6); 19517c478bd9Sstevel@tonic-gate } /* 'for' loop 2b ends */ 19527c478bd9Sstevel@tonic-gate (void) fputs("\nICMPv6", stdout); 19537c478bd9Sstevel@tonic-gate print_icmp6_stats(&sum6); 19547c478bd9Sstevel@tonic-gate break; 19557c478bd9Sstevel@tonic-gate } 19567c478bd9Sstevel@tonic-gate case MIB2_TCP: { 19577c478bd9Sstevel@tonic-gate mib2_tcp_t *tcp = (mib2_tcp_t *)item->valp; 19587c478bd9Sstevel@tonic-gate 19597c478bd9Sstevel@tonic-gate if (protocol_selected(IPPROTO_TCP) && 19607c478bd9Sstevel@tonic-gate (family_selected(AF_INET) || 19617c478bd9Sstevel@tonic-gate family_selected(AF_INET6))) { 19627c478bd9Sstevel@tonic-gate (void) fputs("\nTCP", stdout); 19637c478bd9Sstevel@tonic-gate print_tcp_stats(tcp); 19647c478bd9Sstevel@tonic-gate } 19657c478bd9Sstevel@tonic-gate break; 19667c478bd9Sstevel@tonic-gate } 19677c478bd9Sstevel@tonic-gate case MIB2_UDP: { 19687c478bd9Sstevel@tonic-gate mib2_udp_t *udp = (mib2_udp_t *)item->valp; 19697c478bd9Sstevel@tonic-gate 19707c478bd9Sstevel@tonic-gate if (protocol_selected(IPPROTO_UDP) && 19717c478bd9Sstevel@tonic-gate (family_selected(AF_INET) || 19727c478bd9Sstevel@tonic-gate family_selected(AF_INET6))) { 19737c478bd9Sstevel@tonic-gate (void) fputs("\nUDP", stdout); 19747c478bd9Sstevel@tonic-gate print_udp_stats(udp); 19757c478bd9Sstevel@tonic-gate } 19767c478bd9Sstevel@tonic-gate break; 19777c478bd9Sstevel@tonic-gate } 19787c478bd9Sstevel@tonic-gate case MIB2_SCTP: { 19797c478bd9Sstevel@tonic-gate mib2_sctp_t *sctp = (mib2_sctp_t *)item->valp; 19807c478bd9Sstevel@tonic-gate 19817c478bd9Sstevel@tonic-gate if (protocol_selected(IPPROTO_SCTP) && 19827c478bd9Sstevel@tonic-gate (family_selected(AF_INET) || 19837c478bd9Sstevel@tonic-gate family_selected(AF_INET6))) { 19847c478bd9Sstevel@tonic-gate (void) fputs("\nSCTP", stdout); 19857c478bd9Sstevel@tonic-gate print_sctp_stats(sctp); 19867c478bd9Sstevel@tonic-gate } 19877c478bd9Sstevel@tonic-gate break; 19887c478bd9Sstevel@tonic-gate } 19897c478bd9Sstevel@tonic-gate case EXPER_RAWIP: { 19907c478bd9Sstevel@tonic-gate mib2_rawip_t *rawip = 19917c478bd9Sstevel@tonic-gate (mib2_rawip_t *)item->valp; 19927c478bd9Sstevel@tonic-gate 19937c478bd9Sstevel@tonic-gate if (protocol_selected(IPPROTO_RAW) && 19947c478bd9Sstevel@tonic-gate (family_selected(AF_INET) || 19957c478bd9Sstevel@tonic-gate family_selected(AF_INET6))) { 19967c478bd9Sstevel@tonic-gate (void) fputs("\nRAWIP", stdout); 19977c478bd9Sstevel@tonic-gate print_rawip_stats(rawip); 19987c478bd9Sstevel@tonic-gate } 19997c478bd9Sstevel@tonic-gate break; 20007c478bd9Sstevel@tonic-gate } 20017c478bd9Sstevel@tonic-gate case EXPER_IGMP: { 20027c478bd9Sstevel@tonic-gate struct igmpstat *igps = 20037c478bd9Sstevel@tonic-gate (struct igmpstat *)item->valp; 20047c478bd9Sstevel@tonic-gate 20057c478bd9Sstevel@tonic-gate if (protocol_selected(IPPROTO_IGMP) && 20067c478bd9Sstevel@tonic-gate (family_selected(AF_INET))) { 20077c478bd9Sstevel@tonic-gate (void) fputs("\nIGMP:\n", stdout); 20087c478bd9Sstevel@tonic-gate print_igmp_stats(igps); 20097c478bd9Sstevel@tonic-gate } 20107c478bd9Sstevel@tonic-gate break; 20117c478bd9Sstevel@tonic-gate } 20127c478bd9Sstevel@tonic-gate } 20137c478bd9Sstevel@tonic-gate } /* 'for' loop 1 ends */ 20147c478bd9Sstevel@tonic-gate (void) putchar('\n'); 20157c478bd9Sstevel@tonic-gate (void) fflush(stdout); 20167c478bd9Sstevel@tonic-gate } 20177c478bd9Sstevel@tonic-gate 20187c478bd9Sstevel@tonic-gate static void 20197c478bd9Sstevel@tonic-gate print_ip_stats(mib2_ip_t *ip) 20207c478bd9Sstevel@tonic-gate { 20217c478bd9Sstevel@tonic-gate prval_init(); 20227c478bd9Sstevel@tonic-gate pr_int_val("ipForwarding", ip->ipForwarding); 20237c478bd9Sstevel@tonic-gate pr_int_val("ipDefaultTTL", ip->ipDefaultTTL); 20247c478bd9Sstevel@tonic-gate prval("ipInReceives", ip->ipInReceives); 20257c478bd9Sstevel@tonic-gate prval("ipInHdrErrors", ip->ipInHdrErrors); 20267c478bd9Sstevel@tonic-gate prval("ipInAddrErrors", ip->ipInAddrErrors); 20277c478bd9Sstevel@tonic-gate prval("ipInCksumErrs", ip->ipInCksumErrs); 20287c478bd9Sstevel@tonic-gate prval("ipForwDatagrams", ip->ipForwDatagrams); 20297c478bd9Sstevel@tonic-gate prval("ipForwProhibits", ip->ipForwProhibits); 20307c478bd9Sstevel@tonic-gate prval("ipInUnknownProtos", ip->ipInUnknownProtos); 20317c478bd9Sstevel@tonic-gate prval("ipInDiscards", ip->ipInDiscards); 20327c478bd9Sstevel@tonic-gate prval("ipInDelivers", ip->ipInDelivers); 20337c478bd9Sstevel@tonic-gate prval("ipOutRequests", ip->ipOutRequests); 20347c478bd9Sstevel@tonic-gate prval("ipOutDiscards", ip->ipOutDiscards); 20357c478bd9Sstevel@tonic-gate prval("ipOutNoRoutes", ip->ipOutNoRoutes); 20367c478bd9Sstevel@tonic-gate pr_int_val("ipReasmTimeout", ip->ipReasmTimeout); 20377c478bd9Sstevel@tonic-gate prval("ipReasmReqds", ip->ipReasmReqds); 20387c478bd9Sstevel@tonic-gate prval("ipReasmOKs", ip->ipReasmOKs); 20397c478bd9Sstevel@tonic-gate prval("ipReasmFails", ip->ipReasmFails); 20407c478bd9Sstevel@tonic-gate prval("ipReasmDuplicates", ip->ipReasmDuplicates); 20417c478bd9Sstevel@tonic-gate prval("ipReasmPartDups", ip->ipReasmPartDups); 20427c478bd9Sstevel@tonic-gate prval("ipFragOKs", ip->ipFragOKs); 20437c478bd9Sstevel@tonic-gate prval("ipFragFails", ip->ipFragFails); 20447c478bd9Sstevel@tonic-gate prval("ipFragCreates", ip->ipFragCreates); 20457c478bd9Sstevel@tonic-gate prval("ipRoutingDiscards", ip->ipRoutingDiscards); 20467c478bd9Sstevel@tonic-gate 20477c478bd9Sstevel@tonic-gate prval("tcpInErrs", ip->tcpInErrs); 20487c478bd9Sstevel@tonic-gate prval("udpNoPorts", ip->udpNoPorts); 20497c478bd9Sstevel@tonic-gate prval("udpInCksumErrs", ip->udpInCksumErrs); 20507c478bd9Sstevel@tonic-gate prval("udpInOverflows", ip->udpInOverflows); 20517c478bd9Sstevel@tonic-gate prval("rawipInOverflows", ip->rawipInOverflows); 20527c478bd9Sstevel@tonic-gate prval("ipsecInSucceeded", ip->ipsecInSucceeded); 20537c478bd9Sstevel@tonic-gate prval("ipsecInFailed", ip->ipsecInFailed); 20547c478bd9Sstevel@tonic-gate prval("ipInIPv6", ip->ipInIPv6); 20557c478bd9Sstevel@tonic-gate prval("ipOutIPv6", ip->ipOutIPv6); 20567c478bd9Sstevel@tonic-gate prval("ipOutSwitchIPv6", ip->ipOutSwitchIPv6); 20577c478bd9Sstevel@tonic-gate prval_end(); 20587c478bd9Sstevel@tonic-gate } 20597c478bd9Sstevel@tonic-gate 20607c478bd9Sstevel@tonic-gate static void 20617c478bd9Sstevel@tonic-gate print_icmp_stats(mib2_icmp_t *icmp) 20627c478bd9Sstevel@tonic-gate { 20637c478bd9Sstevel@tonic-gate prval_init(); 20647c478bd9Sstevel@tonic-gate prval("icmpInMsgs", icmp->icmpInMsgs); 20657c478bd9Sstevel@tonic-gate prval("icmpInErrors", icmp->icmpInErrors); 20667c478bd9Sstevel@tonic-gate prval("icmpInCksumErrs", icmp->icmpInCksumErrs); 20677c478bd9Sstevel@tonic-gate prval("icmpInUnknowns", icmp->icmpInUnknowns); 20687c478bd9Sstevel@tonic-gate prval("icmpInDestUnreachs", icmp->icmpInDestUnreachs); 20697c478bd9Sstevel@tonic-gate prval("icmpInTimeExcds", icmp->icmpInTimeExcds); 20707c478bd9Sstevel@tonic-gate prval("icmpInParmProbs", icmp->icmpInParmProbs); 20717c478bd9Sstevel@tonic-gate prval("icmpInSrcQuenchs", icmp->icmpInSrcQuenchs); 20727c478bd9Sstevel@tonic-gate prval("icmpInRedirects", icmp->icmpInRedirects); 20737c478bd9Sstevel@tonic-gate prval("icmpInBadRedirects", icmp->icmpInBadRedirects); 20747c478bd9Sstevel@tonic-gate prval("icmpInEchos", icmp->icmpInEchos); 20757c478bd9Sstevel@tonic-gate prval("icmpInEchoReps", icmp->icmpInEchoReps); 20767c478bd9Sstevel@tonic-gate prval("icmpInTimestamps", icmp->icmpInTimestamps); 20777c478bd9Sstevel@tonic-gate prval("icmpInTimestampReps", icmp->icmpInTimestampReps); 20787c478bd9Sstevel@tonic-gate prval("icmpInAddrMasks", icmp->icmpInAddrMasks); 20797c478bd9Sstevel@tonic-gate prval("icmpInAddrMaskReps", icmp->icmpInAddrMaskReps); 20807c478bd9Sstevel@tonic-gate prval("icmpInFragNeeded", icmp->icmpInFragNeeded); 20817c478bd9Sstevel@tonic-gate prval("icmpOutMsgs", icmp->icmpOutMsgs); 20827c478bd9Sstevel@tonic-gate prval("icmpOutDrops", icmp->icmpOutDrops); 20837c478bd9Sstevel@tonic-gate prval("icmpOutErrors", icmp->icmpOutErrors); 20847c478bd9Sstevel@tonic-gate prval("icmpOutDestUnreachs", icmp->icmpOutDestUnreachs); 20857c478bd9Sstevel@tonic-gate prval("icmpOutTimeExcds", icmp->icmpOutTimeExcds); 20867c478bd9Sstevel@tonic-gate prval("icmpOutParmProbs", icmp->icmpOutParmProbs); 20877c478bd9Sstevel@tonic-gate prval("icmpOutSrcQuenchs", icmp->icmpOutSrcQuenchs); 20887c478bd9Sstevel@tonic-gate prval("icmpOutRedirects", icmp->icmpOutRedirects); 20897c478bd9Sstevel@tonic-gate prval("icmpOutEchos", icmp->icmpOutEchos); 20907c478bd9Sstevel@tonic-gate prval("icmpOutEchoReps", icmp->icmpOutEchoReps); 20917c478bd9Sstevel@tonic-gate prval("icmpOutTimestamps", icmp->icmpOutTimestamps); 20927c478bd9Sstevel@tonic-gate prval("icmpOutTimestampReps", icmp->icmpOutTimestampReps); 20937c478bd9Sstevel@tonic-gate prval("icmpOutAddrMasks", icmp->icmpOutAddrMasks); 20947c478bd9Sstevel@tonic-gate prval("icmpOutAddrMaskReps", icmp->icmpOutAddrMaskReps); 20957c478bd9Sstevel@tonic-gate prval("icmpOutFragNeeded", icmp->icmpOutFragNeeded); 20967c478bd9Sstevel@tonic-gate prval("icmpInOverflows", icmp->icmpInOverflows); 20977c478bd9Sstevel@tonic-gate prval_end(); 20987c478bd9Sstevel@tonic-gate } 20997c478bd9Sstevel@tonic-gate 21007c478bd9Sstevel@tonic-gate static void 21017c478bd9Sstevel@tonic-gate print_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6) 21027c478bd9Sstevel@tonic-gate { 21037c478bd9Sstevel@tonic-gate prval_init(); 21047c478bd9Sstevel@tonic-gate prval("ipv6Forwarding", ip6->ipv6Forwarding); 21057c478bd9Sstevel@tonic-gate prval("ipv6DefaultHopLimit", ip6->ipv6DefaultHopLimit); 21067c478bd9Sstevel@tonic-gate 21077c478bd9Sstevel@tonic-gate prval("ipv6InReceives", ip6->ipv6InReceives); 21087c478bd9Sstevel@tonic-gate prval("ipv6InHdrErrors", ip6->ipv6InHdrErrors); 21097c478bd9Sstevel@tonic-gate prval("ipv6InTooBigErrors", ip6->ipv6InTooBigErrors); 21107c478bd9Sstevel@tonic-gate prval("ipv6InNoRoutes", ip6->ipv6InNoRoutes); 21117c478bd9Sstevel@tonic-gate prval("ipv6InAddrErrors", ip6->ipv6InAddrErrors); 21127c478bd9Sstevel@tonic-gate prval("ipv6InUnknownProtos", ip6->ipv6InUnknownProtos); 21137c478bd9Sstevel@tonic-gate prval("ipv6InTruncatedPkts", ip6->ipv6InTruncatedPkts); 21147c478bd9Sstevel@tonic-gate prval("ipv6InDiscards", ip6->ipv6InDiscards); 21157c478bd9Sstevel@tonic-gate prval("ipv6InDelivers", ip6->ipv6InDelivers); 21167c478bd9Sstevel@tonic-gate prval("ipv6OutForwDatagrams", ip6->ipv6OutForwDatagrams); 21177c478bd9Sstevel@tonic-gate prval("ipv6OutRequests", ip6->ipv6OutRequests); 21187c478bd9Sstevel@tonic-gate prval("ipv6OutDiscards", ip6->ipv6OutDiscards); 21197c478bd9Sstevel@tonic-gate prval("ipv6OutNoRoutes", ip6->ipv6OutNoRoutes); 21207c478bd9Sstevel@tonic-gate prval("ipv6OutFragOKs", ip6->ipv6OutFragOKs); 21217c478bd9Sstevel@tonic-gate prval("ipv6OutFragFails", ip6->ipv6OutFragFails); 21227c478bd9Sstevel@tonic-gate prval("ipv6OutFragCreates", ip6->ipv6OutFragCreates); 21237c478bd9Sstevel@tonic-gate prval("ipv6ReasmReqds", ip6->ipv6ReasmReqds); 21247c478bd9Sstevel@tonic-gate prval("ipv6ReasmOKs", ip6->ipv6ReasmOKs); 21257c478bd9Sstevel@tonic-gate prval("ipv6ReasmFails", ip6->ipv6ReasmFails); 21267c478bd9Sstevel@tonic-gate prval("ipv6InMcastPkts", ip6->ipv6InMcastPkts); 21277c478bd9Sstevel@tonic-gate prval("ipv6OutMcastPkts", ip6->ipv6OutMcastPkts); 21287c478bd9Sstevel@tonic-gate prval("ipv6ReasmDuplicates", ip6->ipv6ReasmDuplicates); 21297c478bd9Sstevel@tonic-gate prval("ipv6ReasmPartDups", ip6->ipv6ReasmPartDups); 21307c478bd9Sstevel@tonic-gate prval("ipv6ForwProhibits", ip6->ipv6ForwProhibits); 21317c478bd9Sstevel@tonic-gate prval("udpInCksumErrs", ip6->udpInCksumErrs); 21327c478bd9Sstevel@tonic-gate prval("udpInOverflows", ip6->udpInOverflows); 21337c478bd9Sstevel@tonic-gate prval("rawipInOverflows", ip6->rawipInOverflows); 21347c478bd9Sstevel@tonic-gate prval("ipv6InIPv4", ip6->ipv6InIPv4); 21357c478bd9Sstevel@tonic-gate prval("ipv6OutIPv4", ip6->ipv6OutIPv4); 21367c478bd9Sstevel@tonic-gate prval("ipv6OutSwitchIPv4", ip6->ipv6OutSwitchIPv4); 21377c478bd9Sstevel@tonic-gate prval_end(); 21387c478bd9Sstevel@tonic-gate } 21397c478bd9Sstevel@tonic-gate 21407c478bd9Sstevel@tonic-gate static void 21417c478bd9Sstevel@tonic-gate print_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6) 21427c478bd9Sstevel@tonic-gate { 21437c478bd9Sstevel@tonic-gate prval_init(); 21447c478bd9Sstevel@tonic-gate prval("icmp6InMsgs", icmp6->ipv6IfIcmpInMsgs); 21457c478bd9Sstevel@tonic-gate prval("icmp6InErrors", icmp6->ipv6IfIcmpInErrors); 21467c478bd9Sstevel@tonic-gate prval("icmp6InDestUnreachs", icmp6->ipv6IfIcmpInDestUnreachs); 21477c478bd9Sstevel@tonic-gate prval("icmp6InAdminProhibs", icmp6->ipv6IfIcmpInAdminProhibs); 21487c478bd9Sstevel@tonic-gate prval("icmp6InTimeExcds", icmp6->ipv6IfIcmpInTimeExcds); 21497c478bd9Sstevel@tonic-gate prval("icmp6InParmProblems", icmp6->ipv6IfIcmpInParmProblems); 21507c478bd9Sstevel@tonic-gate prval("icmp6InPktTooBigs", icmp6->ipv6IfIcmpInPktTooBigs); 21517c478bd9Sstevel@tonic-gate prval("icmp6InEchos", icmp6->ipv6IfIcmpInEchos); 21527c478bd9Sstevel@tonic-gate prval("icmp6InEchoReplies", icmp6->ipv6IfIcmpInEchoReplies); 21537c478bd9Sstevel@tonic-gate prval("icmp6InRouterSols", icmp6->ipv6IfIcmpInRouterSolicits); 21547c478bd9Sstevel@tonic-gate prval("icmp6InRouterAds", 21557c478bd9Sstevel@tonic-gate icmp6->ipv6IfIcmpInRouterAdvertisements); 21567c478bd9Sstevel@tonic-gate prval("icmp6InNeighborSols", icmp6->ipv6IfIcmpInNeighborSolicits); 21577c478bd9Sstevel@tonic-gate prval("icmp6InNeighborAds", 21587c478bd9Sstevel@tonic-gate icmp6->ipv6IfIcmpInNeighborAdvertisements); 21597c478bd9Sstevel@tonic-gate prval("icmp6InRedirects", icmp6->ipv6IfIcmpInRedirects); 21607c478bd9Sstevel@tonic-gate prval("icmp6InBadRedirects", icmp6->ipv6IfIcmpInBadRedirects); 21617c478bd9Sstevel@tonic-gate prval("icmp6InGroupQueries", icmp6->ipv6IfIcmpInGroupMembQueries); 21627c478bd9Sstevel@tonic-gate prval("icmp6InGroupResps", icmp6->ipv6IfIcmpInGroupMembResponses); 21637c478bd9Sstevel@tonic-gate prval("icmp6InGroupReds", icmp6->ipv6IfIcmpInGroupMembReductions); 21647c478bd9Sstevel@tonic-gate prval("icmp6InOverflows", icmp6->ipv6IfIcmpInOverflows); 21657c478bd9Sstevel@tonic-gate prval_end(); 21667c478bd9Sstevel@tonic-gate prval_init(); 21677c478bd9Sstevel@tonic-gate prval("icmp6OutMsgs", icmp6->ipv6IfIcmpOutMsgs); 21687c478bd9Sstevel@tonic-gate prval("icmp6OutErrors", icmp6->ipv6IfIcmpOutErrors); 21697c478bd9Sstevel@tonic-gate prval("icmp6OutDestUnreachs", icmp6->ipv6IfIcmpOutDestUnreachs); 21707c478bd9Sstevel@tonic-gate prval("icmp6OutAdminProhibs", icmp6->ipv6IfIcmpOutAdminProhibs); 21717c478bd9Sstevel@tonic-gate prval("icmp6OutTimeExcds", icmp6->ipv6IfIcmpOutTimeExcds); 21727c478bd9Sstevel@tonic-gate prval("icmp6OutParmProblems", icmp6->ipv6IfIcmpOutParmProblems); 21737c478bd9Sstevel@tonic-gate prval("icmp6OutPktTooBigs", icmp6->ipv6IfIcmpOutPktTooBigs); 21747c478bd9Sstevel@tonic-gate prval("icmp6OutEchos", icmp6->ipv6IfIcmpOutEchos); 21757c478bd9Sstevel@tonic-gate prval("icmp6OutEchoReplies", icmp6->ipv6IfIcmpOutEchoReplies); 21767c478bd9Sstevel@tonic-gate prval("icmp6OutRouterSols", icmp6->ipv6IfIcmpOutRouterSolicits); 21777c478bd9Sstevel@tonic-gate prval("icmp6OutRouterAds", 21787c478bd9Sstevel@tonic-gate icmp6->ipv6IfIcmpOutRouterAdvertisements); 21797c478bd9Sstevel@tonic-gate prval("icmp6OutNeighborSols", icmp6->ipv6IfIcmpOutNeighborSolicits); 21807c478bd9Sstevel@tonic-gate prval("icmp6OutNeighborAds", 21817c478bd9Sstevel@tonic-gate icmp6->ipv6IfIcmpOutNeighborAdvertisements); 21827c478bd9Sstevel@tonic-gate prval("icmp6OutRedirects", icmp6->ipv6IfIcmpOutRedirects); 21837c478bd9Sstevel@tonic-gate prval("icmp6OutGroupQueries", icmp6->ipv6IfIcmpOutGroupMembQueries); 21847c478bd9Sstevel@tonic-gate prval("icmp6OutGroupResps", 21857c478bd9Sstevel@tonic-gate icmp6->ipv6IfIcmpOutGroupMembResponses); 21867c478bd9Sstevel@tonic-gate prval("icmp6OutGroupReds", 21877c478bd9Sstevel@tonic-gate icmp6->ipv6IfIcmpOutGroupMembReductions); 21887c478bd9Sstevel@tonic-gate prval_end(); 21897c478bd9Sstevel@tonic-gate } 21907c478bd9Sstevel@tonic-gate 21917c478bd9Sstevel@tonic-gate static void 21927c478bd9Sstevel@tonic-gate print_sctp_stats(mib2_sctp_t *sctp) 21937c478bd9Sstevel@tonic-gate { 21947c478bd9Sstevel@tonic-gate prval_init(); 21957c478bd9Sstevel@tonic-gate pr_sctp_rtoalgo("sctpRtoAlgorithm", sctp->sctpRtoAlgorithm); 21967c478bd9Sstevel@tonic-gate prval("sctpRtoMin", sctp->sctpRtoMin); 21977c478bd9Sstevel@tonic-gate prval("sctpRtoMax", sctp->sctpRtoMax); 21987c478bd9Sstevel@tonic-gate prval("sctpRtoInitial", sctp->sctpRtoInitial); 21997c478bd9Sstevel@tonic-gate pr_int_val("sctpMaxAssocs", sctp->sctpMaxAssocs); 22007c478bd9Sstevel@tonic-gate prval("sctpValCookieLife", sctp->sctpValCookieLife); 22017c478bd9Sstevel@tonic-gate prval("sctpMaxInitRetr", sctp->sctpMaxInitRetr); 22027c478bd9Sstevel@tonic-gate prval("sctpCurrEstab", sctp->sctpCurrEstab); 22037c478bd9Sstevel@tonic-gate prval("sctpActiveEstab", sctp->sctpActiveEstab); 22047c478bd9Sstevel@tonic-gate prval("sctpPassiveEstab", sctp->sctpPassiveEstab); 22057c478bd9Sstevel@tonic-gate prval("sctpAborted", sctp->sctpAborted); 22067c478bd9Sstevel@tonic-gate prval("sctpShutdowns", sctp->sctpShutdowns); 22077c478bd9Sstevel@tonic-gate prval("sctpOutOfBlue", sctp->sctpOutOfBlue); 22087c478bd9Sstevel@tonic-gate prval("sctpChecksumError", sctp->sctpChecksumError); 22097c478bd9Sstevel@tonic-gate prval64("sctpOutCtrlChunks", sctp->sctpOutCtrlChunks); 22107c478bd9Sstevel@tonic-gate prval64("sctpOutOrderChunks", sctp->sctpOutOrderChunks); 22117c478bd9Sstevel@tonic-gate prval64("sctpOutUnorderChunks", sctp->sctpOutUnorderChunks); 22127c478bd9Sstevel@tonic-gate prval64("sctpRetransChunks", sctp->sctpRetransChunks); 22137c478bd9Sstevel@tonic-gate prval("sctpOutAck", sctp->sctpOutAck); 22147c478bd9Sstevel@tonic-gate prval("sctpOutAckDelayed", sctp->sctpOutAckDelayed); 22157c478bd9Sstevel@tonic-gate prval("sctpOutWinUpdate", sctp->sctpOutWinUpdate); 22167c478bd9Sstevel@tonic-gate prval("sctpOutFastRetrans", sctp->sctpOutFastRetrans); 22177c478bd9Sstevel@tonic-gate prval("sctpOutWinProbe", sctp->sctpOutWinProbe); 22187c478bd9Sstevel@tonic-gate prval64("sctpInCtrlChunks", sctp->sctpInCtrlChunks); 22197c478bd9Sstevel@tonic-gate prval64("sctpInOrderChunks", sctp->sctpInOrderChunks); 22207c478bd9Sstevel@tonic-gate prval64("sctpInUnorderChunks", sctp->sctpInUnorderChunks); 22217c478bd9Sstevel@tonic-gate prval("sctpInAck", sctp->sctpInAck); 22227c478bd9Sstevel@tonic-gate prval("sctpInDupAck", sctp->sctpInDupAck); 22237c478bd9Sstevel@tonic-gate prval("sctpInAckUnsent", sctp->sctpInAckUnsent); 22247c478bd9Sstevel@tonic-gate prval64("sctpFragUsrMsgs", sctp->sctpFragUsrMsgs); 22257c478bd9Sstevel@tonic-gate prval64("sctpReasmUsrMsgs", sctp->sctpReasmUsrMsgs); 22267c478bd9Sstevel@tonic-gate prval64("sctpOutSCTPPkts", sctp->sctpOutSCTPPkts); 22277c478bd9Sstevel@tonic-gate prval64("sctpInSCTPPkts", sctp->sctpInSCTPPkts); 22287c478bd9Sstevel@tonic-gate prval("sctpInInvalidCookie", sctp->sctpInInvalidCookie); 22297c478bd9Sstevel@tonic-gate prval("sctpTimRetrans", sctp->sctpTimRetrans); 22307c478bd9Sstevel@tonic-gate prval("sctpTimRetransDrop", sctp->sctpTimRetransDrop); 22317c478bd9Sstevel@tonic-gate prval("sctpTimHearBeatProbe", sctp->sctpTimHeartBeatProbe); 22327c478bd9Sstevel@tonic-gate prval("sctpTimHearBeatDrop", sctp->sctpTimHeartBeatDrop); 22337c478bd9Sstevel@tonic-gate prval("sctpListenDrop", sctp->sctpListenDrop); 22347c478bd9Sstevel@tonic-gate prval("sctpInClosed", sctp->sctpInClosed); 22357c478bd9Sstevel@tonic-gate prval_end(); 22367c478bd9Sstevel@tonic-gate } 22377c478bd9Sstevel@tonic-gate 22387c478bd9Sstevel@tonic-gate static void 22397c478bd9Sstevel@tonic-gate print_tcp_stats(mib2_tcp_t *tcp) 22407c478bd9Sstevel@tonic-gate { 22417c478bd9Sstevel@tonic-gate prval_init(); 22427c478bd9Sstevel@tonic-gate pr_int_val("tcpRtoAlgorithm", tcp->tcpRtoAlgorithm); 22437c478bd9Sstevel@tonic-gate pr_int_val("tcpRtoMin", tcp->tcpRtoMin); 22447c478bd9Sstevel@tonic-gate pr_int_val("tcpRtoMax", tcp->tcpRtoMax); 22457c478bd9Sstevel@tonic-gate pr_int_val("tcpMaxConn", tcp->tcpMaxConn); 22467c478bd9Sstevel@tonic-gate prval("tcpActiveOpens", tcp->tcpActiveOpens); 22477c478bd9Sstevel@tonic-gate prval("tcpPassiveOpens", tcp->tcpPassiveOpens); 22487c478bd9Sstevel@tonic-gate prval("tcpAttemptFails", tcp->tcpAttemptFails); 22497c478bd9Sstevel@tonic-gate prval("tcpEstabResets", tcp->tcpEstabResets); 22507c478bd9Sstevel@tonic-gate prval("tcpCurrEstab", tcp->tcpCurrEstab); 22513173664eSapersson prval64("tcpOutSegs", tcp->tcpHCOutSegs); 22527c478bd9Sstevel@tonic-gate prval("tcpOutDataSegs", tcp->tcpOutDataSegs); 22537c478bd9Sstevel@tonic-gate prval("tcpOutDataBytes", tcp->tcpOutDataBytes); 22547c478bd9Sstevel@tonic-gate prval("tcpRetransSegs", tcp->tcpRetransSegs); 22557c478bd9Sstevel@tonic-gate prval("tcpRetransBytes", tcp->tcpRetransBytes); 22567c478bd9Sstevel@tonic-gate prval("tcpOutAck", tcp->tcpOutAck); 22577c478bd9Sstevel@tonic-gate prval("tcpOutAckDelayed", tcp->tcpOutAckDelayed); 22587c478bd9Sstevel@tonic-gate prval("tcpOutUrg", tcp->tcpOutUrg); 22597c478bd9Sstevel@tonic-gate prval("tcpOutWinUpdate", tcp->tcpOutWinUpdate); 22607c478bd9Sstevel@tonic-gate prval("tcpOutWinProbe", tcp->tcpOutWinProbe); 22617c478bd9Sstevel@tonic-gate prval("tcpOutControl", tcp->tcpOutControl); 22627c478bd9Sstevel@tonic-gate prval("tcpOutRsts", tcp->tcpOutRsts); 22637c478bd9Sstevel@tonic-gate prval("tcpOutFastRetrans", tcp->tcpOutFastRetrans); 22643173664eSapersson prval64("tcpInSegs", tcp->tcpHCInSegs); 22657c478bd9Sstevel@tonic-gate prval_end(); 22667c478bd9Sstevel@tonic-gate prval("tcpInAckSegs", tcp->tcpInAckSegs); 22677c478bd9Sstevel@tonic-gate prval("tcpInAckBytes", tcp->tcpInAckBytes); 22687c478bd9Sstevel@tonic-gate prval("tcpInDupAck", tcp->tcpInDupAck); 22697c478bd9Sstevel@tonic-gate prval("tcpInAckUnsent", tcp->tcpInAckUnsent); 22707c478bd9Sstevel@tonic-gate prval("tcpInInorderSegs", tcp->tcpInDataInorderSegs); 22717c478bd9Sstevel@tonic-gate prval("tcpInInorderBytes", tcp->tcpInDataInorderBytes); 22727c478bd9Sstevel@tonic-gate prval("tcpInUnorderSegs", tcp->tcpInDataUnorderSegs); 22737c478bd9Sstevel@tonic-gate prval("tcpInUnorderBytes", tcp->tcpInDataUnorderBytes); 22747c478bd9Sstevel@tonic-gate prval("tcpInDupSegs", tcp->tcpInDataDupSegs); 22757c478bd9Sstevel@tonic-gate prval("tcpInDupBytes", tcp->tcpInDataDupBytes); 22767c478bd9Sstevel@tonic-gate prval("tcpInPartDupSegs", tcp->tcpInDataPartDupSegs); 22777c478bd9Sstevel@tonic-gate prval("tcpInPartDupBytes", tcp->tcpInDataPartDupBytes); 22787c478bd9Sstevel@tonic-gate prval("tcpInPastWinSegs", tcp->tcpInDataPastWinSegs); 22797c478bd9Sstevel@tonic-gate prval("tcpInPastWinBytes", tcp->tcpInDataPastWinBytes); 22807c478bd9Sstevel@tonic-gate prval("tcpInWinProbe", tcp->tcpInWinProbe); 22817c478bd9Sstevel@tonic-gate prval("tcpInWinUpdate", tcp->tcpInWinUpdate); 22827c478bd9Sstevel@tonic-gate prval("tcpInClosed", tcp->tcpInClosed); 22837c478bd9Sstevel@tonic-gate prval("tcpRttNoUpdate", tcp->tcpRttNoUpdate); 22847c478bd9Sstevel@tonic-gate prval("tcpRttUpdate", tcp->tcpRttUpdate); 22857c478bd9Sstevel@tonic-gate prval("tcpTimRetrans", tcp->tcpTimRetrans); 22867c478bd9Sstevel@tonic-gate prval("tcpTimRetransDrop", tcp->tcpTimRetransDrop); 22877c478bd9Sstevel@tonic-gate prval("tcpTimKeepalive", tcp->tcpTimKeepalive); 22887c478bd9Sstevel@tonic-gate prval("tcpTimKeepaliveProbe", tcp->tcpTimKeepaliveProbe); 22897c478bd9Sstevel@tonic-gate prval("tcpTimKeepaliveDrop", tcp->tcpTimKeepaliveDrop); 22907c478bd9Sstevel@tonic-gate prval("tcpListenDrop", tcp->tcpListenDrop); 22917c478bd9Sstevel@tonic-gate prval("tcpListenDropQ0", tcp->tcpListenDropQ0); 22927c478bd9Sstevel@tonic-gate prval("tcpHalfOpenDrop", tcp->tcpHalfOpenDrop); 22937c478bd9Sstevel@tonic-gate prval("tcpOutSackRetrans", tcp->tcpOutSackRetransSegs); 22947c478bd9Sstevel@tonic-gate prval_end(); 22957c478bd9Sstevel@tonic-gate 22967c478bd9Sstevel@tonic-gate } 22977c478bd9Sstevel@tonic-gate 22987c478bd9Sstevel@tonic-gate static void 22997c478bd9Sstevel@tonic-gate print_udp_stats(mib2_udp_t *udp) 23007c478bd9Sstevel@tonic-gate { 23017c478bd9Sstevel@tonic-gate prval_init(); 23023173664eSapersson prval64("udpInDatagrams", udp->udpHCInDatagrams); 23037c478bd9Sstevel@tonic-gate prval("udpInErrors", udp->udpInErrors); 23043173664eSapersson prval64("udpOutDatagrams", udp->udpHCOutDatagrams); 23057c478bd9Sstevel@tonic-gate prval("udpOutErrors", udp->udpOutErrors); 23067c478bd9Sstevel@tonic-gate prval_end(); 23077c478bd9Sstevel@tonic-gate } 23087c478bd9Sstevel@tonic-gate 23097c478bd9Sstevel@tonic-gate static void 23107c478bd9Sstevel@tonic-gate print_rawip_stats(mib2_rawip_t *rawip) 23117c478bd9Sstevel@tonic-gate { 23127c478bd9Sstevel@tonic-gate prval_init(); 23137c478bd9Sstevel@tonic-gate prval("rawipInDatagrams", rawip->rawipInDatagrams); 23147c478bd9Sstevel@tonic-gate prval("rawipInErrors", rawip->rawipInErrors); 23157c478bd9Sstevel@tonic-gate prval("rawipInCksumErrs", rawip->rawipInCksumErrs); 23167c478bd9Sstevel@tonic-gate prval("rawipOutDatagrams", rawip->rawipOutDatagrams); 23177c478bd9Sstevel@tonic-gate prval("rawipOutErrors", rawip->rawipOutErrors); 23187c478bd9Sstevel@tonic-gate prval_end(); 23197c478bd9Sstevel@tonic-gate } 23207c478bd9Sstevel@tonic-gate 23217c478bd9Sstevel@tonic-gate void 23227c478bd9Sstevel@tonic-gate print_igmp_stats(struct igmpstat *igps) 23237c478bd9Sstevel@tonic-gate { 23247c478bd9Sstevel@tonic-gate (void) printf(" %10u message%s received\n", 23257c478bd9Sstevel@tonic-gate igps->igps_rcv_total, PLURAL(igps->igps_rcv_total)); 23267c478bd9Sstevel@tonic-gate (void) printf(" %10u message%s received with too few bytes\n", 23277c478bd9Sstevel@tonic-gate igps->igps_rcv_tooshort, PLURAL(igps->igps_rcv_tooshort)); 23287c478bd9Sstevel@tonic-gate (void) printf(" %10u message%s received with bad checksum\n", 23297c478bd9Sstevel@tonic-gate igps->igps_rcv_badsum, PLURAL(igps->igps_rcv_badsum)); 23307c478bd9Sstevel@tonic-gate (void) printf(" %10u membership quer%s received\n", 23317c478bd9Sstevel@tonic-gate igps->igps_rcv_queries, PLURALY(igps->igps_rcv_queries)); 23327c478bd9Sstevel@tonic-gate (void) printf(" %10u membership quer%s received with invalid " 23337c478bd9Sstevel@tonic-gate "field(s)\n", 23347c478bd9Sstevel@tonic-gate igps->igps_rcv_badqueries, PLURALY(igps->igps_rcv_badqueries)); 23357c478bd9Sstevel@tonic-gate (void) printf(" %10u membership report%s received\n", 23367c478bd9Sstevel@tonic-gate igps->igps_rcv_reports, PLURAL(igps->igps_rcv_reports)); 23377c478bd9Sstevel@tonic-gate (void) printf(" %10u membership report%s received with invalid " 23387c478bd9Sstevel@tonic-gate "field(s)\n", 23397c478bd9Sstevel@tonic-gate igps->igps_rcv_badreports, PLURAL(igps->igps_rcv_badreports)); 23407c478bd9Sstevel@tonic-gate (void) printf(" %10u membership report%s received for groups to " 23417c478bd9Sstevel@tonic-gate "which we belong\n", 23427c478bd9Sstevel@tonic-gate igps->igps_rcv_ourreports, PLURAL(igps->igps_rcv_ourreports)); 23437c478bd9Sstevel@tonic-gate (void) printf(" %10u membership report%s sent\n", 23447c478bd9Sstevel@tonic-gate igps->igps_snd_reports, PLURAL(igps->igps_snd_reports)); 23457c478bd9Sstevel@tonic-gate } 23467c478bd9Sstevel@tonic-gate 23477c478bd9Sstevel@tonic-gate static void 23487c478bd9Sstevel@tonic-gate print_mrt_stats(struct mrtstat *mrts) 23497c478bd9Sstevel@tonic-gate { 23507c478bd9Sstevel@tonic-gate (void) puts("DVMRP multicast routing:"); 23517c478bd9Sstevel@tonic-gate (void) printf(" %10u hit%s - kernel forwarding cache hits\n", 2352*e11c3f44Smeem mrts->mrts_mfc_hits, PLURAL(mrts->mrts_mfc_hits)); 23537c478bd9Sstevel@tonic-gate (void) printf(" %10u miss%s - kernel forwarding cache misses\n", 2354*e11c3f44Smeem mrts->mrts_mfc_misses, PLURALES(mrts->mrts_mfc_misses)); 23557c478bd9Sstevel@tonic-gate (void) printf(" %10u packet%s potentially forwarded\n", 2356*e11c3f44Smeem mrts->mrts_fwd_in, PLURAL(mrts->mrts_fwd_in)); 23577c478bd9Sstevel@tonic-gate (void) printf(" %10u packet%s actually sent out\n", 2358*e11c3f44Smeem mrts->mrts_fwd_out, PLURAL(mrts->mrts_fwd_out)); 23597c478bd9Sstevel@tonic-gate (void) printf(" %10u upcall%s - upcalls made to mrouted\n", 2360*e11c3f44Smeem mrts->mrts_upcalls, PLURAL(mrts->mrts_upcalls)); 23617c478bd9Sstevel@tonic-gate (void) printf(" %10u packet%s not sent out due to lack of resources\n", 2362*e11c3f44Smeem mrts->mrts_fwd_drop, PLURAL(mrts->mrts_fwd_drop)); 23637c478bd9Sstevel@tonic-gate (void) printf(" %10u datagram%s with malformed tunnel options\n", 2364*e11c3f44Smeem mrts->mrts_bad_tunnel, PLURAL(mrts->mrts_bad_tunnel)); 23657c478bd9Sstevel@tonic-gate (void) printf(" %10u datagram%s with no room for tunnel options\n", 2366*e11c3f44Smeem mrts->mrts_cant_tunnel, PLURAL(mrts->mrts_cant_tunnel)); 23677c478bd9Sstevel@tonic-gate (void) printf(" %10u datagram%s arrived on wrong interface\n", 2368*e11c3f44Smeem mrts->mrts_wrong_if, PLURAL(mrts->mrts_wrong_if)); 23697c478bd9Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped due to upcall Q overflow\n", 2370*e11c3f44Smeem mrts->mrts_upq_ovflw, PLURAL(mrts->mrts_upq_ovflw)); 23717c478bd9Sstevel@tonic-gate (void) printf(" %10u datagram%s cleaned up by the cache\n", 2372*e11c3f44Smeem mrts->mrts_cache_cleanups, PLURAL(mrts->mrts_cache_cleanups)); 23737c478bd9Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped selectively by ratelimiter\n", 2374*e11c3f44Smeem mrts->mrts_drop_sel, PLURAL(mrts->mrts_drop_sel)); 23757c478bd9Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - bucket Q overflow\n", 2376*e11c3f44Smeem mrts->mrts_q_overflow, PLURAL(mrts->mrts_q_overflow)); 23777c478bd9Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - larger than bkt size\n", 2378*e11c3f44Smeem mrts->mrts_pkt2large, PLURAL(mrts->mrts_pkt2large)); 23797c478bd9Sstevel@tonic-gate (void) printf("\nPIM multicast routing:\n"); 23807c478bd9Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - bad version number\n", 2381*e11c3f44Smeem mrts->mrts_pim_badversion, PLURAL(mrts->mrts_pim_badversion)); 23827c478bd9Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - bad checksum\n", 2383*e11c3f44Smeem mrts->mrts_pim_rcv_badcsum, PLURAL(mrts->mrts_pim_rcv_badcsum)); 23847c478bd9Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - bad register packets\n", 2385*e11c3f44Smeem mrts->mrts_pim_badregisters, PLURAL(mrts->mrts_pim_badregisters)); 23867c478bd9Sstevel@tonic-gate (void) printf( 2387*e11c3f44Smeem " %10u datagram%s potentially forwarded - register packets\n", 2388*e11c3f44Smeem mrts->mrts_pim_regforwards, PLURAL(mrts->mrts_pim_regforwards)); 23897c478bd9Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - register send drops\n", 2390*e11c3f44Smeem mrts->mrts_pim_regsend_drops, PLURAL(mrts->mrts_pim_regsend_drops)); 23917c478bd9Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - packet malformed\n", 2392*e11c3f44Smeem mrts->mrts_pim_malformed, PLURAL(mrts->mrts_pim_malformed)); 23937c478bd9Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - no memory to forward\n", 2394*e11c3f44Smeem mrts->mrts_pim_nomemory, PLURAL(mrts->mrts_pim_nomemory)); 23957c478bd9Sstevel@tonic-gate } 23967c478bd9Sstevel@tonic-gate 23977c478bd9Sstevel@tonic-gate static void 23987c478bd9Sstevel@tonic-gate sum_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6, mib2_ipv6IfStatsEntry_t *sum6) 23997c478bd9Sstevel@tonic-gate { 24007c478bd9Sstevel@tonic-gate /* First few are not additive */ 24017c478bd9Sstevel@tonic-gate sum6->ipv6Forwarding = ip6->ipv6Forwarding; 24027c478bd9Sstevel@tonic-gate sum6->ipv6DefaultHopLimit = ip6->ipv6DefaultHopLimit; 24037c478bd9Sstevel@tonic-gate 24047c478bd9Sstevel@tonic-gate sum6->ipv6InReceives += ip6->ipv6InReceives; 24057c478bd9Sstevel@tonic-gate sum6->ipv6InHdrErrors += ip6->ipv6InHdrErrors; 24067c478bd9Sstevel@tonic-gate sum6->ipv6InTooBigErrors += ip6->ipv6InTooBigErrors; 24077c478bd9Sstevel@tonic-gate sum6->ipv6InNoRoutes += ip6->ipv6InNoRoutes; 24087c478bd9Sstevel@tonic-gate sum6->ipv6InAddrErrors += ip6->ipv6InAddrErrors; 24097c478bd9Sstevel@tonic-gate sum6->ipv6InUnknownProtos += ip6->ipv6InUnknownProtos; 24107c478bd9Sstevel@tonic-gate sum6->ipv6InTruncatedPkts += ip6->ipv6InTruncatedPkts; 24117c478bd9Sstevel@tonic-gate sum6->ipv6InDiscards += ip6->ipv6InDiscards; 24127c478bd9Sstevel@tonic-gate sum6->ipv6InDelivers += ip6->ipv6InDelivers; 24137c478bd9Sstevel@tonic-gate sum6->ipv6OutForwDatagrams += ip6->ipv6OutForwDatagrams; 24147c478bd9Sstevel@tonic-gate sum6->ipv6OutRequests += ip6->ipv6OutRequests; 24157c478bd9Sstevel@tonic-gate sum6->ipv6OutDiscards += ip6->ipv6OutDiscards; 24167c478bd9Sstevel@tonic-gate sum6->ipv6OutFragOKs += ip6->ipv6OutFragOKs; 24177c478bd9Sstevel@tonic-gate sum6->ipv6OutFragFails += ip6->ipv6OutFragFails; 24187c478bd9Sstevel@tonic-gate sum6->ipv6OutFragCreates += ip6->ipv6OutFragCreates; 24197c478bd9Sstevel@tonic-gate sum6->ipv6ReasmReqds += ip6->ipv6ReasmReqds; 24207c478bd9Sstevel@tonic-gate sum6->ipv6ReasmOKs += ip6->ipv6ReasmOKs; 24217c478bd9Sstevel@tonic-gate sum6->ipv6ReasmFails += ip6->ipv6ReasmFails; 24227c478bd9Sstevel@tonic-gate sum6->ipv6InMcastPkts += ip6->ipv6InMcastPkts; 24237c478bd9Sstevel@tonic-gate sum6->ipv6OutMcastPkts += ip6->ipv6OutMcastPkts; 24247c478bd9Sstevel@tonic-gate sum6->ipv6OutNoRoutes += ip6->ipv6OutNoRoutes; 24257c478bd9Sstevel@tonic-gate sum6->ipv6ReasmDuplicates += ip6->ipv6ReasmDuplicates; 24267c478bd9Sstevel@tonic-gate sum6->ipv6ReasmPartDups += ip6->ipv6ReasmPartDups; 24277c478bd9Sstevel@tonic-gate sum6->ipv6ForwProhibits += ip6->ipv6ForwProhibits; 24287c478bd9Sstevel@tonic-gate sum6->udpInCksumErrs += ip6->udpInCksumErrs; 24297c478bd9Sstevel@tonic-gate sum6->udpInOverflows += ip6->udpInOverflows; 24307c478bd9Sstevel@tonic-gate sum6->rawipInOverflows += ip6->rawipInOverflows; 24317c478bd9Sstevel@tonic-gate } 24327c478bd9Sstevel@tonic-gate 24337c478bd9Sstevel@tonic-gate static void 24347c478bd9Sstevel@tonic-gate sum_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6, mib2_ipv6IfIcmpEntry_t *sum6) 24357c478bd9Sstevel@tonic-gate { 24367c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpInMsgs += icmp6->ipv6IfIcmpInMsgs; 24377c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpInErrors += icmp6->ipv6IfIcmpInErrors; 24387c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpInDestUnreachs += icmp6->ipv6IfIcmpInDestUnreachs; 24397c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpInAdminProhibs += icmp6->ipv6IfIcmpInAdminProhibs; 24407c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpInTimeExcds += icmp6->ipv6IfIcmpInTimeExcds; 24417c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpInParmProblems += icmp6->ipv6IfIcmpInParmProblems; 24427c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpInPktTooBigs += icmp6->ipv6IfIcmpInPktTooBigs; 24437c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpInEchos += icmp6->ipv6IfIcmpInEchos; 24447c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpInEchoReplies += icmp6->ipv6IfIcmpInEchoReplies; 24457c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpInRouterSolicits += icmp6->ipv6IfIcmpInRouterSolicits; 24467c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpInRouterAdvertisements += 24477c478bd9Sstevel@tonic-gate icmp6->ipv6IfIcmpInRouterAdvertisements; 24487c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpInNeighborSolicits += 24497c478bd9Sstevel@tonic-gate icmp6->ipv6IfIcmpInNeighborSolicits; 24507c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpInNeighborAdvertisements += 24517c478bd9Sstevel@tonic-gate icmp6->ipv6IfIcmpInNeighborAdvertisements; 24527c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpInRedirects += icmp6->ipv6IfIcmpInRedirects; 24537c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpInGroupMembQueries += 24547c478bd9Sstevel@tonic-gate icmp6->ipv6IfIcmpInGroupMembQueries; 24557c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpInGroupMembResponses += 24567c478bd9Sstevel@tonic-gate icmp6->ipv6IfIcmpInGroupMembResponses; 24577c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpInGroupMembReductions += 24587c478bd9Sstevel@tonic-gate icmp6->ipv6IfIcmpInGroupMembReductions; 24597c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpOutMsgs += icmp6->ipv6IfIcmpOutMsgs; 24607c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpOutErrors += icmp6->ipv6IfIcmpOutErrors; 24617c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpOutDestUnreachs += icmp6->ipv6IfIcmpOutDestUnreachs; 24627c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpOutAdminProhibs += icmp6->ipv6IfIcmpOutAdminProhibs; 24637c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpOutTimeExcds += icmp6->ipv6IfIcmpOutTimeExcds; 24647c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpOutParmProblems += icmp6->ipv6IfIcmpOutParmProblems; 24657c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpOutPktTooBigs += icmp6->ipv6IfIcmpOutPktTooBigs; 24667c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpOutEchos += icmp6->ipv6IfIcmpOutEchos; 24677c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpOutEchoReplies += icmp6->ipv6IfIcmpOutEchoReplies; 24687c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpOutRouterSolicits += 24697c478bd9Sstevel@tonic-gate icmp6->ipv6IfIcmpOutRouterSolicits; 24707c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpOutRouterAdvertisements += 24717c478bd9Sstevel@tonic-gate icmp6->ipv6IfIcmpOutRouterAdvertisements; 24727c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpOutNeighborSolicits += 24737c478bd9Sstevel@tonic-gate icmp6->ipv6IfIcmpOutNeighborSolicits; 24747c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpOutNeighborAdvertisements += 24757c478bd9Sstevel@tonic-gate icmp6->ipv6IfIcmpOutNeighborAdvertisements; 24767c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpOutRedirects += icmp6->ipv6IfIcmpOutRedirects; 24777c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpOutGroupMembQueries += 24787c478bd9Sstevel@tonic-gate icmp6->ipv6IfIcmpOutGroupMembQueries; 24797c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpOutGroupMembResponses += 24807c478bd9Sstevel@tonic-gate icmp6->ipv6IfIcmpOutGroupMembResponses; 24817c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpOutGroupMembReductions += 24827c478bd9Sstevel@tonic-gate icmp6->ipv6IfIcmpOutGroupMembReductions; 24837c478bd9Sstevel@tonic-gate sum6->ipv6IfIcmpInOverflows += icmp6->ipv6IfIcmpInOverflows; 24847c478bd9Sstevel@tonic-gate } 24857c478bd9Sstevel@tonic-gate 24867c478bd9Sstevel@tonic-gate /* ----------------------------- MRT_STAT_REPORT --------------------------- */ 24877c478bd9Sstevel@tonic-gate 24887c478bd9Sstevel@tonic-gate static void 24897c478bd9Sstevel@tonic-gate mrt_stat_report(mib_item_t *curritem) 24907c478bd9Sstevel@tonic-gate { 24917c478bd9Sstevel@tonic-gate int jtemp = 0; 24927c478bd9Sstevel@tonic-gate mib_item_t *tempitem; 24937c478bd9Sstevel@tonic-gate 24947c478bd9Sstevel@tonic-gate if (!(family_selected(AF_INET))) 24957c478bd9Sstevel@tonic-gate return; 24967c478bd9Sstevel@tonic-gate 24977c478bd9Sstevel@tonic-gate (void) putchar('\n'); 24987c478bd9Sstevel@tonic-gate /* 'for' loop 1: */ 24997c478bd9Sstevel@tonic-gate for (tempitem = curritem; 25007c478bd9Sstevel@tonic-gate tempitem; 25017c478bd9Sstevel@tonic-gate tempitem = tempitem->next_item) { 25027c478bd9Sstevel@tonic-gate if (Dflag) { 25037c478bd9Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp); 25047c478bd9Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, " 25057c478bd9Sstevel@tonic-gate "length = %d, valp = 0x%p\n", 25067c478bd9Sstevel@tonic-gate tempitem->group, tempitem->mib_id, 25077c478bd9Sstevel@tonic-gate tempitem->length, tempitem->valp); 25087c478bd9Sstevel@tonic-gate } 25097c478bd9Sstevel@tonic-gate 25107c478bd9Sstevel@tonic-gate if (tempitem->mib_id == 0) { 25117c478bd9Sstevel@tonic-gate switch (tempitem->group) { 25127c478bd9Sstevel@tonic-gate case EXPER_DVMRP: { 25137c478bd9Sstevel@tonic-gate struct mrtstat *mrts; 25147c478bd9Sstevel@tonic-gate mrts = (struct mrtstat *)tempitem->valp; 25157c478bd9Sstevel@tonic-gate 25167c478bd9Sstevel@tonic-gate if (!(family_selected(AF_INET))) 25177c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 25187c478bd9Sstevel@tonic-gate 25197c478bd9Sstevel@tonic-gate print_mrt_stats(mrts); 25207c478bd9Sstevel@tonic-gate break; 25217c478bd9Sstevel@tonic-gate } 25227c478bd9Sstevel@tonic-gate } 25237c478bd9Sstevel@tonic-gate } 25247c478bd9Sstevel@tonic-gate } /* 'for' loop 1 ends */ 25257c478bd9Sstevel@tonic-gate (void) putchar('\n'); 25267c478bd9Sstevel@tonic-gate (void) fflush(stdout); 25277c478bd9Sstevel@tonic-gate } 25287c478bd9Sstevel@tonic-gate 25297c478bd9Sstevel@tonic-gate /* 25307c478bd9Sstevel@tonic-gate * if_stat_total() - Computes totals for interface statistics 25317c478bd9Sstevel@tonic-gate * and returns result by updating sumstats. 25327c478bd9Sstevel@tonic-gate */ 25337c478bd9Sstevel@tonic-gate static void 25347c478bd9Sstevel@tonic-gate if_stat_total(struct ifstat *oldstats, struct ifstat *newstats, 25357c478bd9Sstevel@tonic-gate struct ifstat *sumstats) 25367c478bd9Sstevel@tonic-gate { 25377c478bd9Sstevel@tonic-gate sumstats->ipackets += newstats->ipackets - oldstats->ipackets; 25387c478bd9Sstevel@tonic-gate sumstats->opackets += newstats->opackets - oldstats->opackets; 25397c478bd9Sstevel@tonic-gate sumstats->ierrors += newstats->ierrors - oldstats->ierrors; 25407c478bd9Sstevel@tonic-gate sumstats->oerrors += newstats->oerrors - oldstats->oerrors; 25417c478bd9Sstevel@tonic-gate sumstats->collisions += newstats->collisions - oldstats->collisions; 25427c478bd9Sstevel@tonic-gate } 25437c478bd9Sstevel@tonic-gate 25447c478bd9Sstevel@tonic-gate /* --------------------- IF_REPORT (netstat -i) -------------------------- */ 25457c478bd9Sstevel@tonic-gate 25467c478bd9Sstevel@tonic-gate static struct ifstat zerostat = { 25477c478bd9Sstevel@tonic-gate 0LL, 0LL, 0LL, 0LL, 0LL 25487c478bd9Sstevel@tonic-gate }; 25497c478bd9Sstevel@tonic-gate 25507c478bd9Sstevel@tonic-gate static void 25517c478bd9Sstevel@tonic-gate if_report(mib_item_t *item, char *matchname, 25527c478bd9Sstevel@tonic-gate int Iflag_only, boolean_t once_only) 25537c478bd9Sstevel@tonic-gate { 25547c478bd9Sstevel@tonic-gate static boolean_t reentry = B_FALSE; 25557c478bd9Sstevel@tonic-gate boolean_t alreadydone = B_FALSE; 25567c478bd9Sstevel@tonic-gate int jtemp = 0; 25577c478bd9Sstevel@tonic-gate uint32_t ifindex_v4 = 0; 25587c478bd9Sstevel@tonic-gate uint32_t ifindex_v6 = 0; 2559ba753d4aSkeerthi boolean_t first_header = B_TRUE; 25607c478bd9Sstevel@tonic-gate 25617c478bd9Sstevel@tonic-gate /* 'for' loop 1: */ 25627c478bd9Sstevel@tonic-gate for (; item; item = item->next_item) { 25637c478bd9Sstevel@tonic-gate if (Dflag) { 25647c478bd9Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp); 25657c478bd9Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, " 25667c478bd9Sstevel@tonic-gate "length = %d, valp = 0x%p\n", 25677c478bd9Sstevel@tonic-gate item->group, item->mib_id, item->length, 25687c478bd9Sstevel@tonic-gate item->valp); 25697c478bd9Sstevel@tonic-gate } 25707c478bd9Sstevel@tonic-gate 25717c478bd9Sstevel@tonic-gate switch (item->group) { 25727c478bd9Sstevel@tonic-gate case MIB2_IP: 25737c478bd9Sstevel@tonic-gate if (item->mib_id != MIB2_IP_ADDR || 25747c478bd9Sstevel@tonic-gate !family_selected(AF_INET)) 25757c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 25767c478bd9Sstevel@tonic-gate { 25777c478bd9Sstevel@tonic-gate static struct ifstat old = {0L, 0L, 0L, 0L, 0L}; 25787c478bd9Sstevel@tonic-gate static struct ifstat new = {0L, 0L, 0L, 0L, 0L}; 25797c478bd9Sstevel@tonic-gate struct ifstat sum; 25807c478bd9Sstevel@tonic-gate struct iflist *newlist = NULL; 25817c478bd9Sstevel@tonic-gate static struct iflist *oldlist = NULL; 25827c478bd9Sstevel@tonic-gate kstat_t *ksp; 25837c478bd9Sstevel@tonic-gate 25847c478bd9Sstevel@tonic-gate if (once_only) { 25857c478bd9Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 25867c478bd9Sstevel@tonic-gate char logintname[LIFNAMSIZ + 1]; 25877c478bd9Sstevel@tonic-gate mib2_ipAddrEntry_t *ap; 25887c478bd9Sstevel@tonic-gate struct ifstat stat = {0L, 0L, 0L, 0L, 0L}; 25897c478bd9Sstevel@tonic-gate boolean_t first = B_TRUE; 25907c478bd9Sstevel@tonic-gate uint32_t new_ifindex; 25917c478bd9Sstevel@tonic-gate 25927c478bd9Sstevel@tonic-gate if (Dflag) 25937c478bd9Sstevel@tonic-gate (void) printf("if_report: %d items\n", 25947c478bd9Sstevel@tonic-gate (item->length) 25957c478bd9Sstevel@tonic-gate / sizeof (mib2_ipAddrEntry_t)); 25967c478bd9Sstevel@tonic-gate 25977c478bd9Sstevel@tonic-gate /* 'for' loop 2a: */ 25987c478bd9Sstevel@tonic-gate for (ap = (mib2_ipAddrEntry_t *)item->valp; 25997c478bd9Sstevel@tonic-gate (char *)ap < (char *)item->valp 26007c478bd9Sstevel@tonic-gate + item->length; 26017c478bd9Sstevel@tonic-gate ap++) { 26027c478bd9Sstevel@tonic-gate (void) octetstr(&ap->ipAdEntIfIndex, 26037c478bd9Sstevel@tonic-gate 'a', logintname, 26047c478bd9Sstevel@tonic-gate sizeof (logintname)); 26057c478bd9Sstevel@tonic-gate (void) strcpy(ifname, logintname); 26067c478bd9Sstevel@tonic-gate (void) strtok(ifname, ":"); 26077c478bd9Sstevel@tonic-gate if (matchname != NULL && 26087c478bd9Sstevel@tonic-gate strcmp(matchname, ifname) != 0 && 26097c478bd9Sstevel@tonic-gate strcmp(matchname, logintname) != 0) 26107c478bd9Sstevel@tonic-gate continue; /* 'for' loop 2a */ 26117c478bd9Sstevel@tonic-gate new_ifindex = 26127c478bd9Sstevel@tonic-gate if_nametoindex(logintname); 2613d62bc4baSyz /* 2614d62bc4baSyz * First lookup the "link" kstats in 2615d62bc4baSyz * case the link is renamed. Then 2616d62bc4baSyz * fallback to the legacy kstats for 2617d62bc4baSyz * those non-GLDv3 links. 2618d62bc4baSyz */ 26197c478bd9Sstevel@tonic-gate if (new_ifindex != ifindex_v4 && 2620d62bc4baSyz (((ksp = kstat_lookup(kc, "link", 0, 2621d62bc4baSyz ifname)) != NULL) || 2622d62bc4baSyz ((ksp = kstat_lookup(kc, NULL, -1, 2623d62bc4baSyz ifname)) != NULL))) { 26247c478bd9Sstevel@tonic-gate (void) safe_kstat_read(kc, ksp, 26257c478bd9Sstevel@tonic-gate NULL); 26267c478bd9Sstevel@tonic-gate stat.ipackets = 26277c478bd9Sstevel@tonic-gate kstat_named_value(ksp, 26287c478bd9Sstevel@tonic-gate "ipackets"); 26297c478bd9Sstevel@tonic-gate stat.ierrors = 26307c478bd9Sstevel@tonic-gate kstat_named_value(ksp, 26317c478bd9Sstevel@tonic-gate "ierrors"); 26327c478bd9Sstevel@tonic-gate stat.opackets = 26337c478bd9Sstevel@tonic-gate kstat_named_value(ksp, 26347c478bd9Sstevel@tonic-gate "opackets"); 26357c478bd9Sstevel@tonic-gate stat.oerrors = 26367c478bd9Sstevel@tonic-gate kstat_named_value(ksp, 26377c478bd9Sstevel@tonic-gate "oerrors"); 26387c478bd9Sstevel@tonic-gate stat.collisions = 26397c478bd9Sstevel@tonic-gate kstat_named_value(ksp, 26407c478bd9Sstevel@tonic-gate "collisions"); 26417c478bd9Sstevel@tonic-gate if (first) { 2642ba753d4aSkeerthi if (!first_header) 2643ba753d4aSkeerthi (void) putchar('\n'); 2644ba753d4aSkeerthi first_header = B_FALSE; 26457c478bd9Sstevel@tonic-gate (void) printf( 26467c478bd9Sstevel@tonic-gate "%-5.5s %-5.5s%-13.13s " 26477c478bd9Sstevel@tonic-gate "%-14.14s %-6.6s %-5.5s " 26487c478bd9Sstevel@tonic-gate "%-6.6s %-5.5s %-6.6s " 26497c478bd9Sstevel@tonic-gate "%-6.6s\n", 26507c478bd9Sstevel@tonic-gate "Name", "Mtu", "Net/Dest", 26517c478bd9Sstevel@tonic-gate "Address", "Ipkts", 26527c478bd9Sstevel@tonic-gate "Ierrs", "Opkts", "Oerrs", 26537c478bd9Sstevel@tonic-gate "Collis", "Queue"); 2654ba753d4aSkeerthi 2655*e11c3f44Smeem first = B_FALSE; 26567c478bd9Sstevel@tonic-gate } 26577c478bd9Sstevel@tonic-gate if_report_ip4(ap, ifname, 26587c478bd9Sstevel@tonic-gate logintname, &stat, B_TRUE); 26597c478bd9Sstevel@tonic-gate ifindex_v4 = new_ifindex; 26607c478bd9Sstevel@tonic-gate } else { 26617c478bd9Sstevel@tonic-gate if_report_ip4(ap, ifname, 26627c478bd9Sstevel@tonic-gate logintname, &stat, B_FALSE); 26637c478bd9Sstevel@tonic-gate } 26647c478bd9Sstevel@tonic-gate } /* 'for' loop 2a ends */ 26657c478bd9Sstevel@tonic-gate } else if (!alreadydone) { 26667c478bd9Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 26677c478bd9Sstevel@tonic-gate char buf[LIFNAMSIZ + 1]; 26687c478bd9Sstevel@tonic-gate mib2_ipAddrEntry_t *ap; 26697c478bd9Sstevel@tonic-gate struct ifstat t; 2670aecc8c24Sja struct iflist *tlp = NULL; 26717c478bd9Sstevel@tonic-gate struct iflist **nextnew = &newlist; 26727c478bd9Sstevel@tonic-gate struct iflist *walkold; 26737c478bd9Sstevel@tonic-gate struct iflist *cleanlist; 2674aecc8c24Sja boolean_t found_if = B_FALSE; 26757c478bd9Sstevel@tonic-gate 26767c478bd9Sstevel@tonic-gate alreadydone = B_TRUE; /* ignore other case */ 2677aecc8c24Sja 2678aecc8c24Sja /* 2679aecc8c24Sja * Check if there is anything to do. 2680aecc8c24Sja */ 2681aecc8c24Sja if (item->length < 2682aecc8c24Sja sizeof (mib2_ipAddrEntry_t)) { 2683aecc8c24Sja fail(0, "No compatible interfaces"); 2684aecc8c24Sja } 2685aecc8c24Sja 26867c478bd9Sstevel@tonic-gate /* 2687aecc8c24Sja * 'for' loop 2b: find the "right" entry: 2688aecc8c24Sja * If an interface name to match has been 2689aecc8c24Sja * supplied then try and find it, otherwise 2690aecc8c24Sja * match the first non-loopback interface found. 2691aecc8c24Sja * Use lo0 if all else fails. 26927c478bd9Sstevel@tonic-gate */ 26937c478bd9Sstevel@tonic-gate for (ap = (mib2_ipAddrEntry_t *)item->valp; 26947c478bd9Sstevel@tonic-gate (char *)ap < (char *)item->valp 26957c478bd9Sstevel@tonic-gate + item->length; 26967c478bd9Sstevel@tonic-gate ap++) { 26977c478bd9Sstevel@tonic-gate (void) octetstr(&ap->ipAdEntIfIndex, 2698*e11c3f44Smeem 'a', ifname, sizeof (ifname)); 26997c478bd9Sstevel@tonic-gate (void) strtok(ifname, ":"); 27007c478bd9Sstevel@tonic-gate 27017c478bd9Sstevel@tonic-gate if (matchname) { 27027c478bd9Sstevel@tonic-gate if (strcmp(matchname, 2703aecc8c24Sja ifname) == 0) { 27047c478bd9Sstevel@tonic-gate /* 'for' loop 2b */ 2705aecc8c24Sja found_if = B_TRUE; 27067c478bd9Sstevel@tonic-gate break; 2707aecc8c24Sja } 2708aecc8c24Sja } else if (strcmp(ifname, "lo0") != 0) 27097c478bd9Sstevel@tonic-gate break; /* 'for' loop 2b */ 27107c478bd9Sstevel@tonic-gate } /* 'for' loop 2b ends */ 27117c478bd9Sstevel@tonic-gate 2712aecc8c24Sja if (matchname == NULL) { 2713aecc8c24Sja matchname = ifname; 2714aecc8c24Sja } else { 2715aecc8c24Sja if (!found_if) 2716aecc8c24Sja fail(0, "-I: %s no such " 2717aecc8c24Sja "interface.", matchname); 2718aecc8c24Sja } 2719aecc8c24Sja 27207c478bd9Sstevel@tonic-gate if (Iflag_only == 0 || !reentry) { 27217c478bd9Sstevel@tonic-gate (void) printf(" input %-6.6s " 27227c478bd9Sstevel@tonic-gate "output ", 27237c478bd9Sstevel@tonic-gate matchname); 27247c478bd9Sstevel@tonic-gate (void) printf(" input (Total) " 27257c478bd9Sstevel@tonic-gate "output\n"); 27267c478bd9Sstevel@tonic-gate (void) printf("%-7.7s %-5.5s %-7.7s " 27277c478bd9Sstevel@tonic-gate "%-5.5s %-6.6s ", 27287c478bd9Sstevel@tonic-gate "packets", "errs", "packets", 27297c478bd9Sstevel@tonic-gate "errs", "colls"); 27307c478bd9Sstevel@tonic-gate (void) printf("%-7.7s %-5.5s %-7.7s " 27317c478bd9Sstevel@tonic-gate "%-5.5s %-6.6s\n", 27327c478bd9Sstevel@tonic-gate "packets", "errs", "packets", 27337c478bd9Sstevel@tonic-gate "errs", "colls"); 27347c478bd9Sstevel@tonic-gate } 27357c478bd9Sstevel@tonic-gate 27367c478bd9Sstevel@tonic-gate sum = zerostat; 27377c478bd9Sstevel@tonic-gate 27387c478bd9Sstevel@tonic-gate /* 'for' loop 2c: */ 27397c478bd9Sstevel@tonic-gate for (ap = (mib2_ipAddrEntry_t *)item->valp; 27407c478bd9Sstevel@tonic-gate (char *)ap < (char *)item->valp 27417c478bd9Sstevel@tonic-gate + item->length; 27427c478bd9Sstevel@tonic-gate ap++) { 27437c478bd9Sstevel@tonic-gate (void) octetstr(&ap->ipAdEntIfIndex, 27447c478bd9Sstevel@tonic-gate 'a', buf, sizeof (buf)); 27457c478bd9Sstevel@tonic-gate (void) strtok(buf, ":"); 2746aecc8c24Sja 2747aecc8c24Sja /* 2748aecc8c24Sja * We have reduced the IP interface 2749aecc8c24Sja * name, which could have been a 2750aecc8c24Sja * logical, down to a name suitable 2751aecc8c24Sja * for use with kstats. 2752aecc8c24Sja * We treat this name as unique and 2753aecc8c24Sja * only collate statistics for it once 2754aecc8c24Sja * per pass. This is to avoid falsely 2755aecc8c24Sja * amplifying these statistics by the 2756aecc8c24Sja * the number of logical instances. 2757aecc8c24Sja */ 2758aecc8c24Sja if ((tlp != NULL) && 2759aecc8c24Sja ((strcmp(buf, tlp->ifname) == 0))) { 2760aecc8c24Sja continue; 2761aecc8c24Sja } 2762aecc8c24Sja 2763d62bc4baSyz /* 2764d62bc4baSyz * First lookup the "link" kstats in 2765d62bc4baSyz * case the link is renamed. Then 2766d62bc4baSyz * fallback to the legacy kstats for 2767d62bc4baSyz * those non-GLDv3 links. 2768d62bc4baSyz */ 2769d62bc4baSyz if (((ksp = kstat_lookup(kc, "link", 2770d62bc4baSyz 0, buf)) != NULL || 2771d62bc4baSyz (ksp = kstat_lookup(kc, NULL, -1, 2772d62bc4baSyz buf)) != NULL) && (ksp->ks_type == 2773d62bc4baSyz KSTAT_TYPE_NAMED)) { 27747c478bd9Sstevel@tonic-gate (void) safe_kstat_read(kc, ksp, 27757c478bd9Sstevel@tonic-gate NULL); 2776d62bc4baSyz } 27777c478bd9Sstevel@tonic-gate 27787c478bd9Sstevel@tonic-gate t.ipackets = kstat_named_value(ksp, 27797c478bd9Sstevel@tonic-gate "ipackets"); 27807c478bd9Sstevel@tonic-gate t.ierrors = kstat_named_value(ksp, 27817c478bd9Sstevel@tonic-gate "ierrors"); 27827c478bd9Sstevel@tonic-gate t.opackets = kstat_named_value(ksp, 27837c478bd9Sstevel@tonic-gate "opackets"); 27847c478bd9Sstevel@tonic-gate t.oerrors = kstat_named_value(ksp, 27857c478bd9Sstevel@tonic-gate "oerrors"); 27867c478bd9Sstevel@tonic-gate t.collisions = kstat_named_value(ksp, 27877c478bd9Sstevel@tonic-gate "collisions"); 27887c478bd9Sstevel@tonic-gate 27897c478bd9Sstevel@tonic-gate if (strcmp(buf, matchname) == 0) 27907c478bd9Sstevel@tonic-gate new = t; 27917c478bd9Sstevel@tonic-gate 27927c478bd9Sstevel@tonic-gate /* Build the interface list */ 27937c478bd9Sstevel@tonic-gate 27947c478bd9Sstevel@tonic-gate tlp = malloc(sizeof (struct iflist)); 27957c478bd9Sstevel@tonic-gate (void) strlcpy(tlp->ifname, buf, 27967c478bd9Sstevel@tonic-gate sizeof (tlp->ifname)); 27977c478bd9Sstevel@tonic-gate tlp->tot = t; 27987c478bd9Sstevel@tonic-gate *nextnew = tlp; 27997c478bd9Sstevel@tonic-gate nextnew = &tlp->next_if; 28007c478bd9Sstevel@tonic-gate 28017c478bd9Sstevel@tonic-gate /* 28027c478bd9Sstevel@tonic-gate * First time through. 28037c478bd9Sstevel@tonic-gate * Just add up the interface stats. 28047c478bd9Sstevel@tonic-gate */ 28057c478bd9Sstevel@tonic-gate 28067c478bd9Sstevel@tonic-gate if (oldlist == NULL) { 28077c478bd9Sstevel@tonic-gate if_stat_total(&zerostat, 28087c478bd9Sstevel@tonic-gate &t, &sum); 28097c478bd9Sstevel@tonic-gate continue; 28107c478bd9Sstevel@tonic-gate } 28117c478bd9Sstevel@tonic-gate 28127c478bd9Sstevel@tonic-gate /* 28137c478bd9Sstevel@tonic-gate * Walk old list for the interface. 28147c478bd9Sstevel@tonic-gate * 28157c478bd9Sstevel@tonic-gate * If found, add difference to total. 28167c478bd9Sstevel@tonic-gate * 28177c478bd9Sstevel@tonic-gate * If not, an interface has been plumbed 28187c478bd9Sstevel@tonic-gate * up. In this case, we will simply 28197c478bd9Sstevel@tonic-gate * ignore the new interface until the 28207c478bd9Sstevel@tonic-gate * next interval; as there's no easy way 28217c478bd9Sstevel@tonic-gate * to acquire statistics between time 28227c478bd9Sstevel@tonic-gate * of the plumb and the next interval 28237c478bd9Sstevel@tonic-gate * boundary. This results in inaccurate 28247c478bd9Sstevel@tonic-gate * total values for current interval. 28257c478bd9Sstevel@tonic-gate * 28267c478bd9Sstevel@tonic-gate * Note the case when an interface is 28277c478bd9Sstevel@tonic-gate * unplumbed; as similar problems exist. 28287c478bd9Sstevel@tonic-gate * The unplumbed interface is not in the 28297c478bd9Sstevel@tonic-gate * current list, and there's no easy way 28307c478bd9Sstevel@tonic-gate * to account for the statistics between 28317c478bd9Sstevel@tonic-gate * the previous interval and time of the 28327c478bd9Sstevel@tonic-gate * unplumb. Therefore, we (in a sense) 28337c478bd9Sstevel@tonic-gate * ignore the removed interface by only 28347c478bd9Sstevel@tonic-gate * involving "current" interfaces when 28357c478bd9Sstevel@tonic-gate * computing the total statistics. 28367c478bd9Sstevel@tonic-gate * Unfortunately, this also results in 28377c478bd9Sstevel@tonic-gate * inaccurate values for interval total. 28387c478bd9Sstevel@tonic-gate */ 28397c478bd9Sstevel@tonic-gate 28407c478bd9Sstevel@tonic-gate for (walkold = oldlist; 28417c478bd9Sstevel@tonic-gate walkold != NULL; 28427c478bd9Sstevel@tonic-gate walkold = walkold->next_if) { 28437c478bd9Sstevel@tonic-gate if (strcmp(walkold->ifname, 28447c478bd9Sstevel@tonic-gate buf) == 0) { 28457c478bd9Sstevel@tonic-gate if_stat_total( 28467c478bd9Sstevel@tonic-gate &walkold->tot, 28477c478bd9Sstevel@tonic-gate &t, &sum); 28487c478bd9Sstevel@tonic-gate break; 28497c478bd9Sstevel@tonic-gate } 28507c478bd9Sstevel@tonic-gate } 28517c478bd9Sstevel@tonic-gate 28527c478bd9Sstevel@tonic-gate } /* 'for' loop 2c ends */ 28537c478bd9Sstevel@tonic-gate 28547c478bd9Sstevel@tonic-gate *nextnew = NULL; 28557c478bd9Sstevel@tonic-gate 28567c478bd9Sstevel@tonic-gate (void) printf("%-7llu %-5llu %-7llu " 28577c478bd9Sstevel@tonic-gate "%-5llu %-6llu ", 28587c478bd9Sstevel@tonic-gate new.ipackets - old.ipackets, 28597c478bd9Sstevel@tonic-gate new.ierrors - old.ierrors, 28607c478bd9Sstevel@tonic-gate new.opackets - old.opackets, 28617c478bd9Sstevel@tonic-gate new.oerrors - old.oerrors, 28627c478bd9Sstevel@tonic-gate new.collisions - old.collisions); 28637c478bd9Sstevel@tonic-gate 28647c478bd9Sstevel@tonic-gate (void) printf("%-7llu %-5llu %-7llu " 28657c478bd9Sstevel@tonic-gate "%-5llu %-6llu\n", sum.ipackets, 28667c478bd9Sstevel@tonic-gate sum.ierrors, sum.opackets, 28677c478bd9Sstevel@tonic-gate sum.oerrors, sum.collisions); 28687c478bd9Sstevel@tonic-gate 28697c478bd9Sstevel@tonic-gate /* 28707c478bd9Sstevel@tonic-gate * Tidy things up once finished. 28717c478bd9Sstevel@tonic-gate */ 28727c478bd9Sstevel@tonic-gate 28737c478bd9Sstevel@tonic-gate old = new; 28747c478bd9Sstevel@tonic-gate cleanlist = oldlist; 28757c478bd9Sstevel@tonic-gate oldlist = newlist; 28767c478bd9Sstevel@tonic-gate while (cleanlist != NULL) { 28777c478bd9Sstevel@tonic-gate tlp = cleanlist->next_if; 28787c478bd9Sstevel@tonic-gate free(cleanlist); 28797c478bd9Sstevel@tonic-gate cleanlist = tlp; 28807c478bd9Sstevel@tonic-gate } 28817c478bd9Sstevel@tonic-gate } 28827c478bd9Sstevel@tonic-gate break; 28837c478bd9Sstevel@tonic-gate } 28847c478bd9Sstevel@tonic-gate case MIB2_IP6: 28857c478bd9Sstevel@tonic-gate if (item->mib_id != MIB2_IP6_ADDR || 28867c478bd9Sstevel@tonic-gate !family_selected(AF_INET6)) 28877c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 28887c478bd9Sstevel@tonic-gate { 28897c478bd9Sstevel@tonic-gate static struct ifstat old6 = {0L, 0L, 0L, 0L, 0L}; 28907c478bd9Sstevel@tonic-gate static struct ifstat new6 = {0L, 0L, 0L, 0L, 0L}; 28917c478bd9Sstevel@tonic-gate struct ifstat sum6; 28927c478bd9Sstevel@tonic-gate struct iflist *newlist6 = NULL; 28937c478bd9Sstevel@tonic-gate static struct iflist *oldlist6 = NULL; 28947c478bd9Sstevel@tonic-gate kstat_t *ksp; 28957c478bd9Sstevel@tonic-gate 28967c478bd9Sstevel@tonic-gate if (once_only) { 28977c478bd9Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 28987c478bd9Sstevel@tonic-gate char logintname[LIFNAMSIZ + 1]; 28997c478bd9Sstevel@tonic-gate mib2_ipv6AddrEntry_t *ap6; 29007c478bd9Sstevel@tonic-gate struct ifstat stat = {0L, 0L, 0L, 0L, 0L}; 29017c478bd9Sstevel@tonic-gate boolean_t first = B_TRUE; 29027c478bd9Sstevel@tonic-gate uint32_t new_ifindex; 29037c478bd9Sstevel@tonic-gate 29047c478bd9Sstevel@tonic-gate if (Dflag) 29057c478bd9Sstevel@tonic-gate (void) printf("if_report: %d items\n", 29067c478bd9Sstevel@tonic-gate (item->length) 29077c478bd9Sstevel@tonic-gate / sizeof (mib2_ipv6AddrEntry_t)); 29087c478bd9Sstevel@tonic-gate /* 'for' loop 2d: */ 29097c478bd9Sstevel@tonic-gate for (ap6 = (mib2_ipv6AddrEntry_t *)item->valp; 29107c478bd9Sstevel@tonic-gate (char *)ap6 < (char *)item->valp 29117c478bd9Sstevel@tonic-gate + item->length; 29127c478bd9Sstevel@tonic-gate ap6++) { 29137c478bd9Sstevel@tonic-gate (void) octetstr(&ap6->ipv6AddrIfIndex, 29147c478bd9Sstevel@tonic-gate 'a', logintname, 29157c478bd9Sstevel@tonic-gate sizeof (logintname)); 29167c478bd9Sstevel@tonic-gate (void) strcpy(ifname, logintname); 29177c478bd9Sstevel@tonic-gate (void) strtok(ifname, ":"); 29187c478bd9Sstevel@tonic-gate if (matchname != NULL && 29197c478bd9Sstevel@tonic-gate strcmp(matchname, ifname) != 0 && 29207c478bd9Sstevel@tonic-gate strcmp(matchname, logintname) != 0) 29217c478bd9Sstevel@tonic-gate continue; /* 'for' loop 2d */ 29227c478bd9Sstevel@tonic-gate new_ifindex = 29237c478bd9Sstevel@tonic-gate if_nametoindex(logintname); 2924d62bc4baSyz 2925d62bc4baSyz /* 2926d62bc4baSyz * First lookup the "link" kstats in 2927d62bc4baSyz * case the link is renamed. Then 2928d62bc4baSyz * fallback to the legacy kstats for 2929d62bc4baSyz * those non-GLDv3 links. 2930d62bc4baSyz */ 29317c478bd9Sstevel@tonic-gate if (new_ifindex != ifindex_v6 && 2932d62bc4baSyz ((ksp = kstat_lookup(kc, "link", 0, 2933d62bc4baSyz ifname)) != NULL || 29347c478bd9Sstevel@tonic-gate (ksp = kstat_lookup(kc, NULL, -1, 2935d62bc4baSyz ifname)) != NULL)) { 29367c478bd9Sstevel@tonic-gate (void) safe_kstat_read(kc, ksp, 29377c478bd9Sstevel@tonic-gate NULL); 29387c478bd9Sstevel@tonic-gate stat.ipackets = 29397c478bd9Sstevel@tonic-gate kstat_named_value(ksp, 29407c478bd9Sstevel@tonic-gate "ipackets"); 29417c478bd9Sstevel@tonic-gate stat.ierrors = 29427c478bd9Sstevel@tonic-gate kstat_named_value(ksp, 29437c478bd9Sstevel@tonic-gate "ierrors"); 29447c478bd9Sstevel@tonic-gate stat.opackets = 29457c478bd9Sstevel@tonic-gate kstat_named_value(ksp, 29467c478bd9Sstevel@tonic-gate "opackets"); 29477c478bd9Sstevel@tonic-gate stat.oerrors = 29487c478bd9Sstevel@tonic-gate kstat_named_value(ksp, 29497c478bd9Sstevel@tonic-gate "oerrors"); 29507c478bd9Sstevel@tonic-gate stat.collisions = 29517c478bd9Sstevel@tonic-gate kstat_named_value(ksp, 29527c478bd9Sstevel@tonic-gate "collisions"); 29537c478bd9Sstevel@tonic-gate if (first) { 2954ba753d4aSkeerthi if (!first_header) 2955ba753d4aSkeerthi (void) putchar('\n'); 2956ba753d4aSkeerthi first_header = B_FALSE; 29577c478bd9Sstevel@tonic-gate (void) printf( 29587c478bd9Sstevel@tonic-gate "%-5.5s %-5.5s%" 29597c478bd9Sstevel@tonic-gate "-27.27s %-27.27s " 29607c478bd9Sstevel@tonic-gate "%-6.6s %-5.5s " 29617c478bd9Sstevel@tonic-gate "%-6.6s %-5.5s " 29627c478bd9Sstevel@tonic-gate "%-6.6s\n", 29637c478bd9Sstevel@tonic-gate "Name", "Mtu", 29647c478bd9Sstevel@tonic-gate "Net/Dest", 29657c478bd9Sstevel@tonic-gate "Address", "Ipkts", 29667c478bd9Sstevel@tonic-gate "Ierrs", "Opkts", 29677c478bd9Sstevel@tonic-gate "Oerrs", "Collis"); 29687c478bd9Sstevel@tonic-gate first = B_FALSE; 29697c478bd9Sstevel@tonic-gate } 29707c478bd9Sstevel@tonic-gate if_report_ip6(ap6, ifname, 29717c478bd9Sstevel@tonic-gate logintname, &stat, B_TRUE); 29727c478bd9Sstevel@tonic-gate ifindex_v6 = new_ifindex; 29737c478bd9Sstevel@tonic-gate } else { 29747c478bd9Sstevel@tonic-gate if_report_ip6(ap6, ifname, 29757c478bd9Sstevel@tonic-gate logintname, &stat, B_FALSE); 29767c478bd9Sstevel@tonic-gate } 29777c478bd9Sstevel@tonic-gate } /* 'for' loop 2d ends */ 29787c478bd9Sstevel@tonic-gate } else if (!alreadydone) { 29797c478bd9Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 29807c478bd9Sstevel@tonic-gate char buf[IFNAMSIZ + 1]; 29817c478bd9Sstevel@tonic-gate mib2_ipv6AddrEntry_t *ap6; 29827c478bd9Sstevel@tonic-gate struct ifstat t; 2983aecc8c24Sja struct iflist *tlp = NULL; 29847c478bd9Sstevel@tonic-gate struct iflist **nextnew = &newlist6; 29857c478bd9Sstevel@tonic-gate struct iflist *walkold; 29867c478bd9Sstevel@tonic-gate struct iflist *cleanlist; 2987aecc8c24Sja boolean_t found_if = B_FALSE; 29887c478bd9Sstevel@tonic-gate 29897c478bd9Sstevel@tonic-gate alreadydone = B_TRUE; /* ignore other case */ 2990aecc8c24Sja 29917c478bd9Sstevel@tonic-gate /* 2992aecc8c24Sja * Check if there is anything to do. 2993aecc8c24Sja */ 2994aecc8c24Sja if (item->length < 2995aecc8c24Sja sizeof (mib2_ipv6AddrEntry_t)) { 2996aecc8c24Sja fail(0, "No compatible interfaces"); 2997aecc8c24Sja } 2998aecc8c24Sja 2999aecc8c24Sja /* 3000aecc8c24Sja * 'for' loop 2e: find the "right" entry: 3001aecc8c24Sja * If an interface name to match has been 3002aecc8c24Sja * supplied then try and find it, otherwise 3003aecc8c24Sja * match the first non-loopback interface found. 3004aecc8c24Sja * Use lo0 if all else fails. 30057c478bd9Sstevel@tonic-gate */ 30067c478bd9Sstevel@tonic-gate for (ap6 = (mib2_ipv6AddrEntry_t *)item->valp; 30077c478bd9Sstevel@tonic-gate (char *)ap6 < (char *)item->valp 30087c478bd9Sstevel@tonic-gate + item->length; 30097c478bd9Sstevel@tonic-gate ap6++) { 30107c478bd9Sstevel@tonic-gate (void) octetstr(&ap6->ipv6AddrIfIndex, 30117c478bd9Sstevel@tonic-gate 'a', ifname, sizeof (ifname)); 30127c478bd9Sstevel@tonic-gate (void) strtok(ifname, ":"); 30137c478bd9Sstevel@tonic-gate 30147c478bd9Sstevel@tonic-gate if (matchname) { 3015aecc8c24Sja if (strcmp(matchname, 3016aecc8c24Sja ifname) == 0) { 30177c478bd9Sstevel@tonic-gate /* 'for' loop 2e */ 3018aecc8c24Sja found_if = B_TRUE; 30197c478bd9Sstevel@tonic-gate break; 3020aecc8c24Sja } 3021aecc8c24Sja } else if (strcmp(ifname, "lo0") != 0) 30227c478bd9Sstevel@tonic-gate break; /* 'for' loop 2e */ 30237c478bd9Sstevel@tonic-gate } /* 'for' loop 2e ends */ 30247c478bd9Sstevel@tonic-gate 3025aecc8c24Sja if (matchname == NULL) { 3026aecc8c24Sja matchname = ifname; 3027aecc8c24Sja } else { 3028aecc8c24Sja if (!found_if) 3029aecc8c24Sja fail(0, "-I: %s no such " 3030aecc8c24Sja "interface.", matchname); 3031aecc8c24Sja } 3032aecc8c24Sja 30337c478bd9Sstevel@tonic-gate if (Iflag_only == 0 || !reentry) { 30347c478bd9Sstevel@tonic-gate (void) printf( 30357c478bd9Sstevel@tonic-gate " input %-6.6s" 30367c478bd9Sstevel@tonic-gate " output ", 30377c478bd9Sstevel@tonic-gate matchname); 30387c478bd9Sstevel@tonic-gate (void) printf(" input (Total)" 30397c478bd9Sstevel@tonic-gate " output\n"); 30407c478bd9Sstevel@tonic-gate (void) printf("%-7.7s %-5.5s %-7.7s " 30417c478bd9Sstevel@tonic-gate "%-5.5s %-6.6s ", 30427c478bd9Sstevel@tonic-gate "packets", "errs", "packets", 30437c478bd9Sstevel@tonic-gate "errs", "colls"); 30447c478bd9Sstevel@tonic-gate (void) printf("%-7.7s %-5.5s %-7.7s " 30457c478bd9Sstevel@tonic-gate "%-5.5s %-6.6s\n", 30467c478bd9Sstevel@tonic-gate "packets", "errs", "packets", 30477c478bd9Sstevel@tonic-gate "errs", "colls"); 30487c478bd9Sstevel@tonic-gate } 30497c478bd9Sstevel@tonic-gate 30507c478bd9Sstevel@tonic-gate sum6 = zerostat; 30517c478bd9Sstevel@tonic-gate 30527c478bd9Sstevel@tonic-gate /* 'for' loop 2f: */ 30537c478bd9Sstevel@tonic-gate for (ap6 = (mib2_ipv6AddrEntry_t *)item->valp; 30547c478bd9Sstevel@tonic-gate (char *)ap6 < (char *)item->valp 30557c478bd9Sstevel@tonic-gate + item->length; 30567c478bd9Sstevel@tonic-gate ap6++) { 30577c478bd9Sstevel@tonic-gate (void) octetstr(&ap6->ipv6AddrIfIndex, 30587c478bd9Sstevel@tonic-gate 'a', buf, sizeof (buf)); 30597c478bd9Sstevel@tonic-gate (void) strtok(buf, ":"); 3060aecc8c24Sja 3061aecc8c24Sja /* 3062aecc8c24Sja * We have reduced the IP interface 3063aecc8c24Sja * name, which could have been a 3064aecc8c24Sja * logical, down to a name suitable 3065aecc8c24Sja * for use with kstats. 3066aecc8c24Sja * We treat this name as unique and 3067aecc8c24Sja * only collate statistics for it once 3068aecc8c24Sja * per pass. This is to avoid falsely 3069aecc8c24Sja * amplifying these statistics by the 3070aecc8c24Sja * the number of logical instances. 3071aecc8c24Sja */ 3072aecc8c24Sja 3073aecc8c24Sja if ((tlp != NULL) && 3074aecc8c24Sja ((strcmp(buf, tlp->ifname) == 0))) { 3075aecc8c24Sja continue; 3076aecc8c24Sja } 3077aecc8c24Sja 3078d62bc4baSyz /* 3079d62bc4baSyz * First lookup the "link" kstats in 3080d62bc4baSyz * case the link is renamed. Then 3081d62bc4baSyz * fallback to the legacy kstats for 3082d62bc4baSyz * those non-GLDv3 links. 3083d62bc4baSyz */ 3084d62bc4baSyz if (((ksp = kstat_lookup(kc, "link", 3085d62bc4baSyz 0, buf)) != NULL || 3086d62bc4baSyz (ksp = kstat_lookup(kc, NULL, -1, 3087d62bc4baSyz buf)) != NULL) && (ksp->ks_type == 3088d62bc4baSyz KSTAT_TYPE_NAMED)) { 30897c478bd9Sstevel@tonic-gate (void) safe_kstat_read(kc, 30907c478bd9Sstevel@tonic-gate ksp, NULL); 3091d62bc4baSyz } 30927c478bd9Sstevel@tonic-gate 30937c478bd9Sstevel@tonic-gate t.ipackets = kstat_named_value(ksp, 30947c478bd9Sstevel@tonic-gate "ipackets"); 30957c478bd9Sstevel@tonic-gate t.ierrors = kstat_named_value(ksp, 30967c478bd9Sstevel@tonic-gate "ierrors"); 30977c478bd9Sstevel@tonic-gate t.opackets = kstat_named_value(ksp, 30987c478bd9Sstevel@tonic-gate "opackets"); 30997c478bd9Sstevel@tonic-gate t.oerrors = kstat_named_value(ksp, 31007c478bd9Sstevel@tonic-gate "oerrors"); 31017c478bd9Sstevel@tonic-gate t.collisions = kstat_named_value(ksp, 31027c478bd9Sstevel@tonic-gate "collisions"); 31037c478bd9Sstevel@tonic-gate 31047c478bd9Sstevel@tonic-gate if (strcmp(buf, matchname) == 0) 31057c478bd9Sstevel@tonic-gate new6 = t; 31067c478bd9Sstevel@tonic-gate 31077c478bd9Sstevel@tonic-gate /* Build the interface list */ 31087c478bd9Sstevel@tonic-gate 31097c478bd9Sstevel@tonic-gate tlp = malloc(sizeof (struct iflist)); 31107c478bd9Sstevel@tonic-gate (void) strlcpy(tlp->ifname, buf, 31117c478bd9Sstevel@tonic-gate sizeof (tlp->ifname)); 31127c478bd9Sstevel@tonic-gate tlp->tot = t; 31137c478bd9Sstevel@tonic-gate *nextnew = tlp; 31147c478bd9Sstevel@tonic-gate nextnew = &tlp->next_if; 31157c478bd9Sstevel@tonic-gate 31167c478bd9Sstevel@tonic-gate /* 31177c478bd9Sstevel@tonic-gate * First time through. 31187c478bd9Sstevel@tonic-gate * Just add up the interface stats. 31197c478bd9Sstevel@tonic-gate */ 31207c478bd9Sstevel@tonic-gate 31217c478bd9Sstevel@tonic-gate if (oldlist6 == NULL) { 31227c478bd9Sstevel@tonic-gate if_stat_total(&zerostat, 31237c478bd9Sstevel@tonic-gate &t, &sum6); 31247c478bd9Sstevel@tonic-gate continue; 31257c478bd9Sstevel@tonic-gate } 31267c478bd9Sstevel@tonic-gate 31277c478bd9Sstevel@tonic-gate /* 31287c478bd9Sstevel@tonic-gate * Walk old list for the interface. 31297c478bd9Sstevel@tonic-gate * 31307c478bd9Sstevel@tonic-gate * If found, add difference to total. 31317c478bd9Sstevel@tonic-gate * 31327c478bd9Sstevel@tonic-gate * If not, an interface has been plumbed 31337c478bd9Sstevel@tonic-gate * up. In this case, we will simply 31347c478bd9Sstevel@tonic-gate * ignore the new interface until the 31357c478bd9Sstevel@tonic-gate * next interval; as there's no easy way 31367c478bd9Sstevel@tonic-gate * to acquire statistics between time 31377c478bd9Sstevel@tonic-gate * of the plumb and the next interval 31387c478bd9Sstevel@tonic-gate * boundary. This results in inaccurate 31397c478bd9Sstevel@tonic-gate * total values for current interval. 31407c478bd9Sstevel@tonic-gate * 31417c478bd9Sstevel@tonic-gate * Note the case when an interface is 31427c478bd9Sstevel@tonic-gate * unplumbed; as similar problems exist. 31437c478bd9Sstevel@tonic-gate * The unplumbed interface is not in the 31447c478bd9Sstevel@tonic-gate * current list, and there's no easy way 31457c478bd9Sstevel@tonic-gate * to account for the statistics between 31467c478bd9Sstevel@tonic-gate * the previous interval and time of the 31477c478bd9Sstevel@tonic-gate * unplumb. Therefore, we (in a sense) 31487c478bd9Sstevel@tonic-gate * ignore the removed interface by only 31497c478bd9Sstevel@tonic-gate * involving "current" interfaces when 31507c478bd9Sstevel@tonic-gate * computing the total statistics. 31517c478bd9Sstevel@tonic-gate * Unfortunately, this also results in 31527c478bd9Sstevel@tonic-gate * inaccurate values for interval total. 31537c478bd9Sstevel@tonic-gate */ 31547c478bd9Sstevel@tonic-gate 31557c478bd9Sstevel@tonic-gate for (walkold = oldlist6; 31567c478bd9Sstevel@tonic-gate walkold != NULL; 31577c478bd9Sstevel@tonic-gate walkold = walkold->next_if) { 31587c478bd9Sstevel@tonic-gate if (strcmp(walkold->ifname, 31597c478bd9Sstevel@tonic-gate buf) == 0) { 31607c478bd9Sstevel@tonic-gate if_stat_total( 31617c478bd9Sstevel@tonic-gate &walkold->tot, 31627c478bd9Sstevel@tonic-gate &t, &sum6); 31637c478bd9Sstevel@tonic-gate break; 31647c478bd9Sstevel@tonic-gate } 31657c478bd9Sstevel@tonic-gate } 31667c478bd9Sstevel@tonic-gate 31677c478bd9Sstevel@tonic-gate } /* 'for' loop 2f ends */ 31687c478bd9Sstevel@tonic-gate 31697c478bd9Sstevel@tonic-gate *nextnew = NULL; 31707c478bd9Sstevel@tonic-gate 31717c478bd9Sstevel@tonic-gate (void) printf("%-7llu %-5llu %-7llu " 31727c478bd9Sstevel@tonic-gate "%-5llu %-6llu ", 31737c478bd9Sstevel@tonic-gate new6.ipackets - old6.ipackets, 31747c478bd9Sstevel@tonic-gate new6.ierrors - old6.ierrors, 31757c478bd9Sstevel@tonic-gate new6.opackets - old6.opackets, 31767c478bd9Sstevel@tonic-gate new6.oerrors - old6.oerrors, 31777c478bd9Sstevel@tonic-gate new6.collisions - old6.collisions); 31787c478bd9Sstevel@tonic-gate 31797c478bd9Sstevel@tonic-gate (void) printf("%-7llu %-5llu %-7llu " 31807c478bd9Sstevel@tonic-gate "%-5llu %-6llu\n", sum6.ipackets, 31817c478bd9Sstevel@tonic-gate sum6.ierrors, sum6.opackets, 31827c478bd9Sstevel@tonic-gate sum6.oerrors, sum6.collisions); 31837c478bd9Sstevel@tonic-gate 31847c478bd9Sstevel@tonic-gate /* 31857c478bd9Sstevel@tonic-gate * Tidy things up once finished. 31867c478bd9Sstevel@tonic-gate */ 31877c478bd9Sstevel@tonic-gate 31887c478bd9Sstevel@tonic-gate old6 = new6; 31897c478bd9Sstevel@tonic-gate cleanlist = oldlist6; 31907c478bd9Sstevel@tonic-gate oldlist6 = newlist6; 31917c478bd9Sstevel@tonic-gate while (cleanlist != NULL) { 31927c478bd9Sstevel@tonic-gate tlp = cleanlist->next_if; 31937c478bd9Sstevel@tonic-gate free(cleanlist); 31947c478bd9Sstevel@tonic-gate cleanlist = tlp; 31957c478bd9Sstevel@tonic-gate } 31967c478bd9Sstevel@tonic-gate } 31977c478bd9Sstevel@tonic-gate break; 31987c478bd9Sstevel@tonic-gate } 31997c478bd9Sstevel@tonic-gate } 32007c478bd9Sstevel@tonic-gate (void) fflush(stdout); 32017c478bd9Sstevel@tonic-gate } /* 'for' loop 1 ends */ 3202ba753d4aSkeerthi if ((Iflag_only == 0) && (!once_only)) 3203ba753d4aSkeerthi (void) putchar('\n'); 32047c478bd9Sstevel@tonic-gate reentry = B_TRUE; 32057c478bd9Sstevel@tonic-gate } 32067c478bd9Sstevel@tonic-gate 32077c478bd9Sstevel@tonic-gate static void 32087c478bd9Sstevel@tonic-gate if_report_ip4(mib2_ipAddrEntry_t *ap, 32097c478bd9Sstevel@tonic-gate char ifname[], char logintname[], struct ifstat *statptr, 32107c478bd9Sstevel@tonic-gate boolean_t ksp_not_null) { 32117c478bd9Sstevel@tonic-gate 32127c478bd9Sstevel@tonic-gate char abuf[MAXHOSTNAMELEN + 1]; 32137c478bd9Sstevel@tonic-gate char dstbuf[MAXHOSTNAMELEN + 1]; 32147c478bd9Sstevel@tonic-gate 32157c478bd9Sstevel@tonic-gate if (ksp_not_null) { 32167c478bd9Sstevel@tonic-gate (void) printf("%-5s %-5u", 32177c478bd9Sstevel@tonic-gate ifname, ap->ipAdEntInfo.ae_mtu); 32187c478bd9Sstevel@tonic-gate if (ap->ipAdEntInfo.ae_flags & IFF_POINTOPOINT) 32197c478bd9Sstevel@tonic-gate (void) pr_addr(ap->ipAdEntInfo.ae_pp_dst_addr, 32207c478bd9Sstevel@tonic-gate abuf, sizeof (abuf)); 32217c478bd9Sstevel@tonic-gate else 32227c478bd9Sstevel@tonic-gate (void) pr_netaddr(ap->ipAdEntAddr, 32237c478bd9Sstevel@tonic-gate ap->ipAdEntNetMask, abuf, sizeof (abuf)); 32247c478bd9Sstevel@tonic-gate (void) printf("%-13s %-14s %-6llu %-5llu %-6llu %-5llu " 32257c478bd9Sstevel@tonic-gate "%-6llu %-6llu\n", 32267c478bd9Sstevel@tonic-gate abuf, pr_addr(ap->ipAdEntAddr, dstbuf, sizeof (dstbuf)), 32277c478bd9Sstevel@tonic-gate statptr->ipackets, statptr->ierrors, 32287c478bd9Sstevel@tonic-gate statptr->opackets, statptr->oerrors, 32297c478bd9Sstevel@tonic-gate statptr->collisions, 0LL); 32307c478bd9Sstevel@tonic-gate } 32317c478bd9Sstevel@tonic-gate /* 32327c478bd9Sstevel@tonic-gate * Print logical interface info if Aflag set (including logical unit 0) 32337c478bd9Sstevel@tonic-gate */ 32347c478bd9Sstevel@tonic-gate if (Aflag) { 32357c478bd9Sstevel@tonic-gate *statptr = zerostat; 32367c478bd9Sstevel@tonic-gate statptr->ipackets = ap->ipAdEntInfo.ae_ibcnt; 32377c478bd9Sstevel@tonic-gate statptr->opackets = ap->ipAdEntInfo.ae_obcnt; 32387c478bd9Sstevel@tonic-gate 32397c478bd9Sstevel@tonic-gate (void) printf("%-5s %-5u", logintname, ap->ipAdEntInfo.ae_mtu); 32407c478bd9Sstevel@tonic-gate if (ap->ipAdEntInfo.ae_flags & IFF_POINTOPOINT) 32417c478bd9Sstevel@tonic-gate (void) pr_addr(ap->ipAdEntInfo.ae_pp_dst_addr, abuf, 32427c478bd9Sstevel@tonic-gate sizeof (abuf)); 32437c478bd9Sstevel@tonic-gate else 32447c478bd9Sstevel@tonic-gate (void) pr_netaddr(ap->ipAdEntAddr, ap->ipAdEntNetMask, 32457c478bd9Sstevel@tonic-gate abuf, sizeof (abuf)); 32467c478bd9Sstevel@tonic-gate 32477c478bd9Sstevel@tonic-gate (void) printf("%-13s %-14s %-6llu %-5s %-6llu " 32487c478bd9Sstevel@tonic-gate "%-5s %-6s %-6llu\n", abuf, 32497c478bd9Sstevel@tonic-gate pr_addr(ap->ipAdEntAddr, dstbuf, sizeof (dstbuf)), 32507c478bd9Sstevel@tonic-gate statptr->ipackets, "N/A", statptr->opackets, "N/A", "N/A", 32517c478bd9Sstevel@tonic-gate 0LL); 32527c478bd9Sstevel@tonic-gate } 32537c478bd9Sstevel@tonic-gate } 32547c478bd9Sstevel@tonic-gate 32557c478bd9Sstevel@tonic-gate static void 32567c478bd9Sstevel@tonic-gate if_report_ip6(mib2_ipv6AddrEntry_t *ap6, 32577c478bd9Sstevel@tonic-gate char ifname[], char logintname[], struct ifstat *statptr, 32587c478bd9Sstevel@tonic-gate boolean_t ksp_not_null) { 32597c478bd9Sstevel@tonic-gate 32607c478bd9Sstevel@tonic-gate char abuf[MAXHOSTNAMELEN + 1]; 32617c478bd9Sstevel@tonic-gate char dstbuf[MAXHOSTNAMELEN + 1]; 32627c478bd9Sstevel@tonic-gate 32637c478bd9Sstevel@tonic-gate if (ksp_not_null) { 32647c478bd9Sstevel@tonic-gate (void) printf("%-5s %-5u", ifname, ap6->ipv6AddrInfo.ae_mtu); 32657c478bd9Sstevel@tonic-gate if (ap6->ipv6AddrInfo.ae_flags & 32667c478bd9Sstevel@tonic-gate IFF_POINTOPOINT) { 32677c478bd9Sstevel@tonic-gate (void) pr_addr6(&ap6->ipv6AddrInfo.ae_pp_dst_addr, 32687c478bd9Sstevel@tonic-gate abuf, sizeof (abuf)); 32697c478bd9Sstevel@tonic-gate } else { 32707c478bd9Sstevel@tonic-gate (void) pr_prefix6(&ap6->ipv6AddrAddress, 32717c478bd9Sstevel@tonic-gate ap6->ipv6AddrPfxLength, abuf, 32727c478bd9Sstevel@tonic-gate sizeof (abuf)); 32737c478bd9Sstevel@tonic-gate } 32747c478bd9Sstevel@tonic-gate (void) printf("%-27s %-27s %-6llu %-5llu " 32757c478bd9Sstevel@tonic-gate "%-6llu %-5llu %-6llu\n", 32767c478bd9Sstevel@tonic-gate abuf, pr_addr6(&ap6->ipv6AddrAddress, dstbuf, 32777c478bd9Sstevel@tonic-gate sizeof (dstbuf)), 32787c478bd9Sstevel@tonic-gate statptr->ipackets, statptr->ierrors, statptr->opackets, 32797c478bd9Sstevel@tonic-gate statptr->oerrors, statptr->collisions); 32807c478bd9Sstevel@tonic-gate } 32817c478bd9Sstevel@tonic-gate /* 32827c478bd9Sstevel@tonic-gate * Print logical interface info if Aflag set (including logical unit 0) 32837c478bd9Sstevel@tonic-gate */ 32847c478bd9Sstevel@tonic-gate if (Aflag) { 32857c478bd9Sstevel@tonic-gate *statptr = zerostat; 32867c478bd9Sstevel@tonic-gate statptr->ipackets = ap6->ipv6AddrInfo.ae_ibcnt; 32877c478bd9Sstevel@tonic-gate statptr->opackets = ap6->ipv6AddrInfo.ae_obcnt; 32887c478bd9Sstevel@tonic-gate 32897c478bd9Sstevel@tonic-gate (void) printf("%-5s %-5u", logintname, 32907c478bd9Sstevel@tonic-gate ap6->ipv6AddrInfo.ae_mtu); 32917c478bd9Sstevel@tonic-gate if (ap6->ipv6AddrInfo.ae_flags & IFF_POINTOPOINT) 32927c478bd9Sstevel@tonic-gate (void) pr_addr6(&ap6->ipv6AddrInfo.ae_pp_dst_addr, 32937c478bd9Sstevel@tonic-gate abuf, sizeof (abuf)); 32947c478bd9Sstevel@tonic-gate else 32957c478bd9Sstevel@tonic-gate (void) pr_prefix6(&ap6->ipv6AddrAddress, 32967c478bd9Sstevel@tonic-gate ap6->ipv6AddrPfxLength, abuf, sizeof (abuf)); 32977c478bd9Sstevel@tonic-gate (void) printf("%-27s %-27s %-6llu %-5s %-6llu %-5s %-6s\n", 32987c478bd9Sstevel@tonic-gate abuf, pr_addr6(&ap6->ipv6AddrAddress, dstbuf, 32997c478bd9Sstevel@tonic-gate sizeof (dstbuf)), 33007c478bd9Sstevel@tonic-gate statptr->ipackets, "N/A", 33017c478bd9Sstevel@tonic-gate statptr->opackets, "N/A", "N/A"); 33027c478bd9Sstevel@tonic-gate } 33037c478bd9Sstevel@tonic-gate } 33047c478bd9Sstevel@tonic-gate 33057c478bd9Sstevel@tonic-gate /* --------------------- DHCP_REPORT (netstat -D) ------------------------- */ 33067c478bd9Sstevel@tonic-gate 3307d04ccbb3Scarlsonj static boolean_t 3308d04ccbb3Scarlsonj dhcp_do_ipc(dhcp_ipc_type_t type, const char *ifname, boolean_t printed_one) 33097c478bd9Sstevel@tonic-gate { 33107c478bd9Sstevel@tonic-gate dhcp_ipc_request_t *request; 33117c478bd9Sstevel@tonic-gate dhcp_ipc_reply_t *reply; 33127c478bd9Sstevel@tonic-gate int error; 33137c478bd9Sstevel@tonic-gate 33147c478bd9Sstevel@tonic-gate request = dhcp_ipc_alloc_request(type, ifname, NULL, 0, DHCP_TYPE_NONE); 33157c478bd9Sstevel@tonic-gate if (request == NULL) 33167c478bd9Sstevel@tonic-gate fail(0, "dhcp_do_ipc: out of memory"); 33177c478bd9Sstevel@tonic-gate 33187c478bd9Sstevel@tonic-gate error = dhcp_ipc_make_request(request, &reply, DHCP_IPC_WAIT_DEFAULT); 33197c478bd9Sstevel@tonic-gate if (error != 0) { 33207c478bd9Sstevel@tonic-gate free(request); 33217c478bd9Sstevel@tonic-gate fail(0, "dhcp_do_ipc: %s", dhcp_ipc_strerror(error)); 33227c478bd9Sstevel@tonic-gate } 33237c478bd9Sstevel@tonic-gate 33247c478bd9Sstevel@tonic-gate free(request); 33257c478bd9Sstevel@tonic-gate error = reply->return_code; 3326d04ccbb3Scarlsonj if (error == DHCP_IPC_E_UNKIF) { 3327d04ccbb3Scarlsonj free(reply); 3328d04ccbb3Scarlsonj return (printed_one); 3329d04ccbb3Scarlsonj } 33307c478bd9Sstevel@tonic-gate if (error != 0) { 33317c478bd9Sstevel@tonic-gate free(reply); 33327c478bd9Sstevel@tonic-gate fail(0, "dhcp_do_ipc: %s", dhcp_ipc_strerror(error)); 33337c478bd9Sstevel@tonic-gate } 33347c478bd9Sstevel@tonic-gate 3335d04ccbb3Scarlsonj if (!printed_one) 3336d04ccbb3Scarlsonj (void) printf("%s", dhcp_status_hdr_string()); 3337d04ccbb3Scarlsonj 3338d04ccbb3Scarlsonj (void) printf("%s", dhcp_status_reply_to_string(reply)); 3339d04ccbb3Scarlsonj free(reply); 3340d04ccbb3Scarlsonj return (B_TRUE); 33417c478bd9Sstevel@tonic-gate } 33427c478bd9Sstevel@tonic-gate 33437c478bd9Sstevel@tonic-gate /* 3344d04ccbb3Scarlsonj * dhcp_walk_interfaces: walk the list of interfaces that have a given set of 3345d04ccbb3Scarlsonj * flags turned on (flags_on) and a given set turned off (flags_off) for a 3346d04ccbb3Scarlsonj * given address family (af). For each, print out the DHCP status using 3347d04ccbb3Scarlsonj * dhcp_do_ipc. 33487c478bd9Sstevel@tonic-gate */ 3349d04ccbb3Scarlsonj static boolean_t 3350d04ccbb3Scarlsonj dhcp_walk_interfaces(uint_t flags_on, uint_t flags_off, int af, 3351d04ccbb3Scarlsonj boolean_t printed_one) 33527c478bd9Sstevel@tonic-gate { 3353d04ccbb3Scarlsonj struct lifnum lifn; 3354d04ccbb3Scarlsonj struct lifconf lifc; 33557c478bd9Sstevel@tonic-gate int n_ifs, i, sock_fd; 33567c478bd9Sstevel@tonic-gate 3357d04ccbb3Scarlsonj sock_fd = socket(af, SOCK_DGRAM, 0); 33587c478bd9Sstevel@tonic-gate if (sock_fd == -1) 3359d04ccbb3Scarlsonj return (printed_one); 33607c478bd9Sstevel@tonic-gate 3361d04ccbb3Scarlsonj /* 3362d04ccbb3Scarlsonj * SIOCGLIFNUM is just an estimate. If the ioctl fails, we don't care; 3363d04ccbb3Scarlsonj * just drive on and use SIOCGLIFCONF with increasing buffer sizes, as 3364d04ccbb3Scarlsonj * is traditional. 3365d04ccbb3Scarlsonj */ 3366d04ccbb3Scarlsonj (void) memset(&lifn, 0, sizeof (lifn)); 3367d04ccbb3Scarlsonj lifn.lifn_family = af; 3368*e11c3f44Smeem lifn.lifn_flags = LIFC_ALLZONES | LIFC_NOXMIT | LIFC_UNDER_IPMP; 3369d04ccbb3Scarlsonj if (ioctl(sock_fd, SIOCGLIFNUM, &lifn) == -1) 3370d04ccbb3Scarlsonj n_ifs = LIFN_GUARD_VALUE; 3371d04ccbb3Scarlsonj else 3372d04ccbb3Scarlsonj n_ifs = lifn.lifn_count + LIFN_GUARD_VALUE; 3373d04ccbb3Scarlsonj 3374d04ccbb3Scarlsonj (void) memset(&lifc, 0, sizeof (lifc)); 3375d04ccbb3Scarlsonj lifc.lifc_family = af; 3376d04ccbb3Scarlsonj lifc.lifc_flags = lifn.lifn_flags; 3377d04ccbb3Scarlsonj lifc.lifc_len = n_ifs * sizeof (struct lifreq); 3378d04ccbb3Scarlsonj lifc.lifc_buf = malloc(lifc.lifc_len); 3379d04ccbb3Scarlsonj if (lifc.lifc_buf != NULL) { 3380d04ccbb3Scarlsonj 3381d04ccbb3Scarlsonj if (ioctl(sock_fd, SIOCGLIFCONF, &lifc) == -1) { 33827c478bd9Sstevel@tonic-gate (void) close(sock_fd); 3383d04ccbb3Scarlsonj free(lifc.lifc_buf); 33847c478bd9Sstevel@tonic-gate return (NULL); 33857c478bd9Sstevel@tonic-gate } 33867c478bd9Sstevel@tonic-gate 3387d04ccbb3Scarlsonj n_ifs = lifc.lifc_len / sizeof (struct lifreq); 33887c478bd9Sstevel@tonic-gate 3389d04ccbb3Scarlsonj for (i = 0; i < n_ifs; i++) { 3390d04ccbb3Scarlsonj if (ioctl(sock_fd, SIOCGLIFFLAGS, &lifc.lifc_req[i]) == 3391d04ccbb3Scarlsonj 0 && (lifc.lifc_req[i].lifr_flags & (flags_on | 3392d04ccbb3Scarlsonj flags_off)) != flags_on) 3393d04ccbb3Scarlsonj continue; 3394d04ccbb3Scarlsonj printed_one = dhcp_do_ipc(DHCP_STATUS | 3395d04ccbb3Scarlsonj (af == AF_INET6 ? DHCP_V6 : 0), 3396d04ccbb3Scarlsonj lifc.lifc_req[i].lifr_name, printed_one); 3397d04ccbb3Scarlsonj } 33987c478bd9Sstevel@tonic-gate } 33997c478bd9Sstevel@tonic-gate (void) close(sock_fd); 3400d04ccbb3Scarlsonj free(lifc.lifc_buf); 3401d04ccbb3Scarlsonj return (printed_one); 34027c478bd9Sstevel@tonic-gate } 34037c478bd9Sstevel@tonic-gate 34047c478bd9Sstevel@tonic-gate static void 34057c478bd9Sstevel@tonic-gate dhcp_report(char *ifname) 34067c478bd9Sstevel@tonic-gate { 3407d04ccbb3Scarlsonj boolean_t printed_one; 34087c478bd9Sstevel@tonic-gate 3409d04ccbb3Scarlsonj if (!family_selected(AF_INET) && !family_selected(AF_INET6)) 34107c478bd9Sstevel@tonic-gate return; 34117c478bd9Sstevel@tonic-gate 3412d04ccbb3Scarlsonj printed_one = B_FALSE; 3413d04ccbb3Scarlsonj if (ifname != NULL) { 3414d04ccbb3Scarlsonj if (family_selected(AF_INET)) { 3415d04ccbb3Scarlsonj printed_one = dhcp_do_ipc(DHCP_STATUS, ifname, 3416d04ccbb3Scarlsonj printed_one); 3417d04ccbb3Scarlsonj } 3418d04ccbb3Scarlsonj if (family_selected(AF_INET6)) { 3419d04ccbb3Scarlsonj printed_one = dhcp_do_ipc(DHCP_STATUS | DHCP_V6, 3420d04ccbb3Scarlsonj ifname, printed_one); 3421d04ccbb3Scarlsonj } 3422d04ccbb3Scarlsonj if (!printed_one) { 3423d04ccbb3Scarlsonj fail(0, "%s: %s", ifname, 3424d04ccbb3Scarlsonj dhcp_ipc_strerror(DHCP_IPC_E_UNKIF)); 3425d04ccbb3Scarlsonj } 3426d04ccbb3Scarlsonj } else { 3427d04ccbb3Scarlsonj if (family_selected(AF_INET)) { 3428d04ccbb3Scarlsonj printed_one = dhcp_walk_interfaces(IFF_DHCPRUNNING, 3429d04ccbb3Scarlsonj 0, AF_INET, printed_one); 3430d04ccbb3Scarlsonj } 3431d04ccbb3Scarlsonj if (family_selected(AF_INET6)) { 3432d04ccbb3Scarlsonj (void) dhcp_walk_interfaces(IFF_DHCPRUNNING, 3433d04ccbb3Scarlsonj IFF_ADDRCONF, AF_INET6, printed_one); 3434d04ccbb3Scarlsonj } 34357c478bd9Sstevel@tonic-gate } 34367c478bd9Sstevel@tonic-gate } 34377c478bd9Sstevel@tonic-gate 34387c478bd9Sstevel@tonic-gate /* --------------------- GROUP_REPORT (netstat -g) ------------------------- */ 34397c478bd9Sstevel@tonic-gate 34407c478bd9Sstevel@tonic-gate static void 34417c478bd9Sstevel@tonic-gate group_report(mib_item_t *item) 34427c478bd9Sstevel@tonic-gate { 34437c478bd9Sstevel@tonic-gate mib_item_t *v4grp = NULL, *v4src = NULL; 34447c478bd9Sstevel@tonic-gate mib_item_t *v6grp = NULL, *v6src = NULL; 34457c478bd9Sstevel@tonic-gate int jtemp = 0; 34467c478bd9Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 34477c478bd9Sstevel@tonic-gate char abuf[MAXHOSTNAMELEN + 1]; 34487c478bd9Sstevel@tonic-gate ip_member_t *ipmp; 34497c478bd9Sstevel@tonic-gate ip_grpsrc_t *ips; 34507c478bd9Sstevel@tonic-gate ipv6_member_t *ipmp6; 34517c478bd9Sstevel@tonic-gate ipv6_grpsrc_t *ips6; 34527c478bd9Sstevel@tonic-gate boolean_t first, first_src; 34537c478bd9Sstevel@tonic-gate 34547c478bd9Sstevel@tonic-gate /* 'for' loop 1: */ 34557c478bd9Sstevel@tonic-gate for (; item; item = item->next_item) { 34567c478bd9Sstevel@tonic-gate if (Dflag) { 34577c478bd9Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp); 34587c478bd9Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, " 34597c478bd9Sstevel@tonic-gate "length = %d, valp = 0x%p\n", 34607c478bd9Sstevel@tonic-gate item->group, item->mib_id, item->length, 34617c478bd9Sstevel@tonic-gate item->valp); 34627c478bd9Sstevel@tonic-gate } 34637c478bd9Sstevel@tonic-gate if (item->group == MIB2_IP && family_selected(AF_INET)) { 34647c478bd9Sstevel@tonic-gate switch (item->mib_id) { 34657c478bd9Sstevel@tonic-gate case EXPER_IP_GROUP_MEMBERSHIP: 34667c478bd9Sstevel@tonic-gate v4grp = item; 34677c478bd9Sstevel@tonic-gate if (Dflag) 34687c478bd9Sstevel@tonic-gate (void) printf("item is v4grp info\n"); 34697c478bd9Sstevel@tonic-gate break; 34707c478bd9Sstevel@tonic-gate case EXPER_IP_GROUP_SOURCES: 34717c478bd9Sstevel@tonic-gate v4src = item; 34727c478bd9Sstevel@tonic-gate if (Dflag) 34737c478bd9Sstevel@tonic-gate (void) printf("item is v4src info\n"); 34747c478bd9Sstevel@tonic-gate break; 34757c478bd9Sstevel@tonic-gate default: 34767c478bd9Sstevel@tonic-gate continue; 34777c478bd9Sstevel@tonic-gate } 34787c478bd9Sstevel@tonic-gate continue; 34797c478bd9Sstevel@tonic-gate } 34807c478bd9Sstevel@tonic-gate if (item->group == MIB2_IP6 && family_selected(AF_INET6)) { 34817c478bd9Sstevel@tonic-gate switch (item->mib_id) { 34827c478bd9Sstevel@tonic-gate case EXPER_IP6_GROUP_MEMBERSHIP: 34837c478bd9Sstevel@tonic-gate v6grp = item; 34847c478bd9Sstevel@tonic-gate if (Dflag) 34857c478bd9Sstevel@tonic-gate (void) printf("item is v6grp info\n"); 34867c478bd9Sstevel@tonic-gate break; 34877c478bd9Sstevel@tonic-gate case EXPER_IP6_GROUP_SOURCES: 34887c478bd9Sstevel@tonic-gate v6src = item; 34897c478bd9Sstevel@tonic-gate if (Dflag) 34907c478bd9Sstevel@tonic-gate (void) printf("item is v6src info\n"); 34917c478bd9Sstevel@tonic-gate break; 34927c478bd9Sstevel@tonic-gate default: 34937c478bd9Sstevel@tonic-gate continue; 34947c478bd9Sstevel@tonic-gate } 34957c478bd9Sstevel@tonic-gate } 34967c478bd9Sstevel@tonic-gate } 34977c478bd9Sstevel@tonic-gate 34987c478bd9Sstevel@tonic-gate if (family_selected(AF_INET) && v4grp != NULL) { 34997c478bd9Sstevel@tonic-gate if (Dflag) 35007c478bd9Sstevel@tonic-gate (void) printf("%u records for ipGroupMember:\n", 35017c478bd9Sstevel@tonic-gate v4grp->length / sizeof (ip_member_t)); 35027c478bd9Sstevel@tonic-gate 35037c478bd9Sstevel@tonic-gate first = B_TRUE; 35047c478bd9Sstevel@tonic-gate for (ipmp = (ip_member_t *)v4grp->valp; 35057c478bd9Sstevel@tonic-gate (char *)ipmp < (char *)v4grp->valp + v4grp->length; 35067c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 35077c478bd9Sstevel@tonic-gate ipmp = (ip_member_t *)((char *)ipmp + ipMemberEntrySize)) { 35087c478bd9Sstevel@tonic-gate if (first) { 35097c478bd9Sstevel@tonic-gate (void) puts(v4compat ? 35107c478bd9Sstevel@tonic-gate "Group Memberships" : 35117c478bd9Sstevel@tonic-gate "Group Memberships: IPv4"); 35127c478bd9Sstevel@tonic-gate (void) puts("Interface " 35137c478bd9Sstevel@tonic-gate "Group RefCnt"); 35147c478bd9Sstevel@tonic-gate (void) puts("--------- " 35157c478bd9Sstevel@tonic-gate "-------------------- ------"); 35167c478bd9Sstevel@tonic-gate first = B_FALSE; 35177c478bd9Sstevel@tonic-gate } 35187c478bd9Sstevel@tonic-gate 35197c478bd9Sstevel@tonic-gate (void) printf("%-9s %-20s %6u\n", 35207c478bd9Sstevel@tonic-gate octetstr(&ipmp->ipGroupMemberIfIndex, 'a', 35217c478bd9Sstevel@tonic-gate ifname, sizeof (ifname)), 35227c478bd9Sstevel@tonic-gate pr_addr(ipmp->ipGroupMemberAddress, 35237c478bd9Sstevel@tonic-gate abuf, sizeof (abuf)), 35247c478bd9Sstevel@tonic-gate ipmp->ipGroupMemberRefCnt); 35257c478bd9Sstevel@tonic-gate 35267c478bd9Sstevel@tonic-gate 35277c478bd9Sstevel@tonic-gate if (!Vflag || v4src == NULL) 35287c478bd9Sstevel@tonic-gate continue; 35297c478bd9Sstevel@tonic-gate 35307c478bd9Sstevel@tonic-gate if (Dflag) 35317c478bd9Sstevel@tonic-gate (void) printf("scanning %u ipGroupSource " 35327c478bd9Sstevel@tonic-gate "records...\n", 35337c478bd9Sstevel@tonic-gate v4src->length/sizeof (ip_grpsrc_t)); 35347c478bd9Sstevel@tonic-gate 35357c478bd9Sstevel@tonic-gate first_src = B_TRUE; 35367c478bd9Sstevel@tonic-gate for (ips = (ip_grpsrc_t *)v4src->valp; 35377c478bd9Sstevel@tonic-gate (char *)ips < (char *)v4src->valp + v4src->length; 35387c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 35397c478bd9Sstevel@tonic-gate ips = (ip_grpsrc_t *)((char *)ips + 35407c478bd9Sstevel@tonic-gate ipGroupSourceEntrySize)) { 35417c478bd9Sstevel@tonic-gate /* 35427c478bd9Sstevel@tonic-gate * We assume that all source addrs for a given 35437c478bd9Sstevel@tonic-gate * interface/group pair are contiguous, so on 35447c478bd9Sstevel@tonic-gate * the first non-match after we've found at 35457c478bd9Sstevel@tonic-gate * least one, we bail. 35467c478bd9Sstevel@tonic-gate */ 35477c478bd9Sstevel@tonic-gate if ((ipmp->ipGroupMemberAddress != 35487c478bd9Sstevel@tonic-gate ips->ipGroupSourceGroup) || 35497c478bd9Sstevel@tonic-gate (!octetstrmatch(&ipmp->ipGroupMemberIfIndex, 35507c478bd9Sstevel@tonic-gate &ips->ipGroupSourceIfIndex))) { 35517c478bd9Sstevel@tonic-gate if (first_src) 35527c478bd9Sstevel@tonic-gate continue; 35537c478bd9Sstevel@tonic-gate else 35547c478bd9Sstevel@tonic-gate break; 35557c478bd9Sstevel@tonic-gate } 35567c478bd9Sstevel@tonic-gate if (first_src) { 35577c478bd9Sstevel@tonic-gate (void) printf("\t%s: %s\n", 35587c478bd9Sstevel@tonic-gate fmodestr( 35597c478bd9Sstevel@tonic-gate ipmp->ipGroupMemberFilterMode), 35607c478bd9Sstevel@tonic-gate pr_addr(ips->ipGroupSourceAddress, 35617c478bd9Sstevel@tonic-gate abuf, sizeof (abuf))); 35627c478bd9Sstevel@tonic-gate first_src = B_FALSE; 35637c478bd9Sstevel@tonic-gate continue; 35647c478bd9Sstevel@tonic-gate } 35657c478bd9Sstevel@tonic-gate 35667c478bd9Sstevel@tonic-gate (void) printf("\t %s\n", 35677c478bd9Sstevel@tonic-gate pr_addr(ips->ipGroupSourceAddress, abuf, 35687c478bd9Sstevel@tonic-gate sizeof (abuf))); 35697c478bd9Sstevel@tonic-gate } 35707c478bd9Sstevel@tonic-gate } 35717c478bd9Sstevel@tonic-gate (void) putchar('\n'); 35727c478bd9Sstevel@tonic-gate } 35737c478bd9Sstevel@tonic-gate 35747c478bd9Sstevel@tonic-gate if (family_selected(AF_INET6) && v6grp != NULL) { 35757c478bd9Sstevel@tonic-gate if (Dflag) 35767c478bd9Sstevel@tonic-gate (void) printf("%u records for ipv6GroupMember:\n", 35777c478bd9Sstevel@tonic-gate v6grp->length / sizeof (ipv6_member_t)); 35787c478bd9Sstevel@tonic-gate 35797c478bd9Sstevel@tonic-gate first = B_TRUE; 35807c478bd9Sstevel@tonic-gate for (ipmp6 = (ipv6_member_t *)v6grp->valp; 35817c478bd9Sstevel@tonic-gate (char *)ipmp6 < (char *)v6grp->valp + v6grp->length; 35827c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 35837c478bd9Sstevel@tonic-gate ipmp6 = (ipv6_member_t *)((char *)ipmp6 + 3584*e11c3f44Smeem ipv6MemberEntrySize)) { 35857c478bd9Sstevel@tonic-gate if (first) { 35867c478bd9Sstevel@tonic-gate (void) puts("Group Memberships: " 35877c478bd9Sstevel@tonic-gate "IPv6"); 35887c478bd9Sstevel@tonic-gate (void) puts(" If " 35897c478bd9Sstevel@tonic-gate "Group RefCnt"); 35907c478bd9Sstevel@tonic-gate (void) puts("----- " 35917c478bd9Sstevel@tonic-gate "--------------------------- ------"); 35927c478bd9Sstevel@tonic-gate first = B_FALSE; 35937c478bd9Sstevel@tonic-gate } 35947c478bd9Sstevel@tonic-gate 35957c478bd9Sstevel@tonic-gate (void) printf("%-5s %-27s %5u\n", 3596*e11c3f44Smeem ifindex2str(ipmp6->ipv6GroupMemberIfIndex, ifname), 35977c478bd9Sstevel@tonic-gate pr_addr6(&ipmp6->ipv6GroupMemberAddress, 35987c478bd9Sstevel@tonic-gate abuf, sizeof (abuf)), 35997c478bd9Sstevel@tonic-gate ipmp6->ipv6GroupMemberRefCnt); 36007c478bd9Sstevel@tonic-gate 36017c478bd9Sstevel@tonic-gate if (!Vflag || v6src == NULL) 36027c478bd9Sstevel@tonic-gate continue; 36037c478bd9Sstevel@tonic-gate 36047c478bd9Sstevel@tonic-gate if (Dflag) 36057c478bd9Sstevel@tonic-gate (void) printf("scanning %u ipv6GroupSource " 36067c478bd9Sstevel@tonic-gate "records...\n", 36077c478bd9Sstevel@tonic-gate v6src->length/sizeof (ipv6_grpsrc_t)); 36087c478bd9Sstevel@tonic-gate 36097c478bd9Sstevel@tonic-gate first_src = B_TRUE; 36107c478bd9Sstevel@tonic-gate for (ips6 = (ipv6_grpsrc_t *)v6src->valp; 36117c478bd9Sstevel@tonic-gate (char *)ips6 < (char *)v6src->valp + v6src->length; 36127c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 36137c478bd9Sstevel@tonic-gate ips6 = (ipv6_grpsrc_t *)((char *)ips6 + 36147c478bd9Sstevel@tonic-gate ipv6GroupSourceEntrySize)) { 36157c478bd9Sstevel@tonic-gate /* same assumption as in the v4 case above */ 36167c478bd9Sstevel@tonic-gate if ((ipmp6->ipv6GroupMemberIfIndex != 36177c478bd9Sstevel@tonic-gate ips6->ipv6GroupSourceIfIndex) || 36187c478bd9Sstevel@tonic-gate (!IN6_ARE_ADDR_EQUAL( 36197c478bd9Sstevel@tonic-gate &ipmp6->ipv6GroupMemberAddress, 36207c478bd9Sstevel@tonic-gate &ips6->ipv6GroupSourceGroup))) { 36217c478bd9Sstevel@tonic-gate if (first_src) 36227c478bd9Sstevel@tonic-gate continue; 36237c478bd9Sstevel@tonic-gate else 36247c478bd9Sstevel@tonic-gate break; 36257c478bd9Sstevel@tonic-gate } 36267c478bd9Sstevel@tonic-gate if (first_src) { 36277c478bd9Sstevel@tonic-gate (void) printf("\t%s: %s\n", 36287c478bd9Sstevel@tonic-gate fmodestr( 36297c478bd9Sstevel@tonic-gate ipmp6->ipv6GroupMemberFilterMode), 36307c478bd9Sstevel@tonic-gate pr_addr6( 36317c478bd9Sstevel@tonic-gate &ips6->ipv6GroupSourceAddress, 36327c478bd9Sstevel@tonic-gate abuf, sizeof (abuf))); 36337c478bd9Sstevel@tonic-gate first_src = B_FALSE; 36347c478bd9Sstevel@tonic-gate continue; 36357c478bd9Sstevel@tonic-gate } 36367c478bd9Sstevel@tonic-gate 36377c478bd9Sstevel@tonic-gate (void) printf("\t %s\n", 36387c478bd9Sstevel@tonic-gate pr_addr6(&ips6->ipv6GroupSourceAddress, 36397c478bd9Sstevel@tonic-gate abuf, sizeof (abuf))); 36407c478bd9Sstevel@tonic-gate } 36417c478bd9Sstevel@tonic-gate } 36427c478bd9Sstevel@tonic-gate (void) putchar('\n'); 36437c478bd9Sstevel@tonic-gate } 36447c478bd9Sstevel@tonic-gate 36457c478bd9Sstevel@tonic-gate (void) putchar('\n'); 36467c478bd9Sstevel@tonic-gate (void) fflush(stdout); 36477c478bd9Sstevel@tonic-gate } 36487c478bd9Sstevel@tonic-gate 36497c478bd9Sstevel@tonic-gate /* --------------------- ARP_REPORT (netstat -p) -------------------------- */ 36507c478bd9Sstevel@tonic-gate 36517c478bd9Sstevel@tonic-gate static void 36527c478bd9Sstevel@tonic-gate arp_report(mib_item_t *item) 36537c478bd9Sstevel@tonic-gate { 36547c478bd9Sstevel@tonic-gate int jtemp = 0; 36557c478bd9Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 36567c478bd9Sstevel@tonic-gate char abuf[MAXHOSTNAMELEN + 1]; 36577c478bd9Sstevel@tonic-gate char maskbuf[STR_EXPAND * OCTET_LENGTH + 1]; 36587c478bd9Sstevel@tonic-gate char flbuf[32]; /* ACE_F_ flags */ 36597c478bd9Sstevel@tonic-gate char xbuf[STR_EXPAND * OCTET_LENGTH + 1]; 36607c478bd9Sstevel@tonic-gate mib2_ipNetToMediaEntry_t *np; 36617c478bd9Sstevel@tonic-gate int flags; 36627c478bd9Sstevel@tonic-gate boolean_t first; 36637c478bd9Sstevel@tonic-gate 36647c478bd9Sstevel@tonic-gate if (!(family_selected(AF_INET))) 36657c478bd9Sstevel@tonic-gate return; 36667c478bd9Sstevel@tonic-gate 36677c478bd9Sstevel@tonic-gate /* 'for' loop 1: */ 36687c478bd9Sstevel@tonic-gate for (; item; item = item->next_item) { 36697c478bd9Sstevel@tonic-gate if (Dflag) { 36707c478bd9Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp); 36717c478bd9Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, " 36727c478bd9Sstevel@tonic-gate "length = %d, valp = 0x%p\n", 36737c478bd9Sstevel@tonic-gate item->group, item->mib_id, item->length, 36747c478bd9Sstevel@tonic-gate item->valp); 36757c478bd9Sstevel@tonic-gate } 36767c478bd9Sstevel@tonic-gate if (!(item->group == MIB2_IP && item->mib_id == MIB2_IP_MEDIA)) 36777c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 36787c478bd9Sstevel@tonic-gate 36797c478bd9Sstevel@tonic-gate if (Dflag) 36807c478bd9Sstevel@tonic-gate (void) printf("%u records for " 36817c478bd9Sstevel@tonic-gate "ipNetToMediaEntryTable:\n", 36827c478bd9Sstevel@tonic-gate item->length/sizeof (mib2_ipNetToMediaEntry_t)); 36837c478bd9Sstevel@tonic-gate 36847c478bd9Sstevel@tonic-gate first = B_TRUE; 36857c478bd9Sstevel@tonic-gate /* 'for' loop 2: */ 36867c478bd9Sstevel@tonic-gate for (np = (mib2_ipNetToMediaEntry_t *)item->valp; 36877c478bd9Sstevel@tonic-gate (char *)np < (char *)item->valp + item->length; 36887c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 36897c478bd9Sstevel@tonic-gate np = (mib2_ipNetToMediaEntry_t *)((char *)np + 36907c478bd9Sstevel@tonic-gate ipNetToMediaEntrySize)) { 36917c478bd9Sstevel@tonic-gate if (first) { 36927c478bd9Sstevel@tonic-gate (void) puts(v4compat ? 36937c478bd9Sstevel@tonic-gate "Net to Media Table" : 36947c478bd9Sstevel@tonic-gate "Net to Media Table: IPv4"); 369569bb4bb4Scarlsonj (void) puts("Device " 369669bb4bb4Scarlsonj " IP Address Mask " 369769bb4bb4Scarlsonj "Flags Phys Addr"); 369869bb4bb4Scarlsonj (void) puts("------ " 369969bb4bb4Scarlsonj "-------------------- --------------- " 370069bb4bb4Scarlsonj "-------- ---------------"); 37017c478bd9Sstevel@tonic-gate first = B_FALSE; 37027c478bd9Sstevel@tonic-gate } 37037c478bd9Sstevel@tonic-gate 37047c478bd9Sstevel@tonic-gate flbuf[0] = '\0'; 37057c478bd9Sstevel@tonic-gate flags = np->ipNetToMediaInfo.ntm_flags; 370669bb4bb4Scarlsonj /* 370769bb4bb4Scarlsonj * Note that not all flags are possible at the same 370869bb4bb4Scarlsonj * time. Patterns: SPLAy DUo 370969bb4bb4Scarlsonj */ 37107c478bd9Sstevel@tonic-gate if (flags & ACE_F_PERMANENT) 37117c478bd9Sstevel@tonic-gate (void) strcat(flbuf, "S"); 37127c478bd9Sstevel@tonic-gate if (flags & ACE_F_PUBLISH) 37137c478bd9Sstevel@tonic-gate (void) strcat(flbuf, "P"); 37147c478bd9Sstevel@tonic-gate if (flags & ACE_F_DYING) 37157c478bd9Sstevel@tonic-gate (void) strcat(flbuf, "D"); 37167c478bd9Sstevel@tonic-gate if (!(flags & ACE_F_RESOLVED)) 37177c478bd9Sstevel@tonic-gate (void) strcat(flbuf, "U"); 37187c478bd9Sstevel@tonic-gate if (flags & ACE_F_MAPPING) 37197c478bd9Sstevel@tonic-gate (void) strcat(flbuf, "M"); 372069bb4bb4Scarlsonj if (flags & ACE_F_MYADDR) 372169bb4bb4Scarlsonj (void) strcat(flbuf, "L"); 372269bb4bb4Scarlsonj if (flags & ACE_F_UNVERIFIED) 372369bb4bb4Scarlsonj (void) strcat(flbuf, "d"); 372469bb4bb4Scarlsonj if (flags & ACE_F_AUTHORITY) 372569bb4bb4Scarlsonj (void) strcat(flbuf, "A"); 372669bb4bb4Scarlsonj if (flags & ACE_F_OLD) 372769bb4bb4Scarlsonj (void) strcat(flbuf, "o"); 372869bb4bb4Scarlsonj if (flags & ACE_F_DELAYED) 372969bb4bb4Scarlsonj (void) strcat(flbuf, "y"); 373069bb4bb4Scarlsonj (void) printf("%-6s %-20s %-15s %-8s %s\n", 37317c478bd9Sstevel@tonic-gate octetstr(&np->ipNetToMediaIfIndex, 'a', 37327c478bd9Sstevel@tonic-gate ifname, sizeof (ifname)), 37337c478bd9Sstevel@tonic-gate pr_addr(np->ipNetToMediaNetAddress, 37347c478bd9Sstevel@tonic-gate abuf, sizeof (abuf)), 37357c478bd9Sstevel@tonic-gate octetstr(&np->ipNetToMediaInfo.ntm_mask, 'd', 37367c478bd9Sstevel@tonic-gate maskbuf, sizeof (maskbuf)), 37377c478bd9Sstevel@tonic-gate flbuf, 37387c478bd9Sstevel@tonic-gate octetstr(&np->ipNetToMediaPhysAddress, 'h', 37397c478bd9Sstevel@tonic-gate xbuf, sizeof (xbuf))); 37407c478bd9Sstevel@tonic-gate } /* 'for' loop 2 ends */ 37417c478bd9Sstevel@tonic-gate } /* 'for' loop 1 ends */ 37427c478bd9Sstevel@tonic-gate (void) fflush(stdout); 37437c478bd9Sstevel@tonic-gate } 37447c478bd9Sstevel@tonic-gate 37457c478bd9Sstevel@tonic-gate /* --------------------- NDP_REPORT (netstat -p) -------------------------- */ 37467c478bd9Sstevel@tonic-gate 37477c478bd9Sstevel@tonic-gate static void 37487c478bd9Sstevel@tonic-gate ndp_report(mib_item_t *item) 37497c478bd9Sstevel@tonic-gate { 37507c478bd9Sstevel@tonic-gate int jtemp = 0; 37517c478bd9Sstevel@tonic-gate char abuf[MAXHOSTNAMELEN + 1]; 37527c478bd9Sstevel@tonic-gate char *state; 37537c478bd9Sstevel@tonic-gate char *type; 37547c478bd9Sstevel@tonic-gate char xbuf[STR_EXPAND * OCTET_LENGTH + 1]; 37557c478bd9Sstevel@tonic-gate mib2_ipv6NetToMediaEntry_t *np6; 37567c478bd9Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 37577c478bd9Sstevel@tonic-gate boolean_t first; 37587c478bd9Sstevel@tonic-gate 37597c478bd9Sstevel@tonic-gate if (!(family_selected(AF_INET6))) 37607c478bd9Sstevel@tonic-gate return; 37617c478bd9Sstevel@tonic-gate 37627c478bd9Sstevel@tonic-gate /* 'for' loop 1: */ 37637c478bd9Sstevel@tonic-gate for (; item; item = item->next_item) { 37647c478bd9Sstevel@tonic-gate if (Dflag) { 37657c478bd9Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp); 37667c478bd9Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, " 37677c478bd9Sstevel@tonic-gate "length = %d, valp = 0x%p\n", 37687c478bd9Sstevel@tonic-gate item->group, item->mib_id, item->length, 37697c478bd9Sstevel@tonic-gate item->valp); 37707c478bd9Sstevel@tonic-gate } 37717c478bd9Sstevel@tonic-gate if (!(item->group == MIB2_IP6 && 37727c478bd9Sstevel@tonic-gate item->mib_id == MIB2_IP6_MEDIA)) 37737c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 37747c478bd9Sstevel@tonic-gate 37757c478bd9Sstevel@tonic-gate first = B_TRUE; 37767c478bd9Sstevel@tonic-gate /* 'for' loop 2: */ 37777c478bd9Sstevel@tonic-gate for (np6 = (mib2_ipv6NetToMediaEntry_t *)item->valp; 37787c478bd9Sstevel@tonic-gate (char *)np6 < (char *)item->valp + item->length; 37797c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 37807c478bd9Sstevel@tonic-gate np6 = (mib2_ipv6NetToMediaEntry_t *)((char *)np6 + 37817c478bd9Sstevel@tonic-gate ipv6NetToMediaEntrySize)) { 37827c478bd9Sstevel@tonic-gate if (first) { 37837c478bd9Sstevel@tonic-gate (void) puts("\nNet to Media Table: IPv6"); 37847c478bd9Sstevel@tonic-gate (void) puts(" If Physical Address " 37857c478bd9Sstevel@tonic-gate " Type State Destination/Mask"); 37867c478bd9Sstevel@tonic-gate (void) puts("----- ----------------- " 37877c478bd9Sstevel@tonic-gate "------- ------------ " 37887c478bd9Sstevel@tonic-gate "---------------------------"); 37897c478bd9Sstevel@tonic-gate first = B_FALSE; 37907c478bd9Sstevel@tonic-gate } 37917c478bd9Sstevel@tonic-gate 37927c478bd9Sstevel@tonic-gate switch (np6->ipv6NetToMediaState) { 37937c478bd9Sstevel@tonic-gate case ND_INCOMPLETE: 37947c478bd9Sstevel@tonic-gate state = "INCOMPLETE"; 37957c478bd9Sstevel@tonic-gate break; 37967c478bd9Sstevel@tonic-gate case ND_REACHABLE: 37977c478bd9Sstevel@tonic-gate state = "REACHABLE"; 37987c478bd9Sstevel@tonic-gate break; 37997c478bd9Sstevel@tonic-gate case ND_STALE: 38007c478bd9Sstevel@tonic-gate state = "STALE"; 38017c478bd9Sstevel@tonic-gate break; 38027c478bd9Sstevel@tonic-gate case ND_DELAY: 38037c478bd9Sstevel@tonic-gate state = "DELAY"; 38047c478bd9Sstevel@tonic-gate break; 38057c478bd9Sstevel@tonic-gate case ND_PROBE: 38067c478bd9Sstevel@tonic-gate state = "PROBE"; 38077c478bd9Sstevel@tonic-gate break; 38087c478bd9Sstevel@tonic-gate case ND_UNREACHABLE: 38097c478bd9Sstevel@tonic-gate state = "UNREACHABLE"; 38107c478bd9Sstevel@tonic-gate break; 38117c478bd9Sstevel@tonic-gate default: 38127c478bd9Sstevel@tonic-gate state = "UNKNOWN"; 38137c478bd9Sstevel@tonic-gate } 38147c478bd9Sstevel@tonic-gate 38157c478bd9Sstevel@tonic-gate switch (np6->ipv6NetToMediaType) { 38167c478bd9Sstevel@tonic-gate case 1: 38177c478bd9Sstevel@tonic-gate type = "other"; 38187c478bd9Sstevel@tonic-gate break; 38197c478bd9Sstevel@tonic-gate case 2: 38207c478bd9Sstevel@tonic-gate type = "dynamic"; 38217c478bd9Sstevel@tonic-gate break; 38227c478bd9Sstevel@tonic-gate case 3: 38237c478bd9Sstevel@tonic-gate type = "static"; 38247c478bd9Sstevel@tonic-gate break; 38257c478bd9Sstevel@tonic-gate case 4: 38267c478bd9Sstevel@tonic-gate type = "local"; 38277c478bd9Sstevel@tonic-gate break; 38287c478bd9Sstevel@tonic-gate } 38297c478bd9Sstevel@tonic-gate (void) printf("%-5s %-17s %-7s %-12s %-27s\n", 3830*e11c3f44Smeem ifindex2str(np6->ipv6NetToMediaIfIndex, ifname), 38317c478bd9Sstevel@tonic-gate octetstr(&np6->ipv6NetToMediaPhysAddress, 'h', 38327c478bd9Sstevel@tonic-gate xbuf, sizeof (xbuf)), 38337c478bd9Sstevel@tonic-gate type, 38347c478bd9Sstevel@tonic-gate state, 38357c478bd9Sstevel@tonic-gate pr_addr6(&np6->ipv6NetToMediaNetAddress, 38367c478bd9Sstevel@tonic-gate abuf, sizeof (abuf))); 38377c478bd9Sstevel@tonic-gate } /* 'for' loop 2 ends */ 38387c478bd9Sstevel@tonic-gate } /* 'for' loop 1 ends */ 38397c478bd9Sstevel@tonic-gate (void) putchar('\n'); 38407c478bd9Sstevel@tonic-gate (void) fflush(stdout); 38417c478bd9Sstevel@tonic-gate } 38427c478bd9Sstevel@tonic-gate 38437c478bd9Sstevel@tonic-gate /* ------------------------- ire_report (netstat -r) ------------------------ */ 38447c478bd9Sstevel@tonic-gate 384545916cd2Sjpk typedef struct sec_attr_list_s { 384645916cd2Sjpk struct sec_attr_list_s *sal_next; 384745916cd2Sjpk const mib2_ipAttributeEntry_t *sal_attr; 384845916cd2Sjpk } sec_attr_list_t; 384945916cd2Sjpk 385045916cd2Sjpk static boolean_t ire_report_item_v4(const mib2_ipRouteEntry_t *, boolean_t, 385145916cd2Sjpk const sec_attr_list_t *); 385245916cd2Sjpk static boolean_t ire_report_item_v6(const mib2_ipv6RouteEntry_t *, boolean_t, 385345916cd2Sjpk const sec_attr_list_t *); 385445916cd2Sjpk static const char *pr_secattr(const sec_attr_list_t *); 38557c478bd9Sstevel@tonic-gate 38567c478bd9Sstevel@tonic-gate static void 385745916cd2Sjpk ire_report(const mib_item_t *item) 38587c478bd9Sstevel@tonic-gate { 38597c478bd9Sstevel@tonic-gate int jtemp = 0; 38607c478bd9Sstevel@tonic-gate boolean_t print_hdr_once_v4 = B_TRUE; 38617c478bd9Sstevel@tonic-gate boolean_t print_hdr_once_v6 = B_TRUE; 38627c478bd9Sstevel@tonic-gate mib2_ipRouteEntry_t *rp; 38637c478bd9Sstevel@tonic-gate mib2_ipv6RouteEntry_t *rp6; 386445916cd2Sjpk sec_attr_list_t **v4_attrs, **v4a; 386545916cd2Sjpk sec_attr_list_t **v6_attrs, **v6a; 386645916cd2Sjpk sec_attr_list_t *all_attrs, *aptr; 386745916cd2Sjpk const mib_item_t *iptr; 386845916cd2Sjpk int ipv4_route_count, ipv6_route_count; 386945916cd2Sjpk int route_attrs_count; 387045916cd2Sjpk 387145916cd2Sjpk /* 387245916cd2Sjpk * Preparation pass: the kernel returns separate entries for IP routing 387345916cd2Sjpk * table entries and security attributes. We loop through the 387445916cd2Sjpk * attributes first and link them into lists. 387545916cd2Sjpk */ 387645916cd2Sjpk ipv4_route_count = ipv6_route_count = route_attrs_count = 0; 387745916cd2Sjpk for (iptr = item; iptr != NULL; iptr = iptr->next_item) { 387845916cd2Sjpk if (iptr->group == MIB2_IP6 && iptr->mib_id == MIB2_IP6_ROUTE) 387945916cd2Sjpk ipv6_route_count += iptr->length / ipv6RouteEntrySize; 388045916cd2Sjpk if (iptr->group == MIB2_IP && iptr->mib_id == MIB2_IP_ROUTE) 388145916cd2Sjpk ipv4_route_count += iptr->length / ipRouteEntrySize; 388245916cd2Sjpk if ((iptr->group == MIB2_IP || iptr->group == MIB2_IP6) && 388345916cd2Sjpk iptr->mib_id == EXPER_IP_RTATTR) 388445916cd2Sjpk route_attrs_count += iptr->length / 388545916cd2Sjpk ipRouteAttributeSize; 388645916cd2Sjpk } 388745916cd2Sjpk v4_attrs = v6_attrs = NULL; 388845916cd2Sjpk all_attrs = NULL; 388945916cd2Sjpk if (family_selected(AF_INET) && ipv4_route_count > 0) { 389045916cd2Sjpk v4_attrs = calloc(ipv4_route_count, sizeof (*v4_attrs)); 389145916cd2Sjpk if (v4_attrs == NULL) { 389245916cd2Sjpk perror("ire_report calloc v4_attrs failed"); 389345916cd2Sjpk return; 389445916cd2Sjpk } 389545916cd2Sjpk } 389645916cd2Sjpk if (family_selected(AF_INET6) && ipv6_route_count > 0) { 389745916cd2Sjpk v6_attrs = calloc(ipv6_route_count, sizeof (*v6_attrs)); 389845916cd2Sjpk if (v6_attrs == NULL) { 389945916cd2Sjpk perror("ire_report calloc v6_attrs failed"); 390045916cd2Sjpk goto ire_report_done; 390145916cd2Sjpk } 390245916cd2Sjpk } 390345916cd2Sjpk if (route_attrs_count > 0) { 390445916cd2Sjpk all_attrs = malloc(route_attrs_count * sizeof (*all_attrs)); 390545916cd2Sjpk if (all_attrs == NULL) { 390645916cd2Sjpk perror("ire_report malloc all_attrs failed"); 390745916cd2Sjpk goto ire_report_done; 390845916cd2Sjpk } 390945916cd2Sjpk } 391045916cd2Sjpk aptr = all_attrs; 391145916cd2Sjpk for (iptr = item; iptr != NULL; iptr = iptr->next_item) { 391245916cd2Sjpk mib2_ipAttributeEntry_t *iae; 391345916cd2Sjpk sec_attr_list_t **alp; 391445916cd2Sjpk 391545916cd2Sjpk if (v4_attrs != NULL && iptr->group == MIB2_IP && 391645916cd2Sjpk iptr->mib_id == EXPER_IP_RTATTR) { 391745916cd2Sjpk alp = v4_attrs; 391845916cd2Sjpk } else if (v6_attrs != NULL && iptr->group == MIB2_IP6 && 391945916cd2Sjpk iptr->mib_id == EXPER_IP_RTATTR) { 392045916cd2Sjpk alp = v6_attrs; 392145916cd2Sjpk } else { 392245916cd2Sjpk continue; 392345916cd2Sjpk } 392445916cd2Sjpk for (iae = iptr->valp; 392545916cd2Sjpk (char *)iae < (char *)iptr->valp + iptr->length; 392645916cd2Sjpk /* LINTED: (note 1) */ 392745916cd2Sjpk iae = (mib2_ipAttributeEntry_t *)((char *)iae + 392845916cd2Sjpk ipRouteAttributeSize)) { 392945916cd2Sjpk aptr->sal_next = alp[iae->iae_routeidx]; 393045916cd2Sjpk aptr->sal_attr = iae; 393145916cd2Sjpk alp[iae->iae_routeidx] = aptr++; 393245916cd2Sjpk } 393345916cd2Sjpk } 39347c478bd9Sstevel@tonic-gate 39357c478bd9Sstevel@tonic-gate /* 'for' loop 1: */ 393645916cd2Sjpk v4a = v4_attrs; 393745916cd2Sjpk v6a = v6_attrs; 393845916cd2Sjpk for (; item != NULL; item = item->next_item) { 39397c478bd9Sstevel@tonic-gate if (Dflag) { 39407c478bd9Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp); 39417c478bd9Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, " 39427c478bd9Sstevel@tonic-gate "length = %d, valp = 0x%p\n", 39437c478bd9Sstevel@tonic-gate item->group, item->mib_id, 39447c478bd9Sstevel@tonic-gate item->length, item->valp); 39457c478bd9Sstevel@tonic-gate } 39467c478bd9Sstevel@tonic-gate if (!((item->group == MIB2_IP && 39477c478bd9Sstevel@tonic-gate item->mib_id == MIB2_IP_ROUTE) || 39487c478bd9Sstevel@tonic-gate (item->group == MIB2_IP6 && 39497c478bd9Sstevel@tonic-gate item->mib_id == MIB2_IP6_ROUTE))) 39507c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 39517c478bd9Sstevel@tonic-gate 39527c478bd9Sstevel@tonic-gate if (item->group == MIB2_IP && !family_selected(AF_INET)) 39537c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 39547c478bd9Sstevel@tonic-gate else if (item->group == MIB2_IP6 && !family_selected(AF_INET6)) 39557c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 39567c478bd9Sstevel@tonic-gate 39577c478bd9Sstevel@tonic-gate if (Dflag) { 39587c478bd9Sstevel@tonic-gate if (item->group == MIB2_IP) { 39597c478bd9Sstevel@tonic-gate (void) printf("%u records for " 39607c478bd9Sstevel@tonic-gate "ipRouteEntryTable:\n", 39617c478bd9Sstevel@tonic-gate item->length/sizeof (mib2_ipRouteEntry_t)); 39627c478bd9Sstevel@tonic-gate } else { 39637c478bd9Sstevel@tonic-gate (void) printf("%u records for " 39647c478bd9Sstevel@tonic-gate "ipv6RouteEntryTable:\n", 39657c478bd9Sstevel@tonic-gate item->length/ 39667c478bd9Sstevel@tonic-gate sizeof (mib2_ipv6RouteEntry_t)); 39677c478bd9Sstevel@tonic-gate } 39687c478bd9Sstevel@tonic-gate } 39697c478bd9Sstevel@tonic-gate 39707c478bd9Sstevel@tonic-gate if (item->group == MIB2_IP) { 39717c478bd9Sstevel@tonic-gate for (rp = (mib2_ipRouteEntry_t *)item->valp; 39727c478bd9Sstevel@tonic-gate (char *)rp < (char *)item->valp + item->length; 39737c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 39747c478bd9Sstevel@tonic-gate rp = (mib2_ipRouteEntry_t *)((char *)rp + 39757c478bd9Sstevel@tonic-gate ipRouteEntrySize)) { 397645916cd2Sjpk aptr = v4a == NULL ? NULL : *v4a++; 39777c478bd9Sstevel@tonic-gate print_hdr_once_v4 = ire_report_item_v4(rp, 397845916cd2Sjpk print_hdr_once_v4, aptr); 39797c478bd9Sstevel@tonic-gate } 39807c478bd9Sstevel@tonic-gate } else { 39817c478bd9Sstevel@tonic-gate for (rp6 = (mib2_ipv6RouteEntry_t *)item->valp; 39827c478bd9Sstevel@tonic-gate (char *)rp6 < (char *)item->valp + item->length; 39837c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 39847c478bd9Sstevel@tonic-gate rp6 = (mib2_ipv6RouteEntry_t *)((char *)rp6 + 39857c478bd9Sstevel@tonic-gate ipv6RouteEntrySize)) { 398645916cd2Sjpk aptr = v6a == NULL ? NULL : *v6a++; 39877c478bd9Sstevel@tonic-gate print_hdr_once_v6 = ire_report_item_v6(rp6, 398845916cd2Sjpk print_hdr_once_v6, aptr); 39897c478bd9Sstevel@tonic-gate } 39907c478bd9Sstevel@tonic-gate } 39917c478bd9Sstevel@tonic-gate } /* 'for' loop 1 ends */ 39927c478bd9Sstevel@tonic-gate (void) fflush(stdout); 399345916cd2Sjpk ire_report_done: 399445916cd2Sjpk if (v4_attrs != NULL) 399545916cd2Sjpk free(v4_attrs); 399645916cd2Sjpk if (v6_attrs != NULL) 399745916cd2Sjpk free(v6_attrs); 399845916cd2Sjpk if (all_attrs != NULL) 399945916cd2Sjpk free(all_attrs); 40007c478bd9Sstevel@tonic-gate } 40017c478bd9Sstevel@tonic-gate 40027c478bd9Sstevel@tonic-gate /* 40037c478bd9Sstevel@tonic-gate * Match a user-supplied device name. We do this by string because 40047c478bd9Sstevel@tonic-gate * the MIB2 interface gives us interface name strings rather than 40057c478bd9Sstevel@tonic-gate * ifIndex numbers. The "none" rule matches only routes with no 40067c478bd9Sstevel@tonic-gate * interface. The "any" rule matches routes with any non-blank 40077c478bd9Sstevel@tonic-gate * interface. A base name ("hme0") matches all aliases as well 40087c478bd9Sstevel@tonic-gate * ("hme0:1"). 40097c478bd9Sstevel@tonic-gate */ 40107c478bd9Sstevel@tonic-gate static boolean_t 40117c478bd9Sstevel@tonic-gate dev_name_match(const DeviceName *devnam, const char *ifname) 40127c478bd9Sstevel@tonic-gate { 40137c478bd9Sstevel@tonic-gate int iflen; 40147c478bd9Sstevel@tonic-gate 40157c478bd9Sstevel@tonic-gate if (ifname == NULL) 40167c478bd9Sstevel@tonic-gate return (devnam->o_length == 0); /* "none" */ 40177c478bd9Sstevel@tonic-gate if (*ifname == '\0') 40187c478bd9Sstevel@tonic-gate return (devnam->o_length != 0); /* "any" */ 40197c478bd9Sstevel@tonic-gate iflen = strlen(ifname); 40207c478bd9Sstevel@tonic-gate /* The check for ':' here supports interface aliases. */ 40217c478bd9Sstevel@tonic-gate if (iflen > devnam->o_length || 40227c478bd9Sstevel@tonic-gate (iflen < devnam->o_length && devnam->o_bytes[iflen] != ':')) 40237c478bd9Sstevel@tonic-gate return (B_FALSE); 40247c478bd9Sstevel@tonic-gate return (strncmp(ifname, devnam->o_bytes, iflen) == 0); 40257c478bd9Sstevel@tonic-gate } 40267c478bd9Sstevel@tonic-gate 40277c478bd9Sstevel@tonic-gate /* 40287c478bd9Sstevel@tonic-gate * Match a user-supplied IP address list. The "any" rule matches any 40297c478bd9Sstevel@tonic-gate * non-zero address. The "none" rule matches only the zero address. 40307c478bd9Sstevel@tonic-gate * IPv6 addresses supplied by the user are ignored. If the user 40317c478bd9Sstevel@tonic-gate * supplies a subnet mask, then match routes that are at least that 40327c478bd9Sstevel@tonic-gate * specific (use the user's mask). If the user supplies only an 40337c478bd9Sstevel@tonic-gate * address, then select any routes that would match (use the route's 40347c478bd9Sstevel@tonic-gate * mask). 40357c478bd9Sstevel@tonic-gate */ 40367c478bd9Sstevel@tonic-gate static boolean_t 40377c478bd9Sstevel@tonic-gate v4_addr_match(IpAddress addr, IpAddress mask, const filter_t *fp) 40387c478bd9Sstevel@tonic-gate { 40397c478bd9Sstevel@tonic-gate char **app; 40407c478bd9Sstevel@tonic-gate char *aptr; 40417c478bd9Sstevel@tonic-gate in_addr_t faddr, fmask; 40427c478bd9Sstevel@tonic-gate 40437c478bd9Sstevel@tonic-gate if (fp->u.a.f_address == NULL) { 40447c478bd9Sstevel@tonic-gate if (IN6_IS_ADDR_UNSPECIFIED(&fp->u.a.f_mask)) 40457c478bd9Sstevel@tonic-gate return (addr != INADDR_ANY); /* "any" */ 40467c478bd9Sstevel@tonic-gate else 40477c478bd9Sstevel@tonic-gate return (addr == INADDR_ANY); /* "none" */ 40487c478bd9Sstevel@tonic-gate } 40497c478bd9Sstevel@tonic-gate if (!IN6_IS_V4MASK(fp->u.a.f_mask)) 40507c478bd9Sstevel@tonic-gate return (B_FALSE); 40517c478bd9Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&fp->u.a.f_mask, fmask); 40527c478bd9Sstevel@tonic-gate if (fmask != IP_HOST_MASK) { 40537c478bd9Sstevel@tonic-gate if (fmask > mask) 40547c478bd9Sstevel@tonic-gate return (B_FALSE); 40557c478bd9Sstevel@tonic-gate mask = fmask; 40567c478bd9Sstevel@tonic-gate } 40577c478bd9Sstevel@tonic-gate for (app = fp->u.a.f_address->h_addr_list; (aptr = *app) != NULL; app++) 40587c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 40597c478bd9Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED((in6_addr_t *)aptr)) { 40607c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 40617c478bd9Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR((in6_addr_t *)aptr, faddr); 40627c478bd9Sstevel@tonic-gate if (((faddr ^ addr) & mask) == 0) 40637c478bd9Sstevel@tonic-gate return (B_TRUE); 40647c478bd9Sstevel@tonic-gate } 40657c478bd9Sstevel@tonic-gate return (B_FALSE); 40667c478bd9Sstevel@tonic-gate } 40677c478bd9Sstevel@tonic-gate 40687c478bd9Sstevel@tonic-gate /* 40697c478bd9Sstevel@tonic-gate * Run through the filter list for an IPv4 MIB2 route entry. If all 40707c478bd9Sstevel@tonic-gate * filters of a given type fail to match, then the route is filtered 40717c478bd9Sstevel@tonic-gate * out (not displayed). If no filter is given or at least one filter 40727c478bd9Sstevel@tonic-gate * of each type matches, then display the route. 40737c478bd9Sstevel@tonic-gate */ 40747c478bd9Sstevel@tonic-gate static boolean_t 407545916cd2Sjpk ire_filter_match_v4(const mib2_ipRouteEntry_t *rp, uint_t flag_b) 40767c478bd9Sstevel@tonic-gate { 40777c478bd9Sstevel@tonic-gate filter_t *fp; 40787c478bd9Sstevel@tonic-gate int idx; 40797c478bd9Sstevel@tonic-gate 40807c478bd9Sstevel@tonic-gate /* 'for' loop 1: */ 40817c478bd9Sstevel@tonic-gate for (idx = 0; idx < NFILTERKEYS; idx++) 40827c478bd9Sstevel@tonic-gate if ((fp = filters[idx]) != NULL) { 40837c478bd9Sstevel@tonic-gate /* 'for' loop 2: */ 40847c478bd9Sstevel@tonic-gate for (; fp != NULL; fp = fp->f_next) { 40857c478bd9Sstevel@tonic-gate switch (idx) { 40867c478bd9Sstevel@tonic-gate case FK_AF: 40877c478bd9Sstevel@tonic-gate if (fp->u.f_family != AF_INET) 40887c478bd9Sstevel@tonic-gate continue; /* 'for' loop 2 */ 40897c478bd9Sstevel@tonic-gate break; 40907c478bd9Sstevel@tonic-gate case FK_OUTIF: 40917c478bd9Sstevel@tonic-gate if (!dev_name_match(&rp->ipRouteIfIndex, 40927c478bd9Sstevel@tonic-gate fp->u.f_ifname)) 40937c478bd9Sstevel@tonic-gate continue; /* 'for' loop 2 */ 40947c478bd9Sstevel@tonic-gate break; 40957c478bd9Sstevel@tonic-gate case FK_DST: 40967c478bd9Sstevel@tonic-gate if (!v4_addr_match(rp->ipRouteDest, 40977c478bd9Sstevel@tonic-gate rp->ipRouteMask, fp)) 40987c478bd9Sstevel@tonic-gate continue; /* 'for' loop 2 */ 40997c478bd9Sstevel@tonic-gate break; 41007c478bd9Sstevel@tonic-gate case FK_FLAGS: 41017c478bd9Sstevel@tonic-gate if ((flag_b & fp->u.f.f_flagset) != 41027c478bd9Sstevel@tonic-gate fp->u.f.f_flagset || 41037c478bd9Sstevel@tonic-gate (flag_b & fp->u.f.f_flagclear)) 41047c478bd9Sstevel@tonic-gate continue; /* 'for' loop 2 */ 41057c478bd9Sstevel@tonic-gate break; 41067c478bd9Sstevel@tonic-gate } 41077c478bd9Sstevel@tonic-gate break; 41087c478bd9Sstevel@tonic-gate } /* 'for' loop 2 ends */ 41097c478bd9Sstevel@tonic-gate if (fp == NULL) 41107c478bd9Sstevel@tonic-gate return (B_FALSE); 41117c478bd9Sstevel@tonic-gate } 41127c478bd9Sstevel@tonic-gate /* 'for' loop 1 ends */ 41137c478bd9Sstevel@tonic-gate return (B_TRUE); 41147c478bd9Sstevel@tonic-gate } 41157c478bd9Sstevel@tonic-gate 41167c478bd9Sstevel@tonic-gate /* 41177c478bd9Sstevel@tonic-gate * Given an IPv4 MIB2 route entry, form the list of flags for the 41187c478bd9Sstevel@tonic-gate * route. 41197c478bd9Sstevel@tonic-gate */ 41207c478bd9Sstevel@tonic-gate static uint_t 412145916cd2Sjpk form_v4_route_flags(const mib2_ipRouteEntry_t *rp, char *flags) 41227c478bd9Sstevel@tonic-gate { 41237c478bd9Sstevel@tonic-gate uint_t flag_b; 41247c478bd9Sstevel@tonic-gate 41257c478bd9Sstevel@tonic-gate flag_b = FLF_U; 41267c478bd9Sstevel@tonic-gate (void) strcpy(flags, "U"); 41277c478bd9Sstevel@tonic-gate if (rp->ipRouteInfo.re_ire_type == IRE_DEFAULT || 41287c478bd9Sstevel@tonic-gate rp->ipRouteInfo.re_ire_type == IRE_PREFIX || 41297c478bd9Sstevel@tonic-gate rp->ipRouteInfo.re_ire_type == IRE_HOST || 41307c478bd9Sstevel@tonic-gate rp->ipRouteInfo.re_ire_type == IRE_HOST_REDIRECT) { 41317c478bd9Sstevel@tonic-gate (void) strcat(flags, "G"); 41327c478bd9Sstevel@tonic-gate flag_b |= FLF_G; 41337c478bd9Sstevel@tonic-gate } 41347c478bd9Sstevel@tonic-gate if (rp->ipRouteMask == IP_HOST_MASK) { 41357c478bd9Sstevel@tonic-gate (void) strcat(flags, "H"); 41367c478bd9Sstevel@tonic-gate flag_b |= FLF_H; 41377c478bd9Sstevel@tonic-gate } 41387c478bd9Sstevel@tonic-gate if (rp->ipRouteInfo.re_ire_type == IRE_HOST_REDIRECT) { 41397c478bd9Sstevel@tonic-gate (void) strcat(flags, "D"); 41407c478bd9Sstevel@tonic-gate flag_b |= FLF_D; 41417c478bd9Sstevel@tonic-gate } 41427c478bd9Sstevel@tonic-gate if (rp->ipRouteInfo.re_ire_type == IRE_CACHE) { 41437c478bd9Sstevel@tonic-gate /* Address resolution */ 41447c478bd9Sstevel@tonic-gate (void) strcat(flags, "A"); 41457c478bd9Sstevel@tonic-gate flag_b |= FLF_A; 41467c478bd9Sstevel@tonic-gate } 41477c478bd9Sstevel@tonic-gate if (rp->ipRouteInfo.re_ire_type == IRE_BROADCAST) { /* Broadcast */ 41487c478bd9Sstevel@tonic-gate (void) strcat(flags, "B"); 41497c478bd9Sstevel@tonic-gate flag_b |= FLF_B; 41507c478bd9Sstevel@tonic-gate } 41517c478bd9Sstevel@tonic-gate if (rp->ipRouteInfo.re_ire_type == IRE_LOCAL) { /* Local */ 41527c478bd9Sstevel@tonic-gate (void) strcat(flags, "L"); 41537c478bd9Sstevel@tonic-gate flag_b |= FLF_L; 41547c478bd9Sstevel@tonic-gate } 41557c478bd9Sstevel@tonic-gate if (rp->ipRouteInfo.re_flags & RTF_MULTIRT) { 41567c478bd9Sstevel@tonic-gate (void) strcat(flags, "M"); /* Multiroute */ 41577c478bd9Sstevel@tonic-gate flag_b |= FLF_M; 41587c478bd9Sstevel@tonic-gate } 41597c478bd9Sstevel@tonic-gate if (rp->ipRouteInfo.re_flags & RTF_SETSRC) { 41607c478bd9Sstevel@tonic-gate (void) strcat(flags, "S"); /* Setsrc */ 41617c478bd9Sstevel@tonic-gate flag_b |= FLF_S; 41627c478bd9Sstevel@tonic-gate } 41637c478bd9Sstevel@tonic-gate return (flag_b); 41647c478bd9Sstevel@tonic-gate } 41657c478bd9Sstevel@tonic-gate 416645916cd2Sjpk static const char ire_hdr_v4[] = 416745916cd2Sjpk "\n%s Table: IPv4\n"; 416845916cd2Sjpk static const char ire_hdr_v4_compat[] = 416945916cd2Sjpk "\n%s Table:\n"; 417045916cd2Sjpk static const char ire_hdr_v4_verbose[] = 417145916cd2Sjpk " Destination Mask Gateway Device Mxfrg " 417245916cd2Sjpk "Rtt Ref Flg Out In/Fwd %s\n" 417345916cd2Sjpk "-------------------- --------------- -------------------- ------ ----- " 417445916cd2Sjpk "----- --- --- ----- ------ %s\n"; 417545916cd2Sjpk 417645916cd2Sjpk static const char ire_hdr_v4_normal[] = 4177aecc8c24Sja " Destination Gateway Flags Ref Use Interface" 4178aecc8c24Sja " %s\n-------------------- -------------------- ----- ----- ---------- " 4179aecc8c24Sja "--------- %s\n"; 418045916cd2Sjpk 41817c478bd9Sstevel@tonic-gate static boolean_t 418245916cd2Sjpk ire_report_item_v4(const mib2_ipRouteEntry_t *rp, boolean_t first, 418345916cd2Sjpk const sec_attr_list_t *attrs) 41847c478bd9Sstevel@tonic-gate { 41857c478bd9Sstevel@tonic-gate char dstbuf[MAXHOSTNAMELEN + 1]; 41867c478bd9Sstevel@tonic-gate char maskbuf[MAXHOSTNAMELEN + 1]; 41877c478bd9Sstevel@tonic-gate char gwbuf[MAXHOSTNAMELEN + 1]; 41887c478bd9Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 41897c478bd9Sstevel@tonic-gate char flags[10]; /* RTF_ flags */ 41907c478bd9Sstevel@tonic-gate uint_t flag_b; 41917c478bd9Sstevel@tonic-gate 41925c0b7edeSseb if (!(Aflag || (rp->ipRouteInfo.re_ire_type != IRE_CACHE && 41937c478bd9Sstevel@tonic-gate rp->ipRouteInfo.re_ire_type != IRE_BROADCAST && 41947c478bd9Sstevel@tonic-gate rp->ipRouteInfo.re_ire_type != IRE_LOCAL))) { 41957c478bd9Sstevel@tonic-gate return (first); 41967c478bd9Sstevel@tonic-gate } 41977c478bd9Sstevel@tonic-gate 41987c478bd9Sstevel@tonic-gate flag_b = form_v4_route_flags(rp, flags); 41997c478bd9Sstevel@tonic-gate 42007c478bd9Sstevel@tonic-gate if (!ire_filter_match_v4(rp, flag_b)) 42017c478bd9Sstevel@tonic-gate return (first); 42027c478bd9Sstevel@tonic-gate 42037c478bd9Sstevel@tonic-gate if (first) { 420445916cd2Sjpk (void) printf(v4compat ? ire_hdr_v4_compat : ire_hdr_v4, 420545916cd2Sjpk Vflag ? "IRE" : "Routing"); 420645916cd2Sjpk (void) printf(Vflag ? ire_hdr_v4_verbose : ire_hdr_v4_normal, 420745916cd2Sjpk RSECflag ? " Gateway security attributes " : "", 420845916cd2Sjpk RSECflag ? "-------------------------------" : ""); 42097c478bd9Sstevel@tonic-gate first = B_FALSE; 42107c478bd9Sstevel@tonic-gate } 42117c478bd9Sstevel@tonic-gate 42127c478bd9Sstevel@tonic-gate if (flag_b & FLF_H) { 42137c478bd9Sstevel@tonic-gate (void) pr_addr(rp->ipRouteDest, dstbuf, sizeof (dstbuf)); 42147c478bd9Sstevel@tonic-gate } else { 42157c478bd9Sstevel@tonic-gate (void) pr_net(rp->ipRouteDest, rp->ipRouteMask, 42167c478bd9Sstevel@tonic-gate dstbuf, sizeof (dstbuf)); 42177c478bd9Sstevel@tonic-gate } 42187c478bd9Sstevel@tonic-gate if (Vflag) { 42197c478bd9Sstevel@tonic-gate (void) printf("%-20s %-15s %-20s %-6s %5u%c %4u %3u " 4220aecc8c24Sja "%-4s%6u %6u %s\n", 42217c478bd9Sstevel@tonic-gate dstbuf, 42227c478bd9Sstevel@tonic-gate pr_mask(rp->ipRouteMask, maskbuf, sizeof (maskbuf)), 42237c478bd9Sstevel@tonic-gate pr_addrnz(rp->ipRouteNextHop, gwbuf, sizeof (gwbuf)), 42247c478bd9Sstevel@tonic-gate octetstr(&rp->ipRouteIfIndex, 'a', ifname, sizeof (ifname)), 42257c478bd9Sstevel@tonic-gate rp->ipRouteInfo.re_max_frag, 42267c478bd9Sstevel@tonic-gate rp->ipRouteInfo.re_frag_flag ? '*' : ' ', 42277c478bd9Sstevel@tonic-gate rp->ipRouteInfo.re_rtt, 42287c478bd9Sstevel@tonic-gate rp->ipRouteInfo.re_ref, 42297c478bd9Sstevel@tonic-gate flags, 42307c478bd9Sstevel@tonic-gate rp->ipRouteInfo.re_obpkt, 423145916cd2Sjpk rp->ipRouteInfo.re_ibpkt, 423245916cd2Sjpk pr_secattr(attrs)); 42337c478bd9Sstevel@tonic-gate } else { 4234aecc8c24Sja (void) printf("%-20s %-20s %-5s %4u %10u %-9s %s\n", 42357c478bd9Sstevel@tonic-gate dstbuf, 42367c478bd9Sstevel@tonic-gate pr_addrnz(rp->ipRouteNextHop, gwbuf, sizeof (gwbuf)), 42377c478bd9Sstevel@tonic-gate flags, 42387c478bd9Sstevel@tonic-gate rp->ipRouteInfo.re_ref, 42397c478bd9Sstevel@tonic-gate rp->ipRouteInfo.re_obpkt + rp->ipRouteInfo.re_ibpkt, 42407c478bd9Sstevel@tonic-gate octetstr(&rp->ipRouteIfIndex, 'a', 424145916cd2Sjpk ifname, sizeof (ifname)), 424245916cd2Sjpk pr_secattr(attrs)); 42437c478bd9Sstevel@tonic-gate } 42447c478bd9Sstevel@tonic-gate return (first); 42457c478bd9Sstevel@tonic-gate } 42467c478bd9Sstevel@tonic-gate 42477c478bd9Sstevel@tonic-gate /* 42487c478bd9Sstevel@tonic-gate * Match a user-supplied IP address list against an IPv6 route entry. 42497c478bd9Sstevel@tonic-gate * If the user specified "any," then any non-zero address matches. If 42507c478bd9Sstevel@tonic-gate * the user specified "none," then only the zero address matches. If 42517c478bd9Sstevel@tonic-gate * the user specified a subnet mask length, then use that in matching 42527c478bd9Sstevel@tonic-gate * routes (select routes that are at least as specific). If the user 42537c478bd9Sstevel@tonic-gate * specified only an address, then use the route's mask (select routes 42547c478bd9Sstevel@tonic-gate * that would match that address). IPv4 addresses are ignored. 42557c478bd9Sstevel@tonic-gate */ 42567c478bd9Sstevel@tonic-gate static boolean_t 42577c478bd9Sstevel@tonic-gate v6_addr_match(const Ip6Address *addr, int masklen, const filter_t *fp) 42587c478bd9Sstevel@tonic-gate { 42597c478bd9Sstevel@tonic-gate const uint8_t *ucp; 42607c478bd9Sstevel@tonic-gate int fmasklen; 42617c478bd9Sstevel@tonic-gate int i; 42627c478bd9Sstevel@tonic-gate char **app; 42637c478bd9Sstevel@tonic-gate char *aptr; 42647c478bd9Sstevel@tonic-gate 42657c478bd9Sstevel@tonic-gate if (fp->u.a.f_address == NULL) { 42667c478bd9Sstevel@tonic-gate if (IN6_IS_ADDR_UNSPECIFIED(&fp->u.a.f_mask)) /* any */ 42677c478bd9Sstevel@tonic-gate return (!IN6_IS_ADDR_UNSPECIFIED(addr)); 42687c478bd9Sstevel@tonic-gate return (IN6_IS_ADDR_UNSPECIFIED(addr)); /* "none" */ 42697c478bd9Sstevel@tonic-gate } 42707c478bd9Sstevel@tonic-gate fmasklen = 0; 42717c478bd9Sstevel@tonic-gate /* 'for' loop 1a: */ 42727c478bd9Sstevel@tonic-gate for (ucp = fp->u.a.f_mask.s6_addr; 42737c478bd9Sstevel@tonic-gate ucp < fp->u.a.f_mask.s6_addr + sizeof (fp->u.a.f_mask.s6_addr); 42747c478bd9Sstevel@tonic-gate ucp++) { 42757c478bd9Sstevel@tonic-gate if (*ucp != 0xff) { 42767c478bd9Sstevel@tonic-gate if (*ucp != 0) 42777c478bd9Sstevel@tonic-gate fmasklen += 9 - ffs(*ucp); 42787c478bd9Sstevel@tonic-gate break; /* 'for' loop 1a */ 42797c478bd9Sstevel@tonic-gate } 42807c478bd9Sstevel@tonic-gate fmasklen += 8; 42817c478bd9Sstevel@tonic-gate } /* 'for' loop 1a ends */ 42827c478bd9Sstevel@tonic-gate if (fmasklen != IPV6_ABITS) { 42837c478bd9Sstevel@tonic-gate if (fmasklen > masklen) 42847c478bd9Sstevel@tonic-gate return (B_FALSE); 42857c478bd9Sstevel@tonic-gate masklen = fmasklen; 42867c478bd9Sstevel@tonic-gate } 42877c478bd9Sstevel@tonic-gate /* 'for' loop 1b: */ 42887c478bd9Sstevel@tonic-gate for (app = fp->u.a.f_address->h_addr_list; (aptr = *app) != NULL; 42897c478bd9Sstevel@tonic-gate app++) { 42907c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 42917c478bd9Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED((in6_addr_t *)aptr)) 42927c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1b */ 42937c478bd9Sstevel@tonic-gate ucp = addr->s6_addr; 42947c478bd9Sstevel@tonic-gate for (i = masklen; i >= 8; i -= 8) 42957c478bd9Sstevel@tonic-gate if (*ucp++ != *aptr++) 42967c478bd9Sstevel@tonic-gate break; /* 'for' loop 1b */ 42977c478bd9Sstevel@tonic-gate if (i == 0 || 42987c478bd9Sstevel@tonic-gate (i < 8 && ((*ucp ^ *aptr) & ~(0xff >> i)) == 0)) 42997c478bd9Sstevel@tonic-gate return (B_TRUE); 43007c478bd9Sstevel@tonic-gate } /* 'for' loop 1b ends */ 43017c478bd9Sstevel@tonic-gate return (B_FALSE); 43027c478bd9Sstevel@tonic-gate } 43037c478bd9Sstevel@tonic-gate 43047c478bd9Sstevel@tonic-gate /* 43057c478bd9Sstevel@tonic-gate * Run through the filter list for an IPv6 MIB2 IRE. For a given 43067c478bd9Sstevel@tonic-gate * type, if there's at least one filter and all filters of that type 43077c478bd9Sstevel@tonic-gate * fail to match, then the route doesn't match and isn't displayed. 43087c478bd9Sstevel@tonic-gate * If at least one matches, or none are specified, for each of the 43097c478bd9Sstevel@tonic-gate * types, then the route is selected and displayed. 43107c478bd9Sstevel@tonic-gate */ 43117c478bd9Sstevel@tonic-gate static boolean_t 431245916cd2Sjpk ire_filter_match_v6(const mib2_ipv6RouteEntry_t *rp6, uint_t flag_b) 43137c478bd9Sstevel@tonic-gate { 43147c478bd9Sstevel@tonic-gate filter_t *fp; 43157c478bd9Sstevel@tonic-gate int idx; 43167c478bd9Sstevel@tonic-gate 43177c478bd9Sstevel@tonic-gate /* 'for' loop 1: */ 43187c478bd9Sstevel@tonic-gate for (idx = 0; idx < NFILTERKEYS; idx++) 43197c478bd9Sstevel@tonic-gate if ((fp = filters[idx]) != NULL) { 43207c478bd9Sstevel@tonic-gate /* 'for' loop 2: */ 43217c478bd9Sstevel@tonic-gate for (; fp != NULL; fp = fp->f_next) { 43227c478bd9Sstevel@tonic-gate switch (idx) { 43237c478bd9Sstevel@tonic-gate case FK_AF: 43247c478bd9Sstevel@tonic-gate if (fp->u.f_family != AF_INET6) 43257c478bd9Sstevel@tonic-gate /* 'for' loop 2 */ 43267c478bd9Sstevel@tonic-gate continue; 43277c478bd9Sstevel@tonic-gate break; 43287c478bd9Sstevel@tonic-gate case FK_OUTIF: 43297c478bd9Sstevel@tonic-gate if (!dev_name_match(&rp6-> 43307c478bd9Sstevel@tonic-gate ipv6RouteIfIndex, fp->u.f_ifname)) 43317c478bd9Sstevel@tonic-gate /* 'for' loop 2 */ 43327c478bd9Sstevel@tonic-gate continue; 43337c478bd9Sstevel@tonic-gate break; 43347c478bd9Sstevel@tonic-gate case FK_DST: 43357c478bd9Sstevel@tonic-gate if (!v6_addr_match(&rp6->ipv6RouteDest, 43367c478bd9Sstevel@tonic-gate rp6->ipv6RoutePfxLength, fp)) 43377c478bd9Sstevel@tonic-gate /* 'for' loop 2 */ 43387c478bd9Sstevel@tonic-gate continue; 43397c478bd9Sstevel@tonic-gate break; 43407c478bd9Sstevel@tonic-gate case FK_FLAGS: 43417c478bd9Sstevel@tonic-gate if ((flag_b & fp->u.f.f_flagset) != 43427c478bd9Sstevel@tonic-gate fp->u.f.f_flagset || 43437c478bd9Sstevel@tonic-gate (flag_b & fp->u.f.f_flagclear)) 43447c478bd9Sstevel@tonic-gate /* 'for' loop 2 */ 43457c478bd9Sstevel@tonic-gate continue; 43467c478bd9Sstevel@tonic-gate break; 43477c478bd9Sstevel@tonic-gate } 43487c478bd9Sstevel@tonic-gate break; 43497c478bd9Sstevel@tonic-gate } /* 'for' loop 2 ends */ 43507c478bd9Sstevel@tonic-gate if (fp == NULL) 43517c478bd9Sstevel@tonic-gate return (B_FALSE); 43527c478bd9Sstevel@tonic-gate } 43537c478bd9Sstevel@tonic-gate /* 'for' loop 1 ends */ 43547c478bd9Sstevel@tonic-gate return (B_TRUE); 43557c478bd9Sstevel@tonic-gate } 43567c478bd9Sstevel@tonic-gate 435745916cd2Sjpk static const char ire_hdr_v6[] = 435845916cd2Sjpk "\n%s Table: IPv6\n"; 435945916cd2Sjpk static const char ire_hdr_v6_verbose[] = 436045916cd2Sjpk " Destination/Mask Gateway If PMTU Rtt " 436145916cd2Sjpk "Ref Flags Out In/Fwd %s\n" 436245916cd2Sjpk "--------------------------- --------------------------- ----- ------ ----- " 436345916cd2Sjpk "--- ----- ------ ------ %s\n"; 436445916cd2Sjpk static const char ire_hdr_v6_normal[] = 436545916cd2Sjpk " Destination/Mask Gateway Flags Ref Use " 4366aecc8c24Sja " If %s\n" 4367aecc8c24Sja "--------------------------- --------------------------- ----- --- ------- " 436845916cd2Sjpk "----- %s\n"; 436945916cd2Sjpk 43707c478bd9Sstevel@tonic-gate static boolean_t 437145916cd2Sjpk ire_report_item_v6(const mib2_ipv6RouteEntry_t *rp6, boolean_t first, 437245916cd2Sjpk const sec_attr_list_t *attrs) 43737c478bd9Sstevel@tonic-gate { 43747c478bd9Sstevel@tonic-gate char dstbuf[MAXHOSTNAMELEN + 1]; 43757c478bd9Sstevel@tonic-gate char gwbuf[MAXHOSTNAMELEN + 1]; 43767c478bd9Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 43777c478bd9Sstevel@tonic-gate char flags[10]; /* RTF_ flags */ 43787c478bd9Sstevel@tonic-gate uint_t flag_b; 43797c478bd9Sstevel@tonic-gate 43807c478bd9Sstevel@tonic-gate if (!(Aflag || (rp6->ipv6RouteInfo.re_ire_type != IRE_CACHE && 43817c478bd9Sstevel@tonic-gate rp6->ipv6RouteInfo.re_ire_type != IRE_LOCAL))) { 43827c478bd9Sstevel@tonic-gate return (first); 43837c478bd9Sstevel@tonic-gate } 43847c478bd9Sstevel@tonic-gate 43857c478bd9Sstevel@tonic-gate flag_b = FLF_U; 43867c478bd9Sstevel@tonic-gate (void) strcpy(flags, "U"); 43877c478bd9Sstevel@tonic-gate if (rp6->ipv6RouteInfo.re_ire_type == IRE_DEFAULT || 43887c478bd9Sstevel@tonic-gate rp6->ipv6RouteInfo.re_ire_type == IRE_PREFIX || 43897c478bd9Sstevel@tonic-gate rp6->ipv6RouteInfo.re_ire_type == IRE_HOST || 43907c478bd9Sstevel@tonic-gate rp6->ipv6RouteInfo.re_ire_type == IRE_HOST_REDIRECT) { 43917c478bd9Sstevel@tonic-gate (void) strcat(flags, "G"); 43927c478bd9Sstevel@tonic-gate flag_b |= FLF_G; 43937c478bd9Sstevel@tonic-gate } 43947c478bd9Sstevel@tonic-gate 43957c478bd9Sstevel@tonic-gate if (rp6->ipv6RoutePfxLength == IPV6_ABITS) { 43967c478bd9Sstevel@tonic-gate (void) strcat(flags, "H"); 43977c478bd9Sstevel@tonic-gate flag_b |= FLF_H; 43987c478bd9Sstevel@tonic-gate } 43997c478bd9Sstevel@tonic-gate 44007c478bd9Sstevel@tonic-gate if (rp6->ipv6RouteInfo.re_ire_type == IRE_HOST_REDIRECT) { 44017c478bd9Sstevel@tonic-gate (void) strcat(flags, "D"); 44027c478bd9Sstevel@tonic-gate flag_b |= FLF_D; 44037c478bd9Sstevel@tonic-gate } 44047c478bd9Sstevel@tonic-gate if (rp6->ipv6RouteInfo.re_ire_type == IRE_CACHE) { 44057c478bd9Sstevel@tonic-gate /* Address resolution */ 44067c478bd9Sstevel@tonic-gate (void) strcat(flags, "A"); 44077c478bd9Sstevel@tonic-gate flag_b |= FLF_A; 44087c478bd9Sstevel@tonic-gate } 44097c478bd9Sstevel@tonic-gate if (rp6->ipv6RouteInfo.re_ire_type == IRE_LOCAL) { /* Local */ 44107c478bd9Sstevel@tonic-gate (void) strcat(flags, "L"); 44117c478bd9Sstevel@tonic-gate flag_b |= FLF_L; 44127c478bd9Sstevel@tonic-gate } 44137c478bd9Sstevel@tonic-gate if (rp6->ipv6RouteInfo.re_flags & RTF_MULTIRT) { 44147c478bd9Sstevel@tonic-gate (void) strcat(flags, "M"); /* Multiroute */ 44157c478bd9Sstevel@tonic-gate flag_b |= FLF_M; 44167c478bd9Sstevel@tonic-gate } 44177c478bd9Sstevel@tonic-gate if (rp6->ipv6RouteInfo.re_flags & RTF_SETSRC) { 44187c478bd9Sstevel@tonic-gate (void) strcat(flags, "S"); /* Setsrc */ 44197c478bd9Sstevel@tonic-gate flag_b |= FLF_S; 44207c478bd9Sstevel@tonic-gate } 44217c478bd9Sstevel@tonic-gate 44227c478bd9Sstevel@tonic-gate if (!ire_filter_match_v6(rp6, flag_b)) 44237c478bd9Sstevel@tonic-gate return (first); 44247c478bd9Sstevel@tonic-gate 44257c478bd9Sstevel@tonic-gate if (first) { 442645916cd2Sjpk (void) printf(ire_hdr_v6, Vflag ? "IRE" : "Routing"); 442745916cd2Sjpk (void) printf(Vflag ? ire_hdr_v6_verbose : ire_hdr_v6_normal, 442845916cd2Sjpk RSECflag ? " Gateway security attributes " : "", 442945916cd2Sjpk RSECflag ? "-------------------------------" : ""); 44307c478bd9Sstevel@tonic-gate first = B_FALSE; 44317c478bd9Sstevel@tonic-gate } 44327c478bd9Sstevel@tonic-gate 44337c478bd9Sstevel@tonic-gate if (Vflag) { 44347c478bd9Sstevel@tonic-gate (void) printf("%-27s %-27s %-5s %5u%c %5u %3u " 443545916cd2Sjpk "%-5s %6u %6u %s\n", 44367c478bd9Sstevel@tonic-gate pr_prefix6(&rp6->ipv6RouteDest, 4437*e11c3f44Smeem rp6->ipv6RoutePfxLength, dstbuf, sizeof (dstbuf)), 44387c478bd9Sstevel@tonic-gate IN6_IS_ADDR_UNSPECIFIED(&rp6->ipv6RouteNextHop) ? 44397c478bd9Sstevel@tonic-gate " --" : 44407c478bd9Sstevel@tonic-gate pr_addr6(&rp6->ipv6RouteNextHop, gwbuf, sizeof (gwbuf)), 44417c478bd9Sstevel@tonic-gate octetstr(&rp6->ipv6RouteIfIndex, 'a', 44427c478bd9Sstevel@tonic-gate ifname, sizeof (ifname)), 44437c478bd9Sstevel@tonic-gate rp6->ipv6RouteInfo.re_max_frag, 44447c478bd9Sstevel@tonic-gate rp6->ipv6RouteInfo.re_frag_flag ? '*' : ' ', 44457c478bd9Sstevel@tonic-gate rp6->ipv6RouteInfo.re_rtt, 44467c478bd9Sstevel@tonic-gate rp6->ipv6RouteInfo.re_ref, 44477c478bd9Sstevel@tonic-gate flags, 44487c478bd9Sstevel@tonic-gate rp6->ipv6RouteInfo.re_obpkt, 444945916cd2Sjpk rp6->ipv6RouteInfo.re_ibpkt, 445045916cd2Sjpk pr_secattr(attrs)); 44517c478bd9Sstevel@tonic-gate } else { 4452aecc8c24Sja (void) printf("%-27s %-27s %-5s %3u %7u %-5s %s\n", 44537c478bd9Sstevel@tonic-gate pr_prefix6(&rp6->ipv6RouteDest, 4454*e11c3f44Smeem rp6->ipv6RoutePfxLength, dstbuf, sizeof (dstbuf)), 44557c478bd9Sstevel@tonic-gate IN6_IS_ADDR_UNSPECIFIED(&rp6->ipv6RouteNextHop) ? 44567c478bd9Sstevel@tonic-gate " --" : 44577c478bd9Sstevel@tonic-gate pr_addr6(&rp6->ipv6RouteNextHop, gwbuf, sizeof (gwbuf)), 44587c478bd9Sstevel@tonic-gate flags, 44597c478bd9Sstevel@tonic-gate rp6->ipv6RouteInfo.re_ref, 44607c478bd9Sstevel@tonic-gate rp6->ipv6RouteInfo.re_obpkt + rp6->ipv6RouteInfo.re_ibpkt, 44617c478bd9Sstevel@tonic-gate octetstr(&rp6->ipv6RouteIfIndex, 'a', 446245916cd2Sjpk ifname, sizeof (ifname)), 446345916cd2Sjpk pr_secattr(attrs)); 44647c478bd9Sstevel@tonic-gate } 44657c478bd9Sstevel@tonic-gate return (first); 44667c478bd9Sstevel@tonic-gate } 44677c478bd9Sstevel@tonic-gate 446845916cd2Sjpk /* 446945916cd2Sjpk * Common attribute-gathering routine for all transports. 447045916cd2Sjpk */ 447145916cd2Sjpk static mib2_transportMLPEntry_t ** 447245916cd2Sjpk gather_attrs(const mib_item_t *item, int group, int mib_id, int esize) 447345916cd2Sjpk { 447445916cd2Sjpk int transport_count = 0; 447545916cd2Sjpk const mib_item_t *iptr; 447645916cd2Sjpk mib2_transportMLPEntry_t **attrs, *tme; 447745916cd2Sjpk 447845916cd2Sjpk for (iptr = item; iptr != NULL; iptr = iptr->next_item) { 447945916cd2Sjpk if (iptr->group == group && iptr->mib_id == mib_id) 448045916cd2Sjpk transport_count += iptr->length / esize; 448145916cd2Sjpk } 448245916cd2Sjpk if (transport_count <= 0) 448345916cd2Sjpk return (NULL); 448445916cd2Sjpk attrs = calloc(transport_count, sizeof (*attrs)); 448545916cd2Sjpk if (attrs == NULL) { 448645916cd2Sjpk perror("gather_attrs calloc failed"); 448745916cd2Sjpk return (NULL); 448845916cd2Sjpk } 448945916cd2Sjpk for (iptr = item; iptr != NULL; iptr = iptr->next_item) { 449045916cd2Sjpk if (iptr->group == group && iptr->mib_id == EXPER_XPORT_MLP) { 449145916cd2Sjpk for (tme = iptr->valp; 449245916cd2Sjpk (char *)tme < (char *)iptr->valp + iptr->length; 449345916cd2Sjpk /* LINTED: (note 1) */ 449445916cd2Sjpk tme = (mib2_transportMLPEntry_t *)((char *)tme + 449545916cd2Sjpk transportMLPSize)) { 449645916cd2Sjpk attrs[tme->tme_connidx] = tme; 449745916cd2Sjpk } 449845916cd2Sjpk } 449945916cd2Sjpk } 450045916cd2Sjpk return (attrs); 450145916cd2Sjpk } 450245916cd2Sjpk 450345916cd2Sjpk static void 450445916cd2Sjpk print_transport_label(const mib2_transportMLPEntry_t *attr) 450545916cd2Sjpk { 450645916cd2Sjpk if (!RSECflag || attr == NULL) 450745916cd2Sjpk return; 450845916cd2Sjpk 450945916cd2Sjpk if (bisinvalid(&attr->tme_label)) 451045916cd2Sjpk (void) printf(" INVALID\n"); 451145916cd2Sjpk else 451245916cd2Sjpk (void) printf(" %s\n", sl_to_str(&attr->tme_label)); 451345916cd2Sjpk } 451445916cd2Sjpk 45157c478bd9Sstevel@tonic-gate /* ------------------------------ TCP_REPORT------------------------------- */ 45167c478bd9Sstevel@tonic-gate 45177c478bd9Sstevel@tonic-gate static const char tcp_hdr_v4[] = 45187c478bd9Sstevel@tonic-gate "\nTCP: IPv4\n"; 45197c478bd9Sstevel@tonic-gate static const char tcp_hdr_v4_compat[] = 45207c478bd9Sstevel@tonic-gate "\nTCP\n"; 45217c478bd9Sstevel@tonic-gate static const char tcp_hdr_v4_verbose[] = 45227c478bd9Sstevel@tonic-gate "Local/Remote Address Swind Snext Suna Rwind Rnext Rack " 452345916cd2Sjpk " Rto Mss State\n" 45247c478bd9Sstevel@tonic-gate "-------------------- ----- -------- -------- ----- -------- -------- " 452545916cd2Sjpk "----- ----- -----------\n"; 45267c478bd9Sstevel@tonic-gate static const char tcp_hdr_v4_normal[] = 452745916cd2Sjpk " Local Address Remote Address Swind Send-Q Rwind Recv-Q " 452845916cd2Sjpk " State\n" 452945916cd2Sjpk "-------------------- -------------------- ----- ------ ----- ------ " 453045916cd2Sjpk "-----------\n"; 45317c478bd9Sstevel@tonic-gate 45327c478bd9Sstevel@tonic-gate static const char tcp_hdr_v6[] = 45337c478bd9Sstevel@tonic-gate "\nTCP: IPv6\n"; 45347c478bd9Sstevel@tonic-gate static const char tcp_hdr_v6_verbose[] = 45357c478bd9Sstevel@tonic-gate "Local/Remote Address Swind Snext Suna Rwind Rnext " 453645916cd2Sjpk " Rack Rto Mss State If\n" 45377c478bd9Sstevel@tonic-gate "--------------------------------- ----- -------- -------- ----- -------- " 45387c478bd9Sstevel@tonic-gate "-------- ----- ----- ----------- -----\n"; 45397c478bd9Sstevel@tonic-gate static const char tcp_hdr_v6_normal[] = 45407c478bd9Sstevel@tonic-gate " Local Address Remote Address " 454145916cd2Sjpk "Swind Send-Q Rwind Recv-Q State If\n" 45427c478bd9Sstevel@tonic-gate "--------------------------------- --------------------------------- " 45437c478bd9Sstevel@tonic-gate "----- ------ ----- ------ ----------- -----\n"; 45447c478bd9Sstevel@tonic-gate 454545916cd2Sjpk static boolean_t tcp_report_item_v4(const mib2_tcpConnEntry_t *, 454645916cd2Sjpk boolean_t first, const mib2_transportMLPEntry_t *); 454745916cd2Sjpk static boolean_t tcp_report_item_v6(const mib2_tcp6ConnEntry_t *, 454845916cd2Sjpk boolean_t first, const mib2_transportMLPEntry_t *); 45497c478bd9Sstevel@tonic-gate 45507c478bd9Sstevel@tonic-gate static void 455145916cd2Sjpk tcp_report(const mib_item_t *item) 45527c478bd9Sstevel@tonic-gate { 45537c478bd9Sstevel@tonic-gate int jtemp = 0; 45547c478bd9Sstevel@tonic-gate boolean_t print_hdr_once_v4 = B_TRUE; 45557c478bd9Sstevel@tonic-gate boolean_t print_hdr_once_v6 = B_TRUE; 45567c478bd9Sstevel@tonic-gate mib2_tcpConnEntry_t *tp; 45577c478bd9Sstevel@tonic-gate mib2_tcp6ConnEntry_t *tp6; 455845916cd2Sjpk mib2_transportMLPEntry_t **v4_attrs, **v6_attrs; 455945916cd2Sjpk mib2_transportMLPEntry_t **v4a, **v6a; 456045916cd2Sjpk mib2_transportMLPEntry_t *aptr; 45617c478bd9Sstevel@tonic-gate 45627c478bd9Sstevel@tonic-gate if (!protocol_selected(IPPROTO_TCP)) 45637c478bd9Sstevel@tonic-gate return; 45647c478bd9Sstevel@tonic-gate 456545916cd2Sjpk /* 456645916cd2Sjpk * Preparation pass: the kernel returns separate entries for TCP 456745916cd2Sjpk * connection table entries and Multilevel Port attributes. We loop 456845916cd2Sjpk * through the attributes first and set up an array for each address 456945916cd2Sjpk * family. 457045916cd2Sjpk */ 457145916cd2Sjpk v4_attrs = family_selected(AF_INET) && RSECflag ? 457245916cd2Sjpk gather_attrs(item, MIB2_TCP, MIB2_TCP_CONN, tcpConnEntrySize) : 457345916cd2Sjpk NULL; 457445916cd2Sjpk v6_attrs = family_selected(AF_INET6) && RSECflag ? 457545916cd2Sjpk gather_attrs(item, MIB2_TCP6, MIB2_TCP6_CONN, tcp6ConnEntrySize) : 457645916cd2Sjpk NULL; 457745916cd2Sjpk 45787c478bd9Sstevel@tonic-gate /* 'for' loop 1: */ 457945916cd2Sjpk v4a = v4_attrs; 458045916cd2Sjpk v6a = v6_attrs; 458145916cd2Sjpk for (; item != NULL; item = item->next_item) { 45827c478bd9Sstevel@tonic-gate if (Dflag) { 45837c478bd9Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp); 45847c478bd9Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, " 45857c478bd9Sstevel@tonic-gate "length = %d, valp = 0x%p\n", 45867c478bd9Sstevel@tonic-gate item->group, item->mib_id, 45877c478bd9Sstevel@tonic-gate item->length, item->valp); 45887c478bd9Sstevel@tonic-gate } 45897c478bd9Sstevel@tonic-gate 45907c478bd9Sstevel@tonic-gate if (!((item->group == MIB2_TCP && 45917c478bd9Sstevel@tonic-gate item->mib_id == MIB2_TCP_CONN) || 45927c478bd9Sstevel@tonic-gate (item->group == MIB2_TCP6 && 45937c478bd9Sstevel@tonic-gate item->mib_id == MIB2_TCP6_CONN))) 45947c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 45957c478bd9Sstevel@tonic-gate 45967c478bd9Sstevel@tonic-gate if (item->group == MIB2_TCP && !family_selected(AF_INET)) 45977c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 45987c478bd9Sstevel@tonic-gate else if (item->group == MIB2_TCP6 && !family_selected(AF_INET6)) 45997c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 46007c478bd9Sstevel@tonic-gate 46017c478bd9Sstevel@tonic-gate if (item->group == MIB2_TCP) { 46027c478bd9Sstevel@tonic-gate for (tp = (mib2_tcpConnEntry_t *)item->valp; 46037c478bd9Sstevel@tonic-gate (char *)tp < (char *)item->valp + item->length; 46047c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 46057c478bd9Sstevel@tonic-gate tp = (mib2_tcpConnEntry_t *)((char *)tp + 46067c478bd9Sstevel@tonic-gate tcpConnEntrySize)) { 460745916cd2Sjpk aptr = v4a == NULL ? NULL : *v4a++; 46087c478bd9Sstevel@tonic-gate print_hdr_once_v4 = tcp_report_item_v4(tp, 460945916cd2Sjpk print_hdr_once_v4, aptr); 46107c478bd9Sstevel@tonic-gate } 46117c478bd9Sstevel@tonic-gate } else { 46127c478bd9Sstevel@tonic-gate for (tp6 = (mib2_tcp6ConnEntry_t *)item->valp; 46137c478bd9Sstevel@tonic-gate (char *)tp6 < (char *)item->valp + item->length; 46147c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 46157c478bd9Sstevel@tonic-gate tp6 = (mib2_tcp6ConnEntry_t *)((char *)tp6 + 46167c478bd9Sstevel@tonic-gate tcp6ConnEntrySize)) { 461745916cd2Sjpk aptr = v6a == NULL ? NULL : *v6a++; 46187c478bd9Sstevel@tonic-gate print_hdr_once_v6 = tcp_report_item_v6(tp6, 461945916cd2Sjpk print_hdr_once_v6, aptr); 46207c478bd9Sstevel@tonic-gate } 46217c478bd9Sstevel@tonic-gate } 46227c478bd9Sstevel@tonic-gate } /* 'for' loop 1 ends */ 46237c478bd9Sstevel@tonic-gate (void) fflush(stdout); 462445916cd2Sjpk 462545916cd2Sjpk if (v4_attrs != NULL) 462645916cd2Sjpk free(v4_attrs); 462745916cd2Sjpk if (v6_attrs != NULL) 462845916cd2Sjpk free(v6_attrs); 46297c478bd9Sstevel@tonic-gate } 46307c478bd9Sstevel@tonic-gate 46317c478bd9Sstevel@tonic-gate static boolean_t 463245916cd2Sjpk tcp_report_item_v4(const mib2_tcpConnEntry_t *tp, boolean_t first, 463345916cd2Sjpk const mib2_transportMLPEntry_t *attr) 46347c478bd9Sstevel@tonic-gate { 46357c478bd9Sstevel@tonic-gate /* 46367c478bd9Sstevel@tonic-gate * lname and fname below are for the hostname as well as the portname 46377c478bd9Sstevel@tonic-gate * There is no limit on portname length so we assume MAXHOSTNAMELEN 46387c478bd9Sstevel@tonic-gate * as the limit 46397c478bd9Sstevel@tonic-gate */ 46407c478bd9Sstevel@tonic-gate char lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1]; 46417c478bd9Sstevel@tonic-gate char fname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1]; 46427c478bd9Sstevel@tonic-gate 46437c478bd9Sstevel@tonic-gate if (!(Aflag || tp->tcpConnEntryInfo.ce_state >= TCPS_ESTABLISHED)) 46447c478bd9Sstevel@tonic-gate return (first); /* Nothing to print */ 46457c478bd9Sstevel@tonic-gate 46467c478bd9Sstevel@tonic-gate if (first) { 464745916cd2Sjpk (void) printf(v4compat ? tcp_hdr_v4_compat : tcp_hdr_v4); 464845916cd2Sjpk (void) printf(Vflag ? tcp_hdr_v4_verbose : tcp_hdr_v4_normal); 46497c478bd9Sstevel@tonic-gate } 46507c478bd9Sstevel@tonic-gate 46517c478bd9Sstevel@tonic-gate if (Vflag) { 46527c478bd9Sstevel@tonic-gate (void) printf("%-20s\n%-20s %5u %08x %08x %5u %08x %08x " 46537c478bd9Sstevel@tonic-gate "%5u %5u %s\n", 46547c478bd9Sstevel@tonic-gate pr_ap(tp->tcpConnLocalAddress, 4655*e11c3f44Smeem tp->tcpConnLocalPort, "tcp", lname, sizeof (lname)), 46567c478bd9Sstevel@tonic-gate pr_ap(tp->tcpConnRemAddress, 4657*e11c3f44Smeem tp->tcpConnRemPort, "tcp", fname, sizeof (fname)), 46587c478bd9Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_swnd, 46597c478bd9Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_snxt, 46607c478bd9Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_suna, 46617c478bd9Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_rwnd, 46627c478bd9Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_rnxt, 46637c478bd9Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_rack, 46647c478bd9Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_rto, 46657c478bd9Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_mss, 466645916cd2Sjpk mitcp_state(tp->tcpConnEntryInfo.ce_state, attr)); 46677c478bd9Sstevel@tonic-gate } else { 46687c478bd9Sstevel@tonic-gate int sq = (int)tp->tcpConnEntryInfo.ce_snxt - 46697c478bd9Sstevel@tonic-gate (int)tp->tcpConnEntryInfo.ce_suna - 1; 46707c478bd9Sstevel@tonic-gate int rq = (int)tp->tcpConnEntryInfo.ce_rnxt - 46717c478bd9Sstevel@tonic-gate (int)tp->tcpConnEntryInfo.ce_rack; 46727c478bd9Sstevel@tonic-gate 46737c478bd9Sstevel@tonic-gate (void) printf("%-20s %-20s %5u %6d %5u %6d %s\n", 46747c478bd9Sstevel@tonic-gate pr_ap(tp->tcpConnLocalAddress, 4675*e11c3f44Smeem tp->tcpConnLocalPort, "tcp", lname, sizeof (lname)), 46767c478bd9Sstevel@tonic-gate pr_ap(tp->tcpConnRemAddress, 4677*e11c3f44Smeem tp->tcpConnRemPort, "tcp", fname, sizeof (fname)), 46787c478bd9Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_swnd, 46797c478bd9Sstevel@tonic-gate (sq >= 0) ? sq : 0, 46807c478bd9Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_rwnd, 46817c478bd9Sstevel@tonic-gate (rq >= 0) ? rq : 0, 468245916cd2Sjpk mitcp_state(tp->tcpConnEntryInfo.ce_state, attr)); 46837c478bd9Sstevel@tonic-gate } 468445916cd2Sjpk 468545916cd2Sjpk print_transport_label(attr); 468645916cd2Sjpk 468745916cd2Sjpk return (B_FALSE); 46887c478bd9Sstevel@tonic-gate } 46897c478bd9Sstevel@tonic-gate 46907c478bd9Sstevel@tonic-gate static boolean_t 469145916cd2Sjpk tcp_report_item_v6(const mib2_tcp6ConnEntry_t *tp6, boolean_t first, 469245916cd2Sjpk const mib2_transportMLPEntry_t *attr) 46937c478bd9Sstevel@tonic-gate { 46947c478bd9Sstevel@tonic-gate /* 46957c478bd9Sstevel@tonic-gate * lname and fname below are for the hostname as well as the portname 46967c478bd9Sstevel@tonic-gate * There is no limit on portname length so we assume MAXHOSTNAMELEN 46977c478bd9Sstevel@tonic-gate * as the limit 46987c478bd9Sstevel@tonic-gate */ 46997c478bd9Sstevel@tonic-gate char lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1]; 47007c478bd9Sstevel@tonic-gate char fname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1]; 47017c478bd9Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 47027c478bd9Sstevel@tonic-gate char *ifnamep; 47037c478bd9Sstevel@tonic-gate 47047c478bd9Sstevel@tonic-gate if (!(Aflag || tp6->tcp6ConnEntryInfo.ce_state >= TCPS_ESTABLISHED)) 47057c478bd9Sstevel@tonic-gate return (first); /* Nothing to print */ 47067c478bd9Sstevel@tonic-gate 47077c478bd9Sstevel@tonic-gate if (first) { 470845916cd2Sjpk (void) printf(tcp_hdr_v6); 470945916cd2Sjpk (void) printf(Vflag ? tcp_hdr_v6_verbose : tcp_hdr_v6_normal); 47107c478bd9Sstevel@tonic-gate } 47117c478bd9Sstevel@tonic-gate 47127c478bd9Sstevel@tonic-gate ifnamep = (tp6->tcp6ConnIfIndex != 0) ? 47137c478bd9Sstevel@tonic-gate if_indextoname(tp6->tcp6ConnIfIndex, ifname) : NULL; 471445916cd2Sjpk if (ifnamep == NULL) 471545916cd2Sjpk ifnamep = ""; 47167c478bd9Sstevel@tonic-gate 47177c478bd9Sstevel@tonic-gate if (Vflag) { 47187c478bd9Sstevel@tonic-gate (void) printf("%-33s\n%-33s %5u %08x %08x %5u %08x %08x " 471945916cd2Sjpk "%5u %5u %-11s %s\n", 47207c478bd9Sstevel@tonic-gate pr_ap6(&tp6->tcp6ConnLocalAddress, 4721*e11c3f44Smeem tp6->tcp6ConnLocalPort, "tcp", lname, sizeof (lname)), 47227c478bd9Sstevel@tonic-gate pr_ap6(&tp6->tcp6ConnRemAddress, 4723*e11c3f44Smeem tp6->tcp6ConnRemPort, "tcp", fname, sizeof (fname)), 47247c478bd9Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_swnd, 47257c478bd9Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_snxt, 47267c478bd9Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_suna, 47277c478bd9Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_rwnd, 47287c478bd9Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_rnxt, 47297c478bd9Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_rack, 47307c478bd9Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_rto, 47317c478bd9Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_mss, 473245916cd2Sjpk mitcp_state(tp6->tcp6ConnEntryInfo.ce_state, attr), 473345916cd2Sjpk ifnamep); 47347c478bd9Sstevel@tonic-gate } else { 47357c478bd9Sstevel@tonic-gate int sq = (int)tp6->tcp6ConnEntryInfo.ce_snxt - 47367c478bd9Sstevel@tonic-gate (int)tp6->tcp6ConnEntryInfo.ce_suna - 1; 47377c478bd9Sstevel@tonic-gate int rq = (int)tp6->tcp6ConnEntryInfo.ce_rnxt - 47387c478bd9Sstevel@tonic-gate (int)tp6->tcp6ConnEntryInfo.ce_rack; 47397c478bd9Sstevel@tonic-gate 474045916cd2Sjpk (void) printf("%-33s %-33s %5u %6d %5u %6d %-11s %s\n", 47417c478bd9Sstevel@tonic-gate pr_ap6(&tp6->tcp6ConnLocalAddress, 4742*e11c3f44Smeem tp6->tcp6ConnLocalPort, "tcp", lname, sizeof (lname)), 47437c478bd9Sstevel@tonic-gate pr_ap6(&tp6->tcp6ConnRemAddress, 4744*e11c3f44Smeem tp6->tcp6ConnRemPort, "tcp", fname, sizeof (fname)), 47457c478bd9Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_swnd, 47467c478bd9Sstevel@tonic-gate (sq >= 0) ? sq : 0, 47477c478bd9Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_rwnd, 47487c478bd9Sstevel@tonic-gate (rq >= 0) ? rq : 0, 474945916cd2Sjpk mitcp_state(tp6->tcp6ConnEntryInfo.ce_state, attr), 475045916cd2Sjpk ifnamep); 47517c478bd9Sstevel@tonic-gate } 475245916cd2Sjpk 475345916cd2Sjpk print_transport_label(attr); 475445916cd2Sjpk 475545916cd2Sjpk return (B_FALSE); 47567c478bd9Sstevel@tonic-gate } 47577c478bd9Sstevel@tonic-gate 47587c478bd9Sstevel@tonic-gate /* ------------------------------- UDP_REPORT------------------------------- */ 47597c478bd9Sstevel@tonic-gate 476045916cd2Sjpk static boolean_t udp_report_item_v4(const mib2_udpEntry_t *ude, 476145916cd2Sjpk boolean_t first, const mib2_transportMLPEntry_t *attr); 476245916cd2Sjpk static boolean_t udp_report_item_v6(const mib2_udp6Entry_t *ude6, 476345916cd2Sjpk boolean_t first, const mib2_transportMLPEntry_t *attr); 476445916cd2Sjpk 476545916cd2Sjpk static const char udp_hdr_v4[] = 476645916cd2Sjpk " Local Address Remote Address State\n" 476745916cd2Sjpk "-------------------- -------------------- ----------\n"; 47687c478bd9Sstevel@tonic-gate 476945916cd2Sjpk static const char udp_hdr_v6[] = 47707c478bd9Sstevel@tonic-gate " Local Address Remote Address " 477145916cd2Sjpk " State If\n" 47727c478bd9Sstevel@tonic-gate "--------------------------------- --------------------------------- " 47737c478bd9Sstevel@tonic-gate "---------- -----\n"; 47747c478bd9Sstevel@tonic-gate 47757c478bd9Sstevel@tonic-gate static void 477645916cd2Sjpk udp_report(const mib_item_t *item) 47777c478bd9Sstevel@tonic-gate { 47787c478bd9Sstevel@tonic-gate int jtemp = 0; 47797c478bd9Sstevel@tonic-gate boolean_t print_hdr_once_v4 = B_TRUE; 47807c478bd9Sstevel@tonic-gate boolean_t print_hdr_once_v6 = B_TRUE; 47817c478bd9Sstevel@tonic-gate mib2_udpEntry_t *ude; 47827c478bd9Sstevel@tonic-gate mib2_udp6Entry_t *ude6; 478345916cd2Sjpk mib2_transportMLPEntry_t **v4_attrs, **v6_attrs; 478445916cd2Sjpk mib2_transportMLPEntry_t **v4a, **v6a; 478545916cd2Sjpk mib2_transportMLPEntry_t *aptr; 47867c478bd9Sstevel@tonic-gate 47877c478bd9Sstevel@tonic-gate if (!protocol_selected(IPPROTO_UDP)) 47887c478bd9Sstevel@tonic-gate return; 47897c478bd9Sstevel@tonic-gate 479045916cd2Sjpk /* 479145916cd2Sjpk * Preparation pass: the kernel returns separate entries for UDP 479245916cd2Sjpk * connection table entries and Multilevel Port attributes. We loop 479345916cd2Sjpk * through the attributes first and set up an array for each address 479445916cd2Sjpk * family. 479545916cd2Sjpk */ 479645916cd2Sjpk v4_attrs = family_selected(AF_INET) && RSECflag ? 479745916cd2Sjpk gather_attrs(item, MIB2_UDP, MIB2_UDP_ENTRY, udpEntrySize) : NULL; 479845916cd2Sjpk v6_attrs = family_selected(AF_INET6) && RSECflag ? 479945916cd2Sjpk gather_attrs(item, MIB2_UDP6, MIB2_UDP6_ENTRY, udp6EntrySize) : 480045916cd2Sjpk NULL; 480145916cd2Sjpk 480245916cd2Sjpk v4a = v4_attrs; 480345916cd2Sjpk v6a = v6_attrs; 48047c478bd9Sstevel@tonic-gate /* 'for' loop 1: */ 48057c478bd9Sstevel@tonic-gate for (; item; item = item->next_item) { 48067c478bd9Sstevel@tonic-gate if (Dflag) { 48077c478bd9Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp); 48087c478bd9Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, " 48097c478bd9Sstevel@tonic-gate "length = %d, valp = 0x%p\n", 48107c478bd9Sstevel@tonic-gate item->group, item->mib_id, 48117c478bd9Sstevel@tonic-gate item->length, item->valp); 48127c478bd9Sstevel@tonic-gate } 48137c478bd9Sstevel@tonic-gate if (!((item->group == MIB2_UDP && 48147c478bd9Sstevel@tonic-gate item->mib_id == MIB2_UDP_ENTRY) || 48157c478bd9Sstevel@tonic-gate (item->group == MIB2_UDP6 && 48167c478bd9Sstevel@tonic-gate item->mib_id == MIB2_UDP6_ENTRY))) 48177c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 48187c478bd9Sstevel@tonic-gate 48197c478bd9Sstevel@tonic-gate if (item->group == MIB2_UDP && !family_selected(AF_INET)) 48207c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 48217c478bd9Sstevel@tonic-gate else if (item->group == MIB2_UDP6 && !family_selected(AF_INET6)) 48227c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 48237c478bd9Sstevel@tonic-gate 48247c478bd9Sstevel@tonic-gate /* xxx.xxx.xxx.xxx,pppp sss... */ 48257c478bd9Sstevel@tonic-gate if (item->group == MIB2_UDP) { 48267c478bd9Sstevel@tonic-gate for (ude = (mib2_udpEntry_t *)item->valp; 48277c478bd9Sstevel@tonic-gate (char *)ude < (char *)item->valp + item->length; 48287c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 48297c478bd9Sstevel@tonic-gate ude = (mib2_udpEntry_t *)((char *)ude + 48307c478bd9Sstevel@tonic-gate udpEntrySize)) { 483145916cd2Sjpk aptr = v4a == NULL ? NULL : *v4a++; 48327c478bd9Sstevel@tonic-gate print_hdr_once_v4 = udp_report_item_v4(ude, 483345916cd2Sjpk print_hdr_once_v4, aptr); 48347c478bd9Sstevel@tonic-gate } 48357c478bd9Sstevel@tonic-gate } else { 48367c478bd9Sstevel@tonic-gate for (ude6 = (mib2_udp6Entry_t *)item->valp; 48377c478bd9Sstevel@tonic-gate (char *)ude6 < (char *)item->valp + item->length; 48387c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 48397c478bd9Sstevel@tonic-gate ude6 = (mib2_udp6Entry_t *)((char *)ude6 + 48407c478bd9Sstevel@tonic-gate udp6EntrySize)) { 484145916cd2Sjpk aptr = v6a == NULL ? NULL : *v6a++; 48427c478bd9Sstevel@tonic-gate print_hdr_once_v6 = udp_report_item_v6(ude6, 484345916cd2Sjpk print_hdr_once_v6, aptr); 48447c478bd9Sstevel@tonic-gate } 48457c478bd9Sstevel@tonic-gate } 48467c478bd9Sstevel@tonic-gate } /* 'for' loop 1 ends */ 48477c478bd9Sstevel@tonic-gate (void) fflush(stdout); 484845916cd2Sjpk 484945916cd2Sjpk if (v4_attrs != NULL) 485045916cd2Sjpk free(v4_attrs); 485145916cd2Sjpk if (v6_attrs != NULL) 485245916cd2Sjpk free(v6_attrs); 48537c478bd9Sstevel@tonic-gate } 48547c478bd9Sstevel@tonic-gate 48557c478bd9Sstevel@tonic-gate static boolean_t 485645916cd2Sjpk udp_report_item_v4(const mib2_udpEntry_t *ude, boolean_t first, 485745916cd2Sjpk const mib2_transportMLPEntry_t *attr) 48587c478bd9Sstevel@tonic-gate { 48597c478bd9Sstevel@tonic-gate char lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1]; 48607c478bd9Sstevel@tonic-gate /* hostname + portname */ 48617c478bd9Sstevel@tonic-gate 48627c478bd9Sstevel@tonic-gate if (!(Aflag || ude->udpEntryInfo.ue_state >= MIB2_UDP_connected)) 48637c478bd9Sstevel@tonic-gate return (first); /* Nothing to print */ 48647c478bd9Sstevel@tonic-gate 48657c478bd9Sstevel@tonic-gate if (first) { 486645916cd2Sjpk (void) printf(v4compat ? "\nUDP\n" : "\nUDP: IPv4\n"); 486745916cd2Sjpk (void) printf(udp_hdr_v4); 48687c478bd9Sstevel@tonic-gate first = B_FALSE; 48697c478bd9Sstevel@tonic-gate } 48707c478bd9Sstevel@tonic-gate 48717c478bd9Sstevel@tonic-gate (void) printf("%-20s ", 48727c478bd9Sstevel@tonic-gate pr_ap(ude->udpLocalAddress, ude->udpLocalPort, "udp", 48737c478bd9Sstevel@tonic-gate lname, sizeof (lname))); 487445916cd2Sjpk (void) printf("%-20s %s\n", 487545916cd2Sjpk ude->udpEntryInfo.ue_state == MIB2_UDP_connected ? 487645916cd2Sjpk pr_ap(ude->udpEntryInfo.ue_RemoteAddress, 487745916cd2Sjpk ude->udpEntryInfo.ue_RemotePort, "udp", lname, sizeof (lname)) : 487845916cd2Sjpk "", 487945916cd2Sjpk miudp_state(ude->udpEntryInfo.ue_state, attr)); 488045916cd2Sjpk 488145916cd2Sjpk /* 488245916cd2Sjpk * UDP sockets don't have remote attributes, so there's no need to 488345916cd2Sjpk * print them here. 488445916cd2Sjpk */ 488545916cd2Sjpk 48867c478bd9Sstevel@tonic-gate return (first); 48877c478bd9Sstevel@tonic-gate } 48887c478bd9Sstevel@tonic-gate 48897c478bd9Sstevel@tonic-gate static boolean_t 489045916cd2Sjpk udp_report_item_v6(const mib2_udp6Entry_t *ude6, boolean_t first, 489145916cd2Sjpk const mib2_transportMLPEntry_t *attr) 48927c478bd9Sstevel@tonic-gate { 48937c478bd9Sstevel@tonic-gate char lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1]; 48947c478bd9Sstevel@tonic-gate /* hostname + portname */ 48957c478bd9Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1]; 489645916cd2Sjpk const char *ifnamep; 48977c478bd9Sstevel@tonic-gate 48987c478bd9Sstevel@tonic-gate if (!(Aflag || ude6->udp6EntryInfo.ue_state >= MIB2_UDP_connected)) 48997c478bd9Sstevel@tonic-gate return (first); /* Nothing to print */ 49007c478bd9Sstevel@tonic-gate 49017c478bd9Sstevel@tonic-gate if (first) { 490245916cd2Sjpk (void) printf("\nUDP: IPv6\n"); 490345916cd2Sjpk (void) printf(udp_hdr_v6); 49047c478bd9Sstevel@tonic-gate first = B_FALSE; 49057c478bd9Sstevel@tonic-gate } 49067c478bd9Sstevel@tonic-gate 490745916cd2Sjpk ifnamep = (ude6->udp6IfIndex != 0) ? 490845916cd2Sjpk if_indextoname(ude6->udp6IfIndex, ifname) : NULL; 490945916cd2Sjpk 49107c478bd9Sstevel@tonic-gate (void) printf("%-33s ", 49117c478bd9Sstevel@tonic-gate pr_ap6(&ude6->udp6LocalAddress, 49127c478bd9Sstevel@tonic-gate ude6->udp6LocalPort, "udp", lname, sizeof (lname))); 491345916cd2Sjpk (void) printf("%-33s %-10s %s\n", 491445916cd2Sjpk ude6->udp6EntryInfo.ue_state == MIB2_UDP_connected ? 491545916cd2Sjpk pr_ap6(&ude6->udp6EntryInfo.ue_RemoteAddress, 491645916cd2Sjpk ude6->udp6EntryInfo.ue_RemotePort, "udp", lname, sizeof (lname)) : 491745916cd2Sjpk "", 491845916cd2Sjpk miudp_state(ude6->udp6EntryInfo.ue_state, attr), 491945916cd2Sjpk ifnamep == NULL ? "" : ifnamep); 492045916cd2Sjpk 492145916cd2Sjpk /* 492245916cd2Sjpk * UDP sockets don't have remote attributes, so there's no need to 492345916cd2Sjpk * print them here. 492445916cd2Sjpk */ 492545916cd2Sjpk 49267c478bd9Sstevel@tonic-gate return (first); 49277c478bd9Sstevel@tonic-gate } 49287c478bd9Sstevel@tonic-gate 49297c478bd9Sstevel@tonic-gate /* ------------------------------ SCTP_REPORT------------------------------- */ 49307c478bd9Sstevel@tonic-gate 49317c478bd9Sstevel@tonic-gate static const char sctp_hdr[] = 49327c478bd9Sstevel@tonic-gate "\nSCTP:"; 49337c478bd9Sstevel@tonic-gate static const char sctp_hdr_normal[] = 49347c478bd9Sstevel@tonic-gate " Local Address Remote Address " 49357c478bd9Sstevel@tonic-gate "Swind Send-Q Rwind Recv-Q StrsI/O State\n" 49367c478bd9Sstevel@tonic-gate "------------------------------- ------------------------------- " 49377c478bd9Sstevel@tonic-gate "------ ------ ------ ------ ------- -----------"; 49387c478bd9Sstevel@tonic-gate 49397c478bd9Sstevel@tonic-gate static const char * 494045916cd2Sjpk nssctp_state(int state, const mib2_transportMLPEntry_t *attr) 49417c478bd9Sstevel@tonic-gate { 494245916cd2Sjpk static char sctpsbuf[50]; 494345916cd2Sjpk const char *cp; 494445916cd2Sjpk 49457c478bd9Sstevel@tonic-gate switch (state) { 49467c478bd9Sstevel@tonic-gate case MIB2_SCTP_closed: 494745916cd2Sjpk cp = "CLOSED"; 494845916cd2Sjpk break; 49497c478bd9Sstevel@tonic-gate case MIB2_SCTP_cookieWait: 495045916cd2Sjpk cp = "COOKIE_WAIT"; 495145916cd2Sjpk break; 49527c478bd9Sstevel@tonic-gate case MIB2_SCTP_cookieEchoed: 495345916cd2Sjpk cp = "COOKIE_ECHOED"; 495445916cd2Sjpk break; 49557c478bd9Sstevel@tonic-gate case MIB2_SCTP_established: 495645916cd2Sjpk cp = "ESTABLISHED"; 495745916cd2Sjpk break; 49587c478bd9Sstevel@tonic-gate case MIB2_SCTP_shutdownPending: 495945916cd2Sjpk cp = "SHUTDOWN_PENDING"; 496045916cd2Sjpk break; 49617c478bd9Sstevel@tonic-gate case MIB2_SCTP_shutdownSent: 496245916cd2Sjpk cp = "SHUTDOWN_SENT"; 496345916cd2Sjpk break; 49647c478bd9Sstevel@tonic-gate case MIB2_SCTP_shutdownReceived: 496545916cd2Sjpk cp = "SHUTDOWN_RECEIVED"; 496645916cd2Sjpk break; 49677c478bd9Sstevel@tonic-gate case MIB2_SCTP_shutdownAckSent: 496845916cd2Sjpk cp = "SHUTDOWN_ACK_SENT"; 496945916cd2Sjpk break; 49707c478bd9Sstevel@tonic-gate case MIB2_SCTP_listen: 497145916cd2Sjpk cp = "LISTEN"; 497245916cd2Sjpk break; 49737c478bd9Sstevel@tonic-gate default: 497445916cd2Sjpk (void) snprintf(sctpsbuf, sizeof (sctpsbuf), 497545916cd2Sjpk "UNKNOWN STATE(%d)", state); 497645916cd2Sjpk cp = sctpsbuf; 497745916cd2Sjpk break; 497845916cd2Sjpk } 497945916cd2Sjpk 498045916cd2Sjpk if (RSECflag && attr != NULL && attr->tme_flags != 0) { 498145916cd2Sjpk if (cp != sctpsbuf) { 498245916cd2Sjpk (void) strlcpy(sctpsbuf, cp, sizeof (sctpsbuf)); 498345916cd2Sjpk cp = sctpsbuf; 498445916cd2Sjpk } 498545916cd2Sjpk if (attr->tme_flags & MIB2_TMEF_PRIVATE) 498645916cd2Sjpk (void) strlcat(sctpsbuf, " P", sizeof (sctpsbuf)); 498745916cd2Sjpk if (attr->tme_flags & MIB2_TMEF_SHARED) 498845916cd2Sjpk (void) strlcat(sctpsbuf, " S", sizeof (sctpsbuf)); 49897c478bd9Sstevel@tonic-gate } 499045916cd2Sjpk 499145916cd2Sjpk return (cp); 49927c478bd9Sstevel@tonic-gate } 49937c478bd9Sstevel@tonic-gate 499445916cd2Sjpk static const mib2_sctpConnRemoteEntry_t * 499545916cd2Sjpk sctp_getnext_rem(const mib_item_t **itemp, 499645916cd2Sjpk const mib2_sctpConnRemoteEntry_t *current, uint32_t associd) 49977c478bd9Sstevel@tonic-gate { 499845916cd2Sjpk const mib_item_t *item = *itemp; 499945916cd2Sjpk const mib2_sctpConnRemoteEntry_t *sre; 50007c478bd9Sstevel@tonic-gate 50017c478bd9Sstevel@tonic-gate for (; item != NULL; item = item->next_item, current = NULL) { 50027c478bd9Sstevel@tonic-gate if (!(item->group == MIB2_SCTP && 50037c478bd9Sstevel@tonic-gate item->mib_id == MIB2_SCTP_CONN_REMOTE)) { 50047c478bd9Sstevel@tonic-gate continue; 50057c478bd9Sstevel@tonic-gate } 50067c478bd9Sstevel@tonic-gate 50077c478bd9Sstevel@tonic-gate if (current != NULL) { 50087c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 500945916cd2Sjpk sre = (const mib2_sctpConnRemoteEntry_t *) 501045916cd2Sjpk ((const char *)current + sctpRemoteEntrySize); 50117c478bd9Sstevel@tonic-gate } else { 50127c478bd9Sstevel@tonic-gate sre = item->valp; 50137c478bd9Sstevel@tonic-gate } 50147c478bd9Sstevel@tonic-gate for (; (char *)sre < (char *)item->valp + item->length; 501545916cd2Sjpk /* LINTED: (note 1) */ 501645916cd2Sjpk sre = (const mib2_sctpConnRemoteEntry_t *) 501745916cd2Sjpk ((const char *)sre + sctpRemoteEntrySize)) { 50187c478bd9Sstevel@tonic-gate if (sre->sctpAssocId != associd) { 50197c478bd9Sstevel@tonic-gate continue; 50207c478bd9Sstevel@tonic-gate } 50217c478bd9Sstevel@tonic-gate *itemp = item; 50227c478bd9Sstevel@tonic-gate return (sre); 50237c478bd9Sstevel@tonic-gate } 50247c478bd9Sstevel@tonic-gate } 50257c478bd9Sstevel@tonic-gate *itemp = NULL; 50267c478bd9Sstevel@tonic-gate return (NULL); 50277c478bd9Sstevel@tonic-gate } 50287c478bd9Sstevel@tonic-gate 502945916cd2Sjpk static const mib2_sctpConnLocalEntry_t * 503045916cd2Sjpk sctp_getnext_local(const mib_item_t **itemp, 503145916cd2Sjpk const mib2_sctpConnLocalEntry_t *current, uint32_t associd) 50327c478bd9Sstevel@tonic-gate { 503345916cd2Sjpk const mib_item_t *item = *itemp; 503445916cd2Sjpk const mib2_sctpConnLocalEntry_t *sle; 50357c478bd9Sstevel@tonic-gate 50367c478bd9Sstevel@tonic-gate for (; item != NULL; item = item->next_item, current = NULL) { 50377c478bd9Sstevel@tonic-gate if (!(item->group == MIB2_SCTP && 50387c478bd9Sstevel@tonic-gate item->mib_id == MIB2_SCTP_CONN_LOCAL)) { 50397c478bd9Sstevel@tonic-gate continue; 50407c478bd9Sstevel@tonic-gate } 50417c478bd9Sstevel@tonic-gate 50427c478bd9Sstevel@tonic-gate if (current != NULL) { 50437c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 504445916cd2Sjpk sle = (const mib2_sctpConnLocalEntry_t *) 504545916cd2Sjpk ((const char *)current + sctpLocalEntrySize); 50467c478bd9Sstevel@tonic-gate } else { 50477c478bd9Sstevel@tonic-gate sle = item->valp; 50487c478bd9Sstevel@tonic-gate } 50497c478bd9Sstevel@tonic-gate for (; (char *)sle < (char *)item->valp + item->length; 505045916cd2Sjpk /* LINTED: (note 1) */ 505145916cd2Sjpk sle = (const mib2_sctpConnLocalEntry_t *) 505245916cd2Sjpk ((const char *)sle + sctpLocalEntrySize)) { 50537c478bd9Sstevel@tonic-gate if (sle->sctpAssocId != associd) { 50547c478bd9Sstevel@tonic-gate continue; 50557c478bd9Sstevel@tonic-gate } 50567c478bd9Sstevel@tonic-gate *itemp = item; 50577c478bd9Sstevel@tonic-gate return (sle); 50587c478bd9Sstevel@tonic-gate } 50597c478bd9Sstevel@tonic-gate } 50607c478bd9Sstevel@tonic-gate *itemp = NULL; 50617c478bd9Sstevel@tonic-gate return (NULL); 50627c478bd9Sstevel@tonic-gate } 50637c478bd9Sstevel@tonic-gate 50647c478bd9Sstevel@tonic-gate static void 50657c478bd9Sstevel@tonic-gate sctp_pr_addr(int type, char *name, int namelen, const in6_addr_t *addr, 50667c478bd9Sstevel@tonic-gate int port) 50677c478bd9Sstevel@tonic-gate { 50687c478bd9Sstevel@tonic-gate ipaddr_t v4addr; 50697c478bd9Sstevel@tonic-gate in6_addr_t v6addr; 50707c478bd9Sstevel@tonic-gate 50717c478bd9Sstevel@tonic-gate /* 50727c478bd9Sstevel@tonic-gate * Address is either a v4 mapped or v6 addr. If 50737c478bd9Sstevel@tonic-gate * it's a v4 mapped, convert to v4 before 50747c478bd9Sstevel@tonic-gate * displaying. 50757c478bd9Sstevel@tonic-gate */ 50767c478bd9Sstevel@tonic-gate switch (type) { 5077*e11c3f44Smeem case MIB2_SCTP_ADDR_V4: 50787c478bd9Sstevel@tonic-gate /* v4 */ 50797c478bd9Sstevel@tonic-gate v6addr = *addr; 50807c478bd9Sstevel@tonic-gate 50817c478bd9Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&v6addr, v4addr); 50827c478bd9Sstevel@tonic-gate if (port > 0) { 50837c478bd9Sstevel@tonic-gate (void) pr_ap(v4addr, port, "sctp", name, namelen); 50847c478bd9Sstevel@tonic-gate } else { 50857c478bd9Sstevel@tonic-gate (void) pr_addr(v4addr, name, namelen); 50867c478bd9Sstevel@tonic-gate } 50877c478bd9Sstevel@tonic-gate break; 50887c478bd9Sstevel@tonic-gate 5089*e11c3f44Smeem case MIB2_SCTP_ADDR_V6: 50907c478bd9Sstevel@tonic-gate /* v6 */ 50917c478bd9Sstevel@tonic-gate if (port > 0) { 50927c478bd9Sstevel@tonic-gate (void) pr_ap6(addr, port, "sctp", name, namelen); 50937c478bd9Sstevel@tonic-gate } else { 50947c478bd9Sstevel@tonic-gate (void) pr_addr6(addr, name, namelen); 50957c478bd9Sstevel@tonic-gate } 50967c478bd9Sstevel@tonic-gate break; 50977c478bd9Sstevel@tonic-gate 5098*e11c3f44Smeem default: 50997c478bd9Sstevel@tonic-gate (void) snprintf(name, namelen, "<unknown addr type>"); 51007c478bd9Sstevel@tonic-gate break; 51017c478bd9Sstevel@tonic-gate } 51027c478bd9Sstevel@tonic-gate } 51037c478bd9Sstevel@tonic-gate 51047c478bd9Sstevel@tonic-gate static void 510545916cd2Sjpk sctp_conn_report_item(const mib_item_t *head, const mib2_sctpConnEntry_t *sp, 510645916cd2Sjpk const mib2_transportMLPEntry_t *attr) 51077c478bd9Sstevel@tonic-gate { 51087c478bd9Sstevel@tonic-gate char lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1]; 51097c478bd9Sstevel@tonic-gate char fname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1]; 511045916cd2Sjpk const mib2_sctpConnRemoteEntry_t *sre = NULL; 511145916cd2Sjpk const mib2_sctpConnLocalEntry_t *sle = NULL; 511245916cd2Sjpk const mib_item_t *local = head; 511345916cd2Sjpk const mib_item_t *remote = head; 51147c478bd9Sstevel@tonic-gate uint32_t id = sp->sctpAssocId; 51157c478bd9Sstevel@tonic-gate boolean_t printfirst = B_TRUE; 51167c478bd9Sstevel@tonic-gate 51177c478bd9Sstevel@tonic-gate sctp_pr_addr(sp->sctpAssocRemPrimAddrType, fname, sizeof (fname), 51187c478bd9Sstevel@tonic-gate &sp->sctpAssocRemPrimAddr, sp->sctpAssocRemPort); 51197c478bd9Sstevel@tonic-gate sctp_pr_addr(sp->sctpAssocRemPrimAddrType, lname, sizeof (lname), 51207c478bd9Sstevel@tonic-gate &sp->sctpAssocLocPrimAddr, sp->sctpAssocLocalPort); 51217c478bd9Sstevel@tonic-gate 51227c478bd9Sstevel@tonic-gate (void) printf("%-31s %-31s %6u %6d %6u %6d %3d/%-3d %s\n", 51237c478bd9Sstevel@tonic-gate lname, fname, 51247c478bd9Sstevel@tonic-gate sp->sctpConnEntryInfo.ce_swnd, 51257c478bd9Sstevel@tonic-gate sp->sctpConnEntryInfo.ce_sendq, 51267c478bd9Sstevel@tonic-gate sp->sctpConnEntryInfo.ce_rwnd, 51277c478bd9Sstevel@tonic-gate sp->sctpConnEntryInfo.ce_recvq, 51287c478bd9Sstevel@tonic-gate sp->sctpAssocInStreams, sp->sctpAssocOutStreams, 512945916cd2Sjpk nssctp_state(sp->sctpAssocState, attr)); 513045916cd2Sjpk 513145916cd2Sjpk print_transport_label(attr); 51327c478bd9Sstevel@tonic-gate 51337c478bd9Sstevel@tonic-gate if (!Vflag) { 51347c478bd9Sstevel@tonic-gate return; 51357c478bd9Sstevel@tonic-gate } 51367c478bd9Sstevel@tonic-gate 51377c478bd9Sstevel@tonic-gate /* Print remote addresses/local addresses on following lines */ 51387c478bd9Sstevel@tonic-gate while ((sre = sctp_getnext_rem(&remote, sre, id)) != NULL) { 51397c478bd9Sstevel@tonic-gate if (!IN6_ARE_ADDR_EQUAL(&sre->sctpAssocRemAddr, 51407c478bd9Sstevel@tonic-gate &sp->sctpAssocRemPrimAddr)) { 51417c478bd9Sstevel@tonic-gate if (printfirst == B_TRUE) { 51427c478bd9Sstevel@tonic-gate (void) fputs("\t<Remote: ", stdout); 51437c478bd9Sstevel@tonic-gate printfirst = B_FALSE; 51447c478bd9Sstevel@tonic-gate } else { 51457c478bd9Sstevel@tonic-gate (void) fputs(", ", stdout); 51467c478bd9Sstevel@tonic-gate } 51477c478bd9Sstevel@tonic-gate sctp_pr_addr(sre->sctpAssocRemAddrType, fname, 51487c478bd9Sstevel@tonic-gate sizeof (fname), &sre->sctpAssocRemAddr, -1); 51497c478bd9Sstevel@tonic-gate if (sre->sctpAssocRemAddrActive == MIB2_SCTP_ACTIVE) { 51507c478bd9Sstevel@tonic-gate (void) fputs(fname, stdout); 51517c478bd9Sstevel@tonic-gate } else { 51527c478bd9Sstevel@tonic-gate (void) printf("(%s)", fname); 51537c478bd9Sstevel@tonic-gate } 51547c478bd9Sstevel@tonic-gate } 51557c478bd9Sstevel@tonic-gate } 51567c478bd9Sstevel@tonic-gate if (printfirst == B_FALSE) { 51577c478bd9Sstevel@tonic-gate (void) puts(">"); 51587c478bd9Sstevel@tonic-gate printfirst = B_TRUE; 51597c478bd9Sstevel@tonic-gate } 51607c478bd9Sstevel@tonic-gate while ((sle = sctp_getnext_local(&local, sle, id)) != NULL) { 51617c478bd9Sstevel@tonic-gate if (!IN6_ARE_ADDR_EQUAL(&sle->sctpAssocLocalAddr, 51627c478bd9Sstevel@tonic-gate &sp->sctpAssocLocPrimAddr)) { 51637c478bd9Sstevel@tonic-gate if (printfirst == B_TRUE) { 51647c478bd9Sstevel@tonic-gate (void) fputs("\t<Local: ", stdout); 51657c478bd9Sstevel@tonic-gate printfirst = B_FALSE; 51667c478bd9Sstevel@tonic-gate } else { 51677c478bd9Sstevel@tonic-gate (void) fputs(", ", stdout); 51687c478bd9Sstevel@tonic-gate } 51697c478bd9Sstevel@tonic-gate sctp_pr_addr(sle->sctpAssocLocalAddrType, lname, 51707c478bd9Sstevel@tonic-gate sizeof (lname), &sle->sctpAssocLocalAddr, -1); 51717c478bd9Sstevel@tonic-gate (void) fputs(lname, stdout); 51727c478bd9Sstevel@tonic-gate } 51737c478bd9Sstevel@tonic-gate } 51747c478bd9Sstevel@tonic-gate if (printfirst == B_FALSE) { 51757c478bd9Sstevel@tonic-gate (void) puts(">"); 51767c478bd9Sstevel@tonic-gate } 51777c478bd9Sstevel@tonic-gate } 51787c478bd9Sstevel@tonic-gate 51797c478bd9Sstevel@tonic-gate static void 518045916cd2Sjpk sctp_report(const mib_item_t *item) 51817c478bd9Sstevel@tonic-gate { 518245916cd2Sjpk const mib_item_t *head; 518345916cd2Sjpk const mib2_sctpConnEntry_t *sp; 51847c478bd9Sstevel@tonic-gate boolean_t first = B_TRUE; 518545916cd2Sjpk mib2_transportMLPEntry_t **attrs, **aptr; 518645916cd2Sjpk mib2_transportMLPEntry_t *attr; 51877c478bd9Sstevel@tonic-gate 518845916cd2Sjpk /* 518945916cd2Sjpk * Preparation pass: the kernel returns separate entries for SCTP 519045916cd2Sjpk * connection table entries and Multilevel Port attributes. We loop 519145916cd2Sjpk * through the attributes first and set up an array for each address 519245916cd2Sjpk * family. 519345916cd2Sjpk */ 519445916cd2Sjpk attrs = RSECflag ? 519545916cd2Sjpk gather_attrs(item, MIB2_SCTP, MIB2_SCTP_CONN, sctpEntrySize) : 519645916cd2Sjpk NULL; 519745916cd2Sjpk 519845916cd2Sjpk aptr = attrs; 51997c478bd9Sstevel@tonic-gate head = item; 52007c478bd9Sstevel@tonic-gate for (; item != NULL; item = item->next_item) { 52017c478bd9Sstevel@tonic-gate 52027c478bd9Sstevel@tonic-gate if (!(item->group == MIB2_SCTP && 52037c478bd9Sstevel@tonic-gate item->mib_id == MIB2_SCTP_CONN)) 52047c478bd9Sstevel@tonic-gate continue; 52057c478bd9Sstevel@tonic-gate 52067c478bd9Sstevel@tonic-gate for (sp = item->valp; 520745916cd2Sjpk (char *)sp < (char *)item->valp + item->length; 520845916cd2Sjpk /* LINTED: (note 1) */ 520945916cd2Sjpk sp = (mib2_sctpConnEntry_t *)((char *)sp + sctpEntrySize)) { 521045916cd2Sjpk attr = aptr == NULL ? NULL : *aptr++; 52117c478bd9Sstevel@tonic-gate if (Aflag || 52127c478bd9Sstevel@tonic-gate sp->sctpAssocState >= MIB2_SCTP_established) { 52137c478bd9Sstevel@tonic-gate if (first == B_TRUE) { 52147c478bd9Sstevel@tonic-gate (void) puts(sctp_hdr); 52157c478bd9Sstevel@tonic-gate (void) puts(sctp_hdr_normal); 52167c478bd9Sstevel@tonic-gate first = B_FALSE; 52177c478bd9Sstevel@tonic-gate } 521845916cd2Sjpk sctp_conn_report_item(head, sp, attr); 52197c478bd9Sstevel@tonic-gate } 52207c478bd9Sstevel@tonic-gate } 52217c478bd9Sstevel@tonic-gate } 522245916cd2Sjpk if (attrs != NULL) 522345916cd2Sjpk free(attrs); 52247c478bd9Sstevel@tonic-gate } 52257c478bd9Sstevel@tonic-gate 52267c478bd9Sstevel@tonic-gate static char * 52277c478bd9Sstevel@tonic-gate plural(int n) 52287c478bd9Sstevel@tonic-gate { 52297c478bd9Sstevel@tonic-gate return (n != 1 ? "s" : ""); 52307c478bd9Sstevel@tonic-gate } 52317c478bd9Sstevel@tonic-gate 52327c478bd9Sstevel@tonic-gate static char * 52337c478bd9Sstevel@tonic-gate pluraly(int n) 52347c478bd9Sstevel@tonic-gate { 52357c478bd9Sstevel@tonic-gate return (n != 1 ? "ies" : "y"); 52367c478bd9Sstevel@tonic-gate } 52377c478bd9Sstevel@tonic-gate 52387c478bd9Sstevel@tonic-gate static char * 52397c478bd9Sstevel@tonic-gate plurales(int n) 52407c478bd9Sstevel@tonic-gate { 52417c478bd9Sstevel@tonic-gate return (n != 1 ? "es" : ""); 52427c478bd9Sstevel@tonic-gate } 52437c478bd9Sstevel@tonic-gate 52447c478bd9Sstevel@tonic-gate static char * 52457c478bd9Sstevel@tonic-gate pktscale(n) 52467c478bd9Sstevel@tonic-gate int n; 52477c478bd9Sstevel@tonic-gate { 52487c478bd9Sstevel@tonic-gate static char buf[6]; 52497c478bd9Sstevel@tonic-gate char t; 52507c478bd9Sstevel@tonic-gate 52517c478bd9Sstevel@tonic-gate if (n < 1024) { 52527c478bd9Sstevel@tonic-gate t = ' '; 52537c478bd9Sstevel@tonic-gate } else if (n < 1024 * 1024) { 52547c478bd9Sstevel@tonic-gate t = 'k'; 52557c478bd9Sstevel@tonic-gate n /= 1024; 52567c478bd9Sstevel@tonic-gate } else if (n < 1024 * 1024 * 1024) { 52577c478bd9Sstevel@tonic-gate t = 'm'; 52587c478bd9Sstevel@tonic-gate n /= 1024 * 1024; 52597c478bd9Sstevel@tonic-gate } else { 52607c478bd9Sstevel@tonic-gate t = 'g'; 52617c478bd9Sstevel@tonic-gate n /= 1024 * 1024 * 1024; 52627c478bd9Sstevel@tonic-gate } 52637c478bd9Sstevel@tonic-gate 52647c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%4u%c", n, t); 52657c478bd9Sstevel@tonic-gate return (buf); 52667c478bd9Sstevel@tonic-gate } 52677c478bd9Sstevel@tonic-gate 52687c478bd9Sstevel@tonic-gate /* --------------------- mrt_report (netstat -m) -------------------------- */ 52697c478bd9Sstevel@tonic-gate 52707c478bd9Sstevel@tonic-gate static void 52717c478bd9Sstevel@tonic-gate mrt_report(mib_item_t *item) 52727c478bd9Sstevel@tonic-gate { 52737c478bd9Sstevel@tonic-gate int jtemp = 0; 52747c478bd9Sstevel@tonic-gate struct vifctl *vip; 52757c478bd9Sstevel@tonic-gate vifi_t vifi; 52767c478bd9Sstevel@tonic-gate struct mfcctl *mfccp; 52777c478bd9Sstevel@tonic-gate int numvifs = 0; 52787c478bd9Sstevel@tonic-gate int nmfc = 0; 52797c478bd9Sstevel@tonic-gate char abuf[MAXHOSTNAMELEN + 1]; 52807c478bd9Sstevel@tonic-gate 52817c478bd9Sstevel@tonic-gate if (!(family_selected(AF_INET))) 52827c478bd9Sstevel@tonic-gate return; 52837c478bd9Sstevel@tonic-gate 52847c478bd9Sstevel@tonic-gate /* 'for' loop 1: */ 52857c478bd9Sstevel@tonic-gate for (; item; item = item->next_item) { 52867c478bd9Sstevel@tonic-gate if (Dflag) { 52877c478bd9Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp); 52887c478bd9Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, " 52897c478bd9Sstevel@tonic-gate "length = %d, valp = 0x%p\n", 52907c478bd9Sstevel@tonic-gate item->group, item->mib_id, item->length, 52917c478bd9Sstevel@tonic-gate item->valp); 52927c478bd9Sstevel@tonic-gate } 52937c478bd9Sstevel@tonic-gate if (item->group != EXPER_DVMRP) 52947c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 52957c478bd9Sstevel@tonic-gate 52967c478bd9Sstevel@tonic-gate switch (item->mib_id) { 52977c478bd9Sstevel@tonic-gate 52987c478bd9Sstevel@tonic-gate case EXPER_DVMRP_VIF: 52997c478bd9Sstevel@tonic-gate if (Dflag) 53007c478bd9Sstevel@tonic-gate (void) printf("%u records for ipVifTable:\n", 53017c478bd9Sstevel@tonic-gate item->length/sizeof (struct vifctl)); 53027c478bd9Sstevel@tonic-gate if (item->length/sizeof (struct vifctl) == 0) { 53037c478bd9Sstevel@tonic-gate (void) puts("\nVirtual Interface Table is " 53047c478bd9Sstevel@tonic-gate "empty"); 53057c478bd9Sstevel@tonic-gate break; 53067c478bd9Sstevel@tonic-gate } 53077c478bd9Sstevel@tonic-gate 53087c478bd9Sstevel@tonic-gate (void) puts("\nVirtual Interface Table\n" 53097c478bd9Sstevel@tonic-gate " Vif Threshold Rate_Limit Local-Address" 53107c478bd9Sstevel@tonic-gate " Remote-Address Pkt_in Pkt_out"); 53117c478bd9Sstevel@tonic-gate 53127c478bd9Sstevel@tonic-gate /* 'for' loop 2: */ 53137c478bd9Sstevel@tonic-gate for (vip = (struct vifctl *)item->valp; 53147c478bd9Sstevel@tonic-gate (char *)vip < (char *)item->valp + item->length; 53157c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 53167c478bd9Sstevel@tonic-gate vip = (struct vifctl *)((char *)vip + 53177c478bd9Sstevel@tonic-gate vifctlSize)) { 53187c478bd9Sstevel@tonic-gate if (vip->vifc_lcl_addr.s_addr == 0) 53197c478bd9Sstevel@tonic-gate continue; /* 'for' loop 2 */ 53207c478bd9Sstevel@tonic-gate /* numvifs = vip->vifc_vifi; */ 53217c478bd9Sstevel@tonic-gate 53227c478bd9Sstevel@tonic-gate numvifs++; 53237c478bd9Sstevel@tonic-gate (void) printf(" %2u %3u " 53247c478bd9Sstevel@tonic-gate "%4u %-15.15s", 53257c478bd9Sstevel@tonic-gate vip->vifc_vifi, 53267c478bd9Sstevel@tonic-gate vip->vifc_threshold, 53277c478bd9Sstevel@tonic-gate vip->vifc_rate_limit, 53287c478bd9Sstevel@tonic-gate pr_addr(vip->vifc_lcl_addr.s_addr, 53297c478bd9Sstevel@tonic-gate abuf, sizeof (abuf))); 53307c478bd9Sstevel@tonic-gate (void) printf(" %-15.15s %8u %8u\n", 53317c478bd9Sstevel@tonic-gate (vip->vifc_flags & VIFF_TUNNEL) ? 53327c478bd9Sstevel@tonic-gate pr_addr(vip->vifc_rmt_addr.s_addr, 53337c478bd9Sstevel@tonic-gate abuf, sizeof (abuf)) : "", 53347c478bd9Sstevel@tonic-gate vip->vifc_pkt_in, 53357c478bd9Sstevel@tonic-gate vip->vifc_pkt_out); 53367c478bd9Sstevel@tonic-gate } /* 'for' loop 2 ends */ 53377c478bd9Sstevel@tonic-gate 53387c478bd9Sstevel@tonic-gate (void) printf("Numvifs: %d\n", numvifs); 53397c478bd9Sstevel@tonic-gate break; 53407c478bd9Sstevel@tonic-gate 53417c478bd9Sstevel@tonic-gate case EXPER_DVMRP_MRT: 53427c478bd9Sstevel@tonic-gate if (Dflag) 53437c478bd9Sstevel@tonic-gate (void) printf("%u records for ipMfcTable:\n", 5344*e11c3f44Smeem item->length/sizeof (struct vifctl)); 53457c478bd9Sstevel@tonic-gate if (item->length/sizeof (struct vifctl) == 0) { 53467c478bd9Sstevel@tonic-gate (void) puts("\nMulticast Forwarding Cache is " 53477c478bd9Sstevel@tonic-gate "empty"); 53487c478bd9Sstevel@tonic-gate break; 53497c478bd9Sstevel@tonic-gate } 53507c478bd9Sstevel@tonic-gate 53517c478bd9Sstevel@tonic-gate (void) puts("\nMulticast Forwarding Cache\n" 53527c478bd9Sstevel@tonic-gate " Origin-Subnet Mcastgroup " 53537c478bd9Sstevel@tonic-gate "# Pkts In-Vif Out-vifs/Forw-ttl"); 53547c478bd9Sstevel@tonic-gate 53557c478bd9Sstevel@tonic-gate for (mfccp = (struct mfcctl *)item->valp; 53567c478bd9Sstevel@tonic-gate (char *)mfccp < (char *)item->valp + item->length; 53577c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 53587c478bd9Sstevel@tonic-gate mfccp = (struct mfcctl *)((char *)mfccp + 53597c478bd9Sstevel@tonic-gate mfcctlSize)) { 53607c478bd9Sstevel@tonic-gate 53617c478bd9Sstevel@tonic-gate nmfc++; 53627c478bd9Sstevel@tonic-gate (void) printf(" %-30.15s", 53637c478bd9Sstevel@tonic-gate pr_addr(mfccp->mfcc_origin.s_addr, 53647c478bd9Sstevel@tonic-gate abuf, sizeof (abuf))); 53657c478bd9Sstevel@tonic-gate (void) printf("%-15.15s %6s %3u ", 53667c478bd9Sstevel@tonic-gate pr_net(mfccp->mfcc_mcastgrp.s_addr, 5367*e11c3f44Smeem mfccp->mfcc_mcastgrp.s_addr, 5368*e11c3f44Smeem abuf, sizeof (abuf)), 53697c478bd9Sstevel@tonic-gate pktscale((int)mfccp->mfcc_pkt_cnt), 5370*e11c3f44Smeem mfccp->mfcc_parent); 53717c478bd9Sstevel@tonic-gate 53727c478bd9Sstevel@tonic-gate for (vifi = 0; vifi < MAXVIFS; ++vifi) { 53737c478bd9Sstevel@tonic-gate if (mfccp->mfcc_ttls[vifi]) { 53747c478bd9Sstevel@tonic-gate (void) printf(" %u (%u)", 53757c478bd9Sstevel@tonic-gate vifi, 53767c478bd9Sstevel@tonic-gate mfccp->mfcc_ttls[vifi]); 53777c478bd9Sstevel@tonic-gate } 53787c478bd9Sstevel@tonic-gate 53797c478bd9Sstevel@tonic-gate } 53807c478bd9Sstevel@tonic-gate (void) putchar('\n'); 53817c478bd9Sstevel@tonic-gate } 53827c478bd9Sstevel@tonic-gate (void) printf("\nTotal no. of entries in cache: %d\n", 53837c478bd9Sstevel@tonic-gate nmfc); 53847c478bd9Sstevel@tonic-gate break; 53857c478bd9Sstevel@tonic-gate } 53867c478bd9Sstevel@tonic-gate } /* 'for' loop 1 ends */ 53877c478bd9Sstevel@tonic-gate (void) putchar('\n'); 53887c478bd9Sstevel@tonic-gate (void) fflush(stdout); 53897c478bd9Sstevel@tonic-gate } 53907c478bd9Sstevel@tonic-gate 53917c478bd9Sstevel@tonic-gate /* 53927c478bd9Sstevel@tonic-gate * Get the stats for the cache named 'name'. If prefix != 0, then 53937c478bd9Sstevel@tonic-gate * interpret the name as a prefix, and sum up stats for all caches 53947c478bd9Sstevel@tonic-gate * named 'name*'. 53957c478bd9Sstevel@tonic-gate */ 53967c478bd9Sstevel@tonic-gate static void 53977c478bd9Sstevel@tonic-gate kmem_cache_stats(char *title, char *name, int prefix, int64_t *total_bytes) 53987c478bd9Sstevel@tonic-gate { 53997c478bd9Sstevel@tonic-gate int len; 54007c478bd9Sstevel@tonic-gate int alloc; 54017c478bd9Sstevel@tonic-gate int64_t total_alloc = 0; 54027c478bd9Sstevel@tonic-gate int alloc_fail, total_alloc_fail = 0; 54037c478bd9Sstevel@tonic-gate int buf_size = 0; 54047c478bd9Sstevel@tonic-gate int buf_avail; 54057c478bd9Sstevel@tonic-gate int buf_total; 54067c478bd9Sstevel@tonic-gate int buf_max, total_buf_max = 0; 54077c478bd9Sstevel@tonic-gate int buf_inuse, total_buf_inuse = 0; 54087c478bd9Sstevel@tonic-gate kstat_t *ksp; 54097c478bd9Sstevel@tonic-gate char buf[256]; 54107c478bd9Sstevel@tonic-gate 54117c478bd9Sstevel@tonic-gate len = prefix ? strlen(name) : 256; 54127c478bd9Sstevel@tonic-gate 54137c478bd9Sstevel@tonic-gate /* 'for' loop 1: */ 54147c478bd9Sstevel@tonic-gate for (ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next) { 54157c478bd9Sstevel@tonic-gate 54167c478bd9Sstevel@tonic-gate if (strcmp(ksp->ks_class, "kmem_cache") != 0) 54177c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 54187c478bd9Sstevel@tonic-gate 54197c478bd9Sstevel@tonic-gate /* 54207c478bd9Sstevel@tonic-gate * Hack alert: because of the way streams messages are 54217c478bd9Sstevel@tonic-gate * allocated, every constructed free dblk has an associated 54227c478bd9Sstevel@tonic-gate * mblk. From the allocator's viewpoint those mblks are 54237c478bd9Sstevel@tonic-gate * allocated (because they haven't been freed), but from 54247c478bd9Sstevel@tonic-gate * our viewpoint they're actually free (because they're 54257c478bd9Sstevel@tonic-gate * not currently in use). To account for this caching 54267c478bd9Sstevel@tonic-gate * effect we subtract the total constructed free dblks 54277c478bd9Sstevel@tonic-gate * from the total allocated mblks to derive mblks in use. 54287c478bd9Sstevel@tonic-gate */ 54297c478bd9Sstevel@tonic-gate if (strcmp(name, "streams_mblk") == 0 && 54307c478bd9Sstevel@tonic-gate strncmp(ksp->ks_name, "streams_dblk", 12) == 0) { 54317c478bd9Sstevel@tonic-gate (void) safe_kstat_read(kc, ksp, NULL); 54327c478bd9Sstevel@tonic-gate total_buf_inuse -= 5433*e11c3f44Smeem kstat_named_value(ksp, "buf_constructed"); 54347c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 54357c478bd9Sstevel@tonic-gate } 54367c478bd9Sstevel@tonic-gate 54377c478bd9Sstevel@tonic-gate if (strncmp(ksp->ks_name, name, len) != 0) 54387c478bd9Sstevel@tonic-gate continue; /* 'for' loop 1 */ 54397c478bd9Sstevel@tonic-gate 54407c478bd9Sstevel@tonic-gate (void) safe_kstat_read(kc, ksp, NULL); 54417c478bd9Sstevel@tonic-gate 54427c478bd9Sstevel@tonic-gate alloc = kstat_named_value(ksp, "alloc"); 54437c478bd9Sstevel@tonic-gate alloc_fail = kstat_named_value(ksp, "alloc_fail"); 54447c478bd9Sstevel@tonic-gate buf_size = kstat_named_value(ksp, "buf_size"); 54457c478bd9Sstevel@tonic-gate buf_avail = kstat_named_value(ksp, "buf_avail"); 54467c478bd9Sstevel@tonic-gate buf_total = kstat_named_value(ksp, "buf_total"); 54477c478bd9Sstevel@tonic-gate buf_max = kstat_named_value(ksp, "buf_max"); 54487c478bd9Sstevel@tonic-gate buf_inuse = buf_total - buf_avail; 54497c478bd9Sstevel@tonic-gate 54507c478bd9Sstevel@tonic-gate if (Vflag && prefix) { 54517c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s%s", title, 54527c478bd9Sstevel@tonic-gate ksp->ks_name + len); 54537c478bd9Sstevel@tonic-gate (void) printf(" %-18s %6u %9u %11u %11u\n", 54547c478bd9Sstevel@tonic-gate buf, buf_inuse, buf_max, alloc, alloc_fail); 54557c478bd9Sstevel@tonic-gate } 54567c478bd9Sstevel@tonic-gate 54577c478bd9Sstevel@tonic-gate total_alloc += alloc; 54587c478bd9Sstevel@tonic-gate total_alloc_fail += alloc_fail; 54597c478bd9Sstevel@tonic-gate total_buf_max += buf_max; 54607c478bd9Sstevel@tonic-gate total_buf_inuse += buf_inuse; 54617c478bd9Sstevel@tonic-gate *total_bytes += (int64_t)buf_inuse * buf_size; 54627c478bd9Sstevel@tonic-gate } /* 'for' loop 1 ends */ 54637c478bd9Sstevel@tonic-gate 54647c478bd9Sstevel@tonic-gate if (buf_size == 0) { 54657c478bd9Sstevel@tonic-gate (void) printf("%-22s [couldn't find statistics for %s]\n", 5466*e11c3f44Smeem title, name); 54677c478bd9Sstevel@tonic-gate return; 54687c478bd9Sstevel@tonic-gate } 54697c478bd9Sstevel@tonic-gate 54707c478bd9Sstevel@tonic-gate if (Vflag && prefix) 54717c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s_total", title); 54727c478bd9Sstevel@tonic-gate else 54737c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s", title); 54747c478bd9Sstevel@tonic-gate 54757c478bd9Sstevel@tonic-gate (void) printf("%-22s %6d %9d %11lld %11d\n", buf, 5476*e11c3f44Smeem total_buf_inuse, total_buf_max, total_alloc, total_alloc_fail); 54777c478bd9Sstevel@tonic-gate } 54787c478bd9Sstevel@tonic-gate 54797c478bd9Sstevel@tonic-gate static void 54807c478bd9Sstevel@tonic-gate m_report(void) 54817c478bd9Sstevel@tonic-gate { 54827c478bd9Sstevel@tonic-gate int64_t total_bytes = 0; 54837c478bd9Sstevel@tonic-gate 54847c478bd9Sstevel@tonic-gate (void) puts("streams allocation:"); 54857c478bd9Sstevel@tonic-gate (void) printf("%63s\n", "cumulative allocation"); 54867c478bd9Sstevel@tonic-gate (void) printf("%63s\n", 54877c478bd9Sstevel@tonic-gate "current maximum total failures"); 54887c478bd9Sstevel@tonic-gate 54897c478bd9Sstevel@tonic-gate kmem_cache_stats("streams", 54907c478bd9Sstevel@tonic-gate "stream_head_cache", 0, &total_bytes); 54917c478bd9Sstevel@tonic-gate kmem_cache_stats("queues", "queue_cache", 0, &total_bytes); 54927c478bd9Sstevel@tonic-gate kmem_cache_stats("mblk", "streams_mblk", 0, &total_bytes); 54937c478bd9Sstevel@tonic-gate kmem_cache_stats("dblk", "streams_dblk", 1, &total_bytes); 54947c478bd9Sstevel@tonic-gate kmem_cache_stats("linkblk", "linkinfo_cache", 0, &total_bytes); 54957c478bd9Sstevel@tonic-gate kmem_cache_stats("syncq", "syncq_cache", 0, &total_bytes); 54967c478bd9Sstevel@tonic-gate kmem_cache_stats("qband", "qband_cache", 0, &total_bytes); 54977c478bd9Sstevel@tonic-gate 54987c478bd9Sstevel@tonic-gate (void) printf("\n%lld Kbytes allocated for streams data\n", 5499*e11c3f44Smeem total_bytes / 1024); 55007c478bd9Sstevel@tonic-gate 55017c478bd9Sstevel@tonic-gate (void) putchar('\n'); 55027c478bd9Sstevel@tonic-gate (void) fflush(stdout); 55037c478bd9Sstevel@tonic-gate } 55047c478bd9Sstevel@tonic-gate 55057c478bd9Sstevel@tonic-gate /* --------------------------------- */ 55067c478bd9Sstevel@tonic-gate 55077c478bd9Sstevel@tonic-gate /* 55087c478bd9Sstevel@tonic-gate * Print an IPv4 address. Remove the matching part of the domain name 55097c478bd9Sstevel@tonic-gate * from the returned name. 55107c478bd9Sstevel@tonic-gate */ 55117c478bd9Sstevel@tonic-gate static char * 55127c478bd9Sstevel@tonic-gate pr_addr(uint_t addr, char *dst, uint_t dstlen) 55137c478bd9Sstevel@tonic-gate { 55147c478bd9Sstevel@tonic-gate char *cp; 55157c478bd9Sstevel@tonic-gate struct hostent *hp = NULL; 55167c478bd9Sstevel@tonic-gate static char domain[MAXHOSTNAMELEN + 1]; 55177c478bd9Sstevel@tonic-gate static boolean_t first = B_TRUE; 55187c478bd9Sstevel@tonic-gate int error_num; 55197c478bd9Sstevel@tonic-gate 55207c478bd9Sstevel@tonic-gate if (first) { 55217c478bd9Sstevel@tonic-gate first = B_FALSE; 55227c478bd9Sstevel@tonic-gate if (sysinfo(SI_HOSTNAME, domain, MAXHOSTNAMELEN) != -1 && 55237c478bd9Sstevel@tonic-gate (cp = strchr(domain, '.'))) { 55247c478bd9Sstevel@tonic-gate (void) strncpy(domain, cp + 1, sizeof (domain)); 55257c478bd9Sstevel@tonic-gate } else 55267c478bd9Sstevel@tonic-gate domain[0] = 0; 55277c478bd9Sstevel@tonic-gate } 55287c478bd9Sstevel@tonic-gate cp = NULL; 55297c478bd9Sstevel@tonic-gate if (!Nflag) { 55307c478bd9Sstevel@tonic-gate hp = getipnodebyaddr((char *)&addr, sizeof (uint_t), AF_INET, 55317c478bd9Sstevel@tonic-gate &error_num); 55327c478bd9Sstevel@tonic-gate if (hp) { 55337c478bd9Sstevel@tonic-gate if ((cp = strchr(hp->h_name, '.')) != NULL && 55347c478bd9Sstevel@tonic-gate strcasecmp(cp + 1, domain) == 0) 55357c478bd9Sstevel@tonic-gate *cp = 0; 55367c478bd9Sstevel@tonic-gate cp = hp->h_name; 55377c478bd9Sstevel@tonic-gate } 55387c478bd9Sstevel@tonic-gate } 55397c478bd9Sstevel@tonic-gate if (cp != NULL) { 55407c478bd9Sstevel@tonic-gate (void) strncpy(dst, cp, dstlen); 55417c478bd9Sstevel@tonic-gate dst[dstlen - 1] = 0; 55427c478bd9Sstevel@tonic-gate } else { 55437c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET, (char *)&addr, dst, dstlen); 55447c478bd9Sstevel@tonic-gate } 55457c478bd9Sstevel@tonic-gate if (hp != NULL) 55467c478bd9Sstevel@tonic-gate freehostent(hp); 55477c478bd9Sstevel@tonic-gate return (dst); 55487c478bd9Sstevel@tonic-gate } 55497c478bd9Sstevel@tonic-gate 55507c478bd9Sstevel@tonic-gate /* 55517c478bd9Sstevel@tonic-gate * Print a non-zero IPv4 address. Print " --" if the address is zero. 55527c478bd9Sstevel@tonic-gate */ 55537c478bd9Sstevel@tonic-gate static char * 55547c478bd9Sstevel@tonic-gate pr_addrnz(ipaddr_t addr, char *dst, uint_t dstlen) 55557c478bd9Sstevel@tonic-gate { 55567c478bd9Sstevel@tonic-gate if (addr == INADDR_ANY) { 55577c478bd9Sstevel@tonic-gate (void) strlcpy(dst, " --", dstlen); 55587c478bd9Sstevel@tonic-gate return (dst); 55597c478bd9Sstevel@tonic-gate } 55607c478bd9Sstevel@tonic-gate return (pr_addr(addr, dst, dstlen)); 55617c478bd9Sstevel@tonic-gate } 55627c478bd9Sstevel@tonic-gate 55637c478bd9Sstevel@tonic-gate /* 55647c478bd9Sstevel@tonic-gate * Print an IPv6 address. Remove the matching part of the domain name 55657c478bd9Sstevel@tonic-gate * from the returned name. 55667c478bd9Sstevel@tonic-gate */ 55677c478bd9Sstevel@tonic-gate static char * 55687c478bd9Sstevel@tonic-gate pr_addr6(const struct in6_addr *addr, char *dst, uint_t dstlen) 55697c478bd9Sstevel@tonic-gate { 55707c478bd9Sstevel@tonic-gate char *cp; 55717c478bd9Sstevel@tonic-gate struct hostent *hp = NULL; 55727c478bd9Sstevel@tonic-gate static char domain[MAXHOSTNAMELEN + 1]; 55737c478bd9Sstevel@tonic-gate static boolean_t first = B_TRUE; 55747c478bd9Sstevel@tonic-gate int error_num; 55757c478bd9Sstevel@tonic-gate 55767c478bd9Sstevel@tonic-gate if (first) { 55777c478bd9Sstevel@tonic-gate first = B_FALSE; 55787c478bd9Sstevel@tonic-gate if (sysinfo(SI_HOSTNAME, domain, MAXHOSTNAMELEN) != -1 && 55797c478bd9Sstevel@tonic-gate (cp = strchr(domain, '.'))) { 55807c478bd9Sstevel@tonic-gate (void) strncpy(domain, cp + 1, sizeof (domain)); 55817c478bd9Sstevel@tonic-gate } else 55827c478bd9Sstevel@tonic-gate domain[0] = 0; 55837c478bd9Sstevel@tonic-gate } 55847c478bd9Sstevel@tonic-gate cp = NULL; 55857c478bd9Sstevel@tonic-gate if (!Nflag) { 55867c478bd9Sstevel@tonic-gate hp = getipnodebyaddr((char *)addr, 55877c478bd9Sstevel@tonic-gate sizeof (struct in6_addr), AF_INET6, &error_num); 55887c478bd9Sstevel@tonic-gate if (hp) { 55897c478bd9Sstevel@tonic-gate if ((cp = strchr(hp->h_name, '.')) != NULL && 55907c478bd9Sstevel@tonic-gate strcasecmp(cp + 1, domain) == 0) 55917c478bd9Sstevel@tonic-gate *cp = 0; 55927c478bd9Sstevel@tonic-gate cp = hp->h_name; 55937c478bd9Sstevel@tonic-gate } 55947c478bd9Sstevel@tonic-gate } 55957c478bd9Sstevel@tonic-gate if (cp != NULL) { 55967c478bd9Sstevel@tonic-gate (void) strncpy(dst, cp, dstlen); 55977c478bd9Sstevel@tonic-gate dst[dstlen - 1] = 0; 55987c478bd9Sstevel@tonic-gate } else { 55997c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, (void *)addr, dst, dstlen); 56007c478bd9Sstevel@tonic-gate } 56017c478bd9Sstevel@tonic-gate if (hp != NULL) 56027c478bd9Sstevel@tonic-gate freehostent(hp); 56037c478bd9Sstevel@tonic-gate return (dst); 56047c478bd9Sstevel@tonic-gate } 56057c478bd9Sstevel@tonic-gate 56067c478bd9Sstevel@tonic-gate /* For IPv4 masks */ 56077c478bd9Sstevel@tonic-gate static char * 56087c478bd9Sstevel@tonic-gate pr_mask(uint_t addr, char *dst, uint_t dstlen) 56097c478bd9Sstevel@tonic-gate { 56107c478bd9Sstevel@tonic-gate uint8_t *ip_addr = (uint8_t *)&addr; 56117c478bd9Sstevel@tonic-gate 56127c478bd9Sstevel@tonic-gate (void) snprintf(dst, dstlen, "%d.%d.%d.%d", 56137c478bd9Sstevel@tonic-gate ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3]); 56147c478bd9Sstevel@tonic-gate return (dst); 56157c478bd9Sstevel@tonic-gate } 56167c478bd9Sstevel@tonic-gate 56177c478bd9Sstevel@tonic-gate /* 56187c478bd9Sstevel@tonic-gate * For ipv6 masks format is : dest/mask 56197c478bd9Sstevel@tonic-gate * Does not print /128 to save space in printout. H flag carries this notion. 56207c478bd9Sstevel@tonic-gate */ 56217c478bd9Sstevel@tonic-gate static char * 562245916cd2Sjpk pr_prefix6(const struct in6_addr *addr, uint_t prefixlen, char *dst, 562345916cd2Sjpk uint_t dstlen) 56247c478bd9Sstevel@tonic-gate { 56257c478bd9Sstevel@tonic-gate char *cp; 56267c478bd9Sstevel@tonic-gate 56277c478bd9Sstevel@tonic-gate if (IN6_IS_ADDR_UNSPECIFIED(addr) && prefixlen == 0) { 56287c478bd9Sstevel@tonic-gate (void) strncpy(dst, "default", dstlen); 56297c478bd9Sstevel@tonic-gate dst[dstlen - 1] = 0; 56307c478bd9Sstevel@tonic-gate return (dst); 56317c478bd9Sstevel@tonic-gate } 56327c478bd9Sstevel@tonic-gate 56337c478bd9Sstevel@tonic-gate (void) pr_addr6(addr, dst, dstlen); 56347c478bd9Sstevel@tonic-gate if (prefixlen != IPV6_ABITS) { 56357c478bd9Sstevel@tonic-gate /* How much room is left? */ 56367c478bd9Sstevel@tonic-gate cp = strchr(dst, '\0'); 56377c478bd9Sstevel@tonic-gate if (dst + dstlen > cp) { 56387c478bd9Sstevel@tonic-gate dstlen -= (cp - dst); 56397c478bd9Sstevel@tonic-gate (void) snprintf(cp, dstlen, "/%d", prefixlen); 56407c478bd9Sstevel@tonic-gate } 56417c478bd9Sstevel@tonic-gate } 56427c478bd9Sstevel@tonic-gate return (dst); 56437c478bd9Sstevel@tonic-gate } 56447c478bd9Sstevel@tonic-gate 56457c478bd9Sstevel@tonic-gate /* Print IPv4 address and port */ 56467c478bd9Sstevel@tonic-gate static char * 56477c478bd9Sstevel@tonic-gate pr_ap(uint_t addr, uint_t port, char *proto, 56487c478bd9Sstevel@tonic-gate char *dst, uint_t dstlen) 56497c478bd9Sstevel@tonic-gate { 56507c478bd9Sstevel@tonic-gate char *cp; 56517c478bd9Sstevel@tonic-gate 56527c478bd9Sstevel@tonic-gate if (addr == INADDR_ANY) { 56537c478bd9Sstevel@tonic-gate (void) strncpy(dst, " *", dstlen); 56547c478bd9Sstevel@tonic-gate dst[dstlen - 1] = 0; 56557c478bd9Sstevel@tonic-gate } else { 56567c478bd9Sstevel@tonic-gate (void) pr_addr(addr, dst, dstlen); 56577c478bd9Sstevel@tonic-gate } 56587c478bd9Sstevel@tonic-gate /* How much room is left? */ 56597c478bd9Sstevel@tonic-gate cp = strchr(dst, '\0'); 56607c478bd9Sstevel@tonic-gate if (dst + dstlen > cp + 1) { 56617c478bd9Sstevel@tonic-gate *cp++ = '.'; 56627c478bd9Sstevel@tonic-gate dstlen -= (cp - dst); 56637c478bd9Sstevel@tonic-gate dstlen--; 56647c478bd9Sstevel@tonic-gate (void) portname(port, proto, cp, dstlen); 56657c478bd9Sstevel@tonic-gate } 56667c478bd9Sstevel@tonic-gate return (dst); 56677c478bd9Sstevel@tonic-gate } 56687c478bd9Sstevel@tonic-gate 56697c478bd9Sstevel@tonic-gate /* Print IPv6 address and port */ 56707c478bd9Sstevel@tonic-gate static char * 56717c478bd9Sstevel@tonic-gate pr_ap6(const in6_addr_t *addr, uint_t port, char *proto, 56727c478bd9Sstevel@tonic-gate char *dst, uint_t dstlen) 56737c478bd9Sstevel@tonic-gate { 56747c478bd9Sstevel@tonic-gate char *cp; 56757c478bd9Sstevel@tonic-gate 56767c478bd9Sstevel@tonic-gate if (IN6_IS_ADDR_UNSPECIFIED(addr)) { 56777c478bd9Sstevel@tonic-gate (void) strncpy(dst, " *", dstlen); 56787c478bd9Sstevel@tonic-gate dst[dstlen - 1] = 0; 56797c478bd9Sstevel@tonic-gate } else { 56807c478bd9Sstevel@tonic-gate (void) pr_addr6(addr, dst, dstlen); 56817c478bd9Sstevel@tonic-gate } 56827c478bd9Sstevel@tonic-gate /* How much room is left? */ 56837c478bd9Sstevel@tonic-gate cp = strchr(dst, '\0'); 56847c478bd9Sstevel@tonic-gate if (dst + dstlen + 1 > cp) { 56857c478bd9Sstevel@tonic-gate *cp++ = '.'; 56867c478bd9Sstevel@tonic-gate dstlen -= (cp - dst); 56877c478bd9Sstevel@tonic-gate dstlen--; 56887c478bd9Sstevel@tonic-gate (void) portname(port, proto, cp, dstlen); 56897c478bd9Sstevel@tonic-gate } 56907c478bd9Sstevel@tonic-gate return (dst); 56917c478bd9Sstevel@tonic-gate } 56927c478bd9Sstevel@tonic-gate 56937c478bd9Sstevel@tonic-gate /* 56947c478bd9Sstevel@tonic-gate * Return the name of the network whose address is given. The address is 56957c478bd9Sstevel@tonic-gate * assumed to be that of a net or subnet, not a host. 56967c478bd9Sstevel@tonic-gate */ 56977c478bd9Sstevel@tonic-gate static char * 56987c478bd9Sstevel@tonic-gate pr_net(uint_t addr, uint_t mask, char *dst, uint_t dstlen) 56997c478bd9Sstevel@tonic-gate { 57007c478bd9Sstevel@tonic-gate char *cp = NULL; 57017c478bd9Sstevel@tonic-gate struct netent *np = NULL; 57027c478bd9Sstevel@tonic-gate struct hostent *hp = NULL; 57037c478bd9Sstevel@tonic-gate uint_t net; 57047c478bd9Sstevel@tonic-gate int subnetshift; 57057c478bd9Sstevel@tonic-gate int error_num; 57067c478bd9Sstevel@tonic-gate 57077c478bd9Sstevel@tonic-gate if (addr == INADDR_ANY && mask == INADDR_ANY) { 57087c478bd9Sstevel@tonic-gate (void) strncpy(dst, "default", dstlen); 57097c478bd9Sstevel@tonic-gate dst[dstlen - 1] = 0; 57107c478bd9Sstevel@tonic-gate return (dst); 57117c478bd9Sstevel@tonic-gate } 57127c478bd9Sstevel@tonic-gate 57137c478bd9Sstevel@tonic-gate if (!Nflag && addr) { 57147c478bd9Sstevel@tonic-gate if (mask == 0) { 57157c478bd9Sstevel@tonic-gate if (IN_CLASSA(addr)) { 57167c478bd9Sstevel@tonic-gate mask = (uint_t)IN_CLASSA_NET; 57177c478bd9Sstevel@tonic-gate subnetshift = 8; 57187c478bd9Sstevel@tonic-gate } else if (IN_CLASSB(addr)) { 57197c478bd9Sstevel@tonic-gate mask = (uint_t)IN_CLASSB_NET; 57207c478bd9Sstevel@tonic-gate subnetshift = 8; 57217c478bd9Sstevel@tonic-gate } else { 57227c478bd9Sstevel@tonic-gate mask = (uint_t)IN_CLASSC_NET; 57237c478bd9Sstevel@tonic-gate subnetshift = 4; 57247c478bd9Sstevel@tonic-gate } 57257c478bd9Sstevel@tonic-gate /* 57267c478bd9Sstevel@tonic-gate * If there are more bits than the standard mask 57277c478bd9Sstevel@tonic-gate * would suggest, subnets must be in use. Guess at 57287c478bd9Sstevel@tonic-gate * the subnet mask, assuming reasonable width subnet 57297c478bd9Sstevel@tonic-gate * fields. 57307c478bd9Sstevel@tonic-gate */ 57317c478bd9Sstevel@tonic-gate while (addr & ~mask) 57327c478bd9Sstevel@tonic-gate /* compiler doesn't sign extend! */ 57337c478bd9Sstevel@tonic-gate mask = (mask | ((int)mask >> subnetshift)); 57347c478bd9Sstevel@tonic-gate } 57357c478bd9Sstevel@tonic-gate net = addr & mask; 57367c478bd9Sstevel@tonic-gate while ((mask & 1) == 0) 57377c478bd9Sstevel@tonic-gate mask >>= 1, net >>= 1; 57387c478bd9Sstevel@tonic-gate np = getnetbyaddr(net, AF_INET); 57397c478bd9Sstevel@tonic-gate if (np && np->n_net == net) 57407c478bd9Sstevel@tonic-gate cp = np->n_name; 57417c478bd9Sstevel@tonic-gate else { 57427c478bd9Sstevel@tonic-gate /* 57437c478bd9Sstevel@tonic-gate * Look for subnets in hosts map. 57447c478bd9Sstevel@tonic-gate */ 57457c478bd9Sstevel@tonic-gate hp = getipnodebyaddr((char *)&addr, sizeof (uint_t), 57467c478bd9Sstevel@tonic-gate AF_INET, &error_num); 57477c478bd9Sstevel@tonic-gate if (hp) 57487c478bd9Sstevel@tonic-gate cp = hp->h_name; 57497c478bd9Sstevel@tonic-gate } 57507c478bd9Sstevel@tonic-gate } 57517c478bd9Sstevel@tonic-gate if (cp != NULL) { 57527c478bd9Sstevel@tonic-gate (void) strncpy(dst, cp, dstlen); 57537c478bd9Sstevel@tonic-gate dst[dstlen - 1] = 0; 57547c478bd9Sstevel@tonic-gate } else { 57557c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET, (char *)&addr, dst, dstlen); 57567c478bd9Sstevel@tonic-gate } 57577c478bd9Sstevel@tonic-gate if (hp != NULL) 57587c478bd9Sstevel@tonic-gate freehostent(hp); 57597c478bd9Sstevel@tonic-gate return (dst); 57607c478bd9Sstevel@tonic-gate } 57617c478bd9Sstevel@tonic-gate 57627c478bd9Sstevel@tonic-gate /* 57637c478bd9Sstevel@tonic-gate * Return the name of the network whose address is given. 57647c478bd9Sstevel@tonic-gate * The address is assumed to be a host address. 57657c478bd9Sstevel@tonic-gate */ 57667c478bd9Sstevel@tonic-gate static char * 57677c478bd9Sstevel@tonic-gate pr_netaddr(uint_t addr, uint_t mask, char *dst, uint_t dstlen) 57687c478bd9Sstevel@tonic-gate { 57697c478bd9Sstevel@tonic-gate char *cp = NULL; 57707c478bd9Sstevel@tonic-gate struct netent *np = NULL; 57717c478bd9Sstevel@tonic-gate struct hostent *hp = NULL; 57727c478bd9Sstevel@tonic-gate uint_t net; 57737c478bd9Sstevel@tonic-gate uint_t netshifted; 57747c478bd9Sstevel@tonic-gate int subnetshift; 57757c478bd9Sstevel@tonic-gate struct in_addr in; 57767c478bd9Sstevel@tonic-gate int error_num; 57777c478bd9Sstevel@tonic-gate uint_t nbo_addr = addr; /* network byte order */ 57787c478bd9Sstevel@tonic-gate 57797c478bd9Sstevel@tonic-gate addr = ntohl(addr); 57807c478bd9Sstevel@tonic-gate mask = ntohl(mask); 57817c478bd9Sstevel@tonic-gate if (addr == INADDR_ANY && mask == INADDR_ANY) { 57827c478bd9Sstevel@tonic-gate (void) strncpy(dst, "default", dstlen); 57837c478bd9Sstevel@tonic-gate dst[dstlen - 1] = 0; 57847c478bd9Sstevel@tonic-gate return (dst); 57857c478bd9Sstevel@tonic-gate } 57867c478bd9Sstevel@tonic-gate 57877c478bd9Sstevel@tonic-gate /* Figure out network portion of address (with host portion = 0) */ 57887c478bd9Sstevel@tonic-gate if (addr) { 57897c478bd9Sstevel@tonic-gate /* Try figuring out mask if unknown (all 0s). */ 57907c478bd9Sstevel@tonic-gate if (mask == 0) { 57917c478bd9Sstevel@tonic-gate if (IN_CLASSA(addr)) { 57927c478bd9Sstevel@tonic-gate mask = (uint_t)IN_CLASSA_NET; 57937c478bd9Sstevel@tonic-gate subnetshift = 8; 57947c478bd9Sstevel@tonic-gate } else if (IN_CLASSB(addr)) { 57957c478bd9Sstevel@tonic-gate mask = (uint_t)IN_CLASSB_NET; 57967c478bd9Sstevel@tonic-gate subnetshift = 8; 57977c478bd9Sstevel@tonic-gate } else { 57987c478bd9Sstevel@tonic-gate mask = (uint_t)IN_CLASSC_NET; 57997c478bd9Sstevel@tonic-gate subnetshift = 4; 58007c478bd9Sstevel@tonic-gate } 58017c478bd9Sstevel@tonic-gate /* 58027c478bd9Sstevel@tonic-gate * If there are more bits than the standard mask 58037c478bd9Sstevel@tonic-gate * would suggest, subnets must be in use. Guess at 58047c478bd9Sstevel@tonic-gate * the subnet mask, assuming reasonable width subnet 58057c478bd9Sstevel@tonic-gate * fields. 58067c478bd9Sstevel@tonic-gate */ 58077c478bd9Sstevel@tonic-gate while (addr & ~mask) 58087c478bd9Sstevel@tonic-gate /* compiler doesn't sign extend! */ 58097c478bd9Sstevel@tonic-gate mask = (mask | ((int)mask >> subnetshift)); 58107c478bd9Sstevel@tonic-gate } 58117c478bd9Sstevel@tonic-gate net = netshifted = addr & mask; 58127c478bd9Sstevel@tonic-gate while ((mask & 1) == 0) 58137c478bd9Sstevel@tonic-gate mask >>= 1, netshifted >>= 1; 58147c478bd9Sstevel@tonic-gate } 58157c478bd9Sstevel@tonic-gate else 58167c478bd9Sstevel@tonic-gate net = netshifted = 0; 58177c478bd9Sstevel@tonic-gate 58187c478bd9Sstevel@tonic-gate /* Try looking up name unless -n was specified. */ 58197c478bd9Sstevel@tonic-gate if (!Nflag) { 58207c478bd9Sstevel@tonic-gate np = getnetbyaddr(netshifted, AF_INET); 58217c478bd9Sstevel@tonic-gate if (np && np->n_net == netshifted) 58227c478bd9Sstevel@tonic-gate cp = np->n_name; 58237c478bd9Sstevel@tonic-gate else { 58247c478bd9Sstevel@tonic-gate /* 58257c478bd9Sstevel@tonic-gate * Look for subnets in hosts map. 58267c478bd9Sstevel@tonic-gate */ 58277c478bd9Sstevel@tonic-gate hp = getipnodebyaddr((char *)&nbo_addr, sizeof (uint_t), 58287c478bd9Sstevel@tonic-gate AF_INET, &error_num); 58297c478bd9Sstevel@tonic-gate if (hp) 58307c478bd9Sstevel@tonic-gate cp = hp->h_name; 58317c478bd9Sstevel@tonic-gate } 58327c478bd9Sstevel@tonic-gate 58337c478bd9Sstevel@tonic-gate if (cp != NULL) { 58347c478bd9Sstevel@tonic-gate (void) strncpy(dst, cp, dstlen); 58357c478bd9Sstevel@tonic-gate dst[dstlen - 1] = 0; 58367c478bd9Sstevel@tonic-gate if (hp != NULL) 58377c478bd9Sstevel@tonic-gate freehostent(hp); 58387c478bd9Sstevel@tonic-gate return (dst); 58397c478bd9Sstevel@tonic-gate } 58407c478bd9Sstevel@tonic-gate /* 58417c478bd9Sstevel@tonic-gate * No name found for net: fallthru and return in decimal 58427c478bd9Sstevel@tonic-gate * dot notation. 58437c478bd9Sstevel@tonic-gate */ 58447c478bd9Sstevel@tonic-gate } 58457c478bd9Sstevel@tonic-gate 58467c478bd9Sstevel@tonic-gate in.s_addr = htonl(net); 58477c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET, (char *)&in, dst, dstlen); 58487c478bd9Sstevel@tonic-gate if (hp != NULL) 58497c478bd9Sstevel@tonic-gate freehostent(hp); 58507c478bd9Sstevel@tonic-gate return (dst); 58517c478bd9Sstevel@tonic-gate } 58527c478bd9Sstevel@tonic-gate 58537c478bd9Sstevel@tonic-gate /* 58547c478bd9Sstevel@tonic-gate * Return the filter mode as a string: 58557c478bd9Sstevel@tonic-gate * 1 => "INCLUDE" 58567c478bd9Sstevel@tonic-gate * 2 => "EXCLUDE" 58577c478bd9Sstevel@tonic-gate * otherwise "<unknown>" 58587c478bd9Sstevel@tonic-gate */ 58597c478bd9Sstevel@tonic-gate static char * 58607c478bd9Sstevel@tonic-gate fmodestr(uint_t fmode) 58617c478bd9Sstevel@tonic-gate { 58627c478bd9Sstevel@tonic-gate switch (fmode) { 58637c478bd9Sstevel@tonic-gate case 1: 58647c478bd9Sstevel@tonic-gate return ("INCLUDE"); 58657c478bd9Sstevel@tonic-gate case 2: 58667c478bd9Sstevel@tonic-gate return ("EXCLUDE"); 58677c478bd9Sstevel@tonic-gate default: 58687c478bd9Sstevel@tonic-gate return ("<unknown>"); 58697c478bd9Sstevel@tonic-gate } 58707c478bd9Sstevel@tonic-gate } 58717c478bd9Sstevel@tonic-gate 587245916cd2Sjpk #define MAX_STRING_SIZE 256 587345916cd2Sjpk 587445916cd2Sjpk static const char * 587545916cd2Sjpk pr_secattr(const sec_attr_list_t *attrs) 587645916cd2Sjpk { 587745916cd2Sjpk int i; 587845916cd2Sjpk char buf[MAX_STRING_SIZE + 1], *cp; 587945916cd2Sjpk static char *sbuf; 588045916cd2Sjpk static size_t sbuf_len; 588145916cd2Sjpk struct rtsa_s rtsa; 588245916cd2Sjpk const sec_attr_list_t *aptr; 588345916cd2Sjpk 588445916cd2Sjpk if (!RSECflag || attrs == NULL) 588545916cd2Sjpk return (""); 588645916cd2Sjpk 588745916cd2Sjpk for (aptr = attrs, i = 1; aptr != NULL; aptr = aptr->sal_next) 588845916cd2Sjpk i += MAX_STRING_SIZE; 588945916cd2Sjpk if (i > sbuf_len) { 589045916cd2Sjpk cp = realloc(sbuf, i); 589145916cd2Sjpk if (cp == NULL) { 589245916cd2Sjpk perror("realloc security attribute buffer"); 589345916cd2Sjpk return (""); 589445916cd2Sjpk } 589545916cd2Sjpk sbuf_len = i; 589645916cd2Sjpk sbuf = cp; 589745916cd2Sjpk } 589845916cd2Sjpk 589945916cd2Sjpk cp = sbuf; 590045916cd2Sjpk while (attrs != NULL) { 590145916cd2Sjpk const mib2_ipAttributeEntry_t *iae = attrs->sal_attr; 590245916cd2Sjpk 590345916cd2Sjpk /* note: effectively hard-coded in rtsa_keyword */ 590445916cd2Sjpk rtsa.rtsa_mask = RTSA_CIPSO | RTSA_SLRANGE | RTSA_DOI; 590545916cd2Sjpk rtsa.rtsa_slrange = iae->iae_slrange; 590645916cd2Sjpk rtsa.rtsa_doi = iae->iae_doi; 590745916cd2Sjpk 590845916cd2Sjpk (void) snprintf(cp, MAX_STRING_SIZE, 590945916cd2Sjpk "<%s>%s ", rtsa_to_str(&rtsa, buf, sizeof (buf)), 591045916cd2Sjpk attrs->sal_next == NULL ? "" : ","); 591145916cd2Sjpk cp += strlen(cp); 591245916cd2Sjpk attrs = attrs->sal_next; 591345916cd2Sjpk } 591445916cd2Sjpk *cp = '\0'; 591545916cd2Sjpk 591645916cd2Sjpk return (sbuf); 591745916cd2Sjpk } 591845916cd2Sjpk 59197c478bd9Sstevel@tonic-gate /* 59207c478bd9Sstevel@tonic-gate * Pretty print a port number. If the Nflag was 59217c478bd9Sstevel@tonic-gate * specified, use numbers instead of names. 59227c478bd9Sstevel@tonic-gate */ 59237c478bd9Sstevel@tonic-gate static char * 59247c478bd9Sstevel@tonic-gate portname(uint_t port, char *proto, char *dst, uint_t dstlen) 59257c478bd9Sstevel@tonic-gate { 59267c478bd9Sstevel@tonic-gate struct servent *sp = NULL; 59277c478bd9Sstevel@tonic-gate 59287c478bd9Sstevel@tonic-gate if (!Nflag && port) 59297c478bd9Sstevel@tonic-gate sp = getservbyport(htons(port), proto); 59307c478bd9Sstevel@tonic-gate if (sp || port == 0) 59317c478bd9Sstevel@tonic-gate (void) snprintf(dst, dstlen, "%.*s", MAXHOSTNAMELEN, 5932*e11c3f44Smeem sp ? sp->s_name : "*"); 59337c478bd9Sstevel@tonic-gate else 59347c478bd9Sstevel@tonic-gate (void) snprintf(dst, dstlen, "%d", port); 59357c478bd9Sstevel@tonic-gate dst[dstlen - 1] = 0; 59367c478bd9Sstevel@tonic-gate return (dst); 59377c478bd9Sstevel@tonic-gate } 59387c478bd9Sstevel@tonic-gate 59397c478bd9Sstevel@tonic-gate /*PRINTFLIKE2*/ 59407c478bd9Sstevel@tonic-gate void 59417c478bd9Sstevel@tonic-gate fail(int do_perror, char *message, ...) 59427c478bd9Sstevel@tonic-gate { 59437c478bd9Sstevel@tonic-gate va_list args; 59447c478bd9Sstevel@tonic-gate 59457c478bd9Sstevel@tonic-gate va_start(args, message); 59467c478bd9Sstevel@tonic-gate (void) fputs("netstat: ", stderr); 59477c478bd9Sstevel@tonic-gate (void) vfprintf(stderr, message, args); 59487c478bd9Sstevel@tonic-gate va_end(args); 59497c478bd9Sstevel@tonic-gate if (do_perror) 59507c478bd9Sstevel@tonic-gate (void) fprintf(stderr, ": %s", strerror(errno)); 59517c478bd9Sstevel@tonic-gate (void) fputc('\n', stderr); 59527c478bd9Sstevel@tonic-gate exit(2); 59537c478bd9Sstevel@tonic-gate } 59547c478bd9Sstevel@tonic-gate 59557c478bd9Sstevel@tonic-gate /* 59567c478bd9Sstevel@tonic-gate * Return value of named statistic for given kstat_named kstat; 59577c478bd9Sstevel@tonic-gate * return 0LL if named statistic is not in list (use "ll" as a 59587c478bd9Sstevel@tonic-gate * type qualifier when printing 64-bit int's with printf() ) 59597c478bd9Sstevel@tonic-gate */ 59607c478bd9Sstevel@tonic-gate static uint64_t 59617c478bd9Sstevel@tonic-gate kstat_named_value(kstat_t *ksp, char *name) 59627c478bd9Sstevel@tonic-gate { 59637c478bd9Sstevel@tonic-gate kstat_named_t *knp; 59647c478bd9Sstevel@tonic-gate uint64_t value; 59657c478bd9Sstevel@tonic-gate 59667c478bd9Sstevel@tonic-gate if (ksp == NULL) 59677c478bd9Sstevel@tonic-gate return (0LL); 59687c478bd9Sstevel@tonic-gate 59697c478bd9Sstevel@tonic-gate knp = kstat_data_lookup(ksp, name); 59707c478bd9Sstevel@tonic-gate if (knp == NULL) 59717c478bd9Sstevel@tonic-gate return (0LL); 59727c478bd9Sstevel@tonic-gate 59737c478bd9Sstevel@tonic-gate switch (knp->data_type) { 59747c478bd9Sstevel@tonic-gate case KSTAT_DATA_INT32: 59757c478bd9Sstevel@tonic-gate case KSTAT_DATA_UINT32: 59767c478bd9Sstevel@tonic-gate value = (uint64_t)(knp->value.ui32); 59777c478bd9Sstevel@tonic-gate break; 59787c478bd9Sstevel@tonic-gate case KSTAT_DATA_INT64: 59797c478bd9Sstevel@tonic-gate case KSTAT_DATA_UINT64: 59807c478bd9Sstevel@tonic-gate value = knp->value.ui64; 59817c478bd9Sstevel@tonic-gate break; 59827c478bd9Sstevel@tonic-gate default: 59837c478bd9Sstevel@tonic-gate value = 0LL; 59847c478bd9Sstevel@tonic-gate break; 59857c478bd9Sstevel@tonic-gate } 59867c478bd9Sstevel@tonic-gate 59877c478bd9Sstevel@tonic-gate return (value); 59887c478bd9Sstevel@tonic-gate } 59897c478bd9Sstevel@tonic-gate 59907c478bd9Sstevel@tonic-gate kid_t 59917c478bd9Sstevel@tonic-gate safe_kstat_read(kstat_ctl_t *kc, kstat_t *ksp, void *data) 59927c478bd9Sstevel@tonic-gate { 59937c478bd9Sstevel@tonic-gate kid_t kstat_chain_id = kstat_read(kc, ksp, data); 59947c478bd9Sstevel@tonic-gate 59957c478bd9Sstevel@tonic-gate if (kstat_chain_id == -1) 59967c478bd9Sstevel@tonic-gate fail(1, "kstat_read(%p, '%s') failed", (void *)kc, 59977c478bd9Sstevel@tonic-gate ksp->ks_name); 59987c478bd9Sstevel@tonic-gate return (kstat_chain_id); 59997c478bd9Sstevel@tonic-gate } 60007c478bd9Sstevel@tonic-gate 60017c478bd9Sstevel@tonic-gate /* 60027c478bd9Sstevel@tonic-gate * Parse a list of IRE flag characters into a bit field. 60037c478bd9Sstevel@tonic-gate */ 60047c478bd9Sstevel@tonic-gate static uint_t 60057c478bd9Sstevel@tonic-gate flag_bits(const char *arg) 60067c478bd9Sstevel@tonic-gate { 60077c478bd9Sstevel@tonic-gate const char *cp; 60087c478bd9Sstevel@tonic-gate uint_t val; 60097c478bd9Sstevel@tonic-gate 60107c478bd9Sstevel@tonic-gate if (*arg == '\0') 60117c478bd9Sstevel@tonic-gate fatal(1, "missing flag list\n"); 60127c478bd9Sstevel@tonic-gate 60137c478bd9Sstevel@tonic-gate val = 0; 60147c478bd9Sstevel@tonic-gate while (*arg != '\0') { 60157c478bd9Sstevel@tonic-gate if ((cp = strchr(flag_list, *arg)) == NULL) 60167c478bd9Sstevel@tonic-gate fatal(1, "%c: illegal flag\n", *arg); 60177c478bd9Sstevel@tonic-gate val |= 1 << (cp - flag_list); 60187c478bd9Sstevel@tonic-gate arg++; 60197c478bd9Sstevel@tonic-gate } 60207c478bd9Sstevel@tonic-gate return (val); 60217c478bd9Sstevel@tonic-gate } 60227c478bd9Sstevel@tonic-gate 60237c478bd9Sstevel@tonic-gate /* 60247c478bd9Sstevel@tonic-gate * Handle -f argument. Validate input format, sort by keyword, and 60257c478bd9Sstevel@tonic-gate * save off digested results. 60267c478bd9Sstevel@tonic-gate */ 60277c478bd9Sstevel@tonic-gate static void 60287c478bd9Sstevel@tonic-gate process_filter(char *arg) 60297c478bd9Sstevel@tonic-gate { 60307c478bd9Sstevel@tonic-gate int idx; 60317c478bd9Sstevel@tonic-gate int klen = 0; 60327c478bd9Sstevel@tonic-gate char *cp, *cp2; 60337c478bd9Sstevel@tonic-gate int val; 60347c478bd9Sstevel@tonic-gate filter_t *newf; 60357c478bd9Sstevel@tonic-gate struct hostent *hp; 60367c478bd9Sstevel@tonic-gate int error_num; 60377c478bd9Sstevel@tonic-gate uint8_t *ucp; 60387c478bd9Sstevel@tonic-gate int maxv; 60397c478bd9Sstevel@tonic-gate 60407c478bd9Sstevel@tonic-gate /* Look up the keyword first */ 60417c478bd9Sstevel@tonic-gate if (strchr(arg, ':') == NULL) { 60427c478bd9Sstevel@tonic-gate idx = FK_AF; 60437c478bd9Sstevel@tonic-gate } else { 60447c478bd9Sstevel@tonic-gate for (idx = 0; idx < NFILTERKEYS; idx++) { 60457c478bd9Sstevel@tonic-gate klen = strlen(filter_keys[idx]); 60467c478bd9Sstevel@tonic-gate if (strncmp(filter_keys[idx], arg, klen) == 0 && 60477c478bd9Sstevel@tonic-gate arg[klen] == ':') 60487c478bd9Sstevel@tonic-gate break; 60497c478bd9Sstevel@tonic-gate } 60507c478bd9Sstevel@tonic-gate if (idx >= NFILTERKEYS) 60517c478bd9Sstevel@tonic-gate fatal(1, "%s: unknown filter keyword\n", arg); 60527c478bd9Sstevel@tonic-gate 60537c478bd9Sstevel@tonic-gate /* Advance past keyword and separator. */ 60547c478bd9Sstevel@tonic-gate arg += klen + 1; 60557c478bd9Sstevel@tonic-gate } 60567c478bd9Sstevel@tonic-gate 60577c478bd9Sstevel@tonic-gate if ((newf = malloc(sizeof (*newf))) == NULL) { 60587c478bd9Sstevel@tonic-gate perror("filter"); 60597c478bd9Sstevel@tonic-gate exit(1); 60607c478bd9Sstevel@tonic-gate } 60617c478bd9Sstevel@tonic-gate switch (idx) { 60627c478bd9Sstevel@tonic-gate case FK_AF: 60637c478bd9Sstevel@tonic-gate if (strcmp(arg, "inet") == 0) { 60647c478bd9Sstevel@tonic-gate newf->u.f_family = AF_INET; 60657c478bd9Sstevel@tonic-gate } else if (strcmp(arg, "inet6") == 0) { 60667c478bd9Sstevel@tonic-gate newf->u.f_family = AF_INET6; 60677c478bd9Sstevel@tonic-gate } else if (strcmp(arg, "unix") == 0) { 60687c478bd9Sstevel@tonic-gate newf->u.f_family = AF_UNIX; 60697c478bd9Sstevel@tonic-gate } else { 60707c478bd9Sstevel@tonic-gate newf->u.f_family = strtol(arg, &cp, 0); 60717c478bd9Sstevel@tonic-gate if (arg == cp || *cp != '\0') 60727c478bd9Sstevel@tonic-gate fatal(1, "%s: unknown address family.\n", arg); 60737c478bd9Sstevel@tonic-gate } 60747c478bd9Sstevel@tonic-gate break; 60757c478bd9Sstevel@tonic-gate 60767c478bd9Sstevel@tonic-gate case FK_OUTIF: 60777c478bd9Sstevel@tonic-gate if (strcmp(arg, "none") == 0) { 60787c478bd9Sstevel@tonic-gate newf->u.f_ifname = NULL; 60797c478bd9Sstevel@tonic-gate break; 60807c478bd9Sstevel@tonic-gate } 60817c478bd9Sstevel@tonic-gate if (strcmp(arg, "any") == 0) { 60827c478bd9Sstevel@tonic-gate newf->u.f_ifname = ""; 60837c478bd9Sstevel@tonic-gate break; 60847c478bd9Sstevel@tonic-gate } 60857c478bd9Sstevel@tonic-gate val = strtol(arg, &cp, 0); 60867c478bd9Sstevel@tonic-gate if (val <= 0 || arg == cp || cp[0] != '\0') { 60877c478bd9Sstevel@tonic-gate if ((val = if_nametoindex(arg)) == 0) { 60887c478bd9Sstevel@tonic-gate perror(arg); 60897c478bd9Sstevel@tonic-gate exit(1); 60907c478bd9Sstevel@tonic-gate } 60917c478bd9Sstevel@tonic-gate } 60927c478bd9Sstevel@tonic-gate newf->u.f_ifname = arg; 60937c478bd9Sstevel@tonic-gate break; 60947c478bd9Sstevel@tonic-gate 60957c478bd9Sstevel@tonic-gate case FK_DST: 60967c478bd9Sstevel@tonic-gate V4MASK_TO_V6(IP_HOST_MASK, newf->u.a.f_mask); 60977c478bd9Sstevel@tonic-gate if (strcmp(arg, "any") == 0) { 60987c478bd9Sstevel@tonic-gate /* Special semantics; any address *but* zero */ 60997c478bd9Sstevel@tonic-gate newf->u.a.f_address = NULL; 61007c478bd9Sstevel@tonic-gate (void) memset(&newf->u.a.f_mask, 0, 61017c478bd9Sstevel@tonic-gate sizeof (newf->u.a.f_mask)); 61027c478bd9Sstevel@tonic-gate break; 61037c478bd9Sstevel@tonic-gate } 61047c478bd9Sstevel@tonic-gate if (strcmp(arg, "none") == 0) { 61057c478bd9Sstevel@tonic-gate newf->u.a.f_address = NULL; 61067c478bd9Sstevel@tonic-gate break; 61077c478bd9Sstevel@tonic-gate } 61087c478bd9Sstevel@tonic-gate if ((cp = strrchr(arg, '/')) != NULL) 61097c478bd9Sstevel@tonic-gate *cp++ = '\0'; 61107c478bd9Sstevel@tonic-gate hp = getipnodebyname(arg, AF_INET6, AI_V4MAPPED|AI_ALL, 61117c478bd9Sstevel@tonic-gate &error_num); 61127c478bd9Sstevel@tonic-gate if (hp == NULL) 61137c478bd9Sstevel@tonic-gate fatal(1, "%s: invalid or unknown host address\n", arg); 61147c478bd9Sstevel@tonic-gate newf->u.a.f_address = hp; 61157c478bd9Sstevel@tonic-gate if (cp == NULL) { 61167c478bd9Sstevel@tonic-gate V4MASK_TO_V6(IP_HOST_MASK, newf->u.a.f_mask); 61177c478bd9Sstevel@tonic-gate } else { 61187c478bd9Sstevel@tonic-gate val = strtol(cp, &cp2, 0); 61197c478bd9Sstevel@tonic-gate if (cp != cp2 && cp2[0] == '\0') { 61207c478bd9Sstevel@tonic-gate /* 61217c478bd9Sstevel@tonic-gate * If decode as "/n" works, then translate 61227c478bd9Sstevel@tonic-gate * into a mask. 61237c478bd9Sstevel@tonic-gate */ 61247c478bd9Sstevel@tonic-gate if (hp->h_addr_list[0] != NULL && 61257c478bd9Sstevel@tonic-gate /* LINTED: (note 1) */ 6126*e11c3f44Smeem IN6_IS_ADDR_V4MAPPED((in6_addr_t *) 6127*e11c3f44Smeem hp->h_addr_list[0])) { 61287c478bd9Sstevel@tonic-gate maxv = IP_ABITS; 61297c478bd9Sstevel@tonic-gate } else { 61307c478bd9Sstevel@tonic-gate maxv = IPV6_ABITS; 61317c478bd9Sstevel@tonic-gate } 61327c478bd9Sstevel@tonic-gate if (val < 0 || val >= maxv) 61337c478bd9Sstevel@tonic-gate fatal(1, "%d: not in range 0 to %d\n", 61347c478bd9Sstevel@tonic-gate val, maxv - 1); 61357c478bd9Sstevel@tonic-gate if (maxv == IP_ABITS) 61367c478bd9Sstevel@tonic-gate val += IPV6_ABITS - IP_ABITS; 61377c478bd9Sstevel@tonic-gate ucp = newf->u.a.f_mask.s6_addr; 61387c478bd9Sstevel@tonic-gate while (val >= 8) 61397c478bd9Sstevel@tonic-gate *ucp++ = 0xff, val -= 8; 61407c478bd9Sstevel@tonic-gate *ucp++ = (0xff << (8 - val)) & 0xff; 61417c478bd9Sstevel@tonic-gate while (ucp < newf->u.a.f_mask.s6_addr + 61427c478bd9Sstevel@tonic-gate sizeof (newf->u.a.f_mask.s6_addr)) 61437c478bd9Sstevel@tonic-gate *ucp++ = 0; 61447c478bd9Sstevel@tonic-gate /* Otherwise, try as numeric address */ 61457c478bd9Sstevel@tonic-gate } else if (inet_pton(AF_INET6, 61467c478bd9Sstevel@tonic-gate cp, &newf->u.a.f_mask) <= 0) { 61477c478bd9Sstevel@tonic-gate fatal(1, "%s: illegal mask format\n", cp); 61487c478bd9Sstevel@tonic-gate } 61497c478bd9Sstevel@tonic-gate } 61507c478bd9Sstevel@tonic-gate break; 61517c478bd9Sstevel@tonic-gate 61527c478bd9Sstevel@tonic-gate case FK_FLAGS: 61537c478bd9Sstevel@tonic-gate if (*arg == '+') { 61547c478bd9Sstevel@tonic-gate newf->u.f.f_flagset = flag_bits(arg + 1); 61557c478bd9Sstevel@tonic-gate newf->u.f.f_flagclear = 0; 61567c478bd9Sstevel@tonic-gate } else if (*arg == '-') { 61577c478bd9Sstevel@tonic-gate newf->u.f.f_flagset = 0; 61587c478bd9Sstevel@tonic-gate newf->u.f.f_flagclear = flag_bits(arg + 1); 61597c478bd9Sstevel@tonic-gate } else { 61607c478bd9Sstevel@tonic-gate newf->u.f.f_flagset = flag_bits(arg); 61617c478bd9Sstevel@tonic-gate newf->u.f.f_flagclear = ~newf->u.f.f_flagset; 61627c478bd9Sstevel@tonic-gate } 61637c478bd9Sstevel@tonic-gate break; 61647c478bd9Sstevel@tonic-gate 61657c478bd9Sstevel@tonic-gate default: 61667c478bd9Sstevel@tonic-gate assert(0); 61677c478bd9Sstevel@tonic-gate } 61687c478bd9Sstevel@tonic-gate newf->f_next = filters[idx]; 61697c478bd9Sstevel@tonic-gate filters[idx] = newf; 61707c478bd9Sstevel@tonic-gate } 61717c478bd9Sstevel@tonic-gate 61727c478bd9Sstevel@tonic-gate /* Determine if user wants this address family printed. */ 61737c478bd9Sstevel@tonic-gate static boolean_t 61747c478bd9Sstevel@tonic-gate family_selected(int family) 61757c478bd9Sstevel@tonic-gate { 61767c478bd9Sstevel@tonic-gate const filter_t *fp; 61777c478bd9Sstevel@tonic-gate 61787c478bd9Sstevel@tonic-gate if (v4compat && family == AF_INET6) 61797c478bd9Sstevel@tonic-gate return (B_FALSE); 61807c478bd9Sstevel@tonic-gate if ((fp = filters[FK_AF]) == NULL) 61817c478bd9Sstevel@tonic-gate return (B_TRUE); 61827c478bd9Sstevel@tonic-gate while (fp != NULL) { 61837c478bd9Sstevel@tonic-gate if (fp->u.f_family == family) 61847c478bd9Sstevel@tonic-gate return (B_TRUE); 61857c478bd9Sstevel@tonic-gate fp = fp->f_next; 61867c478bd9Sstevel@tonic-gate } 61877c478bd9Sstevel@tonic-gate return (B_FALSE); 61887c478bd9Sstevel@tonic-gate } 61897c478bd9Sstevel@tonic-gate 6190*e11c3f44Smeem /* 6191*e11c3f44Smeem * Convert the interface index to a string using the buffer `ifname', which 6192*e11c3f44Smeem * must be at least LIFNAMSIZ bytes. We first try to map it to name. If that 6193*e11c3f44Smeem * fails (e.g., because we're inside a zone and it does not have access to 6194*e11c3f44Smeem * interface for the index in question), just return "if#<num>". 6195*e11c3f44Smeem */ 6196*e11c3f44Smeem static char * 6197*e11c3f44Smeem ifindex2str(uint_t ifindex, char *ifname) 6198*e11c3f44Smeem { 6199*e11c3f44Smeem if (if_indextoname(ifindex, ifname) == NULL) 6200*e11c3f44Smeem (void) snprintf(ifname, LIFNAMSIZ, "if#%d", ifindex); 6201*e11c3f44Smeem 6202*e11c3f44Smeem return (ifname); 6203*e11c3f44Smeem } 6204*e11c3f44Smeem 62057c478bd9Sstevel@tonic-gate /* 62067c478bd9Sstevel@tonic-gate * print the usage line 62077c478bd9Sstevel@tonic-gate */ 62087c478bd9Sstevel@tonic-gate static void 62097c478bd9Sstevel@tonic-gate usage(char *cmdname) 62107c478bd9Sstevel@tonic-gate { 62117c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "usage: %s [-anv] [-f address_family]\n", 62127c478bd9Sstevel@tonic-gate cmdname); 62137c478bd9Sstevel@tonic-gate (void) fprintf(stderr, " %s [-n] [-f address_family] " 62147c478bd9Sstevel@tonic-gate "[-P protocol] [-g | -p | -s [interval [count]]]\n", cmdname); 62157c478bd9Sstevel@tonic-gate (void) fprintf(stderr, " %s -m [-v] " 62167c478bd9Sstevel@tonic-gate "[interval [count]]\n", cmdname); 62177c478bd9Sstevel@tonic-gate (void) fprintf(stderr, " %s -i [-I interface] [-an] " 62187c478bd9Sstevel@tonic-gate "[-f address_family] [interval [count]]\n", cmdname); 62197c478bd9Sstevel@tonic-gate (void) fprintf(stderr, " %s -r [-anv] " 62207c478bd9Sstevel@tonic-gate "[-f address_family|filter]\n", cmdname); 62217c478bd9Sstevel@tonic-gate (void) fprintf(stderr, " %s -M [-ns] [-f address_family]\n", 62227c478bd9Sstevel@tonic-gate cmdname); 62237c478bd9Sstevel@tonic-gate (void) fprintf(stderr, " %s -D [-I interface] " 62247c478bd9Sstevel@tonic-gate "[-f address_family]\n", cmdname); 62257c478bd9Sstevel@tonic-gate exit(EXIT_FAILURE); 62267c478bd9Sstevel@tonic-gate } 62277c478bd9Sstevel@tonic-gate 62287c478bd9Sstevel@tonic-gate /* 62297c478bd9Sstevel@tonic-gate * fatal: print error message to stderr and 62307c478bd9Sstevel@tonic-gate * call exit(errcode) 62317c478bd9Sstevel@tonic-gate */ 62327c478bd9Sstevel@tonic-gate /*PRINTFLIKE2*/ 62337c478bd9Sstevel@tonic-gate static void 623445916cd2Sjpk fatal(int errcode, char *format, ...) 623545916cd2Sjpk { 62367c478bd9Sstevel@tonic-gate va_list argp; 62377c478bd9Sstevel@tonic-gate 62387c478bd9Sstevel@tonic-gate if (format == NULL) 62397c478bd9Sstevel@tonic-gate return; 62407c478bd9Sstevel@tonic-gate 62417c478bd9Sstevel@tonic-gate va_start(argp, format); 62427c478bd9Sstevel@tonic-gate (void) vfprintf(stderr, format, argp); 62437c478bd9Sstevel@tonic-gate va_end(argp); 62447c478bd9Sstevel@tonic-gate 62457c478bd9Sstevel@tonic-gate exit(errcode); 62467c478bd9Sstevel@tonic-gate } 6247