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 52546Scarlsonj * Common Development and Distribution License (the "License"). 62546Scarlsonj * 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*8485SPeter.Memishian@Sun.COM * Copyright 2009 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 <sys/types.h> 270Sstevel@tonic-gate #include <sys/stropts.h> 280Sstevel@tonic-gate #include <sys/stream.h> 290Sstevel@tonic-gate #include <sys/socket.h> 300Sstevel@tonic-gate #include <sys/avl_impl.h> 310Sstevel@tonic-gate #include <net/if.h> 320Sstevel@tonic-gate #include <net/route.h> 330Sstevel@tonic-gate #include <netinet/in.h> 340Sstevel@tonic-gate #include <netinet/ip6.h> 350Sstevel@tonic-gate #include <netinet/udp.h> 360Sstevel@tonic-gate #include <netinet/sctp.h> 370Sstevel@tonic-gate #include <inet/mib2.h> 380Sstevel@tonic-gate #include <inet/common.h> 390Sstevel@tonic-gate #include <inet/ip.h> 400Sstevel@tonic-gate #include <inet/ip_ire.h> 410Sstevel@tonic-gate #include <inet/ip6.h> 420Sstevel@tonic-gate #include <inet/ipclassifier.h> 430Sstevel@tonic-gate #include <inet/mi.h> 440Sstevel@tonic-gate #include <sys/squeue_impl.h> 455023Scarlsonj #include <sys/modhash_impl.h> 465940Ssowmini #include <inet/ip_ndp.h> 475940Ssowmini #include <inet/ip_if.h> 485940Ssowmini #include <sys/dlpi.h> 490Sstevel@tonic-gate 500Sstevel@tonic-gate #include <mdb/mdb_modapi.h> 510Sstevel@tonic-gate #include <mdb/mdb_ks.h> 520Sstevel@tonic-gate 530Sstevel@tonic-gate #define ADDR_WIDTH 11 545940Ssowmini #define L2MAXADDRSTRLEN 255 555940Ssowmini #define MAX_SAP_LEN 255 560Sstevel@tonic-gate 570Sstevel@tonic-gate typedef struct { 580Sstevel@tonic-gate const char *bit_name; /* name of bit */ 590Sstevel@tonic-gate const char *bit_descr; /* description of bit's purpose */ 600Sstevel@tonic-gate } bitname_t; 610Sstevel@tonic-gate 620Sstevel@tonic-gate static const bitname_t squeue_states[] = { 630Sstevel@tonic-gate { "SQS_PROC", "being processed" }, 640Sstevel@tonic-gate { "SQS_WORKER", "... by a worker thread" }, 650Sstevel@tonic-gate { "SQS_ENTER", "... by an squeue_enter() thread" }, 660Sstevel@tonic-gate { "SQS_FAST", "... in fast-path mode" }, 670Sstevel@tonic-gate { "SQS_USER", "A non interrupt user" }, 680Sstevel@tonic-gate { "SQS_BOUND", "worker thread bound to CPU" }, 690Sstevel@tonic-gate { "SQS_PROFILE", "profiling enabled" }, 700Sstevel@tonic-gate { "SQS_REENTER", "re-entered thred" }, 710Sstevel@tonic-gate { NULL } 720Sstevel@tonic-gate }; 730Sstevel@tonic-gate 740Sstevel@tonic-gate typedef struct illif_walk_data { 750Sstevel@tonic-gate ill_g_head_t ill_g_heads[MAX_G_HEADS]; 760Sstevel@tonic-gate int ill_list; 770Sstevel@tonic-gate ill_if_t ill_if; 780Sstevel@tonic-gate } illif_walk_data_t; 790Sstevel@tonic-gate 805940Ssowmini typedef struct nce_walk_data_s { 815940Ssowmini struct ndp_g_s nce_ip_ndp; 825940Ssowmini int nce_hash_tbl_index; 835940Ssowmini nce_t nce; 845940Ssowmini } nce_walk_data_t; 855940Ssowmini 865940Ssowmini typedef struct nce_cbdata_s { 875940Ssowmini uintptr_t nce_addr; 885940Ssowmini int nce_ipversion; 895940Ssowmini } nce_cbdata_t; 905940Ssowmini 915940Ssowmini typedef struct ire_cbdata_s { 925940Ssowmini int ire_ipversion; 935940Ssowmini boolean_t verbose; 945940Ssowmini } ire_cbdata_t; 955940Ssowmini 965023Scarlsonj typedef struct th_walk_data { 975023Scarlsonj uint_t thw_non_zero_only; 985023Scarlsonj boolean_t thw_match; 995023Scarlsonj uintptr_t thw_matchkey; 1005023Scarlsonj uintptr_t thw_ipst; 1015023Scarlsonj clock_t thw_lbolt; 1025023Scarlsonj } th_walk_data_t; 1035023Scarlsonj 1040Sstevel@tonic-gate static int iphdr(uintptr_t, uint_t, int, const mdb_arg_t *); 1050Sstevel@tonic-gate static int ip6hdr(uintptr_t, uint_t, int, const mdb_arg_t *); 1060Sstevel@tonic-gate 1075940Ssowmini static int ire_format(uintptr_t addr, const void *, void *); 1085940Ssowmini static int nce_format(uintptr_t addr, const nce_t *nce, int ipversion); 1095940Ssowmini static int nce(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv); 1105940Ssowmini static int nce_walk_step(mdb_walk_state_t *wsp); 1115940Ssowmini static int nce_stack_walk_init(mdb_walk_state_t *wsp); 1125940Ssowmini static int nce_stack_walk_step(mdb_walk_state_t *wsp); 1135940Ssowmini static void nce_stack_walk_fini(mdb_walk_state_t *wsp); 1145940Ssowmini static int nce_cb(uintptr_t addr, const nce_walk_data_t *iw, nce_cbdata_t *id); 1153448Sdh155122 1163448Sdh155122 /* 1173448Sdh155122 * Given the kernel address of an ip_stack_t, return the stackid 1183448Sdh155122 */ 1193448Sdh155122 static int 1203448Sdh155122 ips_to_stackid(uintptr_t kaddr) 1213448Sdh155122 { 1223448Sdh155122 ip_stack_t ipss; 1233448Sdh155122 netstack_t nss; 1243448Sdh155122 1253448Sdh155122 if (mdb_vread(&ipss, sizeof (ipss), kaddr) == -1) { 1263448Sdh155122 mdb_warn("failed to read ip_stack_t %p", kaddr); 1273448Sdh155122 return (0); 1283448Sdh155122 } 1293448Sdh155122 kaddr = (uintptr_t)ipss.ips_netstack; 1303448Sdh155122 if (mdb_vread(&nss, sizeof (nss), kaddr) == -1) { 1313448Sdh155122 mdb_warn("failed to read netstack_t %p", kaddr); 1323448Sdh155122 return (0); 1333448Sdh155122 } 1343448Sdh155122 return (nss.netstack_stackid); 1353448Sdh155122 } 1363448Sdh155122 1370Sstevel@tonic-gate int 1383448Sdh155122 ip_stacks_walk_init(mdb_walk_state_t *wsp) 1393448Sdh155122 { 1403448Sdh155122 if (mdb_layered_walk("netstack", wsp) == -1) { 1413448Sdh155122 mdb_warn("can't walk 'netstack'"); 1423448Sdh155122 return (WALK_ERR); 1433448Sdh155122 } 1443448Sdh155122 return (WALK_NEXT); 1453448Sdh155122 } 1463448Sdh155122 1473448Sdh155122 int 1483448Sdh155122 ip_stacks_walk_step(mdb_walk_state_t *wsp) 1493448Sdh155122 { 1503448Sdh155122 uintptr_t kaddr; 1513448Sdh155122 netstack_t nss; 1523448Sdh155122 1533448Sdh155122 if (mdb_vread(&nss, sizeof (nss), wsp->walk_addr) == -1) { 1543448Sdh155122 mdb_warn("can't read netstack at %p", wsp->walk_addr); 1553448Sdh155122 return (WALK_ERR); 1563448Sdh155122 } 1573448Sdh155122 kaddr = (uintptr_t)nss.netstack_modules[NS_IP]; 1583448Sdh155122 1593448Sdh155122 return (wsp->walk_callback(kaddr, wsp->walk_layer, wsp->walk_cbdata)); 1603448Sdh155122 } 1613448Sdh155122 1625023Scarlsonj int 1635023Scarlsonj th_hash_walk_init(mdb_walk_state_t *wsp) 1645023Scarlsonj { 1655023Scarlsonj GElf_Sym sym; 1665023Scarlsonj list_node_t *next; 1675023Scarlsonj 1685023Scarlsonj if (wsp->walk_addr == NULL) { 1695023Scarlsonj if (mdb_lookup_by_obj("ip", "ip_thread_list", &sym) == 0) { 1705023Scarlsonj wsp->walk_addr = sym.st_value; 1715023Scarlsonj } else { 1725023Scarlsonj mdb_warn("unable to locate ip_thread_list\n"); 1735023Scarlsonj return (WALK_ERR); 1745023Scarlsonj } 1755023Scarlsonj } 1765023Scarlsonj 1775023Scarlsonj if (mdb_vread(&next, sizeof (next), 1785023Scarlsonj wsp->walk_addr + offsetof(list_t, list_head) + 1795023Scarlsonj offsetof(list_node_t, list_next)) == -1 || 1805023Scarlsonj next == NULL) { 1815023Scarlsonj mdb_warn("non-DEBUG image; cannot walk th_hash list\n"); 1825023Scarlsonj return (WALK_ERR); 1835023Scarlsonj } 1845023Scarlsonj 1855023Scarlsonj if (mdb_layered_walk("list", wsp) == -1) { 1865023Scarlsonj mdb_warn("can't walk 'list'"); 1875023Scarlsonj return (WALK_ERR); 1885023Scarlsonj } else { 1895023Scarlsonj return (WALK_NEXT); 1905023Scarlsonj } 1915023Scarlsonj } 1925023Scarlsonj 1935023Scarlsonj int 1945023Scarlsonj th_hash_walk_step(mdb_walk_state_t *wsp) 1955023Scarlsonj { 1965023Scarlsonj return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer, 1975023Scarlsonj wsp->walk_cbdata)); 1985023Scarlsonj } 1995023Scarlsonj 2003448Sdh155122 /* 2013448Sdh155122 * Called with walk_addr being the address of ips_ill_g_heads 2023448Sdh155122 */ 2033448Sdh155122 int 2043448Sdh155122 illif_stack_walk_init(mdb_walk_state_t *wsp) 2050Sstevel@tonic-gate { 2060Sstevel@tonic-gate illif_walk_data_t *iw; 2070Sstevel@tonic-gate 2083448Sdh155122 if (wsp->walk_addr == NULL) { 2093448Sdh155122 mdb_warn("illif_stack supports only local walks\n"); 2100Sstevel@tonic-gate return (WALK_ERR); 2110Sstevel@tonic-gate } 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate iw = mdb_alloc(sizeof (illif_walk_data_t), UM_SLEEP); 2140Sstevel@tonic-gate 2153448Sdh155122 if (mdb_vread(iw->ill_g_heads, MAX_G_HEADS * sizeof (ill_g_head_t), 2163448Sdh155122 wsp->walk_addr) == -1) { 2173448Sdh155122 mdb_warn("failed to read 'ips_ill_g_heads' at %p", 2183448Sdh155122 wsp->walk_addr); 2190Sstevel@tonic-gate mdb_free(iw, sizeof (illif_walk_data_t)); 2200Sstevel@tonic-gate return (WALK_ERR); 2210Sstevel@tonic-gate } 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate iw->ill_list = 0; 2243448Sdh155122 wsp->walk_addr = (uintptr_t)iw->ill_g_heads[0].ill_g_list_head; 2250Sstevel@tonic-gate wsp->walk_data = iw; 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate return (WALK_NEXT); 2280Sstevel@tonic-gate } 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate int 2313448Sdh155122 illif_stack_walk_step(mdb_walk_state_t *wsp) 2320Sstevel@tonic-gate { 2330Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 2340Sstevel@tonic-gate illif_walk_data_t *iw = wsp->walk_data; 2350Sstevel@tonic-gate int list = iw->ill_list; 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate if (mdb_vread(&iw->ill_if, sizeof (ill_if_t), addr) == -1) { 2380Sstevel@tonic-gate mdb_warn("failed to read ill_if_t at %p", addr); 2390Sstevel@tonic-gate return (WALK_ERR); 2400Sstevel@tonic-gate } 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)iw->ill_if.illif_next; 2430Sstevel@tonic-gate 2443448Sdh155122 if (wsp->walk_addr == 2453448Sdh155122 (uintptr_t)iw->ill_g_heads[list].ill_g_list_head) { 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate if (++list >= MAX_G_HEADS) 2480Sstevel@tonic-gate return (WALK_DONE); 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate iw->ill_list = list; 2513448Sdh155122 wsp->walk_addr = 2523448Sdh155122 (uintptr_t)iw->ill_g_heads[list].ill_g_list_head; 2530Sstevel@tonic-gate return (WALK_NEXT); 2540Sstevel@tonic-gate } 2550Sstevel@tonic-gate 2560Sstevel@tonic-gate return (wsp->walk_callback(addr, iw, wsp->walk_cbdata)); 2570Sstevel@tonic-gate } 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate void 2603448Sdh155122 illif_stack_walk_fini(mdb_walk_state_t *wsp) 2610Sstevel@tonic-gate { 2620Sstevel@tonic-gate mdb_free(wsp->walk_data, sizeof (illif_walk_data_t)); 2630Sstevel@tonic-gate } 2640Sstevel@tonic-gate 2650Sstevel@tonic-gate typedef struct illif_cbdata { 2660Sstevel@tonic-gate uint_t ill_flags; 2670Sstevel@tonic-gate uintptr_t ill_addr; 2680Sstevel@tonic-gate int ill_printlist; /* list to be printed (MAX_G_HEADS for all) */ 2690Sstevel@tonic-gate boolean_t ill_printed; 2700Sstevel@tonic-gate } illif_cbdata_t; 2710Sstevel@tonic-gate 2720Sstevel@tonic-gate static int 2730Sstevel@tonic-gate illif_cb(uintptr_t addr, const illif_walk_data_t *iw, illif_cbdata_t *id) 2740Sstevel@tonic-gate { 2750Sstevel@tonic-gate const char *version; 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate if (id->ill_printlist < MAX_G_HEADS && 2780Sstevel@tonic-gate id->ill_printlist != iw->ill_list) 2790Sstevel@tonic-gate return (WALK_NEXT); 2800Sstevel@tonic-gate 2810Sstevel@tonic-gate if (id->ill_flags & DCMD_ADDRSPEC && id->ill_addr != addr) 2820Sstevel@tonic-gate return (WALK_NEXT); 2830Sstevel@tonic-gate 2840Sstevel@tonic-gate if (id->ill_flags & DCMD_PIPE_OUT) { 2850Sstevel@tonic-gate mdb_printf("%p\n", addr); 2860Sstevel@tonic-gate return (WALK_NEXT); 2870Sstevel@tonic-gate } 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate switch (iw->ill_list) { 2900Sstevel@tonic-gate case IP_V4_G_HEAD: version = "v4"; break; 2910Sstevel@tonic-gate case IP_V6_G_HEAD: version = "v6"; break; 2920Sstevel@tonic-gate default: version = "??"; break; 2930Sstevel@tonic-gate } 2940Sstevel@tonic-gate 2950Sstevel@tonic-gate mdb_printf("%?p %2s %?p %10d %?p %s\n", 2960Sstevel@tonic-gate addr, version, addr + offsetof(ill_if_t, illif_avl_by_ppa), 2970Sstevel@tonic-gate iw->ill_if.illif_avl_by_ppa.avl_numnodes, 2980Sstevel@tonic-gate iw->ill_if.illif_ppa_arena, iw->ill_if.illif_name); 2990Sstevel@tonic-gate 3000Sstevel@tonic-gate id->ill_printed = TRUE; 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate return (WALK_NEXT); 3030Sstevel@tonic-gate } 3040Sstevel@tonic-gate 3050Sstevel@tonic-gate int 3065940Ssowmini ip_stacks_common_walk_init(mdb_walk_state_t *wsp) 3073448Sdh155122 { 3083448Sdh155122 if (mdb_layered_walk("ip_stacks", wsp) == -1) { 3093448Sdh155122 mdb_warn("can't walk 'ip_stacks'"); 3103448Sdh155122 return (WALK_ERR); 3113448Sdh155122 } 3123448Sdh155122 3133448Sdh155122 return (WALK_NEXT); 3143448Sdh155122 } 3153448Sdh155122 3163448Sdh155122 int 3173448Sdh155122 illif_walk_step(mdb_walk_state_t *wsp) 3183448Sdh155122 { 3193448Sdh155122 uintptr_t kaddr; 3203448Sdh155122 3213448Sdh155122 kaddr = wsp->walk_addr + OFFSETOF(ip_stack_t, ips_ill_g_heads); 3223448Sdh155122 3233448Sdh155122 if (mdb_vread(&kaddr, sizeof (kaddr), kaddr) == -1) { 3243448Sdh155122 mdb_warn("can't read ips_ip_cache_table at %p", kaddr); 3253448Sdh155122 return (WALK_ERR); 3263448Sdh155122 } 3273448Sdh155122 3283448Sdh155122 if (mdb_pwalk("illif_stack", wsp->walk_callback, 3295023Scarlsonj wsp->walk_cbdata, kaddr) == -1) { 3303448Sdh155122 mdb_warn("couldn't walk 'illif_stack' for ips_ill_g_heads %p", 3313448Sdh155122 kaddr); 3323448Sdh155122 return (WALK_ERR); 3333448Sdh155122 } 3343448Sdh155122 return (WALK_NEXT); 3353448Sdh155122 } 3363448Sdh155122 3373448Sdh155122 int 3380Sstevel@tonic-gate illif(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3390Sstevel@tonic-gate { 3400Sstevel@tonic-gate illif_cbdata_t id; 3410Sstevel@tonic-gate ill_if_t ill_if; 3420Sstevel@tonic-gate const char *opt_P = NULL; 3430Sstevel@tonic-gate int printlist = MAX_G_HEADS; 3440Sstevel@tonic-gate 3450Sstevel@tonic-gate if (mdb_getopts(argc, argv, 3460Sstevel@tonic-gate 'P', MDB_OPT_STR, &opt_P, NULL) != argc) 3470Sstevel@tonic-gate return (DCMD_USAGE); 3480Sstevel@tonic-gate 3490Sstevel@tonic-gate if (opt_P != NULL) { 3500Sstevel@tonic-gate if (strcmp("v4", opt_P) == 0) { 3510Sstevel@tonic-gate printlist = IP_V4_G_HEAD; 3520Sstevel@tonic-gate } else if (strcmp("v6", opt_P) == 0) { 3530Sstevel@tonic-gate printlist = IP_V6_G_HEAD; 3540Sstevel@tonic-gate } else { 3550Sstevel@tonic-gate mdb_warn("invalid protocol '%s'\n", opt_P); 3560Sstevel@tonic-gate return (DCMD_USAGE); 3570Sstevel@tonic-gate } 3580Sstevel@tonic-gate } 3590Sstevel@tonic-gate 3600Sstevel@tonic-gate if (DCMD_HDRSPEC(flags) && (flags & DCMD_PIPE_OUT) == 0) { 3610Sstevel@tonic-gate mdb_printf("%<u>%?s %2s %?s %10s %?s %-10s%</u>\n", 3620Sstevel@tonic-gate "ADDR", "IP", "AVLADDR", "NUMNODES", "ARENA", "NAME"); 3630Sstevel@tonic-gate } 3640Sstevel@tonic-gate 3650Sstevel@tonic-gate id.ill_flags = flags; 3660Sstevel@tonic-gate id.ill_addr = addr; 3670Sstevel@tonic-gate id.ill_printlist = printlist; 3680Sstevel@tonic-gate id.ill_printed = FALSE; 3690Sstevel@tonic-gate 3700Sstevel@tonic-gate if (mdb_walk("illif", (mdb_walk_cb_t)illif_cb, &id) == -1) { 3710Sstevel@tonic-gate mdb_warn("can't walk ill_if_t structures"); 3720Sstevel@tonic-gate return (DCMD_ERR); 3730Sstevel@tonic-gate } 3740Sstevel@tonic-gate 3750Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC) || opt_P != NULL || id.ill_printed) 3760Sstevel@tonic-gate return (DCMD_OK); 3770Sstevel@tonic-gate 3780Sstevel@tonic-gate /* 3790Sstevel@tonic-gate * If an address is specified and the walk doesn't find it, 3800Sstevel@tonic-gate * print it anyway. 3810Sstevel@tonic-gate */ 3820Sstevel@tonic-gate if (mdb_vread(&ill_if, sizeof (ill_if_t), addr) == -1) { 3830Sstevel@tonic-gate mdb_warn("failed to read ill_if_t at %p", addr); 3840Sstevel@tonic-gate return (DCMD_ERR); 3850Sstevel@tonic-gate } 3860Sstevel@tonic-gate 3870Sstevel@tonic-gate mdb_printf("%?p %2s %?p %10d %?p %s\n", 3880Sstevel@tonic-gate addr, "??", addr + offsetof(ill_if_t, illif_avl_by_ppa), 3890Sstevel@tonic-gate ill_if.illif_avl_by_ppa.avl_numnodes, 3900Sstevel@tonic-gate ill_if.illif_ppa_arena, ill_if.illif_name); 3910Sstevel@tonic-gate 3920Sstevel@tonic-gate return (DCMD_OK); 3930Sstevel@tonic-gate } 3940Sstevel@tonic-gate 3950Sstevel@tonic-gate static void 3960Sstevel@tonic-gate illif_help(void) 3970Sstevel@tonic-gate { 3980Sstevel@tonic-gate mdb_printf("Options:\n"); 3990Sstevel@tonic-gate mdb_printf("\t-P v4 | v6" 4000Sstevel@tonic-gate "\tfilter interface structures for the specified protocol\n"); 4010Sstevel@tonic-gate } 4020Sstevel@tonic-gate 4030Sstevel@tonic-gate int 4040Sstevel@tonic-gate ire_walk_init(mdb_walk_state_t *wsp) 4050Sstevel@tonic-gate { 4060Sstevel@tonic-gate if (mdb_layered_walk("ire_cache", wsp) == -1) { 4070Sstevel@tonic-gate mdb_warn("can't walk 'ire_cache'"); 4080Sstevel@tonic-gate return (WALK_ERR); 4090Sstevel@tonic-gate } 4100Sstevel@tonic-gate 4110Sstevel@tonic-gate return (WALK_NEXT); 4120Sstevel@tonic-gate } 4130Sstevel@tonic-gate 4140Sstevel@tonic-gate int 4150Sstevel@tonic-gate ire_walk_step(mdb_walk_state_t *wsp) 4160Sstevel@tonic-gate { 4170Sstevel@tonic-gate ire_t ire; 4180Sstevel@tonic-gate 4190Sstevel@tonic-gate if (mdb_vread(&ire, sizeof (ire), wsp->walk_addr) == -1) { 4200Sstevel@tonic-gate mdb_warn("can't read ire at %p", wsp->walk_addr); 4210Sstevel@tonic-gate return (WALK_ERR); 4220Sstevel@tonic-gate } 4230Sstevel@tonic-gate 4240Sstevel@tonic-gate return (wsp->walk_callback(wsp->walk_addr, &ire, wsp->walk_cbdata)); 4250Sstevel@tonic-gate } 4260Sstevel@tonic-gate 4273448Sdh155122 4283448Sdh155122 int 4293448Sdh155122 ire_ctable_walk_step(mdb_walk_state_t *wsp) 4303448Sdh155122 { 4313448Sdh155122 uintptr_t kaddr; 4323448Sdh155122 irb_t *irb; 4333448Sdh155122 uint32_t cache_table_size; 4343448Sdh155122 int i; 4355940Ssowmini ire_cbdata_t ire_cb; 4363448Sdh155122 4375940Ssowmini ire_cb.verbose = B_FALSE; 4385940Ssowmini ire_cb.ire_ipversion = 0; 4395940Ssowmini 4403448Sdh155122 4413448Sdh155122 kaddr = wsp->walk_addr + OFFSETOF(ip_stack_t, ips_ip_cache_table_size); 4423448Sdh155122 4433448Sdh155122 if (mdb_vread(&cache_table_size, sizeof (uint32_t), kaddr) == -1) { 4443448Sdh155122 mdb_warn("can't read ips_ip_cache_table at %p", kaddr); 4453448Sdh155122 return (WALK_ERR); 4463448Sdh155122 } 4473448Sdh155122 4483448Sdh155122 kaddr = wsp->walk_addr + OFFSETOF(ip_stack_t, ips_ip_cache_table); 4493448Sdh155122 if (mdb_vread(&kaddr, sizeof (kaddr), kaddr) == -1) { 4503448Sdh155122 mdb_warn("can't read ips_ip_cache_table at %p", kaddr); 4513448Sdh155122 return (WALK_ERR); 4523448Sdh155122 } 4533448Sdh155122 4543448Sdh155122 irb = mdb_alloc(sizeof (irb_t) * cache_table_size, UM_SLEEP|UM_GC); 4553448Sdh155122 if (mdb_vread(irb, sizeof (irb_t) * cache_table_size, kaddr) == -1) { 4563448Sdh155122 mdb_warn("can't read irb at %p", kaddr); 4573448Sdh155122 return (WALK_ERR); 4583448Sdh155122 } 4593448Sdh155122 for (i = 0; i < cache_table_size; i++) { 4603448Sdh155122 kaddr = (uintptr_t)irb[i].irb_ire; 4613448Sdh155122 4625940Ssowmini if (mdb_pwalk("ire_next", ire_format, &ire_cb, 4635023Scarlsonj kaddr) == -1) { 4643448Sdh155122 mdb_warn("can't walk 'ire_next' for ire %p", kaddr); 4653448Sdh155122 return (WALK_ERR); 4663448Sdh155122 } 4673448Sdh155122 } 4683448Sdh155122 return (WALK_NEXT); 4693448Sdh155122 } 4703448Sdh155122 4713448Sdh155122 /* ARGSUSED */ 4723448Sdh155122 int 4733448Sdh155122 ire_next_walk_init(mdb_walk_state_t *wsp) 4743448Sdh155122 { 4753448Sdh155122 return (WALK_NEXT); 4763448Sdh155122 } 4773448Sdh155122 4783448Sdh155122 int 4793448Sdh155122 ire_next_walk_step(mdb_walk_state_t *wsp) 4803448Sdh155122 { 4813448Sdh155122 ire_t ire; 4823448Sdh155122 int status; 4833448Sdh155122 4843448Sdh155122 4853448Sdh155122 if (wsp->walk_addr == NULL) 4863448Sdh155122 return (WALK_DONE); 4873448Sdh155122 4883448Sdh155122 if (mdb_vread(&ire, sizeof (ire), wsp->walk_addr) == -1) { 4893448Sdh155122 mdb_warn("can't read ire at %p", wsp->walk_addr); 4903448Sdh155122 return (WALK_ERR); 4913448Sdh155122 } 4923448Sdh155122 status = wsp->walk_callback(wsp->walk_addr, &ire, 4933448Sdh155122 wsp->walk_cbdata); 4943448Sdh155122 4953448Sdh155122 if (status != WALK_NEXT) 4963448Sdh155122 return (status); 4973448Sdh155122 4983448Sdh155122 wsp->walk_addr = (uintptr_t)ire.ire_next; 4993448Sdh155122 return (status); 5003448Sdh155122 } 5013448Sdh155122 5020Sstevel@tonic-gate static int 5035940Ssowmini ire_format(uintptr_t addr, const void *ire_arg, void *ire_cb_arg) 5040Sstevel@tonic-gate { 5055940Ssowmini const ire_t *irep = ire_arg; 5065940Ssowmini ire_cbdata_t *ire_cb = ire_cb_arg; 5075940Ssowmini boolean_t verbose = ire_cb->verbose; 5085940Ssowmini 5090Sstevel@tonic-gate static const mdb_bitmask_t tmasks[] = { 5100Sstevel@tonic-gate { "BROADCAST", IRE_BROADCAST, IRE_BROADCAST }, 5110Sstevel@tonic-gate { "DEFAULT", IRE_DEFAULT, IRE_DEFAULT }, 5120Sstevel@tonic-gate { "LOCAL", IRE_LOCAL, IRE_LOCAL }, 5130Sstevel@tonic-gate { "LOOPBACK", IRE_LOOPBACK, IRE_LOOPBACK }, 5140Sstevel@tonic-gate { "PREFIX", IRE_PREFIX, IRE_PREFIX }, 5150Sstevel@tonic-gate { "CACHE", IRE_CACHE, IRE_CACHE }, 5160Sstevel@tonic-gate { "IF_NORESOLVER", IRE_IF_NORESOLVER, IRE_IF_NORESOLVER }, 5170Sstevel@tonic-gate { "IF_RESOLVER", IRE_IF_RESOLVER, IRE_IF_RESOLVER }, 5180Sstevel@tonic-gate { "HOST", IRE_HOST, IRE_HOST }, 5190Sstevel@tonic-gate { "HOST_REDIRECT", IRE_HOST_REDIRECT, IRE_HOST_REDIRECT }, 5200Sstevel@tonic-gate { NULL, 0, 0 } 5210Sstevel@tonic-gate }; 5220Sstevel@tonic-gate 5230Sstevel@tonic-gate static const mdb_bitmask_t mmasks[] = { 5240Sstevel@tonic-gate { "CONDEMNED", IRE_MARK_CONDEMNED, IRE_MARK_CONDEMNED }, 525*8485SPeter.Memishian@Sun.COM { "TESTHIDDEN", IRE_MARK_TESTHIDDEN, IRE_MARK_TESTHIDDEN }, 5260Sstevel@tonic-gate { "NOADD", IRE_MARK_NOADD, IRE_MARK_NOADD }, 5270Sstevel@tonic-gate { "TEMPORARY", IRE_MARK_TEMPORARY, IRE_MARK_TEMPORARY }, 5285940Ssowmini { "USESRC", IRE_MARK_USESRC_CHECK, IRE_MARK_USESRC_CHECK }, 5295940Ssowmini { "PRIVATE", IRE_MARK_PRIVATE_ADDR, IRE_MARK_PRIVATE_ADDR }, 5305940Ssowmini { "UNCACHED", IRE_MARK_UNCACHED, IRE_MARK_UNCACHED }, 5310Sstevel@tonic-gate { NULL, 0, 0 } 5320Sstevel@tonic-gate }; 5330Sstevel@tonic-gate 5340Sstevel@tonic-gate static const mdb_bitmask_t fmasks[] = { 5350Sstevel@tonic-gate { "UP", RTF_UP, RTF_UP }, 5360Sstevel@tonic-gate { "GATEWAY", RTF_GATEWAY, RTF_GATEWAY }, 5370Sstevel@tonic-gate { "HOST", RTF_HOST, RTF_HOST }, 5380Sstevel@tonic-gate { "REJECT", RTF_REJECT, RTF_REJECT }, 5390Sstevel@tonic-gate { "DYNAMIC", RTF_DYNAMIC, RTF_DYNAMIC }, 5400Sstevel@tonic-gate { "MODIFIED", RTF_MODIFIED, RTF_MODIFIED }, 5410Sstevel@tonic-gate { "DONE", RTF_DONE, RTF_DONE }, 5420Sstevel@tonic-gate { "MASK", RTF_MASK, RTF_MASK }, 5430Sstevel@tonic-gate { "CLONING", RTF_CLONING, RTF_CLONING }, 5440Sstevel@tonic-gate { "XRESOLVE", RTF_XRESOLVE, RTF_XRESOLVE }, 5450Sstevel@tonic-gate { "LLINFO", RTF_LLINFO, RTF_LLINFO }, 5460Sstevel@tonic-gate { "STATIC", RTF_STATIC, RTF_STATIC }, 5470Sstevel@tonic-gate { "BLACKHOLE", RTF_BLACKHOLE, RTF_BLACKHOLE }, 5480Sstevel@tonic-gate { "PRIVATE", RTF_PRIVATE, RTF_PRIVATE }, 5490Sstevel@tonic-gate { "PROTO2", RTF_PROTO2, RTF_PROTO2 }, 5500Sstevel@tonic-gate { "PROTO1", RTF_PROTO1, RTF_PROTO1 }, 5510Sstevel@tonic-gate { "MULTIRT", RTF_MULTIRT, RTF_MULTIRT }, 5520Sstevel@tonic-gate { "SETSRC", RTF_SETSRC, RTF_SETSRC }, 5530Sstevel@tonic-gate { NULL, 0, 0 } 5540Sstevel@tonic-gate }; 5550Sstevel@tonic-gate 5565940Ssowmini if (ire_cb->ire_ipversion != 0 && 5575940Ssowmini irep->ire_ipversion != ire_cb->ire_ipversion) 5585940Ssowmini return (WALK_NEXT); 5595940Ssowmini 5605940Ssowmini if (irep->ire_ipversion == IPV6_VERSION && verbose) { 5610Sstevel@tonic-gate 5620Sstevel@tonic-gate mdb_printf("%<b>%?p%</b> %40N <%hb>\n" 5630Sstevel@tonic-gate "%?s %40N <%hb>\n" 5643448Sdh155122 "%?s %40d %4d <%hb>\n", 5650Sstevel@tonic-gate addr, &irep->ire_src_addr_v6, irep->ire_type, tmasks, 5660Sstevel@tonic-gate "", &irep->ire_addr_v6, (ushort_t)irep->ire_marks, mmasks, 5673448Sdh155122 "", ips_to_stackid((uintptr_t)irep->ire_ipst), 5683448Sdh155122 irep->ire_zoneid, 5693448Sdh155122 irep->ire_flags, fmasks); 5700Sstevel@tonic-gate 5715940Ssowmini } else if (irep->ire_ipversion == IPV6_VERSION) { 5720Sstevel@tonic-gate 5733448Sdh155122 mdb_printf("%?p %30N %30N %5d %4d\n", 5743448Sdh155122 addr, &irep->ire_src_addr_v6, 5753448Sdh155122 &irep->ire_addr_v6, 5763448Sdh155122 ips_to_stackid((uintptr_t)irep->ire_ipst), 5773448Sdh155122 irep->ire_zoneid); 5780Sstevel@tonic-gate 5795940Ssowmini } else if (verbose) { 5800Sstevel@tonic-gate 5810Sstevel@tonic-gate mdb_printf("%<b>%?p%</b> %40I <%hb>\n" 5820Sstevel@tonic-gate "%?s %40I <%hb>\n" 5835940Ssowmini "%?s %40d %4d <%hb>\n", 5840Sstevel@tonic-gate addr, irep->ire_src_addr, irep->ire_type, tmasks, 5850Sstevel@tonic-gate "", irep->ire_addr, (ushort_t)irep->ire_marks, mmasks, 5863448Sdh155122 "", ips_to_stackid((uintptr_t)irep->ire_ipst), 5873448Sdh155122 irep->ire_zoneid, irep->ire_flags, fmasks); 5880Sstevel@tonic-gate 5890Sstevel@tonic-gate } else { 5900Sstevel@tonic-gate 5913448Sdh155122 mdb_printf("%?p %30I %30I %5d %4d\n", addr, irep->ire_src_addr, 5923448Sdh155122 irep->ire_addr, ips_to_stackid((uintptr_t)irep->ire_ipst), 5933448Sdh155122 irep->ire_zoneid); 5940Sstevel@tonic-gate } 5950Sstevel@tonic-gate 5960Sstevel@tonic-gate return (WALK_NEXT); 5970Sstevel@tonic-gate } 5980Sstevel@tonic-gate 5990Sstevel@tonic-gate /* 6000Sstevel@tonic-gate * There are faster ways to do this. Given the interactive nature of this 6010Sstevel@tonic-gate * use I don't think its worth much effort. 6020Sstevel@tonic-gate */ 6030Sstevel@tonic-gate static unsigned short 6040Sstevel@tonic-gate ipcksum(void *p, int len) 6050Sstevel@tonic-gate { 6060Sstevel@tonic-gate int32_t sum = 0; 6070Sstevel@tonic-gate 6080Sstevel@tonic-gate while (len > 1) { 6090Sstevel@tonic-gate /* alignment */ 6100Sstevel@tonic-gate sum += *(uint16_t *)p; 6110Sstevel@tonic-gate p = (char *)p + sizeof (uint16_t); 6120Sstevel@tonic-gate if (sum & 0x80000000) 6130Sstevel@tonic-gate sum = (sum & 0xFFFF) + (sum >> 16); 6140Sstevel@tonic-gate len -= 2; 6150Sstevel@tonic-gate } 6160Sstevel@tonic-gate 6170Sstevel@tonic-gate if (len) 6180Sstevel@tonic-gate sum += (uint16_t)*(unsigned char *)p; 6190Sstevel@tonic-gate 6200Sstevel@tonic-gate while (sum >> 16) 6210Sstevel@tonic-gate sum = (sum & 0xFFFF) + (sum >> 16); 6220Sstevel@tonic-gate 6230Sstevel@tonic-gate return (~sum); 6240Sstevel@tonic-gate } 6250Sstevel@tonic-gate 6260Sstevel@tonic-gate static const mdb_bitmask_t tcp_flags[] = { 6270Sstevel@tonic-gate { "SYN", TH_SYN, TH_SYN }, 6280Sstevel@tonic-gate { "ACK", TH_ACK, TH_ACK }, 6290Sstevel@tonic-gate { "FIN", TH_FIN, TH_FIN }, 6300Sstevel@tonic-gate { "RST", TH_RST, TH_RST }, 6310Sstevel@tonic-gate { "PSH", TH_PUSH, TH_PUSH }, 6320Sstevel@tonic-gate { "ECE", TH_ECE, TH_ECE }, 6330Sstevel@tonic-gate { "CWR", TH_CWR, TH_CWR }, 6340Sstevel@tonic-gate { NULL, 0, 0 } 6350Sstevel@tonic-gate }; 6360Sstevel@tonic-gate 6370Sstevel@tonic-gate static void 6380Sstevel@tonic-gate tcphdr_print(struct tcphdr *tcph) 6390Sstevel@tonic-gate { 6400Sstevel@tonic-gate in_port_t sport, dport; 6410Sstevel@tonic-gate tcp_seq seq, ack; 6420Sstevel@tonic-gate uint16_t win, urp; 6430Sstevel@tonic-gate 6440Sstevel@tonic-gate mdb_printf("%<b>TCP header%</b>\n"); 6450Sstevel@tonic-gate 6460Sstevel@tonic-gate mdb_nhconvert(&sport, &tcph->th_sport, sizeof (sport)); 6470Sstevel@tonic-gate mdb_nhconvert(&dport, &tcph->th_dport, sizeof (dport)); 6480Sstevel@tonic-gate mdb_nhconvert(&seq, &tcph->th_seq, sizeof (seq)); 6490Sstevel@tonic-gate mdb_nhconvert(&ack, &tcph->th_ack, sizeof (ack)); 6500Sstevel@tonic-gate mdb_nhconvert(&win, &tcph->th_win, sizeof (win)); 6510Sstevel@tonic-gate mdb_nhconvert(&urp, &tcph->th_urp, sizeof (urp)); 6520Sstevel@tonic-gate 6530Sstevel@tonic-gate mdb_printf("%<u>%6s %6s %10s %10s %4s %5s %5s %5s %-15s%</u>\n", 6540Sstevel@tonic-gate "SPORT", "DPORT", "SEQ", "ACK", "HLEN", "WIN", "CSUM", "URP", 6550Sstevel@tonic-gate "FLAGS"); 6560Sstevel@tonic-gate mdb_printf("%6hu %6hu %10u %10u %4d %5hu %5hu %5hu <%b>\n", 6570Sstevel@tonic-gate sport, dport, seq, ack, tcph->th_off << 2, win, 6580Sstevel@tonic-gate tcph->th_sum, urp, tcph->th_flags, tcp_flags); 6590Sstevel@tonic-gate mdb_printf("0x%04x 0x%04x 0x%08x 0x%08x\n\n", 6600Sstevel@tonic-gate sport, dport, seq, ack); 6610Sstevel@tonic-gate } 6620Sstevel@tonic-gate 6630Sstevel@tonic-gate /* ARGSUSED */ 6640Sstevel@tonic-gate static int 6650Sstevel@tonic-gate tcphdr(uintptr_t addr, uint_t flags, int ac, const mdb_arg_t *av) 6660Sstevel@tonic-gate { 6670Sstevel@tonic-gate struct tcphdr tcph; 6680Sstevel@tonic-gate 6690Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 6700Sstevel@tonic-gate return (DCMD_USAGE); 6710Sstevel@tonic-gate 6720Sstevel@tonic-gate if (mdb_vread(&tcph, sizeof (tcph), addr) == -1) { 6730Sstevel@tonic-gate mdb_warn("failed to read TCP header at %p", addr); 6740Sstevel@tonic-gate return (DCMD_ERR); 6750Sstevel@tonic-gate } 6760Sstevel@tonic-gate tcphdr_print(&tcph); 6770Sstevel@tonic-gate return (DCMD_OK); 6780Sstevel@tonic-gate } 6790Sstevel@tonic-gate 6800Sstevel@tonic-gate static void 6810Sstevel@tonic-gate udphdr_print(struct udphdr *udph) 6820Sstevel@tonic-gate { 6830Sstevel@tonic-gate in_port_t sport, dport; 6840Sstevel@tonic-gate uint16_t hlen; 6850Sstevel@tonic-gate 6860Sstevel@tonic-gate mdb_printf("%<b>UDP header%</b>\n"); 6870Sstevel@tonic-gate 6880Sstevel@tonic-gate mdb_nhconvert(&sport, &udph->uh_sport, sizeof (sport)); 6890Sstevel@tonic-gate mdb_nhconvert(&dport, &udph->uh_dport, sizeof (dport)); 6900Sstevel@tonic-gate mdb_nhconvert(&hlen, &udph->uh_ulen, sizeof (hlen)); 6910Sstevel@tonic-gate 6920Sstevel@tonic-gate mdb_printf("%<u>%14s %14s %5s %6s%</u>\n", 6930Sstevel@tonic-gate "SPORT", "DPORT", "LEN", "CSUM"); 6940Sstevel@tonic-gate mdb_printf("%5hu (0x%04x) %5hu (0x%04x) %5hu 0x%04hx\n\n", sport, sport, 6950Sstevel@tonic-gate dport, dport, hlen, udph->uh_sum); 6960Sstevel@tonic-gate } 6970Sstevel@tonic-gate 6980Sstevel@tonic-gate /* ARGSUSED */ 6990Sstevel@tonic-gate static int 7000Sstevel@tonic-gate udphdr(uintptr_t addr, uint_t flags, int ac, const mdb_arg_t *av) 7010Sstevel@tonic-gate { 7020Sstevel@tonic-gate struct udphdr udph; 7030Sstevel@tonic-gate 7040Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 7050Sstevel@tonic-gate return (DCMD_USAGE); 7060Sstevel@tonic-gate 7070Sstevel@tonic-gate if (mdb_vread(&udph, sizeof (udph), addr) == -1) { 7080Sstevel@tonic-gate mdb_warn("failed to read UDP header at %p", addr); 7090Sstevel@tonic-gate return (DCMD_ERR); 7100Sstevel@tonic-gate } 7110Sstevel@tonic-gate udphdr_print(&udph); 7120Sstevel@tonic-gate return (DCMD_OK); 7130Sstevel@tonic-gate } 7140Sstevel@tonic-gate 7150Sstevel@tonic-gate static void 7160Sstevel@tonic-gate sctphdr_print(sctp_hdr_t *sctph) 7170Sstevel@tonic-gate { 7180Sstevel@tonic-gate in_port_t sport, dport; 7190Sstevel@tonic-gate 7200Sstevel@tonic-gate mdb_printf("%<b>SCTP header%</b>\n"); 7210Sstevel@tonic-gate mdb_nhconvert(&sport, &sctph->sh_sport, sizeof (sport)); 7220Sstevel@tonic-gate mdb_nhconvert(&dport, &sctph->sh_dport, sizeof (dport)); 7230Sstevel@tonic-gate 7240Sstevel@tonic-gate mdb_printf("%<u>%14s %14s %10s %10s%</u>\n", 7250Sstevel@tonic-gate "SPORT", "DPORT", "VTAG", "CHKSUM"); 7260Sstevel@tonic-gate mdb_printf("%5hu (0x%04x) %5hu (0x%04x) %10u 0x%08x\n\n", sport, sport, 7270Sstevel@tonic-gate dport, dport, sctph->sh_verf, sctph->sh_chksum); 7280Sstevel@tonic-gate } 7290Sstevel@tonic-gate 7300Sstevel@tonic-gate /* ARGSUSED */ 7310Sstevel@tonic-gate static int 7320Sstevel@tonic-gate sctphdr(uintptr_t addr, uint_t flags, int ac, const mdb_arg_t *av) 7330Sstevel@tonic-gate { 7340Sstevel@tonic-gate sctp_hdr_t sctph; 7350Sstevel@tonic-gate 7360Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 7370Sstevel@tonic-gate return (DCMD_USAGE); 7380Sstevel@tonic-gate 7390Sstevel@tonic-gate if (mdb_vread(&sctph, sizeof (sctph), addr) == -1) { 7400Sstevel@tonic-gate mdb_warn("failed to read SCTP header at %p", addr); 7410Sstevel@tonic-gate return (DCMD_ERR); 7420Sstevel@tonic-gate } 7430Sstevel@tonic-gate 7440Sstevel@tonic-gate sctphdr_print(&sctph); 7450Sstevel@tonic-gate return (DCMD_OK); 7460Sstevel@tonic-gate } 7470Sstevel@tonic-gate 7480Sstevel@tonic-gate static int 7490Sstevel@tonic-gate transport_hdr(int proto, uintptr_t addr) 7500Sstevel@tonic-gate { 7510Sstevel@tonic-gate mdb_printf("\n"); 7520Sstevel@tonic-gate switch (proto) { 7530Sstevel@tonic-gate case IPPROTO_TCP: { 7540Sstevel@tonic-gate struct tcphdr tcph; 7550Sstevel@tonic-gate 7560Sstevel@tonic-gate if (mdb_vread(&tcph, sizeof (tcph), addr) == -1) { 7570Sstevel@tonic-gate mdb_warn("failed to read TCP header at %p", addr); 7580Sstevel@tonic-gate return (DCMD_ERR); 7590Sstevel@tonic-gate } 7600Sstevel@tonic-gate tcphdr_print(&tcph); 7610Sstevel@tonic-gate break; 7620Sstevel@tonic-gate } 7630Sstevel@tonic-gate case IPPROTO_UDP: { 7640Sstevel@tonic-gate struct udphdr udph; 7650Sstevel@tonic-gate 7660Sstevel@tonic-gate if (mdb_vread(&udph, sizeof (udph), addr) == -1) { 7670Sstevel@tonic-gate mdb_warn("failed to read UDP header at %p", addr); 7680Sstevel@tonic-gate return (DCMD_ERR); 7690Sstevel@tonic-gate } 7700Sstevel@tonic-gate udphdr_print(&udph); 7710Sstevel@tonic-gate break; 7720Sstevel@tonic-gate } 7730Sstevel@tonic-gate case IPPROTO_SCTP: { 7740Sstevel@tonic-gate sctp_hdr_t sctph; 7750Sstevel@tonic-gate 7760Sstevel@tonic-gate if (mdb_vread(&sctph, sizeof (sctph), addr) == -1) { 7770Sstevel@tonic-gate mdb_warn("failed to read SCTP header at %p", addr); 7780Sstevel@tonic-gate return (DCMD_ERR); 7790Sstevel@tonic-gate } 7800Sstevel@tonic-gate sctphdr_print(&sctph); 7810Sstevel@tonic-gate break; 7820Sstevel@tonic-gate } 7830Sstevel@tonic-gate default: 7840Sstevel@tonic-gate break; 7850Sstevel@tonic-gate } 7860Sstevel@tonic-gate 7870Sstevel@tonic-gate return (DCMD_OK); 7880Sstevel@tonic-gate } 7890Sstevel@tonic-gate 7900Sstevel@tonic-gate static const mdb_bitmask_t ip_flags[] = { 7910Sstevel@tonic-gate { "DF", IPH_DF, IPH_DF }, 7920Sstevel@tonic-gate { "MF", IPH_MF, IPH_MF }, 7930Sstevel@tonic-gate { NULL, 0, 0 } 7940Sstevel@tonic-gate }; 7950Sstevel@tonic-gate 7960Sstevel@tonic-gate /* ARGSUSED */ 7970Sstevel@tonic-gate static int 7980Sstevel@tonic-gate iphdr(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 7990Sstevel@tonic-gate { 8000Sstevel@tonic-gate uint_t verbose = FALSE, force = FALSE; 8010Sstevel@tonic-gate ipha_t iph[1]; 8020Sstevel@tonic-gate uint16_t ver, totlen, hdrlen, ipid, off, csum; 8030Sstevel@tonic-gate uintptr_t nxt_proto; 8040Sstevel@tonic-gate char exp_csum[8]; 8050Sstevel@tonic-gate 8060Sstevel@tonic-gate if (mdb_getopts(argc, argv, 8070Sstevel@tonic-gate 'v', MDB_OPT_SETBITS, TRUE, &verbose, 8080Sstevel@tonic-gate 'f', MDB_OPT_SETBITS, TRUE, &force, NULL) != argc) 8090Sstevel@tonic-gate return (DCMD_USAGE); 8100Sstevel@tonic-gate 8110Sstevel@tonic-gate if (mdb_vread(iph, sizeof (*iph), addr) == -1) { 8120Sstevel@tonic-gate mdb_warn("failed to read IPv4 header at %p", addr); 8130Sstevel@tonic-gate return (DCMD_ERR); 8140Sstevel@tonic-gate } 8150Sstevel@tonic-gate 8160Sstevel@tonic-gate ver = (iph->ipha_version_and_hdr_length & 0xf0) >> 4; 8170Sstevel@tonic-gate if (ver != IPV4_VERSION) { 8180Sstevel@tonic-gate if (ver == IPV6_VERSION) { 8190Sstevel@tonic-gate return (ip6hdr(addr, flags, argc, argv)); 8200Sstevel@tonic-gate } else if (!force) { 8210Sstevel@tonic-gate mdb_warn("unknown IP version: %d\n", ver); 8220Sstevel@tonic-gate return (DCMD_ERR); 8230Sstevel@tonic-gate } 8240Sstevel@tonic-gate } 8250Sstevel@tonic-gate 8260Sstevel@tonic-gate mdb_printf("%<b>IPv4 header%</b>\n"); 8270Sstevel@tonic-gate mdb_printf("%-34s %-34s\n" 8280Sstevel@tonic-gate "%<u>%-4s %-4s %-5s %-5s %-6s %-5s %-5s %-6s %-8s %-6s%</u>\n", 8290Sstevel@tonic-gate "SRC", "DST", 8300Sstevel@tonic-gate "HLEN", "TOS", "LEN", "ID", "OFFSET", "TTL", "PROTO", "CHKSUM", 8310Sstevel@tonic-gate "EXP-CSUM", "FLGS"); 8320Sstevel@tonic-gate 8330Sstevel@tonic-gate hdrlen = (iph->ipha_version_and_hdr_length & 0x0f) << 2; 8340Sstevel@tonic-gate mdb_nhconvert(&totlen, &iph->ipha_length, sizeof (totlen)); 8350Sstevel@tonic-gate mdb_nhconvert(&ipid, &iph->ipha_ident, sizeof (ipid)); 8360Sstevel@tonic-gate mdb_nhconvert(&off, &iph->ipha_fragment_offset_and_flags, sizeof (off)); 8370Sstevel@tonic-gate if (hdrlen == IP_SIMPLE_HDR_LENGTH) { 8380Sstevel@tonic-gate if ((csum = ipcksum(iph, sizeof (*iph))) != 0) 8390Sstevel@tonic-gate csum = ~(~csum + ~iph->ipha_hdr_checksum); 8400Sstevel@tonic-gate else 8410Sstevel@tonic-gate csum = iph->ipha_hdr_checksum; 8420Sstevel@tonic-gate mdb_snprintf(exp_csum, 8, "%u", csum); 8430Sstevel@tonic-gate } else { 8440Sstevel@tonic-gate mdb_snprintf(exp_csum, 8, "<n/a>"); 8450Sstevel@tonic-gate } 8460Sstevel@tonic-gate 8470Sstevel@tonic-gate mdb_printf("%-34I %-34I%\n" 8480Sstevel@tonic-gate "%-4d %-4d %-5hu %-5hu %-6hu %-5hu %-5hu %-6u %-8s <%5hb>\n", 8490Sstevel@tonic-gate iph->ipha_src, iph->ipha_dst, 8500Sstevel@tonic-gate hdrlen, iph->ipha_type_of_service, totlen, ipid, 8510Sstevel@tonic-gate (off << 3) & 0xffff, iph->ipha_ttl, iph->ipha_protocol, 8520Sstevel@tonic-gate iph->ipha_hdr_checksum, exp_csum, off, ip_flags); 8530Sstevel@tonic-gate 8540Sstevel@tonic-gate if (verbose) { 8550Sstevel@tonic-gate nxt_proto = addr + hdrlen; 8560Sstevel@tonic-gate return (transport_hdr(iph->ipha_protocol, nxt_proto)); 8570Sstevel@tonic-gate } else { 8580Sstevel@tonic-gate return (DCMD_OK); 8590Sstevel@tonic-gate } 8600Sstevel@tonic-gate } 8610Sstevel@tonic-gate 8620Sstevel@tonic-gate /* ARGSUSED */ 8630Sstevel@tonic-gate static int 8640Sstevel@tonic-gate ip6hdr(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 8650Sstevel@tonic-gate { 8660Sstevel@tonic-gate uint_t verbose = FALSE, force = FALSE; 8670Sstevel@tonic-gate ip6_t iph[1]; 8680Sstevel@tonic-gate int ver, class, flow; 8690Sstevel@tonic-gate uint16_t plen; 8700Sstevel@tonic-gate uintptr_t nxt_proto; 8710Sstevel@tonic-gate 8720Sstevel@tonic-gate if (mdb_getopts(argc, argv, 8730Sstevel@tonic-gate 'v', MDB_OPT_SETBITS, TRUE, &verbose, 8740Sstevel@tonic-gate 'f', MDB_OPT_SETBITS, TRUE, &force, NULL) != argc) 8750Sstevel@tonic-gate return (DCMD_USAGE); 8760Sstevel@tonic-gate 8770Sstevel@tonic-gate if (mdb_vread(iph, sizeof (*iph), addr) == -1) { 8780Sstevel@tonic-gate mdb_warn("failed to read IPv6 header at %p", addr); 8790Sstevel@tonic-gate return (DCMD_ERR); 8800Sstevel@tonic-gate } 8810Sstevel@tonic-gate 8820Sstevel@tonic-gate ver = (iph->ip6_vfc & 0xf0) >> 4; 8830Sstevel@tonic-gate if (ver != IPV6_VERSION) { 8840Sstevel@tonic-gate if (ver == IPV4_VERSION) { 8850Sstevel@tonic-gate return (iphdr(addr, flags, argc, argv)); 8860Sstevel@tonic-gate } else if (!force) { 8870Sstevel@tonic-gate mdb_warn("unknown IP version: %d\n", ver); 8880Sstevel@tonic-gate return (DCMD_ERR); 8890Sstevel@tonic-gate } 8900Sstevel@tonic-gate } 8910Sstevel@tonic-gate 8920Sstevel@tonic-gate mdb_printf("%<b>IPv6 header%</b>\n"); 8930Sstevel@tonic-gate mdb_printf("%<u>%-26s %-26s %4s %7s %5s %3s %3s%</u>\n", 8940Sstevel@tonic-gate "SRC", "DST", "TCLS", "FLOW-ID", "PLEN", "NXT", "HOP"); 8950Sstevel@tonic-gate 8960Sstevel@tonic-gate class = (iph->ip6_vcf & IPV6_FLOWINFO_TCLASS) >> 20; 8970Sstevel@tonic-gate mdb_nhconvert(&class, &class, sizeof (class)); 8980Sstevel@tonic-gate flow = iph->ip6_vcf & IPV6_FLOWINFO_FLOWLABEL; 8990Sstevel@tonic-gate mdb_nhconvert(&flow, &flow, sizeof (flow)); 9000Sstevel@tonic-gate mdb_nhconvert(&plen, &iph->ip6_plen, sizeof (plen)); 9010Sstevel@tonic-gate 9020Sstevel@tonic-gate mdb_printf("%-26N %-26N %4d %7d %5hu %3d %3d\n", 9030Sstevel@tonic-gate &iph->ip6_src, &iph->ip6_dst, 9040Sstevel@tonic-gate class, flow, plen, iph->ip6_nxt, iph->ip6_hlim); 9050Sstevel@tonic-gate 9060Sstevel@tonic-gate if (verbose) { 9070Sstevel@tonic-gate nxt_proto = addr + sizeof (ip6_t); 9080Sstevel@tonic-gate return (transport_hdr(iph->ip6_nxt, nxt_proto)); 9090Sstevel@tonic-gate } else { 9100Sstevel@tonic-gate return (DCMD_OK); 9110Sstevel@tonic-gate } 9120Sstevel@tonic-gate } 9130Sstevel@tonic-gate 9140Sstevel@tonic-gate int 9150Sstevel@tonic-gate ire(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 9160Sstevel@tonic-gate { 9170Sstevel@tonic-gate uint_t verbose = FALSE; 9180Sstevel@tonic-gate ire_t ire; 9195940Ssowmini ire_cbdata_t ire_cb; 9205940Ssowmini int ipversion = 0; 9215940Ssowmini const char *opt_P = NULL; 9220Sstevel@tonic-gate 9230Sstevel@tonic-gate if (mdb_getopts(argc, argv, 9245940Ssowmini 'v', MDB_OPT_SETBITS, TRUE, &verbose, 9255940Ssowmini 'P', MDB_OPT_STR, &opt_P, NULL) != argc) 9260Sstevel@tonic-gate return (DCMD_USAGE); 9270Sstevel@tonic-gate 9285940Ssowmini if (opt_P != NULL) { 9295940Ssowmini if (strcmp("v4", opt_P) == 0) { 9305940Ssowmini ipversion = IPV4_VERSION; 9315940Ssowmini } else if (strcmp("v6", opt_P) == 0) { 9325940Ssowmini ipversion = IPV6_VERSION; 9335940Ssowmini } else { 9345940Ssowmini mdb_warn("invalid protocol '%s'\n", opt_P); 9355940Ssowmini return (DCMD_USAGE); 9365940Ssowmini } 9375940Ssowmini } 9385940Ssowmini 9390Sstevel@tonic-gate if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) { 9400Sstevel@tonic-gate 9410Sstevel@tonic-gate if (verbose) { 9420Sstevel@tonic-gate mdb_printf("%?s %40s %-20s%\n" 9430Sstevel@tonic-gate "%?s %40s %-20s%\n" 9443448Sdh155122 "%<u>%?s %40s %4s %-20s%</u>\n", 9450Sstevel@tonic-gate "ADDR", "SRC", "TYPE", 9460Sstevel@tonic-gate "", "DST", "MARKS", 9473448Sdh155122 "", "STACK", "ZONE", "FLAGS"); 9480Sstevel@tonic-gate } else { 9493448Sdh155122 mdb_printf("%<u>%?s %30s %30s %5s %4s%</u>\n", 9503448Sdh155122 "ADDR", "SRC", "DST", "STACK", "ZONE"); 9510Sstevel@tonic-gate } 9520Sstevel@tonic-gate } 9530Sstevel@tonic-gate 9545940Ssowmini ire_cb.verbose = (verbose == TRUE); 9555940Ssowmini ire_cb.ire_ipversion = ipversion; 9565940Ssowmini 9570Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC) { 9580Sstevel@tonic-gate (void) mdb_vread(&ire, sizeof (ire_t), addr); 9595940Ssowmini (void) ire_format(addr, &ire, &ire_cb); 9605940Ssowmini } else if (mdb_walk("ire", (mdb_walk_cb_t)ire_format, &ire_cb) == -1) { 9610Sstevel@tonic-gate mdb_warn("failed to walk ire table"); 9620Sstevel@tonic-gate return (DCMD_ERR); 9630Sstevel@tonic-gate } 9640Sstevel@tonic-gate 9650Sstevel@tonic-gate return (DCMD_OK); 9660Sstevel@tonic-gate } 9670Sstevel@tonic-gate 9680Sstevel@tonic-gate static size_t 9690Sstevel@tonic-gate mi_osize(const queue_t *q) 9700Sstevel@tonic-gate { 9710Sstevel@tonic-gate /* 9720Sstevel@tonic-gate * The code in common/inet/mi.c allocates an extra word to store the 9730Sstevel@tonic-gate * size of the allocation. An mi_o_s is thus a size_t plus an mi_o_s. 9740Sstevel@tonic-gate */ 9750Sstevel@tonic-gate struct mi_block { 9760Sstevel@tonic-gate size_t mi_nbytes; 9770Sstevel@tonic-gate struct mi_o_s mi_o; 9780Sstevel@tonic-gate } m; 9790Sstevel@tonic-gate 9800Sstevel@tonic-gate if (mdb_vread(&m, sizeof (m), (uintptr_t)q->q_ptr - 9810Sstevel@tonic-gate sizeof (m)) == sizeof (m)) 9820Sstevel@tonic-gate return (m.mi_nbytes - sizeof (m)); 9830Sstevel@tonic-gate 9840Sstevel@tonic-gate return (0); 9850Sstevel@tonic-gate } 9860Sstevel@tonic-gate 9870Sstevel@tonic-gate static void 9880Sstevel@tonic-gate ip_ill_qinfo(const queue_t *q, char *buf, size_t nbytes) 9890Sstevel@tonic-gate { 9900Sstevel@tonic-gate char name[32]; 9910Sstevel@tonic-gate ill_t ill; 9920Sstevel@tonic-gate 9930Sstevel@tonic-gate if (mdb_vread(&ill, sizeof (ill), 9940Sstevel@tonic-gate (uintptr_t)q->q_ptr) == sizeof (ill) && 9950Sstevel@tonic-gate mdb_readstr(name, sizeof (name), (uintptr_t)ill.ill_name) > 0) 9960Sstevel@tonic-gate (void) mdb_snprintf(buf, nbytes, "if: %s", name); 9970Sstevel@tonic-gate } 9980Sstevel@tonic-gate 9990Sstevel@tonic-gate void 10000Sstevel@tonic-gate ip_qinfo(const queue_t *q, char *buf, size_t nbytes) 10010Sstevel@tonic-gate { 10020Sstevel@tonic-gate size_t size = mi_osize(q); 10030Sstevel@tonic-gate 10040Sstevel@tonic-gate if (size == sizeof (ill_t)) 10050Sstevel@tonic-gate ip_ill_qinfo(q, buf, nbytes); 10060Sstevel@tonic-gate } 10070Sstevel@tonic-gate 10080Sstevel@tonic-gate uintptr_t 10090Sstevel@tonic-gate ip_rnext(const queue_t *q) 10100Sstevel@tonic-gate { 10110Sstevel@tonic-gate size_t size = mi_osize(q); 10120Sstevel@tonic-gate ill_t ill; 10130Sstevel@tonic-gate 10140Sstevel@tonic-gate if (size == sizeof (ill_t) && mdb_vread(&ill, sizeof (ill), 10150Sstevel@tonic-gate (uintptr_t)q->q_ptr) == sizeof (ill)) 10160Sstevel@tonic-gate return ((uintptr_t)ill.ill_rq); 10170Sstevel@tonic-gate 10180Sstevel@tonic-gate return (NULL); 10190Sstevel@tonic-gate } 10200Sstevel@tonic-gate 10210Sstevel@tonic-gate uintptr_t 10220Sstevel@tonic-gate ip_wnext(const queue_t *q) 10230Sstevel@tonic-gate { 10240Sstevel@tonic-gate size_t size = mi_osize(q); 10250Sstevel@tonic-gate ill_t ill; 10260Sstevel@tonic-gate 10270Sstevel@tonic-gate if (size == sizeof (ill_t) && mdb_vread(&ill, sizeof (ill), 10280Sstevel@tonic-gate (uintptr_t)q->q_ptr) == sizeof (ill)) 10290Sstevel@tonic-gate return ((uintptr_t)ill.ill_wq); 10300Sstevel@tonic-gate 10310Sstevel@tonic-gate return (NULL); 10320Sstevel@tonic-gate } 10330Sstevel@tonic-gate 10340Sstevel@tonic-gate /* 10350Sstevel@tonic-gate * Print the core fields in an squeue_t. With the "-v" argument, 10360Sstevel@tonic-gate * provide more verbose output. 10370Sstevel@tonic-gate */ 10380Sstevel@tonic-gate static int 10390Sstevel@tonic-gate squeue(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 10400Sstevel@tonic-gate { 10410Sstevel@tonic-gate unsigned int i; 10420Sstevel@tonic-gate unsigned int verbose = FALSE; 10430Sstevel@tonic-gate const int SQUEUE_STATEDELT = (int)(sizeof (uintptr_t) + 9); 10440Sstevel@tonic-gate boolean_t arm; 10450Sstevel@tonic-gate squeue_t squeue; 10460Sstevel@tonic-gate 10470Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) { 10480Sstevel@tonic-gate if (mdb_walk_dcmd("genunix`squeue_cache", "ip`squeue", 10490Sstevel@tonic-gate argc, argv) == -1) { 10500Sstevel@tonic-gate mdb_warn("failed to walk squeue cache"); 10510Sstevel@tonic-gate return (DCMD_ERR); 10520Sstevel@tonic-gate } 10530Sstevel@tonic-gate return (DCMD_OK); 10540Sstevel@tonic-gate } 10550Sstevel@tonic-gate 10560Sstevel@tonic-gate if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, TRUE, &verbose, NULL) 10570Sstevel@tonic-gate != argc) 10580Sstevel@tonic-gate return (DCMD_USAGE); 10590Sstevel@tonic-gate 10600Sstevel@tonic-gate if (!DCMD_HDRSPEC(flags) && verbose) 10610Sstevel@tonic-gate mdb_printf("\n\n"); 10620Sstevel@tonic-gate 10630Sstevel@tonic-gate if (DCMD_HDRSPEC(flags) || verbose) { 10640Sstevel@tonic-gate mdb_printf("%?s %-5s %-3s %?s %?s %?s\n", 10650Sstevel@tonic-gate "ADDR", "STATE", "CPU", 10660Sstevel@tonic-gate "FIRST", "LAST", "WORKER"); 10670Sstevel@tonic-gate } 10680Sstevel@tonic-gate 10690Sstevel@tonic-gate if (mdb_vread(&squeue, sizeof (squeue_t), addr) == -1) { 10700Sstevel@tonic-gate mdb_warn("cannot read squeue_t at %p", addr); 10710Sstevel@tonic-gate return (DCMD_ERR); 10720Sstevel@tonic-gate } 10730Sstevel@tonic-gate 10740Sstevel@tonic-gate mdb_printf("%0?p %05x %3d %0?p %0?p %0?p\n", 10750Sstevel@tonic-gate addr, squeue.sq_state, squeue.sq_bind, 10760Sstevel@tonic-gate squeue.sq_first, squeue.sq_last, squeue.sq_worker); 10770Sstevel@tonic-gate 10780Sstevel@tonic-gate if (!verbose) 10790Sstevel@tonic-gate return (DCMD_OK); 10800Sstevel@tonic-gate 10810Sstevel@tonic-gate arm = B_TRUE; 10820Sstevel@tonic-gate for (i = 0; squeue_states[i].bit_name != NULL; i++) { 10830Sstevel@tonic-gate if (((squeue.sq_state) & (1 << i)) == 0) 10840Sstevel@tonic-gate continue; 10850Sstevel@tonic-gate 10860Sstevel@tonic-gate if (arm) { 10870Sstevel@tonic-gate mdb_printf("%*s|\n", SQUEUE_STATEDELT, ""); 10880Sstevel@tonic-gate mdb_printf("%*s+--> ", SQUEUE_STATEDELT, ""); 10890Sstevel@tonic-gate arm = B_FALSE; 10900Sstevel@tonic-gate } else 10910Sstevel@tonic-gate mdb_printf("%*s ", SQUEUE_STATEDELT, ""); 10920Sstevel@tonic-gate 10930Sstevel@tonic-gate mdb_printf("%-12s %s\n", squeue_states[i].bit_name, 10940Sstevel@tonic-gate squeue_states[i].bit_descr); 10950Sstevel@tonic-gate } 10960Sstevel@tonic-gate 10970Sstevel@tonic-gate return (DCMD_OK); 10980Sstevel@tonic-gate } 10990Sstevel@tonic-gate 11000Sstevel@tonic-gate static void 11010Sstevel@tonic-gate ip_squeue_help(void) 11020Sstevel@tonic-gate { 11030Sstevel@tonic-gate mdb_printf("Print the core information for a given NCA squeue_t.\n\n"); 11040Sstevel@tonic-gate mdb_printf("Options:\n"); 11050Sstevel@tonic-gate mdb_printf("\t-v\tbe verbose (more descriptive)\n"); 11060Sstevel@tonic-gate } 11070Sstevel@tonic-gate 11085023Scarlsonj /* 11095023Scarlsonj * This is called by ::th_trace (via a callback) when walking the th_hash 11105023Scarlsonj * list. It calls modent to find the entries. 11115023Scarlsonj */ 11125023Scarlsonj /* ARGSUSED */ 11135023Scarlsonj static int 11145023Scarlsonj modent_summary(uintptr_t addr, const void *data, void *private) 11155023Scarlsonj { 11165023Scarlsonj th_walk_data_t *thw = private; 11175023Scarlsonj const struct mod_hash_entry *mhe = data; 11185023Scarlsonj th_trace_t th; 11195023Scarlsonj 11205023Scarlsonj if (mdb_vread(&th, sizeof (th), (uintptr_t)mhe->mhe_val) == -1) { 11215023Scarlsonj mdb_warn("failed to read th_trace_t %p", mhe->mhe_val); 11225023Scarlsonj return (WALK_ERR); 11235023Scarlsonj } 11245023Scarlsonj 11255023Scarlsonj if (th.th_refcnt == 0 && thw->thw_non_zero_only) 11265023Scarlsonj return (WALK_NEXT); 11275023Scarlsonj 11285023Scarlsonj if (!thw->thw_match) { 11295023Scarlsonj mdb_printf("%?p %?p %?p %8d %?p\n", thw->thw_ipst, mhe->mhe_key, 11305023Scarlsonj mhe->mhe_val, th.th_refcnt, th.th_id); 11315023Scarlsonj } else if (thw->thw_matchkey == (uintptr_t)mhe->mhe_key) { 11325023Scarlsonj int i, j, k; 11335023Scarlsonj tr_buf_t *tr; 11345023Scarlsonj 11355023Scarlsonj mdb_printf("Object %p in IP stack %p:\n", mhe->mhe_key, 11365023Scarlsonj thw->thw_ipst); 11375023Scarlsonj i = th.th_trace_lastref; 11385023Scarlsonj mdb_printf("\tThread %p refcnt %d:\n", th.th_id, 11395023Scarlsonj th.th_refcnt); 11405023Scarlsonj for (j = TR_BUF_MAX; j > 0; j--) { 11415023Scarlsonj tr = th.th_trbuf + i; 11425023Scarlsonj if (tr->tr_depth == 0 || tr->tr_depth > TR_STACK_DEPTH) 11435023Scarlsonj break; 11445023Scarlsonj mdb_printf("\t T%+ld:\n", tr->tr_time - 11455023Scarlsonj thw->thw_lbolt); 11465023Scarlsonj for (k = 0; k < tr->tr_depth; k++) 11475023Scarlsonj mdb_printf("\t\t%a\n", tr->tr_stack[k]); 11485023Scarlsonj if (--i < 0) 11495023Scarlsonj i = TR_BUF_MAX - 1; 11505023Scarlsonj } 11515023Scarlsonj } 11525023Scarlsonj return (WALK_NEXT); 11535023Scarlsonj } 11545023Scarlsonj 11555023Scarlsonj /* 11565023Scarlsonj * This is called by ::th_trace (via a callback) when walking the th_hash 11575023Scarlsonj * list. It calls modent to find the entries. 11585023Scarlsonj */ 11595023Scarlsonj /* ARGSUSED */ 11605023Scarlsonj static int 11615023Scarlsonj th_hash_summary(uintptr_t addr, const void *data, void *private) 11625023Scarlsonj { 11635023Scarlsonj const th_hash_t *thh = data; 11645023Scarlsonj th_walk_data_t *thw = private; 11655023Scarlsonj 11665023Scarlsonj thw->thw_ipst = (uintptr_t)thh->thh_ipst; 11675023Scarlsonj return (mdb_pwalk("modent", modent_summary, private, 11685023Scarlsonj (uintptr_t)thh->thh_hash)); 11695023Scarlsonj } 11705023Scarlsonj 11715023Scarlsonj /* 11725023Scarlsonj * Print or summarize the th_trace_t structures. 11735023Scarlsonj */ 11745023Scarlsonj static int 11755023Scarlsonj th_trace(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 11765023Scarlsonj { 11775023Scarlsonj th_walk_data_t thw; 11785023Scarlsonj 11795023Scarlsonj (void) memset(&thw, 0, sizeof (thw)); 11805023Scarlsonj 11815023Scarlsonj if (mdb_getopts(argc, argv, 11825023Scarlsonj 'n', MDB_OPT_SETBITS, TRUE, &thw.thw_non_zero_only, 11835023Scarlsonj NULL) != argc) 11845023Scarlsonj return (DCMD_USAGE); 11855023Scarlsonj 11865023Scarlsonj if (!(flags & DCMD_ADDRSPEC)) { 11875023Scarlsonj /* 11885023Scarlsonj * No address specified. Walk all of the th_hash_t in the 11895023Scarlsonj * system, and summarize the th_trace_t entries in each. 11905023Scarlsonj */ 11915023Scarlsonj mdb_printf("%?s %?s %?s %8s %?s\n", 11925023Scarlsonj "IPSTACK", "OBJECT", "TRACE", "REFCNT", "THREAD"); 11935023Scarlsonj thw.thw_match = B_FALSE; 11945023Scarlsonj } else { 11955023Scarlsonj thw.thw_match = B_TRUE; 11965023Scarlsonj thw.thw_matchkey = addr; 11975023Scarlsonj if (mdb_readvar(&thw.thw_lbolt, 11985023Scarlsonj mdb_prop_postmortem ? "panic_lbolt" : "lbolt") == -1) { 11995023Scarlsonj mdb_warn("failed to read lbolt"); 12005023Scarlsonj return (DCMD_ERR); 12015023Scarlsonj } 12025023Scarlsonj } 12035023Scarlsonj if (mdb_pwalk("th_hash", th_hash_summary, &thw, NULL) == -1) { 12045023Scarlsonj mdb_warn("can't walk th_hash entries"); 12055023Scarlsonj return (DCMD_ERR); 12065023Scarlsonj } 12075023Scarlsonj return (DCMD_OK); 12085023Scarlsonj } 12095023Scarlsonj 12105023Scarlsonj static void 12115023Scarlsonj th_trace_help(void) 12125023Scarlsonj { 12135023Scarlsonj mdb_printf("If given an address of an ill_t, ipif_t, ire_t, or nce_t, " 12145023Scarlsonj "print the\n" 12155023Scarlsonj "corresponding th_trace_t structure in detail. Otherwise, if no " 12165023Scarlsonj "address is\n" 12175023Scarlsonj "given, then summarize all th_trace_t structures.\n\n"); 12185023Scarlsonj mdb_printf("Options:\n" 12195023Scarlsonj "\t-n\tdisplay only entries with non-zero th_refcnt\n"); 12205023Scarlsonj } 12215023Scarlsonj 12220Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = { 12230Sstevel@tonic-gate { "illif", "?[-P v4 | v6]", 12240Sstevel@tonic-gate "display or filter IP Lower Level InterFace structures", illif, 12250Sstevel@tonic-gate illif_help }, 12260Sstevel@tonic-gate { "iphdr", ":[-vf]", "display an IPv4 header", iphdr }, 12270Sstevel@tonic-gate { "ip6hdr", ":[-vf]", "display an IPv6 header", ip6hdr }, 12285940Ssowmini { "ire", "?[-v] [-P v4|v6]", 12295940Ssowmini "display Internet Route Entry structures", ire }, 12305940Ssowmini { "nce", "?[-P v4 | v6]", "display Neighbor Cache Entry structures", 12315940Ssowmini nce }, 12320Sstevel@tonic-gate { "squeue", ":[-v]", "print core squeue_t info", squeue, 12330Sstevel@tonic-gate ip_squeue_help }, 12340Sstevel@tonic-gate { "tcphdr", ":", "display a TCP header", tcphdr }, 12350Sstevel@tonic-gate { "udphdr", ":", "display an UDP header", udphdr }, 12360Sstevel@tonic-gate { "sctphdr", ":", "display an SCTP header", sctphdr }, 12375023Scarlsonj { "th_trace", "?[-n]", "display th_trace_t structures", th_trace, 12385023Scarlsonj th_trace_help }, 12390Sstevel@tonic-gate { NULL } 12400Sstevel@tonic-gate }; 12410Sstevel@tonic-gate 12420Sstevel@tonic-gate static const mdb_walker_t walkers[] = { 12433448Sdh155122 { "illif", "walk list of ill interface types for all stacks", 12445940Ssowmini ip_stacks_common_walk_init, illif_walk_step, NULL }, 12453448Sdh155122 { "illif_stack", "walk list of ill interface types", 12463448Sdh155122 illif_stack_walk_init, illif_stack_walk_step, 12473448Sdh155122 illif_stack_walk_fini }, 12480Sstevel@tonic-gate { "ire", "walk active ire_t structures", 12490Sstevel@tonic-gate ire_walk_init, ire_walk_step, NULL }, 12503448Sdh155122 { "ire_ctable", "walk ire_t structures in the ctable", 12515940Ssowmini ip_stacks_common_walk_init, ire_ctable_walk_step, NULL }, 12523448Sdh155122 { "ire_next", "walk ire_t structures in the ctable", 12533448Sdh155122 ire_next_walk_init, ire_next_walk_step, NULL }, 12543448Sdh155122 { "ip_stacks", "walk all the ip_stack_t", 12553448Sdh155122 ip_stacks_walk_init, ip_stacks_walk_step, NULL }, 12565023Scarlsonj { "th_hash", "walk all the th_hash_t entries", 12575023Scarlsonj th_hash_walk_init, th_hash_walk_step, NULL }, 12585940Ssowmini { "nce", "walk list of nce structures for all stacks", 12595940Ssowmini ip_stacks_common_walk_init, nce_walk_step, NULL }, 12605940Ssowmini { "nce_stack", "walk list of nce structures", 12615940Ssowmini nce_stack_walk_init, nce_stack_walk_step, 12625940Ssowmini nce_stack_walk_fini}, 12630Sstevel@tonic-gate { NULL } 12640Sstevel@tonic-gate }; 12650Sstevel@tonic-gate 12660Sstevel@tonic-gate static const mdb_qops_t ip_qops = { ip_qinfo, ip_rnext, ip_wnext }; 12670Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers }; 12680Sstevel@tonic-gate 12690Sstevel@tonic-gate const mdb_modinfo_t * 12700Sstevel@tonic-gate _mdb_init(void) 12710Sstevel@tonic-gate { 12720Sstevel@tonic-gate GElf_Sym sym; 12730Sstevel@tonic-gate 12742546Scarlsonj if (mdb_lookup_by_obj("ip", "ipwinit", &sym) == 0) 12750Sstevel@tonic-gate mdb_qops_install(&ip_qops, (uintptr_t)sym.st_value); 12760Sstevel@tonic-gate 12770Sstevel@tonic-gate return (&modinfo); 12780Sstevel@tonic-gate } 12790Sstevel@tonic-gate 12800Sstevel@tonic-gate void 12810Sstevel@tonic-gate _mdb_fini(void) 12820Sstevel@tonic-gate { 12830Sstevel@tonic-gate GElf_Sym sym; 12840Sstevel@tonic-gate 12852546Scarlsonj if (mdb_lookup_by_obj("ip", "ipwinit", &sym) == 0) 12860Sstevel@tonic-gate mdb_qops_remove(&ip_qops, (uintptr_t)sym.st_value); 12870Sstevel@tonic-gate } 12885940Ssowmini 12895940Ssowmini static char * 12905940Ssowmini nce_state(int nce_state) 12915940Ssowmini { 12925940Ssowmini switch (nce_state) { 12935940Ssowmini case ND_UNCHANGED: 12945940Ssowmini return ("unchanged"); 12955940Ssowmini case ND_INCOMPLETE: 12965940Ssowmini return ("incomplete"); 12975940Ssowmini case ND_REACHABLE: 12985940Ssowmini return ("reachable"); 12995940Ssowmini case ND_STALE: 13005940Ssowmini return ("stale"); 13015940Ssowmini case ND_DELAY: 13025940Ssowmini return ("delay"); 13035940Ssowmini case ND_PROBE: 13045940Ssowmini return ("probe"); 13055940Ssowmini case ND_UNREACHABLE: 13065940Ssowmini return ("unreach"); 13075940Ssowmini case ND_INITIAL: 13085940Ssowmini return ("initial"); 13095940Ssowmini default: 13105940Ssowmini return ("??"); 13115940Ssowmini } 13125940Ssowmini } 13135940Ssowmini 13145940Ssowmini static char * 13155940Ssowmini nce_l2_addr(const nce_t *nce, const ill_t *ill) 13165940Ssowmini { 13175940Ssowmini uchar_t *h; 13185940Ssowmini static char addr_buf[L2MAXADDRSTRLEN]; 13195940Ssowmini mblk_t mp; 13205940Ssowmini size_t mblen; 13215940Ssowmini 13225940Ssowmini if (ill->ill_flags & ILLF_XRESOLV) { 13235940Ssowmini return ("XRESOLV"); 13245940Ssowmini } 13255940Ssowmini 13265940Ssowmini if (nce->nce_res_mp == NULL) { 13275940Ssowmini return ("None"); 13285940Ssowmini } 13295940Ssowmini 13305940Ssowmini if (ill->ill_net_type == IRE_IF_RESOLVER) { 13315940Ssowmini 13325940Ssowmini if (mdb_vread(&mp, sizeof (mblk_t), 13335940Ssowmini (uintptr_t)nce->nce_res_mp) == -1) { 13345940Ssowmini mdb_warn("failed to read nce_res_mp at %p", 13355940Ssowmini nce->nce_res_mp); 13365940Ssowmini } 13375940Ssowmini 13385940Ssowmini if (ill->ill_nd_lla_len == 0) 13395940Ssowmini return ("None"); 13405940Ssowmini mblen = mp.b_wptr - mp.b_rptr; 13415940Ssowmini if (mblen > (sizeof (dl_unitdata_req_t) + MAX_SAP_LEN) || 13425940Ssowmini ill->ill_nd_lla_len > MAX_SAP_LEN || 13435940Ssowmini NCE_LL_ADDR_OFFSET(ill) + ill->ill_nd_lla_len > mblen) { 13445940Ssowmini return ("Truncated"); 13455940Ssowmini } 13465940Ssowmini h = mdb_zalloc(mblen, UM_SLEEP); 13475940Ssowmini if (mdb_vread(h, mblen, (uintptr_t)(mp.b_rptr)) == -1) { 13485940Ssowmini mdb_warn("failed to read hwaddr at %p", 13495940Ssowmini mp.b_rptr + NCE_LL_ADDR_OFFSET(ill)); 13505940Ssowmini return ("Unknown"); 13515940Ssowmini } 13525940Ssowmini mdb_mac_addr(h + NCE_LL_ADDR_OFFSET(ill), ill->ill_nd_lla_len, 13535940Ssowmini addr_buf, sizeof (addr_buf)); 13545940Ssowmini } else { 13555940Ssowmini return ("None"); 13565940Ssowmini } 13575940Ssowmini mdb_free(h, mblen); 13585940Ssowmini return (addr_buf); 13595940Ssowmini } 13605940Ssowmini 13615940Ssowmini static void 13625940Ssowmini nce_header(uint_t flags) 13635940Ssowmini { 13645940Ssowmini if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) { 13655940Ssowmini 13665940Ssowmini mdb_printf("%<u>%?s %-20s %-10s %-8s %-5s %s%</u>\n", 13675940Ssowmini "ADDR", "HW_ADDR", "STATE", "FLAGS", "ILL", "IP ADDR"); 13685940Ssowmini } 13695940Ssowmini } 13705940Ssowmini 13715940Ssowmini int 13725940Ssowmini nce(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 13735940Ssowmini { 13745940Ssowmini nce_t nce; 13755940Ssowmini nce_cbdata_t id; 13765940Ssowmini int ipversion = 0; 13775940Ssowmini const char *opt_P = NULL; 13785940Ssowmini 13795940Ssowmini if (mdb_getopts(argc, argv, 13805940Ssowmini 'P', MDB_OPT_STR, &opt_P, NULL) != argc) 13815940Ssowmini return (DCMD_USAGE); 13825940Ssowmini 13835940Ssowmini if (opt_P != NULL) { 13845940Ssowmini if (strcmp("v4", opt_P) == 0) { 13855940Ssowmini ipversion = IPV4_VERSION; 13865940Ssowmini } else if (strcmp("v6", opt_P) == 0) { 13875940Ssowmini ipversion = IPV6_VERSION; 13885940Ssowmini } else { 13895940Ssowmini mdb_warn("invalid protocol '%s'\n", opt_P); 13905940Ssowmini return (DCMD_USAGE); 13915940Ssowmini } 13925940Ssowmini } 13935940Ssowmini 13945940Ssowmini if (flags & DCMD_ADDRSPEC) { 13955940Ssowmini 13965940Ssowmini if (mdb_vread(&nce, sizeof (nce_t), addr) == -1) { 13975940Ssowmini mdb_warn("failed to read nce at %p\n", addr); 13985940Ssowmini return (DCMD_ERR); 13995940Ssowmini } 14005940Ssowmini if (ipversion != 0 && nce.nce_ipversion != ipversion) { 14015940Ssowmini mdb_printf("IP Version mismatch\n"); 14025940Ssowmini return (DCMD_ERR); 14035940Ssowmini } 14045940Ssowmini nce_header(flags); 14055940Ssowmini return (nce_format(addr, &nce, ipversion)); 14065940Ssowmini 14075940Ssowmini } else { 14085940Ssowmini id.nce_addr = addr; 14095940Ssowmini id.nce_ipversion = ipversion; 14105940Ssowmini nce_header(flags); 14115940Ssowmini if (mdb_walk("nce", (mdb_walk_cb_t)nce_cb, &id) == -1) { 14125940Ssowmini mdb_warn("failed to walk nce table\n"); 14135940Ssowmini return (DCMD_ERR); 14145940Ssowmini } 14155940Ssowmini } 14165940Ssowmini return (DCMD_OK); 14175940Ssowmini } 14185940Ssowmini 14195940Ssowmini static int 14205940Ssowmini nce_format(uintptr_t addr, const nce_t *nce, int ipversion) 14215940Ssowmini { 14225940Ssowmini static const mdb_bitmask_t nce_flags[] = { 14235940Ssowmini { "P", NCE_F_PERMANENT, NCE_F_PERMANENT }, 14245940Ssowmini { "R", NCE_F_ISROUTER, NCE_F_ISROUTER }, 14255940Ssowmini { "N", NCE_F_NONUD, NCE_F_NONUD }, 14265940Ssowmini { "A", NCE_F_ANYCAST, NCE_F_ANYCAST }, 14275940Ssowmini { "C", NCE_F_CONDEMNED, NCE_F_CONDEMNED }, 14285940Ssowmini { "U", NCE_F_UNSOL_ADV, NCE_F_UNSOL_ADV }, 14295940Ssowmini { "B", NCE_F_BCAST, NCE_F_BCAST }, 14305940Ssowmini { NULL, 0, 0 } 14315940Ssowmini }; 14325940Ssowmini #define NCE_MAX_FLAGS (sizeof (nce_flags) / sizeof (mdb_bitmask_t)) 14335940Ssowmini struct in_addr nceaddr; 14345940Ssowmini ill_t ill; 14355940Ssowmini char ill_name[LIFNAMSIZ]; 14365940Ssowmini char flagsbuf[NCE_MAX_FLAGS]; 14375940Ssowmini 14385940Ssowmini if (mdb_vread(&ill, sizeof (ill), (uintptr_t)nce->nce_ill) == -1) { 14395940Ssowmini mdb_warn("failed to read nce_ill at %p", 14405940Ssowmini nce->nce_ill); 14415940Ssowmini return (DCMD_ERR); 14425940Ssowmini } 14435940Ssowmini 14445940Ssowmini (void) mdb_readstr(ill_name, MIN(LIFNAMSIZ, ill.ill_name_length), 14455940Ssowmini (uintptr_t)ill.ill_name); 14465940Ssowmini 14475940Ssowmini mdb_snprintf(flagsbuf, sizeof (flagsbuf), "%hb", 14485940Ssowmini nce->nce_flags, nce_flags); 14495940Ssowmini 14505940Ssowmini if (ipversion != 0 && nce->nce_ipversion != ipversion) 14515940Ssowmini return (DCMD_OK); 14525940Ssowmini 14535940Ssowmini if (nce->nce_ipversion == IPV4_VERSION) { 14545940Ssowmini IN6_V4MAPPED_TO_INADDR(&nce->nce_addr, &nceaddr); 14555940Ssowmini mdb_printf("%?p %-20s %-10s " 14565940Ssowmini "%-8s " 14575940Ssowmini "%-5s %I\n", 14585940Ssowmini addr, nce_l2_addr(nce, &ill), 14595940Ssowmini nce_state(nce->nce_state), 14605940Ssowmini flagsbuf, 14615940Ssowmini ill_name, nceaddr.s_addr); 14625940Ssowmini } else { 14635940Ssowmini mdb_printf("%?p %-20s %-10s %-8s %-5s %N\n", 14645940Ssowmini addr, nce_l2_addr(nce, &ill), 14655940Ssowmini nce_state(nce->nce_state), 14665940Ssowmini flagsbuf, 14675940Ssowmini ill_name, &nce->nce_addr); 14685940Ssowmini } 14695940Ssowmini 14705940Ssowmini return (DCMD_OK); 14715940Ssowmini } 14725940Ssowmini 14735940Ssowmini static uintptr_t 14745940Ssowmini nce_get_next_hash_tbl(uintptr_t start, int *index, struct ndp_g_s ndp) 14755940Ssowmini { 14765940Ssowmini uintptr_t addr = start; 14775940Ssowmini int i = *index; 14785940Ssowmini 14795940Ssowmini while (addr == NULL) { 14805940Ssowmini 14815940Ssowmini if (++i >= NCE_TABLE_SIZE) 14825940Ssowmini break; 14835940Ssowmini addr = (uintptr_t)ndp.nce_hash_tbl[i]; 14845940Ssowmini } 14855940Ssowmini *index = i; 14865940Ssowmini return (addr); 14875940Ssowmini } 14885940Ssowmini 14895940Ssowmini static int 14905940Ssowmini nce_walk_step(mdb_walk_state_t *wsp) 14915940Ssowmini { 14925940Ssowmini uintptr_t kaddr4, kaddr6; 14935940Ssowmini 14945940Ssowmini kaddr4 = wsp->walk_addr + OFFSETOF(ip_stack_t, ips_ndp4); 14955940Ssowmini kaddr6 = wsp->walk_addr + OFFSETOF(ip_stack_t, ips_ndp6); 14965940Ssowmini 14975940Ssowmini if (mdb_vread(&kaddr4, sizeof (kaddr4), kaddr4) == -1) { 14985940Ssowmini mdb_warn("can't read ips_ip_cache_table at %p", kaddr4); 14995940Ssowmini return (WALK_ERR); 15005940Ssowmini } 15015940Ssowmini if (mdb_vread(&kaddr6, sizeof (kaddr6), kaddr6) == -1) { 15025940Ssowmini mdb_warn("can't read ips_ip_cache_table at %p", kaddr6); 15035940Ssowmini return (WALK_ERR); 15045940Ssowmini } 15055940Ssowmini if (mdb_pwalk("nce_stack", wsp->walk_callback, wsp->walk_cbdata, 15065940Ssowmini kaddr4) == -1) { 15075940Ssowmini mdb_warn("couldn't walk 'nce_stack' for ips_ndp4 %p", 15085940Ssowmini kaddr4); 15095940Ssowmini return (WALK_ERR); 15105940Ssowmini } 15115940Ssowmini if (mdb_pwalk("nce_stack", wsp->walk_callback, 15125940Ssowmini wsp->walk_cbdata, kaddr6) == -1) { 15135940Ssowmini mdb_warn("couldn't walk 'nce_stack' for ips_ndp6 %p", 15145940Ssowmini kaddr6); 15155940Ssowmini return (WALK_ERR); 15165940Ssowmini } 15175940Ssowmini return (WALK_NEXT); 15185940Ssowmini } 15195940Ssowmini 15205940Ssowmini /* 15215940Ssowmini * Called with walk_addr being the address of ips_ndp{4,6} 15225940Ssowmini */ 15235940Ssowmini static int 15245940Ssowmini nce_stack_walk_init(mdb_walk_state_t *wsp) 15255940Ssowmini { 15265940Ssowmini nce_walk_data_t *nw; 15275940Ssowmini 15285940Ssowmini if (wsp->walk_addr == NULL) { 15295940Ssowmini mdb_warn("nce_stack requires ndp_g_s address\n"); 15305940Ssowmini return (WALK_ERR); 15315940Ssowmini } 15325940Ssowmini 15335940Ssowmini nw = mdb_alloc(sizeof (nce_walk_data_t), UM_SLEEP); 15345940Ssowmini 15355940Ssowmini if (mdb_vread(&nw->nce_ip_ndp, sizeof (struct ndp_g_s), 15365940Ssowmini wsp->walk_addr) == -1) { 15375940Ssowmini mdb_warn("failed to read 'ip_ndp' at %p", 15385940Ssowmini wsp->walk_addr); 15395940Ssowmini mdb_free(nw, sizeof (nce_walk_data_t)); 15405940Ssowmini return (WALK_ERR); 15415940Ssowmini } 15425940Ssowmini 15435940Ssowmini nw->nce_hash_tbl_index = 0; 15445940Ssowmini wsp->walk_addr = nce_get_next_hash_tbl(NULL, 15455940Ssowmini &nw->nce_hash_tbl_index, nw->nce_ip_ndp); 15465940Ssowmini wsp->walk_data = nw; 15475940Ssowmini 15485940Ssowmini return (WALK_NEXT); 15495940Ssowmini } 15505940Ssowmini 15515940Ssowmini static int 15525940Ssowmini nce_stack_walk_step(mdb_walk_state_t *wsp) 15535940Ssowmini { 15545940Ssowmini uintptr_t addr = wsp->walk_addr; 15555940Ssowmini nce_walk_data_t *nw = wsp->walk_data; 15565940Ssowmini 15575940Ssowmini if (addr == NULL) 15585940Ssowmini return (WALK_DONE); 15595940Ssowmini 15605940Ssowmini if (mdb_vread(&nw->nce, sizeof (nce_t), addr) == -1) { 15615940Ssowmini mdb_warn("failed to read nce_t at %p", addr); 15625940Ssowmini return (WALK_ERR); 15635940Ssowmini } 15645940Ssowmini 15655940Ssowmini wsp->walk_addr = (uintptr_t)nw->nce.nce_next; 15665940Ssowmini 15675940Ssowmini wsp->walk_addr = nce_get_next_hash_tbl(wsp->walk_addr, 15685940Ssowmini &nw->nce_hash_tbl_index, nw->nce_ip_ndp); 15695940Ssowmini 15705940Ssowmini return (wsp->walk_callback(addr, nw, wsp->walk_cbdata)); 15715940Ssowmini } 15725940Ssowmini 15735940Ssowmini static void 15745940Ssowmini nce_stack_walk_fini(mdb_walk_state_t *wsp) 15755940Ssowmini { 15765940Ssowmini mdb_free(wsp->walk_data, sizeof (nce_walk_data_t)); 15775940Ssowmini } 15785940Ssowmini 15795940Ssowmini /* ARGSUSED */ 15805940Ssowmini static int 15815940Ssowmini nce_cb(uintptr_t addr, const nce_walk_data_t *iw, nce_cbdata_t *id) 15825940Ssowmini { 15835940Ssowmini nce_t nce; 15845940Ssowmini 15855940Ssowmini if (mdb_vread(&nce, sizeof (nce_t), addr) == -1) { 15865940Ssowmini mdb_warn("failed to read nce at %p", addr); 15875940Ssowmini return (WALK_NEXT); 15885940Ssowmini } 15895940Ssowmini (void) nce_format(addr, &nce, id->nce_ipversion); 15905940Ssowmini return (WALK_NEXT); 15915940Ssowmini } 1592