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 /* 22*8348SEric.Yu@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #include <mdb/mdb_modapi.h> 270Sstevel@tonic-gate #include <mdb/mdb_ks.h> 280Sstevel@tonic-gate #include <mdb/mdb_ctf.h> 290Sstevel@tonic-gate #include <sys/types.h> 300Sstevel@tonic-gate #include <sys/tihdr.h> 310Sstevel@tonic-gate #include <inet/led.h> 320Sstevel@tonic-gate #include <inet/common.h> 330Sstevel@tonic-gate #include <netinet/in.h> 340Sstevel@tonic-gate #include <netinet/ip6.h> 350Sstevel@tonic-gate #include <netinet/icmp6.h> 360Sstevel@tonic-gate #include <inet/ip.h> 370Sstevel@tonic-gate #include <inet/ip6.h> 380Sstevel@tonic-gate #include <inet/ipclassifier.h> 390Sstevel@tonic-gate #include <inet/tcp.h> 400Sstevel@tonic-gate #include <sys/stream.h> 410Sstevel@tonic-gate #include <sys/vfs.h> 420Sstevel@tonic-gate #include <sys/stropts.h> 430Sstevel@tonic-gate #include <sys/tpicommon.h> 440Sstevel@tonic-gate #include <sys/socket.h> 450Sstevel@tonic-gate #include <sys/socketvar.h> 460Sstevel@tonic-gate #include <sys/cred_impl.h> 470Sstevel@tonic-gate #include <inet/udp_impl.h> 480Sstevel@tonic-gate #include <inet/arp_impl.h> 490Sstevel@tonic-gate #include <inet/rawip_impl.h> 500Sstevel@tonic-gate #include <inet/mi.h> 51*8348SEric.Yu@Sun.COM #include <fs/sockfs/socktpi_impl.h> 520Sstevel@tonic-gate 530Sstevel@tonic-gate #define ADDR_V6_WIDTH 23 540Sstevel@tonic-gate #define ADDR_V4_WIDTH 15 550Sstevel@tonic-gate 561676Sjpk #define NETSTAT_ALL 0x01 571676Sjpk #define NETSTAT_VERBOSE 0x02 581676Sjpk #define NETSTAT_ROUTE 0x04 591676Sjpk #define NETSTAT_V4 0x08 601676Sjpk #define NETSTAT_V6 0x10 611676Sjpk #define NETSTAT_UNIX 0x20 621676Sjpk 631676Sjpk #define NETSTAT_FIRST 0x80000000u 640Sstevel@tonic-gate 653448Sdh155122 663448Sdh155122 /* Walkers for various *_stack_t */ 673448Sdh155122 int 683448Sdh155122 ar_stacks_walk_init(mdb_walk_state_t *wsp) 693448Sdh155122 { 703448Sdh155122 if (mdb_layered_walk("netstack", wsp) == -1) { 713448Sdh155122 mdb_warn("can't walk 'netstack'"); 723448Sdh155122 return (WALK_ERR); 733448Sdh155122 } 743448Sdh155122 return (WALK_NEXT); 753448Sdh155122 } 763448Sdh155122 773448Sdh155122 int 783448Sdh155122 ar_stacks_walk_step(mdb_walk_state_t *wsp) 793448Sdh155122 { 803448Sdh155122 uintptr_t kaddr; 813448Sdh155122 netstack_t nss; 823448Sdh155122 833448Sdh155122 if (mdb_vread(&nss, sizeof (nss), wsp->walk_addr) == -1) { 843448Sdh155122 mdb_warn("can't read netstack at %p", wsp->walk_addr); 853448Sdh155122 return (WALK_ERR); 863448Sdh155122 } 873448Sdh155122 kaddr = (uintptr_t)nss.netstack_modules[NS_ARP]; 883448Sdh155122 return (wsp->walk_callback(kaddr, wsp->walk_layer, wsp->walk_cbdata)); 893448Sdh155122 } 903448Sdh155122 913448Sdh155122 int 923448Sdh155122 icmp_stacks_walk_init(mdb_walk_state_t *wsp) 933448Sdh155122 { 943448Sdh155122 if (mdb_layered_walk("netstack", wsp) == -1) { 953448Sdh155122 mdb_warn("can't walk 'netstack'"); 963448Sdh155122 return (WALK_ERR); 973448Sdh155122 } 983448Sdh155122 return (WALK_NEXT); 993448Sdh155122 } 1003448Sdh155122 1013448Sdh155122 int 1023448Sdh155122 icmp_stacks_walk_step(mdb_walk_state_t *wsp) 1033448Sdh155122 { 1043448Sdh155122 uintptr_t kaddr; 1053448Sdh155122 netstack_t nss; 1063448Sdh155122 1073448Sdh155122 if (mdb_vread(&nss, sizeof (nss), wsp->walk_addr) == -1) { 1083448Sdh155122 mdb_warn("can't read netstack at %p", wsp->walk_addr); 1093448Sdh155122 return (WALK_ERR); 1103448Sdh155122 } 1113448Sdh155122 kaddr = (uintptr_t)nss.netstack_modules[NS_ICMP]; 1123448Sdh155122 return (wsp->walk_callback(kaddr, wsp->walk_layer, wsp->walk_cbdata)); 1133448Sdh155122 } 1143448Sdh155122 1153448Sdh155122 int 1163448Sdh155122 tcp_stacks_walk_init(mdb_walk_state_t *wsp) 1173448Sdh155122 { 1183448Sdh155122 if (mdb_layered_walk("netstack", wsp) == -1) { 1193448Sdh155122 mdb_warn("can't walk 'netstack'"); 1203448Sdh155122 return (WALK_ERR); 1213448Sdh155122 } 1223448Sdh155122 return (WALK_NEXT); 1233448Sdh155122 } 1243448Sdh155122 1253448Sdh155122 int 1263448Sdh155122 tcp_stacks_walk_step(mdb_walk_state_t *wsp) 1273448Sdh155122 { 1283448Sdh155122 uintptr_t kaddr; 1293448Sdh155122 netstack_t nss; 1303448Sdh155122 1313448Sdh155122 if (mdb_vread(&nss, sizeof (nss), wsp->walk_addr) == -1) { 1323448Sdh155122 mdb_warn("can't read netstack at %p", wsp->walk_addr); 1333448Sdh155122 return (WALK_ERR); 1343448Sdh155122 } 1353448Sdh155122 kaddr = (uintptr_t)nss.netstack_modules[NS_TCP]; 1363448Sdh155122 return (wsp->walk_callback(kaddr, wsp->walk_layer, wsp->walk_cbdata)); 1373448Sdh155122 } 1383448Sdh155122 1393448Sdh155122 int 1403448Sdh155122 udp_stacks_walk_init(mdb_walk_state_t *wsp) 1413448Sdh155122 { 1423448Sdh155122 if (mdb_layered_walk("netstack", wsp) == -1) { 1433448Sdh155122 mdb_warn("can't walk 'netstack'"); 1443448Sdh155122 return (WALK_ERR); 1453448Sdh155122 } 1463448Sdh155122 return (WALK_NEXT); 1473448Sdh155122 } 1483448Sdh155122 1493448Sdh155122 int 1503448Sdh155122 udp_stacks_walk_step(mdb_walk_state_t *wsp) 1513448Sdh155122 { 1523448Sdh155122 uintptr_t kaddr; 1533448Sdh155122 netstack_t nss; 1543448Sdh155122 1553448Sdh155122 if (mdb_vread(&nss, sizeof (nss), wsp->walk_addr) == -1) { 1563448Sdh155122 mdb_warn("can't read netstack at %p", wsp->walk_addr); 1573448Sdh155122 return (WALK_ERR); 1583448Sdh155122 } 1593448Sdh155122 kaddr = (uintptr_t)nss.netstack_modules[NS_UDP]; 1603448Sdh155122 return (wsp->walk_callback(kaddr, wsp->walk_layer, wsp->walk_cbdata)); 1613448Sdh155122 } 1623448Sdh155122 1630Sstevel@tonic-gate /* 1640Sstevel@tonic-gate * Print an IPv4 address and port number in a compact and easy to read format 1650Sstevel@tonic-gate * The arguments are in network byte order 1660Sstevel@tonic-gate */ 1670Sstevel@tonic-gate static void 1680Sstevel@tonic-gate net_ipv4addrport_pr(const in6_addr_t *nipv6addr, in_port_t nport) 1690Sstevel@tonic-gate { 1700Sstevel@tonic-gate uint32_t naddr = V4_PART_OF_V6((*nipv6addr)); 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate mdb_nhconvert(&nport, &nport, sizeof (nport)); 1730Sstevel@tonic-gate mdb_printf("%*I.%-5hu", ADDR_V4_WIDTH, naddr, nport); 1740Sstevel@tonic-gate } 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate /* 1770Sstevel@tonic-gate * Print an IPv6 address and port number in a compact and easy to read format 1780Sstevel@tonic-gate * The arguments are in network byte order 1790Sstevel@tonic-gate */ 1800Sstevel@tonic-gate static void 1810Sstevel@tonic-gate net_ipv6addrport_pr(const in6_addr_t *naddr, in_port_t nport) 1820Sstevel@tonic-gate { 1830Sstevel@tonic-gate mdb_nhconvert(&nport, &nport, sizeof (nport)); 1840Sstevel@tonic-gate mdb_printf("%*N.%-5hu", ADDR_V6_WIDTH, naddr, nport); 1850Sstevel@tonic-gate } 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate static int 1880Sstevel@tonic-gate net_tcp_active(const tcp_t *tcp) 1890Sstevel@tonic-gate { 1900Sstevel@tonic-gate return (tcp->tcp_state >= TCPS_ESTABLISHED); 1910Sstevel@tonic-gate } 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate static int 1940Sstevel@tonic-gate net_tcp_ipv4(const tcp_t *tcp) 1950Sstevel@tonic-gate { 1960Sstevel@tonic-gate return ((tcp->tcp_ipversion == IPV4_VERSION) || 1970Sstevel@tonic-gate (IN6_IS_ADDR_UNSPECIFIED(&tcp->tcp_ip_src_v6) && 1980Sstevel@tonic-gate (tcp->tcp_state <= TCPS_LISTEN))); 1990Sstevel@tonic-gate } 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate static int 2020Sstevel@tonic-gate net_tcp_ipv6(const tcp_t *tcp) 2030Sstevel@tonic-gate { 2040Sstevel@tonic-gate return (tcp->tcp_ipversion == IPV6_VERSION); 2050Sstevel@tonic-gate } 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate static int 2080Sstevel@tonic-gate net_udp_active(const udp_t *udp) 2090Sstevel@tonic-gate { 210741Smasputra return ((udp->udp_state == TS_IDLE) || 211741Smasputra (udp->udp_state == TS_DATA_XFER)); 2120Sstevel@tonic-gate } 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate static int 2150Sstevel@tonic-gate net_udp_ipv4(const udp_t *udp) 2160Sstevel@tonic-gate { 2170Sstevel@tonic-gate return ((udp->udp_ipversion == IPV4_VERSION) || 2180Sstevel@tonic-gate (IN6_IS_ADDR_UNSPECIFIED(&udp->udp_v6src) && 2190Sstevel@tonic-gate (udp->udp_state <= TS_IDLE))); 2200Sstevel@tonic-gate } 2210Sstevel@tonic-gate 2220Sstevel@tonic-gate static int 2230Sstevel@tonic-gate net_udp_ipv6(const udp_t *udp) 2240Sstevel@tonic-gate { 2250Sstevel@tonic-gate return (udp->udp_ipversion == IPV6_VERSION); 2260Sstevel@tonic-gate } 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate int 2290Sstevel@tonic-gate sonode_walk_init(mdb_walk_state_t *wsp) 2300Sstevel@tonic-gate { 2310Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 2320Sstevel@tonic-gate GElf_Sym sym; 2330Sstevel@tonic-gate struct socklist *slp; 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate if (mdb_lookup_by_obj("sockfs", "socklist", &sym) == -1) { 2360Sstevel@tonic-gate mdb_warn("failed to lookup sockfs`socklist"); 2370Sstevel@tonic-gate return (WALK_ERR); 2380Sstevel@tonic-gate } 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate slp = (struct socklist *)(uintptr_t)sym.st_value; 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate if (mdb_vread(&wsp->walk_addr, sizeof (wsp->walk_addr), 2430Sstevel@tonic-gate (uintptr_t)&slp->sl_list) == -1) { 2440Sstevel@tonic-gate mdb_warn("failed to read address of initial sonode " 2450Sstevel@tonic-gate "at %p", &slp->sl_list); 2460Sstevel@tonic-gate return (WALK_ERR); 2470Sstevel@tonic-gate } 2480Sstevel@tonic-gate } 2490Sstevel@tonic-gate 250*8348SEric.Yu@Sun.COM wsp->walk_data = mdb_alloc(sizeof (struct sotpi_sonode), UM_SLEEP); 2510Sstevel@tonic-gate return (WALK_NEXT); 2520Sstevel@tonic-gate } 2530Sstevel@tonic-gate 2540Sstevel@tonic-gate int 2550Sstevel@tonic-gate sonode_walk_step(mdb_walk_state_t *wsp) 2560Sstevel@tonic-gate { 2570Sstevel@tonic-gate int status; 258*8348SEric.Yu@Sun.COM struct sotpi_sonode *stp; 2590Sstevel@tonic-gate 2600Sstevel@tonic-gate if (wsp->walk_addr == NULL) 2610Sstevel@tonic-gate return (WALK_DONE); 2620Sstevel@tonic-gate 263*8348SEric.Yu@Sun.COM if (mdb_vread(wsp->walk_data, sizeof (struct sotpi_sonode), 2640Sstevel@tonic-gate wsp->walk_addr) == -1) { 2650Sstevel@tonic-gate mdb_warn("failed to read sonode at %p", wsp->walk_addr); 2660Sstevel@tonic-gate return (WALK_ERR); 2670Sstevel@tonic-gate } 2680Sstevel@tonic-gate 2690Sstevel@tonic-gate status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data, 2700Sstevel@tonic-gate wsp->walk_cbdata); 2710Sstevel@tonic-gate 272*8348SEric.Yu@Sun.COM stp = wsp->walk_data; 2730Sstevel@tonic-gate 274*8348SEric.Yu@Sun.COM wsp->walk_addr = (uintptr_t)stp->st_info.sti_next_so; 2750Sstevel@tonic-gate return (status); 2760Sstevel@tonic-gate } 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate void 2790Sstevel@tonic-gate sonode_walk_fini(mdb_walk_state_t *wsp) 2800Sstevel@tonic-gate { 281*8348SEric.Yu@Sun.COM mdb_free(wsp->walk_data, sizeof (struct sotpi_sonode)); 2820Sstevel@tonic-gate } 2830Sstevel@tonic-gate 2840Sstevel@tonic-gate struct mi_walk_data { 2850Sstevel@tonic-gate uintptr_t mi_wd_miofirst; 2860Sstevel@tonic-gate MI_O mi_wd_miodata; 2870Sstevel@tonic-gate }; 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate int 2900Sstevel@tonic-gate mi_walk_init(mdb_walk_state_t *wsp) 2910Sstevel@tonic-gate { 2920Sstevel@tonic-gate struct mi_walk_data *wdp; 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 2950Sstevel@tonic-gate mdb_warn("mi doesn't support global walks\n"); 2960Sstevel@tonic-gate return (WALK_ERR); 2970Sstevel@tonic-gate } 2980Sstevel@tonic-gate 2990Sstevel@tonic-gate wdp = mdb_alloc(sizeof (struct mi_walk_data), UM_SLEEP); 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate /* So that we do not immediately return WALK_DONE below */ 3020Sstevel@tonic-gate wdp->mi_wd_miofirst = NULL; 3030Sstevel@tonic-gate 3040Sstevel@tonic-gate wsp->walk_data = wdp; 3050Sstevel@tonic-gate return (WALK_NEXT); 3060Sstevel@tonic-gate } 3070Sstevel@tonic-gate 3080Sstevel@tonic-gate int 3090Sstevel@tonic-gate mi_walk_step(mdb_walk_state_t *wsp) 3100Sstevel@tonic-gate { 3110Sstevel@tonic-gate struct mi_walk_data *wdp = wsp->walk_data; 3120Sstevel@tonic-gate MI_OP miop = &wdp->mi_wd_miodata; 3130Sstevel@tonic-gate int status; 3140Sstevel@tonic-gate 3150Sstevel@tonic-gate /* Always false in the first iteration */ 3160Sstevel@tonic-gate if ((wsp->walk_addr == (uintptr_t)NULL) || 3170Sstevel@tonic-gate (wsp->walk_addr == wdp->mi_wd_miofirst)) { 3180Sstevel@tonic-gate return (WALK_DONE); 3190Sstevel@tonic-gate } 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate if (mdb_vread(miop, sizeof (MI_O), wsp->walk_addr) == -1) { 3220Sstevel@tonic-gate mdb_warn("failed to read MI object at %p", wsp->walk_addr); 3230Sstevel@tonic-gate return (WALK_ERR); 3240Sstevel@tonic-gate } 3250Sstevel@tonic-gate 3260Sstevel@tonic-gate /* Only true in the first iteration */ 3273448Sdh155122 if (wdp->mi_wd_miofirst == NULL) { 3280Sstevel@tonic-gate wdp->mi_wd_miofirst = wsp->walk_addr; 3293448Sdh155122 status = WALK_NEXT; 3303448Sdh155122 } else { 3313448Sdh155122 status = wsp->walk_callback(wsp->walk_addr + sizeof (MI_O), 3323448Sdh155122 &miop[1], wsp->walk_cbdata); 3333448Sdh155122 } 3340Sstevel@tonic-gate 3350Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)miop->mi_o_next; 3360Sstevel@tonic-gate return (status); 3370Sstevel@tonic-gate } 3380Sstevel@tonic-gate 3390Sstevel@tonic-gate void 3400Sstevel@tonic-gate mi_walk_fini(mdb_walk_state_t *wsp) 3410Sstevel@tonic-gate { 3420Sstevel@tonic-gate mdb_free(wsp->walk_data, sizeof (struct mi_walk_data)); 3430Sstevel@tonic-gate } 3440Sstevel@tonic-gate 3450Sstevel@tonic-gate typedef struct mi_payload_walk_arg_s { 3463448Sdh155122 const char *mi_pwa_walker; /* Underlying walker */ 3473448Sdh155122 const off_t mi_pwa_head_off; /* Offset for mi_o_head_t * in stack */ 3480Sstevel@tonic-gate const size_t mi_pwa_size; /* size of mi payload */ 3490Sstevel@tonic-gate const uint_t mi_pwa_flags; /* device and/or module */ 3500Sstevel@tonic-gate } mi_payload_walk_arg_t; 3510Sstevel@tonic-gate 3520Sstevel@tonic-gate #define MI_PAYLOAD_DEVICE 0x1 3530Sstevel@tonic-gate #define MI_PAYLOAD_MODULE 0x2 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate int 3560Sstevel@tonic-gate mi_payload_walk_init(mdb_walk_state_t *wsp) 3570Sstevel@tonic-gate { 3580Sstevel@tonic-gate const mi_payload_walk_arg_t *arg = wsp->walk_arg; 3590Sstevel@tonic-gate 3603448Sdh155122 if (mdb_layered_walk(arg->mi_pwa_walker, wsp) == -1) { 3613448Sdh155122 mdb_warn("can't walk '%s'", arg->mi_pwa_walker); 3620Sstevel@tonic-gate return (WALK_ERR); 3630Sstevel@tonic-gate } 3640Sstevel@tonic-gate return (WALK_NEXT); 3650Sstevel@tonic-gate } 3660Sstevel@tonic-gate 3670Sstevel@tonic-gate int 3680Sstevel@tonic-gate mi_payload_walk_step(mdb_walk_state_t *wsp) 3690Sstevel@tonic-gate { 3700Sstevel@tonic-gate const mi_payload_walk_arg_t *arg = wsp->walk_arg; 3713448Sdh155122 uintptr_t kaddr; 3720Sstevel@tonic-gate 3733448Sdh155122 kaddr = wsp->walk_addr + arg->mi_pwa_head_off; 3740Sstevel@tonic-gate 3753448Sdh155122 if (mdb_vread(&kaddr, sizeof (kaddr), kaddr) == -1) { 3763448Sdh155122 mdb_warn("can't read address of mi head at %p for %s", 3773448Sdh155122 kaddr, arg->mi_pwa_walker); 3780Sstevel@tonic-gate return (WALK_ERR); 3790Sstevel@tonic-gate } 3800Sstevel@tonic-gate 3813448Sdh155122 if (kaddr == 0) { 3823448Sdh155122 /* Empty list */ 3833448Sdh155122 return (WALK_DONE); 3843448Sdh155122 } 3850Sstevel@tonic-gate 3863448Sdh155122 if (mdb_pwalk("genunix`mi", wsp->walk_callback, 3873448Sdh155122 wsp->walk_cbdata, kaddr) == -1) { 3883448Sdh155122 mdb_warn("failed to walk genunix`mi"); 3893448Sdh155122 return (WALK_ERR); 3903448Sdh155122 } 3913448Sdh155122 return (WALK_NEXT); 3920Sstevel@tonic-gate } 3930Sstevel@tonic-gate 3940Sstevel@tonic-gate const mi_payload_walk_arg_t mi_ar_arg = { 3953448Sdh155122 "ar_stacks", OFFSETOF(arp_stack_t, as_head), sizeof (ar_t), 3960Sstevel@tonic-gate MI_PAYLOAD_DEVICE | MI_PAYLOAD_MODULE 3970Sstevel@tonic-gate }; 3980Sstevel@tonic-gate 3990Sstevel@tonic-gate const mi_payload_walk_arg_t mi_icmp_arg = { 4003448Sdh155122 "icmp_stacks", OFFSETOF(icmp_stack_t, is_head), sizeof (icmp_t), 4010Sstevel@tonic-gate MI_PAYLOAD_DEVICE | MI_PAYLOAD_MODULE 4020Sstevel@tonic-gate }; 4030Sstevel@tonic-gate 4043448Sdh155122 const mi_payload_walk_arg_t mi_ill_arg = { 4053448Sdh155122 "ip_stacks", OFFSETOF(ip_stack_t, ips_ip_g_head), sizeof (ill_t), 4063448Sdh155122 MI_PAYLOAD_MODULE 4073448Sdh155122 }; 4080Sstevel@tonic-gate 4090Sstevel@tonic-gate int 4100Sstevel@tonic-gate sonode(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 4110Sstevel@tonic-gate { 4120Sstevel@tonic-gate const char *optf = NULL; 4130Sstevel@tonic-gate const char *optt = NULL; 4140Sstevel@tonic-gate const char *optp = NULL; 4150Sstevel@tonic-gate int family, type, proto; 4160Sstevel@tonic-gate int filter = 0; 4170Sstevel@tonic-gate struct sonode so; 4180Sstevel@tonic-gate 4190Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) { 4200Sstevel@tonic-gate if (mdb_walk_dcmd("genunix`sonode", "genunix`sonode", argc, 4210Sstevel@tonic-gate argv) == -1) { 4220Sstevel@tonic-gate mdb_warn("failed to walk sonode"); 4230Sstevel@tonic-gate return (DCMD_ERR); 4240Sstevel@tonic-gate } 4250Sstevel@tonic-gate 4260Sstevel@tonic-gate return (DCMD_OK); 4270Sstevel@tonic-gate } 4280Sstevel@tonic-gate 4290Sstevel@tonic-gate if (mdb_getopts(argc, argv, 4300Sstevel@tonic-gate 'f', MDB_OPT_STR, &optf, 4310Sstevel@tonic-gate 't', MDB_OPT_STR, &optt, 4320Sstevel@tonic-gate 'p', MDB_OPT_STR, &optp, 4330Sstevel@tonic-gate NULL) != argc) 4340Sstevel@tonic-gate return (DCMD_USAGE); 4350Sstevel@tonic-gate 4360Sstevel@tonic-gate if (optf != NULL) { 4370Sstevel@tonic-gate if (strcmp("inet", optf) == 0) 4380Sstevel@tonic-gate family = AF_INET; 4390Sstevel@tonic-gate else if (strcmp("inet6", optf) == 0) 4400Sstevel@tonic-gate family = AF_INET6; 4410Sstevel@tonic-gate else if (strcmp("unix", optf) == 0) 4420Sstevel@tonic-gate family = AF_UNIX; 4430Sstevel@tonic-gate else 4440Sstevel@tonic-gate family = mdb_strtoull(optf); 4450Sstevel@tonic-gate filter = 1; 4460Sstevel@tonic-gate } 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate if (optt != NULL) { 4490Sstevel@tonic-gate if (strcmp("stream", optt) == 0) 4500Sstevel@tonic-gate type = SOCK_STREAM; 4510Sstevel@tonic-gate else if (strcmp("dgram", optt) == 0) 4520Sstevel@tonic-gate type = SOCK_DGRAM; 4530Sstevel@tonic-gate else if (strcmp("raw", optt) == 0) 4540Sstevel@tonic-gate type = SOCK_RAW; 4550Sstevel@tonic-gate else 4560Sstevel@tonic-gate type = mdb_strtoull(optt); 4570Sstevel@tonic-gate filter = 1; 4580Sstevel@tonic-gate } 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate if (optp != NULL) { 4610Sstevel@tonic-gate proto = mdb_strtoull(optp); 4620Sstevel@tonic-gate filter = 1; 4630Sstevel@tonic-gate } 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate if (DCMD_HDRSPEC(flags) && !filter) { 4660Sstevel@tonic-gate mdb_printf("%<u>%-?s Family Type Proto State Mode Flag " 4670Sstevel@tonic-gate "AccessVP%</u>\n", "Sonode:"); 4680Sstevel@tonic-gate } 4690Sstevel@tonic-gate 4700Sstevel@tonic-gate if (mdb_vread(&so, sizeof (so), addr) == -1) { 4710Sstevel@tonic-gate mdb_warn("failed to read sonode at %p", addr); 4720Sstevel@tonic-gate return (DCMD_ERR); 4730Sstevel@tonic-gate } 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate if ((optf != NULL) && (so.so_family != family)) 4760Sstevel@tonic-gate return (DCMD_OK); 4770Sstevel@tonic-gate 4780Sstevel@tonic-gate if ((optt != NULL) && (so.so_type != type)) 4790Sstevel@tonic-gate return (DCMD_OK); 4800Sstevel@tonic-gate 4810Sstevel@tonic-gate if ((optp != NULL) && (so.so_protocol != proto)) 4820Sstevel@tonic-gate return (DCMD_OK); 4830Sstevel@tonic-gate 4840Sstevel@tonic-gate if (filter) { 4850Sstevel@tonic-gate mdb_printf("%0?p\n", addr); 4860Sstevel@tonic-gate return (DCMD_OK); 4870Sstevel@tonic-gate } 4880Sstevel@tonic-gate 4890Sstevel@tonic-gate mdb_printf("%0?p ", addr); 4900Sstevel@tonic-gate 4910Sstevel@tonic-gate switch (so.so_family) { 4925563Snordmark case AF_UNIX: 4930Sstevel@tonic-gate mdb_printf("unix "); 4940Sstevel@tonic-gate break; 4955563Snordmark case AF_INET: 4960Sstevel@tonic-gate mdb_printf("inet "); 4970Sstevel@tonic-gate break; 4985563Snordmark case AF_INET6: 4990Sstevel@tonic-gate mdb_printf("inet6 "); 5000Sstevel@tonic-gate break; 5015563Snordmark default: 5020Sstevel@tonic-gate mdb_printf("%6hi", so.so_family); 5030Sstevel@tonic-gate } 5040Sstevel@tonic-gate 5050Sstevel@tonic-gate switch (so.so_type) { 5065563Snordmark case SOCK_STREAM: 5070Sstevel@tonic-gate mdb_printf(" strm"); 5080Sstevel@tonic-gate break; 5095563Snordmark case SOCK_DGRAM: 5100Sstevel@tonic-gate mdb_printf(" dgrm"); 5110Sstevel@tonic-gate break; 5125563Snordmark case SOCK_RAW: 5130Sstevel@tonic-gate mdb_printf(" raw "); 5140Sstevel@tonic-gate break; 5155563Snordmark default: 5160Sstevel@tonic-gate mdb_printf(" %4hi", so.so_type); 5170Sstevel@tonic-gate } 5180Sstevel@tonic-gate 519*8348SEric.Yu@Sun.COM mdb_printf(" %5hi %05x %04x %04hx\n", 5200Sstevel@tonic-gate so.so_protocol, so.so_state, so.so_mode, 521*8348SEric.Yu@Sun.COM so.so_flag); 5220Sstevel@tonic-gate 5230Sstevel@tonic-gate return (DCMD_OK); 5240Sstevel@tonic-gate } 5250Sstevel@tonic-gate 5260Sstevel@tonic-gate #define MI_PAYLOAD 0x1 5270Sstevel@tonic-gate #define MI_DEVICE 0x2 5280Sstevel@tonic-gate #define MI_MODULE 0x4 5290Sstevel@tonic-gate 5300Sstevel@tonic-gate int 5310Sstevel@tonic-gate mi(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 5320Sstevel@tonic-gate { 5330Sstevel@tonic-gate uint_t opts = 0; 5340Sstevel@tonic-gate MI_O mio; 5350Sstevel@tonic-gate 5360Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 5370Sstevel@tonic-gate return (DCMD_USAGE); 5380Sstevel@tonic-gate 5390Sstevel@tonic-gate if (mdb_getopts(argc, argv, 5400Sstevel@tonic-gate 'p', MDB_OPT_SETBITS, MI_PAYLOAD, &opts, 5410Sstevel@tonic-gate 'd', MDB_OPT_SETBITS, MI_DEVICE, &opts, 5420Sstevel@tonic-gate 'm', MDB_OPT_SETBITS, MI_MODULE, &opts, 5430Sstevel@tonic-gate NULL) != argc) 5440Sstevel@tonic-gate return (DCMD_USAGE); 5450Sstevel@tonic-gate 5460Sstevel@tonic-gate if ((opts & (MI_DEVICE | MI_MODULE)) == (MI_DEVICE | MI_MODULE)) { 5470Sstevel@tonic-gate mdb_warn("at most one filter, d for devices or m " 5480Sstevel@tonic-gate "for modules, may be specified\n"); 5490Sstevel@tonic-gate return (DCMD_USAGE); 5500Sstevel@tonic-gate } 5510Sstevel@tonic-gate 5520Sstevel@tonic-gate if ((opts == 0) && (DCMD_HDRSPEC(flags))) { 5530Sstevel@tonic-gate mdb_printf("%<u>%-?s %-?s %-?s IsDev Dev%</u>\n", 5540Sstevel@tonic-gate "MI_O", "Next", "Prev"); 5550Sstevel@tonic-gate } 5560Sstevel@tonic-gate 5570Sstevel@tonic-gate if (mdb_vread(&mio, sizeof (mio), addr) == -1) { 5580Sstevel@tonic-gate mdb_warn("failed to read mi object MI_O at %p", addr); 5590Sstevel@tonic-gate return (DCMD_ERR); 5600Sstevel@tonic-gate } 5610Sstevel@tonic-gate 5620Sstevel@tonic-gate if (opts != 0) { 5630Sstevel@tonic-gate if (mio.mi_o_isdev == B_FALSE) { 5640Sstevel@tonic-gate /* mio is a module */ 5650Sstevel@tonic-gate if (!(opts & MI_MODULE) && (opts & MI_DEVICE)) 5660Sstevel@tonic-gate return (DCMD_OK); 5670Sstevel@tonic-gate } else { 5680Sstevel@tonic-gate /* mio is a device */ 5690Sstevel@tonic-gate if (!(opts & MI_DEVICE) && (opts & MI_MODULE)) 5700Sstevel@tonic-gate return (DCMD_OK); 5710Sstevel@tonic-gate } 5720Sstevel@tonic-gate 5730Sstevel@tonic-gate if (opts & MI_PAYLOAD) 5740Sstevel@tonic-gate mdb_printf("%p\n", addr + sizeof (MI_O)); 5750Sstevel@tonic-gate else 5760Sstevel@tonic-gate mdb_printf("%p\n", addr); 5770Sstevel@tonic-gate return (DCMD_OK); 5780Sstevel@tonic-gate } 5790Sstevel@tonic-gate 5800Sstevel@tonic-gate mdb_printf("%0?p %0?p %0?p ", addr, mio.mi_o_next, mio.mi_o_prev); 5810Sstevel@tonic-gate 5820Sstevel@tonic-gate if (mio.mi_o_isdev == B_FALSE) 5830Sstevel@tonic-gate mdb_printf("FALSE"); 5840Sstevel@tonic-gate else 5850Sstevel@tonic-gate mdb_printf("TRUE "); 5860Sstevel@tonic-gate 5870Sstevel@tonic-gate mdb_printf(" %0?p\n", mio.mi_o_dev); 5880Sstevel@tonic-gate 5890Sstevel@tonic-gate return (DCMD_OK); 5900Sstevel@tonic-gate } 5910Sstevel@tonic-gate 5923448Sdh155122 static int 5933448Sdh155122 ns_to_stackid(uintptr_t kaddr) 5943448Sdh155122 { 5953448Sdh155122 netstack_t nss; 5963448Sdh155122 5973448Sdh155122 if (mdb_vread(&nss, sizeof (nss), kaddr) == -1) { 5983448Sdh155122 mdb_warn("failed to read netstack_t %p", kaddr); 5993448Sdh155122 return (0); 6003448Sdh155122 } 6013448Sdh155122 return (nss.netstack_stackid); 6023448Sdh155122 } 6033448Sdh155122 6043448Sdh155122 6053448Sdh155122 6060Sstevel@tonic-gate static void 6070Sstevel@tonic-gate netstat_tcp_verbose_pr(const tcp_t *tcp) 6080Sstevel@tonic-gate { 6090Sstevel@tonic-gate mdb_printf(" %5i %08x %08x %5i %08x %08x %5li %5i\n", 6100Sstevel@tonic-gate tcp->tcp_swnd, tcp->tcp_snxt, tcp->tcp_suna, tcp->tcp_rwnd, 6110Sstevel@tonic-gate tcp->tcp_rack, tcp->tcp_rnxt, tcp->tcp_rto, tcp->tcp_mss); 6120Sstevel@tonic-gate } 6130Sstevel@tonic-gate 6140Sstevel@tonic-gate /*ARGSUSED*/ 6150Sstevel@tonic-gate static int 6160Sstevel@tonic-gate netstat_tcp_cb(uintptr_t kaddr, const void *walk_data, void *cb_data, int af) 6170Sstevel@tonic-gate { 6180Sstevel@tonic-gate const uintptr_t opts = (uintptr_t)cb_data; 6190Sstevel@tonic-gate uintptr_t tcp_kaddr; 6205563Snordmark conn_t conns, *connp; 6215563Snordmark tcp_t tcps, *tcp; 6220Sstevel@tonic-gate 6235563Snordmark if (mdb_vread(&conns, sizeof (conn_t), kaddr) == -1) { 6245563Snordmark mdb_warn("failed to read conn_t at %p", kaddr); 6255563Snordmark return (WALK_ERR); 6260Sstevel@tonic-gate } 6275563Snordmark connp = &conns; 6280Sstevel@tonic-gate 6295563Snordmark tcp_kaddr = (uintptr_t)connp->conn_tcp; 6305563Snordmark if (mdb_vread(&tcps, sizeof (tcp_t), tcp_kaddr) == -1) { 6315563Snordmark mdb_warn("failed to read tcp_t at %p", kaddr); 6320Sstevel@tonic-gate return (WALK_ERR); 6330Sstevel@tonic-gate } 6340Sstevel@tonic-gate 6355563Snordmark tcp = &tcps; 6360Sstevel@tonic-gate 6370Sstevel@tonic-gate connp->conn_tcp = tcp; 6380Sstevel@tonic-gate tcp->tcp_connp = connp; 6390Sstevel@tonic-gate 640741Smasputra if (!((opts & NETSTAT_ALL) || net_tcp_active(tcp)) || 6410Sstevel@tonic-gate (af == AF_INET && !net_tcp_ipv4(tcp)) || 6420Sstevel@tonic-gate (af == AF_INET6 && !net_tcp_ipv6(tcp))) { 6430Sstevel@tonic-gate return (WALK_NEXT); 6440Sstevel@tonic-gate } 6450Sstevel@tonic-gate 6460Sstevel@tonic-gate mdb_printf("%0?p %2i ", tcp_kaddr, tcp->tcp_state); 6470Sstevel@tonic-gate if (af == AF_INET) { 6480Sstevel@tonic-gate net_ipv4addrport_pr(&tcp->tcp_ip_src_v6, tcp->tcp_lport); 6490Sstevel@tonic-gate mdb_printf(" "); 6500Sstevel@tonic-gate net_ipv4addrport_pr(&tcp->tcp_remote_v6, tcp->tcp_fport); 6510Sstevel@tonic-gate } else if (af == AF_INET6) { 6520Sstevel@tonic-gate net_ipv6addrport_pr(&tcp->tcp_ip_src_v6, tcp->tcp_lport); 6530Sstevel@tonic-gate mdb_printf(" "); 6540Sstevel@tonic-gate net_ipv6addrport_pr(&tcp->tcp_remote_v6, tcp->tcp_fport); 6550Sstevel@tonic-gate } 6563448Sdh155122 mdb_printf(" %4i", ns_to_stackid((uintptr_t)connp->conn_netstack)); 6573448Sdh155122 6580Sstevel@tonic-gate mdb_printf(" %4i\n", connp->conn_zoneid); 6590Sstevel@tonic-gate 6600Sstevel@tonic-gate if (opts & NETSTAT_VERBOSE) 6610Sstevel@tonic-gate netstat_tcp_verbose_pr(tcp); 6620Sstevel@tonic-gate 6630Sstevel@tonic-gate return (WALK_NEXT); 6640Sstevel@tonic-gate } 6650Sstevel@tonic-gate 6660Sstevel@tonic-gate static int 6670Sstevel@tonic-gate netstat_tcpv4_cb(uintptr_t kaddr, const void *walk_data, void *cb_data) 6680Sstevel@tonic-gate { 6690Sstevel@tonic-gate return (netstat_tcp_cb(kaddr, walk_data, cb_data, AF_INET)); 6700Sstevel@tonic-gate } 6710Sstevel@tonic-gate 6720Sstevel@tonic-gate static int 6730Sstevel@tonic-gate netstat_tcpv6_cb(uintptr_t kaddr, const void *walk_data, void *cb_data) 6740Sstevel@tonic-gate { 6750Sstevel@tonic-gate return (netstat_tcp_cb(kaddr, walk_data, cb_data, AF_INET6)); 6760Sstevel@tonic-gate } 6770Sstevel@tonic-gate 678741Smasputra /*ARGSUSED*/ 6790Sstevel@tonic-gate static int 680741Smasputra netstat_udp_cb(uintptr_t kaddr, const void *walk_data, void *cb_data, int af) 6810Sstevel@tonic-gate { 6820Sstevel@tonic-gate const uintptr_t opts = (uintptr_t)cb_data; 683741Smasputra udp_t udp; 6845563Snordmark conn_t conns; 685741Smasputra 6865563Snordmark if (mdb_vread(&conns, sizeof (conn_t), kaddr) == -1) { 6875563Snordmark mdb_warn("failed to read conn_t at %p", kaddr); 688741Smasputra return (WALK_ERR); 689741Smasputra } 6900Sstevel@tonic-gate 6915563Snordmark if (mdb_vread(&udp, sizeof (udp_t), 6925563Snordmark (uintptr_t)conns.conn_udp) == -1) { 6935563Snordmark mdb_warn("failed to read conn_udp at %p", 6945563Snordmark (uintptr_t)conns.conn_udp); 695741Smasputra return (WALK_ERR); 696741Smasputra } 6970Sstevel@tonic-gate 698741Smasputra if (!((opts & NETSTAT_ALL) || net_udp_active(&udp)) || 699741Smasputra (af == AF_INET && !net_udp_ipv4(&udp)) || 700741Smasputra (af == AF_INET6 && !net_udp_ipv6(&udp))) { 701741Smasputra return (WALK_NEXT); 702741Smasputra } 703741Smasputra 704741Smasputra mdb_printf("%0?p %2i ", kaddr, udp.udp_state); 705741Smasputra if (af == AF_INET) { 706741Smasputra net_ipv4addrport_pr(&udp.udp_v6src, udp.udp_port); 707741Smasputra mdb_printf(" "); 708741Smasputra net_ipv4addrport_pr(&udp.udp_v6dst, udp.udp_dstport); 709741Smasputra } else if (af == AF_INET6) { 710741Smasputra net_ipv6addrport_pr(&udp.udp_v6src, udp.udp_port); 711741Smasputra mdb_printf(" "); 712741Smasputra net_ipv6addrport_pr(&udp.udp_v6dst, udp.udp_dstport); 713741Smasputra } 7145563Snordmark mdb_printf(" %4i", ns_to_stackid((uintptr_t)conns.conn_netstack)); 7153448Sdh155122 7165563Snordmark mdb_printf(" %4i\n", conns.conn_zoneid); 7170Sstevel@tonic-gate 7180Sstevel@tonic-gate return (WALK_NEXT); 7190Sstevel@tonic-gate } 7200Sstevel@tonic-gate 7210Sstevel@tonic-gate static int 722741Smasputra netstat_udpv4_cb(uintptr_t kaddr, const void *walk_data, void *cb_data) 723741Smasputra { 724741Smasputra return (netstat_udp_cb(kaddr, walk_data, cb_data, AF_INET)); 725741Smasputra } 726741Smasputra 727741Smasputra static int 7280Sstevel@tonic-gate netstat_udpv6_cb(uintptr_t kaddr, const void *walk_data, void *cb_data) 7290Sstevel@tonic-gate { 730741Smasputra return (netstat_udp_cb(kaddr, walk_data, cb_data, AF_INET6)); 7310Sstevel@tonic-gate } 7320Sstevel@tonic-gate 7330Sstevel@tonic-gate /* 7340Sstevel@tonic-gate * print the address of a unix domain socket 7350Sstevel@tonic-gate * 7360Sstevel@tonic-gate * so is the address of a AF_UNIX struct sonode in mdb's address space 7370Sstevel@tonic-gate * soa is the address of the struct soaddr to print 7380Sstevel@tonic-gate * 7390Sstevel@tonic-gate * returns 0 on success, -1 otherwise 7400Sstevel@tonic-gate */ 7410Sstevel@tonic-gate static int 742*8348SEric.Yu@Sun.COM netstat_unix_name_pr(const struct sotpi_sonode *st, const struct soaddr *soa) 7430Sstevel@tonic-gate { 744*8348SEric.Yu@Sun.COM const struct sonode *so = &st->st_sonode; 7450Sstevel@tonic-gate const char none[] = " (none)"; 7460Sstevel@tonic-gate 7470Sstevel@tonic-gate if ((so->so_state & SS_ISBOUND) && (soa->soa_len != 0)) { 748*8348SEric.Yu@Sun.COM if (st->st_info.sti_faddr_noxlate) { 7490Sstevel@tonic-gate mdb_printf("%-14s ", " (socketpair)"); 7500Sstevel@tonic-gate } else { 7510Sstevel@tonic-gate if (soa->soa_len > sizeof (sa_family_t)) { 7520Sstevel@tonic-gate char addr[MAXPATHLEN + 1]; 7530Sstevel@tonic-gate 7540Sstevel@tonic-gate if (mdb_readstr(addr, sizeof (addr), 7550Sstevel@tonic-gate (uintptr_t)&soa->soa_sa->sa_data) == -1) { 7560Sstevel@tonic-gate mdb_warn("failed to read unix address " 7570Sstevel@tonic-gate "at %p", &soa->soa_sa->sa_data); 7580Sstevel@tonic-gate return (-1); 7590Sstevel@tonic-gate } 7600Sstevel@tonic-gate 7610Sstevel@tonic-gate mdb_printf("%-14s ", addr); 7620Sstevel@tonic-gate } else { 7630Sstevel@tonic-gate mdb_printf("%-14s ", none); 7640Sstevel@tonic-gate } 7650Sstevel@tonic-gate } 7660Sstevel@tonic-gate } else { 7670Sstevel@tonic-gate mdb_printf("%-14s ", none); 7680Sstevel@tonic-gate } 7690Sstevel@tonic-gate 7700Sstevel@tonic-gate return (0); 7710Sstevel@tonic-gate } 7720Sstevel@tonic-gate 7730Sstevel@tonic-gate /* based on sockfs_snapshot */ 7740Sstevel@tonic-gate /*ARGSUSED*/ 7750Sstevel@tonic-gate static int 7760Sstevel@tonic-gate netstat_unix_cb(uintptr_t kaddr, const void *walk_data, void *cb_data) 7770Sstevel@tonic-gate { 778*8348SEric.Yu@Sun.COM const struct sotpi_sonode *st = walk_data; 779*8348SEric.Yu@Sun.COM const struct sonode *so = &st->st_sonode; 780*8348SEric.Yu@Sun.COM const struct sotpi_info *sti = &st->st_info; 7810Sstevel@tonic-gate 782*8348SEric.Yu@Sun.COM if (so->so_count == 0) 7830Sstevel@tonic-gate return (WALK_NEXT); 7840Sstevel@tonic-gate 7850Sstevel@tonic-gate if (so->so_family != AF_UNIX) { 7860Sstevel@tonic-gate mdb_warn("sonode of family %hi at %p\n", so->so_family, kaddr); 7870Sstevel@tonic-gate return (WALK_ERR); 7880Sstevel@tonic-gate } 7890Sstevel@tonic-gate 7900Sstevel@tonic-gate mdb_printf("%-?p ", kaddr); 7910Sstevel@tonic-gate 792*8348SEric.Yu@Sun.COM switch (sti->sti_serv_type) { 7935563Snordmark case T_CLTS: 7940Sstevel@tonic-gate mdb_printf("%-10s ", "dgram"); 7950Sstevel@tonic-gate break; 7965563Snordmark case T_COTS: 7970Sstevel@tonic-gate mdb_printf("%-10s ", "stream"); 7980Sstevel@tonic-gate break; 7995563Snordmark case T_COTS_ORD: 8000Sstevel@tonic-gate mdb_printf("%-10s ", "stream-ord"); 8010Sstevel@tonic-gate break; 8025563Snordmark default: 803*8348SEric.Yu@Sun.COM mdb_printf("%-10i ", sti->sti_serv_type); 8040Sstevel@tonic-gate } 8050Sstevel@tonic-gate 8060Sstevel@tonic-gate if ((so->so_state & SS_ISBOUND) && 807*8348SEric.Yu@Sun.COM (sti->sti_ux_laddr.soua_magic == SOU_MAGIC_EXPLICIT)) { 808*8348SEric.Yu@Sun.COM mdb_printf("%0?p ", sti->sti_ux_laddr.soua_vp); 8090Sstevel@tonic-gate } else { 8100Sstevel@tonic-gate mdb_printf("%0?p ", NULL); 8110Sstevel@tonic-gate } 8120Sstevel@tonic-gate 8130Sstevel@tonic-gate if ((so->so_state & SS_ISCONNECTED) && 814*8348SEric.Yu@Sun.COM (sti->sti_ux_faddr.soua_magic == SOU_MAGIC_EXPLICIT)) { 815*8348SEric.Yu@Sun.COM mdb_printf("%0?p ", sti->sti_ux_faddr.soua_vp); 8160Sstevel@tonic-gate } else { 8170Sstevel@tonic-gate mdb_printf("%0?p ", NULL); 8180Sstevel@tonic-gate } 8190Sstevel@tonic-gate 820*8348SEric.Yu@Sun.COM if (netstat_unix_name_pr(st, &sti->sti_laddr) == -1) 8210Sstevel@tonic-gate return (WALK_ERR); 8220Sstevel@tonic-gate 823*8348SEric.Yu@Sun.COM if (netstat_unix_name_pr(st, &sti->sti_faddr) == -1) 8240Sstevel@tonic-gate return (WALK_ERR); 8250Sstevel@tonic-gate 8260Sstevel@tonic-gate mdb_printf("%4i\n", so->so_zoneid); 8270Sstevel@tonic-gate 8280Sstevel@tonic-gate return (WALK_NEXT); 8290Sstevel@tonic-gate } 8300Sstevel@tonic-gate 8310Sstevel@tonic-gate static void 8320Sstevel@tonic-gate netstat_tcp_verbose_header_pr(void) 8330Sstevel@tonic-gate { 8340Sstevel@tonic-gate mdb_printf(" %<u>%-5s %-8s %-8s %-5s %-8s %-8s %5s %5s%</u>\n", 8350Sstevel@tonic-gate "Swind", "Snext", "Suna", "Rwind", "Rack", "Rnext", "Rto", "Mss"); 8360Sstevel@tonic-gate } 8370Sstevel@tonic-gate 8381676Sjpk static void 8391676Sjpk get_ifname(const ire_t *ire, char *intf) 8401676Sjpk { 8411676Sjpk ill_t ill; 8421676Sjpk 8431676Sjpk *intf = '\0'; 8441676Sjpk if (ire->ire_type == IRE_CACHE) { 8451676Sjpk queue_t stq; 8461676Sjpk 8471676Sjpk if (mdb_vread(&stq, sizeof (stq), (uintptr_t)ire->ire_stq) == 8481676Sjpk -1) 8491676Sjpk return; 8501676Sjpk if (mdb_vread(&ill, sizeof (ill), (uintptr_t)stq.q_ptr) == -1) 8511676Sjpk return; 8521676Sjpk (void) mdb_readstr(intf, MIN(LIFNAMSIZ, ill.ill_name_length), 8531676Sjpk (uintptr_t)ill.ill_name); 8541676Sjpk } else if (ire->ire_ipif != NULL) { 8551676Sjpk ipif_t ipif; 8561676Sjpk char *cp; 8571676Sjpk 8581676Sjpk if (mdb_vread(&ipif, sizeof (ipif), 8591676Sjpk (uintptr_t)ire->ire_ipif) == -1) 8601676Sjpk return; 8611676Sjpk if (mdb_vread(&ill, sizeof (ill), (uintptr_t)ipif.ipif_ill) == 8621676Sjpk -1) 8631676Sjpk return; 8641676Sjpk (void) mdb_readstr(intf, MIN(LIFNAMSIZ, ill.ill_name_length), 8651676Sjpk (uintptr_t)ill.ill_name); 8661676Sjpk if (ipif.ipif_id != 0) { 8671676Sjpk cp = intf + strlen(intf); 8681676Sjpk (void) mdb_snprintf(cp, LIFNAMSIZ + 1 - (cp - intf), 8691676Sjpk ":%u", ipif.ipif_id); 8701676Sjpk } 8711676Sjpk } 8721676Sjpk } 8731676Sjpk 8741676Sjpk static void 8751676Sjpk get_v4flags(const ire_t *ire, char *flags) 8761676Sjpk { 8771676Sjpk (void) strcpy(flags, "U"); 8781676Sjpk if (ire->ire_type == IRE_DEFAULT || ire->ire_type == IRE_PREFIX || 8791676Sjpk ire->ire_type == IRE_HOST || ire->ire_type == IRE_HOST_REDIRECT) 8801676Sjpk (void) strcat(flags, "G"); 8811676Sjpk if (ire->ire_mask == IP_HOST_MASK) 8821676Sjpk (void) strcat(flags, "H"); 8831676Sjpk if (ire->ire_type == IRE_HOST_REDIRECT) 8841676Sjpk (void) strcat(flags, "D"); 8851676Sjpk if (ire->ire_type == IRE_CACHE) 8861676Sjpk (void) strcat(flags, "A"); 8871676Sjpk if (ire->ire_type == IRE_BROADCAST) 8881676Sjpk (void) strcat(flags, "B"); 8891676Sjpk if (ire->ire_type == IRE_LOCAL) 8901676Sjpk (void) strcat(flags, "L"); 8911676Sjpk if (ire->ire_flags & RTF_MULTIRT) 8921676Sjpk (void) strcat(flags, "M"); 8931676Sjpk if (ire->ire_flags & RTF_SETSRC) 8941676Sjpk (void) strcat(flags, "S"); 8951676Sjpk } 8961676Sjpk 8971676Sjpk static int 8981676Sjpk netstat_irev4_cb(uintptr_t kaddr, const void *walk_data, void *cb_data) 8991676Sjpk { 9001676Sjpk const ire_t *ire = walk_data; 9011676Sjpk uint_t *opts = cb_data; 9021676Sjpk ipaddr_t gate; 9031676Sjpk char flags[10], intf[LIFNAMSIZ + 1]; 9041676Sjpk 9054823Sseb if (ire->ire_ipversion != IPV4_VERSION) 9061676Sjpk return (WALK_NEXT); 9071676Sjpk 9081676Sjpk if (!(*opts & NETSTAT_ALL) && (ire->ire_type == IRE_CACHE || 9091676Sjpk ire->ire_type == IRE_BROADCAST || ire->ire_type == IRE_LOCAL)) 9101676Sjpk return (WALK_NEXT); 9111676Sjpk 9121676Sjpk if (*opts & NETSTAT_FIRST) { 9131676Sjpk *opts &= ~NETSTAT_FIRST; 9141676Sjpk mdb_printf("%<u>%s Table: IPv4%</u>\n", 9151676Sjpk (*opts & NETSTAT_VERBOSE) ? "IRE" : "Routing"); 9161676Sjpk if (*opts & NETSTAT_VERBOSE) { 9171676Sjpk mdb_printf("%<u>%-?s %-*s %-*s %-*s Device Mxfrg Rtt " 9181676Sjpk " Ref Flg Out In/Fwd%</u>\n", 9191676Sjpk "Address", ADDR_V4_WIDTH, "Destination", 9201676Sjpk ADDR_V4_WIDTH, "Mask", ADDR_V4_WIDTH, "Gateway"); 9211676Sjpk } else { 9221676Sjpk mdb_printf("%<u>%-?s %-*s %-*s Flags Ref Use " 9231676Sjpk "Interface%</u>\n", 9241676Sjpk "Address", ADDR_V4_WIDTH, "Destination", 9251676Sjpk ADDR_V4_WIDTH, "Gateway"); 9261676Sjpk } 9271676Sjpk } 9281676Sjpk 9291676Sjpk gate = (ire->ire_type & (IRE_INTERFACE|IRE_LOOPBACK|IRE_BROADCAST)) ? 9301676Sjpk ire->ire_src_addr : ire->ire_gateway_addr; 9311676Sjpk 9321676Sjpk get_v4flags(ire, flags); 9331676Sjpk 9341676Sjpk get_ifname(ire, intf); 9351676Sjpk 9361676Sjpk if (*opts & NETSTAT_VERBOSE) { 9371676Sjpk mdb_printf("%?p %-*I %-*I %-*I %-6s %5u%c %4u %3u %-3s %5u " 9381676Sjpk "%u\n", kaddr, ADDR_V4_WIDTH, ire->ire_addr, ADDR_V4_WIDTH, 9391676Sjpk ire->ire_mask, ADDR_V4_WIDTH, gate, intf, 9401676Sjpk ire->ire_max_frag, ire->ire_frag_flag ? '*' : ' ', 9411676Sjpk ire->ire_uinfo.iulp_rtt, ire->ire_refcnt, flags, 9421676Sjpk ire->ire_ob_pkt_count, ire->ire_ib_pkt_count); 9431676Sjpk } else { 9441676Sjpk mdb_printf("%?p %-*I %-*I %-5s %4u %5u %s\n", kaddr, 9451676Sjpk ADDR_V4_WIDTH, ire->ire_addr, ADDR_V4_WIDTH, gate, flags, 9461676Sjpk ire->ire_refcnt, 9471676Sjpk ire->ire_ob_pkt_count + ire->ire_ib_pkt_count, intf); 9481676Sjpk } 9491676Sjpk 9501676Sjpk return (WALK_NEXT); 9511676Sjpk } 9521676Sjpk 9531676Sjpk int 9541676Sjpk ip_mask_to_plen_v6(const in6_addr_t *v6mask) 9551676Sjpk { 9561676Sjpk int plen; 9571676Sjpk int i; 9581676Sjpk uint32_t val; 9591676Sjpk 9601676Sjpk for (i = 3; i >= 0; i--) 9611676Sjpk if (v6mask->s6_addr32[i] != 0) 9621676Sjpk break; 9631676Sjpk if (i < 0) 9641676Sjpk return (0); 9651676Sjpk plen = 32 + 32 * i; 9661676Sjpk val = v6mask->s6_addr32[i]; 9671676Sjpk while (!(val & 1)) { 9681676Sjpk val >>= 1; 9691676Sjpk plen--; 9701676Sjpk } 9711676Sjpk 9721676Sjpk return (plen); 9731676Sjpk } 9741676Sjpk 9751676Sjpk static int 9761676Sjpk netstat_irev6_cb(uintptr_t kaddr, const void *walk_data, void *cb_data) 9771676Sjpk { 9781676Sjpk const ire_t *ire = walk_data; 9791676Sjpk uint_t *opts = cb_data; 9801676Sjpk const in6_addr_t *gatep; 9811676Sjpk char deststr[ADDR_V6_WIDTH + 5]; 9821676Sjpk char flags[10], intf[LIFNAMSIZ + 1]; 9831676Sjpk int masklen; 9841676Sjpk 9851676Sjpk if (ire->ire_ipversion != IPV6_VERSION) 9861676Sjpk return (WALK_NEXT); 9871676Sjpk 9881676Sjpk if (!(*opts & NETSTAT_ALL) && ire->ire_type == IRE_CACHE) 9891676Sjpk return (WALK_NEXT); 9901676Sjpk 9911676Sjpk if (*opts & NETSTAT_FIRST) { 9921676Sjpk *opts &= ~NETSTAT_FIRST; 9931676Sjpk mdb_printf("\n%<u>%s Table: IPv6%</u>\n", 9941676Sjpk (*opts & NETSTAT_VERBOSE) ? "IRE" : "Routing"); 9951676Sjpk if (*opts & NETSTAT_VERBOSE) { 9961676Sjpk mdb_printf("%<u>%-?s %-*s %-*s If PMTU Rtt Ref " 9971676Sjpk "Flags Out In/Fwd%</u>\n", 9981676Sjpk "Address", ADDR_V6_WIDTH+4, "Destination/Mask", 9991676Sjpk ADDR_V6_WIDTH, "Gateway"); 10001676Sjpk } else { 10011676Sjpk mdb_printf("%<u>%-?s %-*s %-*s Flags Ref Use If" 10021676Sjpk "%</u>\n", 10031676Sjpk "Address", ADDR_V6_WIDTH+4, "Destination/Mask", 10041676Sjpk ADDR_V6_WIDTH, "Gateway"); 10051676Sjpk } 10061676Sjpk } 10071676Sjpk 10081676Sjpk gatep = (ire->ire_type & (IRE_INTERFACE|IRE_LOOPBACK)) ? 10091676Sjpk &ire->ire_src_addr_v6 : &ire->ire_gateway_addr_v6; 10101676Sjpk 10111676Sjpk masklen = ip_mask_to_plen_v6(&ire->ire_mask_v6); 10121676Sjpk (void) mdb_snprintf(deststr, sizeof (deststr), "%N/%d", 10131676Sjpk &ire->ire_addr_v6, masklen); 10141676Sjpk 10151676Sjpk (void) strcpy(flags, "U"); 10161676Sjpk if (ire->ire_type == IRE_DEFAULT || ire->ire_type == IRE_PREFIX || 10171676Sjpk ire->ire_type == IRE_HOST || ire->ire_type == IRE_HOST_REDIRECT) 10181676Sjpk (void) strcat(flags, "G"); 10191676Sjpk if (masklen == IPV6_ABITS) 10201676Sjpk (void) strcat(flags, "H"); 10211676Sjpk if (ire->ire_type == IRE_HOST_REDIRECT) 10221676Sjpk (void) strcat(flags, "D"); 10231676Sjpk if (ire->ire_type == IRE_CACHE) 10241676Sjpk (void) strcat(flags, "A"); 10251676Sjpk if (ire->ire_type == IRE_LOCAL) 10261676Sjpk (void) strcat(flags, "L"); 10271676Sjpk if (ire->ire_flags & RTF_MULTIRT) 10281676Sjpk (void) strcat(flags, "M"); 10291676Sjpk if (ire->ire_flags & RTF_SETSRC) 10301676Sjpk (void) strcat(flags, "S"); 10311676Sjpk 10321676Sjpk get_ifname(ire, intf); 10331676Sjpk 10341676Sjpk if (*opts & NETSTAT_VERBOSE) { 10351676Sjpk mdb_printf("%?p %-*s %-*N %-5s %5u%c %5u %3u %-5s %6u %u\n", 10361676Sjpk kaddr, ADDR_V6_WIDTH+4, deststr, ADDR_V6_WIDTH, gatep, 10371676Sjpk intf, ire->ire_max_frag, ire->ire_frag_flag ? '*' : ' ', 10381676Sjpk ire->ire_uinfo.iulp_rtt, ire->ire_refcnt, 10391676Sjpk flags, ire->ire_ob_pkt_count, ire->ire_ib_pkt_count); 10401676Sjpk } else { 10411676Sjpk mdb_printf("%?p %-*s %-*N %-5s %3u %6u %s\n", kaddr, 10421676Sjpk ADDR_V6_WIDTH+4, deststr, ADDR_V6_WIDTH, gatep, flags, 10431676Sjpk ire->ire_refcnt, 10441676Sjpk ire->ire_ob_pkt_count + ire->ire_ib_pkt_count, intf); 10451676Sjpk } 10461676Sjpk 10471676Sjpk return (WALK_NEXT); 10481676Sjpk } 10491676Sjpk 10500Sstevel@tonic-gate /*ARGSUSED*/ 10510Sstevel@tonic-gate int 10520Sstevel@tonic-gate netstat(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 10530Sstevel@tonic-gate { 10540Sstevel@tonic-gate uint_t opts = 0; 10550Sstevel@tonic-gate const char *optf = NULL; 10560Sstevel@tonic-gate const char *optP = NULL; 10570Sstevel@tonic-gate 10580Sstevel@tonic-gate if (mdb_getopts(argc, argv, 10590Sstevel@tonic-gate 'a', MDB_OPT_SETBITS, NETSTAT_ALL, &opts, 10600Sstevel@tonic-gate 'f', MDB_OPT_STR, &optf, 10610Sstevel@tonic-gate 'P', MDB_OPT_STR, &optP, 10621676Sjpk 'r', MDB_OPT_SETBITS, NETSTAT_ROUTE, &opts, 10631676Sjpk 'v', MDB_OPT_SETBITS, NETSTAT_VERBOSE, &opts, 10640Sstevel@tonic-gate NULL) != argc) 10650Sstevel@tonic-gate return (DCMD_USAGE); 10660Sstevel@tonic-gate 10670Sstevel@tonic-gate if (optP != NULL) { 10680Sstevel@tonic-gate if ((strcmp("tcp", optP) != 0) && (strcmp("udp", optP) != 0)) 10690Sstevel@tonic-gate return (DCMD_USAGE); 10701676Sjpk if (opts & NETSTAT_ROUTE) 10711676Sjpk return (DCMD_USAGE); 10720Sstevel@tonic-gate } 10730Sstevel@tonic-gate 10741676Sjpk if (optf == NULL) 10751676Sjpk opts |= NETSTAT_V4 | NETSTAT_V6 | NETSTAT_UNIX; 10761676Sjpk else if (strcmp("inet", optf) == 0) 10771676Sjpk opts |= NETSTAT_V4; 10781676Sjpk else if (strcmp("inet6", optf) == 0) 10791676Sjpk opts |= NETSTAT_V6; 10801676Sjpk else if (strcmp("unix", optf) == 0) 10811676Sjpk opts |= NETSTAT_UNIX; 10821676Sjpk else 10831676Sjpk return (DCMD_USAGE); 10841676Sjpk 10851676Sjpk if (opts & NETSTAT_ROUTE) { 10861676Sjpk if (!(opts & (NETSTAT_V4|NETSTAT_V6))) 10870Sstevel@tonic-gate return (DCMD_USAGE); 10881676Sjpk if (opts & NETSTAT_V4) { 10891676Sjpk opts |= NETSTAT_FIRST; 10901676Sjpk if (mdb_walk("ip`ire", netstat_irev4_cb, &opts) == -1) { 10911676Sjpk mdb_warn("failed to walk ip`ire"); 10921676Sjpk return (DCMD_ERR); 10931676Sjpk } 10941676Sjpk } 10951676Sjpk if (opts & NETSTAT_V6) { 10961676Sjpk opts |= NETSTAT_FIRST; 10971676Sjpk if (mdb_walk("ip`ire", netstat_irev6_cb, &opts) == -1) { 10981676Sjpk mdb_warn("failed to walk ip`ire"); 10991676Sjpk return (DCMD_ERR); 11001676Sjpk } 11011676Sjpk } 11021676Sjpk return (DCMD_OK); 11030Sstevel@tonic-gate } 11040Sstevel@tonic-gate 11050Sstevel@tonic-gate if ((optP == NULL) || (strcmp("tcp", optP) == 0)) { 11060Sstevel@tonic-gate if ((optf == NULL) || (strcmp("inet", optf) == 0)) { 11070Sstevel@tonic-gate /* Print TCPv4 connection */ 11083448Sdh155122 mdb_printf("%<u>%-?s St %*s %*s " 11093448Sdh155122 "%s% %s%</u>\n", 11100Sstevel@tonic-gate "TCPv4", ADDR_V4_WIDTH, "Local Address", 11113448Sdh155122 ADDR_V4_WIDTH, "Remote Address", "Stack", "Zone"); 11120Sstevel@tonic-gate 11130Sstevel@tonic-gate if (opts & NETSTAT_VERBOSE) 11140Sstevel@tonic-gate netstat_tcp_verbose_header_pr(); 11150Sstevel@tonic-gate 11165563Snordmark if (mdb_walk("tcp_conn_cache", netstat_tcpv4_cb, 11170Sstevel@tonic-gate (void *)(uintptr_t)opts) == -1) { 11185563Snordmark mdb_warn("failed to walk tcp_conn_cache"); 11190Sstevel@tonic-gate return (DCMD_ERR); 11200Sstevel@tonic-gate } 11210Sstevel@tonic-gate } 11220Sstevel@tonic-gate 11230Sstevel@tonic-gate if ((optf == NULL) || (strcmp("inet6", optf) == 0)) { 11240Sstevel@tonic-gate /* Print TCPv6 connection */ 11253448Sdh155122 mdb_printf("%<u>%-?s St %*s %*s " 11263448Sdh155122 "%s %s%\n%</u>", 11270Sstevel@tonic-gate "TCPv6", ADDR_V6_WIDTH, "Local Address", 11283448Sdh155122 ADDR_V6_WIDTH, "Remote Address", "Stack", "Zone"); 11290Sstevel@tonic-gate 11300Sstevel@tonic-gate if (opts & NETSTAT_VERBOSE) 11310Sstevel@tonic-gate netstat_tcp_verbose_header_pr(); 11320Sstevel@tonic-gate 11335563Snordmark if (mdb_walk("tcp_conn_cache", netstat_tcpv6_cb, 11340Sstevel@tonic-gate (void *)(uintptr_t)opts) == -1) { 11355563Snordmark mdb_warn("failed to walk tcp_conn_cache"); 11360Sstevel@tonic-gate return (DCMD_ERR); 11370Sstevel@tonic-gate } 11380Sstevel@tonic-gate } 11390Sstevel@tonic-gate } 11400Sstevel@tonic-gate 11410Sstevel@tonic-gate if ((optP == NULL) || (strcmp("udp", optP) == 0)) { 11420Sstevel@tonic-gate if ((optf == NULL) || (strcmp("inet", optf) == 0)) { 11430Sstevel@tonic-gate /* Print UDPv4 connection */ 11443448Sdh155122 mdb_printf("%<u>%-?s St %*s %*s " 11453448Sdh155122 "%s %s%\n%</u>", 11460Sstevel@tonic-gate "UDPv4", ADDR_V4_WIDTH, "Local Address", 11473448Sdh155122 ADDR_V4_WIDTH, "Remote Address", "Stack", "Zone"); 11480Sstevel@tonic-gate 11495563Snordmark if (mdb_walk("udp_conn_cache", netstat_udpv4_cb, 11500Sstevel@tonic-gate (void *)(uintptr_t)opts) == -1) { 11515563Snordmark mdb_warn("failed to walk udp_conn_cache"); 11520Sstevel@tonic-gate return (DCMD_ERR); 11530Sstevel@tonic-gate } 11540Sstevel@tonic-gate 11550Sstevel@tonic-gate } 11560Sstevel@tonic-gate 11570Sstevel@tonic-gate if ((optf == NULL) || (strcmp("inet6", optf) == 0)) { 11580Sstevel@tonic-gate /* Print UDPv6 connection */ 11593448Sdh155122 mdb_printf("%<u>%-?s St %*s %*s " 11603448Sdh155122 "%s %s%\n%</u>", 11610Sstevel@tonic-gate "UDPv6", ADDR_V6_WIDTH, "Local Address", 11623448Sdh155122 ADDR_V6_WIDTH, "Remote Address", "Stack", "Zone"); 11630Sstevel@tonic-gate 11645563Snordmark if (mdb_walk("udp_conn_cache", netstat_udpv6_cb, 11650Sstevel@tonic-gate (void *)(uintptr_t)opts) == -1) { 11665563Snordmark mdb_warn("failed to walk udp_conn_cache"); 11670Sstevel@tonic-gate return (DCMD_ERR); 11680Sstevel@tonic-gate } 11690Sstevel@tonic-gate } 11700Sstevel@tonic-gate } 11710Sstevel@tonic-gate 11720Sstevel@tonic-gate if (((optf == NULL) || (strcmp("unix", optf) == 0)) && (optP == NULL)) { 11730Sstevel@tonic-gate /* Print Unix Domain Sockets */ 11740Sstevel@tonic-gate mdb_printf("%<u>%-?s %-10s %-?s %-?s %-14s %-14s %s%</u>\n", 11750Sstevel@tonic-gate "AF_UNIX", "Type", "Vnode", "Conn", "Local Addr", 11760Sstevel@tonic-gate "Remote Addr", "Zone"); 11770Sstevel@tonic-gate 11780Sstevel@tonic-gate if (mdb_walk("genunix`sonode", netstat_unix_cb, NULL) == -1) { 11790Sstevel@tonic-gate mdb_warn("failed to walk genunix`sonode"); 11800Sstevel@tonic-gate return (DCMD_ERR); 11810Sstevel@tonic-gate } 11820Sstevel@tonic-gate } 11830Sstevel@tonic-gate 11840Sstevel@tonic-gate return (DCMD_OK); 11850Sstevel@tonic-gate } 1186