4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
27 #include <mdb/mdb_modapi.h>
28 #include <mdb/mdb_ks.h>
29 #include <mdb/mdb_ctf.h>
30 #include <sys/types.h>
31 #include <sys/netstack.h>
34 netstack_walk_init(mdb_walk_state_t
*wsp
)
39 if (mdb_lookup_by_name("netstack_head", &sym
) == -1) {
40 mdb_warn("couldn't find netstack_head");
43 addr
= (uintptr_t)sym
.st_value
;
45 if (mdb_vread(&wsp
->walk_addr
, sizeof (wsp
->walk_addr
), addr
) == -1) {
46 mdb_warn("failed to read address of initial netstack "
54 netstack_walk_step(mdb_walk_state_t
*wsp
)
59 if (wsp
->walk_addr
== (uintptr_t)NULL
)
62 if (mdb_vread(&nss
, sizeof (netstack_t
), wsp
->walk_addr
) == -1) {
63 mdb_warn("failed to read netstack at %p", wsp
->walk_addr
);
67 status
= wsp
->walk_callback(wsp
->walk_addr
, &nss
,
70 if (status
!= WALK_NEXT
)
73 wsp
->walk_addr
= (uintptr_t)nss
.netstack_next
;
79 netstack(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
83 uint_t verbose
= FALSE
;
85 if (!(flags
& DCMD_ADDRSPEC
)) {
86 if (mdb_walk_dcmd("genunix`netstack", "genunix`netstack",
88 mdb_warn("failed to walk netstack");
93 if (mdb_getopts(argc
, argv
,
94 'v', MDB_OPT_SETBITS
, TRUE
, &verbose
,
95 'q', MDB_OPT_SETBITS
, TRUE
, &quiet
,
99 if (DCMD_HDRSPEC(flags
) && !quiet
) {
100 mdb_printf("%?s %-7s %6s\n",
101 "ADDR", "STACKID", "FLAGS");
104 if (mdb_vread(&nss
, sizeof (nss
), addr
) == -1) {
105 mdb_warn("couldn't read netstack at %p", addr
);
110 * Options are specified for filtering, so If any option is specified on
111 * the command line, just print address and exit.
114 mdb_printf("%0?p\n", addr
);
118 mdb_printf("%0?p %6d %06x\n",
119 addr
, nss
.netstack_stackid
, nss
.netstack_flags
);
125 netstackid_lookup_cb(uintptr_t addr
, const netstack_t
*ns
, void *arg
)
127 netstackid_t nid
= *(uintptr_t *)arg
;
128 if (ns
->netstack_stackid
== nid
)
129 mdb_printf("%p\n", addr
);
136 netstackid2netstack(uintptr_t addr
, uint_t flags
, int argc
,
137 const mdb_arg_t
*argv
)
139 if (!(flags
& DCMD_ADDRSPEC
) || argc
!= 0)
142 if (mdb_walk("netstack", (mdb_walk_cb_t
)netstackid_lookup_cb
, &addr
) ==
144 mdb_warn("failed to walk zone");