10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51676Sjpk * Common Development and Distribution License (the "License").
61676Sjpk * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
2212748SSowmini.Varadhan@oracle.COM * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate * Copyright (c) 1990 Mentat Inc.
240Sstevel@tonic-gate * netstat.c 2.2, last change 9/9/91
250Sstevel@tonic-gate * MROUTING Revision 3.5
260Sstevel@tonic-gate */
270Sstevel@tonic-gate
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate * simple netstat based on snmp/mib-2 interface to the TCP/IP stack
300Sstevel@tonic-gate *
310Sstevel@tonic-gate * NOTES:
320Sstevel@tonic-gate * 1. A comment "LINTED: (note 1)" appears before certain lines where
330Sstevel@tonic-gate * lint would have complained, "pointer cast may result in improper
340Sstevel@tonic-gate * alignment". These are lines where lint had suspected potential
350Sstevel@tonic-gate * improper alignment of a data structure; in each such situation
360Sstevel@tonic-gate * we have relied on the kernel guaranteeing proper alignment.
370Sstevel@tonic-gate * 2. Some 'for' loops have been commented as "'for' loop 1", etc
380Sstevel@tonic-gate * because they have 'continue' or 'break' statements in their
390Sstevel@tonic-gate * bodies. 'continue' statements have been used inside some loops
400Sstevel@tonic-gate * where avoiding them would have led to deep levels of indentation.
410Sstevel@tonic-gate *
420Sstevel@tonic-gate * TODO:
430Sstevel@tonic-gate * Add ability to request subsets from kernel (with level = MIB2_IP;
440Sstevel@tonic-gate * name = 0 meaning everything for compatibility)
450Sstevel@tonic-gate */
460Sstevel@tonic-gate
470Sstevel@tonic-gate #include <stdio.h>
480Sstevel@tonic-gate #include <stdlib.h>
490Sstevel@tonic-gate #include <stdarg.h>
500Sstevel@tonic-gate #include <unistd.h>
510Sstevel@tonic-gate #include <strings.h>
520Sstevel@tonic-gate #include <string.h>
530Sstevel@tonic-gate #include <errno.h>
540Sstevel@tonic-gate #include <ctype.h>
550Sstevel@tonic-gate #include <kstat.h>
560Sstevel@tonic-gate #include <assert.h>
5710265SKrishnendu.Sadhukhan@Sun.COM #include <locale.h>
580Sstevel@tonic-gate
590Sstevel@tonic-gate #include <sys/types.h>
600Sstevel@tonic-gate #include <sys/stream.h>
610Sstevel@tonic-gate #include <stropts.h>
620Sstevel@tonic-gate #include <sys/strstat.h>
630Sstevel@tonic-gate #include <sys/tihdr.h>
640Sstevel@tonic-gate
650Sstevel@tonic-gate #include <sys/socket.h>
660Sstevel@tonic-gate #include <sys/sockio.h>
670Sstevel@tonic-gate #include <netinet/in.h>
680Sstevel@tonic-gate #include <net/if.h>
690Sstevel@tonic-gate #include <net/route.h>
700Sstevel@tonic-gate
710Sstevel@tonic-gate #include <inet/mib2.h>
720Sstevel@tonic-gate #include <inet/ip.h>
730Sstevel@tonic-gate #include <inet/arp.h>
740Sstevel@tonic-gate #include <inet/tcp.h>
750Sstevel@tonic-gate #include <netinet/igmp_var.h>
760Sstevel@tonic-gate #include <netinet/ip_mroute.h>
770Sstevel@tonic-gate
780Sstevel@tonic-gate #include <arpa/inet.h>
790Sstevel@tonic-gate #include <netdb.h>
800Sstevel@tonic-gate #include <fcntl.h>
810Sstevel@tonic-gate #include <sys/systeminfo.h>
820Sstevel@tonic-gate #include <arpa/inet.h>
830Sstevel@tonic-gate
840Sstevel@tonic-gate #include <netinet/dhcp.h>
850Sstevel@tonic-gate #include <dhcpagent_ipc.h>
860Sstevel@tonic-gate #include <dhcpagent_util.h>
870Sstevel@tonic-gate #include <compat.h>
880Sstevel@tonic-gate
891676Sjpk #include <libtsnet.h>
901676Sjpk #include <tsol/label.h>
911676Sjpk
9210265SKrishnendu.Sadhukhan@Sun.COM #include "statcommon.h"
9310265SKrishnendu.Sadhukhan@Sun.COM
940Sstevel@tonic-gate extern void unixpr(kstat_ctl_t *kc);
950Sstevel@tonic-gate
960Sstevel@tonic-gate #define STR_EXPAND 4
970Sstevel@tonic-gate
980Sstevel@tonic-gate #define V4MASK_TO_V6(v4, v6) ((v6)._S6_un._S6_u32[0] = 0xfffffffful, \
990Sstevel@tonic-gate (v6)._S6_un._S6_u32[1] = 0xfffffffful, \
1000Sstevel@tonic-gate (v6)._S6_un._S6_u32[2] = 0xfffffffful, \
1010Sstevel@tonic-gate (v6)._S6_un._S6_u32[3] = (v4))
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate #define IN6_IS_V4MASK(v6) ((v6)._S6_un._S6_u32[0] == 0xfffffffful && \
1040Sstevel@tonic-gate (v6)._S6_un._S6_u32[1] == 0xfffffffful && \
1050Sstevel@tonic-gate (v6)._S6_un._S6_u32[2] == 0xfffffffful)
1060Sstevel@tonic-gate
1073431Scarlsonj /*
1083431Scarlsonj * This is used as a cushion in the buffer allocation directed by SIOCGLIFNUM.
1093431Scarlsonj * Because there's no locking between SIOCGLIFNUM and SIOCGLIFCONF, it's
1103431Scarlsonj * possible for an administrator to plumb new interfaces between those two
1113431Scarlsonj * calls, resulting in the failure of the latter. This addition makes that
1123431Scarlsonj * less likely.
1133431Scarlsonj */
1143431Scarlsonj #define LIFN_GUARD_VALUE 10
1153431Scarlsonj
1160Sstevel@tonic-gate typedef struct mib_item_s {
1170Sstevel@tonic-gate struct mib_item_s *next_item;
1180Sstevel@tonic-gate int group;
1190Sstevel@tonic-gate int mib_id;
1200Sstevel@tonic-gate int length;
1210Sstevel@tonic-gate void *valp;
1220Sstevel@tonic-gate } mib_item_t;
1230Sstevel@tonic-gate
1240Sstevel@tonic-gate struct ifstat {
1250Sstevel@tonic-gate uint64_t ipackets;
1260Sstevel@tonic-gate uint64_t ierrors;
1270Sstevel@tonic-gate uint64_t opackets;
1280Sstevel@tonic-gate uint64_t oerrors;
1290Sstevel@tonic-gate uint64_t collisions;
1300Sstevel@tonic-gate };
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate struct iflist {
1330Sstevel@tonic-gate struct iflist *next_if;
1340Sstevel@tonic-gate char ifname[LIFNAMSIZ];
1350Sstevel@tonic-gate struct ifstat tot;
1360Sstevel@tonic-gate };
1370Sstevel@tonic-gate
1380Sstevel@tonic-gate static mib_item_t *mibget(int sd);
1390Sstevel@tonic-gate static void mibfree(mib_item_t *firstitem);
1400Sstevel@tonic-gate static int mibopen(void);
1410Sstevel@tonic-gate static void mib_get_constants(mib_item_t *item);
1420Sstevel@tonic-gate static mib_item_t *mib_item_dup(mib_item_t *item);
1430Sstevel@tonic-gate static mib_item_t *mib_item_diff(mib_item_t *item1,
1440Sstevel@tonic-gate mib_item_t *item2);
1450Sstevel@tonic-gate static void mib_item_destroy(mib_item_t **item);
1460Sstevel@tonic-gate
1470Sstevel@tonic-gate static boolean_t octetstrmatch(const Octet_t *a, const Octet_t *b);
1481676Sjpk static char *octetstr(const Octet_t *op, int code,
1490Sstevel@tonic-gate char *dst, uint_t dstlen);
1500Sstevel@tonic-gate static char *pr_addr(uint_t addr,
1510Sstevel@tonic-gate char *dst, uint_t dstlen);
1520Sstevel@tonic-gate static char *pr_addrnz(ipaddr_t addr, char *dst, uint_t dstlen);
1530Sstevel@tonic-gate static char *pr_addr6(const in6_addr_t *addr,
1540Sstevel@tonic-gate char *dst, uint_t dstlen);
1550Sstevel@tonic-gate static char *pr_mask(uint_t addr,
1560Sstevel@tonic-gate char *dst, uint_t dstlen);
1571676Sjpk static char *pr_prefix6(const struct in6_addr *addr,
1581676Sjpk uint_t prefixlen, char *dst, uint_t dstlen);
1590Sstevel@tonic-gate static char *pr_ap(uint_t addr, uint_t port,
1600Sstevel@tonic-gate char *proto, char *dst, uint_t dstlen);
1610Sstevel@tonic-gate static char *pr_ap6(const in6_addr_t *addr, uint_t port,
1620Sstevel@tonic-gate char *proto, char *dst, uint_t dstlen);
1630Sstevel@tonic-gate static char *pr_net(uint_t addr, uint_t mask,
1640Sstevel@tonic-gate char *dst, uint_t dstlen);
1650Sstevel@tonic-gate static char *pr_netaddr(uint_t addr, uint_t mask,
1660Sstevel@tonic-gate char *dst, uint_t dstlen);
1670Sstevel@tonic-gate static char *fmodestr(uint_t fmode);
1680Sstevel@tonic-gate static char *portname(uint_t port, char *proto,
1690Sstevel@tonic-gate char *dst, uint_t dstlen);
1700Sstevel@tonic-gate
1711676Sjpk static const char *mitcp_state(int code,
1721676Sjpk const mib2_transportMLPEntry_t *attr);
1731676Sjpk static const char *miudp_state(int code,
1741676Sjpk const mib2_transportMLPEntry_t *attr);
1750Sstevel@tonic-gate
1760Sstevel@tonic-gate static void stat_report(mib_item_t *item);
1770Sstevel@tonic-gate static void mrt_stat_report(mib_item_t *item);
1780Sstevel@tonic-gate static void arp_report(mib_item_t *item);
1790Sstevel@tonic-gate static void ndp_report(mib_item_t *item);
1800Sstevel@tonic-gate static void mrt_report(mib_item_t *item);
1810Sstevel@tonic-gate static void if_stat_total(struct ifstat *oldstats,
1820Sstevel@tonic-gate struct ifstat *newstats, struct ifstat *sumstats);
1830Sstevel@tonic-gate static void if_report(mib_item_t *item, char *ifname,
1840Sstevel@tonic-gate int Iflag_only, boolean_t once_only);
1850Sstevel@tonic-gate static void if_report_ip4(mib2_ipAddrEntry_t *ap,
1860Sstevel@tonic-gate char ifname[], char logintname[],
1870Sstevel@tonic-gate struct ifstat *statptr, boolean_t ksp_not_null);
1880Sstevel@tonic-gate static void if_report_ip6(mib2_ipv6AddrEntry_t *ap6,
1890Sstevel@tonic-gate char ifname[], char logintname[],
1900Sstevel@tonic-gate struct ifstat *statptr, boolean_t ksp_not_null);
1911676Sjpk static void ire_report(const mib_item_t *item);
1921676Sjpk static void tcp_report(const mib_item_t *item);
1931676Sjpk static void udp_report(const mib_item_t *item);
1940Sstevel@tonic-gate static void group_report(mib_item_t *item);
19511042SErik.Nordmark@Sun.COM static void dce_report(mib_item_t *item);
1960Sstevel@tonic-gate static void print_ip_stats(mib2_ip_t *ip);
1970Sstevel@tonic-gate static void print_icmp_stats(mib2_icmp_t *icmp);
1980Sstevel@tonic-gate static void print_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6);
1990Sstevel@tonic-gate static void print_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6);
2000Sstevel@tonic-gate static void print_sctp_stats(mib2_sctp_t *tcp);
2010Sstevel@tonic-gate static void print_tcp_stats(mib2_tcp_t *tcp);
2020Sstevel@tonic-gate static void print_udp_stats(mib2_udp_t *udp);
2030Sstevel@tonic-gate static void print_rawip_stats(mib2_rawip_t *rawip);
2040Sstevel@tonic-gate static void print_igmp_stats(struct igmpstat *igps);
2050Sstevel@tonic-gate static void print_mrt_stats(struct mrtstat *mrts);
2061676Sjpk static void sctp_report(const mib_item_t *item);
2070Sstevel@tonic-gate static void sum_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6,
2080Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t *sum6);
2090Sstevel@tonic-gate static void sum_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6,
2100Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t *sum6);
2110Sstevel@tonic-gate static void m_report(void);
2120Sstevel@tonic-gate static void dhcp_report(char *);
2130Sstevel@tonic-gate
2140Sstevel@tonic-gate static uint64_t kstat_named_value(kstat_t *, char *);
2150Sstevel@tonic-gate static kid_t safe_kstat_read(kstat_ctl_t *, kstat_t *, void *);
2160Sstevel@tonic-gate static int isnum(char *);
2170Sstevel@tonic-gate static char *plural(int n);
2180Sstevel@tonic-gate static char *pluraly(int n);
2190Sstevel@tonic-gate static char *plurales(int n);
2200Sstevel@tonic-gate static void process_filter(char *arg);
2218485SPeter.Memishian@Sun.COM static char *ifindex2str(uint_t, char *);
2220Sstevel@tonic-gate static boolean_t family_selected(int family);
2230Sstevel@tonic-gate
2240Sstevel@tonic-gate static void usage(char *);
2250Sstevel@tonic-gate static void fatal(int errcode, char *str1, ...);
2260Sstevel@tonic-gate
2270Sstevel@tonic-gate #define PLURAL(n) plural((int)n)
2280Sstevel@tonic-gate #define PLURALY(n) pluraly((int)n)
2290Sstevel@tonic-gate #define PLURALES(n) plurales((int)n)
2300Sstevel@tonic-gate #define IFLAGMOD(flg, val1, val2) if (flg == val1) flg = val2
2310Sstevel@tonic-gate #define MDIFF(diff, elem2, elem1, member) (diff)->member = \
2320Sstevel@tonic-gate (elem2)->member - (elem1)->member
2330Sstevel@tonic-gate
2340Sstevel@tonic-gate
2350Sstevel@tonic-gate static boolean_t Aflag = B_FALSE; /* All sockets/ifs/rtng-tbls */
23611042SErik.Nordmark@Sun.COM static boolean_t Dflag = B_FALSE; /* DCE info */
2370Sstevel@tonic-gate static boolean_t Iflag = B_FALSE; /* IP Traffic Interfaces */
2380Sstevel@tonic-gate static boolean_t Mflag = B_FALSE; /* STREAMS Memory Statistics */
2390Sstevel@tonic-gate static boolean_t Nflag = B_FALSE; /* Numeric Network Addresses */
2400Sstevel@tonic-gate static boolean_t Rflag = B_FALSE; /* Routing Tables */
2411676Sjpk static boolean_t RSECflag = B_FALSE; /* Security attributes */
2420Sstevel@tonic-gate static boolean_t Sflag = B_FALSE; /* Per-protocol Statistics */
2430Sstevel@tonic-gate static boolean_t Vflag = B_FALSE; /* Verbose */
2440Sstevel@tonic-gate static boolean_t Pflag = B_FALSE; /* Net to Media Tables */
2450Sstevel@tonic-gate static boolean_t Gflag = B_FALSE; /* Multicast group membership */
2460Sstevel@tonic-gate static boolean_t MMflag = B_FALSE; /* Multicast routing table */
2470Sstevel@tonic-gate static boolean_t DHCPflag = B_FALSE; /* DHCP statistics */
24811042SErik.Nordmark@Sun.COM static boolean_t Xflag = B_FALSE; /* Debug Info */
2490Sstevel@tonic-gate
2500Sstevel@tonic-gate static int v4compat = 0; /* Compatible printing format for status */
2510Sstevel@tonic-gate
2520Sstevel@tonic-gate static int proto = IPPROTO_MAX; /* all protocols */
2530Sstevel@tonic-gate kstat_ctl_t *kc = NULL;
2540Sstevel@tonic-gate
2550Sstevel@tonic-gate /*
2560Sstevel@tonic-gate * Sizes of data structures extracted from the base mib.
2570Sstevel@tonic-gate * This allows the size of the tables entries to grow while preserving
2580Sstevel@tonic-gate * binary compatibility.
2590Sstevel@tonic-gate */
2600Sstevel@tonic-gate static int ipAddrEntrySize;
2610Sstevel@tonic-gate static int ipRouteEntrySize;
2620Sstevel@tonic-gate static int ipNetToMediaEntrySize;
2630Sstevel@tonic-gate static int ipMemberEntrySize;
2640Sstevel@tonic-gate static int ipGroupSourceEntrySize;
2651676Sjpk static int ipRouteAttributeSize;
2660Sstevel@tonic-gate static int vifctlSize;
2670Sstevel@tonic-gate static int mfcctlSize;
2680Sstevel@tonic-gate
2690Sstevel@tonic-gate static int ipv6IfStatsEntrySize;
2700Sstevel@tonic-gate static int ipv6IfIcmpEntrySize;
2710Sstevel@tonic-gate static int ipv6AddrEntrySize;
2720Sstevel@tonic-gate static int ipv6RouteEntrySize;
2730Sstevel@tonic-gate static int ipv6NetToMediaEntrySize;
2740Sstevel@tonic-gate static int ipv6MemberEntrySize;
2750Sstevel@tonic-gate static int ipv6GroupSourceEntrySize;
2760Sstevel@tonic-gate
27711042SErik.Nordmark@Sun.COM static int ipDestEntrySize;
27811042SErik.Nordmark@Sun.COM
2791676Sjpk static int transportMLPSize;
2800Sstevel@tonic-gate static int tcpConnEntrySize;
2810Sstevel@tonic-gate static int tcp6ConnEntrySize;
2820Sstevel@tonic-gate static int udpEntrySize;
2830Sstevel@tonic-gate static int udp6EntrySize;
2840Sstevel@tonic-gate static int sctpEntrySize;
2850Sstevel@tonic-gate static int sctpLocalEntrySize;
2860Sstevel@tonic-gate static int sctpRemoteEntrySize;
2870Sstevel@tonic-gate
2880Sstevel@tonic-gate #define protocol_selected(p) (proto == IPPROTO_MAX || proto == (p))
2890Sstevel@tonic-gate
2900Sstevel@tonic-gate /* Machinery used for -f (filter) option */
2914823Sseb enum { FK_AF = 0, FK_OUTIF, FK_DST, FK_FLAGS, NFILTERKEYS };
2920Sstevel@tonic-gate
2930Sstevel@tonic-gate static const char *filter_keys[NFILTERKEYS] = {
2944823Sseb "af", "outif", "dst", "flags"
2950Sstevel@tonic-gate };
2960Sstevel@tonic-gate
2979710SKen.Powell@Sun.COM static m_label_t *zone_security_label = NULL;
2989710SKen.Powell@Sun.COM
2990Sstevel@tonic-gate /* Flags on routes */
3000Sstevel@tonic-gate #define FLF_A 0x00000001
30111042SErik.Nordmark@Sun.COM #define FLF_b 0x00000002
3020Sstevel@tonic-gate #define FLF_D 0x00000004
3030Sstevel@tonic-gate #define FLF_G 0x00000008
3040Sstevel@tonic-gate #define FLF_H 0x00000010
3050Sstevel@tonic-gate #define FLF_L 0x00000020
3060Sstevel@tonic-gate #define FLF_U 0x00000040
3070Sstevel@tonic-gate #define FLF_M 0x00000080
3080Sstevel@tonic-gate #define FLF_S 0x00000100
30911042SErik.Nordmark@Sun.COM #define FLF_C 0x00000200 /* IRE_IF_CLONE */
31011042SErik.Nordmark@Sun.COM #define FLF_I 0x00000400 /* RTF_INDIRECT */
31111042SErik.Nordmark@Sun.COM #define FLF_R 0x00000800 /* RTF_REJECT */
31211042SErik.Nordmark@Sun.COM #define FLF_B 0x00001000 /* RTF_BLACKHOLE */
31312748SSowmini.Varadhan@oracle.COM #define FLF_Z 0x00100000 /* RTF_ZONE */
31412748SSowmini.Varadhan@oracle.COM
31512748SSowmini.Varadhan@oracle.COM static const char flag_list[] = "AbDGHLUMSCIRBZ";
3160Sstevel@tonic-gate
3170Sstevel@tonic-gate typedef struct filter_rule filter_t;
3180Sstevel@tonic-gate
3190Sstevel@tonic-gate struct filter_rule {
3200Sstevel@tonic-gate filter_t *f_next;
3210Sstevel@tonic-gate union {
3220Sstevel@tonic-gate int f_family;
3230Sstevel@tonic-gate const char *f_ifname;
3240Sstevel@tonic-gate struct {
3250Sstevel@tonic-gate struct hostent *f_address;
3260Sstevel@tonic-gate in6_addr_t f_mask;
3270Sstevel@tonic-gate } a;
3280Sstevel@tonic-gate struct {
3290Sstevel@tonic-gate uint_t f_flagset;
3300Sstevel@tonic-gate uint_t f_flagclear;
3310Sstevel@tonic-gate } f;
3320Sstevel@tonic-gate } u;
3330Sstevel@tonic-gate };
3340Sstevel@tonic-gate
3350Sstevel@tonic-gate /*
3360Sstevel@tonic-gate * The user-specified filters are linked into lists separated by
3370Sstevel@tonic-gate * keyword (type of filter). Thus, the matching algorithm is:
3380Sstevel@tonic-gate * For each non-empty filter list
3390Sstevel@tonic-gate * If no filters in the list match
3400Sstevel@tonic-gate * then stop here; route doesn't match
3410Sstevel@tonic-gate * If loop above completes, then route does match and will be
3420Sstevel@tonic-gate * displayed.
3430Sstevel@tonic-gate */
3440Sstevel@tonic-gate static filter_t *filters[NFILTERKEYS];
3450Sstevel@tonic-gate
34610265SKrishnendu.Sadhukhan@Sun.COM static uint_t timestamp_fmt = NODATE;
34710265SKrishnendu.Sadhukhan@Sun.COM
34810265SKrishnendu.Sadhukhan@Sun.COM #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
34910265SKrishnendu.Sadhukhan@Sun.COM #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it isn't */
35010265SKrishnendu.Sadhukhan@Sun.COM #endif
35110265SKrishnendu.Sadhukhan@Sun.COM
3520Sstevel@tonic-gate int
main(int argc,char ** argv)3530Sstevel@tonic-gate main(int argc, char **argv)
3540Sstevel@tonic-gate {
3550Sstevel@tonic-gate char *name;
3560Sstevel@tonic-gate mib_item_t *item = NULL;
3570Sstevel@tonic-gate mib_item_t *previtem = NULL;
3580Sstevel@tonic-gate int sd = -1;
3590Sstevel@tonic-gate char *ifname = NULL;
3600Sstevel@tonic-gate int interval = 0; /* Single time by default */
3610Sstevel@tonic-gate int count = -1; /* Forever */
3620Sstevel@tonic-gate int c;
3630Sstevel@tonic-gate int d;
3640Sstevel@tonic-gate /*
3650Sstevel@tonic-gate * Possible values of 'Iflag_only':
3660Sstevel@tonic-gate * -1, no feature-flags;
3670Sstevel@tonic-gate * 0, IFlag and other feature-flags enabled
3680Sstevel@tonic-gate * 1, IFlag is the only feature-flag enabled
3690Sstevel@tonic-gate * : trinary variable, modified using IFLAGMOD()
3700Sstevel@tonic-gate */
3710Sstevel@tonic-gate int Iflag_only = -1;
3720Sstevel@tonic-gate boolean_t once_only = B_FALSE; /* '-i' with count > 1 */
3730Sstevel@tonic-gate extern char *optarg;
3740Sstevel@tonic-gate extern int optind;
3750Sstevel@tonic-gate char *default_ip_str = NULL;
3760Sstevel@tonic-gate
3770Sstevel@tonic-gate name = argv[0];
3780Sstevel@tonic-gate
3790Sstevel@tonic-gate v4compat = get_compat_flag(&default_ip_str);
3800Sstevel@tonic-gate if (v4compat == DEFAULT_PROT_BAD_VALUE)
3810Sstevel@tonic-gate fatal(2, "%s: %s: Bad value for %s in %s\n", name,
3820Sstevel@tonic-gate default_ip_str, DEFAULT_IP, INET_DEFAULT_FILE);
3830Sstevel@tonic-gate free(default_ip_str);
3840Sstevel@tonic-gate
38510265SKrishnendu.Sadhukhan@Sun.COM (void) setlocale(LC_ALL, "");
38610265SKrishnendu.Sadhukhan@Sun.COM (void) textdomain(TEXT_DOMAIN);
38710265SKrishnendu.Sadhukhan@Sun.COM
38811042SErik.Nordmark@Sun.COM while ((c = getopt(argc, argv, "adimnrspMgvxf:P:I:DRT:")) != -1) {
3890Sstevel@tonic-gate switch ((char)c) {
3900Sstevel@tonic-gate case 'a': /* all connections */
3910Sstevel@tonic-gate Aflag = B_TRUE;
3920Sstevel@tonic-gate break;
3930Sstevel@tonic-gate
39411042SErik.Nordmark@Sun.COM case 'd': /* DCE info */
3950Sstevel@tonic-gate Dflag = B_TRUE;
39611042SErik.Nordmark@Sun.COM IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
3970Sstevel@tonic-gate break;
3980Sstevel@tonic-gate
3990Sstevel@tonic-gate case 'i': /* interface (ill/ipif report) */
4000Sstevel@tonic-gate Iflag = B_TRUE;
4010Sstevel@tonic-gate IFLAGMOD(Iflag_only, -1, 1); /* '-i' exists */
4020Sstevel@tonic-gate break;
4030Sstevel@tonic-gate
4040Sstevel@tonic-gate case 'm': /* streams msg report */
4050Sstevel@tonic-gate Mflag = B_TRUE;
4060Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
4070Sstevel@tonic-gate break;
4080Sstevel@tonic-gate
4090Sstevel@tonic-gate case 'n': /* numeric format */
4100Sstevel@tonic-gate Nflag = B_TRUE;
4110Sstevel@tonic-gate break;
4120Sstevel@tonic-gate
4130Sstevel@tonic-gate case 'r': /* route tables */
4140Sstevel@tonic-gate Rflag = B_TRUE;
4150Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
4160Sstevel@tonic-gate break;
4170Sstevel@tonic-gate
4181676Sjpk case 'R': /* security attributes */
4191676Sjpk RSECflag = B_TRUE;
4201676Sjpk IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
4211676Sjpk break;
4221676Sjpk
4230Sstevel@tonic-gate case 's': /* per-protocol statistics */
4240Sstevel@tonic-gate Sflag = B_TRUE;
4250Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
4260Sstevel@tonic-gate break;
4270Sstevel@tonic-gate
4280Sstevel@tonic-gate case 'p': /* arp/ndp table */
4290Sstevel@tonic-gate Pflag = B_TRUE;
4300Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
4310Sstevel@tonic-gate break;
4320Sstevel@tonic-gate
4330Sstevel@tonic-gate case 'M': /* multicast routing tables */
4340Sstevel@tonic-gate MMflag = B_TRUE;
4350Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
4360Sstevel@tonic-gate break;
4370Sstevel@tonic-gate
4380Sstevel@tonic-gate case 'g': /* multicast group membership */
4390Sstevel@tonic-gate Gflag = B_TRUE;
4400Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
4410Sstevel@tonic-gate break;
4420Sstevel@tonic-gate
4430Sstevel@tonic-gate case 'v': /* verbose output format */
4440Sstevel@tonic-gate Vflag = B_TRUE;
4450Sstevel@tonic-gate IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
4460Sstevel@tonic-gate break;
4470Sstevel@tonic-gate
44811042SErik.Nordmark@Sun.COM case 'x': /* turn on debugging */
44911042SErik.Nordmark@Sun.COM Xflag = B_TRUE;
45011042SErik.Nordmark@Sun.COM break;
45111042SErik.Nordmark@Sun.COM
4520Sstevel@tonic-gate case 'f':
4530Sstevel@tonic-gate process_filter(optarg);
4540Sstevel@tonic-gate break;
4550Sstevel@tonic-gate
4560Sstevel@tonic-gate case 'P':
4570Sstevel@tonic-gate if (strcmp(optarg, "ip") == 0) {
4580Sstevel@tonic-gate proto = IPPROTO_IP;
4590Sstevel@tonic-gate } else if (strcmp(optarg, "ipv6") == 0 ||
4600Sstevel@tonic-gate strcmp(optarg, "ip6") == 0) {
4610Sstevel@tonic-gate v4compat = 0; /* Overridden */
4620Sstevel@tonic-gate proto = IPPROTO_IPV6;
4630Sstevel@tonic-gate } else if (strcmp(optarg, "icmp") == 0) {
4640Sstevel@tonic-gate proto = IPPROTO_ICMP;
4650Sstevel@tonic-gate } else if (strcmp(optarg, "icmpv6") == 0 ||
4660Sstevel@tonic-gate strcmp(optarg, "icmp6") == 0) {
4670Sstevel@tonic-gate v4compat = 0; /* Overridden */
4680Sstevel@tonic-gate proto = IPPROTO_ICMPV6;
4690Sstevel@tonic-gate } else if (strcmp(optarg, "igmp") == 0) {
4700Sstevel@tonic-gate proto = IPPROTO_IGMP;
4710Sstevel@tonic-gate } else if (strcmp(optarg, "udp") == 0) {
4720Sstevel@tonic-gate proto = IPPROTO_UDP;
4730Sstevel@tonic-gate } else if (strcmp(optarg, "tcp") == 0) {
4740Sstevel@tonic-gate proto = IPPROTO_TCP;
4750Sstevel@tonic-gate } else if (strcmp(optarg, "sctp") == 0) {
4760Sstevel@tonic-gate proto = IPPROTO_SCTP;
4770Sstevel@tonic-gate } else if (strcmp(optarg, "raw") == 0 ||
4780Sstevel@tonic-gate strcmp(optarg, "rawip") == 0) {
4790Sstevel@tonic-gate proto = IPPROTO_RAW;
4800Sstevel@tonic-gate } else {
4810Sstevel@tonic-gate fatal(1, "%s: unknown protocol.\n", optarg);
4820Sstevel@tonic-gate }
4830Sstevel@tonic-gate break;
4840Sstevel@tonic-gate
4850Sstevel@tonic-gate case 'I':
4860Sstevel@tonic-gate ifname = optarg;
4870Sstevel@tonic-gate Iflag = B_TRUE;
4880Sstevel@tonic-gate IFLAGMOD(Iflag_only, -1, 1); /* see macro def'n */
4890Sstevel@tonic-gate break;
4900Sstevel@tonic-gate
4910Sstevel@tonic-gate case 'D':
4920Sstevel@tonic-gate DHCPflag = B_TRUE;
4930Sstevel@tonic-gate Iflag_only = 0;
4940Sstevel@tonic-gate break;
4950Sstevel@tonic-gate
49610265SKrishnendu.Sadhukhan@Sun.COM case 'T':
49710265SKrishnendu.Sadhukhan@Sun.COM if (optarg) {
49810265SKrishnendu.Sadhukhan@Sun.COM if (*optarg == 'u')
49910265SKrishnendu.Sadhukhan@Sun.COM timestamp_fmt = UDATE;
50010265SKrishnendu.Sadhukhan@Sun.COM else if (*optarg == 'd')
50110265SKrishnendu.Sadhukhan@Sun.COM timestamp_fmt = DDATE;
50210265SKrishnendu.Sadhukhan@Sun.COM else
50310265SKrishnendu.Sadhukhan@Sun.COM usage(name);
50410265SKrishnendu.Sadhukhan@Sun.COM } else {
50510265SKrishnendu.Sadhukhan@Sun.COM usage(name);
50610265SKrishnendu.Sadhukhan@Sun.COM }
50710265SKrishnendu.Sadhukhan@Sun.COM break;
50810265SKrishnendu.Sadhukhan@Sun.COM
5090Sstevel@tonic-gate case '?':
5100Sstevel@tonic-gate default:
5110Sstevel@tonic-gate usage(name);
5120Sstevel@tonic-gate }
5130Sstevel@tonic-gate }
5140Sstevel@tonic-gate
5150Sstevel@tonic-gate /*
5161676Sjpk * Make sure -R option is set only on a labeled system.
5171676Sjpk */
5181676Sjpk if (RSECflag && !is_system_labeled()) {
5191676Sjpk (void) fprintf(stderr, "-R set but labeling is not enabled\n");
5201676Sjpk usage(name);
5211676Sjpk }
5221676Sjpk
5231676Sjpk /*
5240Sstevel@tonic-gate * Handle other arguments: find interval, count; the
5250Sstevel@tonic-gate * flags that accept 'interval' and 'count' are OR'd
5260Sstevel@tonic-gate * in the outermost 'if'; more flags may be added as
5270Sstevel@tonic-gate * required
5280Sstevel@tonic-gate */
5290Sstevel@tonic-gate if (Iflag || Sflag || Mflag) {
5300Sstevel@tonic-gate for (d = optind; d < argc; d++) {
5310Sstevel@tonic-gate if (isnum(argv[d])) {
5320Sstevel@tonic-gate interval = atoi(argv[d]);
5330Sstevel@tonic-gate if (d + 1 < argc &&
5340Sstevel@tonic-gate isnum(argv[d + 1])) {
5350Sstevel@tonic-gate count = atoi(argv[d + 1]);
5360Sstevel@tonic-gate optind++;
5370Sstevel@tonic-gate }
5380Sstevel@tonic-gate optind++;
5390Sstevel@tonic-gate if (interval == 0 || count == 0)
5400Sstevel@tonic-gate usage(name);
5410Sstevel@tonic-gate break;
5420Sstevel@tonic-gate }
5430Sstevel@tonic-gate }
5440Sstevel@tonic-gate }
5450Sstevel@tonic-gate if (optind < argc) {
5460Sstevel@tonic-gate if (Iflag && isnum(argv[optind])) {
5470Sstevel@tonic-gate count = atoi(argv[optind]);
5480Sstevel@tonic-gate if (count == 0)
5490Sstevel@tonic-gate usage(name);
5500Sstevel@tonic-gate optind++;
5510Sstevel@tonic-gate }
5520Sstevel@tonic-gate }
5530Sstevel@tonic-gate if (optind < argc) {
5540Sstevel@tonic-gate (void) fprintf(stderr,
5550Sstevel@tonic-gate "%s: extra arguments\n", name);
5560Sstevel@tonic-gate usage(name);
5570Sstevel@tonic-gate }
5580Sstevel@tonic-gate if (interval)
5590Sstevel@tonic-gate setbuf(stdout, NULL);
5600Sstevel@tonic-gate
5610Sstevel@tonic-gate if (DHCPflag) {
5620Sstevel@tonic-gate dhcp_report(Iflag ? ifname : NULL);
5630Sstevel@tonic-gate exit(0);
5640Sstevel@tonic-gate }
5650Sstevel@tonic-gate
5669710SKen.Powell@Sun.COM /*
5679710SKen.Powell@Sun.COM * Get this process's security label if the -R switch is set.
5689710SKen.Powell@Sun.COM * We use this label as the current zone's security label.
5699710SKen.Powell@Sun.COM */
5709710SKen.Powell@Sun.COM if (RSECflag) {
5719710SKen.Powell@Sun.COM zone_security_label = m_label_alloc(MAC_LABEL);
5729710SKen.Powell@Sun.COM if (zone_security_label == NULL)
5739710SKen.Powell@Sun.COM fatal(errno, "m_label_alloc() failed");
5749710SKen.Powell@Sun.COM if (getplabel(zone_security_label) < 0)
5759710SKen.Powell@Sun.COM fatal(errno, "getplabel() failed");
5769710SKen.Powell@Sun.COM }
5779710SKen.Powell@Sun.COM
5780Sstevel@tonic-gate /* Get data structures: priming before iteration */
5790Sstevel@tonic-gate if (family_selected(AF_INET) || family_selected(AF_INET6)) {
5800Sstevel@tonic-gate sd = mibopen();
5810Sstevel@tonic-gate if (sd == -1)
5820Sstevel@tonic-gate fatal(1, "can't open mib stream\n");
5830Sstevel@tonic-gate if ((item = mibget(sd)) == NULL) {
5840Sstevel@tonic-gate (void) close(sd);
5850Sstevel@tonic-gate fatal(1, "mibget() failed\n");
5860Sstevel@tonic-gate }
5870Sstevel@tonic-gate /* Extract constant sizes - need do once only */
5880Sstevel@tonic-gate mib_get_constants(item);
5890Sstevel@tonic-gate }
5900Sstevel@tonic-gate if ((kc = kstat_open()) == NULL) {
5910Sstevel@tonic-gate mibfree(item);
5920Sstevel@tonic-gate (void) close(sd);
5930Sstevel@tonic-gate fail(1, "kstat_open(): can't open /dev/kstat");
5940Sstevel@tonic-gate }
5950Sstevel@tonic-gate
5960Sstevel@tonic-gate if (interval <= 0) {
5970Sstevel@tonic-gate count = 1;
5980Sstevel@tonic-gate once_only = B_TRUE;
5990Sstevel@tonic-gate }
6000Sstevel@tonic-gate /* 'for' loop 1: */
6010Sstevel@tonic-gate for (;;) {
6020Sstevel@tonic-gate mib_item_t *curritem = NULL; /* only for -[M]s */
6030Sstevel@tonic-gate
60410265SKrishnendu.Sadhukhan@Sun.COM if (timestamp_fmt != NODATE)
60510265SKrishnendu.Sadhukhan@Sun.COM print_timestamp(timestamp_fmt);
60610265SKrishnendu.Sadhukhan@Sun.COM
6070Sstevel@tonic-gate /* netstat: AF_INET[6] behaviour */
6080Sstevel@tonic-gate if (family_selected(AF_INET) || family_selected(AF_INET6)) {
6090Sstevel@tonic-gate if (Sflag) {
6100Sstevel@tonic-gate curritem = mib_item_diff(previtem, item);
6110Sstevel@tonic-gate if (curritem == NULL)
6120Sstevel@tonic-gate fatal(1, "can't process mib data, "
6130Sstevel@tonic-gate "out of memory\n");
6140Sstevel@tonic-gate mib_item_destroy(&previtem);
6150Sstevel@tonic-gate }
6160Sstevel@tonic-gate
61711042SErik.Nordmark@Sun.COM if (!(Dflag || Iflag || Rflag || Sflag || Mflag ||
6180Sstevel@tonic-gate MMflag || Pflag || Gflag || DHCPflag)) {
6190Sstevel@tonic-gate if (protocol_selected(IPPROTO_UDP))
6200Sstevel@tonic-gate udp_report(item);
6210Sstevel@tonic-gate if (protocol_selected(IPPROTO_TCP))
6220Sstevel@tonic-gate tcp_report(item);
6230Sstevel@tonic-gate if (protocol_selected(IPPROTO_SCTP))
6240Sstevel@tonic-gate sctp_report(item);
6250Sstevel@tonic-gate }
6260Sstevel@tonic-gate if (Iflag)
6270Sstevel@tonic-gate if_report(item, ifname, Iflag_only, once_only);
6280Sstevel@tonic-gate if (Mflag)
6290Sstevel@tonic-gate m_report();
6300Sstevel@tonic-gate if (Rflag)
6310Sstevel@tonic-gate ire_report(item);
6320Sstevel@tonic-gate if (Sflag && MMflag) {
6330Sstevel@tonic-gate mrt_stat_report(curritem);
6340Sstevel@tonic-gate } else {
6350Sstevel@tonic-gate if (Sflag)
6360Sstevel@tonic-gate stat_report(curritem);
6370Sstevel@tonic-gate if (MMflag)
6380Sstevel@tonic-gate mrt_report(item);
6390Sstevel@tonic-gate }
6400Sstevel@tonic-gate if (Gflag)
6410Sstevel@tonic-gate group_report(item);
6420Sstevel@tonic-gate if (Pflag) {
6430Sstevel@tonic-gate if (family_selected(AF_INET))
6440Sstevel@tonic-gate arp_report(item);
6450Sstevel@tonic-gate if (family_selected(AF_INET6))
6460Sstevel@tonic-gate ndp_report(item);
6470Sstevel@tonic-gate }
64811042SErik.Nordmark@Sun.COM if (Dflag)
64911042SErik.Nordmark@Sun.COM dce_report(item);
6500Sstevel@tonic-gate mib_item_destroy(&curritem);
6510Sstevel@tonic-gate }
6520Sstevel@tonic-gate
6530Sstevel@tonic-gate /* netstat: AF_UNIX behaviour */
6540Sstevel@tonic-gate if (family_selected(AF_UNIX) &&
65511042SErik.Nordmark@Sun.COM (!(Dflag || Iflag || Rflag || Sflag || Mflag ||
6560Sstevel@tonic-gate MMflag || Pflag || Gflag)))
6570Sstevel@tonic-gate unixpr(kc);
6580Sstevel@tonic-gate (void) kstat_close(kc);
6590Sstevel@tonic-gate
6600Sstevel@tonic-gate /* iteration handling code */
6610Sstevel@tonic-gate if (count > 0 && --count == 0)
6620Sstevel@tonic-gate break;
6630Sstevel@tonic-gate (void) sleep(interval);
6640Sstevel@tonic-gate
6650Sstevel@tonic-gate /* re-populating of data structures */
6660Sstevel@tonic-gate if (family_selected(AF_INET) || family_selected(AF_INET6)) {
6670Sstevel@tonic-gate if (Sflag) {
6680Sstevel@tonic-gate /* previtem is a cut-down list */
6690Sstevel@tonic-gate previtem = mib_item_dup(item);
6700Sstevel@tonic-gate if (previtem == NULL)
6710Sstevel@tonic-gate fatal(1, "can't process mib data, "
6720Sstevel@tonic-gate "out of memory\n");
6730Sstevel@tonic-gate }
6740Sstevel@tonic-gate mibfree(item);
6750Sstevel@tonic-gate (void) close(sd);
6760Sstevel@tonic-gate if ((sd = mibopen()) == -1)
6770Sstevel@tonic-gate fatal(1, "can't open mib stream anymore\n");
6780Sstevel@tonic-gate if ((item = mibget(sd)) == NULL) {
6790Sstevel@tonic-gate (void) close(sd);
6800Sstevel@tonic-gate fatal(1, "mibget() failed\n");
6810Sstevel@tonic-gate }
6820Sstevel@tonic-gate }
6830Sstevel@tonic-gate if ((kc = kstat_open()) == NULL)
6840Sstevel@tonic-gate fail(1, "kstat_open(): can't open /dev/kstat");
6850Sstevel@tonic-gate
6860Sstevel@tonic-gate } /* 'for' loop 1 ends */
6870Sstevel@tonic-gate mibfree(item);
6880Sstevel@tonic-gate (void) close(sd);
6899710SKen.Powell@Sun.COM if (zone_security_label != NULL)
6909710SKen.Powell@Sun.COM m_label_free(zone_security_label);
6910Sstevel@tonic-gate
6920Sstevel@tonic-gate return (0);
6930Sstevel@tonic-gate }
6940Sstevel@tonic-gate
6950Sstevel@tonic-gate
6960Sstevel@tonic-gate static int
isnum(char * p)6970Sstevel@tonic-gate isnum(char *p)
6980Sstevel@tonic-gate {
6990Sstevel@tonic-gate int len;
7000Sstevel@tonic-gate int i;
7010Sstevel@tonic-gate
7020Sstevel@tonic-gate len = strlen(p);
7030Sstevel@tonic-gate for (i = 0; i < len; i++)
7040Sstevel@tonic-gate if (!isdigit(p[i]))
7050Sstevel@tonic-gate return (0);
7060Sstevel@tonic-gate return (1);
7070Sstevel@tonic-gate }
7080Sstevel@tonic-gate
7090Sstevel@tonic-gate
7100Sstevel@tonic-gate /* --------------------------------- MIBGET -------------------------------- */
7110Sstevel@tonic-gate
7120Sstevel@tonic-gate static mib_item_t *
mibget(int sd)7130Sstevel@tonic-gate mibget(int sd)
7140Sstevel@tonic-gate {
7150Sstevel@tonic-gate /*
7160Sstevel@tonic-gate * buf is an automatic for this function, so the
7170Sstevel@tonic-gate * compiler has complete control over its alignment;
7180Sstevel@tonic-gate * it is assumed this alignment is satisfactory for
7190Sstevel@tonic-gate * it to be casted to certain other struct pointers
7200Sstevel@tonic-gate * here, such as struct T_optmgmt_ack * .
7210Sstevel@tonic-gate */
7220Sstevel@tonic-gate uintptr_t buf[512 / sizeof (uintptr_t)];
7230Sstevel@tonic-gate int flags;
7240Sstevel@tonic-gate int i, j, getcode;
7250Sstevel@tonic-gate struct strbuf ctlbuf, databuf;
7260Sstevel@tonic-gate struct T_optmgmt_req *tor = (struct T_optmgmt_req *)buf;
7270Sstevel@tonic-gate struct T_optmgmt_ack *toa = (struct T_optmgmt_ack *)buf;
7280Sstevel@tonic-gate struct T_error_ack *tea = (struct T_error_ack *)buf;
7290Sstevel@tonic-gate struct opthdr *req;
7300Sstevel@tonic-gate mib_item_t *first_item = NULL;
7310Sstevel@tonic-gate mib_item_t *last_item = NULL;
7320Sstevel@tonic-gate mib_item_t *temp;
7330Sstevel@tonic-gate
7340Sstevel@tonic-gate tor->PRIM_type = T_SVR4_OPTMGMT_REQ;
7350Sstevel@tonic-gate tor->OPT_offset = sizeof (struct T_optmgmt_req);
7360Sstevel@tonic-gate tor->OPT_length = sizeof (struct opthdr);
7370Sstevel@tonic-gate tor->MGMT_flags = T_CURRENT;
7388485SPeter.Memishian@Sun.COM
7398485SPeter.Memishian@Sun.COM
7408485SPeter.Memishian@Sun.COM /*
7418485SPeter.Memishian@Sun.COM * Note: we use the special level value below so that IP will return
7428485SPeter.Memishian@Sun.COM * us information concerning IRE_MARK_TESTHIDDEN routes.
7438485SPeter.Memishian@Sun.COM */
7440Sstevel@tonic-gate req = (struct opthdr *)&tor[1];
74511042SErik.Nordmark@Sun.COM req->level = EXPER_IP_AND_ALL_IRES;
7460Sstevel@tonic-gate req->name = 0;
747*12897SBaban.Kenkre@Sun.COM req->len = 1;
7480Sstevel@tonic-gate
7490Sstevel@tonic-gate ctlbuf.buf = (char *)buf;
7500Sstevel@tonic-gate ctlbuf.len = tor->OPT_length + tor->OPT_offset;
7510Sstevel@tonic-gate flags = 0;
7520Sstevel@tonic-gate if (putmsg(sd, &ctlbuf, (struct strbuf *)0, flags) == -1) {
7530Sstevel@tonic-gate perror("mibget: putmsg(ctl) failed");
7540Sstevel@tonic-gate goto error_exit;
7550Sstevel@tonic-gate }
7560Sstevel@tonic-gate
7570Sstevel@tonic-gate /*
7580Sstevel@tonic-gate * Each reply consists of a ctl part for one fixed structure
7590Sstevel@tonic-gate * or table, as defined in mib2.h. The format is a T_OPTMGMT_ACK,
7600Sstevel@tonic-gate * containing an opthdr structure. level/name identify the entry,
7610Sstevel@tonic-gate * len is the size of the data part of the message.
7620Sstevel@tonic-gate */
7630Sstevel@tonic-gate req = (struct opthdr *)&toa[1];
7640Sstevel@tonic-gate ctlbuf.maxlen = sizeof (buf);
7650Sstevel@tonic-gate j = 1;
7660Sstevel@tonic-gate for (;;) {
7670Sstevel@tonic-gate flags = 0;
7680Sstevel@tonic-gate getcode = getmsg(sd, &ctlbuf, (struct strbuf *)0, &flags);
7690Sstevel@tonic-gate if (getcode == -1) {
7700Sstevel@tonic-gate perror("mibget getmsg(ctl) failed");
77111042SErik.Nordmark@Sun.COM if (Xflag) {
7720Sstevel@tonic-gate (void) fputs("# level name len\n",
7730Sstevel@tonic-gate stderr);
7740Sstevel@tonic-gate i = 0;
7750Sstevel@tonic-gate for (last_item = first_item; last_item;
7768485SPeter.Memishian@Sun.COM last_item = last_item->next_item)
7770Sstevel@tonic-gate (void) printf("%d %4d %5d %d\n",
7780Sstevel@tonic-gate ++i,
7790Sstevel@tonic-gate last_item->group,
7800Sstevel@tonic-gate last_item->mib_id,
7810Sstevel@tonic-gate last_item->length);
7820Sstevel@tonic-gate }
7830Sstevel@tonic-gate goto error_exit;
7840Sstevel@tonic-gate }
7850Sstevel@tonic-gate if (getcode == 0 &&
7860Sstevel@tonic-gate ctlbuf.len >= sizeof (struct T_optmgmt_ack) &&
7870Sstevel@tonic-gate toa->PRIM_type == T_OPTMGMT_ACK &&
7880Sstevel@tonic-gate toa->MGMT_flags == T_SUCCESS &&
7890Sstevel@tonic-gate req->len == 0) {
79011042SErik.Nordmark@Sun.COM if (Xflag)
7910Sstevel@tonic-gate (void) printf("mibget getmsg() %d returned "
7920Sstevel@tonic-gate "EOD (level %ld, name %ld)\n",
7930Sstevel@tonic-gate j, req->level, req->name);
7940Sstevel@tonic-gate return (first_item); /* this is EOD msg */
7950Sstevel@tonic-gate }
7960Sstevel@tonic-gate
7970Sstevel@tonic-gate if (ctlbuf.len >= sizeof (struct T_error_ack) &&
7980Sstevel@tonic-gate tea->PRIM_type == T_ERROR_ACK) {
7990Sstevel@tonic-gate (void) fprintf(stderr,
8000Sstevel@tonic-gate "mibget %d gives T_ERROR_ACK: TLI_error = 0x%lx, "
8010Sstevel@tonic-gate "UNIX_error = 0x%lx\n",
8020Sstevel@tonic-gate j, tea->TLI_error, tea->UNIX_error);
8030Sstevel@tonic-gate
8040Sstevel@tonic-gate errno = (tea->TLI_error == TSYSERR) ?
8050Sstevel@tonic-gate tea->UNIX_error : EPROTO;
8060Sstevel@tonic-gate goto error_exit;
8070Sstevel@tonic-gate }
8080Sstevel@tonic-gate
8090Sstevel@tonic-gate if (getcode != MOREDATA ||
8100Sstevel@tonic-gate ctlbuf.len < sizeof (struct T_optmgmt_ack) ||
8110Sstevel@tonic-gate toa->PRIM_type != T_OPTMGMT_ACK ||
8120Sstevel@tonic-gate toa->MGMT_flags != T_SUCCESS) {
8130Sstevel@tonic-gate (void) printf("mibget getmsg(ctl) %d returned %d, "
8140Sstevel@tonic-gate "ctlbuf.len = %d, PRIM_type = %ld\n",
8150Sstevel@tonic-gate j, getcode, ctlbuf.len, toa->PRIM_type);
8160Sstevel@tonic-gate
8170Sstevel@tonic-gate if (toa->PRIM_type == T_OPTMGMT_ACK)
8180Sstevel@tonic-gate (void) printf("T_OPTMGMT_ACK: "
8190Sstevel@tonic-gate "MGMT_flags = 0x%lx, req->len = %ld\n",
8200Sstevel@tonic-gate toa->MGMT_flags, req->len);
8210Sstevel@tonic-gate errno = ENOMSG;
8220Sstevel@tonic-gate goto error_exit;
8230Sstevel@tonic-gate }
8240Sstevel@tonic-gate
8250Sstevel@tonic-gate temp = (mib_item_t *)malloc(sizeof (mib_item_t));
8260Sstevel@tonic-gate if (temp == NULL) {
8270Sstevel@tonic-gate perror("mibget malloc failed");
8280Sstevel@tonic-gate goto error_exit;
8290Sstevel@tonic-gate }
8300Sstevel@tonic-gate if (last_item != NULL)
8310Sstevel@tonic-gate last_item->next_item = temp;
8320Sstevel@tonic-gate else
8330Sstevel@tonic-gate first_item = temp;
8340Sstevel@tonic-gate last_item = temp;
8350Sstevel@tonic-gate last_item->next_item = NULL;
8360Sstevel@tonic-gate last_item->group = req->level;
8370Sstevel@tonic-gate last_item->mib_id = req->name;
8380Sstevel@tonic-gate last_item->length = req->len;
8390Sstevel@tonic-gate last_item->valp = malloc((int)req->len);
8400Sstevel@tonic-gate if (last_item->valp == NULL)
8410Sstevel@tonic-gate goto error_exit;
84211042SErik.Nordmark@Sun.COM if (Xflag)
8430Sstevel@tonic-gate (void) printf("msg %d: group = %4d mib_id = %5d"
8440Sstevel@tonic-gate "length = %d\n",
8450Sstevel@tonic-gate j, last_item->group, last_item->mib_id,
8460Sstevel@tonic-gate last_item->length);
8470Sstevel@tonic-gate
8480Sstevel@tonic-gate databuf.maxlen = last_item->length;
8490Sstevel@tonic-gate databuf.buf = (char *)last_item->valp;
8500Sstevel@tonic-gate databuf.len = 0;
8510Sstevel@tonic-gate flags = 0;
8520Sstevel@tonic-gate getcode = getmsg(sd, (struct strbuf *)0, &databuf, &flags);
8530Sstevel@tonic-gate if (getcode == -1) {
8540Sstevel@tonic-gate perror("mibget getmsg(data) failed");
8550Sstevel@tonic-gate goto error_exit;
8560Sstevel@tonic-gate } else if (getcode != 0) {
8570Sstevel@tonic-gate (void) printf("mibget getmsg(data) returned %d, "
8580Sstevel@tonic-gate "databuf.maxlen = %d, databuf.len = %d\n",
8590Sstevel@tonic-gate getcode, databuf.maxlen, databuf.len);
8600Sstevel@tonic-gate goto error_exit;
8610Sstevel@tonic-gate }
8620Sstevel@tonic-gate j++;
8630Sstevel@tonic-gate }
8640Sstevel@tonic-gate /* NOTREACHED */
8650Sstevel@tonic-gate
8660Sstevel@tonic-gate error_exit:;
8670Sstevel@tonic-gate mibfree(first_item);
8680Sstevel@tonic-gate return (NULL);
8690Sstevel@tonic-gate }
8700Sstevel@tonic-gate
8710Sstevel@tonic-gate /*
8720Sstevel@tonic-gate * mibfree: frees a linked list of type (mib_item_t *)
8730Sstevel@tonic-gate * returned by mibget(); this is NOT THE SAME AS
8740Sstevel@tonic-gate * mib_item_destroy(), so should be used for objects
8750Sstevel@tonic-gate * returned by mibget() only
8760Sstevel@tonic-gate */
8770Sstevel@tonic-gate static void
mibfree(mib_item_t * firstitem)8780Sstevel@tonic-gate mibfree(mib_item_t *firstitem)
8790Sstevel@tonic-gate {
8800Sstevel@tonic-gate mib_item_t *lastitem;
8810Sstevel@tonic-gate
8820Sstevel@tonic-gate while (firstitem != NULL) {
8830Sstevel@tonic-gate lastitem = firstitem;
8840Sstevel@tonic-gate firstitem = firstitem->next_item;
8850Sstevel@tonic-gate if (lastitem->valp != NULL)
8860Sstevel@tonic-gate free(lastitem->valp);
8870Sstevel@tonic-gate free(lastitem);
8880Sstevel@tonic-gate }
8890Sstevel@tonic-gate }
8900Sstevel@tonic-gate
8910Sstevel@tonic-gate static int
mibopen(void)8920Sstevel@tonic-gate mibopen(void)
8930Sstevel@tonic-gate {
8940Sstevel@tonic-gate int sd;
8950Sstevel@tonic-gate
8960Sstevel@tonic-gate sd = open("/dev/arp", O_RDWR);
8970Sstevel@tonic-gate if (sd == -1) {
8980Sstevel@tonic-gate perror("arp open");
8990Sstevel@tonic-gate return (-1);
9000Sstevel@tonic-gate }
9010Sstevel@tonic-gate if (ioctl(sd, I_PUSH, "tcp") == -1) {
9020Sstevel@tonic-gate perror("tcp I_PUSH");
9030Sstevel@tonic-gate (void) close(sd);
9040Sstevel@tonic-gate return (-1);
9050Sstevel@tonic-gate }
9060Sstevel@tonic-gate if (ioctl(sd, I_PUSH, "udp") == -1) {
9070Sstevel@tonic-gate perror("udp I_PUSH");
9080Sstevel@tonic-gate (void) close(sd);
9090Sstevel@tonic-gate return (-1);
9100Sstevel@tonic-gate }
9110Sstevel@tonic-gate if (ioctl(sd, I_PUSH, "icmp") == -1) {
9120Sstevel@tonic-gate perror("icmp I_PUSH");
9130Sstevel@tonic-gate (void) close(sd);
9140Sstevel@tonic-gate return (-1);
9150Sstevel@tonic-gate }
9160Sstevel@tonic-gate return (sd);
9170Sstevel@tonic-gate }
9180Sstevel@tonic-gate
9190Sstevel@tonic-gate /*
9200Sstevel@tonic-gate * mib_item_dup: returns a clean mib_item_t * linked
9210Sstevel@tonic-gate * list, so that for every element item->mib_id is 0;
9220Sstevel@tonic-gate * to deallocate this linked list, use mib_item_destroy
9230Sstevel@tonic-gate */
9240Sstevel@tonic-gate static mib_item_t *
mib_item_dup(mib_item_t * item)9250Sstevel@tonic-gate mib_item_dup(mib_item_t *item)
9260Sstevel@tonic-gate {
9270Sstevel@tonic-gate int c = 0;
9280Sstevel@tonic-gate mib_item_t *localp;
9290Sstevel@tonic-gate mib_item_t *tempp;
9300Sstevel@tonic-gate
9310Sstevel@tonic-gate for (tempp = item; tempp; tempp = tempp->next_item)
9320Sstevel@tonic-gate if (tempp->mib_id == 0)
9330Sstevel@tonic-gate c++;
9340Sstevel@tonic-gate tempp = NULL;
9350Sstevel@tonic-gate
9360Sstevel@tonic-gate localp = (mib_item_t *)malloc(c * sizeof (mib_item_t));
9370Sstevel@tonic-gate if (localp == NULL)
9380Sstevel@tonic-gate return (NULL);
9390Sstevel@tonic-gate c = 0;
9400Sstevel@tonic-gate for (; item; item = item->next_item) {
9410Sstevel@tonic-gate if (item->mib_id == 0) {
9420Sstevel@tonic-gate /* Replicate item in localp */
9430Sstevel@tonic-gate (localp[c]).next_item = NULL;
9440Sstevel@tonic-gate (localp[c]).group = item->group;
9450Sstevel@tonic-gate (localp[c]).mib_id = item->mib_id;
9460Sstevel@tonic-gate (localp[c]).length = item->length;
9470Sstevel@tonic-gate (localp[c]).valp = (uintptr_t *)malloc(
9480Sstevel@tonic-gate item->length);
9490Sstevel@tonic-gate if ((localp[c]).valp == NULL) {
9500Sstevel@tonic-gate mib_item_destroy(&localp);
9510Sstevel@tonic-gate return (NULL);
9520Sstevel@tonic-gate }
9530Sstevel@tonic-gate (void *) memcpy((localp[c]).valp,
9540Sstevel@tonic-gate item->valp,
9550Sstevel@tonic-gate item->length);
9560Sstevel@tonic-gate tempp = &(localp[c]);
9570Sstevel@tonic-gate if (c > 0)
9580Sstevel@tonic-gate (localp[c - 1]).next_item = tempp;
9590Sstevel@tonic-gate c++;
9600Sstevel@tonic-gate }
9610Sstevel@tonic-gate }
9620Sstevel@tonic-gate return (localp);
9630Sstevel@tonic-gate }
9640Sstevel@tonic-gate
9650Sstevel@tonic-gate /*
9660Sstevel@tonic-gate * mib_item_diff: takes two (mib_item_t *) linked lists
9670Sstevel@tonic-gate * item1 and item2 and computes the difference between
9680Sstevel@tonic-gate * differentiable values in item2 against item1 for every
9690Sstevel@tonic-gate * given member of item2; returns an mib_item_t * linked
9700Sstevel@tonic-gate * list of diff's, or a copy of item2 if item1 is NULL;
9710Sstevel@tonic-gate * will return NULL if system out of memory; works only
9720Sstevel@tonic-gate * for item->mib_id == 0
9730Sstevel@tonic-gate */
9740Sstevel@tonic-gate static mib_item_t *
mib_item_diff(mib_item_t * item1,mib_item_t * item2)9750Sstevel@tonic-gate mib_item_diff(mib_item_t *item1, mib_item_t *item2) {
9760Sstevel@tonic-gate int nitems = 0; /* no. of items in item2 */
9770Sstevel@tonic-gate mib_item_t *tempp2; /* walking copy of item2 */
9780Sstevel@tonic-gate mib_item_t *tempp1; /* walking copy of item1 */
9790Sstevel@tonic-gate mib_item_t *diffp;
9800Sstevel@tonic-gate mib_item_t *diffptr; /* walking copy of diffp */
9810Sstevel@tonic-gate mib_item_t *prevp = NULL;
9820Sstevel@tonic-gate
9830Sstevel@tonic-gate if (item1 == NULL) {
9840Sstevel@tonic-gate diffp = mib_item_dup(item2);
9850Sstevel@tonic-gate return (diffp);
9860Sstevel@tonic-gate }
9870Sstevel@tonic-gate
9880Sstevel@tonic-gate for (tempp2 = item2;
9890Sstevel@tonic-gate tempp2;
9900Sstevel@tonic-gate tempp2 = tempp2->next_item) {
9910Sstevel@tonic-gate if (tempp2->mib_id == 0)
9920Sstevel@tonic-gate switch (tempp2->group) {
9930Sstevel@tonic-gate /*
9940Sstevel@tonic-gate * upon adding a case here, the same
9950Sstevel@tonic-gate * must also be added in the next
9960Sstevel@tonic-gate * switch statement, alongwith
9970Sstevel@tonic-gate * appropriate code
9980Sstevel@tonic-gate */
9990Sstevel@tonic-gate case MIB2_IP:
10000Sstevel@tonic-gate case MIB2_IP6:
10010Sstevel@tonic-gate case EXPER_DVMRP:
10020Sstevel@tonic-gate case EXPER_IGMP:
10030Sstevel@tonic-gate case MIB2_ICMP:
10040Sstevel@tonic-gate case MIB2_ICMP6:
10050Sstevel@tonic-gate case MIB2_TCP:
10060Sstevel@tonic-gate case MIB2_UDP:
10070Sstevel@tonic-gate case MIB2_SCTP:
10080Sstevel@tonic-gate case EXPER_RAWIP:
10090Sstevel@tonic-gate nitems++;
10100Sstevel@tonic-gate }
10110Sstevel@tonic-gate }
10120Sstevel@tonic-gate tempp2 = NULL;
10130Sstevel@tonic-gate if (nitems == 0) {
10140Sstevel@tonic-gate diffp = mib_item_dup(item2);
10150Sstevel@tonic-gate return (diffp);
10160Sstevel@tonic-gate }
10170Sstevel@tonic-gate
10180Sstevel@tonic-gate diffp = (mib_item_t *)calloc(nitems, sizeof (mib_item_t));
10190Sstevel@tonic-gate if (diffp == NULL)
10200Sstevel@tonic-gate return (NULL);
10210Sstevel@tonic-gate diffptr = diffp;
10220Sstevel@tonic-gate /* 'for' loop 1: */
10230Sstevel@tonic-gate for (tempp2 = item2; tempp2 != NULL; tempp2 = tempp2->next_item) {
10240Sstevel@tonic-gate if (tempp2->mib_id != 0)
10250Sstevel@tonic-gate continue; /* 'for' loop 1 */
10260Sstevel@tonic-gate /* 'for' loop 2: */
10270Sstevel@tonic-gate for (tempp1 = item1; tempp1 != NULL;
10280Sstevel@tonic-gate tempp1 = tempp1->next_item) {
10290Sstevel@tonic-gate if (!(tempp1->mib_id == 0 &&
10300Sstevel@tonic-gate tempp1->group == tempp2->group &&
10310Sstevel@tonic-gate tempp1->mib_id == tempp2->mib_id))
10320Sstevel@tonic-gate continue; /* 'for' loop 2 */
10330Sstevel@tonic-gate /* found comparable data sets */
10340Sstevel@tonic-gate if (prevp != NULL)
10350Sstevel@tonic-gate prevp->next_item = diffptr;
10360Sstevel@tonic-gate switch (tempp2->group) {
10370Sstevel@tonic-gate /*
10380Sstevel@tonic-gate * Indenting note: Because of long variable names
10390Sstevel@tonic-gate * in cases MIB2_IP6 and MIB2_ICMP6, their contents
10400Sstevel@tonic-gate * have been indented by one tab space only
10410Sstevel@tonic-gate */
10420Sstevel@tonic-gate case MIB2_IP: {
10430Sstevel@tonic-gate mib2_ip_t *i2 = (mib2_ip_t *)tempp2->valp;
10440Sstevel@tonic-gate mib2_ip_t *i1 = (mib2_ip_t *)tempp1->valp;
10450Sstevel@tonic-gate mib2_ip_t *d;
10460Sstevel@tonic-gate
10470Sstevel@tonic-gate diffptr->group = tempp2->group;
10480Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id;
10490Sstevel@tonic-gate diffptr->length = tempp2->length;
10500Sstevel@tonic-gate d = (mib2_ip_t *)calloc(tempp2->length, 1);
10510Sstevel@tonic-gate if (d == NULL)
10520Sstevel@tonic-gate goto mibdiff_out_of_memory;
10530Sstevel@tonic-gate diffptr->valp = d;
10540Sstevel@tonic-gate d->ipForwarding = i2->ipForwarding;
10550Sstevel@tonic-gate d->ipDefaultTTL = i2->ipDefaultTTL;
10560Sstevel@tonic-gate MDIFF(d, i2, i1, ipInReceives);
10570Sstevel@tonic-gate MDIFF(d, i2, i1, ipInHdrErrors);
10580Sstevel@tonic-gate MDIFF(d, i2, i1, ipInAddrErrors);
10590Sstevel@tonic-gate MDIFF(d, i2, i1, ipInCksumErrs);
10600Sstevel@tonic-gate MDIFF(d, i2, i1, ipForwDatagrams);
10610Sstevel@tonic-gate MDIFF(d, i2, i1, ipForwProhibits);
10620Sstevel@tonic-gate MDIFF(d, i2, i1, ipInUnknownProtos);
10630Sstevel@tonic-gate MDIFF(d, i2, i1, ipInDiscards);
10640Sstevel@tonic-gate MDIFF(d, i2, i1, ipInDelivers);
10650Sstevel@tonic-gate MDIFF(d, i2, i1, ipOutRequests);
10660Sstevel@tonic-gate MDIFF(d, i2, i1, ipOutDiscards);
10670Sstevel@tonic-gate MDIFF(d, i2, i1, ipOutNoRoutes);
10680Sstevel@tonic-gate MDIFF(d, i2, i1, ipReasmTimeout);
10690Sstevel@tonic-gate MDIFF(d, i2, i1, ipReasmReqds);
10700Sstevel@tonic-gate MDIFF(d, i2, i1, ipReasmOKs);
10710Sstevel@tonic-gate MDIFF(d, i2, i1, ipReasmFails);
10720Sstevel@tonic-gate MDIFF(d, i2, i1, ipReasmDuplicates);
10730Sstevel@tonic-gate MDIFF(d, i2, i1, ipReasmPartDups);
10740Sstevel@tonic-gate MDIFF(d, i2, i1, ipFragOKs);
10750Sstevel@tonic-gate MDIFF(d, i2, i1, ipFragFails);
10760Sstevel@tonic-gate MDIFF(d, i2, i1, ipFragCreates);
10770Sstevel@tonic-gate MDIFF(d, i2, i1, ipRoutingDiscards);
10780Sstevel@tonic-gate MDIFF(d, i2, i1, tcpInErrs);
10790Sstevel@tonic-gate MDIFF(d, i2, i1, udpNoPorts);
10800Sstevel@tonic-gate MDIFF(d, i2, i1, udpInCksumErrs);
10810Sstevel@tonic-gate MDIFF(d, i2, i1, udpInOverflows);
10820Sstevel@tonic-gate MDIFF(d, i2, i1, rawipInOverflows);
10830Sstevel@tonic-gate MDIFF(d, i2, i1, ipsecInSucceeded);
10840Sstevel@tonic-gate MDIFF(d, i2, i1, ipsecInFailed);
10850Sstevel@tonic-gate MDIFF(d, i2, i1, ipInIPv6);
10860Sstevel@tonic-gate MDIFF(d, i2, i1, ipOutIPv6);
10870Sstevel@tonic-gate MDIFF(d, i2, i1, ipOutSwitchIPv6);
10880Sstevel@tonic-gate prevp = diffptr++;
10890Sstevel@tonic-gate break;
10900Sstevel@tonic-gate }
10910Sstevel@tonic-gate case MIB2_IP6: {
10920Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t *i2;
10930Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t *i1;
10940Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t *d;
10950Sstevel@tonic-gate
10960Sstevel@tonic-gate i2 = (mib2_ipv6IfStatsEntry_t *)tempp2->valp;
10970Sstevel@tonic-gate i1 = (mib2_ipv6IfStatsEntry_t *)tempp1->valp;
10980Sstevel@tonic-gate diffptr->group = tempp2->group;
10990Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id;
11000Sstevel@tonic-gate diffptr->length = tempp2->length;
11010Sstevel@tonic-gate d = (mib2_ipv6IfStatsEntry_t *)calloc(
11020Sstevel@tonic-gate tempp2->length, 1);
11030Sstevel@tonic-gate if (d == NULL)
11040Sstevel@tonic-gate goto mibdiff_out_of_memory;
11050Sstevel@tonic-gate diffptr->valp = d;
11060Sstevel@tonic-gate d->ipv6Forwarding = i2->ipv6Forwarding;
11070Sstevel@tonic-gate d->ipv6DefaultHopLimit =
11080Sstevel@tonic-gate i2->ipv6DefaultHopLimit;
11090Sstevel@tonic-gate
11100Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InReceives);
11110Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InHdrErrors);
11120Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InTooBigErrors);
11130Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InNoRoutes);
11140Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InAddrErrors);
11150Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InUnknownProtos);
11160Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InTruncatedPkts);
11170Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InDiscards);
11180Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InDelivers);
11190Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutForwDatagrams);
11200Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutRequests);
11210Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutDiscards);
11220Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutNoRoutes);
11230Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutFragOKs);
11240Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutFragFails);
11250Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutFragCreates);
11260Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6ReasmReqds);
11270Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6ReasmOKs);
11280Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6ReasmFails);
11290Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InMcastPkts);
11300Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutMcastPkts);
11310Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6ReasmDuplicates);
11320Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6ReasmPartDups);
11330Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6ForwProhibits);
11340Sstevel@tonic-gate MDIFF(d, i2, i1, udpInCksumErrs);
11350Sstevel@tonic-gate MDIFF(d, i2, i1, udpInOverflows);
11360Sstevel@tonic-gate MDIFF(d, i2, i1, rawipInOverflows);
11370Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6InIPv4);
11380Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutIPv4);
11390Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6OutSwitchIPv4);
11400Sstevel@tonic-gate prevp = diffptr++;
11410Sstevel@tonic-gate break;
11420Sstevel@tonic-gate }
11430Sstevel@tonic-gate case EXPER_DVMRP: {
11440Sstevel@tonic-gate struct mrtstat *m2;
11450Sstevel@tonic-gate struct mrtstat *m1;
11460Sstevel@tonic-gate struct mrtstat *d;
11470Sstevel@tonic-gate
11480Sstevel@tonic-gate m2 = (struct mrtstat *)tempp2->valp;
11490Sstevel@tonic-gate m1 = (struct mrtstat *)tempp1->valp;
11500Sstevel@tonic-gate diffptr->group = tempp2->group;
11510Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id;
11520Sstevel@tonic-gate diffptr->length = tempp2->length;
11530Sstevel@tonic-gate d = (struct mrtstat *)calloc(tempp2->length, 1);
11540Sstevel@tonic-gate if (d == NULL)
11550Sstevel@tonic-gate goto mibdiff_out_of_memory;
11560Sstevel@tonic-gate diffptr->valp = d;
11570Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_mfc_hits);
11580Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_mfc_misses);
11590Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_fwd_in);
11600Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_fwd_out);
11610Sstevel@tonic-gate d->mrts_upcalls = m2->mrts_upcalls;
11620Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_fwd_drop);
11630Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_bad_tunnel);
11640Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_cant_tunnel);
11650Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_wrong_if);
11660Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_upq_ovflw);
11670Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_cache_cleanups);
11680Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_drop_sel);
11690Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_q_overflow);
11700Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pkt2large);
11710Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_badversion);
11720Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_rcv_badcsum);
11730Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_badregisters);
11740Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_regforwards);
11750Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_regsend_drops);
11760Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_malformed);
11770Sstevel@tonic-gate MDIFF(d, m2, m1, mrts_pim_nomemory);
11780Sstevel@tonic-gate prevp = diffptr++;
11790Sstevel@tonic-gate break;
11800Sstevel@tonic-gate }
11810Sstevel@tonic-gate case EXPER_IGMP: {
11820Sstevel@tonic-gate struct igmpstat *i2;
11830Sstevel@tonic-gate struct igmpstat *i1;
11840Sstevel@tonic-gate struct igmpstat *d;
11850Sstevel@tonic-gate
11860Sstevel@tonic-gate i2 = (struct igmpstat *)tempp2->valp;
11870Sstevel@tonic-gate i1 = (struct igmpstat *)tempp1->valp;
11880Sstevel@tonic-gate diffptr->group = tempp2->group;
11890Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id;
11900Sstevel@tonic-gate diffptr->length = tempp2->length;
11910Sstevel@tonic-gate d = (struct igmpstat *)calloc(
11920Sstevel@tonic-gate tempp2->length, 1);
11930Sstevel@tonic-gate if (d == NULL)
11940Sstevel@tonic-gate goto mibdiff_out_of_memory;
11950Sstevel@tonic-gate diffptr->valp = d;
11960Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_total);
11970Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_tooshort);
11980Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_badsum);
11990Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_queries);
12000Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_badqueries);
12010Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_reports);
12020Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_badreports);
12030Sstevel@tonic-gate MDIFF(d, i2, i1, igps_rcv_ourreports);
12040Sstevel@tonic-gate MDIFF(d, i2, i1, igps_snd_reports);
12050Sstevel@tonic-gate prevp = diffptr++;
12060Sstevel@tonic-gate break;
12070Sstevel@tonic-gate }
12080Sstevel@tonic-gate case MIB2_ICMP: {
12090Sstevel@tonic-gate mib2_icmp_t *i2;
12100Sstevel@tonic-gate mib2_icmp_t *i1;
12110Sstevel@tonic-gate mib2_icmp_t *d;
12120Sstevel@tonic-gate
12130Sstevel@tonic-gate i2 = (mib2_icmp_t *)tempp2->valp;
12140Sstevel@tonic-gate i1 = (mib2_icmp_t *)tempp1->valp;
12150Sstevel@tonic-gate diffptr->group = tempp2->group;
12160Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id;
12170Sstevel@tonic-gate diffptr->length = tempp2->length;
12180Sstevel@tonic-gate d = (mib2_icmp_t *)calloc(tempp2->length, 1);
12190Sstevel@tonic-gate if (d == NULL)
12200Sstevel@tonic-gate goto mibdiff_out_of_memory;
12210Sstevel@tonic-gate diffptr->valp = d;
12220Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInMsgs);
12230Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInErrors);
12240Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInCksumErrs);
12250Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInUnknowns);
12260Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInDestUnreachs);
12270Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInTimeExcds);
12280Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInParmProbs);
12290Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInSrcQuenchs);
12300Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInRedirects);
12310Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInBadRedirects);
12320Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInEchos);
12330Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInEchoReps);
12340Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInTimestamps);
12350Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInAddrMasks);
12360Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInAddrMaskReps);
12370Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInFragNeeded);
12380Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutMsgs);
12390Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutDrops);
12400Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutErrors);
12410Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutDestUnreachs);
12420Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutTimeExcds);
12430Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutParmProbs);
12440Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutSrcQuenchs);
12450Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutRedirects);
12460Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutEchos);
12470Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutEchoReps);
12480Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutTimestamps);
12490Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutTimestampReps);
12500Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutAddrMasks);
12510Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutAddrMaskReps);
12520Sstevel@tonic-gate MDIFF(d, i2, i1, icmpOutFragNeeded);
12530Sstevel@tonic-gate MDIFF(d, i2, i1, icmpInOverflows);
12540Sstevel@tonic-gate prevp = diffptr++;
12550Sstevel@tonic-gate break;
12560Sstevel@tonic-gate }
12570Sstevel@tonic-gate case MIB2_ICMP6: {
12580Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t *i2;
12590Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t *i1;
12600Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t *d;
12610Sstevel@tonic-gate
12620Sstevel@tonic-gate i2 = (mib2_ipv6IfIcmpEntry_t *)tempp2->valp;
12630Sstevel@tonic-gate i1 = (mib2_ipv6IfIcmpEntry_t *)tempp1->valp;
12640Sstevel@tonic-gate diffptr->group = tempp2->group;
12650Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id;
12660Sstevel@tonic-gate diffptr->length = tempp2->length;
12670Sstevel@tonic-gate d = (mib2_ipv6IfIcmpEntry_t *)calloc(tempp2->length, 1);
12680Sstevel@tonic-gate if (d == NULL)
12690Sstevel@tonic-gate goto mibdiff_out_of_memory;
12700Sstevel@tonic-gate diffptr->valp = d;
12710Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInMsgs);
12720Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInErrors);
12730Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInDestUnreachs);
12740Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInAdminProhibs);
12750Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInTimeExcds);
12760Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInParmProblems);
12770Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInPktTooBigs);
12780Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInEchos);
12790Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInEchoReplies);
12800Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInRouterSolicits);
12810Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInRouterAdvertisements);
12820Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInNeighborSolicits);
12830Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInNeighborAdvertisements);
12840Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInRedirects);
12850Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInBadRedirects);
12860Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInGroupMembQueries);
12870Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInGroupMembResponses);
12880Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInGroupMembReductions);
12890Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpInOverflows);
12900Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutMsgs);
12910Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutErrors);
12920Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutDestUnreachs);
12930Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutAdminProhibs);
12940Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutTimeExcds);
12950Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutParmProblems);
12960Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutPktTooBigs);
12970Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutEchos);
12980Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutEchoReplies);
12990Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutRouterSolicits);
13000Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutRouterAdvertisements);
13010Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutNeighborSolicits);
13020Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutNeighborAdvertisements);
13030Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutRedirects);
13040Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutGroupMembQueries);
13050Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutGroupMembResponses);
13060Sstevel@tonic-gate MDIFF(d, i2, i1, ipv6IfIcmpOutGroupMembReductions);
13070Sstevel@tonic-gate prevp = diffptr++;
13080Sstevel@tonic-gate break;
13090Sstevel@tonic-gate }
13100Sstevel@tonic-gate case MIB2_TCP: {
13110Sstevel@tonic-gate mib2_tcp_t *t2;
13120Sstevel@tonic-gate mib2_tcp_t *t1;
13130Sstevel@tonic-gate mib2_tcp_t *d;
13140Sstevel@tonic-gate
13150Sstevel@tonic-gate t2 = (mib2_tcp_t *)tempp2->valp;
13160Sstevel@tonic-gate t1 = (mib2_tcp_t *)tempp1->valp;
13170Sstevel@tonic-gate diffptr->group = tempp2->group;
13180Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id;
13190Sstevel@tonic-gate diffptr->length = tempp2->length;
13200Sstevel@tonic-gate d = (mib2_tcp_t *)calloc(tempp2->length, 1);
13210Sstevel@tonic-gate if (d == NULL)
13220Sstevel@tonic-gate goto mibdiff_out_of_memory;
13230Sstevel@tonic-gate diffptr->valp = d;
13240Sstevel@tonic-gate d->tcpRtoMin = t2->tcpRtoMin;
13250Sstevel@tonic-gate d->tcpRtoMax = t2->tcpRtoMax;
13260Sstevel@tonic-gate d->tcpMaxConn = t2->tcpMaxConn;
13270Sstevel@tonic-gate MDIFF(d, t2, t1, tcpActiveOpens);
13280Sstevel@tonic-gate MDIFF(d, t2, t1, tcpPassiveOpens);
13290Sstevel@tonic-gate MDIFF(d, t2, t1, tcpAttemptFails);
13300Sstevel@tonic-gate MDIFF(d, t2, t1, tcpEstabResets);
13310Sstevel@tonic-gate d->tcpCurrEstab = t2->tcpCurrEstab;
13323284Sapersson MDIFF(d, t2, t1, tcpHCOutSegs);
13330Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutDataSegs);
13340Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutDataBytes);
13350Sstevel@tonic-gate MDIFF(d, t2, t1, tcpRetransSegs);
13360Sstevel@tonic-gate MDIFF(d, t2, t1, tcpRetransBytes);
13370Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutAck);
13380Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutAckDelayed);
13390Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutUrg);
13400Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutWinUpdate);
13410Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutWinProbe);
13420Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutControl);
13430Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutRsts);
13440Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutFastRetrans);
13453284Sapersson MDIFF(d, t2, t1, tcpHCInSegs);
13460Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInAckSegs);
13470Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInAckBytes);
13480Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDupAck);
13490Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInAckUnsent);
13500Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataInorderSegs);
13510Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataInorderBytes);
13520Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataUnorderSegs);
13530Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataUnorderBytes);
13540Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataDupSegs);
13550Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataDupBytes);
13560Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataPartDupSegs);
13570Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataPartDupBytes);
13580Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataPastWinSegs);
13590Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInDataPastWinBytes);
13600Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInWinProbe);
13610Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInWinUpdate);
13620Sstevel@tonic-gate MDIFF(d, t2, t1, tcpInClosed);
13630Sstevel@tonic-gate MDIFF(d, t2, t1, tcpRttNoUpdate);
13640Sstevel@tonic-gate MDIFF(d, t2, t1, tcpRttUpdate);
13650Sstevel@tonic-gate MDIFF(d, t2, t1, tcpTimRetrans);
13660Sstevel@tonic-gate MDIFF(d, t2, t1, tcpTimRetransDrop);
13670Sstevel@tonic-gate MDIFF(d, t2, t1, tcpTimKeepalive);
13680Sstevel@tonic-gate MDIFF(d, t2, t1, tcpTimKeepaliveProbe);
13690Sstevel@tonic-gate MDIFF(d, t2, t1, tcpTimKeepaliveDrop);
13700Sstevel@tonic-gate MDIFF(d, t2, t1, tcpListenDrop);
13710Sstevel@tonic-gate MDIFF(d, t2, t1, tcpListenDropQ0);
13720Sstevel@tonic-gate MDIFF(d, t2, t1, tcpHalfOpenDrop);
13730Sstevel@tonic-gate MDIFF(d, t2, t1, tcpOutSackRetransSegs);
13740Sstevel@tonic-gate prevp = diffptr++;
13750Sstevel@tonic-gate break;
13760Sstevel@tonic-gate }
13770Sstevel@tonic-gate case MIB2_UDP: {
13780Sstevel@tonic-gate mib2_udp_t *u2;
13790Sstevel@tonic-gate mib2_udp_t *u1;
13800Sstevel@tonic-gate mib2_udp_t *d;
13810Sstevel@tonic-gate
13820Sstevel@tonic-gate u2 = (mib2_udp_t *)tempp2->valp;
13830Sstevel@tonic-gate u1 = (mib2_udp_t *)tempp1->valp;
13840Sstevel@tonic-gate diffptr->group = tempp2->group;
13850Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id;
13860Sstevel@tonic-gate diffptr->length = tempp2->length;
13870Sstevel@tonic-gate d = (mib2_udp_t *)calloc(tempp2->length, 1);
13880Sstevel@tonic-gate if (d == NULL)
13890Sstevel@tonic-gate goto mibdiff_out_of_memory;
13900Sstevel@tonic-gate diffptr->valp = d;
13913284Sapersson MDIFF(d, u2, u1, udpHCInDatagrams);
13920Sstevel@tonic-gate MDIFF(d, u2, u1, udpInErrors);
13933284Sapersson MDIFF(d, u2, u1, udpHCOutDatagrams);
13940Sstevel@tonic-gate MDIFF(d, u2, u1, udpOutErrors);
13950Sstevel@tonic-gate prevp = diffptr++;
13960Sstevel@tonic-gate break;
13970Sstevel@tonic-gate }
13980Sstevel@tonic-gate case MIB2_SCTP: {
13990Sstevel@tonic-gate mib2_sctp_t *s2;
14000Sstevel@tonic-gate mib2_sctp_t *s1;
14010Sstevel@tonic-gate mib2_sctp_t *d;
14020Sstevel@tonic-gate
14030Sstevel@tonic-gate s2 = (mib2_sctp_t *)tempp2->valp;
14040Sstevel@tonic-gate s1 = (mib2_sctp_t *)tempp1->valp;
14050Sstevel@tonic-gate diffptr->group = tempp2->group;
14060Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id;
14070Sstevel@tonic-gate diffptr->length = tempp2->length;
14080Sstevel@tonic-gate d = (mib2_sctp_t *)calloc(tempp2->length, 1);
14090Sstevel@tonic-gate if (d == NULL)
14100Sstevel@tonic-gate goto mibdiff_out_of_memory;
14110Sstevel@tonic-gate diffptr->valp = d;
14120Sstevel@tonic-gate d->sctpRtoAlgorithm = s2->sctpRtoAlgorithm;
14130Sstevel@tonic-gate d->sctpRtoMin = s2->sctpRtoMin;
14140Sstevel@tonic-gate d->sctpRtoMax = s2->sctpRtoMax;
14150Sstevel@tonic-gate d->sctpRtoInitial = s2->sctpRtoInitial;
14160Sstevel@tonic-gate d->sctpMaxAssocs = s2->sctpMaxAssocs;
14170Sstevel@tonic-gate d->sctpValCookieLife = s2->sctpValCookieLife;
14180Sstevel@tonic-gate d->sctpMaxInitRetr = s2->sctpMaxInitRetr;
14190Sstevel@tonic-gate d->sctpCurrEstab = s2->sctpCurrEstab;
14200Sstevel@tonic-gate MDIFF(d, s2, s1, sctpActiveEstab);
14210Sstevel@tonic-gate MDIFF(d, s2, s1, sctpPassiveEstab);
14220Sstevel@tonic-gate MDIFF(d, s2, s1, sctpAborted);
14230Sstevel@tonic-gate MDIFF(d, s2, s1, sctpShutdowns);
14240Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutOfBlue);
14250Sstevel@tonic-gate MDIFF(d, s2, s1, sctpChecksumError);
14260Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutCtrlChunks);
14270Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutOrderChunks);
14280Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutUnorderChunks);
14290Sstevel@tonic-gate MDIFF(d, s2, s1, sctpRetransChunks);
14300Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutAck);
14310Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutAckDelayed);
14320Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutWinUpdate);
14330Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutFastRetrans);
14340Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutWinProbe);
14350Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInCtrlChunks);
14360Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInOrderChunks);
14370Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInUnorderChunks);
14380Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInAck);
14390Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInDupAck);
14400Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInAckUnsent);
14410Sstevel@tonic-gate MDIFF(d, s2, s1, sctpFragUsrMsgs);
14420Sstevel@tonic-gate MDIFF(d, s2, s1, sctpReasmUsrMsgs);
14430Sstevel@tonic-gate MDIFF(d, s2, s1, sctpOutSCTPPkts);
14440Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInSCTPPkts);
14450Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInInvalidCookie);
14460Sstevel@tonic-gate MDIFF(d, s2, s1, sctpTimRetrans);
14470Sstevel@tonic-gate MDIFF(d, s2, s1, sctpTimRetransDrop);
14480Sstevel@tonic-gate MDIFF(d, s2, s1, sctpTimHeartBeatProbe);
14490Sstevel@tonic-gate MDIFF(d, s2, s1, sctpTimHeartBeatDrop);
14500Sstevel@tonic-gate MDIFF(d, s2, s1, sctpListenDrop);
14510Sstevel@tonic-gate MDIFF(d, s2, s1, sctpInClosed);
14520Sstevel@tonic-gate prevp = diffptr++;
14530Sstevel@tonic-gate break;
14540Sstevel@tonic-gate }
14550Sstevel@tonic-gate case EXPER_RAWIP: {
14560Sstevel@tonic-gate mib2_rawip_t *r2;
14570Sstevel@tonic-gate mib2_rawip_t *r1;
14580Sstevel@tonic-gate mib2_rawip_t *d;
14590Sstevel@tonic-gate
14600Sstevel@tonic-gate r2 = (mib2_rawip_t *)tempp2->valp;
14610Sstevel@tonic-gate r1 = (mib2_rawip_t *)tempp1->valp;
14620Sstevel@tonic-gate diffptr->group = tempp2->group;
14630Sstevel@tonic-gate diffptr->mib_id = tempp2->mib_id;
14640Sstevel@tonic-gate diffptr->length = tempp2->length;
14650Sstevel@tonic-gate d = (mib2_rawip_t *)calloc(tempp2->length, 1);
14660Sstevel@tonic-gate if (d == NULL)
14670Sstevel@tonic-gate goto mibdiff_out_of_memory;
14680Sstevel@tonic-gate diffptr->valp = d;
14690Sstevel@tonic-gate MDIFF(d, r2, r1, rawipInDatagrams);
14700Sstevel@tonic-gate MDIFF(d, r2, r1, rawipInErrors);
14710Sstevel@tonic-gate MDIFF(d, r2, r1, rawipInCksumErrs);
14720Sstevel@tonic-gate MDIFF(d, r2, r1, rawipOutDatagrams);
14730Sstevel@tonic-gate MDIFF(d, r2, r1, rawipOutErrors);
14740Sstevel@tonic-gate prevp = diffptr++;
14750Sstevel@tonic-gate break;
14760Sstevel@tonic-gate }
14770Sstevel@tonic-gate /*
14780Sstevel@tonic-gate * there are more "group" types but they aren't
14790Sstevel@tonic-gate * required for the -s and -Ms options
14800Sstevel@tonic-gate */
14810Sstevel@tonic-gate }
14820Sstevel@tonic-gate } /* 'for' loop 2 ends */
14830Sstevel@tonic-gate tempp1 = NULL;
14840Sstevel@tonic-gate } /* 'for' loop 1 ends */
14850Sstevel@tonic-gate tempp2 = NULL;
14860Sstevel@tonic-gate diffptr--;
14870Sstevel@tonic-gate diffptr->next_item = NULL;
14880Sstevel@tonic-gate return (diffp);
14890Sstevel@tonic-gate
14900Sstevel@tonic-gate mibdiff_out_of_memory:;
14910Sstevel@tonic-gate mib_item_destroy(&diffp);
14920Sstevel@tonic-gate return (NULL);
14930Sstevel@tonic-gate }
14940Sstevel@tonic-gate
14950Sstevel@tonic-gate /*
14960Sstevel@tonic-gate * mib_item_destroy: cleans up a mib_item_t *
14970Sstevel@tonic-gate * that was created by calling mib_item_dup or
14980Sstevel@tonic-gate * mib_item_diff
14990Sstevel@tonic-gate */
15000Sstevel@tonic-gate static void
mib_item_destroy(mib_item_t ** itemp)15010Sstevel@tonic-gate mib_item_destroy(mib_item_t **itemp) {
15020Sstevel@tonic-gate int nitems = 0;
15030Sstevel@tonic-gate int c = 0;
15040Sstevel@tonic-gate mib_item_t *tempp;
15050Sstevel@tonic-gate
15060Sstevel@tonic-gate if (itemp == NULL || *itemp == NULL)
15070Sstevel@tonic-gate return;
15080Sstevel@tonic-gate
15090Sstevel@tonic-gate for (tempp = *itemp; tempp != NULL; tempp = tempp->next_item)
15100Sstevel@tonic-gate if (tempp->mib_id == 0)
15110Sstevel@tonic-gate nitems++;
15120Sstevel@tonic-gate else
15130Sstevel@tonic-gate return; /* cannot destroy! */
15140Sstevel@tonic-gate
15150Sstevel@tonic-gate if (nitems == 0)
15160Sstevel@tonic-gate return; /* cannot destroy! */
15170Sstevel@tonic-gate
15180Sstevel@tonic-gate for (c = nitems - 1; c >= 0; c--) {
15190Sstevel@tonic-gate if ((itemp[0][c]).valp != NULL)
15200Sstevel@tonic-gate free((itemp[0][c]).valp);
15210Sstevel@tonic-gate }
15220Sstevel@tonic-gate free(*itemp);
15230Sstevel@tonic-gate
15240Sstevel@tonic-gate *itemp = NULL;
15250Sstevel@tonic-gate }
15260Sstevel@tonic-gate
15270Sstevel@tonic-gate /* Compare two Octet_ts. Return B_TRUE if they match, B_FALSE if not. */
15280Sstevel@tonic-gate static boolean_t
octetstrmatch(const Octet_t * a,const Octet_t * b)15290Sstevel@tonic-gate octetstrmatch(const Octet_t *a, const Octet_t *b)
15300Sstevel@tonic-gate {
15310Sstevel@tonic-gate if (a == NULL || b == NULL)
15320Sstevel@tonic-gate return (B_FALSE);
15330Sstevel@tonic-gate
15340Sstevel@tonic-gate if (a->o_length != b->o_length)
15350Sstevel@tonic-gate return (B_FALSE);
15360Sstevel@tonic-gate
15370Sstevel@tonic-gate return (memcmp(a->o_bytes, b->o_bytes, a->o_length) == 0);
15380Sstevel@tonic-gate }
15390Sstevel@tonic-gate
15400Sstevel@tonic-gate /* If octetstr() changes make an appropriate change to STR_EXPAND */
15410Sstevel@tonic-gate static char *
octetstr(const Octet_t * op,int code,char * dst,uint_t dstlen)15421676Sjpk octetstr(const Octet_t *op, int code, char *dst, uint_t dstlen)
15430Sstevel@tonic-gate {
15440Sstevel@tonic-gate int i;
15450Sstevel@tonic-gate char *cp;
15460Sstevel@tonic-gate
15470Sstevel@tonic-gate cp = dst;
15480Sstevel@tonic-gate if (op) {
15490Sstevel@tonic-gate for (i = 0; i < op->o_length; i++) {
15500Sstevel@tonic-gate switch (code) {
15510Sstevel@tonic-gate case 'd':
15520Sstevel@tonic-gate if (cp - dst + 4 > dstlen) {
15530Sstevel@tonic-gate *cp = '\0';
15540Sstevel@tonic-gate return (dst);
15550Sstevel@tonic-gate }
15560Sstevel@tonic-gate (void) snprintf(cp, 5, "%d.",
15570Sstevel@tonic-gate 0xff & op->o_bytes[i]);
15580Sstevel@tonic-gate cp = strchr(cp, '\0');
15590Sstevel@tonic-gate break;
15600Sstevel@tonic-gate case 'a':
15610Sstevel@tonic-gate if (cp - dst + 1 > dstlen) {
15620Sstevel@tonic-gate *cp = '\0';
15630Sstevel@tonic-gate return (dst);
15640Sstevel@tonic-gate }
15650Sstevel@tonic-gate *cp++ = op->o_bytes[i];
15660Sstevel@tonic-gate break;
15670Sstevel@tonic-gate case 'h':
15680Sstevel@tonic-gate default:
15690Sstevel@tonic-gate if (cp - dst + 3 > dstlen) {
15700Sstevel@tonic-gate *cp = '\0';
15710Sstevel@tonic-gate return (dst);
15720Sstevel@tonic-gate }
15730Sstevel@tonic-gate (void) snprintf(cp, 4, "%02x:",
15740Sstevel@tonic-gate 0xff & op->o_bytes[i]);
15750Sstevel@tonic-gate cp += 3;
15760Sstevel@tonic-gate break;
15770Sstevel@tonic-gate }
15780Sstevel@tonic-gate }
15790Sstevel@tonic-gate }
15800Sstevel@tonic-gate if (code != 'a' && cp != dst)
15810Sstevel@tonic-gate cp--;
15820Sstevel@tonic-gate *cp = '\0';
15830Sstevel@tonic-gate return (dst);
15840Sstevel@tonic-gate }
15850Sstevel@tonic-gate
15861676Sjpk static const char *
mitcp_state(int state,const mib2_transportMLPEntry_t * attr)15871676Sjpk mitcp_state(int state, const mib2_transportMLPEntry_t *attr)
15880Sstevel@tonic-gate {
15891676Sjpk static char tcpsbuf[50];
15901676Sjpk const char *cp;
15910Sstevel@tonic-gate
15920Sstevel@tonic-gate switch (state) {
15930Sstevel@tonic-gate case TCPS_CLOSED:
15940Sstevel@tonic-gate cp = "CLOSED";
15950Sstevel@tonic-gate break;
15960Sstevel@tonic-gate case TCPS_IDLE:
15970Sstevel@tonic-gate cp = "IDLE";
15980Sstevel@tonic-gate break;
15990Sstevel@tonic-gate case TCPS_BOUND:
16000Sstevel@tonic-gate cp = "BOUND";
16010Sstevel@tonic-gate break;
16020Sstevel@tonic-gate case TCPS_LISTEN:
16030Sstevel@tonic-gate cp = "LISTEN";
16040Sstevel@tonic-gate break;
16050Sstevel@tonic-gate case TCPS_SYN_SENT:
16060Sstevel@tonic-gate cp = "SYN_SENT";
16070Sstevel@tonic-gate break;
16080Sstevel@tonic-gate case TCPS_SYN_RCVD:
16090Sstevel@tonic-gate cp = "SYN_RCVD";
16100Sstevel@tonic-gate break;
16110Sstevel@tonic-gate case TCPS_ESTABLISHED:
16120Sstevel@tonic-gate cp = "ESTABLISHED";
16130Sstevel@tonic-gate break;
16140Sstevel@tonic-gate case TCPS_CLOSE_WAIT:
16150Sstevel@tonic-gate cp = "CLOSE_WAIT";
16160Sstevel@tonic-gate break;
16170Sstevel@tonic-gate case TCPS_FIN_WAIT_1:
16180Sstevel@tonic-gate cp = "FIN_WAIT_1";
16190Sstevel@tonic-gate break;
16200Sstevel@tonic-gate case TCPS_CLOSING:
16210Sstevel@tonic-gate cp = "CLOSING";
16220Sstevel@tonic-gate break;
16230Sstevel@tonic-gate case TCPS_LAST_ACK:
16240Sstevel@tonic-gate cp = "LAST_ACK";
16250Sstevel@tonic-gate break;
16260Sstevel@tonic-gate case TCPS_FIN_WAIT_2:
16270Sstevel@tonic-gate cp = "FIN_WAIT_2";
16280Sstevel@tonic-gate break;
16290Sstevel@tonic-gate case TCPS_TIME_WAIT:
16300Sstevel@tonic-gate cp = "TIME_WAIT";
16310Sstevel@tonic-gate break;
16320Sstevel@tonic-gate default:
16330Sstevel@tonic-gate (void) snprintf(tcpsbuf, sizeof (tcpsbuf),
16340Sstevel@tonic-gate "UnknownState(%d)", state);
16350Sstevel@tonic-gate cp = tcpsbuf;
16360Sstevel@tonic-gate break;
16370Sstevel@tonic-gate }
16381676Sjpk
16391676Sjpk if (RSECflag && attr != NULL && attr->tme_flags != 0) {
16401676Sjpk if (cp != tcpsbuf) {
16411676Sjpk (void) strlcpy(tcpsbuf, cp, sizeof (tcpsbuf));
16421676Sjpk cp = tcpsbuf;
16431676Sjpk }
16441676Sjpk if (attr->tme_flags & MIB2_TMEF_PRIVATE)
16451676Sjpk (void) strlcat(tcpsbuf, " P", sizeof (tcpsbuf));
16461676Sjpk if (attr->tme_flags & MIB2_TMEF_SHARED)
16471676Sjpk (void) strlcat(tcpsbuf, " S", sizeof (tcpsbuf));
16481676Sjpk }
16491676Sjpk
16501676Sjpk return (cp);
16511676Sjpk }
16521676Sjpk
16531676Sjpk static const char *
miudp_state(int state,const mib2_transportMLPEntry_t * attr)16541676Sjpk miudp_state(int state, const mib2_transportMLPEntry_t *attr)
16551676Sjpk {
16561676Sjpk static char udpsbuf[50];
16571676Sjpk const char *cp;
16581676Sjpk
16591676Sjpk switch (state) {
16601676Sjpk case MIB2_UDP_unbound:
16611676Sjpk cp = "Unbound";
16621676Sjpk break;
16631676Sjpk case MIB2_UDP_idle:
16641676Sjpk cp = "Idle";
16651676Sjpk break;
16661676Sjpk case MIB2_UDP_connected:
16671676Sjpk cp = "Connected";
16681676Sjpk break;
16691676Sjpk default:
16701676Sjpk (void) snprintf(udpsbuf, sizeof (udpsbuf),
16711676Sjpk "Unknown State(%d)", state);
16721676Sjpk cp = udpsbuf;
16731676Sjpk break;
16741676Sjpk }
16751676Sjpk
16761676Sjpk if (RSECflag && attr != NULL && attr->tme_flags != 0) {
16771676Sjpk if (cp != udpsbuf) {
16781676Sjpk (void) strlcpy(udpsbuf, cp, sizeof (udpsbuf));
16791676Sjpk cp = udpsbuf;
16801676Sjpk }
16811676Sjpk if (attr->tme_flags & MIB2_TMEF_PRIVATE)
16821676Sjpk (void) strlcat(udpsbuf, " P", sizeof (udpsbuf));
16831676Sjpk if (attr->tme_flags & MIB2_TMEF_SHARED)
16841676Sjpk (void) strlcat(udpsbuf, " S", sizeof (udpsbuf));
16851676Sjpk }
16861676Sjpk
16870Sstevel@tonic-gate return (cp);
16880Sstevel@tonic-gate }
16890Sstevel@tonic-gate
16900Sstevel@tonic-gate static int odd;
16910Sstevel@tonic-gate
16920Sstevel@tonic-gate static void
prval_init(void)16930Sstevel@tonic-gate prval_init(void)
16940Sstevel@tonic-gate {
16950Sstevel@tonic-gate odd = 0;
16960Sstevel@tonic-gate }
16970Sstevel@tonic-gate
16980Sstevel@tonic-gate static void
prval(char * str,Counter val)16990Sstevel@tonic-gate prval(char *str, Counter val)
17000Sstevel@tonic-gate {
17010Sstevel@tonic-gate (void) printf("\t%-20s=%6u", str, val);
17020Sstevel@tonic-gate if (odd++ & 1)
17030Sstevel@tonic-gate (void) putchar('\n');
17040Sstevel@tonic-gate }
17050Sstevel@tonic-gate
17060Sstevel@tonic-gate static void
prval64(char * str,Counter64 val)17070Sstevel@tonic-gate prval64(char *str, Counter64 val)
17080Sstevel@tonic-gate {
17090Sstevel@tonic-gate (void) printf("\t%-20s=%6llu", str, val);
17100Sstevel@tonic-gate if (odd++ & 1)
17110Sstevel@tonic-gate (void) putchar('\n');
17120Sstevel@tonic-gate }
17130Sstevel@tonic-gate
17140Sstevel@tonic-gate static void
pr_int_val(char * str,int val)17150Sstevel@tonic-gate pr_int_val(char *str, int val)
17160Sstevel@tonic-gate {
17170Sstevel@tonic-gate (void) printf("\t%-20s=%6d", str, val);
17180Sstevel@tonic-gate if (odd++ & 1)
17190Sstevel@tonic-gate (void) putchar('\n');
17200Sstevel@tonic-gate }
17210Sstevel@tonic-gate
17220Sstevel@tonic-gate static void
pr_sctp_rtoalgo(char * str,int val)17230Sstevel@tonic-gate pr_sctp_rtoalgo(char *str, int val)
17240Sstevel@tonic-gate {
17250Sstevel@tonic-gate (void) printf("\t%-20s=", str);
17260Sstevel@tonic-gate switch (val) {
17270Sstevel@tonic-gate case MIB2_SCTP_RTOALGO_OTHER:
17280Sstevel@tonic-gate (void) printf("%6.6s", "other");
17290Sstevel@tonic-gate break;
17300Sstevel@tonic-gate
17310Sstevel@tonic-gate case MIB2_SCTP_RTOALGO_VANJ:
17320Sstevel@tonic-gate (void) printf("%6.6s", "vanj");
17330Sstevel@tonic-gate break;
17340Sstevel@tonic-gate
17350Sstevel@tonic-gate default:
17360Sstevel@tonic-gate (void) printf("%6d", val);
17370Sstevel@tonic-gate break;
17380Sstevel@tonic-gate }
17390Sstevel@tonic-gate if (odd++ & 1)
17400Sstevel@tonic-gate (void) putchar('\n');
17410Sstevel@tonic-gate }
17420Sstevel@tonic-gate
17430Sstevel@tonic-gate static void
prval_end(void)17440Sstevel@tonic-gate prval_end(void)
17450Sstevel@tonic-gate {
17460Sstevel@tonic-gate if (odd++ & 1)
17470Sstevel@tonic-gate (void) putchar('\n');
17480Sstevel@tonic-gate }
17490Sstevel@tonic-gate
17500Sstevel@tonic-gate /* Extract constant sizes */
17510Sstevel@tonic-gate static void
mib_get_constants(mib_item_t * item)17520Sstevel@tonic-gate mib_get_constants(mib_item_t *item)
17530Sstevel@tonic-gate {
17540Sstevel@tonic-gate /* 'for' loop 1: */
17550Sstevel@tonic-gate for (; item; item = item->next_item) {
17560Sstevel@tonic-gate if (item->mib_id != 0)
17570Sstevel@tonic-gate continue; /* 'for' loop 1 */
17580Sstevel@tonic-gate
17590Sstevel@tonic-gate switch (item->group) {
17600Sstevel@tonic-gate case MIB2_IP: {
17610Sstevel@tonic-gate mib2_ip_t *ip = (mib2_ip_t *)item->valp;
17620Sstevel@tonic-gate
17630Sstevel@tonic-gate ipAddrEntrySize = ip->ipAddrEntrySize;
17640Sstevel@tonic-gate ipRouteEntrySize = ip->ipRouteEntrySize;
17650Sstevel@tonic-gate ipNetToMediaEntrySize = ip->ipNetToMediaEntrySize;
17660Sstevel@tonic-gate ipMemberEntrySize = ip->ipMemberEntrySize;
17670Sstevel@tonic-gate ipGroupSourceEntrySize = ip->ipGroupSourceEntrySize;
17681676Sjpk ipRouteAttributeSize = ip->ipRouteAttributeSize;
17691676Sjpk transportMLPSize = ip->transportMLPSize;
177011042SErik.Nordmark@Sun.COM ipDestEntrySize = ip->ipDestEntrySize;
17710Sstevel@tonic-gate assert(IS_P2ALIGNED(ipAddrEntrySize,
17728485SPeter.Memishian@Sun.COM sizeof (mib2_ipAddrEntry_t *)));
17738485SPeter.Memishian@Sun.COM assert(IS_P2ALIGNED(ipRouteEntrySize,
17748485SPeter.Memishian@Sun.COM sizeof (mib2_ipRouteEntry_t *)));
17758485SPeter.Memishian@Sun.COM assert(IS_P2ALIGNED(ipNetToMediaEntrySize,
17768485SPeter.Memishian@Sun.COM sizeof (mib2_ipNetToMediaEntry_t *)));
17778485SPeter.Memishian@Sun.COM assert(IS_P2ALIGNED(ipMemberEntrySize,
17788485SPeter.Memishian@Sun.COM sizeof (ip_member_t *)));
17798485SPeter.Memishian@Sun.COM assert(IS_P2ALIGNED(ipGroupSourceEntrySize,
17808485SPeter.Memishian@Sun.COM sizeof (ip_grpsrc_t *)));
17818485SPeter.Memishian@Sun.COM assert(IS_P2ALIGNED(ipRouteAttributeSize,
17828485SPeter.Memishian@Sun.COM sizeof (mib2_ipAttributeEntry_t *)));
17838485SPeter.Memishian@Sun.COM assert(IS_P2ALIGNED(transportMLPSize,
17848485SPeter.Memishian@Sun.COM sizeof (mib2_transportMLPEntry_t *)));
17850Sstevel@tonic-gate break;
17860Sstevel@tonic-gate }
17870Sstevel@tonic-gate case EXPER_DVMRP: {
17880Sstevel@tonic-gate struct mrtstat *mrts = (struct mrtstat *)item->valp;
17890Sstevel@tonic-gate
17900Sstevel@tonic-gate vifctlSize = mrts->mrts_vifctlSize;
17910Sstevel@tonic-gate mfcctlSize = mrts->mrts_mfcctlSize;
17920Sstevel@tonic-gate assert(IS_P2ALIGNED(vifctlSize,
17938485SPeter.Memishian@Sun.COM sizeof (struct vifclt *)));
17948485SPeter.Memishian@Sun.COM assert(IS_P2ALIGNED(mfcctlSize,
17958485SPeter.Memishian@Sun.COM sizeof (struct mfcctl *)));
17960Sstevel@tonic-gate break;
17970Sstevel@tonic-gate }
17980Sstevel@tonic-gate case MIB2_IP6: {
17990Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t *ip6;
18000Sstevel@tonic-gate /* Just use the first entry */
18010Sstevel@tonic-gate
18020Sstevel@tonic-gate ip6 = (mib2_ipv6IfStatsEntry_t *)item->valp;
18030Sstevel@tonic-gate ipv6IfStatsEntrySize = ip6->ipv6IfStatsEntrySize;
18040Sstevel@tonic-gate ipv6AddrEntrySize = ip6->ipv6AddrEntrySize;
18050Sstevel@tonic-gate ipv6RouteEntrySize = ip6->ipv6RouteEntrySize;
18060Sstevel@tonic-gate ipv6NetToMediaEntrySize = ip6->ipv6NetToMediaEntrySize;
18070Sstevel@tonic-gate ipv6MemberEntrySize = ip6->ipv6MemberEntrySize;
18080Sstevel@tonic-gate ipv6GroupSourceEntrySize =
18090Sstevel@tonic-gate ip6->ipv6GroupSourceEntrySize;
18100Sstevel@tonic-gate assert(IS_P2ALIGNED(ipv6IfStatsEntrySize,
18118485SPeter.Memishian@Sun.COM sizeof (mib2_ipv6IfStatsEntry_t *)));
18128485SPeter.Memishian@Sun.COM assert(IS_P2ALIGNED(ipv6AddrEntrySize,
18138485SPeter.Memishian@Sun.COM sizeof (mib2_ipv6AddrEntry_t *)));
18148485SPeter.Memishian@Sun.COM assert(IS_P2ALIGNED(ipv6RouteEntrySize,
18158485SPeter.Memishian@Sun.COM sizeof (mib2_ipv6RouteEntry_t *)));
18168485SPeter.Memishian@Sun.COM assert(IS_P2ALIGNED(ipv6NetToMediaEntrySize,
18178485SPeter.Memishian@Sun.COM sizeof (mib2_ipv6NetToMediaEntry_t *)));
18188485SPeter.Memishian@Sun.COM assert(IS_P2ALIGNED(ipv6MemberEntrySize,
18198485SPeter.Memishian@Sun.COM sizeof (ipv6_member_t *)));
18208485SPeter.Memishian@Sun.COM assert(IS_P2ALIGNED(ipv6GroupSourceEntrySize,
18218485SPeter.Memishian@Sun.COM sizeof (ipv6_grpsrc_t *)));
18220Sstevel@tonic-gate break;
18230Sstevel@tonic-gate }
18240Sstevel@tonic-gate case MIB2_ICMP6: {
18250Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t *icmp6;
18260Sstevel@tonic-gate /* Just use the first entry */
18270Sstevel@tonic-gate
18280Sstevel@tonic-gate icmp6 = (mib2_ipv6IfIcmpEntry_t *)item->valp;
18290Sstevel@tonic-gate ipv6IfIcmpEntrySize = icmp6->ipv6IfIcmpEntrySize;
18300Sstevel@tonic-gate assert(IS_P2ALIGNED(ipv6IfIcmpEntrySize,
18310Sstevel@tonic-gate sizeof (mib2_ipv6IfIcmpEntry_t *)));
18320Sstevel@tonic-gate break;
18330Sstevel@tonic-gate }
18340Sstevel@tonic-gate case MIB2_TCP: {
18350Sstevel@tonic-gate mib2_tcp_t *tcp = (mib2_tcp_t *)item->valp;
18360Sstevel@tonic-gate
18370Sstevel@tonic-gate tcpConnEntrySize = tcp->tcpConnTableSize;
18380Sstevel@tonic-gate tcp6ConnEntrySize = tcp->tcp6ConnTableSize;
18390Sstevel@tonic-gate assert(IS_P2ALIGNED(tcpConnEntrySize,
18408485SPeter.Memishian@Sun.COM sizeof (mib2_tcpConnEntry_t *)));
18418485SPeter.Memishian@Sun.COM assert(IS_P2ALIGNED(tcp6ConnEntrySize,
18428485SPeter.Memishian@Sun.COM sizeof (mib2_tcp6ConnEntry_t *)));
18430Sstevel@tonic-gate break;
18440Sstevel@tonic-gate }
18450Sstevel@tonic-gate case MIB2_UDP: {
18460Sstevel@tonic-gate mib2_udp_t *udp = (mib2_udp_t *)item->valp;
18470Sstevel@tonic-gate
18480Sstevel@tonic-gate udpEntrySize = udp->udpEntrySize;
18490Sstevel@tonic-gate udp6EntrySize = udp->udp6EntrySize;
18500Sstevel@tonic-gate assert(IS_P2ALIGNED(udpEntrySize,
18518485SPeter.Memishian@Sun.COM sizeof (mib2_udpEntry_t *)));
18528485SPeter.Memishian@Sun.COM assert(IS_P2ALIGNED(udp6EntrySize,
18538485SPeter.Memishian@Sun.COM sizeof (mib2_udp6Entry_t *)));
18540Sstevel@tonic-gate break;
18550Sstevel@tonic-gate }
18560Sstevel@tonic-gate case MIB2_SCTP: {
18570Sstevel@tonic-gate mib2_sctp_t *sctp = (mib2_sctp_t *)item->valp;
18580Sstevel@tonic-gate
18590Sstevel@tonic-gate sctpEntrySize = sctp->sctpEntrySize;
18600Sstevel@tonic-gate sctpLocalEntrySize = sctp->sctpLocalEntrySize;
18610Sstevel@tonic-gate sctpRemoteEntrySize = sctp->sctpRemoteEntrySize;
18620Sstevel@tonic-gate break;
18630Sstevel@tonic-gate }
18640Sstevel@tonic-gate }
18650Sstevel@tonic-gate } /* 'for' loop 1 ends */
18660Sstevel@tonic-gate
186711042SErik.Nordmark@Sun.COM if (Xflag) {
18680Sstevel@tonic-gate (void) puts("mib_get_constants:");
18690Sstevel@tonic-gate (void) printf("\tipv6IfStatsEntrySize %d\n",
18700Sstevel@tonic-gate ipv6IfStatsEntrySize);
18710Sstevel@tonic-gate (void) printf("\tipAddrEntrySize %d\n", ipAddrEntrySize);
18720Sstevel@tonic-gate (void) printf("\tipRouteEntrySize %d\n", ipRouteEntrySize);
18730Sstevel@tonic-gate (void) printf("\tipNetToMediaEntrySize %d\n",
18740Sstevel@tonic-gate ipNetToMediaEntrySize);
18750Sstevel@tonic-gate (void) printf("\tipMemberEntrySize %d\n", ipMemberEntrySize);
18761676Sjpk (void) printf("\tipRouteAttributeSize %d\n",
18771676Sjpk ipRouteAttributeSize);
18780Sstevel@tonic-gate (void) printf("\tvifctlSize %d\n", vifctlSize);
18790Sstevel@tonic-gate (void) printf("\tmfcctlSize %d\n", mfcctlSize);
18800Sstevel@tonic-gate
18810Sstevel@tonic-gate (void) printf("\tipv6AddrEntrySize %d\n", ipv6AddrEntrySize);
18820Sstevel@tonic-gate (void) printf("\tipv6RouteEntrySize %d\n", ipv6RouteEntrySize);
18830Sstevel@tonic-gate (void) printf("\tipv6NetToMediaEntrySize %d\n",
18840Sstevel@tonic-gate ipv6NetToMediaEntrySize);
18850Sstevel@tonic-gate (void) printf("\tipv6MemberEntrySize %d\n",
18860Sstevel@tonic-gate ipv6MemberEntrySize);
18870Sstevel@tonic-gate (void) printf("\tipv6IfIcmpEntrySize %d\n",
18880Sstevel@tonic-gate ipv6IfIcmpEntrySize);
188911042SErik.Nordmark@Sun.COM (void) printf("\tipDestEntrySize %d\n", ipDestEntrySize);
18901676Sjpk (void) printf("\ttransportMLPSize %d\n", transportMLPSize);
18910Sstevel@tonic-gate (void) printf("\ttcpConnEntrySize %d\n", tcpConnEntrySize);
18920Sstevel@tonic-gate (void) printf("\ttcp6ConnEntrySize %d\n", tcp6ConnEntrySize);
18930Sstevel@tonic-gate (void) printf("\tudpEntrySize %d\n", udpEntrySize);
18940Sstevel@tonic-gate (void) printf("\tudp6EntrySize %d\n", udp6EntrySize);
18950Sstevel@tonic-gate (void) printf("\tsctpEntrySize %d\n", sctpEntrySize);
18960Sstevel@tonic-gate (void) printf("\tsctpLocalEntrySize %d\n", sctpLocalEntrySize);
18970Sstevel@tonic-gate (void) printf("\tsctpRemoteEntrySize %d\n",
18980Sstevel@tonic-gate sctpRemoteEntrySize);
18990Sstevel@tonic-gate }
19000Sstevel@tonic-gate }
19010Sstevel@tonic-gate
19020Sstevel@tonic-gate
19030Sstevel@tonic-gate /* ----------------------------- STAT_REPORT ------------------------------- */
19040Sstevel@tonic-gate
19050Sstevel@tonic-gate static void
stat_report(mib_item_t * item)19060Sstevel@tonic-gate stat_report(mib_item_t *item)
19070Sstevel@tonic-gate {
19080Sstevel@tonic-gate int jtemp = 0;
19090Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1];
19100Sstevel@tonic-gate
19110Sstevel@tonic-gate /* 'for' loop 1: */
19120Sstevel@tonic-gate for (; item; item = item->next_item) {
191311042SErik.Nordmark@Sun.COM if (Xflag) {
19140Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp);
19150Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, "
19160Sstevel@tonic-gate "length = %d, valp = 0x%p\n",
19170Sstevel@tonic-gate item->group, item->mib_id,
19180Sstevel@tonic-gate item->length, item->valp);
19190Sstevel@tonic-gate }
19200Sstevel@tonic-gate if (item->mib_id != 0)
19210Sstevel@tonic-gate continue; /* 'for' loop 1 */
19220Sstevel@tonic-gate
19230Sstevel@tonic-gate switch (item->group) {
19240Sstevel@tonic-gate case MIB2_IP: {
19250Sstevel@tonic-gate mib2_ip_t *ip = (mib2_ip_t *)item->valp;
19260Sstevel@tonic-gate
19270Sstevel@tonic-gate if (protocol_selected(IPPROTO_IP) &&
19280Sstevel@tonic-gate family_selected(AF_INET)) {
19290Sstevel@tonic-gate (void) fputs(v4compat ? "\nIP" : "\nIPv4",
19300Sstevel@tonic-gate stdout);
19310Sstevel@tonic-gate print_ip_stats(ip);
19320Sstevel@tonic-gate }
19330Sstevel@tonic-gate break;
19340Sstevel@tonic-gate }
19350Sstevel@tonic-gate case MIB2_ICMP: {
19360Sstevel@tonic-gate mib2_icmp_t *icmp =
19370Sstevel@tonic-gate (mib2_icmp_t *)item->valp;
19380Sstevel@tonic-gate
19390Sstevel@tonic-gate if (protocol_selected(IPPROTO_ICMP) &&
19400Sstevel@tonic-gate family_selected(AF_INET)) {
19410Sstevel@tonic-gate (void) fputs(v4compat ? "\nICMP" : "\nICMPv4",
19420Sstevel@tonic-gate stdout);
19430Sstevel@tonic-gate print_icmp_stats(icmp);
19440Sstevel@tonic-gate }
19450Sstevel@tonic-gate break;
19460Sstevel@tonic-gate }
19470Sstevel@tonic-gate case MIB2_IP6: {
19480Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t *ip6;
19490Sstevel@tonic-gate mib2_ipv6IfStatsEntry_t sum6;
19500Sstevel@tonic-gate
19510Sstevel@tonic-gate if (!(protocol_selected(IPPROTO_IPV6)) ||
19520Sstevel@tonic-gate !(family_selected(AF_INET6)))
19530Sstevel@tonic-gate break;
19540Sstevel@tonic-gate bzero(&sum6, sizeof (sum6));
19550Sstevel@tonic-gate /* 'for' loop 2a: */
19560Sstevel@tonic-gate for (ip6 = (mib2_ipv6IfStatsEntry_t *)item->valp;
19578485SPeter.Memishian@Sun.COM (char *)ip6 < (char *)item->valp + item->length;
19580Sstevel@tonic-gate /* LINTED: (note 1) */
19590Sstevel@tonic-gate ip6 = (mib2_ipv6IfStatsEntry_t *)((char *)ip6 +
19600Sstevel@tonic-gate ipv6IfStatsEntrySize)) {
19610Sstevel@tonic-gate if (ip6->ipv6IfIndex == 0) {
19620Sstevel@tonic-gate /*
19630Sstevel@tonic-gate * The "unknown interface" ip6
19640Sstevel@tonic-gate * mib. Just add to the sum.
19650Sstevel@tonic-gate */
19660Sstevel@tonic-gate sum_ip6_stats(ip6, &sum6);
19670Sstevel@tonic-gate continue; /* 'for' loop 2a */
19680Sstevel@tonic-gate }
19690Sstevel@tonic-gate if (Aflag) {
19700Sstevel@tonic-gate (void) printf("\nIPv6 for %s\n",
19718485SPeter.Memishian@Sun.COM ifindex2str(ip6->ipv6IfIndex,
19728485SPeter.Memishian@Sun.COM ifname));
19730Sstevel@tonic-gate print_ip6_stats(ip6);
19740Sstevel@tonic-gate }
19750Sstevel@tonic-gate sum_ip6_stats(ip6, &sum6);
19760Sstevel@tonic-gate } /* 'for' loop 2a ends */
19770Sstevel@tonic-gate (void) fputs("\nIPv6", stdout);
19780Sstevel@tonic-gate print_ip6_stats(&sum6);
19790Sstevel@tonic-gate break;
19800Sstevel@tonic-gate }
19810Sstevel@tonic-gate case MIB2_ICMP6: {
19820Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t *icmp6;
19830Sstevel@tonic-gate mib2_ipv6IfIcmpEntry_t sum6;
19840Sstevel@tonic-gate
19850Sstevel@tonic-gate if (!(protocol_selected(IPPROTO_ICMPV6)) ||
19860Sstevel@tonic-gate !(family_selected(AF_INET6)))
19870Sstevel@tonic-gate break;
19880Sstevel@tonic-gate bzero(&sum6, sizeof (sum6));
19890Sstevel@tonic-gate /* 'for' loop 2b: */
19908485SPeter.Memishian@Sun.COM for (icmp6 = (mib2_ipv6IfIcmpEntry_t *)item->valp;
19918485SPeter.Memishian@Sun.COM (char *)icmp6 < (char *)item->valp + item->length;
19928485SPeter.Memishian@Sun.COM icmp6 = (void *)((char *)icmp6 +
19938485SPeter.Memishian@Sun.COM ipv6IfIcmpEntrySize)) {
19940Sstevel@tonic-gate if (icmp6->ipv6IfIcmpIfIndex == 0) {
19950Sstevel@tonic-gate /*
19960Sstevel@tonic-gate * The "unknown interface" icmp6
19970Sstevel@tonic-gate * mib. Just add to the sum.
19980Sstevel@tonic-gate */
19990Sstevel@tonic-gate sum_icmp6_stats(icmp6, &sum6);
20000Sstevel@tonic-gate continue; /* 'for' loop 2b: */
20010Sstevel@tonic-gate }
20020Sstevel@tonic-gate if (Aflag) {
20038485SPeter.Memishian@Sun.COM (void) printf("\nICMPv6 for %s\n",
20048485SPeter.Memishian@Sun.COM ifindex2str(
20058485SPeter.Memishian@Sun.COM icmp6->ipv6IfIcmpIfIndex, ifname));
20060Sstevel@tonic-gate print_icmp6_stats(icmp6);
20070Sstevel@tonic-gate }
20080Sstevel@tonic-gate sum_icmp6_stats(icmp6, &sum6);
20090Sstevel@tonic-gate } /* 'for' loop 2b ends */
20100Sstevel@tonic-gate (void) fputs("\nICMPv6", stdout);
20110Sstevel@tonic-gate print_icmp6_stats(&sum6);
20120Sstevel@tonic-gate break;
20130Sstevel@tonic-gate }
20140Sstevel@tonic-gate case MIB2_TCP: {
20150Sstevel@tonic-gate mib2_tcp_t *tcp = (mib2_tcp_t *)item->valp;
20160Sstevel@tonic-gate
20170Sstevel@tonic-gate if (protocol_selected(IPPROTO_TCP) &&
20180Sstevel@tonic-gate (family_selected(AF_INET) ||
20190Sstevel@tonic-gate family_selected(AF_INET6))) {
20200Sstevel@tonic-gate (void) fputs("\nTCP", stdout);
20210Sstevel@tonic-gate print_tcp_stats(tcp);
20220Sstevel@tonic-gate }
20230Sstevel@tonic-gate break;
20240Sstevel@tonic-gate }
20250Sstevel@tonic-gate case MIB2_UDP: {
20260Sstevel@tonic-gate mib2_udp_t *udp = (mib2_udp_t *)item->valp;
20270Sstevel@tonic-gate
20280Sstevel@tonic-gate if (protocol_selected(IPPROTO_UDP) &&
20290Sstevel@tonic-gate (family_selected(AF_INET) ||
20300Sstevel@tonic-gate family_selected(AF_INET6))) {
20310Sstevel@tonic-gate (void) fputs("\nUDP", stdout);
20320Sstevel@tonic-gate print_udp_stats(udp);
20330Sstevel@tonic-gate }
20340Sstevel@tonic-gate break;
20350Sstevel@tonic-gate }
20360Sstevel@tonic-gate case MIB2_SCTP: {
20370Sstevel@tonic-gate mib2_sctp_t *sctp = (mib2_sctp_t *)item->valp;
20380Sstevel@tonic-gate
20390Sstevel@tonic-gate if (protocol_selected(IPPROTO_SCTP) &&
20400Sstevel@tonic-gate (family_selected(AF_INET) ||
20410Sstevel@tonic-gate family_selected(AF_INET6))) {
20420Sstevel@tonic-gate (void) fputs("\nSCTP", stdout);
20430Sstevel@tonic-gate print_sctp_stats(sctp);
20440Sstevel@tonic-gate }
20450Sstevel@tonic-gate break;
20460Sstevel@tonic-gate }
20470Sstevel@tonic-gate case EXPER_RAWIP: {
20480Sstevel@tonic-gate mib2_rawip_t *rawip =
20490Sstevel@tonic-gate (mib2_rawip_t *)item->valp;
20500Sstevel@tonic-gate
20510Sstevel@tonic-gate if (protocol_selected(IPPROTO_RAW) &&
20520Sstevel@tonic-gate (family_selected(AF_INET) ||
20530Sstevel@tonic-gate family_selected(AF_INET6))) {
20540Sstevel@tonic-gate (void) fputs("\nRAWIP", stdout);
20550Sstevel@tonic-gate print_rawip_stats(rawip);
20560Sstevel@tonic-gate }
20570Sstevel@tonic-gate break;
20580Sstevel@tonic-gate }
20590Sstevel@tonic-gate case EXPER_IGMP: {
20600Sstevel@tonic-gate struct igmpstat *igps =
20610Sstevel@tonic-gate (struct igmpstat *)item->valp;
20620Sstevel@tonic-gate
20630Sstevel@tonic-gate if (protocol_selected(IPPROTO_IGMP) &&
20640Sstevel@tonic-gate (family_selected(AF_INET))) {
20650Sstevel@tonic-gate (void) fputs("\nIGMP:\n", stdout);
20660Sstevel@tonic-gate print_igmp_stats(igps);
20670Sstevel@tonic-gate }
20680Sstevel@tonic-gate break;
20690Sstevel@tonic-gate }
20700Sstevel@tonic-gate }
20710Sstevel@tonic-gate } /* 'for' loop 1 ends */
20720Sstevel@tonic-gate (void) putchar('\n');
20730Sstevel@tonic-gate (void) fflush(stdout);
20740Sstevel@tonic-gate }
20750Sstevel@tonic-gate
20760Sstevel@tonic-gate static void
print_ip_stats(mib2_ip_t * ip)20770Sstevel@tonic-gate print_ip_stats(mib2_ip_t *ip)
20780Sstevel@tonic-gate {
20790Sstevel@tonic-gate prval_init();
20800Sstevel@tonic-gate pr_int_val("ipForwarding", ip->ipForwarding);
20810Sstevel@tonic-gate pr_int_val("ipDefaultTTL", ip->ipDefaultTTL);
20820Sstevel@tonic-gate prval("ipInReceives", ip->ipInReceives);
20830Sstevel@tonic-gate prval("ipInHdrErrors", ip->ipInHdrErrors);
20840Sstevel@tonic-gate prval("ipInAddrErrors", ip->ipInAddrErrors);
20850Sstevel@tonic-gate prval("ipInCksumErrs", ip->ipInCksumErrs);
20860Sstevel@tonic-gate prval("ipForwDatagrams", ip->ipForwDatagrams);
20870Sstevel@tonic-gate prval("ipForwProhibits", ip->ipForwProhibits);
20880Sstevel@tonic-gate prval("ipInUnknownProtos", ip->ipInUnknownProtos);
20890Sstevel@tonic-gate prval("ipInDiscards", ip->ipInDiscards);
20900Sstevel@tonic-gate prval("ipInDelivers", ip->ipInDelivers);
20910Sstevel@tonic-gate prval("ipOutRequests", ip->ipOutRequests);
20920Sstevel@tonic-gate prval("ipOutDiscards", ip->ipOutDiscards);
20930Sstevel@tonic-gate prval("ipOutNoRoutes", ip->ipOutNoRoutes);
20940Sstevel@tonic-gate pr_int_val("ipReasmTimeout", ip->ipReasmTimeout);
20950Sstevel@tonic-gate prval("ipReasmReqds", ip->ipReasmReqds);
20960Sstevel@tonic-gate prval("ipReasmOKs", ip->ipReasmOKs);
20970Sstevel@tonic-gate prval("ipReasmFails", ip->ipReasmFails);
20980Sstevel@tonic-gate prval("ipReasmDuplicates", ip->ipReasmDuplicates);
20990Sstevel@tonic-gate prval("ipReasmPartDups", ip->ipReasmPartDups);
21000Sstevel@tonic-gate prval("ipFragOKs", ip->ipFragOKs);
21010Sstevel@tonic-gate prval("ipFragFails", ip->ipFragFails);
21020Sstevel@tonic-gate prval("ipFragCreates", ip->ipFragCreates);
21030Sstevel@tonic-gate prval("ipRoutingDiscards", ip->ipRoutingDiscards);
21040Sstevel@tonic-gate
21050Sstevel@tonic-gate prval("tcpInErrs", ip->tcpInErrs);
21060Sstevel@tonic-gate prval("udpNoPorts", ip->udpNoPorts);
21070Sstevel@tonic-gate prval("udpInCksumErrs", ip->udpInCksumErrs);
21080Sstevel@tonic-gate prval("udpInOverflows", ip->udpInOverflows);
21090Sstevel@tonic-gate prval("rawipInOverflows", ip->rawipInOverflows);
21100Sstevel@tonic-gate prval("ipsecInSucceeded", ip->ipsecInSucceeded);
21110Sstevel@tonic-gate prval("ipsecInFailed", ip->ipsecInFailed);
21120Sstevel@tonic-gate prval("ipInIPv6", ip->ipInIPv6);
21130Sstevel@tonic-gate prval("ipOutIPv6", ip->ipOutIPv6);
21140Sstevel@tonic-gate prval("ipOutSwitchIPv6", ip->ipOutSwitchIPv6);
21150Sstevel@tonic-gate prval_end();
21160Sstevel@tonic-gate }
21170Sstevel@tonic-gate
21180Sstevel@tonic-gate static void
print_icmp_stats(mib2_icmp_t * icmp)21190Sstevel@tonic-gate print_icmp_stats(mib2_icmp_t *icmp)
21200Sstevel@tonic-gate {
21210Sstevel@tonic-gate prval_init();
21220Sstevel@tonic-gate prval("icmpInMsgs", icmp->icmpInMsgs);
21230Sstevel@tonic-gate prval("icmpInErrors", icmp->icmpInErrors);
21240Sstevel@tonic-gate prval("icmpInCksumErrs", icmp->icmpInCksumErrs);
21250Sstevel@tonic-gate prval("icmpInUnknowns", icmp->icmpInUnknowns);
21260Sstevel@tonic-gate prval("icmpInDestUnreachs", icmp->icmpInDestUnreachs);
21270Sstevel@tonic-gate prval("icmpInTimeExcds", icmp->icmpInTimeExcds);
21280Sstevel@tonic-gate prval("icmpInParmProbs", icmp->icmpInParmProbs);
21290Sstevel@tonic-gate prval("icmpInSrcQuenchs", icmp->icmpInSrcQuenchs);
21300Sstevel@tonic-gate prval("icmpInRedirects", icmp->icmpInRedirects);
21310Sstevel@tonic-gate prval("icmpInBadRedirects", icmp->icmpInBadRedirects);
21320Sstevel@tonic-gate prval("icmpInEchos", icmp->icmpInEchos);
21330Sstevel@tonic-gate prval("icmpInEchoReps", icmp->icmpInEchoReps);
21340Sstevel@tonic-gate prval("icmpInTimestamps", icmp->icmpInTimestamps);
21350Sstevel@tonic-gate prval("icmpInTimestampReps", icmp->icmpInTimestampReps);
21360Sstevel@tonic-gate prval("icmpInAddrMasks", icmp->icmpInAddrMasks);
21370Sstevel@tonic-gate prval("icmpInAddrMaskReps", icmp->icmpInAddrMaskReps);
21380Sstevel@tonic-gate prval("icmpInFragNeeded", icmp->icmpInFragNeeded);
21390Sstevel@tonic-gate prval("icmpOutMsgs", icmp->icmpOutMsgs);
21400Sstevel@tonic-gate prval("icmpOutDrops", icmp->icmpOutDrops);
21410Sstevel@tonic-gate prval("icmpOutErrors", icmp->icmpOutErrors);
21420Sstevel@tonic-gate prval("icmpOutDestUnreachs", icmp->icmpOutDestUnreachs);
21430Sstevel@tonic-gate prval("icmpOutTimeExcds", icmp->icmpOutTimeExcds);
21440Sstevel@tonic-gate prval("icmpOutParmProbs", icmp->icmpOutParmProbs);
21450Sstevel@tonic-gate prval("icmpOutSrcQuenchs", icmp->icmpOutSrcQuenchs);
21460Sstevel@tonic-gate prval("icmpOutRedirects", icmp->icmpOutRedirects);
21470Sstevel@tonic-gate prval("icmpOutEchos", icmp->icmpOutEchos);
21480Sstevel@tonic-gate prval("icmpOutEchoReps", icmp->icmpOutEchoReps);
21490Sstevel@tonic-gate prval("icmpOutTimestamps", icmp->icmpOutTimestamps);
21500Sstevel@tonic-gate prval("icmpOutTimestampReps", icmp->icmpOutTimestampReps);
21510Sstevel@tonic-gate prval("icmpOutAddrMasks", icmp->icmpOutAddrMasks);
21520Sstevel@tonic-gate prval("icmpOutAddrMaskReps", icmp->icmpOutAddrMaskReps);
21530Sstevel@tonic-gate prval("icmpOutFragNeeded", icmp->icmpOutFragNeeded);
21540Sstevel@tonic-gate prval("icmpInOverflows", icmp->icmpInOverflows);
21550Sstevel@tonic-gate prval_end();
21560Sstevel@tonic-gate }
21570Sstevel@tonic-gate
21580Sstevel@tonic-gate static void
print_ip6_stats(mib2_ipv6IfStatsEntry_t * ip6)21590Sstevel@tonic-gate print_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6)
21600Sstevel@tonic-gate {
21610Sstevel@tonic-gate prval_init();
21620Sstevel@tonic-gate prval("ipv6Forwarding", ip6->ipv6Forwarding);
21630Sstevel@tonic-gate prval("ipv6DefaultHopLimit", ip6->ipv6DefaultHopLimit);
21640Sstevel@tonic-gate
21650Sstevel@tonic-gate prval("ipv6InReceives", ip6->ipv6InReceives);
21660Sstevel@tonic-gate prval("ipv6InHdrErrors", ip6->ipv6InHdrErrors);
21670Sstevel@tonic-gate prval("ipv6InTooBigErrors", ip6->ipv6InTooBigErrors);
21680Sstevel@tonic-gate prval("ipv6InNoRoutes", ip6->ipv6InNoRoutes);
21690Sstevel@tonic-gate prval("ipv6InAddrErrors", ip6->ipv6InAddrErrors);
21700Sstevel@tonic-gate prval("ipv6InUnknownProtos", ip6->ipv6InUnknownProtos);
21710Sstevel@tonic-gate prval("ipv6InTruncatedPkts", ip6->ipv6InTruncatedPkts);
21720Sstevel@tonic-gate prval("ipv6InDiscards", ip6->ipv6InDiscards);
21730Sstevel@tonic-gate prval("ipv6InDelivers", ip6->ipv6InDelivers);
21740Sstevel@tonic-gate prval("ipv6OutForwDatagrams", ip6->ipv6OutForwDatagrams);
21750Sstevel@tonic-gate prval("ipv6OutRequests", ip6->ipv6OutRequests);
21760Sstevel@tonic-gate prval("ipv6OutDiscards", ip6->ipv6OutDiscards);
21770Sstevel@tonic-gate prval("ipv6OutNoRoutes", ip6->ipv6OutNoRoutes);
21780Sstevel@tonic-gate prval("ipv6OutFragOKs", ip6->ipv6OutFragOKs);
21790Sstevel@tonic-gate prval("ipv6OutFragFails", ip6->ipv6OutFragFails);
21800Sstevel@tonic-gate prval("ipv6OutFragCreates", ip6->ipv6OutFragCreates);
21810Sstevel@tonic-gate prval("ipv6ReasmReqds", ip6->ipv6ReasmReqds);
21820Sstevel@tonic-gate prval("ipv6ReasmOKs", ip6->ipv6ReasmOKs);
21830Sstevel@tonic-gate prval("ipv6ReasmFails", ip6->ipv6ReasmFails);
21840Sstevel@tonic-gate prval("ipv6InMcastPkts", ip6->ipv6InMcastPkts);
21850Sstevel@tonic-gate prval("ipv6OutMcastPkts", ip6->ipv6OutMcastPkts);
21860Sstevel@tonic-gate prval("ipv6ReasmDuplicates", ip6->ipv6ReasmDuplicates);
21870Sstevel@tonic-gate prval("ipv6ReasmPartDups", ip6->ipv6ReasmPartDups);
21880Sstevel@tonic-gate prval("ipv6ForwProhibits", ip6->ipv6ForwProhibits);
21890Sstevel@tonic-gate prval("udpInCksumErrs", ip6->udpInCksumErrs);
21900Sstevel@tonic-gate prval("udpInOverflows", ip6->udpInOverflows);
21910Sstevel@tonic-gate prval("rawipInOverflows", ip6->rawipInOverflows);
21920Sstevel@tonic-gate prval("ipv6InIPv4", ip6->ipv6InIPv4);
21930Sstevel@tonic-gate prval("ipv6OutIPv4", ip6->ipv6OutIPv4);
21940Sstevel@tonic-gate prval("ipv6OutSwitchIPv4", ip6->ipv6OutSwitchIPv4);
21950Sstevel@tonic-gate prval_end();
21960Sstevel@tonic-gate }
21970Sstevel@tonic-gate
21980Sstevel@tonic-gate static void
print_icmp6_stats(mib2_ipv6IfIcmpEntry_t * icmp6)21990Sstevel@tonic-gate print_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6)
22000Sstevel@tonic-gate {
22010Sstevel@tonic-gate prval_init();
22020Sstevel@tonic-gate prval("icmp6InMsgs", icmp6->ipv6IfIcmpInMsgs);
22030Sstevel@tonic-gate prval("icmp6InErrors", icmp6->ipv6IfIcmpInErrors);
22040Sstevel@tonic-gate prval("icmp6InDestUnreachs", icmp6->ipv6IfIcmpInDestUnreachs);
22050Sstevel@tonic-gate prval("icmp6InAdminProhibs", icmp6->ipv6IfIcmpInAdminProhibs);
22060Sstevel@tonic-gate prval("icmp6InTimeExcds", icmp6->ipv6IfIcmpInTimeExcds);
22070Sstevel@tonic-gate prval("icmp6InParmProblems", icmp6->ipv6IfIcmpInParmProblems);
22080Sstevel@tonic-gate prval("icmp6InPktTooBigs", icmp6->ipv6IfIcmpInPktTooBigs);
22090Sstevel@tonic-gate prval("icmp6InEchos", icmp6->ipv6IfIcmpInEchos);
22100Sstevel@tonic-gate prval("icmp6InEchoReplies", icmp6->ipv6IfIcmpInEchoReplies);
22110Sstevel@tonic-gate prval("icmp6InRouterSols", icmp6->ipv6IfIcmpInRouterSolicits);
22120Sstevel@tonic-gate prval("icmp6InRouterAds",
22130Sstevel@tonic-gate icmp6->ipv6IfIcmpInRouterAdvertisements);
22140Sstevel@tonic-gate prval("icmp6InNeighborSols", icmp6->ipv6IfIcmpInNeighborSolicits);
22150Sstevel@tonic-gate prval("icmp6InNeighborAds",
22160Sstevel@tonic-gate icmp6->ipv6IfIcmpInNeighborAdvertisements);
22170Sstevel@tonic-gate prval("icmp6InRedirects", icmp6->ipv6IfIcmpInRedirects);
22180Sstevel@tonic-gate prval("icmp6InBadRedirects", icmp6->ipv6IfIcmpInBadRedirects);
22190Sstevel@tonic-gate prval("icmp6InGroupQueries", icmp6->ipv6IfIcmpInGroupMembQueries);
22200Sstevel@tonic-gate prval("icmp6InGroupResps", icmp6->ipv6IfIcmpInGroupMembResponses);
22210Sstevel@tonic-gate prval("icmp6InGroupReds", icmp6->ipv6IfIcmpInGroupMembReductions);
22220Sstevel@tonic-gate prval("icmp6InOverflows", icmp6->ipv6IfIcmpInOverflows);
22230Sstevel@tonic-gate prval_end();
22240Sstevel@tonic-gate prval_init();
22250Sstevel@tonic-gate prval("icmp6OutMsgs", icmp6->ipv6IfIcmpOutMsgs);
22260Sstevel@tonic-gate prval("icmp6OutErrors", icmp6->ipv6IfIcmpOutErrors);
22270Sstevel@tonic-gate prval("icmp6OutDestUnreachs", icmp6->ipv6IfIcmpOutDestUnreachs);
22280Sstevel@tonic-gate prval("icmp6OutAdminProhibs", icmp6->ipv6IfIcmpOutAdminProhibs);
22290Sstevel@tonic-gate prval("icmp6OutTimeExcds", icmp6->ipv6IfIcmpOutTimeExcds);
22300Sstevel@tonic-gate prval("icmp6OutParmProblems", icmp6->ipv6IfIcmpOutParmProblems);
22310Sstevel@tonic-gate prval("icmp6OutPktTooBigs", icmp6->ipv6IfIcmpOutPktTooBigs);
22320Sstevel@tonic-gate prval("icmp6OutEchos", icmp6->ipv6IfIcmpOutEchos);
22330Sstevel@tonic-gate prval("icmp6OutEchoReplies", icmp6->ipv6IfIcmpOutEchoReplies);
22340Sstevel@tonic-gate prval("icmp6OutRouterSols", icmp6->ipv6IfIcmpOutRouterSolicits);
22350Sstevel@tonic-gate prval("icmp6OutRouterAds",
22360Sstevel@tonic-gate icmp6->ipv6IfIcmpOutRouterAdvertisements);
22370Sstevel@tonic-gate prval("icmp6OutNeighborSols", icmp6->ipv6IfIcmpOutNeighborSolicits);
22380Sstevel@tonic-gate prval("icmp6OutNeighborAds",
22390Sstevel@tonic-gate icmp6->ipv6IfIcmpOutNeighborAdvertisements);
22400Sstevel@tonic-gate prval("icmp6OutRedirects", icmp6->ipv6IfIcmpOutRedirects);
22410Sstevel@tonic-gate prval("icmp6OutGroupQueries", icmp6->ipv6IfIcmpOutGroupMembQueries);
22420Sstevel@tonic-gate prval("icmp6OutGroupResps",
22430Sstevel@tonic-gate icmp6->ipv6IfIcmpOutGroupMembResponses);
22440Sstevel@tonic-gate prval("icmp6OutGroupReds",
22450Sstevel@tonic-gate icmp6->ipv6IfIcmpOutGroupMembReductions);
22460Sstevel@tonic-gate prval_end();
22470Sstevel@tonic-gate }
22480Sstevel@tonic-gate
22490Sstevel@tonic-gate static void
print_sctp_stats(mib2_sctp_t * sctp)22500Sstevel@tonic-gate print_sctp_stats(mib2_sctp_t *sctp)
22510Sstevel@tonic-gate {
22520Sstevel@tonic-gate prval_init();
22530Sstevel@tonic-gate pr_sctp_rtoalgo("sctpRtoAlgorithm", sctp->sctpRtoAlgorithm);
22540Sstevel@tonic-gate prval("sctpRtoMin", sctp->sctpRtoMin);
22550Sstevel@tonic-gate prval("sctpRtoMax", sctp->sctpRtoMax);
22560Sstevel@tonic-gate prval("sctpRtoInitial", sctp->sctpRtoInitial);
22570Sstevel@tonic-gate pr_int_val("sctpMaxAssocs", sctp->sctpMaxAssocs);
22580Sstevel@tonic-gate prval("sctpValCookieLife", sctp->sctpValCookieLife);
22590Sstevel@tonic-gate prval("sctpMaxInitRetr", sctp->sctpMaxInitRetr);
22600Sstevel@tonic-gate prval("sctpCurrEstab", sctp->sctpCurrEstab);
22610Sstevel@tonic-gate prval("sctpActiveEstab", sctp->sctpActiveEstab);
22620Sstevel@tonic-gate prval("sctpPassiveEstab", sctp->sctpPassiveEstab);
22630Sstevel@tonic-gate prval("sctpAborted", sctp->sctpAborted);
22640Sstevel@tonic-gate prval("sctpShutdowns", sctp->sctpShutdowns);
22650Sstevel@tonic-gate prval("sctpOutOfBlue", sctp->sctpOutOfBlue);
22660Sstevel@tonic-gate prval("sctpChecksumError", sctp->sctpChecksumError);
22670Sstevel@tonic-gate prval64("sctpOutCtrlChunks", sctp->sctpOutCtrlChunks);
22680Sstevel@tonic-gate prval64("sctpOutOrderChunks", sctp->sctpOutOrderChunks);
22690Sstevel@tonic-gate prval64("sctpOutUnorderChunks", sctp->sctpOutUnorderChunks);
22700Sstevel@tonic-gate prval64("sctpRetransChunks", sctp->sctpRetransChunks);
22710Sstevel@tonic-gate prval("sctpOutAck", sctp->sctpOutAck);
22720Sstevel@tonic-gate prval("sctpOutAckDelayed", sctp->sctpOutAckDelayed);
22730Sstevel@tonic-gate prval("sctpOutWinUpdate", sctp->sctpOutWinUpdate);
22740Sstevel@tonic-gate prval("sctpOutFastRetrans", sctp->sctpOutFastRetrans);
22750Sstevel@tonic-gate prval("sctpOutWinProbe", sctp->sctpOutWinProbe);
22760Sstevel@tonic-gate prval64("sctpInCtrlChunks", sctp->sctpInCtrlChunks);
22770Sstevel@tonic-gate prval64("sctpInOrderChunks", sctp->sctpInOrderChunks);
22780Sstevel@tonic-gate prval64("sctpInUnorderChunks", sctp->sctpInUnorderChunks);
22790Sstevel@tonic-gate prval("sctpInAck", sctp->sctpInAck);
22800Sstevel@tonic-gate prval("sctpInDupAck", sctp->sctpInDupAck);
22810Sstevel@tonic-gate prval("sctpInAckUnsent", sctp->sctpInAckUnsent);
22820Sstevel@tonic-gate prval64("sctpFragUsrMsgs", sctp->sctpFragUsrMsgs);
22830Sstevel@tonic-gate prval64("sctpReasmUsrMsgs", sctp->sctpReasmUsrMsgs);
22840Sstevel@tonic-gate prval64("sctpOutSCTPPkts", sctp->sctpOutSCTPPkts);
22850Sstevel@tonic-gate prval64("sctpInSCTPPkts", sctp->sctpInSCTPPkts);
22860Sstevel@tonic-gate prval("sctpInInvalidCookie", sctp->sctpInInvalidCookie);
22870Sstevel@tonic-gate prval("sctpTimRetrans", sctp->sctpTimRetrans);
22880Sstevel@tonic-gate prval("sctpTimRetransDrop", sctp->sctpTimRetransDrop);
22890Sstevel@tonic-gate prval("sctpTimHearBeatProbe", sctp->sctpTimHeartBeatProbe);
22900Sstevel@tonic-gate prval("sctpTimHearBeatDrop", sctp->sctpTimHeartBeatDrop);
22910Sstevel@tonic-gate prval("sctpListenDrop", sctp->sctpListenDrop);
22920Sstevel@tonic-gate prval("sctpInClosed", sctp->sctpInClosed);
22930Sstevel@tonic-gate prval_end();
22940Sstevel@tonic-gate }
22950Sstevel@tonic-gate
22960Sstevel@tonic-gate static void
print_tcp_stats(mib2_tcp_t * tcp)22970Sstevel@tonic-gate print_tcp_stats(mib2_tcp_t *tcp)
22980Sstevel@tonic-gate {
22990Sstevel@tonic-gate prval_init();
23000Sstevel@tonic-gate pr_int_val("tcpRtoAlgorithm", tcp->tcpRtoAlgorithm);
23010Sstevel@tonic-gate pr_int_val("tcpRtoMin", tcp->tcpRtoMin);
23020Sstevel@tonic-gate pr_int_val("tcpRtoMax", tcp->tcpRtoMax);
23030Sstevel@tonic-gate pr_int_val("tcpMaxConn", tcp->tcpMaxConn);
23040Sstevel@tonic-gate prval("tcpActiveOpens", tcp->tcpActiveOpens);
23050Sstevel@tonic-gate prval("tcpPassiveOpens", tcp->tcpPassiveOpens);
23060Sstevel@tonic-gate prval("tcpAttemptFails", tcp->tcpAttemptFails);
23070Sstevel@tonic-gate prval("tcpEstabResets", tcp->tcpEstabResets);
23080Sstevel@tonic-gate prval("tcpCurrEstab", tcp->tcpCurrEstab);
23093284Sapersson prval64("tcpOutSegs", tcp->tcpHCOutSegs);
23100Sstevel@tonic-gate prval("tcpOutDataSegs", tcp->tcpOutDataSegs);
23110Sstevel@tonic-gate prval("tcpOutDataBytes", tcp->tcpOutDataBytes);
23120Sstevel@tonic-gate prval("tcpRetransSegs", tcp->tcpRetransSegs);
23130Sstevel@tonic-gate prval("tcpRetransBytes", tcp->tcpRetransBytes);
23140Sstevel@tonic-gate prval("tcpOutAck", tcp->tcpOutAck);
23150Sstevel@tonic-gate prval("tcpOutAckDelayed", tcp->tcpOutAckDelayed);
23160Sstevel@tonic-gate prval("tcpOutUrg", tcp->tcpOutUrg);
23170Sstevel@tonic-gate prval("tcpOutWinUpdate", tcp->tcpOutWinUpdate);
23180Sstevel@tonic-gate prval("tcpOutWinProbe", tcp->tcpOutWinProbe);
23190Sstevel@tonic-gate prval("tcpOutControl", tcp->tcpOutControl);
23200Sstevel@tonic-gate prval("tcpOutRsts", tcp->tcpOutRsts);
23210Sstevel@tonic-gate prval("tcpOutFastRetrans", tcp->tcpOutFastRetrans);
23223284Sapersson prval64("tcpInSegs", tcp->tcpHCInSegs);
23230Sstevel@tonic-gate prval_end();
23240Sstevel@tonic-gate prval("tcpInAckSegs", tcp->tcpInAckSegs);
23250Sstevel@tonic-gate prval("tcpInAckBytes", tcp->tcpInAckBytes);
23260Sstevel@tonic-gate prval("tcpInDupAck", tcp->tcpInDupAck);
23270Sstevel@tonic-gate prval("tcpInAckUnsent", tcp->tcpInAckUnsent);
23280Sstevel@tonic-gate prval("tcpInInorderSegs", tcp->tcpInDataInorderSegs);
23290Sstevel@tonic-gate prval("tcpInInorderBytes", tcp->tcpInDataInorderBytes);
23300Sstevel@tonic-gate prval("tcpInUnorderSegs", tcp->tcpInDataUnorderSegs);
23310Sstevel@tonic-gate prval("tcpInUnorderBytes", tcp->tcpInDataUnorderBytes);
23320Sstevel@tonic-gate prval("tcpInDupSegs", tcp->tcpInDataDupSegs);
23330Sstevel@tonic-gate prval("tcpInDupBytes", tcp->tcpInDataDupBytes);
23340Sstevel@tonic-gate prval("tcpInPartDupSegs", tcp->tcpInDataPartDupSegs);
23350Sstevel@tonic-gate prval("tcpInPartDupBytes", tcp->tcpInDataPartDupBytes);
23360Sstevel@tonic-gate prval("tcpInPastWinSegs", tcp->tcpInDataPastWinSegs);
23370Sstevel@tonic-gate prval("tcpInPastWinBytes", tcp->tcpInDataPastWinBytes);
23380Sstevel@tonic-gate prval("tcpInWinProbe", tcp->tcpInWinProbe);
23390Sstevel@tonic-gate prval("tcpInWinUpdate", tcp->tcpInWinUpdate);
23400Sstevel@tonic-gate prval("tcpInClosed", tcp->tcpInClosed);
23410Sstevel@tonic-gate prval("tcpRttNoUpdate", tcp->tcpRttNoUpdate);
23420Sstevel@tonic-gate prval("tcpRttUpdate", tcp->tcpRttUpdate);
23430Sstevel@tonic-gate prval("tcpTimRetrans", tcp->tcpTimRetrans);
23440Sstevel@tonic-gate prval("tcpTimRetransDrop", tcp->tcpTimRetransDrop);
23450Sstevel@tonic-gate prval("tcpTimKeepalive", tcp->tcpTimKeepalive);
23460Sstevel@tonic-gate prval("tcpTimKeepaliveProbe", tcp->tcpTimKeepaliveProbe);
23470Sstevel@tonic-gate prval("tcpTimKeepaliveDrop", tcp->tcpTimKeepaliveDrop);
23480Sstevel@tonic-gate prval("tcpListenDrop", tcp->tcpListenDrop);
23490Sstevel@tonic-gate prval("tcpListenDropQ0", tcp->tcpListenDropQ0);
23500Sstevel@tonic-gate prval("tcpHalfOpenDrop", tcp->tcpHalfOpenDrop);
23510Sstevel@tonic-gate prval("tcpOutSackRetrans", tcp->tcpOutSackRetransSegs);
23520Sstevel@tonic-gate prval_end();
23530Sstevel@tonic-gate
23540Sstevel@tonic-gate }
23550Sstevel@tonic-gate
23560Sstevel@tonic-gate static void
print_udp_stats(mib2_udp_t * udp)23570Sstevel@tonic-gate print_udp_stats(mib2_udp_t *udp)
23580Sstevel@tonic-gate {
23590Sstevel@tonic-gate prval_init();
23603284Sapersson prval64("udpInDatagrams", udp->udpHCInDatagrams);
23610Sstevel@tonic-gate prval("udpInErrors", udp->udpInErrors);
23623284Sapersson prval64("udpOutDatagrams", udp->udpHCOutDatagrams);
23630Sstevel@tonic-gate prval("udpOutErrors", udp->udpOutErrors);
23640Sstevel@tonic-gate prval_end();
23650Sstevel@tonic-gate }
23660Sstevel@tonic-gate
23670Sstevel@tonic-gate static void
print_rawip_stats(mib2_rawip_t * rawip)23680Sstevel@tonic-gate print_rawip_stats(mib2_rawip_t *rawip)
23690Sstevel@tonic-gate {
23700Sstevel@tonic-gate prval_init();
23710Sstevel@tonic-gate prval("rawipInDatagrams", rawip->rawipInDatagrams);
23720Sstevel@tonic-gate prval("rawipInErrors", rawip->rawipInErrors);
23730Sstevel@tonic-gate prval("rawipInCksumErrs", rawip->rawipInCksumErrs);
23740Sstevel@tonic-gate prval("rawipOutDatagrams", rawip->rawipOutDatagrams);
23750Sstevel@tonic-gate prval("rawipOutErrors", rawip->rawipOutErrors);
23760Sstevel@tonic-gate prval_end();
23770Sstevel@tonic-gate }
23780Sstevel@tonic-gate
23790Sstevel@tonic-gate void
print_igmp_stats(struct igmpstat * igps)23800Sstevel@tonic-gate print_igmp_stats(struct igmpstat *igps)
23810Sstevel@tonic-gate {
23820Sstevel@tonic-gate (void) printf(" %10u message%s received\n",
23830Sstevel@tonic-gate igps->igps_rcv_total, PLURAL(igps->igps_rcv_total));
23840Sstevel@tonic-gate (void) printf(" %10u message%s received with too few bytes\n",
23850Sstevel@tonic-gate igps->igps_rcv_tooshort, PLURAL(igps->igps_rcv_tooshort));
23860Sstevel@tonic-gate (void) printf(" %10u message%s received with bad checksum\n",
23870Sstevel@tonic-gate igps->igps_rcv_badsum, PLURAL(igps->igps_rcv_badsum));
23880Sstevel@tonic-gate (void) printf(" %10u membership quer%s received\n",
23890Sstevel@tonic-gate igps->igps_rcv_queries, PLURALY(igps->igps_rcv_queries));
23900Sstevel@tonic-gate (void) printf(" %10u membership quer%s received with invalid "
23910Sstevel@tonic-gate "field(s)\n",
23920Sstevel@tonic-gate igps->igps_rcv_badqueries, PLURALY(igps->igps_rcv_badqueries));
23930Sstevel@tonic-gate (void) printf(" %10u membership report%s received\n",
23940Sstevel@tonic-gate igps->igps_rcv_reports, PLURAL(igps->igps_rcv_reports));
23950Sstevel@tonic-gate (void) printf(" %10u membership report%s received with invalid "
23960Sstevel@tonic-gate "field(s)\n",
23970Sstevel@tonic-gate igps->igps_rcv_badreports, PLURAL(igps->igps_rcv_badreports));
23980Sstevel@tonic-gate (void) printf(" %10u membership report%s received for groups to "
23990Sstevel@tonic-gate "which we belong\n",
24000Sstevel@tonic-gate igps->igps_rcv_ourreports, PLURAL(igps->igps_rcv_ourreports));
24010Sstevel@tonic-gate (void) printf(" %10u membership report%s sent\n",
24020Sstevel@tonic-gate igps->igps_snd_reports, PLURAL(igps->igps_snd_reports));
24030Sstevel@tonic-gate }
24040Sstevel@tonic-gate
24050Sstevel@tonic-gate static void
print_mrt_stats(struct mrtstat * mrts)24060Sstevel@tonic-gate print_mrt_stats(struct mrtstat *mrts)
24070Sstevel@tonic-gate {
24080Sstevel@tonic-gate (void) puts("DVMRP multicast routing:");
24090Sstevel@tonic-gate (void) printf(" %10u hit%s - kernel forwarding cache hits\n",
24108485SPeter.Memishian@Sun.COM mrts->mrts_mfc_hits, PLURAL(mrts->mrts_mfc_hits));
24110Sstevel@tonic-gate (void) printf(" %10u miss%s - kernel forwarding cache misses\n",
24128485SPeter.Memishian@Sun.COM mrts->mrts_mfc_misses, PLURALES(mrts->mrts_mfc_misses));
24130Sstevel@tonic-gate (void) printf(" %10u packet%s potentially forwarded\n",
24148485SPeter.Memishian@Sun.COM mrts->mrts_fwd_in, PLURAL(mrts->mrts_fwd_in));
24150Sstevel@tonic-gate (void) printf(" %10u packet%s actually sent out\n",
24168485SPeter.Memishian@Sun.COM mrts->mrts_fwd_out, PLURAL(mrts->mrts_fwd_out));
24170Sstevel@tonic-gate (void) printf(" %10u upcall%s - upcalls made to mrouted\n",
24188485SPeter.Memishian@Sun.COM mrts->mrts_upcalls, PLURAL(mrts->mrts_upcalls));
24190Sstevel@tonic-gate (void) printf(" %10u packet%s not sent out due to lack of resources\n",
24208485SPeter.Memishian@Sun.COM mrts->mrts_fwd_drop, PLURAL(mrts->mrts_fwd_drop));
24210Sstevel@tonic-gate (void) printf(" %10u datagram%s with malformed tunnel options\n",
24228485SPeter.Memishian@Sun.COM mrts->mrts_bad_tunnel, PLURAL(mrts->mrts_bad_tunnel));
24230Sstevel@tonic-gate (void) printf(" %10u datagram%s with no room for tunnel options\n",
24248485SPeter.Memishian@Sun.COM mrts->mrts_cant_tunnel, PLURAL(mrts->mrts_cant_tunnel));
24250Sstevel@tonic-gate (void) printf(" %10u datagram%s arrived on wrong interface\n",
24268485SPeter.Memishian@Sun.COM mrts->mrts_wrong_if, PLURAL(mrts->mrts_wrong_if));
24270Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped due to upcall Q overflow\n",
24288485SPeter.Memishian@Sun.COM mrts->mrts_upq_ovflw, PLURAL(mrts->mrts_upq_ovflw));
24290Sstevel@tonic-gate (void) printf(" %10u datagram%s cleaned up by the cache\n",
24308485SPeter.Memishian@Sun.COM mrts->mrts_cache_cleanups, PLURAL(mrts->mrts_cache_cleanups));
24310Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped selectively by ratelimiter\n",
24328485SPeter.Memishian@Sun.COM mrts->mrts_drop_sel, PLURAL(mrts->mrts_drop_sel));
24330Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - bucket Q overflow\n",
24348485SPeter.Memishian@Sun.COM mrts->mrts_q_overflow, PLURAL(mrts->mrts_q_overflow));
24350Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - larger than bkt size\n",
24368485SPeter.Memishian@Sun.COM mrts->mrts_pkt2large, PLURAL(mrts->mrts_pkt2large));
24370Sstevel@tonic-gate (void) printf("\nPIM multicast routing:\n");
24380Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - bad version number\n",
24398485SPeter.Memishian@Sun.COM mrts->mrts_pim_badversion, PLURAL(mrts->mrts_pim_badversion));
24400Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - bad checksum\n",
24418485SPeter.Memishian@Sun.COM mrts->mrts_pim_rcv_badcsum, PLURAL(mrts->mrts_pim_rcv_badcsum));
24420Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - bad register packets\n",
24438485SPeter.Memishian@Sun.COM mrts->mrts_pim_badregisters, PLURAL(mrts->mrts_pim_badregisters));
24440Sstevel@tonic-gate (void) printf(
24458485SPeter.Memishian@Sun.COM " %10u datagram%s potentially forwarded - register packets\n",
24468485SPeter.Memishian@Sun.COM mrts->mrts_pim_regforwards, PLURAL(mrts->mrts_pim_regforwards));
24470Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - register send drops\n",
24488485SPeter.Memishian@Sun.COM mrts->mrts_pim_regsend_drops, PLURAL(mrts->mrts_pim_regsend_drops));
24490Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - packet malformed\n",
24508485SPeter.Memishian@Sun.COM mrts->mrts_pim_malformed, PLURAL(mrts->mrts_pim_malformed));
24510Sstevel@tonic-gate (void) printf(" %10u datagram%s dropped - no memory to forward\n",
24528485SPeter.Memishian@Sun.COM mrts->mrts_pim_nomemory, PLURAL(mrts->mrts_pim_nomemory));
24530Sstevel@tonic-gate }
24540Sstevel@tonic-gate
24550Sstevel@tonic-gate static void
sum_ip6_stats(mib2_ipv6IfStatsEntry_t * ip6,mib2_ipv6IfStatsEntry_t * sum6)24560Sstevel@tonic-gate sum_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6, mib2_ipv6IfStatsEntry_t *sum6)
24570Sstevel@tonic-gate {
24580Sstevel@tonic-gate /* First few are not additive */
24590Sstevel@tonic-gate sum6->ipv6Forwarding = ip6->ipv6Forwarding;
24600Sstevel@tonic-gate sum6->ipv6DefaultHopLimit = ip6->ipv6DefaultHopLimit;
24610Sstevel@tonic-gate
24620Sstevel@tonic-gate sum6->ipv6InReceives += ip6->ipv6InReceives;
24630Sstevel@tonic-gate sum6->ipv6InHdrErrors += ip6->ipv6InHdrErrors;
24640Sstevel@tonic-gate sum6->ipv6InTooBigErrors += ip6->ipv6InTooBigErrors;
24650Sstevel@tonic-gate sum6->ipv6InNoRoutes += ip6->ipv6InNoRoutes;
24660Sstevel@tonic-gate sum6->ipv6InAddrErrors += ip6->ipv6InAddrErrors;
24670Sstevel@tonic-gate sum6->ipv6InUnknownProtos += ip6->ipv6InUnknownProtos;
24680Sstevel@tonic-gate sum6->ipv6InTruncatedPkts += ip6->ipv6InTruncatedPkts;
24690Sstevel@tonic-gate sum6->ipv6InDiscards += ip6->ipv6InDiscards;
24700Sstevel@tonic-gate sum6->ipv6InDelivers += ip6->ipv6InDelivers;
24710Sstevel@tonic-gate sum6->ipv6OutForwDatagrams += ip6->ipv6OutForwDatagrams;
24720Sstevel@tonic-gate sum6->ipv6OutRequests += ip6->ipv6OutRequests;
24730Sstevel@tonic-gate sum6->ipv6OutDiscards += ip6->ipv6OutDiscards;
24740Sstevel@tonic-gate sum6->ipv6OutFragOKs += ip6->ipv6OutFragOKs;
24750Sstevel@tonic-gate sum6->ipv6OutFragFails += ip6->ipv6OutFragFails;
24760Sstevel@tonic-gate sum6->ipv6OutFragCreates += ip6->ipv6OutFragCreates;
24770Sstevel@tonic-gate sum6->ipv6ReasmReqds += ip6->ipv6ReasmReqds;
24780Sstevel@tonic-gate sum6->ipv6ReasmOKs += ip6->ipv6ReasmOKs;
24790Sstevel@tonic-gate sum6->ipv6ReasmFails += ip6->ipv6ReasmFails;
24800Sstevel@tonic-gate sum6->ipv6InMcastPkts += ip6->ipv6InMcastPkts;
24810Sstevel@tonic-gate sum6->ipv6OutMcastPkts += ip6->ipv6OutMcastPkts;
24820Sstevel@tonic-gate sum6->ipv6OutNoRoutes += ip6->ipv6OutNoRoutes;
24830Sstevel@tonic-gate sum6->ipv6ReasmDuplicates += ip6->ipv6ReasmDuplicates;
24840Sstevel@tonic-gate sum6->ipv6ReasmPartDups += ip6->ipv6ReasmPartDups;
24850Sstevel@tonic-gate sum6->ipv6ForwProhibits += ip6->ipv6ForwProhibits;
24860Sstevel@tonic-gate sum6->udpInCksumErrs += ip6->udpInCksumErrs;
24870Sstevel@tonic-gate sum6->udpInOverflows += ip6->udpInOverflows;
24880Sstevel@tonic-gate sum6->rawipInOverflows += ip6->rawipInOverflows;
24890Sstevel@tonic-gate }
24900Sstevel@tonic-gate
24910Sstevel@tonic-gate static void
sum_icmp6_stats(mib2_ipv6IfIcmpEntry_t * icmp6,mib2_ipv6IfIcmpEntry_t * sum6)24920Sstevel@tonic-gate sum_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6, mib2_ipv6IfIcmpEntry_t *sum6)
24930Sstevel@tonic-gate {
24940Sstevel@tonic-gate sum6->ipv6IfIcmpInMsgs += icmp6->ipv6IfIcmpInMsgs;
24950Sstevel@tonic-gate sum6->ipv6IfIcmpInErrors += icmp6->ipv6IfIcmpInErrors;
24960Sstevel@tonic-gate sum6->ipv6IfIcmpInDestUnreachs += icmp6->ipv6IfIcmpInDestUnreachs;
24970Sstevel@tonic-gate sum6->ipv6IfIcmpInAdminProhibs += icmp6->ipv6IfIcmpInAdminProhibs;
24980Sstevel@tonic-gate sum6->ipv6IfIcmpInTimeExcds += icmp6->ipv6IfIcmpInTimeExcds;
24990Sstevel@tonic-gate sum6->ipv6IfIcmpInParmProblems += icmp6->ipv6IfIcmpInParmProblems;
25000Sstevel@tonic-gate sum6->ipv6IfIcmpInPktTooBigs += icmp6->ipv6IfIcmpInPktTooBigs;
25010Sstevel@tonic-gate sum6->ipv6IfIcmpInEchos += icmp6->ipv6IfIcmpInEchos;
25020Sstevel@tonic-gate sum6->ipv6IfIcmpInEchoReplies += icmp6->ipv6IfIcmpInEchoReplies;
25030Sstevel@tonic-gate sum6->ipv6IfIcmpInRouterSolicits += icmp6->ipv6IfIcmpInRouterSolicits;
25040Sstevel@tonic-gate sum6->ipv6IfIcmpInRouterAdvertisements +=
25050Sstevel@tonic-gate icmp6->ipv6IfIcmpInRouterAdvertisements;
25060Sstevel@tonic-gate sum6->ipv6IfIcmpInNeighborSolicits +=
25070Sstevel@tonic-gate icmp6->ipv6IfIcmpInNeighborSolicits;
25080Sstevel@tonic-gate sum6->ipv6IfIcmpInNeighborAdvertisements +=
25090Sstevel@tonic-gate icmp6->ipv6IfIcmpInNeighborAdvertisements;
25100Sstevel@tonic-gate sum6->ipv6IfIcmpInRedirects += icmp6->ipv6IfIcmpInRedirects;
25110Sstevel@tonic-gate sum6->ipv6IfIcmpInGroupMembQueries +=
25120Sstevel@tonic-gate icmp6->ipv6IfIcmpInGroupMembQueries;
25130Sstevel@tonic-gate sum6->ipv6IfIcmpInGroupMembResponses +=
25140Sstevel@tonic-gate icmp6->ipv6IfIcmpInGroupMembResponses;
25150Sstevel@tonic-gate sum6->ipv6IfIcmpInGroupMembReductions +=
25160Sstevel@tonic-gate icmp6->ipv6IfIcmpInGroupMembReductions;
25170Sstevel@tonic-gate sum6->ipv6IfIcmpOutMsgs += icmp6->ipv6IfIcmpOutMsgs;
25180Sstevel@tonic-gate sum6->ipv6IfIcmpOutErrors += icmp6->ipv6IfIcmpOutErrors;
25190Sstevel@tonic-gate sum6->ipv6IfIcmpOutDestUnreachs += icmp6->ipv6IfIcmpOutDestUnreachs;
25200Sstevel@tonic-gate sum6->ipv6IfIcmpOutAdminProhibs += icmp6->ipv6IfIcmpOutAdminProhibs;
25210Sstevel@tonic-gate sum6->ipv6IfIcmpOutTimeExcds += icmp6->ipv6IfIcmpOutTimeExcds;
25220Sstevel@tonic-gate sum6->ipv6IfIcmpOutParmProblems += icmp6->ipv6IfIcmpOutParmProblems;
25230Sstevel@tonic-gate sum6->ipv6IfIcmpOutPktTooBigs += icmp6->ipv6IfIcmpOutPktTooBigs;
25240Sstevel@tonic-gate sum6->ipv6IfIcmpOutEchos += icmp6->ipv6IfIcmpOutEchos;
25250Sstevel@tonic-gate sum6->ipv6IfIcmpOutEchoReplies += icmp6->ipv6IfIcmpOutEchoReplies;
25260Sstevel@tonic-gate sum6->ipv6IfIcmpOutRouterSolicits +=
25270Sstevel@tonic-gate icmp6->ipv6IfIcmpOutRouterSolicits;
25280Sstevel@tonic-gate sum6->ipv6IfIcmpOutRouterAdvertisements +=
25290Sstevel@tonic-gate icmp6->ipv6IfIcmpOutRouterAdvertisements;
25300Sstevel@tonic-gate sum6->ipv6IfIcmpOutNeighborSolicits +=
25310Sstevel@tonic-gate icmp6->ipv6IfIcmpOutNeighborSolicits;
25320Sstevel@tonic-gate sum6->ipv6IfIcmpOutNeighborAdvertisements +=
25330Sstevel@tonic-gate icmp6->ipv6IfIcmpOutNeighborAdvertisements;
25340Sstevel@tonic-gate sum6->ipv6IfIcmpOutRedirects += icmp6->ipv6IfIcmpOutRedirects;
25350Sstevel@tonic-gate sum6->ipv6IfIcmpOutGroupMembQueries +=
25360Sstevel@tonic-gate icmp6->ipv6IfIcmpOutGroupMembQueries;
25370Sstevel@tonic-gate sum6->ipv6IfIcmpOutGroupMembResponses +=
25380Sstevel@tonic-gate icmp6->ipv6IfIcmpOutGroupMembResponses;
25390Sstevel@tonic-gate sum6->ipv6IfIcmpOutGroupMembReductions +=
25400Sstevel@tonic-gate icmp6->ipv6IfIcmpOutGroupMembReductions;
25410Sstevel@tonic-gate sum6->ipv6IfIcmpInOverflows += icmp6->ipv6IfIcmpInOverflows;
25420Sstevel@tonic-gate }
25430Sstevel@tonic-gate
25440Sstevel@tonic-gate /* ----------------------------- MRT_STAT_REPORT --------------------------- */
25450Sstevel@tonic-gate
25460Sstevel@tonic-gate static void
mrt_stat_report(mib_item_t * curritem)25470Sstevel@tonic-gate mrt_stat_report(mib_item_t *curritem)
25480Sstevel@tonic-gate {
25490Sstevel@tonic-gate int jtemp = 0;
25500Sstevel@tonic-gate mib_item_t *tempitem;
25510Sstevel@tonic-gate
25520Sstevel@tonic-gate if (!(family_selected(AF_INET)))
25530Sstevel@tonic-gate return;
25540Sstevel@tonic-gate
25550Sstevel@tonic-gate (void) putchar('\n');
25560Sstevel@tonic-gate /* 'for' loop 1: */
25570Sstevel@tonic-gate for (tempitem = curritem;
25580Sstevel@tonic-gate tempitem;
25590Sstevel@tonic-gate tempitem = tempitem->next_item) {
256011042SErik.Nordmark@Sun.COM if (Xflag) {
25610Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp);
25620Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, "
25630Sstevel@tonic-gate "length = %d, valp = 0x%p\n",
25640Sstevel@tonic-gate tempitem->group, tempitem->mib_id,
25650Sstevel@tonic-gate tempitem->length, tempitem->valp);
25660Sstevel@tonic-gate }
25670Sstevel@tonic-gate
25680Sstevel@tonic-gate if (tempitem->mib_id == 0) {
25690Sstevel@tonic-gate switch (tempitem->group) {
25700Sstevel@tonic-gate case EXPER_DVMRP: {
25710Sstevel@tonic-gate struct mrtstat *mrts;
25720Sstevel@tonic-gate mrts = (struct mrtstat *)tempitem->valp;
25730Sstevel@tonic-gate
25740Sstevel@tonic-gate if (!(family_selected(AF_INET)))
25750Sstevel@tonic-gate continue; /* 'for' loop 1 */
25760Sstevel@tonic-gate
25770Sstevel@tonic-gate print_mrt_stats(mrts);
25780Sstevel@tonic-gate break;
25790Sstevel@tonic-gate }
25800Sstevel@tonic-gate }
25810Sstevel@tonic-gate }
25820Sstevel@tonic-gate } /* 'for' loop 1 ends */
25830Sstevel@tonic-gate (void) putchar('\n');
25840Sstevel@tonic-gate (void) fflush(stdout);
25850Sstevel@tonic-gate }
25860Sstevel@tonic-gate
25870Sstevel@tonic-gate /*
25880Sstevel@tonic-gate * if_stat_total() - Computes totals for interface statistics
25890Sstevel@tonic-gate * and returns result by updating sumstats.
25900Sstevel@tonic-gate */
25910Sstevel@tonic-gate static void
if_stat_total(struct ifstat * oldstats,struct ifstat * newstats,struct ifstat * sumstats)25920Sstevel@tonic-gate if_stat_total(struct ifstat *oldstats, struct ifstat *newstats,
25930Sstevel@tonic-gate struct ifstat *sumstats)
25940Sstevel@tonic-gate {
25950Sstevel@tonic-gate sumstats->ipackets += newstats->ipackets - oldstats->ipackets;
25960Sstevel@tonic-gate sumstats->opackets += newstats->opackets - oldstats->opackets;
25970Sstevel@tonic-gate sumstats->ierrors += newstats->ierrors - oldstats->ierrors;
25980Sstevel@tonic-gate sumstats->oerrors += newstats->oerrors - oldstats->oerrors;
25990Sstevel@tonic-gate sumstats->collisions += newstats->collisions - oldstats->collisions;
26000Sstevel@tonic-gate }
26010Sstevel@tonic-gate
26020Sstevel@tonic-gate /* --------------------- IF_REPORT (netstat -i) -------------------------- */
26030Sstevel@tonic-gate
26040Sstevel@tonic-gate static struct ifstat zerostat = {
26050Sstevel@tonic-gate 0LL, 0LL, 0LL, 0LL, 0LL
26060Sstevel@tonic-gate };
26070Sstevel@tonic-gate
26080Sstevel@tonic-gate static void
if_report(mib_item_t * item,char * matchname,int Iflag_only,boolean_t once_only)26090Sstevel@tonic-gate if_report(mib_item_t *item, char *matchname,
26100Sstevel@tonic-gate int Iflag_only, boolean_t once_only)
26110Sstevel@tonic-gate {
26120Sstevel@tonic-gate static boolean_t reentry = B_FALSE;
26130Sstevel@tonic-gate boolean_t alreadydone = B_FALSE;
26140Sstevel@tonic-gate int jtemp = 0;
26150Sstevel@tonic-gate uint32_t ifindex_v4 = 0;
26160Sstevel@tonic-gate uint32_t ifindex_v6 = 0;
26175739Skeerthi boolean_t first_header = B_TRUE;
26180Sstevel@tonic-gate
26190Sstevel@tonic-gate /* 'for' loop 1: */
26200Sstevel@tonic-gate for (; item; item = item->next_item) {
262111042SErik.Nordmark@Sun.COM if (Xflag) {
26220Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp);
26230Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, "
26240Sstevel@tonic-gate "length = %d, valp = 0x%p\n",
26250Sstevel@tonic-gate item->group, item->mib_id, item->length,
26260Sstevel@tonic-gate item->valp);
26270Sstevel@tonic-gate }
26280Sstevel@tonic-gate
26290Sstevel@tonic-gate switch (item->group) {
26300Sstevel@tonic-gate case MIB2_IP:
26310Sstevel@tonic-gate if (item->mib_id != MIB2_IP_ADDR ||
26320Sstevel@tonic-gate !family_selected(AF_INET))
26330Sstevel@tonic-gate continue; /* 'for' loop 1 */
26340Sstevel@tonic-gate {
26350Sstevel@tonic-gate static struct ifstat old = {0L, 0L, 0L, 0L, 0L};
26360Sstevel@tonic-gate static struct ifstat new = {0L, 0L, 0L, 0L, 0L};
26370Sstevel@tonic-gate struct ifstat sum;
26380Sstevel@tonic-gate struct iflist *newlist = NULL;
26390Sstevel@tonic-gate static struct iflist *oldlist = NULL;
26400Sstevel@tonic-gate kstat_t *ksp;
26410Sstevel@tonic-gate
26420Sstevel@tonic-gate if (once_only) {
26430Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1];
26440Sstevel@tonic-gate char logintname[LIFNAMSIZ + 1];
26450Sstevel@tonic-gate mib2_ipAddrEntry_t *ap;
26460Sstevel@tonic-gate struct ifstat stat = {0L, 0L, 0L, 0L, 0L};
26470Sstevel@tonic-gate boolean_t first = B_TRUE;
26480Sstevel@tonic-gate uint32_t new_ifindex;
26490Sstevel@tonic-gate
265011042SErik.Nordmark@Sun.COM if (Xflag)
26510Sstevel@tonic-gate (void) printf("if_report: %d items\n",
26520Sstevel@tonic-gate (item->length)
26530Sstevel@tonic-gate / sizeof (mib2_ipAddrEntry_t));
26540Sstevel@tonic-gate
26550Sstevel@tonic-gate /* 'for' loop 2a: */
26560Sstevel@tonic-gate for (ap = (mib2_ipAddrEntry_t *)item->valp;
26570Sstevel@tonic-gate (char *)ap < (char *)item->valp
26580Sstevel@tonic-gate + item->length;
26590Sstevel@tonic-gate ap++) {
26600Sstevel@tonic-gate (void) octetstr(&ap->ipAdEntIfIndex,
26610Sstevel@tonic-gate 'a', logintname,
26620Sstevel@tonic-gate sizeof (logintname));
26630Sstevel@tonic-gate (void) strcpy(ifname, logintname);
26640Sstevel@tonic-gate (void) strtok(ifname, ":");
26650Sstevel@tonic-gate if (matchname != NULL &&
26660Sstevel@tonic-gate strcmp(matchname, ifname) != 0 &&
26670Sstevel@tonic-gate strcmp(matchname, logintname) != 0)
26680Sstevel@tonic-gate continue; /* 'for' loop 2a */
26690Sstevel@tonic-gate new_ifindex =
26700Sstevel@tonic-gate if_nametoindex(logintname);
26715895Syz147064 /*
26725895Syz147064 * First lookup the "link" kstats in
26735895Syz147064 * case the link is renamed. Then
26745895Syz147064 * fallback to the legacy kstats for
26755895Syz147064 * those non-GLDv3 links.
26765895Syz147064 */
26770Sstevel@tonic-gate if (new_ifindex != ifindex_v4 &&
26785895Syz147064 (((ksp = kstat_lookup(kc, "link", 0,
26795895Syz147064 ifname)) != NULL) ||
26805895Syz147064 ((ksp = kstat_lookup(kc, NULL, -1,
26815895Syz147064 ifname)) != NULL))) {
26820Sstevel@tonic-gate (void) safe_kstat_read(kc, ksp,
26830Sstevel@tonic-gate NULL);
26840Sstevel@tonic-gate stat.ipackets =
26850Sstevel@tonic-gate kstat_named_value(ksp,
26860Sstevel@tonic-gate "ipackets");
26870Sstevel@tonic-gate stat.ierrors =
26880Sstevel@tonic-gate kstat_named_value(ksp,
26890Sstevel@tonic-gate "ierrors");
26900Sstevel@tonic-gate stat.opackets =
26910Sstevel@tonic-gate kstat_named_value(ksp,
26920Sstevel@tonic-gate "opackets");
26930Sstevel@tonic-gate stat.oerrors =
26940Sstevel@tonic-gate kstat_named_value(ksp,
26950Sstevel@tonic-gate "oerrors");
26960Sstevel@tonic-gate stat.collisions =
26970Sstevel@tonic-gate kstat_named_value(ksp,
26980Sstevel@tonic-gate "collisions");
26990Sstevel@tonic-gate if (first) {
27005739Skeerthi if (!first_header)
27015739Skeerthi (void) putchar('\n');
27025739Skeerthi first_header = B_FALSE;
27030Sstevel@tonic-gate (void) printf(
27040Sstevel@tonic-gate "%-5.5s %-5.5s%-13.13s "
27050Sstevel@tonic-gate "%-14.14s %-6.6s %-5.5s "
27060Sstevel@tonic-gate "%-6.6s %-5.5s %-6.6s "
27070Sstevel@tonic-gate "%-6.6s\n",
27080Sstevel@tonic-gate "Name", "Mtu", "Net/Dest",
27090Sstevel@tonic-gate "Address", "Ipkts",
27100Sstevel@tonic-gate "Ierrs", "Opkts", "Oerrs",
27110Sstevel@tonic-gate "Collis", "Queue");
27125739Skeerthi
27138485SPeter.Memishian@Sun.COM first = B_FALSE;
27140Sstevel@tonic-gate }
27150Sstevel@tonic-gate if_report_ip4(ap, ifname,
27160Sstevel@tonic-gate logintname, &stat, B_TRUE);
27170Sstevel@tonic-gate ifindex_v4 = new_ifindex;
27180Sstevel@tonic-gate } else {
27190Sstevel@tonic-gate if_report_ip4(ap, ifname,
27200Sstevel@tonic-gate logintname, &stat, B_FALSE);
27210Sstevel@tonic-gate }
27220Sstevel@tonic-gate } /* 'for' loop 2a ends */
27230Sstevel@tonic-gate } else if (!alreadydone) {
27240Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1];
27250Sstevel@tonic-gate char buf[LIFNAMSIZ + 1];
27260Sstevel@tonic-gate mib2_ipAddrEntry_t *ap;
27270Sstevel@tonic-gate struct ifstat t;
27283129Sja97890 struct iflist *tlp = NULL;
27290Sstevel@tonic-gate struct iflist **nextnew = &newlist;
27300Sstevel@tonic-gate struct iflist *walkold;
27310Sstevel@tonic-gate struct iflist *cleanlist;
27323129Sja97890 boolean_t found_if = B_FALSE;
27330Sstevel@tonic-gate
27340Sstevel@tonic-gate alreadydone = B_TRUE; /* ignore other case */
27353129Sja97890
27360Sstevel@tonic-gate /*
27373129Sja97890 * Check if there is anything to do.
27383129Sja97890 */
27393129Sja97890 if (item->length <
27403129Sja97890 sizeof (mib2_ipAddrEntry_t)) {
27413129Sja97890 fail(0, "No compatible interfaces");
27423129Sja97890 }
27433129Sja97890
27443129Sja97890 /*
27453129Sja97890 * 'for' loop 2b: find the "right" entry:
27463129Sja97890 * If an interface name to match has been
27473129Sja97890 * supplied then try and find it, otherwise
27483129Sja97890 * match the first non-loopback interface found.
27493129Sja97890 * Use lo0 if all else fails.
27500Sstevel@tonic-gate */
27510Sstevel@tonic-gate for (ap = (mib2_ipAddrEntry_t *)item->valp;
27520Sstevel@tonic-gate (char *)ap < (char *)item->valp
27530Sstevel@tonic-gate + item->length;
27540Sstevel@tonic-gate ap++) {
27550Sstevel@tonic-gate (void) octetstr(&ap->ipAdEntIfIndex,
27568485SPeter.Memishian@Sun.COM 'a', ifname, sizeof (ifname));
27570Sstevel@tonic-gate (void) strtok(ifname, ":");
27580Sstevel@tonic-gate
27590Sstevel@tonic-gate if (matchname) {
27600Sstevel@tonic-gate if (strcmp(matchname,
27613129Sja97890 ifname) == 0) {
27620Sstevel@tonic-gate /* 'for' loop 2b */
27633129Sja97890 found_if = B_TRUE;
27640Sstevel@tonic-gate break;
27653129Sja97890 }
27663129Sja97890 } else if (strcmp(ifname, "lo0") != 0)
27670Sstevel@tonic-gate break; /* 'for' loop 2b */
27680Sstevel@tonic-gate } /* 'for' loop 2b ends */
27690Sstevel@tonic-gate
27703129Sja97890 if (matchname == NULL) {
27713129Sja97890 matchname = ifname;
27723129Sja97890 } else {
27733129Sja97890 if (!found_if)
27743129Sja97890 fail(0, "-I: %s no such "
27753129Sja97890 "interface.", matchname);
27763129Sja97890 }
27773129Sja97890
27780Sstevel@tonic-gate if (Iflag_only == 0 || !reentry) {
27790Sstevel@tonic-gate (void) printf(" input %-6.6s "
27800Sstevel@tonic-gate "output ",
27810Sstevel@tonic-gate matchname);
27820Sstevel@tonic-gate (void) printf(" input (Total) "
27830Sstevel@tonic-gate "output\n");
27840Sstevel@tonic-gate (void) printf("%-7.7s %-5.5s %-7.7s "
27850Sstevel@tonic-gate "%-5.5s %-6.6s ",
27860Sstevel@tonic-gate "packets", "errs", "packets",
27870Sstevel@tonic-gate "errs", "colls");
27880Sstevel@tonic-gate (void) printf("%-7.7s %-5.5s %-7.7s "
27890Sstevel@tonic-gate "%-5.5s %-6.6s\n",
27900Sstevel@tonic-gate "packets", "errs", "packets",
27910Sstevel@tonic-gate "errs", "colls");
27920Sstevel@tonic-gate }
27930Sstevel@tonic-gate
27940Sstevel@tonic-gate sum = zerostat;
27950Sstevel@tonic-gate
27960Sstevel@tonic-gate /* 'for' loop 2c: */
27970Sstevel@tonic-gate for (ap = (mib2_ipAddrEntry_t *)item->valp;
27980Sstevel@tonic-gate (char *)ap < (char *)item->valp
27990Sstevel@tonic-gate + item->length;
28000Sstevel@tonic-gate ap++) {
28010Sstevel@tonic-gate (void) octetstr(&ap->ipAdEntIfIndex,
28020Sstevel@tonic-gate 'a', buf, sizeof (buf));
28030Sstevel@tonic-gate (void) strtok(buf, ":");
28043129Sja97890
28053129Sja97890 /*
28063129Sja97890 * We have reduced the IP interface
28073129Sja97890 * name, which could have been a
28083129Sja97890 * logical, down to a name suitable
28093129Sja97890 * for use with kstats.
28103129Sja97890 * We treat this name as unique and
28113129Sja97890 * only collate statistics for it once
28123129Sja97890 * per pass. This is to avoid falsely
28133129Sja97890 * amplifying these statistics by the
28143129Sja97890 * the number of logical instances.
28153129Sja97890 */
28163129Sja97890 if ((tlp != NULL) &&
28173129Sja97890 ((strcmp(buf, tlp->ifname) == 0))) {
28183129Sja97890 continue;
28193129Sja97890 }
28203129Sja97890
28215895Syz147064 /*
28225895Syz147064 * First lookup the "link" kstats in
28235895Syz147064 * case the link is renamed. Then
28245895Syz147064 * fallback to the legacy kstats for
28255895Syz147064 * those non-GLDv3 links.
28265895Syz147064 */
28275895Syz147064 if (((ksp = kstat_lookup(kc, "link",
28285895Syz147064 0, buf)) != NULL ||
28295895Syz147064 (ksp = kstat_lookup(kc, NULL, -1,
28305895Syz147064 buf)) != NULL) && (ksp->ks_type ==
28315895Syz147064 KSTAT_TYPE_NAMED)) {
28320Sstevel@tonic-gate (void) safe_kstat_read(kc, ksp,
28330Sstevel@tonic-gate NULL);
28345895Syz147064 }
28350Sstevel@tonic-gate
28360Sstevel@tonic-gate t.ipackets = kstat_named_value(ksp,
28370Sstevel@tonic-gate "ipackets");
28380Sstevel@tonic-gate t.ierrors = kstat_named_value(ksp,
28390Sstevel@tonic-gate "ierrors");
28400Sstevel@tonic-gate t.opackets = kstat_named_value(ksp,
28410Sstevel@tonic-gate "opackets");
28420Sstevel@tonic-gate t.oerrors = kstat_named_value(ksp,
28430Sstevel@tonic-gate "oerrors");
28440Sstevel@tonic-gate t.collisions = kstat_named_value(ksp,
28450Sstevel@tonic-gate "collisions");
28460Sstevel@tonic-gate
28470Sstevel@tonic-gate if (strcmp(buf, matchname) == 0)
28480Sstevel@tonic-gate new = t;
28490Sstevel@tonic-gate
28500Sstevel@tonic-gate /* Build the interface list */
28510Sstevel@tonic-gate
28520Sstevel@tonic-gate tlp = malloc(sizeof (struct iflist));
28530Sstevel@tonic-gate (void) strlcpy(tlp->ifname, buf,
28540Sstevel@tonic-gate sizeof (tlp->ifname));
28550Sstevel@tonic-gate tlp->tot = t;
28560Sstevel@tonic-gate *nextnew = tlp;
28570Sstevel@tonic-gate nextnew = &tlp->next_if;
28580Sstevel@tonic-gate
28590Sstevel@tonic-gate /*
28600Sstevel@tonic-gate * First time through.
28610Sstevel@tonic-gate * Just add up the interface stats.
28620Sstevel@tonic-gate */
28630Sstevel@tonic-gate
28640Sstevel@tonic-gate if (oldlist == NULL) {
28650Sstevel@tonic-gate if_stat_total(&zerostat,
28660Sstevel@tonic-gate &t, &sum);
28670Sstevel@tonic-gate continue;
28680Sstevel@tonic-gate }
28690Sstevel@tonic-gate
28700Sstevel@tonic-gate /*
28710Sstevel@tonic-gate * Walk old list for the interface.
28720Sstevel@tonic-gate *
28730Sstevel@tonic-gate * If found, add difference to total.
28740Sstevel@tonic-gate *
28750Sstevel@tonic-gate * If not, an interface has been plumbed
28760Sstevel@tonic-gate * up. In this case, we will simply
28770Sstevel@tonic-gate * ignore the new interface until the
28780Sstevel@tonic-gate * next interval; as there's no easy way
28790Sstevel@tonic-gate * to acquire statistics between time
28800Sstevel@tonic-gate * of the plumb and the next interval
28810Sstevel@tonic-gate * boundary. This results in inaccurate
28820Sstevel@tonic-gate * total values for current interval.
28830Sstevel@tonic-gate *
28840Sstevel@tonic-gate * Note the case when an interface is
28850Sstevel@tonic-gate * unplumbed; as similar problems exist.
28860Sstevel@tonic-gate * The unplumbed interface is not in the
28870Sstevel@tonic-gate * current list, and there's no easy way
28880Sstevel@tonic-gate * to account for the statistics between
28890Sstevel@tonic-gate * the previous interval and time of the
28900Sstevel@tonic-gate * unplumb. Therefore, we (in a sense)
28910Sstevel@tonic-gate * ignore the removed interface by only
28920Sstevel@tonic-gate * involving "current" interfaces when
28930Sstevel@tonic-gate * computing the total statistics.
28940Sstevel@tonic-gate * Unfortunately, this also results in
28950Sstevel@tonic-gate * inaccurate values for interval total.
28960Sstevel@tonic-gate */
28970Sstevel@tonic-gate
28980Sstevel@tonic-gate for (walkold = oldlist;
28990Sstevel@tonic-gate walkold != NULL;
29000Sstevel@tonic-gate walkold = walkold->next_if) {
29010Sstevel@tonic-gate if (strcmp(walkold->ifname,
29020Sstevel@tonic-gate buf) == 0) {
29030Sstevel@tonic-gate if_stat_total(
29040Sstevel@tonic-gate &walkold->tot,
29050Sstevel@tonic-gate &t, &sum);
29060Sstevel@tonic-gate break;
29070Sstevel@tonic-gate }
29080Sstevel@tonic-gate }
29090Sstevel@tonic-gate
29100Sstevel@tonic-gate } /* 'for' loop 2c ends */
29110Sstevel@tonic-gate
29120Sstevel@tonic-gate *nextnew = NULL;
29130Sstevel@tonic-gate
29140Sstevel@tonic-gate (void) printf("%-7llu %-5llu %-7llu "
29150Sstevel@tonic-gate "%-5llu %-6llu ",
29160Sstevel@tonic-gate new.ipackets - old.ipackets,
29170Sstevel@tonic-gate new.ierrors - old.ierrors,
29180Sstevel@tonic-gate new.opackets - old.opackets,
29190Sstevel@tonic-gate new.oerrors - old.oerrors,
29200Sstevel@tonic-gate new.collisions - old.collisions);
29210Sstevel@tonic-gate
29220Sstevel@tonic-gate (void) printf("%-7llu %-5llu %-7llu "
29230Sstevel@tonic-gate "%-5llu %-6llu\n", sum.ipackets,
29240Sstevel@tonic-gate sum.ierrors, sum.opackets,
29250Sstevel@tonic-gate sum.oerrors, sum.collisions);
29260Sstevel@tonic-gate
29270Sstevel@tonic-gate /*
29280Sstevel@tonic-gate * Tidy things up once finished.
29290Sstevel@tonic-gate */
29300Sstevel@tonic-gate
29310Sstevel@tonic-gate old = new;
29320Sstevel@tonic-gate cleanlist = oldlist;
29330Sstevel@tonic-gate oldlist = newlist;
29340Sstevel@tonic-gate while (cleanlist != NULL) {
29350Sstevel@tonic-gate tlp = cleanlist->next_if;
29360Sstevel@tonic-gate free(cleanlist);
29370Sstevel@tonic-gate cleanlist = tlp;
29380Sstevel@tonic-gate }
29390Sstevel@tonic-gate }
29400Sstevel@tonic-gate break;
29410Sstevel@tonic-gate }
29420Sstevel@tonic-gate case MIB2_IP6:
29430Sstevel@tonic-gate if (item->mib_id != MIB2_IP6_ADDR ||
29440Sstevel@tonic-gate !family_selected(AF_INET6))
29450Sstevel@tonic-gate continue; /* 'for' loop 1 */
29460Sstevel@tonic-gate {
29470Sstevel@tonic-gate static struct ifstat old6 = {0L, 0L, 0L, 0L, 0L};
29480Sstevel@tonic-gate static struct ifstat new6 = {0L, 0L, 0L, 0L, 0L};
29490Sstevel@tonic-gate struct ifstat sum6;
29500Sstevel@tonic-gate struct iflist *newlist6 = NULL;
29510Sstevel@tonic-gate static struct iflist *oldlist6 = NULL;
29520Sstevel@tonic-gate kstat_t *ksp;
29530Sstevel@tonic-gate
29540Sstevel@tonic-gate if (once_only) {
29550Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1];
29560Sstevel@tonic-gate char logintname[LIFNAMSIZ + 1];
29570Sstevel@tonic-gate mib2_ipv6AddrEntry_t *ap6;
29580Sstevel@tonic-gate struct ifstat stat = {0L, 0L, 0L, 0L, 0L};
29590Sstevel@tonic-gate boolean_t first = B_TRUE;
29600Sstevel@tonic-gate uint32_t new_ifindex;
29610Sstevel@tonic-gate
296211042SErik.Nordmark@Sun.COM if (Xflag)
29630Sstevel@tonic-gate (void) printf("if_report: %d items\n",
29640Sstevel@tonic-gate (item->length)
29650Sstevel@tonic-gate / sizeof (mib2_ipv6AddrEntry_t));
29660Sstevel@tonic-gate /* 'for' loop 2d: */
29670Sstevel@tonic-gate for (ap6 = (mib2_ipv6AddrEntry_t *)item->valp;
29680Sstevel@tonic-gate (char *)ap6 < (char *)item->valp
29690Sstevel@tonic-gate + item->length;
29700Sstevel@tonic-gate ap6++) {
29710Sstevel@tonic-gate (void) octetstr(&ap6->ipv6AddrIfIndex,
29720Sstevel@tonic-gate 'a', logintname,
29730Sstevel@tonic-gate sizeof (logintname));
29740Sstevel@tonic-gate (void) strcpy(ifname, logintname);
29750Sstevel@tonic-gate (void) strtok(ifname, ":");
29760Sstevel@tonic-gate if (matchname != NULL &&
29770Sstevel@tonic-gate strcmp(matchname, ifname) != 0 &&
29780Sstevel@tonic-gate strcmp(matchname, logintname) != 0)
29790Sstevel@tonic-gate continue; /* 'for' loop 2d */
29800Sstevel@tonic-gate new_ifindex =
29810Sstevel@tonic-gate if_nametoindex(logintname);
29825895Syz147064
29835895Syz147064 /*
29845895Syz147064 * First lookup the "link" kstats in
29855895Syz147064 * case the link is renamed. Then
29865895Syz147064 * fallback to the legacy kstats for
29875895Syz147064 * those non-GLDv3 links.
29885895Syz147064 */
29890Sstevel@tonic-gate if (new_ifindex != ifindex_v6 &&
29905895Syz147064 ((ksp = kstat_lookup(kc, "link", 0,
29915895Syz147064 ifname)) != NULL ||
29920Sstevel@tonic-gate (ksp = kstat_lookup(kc, NULL, -1,
29935895Syz147064 ifname)) != NULL)) {
29940Sstevel@tonic-gate (void) safe_kstat_read(kc, ksp,
29950Sstevel@tonic-gate NULL);
29960Sstevel@tonic-gate stat.ipackets =
29970Sstevel@tonic-gate kstat_named_value(ksp,
29980Sstevel@tonic-gate "ipackets");
29990Sstevel@tonic-gate stat.ierrors =
30000Sstevel@tonic-gate kstat_named_value(ksp,
30010Sstevel@tonic-gate "ierrors");
30020Sstevel@tonic-gate stat.opackets =
30030Sstevel@tonic-gate kstat_named_value(ksp,
30040Sstevel@tonic-gate "opackets");
30050Sstevel@tonic-gate stat.oerrors =
30060Sstevel@tonic-gate kstat_named_value(ksp,
30070Sstevel@tonic-gate "oerrors");
30080Sstevel@tonic-gate stat.collisions =
30090Sstevel@tonic-gate kstat_named_value(ksp,
30100Sstevel@tonic-gate "collisions");
30110Sstevel@tonic-gate if (first) {
30125739Skeerthi if (!first_header)
30135739Skeerthi (void) putchar('\n');
30145739Skeerthi first_header = B_FALSE;
30150Sstevel@tonic-gate (void) printf(
30160Sstevel@tonic-gate "%-5.5s %-5.5s%"
30170Sstevel@tonic-gate "-27.27s %-27.27s "
30180Sstevel@tonic-gate "%-6.6s %-5.5s "
30190Sstevel@tonic-gate "%-6.6s %-5.5s "
30200Sstevel@tonic-gate "%-6.6s\n",
30210Sstevel@tonic-gate "Name", "Mtu",
30220Sstevel@tonic-gate "Net/Dest",
30230Sstevel@tonic-gate "Address", "Ipkts",
30240Sstevel@tonic-gate "Ierrs", "Opkts",
30250Sstevel@tonic-gate "Oerrs", "Collis");
30260Sstevel@tonic-gate first = B_FALSE;
30270Sstevel@tonic-gate }
30280Sstevel@tonic-gate if_report_ip6(ap6, ifname,
30290Sstevel@tonic-gate logintname, &stat, B_TRUE);
30300Sstevel@tonic-gate ifindex_v6 = new_ifindex;
30310Sstevel@tonic-gate } else {
30320Sstevel@tonic-gate if_report_ip6(ap6, ifname,
30330Sstevel@tonic-gate logintname, &stat, B_FALSE);
30340Sstevel@tonic-gate }
30350Sstevel@tonic-gate } /* 'for' loop 2d ends */
30360Sstevel@tonic-gate } else if (!alreadydone) {
30370Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1];
30380Sstevel@tonic-gate char buf[IFNAMSIZ + 1];
30390Sstevel@tonic-gate mib2_ipv6AddrEntry_t *ap6;
30400Sstevel@tonic-gate struct ifstat t;
30413129Sja97890 struct iflist *tlp = NULL;
30420Sstevel@tonic-gate struct iflist **nextnew = &newlist6;
30430Sstevel@tonic-gate struct iflist *walkold;
30440Sstevel@tonic-gate struct iflist *cleanlist;
30453129Sja97890 boolean_t found_if = B_FALSE;
30460Sstevel@tonic-gate
30470Sstevel@tonic-gate alreadydone = B_TRUE; /* ignore other case */
30483129Sja97890
30490Sstevel@tonic-gate /*
30503129Sja97890 * Check if there is anything to do.
30513129Sja97890 */
30523129Sja97890 if (item->length <
30533129Sja97890 sizeof (mib2_ipv6AddrEntry_t)) {
30543129Sja97890 fail(0, "No compatible interfaces");
30553129Sja97890 }
30563129Sja97890
30573129Sja97890 /*
30583129Sja97890 * 'for' loop 2e: find the "right" entry:
30593129Sja97890 * If an interface name to match has been
30603129Sja97890 * supplied then try and find it, otherwise
30613129Sja97890 * match the first non-loopback interface found.
30623129Sja97890 * Use lo0 if all else fails.
30630Sstevel@tonic-gate */
30640Sstevel@tonic-gate for (ap6 = (mib2_ipv6AddrEntry_t *)item->valp;
30650Sstevel@tonic-gate (char *)ap6 < (char *)item->valp
30660Sstevel@tonic-gate + item->length;
30670Sstevel@tonic-gate ap6++) {
30680Sstevel@tonic-gate (void) octetstr(&ap6->ipv6AddrIfIndex,
30690Sstevel@tonic-gate 'a', ifname, sizeof (ifname));
30700Sstevel@tonic-gate (void) strtok(ifname, ":");
30710Sstevel@tonic-gate
30720Sstevel@tonic-gate if (matchname) {
30733129Sja97890 if (strcmp(matchname,
30743129Sja97890 ifname) == 0) {
30750Sstevel@tonic-gate /* 'for' loop 2e */
30763129Sja97890 found_if = B_TRUE;
30770Sstevel@tonic-gate break;
30783129Sja97890 }
30793129Sja97890 } else if (strcmp(ifname, "lo0") != 0)
30800Sstevel@tonic-gate break; /* 'for' loop 2e */
30810Sstevel@tonic-gate } /* 'for' loop 2e ends */
30820Sstevel@tonic-gate
30833129Sja97890 if (matchname == NULL) {
30843129Sja97890 matchname = ifname;
30853129Sja97890 } else {
30863129Sja97890 if (!found_if)
30873129Sja97890 fail(0, "-I: %s no such "
30883129Sja97890 "interface.", matchname);
30893129Sja97890 }
30903129Sja97890
30910Sstevel@tonic-gate if (Iflag_only == 0 || !reentry) {
30920Sstevel@tonic-gate (void) printf(
30930Sstevel@tonic-gate " input %-6.6s"
30940Sstevel@tonic-gate " output ",
30950Sstevel@tonic-gate matchname);
30960Sstevel@tonic-gate (void) printf(" input (Total)"
30970Sstevel@tonic-gate " output\n");
30980Sstevel@tonic-gate (void) printf("%-7.7s %-5.5s %-7.7s "
30990Sstevel@tonic-gate "%-5.5s %-6.6s ",
31000Sstevel@tonic-gate "packets", "errs", "packets",
31010Sstevel@tonic-gate "errs", "colls");
31020Sstevel@tonic-gate (void) printf("%-7.7s %-5.5s %-7.7s "
31030Sstevel@tonic-gate "%-5.5s %-6.6s\n",
31040Sstevel@tonic-gate "packets", "errs", "packets",
31050Sstevel@tonic-gate "errs", "colls");
31060Sstevel@tonic-gate }
31070Sstevel@tonic-gate
31080Sstevel@tonic-gate sum6 = zerostat;
31090Sstevel@tonic-gate
31100Sstevel@tonic-gate /* 'for' loop 2f: */
31110Sstevel@tonic-gate for (ap6 = (mib2_ipv6AddrEntry_t *)item->valp;
31120Sstevel@tonic-gate (char *)ap6 < (char *)item->valp
31130Sstevel@tonic-gate + item->length;
31140Sstevel@tonic-gate ap6++) {
31150Sstevel@tonic-gate (void) octetstr(&ap6->ipv6AddrIfIndex,
31160Sstevel@tonic-gate 'a', buf, sizeof (buf));
31170Sstevel@tonic-gate (void) strtok(buf, ":");
31183129Sja97890
31193129Sja97890 /*
31203129Sja97890 * We have reduced the IP interface
31213129Sja97890 * name, which could have been a
31223129Sja97890 * logical, down to a name suitable
31233129Sja97890 * for use with kstats.
31243129Sja97890 * We treat this name as unique and
31253129Sja97890 * only collate statistics for it once
31263129Sja97890 * per pass. This is to avoid falsely
31273129Sja97890 * amplifying these statistics by the
31283129Sja97890 * the number of logical instances.
31293129Sja97890 */
31303129Sja97890
31313129Sja97890 if ((tlp != NULL) &&
31323129Sja97890 ((strcmp(buf, tlp->ifname) == 0))) {
31333129Sja97890 continue;
31343129Sja97890 }
31353129Sja97890
31365895Syz147064 /*
31375895Syz147064 * First lookup the "link" kstats in
31385895Syz147064 * case the link is renamed. Then
31395895Syz147064 * fallback to the legacy kstats for
31405895Syz147064 * those non-GLDv3 links.
31415895Syz147064 */
31425895Syz147064 if (((ksp = kstat_lookup(kc, "link",
31435895Syz147064 0, buf)) != NULL ||
31445895Syz147064 (ksp = kstat_lookup(kc, NULL, -1,
31455895Syz147064 buf)) != NULL) && (ksp->ks_type ==
31465895Syz147064 KSTAT_TYPE_NAMED)) {
31470Sstevel@tonic-gate (void) safe_kstat_read(kc,
31480Sstevel@tonic-gate ksp, NULL);
31495895Syz147064 }
31500Sstevel@tonic-gate
31510Sstevel@tonic-gate t.ipackets = kstat_named_value(ksp,
31520Sstevel@tonic-gate "ipackets");
31530Sstevel@tonic-gate t.ierrors = kstat_named_value(ksp,
31540Sstevel@tonic-gate "ierrors");
31550Sstevel@tonic-gate t.opackets = kstat_named_value(ksp,
31560Sstevel@tonic-gate "opackets");
31570Sstevel@tonic-gate t.oerrors = kstat_named_value(ksp,
31580Sstevel@tonic-gate "oerrors");
31590Sstevel@tonic-gate t.collisions = kstat_named_value(ksp,
31600Sstevel@tonic-gate "collisions");
31610Sstevel@tonic-gate
31620Sstevel@tonic-gate if (strcmp(buf, matchname) == 0)
31630Sstevel@tonic-gate new6 = t;
31640Sstevel@tonic-gate
31650Sstevel@tonic-gate /* Build the interface list */
31660Sstevel@tonic-gate
31670Sstevel@tonic-gate tlp = malloc(sizeof (struct iflist));
31680Sstevel@tonic-gate (void) strlcpy(tlp->ifname, buf,
31690Sstevel@tonic-gate sizeof (tlp->ifname));
31700Sstevel@tonic-gate tlp->tot = t;
31710Sstevel@tonic-gate *nextnew = tlp;
31720Sstevel@tonic-gate nextnew = &tlp->next_if;
31730Sstevel@tonic-gate
31740Sstevel@tonic-gate /*
31750Sstevel@tonic-gate * First time through.
31760Sstevel@tonic-gate * Just add up the interface stats.
31770Sstevel@tonic-gate */
31780Sstevel@tonic-gate
31790Sstevel@tonic-gate if (oldlist6 == NULL) {
31800Sstevel@tonic-gate if_stat_total(&zerostat,
31810Sstevel@tonic-gate &t, &sum6);
31820Sstevel@tonic-gate continue;
31830Sstevel@tonic-gate }
31840Sstevel@tonic-gate
31850Sstevel@tonic-gate /*
31860Sstevel@tonic-gate * Walk old list for the interface.
31870Sstevel@tonic-gate *
31880Sstevel@tonic-gate * If found, add difference to total.
31890Sstevel@tonic-gate *
31900Sstevel@tonic-gate * If not, an interface has been plumbed
31910Sstevel@tonic-gate * up. In this case, we will simply
31920Sstevel@tonic-gate * ignore the new interface until the
31930Sstevel@tonic-gate * next interval; as there's no easy way
31940Sstevel@tonic-gate * to acquire statistics between time
31950Sstevel@tonic-gate * of the plumb and the next interval
31960Sstevel@tonic-gate * boundary. This results in inaccurate
31970Sstevel@tonic-gate * total values for current interval.
31980Sstevel@tonic-gate *
31990Sstevel@tonic-gate * Note the case when an interface is
32000Sstevel@tonic-gate * unplumbed; as similar problems exist.
32010Sstevel@tonic-gate * The unplumbed interface is not in the
32020Sstevel@tonic-gate * current list, and there's no easy way
32030Sstevel@tonic-gate * to account for the statistics between
32040Sstevel@tonic-gate * the previous interval and time of the
32050Sstevel@tonic-gate * unplumb. Therefore, we (in a sense)
32060Sstevel@tonic-gate * ignore the removed interface by only
32070Sstevel@tonic-gate * involving "current" interfaces when
32080Sstevel@tonic-gate * computing the total statistics.
32090Sstevel@tonic-gate * Unfortunately, this also results in
32100Sstevel@tonic-gate * inaccurate values for interval total.
32110Sstevel@tonic-gate */
32120Sstevel@tonic-gate
32130Sstevel@tonic-gate for (walkold = oldlist6;
32140Sstevel@tonic-gate walkold != NULL;
32150Sstevel@tonic-gate walkold = walkold->next_if) {
32160Sstevel@tonic-gate if (strcmp(walkold->ifname,
32170Sstevel@tonic-gate buf) == 0) {
32180Sstevel@tonic-gate if_stat_total(
32190Sstevel@tonic-gate &walkold->tot,
32200Sstevel@tonic-gate &t, &sum6);
32210Sstevel@tonic-gate break;
32220Sstevel@tonic-gate }
32230Sstevel@tonic-gate }
32240Sstevel@tonic-gate
32250Sstevel@tonic-gate } /* 'for' loop 2f ends */
32260Sstevel@tonic-gate
32270Sstevel@tonic-gate *nextnew = NULL;
32280Sstevel@tonic-gate
32290Sstevel@tonic-gate (void) printf("%-7llu %-5llu %-7llu "
32300Sstevel@tonic-gate "%-5llu %-6llu ",
32310Sstevel@tonic-gate new6.ipackets - old6.ipackets,
32320Sstevel@tonic-gate new6.ierrors - old6.ierrors,
32330Sstevel@tonic-gate new6.opackets - old6.opackets,
32340Sstevel@tonic-gate new6.oerrors - old6.oerrors,
32350Sstevel@tonic-gate new6.collisions - old6.collisions);
32360Sstevel@tonic-gate
32370Sstevel@tonic-gate (void) printf("%-7llu %-5llu %-7llu "
32380Sstevel@tonic-gate "%-5llu %-6llu\n", sum6.ipackets,
32390Sstevel@tonic-gate sum6.ierrors, sum6.opackets,
32400Sstevel@tonic-gate sum6.oerrors, sum6.collisions);
32410Sstevel@tonic-gate
32420Sstevel@tonic-gate /*
32430Sstevel@tonic-gate * Tidy things up once finished.
32440Sstevel@tonic-gate */
32450Sstevel@tonic-gate
32460Sstevel@tonic-gate old6 = new6;
32470Sstevel@tonic-gate cleanlist = oldlist6;
32480Sstevel@tonic-gate oldlist6 = newlist6;
32490Sstevel@tonic-gate while (cleanlist != NULL) {
32500Sstevel@tonic-gate tlp = cleanlist->next_if;
32510Sstevel@tonic-gate free(cleanlist);
32520Sstevel@tonic-gate cleanlist = tlp;
32530Sstevel@tonic-gate }
32540Sstevel@tonic-gate }
32550Sstevel@tonic-gate break;
32560Sstevel@tonic-gate }
32570Sstevel@tonic-gate }
32580Sstevel@tonic-gate (void) fflush(stdout);
32590Sstevel@tonic-gate } /* 'for' loop 1 ends */
32605739Skeerthi if ((Iflag_only == 0) && (!once_only))
32615739Skeerthi (void) putchar('\n');
32620Sstevel@tonic-gate reentry = B_TRUE;
32630Sstevel@tonic-gate }
32640Sstevel@tonic-gate
32650Sstevel@tonic-gate static void
if_report_ip4(mib2_ipAddrEntry_t * ap,char ifname[],char logintname[],struct ifstat * statptr,boolean_t ksp_not_null)32660Sstevel@tonic-gate if_report_ip4(mib2_ipAddrEntry_t *ap,
32670Sstevel@tonic-gate char ifname[], char logintname[], struct ifstat *statptr,
32680Sstevel@tonic-gate boolean_t ksp_not_null) {
32690Sstevel@tonic-gate
32700Sstevel@tonic-gate char abuf[MAXHOSTNAMELEN + 1];
32710Sstevel@tonic-gate char dstbuf[MAXHOSTNAMELEN + 1];
32720Sstevel@tonic-gate
32730Sstevel@tonic-gate if (ksp_not_null) {
32749843SAjaykumar.Venkatesulu@Sun.COM (void) printf("%-5s %-4u ",
32750Sstevel@tonic-gate ifname, ap->ipAdEntInfo.ae_mtu);
32760Sstevel@tonic-gate if (ap->ipAdEntInfo.ae_flags & IFF_POINTOPOINT)
32770Sstevel@tonic-gate (void) pr_addr(ap->ipAdEntInfo.ae_pp_dst_addr,
32780Sstevel@tonic-gate abuf, sizeof (abuf));
32790Sstevel@tonic-gate else
32800Sstevel@tonic-gate (void) pr_netaddr(ap->ipAdEntAddr,
32810Sstevel@tonic-gate ap->ipAdEntNetMask, abuf, sizeof (abuf));
32820Sstevel@tonic-gate (void) printf("%-13s %-14s %-6llu %-5llu %-6llu %-5llu "
32830Sstevel@tonic-gate "%-6llu %-6llu\n",
32840Sstevel@tonic-gate abuf, pr_addr(ap->ipAdEntAddr, dstbuf, sizeof (dstbuf)),
32850Sstevel@tonic-gate statptr->ipackets, statptr->ierrors,
32860Sstevel@tonic-gate statptr->opackets, statptr->oerrors,
32870Sstevel@tonic-gate statptr->collisions, 0LL);
32880Sstevel@tonic-gate }
32890Sstevel@tonic-gate /*
32900Sstevel@tonic-gate * Print logical interface info if Aflag set (including logical unit 0)
32910Sstevel@tonic-gate */
32920Sstevel@tonic-gate if (Aflag) {
32930Sstevel@tonic-gate *statptr = zerostat;
32940Sstevel@tonic-gate statptr->ipackets = ap->ipAdEntInfo.ae_ibcnt;
32950Sstevel@tonic-gate statptr->opackets = ap->ipAdEntInfo.ae_obcnt;
32960Sstevel@tonic-gate
32979843SAjaykumar.Venkatesulu@Sun.COM (void) printf("%-5s %-4u ", logintname, ap->ipAdEntInfo.ae_mtu);
32980Sstevel@tonic-gate if (ap->ipAdEntInfo.ae_flags & IFF_POINTOPOINT)
32990Sstevel@tonic-gate (void) pr_addr(ap->ipAdEntInfo.ae_pp_dst_addr, abuf,
33000Sstevel@tonic-gate sizeof (abuf));
33010Sstevel@tonic-gate else
33020Sstevel@tonic-gate (void) pr_netaddr(ap->ipAdEntAddr, ap->ipAdEntNetMask,
33030Sstevel@tonic-gate abuf, sizeof (abuf));
33040Sstevel@tonic-gate
330511042SErik.Nordmark@Sun.COM (void) printf("%-13s %-14s %-6llu %-5s %-6s "
33060Sstevel@tonic-gate "%-5s %-6s %-6llu\n", abuf,
33070Sstevel@tonic-gate pr_addr(ap->ipAdEntAddr, dstbuf, sizeof (dstbuf)),
330811042SErik.Nordmark@Sun.COM statptr->ipackets, "N/A", "N/A", "N/A", "N/A",
33090Sstevel@tonic-gate 0LL);
33100Sstevel@tonic-gate }
33110Sstevel@tonic-gate }
33120Sstevel@tonic-gate
33130Sstevel@tonic-gate static void
if_report_ip6(mib2_ipv6AddrEntry_t * ap6,char ifname[],char logintname[],struct ifstat * statptr,boolean_t ksp_not_null)33140Sstevel@tonic-gate if_report_ip6(mib2_ipv6AddrEntry_t *ap6,
33150Sstevel@tonic-gate char ifname[], char logintname[], struct ifstat *statptr,
33160Sstevel@tonic-gate boolean_t ksp_not_null) {
33170Sstevel@tonic-gate
33180Sstevel@tonic-gate char abuf[MAXHOSTNAMELEN + 1];
33190Sstevel@tonic-gate char dstbuf[MAXHOSTNAMELEN + 1];
33200Sstevel@tonic-gate
33210Sstevel@tonic-gate if (ksp_not_null) {
33229843SAjaykumar.Venkatesulu@Sun.COM (void) printf("%-5s %-4u ", ifname, ap6->ipv6AddrInfo.ae_mtu);
33230Sstevel@tonic-gate if (ap6->ipv6AddrInfo.ae_flags &
33240Sstevel@tonic-gate IFF_POINTOPOINT) {
33250Sstevel@tonic-gate (void) pr_addr6(&ap6->ipv6AddrInfo.ae_pp_dst_addr,
33260Sstevel@tonic-gate abuf, sizeof (abuf));
33270Sstevel@tonic-gate } else {
33280Sstevel@tonic-gate (void) pr_prefix6(&ap6->ipv6AddrAddress,
33290Sstevel@tonic-gate ap6->ipv6AddrPfxLength, abuf,
33300Sstevel@tonic-gate sizeof (abuf));
33310Sstevel@tonic-gate }
33320Sstevel@tonic-gate (void) printf("%-27s %-27s %-6llu %-5llu "
33330Sstevel@tonic-gate "%-6llu %-5llu %-6llu\n",
33340Sstevel@tonic-gate abuf, pr_addr6(&ap6->ipv6AddrAddress, dstbuf,
33350Sstevel@tonic-gate sizeof (dstbuf)),
33360Sstevel@tonic-gate statptr->ipackets, statptr->ierrors, statptr->opackets,
33370Sstevel@tonic-gate statptr->oerrors, statptr->collisions);
33380Sstevel@tonic-gate }
33390Sstevel@tonic-gate /*
33400Sstevel@tonic-gate * Print logical interface info if Aflag set (including logical unit 0)
33410Sstevel@tonic-gate */
33420Sstevel@tonic-gate if (Aflag) {
33430Sstevel@tonic-gate *statptr = zerostat;
33440Sstevel@tonic-gate statptr->ipackets = ap6->ipv6AddrInfo.ae_ibcnt;
33450Sstevel@tonic-gate statptr->opackets = ap6->ipv6AddrInfo.ae_obcnt;
33460Sstevel@tonic-gate
33479843SAjaykumar.Venkatesulu@Sun.COM (void) printf("%-5s %-4u ", logintname,
33480Sstevel@tonic-gate ap6->ipv6AddrInfo.ae_mtu);
33490Sstevel@tonic-gate if (ap6->ipv6AddrInfo.ae_flags & IFF_POINTOPOINT)
33500Sstevel@tonic-gate (void) pr_addr6(&ap6->ipv6AddrInfo.ae_pp_dst_addr,
33510Sstevel@tonic-gate abuf, sizeof (abuf));
33520Sstevel@tonic-gate else
33530Sstevel@tonic-gate (void) pr_prefix6(&ap6->ipv6AddrAddress,
33540Sstevel@tonic-gate ap6->ipv6AddrPfxLength, abuf, sizeof (abuf));
335511042SErik.Nordmark@Sun.COM (void) printf("%-27s %-27s %-6llu %-5s %-6s %-5s %-6s\n",
33560Sstevel@tonic-gate abuf, pr_addr6(&ap6->ipv6AddrAddress, dstbuf,
33570Sstevel@tonic-gate sizeof (dstbuf)),
335811042SErik.Nordmark@Sun.COM statptr->ipackets, "N/A", "N/A", "N/A", "N/A");
33590Sstevel@tonic-gate }
33600Sstevel@tonic-gate }
33610Sstevel@tonic-gate
33620Sstevel@tonic-gate /* --------------------- DHCP_REPORT (netstat -D) ------------------------- */
33630Sstevel@tonic-gate
33643431Scarlsonj static boolean_t
dhcp_do_ipc(dhcp_ipc_type_t type,const char * ifname,boolean_t printed_one)33653431Scarlsonj dhcp_do_ipc(dhcp_ipc_type_t type, const char *ifname, boolean_t printed_one)
33660Sstevel@tonic-gate {
33670Sstevel@tonic-gate dhcp_ipc_request_t *request;
33680Sstevel@tonic-gate dhcp_ipc_reply_t *reply;
33690Sstevel@tonic-gate int error;
33700Sstevel@tonic-gate
33710Sstevel@tonic-gate request = dhcp_ipc_alloc_request(type, ifname, NULL, 0, DHCP_TYPE_NONE);
33720Sstevel@tonic-gate if (request == NULL)
33730Sstevel@tonic-gate fail(0, "dhcp_do_ipc: out of memory");
33740Sstevel@tonic-gate
33750Sstevel@tonic-gate error = dhcp_ipc_make_request(request, &reply, DHCP_IPC_WAIT_DEFAULT);
33760Sstevel@tonic-gate if (error != 0) {
33770Sstevel@tonic-gate free(request);
33780Sstevel@tonic-gate fail(0, "dhcp_do_ipc: %s", dhcp_ipc_strerror(error));
33790Sstevel@tonic-gate }
33800Sstevel@tonic-gate
33810Sstevel@tonic-gate free(request);
33820Sstevel@tonic-gate error = reply->return_code;
33833431Scarlsonj if (error == DHCP_IPC_E_UNKIF) {
33843431Scarlsonj free(reply);
33853431Scarlsonj return (printed_one);
33863431Scarlsonj }
33870Sstevel@tonic-gate if (error != 0) {
33880Sstevel@tonic-gate free(reply);
33890Sstevel@tonic-gate fail(0, "dhcp_do_ipc: %s", dhcp_ipc_strerror(error));
33900Sstevel@tonic-gate }
33910Sstevel@tonic-gate
339210265SKrishnendu.Sadhukhan@Sun.COM if (timestamp_fmt != NODATE)
339310265SKrishnendu.Sadhukhan@Sun.COM print_timestamp(timestamp_fmt);
339410265SKrishnendu.Sadhukhan@Sun.COM
33953431Scarlsonj if (!printed_one)
33963431Scarlsonj (void) printf("%s", dhcp_status_hdr_string());
33973431Scarlsonj
33983431Scarlsonj (void) printf("%s", dhcp_status_reply_to_string(reply));
33993431Scarlsonj free(reply);
34003431Scarlsonj return (B_TRUE);
34010Sstevel@tonic-gate }
34020Sstevel@tonic-gate
34030Sstevel@tonic-gate /*
340410785SPeter.Memishian@Sun.COM * dhcp_walk_interfaces: walk the list of interfaces for a given address
340510785SPeter.Memishian@Sun.COM * family (af). For each, print out the DHCP status using dhcp_do_ipc.
34060Sstevel@tonic-gate */
34073431Scarlsonj static boolean_t
dhcp_walk_interfaces(int af,boolean_t printed_one)340810785SPeter.Memishian@Sun.COM dhcp_walk_interfaces(int af, boolean_t printed_one)
34090Sstevel@tonic-gate {
34103431Scarlsonj struct lifnum lifn;
34113431Scarlsonj struct lifconf lifc;
34120Sstevel@tonic-gate int n_ifs, i, sock_fd;
34133431Scarlsonj
34143431Scarlsonj sock_fd = socket(af, SOCK_DGRAM, 0);
34150Sstevel@tonic-gate if (sock_fd == -1)
34163431Scarlsonj return (printed_one);
34173431Scarlsonj
34183431Scarlsonj /*
34193431Scarlsonj * SIOCGLIFNUM is just an estimate. If the ioctl fails, we don't care;
34203431Scarlsonj * just drive on and use SIOCGLIFCONF with increasing buffer sizes, as
34213431Scarlsonj * is traditional.
34223431Scarlsonj */
34233431Scarlsonj (void) memset(&lifn, 0, sizeof (lifn));
34243431Scarlsonj lifn.lifn_family = af;
34258485SPeter.Memishian@Sun.COM lifn.lifn_flags = LIFC_ALLZONES | LIFC_NOXMIT | LIFC_UNDER_IPMP;
34263431Scarlsonj if (ioctl(sock_fd, SIOCGLIFNUM, &lifn) == -1)
34273431Scarlsonj n_ifs = LIFN_GUARD_VALUE;
34283431Scarlsonj else
34293431Scarlsonj n_ifs = lifn.lifn_count + LIFN_GUARD_VALUE;
34303431Scarlsonj
34313431Scarlsonj (void) memset(&lifc, 0, sizeof (lifc));
34323431Scarlsonj lifc.lifc_family = af;
34333431Scarlsonj lifc.lifc_flags = lifn.lifn_flags;
34343431Scarlsonj lifc.lifc_len = n_ifs * sizeof (struct lifreq);
34353431Scarlsonj lifc.lifc_buf = malloc(lifc.lifc_len);
34363431Scarlsonj if (lifc.lifc_buf != NULL) {
34373431Scarlsonj
34383431Scarlsonj if (ioctl(sock_fd, SIOCGLIFCONF, &lifc) == -1) {
34390Sstevel@tonic-gate (void) close(sock_fd);
34403431Scarlsonj free(lifc.lifc_buf);
34410Sstevel@tonic-gate return (NULL);
34420Sstevel@tonic-gate }
34430Sstevel@tonic-gate
34443431Scarlsonj n_ifs = lifc.lifc_len / sizeof (struct lifreq);
34453431Scarlsonj
34460Sstevel@tonic-gate for (i = 0; i < n_ifs; i++) {
34473431Scarlsonj printed_one = dhcp_do_ipc(DHCP_STATUS |
34483431Scarlsonj (af == AF_INET6 ? DHCP_V6 : 0),
34493431Scarlsonj lifc.lifc_req[i].lifr_name, printed_one);
34503431Scarlsonj }
34510Sstevel@tonic-gate }
34520Sstevel@tonic-gate (void) close(sock_fd);
34533431Scarlsonj free(lifc.lifc_buf);
34543431Scarlsonj return (printed_one);
34550Sstevel@tonic-gate }
34560Sstevel@tonic-gate
34570Sstevel@tonic-gate static void
dhcp_report(char * ifname)34580Sstevel@tonic-gate dhcp_report(char *ifname)
34590Sstevel@tonic-gate {
34603431Scarlsonj boolean_t printed_one;
34613431Scarlsonj
34623431Scarlsonj if (!family_selected(AF_INET) && !family_selected(AF_INET6))
34630Sstevel@tonic-gate return;
34640Sstevel@tonic-gate
34653431Scarlsonj printed_one = B_FALSE;
34663431Scarlsonj if (ifname != NULL) {
34673431Scarlsonj if (family_selected(AF_INET)) {
34683431Scarlsonj printed_one = dhcp_do_ipc(DHCP_STATUS, ifname,
34693431Scarlsonj printed_one);
34703431Scarlsonj }
34713431Scarlsonj if (family_selected(AF_INET6)) {
34723431Scarlsonj printed_one = dhcp_do_ipc(DHCP_STATUS | DHCP_V6,
34733431Scarlsonj ifname, printed_one);
34743431Scarlsonj }
34753431Scarlsonj if (!printed_one) {
34763431Scarlsonj fail(0, "%s: %s", ifname,
34773431Scarlsonj dhcp_ipc_strerror(DHCP_IPC_E_UNKIF));
34783431Scarlsonj }
34793431Scarlsonj } else {
34803431Scarlsonj if (family_selected(AF_INET)) {
348110785SPeter.Memishian@Sun.COM printed_one = dhcp_walk_interfaces(AF_INET,
348210785SPeter.Memishian@Sun.COM printed_one);
34833431Scarlsonj }
348410785SPeter.Memishian@Sun.COM if (family_selected(AF_INET6))
348510785SPeter.Memishian@Sun.COM (void) dhcp_walk_interfaces(AF_INET6, printed_one);
34860Sstevel@tonic-gate }
34870Sstevel@tonic-gate }
34880Sstevel@tonic-gate
34890Sstevel@tonic-gate /* --------------------- GROUP_REPORT (netstat -g) ------------------------- */
34900Sstevel@tonic-gate
34910Sstevel@tonic-gate static void
group_report(mib_item_t * item)34920Sstevel@tonic-gate group_report(mib_item_t *item)
34930Sstevel@tonic-gate {
34940Sstevel@tonic-gate mib_item_t *v4grp = NULL, *v4src = NULL;
34950Sstevel@tonic-gate mib_item_t *v6grp = NULL, *v6src = NULL;
34960Sstevel@tonic-gate int jtemp = 0;
34970Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1];
34980Sstevel@tonic-gate char abuf[MAXHOSTNAMELEN + 1];
34990Sstevel@tonic-gate ip_member_t *ipmp;
35000Sstevel@tonic-gate ip_grpsrc_t *ips;
35010Sstevel@tonic-gate ipv6_member_t *ipmp6;
35020Sstevel@tonic-gate ipv6_grpsrc_t *ips6;
35030Sstevel@tonic-gate boolean_t first, first_src;
35040Sstevel@tonic-gate
35050Sstevel@tonic-gate /* 'for' loop 1: */
35060Sstevel@tonic-gate for (; item; item = item->next_item) {
350711042SErik.Nordmark@Sun.COM if (Xflag) {
35080Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp);
35090Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, "
35100Sstevel@tonic-gate "length = %d, valp = 0x%p\n",
35110Sstevel@tonic-gate item->group, item->mib_id, item->length,
35120Sstevel@tonic-gate item->valp);
35130Sstevel@tonic-gate }
35140Sstevel@tonic-gate if (item->group == MIB2_IP && family_selected(AF_INET)) {
35150Sstevel@tonic-gate switch (item->mib_id) {
35160Sstevel@tonic-gate case EXPER_IP_GROUP_MEMBERSHIP:
35170Sstevel@tonic-gate v4grp = item;
351811042SErik.Nordmark@Sun.COM if (Xflag)
35190Sstevel@tonic-gate (void) printf("item is v4grp info\n");
35200Sstevel@tonic-gate break;
35210Sstevel@tonic-gate case EXPER_IP_GROUP_SOURCES:
35220Sstevel@tonic-gate v4src = item;
352311042SErik.Nordmark@Sun.COM if (Xflag)
35240Sstevel@tonic-gate (void) printf("item is v4src info\n");
35250Sstevel@tonic-gate break;
35260Sstevel@tonic-gate default:
35270Sstevel@tonic-gate continue;
35280Sstevel@tonic-gate }
35290Sstevel@tonic-gate continue;
35300Sstevel@tonic-gate }
35310Sstevel@tonic-gate if (item->group == MIB2_IP6 && family_selected(AF_INET6)) {
35320Sstevel@tonic-gate switch (item->mib_id) {
35330Sstevel@tonic-gate case EXPER_IP6_GROUP_MEMBERSHIP:
35340Sstevel@tonic-gate v6grp = item;
353511042SErik.Nordmark@Sun.COM if (Xflag)
35360Sstevel@tonic-gate (void) printf("item is v6grp info\n");
35370Sstevel@tonic-gate break;
35380Sstevel@tonic-gate case EXPER_IP6_GROUP_SOURCES:
35390Sstevel@tonic-gate v6src = item;
354011042SErik.Nordmark@Sun.COM if (Xflag)
35410Sstevel@tonic-gate (void) printf("item is v6src info\n");
35420Sstevel@tonic-gate break;
35430Sstevel@tonic-gate default:
35440Sstevel@tonic-gate continue;
35450Sstevel@tonic-gate }
35460Sstevel@tonic-gate }
35470Sstevel@tonic-gate }
35480Sstevel@tonic-gate
35490Sstevel@tonic-gate if (family_selected(AF_INET) && v4grp != NULL) {
355011042SErik.Nordmark@Sun.COM if (Xflag)
35510Sstevel@tonic-gate (void) printf("%u records for ipGroupMember:\n",
35520Sstevel@tonic-gate v4grp->length / sizeof (ip_member_t));
35530Sstevel@tonic-gate
35540Sstevel@tonic-gate first = B_TRUE;
35550Sstevel@tonic-gate for (ipmp = (ip_member_t *)v4grp->valp;
35560Sstevel@tonic-gate (char *)ipmp < (char *)v4grp->valp + v4grp->length;
35570Sstevel@tonic-gate /* LINTED: (note 1) */
35580Sstevel@tonic-gate ipmp = (ip_member_t *)((char *)ipmp + ipMemberEntrySize)) {
35590Sstevel@tonic-gate if (first) {
35600Sstevel@tonic-gate (void) puts(v4compat ?
35610Sstevel@tonic-gate "Group Memberships" :
35620Sstevel@tonic-gate "Group Memberships: IPv4");
35630Sstevel@tonic-gate (void) puts("Interface "
35640Sstevel@tonic-gate "Group RefCnt");
35650Sstevel@tonic-gate (void) puts("--------- "
35660Sstevel@tonic-gate "-------------------- ------");
35670Sstevel@tonic-gate first = B_FALSE;
35680Sstevel@tonic-gate }
35690Sstevel@tonic-gate
35700Sstevel@tonic-gate (void) printf("%-9s %-20s %6u\n",
35710Sstevel@tonic-gate octetstr(&ipmp->ipGroupMemberIfIndex, 'a',
35720Sstevel@tonic-gate ifname, sizeof (ifname)),
35730Sstevel@tonic-gate pr_addr(ipmp->ipGroupMemberAddress,
35740Sstevel@tonic-gate abuf, sizeof (abuf)),
35750Sstevel@tonic-gate ipmp->ipGroupMemberRefCnt);
35760Sstevel@tonic-gate
35770Sstevel@tonic-gate
35780Sstevel@tonic-gate if (!Vflag || v4src == NULL)
35790Sstevel@tonic-gate continue;
35800Sstevel@tonic-gate
358111042SErik.Nordmark@Sun.COM if (Xflag)
35820Sstevel@tonic-gate (void) printf("scanning %u ipGroupSource "
35830Sstevel@tonic-gate "records...\n",
35840Sstevel@tonic-gate v4src->length/sizeof (ip_grpsrc_t));
35850Sstevel@tonic-gate
35860Sstevel@tonic-gate first_src = B_TRUE;
35870Sstevel@tonic-gate for (ips = (ip_grpsrc_t *)v4src->valp;
35880Sstevel@tonic-gate (char *)ips < (char *)v4src->valp + v4src->length;
35890Sstevel@tonic-gate /* LINTED: (note 1) */
35900Sstevel@tonic-gate ips = (ip_grpsrc_t *)((char *)ips +
35910Sstevel@tonic-gate ipGroupSourceEntrySize)) {
35920Sstevel@tonic-gate /*
35930Sstevel@tonic-gate * We assume that all source addrs for a given
35940Sstevel@tonic-gate * interface/group pair are contiguous, so on
35950Sstevel@tonic-gate * the first non-match after we've found at
35960Sstevel@tonic-gate * least one, we bail.
35970Sstevel@tonic-gate */
35980Sstevel@tonic-gate if ((ipmp->ipGroupMemberAddress !=
35990Sstevel@tonic-gate ips->ipGroupSourceGroup) ||
36000Sstevel@tonic-gate (!octetstrmatch(&ipmp->ipGroupMemberIfIndex,
36010Sstevel@tonic-gate &ips->ipGroupSourceIfIndex))) {
36020Sstevel@tonic-gate if (first_src)
36030Sstevel@tonic-gate continue;
36040Sstevel@tonic-gate else
36050Sstevel@tonic-gate break;
36060Sstevel@tonic-gate }
36070Sstevel@tonic-gate if (first_src) {
36080Sstevel@tonic-gate (void) printf("\t%s: %s\n",
36090Sstevel@tonic-gate fmodestr(
36100Sstevel@tonic-gate ipmp->ipGroupMemberFilterMode),
36110Sstevel@tonic-gate pr_addr(ips->ipGroupSourceAddress,
36120Sstevel@tonic-gate abuf, sizeof (abuf)));
36130Sstevel@tonic-gate first_src = B_FALSE;
36140Sstevel@tonic-gate continue;
36150Sstevel@tonic-gate }
36160Sstevel@tonic-gate
36170Sstevel@tonic-gate (void) printf("\t %s\n",
36180Sstevel@tonic-gate pr_addr(ips->ipGroupSourceAddress, abuf,
36190Sstevel@tonic-gate sizeof (abuf)));
36200Sstevel@tonic-gate }
36210Sstevel@tonic-gate }
36220Sstevel@tonic-gate (void) putchar('\n');
36230Sstevel@tonic-gate }
36240Sstevel@tonic-gate
36250Sstevel@tonic-gate if (family_selected(AF_INET6) && v6grp != NULL) {
362611042SErik.Nordmark@Sun.COM if (Xflag)
36270Sstevel@tonic-gate (void) printf("%u records for ipv6GroupMember:\n",
36280Sstevel@tonic-gate v6grp->length / sizeof (ipv6_member_t));
36290Sstevel@tonic-gate
36300Sstevel@tonic-gate first = B_TRUE;
36310Sstevel@tonic-gate for (ipmp6 = (ipv6_member_t *)v6grp->valp;
36320Sstevel@tonic-gate (char *)ipmp6 < (char *)v6grp->valp + v6grp->length;
36330Sstevel@tonic-gate /* LINTED: (note 1) */
36340Sstevel@tonic-gate ipmp6 = (ipv6_member_t *)((char *)ipmp6 +
36358485SPeter.Memishian@Sun.COM ipv6MemberEntrySize)) {
36360Sstevel@tonic-gate if (first) {
36370Sstevel@tonic-gate (void) puts("Group Memberships: "
36380Sstevel@tonic-gate "IPv6");
36390Sstevel@tonic-gate (void) puts(" If "
36400Sstevel@tonic-gate "Group RefCnt");
36410Sstevel@tonic-gate (void) puts("----- "
36420Sstevel@tonic-gate "--------------------------- ------");
36430Sstevel@tonic-gate first = B_FALSE;
36440Sstevel@tonic-gate }
36450Sstevel@tonic-gate
36460Sstevel@tonic-gate (void) printf("%-5s %-27s %5u\n",
36478485SPeter.Memishian@Sun.COM ifindex2str(ipmp6->ipv6GroupMemberIfIndex, ifname),
36480Sstevel@tonic-gate pr_addr6(&ipmp6->ipv6GroupMemberAddress,
36490Sstevel@tonic-gate abuf, sizeof (abuf)),
36500Sstevel@tonic-gate ipmp6->ipv6GroupMemberRefCnt);
36510Sstevel@tonic-gate
36520Sstevel@tonic-gate if (!Vflag || v6src == NULL)
36530Sstevel@tonic-gate continue;
36540Sstevel@tonic-gate
365511042SErik.Nordmark@Sun.COM if (Xflag)
36560Sstevel@tonic-gate (void) printf("scanning %u ipv6GroupSource "
36570Sstevel@tonic-gate "records...\n",
36580Sstevel@tonic-gate v6src->length/sizeof (ipv6_grpsrc_t));
36590Sstevel@tonic-gate
36600Sstevel@tonic-gate first_src = B_TRUE;
36610Sstevel@tonic-gate for (ips6 = (ipv6_grpsrc_t *)v6src->valp;
36620Sstevel@tonic-gate (char *)ips6 < (char *)v6src->valp + v6src->length;
36630Sstevel@tonic-gate /* LINTED: (note 1) */
36640Sstevel@tonic-gate ips6 = (ipv6_grpsrc_t *)((char *)ips6 +
36650Sstevel@tonic-gate ipv6GroupSourceEntrySize)) {
36660Sstevel@tonic-gate /* same assumption as in the v4 case above */
36670Sstevel@tonic-gate if ((ipmp6->ipv6GroupMemberIfIndex !=
36680Sstevel@tonic-gate ips6->ipv6GroupSourceIfIndex) ||
36690Sstevel@tonic-gate (!IN6_ARE_ADDR_EQUAL(
36700Sstevel@tonic-gate &ipmp6->ipv6GroupMemberAddress,
36710Sstevel@tonic-gate &ips6->ipv6GroupSourceGroup))) {
36720Sstevel@tonic-gate if (first_src)
36730Sstevel@tonic-gate continue;
36740Sstevel@tonic-gate else
36750Sstevel@tonic-gate break;
36760Sstevel@tonic-gate }
36770Sstevel@tonic-gate if (first_src) {
36780Sstevel@tonic-gate (void) printf("\t%s: %s\n",
36790Sstevel@tonic-gate fmodestr(
36800Sstevel@tonic-gate ipmp6->ipv6GroupMemberFilterMode),
36810Sstevel@tonic-gate pr_addr6(
36820Sstevel@tonic-gate &ips6->ipv6GroupSourceAddress,
36830Sstevel@tonic-gate abuf, sizeof (abuf)));
36840Sstevel@tonic-gate first_src = B_FALSE;
36850Sstevel@tonic-gate continue;
36860Sstevel@tonic-gate }
36870Sstevel@tonic-gate
36880Sstevel@tonic-gate (void) printf("\t %s\n",
36890Sstevel@tonic-gate pr_addr6(&ips6->ipv6GroupSourceAddress,
36900Sstevel@tonic-gate abuf, sizeof (abuf)));
36910Sstevel@tonic-gate }
36920Sstevel@tonic-gate }
36930Sstevel@tonic-gate (void) putchar('\n');
36940Sstevel@tonic-gate }
36950Sstevel@tonic-gate
36960Sstevel@tonic-gate (void) putchar('\n');
36970Sstevel@tonic-gate (void) fflush(stdout);
36980Sstevel@tonic-gate }
36990Sstevel@tonic-gate
370011042SErik.Nordmark@Sun.COM /* --------------------- DCE_REPORT (netstat -d) ------------------------- */
370111042SErik.Nordmark@Sun.COM
370211042SErik.Nordmark@Sun.COM #define FLBUFSIZE 8
370311042SErik.Nordmark@Sun.COM
370411042SErik.Nordmark@Sun.COM /* Assumes flbuf is at least 5 characters; callers use FLBUFSIZE */
370511042SErik.Nordmark@Sun.COM static char *
dceflags2str(uint32_t flags,char * flbuf)370611042SErik.Nordmark@Sun.COM dceflags2str(uint32_t flags, char *flbuf)
370711042SErik.Nordmark@Sun.COM {
370811042SErik.Nordmark@Sun.COM char *str = flbuf;
370911042SErik.Nordmark@Sun.COM
371011042SErik.Nordmark@Sun.COM if (flags & DCEF_DEFAULT)
371111042SErik.Nordmark@Sun.COM *str++ = 'D';
371211042SErik.Nordmark@Sun.COM if (flags & DCEF_PMTU)
371311042SErik.Nordmark@Sun.COM *str++ = 'P';
371411042SErik.Nordmark@Sun.COM if (flags & DCEF_UINFO)
371511042SErik.Nordmark@Sun.COM *str++ = 'U';
371611042SErik.Nordmark@Sun.COM if (flags & DCEF_TOO_SMALL_PMTU)
371711042SErik.Nordmark@Sun.COM *str++ = 'S';
371811042SErik.Nordmark@Sun.COM *str++ = '\0';
371911042SErik.Nordmark@Sun.COM return (flbuf);
372011042SErik.Nordmark@Sun.COM }
372111042SErik.Nordmark@Sun.COM
372211042SErik.Nordmark@Sun.COM static void
dce_report(mib_item_t * item)372311042SErik.Nordmark@Sun.COM dce_report(mib_item_t *item)
372411042SErik.Nordmark@Sun.COM {
372511042SErik.Nordmark@Sun.COM mib_item_t *v4dce = NULL;
372611042SErik.Nordmark@Sun.COM mib_item_t *v6dce = NULL;
372711042SErik.Nordmark@Sun.COM int jtemp = 0;
372811042SErik.Nordmark@Sun.COM char ifname[LIFNAMSIZ + 1];
372911042SErik.Nordmark@Sun.COM char abuf[MAXHOSTNAMELEN + 1];
373011042SErik.Nordmark@Sun.COM char flbuf[FLBUFSIZE];
373111042SErik.Nordmark@Sun.COM boolean_t first;
373211042SErik.Nordmark@Sun.COM dest_cache_entry_t *dce;
373311042SErik.Nordmark@Sun.COM
373411042SErik.Nordmark@Sun.COM /* 'for' loop 1: */
373511042SErik.Nordmark@Sun.COM for (; item; item = item->next_item) {
373611042SErik.Nordmark@Sun.COM if (Xflag) {
373711042SErik.Nordmark@Sun.COM (void) printf("\n--- Entry %d ---\n", ++jtemp);
373811042SErik.Nordmark@Sun.COM (void) printf("Group = %d, mib_id = %d, "
373911042SErik.Nordmark@Sun.COM "length = %d, valp = 0x%p\n",
374011042SErik.Nordmark@Sun.COM item->group, item->mib_id, item->length,
374111042SErik.Nordmark@Sun.COM item->valp);
374211042SErik.Nordmark@Sun.COM }
374311042SErik.Nordmark@Sun.COM if (item->group == MIB2_IP && family_selected(AF_INET) &&
374411042SErik.Nordmark@Sun.COM item->mib_id == EXPER_IP_DCE) {
374511042SErik.Nordmark@Sun.COM v4dce = item;
374611042SErik.Nordmark@Sun.COM if (Xflag)
374711042SErik.Nordmark@Sun.COM (void) printf("item is v4dce info\n");
374811042SErik.Nordmark@Sun.COM }
374911042SErik.Nordmark@Sun.COM if (item->group == MIB2_IP6 && family_selected(AF_INET6) &&
375011042SErik.Nordmark@Sun.COM item->mib_id == EXPER_IP_DCE) {
375111042SErik.Nordmark@Sun.COM v6dce = item;
375211042SErik.Nordmark@Sun.COM if (Xflag)
375311042SErik.Nordmark@Sun.COM (void) printf("item is v6dce info\n");
375411042SErik.Nordmark@Sun.COM }
375511042SErik.Nordmark@Sun.COM }
375611042SErik.Nordmark@Sun.COM
375711042SErik.Nordmark@Sun.COM if (family_selected(AF_INET) && v4dce != NULL) {
375811042SErik.Nordmark@Sun.COM if (Xflag)
375911042SErik.Nordmark@Sun.COM (void) printf("%u records for DestCacheEntry:\n",
376011042SErik.Nordmark@Sun.COM v4dce->length / ipDestEntrySize);
376111042SErik.Nordmark@Sun.COM
376211042SErik.Nordmark@Sun.COM first = B_TRUE;
376311042SErik.Nordmark@Sun.COM for (dce = (dest_cache_entry_t *)v4dce->valp;
376411042SErik.Nordmark@Sun.COM (char *)dce < (char *)v4dce->valp + v4dce->length;
376511042SErik.Nordmark@Sun.COM /* LINTED: (note 1) */
376611042SErik.Nordmark@Sun.COM dce = (dest_cache_entry_t *)((char *)dce +
376711042SErik.Nordmark@Sun.COM ipDestEntrySize)) {
376811042SErik.Nordmark@Sun.COM if (first) {
376911042SErik.Nordmark@Sun.COM (void) putchar('\n');
377011042SErik.Nordmark@Sun.COM (void) puts("Destination Cache Entries: IPv4");
377111042SErik.Nordmark@Sun.COM (void) puts(
377211042SErik.Nordmark@Sun.COM "Address PMTU Age Flags");
377311042SErik.Nordmark@Sun.COM (void) puts(
377411042SErik.Nordmark@Sun.COM "-------------------- ------ ----- -----");
377511042SErik.Nordmark@Sun.COM first = B_FALSE;
377611042SErik.Nordmark@Sun.COM }
377711042SErik.Nordmark@Sun.COM
377811042SErik.Nordmark@Sun.COM (void) printf("%-20s %6u %5u %-5s\n",
377911042SErik.Nordmark@Sun.COM pr_addr(dce->DestIpv4Address, abuf, sizeof (abuf)),
378011042SErik.Nordmark@Sun.COM dce->DestPmtu, dce->DestAge,
378111042SErik.Nordmark@Sun.COM dceflags2str(dce->DestFlags, flbuf));
378211042SErik.Nordmark@Sun.COM }
378311042SErik.Nordmark@Sun.COM }
378411042SErik.Nordmark@Sun.COM
378511042SErik.Nordmark@Sun.COM if (family_selected(AF_INET6) && v6dce != NULL) {
378611042SErik.Nordmark@Sun.COM if (Xflag)
378711042SErik.Nordmark@Sun.COM (void) printf("%u records for DestCacheEntry:\n",
378811042SErik.Nordmark@Sun.COM v6dce->length / ipDestEntrySize);
378911042SErik.Nordmark@Sun.COM
379011042SErik.Nordmark@Sun.COM first = B_TRUE;
379111042SErik.Nordmark@Sun.COM for (dce = (dest_cache_entry_t *)v6dce->valp;
379211042SErik.Nordmark@Sun.COM (char *)dce < (char *)v6dce->valp + v6dce->length;
379311042SErik.Nordmark@Sun.COM /* LINTED: (note 1) */
379411042SErik.Nordmark@Sun.COM dce = (dest_cache_entry_t *)((char *)dce +
379511042SErik.Nordmark@Sun.COM ipDestEntrySize)) {
379611042SErik.Nordmark@Sun.COM if (first) {
379711042SErik.Nordmark@Sun.COM (void) putchar('\n');
379811042SErik.Nordmark@Sun.COM (void) puts("Destination Cache Entries: IPv6");
379911042SErik.Nordmark@Sun.COM (void) puts(
380011042SErik.Nordmark@Sun.COM "Address PMTU "
380111042SErik.Nordmark@Sun.COM " Age Flags If ");
380211042SErik.Nordmark@Sun.COM (void) puts(
380311042SErik.Nordmark@Sun.COM "--------------------------- ------ "
380411042SErik.Nordmark@Sun.COM "----- ----- ---");
380511042SErik.Nordmark@Sun.COM first = B_FALSE;
380611042SErik.Nordmark@Sun.COM }
380711042SErik.Nordmark@Sun.COM
380811042SErik.Nordmark@Sun.COM (void) printf("%-27s %6u %5u %-5s %s\n",
380911042SErik.Nordmark@Sun.COM pr_addr6(&dce->DestIpv6Address, abuf,
381011042SErik.Nordmark@Sun.COM sizeof (abuf)),
381111042SErik.Nordmark@Sun.COM dce->DestPmtu, dce->DestAge,
381211042SErik.Nordmark@Sun.COM dceflags2str(dce->DestFlags, flbuf),
381311042SErik.Nordmark@Sun.COM dce->DestIfindex == 0 ? "" :
381411042SErik.Nordmark@Sun.COM ifindex2str(dce->DestIfindex, ifname));
381511042SErik.Nordmark@Sun.COM }
381611042SErik.Nordmark@Sun.COM }
381711042SErik.Nordmark@Sun.COM (void) fflush(stdout);
381811042SErik.Nordmark@Sun.COM }
381911042SErik.Nordmark@Sun.COM
38200Sstevel@tonic-gate /* --------------------- ARP_REPORT (netstat -p) -------------------------- */
38210Sstevel@tonic-gate
38220Sstevel@tonic-gate static void
arp_report(mib_item_t * item)38230Sstevel@tonic-gate arp_report(mib_item_t *item)
38240Sstevel@tonic-gate {
38250Sstevel@tonic-gate int jtemp = 0;
38260Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1];
38270Sstevel@tonic-gate char abuf[MAXHOSTNAMELEN + 1];
38280Sstevel@tonic-gate char maskbuf[STR_EXPAND * OCTET_LENGTH + 1];
38290Sstevel@tonic-gate char flbuf[32]; /* ACE_F_ flags */
38300Sstevel@tonic-gate char xbuf[STR_EXPAND * OCTET_LENGTH + 1];
38310Sstevel@tonic-gate mib2_ipNetToMediaEntry_t *np;
38320Sstevel@tonic-gate int flags;
38330Sstevel@tonic-gate boolean_t first;
38340Sstevel@tonic-gate
38350Sstevel@tonic-gate if (!(family_selected(AF_INET)))
38360Sstevel@tonic-gate return;
38370Sstevel@tonic-gate
38380Sstevel@tonic-gate /* 'for' loop 1: */
38390Sstevel@tonic-gate for (; item; item = item->next_item) {
384011042SErik.Nordmark@Sun.COM if (Xflag) {
38410Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp);
38420Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, "
38430Sstevel@tonic-gate "length = %d, valp = 0x%p\n",
38440Sstevel@tonic-gate item->group, item->mib_id, item->length,
38450Sstevel@tonic-gate item->valp);
38460Sstevel@tonic-gate }
38470Sstevel@tonic-gate if (!(item->group == MIB2_IP && item->mib_id == MIB2_IP_MEDIA))
38480Sstevel@tonic-gate continue; /* 'for' loop 1 */
38490Sstevel@tonic-gate
385011042SErik.Nordmark@Sun.COM if (Xflag)
38510Sstevel@tonic-gate (void) printf("%u records for "
38520Sstevel@tonic-gate "ipNetToMediaEntryTable:\n",
38530Sstevel@tonic-gate item->length/sizeof (mib2_ipNetToMediaEntry_t));
38540Sstevel@tonic-gate
38550Sstevel@tonic-gate first = B_TRUE;
38560Sstevel@tonic-gate /* 'for' loop 2: */
38570Sstevel@tonic-gate for (np = (mib2_ipNetToMediaEntry_t *)item->valp;
38580Sstevel@tonic-gate (char *)np < (char *)item->valp + item->length;
38590Sstevel@tonic-gate /* LINTED: (note 1) */
38600Sstevel@tonic-gate np = (mib2_ipNetToMediaEntry_t *)((char *)np +
38610Sstevel@tonic-gate ipNetToMediaEntrySize)) {
38620Sstevel@tonic-gate if (first) {
38630Sstevel@tonic-gate (void) puts(v4compat ?
38640Sstevel@tonic-gate "Net to Media Table" :
38650Sstevel@tonic-gate "Net to Media Table: IPv4");
38662546Scarlsonj (void) puts("Device "
38672546Scarlsonj " IP Address Mask "
38682546Scarlsonj "Flags Phys Addr");
38692546Scarlsonj (void) puts("------ "
38702546Scarlsonj "-------------------- --------------- "
38712546Scarlsonj "-------- ---------------");
38720Sstevel@tonic-gate first = B_FALSE;
38730Sstevel@tonic-gate }
38740Sstevel@tonic-gate
38750Sstevel@tonic-gate flbuf[0] = '\0';
38760Sstevel@tonic-gate flags = np->ipNetToMediaInfo.ntm_flags;
38772546Scarlsonj /*
38782546Scarlsonj * Note that not all flags are possible at the same
38792546Scarlsonj * time. Patterns: SPLAy DUo
38802546Scarlsonj */
38810Sstevel@tonic-gate if (flags & ACE_F_PERMANENT)
38820Sstevel@tonic-gate (void) strcat(flbuf, "S");
38830Sstevel@tonic-gate if (flags & ACE_F_PUBLISH)
38840Sstevel@tonic-gate (void) strcat(flbuf, "P");
38850Sstevel@tonic-gate if (flags & ACE_F_DYING)
38860Sstevel@tonic-gate (void) strcat(flbuf, "D");
38870Sstevel@tonic-gate if (!(flags & ACE_F_RESOLVED))
38880Sstevel@tonic-gate (void) strcat(flbuf, "U");
38890Sstevel@tonic-gate if (flags & ACE_F_MAPPING)
38900Sstevel@tonic-gate (void) strcat(flbuf, "M");
38912546Scarlsonj if (flags & ACE_F_MYADDR)
38922546Scarlsonj (void) strcat(flbuf, "L");
38932546Scarlsonj if (flags & ACE_F_UNVERIFIED)
38942546Scarlsonj (void) strcat(flbuf, "d");
38952546Scarlsonj if (flags & ACE_F_AUTHORITY)
38962546Scarlsonj (void) strcat(flbuf, "A");
38972546Scarlsonj if (flags & ACE_F_OLD)
38982546Scarlsonj (void) strcat(flbuf, "o");
38992546Scarlsonj if (flags & ACE_F_DELAYED)
39002546Scarlsonj (void) strcat(flbuf, "y");
39012546Scarlsonj (void) printf("%-6s %-20s %-15s %-8s %s\n",
39020Sstevel@tonic-gate octetstr(&np->ipNetToMediaIfIndex, 'a',
39030Sstevel@tonic-gate ifname, sizeof (ifname)),
39040Sstevel@tonic-gate pr_addr(np->ipNetToMediaNetAddress,
39050Sstevel@tonic-gate abuf, sizeof (abuf)),
39060Sstevel@tonic-gate octetstr(&np->ipNetToMediaInfo.ntm_mask, 'd',
39070Sstevel@tonic-gate maskbuf, sizeof (maskbuf)),
39080Sstevel@tonic-gate flbuf,
39090Sstevel@tonic-gate octetstr(&np->ipNetToMediaPhysAddress, 'h',
39100Sstevel@tonic-gate xbuf, sizeof (xbuf)));
39110Sstevel@tonic-gate } /* 'for' loop 2 ends */
39120Sstevel@tonic-gate } /* 'for' loop 1 ends */
39130Sstevel@tonic-gate (void) fflush(stdout);
39140Sstevel@tonic-gate }
39150Sstevel@tonic-gate
39160Sstevel@tonic-gate /* --------------------- NDP_REPORT (netstat -p) -------------------------- */
39170Sstevel@tonic-gate
39180Sstevel@tonic-gate static void
ndp_report(mib_item_t * item)39190Sstevel@tonic-gate ndp_report(mib_item_t *item)
39200Sstevel@tonic-gate {
39210Sstevel@tonic-gate int jtemp = 0;
39220Sstevel@tonic-gate char abuf[MAXHOSTNAMELEN + 1];
39230Sstevel@tonic-gate char *state;
39240Sstevel@tonic-gate char *type;
39250Sstevel@tonic-gate char xbuf[STR_EXPAND * OCTET_LENGTH + 1];
39260Sstevel@tonic-gate mib2_ipv6NetToMediaEntry_t *np6;
39270Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1];
39280Sstevel@tonic-gate boolean_t first;
39290Sstevel@tonic-gate
39300Sstevel@tonic-gate if (!(family_selected(AF_INET6)))
39310Sstevel@tonic-gate return;
39320Sstevel@tonic-gate
39330Sstevel@tonic-gate /* 'for' loop 1: */
39340Sstevel@tonic-gate for (; item; item = item->next_item) {
393511042SErik.Nordmark@Sun.COM if (Xflag) {
39360Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp);
39370Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, "
39380Sstevel@tonic-gate "length = %d, valp = 0x%p\n",
39390Sstevel@tonic-gate item->group, item->mib_id, item->length,
39400Sstevel@tonic-gate item->valp);
39410Sstevel@tonic-gate }
39420Sstevel@tonic-gate if (!(item->group == MIB2_IP6 &&
39430Sstevel@tonic-gate item->mib_id == MIB2_IP6_MEDIA))
39440Sstevel@tonic-gate continue; /* 'for' loop 1 */
39450Sstevel@tonic-gate
39460Sstevel@tonic-gate first = B_TRUE;
39470Sstevel@tonic-gate /* 'for' loop 2: */
39480Sstevel@tonic-gate for (np6 = (mib2_ipv6NetToMediaEntry_t *)item->valp;
39490Sstevel@tonic-gate (char *)np6 < (char *)item->valp + item->length;
39500Sstevel@tonic-gate /* LINTED: (note 1) */
39510Sstevel@tonic-gate np6 = (mib2_ipv6NetToMediaEntry_t *)((char *)np6 +
39520Sstevel@tonic-gate ipv6NetToMediaEntrySize)) {
39530Sstevel@tonic-gate if (first) {
39540Sstevel@tonic-gate (void) puts("\nNet to Media Table: IPv6");
39550Sstevel@tonic-gate (void) puts(" If Physical Address "
39560Sstevel@tonic-gate " Type State Destination/Mask");
39570Sstevel@tonic-gate (void) puts("----- ----------------- "
39580Sstevel@tonic-gate "------- ------------ "
39590Sstevel@tonic-gate "---------------------------");
39600Sstevel@tonic-gate first = B_FALSE;
39610Sstevel@tonic-gate }
39620Sstevel@tonic-gate
39630Sstevel@tonic-gate switch (np6->ipv6NetToMediaState) {
39640Sstevel@tonic-gate case ND_INCOMPLETE:
39650Sstevel@tonic-gate state = "INCOMPLETE";
39660Sstevel@tonic-gate break;
39670Sstevel@tonic-gate case ND_REACHABLE:
39680Sstevel@tonic-gate state = "REACHABLE";
39690Sstevel@tonic-gate break;
39700Sstevel@tonic-gate case ND_STALE:
39710Sstevel@tonic-gate state = "STALE";
39720Sstevel@tonic-gate break;
39730Sstevel@tonic-gate case ND_DELAY:
39740Sstevel@tonic-gate state = "DELAY";
39750Sstevel@tonic-gate break;
39760Sstevel@tonic-gate case ND_PROBE:
39770Sstevel@tonic-gate state = "PROBE";
39780Sstevel@tonic-gate break;
39790Sstevel@tonic-gate case ND_UNREACHABLE:
39800Sstevel@tonic-gate state = "UNREACHABLE";
39810Sstevel@tonic-gate break;
39820Sstevel@tonic-gate default:
39830Sstevel@tonic-gate state = "UNKNOWN";
39840Sstevel@tonic-gate }
39850Sstevel@tonic-gate
39860Sstevel@tonic-gate switch (np6->ipv6NetToMediaType) {
39870Sstevel@tonic-gate case 1:
39880Sstevel@tonic-gate type = "other";
39890Sstevel@tonic-gate break;
39900Sstevel@tonic-gate case 2:
39910Sstevel@tonic-gate type = "dynamic";
39920Sstevel@tonic-gate break;
39930Sstevel@tonic-gate case 3:
39940Sstevel@tonic-gate type = "static";
39950Sstevel@tonic-gate break;
39960Sstevel@tonic-gate case 4:
39970Sstevel@tonic-gate type = "local";
39980Sstevel@tonic-gate break;
39990Sstevel@tonic-gate }
40000Sstevel@tonic-gate (void) printf("%-5s %-17s %-7s %-12s %-27s\n",
40018485SPeter.Memishian@Sun.COM ifindex2str(np6->ipv6NetToMediaIfIndex, ifname),
40020Sstevel@tonic-gate octetstr(&np6->ipv6NetToMediaPhysAddress, 'h',
40030Sstevel@tonic-gate xbuf, sizeof (xbuf)),
40040Sstevel@tonic-gate type,
40050Sstevel@tonic-gate state,
40060Sstevel@tonic-gate pr_addr6(&np6->ipv6NetToMediaNetAddress,
40070Sstevel@tonic-gate abuf, sizeof (abuf)));
40080Sstevel@tonic-gate } /* 'for' loop 2 ends */
40090Sstevel@tonic-gate } /* 'for' loop 1 ends */
40100Sstevel@tonic-gate (void) putchar('\n');
40110Sstevel@tonic-gate (void) fflush(stdout);
40120Sstevel@tonic-gate }
40130Sstevel@tonic-gate
40140Sstevel@tonic-gate /* ------------------------- ire_report (netstat -r) ------------------------ */
40150Sstevel@tonic-gate
40161676Sjpk typedef struct sec_attr_list_s {
40171676Sjpk struct sec_attr_list_s *sal_next;
40181676Sjpk const mib2_ipAttributeEntry_t *sal_attr;
40191676Sjpk } sec_attr_list_t;
40201676Sjpk
40211676Sjpk static boolean_t ire_report_item_v4(const mib2_ipRouteEntry_t *, boolean_t,
40221676Sjpk const sec_attr_list_t *);
40231676Sjpk static boolean_t ire_report_item_v6(const mib2_ipv6RouteEntry_t *, boolean_t,
40241676Sjpk const sec_attr_list_t *);
40251676Sjpk static const char *pr_secattr(const sec_attr_list_t *);
40260Sstevel@tonic-gate
40270Sstevel@tonic-gate static void
ire_report(const mib_item_t * item)40281676Sjpk ire_report(const mib_item_t *item)
40290Sstevel@tonic-gate {
40300Sstevel@tonic-gate int jtemp = 0;
40310Sstevel@tonic-gate boolean_t print_hdr_once_v4 = B_TRUE;
40320Sstevel@tonic-gate boolean_t print_hdr_once_v6 = B_TRUE;
40330Sstevel@tonic-gate mib2_ipRouteEntry_t *rp;
40340Sstevel@tonic-gate mib2_ipv6RouteEntry_t *rp6;
40351676Sjpk sec_attr_list_t **v4_attrs, **v4a;
40361676Sjpk sec_attr_list_t **v6_attrs, **v6a;
40371676Sjpk sec_attr_list_t *all_attrs, *aptr;
40381676Sjpk const mib_item_t *iptr;
40391676Sjpk int ipv4_route_count, ipv6_route_count;
40401676Sjpk int route_attrs_count;
40411676Sjpk
40421676Sjpk /*
40431676Sjpk * Preparation pass: the kernel returns separate entries for IP routing
40441676Sjpk * table entries and security attributes. We loop through the
40451676Sjpk * attributes first and link them into lists.
40461676Sjpk */
40471676Sjpk ipv4_route_count = ipv6_route_count = route_attrs_count = 0;
40481676Sjpk for (iptr = item; iptr != NULL; iptr = iptr->next_item) {
40491676Sjpk if (iptr->group == MIB2_IP6 && iptr->mib_id == MIB2_IP6_ROUTE)
40501676Sjpk ipv6_route_count += iptr->length / ipv6RouteEntrySize;
40511676Sjpk if (iptr->group == MIB2_IP && iptr->mib_id == MIB2_IP_ROUTE)
40521676Sjpk ipv4_route_count += iptr->length / ipRouteEntrySize;
40531676Sjpk if ((iptr->group == MIB2_IP || iptr->group == MIB2_IP6) &&
40541676Sjpk iptr->mib_id == EXPER_IP_RTATTR)
40551676Sjpk route_attrs_count += iptr->length /
40561676Sjpk ipRouteAttributeSize;
40571676Sjpk }
40581676Sjpk v4_attrs = v6_attrs = NULL;
40591676Sjpk all_attrs = NULL;
40601676Sjpk if (family_selected(AF_INET) && ipv4_route_count > 0) {
40611676Sjpk v4_attrs = calloc(ipv4_route_count, sizeof (*v4_attrs));
40621676Sjpk if (v4_attrs == NULL) {
40631676Sjpk perror("ire_report calloc v4_attrs failed");
40641676Sjpk return;
40651676Sjpk }
40661676Sjpk }
40671676Sjpk if (family_selected(AF_INET6) && ipv6_route_count > 0) {
40681676Sjpk v6_attrs = calloc(ipv6_route_count, sizeof (*v6_attrs));
40691676Sjpk if (v6_attrs == NULL) {
40701676Sjpk perror("ire_report calloc v6_attrs failed");
40711676Sjpk goto ire_report_done;
40721676Sjpk }
40731676Sjpk }
40741676Sjpk if (route_attrs_count > 0) {
40751676Sjpk all_attrs = malloc(route_attrs_count * sizeof (*all_attrs));
40761676Sjpk if (all_attrs == NULL) {
40771676Sjpk perror("ire_report malloc all_attrs failed");
40781676Sjpk goto ire_report_done;
40791676Sjpk }
40801676Sjpk }
40811676Sjpk aptr = all_attrs;
40821676Sjpk for (iptr = item; iptr != NULL; iptr = iptr->next_item) {
40831676Sjpk mib2_ipAttributeEntry_t *iae;
40841676Sjpk sec_attr_list_t **alp;
40851676Sjpk
40861676Sjpk if (v4_attrs != NULL && iptr->group == MIB2_IP &&
40871676Sjpk iptr->mib_id == EXPER_IP_RTATTR) {
40881676Sjpk alp = v4_attrs;
40891676Sjpk } else if (v6_attrs != NULL && iptr->group == MIB2_IP6 &&
40901676Sjpk iptr->mib_id == EXPER_IP_RTATTR) {
40911676Sjpk alp = v6_attrs;
40921676Sjpk } else {
40931676Sjpk continue;
40941676Sjpk }
40951676Sjpk for (iae = iptr->valp;
40961676Sjpk (char *)iae < (char *)iptr->valp + iptr->length;
40971676Sjpk /* LINTED: (note 1) */
40981676Sjpk iae = (mib2_ipAttributeEntry_t *)((char *)iae +
40991676Sjpk ipRouteAttributeSize)) {
41001676Sjpk aptr->sal_next = alp[iae->iae_routeidx];
41011676Sjpk aptr->sal_attr = iae;
41021676Sjpk alp[iae->iae_routeidx] = aptr++;
41031676Sjpk }
41041676Sjpk }
41050Sstevel@tonic-gate
41060Sstevel@tonic-gate /* 'for' loop 1: */
41071676Sjpk v4a = v4_attrs;
41081676Sjpk v6a = v6_attrs;
41091676Sjpk for (; item != NULL; item = item->next_item) {
411011042SErik.Nordmark@Sun.COM if (Xflag) {
41110Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp);
41120Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, "
41130Sstevel@tonic-gate "length = %d, valp = 0x%p\n",
41140Sstevel@tonic-gate item->group, item->mib_id,
41150Sstevel@tonic-gate item->length, item->valp);
41160Sstevel@tonic-gate }
41170Sstevel@tonic-gate if (!((item->group == MIB2_IP &&
41180Sstevel@tonic-gate item->mib_id == MIB2_IP_ROUTE) ||
41190Sstevel@tonic-gate (item->group == MIB2_IP6 &&
41200Sstevel@tonic-gate item->mib_id == MIB2_IP6_ROUTE)))
41210Sstevel@tonic-gate continue; /* 'for' loop 1 */
41220Sstevel@tonic-gate
41230Sstevel@tonic-gate if (item->group == MIB2_IP && !family_selected(AF_INET))
41240Sstevel@tonic-gate continue; /* 'for' loop 1 */
41250Sstevel@tonic-gate else if (item->group == MIB2_IP6 && !family_selected(AF_INET6))
41260Sstevel@tonic-gate continue; /* 'for' loop 1 */
41270Sstevel@tonic-gate
412811042SErik.Nordmark@Sun.COM if (Xflag) {
41290Sstevel@tonic-gate if (item->group == MIB2_IP) {
41300Sstevel@tonic-gate (void) printf("%u records for "
41310Sstevel@tonic-gate "ipRouteEntryTable:\n",
41320Sstevel@tonic-gate item->length/sizeof (mib2_ipRouteEntry_t));
41330Sstevel@tonic-gate } else {
41340Sstevel@tonic-gate (void) printf("%u records for "
41350Sstevel@tonic-gate "ipv6RouteEntryTable:\n",
41360Sstevel@tonic-gate item->length/
41370Sstevel@tonic-gate sizeof (mib2_ipv6RouteEntry_t));
41380Sstevel@tonic-gate }
41390Sstevel@tonic-gate }
41400Sstevel@tonic-gate
41410Sstevel@tonic-gate if (item->group == MIB2_IP) {
41420Sstevel@tonic-gate for (rp = (mib2_ipRouteEntry_t *)item->valp;
41430Sstevel@tonic-gate (char *)rp < (char *)item->valp + item->length;
41440Sstevel@tonic-gate /* LINTED: (note 1) */
41450Sstevel@tonic-gate rp = (mib2_ipRouteEntry_t *)((char *)rp +
41460Sstevel@tonic-gate ipRouteEntrySize)) {
41471676Sjpk aptr = v4a == NULL ? NULL : *v4a++;
41480Sstevel@tonic-gate print_hdr_once_v4 = ire_report_item_v4(rp,
41491676Sjpk print_hdr_once_v4, aptr);
41500Sstevel@tonic-gate }
41510Sstevel@tonic-gate } else {
41520Sstevel@tonic-gate for (rp6 = (mib2_ipv6RouteEntry_t *)item->valp;
41530Sstevel@tonic-gate (char *)rp6 < (char *)item->valp + item->length;
41540Sstevel@tonic-gate /* LINTED: (note 1) */
41550Sstevel@tonic-gate rp6 = (mib2_ipv6RouteEntry_t *)((char *)rp6 +
41560Sstevel@tonic-gate ipv6RouteEntrySize)) {
41571676Sjpk aptr = v6a == NULL ? NULL : *v6a++;
41580Sstevel@tonic-gate print_hdr_once_v6 = ire_report_item_v6(rp6,
41591676Sjpk print_hdr_once_v6, aptr);
41600Sstevel@tonic-gate }
41610Sstevel@tonic-gate }
41620Sstevel@tonic-gate } /* 'for' loop 1 ends */
41630Sstevel@tonic-gate (void) fflush(stdout);
41641676Sjpk ire_report_done:
41651676Sjpk if (v4_attrs != NULL)
41661676Sjpk free(v4_attrs);
41671676Sjpk if (v6_attrs != NULL)
41681676Sjpk free(v6_attrs);
41691676Sjpk if (all_attrs != NULL)
41701676Sjpk free(all_attrs);
41710Sstevel@tonic-gate }
41720Sstevel@tonic-gate
41730Sstevel@tonic-gate /*
41740Sstevel@tonic-gate * Match a user-supplied device name. We do this by string because
41750Sstevel@tonic-gate * the MIB2 interface gives us interface name strings rather than
41760Sstevel@tonic-gate * ifIndex numbers. The "none" rule matches only routes with no
41770Sstevel@tonic-gate * interface. The "any" rule matches routes with any non-blank
41780Sstevel@tonic-gate * interface. A base name ("hme0") matches all aliases as well
41790Sstevel@tonic-gate * ("hme0:1").
41800Sstevel@tonic-gate */
41810Sstevel@tonic-gate static boolean_t
dev_name_match(const DeviceName * devnam,const char * ifname)41820Sstevel@tonic-gate dev_name_match(const DeviceName *devnam, const char *ifname)
41830Sstevel@tonic-gate {
41840Sstevel@tonic-gate int iflen;
41850Sstevel@tonic-gate
41860Sstevel@tonic-gate if (ifname == NULL)
41870Sstevel@tonic-gate return (devnam->o_length == 0); /* "none" */
41880Sstevel@tonic-gate if (*ifname == '\0')
41890Sstevel@tonic-gate return (devnam->o_length != 0); /* "any" */
41900Sstevel@tonic-gate iflen = strlen(ifname);
41910Sstevel@tonic-gate /* The check for ':' here supports interface aliases. */
41920Sstevel@tonic-gate if (iflen > devnam->o_length ||
41930Sstevel@tonic-gate (iflen < devnam->o_length && devnam->o_bytes[iflen] != ':'))
41940Sstevel@tonic-gate return (B_FALSE);
41950Sstevel@tonic-gate return (strncmp(ifname, devnam->o_bytes, iflen) == 0);
41960Sstevel@tonic-gate }
41970Sstevel@tonic-gate
41980Sstevel@tonic-gate /*
41990Sstevel@tonic-gate * Match a user-supplied IP address list. The "any" rule matches any
42000Sstevel@tonic-gate * non-zero address. The "none" rule matches only the zero address.
42010Sstevel@tonic-gate * IPv6 addresses supplied by the user are ignored. If the user
42020Sstevel@tonic-gate * supplies a subnet mask, then match routes that are at least that
42030Sstevel@tonic-gate * specific (use the user's mask). If the user supplies only an
42040Sstevel@tonic-gate * address, then select any routes that would match (use the route's
42050Sstevel@tonic-gate * mask).
42060Sstevel@tonic-gate */
42070Sstevel@tonic-gate static boolean_t
v4_addr_match(IpAddress addr,IpAddress mask,const filter_t * fp)42080Sstevel@tonic-gate v4_addr_match(IpAddress addr, IpAddress mask, const filter_t *fp)
42090Sstevel@tonic-gate {
42100Sstevel@tonic-gate char **app;
42110Sstevel@tonic-gate char *aptr;
42120Sstevel@tonic-gate in_addr_t faddr, fmask;
42130Sstevel@tonic-gate
42140Sstevel@tonic-gate if (fp->u.a.f_address == NULL) {
42150Sstevel@tonic-gate if (IN6_IS_ADDR_UNSPECIFIED(&fp->u.a.f_mask))
42160Sstevel@tonic-gate return (addr != INADDR_ANY); /* "any" */
42170Sstevel@tonic-gate else
42180Sstevel@tonic-gate return (addr == INADDR_ANY); /* "none" */
42190Sstevel@tonic-gate }
42200Sstevel@tonic-gate if (!IN6_IS_V4MASK(fp->u.a.f_mask))
42210Sstevel@tonic-gate return (B_FALSE);
42220Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&fp->u.a.f_mask, fmask);
42230Sstevel@tonic-gate if (fmask != IP_HOST_MASK) {
42240Sstevel@tonic-gate if (fmask > mask)
42250Sstevel@tonic-gate return (B_FALSE);
42260Sstevel@tonic-gate mask = fmask;
42270Sstevel@tonic-gate }
42280Sstevel@tonic-gate for (app = fp->u.a.f_address->h_addr_list; (aptr = *app) != NULL; app++)
42290Sstevel@tonic-gate /* LINTED: (note 1) */
42300Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED((in6_addr_t *)aptr)) {
42310Sstevel@tonic-gate /* LINTED: (note 1) */
42320Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR((in6_addr_t *)aptr, faddr);
42330Sstevel@tonic-gate if (((faddr ^ addr) & mask) == 0)
42340Sstevel@tonic-gate return (B_TRUE);
42350Sstevel@tonic-gate }
42360Sstevel@tonic-gate return (B_FALSE);
42370Sstevel@tonic-gate }
42380Sstevel@tonic-gate
42390Sstevel@tonic-gate /*
42400Sstevel@tonic-gate * Run through the filter list for an IPv4 MIB2 route entry. If all
42410Sstevel@tonic-gate * filters of a given type fail to match, then the route is filtered
42420Sstevel@tonic-gate * out (not displayed). If no filter is given or at least one filter
42430Sstevel@tonic-gate * of each type matches, then display the route.
42440Sstevel@tonic-gate */
42450Sstevel@tonic-gate static boolean_t
ire_filter_match_v4(const mib2_ipRouteEntry_t * rp,uint_t flag_b)42461676Sjpk ire_filter_match_v4(const mib2_ipRouteEntry_t *rp, uint_t flag_b)
42470Sstevel@tonic-gate {
42480Sstevel@tonic-gate filter_t *fp;
42490Sstevel@tonic-gate int idx;
42500Sstevel@tonic-gate
42510Sstevel@tonic-gate /* 'for' loop 1: */
42520Sstevel@tonic-gate for (idx = 0; idx < NFILTERKEYS; idx++)
42530Sstevel@tonic-gate if ((fp = filters[idx]) != NULL) {
42540Sstevel@tonic-gate /* 'for' loop 2: */
42550Sstevel@tonic-gate for (; fp != NULL; fp = fp->f_next) {
42560Sstevel@tonic-gate switch (idx) {
42570Sstevel@tonic-gate case FK_AF:
42580Sstevel@tonic-gate if (fp->u.f_family != AF_INET)
42590Sstevel@tonic-gate continue; /* 'for' loop 2 */
42600Sstevel@tonic-gate break;
42610Sstevel@tonic-gate case FK_OUTIF:
42620Sstevel@tonic-gate if (!dev_name_match(&rp->ipRouteIfIndex,
42630Sstevel@tonic-gate fp->u.f_ifname))
42640Sstevel@tonic-gate continue; /* 'for' loop 2 */
42650Sstevel@tonic-gate break;
42660Sstevel@tonic-gate case FK_DST:
42670Sstevel@tonic-gate if (!v4_addr_match(rp->ipRouteDest,
42680Sstevel@tonic-gate rp->ipRouteMask, fp))
42690Sstevel@tonic-gate continue; /* 'for' loop 2 */
42700Sstevel@tonic-gate break;
42710Sstevel@tonic-gate case FK_FLAGS:
42720Sstevel@tonic-gate if ((flag_b & fp->u.f.f_flagset) !=
42730Sstevel@tonic-gate fp->u.f.f_flagset ||
42740Sstevel@tonic-gate (flag_b & fp->u.f.f_flagclear))
42750Sstevel@tonic-gate continue; /* 'for' loop 2 */
42760Sstevel@tonic-gate break;
42770Sstevel@tonic-gate }
42780Sstevel@tonic-gate break;
42790Sstevel@tonic-gate } /* 'for' loop 2 ends */
42800Sstevel@tonic-gate if (fp == NULL)
42810Sstevel@tonic-gate return (B_FALSE);
42820Sstevel@tonic-gate }
42830Sstevel@tonic-gate /* 'for' loop 1 ends */
42840Sstevel@tonic-gate return (B_TRUE);
42850Sstevel@tonic-gate }
42860Sstevel@tonic-gate
42870Sstevel@tonic-gate /*
42880Sstevel@tonic-gate * Given an IPv4 MIB2 route entry, form the list of flags for the
42890Sstevel@tonic-gate * route.
42900Sstevel@tonic-gate */
42910Sstevel@tonic-gate static uint_t
form_v4_route_flags(const mib2_ipRouteEntry_t * rp,char * flags)42921676Sjpk form_v4_route_flags(const mib2_ipRouteEntry_t *rp, char *flags)
42930Sstevel@tonic-gate {
42940Sstevel@tonic-gate uint_t flag_b;
42950Sstevel@tonic-gate
42960Sstevel@tonic-gate flag_b = FLF_U;
42970Sstevel@tonic-gate (void) strcpy(flags, "U");
429811042SErik.Nordmark@Sun.COM /* RTF_INDIRECT wins over RTF_GATEWAY - don't display both */
429911042SErik.Nordmark@Sun.COM if (rp->ipRouteInfo.re_flags & RTF_INDIRECT) {
430011042SErik.Nordmark@Sun.COM (void) strcat(flags, "I");
430111042SErik.Nordmark@Sun.COM flag_b |= FLF_I;
430211042SErik.Nordmark@Sun.COM } else if (rp->ipRouteInfo.re_ire_type & IRE_OFFLINK) {
43030Sstevel@tonic-gate (void) strcat(flags, "G");
43040Sstevel@tonic-gate flag_b |= FLF_G;
43050Sstevel@tonic-gate }
430611042SErik.Nordmark@Sun.COM /* IRE_IF_CLONE wins over RTF_HOST - don't display both */
430711042SErik.Nordmark@Sun.COM if (rp->ipRouteInfo.re_ire_type & IRE_IF_CLONE) {
430811042SErik.Nordmark@Sun.COM (void) strcat(flags, "C");
430911042SErik.Nordmark@Sun.COM flag_b |= FLF_C;
431011042SErik.Nordmark@Sun.COM } else if (rp->ipRouteMask == IP_HOST_MASK) {
43110Sstevel@tonic-gate (void) strcat(flags, "H");
43120Sstevel@tonic-gate flag_b |= FLF_H;
43130Sstevel@tonic-gate }
431411042SErik.Nordmark@Sun.COM if (rp->ipRouteInfo.re_flags & RTF_DYNAMIC) {
43150Sstevel@tonic-gate (void) strcat(flags, "D");
43160Sstevel@tonic-gate flag_b |= FLF_D;
43170Sstevel@tonic-gate }
43180Sstevel@tonic-gate if (rp->ipRouteInfo.re_ire_type == IRE_BROADCAST) { /* Broadcast */
431911042SErik.Nordmark@Sun.COM (void) strcat(flags, "b");
432011042SErik.Nordmark@Sun.COM flag_b |= FLF_b;
43210Sstevel@tonic-gate }
43220Sstevel@tonic-gate if (rp->ipRouteInfo.re_ire_type == IRE_LOCAL) { /* Local */
43230Sstevel@tonic-gate (void) strcat(flags, "L");
43240Sstevel@tonic-gate flag_b |= FLF_L;
43250Sstevel@tonic-gate }
43260Sstevel@tonic-gate if (rp->ipRouteInfo.re_flags & RTF_MULTIRT) {
43270Sstevel@tonic-gate (void) strcat(flags, "M"); /* Multiroute */
43280Sstevel@tonic-gate flag_b |= FLF_M;
43290Sstevel@tonic-gate }
43300Sstevel@tonic-gate if (rp->ipRouteInfo.re_flags & RTF_SETSRC) {
43310Sstevel@tonic-gate (void) strcat(flags, "S"); /* Setsrc */
43320Sstevel@tonic-gate flag_b |= FLF_S;
43330Sstevel@tonic-gate }
433411042SErik.Nordmark@Sun.COM if (rp->ipRouteInfo.re_flags & RTF_REJECT) {
433511042SErik.Nordmark@Sun.COM (void) strcat(flags, "R");
433611042SErik.Nordmark@Sun.COM flag_b |= FLF_R;
433711042SErik.Nordmark@Sun.COM }
433811042SErik.Nordmark@Sun.COM if (rp->ipRouteInfo.re_flags & RTF_BLACKHOLE) {
433911042SErik.Nordmark@Sun.COM (void) strcat(flags, "B");
434011042SErik.Nordmark@Sun.COM flag_b |= FLF_B;
434111042SErik.Nordmark@Sun.COM }
434212748SSowmini.Varadhan@oracle.COM if (rp->ipRouteInfo.re_flags & RTF_ZONE) {
434312748SSowmini.Varadhan@oracle.COM (void) strcat(flags, "Z");
434412748SSowmini.Varadhan@oracle.COM flag_b |= FLF_Z;
434512748SSowmini.Varadhan@oracle.COM }
43460Sstevel@tonic-gate return (flag_b);
43470Sstevel@tonic-gate }
43480Sstevel@tonic-gate
43491676Sjpk static const char ire_hdr_v4[] =
43501676Sjpk "\n%s Table: IPv4\n";
43511676Sjpk static const char ire_hdr_v4_compat[] =
43521676Sjpk "\n%s Table:\n";
43531676Sjpk static const char ire_hdr_v4_verbose[] =
435411042SErik.Nordmark@Sun.COM " Destination Mask Gateway Device "
435511042SErik.Nordmark@Sun.COM " MTU Ref Flg Out In/Fwd %s\n"
435611042SErik.Nordmark@Sun.COM "-------------------- --------------- -------------------- ------ "
43571676Sjpk "----- --- --- ----- ------ %s\n";
43581676Sjpk
43591676Sjpk static const char ire_hdr_v4_normal[] =
43603129Sja97890 " Destination Gateway Flags Ref Use Interface"
43613129Sja97890 " %s\n-------------------- -------------------- ----- ----- ---------- "
43623129Sja97890 "--------- %s\n";
43631676Sjpk
43640Sstevel@tonic-gate static boolean_t
ire_report_item_v4(const mib2_ipRouteEntry_t * rp,boolean_t first,const sec_attr_list_t * attrs)43651676Sjpk ire_report_item_v4(const mib2_ipRouteEntry_t *rp, boolean_t first,
43661676Sjpk const sec_attr_list_t *attrs)
43670Sstevel@tonic-gate {
43680Sstevel@tonic-gate char dstbuf[MAXHOSTNAMELEN + 1];
43690Sstevel@tonic-gate char maskbuf[MAXHOSTNAMELEN + 1];
43700Sstevel@tonic-gate char gwbuf[MAXHOSTNAMELEN + 1];
43710Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1];
43720Sstevel@tonic-gate char flags[10]; /* RTF_ flags */
43730Sstevel@tonic-gate uint_t flag_b;
43740Sstevel@tonic-gate
437511042SErik.Nordmark@Sun.COM if (!(Aflag || (rp->ipRouteInfo.re_ire_type != IRE_IF_CLONE &&
43760Sstevel@tonic-gate rp->ipRouteInfo.re_ire_type != IRE_BROADCAST &&
437711042SErik.Nordmark@Sun.COM rp->ipRouteInfo.re_ire_type != IRE_MULTICAST &&
437811042SErik.Nordmark@Sun.COM rp->ipRouteInfo.re_ire_type != IRE_NOROUTE &&
43790Sstevel@tonic-gate rp->ipRouteInfo.re_ire_type != IRE_LOCAL))) {
43800Sstevel@tonic-gate return (first);
43810Sstevel@tonic-gate }
43820Sstevel@tonic-gate
43830Sstevel@tonic-gate flag_b = form_v4_route_flags(rp, flags);
43840Sstevel@tonic-gate
43850Sstevel@tonic-gate if (!ire_filter_match_v4(rp, flag_b))
43860Sstevel@tonic-gate return (first);
43870Sstevel@tonic-gate
43880Sstevel@tonic-gate if (first) {
43891676Sjpk (void) printf(v4compat ? ire_hdr_v4_compat : ire_hdr_v4,
43901676Sjpk Vflag ? "IRE" : "Routing");
43911676Sjpk (void) printf(Vflag ? ire_hdr_v4_verbose : ire_hdr_v4_normal,
43921676Sjpk RSECflag ? " Gateway security attributes " : "",
43931676Sjpk RSECflag ? "-------------------------------" : "");
43940Sstevel@tonic-gate first = B_FALSE;
43950Sstevel@tonic-gate }
43960Sstevel@tonic-gate
43970Sstevel@tonic-gate if (flag_b & FLF_H) {
43980Sstevel@tonic-gate (void) pr_addr(rp->ipRouteDest, dstbuf, sizeof (dstbuf));
43990Sstevel@tonic-gate } else {
44000Sstevel@tonic-gate (void) pr_net(rp->ipRouteDest, rp->ipRouteMask,
44010Sstevel@tonic-gate dstbuf, sizeof (dstbuf));
44020Sstevel@tonic-gate }
44030Sstevel@tonic-gate if (Vflag) {
440411042SErik.Nordmark@Sun.COM (void) printf("%-20s %-15s %-20s %-6s %5u %3u "
44053129Sja97890 "%-4s%6u %6u %s\n",
44060Sstevel@tonic-gate dstbuf,
44070Sstevel@tonic-gate pr_mask(rp->ipRouteMask, maskbuf, sizeof (maskbuf)),
44080Sstevel@tonic-gate pr_addrnz(rp->ipRouteNextHop, gwbuf, sizeof (gwbuf)),
44090Sstevel@tonic-gate octetstr(&rp->ipRouteIfIndex, 'a', ifname, sizeof (ifname)),
44100Sstevel@tonic-gate rp->ipRouteInfo.re_max_frag,
44110Sstevel@tonic-gate rp->ipRouteInfo.re_ref,
44120Sstevel@tonic-gate flags,
44130Sstevel@tonic-gate rp->ipRouteInfo.re_obpkt,
44141676Sjpk rp->ipRouteInfo.re_ibpkt,
44151676Sjpk pr_secattr(attrs));
44160Sstevel@tonic-gate } else {
44173129Sja97890 (void) printf("%-20s %-20s %-5s %4u %10u %-9s %s\n",
44180Sstevel@tonic-gate dstbuf,
44190Sstevel@tonic-gate pr_addrnz(rp->ipRouteNextHop, gwbuf, sizeof (gwbuf)),
44200Sstevel@tonic-gate flags,
44210Sstevel@tonic-gate rp->ipRouteInfo.re_ref,
44220Sstevel@tonic-gate rp->ipRouteInfo.re_obpkt + rp->ipRouteInfo.re_ibpkt,
44230Sstevel@tonic-gate octetstr(&rp->ipRouteIfIndex, 'a',
44241676Sjpk ifname, sizeof (ifname)),
44251676Sjpk pr_secattr(attrs));
44260Sstevel@tonic-gate }
44270Sstevel@tonic-gate return (first);
44280Sstevel@tonic-gate }
44290Sstevel@tonic-gate
44300Sstevel@tonic-gate /*
44310Sstevel@tonic-gate * Match a user-supplied IP address list against an IPv6 route entry.
44320Sstevel@tonic-gate * If the user specified "any," then any non-zero address matches. If
44330Sstevel@tonic-gate * the user specified "none," then only the zero address matches. If
44340Sstevel@tonic-gate * the user specified a subnet mask length, then use that in matching
44350Sstevel@tonic-gate * routes (select routes that are at least as specific). If the user
44360Sstevel@tonic-gate * specified only an address, then use the route's mask (select routes
44370Sstevel@tonic-gate * that would match that address). IPv4 addresses are ignored.
44380Sstevel@tonic-gate */
44390Sstevel@tonic-gate static boolean_t
v6_addr_match(const Ip6Address * addr,int masklen,const filter_t * fp)44400Sstevel@tonic-gate v6_addr_match(const Ip6Address *addr, int masklen, const filter_t *fp)
44410Sstevel@tonic-gate {
44420Sstevel@tonic-gate const uint8_t *ucp;
44430Sstevel@tonic-gate int fmasklen;
44440Sstevel@tonic-gate int i;
44450Sstevel@tonic-gate char **app;
44469754SShrikrishna.Khare@Sun.COM const uint8_t *aptr;
44470Sstevel@tonic-gate
44480Sstevel@tonic-gate if (fp->u.a.f_address == NULL) {
44490Sstevel@tonic-gate if (IN6_IS_ADDR_UNSPECIFIED(&fp->u.a.f_mask)) /* any */
44500Sstevel@tonic-gate return (!IN6_IS_ADDR_UNSPECIFIED(addr));
44510Sstevel@tonic-gate return (IN6_IS_ADDR_UNSPECIFIED(addr)); /* "none" */
44520Sstevel@tonic-gate }
44530Sstevel@tonic-gate fmasklen = 0;
44540Sstevel@tonic-gate /* 'for' loop 1a: */
44550Sstevel@tonic-gate for (ucp = fp->u.a.f_mask.s6_addr;
44560Sstevel@tonic-gate ucp < fp->u.a.f_mask.s6_addr + sizeof (fp->u.a.f_mask.s6_addr);
44570Sstevel@tonic-gate ucp++) {
44580Sstevel@tonic-gate if (*ucp != 0xff) {
44590Sstevel@tonic-gate if (*ucp != 0)
44600Sstevel@tonic-gate fmasklen += 9 - ffs(*ucp);
44610Sstevel@tonic-gate break; /* 'for' loop 1a */
44620Sstevel@tonic-gate }
44630Sstevel@tonic-gate fmasklen += 8;
44640Sstevel@tonic-gate } /* 'for' loop 1a ends */
44650Sstevel@tonic-gate if (fmasklen != IPV6_ABITS) {
44660Sstevel@tonic-gate if (fmasklen > masklen)
44670Sstevel@tonic-gate return (B_FALSE);
44680Sstevel@tonic-gate masklen = fmasklen;
44690Sstevel@tonic-gate }
44700Sstevel@tonic-gate /* 'for' loop 1b: */
44719754SShrikrishna.Khare@Sun.COM for (app = fp->u.a.f_address->h_addr_list;
44729754SShrikrishna.Khare@Sun.COM (aptr = (uint8_t *)*app) != NULL; app++) {
44730Sstevel@tonic-gate /* LINTED: (note 1) */
44740Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED((in6_addr_t *)aptr))
44750Sstevel@tonic-gate continue; /* 'for' loop 1b */
44760Sstevel@tonic-gate ucp = addr->s6_addr;
44770Sstevel@tonic-gate for (i = masklen; i >= 8; i -= 8)
44780Sstevel@tonic-gate if (*ucp++ != *aptr++)
44790Sstevel@tonic-gate break; /* 'for' loop 1b */
44800Sstevel@tonic-gate if (i == 0 ||
44810Sstevel@tonic-gate (i < 8 && ((*ucp ^ *aptr) & ~(0xff >> i)) == 0))
44820Sstevel@tonic-gate return (B_TRUE);
44830Sstevel@tonic-gate } /* 'for' loop 1b ends */
44840Sstevel@tonic-gate return (B_FALSE);
44850Sstevel@tonic-gate }
44860Sstevel@tonic-gate
44870Sstevel@tonic-gate /*
44880Sstevel@tonic-gate * Run through the filter list for an IPv6 MIB2 IRE. For a given
44890Sstevel@tonic-gate * type, if there's at least one filter and all filters of that type
44900Sstevel@tonic-gate * fail to match, then the route doesn't match and isn't displayed.
44910Sstevel@tonic-gate * If at least one matches, or none are specified, for each of the
44920Sstevel@tonic-gate * types, then the route is selected and displayed.
44930Sstevel@tonic-gate */
44940Sstevel@tonic-gate static boolean_t
ire_filter_match_v6(const mib2_ipv6RouteEntry_t * rp6,uint_t flag_b)44951676Sjpk ire_filter_match_v6(const mib2_ipv6RouteEntry_t *rp6, uint_t flag_b)
44960Sstevel@tonic-gate {
44970Sstevel@tonic-gate filter_t *fp;
44980Sstevel@tonic-gate int idx;
44990Sstevel@tonic-gate
45000Sstevel@tonic-gate /* 'for' loop 1: */
45010Sstevel@tonic-gate for (idx = 0; idx < NFILTERKEYS; idx++)
45020Sstevel@tonic-gate if ((fp = filters[idx]) != NULL) {
45030Sstevel@tonic-gate /* 'for' loop 2: */
45040Sstevel@tonic-gate for (; fp != NULL; fp = fp->f_next) {
45050Sstevel@tonic-gate switch (idx) {
45060Sstevel@tonic-gate case FK_AF:
45070Sstevel@tonic-gate if (fp->u.f_family != AF_INET6)
45080Sstevel@tonic-gate /* 'for' loop 2 */
45090Sstevel@tonic-gate continue;
45100Sstevel@tonic-gate break;
45110Sstevel@tonic-gate case FK_OUTIF:
45120Sstevel@tonic-gate if (!dev_name_match(&rp6->
45130Sstevel@tonic-gate ipv6RouteIfIndex, fp->u.f_ifname))
45140Sstevel@tonic-gate /* 'for' loop 2 */
45150Sstevel@tonic-gate continue;
45160Sstevel@tonic-gate break;
45170Sstevel@tonic-gate case FK_DST:
45180Sstevel@tonic-gate if (!v6_addr_match(&rp6->ipv6RouteDest,
45190Sstevel@tonic-gate rp6->ipv6RoutePfxLength, fp))
45200Sstevel@tonic-gate /* 'for' loop 2 */
45210Sstevel@tonic-gate continue;
45220Sstevel@tonic-gate break;
45230Sstevel@tonic-gate case FK_FLAGS:
45240Sstevel@tonic-gate if ((flag_b & fp->u.f.f_flagset) !=
45250Sstevel@tonic-gate fp->u.f.f_flagset ||
45260Sstevel@tonic-gate (flag_b & fp->u.f.f_flagclear))
45270Sstevel@tonic-gate /* 'for' loop 2 */
45280Sstevel@tonic-gate continue;
45290Sstevel@tonic-gate break;
45300Sstevel@tonic-gate }
45310Sstevel@tonic-gate break;
45320Sstevel@tonic-gate } /* 'for' loop 2 ends */
45330Sstevel@tonic-gate if (fp == NULL)
45340Sstevel@tonic-gate return (B_FALSE);
45350Sstevel@tonic-gate }
45360Sstevel@tonic-gate /* 'for' loop 1 ends */
45370Sstevel@tonic-gate return (B_TRUE);
45380Sstevel@tonic-gate }
45390Sstevel@tonic-gate
454011042SErik.Nordmark@Sun.COM /*
454111042SErik.Nordmark@Sun.COM * Given an IPv6 MIB2 route entry, form the list of flags for the
454211042SErik.Nordmark@Sun.COM * route.
454311042SErik.Nordmark@Sun.COM */
454411042SErik.Nordmark@Sun.COM static uint_t
form_v6_route_flags(const mib2_ipv6RouteEntry_t * rp6,char * flags)454511042SErik.Nordmark@Sun.COM form_v6_route_flags(const mib2_ipv6RouteEntry_t *rp6, char *flags)
454611042SErik.Nordmark@Sun.COM {
454711042SErik.Nordmark@Sun.COM uint_t flag_b;
454811042SErik.Nordmark@Sun.COM
454911042SErik.Nordmark@Sun.COM flag_b = FLF_U;
455011042SErik.Nordmark@Sun.COM (void) strcpy(flags, "U");
455111042SErik.Nordmark@Sun.COM /* RTF_INDIRECT wins over RTF_GATEWAY - don't display both */
455211042SErik.Nordmark@Sun.COM if (rp6->ipv6RouteInfo.re_flags & RTF_INDIRECT) {
455311042SErik.Nordmark@Sun.COM (void) strcat(flags, "I");
455411042SErik.Nordmark@Sun.COM flag_b |= FLF_I;
455511042SErik.Nordmark@Sun.COM } else if (rp6->ipv6RouteInfo.re_ire_type & IRE_OFFLINK) {
455611042SErik.Nordmark@Sun.COM (void) strcat(flags, "G");
455711042SErik.Nordmark@Sun.COM flag_b |= FLF_G;
455811042SErik.Nordmark@Sun.COM }
455911042SErik.Nordmark@Sun.COM
456011042SErik.Nordmark@Sun.COM /* IRE_IF_CLONE wins over RTF_HOST - don't display both */
456111042SErik.Nordmark@Sun.COM if (rp6->ipv6RouteInfo.re_ire_type & IRE_IF_CLONE) {
456211042SErik.Nordmark@Sun.COM (void) strcat(flags, "C");
456311042SErik.Nordmark@Sun.COM flag_b |= FLF_C;
456411042SErik.Nordmark@Sun.COM } else if (rp6->ipv6RoutePfxLength == IPV6_ABITS) {
456511042SErik.Nordmark@Sun.COM (void) strcat(flags, "H");
456611042SErik.Nordmark@Sun.COM flag_b |= FLF_H;
456711042SErik.Nordmark@Sun.COM }
456811042SErik.Nordmark@Sun.COM
456911042SErik.Nordmark@Sun.COM if (rp6->ipv6RouteInfo.re_flags & RTF_DYNAMIC) {
457011042SErik.Nordmark@Sun.COM (void) strcat(flags, "D");
457111042SErik.Nordmark@Sun.COM flag_b |= FLF_D;
457211042SErik.Nordmark@Sun.COM }
457311042SErik.Nordmark@Sun.COM if (rp6->ipv6RouteInfo.re_ire_type == IRE_LOCAL) { /* Local */
457411042SErik.Nordmark@Sun.COM (void) strcat(flags, "L");
457511042SErik.Nordmark@Sun.COM flag_b |= FLF_L;
457611042SErik.Nordmark@Sun.COM }
457711042SErik.Nordmark@Sun.COM if (rp6->ipv6RouteInfo.re_flags & RTF_MULTIRT) {
457811042SErik.Nordmark@Sun.COM (void) strcat(flags, "M"); /* Multiroute */
457911042SErik.Nordmark@Sun.COM flag_b |= FLF_M;
458011042SErik.Nordmark@Sun.COM }
458111042SErik.Nordmark@Sun.COM if (rp6->ipv6RouteInfo.re_flags & RTF_SETSRC) {
458211042SErik.Nordmark@Sun.COM (void) strcat(flags, "S"); /* Setsrc */
458311042SErik.Nordmark@Sun.COM flag_b |= FLF_S;
458411042SErik.Nordmark@Sun.COM }
458511042SErik.Nordmark@Sun.COM if (rp6->ipv6RouteInfo.re_flags & RTF_REJECT) {
458611042SErik.Nordmark@Sun.COM (void) strcat(flags, "R");
458711042SErik.Nordmark@Sun.COM flag_b |= FLF_R;
458811042SErik.Nordmark@Sun.COM }
458911042SErik.Nordmark@Sun.COM if (rp6->ipv6RouteInfo.re_flags & RTF_BLACKHOLE) {
459011042SErik.Nordmark@Sun.COM (void) strcat(flags, "B");
459111042SErik.Nordmark@Sun.COM flag_b |= FLF_B;
459211042SErik.Nordmark@Sun.COM }
459312748SSowmini.Varadhan@oracle.COM if (rp6->ipv6RouteInfo.re_flags & RTF_ZONE) {
459412748SSowmini.Varadhan@oracle.COM (void) strcat(flags, "Z");
459512748SSowmini.Varadhan@oracle.COM flag_b |= FLF_Z;
459612748SSowmini.Varadhan@oracle.COM }
459711042SErik.Nordmark@Sun.COM return (flag_b);
459811042SErik.Nordmark@Sun.COM }
459911042SErik.Nordmark@Sun.COM
46001676Sjpk static const char ire_hdr_v6[] =
46011676Sjpk "\n%s Table: IPv6\n";
46021676Sjpk static const char ire_hdr_v6_verbose[] =
460311042SErik.Nordmark@Sun.COM " Destination/Mask Gateway If MTU "
46041676Sjpk "Ref Flags Out In/Fwd %s\n"
460511042SErik.Nordmark@Sun.COM "--------------------------- --------------------------- ----- ----- "
46061676Sjpk "--- ----- ------ ------ %s\n";
46071676Sjpk static const char ire_hdr_v6_normal[] =
46081676Sjpk " Destination/Mask Gateway Flags Ref Use "
46093129Sja97890 " If %s\n"
46103129Sja97890 "--------------------------- --------------------------- ----- --- ------- "
46111676Sjpk "----- %s\n";
46121676Sjpk
46130Sstevel@tonic-gate static boolean_t
ire_report_item_v6(const mib2_ipv6RouteEntry_t * rp6,boolean_t first,const sec_attr_list_t * attrs)46141676Sjpk ire_report_item_v6(const mib2_ipv6RouteEntry_t *rp6, boolean_t first,
46151676Sjpk const sec_attr_list_t *attrs)
46160Sstevel@tonic-gate {
46170Sstevel@tonic-gate char dstbuf[MAXHOSTNAMELEN + 1];
46180Sstevel@tonic-gate char gwbuf[MAXHOSTNAMELEN + 1];
46190Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1];
46200Sstevel@tonic-gate char flags[10]; /* RTF_ flags */
46210Sstevel@tonic-gate uint_t flag_b;
46220Sstevel@tonic-gate
462311042SErik.Nordmark@Sun.COM if (!(Aflag || (rp6->ipv6RouteInfo.re_ire_type != IRE_IF_CLONE &&
462411042SErik.Nordmark@Sun.COM rp6->ipv6RouteInfo.re_ire_type != IRE_MULTICAST &&
462511042SErik.Nordmark@Sun.COM rp6->ipv6RouteInfo.re_ire_type != IRE_NOROUTE &&
46260Sstevel@tonic-gate rp6->ipv6RouteInfo.re_ire_type != IRE_LOCAL))) {
46270Sstevel@tonic-gate return (first);
46280Sstevel@tonic-gate }
46290Sstevel@tonic-gate
463011042SErik.Nordmark@Sun.COM flag_b = form_v6_route_flags(rp6, flags);
46310Sstevel@tonic-gate
46320Sstevel@tonic-gate if (!ire_filter_match_v6(rp6, flag_b))
46330Sstevel@tonic-gate return (first);
46340Sstevel@tonic-gate
46350Sstevel@tonic-gate if (first) {
46361676Sjpk (void) printf(ire_hdr_v6, Vflag ? "IRE" : "Routing");
46371676Sjpk (void) printf(Vflag ? ire_hdr_v6_verbose : ire_hdr_v6_normal,
46381676Sjpk RSECflag ? " Gateway security attributes " : "",
46391676Sjpk RSECflag ? "-------------------------------" : "");
46400Sstevel@tonic-gate first = B_FALSE;
46410Sstevel@tonic-gate }
46420Sstevel@tonic-gate
46430Sstevel@tonic-gate if (Vflag) {
464411042SErik.Nordmark@Sun.COM (void) printf("%-27s %-27s %-5s %5u %3u "
46451676Sjpk "%-5s %6u %6u %s\n",
46460Sstevel@tonic-gate pr_prefix6(&rp6->ipv6RouteDest,
46478485SPeter.Memishian@Sun.COM rp6->ipv6RoutePfxLength, dstbuf, sizeof (dstbuf)),
46480Sstevel@tonic-gate IN6_IS_ADDR_UNSPECIFIED(&rp6->ipv6RouteNextHop) ?
46490Sstevel@tonic-gate " --" :
46500Sstevel@tonic-gate pr_addr6(&rp6->ipv6RouteNextHop, gwbuf, sizeof (gwbuf)),
46510Sstevel@tonic-gate octetstr(&rp6->ipv6RouteIfIndex, 'a',
46520Sstevel@tonic-gate ifname, sizeof (ifname)),
46530Sstevel@tonic-gate rp6->ipv6RouteInfo.re_max_frag,
46540Sstevel@tonic-gate rp6->ipv6RouteInfo.re_ref,
46550Sstevel@tonic-gate flags,
46560Sstevel@tonic-gate rp6->ipv6RouteInfo.re_obpkt,
46571676Sjpk rp6->ipv6RouteInfo.re_ibpkt,
46581676Sjpk pr_secattr(attrs));
46590Sstevel@tonic-gate } else {
46603129Sja97890 (void) printf("%-27s %-27s %-5s %3u %7u %-5s %s\n",
46610Sstevel@tonic-gate pr_prefix6(&rp6->ipv6RouteDest,
46628485SPeter.Memishian@Sun.COM rp6->ipv6RoutePfxLength, dstbuf, sizeof (dstbuf)),
46630Sstevel@tonic-gate IN6_IS_ADDR_UNSPECIFIED(&rp6->ipv6RouteNextHop) ?
46640Sstevel@tonic-gate " --" :
46650Sstevel@tonic-gate pr_addr6(&rp6->ipv6RouteNextHop, gwbuf, sizeof (gwbuf)),
46660Sstevel@tonic-gate flags,
46670Sstevel@tonic-gate rp6->ipv6RouteInfo.re_ref,
46680Sstevel@tonic-gate rp6->ipv6RouteInfo.re_obpkt + rp6->ipv6RouteInfo.re_ibpkt,
46690Sstevel@tonic-gate octetstr(&rp6->ipv6RouteIfIndex, 'a',
46701676Sjpk ifname, sizeof (ifname)),
46711676Sjpk pr_secattr(attrs));
46720Sstevel@tonic-gate }
46730Sstevel@tonic-gate return (first);
46740Sstevel@tonic-gate }
46750Sstevel@tonic-gate
46761676Sjpk /*
46771676Sjpk * Common attribute-gathering routine for all transports.
46781676Sjpk */
46791676Sjpk static mib2_transportMLPEntry_t **
gather_attrs(const mib_item_t * item,int group,int mib_id,int esize)46801676Sjpk gather_attrs(const mib_item_t *item, int group, int mib_id, int esize)
46811676Sjpk {
46821676Sjpk int transport_count = 0;
46831676Sjpk const mib_item_t *iptr;
46841676Sjpk mib2_transportMLPEntry_t **attrs, *tme;
46851676Sjpk
46861676Sjpk for (iptr = item; iptr != NULL; iptr = iptr->next_item) {
46871676Sjpk if (iptr->group == group && iptr->mib_id == mib_id)
46881676Sjpk transport_count += iptr->length / esize;
46891676Sjpk }
46901676Sjpk if (transport_count <= 0)
46911676Sjpk return (NULL);
46921676Sjpk attrs = calloc(transport_count, sizeof (*attrs));
46931676Sjpk if (attrs == NULL) {
46941676Sjpk perror("gather_attrs calloc failed");
46951676Sjpk return (NULL);
46961676Sjpk }
46971676Sjpk for (iptr = item; iptr != NULL; iptr = iptr->next_item) {
46981676Sjpk if (iptr->group == group && iptr->mib_id == EXPER_XPORT_MLP) {
46991676Sjpk for (tme = iptr->valp;
47001676Sjpk (char *)tme < (char *)iptr->valp + iptr->length;
47011676Sjpk /* LINTED: (note 1) */
47021676Sjpk tme = (mib2_transportMLPEntry_t *)((char *)tme +
47031676Sjpk transportMLPSize)) {
47041676Sjpk attrs[tme->tme_connidx] = tme;
47051676Sjpk }
47061676Sjpk }
47071676Sjpk }
47081676Sjpk return (attrs);
47091676Sjpk }
47101676Sjpk
47111676Sjpk static void
print_transport_label(const mib2_transportMLPEntry_t * attr)47121676Sjpk print_transport_label(const mib2_transportMLPEntry_t *attr)
47131676Sjpk {
47149710SKen.Powell@Sun.COM if (!RSECflag || attr == NULL ||
47159710SKen.Powell@Sun.COM !(attr->tme_flags & MIB2_TMEF_IS_LABELED))
47161676Sjpk return;
47171676Sjpk
471811561SRic.Aleshire@Sun.COM if (bisinvalid(&attr->tme_label)) {
47191676Sjpk (void) printf(" INVALID\n");
472011561SRic.Aleshire@Sun.COM } else if (!blequal(&attr->tme_label, zone_security_label)) {
472111561SRic.Aleshire@Sun.COM char *sl_str;
472211561SRic.Aleshire@Sun.COM
472311561SRic.Aleshire@Sun.COM sl_str = sl_to_str(&attr->tme_label);
472411561SRic.Aleshire@Sun.COM (void) printf(" %s\n", sl_str);
472511561SRic.Aleshire@Sun.COM free(sl_str);
472611561SRic.Aleshire@Sun.COM }
47271676Sjpk }
47281676Sjpk
47290Sstevel@tonic-gate /* ------------------------------ TCP_REPORT------------------------------- */
47300Sstevel@tonic-gate
47310Sstevel@tonic-gate static const char tcp_hdr_v4[] =
47320Sstevel@tonic-gate "\nTCP: IPv4\n";
47330Sstevel@tonic-gate static const char tcp_hdr_v4_compat[] =
47340Sstevel@tonic-gate "\nTCP\n";
47350Sstevel@tonic-gate static const char tcp_hdr_v4_verbose[] =
47360Sstevel@tonic-gate "Local/Remote Address Swind Snext Suna Rwind Rnext Rack "
47371676Sjpk " Rto Mss State\n"
47380Sstevel@tonic-gate "-------------------- ----- -------- -------- ----- -------- -------- "
47391676Sjpk "----- ----- -----------\n";
47400Sstevel@tonic-gate static const char tcp_hdr_v4_normal[] =
47411676Sjpk " Local Address Remote Address Swind Send-Q Rwind Recv-Q "
47421676Sjpk " State\n"
47431676Sjpk "-------------------- -------------------- ----- ------ ----- ------ "
47441676Sjpk "-----------\n";
47450Sstevel@tonic-gate
47460Sstevel@tonic-gate static const char tcp_hdr_v6[] =
47470Sstevel@tonic-gate "\nTCP: IPv6\n";
47480Sstevel@tonic-gate static const char tcp_hdr_v6_verbose[] =
47490Sstevel@tonic-gate "Local/Remote Address Swind Snext Suna Rwind Rnext "
47501676Sjpk " Rack Rto Mss State If\n"
47510Sstevel@tonic-gate "--------------------------------- ----- -------- -------- ----- -------- "
47520Sstevel@tonic-gate "-------- ----- ----- ----------- -----\n";
47530Sstevel@tonic-gate static const char tcp_hdr_v6_normal[] =
47540Sstevel@tonic-gate " Local Address Remote Address "
47551676Sjpk "Swind Send-Q Rwind Recv-Q State If\n"
47560Sstevel@tonic-gate "--------------------------------- --------------------------------- "
47570Sstevel@tonic-gate "----- ------ ----- ------ ----------- -----\n";
47580Sstevel@tonic-gate
47591676Sjpk static boolean_t tcp_report_item_v4(const mib2_tcpConnEntry_t *,
47601676Sjpk boolean_t first, const mib2_transportMLPEntry_t *);
47611676Sjpk static boolean_t tcp_report_item_v6(const mib2_tcp6ConnEntry_t *,
47621676Sjpk boolean_t first, const mib2_transportMLPEntry_t *);
47630Sstevel@tonic-gate
47640Sstevel@tonic-gate static void
tcp_report(const mib_item_t * item)47651676Sjpk tcp_report(const mib_item_t *item)
47660Sstevel@tonic-gate {
47670Sstevel@tonic-gate int jtemp = 0;
47680Sstevel@tonic-gate boolean_t print_hdr_once_v4 = B_TRUE;
47690Sstevel@tonic-gate boolean_t print_hdr_once_v6 = B_TRUE;
47700Sstevel@tonic-gate mib2_tcpConnEntry_t *tp;
47710Sstevel@tonic-gate mib2_tcp6ConnEntry_t *tp6;
47721676Sjpk mib2_transportMLPEntry_t **v4_attrs, **v6_attrs;
47731676Sjpk mib2_transportMLPEntry_t **v4a, **v6a;
47741676Sjpk mib2_transportMLPEntry_t *aptr;
47750Sstevel@tonic-gate
47760Sstevel@tonic-gate if (!protocol_selected(IPPROTO_TCP))
47770Sstevel@tonic-gate return;
47780Sstevel@tonic-gate
47791676Sjpk /*
47801676Sjpk * Preparation pass: the kernel returns separate entries for TCP
47811676Sjpk * connection table entries and Multilevel Port attributes. We loop
47821676Sjpk * through the attributes first and set up an array for each address
47831676Sjpk * family.
47841676Sjpk */
47851676Sjpk v4_attrs = family_selected(AF_INET) && RSECflag ?
47861676Sjpk gather_attrs(item, MIB2_TCP, MIB2_TCP_CONN, tcpConnEntrySize) :
47871676Sjpk NULL;
47881676Sjpk v6_attrs = family_selected(AF_INET6) && RSECflag ?
47891676Sjpk gather_attrs(item, MIB2_TCP6, MIB2_TCP6_CONN, tcp6ConnEntrySize) :
47901676Sjpk NULL;
47911676Sjpk
47920Sstevel@tonic-gate /* 'for' loop 1: */
47931676Sjpk v4a = v4_attrs;
47941676Sjpk v6a = v6_attrs;
47951676Sjpk for (; item != NULL; item = item->next_item) {
479611042SErik.Nordmark@Sun.COM if (Xflag) {
47970Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp);
47980Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, "
47990Sstevel@tonic-gate "length = %d, valp = 0x%p\n",
48000Sstevel@tonic-gate item->group, item->mib_id,
48010Sstevel@tonic-gate item->length, item->valp);
48020Sstevel@tonic-gate }
48030Sstevel@tonic-gate
48040Sstevel@tonic-gate if (!((item->group == MIB2_TCP &&
48050Sstevel@tonic-gate item->mib_id == MIB2_TCP_CONN) ||
48060Sstevel@tonic-gate (item->group == MIB2_TCP6 &&
48070Sstevel@tonic-gate item->mib_id == MIB2_TCP6_CONN)))
48080Sstevel@tonic-gate continue; /* 'for' loop 1 */
48090Sstevel@tonic-gate
48100Sstevel@tonic-gate if (item->group == MIB2_TCP && !family_selected(AF_INET))
48110Sstevel@tonic-gate continue; /* 'for' loop 1 */
48120Sstevel@tonic-gate else if (item->group == MIB2_TCP6 && !family_selected(AF_INET6))
48130Sstevel@tonic-gate continue; /* 'for' loop 1 */
48140Sstevel@tonic-gate
48150Sstevel@tonic-gate if (item->group == MIB2_TCP) {
48160Sstevel@tonic-gate for (tp = (mib2_tcpConnEntry_t *)item->valp;
48170Sstevel@tonic-gate (char *)tp < (char *)item->valp + item->length;
48180Sstevel@tonic-gate /* LINTED: (note 1) */
48190Sstevel@tonic-gate tp = (mib2_tcpConnEntry_t *)((char *)tp +
48200Sstevel@tonic-gate tcpConnEntrySize)) {
48211676Sjpk aptr = v4a == NULL ? NULL : *v4a++;
48220Sstevel@tonic-gate print_hdr_once_v4 = tcp_report_item_v4(tp,
48231676Sjpk print_hdr_once_v4, aptr);
48240Sstevel@tonic-gate }
48250Sstevel@tonic-gate } else {
48260Sstevel@tonic-gate for (tp6 = (mib2_tcp6ConnEntry_t *)item->valp;
48270Sstevel@tonic-gate (char *)tp6 < (char *)item->valp + item->length;
48280Sstevel@tonic-gate /* LINTED: (note 1) */
48290Sstevel@tonic-gate tp6 = (mib2_tcp6ConnEntry_t *)((char *)tp6 +
48300Sstevel@tonic-gate tcp6ConnEntrySize)) {
48311676Sjpk aptr = v6a == NULL ? NULL : *v6a++;
48320Sstevel@tonic-gate print_hdr_once_v6 = tcp_report_item_v6(tp6,
48331676Sjpk print_hdr_once_v6, aptr);
48340Sstevel@tonic-gate }
48350Sstevel@tonic-gate }
48360Sstevel@tonic-gate } /* 'for' loop 1 ends */
48370Sstevel@tonic-gate (void) fflush(stdout);
48381676Sjpk
48391676Sjpk if (v4_attrs != NULL)
48401676Sjpk free(v4_attrs);
48411676Sjpk if (v6_attrs != NULL)
48421676Sjpk free(v6_attrs);
48430Sstevel@tonic-gate }
48440Sstevel@tonic-gate
48450Sstevel@tonic-gate static boolean_t
tcp_report_item_v4(const mib2_tcpConnEntry_t * tp,boolean_t first,const mib2_transportMLPEntry_t * attr)48461676Sjpk tcp_report_item_v4(const mib2_tcpConnEntry_t *tp, boolean_t first,
48471676Sjpk const mib2_transportMLPEntry_t *attr)
48480Sstevel@tonic-gate {
48490Sstevel@tonic-gate /*
48500Sstevel@tonic-gate * lname and fname below are for the hostname as well as the portname
48510Sstevel@tonic-gate * There is no limit on portname length so we assume MAXHOSTNAMELEN
48520Sstevel@tonic-gate * as the limit
48530Sstevel@tonic-gate */
48540Sstevel@tonic-gate char lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
48550Sstevel@tonic-gate char fname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
48560Sstevel@tonic-gate
48570Sstevel@tonic-gate if (!(Aflag || tp->tcpConnEntryInfo.ce_state >= TCPS_ESTABLISHED))
48580Sstevel@tonic-gate return (first); /* Nothing to print */
48590Sstevel@tonic-gate
48600Sstevel@tonic-gate if (first) {
48611676Sjpk (void) printf(v4compat ? tcp_hdr_v4_compat : tcp_hdr_v4);
48621676Sjpk (void) printf(Vflag ? tcp_hdr_v4_verbose : tcp_hdr_v4_normal);
48630Sstevel@tonic-gate }
48640Sstevel@tonic-gate
48650Sstevel@tonic-gate if (Vflag) {
48660Sstevel@tonic-gate (void) printf("%-20s\n%-20s %5u %08x %08x %5u %08x %08x "
48670Sstevel@tonic-gate "%5u %5u %s\n",
48680Sstevel@tonic-gate pr_ap(tp->tcpConnLocalAddress,
48698485SPeter.Memishian@Sun.COM tp->tcpConnLocalPort, "tcp", lname, sizeof (lname)),
48700Sstevel@tonic-gate pr_ap(tp->tcpConnRemAddress,
48718485SPeter.Memishian@Sun.COM tp->tcpConnRemPort, "tcp", fname, sizeof (fname)),
48720Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_swnd,
48730Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_snxt,
48740Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_suna,
48750Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_rwnd,
48760Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_rnxt,
48770Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_rack,
48780Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_rto,
48790Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_mss,
48801676Sjpk mitcp_state(tp->tcpConnEntryInfo.ce_state, attr));
48810Sstevel@tonic-gate } else {
48820Sstevel@tonic-gate int sq = (int)tp->tcpConnEntryInfo.ce_snxt -
48830Sstevel@tonic-gate (int)tp->tcpConnEntryInfo.ce_suna - 1;
48840Sstevel@tonic-gate int rq = (int)tp->tcpConnEntryInfo.ce_rnxt -
48850Sstevel@tonic-gate (int)tp->tcpConnEntryInfo.ce_rack;
48860Sstevel@tonic-gate
48870Sstevel@tonic-gate (void) printf("%-20s %-20s %5u %6d %5u %6d %s\n",
48880Sstevel@tonic-gate pr_ap(tp->tcpConnLocalAddress,
48898485SPeter.Memishian@Sun.COM tp->tcpConnLocalPort, "tcp", lname, sizeof (lname)),
48900Sstevel@tonic-gate pr_ap(tp->tcpConnRemAddress,
48918485SPeter.Memishian@Sun.COM tp->tcpConnRemPort, "tcp", fname, sizeof (fname)),
48920Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_swnd,
48930Sstevel@tonic-gate (sq >= 0) ? sq : 0,
48940Sstevel@tonic-gate tp->tcpConnEntryInfo.ce_rwnd,
48950Sstevel@tonic-gate (rq >= 0) ? rq : 0,
48961676Sjpk mitcp_state(tp->tcpConnEntryInfo.ce_state, attr));
48970Sstevel@tonic-gate }
48981676Sjpk
48991676Sjpk print_transport_label(attr);
49001676Sjpk
49011676Sjpk return (B_FALSE);
49020Sstevel@tonic-gate }
49030Sstevel@tonic-gate
49040Sstevel@tonic-gate static boolean_t
tcp_report_item_v6(const mib2_tcp6ConnEntry_t * tp6,boolean_t first,const mib2_transportMLPEntry_t * attr)49051676Sjpk tcp_report_item_v6(const mib2_tcp6ConnEntry_t *tp6, boolean_t first,
49061676Sjpk const mib2_transportMLPEntry_t *attr)
49070Sstevel@tonic-gate {
49080Sstevel@tonic-gate /*
49090Sstevel@tonic-gate * lname and fname below are for the hostname as well as the portname
49100Sstevel@tonic-gate * There is no limit on portname length so we assume MAXHOSTNAMELEN
49110Sstevel@tonic-gate * as the limit
49120Sstevel@tonic-gate */
49130Sstevel@tonic-gate char lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
49140Sstevel@tonic-gate char fname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
49150Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1];
49160Sstevel@tonic-gate char *ifnamep;
49170Sstevel@tonic-gate
49180Sstevel@tonic-gate if (!(Aflag || tp6->tcp6ConnEntryInfo.ce_state >= TCPS_ESTABLISHED))
49190Sstevel@tonic-gate return (first); /* Nothing to print */
49200Sstevel@tonic-gate
49210Sstevel@tonic-gate if (first) {
49221676Sjpk (void) printf(tcp_hdr_v6);
49231676Sjpk (void) printf(Vflag ? tcp_hdr_v6_verbose : tcp_hdr_v6_normal);
49240Sstevel@tonic-gate }
49250Sstevel@tonic-gate
49260Sstevel@tonic-gate ifnamep = (tp6->tcp6ConnIfIndex != 0) ?
49270Sstevel@tonic-gate if_indextoname(tp6->tcp6ConnIfIndex, ifname) : NULL;
49281676Sjpk if (ifnamep == NULL)
49291676Sjpk ifnamep = "";
49300Sstevel@tonic-gate
49310Sstevel@tonic-gate if (Vflag) {
49320Sstevel@tonic-gate (void) printf("%-33s\n%-33s %5u %08x %08x %5u %08x %08x "
49331676Sjpk "%5u %5u %-11s %s\n",
49340Sstevel@tonic-gate pr_ap6(&tp6->tcp6ConnLocalAddress,
49358485SPeter.Memishian@Sun.COM tp6->tcp6ConnLocalPort, "tcp", lname, sizeof (lname)),
49360Sstevel@tonic-gate pr_ap6(&tp6->tcp6ConnRemAddress,
49378485SPeter.Memishian@Sun.COM tp6->tcp6ConnRemPort, "tcp", fname, sizeof (fname)),
49380Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_swnd,
49390Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_snxt,
49400Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_suna,
49410Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_rwnd,
49420Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_rnxt,
49430Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_rack,
49440Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_rto,
49450Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_mss,
49461676Sjpk mitcp_state(tp6->tcp6ConnEntryInfo.ce_state, attr),
49471676Sjpk ifnamep);
49480Sstevel@tonic-gate } else {
49490Sstevel@tonic-gate int sq = (int)tp6->tcp6ConnEntryInfo.ce_snxt -
49500Sstevel@tonic-gate (int)tp6->tcp6ConnEntryInfo.ce_suna - 1;
49510Sstevel@tonic-gate int rq = (int)tp6->tcp6ConnEntryInfo.ce_rnxt -
49520Sstevel@tonic-gate (int)tp6->tcp6ConnEntryInfo.ce_rack;
49530Sstevel@tonic-gate
49541676Sjpk (void) printf("%-33s %-33s %5u %6d %5u %6d %-11s %s\n",
49550Sstevel@tonic-gate pr_ap6(&tp6->tcp6ConnLocalAddress,
49568485SPeter.Memishian@Sun.COM tp6->tcp6ConnLocalPort, "tcp", lname, sizeof (lname)),
49570Sstevel@tonic-gate pr_ap6(&tp6->tcp6ConnRemAddress,
49588485SPeter.Memishian@Sun.COM tp6->tcp6ConnRemPort, "tcp", fname, sizeof (fname)),
49590Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_swnd,
49600Sstevel@tonic-gate (sq >= 0) ? sq : 0,
49610Sstevel@tonic-gate tp6->tcp6ConnEntryInfo.ce_rwnd,
49620Sstevel@tonic-gate (rq >= 0) ? rq : 0,
49631676Sjpk mitcp_state(tp6->tcp6ConnEntryInfo.ce_state, attr),
49641676Sjpk ifnamep);
49650Sstevel@tonic-gate }
49661676Sjpk
49671676Sjpk print_transport_label(attr);
49681676Sjpk
49691676Sjpk return (B_FALSE);
49700Sstevel@tonic-gate }
49710Sstevel@tonic-gate
49720Sstevel@tonic-gate /* ------------------------------- UDP_REPORT------------------------------- */
49730Sstevel@tonic-gate
49741676Sjpk static boolean_t udp_report_item_v4(const mib2_udpEntry_t *ude,
49751676Sjpk boolean_t first, const mib2_transportMLPEntry_t *attr);
49761676Sjpk static boolean_t udp_report_item_v6(const mib2_udp6Entry_t *ude6,
49771676Sjpk boolean_t first, const mib2_transportMLPEntry_t *attr);
49781676Sjpk
49791676Sjpk static const char udp_hdr_v4[] =
49801676Sjpk " Local Address Remote Address State\n"
49811676Sjpk "-------------------- -------------------- ----------\n";
49821676Sjpk
49831676Sjpk static const char udp_hdr_v6[] =
49840Sstevel@tonic-gate " Local Address Remote Address "
49851676Sjpk " State If\n"
49860Sstevel@tonic-gate "--------------------------------- --------------------------------- "
49870Sstevel@tonic-gate "---------- -----\n";
49880Sstevel@tonic-gate
49890Sstevel@tonic-gate static void
udp_report(const mib_item_t * item)49901676Sjpk udp_report(const mib_item_t *item)
49910Sstevel@tonic-gate {
49920Sstevel@tonic-gate int jtemp = 0;
49930Sstevel@tonic-gate boolean_t print_hdr_once_v4 = B_TRUE;
49940Sstevel@tonic-gate boolean_t print_hdr_once_v6 = B_TRUE;
49950Sstevel@tonic-gate mib2_udpEntry_t *ude;
49960Sstevel@tonic-gate mib2_udp6Entry_t *ude6;
49971676Sjpk mib2_transportMLPEntry_t **v4_attrs, **v6_attrs;
49981676Sjpk mib2_transportMLPEntry_t **v4a, **v6a;
49991676Sjpk mib2_transportMLPEntry_t *aptr;
50000Sstevel@tonic-gate
50010Sstevel@tonic-gate if (!protocol_selected(IPPROTO_UDP))
50020Sstevel@tonic-gate return;
50030Sstevel@tonic-gate
50041676Sjpk /*
50051676Sjpk * Preparation pass: the kernel returns separate entries for UDP
50061676Sjpk * connection table entries and Multilevel Port attributes. We loop
50071676Sjpk * through the attributes first and set up an array for each address
50081676Sjpk * family.
50091676Sjpk */
50101676Sjpk v4_attrs = family_selected(AF_INET) && RSECflag ?
50111676Sjpk gather_attrs(item, MIB2_UDP, MIB2_UDP_ENTRY, udpEntrySize) : NULL;
50121676Sjpk v6_attrs = family_selected(AF_INET6) && RSECflag ?
50131676Sjpk gather_attrs(item, MIB2_UDP6, MIB2_UDP6_ENTRY, udp6EntrySize) :
50141676Sjpk NULL;
50151676Sjpk
50161676Sjpk v4a = v4_attrs;
50171676Sjpk v6a = v6_attrs;
50180Sstevel@tonic-gate /* 'for' loop 1: */
50190Sstevel@tonic-gate for (; item; item = item->next_item) {
502011042SErik.Nordmark@Sun.COM if (Xflag) {
50210Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp);
50220Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, "
50230Sstevel@tonic-gate "length = %d, valp = 0x%p\n",
50240Sstevel@tonic-gate item->group, item->mib_id,
50250Sstevel@tonic-gate item->length, item->valp);
50260Sstevel@tonic-gate }
50270Sstevel@tonic-gate if (!((item->group == MIB2_UDP &&
50280Sstevel@tonic-gate item->mib_id == MIB2_UDP_ENTRY) ||
50290Sstevel@tonic-gate (item->group == MIB2_UDP6 &&
50300Sstevel@tonic-gate item->mib_id == MIB2_UDP6_ENTRY)))
50310Sstevel@tonic-gate continue; /* 'for' loop 1 */
50320Sstevel@tonic-gate
50330Sstevel@tonic-gate if (item->group == MIB2_UDP && !family_selected(AF_INET))
50340Sstevel@tonic-gate continue; /* 'for' loop 1 */
50350Sstevel@tonic-gate else if (item->group == MIB2_UDP6 && !family_selected(AF_INET6))
50360Sstevel@tonic-gate continue; /* 'for' loop 1 */
50370Sstevel@tonic-gate
50380Sstevel@tonic-gate /* xxx.xxx.xxx.xxx,pppp sss... */
50390Sstevel@tonic-gate if (item->group == MIB2_UDP) {
50400Sstevel@tonic-gate for (ude = (mib2_udpEntry_t *)item->valp;
50410Sstevel@tonic-gate (char *)ude < (char *)item->valp + item->length;
50420Sstevel@tonic-gate /* LINTED: (note 1) */
50430Sstevel@tonic-gate ude = (mib2_udpEntry_t *)((char *)ude +
50440Sstevel@tonic-gate udpEntrySize)) {
50451676Sjpk aptr = v4a == NULL ? NULL : *v4a++;
50460Sstevel@tonic-gate print_hdr_once_v4 = udp_report_item_v4(ude,
50471676Sjpk print_hdr_once_v4, aptr);
50480Sstevel@tonic-gate }
50490Sstevel@tonic-gate } else {
50500Sstevel@tonic-gate for (ude6 = (mib2_udp6Entry_t *)item->valp;
50510Sstevel@tonic-gate (char *)ude6 < (char *)item->valp + item->length;
50520Sstevel@tonic-gate /* LINTED: (note 1) */
50530Sstevel@tonic-gate ude6 = (mib2_udp6Entry_t *)((char *)ude6 +
50540Sstevel@tonic-gate udp6EntrySize)) {
50551676Sjpk aptr = v6a == NULL ? NULL : *v6a++;
50560Sstevel@tonic-gate print_hdr_once_v6 = udp_report_item_v6(ude6,
50571676Sjpk print_hdr_once_v6, aptr);
50580Sstevel@tonic-gate }
50590Sstevel@tonic-gate }
50600Sstevel@tonic-gate } /* 'for' loop 1 ends */
50610Sstevel@tonic-gate (void) fflush(stdout);
50621676Sjpk
50631676Sjpk if (v4_attrs != NULL)
50641676Sjpk free(v4_attrs);
50651676Sjpk if (v6_attrs != NULL)
50661676Sjpk free(v6_attrs);
50670Sstevel@tonic-gate }
50680Sstevel@tonic-gate
50690Sstevel@tonic-gate static boolean_t
udp_report_item_v4(const mib2_udpEntry_t * ude,boolean_t first,const mib2_transportMLPEntry_t * attr)50701676Sjpk udp_report_item_v4(const mib2_udpEntry_t *ude, boolean_t first,
50711676Sjpk const mib2_transportMLPEntry_t *attr)
50720Sstevel@tonic-gate {
50730Sstevel@tonic-gate char lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
50740Sstevel@tonic-gate /* hostname + portname */
50750Sstevel@tonic-gate
50760Sstevel@tonic-gate if (!(Aflag || ude->udpEntryInfo.ue_state >= MIB2_UDP_connected))
50770Sstevel@tonic-gate return (first); /* Nothing to print */
50780Sstevel@tonic-gate
50790Sstevel@tonic-gate if (first) {
50801676Sjpk (void) printf(v4compat ? "\nUDP\n" : "\nUDP: IPv4\n");
50811676Sjpk (void) printf(udp_hdr_v4);
50820Sstevel@tonic-gate first = B_FALSE;
50830Sstevel@tonic-gate }
50840Sstevel@tonic-gate
50850Sstevel@tonic-gate (void) printf("%-20s ",
50860Sstevel@tonic-gate pr_ap(ude->udpLocalAddress, ude->udpLocalPort, "udp",
50870Sstevel@tonic-gate lname, sizeof (lname)));
50881676Sjpk (void) printf("%-20s %s\n",
50891676Sjpk ude->udpEntryInfo.ue_state == MIB2_UDP_connected ?
50901676Sjpk pr_ap(ude->udpEntryInfo.ue_RemoteAddress,
50911676Sjpk ude->udpEntryInfo.ue_RemotePort, "udp", lname, sizeof (lname)) :
50921676Sjpk "",
50931676Sjpk miudp_state(ude->udpEntryInfo.ue_state, attr));
50941676Sjpk
509511042SErik.Nordmark@Sun.COM print_transport_label(attr);
50961676Sjpk
50970Sstevel@tonic-gate return (first);
50980Sstevel@tonic-gate }
50990Sstevel@tonic-gate
51000Sstevel@tonic-gate static boolean_t
udp_report_item_v6(const mib2_udp6Entry_t * ude6,boolean_t first,const mib2_transportMLPEntry_t * attr)51011676Sjpk udp_report_item_v6(const mib2_udp6Entry_t *ude6, boolean_t first,
51021676Sjpk const mib2_transportMLPEntry_t *attr)
51030Sstevel@tonic-gate {
51040Sstevel@tonic-gate char lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
51050Sstevel@tonic-gate /* hostname + portname */
51060Sstevel@tonic-gate char ifname[LIFNAMSIZ + 1];
51071676Sjpk const char *ifnamep;
51080Sstevel@tonic-gate
51090Sstevel@tonic-gate if (!(Aflag || ude6->udp6EntryInfo.ue_state >= MIB2_UDP_connected))
51100Sstevel@tonic-gate return (first); /* Nothing to print */
51110Sstevel@tonic-gate
51120Sstevel@tonic-gate if (first) {
51131676Sjpk (void) printf("\nUDP: IPv6\n");
51141676Sjpk (void) printf(udp_hdr_v6);
51150Sstevel@tonic-gate first = B_FALSE;
51160Sstevel@tonic-gate }
51170Sstevel@tonic-gate
51181676Sjpk ifnamep = (ude6->udp6IfIndex != 0) ?
51191676Sjpk if_indextoname(ude6->udp6IfIndex, ifname) : NULL;
51201676Sjpk
51210Sstevel@tonic-gate (void) printf("%-33s ",
51220Sstevel@tonic-gate pr_ap6(&ude6->udp6LocalAddress,
51230Sstevel@tonic-gate ude6->udp6LocalPort, "udp", lname, sizeof (lname)));
51241676Sjpk (void) printf("%-33s %-10s %s\n",
51251676Sjpk ude6->udp6EntryInfo.ue_state == MIB2_UDP_connected ?
51261676Sjpk pr_ap6(&ude6->udp6EntryInfo.ue_RemoteAddress,
51271676Sjpk ude6->udp6EntryInfo.ue_RemotePort, "udp", lname, sizeof (lname)) :
51281676Sjpk "",
51291676Sjpk miudp_state(ude6->udp6EntryInfo.ue_state, attr),
51301676Sjpk ifnamep == NULL ? "" : ifnamep);
51311676Sjpk
513211042SErik.Nordmark@Sun.COM print_transport_label(attr);
51331676Sjpk
51340Sstevel@tonic-gate return (first);
51350Sstevel@tonic-gate }
51360Sstevel@tonic-gate
51370Sstevel@tonic-gate /* ------------------------------ SCTP_REPORT------------------------------- */
51380Sstevel@tonic-gate
51390Sstevel@tonic-gate static const char sctp_hdr[] =
51400Sstevel@tonic-gate "\nSCTP:";
51410Sstevel@tonic-gate static const char sctp_hdr_normal[] =
51420Sstevel@tonic-gate " Local Address Remote Address "
51430Sstevel@tonic-gate "Swind Send-Q Rwind Recv-Q StrsI/O State\n"
51440Sstevel@tonic-gate "------------------------------- ------------------------------- "
51450Sstevel@tonic-gate "------ ------ ------ ------ ------- -----------";
51460Sstevel@tonic-gate
51470Sstevel@tonic-gate static const char *
nssctp_state(int state,const mib2_transportMLPEntry_t * attr)51481676Sjpk nssctp_state(int state, const mib2_transportMLPEntry_t *attr)
51490Sstevel@tonic-gate {
51501676Sjpk static char sctpsbuf[50];
51511676Sjpk const char *cp;
51521676Sjpk
51530Sstevel@tonic-gate switch (state) {
51540Sstevel@tonic-gate case MIB2_SCTP_closed:
51551676Sjpk cp = "CLOSED";
51561676Sjpk break;
51570Sstevel@tonic-gate case MIB2_SCTP_cookieWait:
51581676Sjpk cp = "COOKIE_WAIT";
51591676Sjpk break;
51600Sstevel@tonic-gate case MIB2_SCTP_cookieEchoed:
51611676Sjpk cp = "COOKIE_ECHOED";
51621676Sjpk break;
51630Sstevel@tonic-gate case MIB2_SCTP_established:
51641676Sjpk cp = "ESTABLISHED";
51651676Sjpk break;
51660Sstevel@tonic-gate case MIB2_SCTP_shutdownPending:
51671676Sjpk cp = "SHUTDOWN_PENDING";
51681676Sjpk break;
51690Sstevel@tonic-gate case MIB2_SCTP_shutdownSent:
51701676Sjpk cp = "SHUTDOWN_SENT";
51711676Sjpk break;
51720Sstevel@tonic-gate case MIB2_SCTP_shutdownReceived:
51731676Sjpk cp = "SHUTDOWN_RECEIVED";
51741676Sjpk break;
51750Sstevel@tonic-gate case MIB2_SCTP_shutdownAckSent:
51761676Sjpk cp = "SHUTDOWN_ACK_SENT";
51771676Sjpk break;
51780Sstevel@tonic-gate case MIB2_SCTP_listen:
51791676Sjpk cp = "LISTEN";
51801676Sjpk break;
51810Sstevel@tonic-gate default:
51821676Sjpk (void) snprintf(sctpsbuf, sizeof (sctpsbuf),
51831676Sjpk "UNKNOWN STATE(%d)", state);
51841676Sjpk cp = sctpsbuf;
51851676Sjpk break;
51860Sstevel@tonic-gate }
51871676Sjpk
51881676Sjpk if (RSECflag && attr != NULL && attr->tme_flags != 0) {
51891676Sjpk if (cp != sctpsbuf) {
51901676Sjpk (void) strlcpy(sctpsbuf, cp, sizeof (sctpsbuf));
51911676Sjpk cp = sctpsbuf;
51921676Sjpk }
51931676Sjpk if (attr->tme_flags & MIB2_TMEF_PRIVATE)
51941676Sjpk (void) strlcat(sctpsbuf, " P", sizeof (sctpsbuf));
51951676Sjpk if (attr->tme_flags & MIB2_TMEF_SHARED)
51961676Sjpk (void) strlcat(sctpsbuf, " S", sizeof (sctpsbuf));
51971676Sjpk }
51981676Sjpk
51991676Sjpk return (cp);
52000Sstevel@tonic-gate }
52010Sstevel@tonic-gate
52021676Sjpk static const mib2_sctpConnRemoteEntry_t *
sctp_getnext_rem(const mib_item_t ** itemp,const mib2_sctpConnRemoteEntry_t * current,uint32_t associd)52031676Sjpk sctp_getnext_rem(const mib_item_t **itemp,
52041676Sjpk const mib2_sctpConnRemoteEntry_t *current, uint32_t associd)
52050Sstevel@tonic-gate {
52061676Sjpk const mib_item_t *item = *itemp;
52071676Sjpk const mib2_sctpConnRemoteEntry_t *sre;
52080Sstevel@tonic-gate
52090Sstevel@tonic-gate for (; item != NULL; item = item->next_item, current = NULL) {
52100Sstevel@tonic-gate if (!(item->group == MIB2_SCTP &&
52110Sstevel@tonic-gate item->mib_id == MIB2_SCTP_CONN_REMOTE)) {
52120Sstevel@tonic-gate continue;
52130Sstevel@tonic-gate }
52140Sstevel@tonic-gate
52150Sstevel@tonic-gate if (current != NULL) {
52160Sstevel@tonic-gate /* LINTED: (note 1) */
52171676Sjpk sre = (const mib2_sctpConnRemoteEntry_t *)
52181676Sjpk ((const char *)current + sctpRemoteEntrySize);
52190Sstevel@tonic-gate } else {
52200Sstevel@tonic-gate sre = item->valp;
52210Sstevel@tonic-gate }
52220Sstevel@tonic-gate for (; (char *)sre < (char *)item->valp + item->length;
52231676Sjpk /* LINTED: (note 1) */
52241676Sjpk sre = (const mib2_sctpConnRemoteEntry_t *)
52251676Sjpk ((const char *)sre + sctpRemoteEntrySize)) {
52260Sstevel@tonic-gate if (sre->sctpAssocId != associd) {
52270Sstevel@tonic-gate continue;
52280Sstevel@tonic-gate }
52290Sstevel@tonic-gate *itemp = item;
52300Sstevel@tonic-gate return (sre);
52310Sstevel@tonic-gate }
52320Sstevel@tonic-gate }
52330Sstevel@tonic-gate *itemp = NULL;
52340Sstevel@tonic-gate return (NULL);
52350Sstevel@tonic-gate }
52360Sstevel@tonic-gate
52371676Sjpk static const mib2_sctpConnLocalEntry_t *
sctp_getnext_local(const mib_item_t ** itemp,const mib2_sctpConnLocalEntry_t * current,uint32_t associd)52381676Sjpk sctp_getnext_local(const mib_item_t **itemp,
52391676Sjpk const mib2_sctpConnLocalEntry_t *current, uint32_t associd)
52400Sstevel@tonic-gate {
52411676Sjpk const mib_item_t *item = *itemp;
52421676Sjpk const mib2_sctpConnLocalEntry_t *sle;
52430Sstevel@tonic-gate
52440Sstevel@tonic-gate for (; item != NULL; item = item->next_item, current = NULL) {
52450Sstevel@tonic-gate if (!(item->group == MIB2_SCTP &&
52460Sstevel@tonic-gate item->mib_id == MIB2_SCTP_CONN_LOCAL)) {
52470Sstevel@tonic-gate continue;
52480Sstevel@tonic-gate }
52490Sstevel@tonic-gate
52500Sstevel@tonic-gate if (current != NULL) {
52510Sstevel@tonic-gate /* LINTED: (note 1) */
52521676Sjpk sle = (const mib2_sctpConnLocalEntry_t *)
52531676Sjpk ((const char *)current + sctpLocalEntrySize);
52540Sstevel@tonic-gate } else {
52550Sstevel@tonic-gate sle = item->valp;
52560Sstevel@tonic-gate }
52570Sstevel@tonic-gate for (; (char *)sle < (char *)item->valp + item->length;
52581676Sjpk /* LINTED: (note 1) */
52591676Sjpk sle = (const mib2_sctpConnLocalEntry_t *)
52601676Sjpk ((const char *)sle + sctpLocalEntrySize)) {
52610Sstevel@tonic-gate if (sle->sctpAssocId != associd) {
52620Sstevel@tonic-gate continue;
52630Sstevel@tonic-gate }
52640Sstevel@tonic-gate *itemp = item;
52650Sstevel@tonic-gate return (sle);
52660Sstevel@tonic-gate }
52670Sstevel@tonic-gate }
52680Sstevel@tonic-gate *itemp = NULL;
52690Sstevel@tonic-gate return (NULL);
52700Sstevel@tonic-gate }
52710Sstevel@tonic-gate
52720Sstevel@tonic-gate static void
sctp_pr_addr(int type,char * name,int namelen,const in6_addr_t * addr,int port)52730Sstevel@tonic-gate sctp_pr_addr(int type, char *name, int namelen, const in6_addr_t *addr,
52740Sstevel@tonic-gate int port)
52750Sstevel@tonic-gate {
52760Sstevel@tonic-gate ipaddr_t v4addr;
52770Sstevel@tonic-gate in6_addr_t v6addr;
52780Sstevel@tonic-gate
52790Sstevel@tonic-gate /*
52800Sstevel@tonic-gate * Address is either a v4 mapped or v6 addr. If
52810Sstevel@tonic-gate * it's a v4 mapped, convert to v4 before
52820Sstevel@tonic-gate * displaying.
52830Sstevel@tonic-gate */
52840Sstevel@tonic-gate switch (type) {
52858485SPeter.Memishian@Sun.COM case MIB2_SCTP_ADDR_V4:
52860Sstevel@tonic-gate /* v4 */
52870Sstevel@tonic-gate v6addr = *addr;
52880Sstevel@tonic-gate
52890Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&v6addr, v4addr);
52900Sstevel@tonic-gate if (port > 0) {
52910Sstevel@tonic-gate (void) pr_ap(v4addr, port, "sctp", name, namelen);
52920Sstevel@tonic-gate } else {
52930Sstevel@tonic-gate (void) pr_addr(v4addr, name, namelen);
52940Sstevel@tonic-gate }
52950Sstevel@tonic-gate break;
52960Sstevel@tonic-gate
52978485SPeter.Memishian@Sun.COM case MIB2_SCTP_ADDR_V6:
52980Sstevel@tonic-gate /* v6 */
52990Sstevel@tonic-gate if (port > 0) {
53000Sstevel@tonic-gate (void) pr_ap6(addr, port, "sctp", name, namelen);
53010Sstevel@tonic-gate } else {
53020Sstevel@tonic-gate (void) pr_addr6(addr, name, namelen);
53030Sstevel@tonic-gate }
53040Sstevel@tonic-gate break;
53050Sstevel@tonic-gate
53068485SPeter.Memishian@Sun.COM default:
53070Sstevel@tonic-gate (void) snprintf(name, namelen, "<unknown addr type>");
53080Sstevel@tonic-gate break;
53090Sstevel@tonic-gate }
53100Sstevel@tonic-gate }
53110Sstevel@tonic-gate
53120Sstevel@tonic-gate static void
sctp_conn_report_item(const mib_item_t * head,const mib2_sctpConnEntry_t * sp,const mib2_transportMLPEntry_t * attr)53131676Sjpk sctp_conn_report_item(const mib_item_t *head, const mib2_sctpConnEntry_t *sp,
53141676Sjpk const mib2_transportMLPEntry_t *attr)
53150Sstevel@tonic-gate {
53160Sstevel@tonic-gate char lname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
53170Sstevel@tonic-gate char fname[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 1];
53181676Sjpk const mib2_sctpConnRemoteEntry_t *sre = NULL;
53191676Sjpk const mib2_sctpConnLocalEntry_t *sle = NULL;
53201676Sjpk const mib_item_t *local = head;
53211676Sjpk const mib_item_t *remote = head;
53220Sstevel@tonic-gate uint32_t id = sp->sctpAssocId;
53230Sstevel@tonic-gate boolean_t printfirst = B_TRUE;
53240Sstevel@tonic-gate
53250Sstevel@tonic-gate sctp_pr_addr(sp->sctpAssocRemPrimAddrType, fname, sizeof (fname),
53260Sstevel@tonic-gate &sp->sctpAssocRemPrimAddr, sp->sctpAssocRemPort);
53270Sstevel@tonic-gate sctp_pr_addr(sp->sctpAssocRemPrimAddrType, lname, sizeof (lname),
53280Sstevel@tonic-gate &sp->sctpAssocLocPrimAddr, sp->sctpAssocLocalPort);
53290Sstevel@tonic-gate
53300Sstevel@tonic-gate (void) printf("%-31s %-31s %6u %6d %6u %6d %3d/%-3d %s\n",
53310Sstevel@tonic-gate lname, fname,
53320Sstevel@tonic-gate sp->sctpConnEntryInfo.ce_swnd,
53330Sstevel@tonic-gate sp->sctpConnEntryInfo.ce_sendq,
53340Sstevel@tonic-gate sp->sctpConnEntryInfo.ce_rwnd,
53350Sstevel@tonic-gate sp->sctpConnEntryInfo.ce_recvq,
53360Sstevel@tonic-gate sp->sctpAssocInStreams, sp->sctpAssocOutStreams,
53371676Sjpk nssctp_state(sp->sctpAssocState, attr));
53381676Sjpk
53391676Sjpk print_transport_label(attr);
53400Sstevel@tonic-gate
53410Sstevel@tonic-gate if (!Vflag) {
53420Sstevel@tonic-gate return;
53430Sstevel@tonic-gate }
53440Sstevel@tonic-gate
53450Sstevel@tonic-gate /* Print remote addresses/local addresses on following lines */
53460Sstevel@tonic-gate while ((sre = sctp_getnext_rem(&remote, sre, id)) != NULL) {
53470Sstevel@tonic-gate if (!IN6_ARE_ADDR_EQUAL(&sre->sctpAssocRemAddr,
53480Sstevel@tonic-gate &sp->sctpAssocRemPrimAddr)) {
53490Sstevel@tonic-gate if (printfirst == B_TRUE) {
53500Sstevel@tonic-gate (void) fputs("\t<Remote: ", stdout);
53510Sstevel@tonic-gate printfirst = B_FALSE;
53520Sstevel@tonic-gate } else {
53530Sstevel@tonic-gate (void) fputs(", ", stdout);
53540Sstevel@tonic-gate }
53550Sstevel@tonic-gate sctp_pr_addr(sre->sctpAssocRemAddrType, fname,
53560Sstevel@tonic-gate sizeof (fname), &sre->sctpAssocRemAddr, -1);
53570Sstevel@tonic-gate if (sre->sctpAssocRemAddrActive == MIB2_SCTP_ACTIVE) {
53580Sstevel@tonic-gate (void) fputs(fname, stdout);
53590Sstevel@tonic-gate } else {
53600Sstevel@tonic-gate (void) printf("(%s)", fname);
53610Sstevel@tonic-gate }
53620Sstevel@tonic-gate }
53630Sstevel@tonic-gate }
53640Sstevel@tonic-gate if (printfirst == B_FALSE) {
53650Sstevel@tonic-gate (void) puts(">");
53660Sstevel@tonic-gate printfirst = B_TRUE;
53670Sstevel@tonic-gate }
53680Sstevel@tonic-gate while ((sle = sctp_getnext_local(&local, sle, id)) != NULL) {
53690Sstevel@tonic-gate if (!IN6_ARE_ADDR_EQUAL(&sle->sctpAssocLocalAddr,
53700Sstevel@tonic-gate &sp->sctpAssocLocPrimAddr)) {
53710Sstevel@tonic-gate if (printfirst == B_TRUE) {
53720Sstevel@tonic-gate (void) fputs("\t<Local: ", stdout);
53730Sstevel@tonic-gate printfirst = B_FALSE;
53740Sstevel@tonic-gate } else {
53750Sstevel@tonic-gate (void) fputs(", ", stdout);
53760Sstevel@tonic-gate }
53770Sstevel@tonic-gate sctp_pr_addr(sle->sctpAssocLocalAddrType, lname,
53780Sstevel@tonic-gate sizeof (lname), &sle->sctpAssocLocalAddr, -1);
53790Sstevel@tonic-gate (void) fputs(lname, stdout);
53800Sstevel@tonic-gate }
53810Sstevel@tonic-gate }
53820Sstevel@tonic-gate if (printfirst == B_FALSE) {
53830Sstevel@tonic-gate (void) puts(">");
53840Sstevel@tonic-gate }
53850Sstevel@tonic-gate }
53860Sstevel@tonic-gate
53870Sstevel@tonic-gate static void
sctp_report(const mib_item_t * item)53881676Sjpk sctp_report(const mib_item_t *item)
53890Sstevel@tonic-gate {
53901676Sjpk const mib_item_t *head;
53911676Sjpk const mib2_sctpConnEntry_t *sp;
53920Sstevel@tonic-gate boolean_t first = B_TRUE;
53931676Sjpk mib2_transportMLPEntry_t **attrs, **aptr;
53941676Sjpk mib2_transportMLPEntry_t *attr;
53951676Sjpk
53961676Sjpk /*
53971676Sjpk * Preparation pass: the kernel returns separate entries for SCTP
53981676Sjpk * connection table entries and Multilevel Port attributes. We loop
53991676Sjpk * through the attributes first and set up an array for each address
54001676Sjpk * family.
54011676Sjpk */
54021676Sjpk attrs = RSECflag ?
54031676Sjpk gather_attrs(item, MIB2_SCTP, MIB2_SCTP_CONN, sctpEntrySize) :
54041676Sjpk NULL;
54051676Sjpk
54061676Sjpk aptr = attrs;
54070Sstevel@tonic-gate head = item;
54080Sstevel@tonic-gate for (; item != NULL; item = item->next_item) {
54090Sstevel@tonic-gate
54100Sstevel@tonic-gate if (!(item->group == MIB2_SCTP &&
54110Sstevel@tonic-gate item->mib_id == MIB2_SCTP_CONN))
54120Sstevel@tonic-gate continue;
54130Sstevel@tonic-gate
54140Sstevel@tonic-gate for (sp = item->valp;
54151676Sjpk (char *)sp < (char *)item->valp + item->length;
54161676Sjpk /* LINTED: (note 1) */
54171676Sjpk sp = (mib2_sctpConnEntry_t *)((char *)sp + sctpEntrySize)) {
54181676Sjpk attr = aptr == NULL ? NULL : *aptr++;
54190Sstevel@tonic-gate if (Aflag ||
54200Sstevel@tonic-gate sp->sctpAssocState >= MIB2_SCTP_established) {
54210Sstevel@tonic-gate if (first == B_TRUE) {
54220Sstevel@tonic-gate (void) puts(sctp_hdr);
54230Sstevel@tonic-gate (void) puts(sctp_hdr_normal);
54240Sstevel@tonic-gate first = B_FALSE;
54250Sstevel@tonic-gate }
54261676Sjpk sctp_conn_report_item(head, sp, attr);
54270Sstevel@tonic-gate }
54280Sstevel@tonic-gate }
54290Sstevel@tonic-gate }
54301676Sjpk if (attrs != NULL)
54311676Sjpk free(attrs);
54320Sstevel@tonic-gate }
54330Sstevel@tonic-gate
54340Sstevel@tonic-gate static char *
plural(int n)54350Sstevel@tonic-gate plural(int n)
54360Sstevel@tonic-gate {
54370Sstevel@tonic-gate return (n != 1 ? "s" : "");
54380Sstevel@tonic-gate }
54390Sstevel@tonic-gate
54400Sstevel@tonic-gate static char *
pluraly(int n)54410Sstevel@tonic-gate pluraly(int n)
54420Sstevel@tonic-gate {
54430Sstevel@tonic-gate return (n != 1 ? "ies" : "y");
54440Sstevel@tonic-gate }
54450Sstevel@tonic-gate
54460Sstevel@tonic-gate static char *
plurales(int n)54470Sstevel@tonic-gate plurales(int n)
54480Sstevel@tonic-gate {
54490Sstevel@tonic-gate return (n != 1 ? "es" : "");
54500Sstevel@tonic-gate }
54510Sstevel@tonic-gate
54520Sstevel@tonic-gate static char *
pktscale(n)54530Sstevel@tonic-gate pktscale(n)
54540Sstevel@tonic-gate int n;
54550Sstevel@tonic-gate {
54560Sstevel@tonic-gate static char buf[6];
54570Sstevel@tonic-gate char t;
54580Sstevel@tonic-gate
54590Sstevel@tonic-gate if (n < 1024) {
54600Sstevel@tonic-gate t = ' ';
54610Sstevel@tonic-gate } else if (n < 1024 * 1024) {
54620Sstevel@tonic-gate t = 'k';
54630Sstevel@tonic-gate n /= 1024;
54640Sstevel@tonic-gate } else if (n < 1024 * 1024 * 1024) {
54650Sstevel@tonic-gate t = 'm';
54660Sstevel@tonic-gate n /= 1024 * 1024;
54670Sstevel@tonic-gate } else {
54680Sstevel@tonic-gate t = 'g';
54690Sstevel@tonic-gate n /= 1024 * 1024 * 1024;
54700Sstevel@tonic-gate }
54710Sstevel@tonic-gate
54720Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%4u%c", n, t);
54730Sstevel@tonic-gate return (buf);
54740Sstevel@tonic-gate }
54750Sstevel@tonic-gate
54760Sstevel@tonic-gate /* --------------------- mrt_report (netstat -m) -------------------------- */
54770Sstevel@tonic-gate
54780Sstevel@tonic-gate static void
mrt_report(mib_item_t * item)54790Sstevel@tonic-gate mrt_report(mib_item_t *item)
54800Sstevel@tonic-gate {
54810Sstevel@tonic-gate int jtemp = 0;
54820Sstevel@tonic-gate struct vifctl *vip;
54830Sstevel@tonic-gate vifi_t vifi;
54840Sstevel@tonic-gate struct mfcctl *mfccp;
54850Sstevel@tonic-gate int numvifs = 0;
54860Sstevel@tonic-gate int nmfc = 0;
54870Sstevel@tonic-gate char abuf[MAXHOSTNAMELEN + 1];
54880Sstevel@tonic-gate
54890Sstevel@tonic-gate if (!(family_selected(AF_INET)))
54900Sstevel@tonic-gate return;
54910Sstevel@tonic-gate
54920Sstevel@tonic-gate /* 'for' loop 1: */
54930Sstevel@tonic-gate for (; item; item = item->next_item) {
549411042SErik.Nordmark@Sun.COM if (Xflag) {
54950Sstevel@tonic-gate (void) printf("\n--- Entry %d ---\n", ++jtemp);
54960Sstevel@tonic-gate (void) printf("Group = %d, mib_id = %d, "
54970Sstevel@tonic-gate "length = %d, valp = 0x%p\n",
54980Sstevel@tonic-gate item->group, item->mib_id, item->length,
54990Sstevel@tonic-gate item->valp);
55000Sstevel@tonic-gate }
55010Sstevel@tonic-gate if (item->group != EXPER_DVMRP)
55020Sstevel@tonic-gate continue; /* 'for' loop 1 */
55030Sstevel@tonic-gate
55040Sstevel@tonic-gate switch (item->mib_id) {
55050Sstevel@tonic-gate
55060Sstevel@tonic-gate case EXPER_DVMRP_VIF:
550711042SErik.Nordmark@Sun.COM if (Xflag)
55080Sstevel@tonic-gate (void) printf("%u records for ipVifTable:\n",
55090Sstevel@tonic-gate item->length/sizeof (struct vifctl));
55100Sstevel@tonic-gate if (item->length/sizeof (struct vifctl) == 0) {
55110Sstevel@tonic-gate (void) puts("\nVirtual Interface Table is "
55120Sstevel@tonic-gate "empty");
55130Sstevel@tonic-gate break;
55140Sstevel@tonic-gate }
55150Sstevel@tonic-gate
55160Sstevel@tonic-gate (void) puts("\nVirtual Interface Table\n"
55170Sstevel@tonic-gate " Vif Threshold Rate_Limit Local-Address"
55180Sstevel@tonic-gate " Remote-Address Pkt_in Pkt_out");
55190Sstevel@tonic-gate
55200Sstevel@tonic-gate /* 'for' loop 2: */
55210Sstevel@tonic-gate for (vip = (struct vifctl *)item->valp;
55220Sstevel@tonic-gate (char *)vip < (char *)item->valp + item->length;
55230Sstevel@tonic-gate /* LINTED: (note 1) */
55240Sstevel@tonic-gate vip = (struct vifctl *)((char *)vip +
55250Sstevel@tonic-gate vifctlSize)) {
55260Sstevel@tonic-gate if (vip->vifc_lcl_addr.s_addr == 0)
55270Sstevel@tonic-gate continue; /* 'for' loop 2 */
55280Sstevel@tonic-gate /* numvifs = vip->vifc_vifi; */
55290Sstevel@tonic-gate
55300Sstevel@tonic-gate numvifs++;
55310Sstevel@tonic-gate (void) printf(" %2u %3u "
55320Sstevel@tonic-gate "%4u %-15.15s",
55330Sstevel@tonic-gate vip->vifc_vifi,
55340Sstevel@tonic-gate vip->vifc_threshold,
55350Sstevel@tonic-gate vip->vifc_rate_limit,
55360Sstevel@tonic-gate pr_addr(vip->vifc_lcl_addr.s_addr,
55370Sstevel@tonic-gate abuf, sizeof (abuf)));
55380Sstevel@tonic-gate (void) printf(" %-15.15s %8u %8u\n",
55390Sstevel@tonic-gate (vip->vifc_flags & VIFF_TUNNEL) ?
55400Sstevel@tonic-gate pr_addr(vip->vifc_rmt_addr.s_addr,
55410Sstevel@tonic-gate abuf, sizeof (abuf)) : "",
55420Sstevel@tonic-gate vip->vifc_pkt_in,
55430Sstevel@tonic-gate vip->vifc_pkt_out);
55440Sstevel@tonic-gate } /* 'for' loop 2 ends */
55450Sstevel@tonic-gate
55460Sstevel@tonic-gate (void) printf("Numvifs: %d\n", numvifs);
55470Sstevel@tonic-gate break;
55480Sstevel@tonic-gate
55490Sstevel@tonic-gate case EXPER_DVMRP_MRT:
555011042SErik.Nordmark@Sun.COM if (Xflag)
55510Sstevel@tonic-gate (void) printf("%u records for ipMfcTable:\n",
55528485SPeter.Memishian@Sun.COM item->length/sizeof (struct vifctl));
55530Sstevel@tonic-gate if (item->length/sizeof (struct vifctl) == 0) {
55540Sstevel@tonic-gate (void) puts("\nMulticast Forwarding Cache is "
55550Sstevel@tonic-gate "empty");
55560Sstevel@tonic-gate break;
55570Sstevel@tonic-gate }
55580Sstevel@tonic-gate
55590Sstevel@tonic-gate (void) puts("\nMulticast Forwarding Cache\n"
55600Sstevel@tonic-gate " Origin-Subnet Mcastgroup "
55610Sstevel@tonic-gate "# Pkts In-Vif Out-vifs/Forw-ttl");
55620Sstevel@tonic-gate
55630Sstevel@tonic-gate for (mfccp = (struct mfcctl *)item->valp;
55640Sstevel@tonic-gate (char *)mfccp < (char *)item->valp + item->length;
55650Sstevel@tonic-gate /* LINTED: (note 1) */
55660Sstevel@tonic-gate mfccp = (struct mfcctl *)((char *)mfccp +
55670Sstevel@tonic-gate mfcctlSize)) {
55680Sstevel@tonic-gate
55690Sstevel@tonic-gate nmfc++;
55700Sstevel@tonic-gate (void) printf(" %-30.15s",
55710Sstevel@tonic-gate pr_addr(mfccp->mfcc_origin.s_addr,
55720Sstevel@tonic-gate abuf, sizeof (abuf)));
55730Sstevel@tonic-gate (void) printf("%-15.15s %6s %3u ",
55740Sstevel@tonic-gate pr_net(mfccp->mfcc_mcastgrp.s_addr,
55758485SPeter.Memishian@Sun.COM mfccp->mfcc_mcastgrp.s_addr,
55768485SPeter.Memishian@Sun.COM abuf, sizeof (abuf)),
55770Sstevel@tonic-gate pktscale((int)mfccp->mfcc_pkt_cnt),
55788485SPeter.Memishian@Sun.COM mfccp->mfcc_parent);
55790Sstevel@tonic-gate
55800Sstevel@tonic-gate for (vifi = 0; vifi < MAXVIFS; ++vifi) {
55810Sstevel@tonic-gate if (mfccp->mfcc_ttls[vifi]) {
55820Sstevel@tonic-gate (void) printf(" %u (%u)",
55830Sstevel@tonic-gate vifi,
55840Sstevel@tonic-gate mfccp->mfcc_ttls[vifi]);
55850Sstevel@tonic-gate }
55860Sstevel@tonic-gate
55870Sstevel@tonic-gate }
55880Sstevel@tonic-gate (void) putchar('\n');
55890Sstevel@tonic-gate }
55900Sstevel@tonic-gate (void) printf("\nTotal no. of entries in cache: %d\n",
55910Sstevel@tonic-gate nmfc);
55920Sstevel@tonic-gate break;
55930Sstevel@tonic-gate }
55940Sstevel@tonic-gate } /* 'for' loop 1 ends */
55950Sstevel@tonic-gate (void) putchar('\n');
55960Sstevel@tonic-gate (void) fflush(stdout);
55970Sstevel@tonic-gate }
55980Sstevel@tonic-gate
55990Sstevel@tonic-gate /*
56000Sstevel@tonic-gate * Get the stats for the cache named 'name'. If prefix != 0, then
56010Sstevel@tonic-gate * interpret the name as a prefix, and sum up stats for all caches
56020Sstevel@tonic-gate * named 'name*'.
56030Sstevel@tonic-gate */
56040Sstevel@tonic-gate static void
kmem_cache_stats(char * title,char * name,int prefix,int64_t * total_bytes)56050Sstevel@tonic-gate kmem_cache_stats(char *title, char *name, int prefix, int64_t *total_bytes)
56060Sstevel@tonic-gate {
56070Sstevel@tonic-gate int len;
56080Sstevel@tonic-gate int alloc;
56090Sstevel@tonic-gate int64_t total_alloc = 0;
56100Sstevel@tonic-gate int alloc_fail, total_alloc_fail = 0;
56110Sstevel@tonic-gate int buf_size = 0;
56120Sstevel@tonic-gate int buf_avail;
56130Sstevel@tonic-gate int buf_total;
56140Sstevel@tonic-gate int buf_max, total_buf_max = 0;
56150Sstevel@tonic-gate int buf_inuse, total_buf_inuse = 0;
56160Sstevel@tonic-gate kstat_t *ksp;
56170Sstevel@tonic-gate char buf[256];
56180Sstevel@tonic-gate
56190Sstevel@tonic-gate len = prefix ? strlen(name) : 256;
56200Sstevel@tonic-gate
56210Sstevel@tonic-gate /* 'for' loop 1: */
56220Sstevel@tonic-gate for (ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next) {
56230Sstevel@tonic-gate
56240Sstevel@tonic-gate if (strcmp(ksp->ks_class, "kmem_cache") != 0)
56250Sstevel@tonic-gate continue; /* 'for' loop 1 */
56260Sstevel@tonic-gate
56270Sstevel@tonic-gate /*
56280Sstevel@tonic-gate * Hack alert: because of the way streams messages are
56290Sstevel@tonic-gate * allocated, every constructed free dblk has an associated
56300Sstevel@tonic-gate * mblk. From the allocator's viewpoint those mblks are
56310Sstevel@tonic-gate * allocated (because they haven't been freed), but from
56320Sstevel@tonic-gate * our viewpoint they're actually free (because they're
56330Sstevel@tonic-gate * not currently in use). To account for this caching
56340Sstevel@tonic-gate * effect we subtract the total constructed free dblks
56350Sstevel@tonic-gate * from the total allocated mblks to derive mblks in use.
56360Sstevel@tonic-gate */
56370Sstevel@tonic-gate if (strcmp(name, "streams_mblk") == 0 &&
56380Sstevel@tonic-gate strncmp(ksp->ks_name, "streams_dblk", 12) == 0) {
56390Sstevel@tonic-gate (void) safe_kstat_read(kc, ksp, NULL);
56400Sstevel@tonic-gate total_buf_inuse -=
56418485SPeter.Memishian@Sun.COM kstat_named_value(ksp, "buf_constructed");
56420Sstevel@tonic-gate continue; /* 'for' loop 1 */
56430Sstevel@tonic-gate }
56440Sstevel@tonic-gate
56450Sstevel@tonic-gate if (strncmp(ksp->ks_name, name, len) != 0)
56460Sstevel@tonic-gate continue; /* 'for' loop 1 */
56470Sstevel@tonic-gate
56480Sstevel@tonic-gate (void) safe_kstat_read(kc, ksp, NULL);
56490Sstevel@tonic-gate
56500Sstevel@tonic-gate alloc = kstat_named_value(ksp, "alloc");
56510Sstevel@tonic-gate alloc_fail = kstat_named_value(ksp, "alloc_fail");
56520Sstevel@tonic-gate buf_size = kstat_named_value(ksp, "buf_size");
56530Sstevel@tonic-gate buf_avail = kstat_named_value(ksp, "buf_avail");
56540Sstevel@tonic-gate buf_total = kstat_named_value(ksp, "buf_total");
56550Sstevel@tonic-gate buf_max = kstat_named_value(ksp, "buf_max");
56560Sstevel@tonic-gate buf_inuse = buf_total - buf_avail;
56570Sstevel@tonic-gate
56580Sstevel@tonic-gate if (Vflag && prefix) {
56590Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s%s", title,
56600Sstevel@tonic-gate ksp->ks_name + len);
56610Sstevel@tonic-gate (void) printf(" %-18s %6u %9u %11u %11u\n",
56620Sstevel@tonic-gate buf, buf_inuse, buf_max, alloc, alloc_fail);
56630Sstevel@tonic-gate }
56640Sstevel@tonic-gate
56650Sstevel@tonic-gate total_alloc += alloc;
56660Sstevel@tonic-gate total_alloc_fail += alloc_fail;
56670Sstevel@tonic-gate total_buf_max += buf_max;
56680Sstevel@tonic-gate total_buf_inuse += buf_inuse;
56690Sstevel@tonic-gate *total_bytes += (int64_t)buf_inuse * buf_size;
56700Sstevel@tonic-gate } /* 'for' loop 1 ends */
56710Sstevel@tonic-gate
56720Sstevel@tonic-gate if (buf_size == 0) {
56730Sstevel@tonic-gate (void) printf("%-22s [couldn't find statistics for %s]\n",
56748485SPeter.Memishian@Sun.COM title, name);
56750Sstevel@tonic-gate return;
56760Sstevel@tonic-gate }
56770Sstevel@tonic-gate
56780Sstevel@tonic-gate if (Vflag && prefix)
56790Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s_total", title);
56800Sstevel@tonic-gate else
56810Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s", title);
56820Sstevel@tonic-gate
56830Sstevel@tonic-gate (void) printf("%-22s %6d %9d %11lld %11d\n", buf,
56848485SPeter.Memishian@Sun.COM total_buf_inuse, total_buf_max, total_alloc, total_alloc_fail);
56850Sstevel@tonic-gate }
56860Sstevel@tonic-gate
56870Sstevel@tonic-gate static void
m_report(void)56880Sstevel@tonic-gate m_report(void)
56890Sstevel@tonic-gate {
56900Sstevel@tonic-gate int64_t total_bytes = 0;
56910Sstevel@tonic-gate
56920Sstevel@tonic-gate (void) puts("streams allocation:");
56930Sstevel@tonic-gate (void) printf("%63s\n", "cumulative allocation");
56940Sstevel@tonic-gate (void) printf("%63s\n",
56950Sstevel@tonic-gate "current maximum total failures");
56960Sstevel@tonic-gate
56970Sstevel@tonic-gate kmem_cache_stats("streams",
56980Sstevel@tonic-gate "stream_head_cache", 0, &total_bytes);
56990Sstevel@tonic-gate kmem_cache_stats("queues", "queue_cache", 0, &total_bytes);
57000Sstevel@tonic-gate kmem_cache_stats("mblk", "streams_mblk", 0, &total_bytes);
57010Sstevel@tonic-gate kmem_cache_stats("dblk", "streams_dblk", 1, &total_bytes);
57020Sstevel@tonic-gate kmem_cache_stats("linkblk", "linkinfo_cache", 0, &total_bytes);
57030Sstevel@tonic-gate kmem_cache_stats("syncq", "syncq_cache", 0, &total_bytes);
57040Sstevel@tonic-gate kmem_cache_stats("qband", "qband_cache", 0, &total_bytes);
57050Sstevel@tonic-gate
57060Sstevel@tonic-gate (void) printf("\n%lld Kbytes allocated for streams data\n",
57078485SPeter.Memishian@Sun.COM total_bytes / 1024);
57080Sstevel@tonic-gate
57090Sstevel@tonic-gate (void) putchar('\n');
57100Sstevel@tonic-gate (void) fflush(stdout);
57110Sstevel@tonic-gate }
57120Sstevel@tonic-gate
57130Sstevel@tonic-gate /* --------------------------------- */
57140Sstevel@tonic-gate
57150Sstevel@tonic-gate /*
57160Sstevel@tonic-gate * Print an IPv4 address. Remove the matching part of the domain name
57170Sstevel@tonic-gate * from the returned name.
57180Sstevel@tonic-gate */
57190Sstevel@tonic-gate static char *
pr_addr(uint_t addr,char * dst,uint_t dstlen)57200Sstevel@tonic-gate pr_addr(uint_t addr, char *dst, uint_t dstlen)
57210Sstevel@tonic-gate {
57220Sstevel@tonic-gate char *cp;
57230Sstevel@tonic-gate struct hostent *hp = NULL;
57240Sstevel@tonic-gate static char domain[MAXHOSTNAMELEN + 1];
57250Sstevel@tonic-gate static boolean_t first = B_TRUE;
57260Sstevel@tonic-gate int error_num;
57270Sstevel@tonic-gate
57280Sstevel@tonic-gate if (first) {
57290Sstevel@tonic-gate first = B_FALSE;
57300Sstevel@tonic-gate if (sysinfo(SI_HOSTNAME, domain, MAXHOSTNAMELEN) != -1 &&
57310Sstevel@tonic-gate (cp = strchr(domain, '.'))) {
57320Sstevel@tonic-gate (void) strncpy(domain, cp + 1, sizeof (domain));
57330Sstevel@tonic-gate } else
57340Sstevel@tonic-gate domain[0] = 0;
57350Sstevel@tonic-gate }
57360Sstevel@tonic-gate cp = NULL;
57370Sstevel@tonic-gate if (!Nflag) {
57380Sstevel@tonic-gate hp = getipnodebyaddr((char *)&addr, sizeof (uint_t), AF_INET,
57390Sstevel@tonic-gate &error_num);
57400Sstevel@tonic-gate if (hp) {
57410Sstevel@tonic-gate if ((cp = strchr(hp->h_name, '.')) != NULL &&
57420Sstevel@tonic-gate strcasecmp(cp + 1, domain) == 0)
57430Sstevel@tonic-gate *cp = 0;
57440Sstevel@tonic-gate cp = hp->h_name;
57450Sstevel@tonic-gate }
57460Sstevel@tonic-gate }
57470Sstevel@tonic-gate if (cp != NULL) {
57480Sstevel@tonic-gate (void) strncpy(dst, cp, dstlen);
57490Sstevel@tonic-gate dst[dstlen - 1] = 0;
57500Sstevel@tonic-gate } else {
57510Sstevel@tonic-gate (void) inet_ntop(AF_INET, (char *)&addr, dst, dstlen);
57520Sstevel@tonic-gate }
57530Sstevel@tonic-gate if (hp != NULL)
57540Sstevel@tonic-gate freehostent(hp);
57550Sstevel@tonic-gate return (dst);
57560Sstevel@tonic-gate }
57570Sstevel@tonic-gate
57580Sstevel@tonic-gate /*
57590Sstevel@tonic-gate * Print a non-zero IPv4 address. Print " --" if the address is zero.
57600Sstevel@tonic-gate */
57610Sstevel@tonic-gate static char *
pr_addrnz(ipaddr_t addr,char * dst,uint_t dstlen)57620Sstevel@tonic-gate pr_addrnz(ipaddr_t addr, char *dst, uint_t dstlen)
57630Sstevel@tonic-gate {
57640Sstevel@tonic-gate if (addr == INADDR_ANY) {
57650Sstevel@tonic-gate (void) strlcpy(dst, " --", dstlen);
57660Sstevel@tonic-gate return (dst);
57670Sstevel@tonic-gate }
57680Sstevel@tonic-gate return (pr_addr(addr, dst, dstlen));
57690Sstevel@tonic-gate }
57700Sstevel@tonic-gate
57710Sstevel@tonic-gate /*
57720Sstevel@tonic-gate * Print an IPv6 address. Remove the matching part of the domain name
57730Sstevel@tonic-gate * from the returned name.
57740Sstevel@tonic-gate */
57750Sstevel@tonic-gate static char *
pr_addr6(const struct in6_addr * addr,char * dst,uint_t dstlen)57760Sstevel@tonic-gate pr_addr6(const struct in6_addr *addr, char *dst, uint_t dstlen)
57770Sstevel@tonic-gate {
57780Sstevel@tonic-gate char *cp;
57790Sstevel@tonic-gate struct hostent *hp = NULL;
57800Sstevel@tonic-gate static char domain[MAXHOSTNAMELEN + 1];
57810Sstevel@tonic-gate static boolean_t first = B_TRUE;
57820Sstevel@tonic-gate int error_num;
57830Sstevel@tonic-gate
57840Sstevel@tonic-gate if (first) {
57850Sstevel@tonic-gate first = B_FALSE;
57860Sstevel@tonic-gate if (sysinfo(SI_HOSTNAME, domain, MAXHOSTNAMELEN) != -1 &&
57870Sstevel@tonic-gate (cp = strchr(domain, '.'))) {
57880Sstevel@tonic-gate (void) strncpy(domain, cp + 1, sizeof (domain));
57890Sstevel@tonic-gate } else
57900Sstevel@tonic-gate domain[0] = 0;
57910Sstevel@tonic-gate }
57920Sstevel@tonic-gate cp = NULL;
57930Sstevel@tonic-gate if (!Nflag) {
57940Sstevel@tonic-gate hp = getipnodebyaddr((char *)addr,
57950Sstevel@tonic-gate sizeof (struct in6_addr), AF_INET6, &error_num);
57960Sstevel@tonic-gate if (hp) {
57970Sstevel@tonic-gate if ((cp = strchr(hp->h_name, '.')) != NULL &&
57980Sstevel@tonic-gate strcasecmp(cp + 1, domain) == 0)
57990Sstevel@tonic-gate *cp = 0;
58000Sstevel@tonic-gate cp = hp->h_name;
58010Sstevel@tonic-gate }
58020Sstevel@tonic-gate }
58030Sstevel@tonic-gate if (cp != NULL) {
58040Sstevel@tonic-gate (void) strncpy(dst, cp, dstlen);
58050Sstevel@tonic-gate dst[dstlen - 1] = 0;
58060Sstevel@tonic-gate } else {
58070Sstevel@tonic-gate (void) inet_ntop(AF_INET6, (void *)addr, dst, dstlen);
58080Sstevel@tonic-gate }
58090Sstevel@tonic-gate if (hp != NULL)
58100Sstevel@tonic-gate freehostent(hp);
58110Sstevel@tonic-gate return (dst);
58120Sstevel@tonic-gate }
58130Sstevel@tonic-gate
58140Sstevel@tonic-gate /* For IPv4 masks */
58150Sstevel@tonic-gate static char *
pr_mask(uint_t addr,char * dst,uint_t dstlen)58160Sstevel@tonic-gate pr_mask(uint_t addr, char *dst, uint_t dstlen)
58170Sstevel@tonic-gate {
58180Sstevel@tonic-gate uint8_t *ip_addr = (uint8_t *)&addr;
58190Sstevel@tonic-gate
58200Sstevel@tonic-gate (void) snprintf(dst, dstlen, "%d.%d.%d.%d",
58210Sstevel@tonic-gate ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3]);
58220Sstevel@tonic-gate return (dst);
58230Sstevel@tonic-gate }
58240Sstevel@tonic-gate
58250Sstevel@tonic-gate /*
58260Sstevel@tonic-gate * For ipv6 masks format is : dest/mask
58270Sstevel@tonic-gate * Does not print /128 to save space in printout. H flag carries this notion.
58280Sstevel@tonic-gate */
58290Sstevel@tonic-gate static char *
pr_prefix6(const struct in6_addr * addr,uint_t prefixlen,char * dst,uint_t dstlen)58301676Sjpk pr_prefix6(const struct in6_addr *addr, uint_t prefixlen, char *dst,
58311676Sjpk uint_t dstlen)
58320Sstevel@tonic-gate {
58330Sstevel@tonic-gate char *cp;
58340Sstevel@tonic-gate
58350Sstevel@tonic-gate if (IN6_IS_ADDR_UNSPECIFIED(addr) && prefixlen == 0) {
58360Sstevel@tonic-gate (void) strncpy(dst, "default", dstlen);
58370Sstevel@tonic-gate dst[dstlen - 1] = 0;
58380Sstevel@tonic-gate return (dst);
58390Sstevel@tonic-gate }
58400Sstevel@tonic-gate
58410Sstevel@tonic-gate (void) pr_addr6(addr, dst, dstlen);
58420Sstevel@tonic-gate if (prefixlen != IPV6_ABITS) {
58430Sstevel@tonic-gate /* How much room is left? */
58440Sstevel@tonic-gate cp = strchr(dst, '\0');
58450Sstevel@tonic-gate if (dst + dstlen > cp) {
58460Sstevel@tonic-gate dstlen -= (cp - dst);
58470Sstevel@tonic-gate (void) snprintf(cp, dstlen, "/%d", prefixlen);
58480Sstevel@tonic-gate }
58490Sstevel@tonic-gate }
58500Sstevel@tonic-gate return (dst);
58510Sstevel@tonic-gate }
58520Sstevel@tonic-gate
58530Sstevel@tonic-gate /* Print IPv4 address and port */
58540Sstevel@tonic-gate static char *
pr_ap(uint_t addr,uint_t port,char * proto,char * dst,uint_t dstlen)58550Sstevel@tonic-gate pr_ap(uint_t addr, uint_t port, char *proto,
58560Sstevel@tonic-gate char *dst, uint_t dstlen)
58570Sstevel@tonic-gate {
58580Sstevel@tonic-gate char *cp;
58590Sstevel@tonic-gate
58600Sstevel@tonic-gate if (addr == INADDR_ANY) {
58610Sstevel@tonic-gate (void) strncpy(dst, " *", dstlen);
58620Sstevel@tonic-gate dst[dstlen - 1] = 0;
58630Sstevel@tonic-gate } else {
58640Sstevel@tonic-gate (void) pr_addr(addr, dst, dstlen);
58650Sstevel@tonic-gate }
58660Sstevel@tonic-gate /* How much room is left? */
58670Sstevel@tonic-gate cp = strchr(dst, '\0');
58680Sstevel@tonic-gate if (dst + dstlen > cp + 1) {
58690Sstevel@tonic-gate *cp++ = '.';
58700Sstevel@tonic-gate dstlen -= (cp - dst);
58710Sstevel@tonic-gate dstlen--;
58720Sstevel@tonic-gate (void) portname(port, proto, cp, dstlen);
58730Sstevel@tonic-gate }
58740Sstevel@tonic-gate return (dst);
58750Sstevel@tonic-gate }
58760Sstevel@tonic-gate
58770Sstevel@tonic-gate /* Print IPv6 address and port */
58780Sstevel@tonic-gate static char *
pr_ap6(const in6_addr_t * addr,uint_t port,char * proto,char * dst,uint_t dstlen)58790Sstevel@tonic-gate pr_ap6(const in6_addr_t *addr, uint_t port, char *proto,
58800Sstevel@tonic-gate char *dst, uint_t dstlen)
58810Sstevel@tonic-gate {
58820Sstevel@tonic-gate char *cp;
58830Sstevel@tonic-gate
58840Sstevel@tonic-gate if (IN6_IS_ADDR_UNSPECIFIED(addr)) {
58850Sstevel@tonic-gate (void) strncpy(dst, " *", dstlen);
58860Sstevel@tonic-gate dst[dstlen - 1] = 0;
58870Sstevel@tonic-gate } else {
58880Sstevel@tonic-gate (void) pr_addr6(addr, dst, dstlen);
58890Sstevel@tonic-gate }
58900Sstevel@tonic-gate /* How much room is left? */
58910Sstevel@tonic-gate cp = strchr(dst, '\0');
58920Sstevel@tonic-gate if (dst + dstlen + 1 > cp) {
58930Sstevel@tonic-gate *cp++ = '.';
58940Sstevel@tonic-gate dstlen -= (cp - dst);
58950Sstevel@tonic-gate dstlen--;
58960Sstevel@tonic-gate (void) portname(port, proto, cp, dstlen);
58970Sstevel@tonic-gate }
58980Sstevel@tonic-gate return (dst);
58990Sstevel@tonic-gate }
59000Sstevel@tonic-gate
59010Sstevel@tonic-gate /*
59020Sstevel@tonic-gate * Return the name of the network whose address is given. The address is
59030Sstevel@tonic-gate * assumed to be that of a net or subnet, not a host.
59040Sstevel@tonic-gate */
59050Sstevel@tonic-gate static char *
pr_net(uint_t addr,uint_t mask,char * dst,uint_t dstlen)59060Sstevel@tonic-gate pr_net(uint_t addr, uint_t mask, char *dst, uint_t dstlen)
59070Sstevel@tonic-gate {
59080Sstevel@tonic-gate char *cp = NULL;
59090Sstevel@tonic-gate struct netent *np = NULL;
59100Sstevel@tonic-gate struct hostent *hp = NULL;
59110Sstevel@tonic-gate uint_t net;
59120Sstevel@tonic-gate int subnetshift;
59130Sstevel@tonic-gate int error_num;
59140Sstevel@tonic-gate
59150Sstevel@tonic-gate if (addr == INADDR_ANY && mask == INADDR_ANY) {
59160Sstevel@tonic-gate (void) strncpy(dst, "default", dstlen);
59170Sstevel@tonic-gate dst[dstlen - 1] = 0;
59180Sstevel@tonic-gate return (dst);
59190Sstevel@tonic-gate }
59200Sstevel@tonic-gate
59210Sstevel@tonic-gate if (!Nflag && addr) {
59220Sstevel@tonic-gate if (mask == 0) {
59230Sstevel@tonic-gate if (IN_CLASSA(addr)) {
59240Sstevel@tonic-gate mask = (uint_t)IN_CLASSA_NET;
59250Sstevel@tonic-gate subnetshift = 8;
59260Sstevel@tonic-gate } else if (IN_CLASSB(addr)) {
59270Sstevel@tonic-gate mask = (uint_t)IN_CLASSB_NET;
59280Sstevel@tonic-gate subnetshift = 8;
59290Sstevel@tonic-gate } else {
59300Sstevel@tonic-gate mask = (uint_t)IN_CLASSC_NET;
59310Sstevel@tonic-gate subnetshift = 4;
59320Sstevel@tonic-gate }
59330Sstevel@tonic-gate /*
59340Sstevel@tonic-gate * If there are more bits than the standard mask
59350Sstevel@tonic-gate * would suggest, subnets must be in use. Guess at
59360Sstevel@tonic-gate * the subnet mask, assuming reasonable width subnet
59370Sstevel@tonic-gate * fields.
59380Sstevel@tonic-gate */
59390Sstevel@tonic-gate while (addr & ~mask)
59400Sstevel@tonic-gate /* compiler doesn't sign extend! */
59410Sstevel@tonic-gate mask = (mask | ((int)mask >> subnetshift));
59420Sstevel@tonic-gate }
59430Sstevel@tonic-gate net = addr & mask;
59440Sstevel@tonic-gate while ((mask & 1) == 0)
59450Sstevel@tonic-gate mask >>= 1, net >>= 1;
59460Sstevel@tonic-gate np = getnetbyaddr(net, AF_INET);
59470Sstevel@tonic-gate if (np && np->n_net == net)
59480Sstevel@tonic-gate cp = np->n_name;
59490Sstevel@tonic-gate else {
59500Sstevel@tonic-gate /*
59510Sstevel@tonic-gate * Look for subnets in hosts map.
59520Sstevel@tonic-gate */
59530Sstevel@tonic-gate hp = getipnodebyaddr((char *)&addr, sizeof (uint_t),
59540Sstevel@tonic-gate AF_INET, &error_num);
59550Sstevel@tonic-gate if (hp)
59560Sstevel@tonic-gate cp = hp->h_name;
59570Sstevel@tonic-gate }
59580Sstevel@tonic-gate }
59590Sstevel@tonic-gate if (cp != NULL) {
59600Sstevel@tonic-gate (void) strncpy(dst, cp, dstlen);
59610Sstevel@tonic-gate dst[dstlen - 1] = 0;
59620Sstevel@tonic-gate } else {
59630Sstevel@tonic-gate (void) inet_ntop(AF_INET, (char *)&addr, dst, dstlen);
59640Sstevel@tonic-gate }
59650Sstevel@tonic-gate if (hp != NULL)
59660Sstevel@tonic-gate freehostent(hp);
59670Sstevel@tonic-gate return (dst);
59680Sstevel@tonic-gate }
59690Sstevel@tonic-gate
59700Sstevel@tonic-gate /*
59710Sstevel@tonic-gate * Return the name of the network whose address is given.
59720Sstevel@tonic-gate * The address is assumed to be a host address.
59730Sstevel@tonic-gate */
59740Sstevel@tonic-gate static char *
pr_netaddr(uint_t addr,uint_t mask,char * dst,uint_t dstlen)59750Sstevel@tonic-gate pr_netaddr(uint_t addr, uint_t mask, char *dst, uint_t dstlen)
59760Sstevel@tonic-gate {
59770Sstevel@tonic-gate char *cp = NULL;
59780Sstevel@tonic-gate struct netent *np = NULL;
59790Sstevel@tonic-gate struct hostent *hp = NULL;
59800Sstevel@tonic-gate uint_t net;
59810Sstevel@tonic-gate uint_t netshifted;
59820Sstevel@tonic-gate int subnetshift;
59830Sstevel@tonic-gate struct in_addr in;
59840Sstevel@tonic-gate int error_num;
59850Sstevel@tonic-gate uint_t nbo_addr = addr; /* network byte order */
59860Sstevel@tonic-gate
59870Sstevel@tonic-gate addr = ntohl(addr);
59880Sstevel@tonic-gate mask = ntohl(mask);
59890Sstevel@tonic-gate if (addr == INADDR_ANY && mask == INADDR_ANY) {
59900Sstevel@tonic-gate (void) strncpy(dst, "default", dstlen);
59910Sstevel@tonic-gate dst[dstlen - 1] = 0;
59920Sstevel@tonic-gate return (dst);
59930Sstevel@tonic-gate }
59940Sstevel@tonic-gate
59950Sstevel@tonic-gate /* Figure out network portion of address (with host portion = 0) */
59960Sstevel@tonic-gate if (addr) {
59970Sstevel@tonic-gate /* Try figuring out mask if unknown (all 0s). */
59980Sstevel@tonic-gate if (mask == 0) {
59990Sstevel@tonic-gate if (IN_CLASSA(addr)) {
60000Sstevel@tonic-gate mask = (uint_t)IN_CLASSA_NET;
60010Sstevel@tonic-gate subnetshift = 8;
60020Sstevel@tonic-gate } else if (IN_CLASSB(addr)) {
60030Sstevel@tonic-gate mask = (uint_t)IN_CLASSB_NET;
60040Sstevel@tonic-gate subnetshift = 8;
60050Sstevel@tonic-gate } else {
60060Sstevel@tonic-gate mask = (uint_t)IN_CLASSC_NET;
60070Sstevel@tonic-gate subnetshift = 4;
60080Sstevel@tonic-gate }
60090Sstevel@tonic-gate /*
60100Sstevel@tonic-gate * If there are more bits than the standard mask
60110Sstevel@tonic-gate * would suggest, subnets must be in use. Guess at
60120Sstevel@tonic-gate * the subnet mask, assuming reasonable width subnet
60130Sstevel@tonic-gate * fields.
60140Sstevel@tonic-gate */
60150Sstevel@tonic-gate while (addr & ~mask)
60160Sstevel@tonic-gate /* compiler doesn't sign extend! */
60170Sstevel@tonic-gate mask = (mask | ((int)mask >> subnetshift));
60180Sstevel@tonic-gate }
60190Sstevel@tonic-gate net = netshifted = addr & mask;
60200Sstevel@tonic-gate while ((mask & 1) == 0)
60210Sstevel@tonic-gate mask >>= 1, netshifted >>= 1;
60220Sstevel@tonic-gate }
60230Sstevel@tonic-gate else
60240Sstevel@tonic-gate net = netshifted = 0;
60250Sstevel@tonic-gate
60260Sstevel@tonic-gate /* Try looking up name unless -n was specified. */
60270Sstevel@tonic-gate if (!Nflag) {
60280Sstevel@tonic-gate np = getnetbyaddr(netshifted, AF_INET);
60290Sstevel@tonic-gate if (np && np->n_net == netshifted)
60300Sstevel@tonic-gate cp = np->n_name;
60310Sstevel@tonic-gate else {
60320Sstevel@tonic-gate /*
60330Sstevel@tonic-gate * Look for subnets in hosts map.
60340Sstevel@tonic-gate */
60350Sstevel@tonic-gate hp = getipnodebyaddr((char *)&nbo_addr, sizeof (uint_t),
60360Sstevel@tonic-gate AF_INET, &error_num);
60370Sstevel@tonic-gate if (hp)
60380Sstevel@tonic-gate cp = hp->h_name;
60390Sstevel@tonic-gate }
60400Sstevel@tonic-gate
60410Sstevel@tonic-gate if (cp != NULL) {
60420Sstevel@tonic-gate (void) strncpy(dst, cp, dstlen);
60430Sstevel@tonic-gate dst[dstlen - 1] = 0;
60440Sstevel@tonic-gate if (hp != NULL)
60450Sstevel@tonic-gate freehostent(hp);
60460Sstevel@tonic-gate return (dst);
60470Sstevel@tonic-gate }
60480Sstevel@tonic-gate /*
60490Sstevel@tonic-gate * No name found for net: fallthru and return in decimal
60500Sstevel@tonic-gate * dot notation.
60510Sstevel@tonic-gate */
60520Sstevel@tonic-gate }
60530Sstevel@tonic-gate
60540Sstevel@tonic-gate in.s_addr = htonl(net);
60550Sstevel@tonic-gate (void) inet_ntop(AF_INET, (char *)&in, dst, dstlen);
60560Sstevel@tonic-gate if (hp != NULL)
60570Sstevel@tonic-gate freehostent(hp);
60580Sstevel@tonic-gate return (dst);
60590Sstevel@tonic-gate }
60600Sstevel@tonic-gate
60610Sstevel@tonic-gate /*
60620Sstevel@tonic-gate * Return the filter mode as a string:
60630Sstevel@tonic-gate * 1 => "INCLUDE"
60640Sstevel@tonic-gate * 2 => "EXCLUDE"
60650Sstevel@tonic-gate * otherwise "<unknown>"
60660Sstevel@tonic-gate */
60670Sstevel@tonic-gate static char *
fmodestr(uint_t fmode)60680Sstevel@tonic-gate fmodestr(uint_t fmode)
60690Sstevel@tonic-gate {
60700Sstevel@tonic-gate switch (fmode) {
60710Sstevel@tonic-gate case 1:
60720Sstevel@tonic-gate return ("INCLUDE");
60730Sstevel@tonic-gate case 2:
60740Sstevel@tonic-gate return ("EXCLUDE");
60750Sstevel@tonic-gate default:
60760Sstevel@tonic-gate return ("<unknown>");
60770Sstevel@tonic-gate }
60780Sstevel@tonic-gate }
60790Sstevel@tonic-gate
60801676Sjpk #define MAX_STRING_SIZE 256
60811676Sjpk
60821676Sjpk static const char *
pr_secattr(const sec_attr_list_t * attrs)60831676Sjpk pr_secattr(const sec_attr_list_t *attrs)
60841676Sjpk {
60851676Sjpk int i;
60861676Sjpk char buf[MAX_STRING_SIZE + 1], *cp;
60871676Sjpk static char *sbuf;
60881676Sjpk static size_t sbuf_len;
60891676Sjpk struct rtsa_s rtsa;
60901676Sjpk const sec_attr_list_t *aptr;
60911676Sjpk
60921676Sjpk if (!RSECflag || attrs == NULL)
60931676Sjpk return ("");
60941676Sjpk
60951676Sjpk for (aptr = attrs, i = 1; aptr != NULL; aptr = aptr->sal_next)
60961676Sjpk i += MAX_STRING_SIZE;
60971676Sjpk if (i > sbuf_len) {
60981676Sjpk cp = realloc(sbuf, i);
60991676Sjpk if (cp == NULL) {
61001676Sjpk perror("realloc security attribute buffer");
61011676Sjpk return ("");
61021676Sjpk }
61031676Sjpk sbuf_len = i;
61041676Sjpk sbuf = cp;
61051676Sjpk }
61061676Sjpk
61071676Sjpk cp = sbuf;
61081676Sjpk while (attrs != NULL) {
61091676Sjpk const mib2_ipAttributeEntry_t *iae = attrs->sal_attr;
61101676Sjpk
61111676Sjpk /* note: effectively hard-coded in rtsa_keyword */
61121676Sjpk rtsa.rtsa_mask = RTSA_CIPSO | RTSA_SLRANGE | RTSA_DOI;
61131676Sjpk rtsa.rtsa_slrange = iae->iae_slrange;
61141676Sjpk rtsa.rtsa_doi = iae->iae_doi;
61151676Sjpk
61161676Sjpk (void) snprintf(cp, MAX_STRING_SIZE,
61171676Sjpk "<%s>%s ", rtsa_to_str(&rtsa, buf, sizeof (buf)),
61181676Sjpk attrs->sal_next == NULL ? "" : ",");
61191676Sjpk cp += strlen(cp);
61201676Sjpk attrs = attrs->sal_next;
61211676Sjpk }
61221676Sjpk *cp = '\0';
61231676Sjpk
61241676Sjpk return (sbuf);
61251676Sjpk }
61261676Sjpk
61270Sstevel@tonic-gate /*
61280Sstevel@tonic-gate * Pretty print a port number. If the Nflag was
61290Sstevel@tonic-gate * specified, use numbers instead of names.
61300Sstevel@tonic-gate */
61310Sstevel@tonic-gate static char *
portname(uint_t port,char * proto,char * dst,uint_t dstlen)61320Sstevel@tonic-gate portname(uint_t port, char *proto, char *dst, uint_t dstlen)
61330Sstevel@tonic-gate {
61340Sstevel@tonic-gate struct servent *sp = NULL;
61350Sstevel@tonic-gate
61360Sstevel@tonic-gate if (!Nflag && port)
61370Sstevel@tonic-gate sp = getservbyport(htons(port), proto);
61380Sstevel@tonic-gate if (sp || port == 0)
61390Sstevel@tonic-gate (void) snprintf(dst, dstlen, "%.*s", MAXHOSTNAMELEN,
61408485SPeter.Memishian@Sun.COM sp ? sp->s_name : "*");
61410Sstevel@tonic-gate else
61420Sstevel@tonic-gate (void) snprintf(dst, dstlen, "%d", port);
61430Sstevel@tonic-gate dst[dstlen - 1] = 0;
61440Sstevel@tonic-gate return (dst);
61450Sstevel@tonic-gate }
61460Sstevel@tonic-gate
61470Sstevel@tonic-gate /*PRINTFLIKE2*/
61480Sstevel@tonic-gate void
fail(int do_perror,char * message,...)61490Sstevel@tonic-gate fail(int do_perror, char *message, ...)
61500Sstevel@tonic-gate {
61510Sstevel@tonic-gate va_list args;
61520Sstevel@tonic-gate
61530Sstevel@tonic-gate va_start(args, message);
61540Sstevel@tonic-gate (void) fputs("netstat: ", stderr);
61550Sstevel@tonic-gate (void) vfprintf(stderr, message, args);
61560Sstevel@tonic-gate va_end(args);
61570Sstevel@tonic-gate if (do_perror)
61580Sstevel@tonic-gate (void) fprintf(stderr, ": %s", strerror(errno));
61590Sstevel@tonic-gate (void) fputc('\n', stderr);
61600Sstevel@tonic-gate exit(2);
61610Sstevel@tonic-gate }
61620Sstevel@tonic-gate
61630Sstevel@tonic-gate /*
61640Sstevel@tonic-gate * Return value of named statistic for given kstat_named kstat;
61650Sstevel@tonic-gate * return 0LL if named statistic is not in list (use "ll" as a
61660Sstevel@tonic-gate * type qualifier when printing 64-bit int's with printf() )
61670Sstevel@tonic-gate */
61680Sstevel@tonic-gate static uint64_t
kstat_named_value(kstat_t * ksp,char * name)61690Sstevel@tonic-gate kstat_named_value(kstat_t *ksp, char *name)
61700Sstevel@tonic-gate {
61710Sstevel@tonic-gate kstat_named_t *knp;
61720Sstevel@tonic-gate uint64_t value;
61730Sstevel@tonic-gate
61740Sstevel@tonic-gate if (ksp == NULL)
61750Sstevel@tonic-gate return (0LL);
61760Sstevel@tonic-gate
61770Sstevel@tonic-gate knp = kstat_data_lookup(ksp, name);
61780Sstevel@tonic-gate if (knp == NULL)
61790Sstevel@tonic-gate return (0LL);
61800Sstevel@tonic-gate
61810Sstevel@tonic-gate switch (knp->data_type) {
61820Sstevel@tonic-gate case KSTAT_DATA_INT32:
61830Sstevel@tonic-gate case KSTAT_DATA_UINT32:
61840Sstevel@tonic-gate value = (uint64_t)(knp->value.ui32);
61850Sstevel@tonic-gate break;
61860Sstevel@tonic-gate case KSTAT_DATA_INT64:
61870Sstevel@tonic-gate case KSTAT_DATA_UINT64:
61880Sstevel@tonic-gate value = knp->value.ui64;
61890Sstevel@tonic-gate break;
61900Sstevel@tonic-gate default:
61910Sstevel@tonic-gate value = 0LL;
61920Sstevel@tonic-gate break;
61930Sstevel@tonic-gate }
61940Sstevel@tonic-gate
61950Sstevel@tonic-gate return (value);
61960Sstevel@tonic-gate }
61970Sstevel@tonic-gate
61980Sstevel@tonic-gate kid_t
safe_kstat_read(kstat_ctl_t * kc,kstat_t * ksp,void * data)61990Sstevel@tonic-gate safe_kstat_read(kstat_ctl_t *kc, kstat_t *ksp, void *data)
62000Sstevel@tonic-gate {
62010Sstevel@tonic-gate kid_t kstat_chain_id = kstat_read(kc, ksp, data);
62020Sstevel@tonic-gate
62030Sstevel@tonic-gate if (kstat_chain_id == -1)
62040Sstevel@tonic-gate fail(1, "kstat_read(%p, '%s') failed", (void *)kc,
62050Sstevel@tonic-gate ksp->ks_name);
62060Sstevel@tonic-gate return (kstat_chain_id);
62070Sstevel@tonic-gate }
62080Sstevel@tonic-gate
62090Sstevel@tonic-gate /*
62100Sstevel@tonic-gate * Parse a list of IRE flag characters into a bit field.
62110Sstevel@tonic-gate */
62120Sstevel@tonic-gate static uint_t
flag_bits(const char * arg)62130Sstevel@tonic-gate flag_bits(const char *arg)
62140Sstevel@tonic-gate {
62150Sstevel@tonic-gate const char *cp;
62160Sstevel@tonic-gate uint_t val;
62170Sstevel@tonic-gate
62180Sstevel@tonic-gate if (*arg == '\0')
62190Sstevel@tonic-gate fatal(1, "missing flag list\n");
62200Sstevel@tonic-gate
62210Sstevel@tonic-gate val = 0;
62220Sstevel@tonic-gate while (*arg != '\0') {
62230Sstevel@tonic-gate if ((cp = strchr(flag_list, *arg)) == NULL)
62240Sstevel@tonic-gate fatal(1, "%c: illegal flag\n", *arg);
62250Sstevel@tonic-gate val |= 1 << (cp - flag_list);
62260Sstevel@tonic-gate arg++;
62270Sstevel@tonic-gate }
62280Sstevel@tonic-gate return (val);
62290Sstevel@tonic-gate }
62300Sstevel@tonic-gate
62310Sstevel@tonic-gate /*
62320Sstevel@tonic-gate * Handle -f argument. Validate input format, sort by keyword, and
62330Sstevel@tonic-gate * save off digested results.
62340Sstevel@tonic-gate */
62350Sstevel@tonic-gate static void
process_filter(char * arg)62360Sstevel@tonic-gate process_filter(char *arg)
62370Sstevel@tonic-gate {
62380Sstevel@tonic-gate int idx;
62390Sstevel@tonic-gate int klen = 0;
62400Sstevel@tonic-gate char *cp, *cp2;
62410Sstevel@tonic-gate int val;
62420Sstevel@tonic-gate filter_t *newf;
62430Sstevel@tonic-gate struct hostent *hp;
62440Sstevel@tonic-gate int error_num;
62450Sstevel@tonic-gate uint8_t *ucp;
62460Sstevel@tonic-gate int maxv;
62470Sstevel@tonic-gate
62480Sstevel@tonic-gate /* Look up the keyword first */
62490Sstevel@tonic-gate if (strchr(arg, ':') == NULL) {
62500Sstevel@tonic-gate idx = FK_AF;
62510Sstevel@tonic-gate } else {
62520Sstevel@tonic-gate for (idx = 0; idx < NFILTERKEYS; idx++) {
62530Sstevel@tonic-gate klen = strlen(filter_keys[idx]);
62540Sstevel@tonic-gate if (strncmp(filter_keys[idx], arg, klen) == 0 &&
62550Sstevel@tonic-gate arg[klen] == ':')
62560Sstevel@tonic-gate break;
62570Sstevel@tonic-gate }
62580Sstevel@tonic-gate if (idx >= NFILTERKEYS)
62590Sstevel@tonic-gate fatal(1, "%s: unknown filter keyword\n", arg);
62600Sstevel@tonic-gate
62610Sstevel@tonic-gate /* Advance past keyword and separator. */
62620Sstevel@tonic-gate arg += klen + 1;
62630Sstevel@tonic-gate }
62640Sstevel@tonic-gate
62650Sstevel@tonic-gate if ((newf = malloc(sizeof (*newf))) == NULL) {
62660Sstevel@tonic-gate perror("filter");
62670Sstevel@tonic-gate exit(1);
62680Sstevel@tonic-gate }
62690Sstevel@tonic-gate switch (idx) {
62700Sstevel@tonic-gate case FK_AF:
62710Sstevel@tonic-gate if (strcmp(arg, "inet") == 0) {
62720Sstevel@tonic-gate newf->u.f_family = AF_INET;
62730Sstevel@tonic-gate } else if (strcmp(arg, "inet6") == 0) {
62740Sstevel@tonic-gate newf->u.f_family = AF_INET6;
62750Sstevel@tonic-gate } else if (strcmp(arg, "unix") == 0) {
62760Sstevel@tonic-gate newf->u.f_family = AF_UNIX;
62770Sstevel@tonic-gate } else {
62780Sstevel@tonic-gate newf->u.f_family = strtol(arg, &cp, 0);
62790Sstevel@tonic-gate if (arg == cp || *cp != '\0')
62800Sstevel@tonic-gate fatal(1, "%s: unknown address family.\n", arg);
62810Sstevel@tonic-gate }
62820Sstevel@tonic-gate break;
62830Sstevel@tonic-gate
62840Sstevel@tonic-gate case FK_OUTIF:
62850Sstevel@tonic-gate if (strcmp(arg, "none") == 0) {
62860Sstevel@tonic-gate newf->u.f_ifname = NULL;
62870Sstevel@tonic-gate break;
62880Sstevel@tonic-gate }
62890Sstevel@tonic-gate if (strcmp(arg, "any") == 0) {
62900Sstevel@tonic-gate newf->u.f_ifname = "";
62910Sstevel@tonic-gate break;
62920Sstevel@tonic-gate }
62930Sstevel@tonic-gate val = strtol(arg, &cp, 0);
62940Sstevel@tonic-gate if (val <= 0 || arg == cp || cp[0] != '\0') {
62950Sstevel@tonic-gate if ((val = if_nametoindex(arg)) == 0) {
62960Sstevel@tonic-gate perror(arg);
62970Sstevel@tonic-gate exit(1);
62980Sstevel@tonic-gate }
62990Sstevel@tonic-gate }
63000Sstevel@tonic-gate newf->u.f_ifname = arg;
63010Sstevel@tonic-gate break;
63020Sstevel@tonic-gate
63030Sstevel@tonic-gate case FK_DST:
63040Sstevel@tonic-gate V4MASK_TO_V6(IP_HOST_MASK, newf->u.a.f_mask);
63050Sstevel@tonic-gate if (strcmp(arg, "any") == 0) {
63060Sstevel@tonic-gate /* Special semantics; any address *but* zero */
63070Sstevel@tonic-gate newf->u.a.f_address = NULL;
63080Sstevel@tonic-gate (void) memset(&newf->u.a.f_mask, 0,
63090Sstevel@tonic-gate sizeof (newf->u.a.f_mask));
63100Sstevel@tonic-gate break;
63110Sstevel@tonic-gate }
63120Sstevel@tonic-gate if (strcmp(arg, "none") == 0) {
63130Sstevel@tonic-gate newf->u.a.f_address = NULL;
63140Sstevel@tonic-gate break;
63150Sstevel@tonic-gate }
63160Sstevel@tonic-gate if ((cp = strrchr(arg, '/')) != NULL)
63170Sstevel@tonic-gate *cp++ = '\0';
63180Sstevel@tonic-gate hp = getipnodebyname(arg, AF_INET6, AI_V4MAPPED|AI_ALL,
63190Sstevel@tonic-gate &error_num);
63200Sstevel@tonic-gate if (hp == NULL)
63210Sstevel@tonic-gate fatal(1, "%s: invalid or unknown host address\n", arg);
63220Sstevel@tonic-gate newf->u.a.f_address = hp;
63230Sstevel@tonic-gate if (cp == NULL) {
63240Sstevel@tonic-gate V4MASK_TO_V6(IP_HOST_MASK, newf->u.a.f_mask);
63250Sstevel@tonic-gate } else {
63260Sstevel@tonic-gate val = strtol(cp, &cp2, 0);
63270Sstevel@tonic-gate if (cp != cp2 && cp2[0] == '\0') {
63280Sstevel@tonic-gate /*
63290Sstevel@tonic-gate * If decode as "/n" works, then translate
63300Sstevel@tonic-gate * into a mask.
63310Sstevel@tonic-gate */
63320Sstevel@tonic-gate if (hp->h_addr_list[0] != NULL &&
63330Sstevel@tonic-gate /* LINTED: (note 1) */
63348485SPeter.Memishian@Sun.COM IN6_IS_ADDR_V4MAPPED((in6_addr_t *)
63358485SPeter.Memishian@Sun.COM hp->h_addr_list[0])) {
63360Sstevel@tonic-gate maxv = IP_ABITS;
63370Sstevel@tonic-gate } else {
63380Sstevel@tonic-gate maxv = IPV6_ABITS;
63390Sstevel@tonic-gate }
63400Sstevel@tonic-gate if (val < 0 || val >= maxv)
63410Sstevel@tonic-gate fatal(1, "%d: not in range 0 to %d\n",
63420Sstevel@tonic-gate val, maxv - 1);
63430Sstevel@tonic-gate if (maxv == IP_ABITS)
63440Sstevel@tonic-gate val += IPV6_ABITS - IP_ABITS;
63450Sstevel@tonic-gate ucp = newf->u.a.f_mask.s6_addr;
63460Sstevel@tonic-gate while (val >= 8)
63470Sstevel@tonic-gate *ucp++ = 0xff, val -= 8;
63480Sstevel@tonic-gate *ucp++ = (0xff << (8 - val)) & 0xff;
63490Sstevel@tonic-gate while (ucp < newf->u.a.f_mask.s6_addr +
63500Sstevel@tonic-gate sizeof (newf->u.a.f_mask.s6_addr))
63510Sstevel@tonic-gate *ucp++ = 0;
63520Sstevel@tonic-gate /* Otherwise, try as numeric address */
63530Sstevel@tonic-gate } else if (inet_pton(AF_INET6,
63540Sstevel@tonic-gate cp, &newf->u.a.f_mask) <= 0) {
63550Sstevel@tonic-gate fatal(1, "%s: illegal mask format\n", cp);
63560Sstevel@tonic-gate }
63570Sstevel@tonic-gate }
63580Sstevel@tonic-gate break;
63590Sstevel@tonic-gate
63600Sstevel@tonic-gate case FK_FLAGS:
63610Sstevel@tonic-gate if (*arg == '+') {
63620Sstevel@tonic-gate newf->u.f.f_flagset = flag_bits(arg + 1);
63630Sstevel@tonic-gate newf->u.f.f_flagclear = 0;
63640Sstevel@tonic-gate } else if (*arg == '-') {
63650Sstevel@tonic-gate newf->u.f.f_flagset = 0;
63660Sstevel@tonic-gate newf->u.f.f_flagclear = flag_bits(arg + 1);
63670Sstevel@tonic-gate } else {
63680Sstevel@tonic-gate newf->u.f.f_flagset = flag_bits(arg);
63690Sstevel@tonic-gate newf->u.f.f_flagclear = ~newf->u.f.f_flagset;
63700Sstevel@tonic-gate }
63710Sstevel@tonic-gate break;
63720Sstevel@tonic-gate
63730Sstevel@tonic-gate default:
63740Sstevel@tonic-gate assert(0);
63750Sstevel@tonic-gate }
63760Sstevel@tonic-gate newf->f_next = filters[idx];
63770Sstevel@tonic-gate filters[idx] = newf;
63780Sstevel@tonic-gate }
63790Sstevel@tonic-gate
63800Sstevel@tonic-gate /* Determine if user wants this address family printed. */
63810Sstevel@tonic-gate static boolean_t
family_selected(int family)63820Sstevel@tonic-gate family_selected(int family)
63830Sstevel@tonic-gate {
63840Sstevel@tonic-gate const filter_t *fp;
63850Sstevel@tonic-gate
63860Sstevel@tonic-gate if (v4compat && family == AF_INET6)
63870Sstevel@tonic-gate return (B_FALSE);
63880Sstevel@tonic-gate if ((fp = filters[FK_AF]) == NULL)
63890Sstevel@tonic-gate return (B_TRUE);
63900Sstevel@tonic-gate while (fp != NULL) {
63910Sstevel@tonic-gate if (fp->u.f_family == family)
63920Sstevel@tonic-gate return (B_TRUE);
63930Sstevel@tonic-gate fp = fp->f_next;
63940Sstevel@tonic-gate }
63950Sstevel@tonic-gate return (B_FALSE);
63960Sstevel@tonic-gate }
63970Sstevel@tonic-gate
63980Sstevel@tonic-gate /*
63998485SPeter.Memishian@Sun.COM * Convert the interface index to a string using the buffer `ifname', which
64008485SPeter.Memishian@Sun.COM * must be at least LIFNAMSIZ bytes. We first try to map it to name. If that
64018485SPeter.Memishian@Sun.COM * fails (e.g., because we're inside a zone and it does not have access to
64028485SPeter.Memishian@Sun.COM * interface for the index in question), just return "if#<num>".
64038485SPeter.Memishian@Sun.COM */
64048485SPeter.Memishian@Sun.COM static char *
ifindex2str(uint_t ifindex,char * ifname)64058485SPeter.Memishian@Sun.COM ifindex2str(uint_t ifindex, char *ifname)
64068485SPeter.Memishian@Sun.COM {
64078485SPeter.Memishian@Sun.COM if (if_indextoname(ifindex, ifname) == NULL)
64088485SPeter.Memishian@Sun.COM (void) snprintf(ifname, LIFNAMSIZ, "if#%d", ifindex);
64098485SPeter.Memishian@Sun.COM
64108485SPeter.Memishian@Sun.COM return (ifname);
64118485SPeter.Memishian@Sun.COM }
64128485SPeter.Memishian@Sun.COM
64138485SPeter.Memishian@Sun.COM /*
64140Sstevel@tonic-gate * print the usage line
64150Sstevel@tonic-gate */
64160Sstevel@tonic-gate static void
usage(char * cmdname)64170Sstevel@tonic-gate usage(char *cmdname)
64180Sstevel@tonic-gate {
641910265SKrishnendu.Sadhukhan@Sun.COM (void) fprintf(stderr, "usage: %s [-anv] [-f address_family] "
642010265SKrishnendu.Sadhukhan@Sun.COM "[-T d|u]\n", cmdname);
64210Sstevel@tonic-gate (void) fprintf(stderr, " %s [-n] [-f address_family] "
642210265SKrishnendu.Sadhukhan@Sun.COM "[-P protocol] [-T d|u] [-g | -p | -s [interval [count]]]\n",
642310265SKrishnendu.Sadhukhan@Sun.COM cmdname);
642410265SKrishnendu.Sadhukhan@Sun.COM (void) fprintf(stderr, " %s -m [-v] [-T d|u] "
64250Sstevel@tonic-gate "[interval [count]]\n", cmdname);
64260Sstevel@tonic-gate (void) fprintf(stderr, " %s -i [-I interface] [-an] "
642710265SKrishnendu.Sadhukhan@Sun.COM "[-f address_family] [-T d|u] [interval [count]]\n", cmdname);
64280Sstevel@tonic-gate (void) fprintf(stderr, " %s -r [-anv] "
642910265SKrishnendu.Sadhukhan@Sun.COM "[-f address_family|filter] [-T d|u]\n", cmdname);
643010265SKrishnendu.Sadhukhan@Sun.COM (void) fprintf(stderr, " %s -M [-ns] [-f address_family] "
643110265SKrishnendu.Sadhukhan@Sun.COM "[-T d|u]\n", cmdname);
64320Sstevel@tonic-gate (void) fprintf(stderr, " %s -D [-I interface] "
643310265SKrishnendu.Sadhukhan@Sun.COM "[-f address_family] [-T d|u]\n", cmdname);
64340Sstevel@tonic-gate exit(EXIT_FAILURE);
64350Sstevel@tonic-gate }
64360Sstevel@tonic-gate
64370Sstevel@tonic-gate /*
64380Sstevel@tonic-gate * fatal: print error message to stderr and
64390Sstevel@tonic-gate * call exit(errcode)
64400Sstevel@tonic-gate */
64410Sstevel@tonic-gate /*PRINTFLIKE2*/
64420Sstevel@tonic-gate static void
fatal(int errcode,char * format,...)64431676Sjpk fatal(int errcode, char *format, ...)
64441676Sjpk {
64450Sstevel@tonic-gate va_list argp;
64460Sstevel@tonic-gate
64470Sstevel@tonic-gate if (format == NULL)
64480Sstevel@tonic-gate return;
64490Sstevel@tonic-gate
64500Sstevel@tonic-gate va_start(argp, format);
64510Sstevel@tonic-gate (void) vfprintf(stderr, format, argp);
64520Sstevel@tonic-gate va_end(argp);
64530Sstevel@tonic-gate
64540Sstevel@tonic-gate exit(errcode);
64550Sstevel@tonic-gate }
6456