1*f4b3ec61Sdh155122 /* 2*f4b3ec61Sdh155122 * CDDL HEADER START 3*f4b3ec61Sdh155122 * 4*f4b3ec61Sdh155122 * The contents of this file are subject to the terms of the 5*f4b3ec61Sdh155122 * Common Development and Distribution License (the "License"). 6*f4b3ec61Sdh155122 * You may not use this file except in compliance with the License. 7*f4b3ec61Sdh155122 * 8*f4b3ec61Sdh155122 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*f4b3ec61Sdh155122 * or http://www.opensolaris.org/os/licensing. 10*f4b3ec61Sdh155122 * See the License for the specific language governing permissions 11*f4b3ec61Sdh155122 * and limitations under the License. 12*f4b3ec61Sdh155122 * 13*f4b3ec61Sdh155122 * When distributing Covered Code, include this CDDL HEADER in each 14*f4b3ec61Sdh155122 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*f4b3ec61Sdh155122 * If applicable, add the following below this CDDL HEADER, with the 16*f4b3ec61Sdh155122 * fields enclosed by brackets "[]" replaced with your own identifying 17*f4b3ec61Sdh155122 * information: Portions Copyright [yyyy] [name of copyright owner] 18*f4b3ec61Sdh155122 * 19*f4b3ec61Sdh155122 * CDDL HEADER END 20*f4b3ec61Sdh155122 */ 21*f4b3ec61Sdh155122 /* 22*f4b3ec61Sdh155122 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23*f4b3ec61Sdh155122 * Use is subject to license terms. 24*f4b3ec61Sdh155122 */ 25*f4b3ec61Sdh155122 26*f4b3ec61Sdh155122 #pragma ident "%Z%%M% %I% %E% SMI" 27*f4b3ec61Sdh155122 28*f4b3ec61Sdh155122 #include <mdb/mdb_modapi.h> 29*f4b3ec61Sdh155122 #include <mdb/mdb_ks.h> 30*f4b3ec61Sdh155122 #include <mdb/mdb_ctf.h> 31*f4b3ec61Sdh155122 #include <sys/types.h> 32*f4b3ec61Sdh155122 #include <sys/netstack.h> 33*f4b3ec61Sdh155122 34*f4b3ec61Sdh155122 int 35*f4b3ec61Sdh155122 netstack_walk_init(mdb_walk_state_t *wsp) 36*f4b3ec61Sdh155122 { 37*f4b3ec61Sdh155122 GElf_Sym sym; 38*f4b3ec61Sdh155122 uintptr_t addr; 39*f4b3ec61Sdh155122 40*f4b3ec61Sdh155122 if (mdb_lookup_by_name("netstack_head", &sym) == -1) { 41*f4b3ec61Sdh155122 mdb_warn("couldn't find netstack_head"); 42*f4b3ec61Sdh155122 return (WALK_ERR); 43*f4b3ec61Sdh155122 } 44*f4b3ec61Sdh155122 addr = (uintptr_t)sym.st_value; 45*f4b3ec61Sdh155122 46*f4b3ec61Sdh155122 if (mdb_vread(&wsp->walk_addr, sizeof (wsp->walk_addr), addr) == -1) { 47*f4b3ec61Sdh155122 mdb_warn("failed to read address of initial netstack " 48*f4b3ec61Sdh155122 "at %p", addr); 49*f4b3ec61Sdh155122 return (WALK_ERR); 50*f4b3ec61Sdh155122 } 51*f4b3ec61Sdh155122 return (WALK_NEXT); 52*f4b3ec61Sdh155122 } 53*f4b3ec61Sdh155122 54*f4b3ec61Sdh155122 int 55*f4b3ec61Sdh155122 netstack_walk_step(mdb_walk_state_t *wsp) 56*f4b3ec61Sdh155122 { 57*f4b3ec61Sdh155122 int status; 58*f4b3ec61Sdh155122 netstack_t nss; 59*f4b3ec61Sdh155122 60*f4b3ec61Sdh155122 if (wsp->walk_addr == NULL) 61*f4b3ec61Sdh155122 return (WALK_DONE); 62*f4b3ec61Sdh155122 63*f4b3ec61Sdh155122 if (mdb_vread(&nss, sizeof (netstack_t), wsp->walk_addr) == -1) { 64*f4b3ec61Sdh155122 mdb_warn("failed to read netstack at %p", wsp->walk_addr); 65*f4b3ec61Sdh155122 return (WALK_ERR); 66*f4b3ec61Sdh155122 } 67*f4b3ec61Sdh155122 68*f4b3ec61Sdh155122 status = wsp->walk_callback(wsp->walk_addr, &nss, 69*f4b3ec61Sdh155122 wsp->walk_cbdata); 70*f4b3ec61Sdh155122 71*f4b3ec61Sdh155122 if (status != WALK_NEXT) 72*f4b3ec61Sdh155122 return (status); 73*f4b3ec61Sdh155122 74*f4b3ec61Sdh155122 wsp->walk_addr = (uintptr_t)nss.netstack_next; 75*f4b3ec61Sdh155122 return (status); 76*f4b3ec61Sdh155122 } 77*f4b3ec61Sdh155122 78*f4b3ec61Sdh155122 /*ARGSUSED*/ 79*f4b3ec61Sdh155122 int 80*f4b3ec61Sdh155122 netstack(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 81*f4b3ec61Sdh155122 { 82*f4b3ec61Sdh155122 netstack_t nss; 83*f4b3ec61Sdh155122 uint_t quiet = FALSE; 84*f4b3ec61Sdh155122 uint_t verbose = FALSE; 85*f4b3ec61Sdh155122 86*f4b3ec61Sdh155122 if (!(flags & DCMD_ADDRSPEC)) { 87*f4b3ec61Sdh155122 if (mdb_walk_dcmd("genunix`netstack", "genunix`netstack", 88*f4b3ec61Sdh155122 argc, argv) == -1) { 89*f4b3ec61Sdh155122 mdb_warn("failed to walk netstack"); 90*f4b3ec61Sdh155122 return (DCMD_ERR); 91*f4b3ec61Sdh155122 } 92*f4b3ec61Sdh155122 return (DCMD_OK); 93*f4b3ec61Sdh155122 } 94*f4b3ec61Sdh155122 if (mdb_getopts(argc, argv, 95*f4b3ec61Sdh155122 'v', MDB_OPT_SETBITS, TRUE, &verbose, 96*f4b3ec61Sdh155122 'q', MDB_OPT_SETBITS, TRUE, &quiet, 97*f4b3ec61Sdh155122 NULL) != argc) 98*f4b3ec61Sdh155122 return (DCMD_USAGE); 99*f4b3ec61Sdh155122 100*f4b3ec61Sdh155122 if (DCMD_HDRSPEC(flags) && !quiet) { 101*f4b3ec61Sdh155122 mdb_printf("%?s %-7s %6s\n", 102*f4b3ec61Sdh155122 "ADDR", "STACKID", "FLAGS"); 103*f4b3ec61Sdh155122 } 104*f4b3ec61Sdh155122 105*f4b3ec61Sdh155122 if (mdb_vread(&nss, sizeof (nss), addr) == -1) { 106*f4b3ec61Sdh155122 mdb_warn("couldn't read netstack at %p", addr); 107*f4b3ec61Sdh155122 return (DCMD_ERR); 108*f4b3ec61Sdh155122 } 109*f4b3ec61Sdh155122 110*f4b3ec61Sdh155122 /* 111*f4b3ec61Sdh155122 * Options are specified for filtering, so If any option is specified on 112*f4b3ec61Sdh155122 * the command line, just print address and exit. 113*f4b3ec61Sdh155122 */ 114*f4b3ec61Sdh155122 if (quiet) { 115*f4b3ec61Sdh155122 mdb_printf("%0?p\n", addr); 116*f4b3ec61Sdh155122 return (DCMD_OK); 117*f4b3ec61Sdh155122 } 118*f4b3ec61Sdh155122 119*f4b3ec61Sdh155122 mdb_printf("%0?p %6d %06x\n", 120*f4b3ec61Sdh155122 addr, nss.netstack_stackid, nss.netstack_flags); 121*f4b3ec61Sdh155122 122*f4b3ec61Sdh155122 return (DCMD_OK); 123*f4b3ec61Sdh155122 } 124