17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
569bb4bb4Scarlsonj * Common Development and Distribution License (the "License").
669bb4bb4Scarlsonj * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*0870f17bSKacheong Poon * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate */
247c478bd9Sstevel@tonic-gate
257c478bd9Sstevel@tonic-gate #include <sys/types.h>
267c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
277c478bd9Sstevel@tonic-gate #include <sys/stream.h>
287c478bd9Sstevel@tonic-gate #include <sys/socket.h>
297c478bd9Sstevel@tonic-gate #include <sys/avl_impl.h>
30d5b6ed4bSVasumathi Sundaram - Sun Microsystems #include <net/if_types.h>
317c478bd9Sstevel@tonic-gate #include <net/if.h>
327c478bd9Sstevel@tonic-gate #include <net/route.h>
337c478bd9Sstevel@tonic-gate #include <netinet/in.h>
347c478bd9Sstevel@tonic-gate #include <netinet/ip6.h>
357c478bd9Sstevel@tonic-gate #include <netinet/udp.h>
367c478bd9Sstevel@tonic-gate #include <netinet/sctp.h>
377c478bd9Sstevel@tonic-gate #include <inet/mib2.h>
387c478bd9Sstevel@tonic-gate #include <inet/common.h>
397c478bd9Sstevel@tonic-gate #include <inet/ip.h>
407c478bd9Sstevel@tonic-gate #include <inet/ip_ire.h>
417c478bd9Sstevel@tonic-gate #include <inet/ip6.h>
427c478bd9Sstevel@tonic-gate #include <inet/ipclassifier.h>
437c478bd9Sstevel@tonic-gate #include <inet/mi.h>
447c478bd9Sstevel@tonic-gate #include <sys/squeue_impl.h>
456a8288c7Scarlsonj #include <sys/modhash_impl.h>
46ffaa671aSsowmini #include <inet/ip_ndp.h>
47ffaa671aSsowmini #include <inet/ip_if.h>
48dbed73cbSSangeeta Misra #include <ilb.h>
49dbed73cbSSangeeta Misra #include <ilb/ilb_impl.h>
50dbed73cbSSangeeta Misra #include <ilb/ilb_stack.h>
51dbed73cbSSangeeta Misra #include <ilb/ilb_nat.h>
52dbed73cbSSangeeta Misra #include <ilb/ilb_conn.h>
53ffaa671aSsowmini #include <sys/dlpi.h>
54bd670b35SErik Nordmark #include <sys/zone.h>
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate #include <mdb/mdb_modapi.h>
577c478bd9Sstevel@tonic-gate #include <mdb/mdb_ks.h>
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate #define ADDR_WIDTH 11
60ffaa671aSsowmini #define L2MAXADDRSTRLEN 255
61ffaa671aSsowmini #define MAX_SAP_LEN 255
62d5b6ed4bSVasumathi Sundaram - Sun Microsystems #define DEFCOLS 80
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate typedef struct {
657c478bd9Sstevel@tonic-gate const char *bit_name; /* name of bit */
667c478bd9Sstevel@tonic-gate const char *bit_descr; /* description of bit's purpose */
677c478bd9Sstevel@tonic-gate } bitname_t;
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate static const bitname_t squeue_states[] = {
707c478bd9Sstevel@tonic-gate { "SQS_PROC", "being processed" },
717c478bd9Sstevel@tonic-gate { "SQS_WORKER", "... by a worker thread" },
727c478bd9Sstevel@tonic-gate { "SQS_ENTER", "... by an squeue_enter() thread" },
737c478bd9Sstevel@tonic-gate { "SQS_FAST", "... in fast-path mode" },
747c478bd9Sstevel@tonic-gate { "SQS_USER", "A non interrupt user" },
757c478bd9Sstevel@tonic-gate { "SQS_BOUND", "worker thread bound to CPU" },
767c478bd9Sstevel@tonic-gate { "SQS_PROFILE", "profiling enabled" },
777c478bd9Sstevel@tonic-gate { "SQS_REENTER", "re-entered thred" },
787c478bd9Sstevel@tonic-gate { NULL }
797c478bd9Sstevel@tonic-gate };
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate typedef struct illif_walk_data {
827c478bd9Sstevel@tonic-gate ill_g_head_t ill_g_heads[MAX_G_HEADS];
837c478bd9Sstevel@tonic-gate int ill_list;
847c478bd9Sstevel@tonic-gate ill_if_t ill_if;
857c478bd9Sstevel@tonic-gate } illif_walk_data_t;
867c478bd9Sstevel@tonic-gate
87bd670b35SErik Nordmark typedef struct ncec_walk_data_s {
88bd670b35SErik Nordmark struct ndp_g_s ncec_ip_ndp;
89bd670b35SErik Nordmark int ncec_hash_tbl_index;
90bd670b35SErik Nordmark ncec_t ncec;
91bd670b35SErik Nordmark } ncec_walk_data_t;
92bd670b35SErik Nordmark
93bd670b35SErik Nordmark typedef struct ncec_cbdata_s {
94bd670b35SErik Nordmark uintptr_t ncec_addr;
95bd670b35SErik Nordmark int ncec_ipversion;
96bd670b35SErik Nordmark } ncec_cbdata_t;
97ffaa671aSsowmini
98ffaa671aSsowmini typedef struct nce_cbdata_s {
99ffaa671aSsowmini int nce_ipversion;
100bd670b35SErik Nordmark char nce_ill_name[LIFNAMSIZ];
101ffaa671aSsowmini } nce_cbdata_t;
102ffaa671aSsowmini
103ffaa671aSsowmini typedef struct ire_cbdata_s {
104ffaa671aSsowmini int ire_ipversion;
105ffaa671aSsowmini boolean_t verbose;
106ffaa671aSsowmini } ire_cbdata_t;
107ffaa671aSsowmini
108bd670b35SErik Nordmark typedef struct zi_cbdata_s {
109bd670b35SErik Nordmark const char *zone_name;
110bd670b35SErik Nordmark ip_stack_t *ipst;
111bd670b35SErik Nordmark boolean_t shared_ip_zone;
112bd670b35SErik Nordmark } zi_cbdata_t;
113bd670b35SErik Nordmark
1146a8288c7Scarlsonj typedef struct th_walk_data {
1156a8288c7Scarlsonj uint_t thw_non_zero_only;
1166a8288c7Scarlsonj boolean_t thw_match;
1176a8288c7Scarlsonj uintptr_t thw_matchkey;
1186a8288c7Scarlsonj uintptr_t thw_ipst;
1196a8288c7Scarlsonj clock_t thw_lbolt;
1206a8288c7Scarlsonj } th_walk_data_t;
1216a8288c7Scarlsonj
122d5b6ed4bSVasumathi Sundaram - Sun Microsystems typedef struct ipcl_hash_walk_data_s {
123d5b6ed4bSVasumathi Sundaram - Sun Microsystems conn_t *conn;
124d5b6ed4bSVasumathi Sundaram - Sun Microsystems int connf_tbl_index;
125d5b6ed4bSVasumathi Sundaram - Sun Microsystems uintptr_t hash_tbl;
126d5b6ed4bSVasumathi Sundaram - Sun Microsystems int hash_tbl_size;
127d5b6ed4bSVasumathi Sundaram - Sun Microsystems } ipcl_hash_walk_data_t;
128d5b6ed4bSVasumathi Sundaram - Sun Microsystems
129d5b6ed4bSVasumathi Sundaram - Sun Microsystems typedef struct ill_walk_data_s {
130d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill_t ill;
131d5b6ed4bSVasumathi Sundaram - Sun Microsystems } ill_walk_data_t;
132d5b6ed4bSVasumathi Sundaram - Sun Microsystems
133d5b6ed4bSVasumathi Sundaram - Sun Microsystems typedef struct ill_cbdata_s {
134d5b6ed4bSVasumathi Sundaram - Sun Microsystems uintptr_t ill_addr;
135d5b6ed4bSVasumathi Sundaram - Sun Microsystems int ill_ipversion;
136bd670b35SErik Nordmark ip_stack_t *ill_ipst;
137d5b6ed4bSVasumathi Sundaram - Sun Microsystems boolean_t verbose;
138d5b6ed4bSVasumathi Sundaram - Sun Microsystems } ill_cbdata_t;
139d5b6ed4bSVasumathi Sundaram - Sun Microsystems
140d5b6ed4bSVasumathi Sundaram - Sun Microsystems typedef struct ipif_walk_data_s {
141d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipif_t ipif;
142d5b6ed4bSVasumathi Sundaram - Sun Microsystems } ipif_walk_data_t;
143d5b6ed4bSVasumathi Sundaram - Sun Microsystems
144d5b6ed4bSVasumathi Sundaram - Sun Microsystems typedef struct ipif_cbdata_s {
145d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill_t ill;
146d5b6ed4bSVasumathi Sundaram - Sun Microsystems int ipif_ipversion;
147d5b6ed4bSVasumathi Sundaram - Sun Microsystems boolean_t verbose;
148d5b6ed4bSVasumathi Sundaram - Sun Microsystems } ipif_cbdata_t;
149d5b6ed4bSVasumathi Sundaram - Sun Microsystems
150d5b6ed4bSVasumathi Sundaram - Sun Microsystems typedef struct hash_walk_arg_s {
151d5b6ed4bSVasumathi Sundaram - Sun Microsystems off_t tbl_off;
152d5b6ed4bSVasumathi Sundaram - Sun Microsystems off_t size_off;
153d5b6ed4bSVasumathi Sundaram - Sun Microsystems } hash_walk_arg_t;
154d5b6ed4bSVasumathi Sundaram - Sun Microsystems
155d5b6ed4bSVasumathi Sundaram - Sun Microsystems static hash_walk_arg_t udp_hash_arg = {
156d5b6ed4bSVasumathi Sundaram - Sun Microsystems OFFSETOF(ip_stack_t, ips_ipcl_udp_fanout),
157d5b6ed4bSVasumathi Sundaram - Sun Microsystems OFFSETOF(ip_stack_t, ips_ipcl_udp_fanout_size)
158d5b6ed4bSVasumathi Sundaram - Sun Microsystems };
159d5b6ed4bSVasumathi Sundaram - Sun Microsystems
160d5b6ed4bSVasumathi Sundaram - Sun Microsystems static hash_walk_arg_t conn_hash_arg = {
161d5b6ed4bSVasumathi Sundaram - Sun Microsystems OFFSETOF(ip_stack_t, ips_ipcl_conn_fanout),
162d5b6ed4bSVasumathi Sundaram - Sun Microsystems OFFSETOF(ip_stack_t, ips_ipcl_conn_fanout_size)
163d5b6ed4bSVasumathi Sundaram - Sun Microsystems };
164d5b6ed4bSVasumathi Sundaram - Sun Microsystems
165d5b6ed4bSVasumathi Sundaram - Sun Microsystems static hash_walk_arg_t bind_hash_arg = {
166d5b6ed4bSVasumathi Sundaram - Sun Microsystems OFFSETOF(ip_stack_t, ips_ipcl_bind_fanout),
167d5b6ed4bSVasumathi Sundaram - Sun Microsystems OFFSETOF(ip_stack_t, ips_ipcl_bind_fanout_size)
168d5b6ed4bSVasumathi Sundaram - Sun Microsystems };
169d5b6ed4bSVasumathi Sundaram - Sun Microsystems
170d5b6ed4bSVasumathi Sundaram - Sun Microsystems static hash_walk_arg_t proto_hash_arg = {
171bd670b35SErik Nordmark OFFSETOF(ip_stack_t, ips_ipcl_proto_fanout_v4),
172d5b6ed4bSVasumathi Sundaram - Sun Microsystems 0
173d5b6ed4bSVasumathi Sundaram - Sun Microsystems };
174d5b6ed4bSVasumathi Sundaram - Sun Microsystems
175d5b6ed4bSVasumathi Sundaram - Sun Microsystems static hash_walk_arg_t proto_v6_hash_arg = {
176d5b6ed4bSVasumathi Sundaram - Sun Microsystems OFFSETOF(ip_stack_t, ips_ipcl_proto_fanout_v6),
177d5b6ed4bSVasumathi Sundaram - Sun Microsystems 0
178d5b6ed4bSVasumathi Sundaram - Sun Microsystems };
179d5b6ed4bSVasumathi Sundaram - Sun Microsystems
180d5b6ed4bSVasumathi Sundaram - Sun Microsystems typedef struct ip_list_walk_data_s {
181d5b6ed4bSVasumathi Sundaram - Sun Microsystems off_t nextoff;
182d5b6ed4bSVasumathi Sundaram - Sun Microsystems } ip_list_walk_data_t;
183d5b6ed4bSVasumathi Sundaram - Sun Microsystems
184d5b6ed4bSVasumathi Sundaram - Sun Microsystems typedef struct ip_list_walk_arg_s {
185d5b6ed4bSVasumathi Sundaram - Sun Microsystems off_t off;
186d5b6ed4bSVasumathi Sundaram - Sun Microsystems size_t size;
187d5b6ed4bSVasumathi Sundaram - Sun Microsystems off_t nextp_off;
188d5b6ed4bSVasumathi Sundaram - Sun Microsystems } ip_list_walk_arg_t;
189d5b6ed4bSVasumathi Sundaram - Sun Microsystems
190d5b6ed4bSVasumathi Sundaram - Sun Microsystems static ip_list_walk_arg_t ipif_walk_arg = {
191d5b6ed4bSVasumathi Sundaram - Sun Microsystems OFFSETOF(ill_t, ill_ipif),
192d5b6ed4bSVasumathi Sundaram - Sun Microsystems sizeof (ipif_t),
193d5b6ed4bSVasumathi Sundaram - Sun Microsystems OFFSETOF(ipif_t, ipif_next)
194d5b6ed4bSVasumathi Sundaram - Sun Microsystems };
195d5b6ed4bSVasumathi Sundaram - Sun Microsystems
196d5b6ed4bSVasumathi Sundaram - Sun Microsystems static ip_list_walk_arg_t srcid_walk_arg = {
197d5b6ed4bSVasumathi Sundaram - Sun Microsystems OFFSETOF(ip_stack_t, ips_srcid_head),
198d5b6ed4bSVasumathi Sundaram - Sun Microsystems sizeof (srcid_map_t),
199d5b6ed4bSVasumathi Sundaram - Sun Microsystems OFFSETOF(srcid_map_t, sm_next)
200d5b6ed4bSVasumathi Sundaram - Sun Microsystems };
201d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2027c478bd9Sstevel@tonic-gate static int iphdr(uintptr_t, uint_t, int, const mdb_arg_t *);
2037c478bd9Sstevel@tonic-gate static int ip6hdr(uintptr_t, uint_t, int, const mdb_arg_t *);
2047c478bd9Sstevel@tonic-gate
205d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int ill(uintptr_t, uint_t, int, const mdb_arg_t *);
206d5b6ed4bSVasumathi Sundaram - Sun Microsystems static void ill_help(void);
207d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int ill_walk_init(mdb_walk_state_t *);
208d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int ill_walk_step(mdb_walk_state_t *);
209d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int ill_format(uintptr_t, const void *, void *);
210d5b6ed4bSVasumathi Sundaram - Sun Microsystems static void ill_header(boolean_t);
211d5b6ed4bSVasumathi Sundaram - Sun Microsystems
212d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int ipif(uintptr_t, uint_t, int, const mdb_arg_t *);
213d5b6ed4bSVasumathi Sundaram - Sun Microsystems static void ipif_help(void);
214d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int ipif_walk_init(mdb_walk_state_t *);
215d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int ipif_walk_step(mdb_walk_state_t *);
216d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int ipif_format(uintptr_t, const void *, void *);
217d5b6ed4bSVasumathi Sundaram - Sun Microsystems static void ipif_header(boolean_t);
218d5b6ed4bSVasumathi Sundaram - Sun Microsystems
219d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int ip_list_walk_init(mdb_walk_state_t *);
220d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int ip_list_walk_step(mdb_walk_state_t *);
221d5b6ed4bSVasumathi Sundaram - Sun Microsystems static void ip_list_walk_fini(mdb_walk_state_t *);
222d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int srcid_walk_step(mdb_walk_state_t *);
223d5b6ed4bSVasumathi Sundaram - Sun Microsystems
224ffaa671aSsowmini static int ire_format(uintptr_t addr, const void *, void *);
225bd670b35SErik Nordmark static int ncec_format(uintptr_t addr, const ncec_t *ncec, int ipversion);
226bd670b35SErik Nordmark static int ncec(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv);
227bd670b35SErik Nordmark static int ncec_walk_step(mdb_walk_state_t *wsp);
228bd670b35SErik Nordmark static int ncec_stack_walk_init(mdb_walk_state_t *wsp);
229bd670b35SErik Nordmark static int ncec_stack_walk_step(mdb_walk_state_t *wsp);
230bd670b35SErik Nordmark static void ncec_stack_walk_fini(mdb_walk_state_t *wsp);
231bd670b35SErik Nordmark static int ncec_cb(uintptr_t addr, const ncec_walk_data_t *iw,
232bd670b35SErik Nordmark ncec_cbdata_t *id);
233bd670b35SErik Nordmark static char *nce_l2_addr(const nce_t *, const ill_t *);
234f4b3ec61Sdh155122
235d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int ipcl_hash_walk_init(mdb_walk_state_t *);
236d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int ipcl_hash_walk_step(mdb_walk_state_t *);
237d5b6ed4bSVasumathi Sundaram - Sun Microsystems static void ipcl_hash_walk_fini(mdb_walk_state_t *);
238d5b6ed4bSVasumathi Sundaram - Sun Microsystems
239d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int conn_status_walk_step(mdb_walk_state_t *);
240d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int conn_status(uintptr_t, uint_t, int, const mdb_arg_t *);
241d5b6ed4bSVasumathi Sundaram - Sun Microsystems static void conn_status_help(void);
242d5b6ed4bSVasumathi Sundaram - Sun Microsystems
243d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int srcid_status(uintptr_t, uint_t, int, const mdb_arg_t *);
244d5b6ed4bSVasumathi Sundaram - Sun Microsystems
245dbed73cbSSangeeta Misra static int ilb_stacks_walk_step(mdb_walk_state_t *);
246dbed73cbSSangeeta Misra static int ilb_rules_walk_init(mdb_walk_state_t *);
247dbed73cbSSangeeta Misra static int ilb_rules_walk_step(mdb_walk_state_t *);
248dbed73cbSSangeeta Misra static int ilb_servers_walk_init(mdb_walk_state_t *);
249dbed73cbSSangeeta Misra static int ilb_servers_walk_step(mdb_walk_state_t *);
250dbed73cbSSangeeta Misra static int ilb_nat_src_walk_init(mdb_walk_state_t *);
251dbed73cbSSangeeta Misra static int ilb_nat_src_walk_step(mdb_walk_state_t *);
252dbed73cbSSangeeta Misra static int ilb_conn_walk_init(mdb_walk_state_t *);
253dbed73cbSSangeeta Misra static int ilb_conn_walk_step(mdb_walk_state_t *);
254dbed73cbSSangeeta Misra static int ilb_sticky_walk_init(mdb_walk_state_t *);
255dbed73cbSSangeeta Misra static int ilb_sticky_walk_step(mdb_walk_state_t *);
256dbed73cbSSangeeta Misra static void ilb_common_walk_fini(mdb_walk_state_t *);
257dbed73cbSSangeeta Misra
258f4b3ec61Sdh155122 /*
259f4b3ec61Sdh155122 * Given the kernel address of an ip_stack_t, return the stackid
260f4b3ec61Sdh155122 */
261f4b3ec61Sdh155122 static int
ips_to_stackid(uintptr_t kaddr)262f4b3ec61Sdh155122 ips_to_stackid(uintptr_t kaddr)
263f4b3ec61Sdh155122 {
264f4b3ec61Sdh155122 ip_stack_t ipss;
265f4b3ec61Sdh155122 netstack_t nss;
266f4b3ec61Sdh155122
267f4b3ec61Sdh155122 if (mdb_vread(&ipss, sizeof (ipss), kaddr) == -1) {
268f4b3ec61Sdh155122 mdb_warn("failed to read ip_stack_t %p", kaddr);
269f4b3ec61Sdh155122 return (0);
270f4b3ec61Sdh155122 }
271f4b3ec61Sdh155122 kaddr = (uintptr_t)ipss.ips_netstack;
272f4b3ec61Sdh155122 if (mdb_vread(&nss, sizeof (nss), kaddr) == -1) {
273f4b3ec61Sdh155122 mdb_warn("failed to read netstack_t %p", kaddr);
274f4b3ec61Sdh155122 return (0);
275f4b3ec61Sdh155122 }
276f4b3ec61Sdh155122 return (nss.netstack_stackid);
277f4b3ec61Sdh155122 }
278f4b3ec61Sdh155122
279bd670b35SErik Nordmark /* ARGSUSED */
280bd670b35SErik Nordmark static int
zone_to_ips_cb(uintptr_t addr,const void * zi_arg,void * zi_cb_arg)281bd670b35SErik Nordmark zone_to_ips_cb(uintptr_t addr, const void *zi_arg, void *zi_cb_arg)
282bd670b35SErik Nordmark {
283bd670b35SErik Nordmark zi_cbdata_t *zi_cb = zi_cb_arg;
284bd670b35SErik Nordmark zone_t zone;
285bd670b35SErik Nordmark char zone_name[ZONENAME_MAX];
286bd670b35SErik Nordmark netstack_t ns;
287bd670b35SErik Nordmark
288bd670b35SErik Nordmark if (mdb_vread(&zone, sizeof (zone_t), addr) == -1) {
289bd670b35SErik Nordmark mdb_warn("can't read zone at %p", addr);
290bd670b35SErik Nordmark return (WALK_ERR);
291bd670b35SErik Nordmark }
292bd670b35SErik Nordmark
293bd670b35SErik Nordmark (void) mdb_readstr(zone_name, ZONENAME_MAX, (uintptr_t)zone.zone_name);
294bd670b35SErik Nordmark
295bd670b35SErik Nordmark if (strcmp(zi_cb->zone_name, zone_name) != 0)
296bd670b35SErik Nordmark return (WALK_NEXT);
297bd670b35SErik Nordmark
298bd670b35SErik Nordmark zi_cb->shared_ip_zone = (!(zone.zone_flags & ZF_NET_EXCL) &&
299bd670b35SErik Nordmark (strcmp(zone_name, "global") != 0));
300bd670b35SErik Nordmark
301bd670b35SErik Nordmark if (mdb_vread(&ns, sizeof (netstack_t), (uintptr_t)zone.zone_netstack)
302bd670b35SErik Nordmark == -1) {
303bd670b35SErik Nordmark mdb_warn("can't read netstack at %p", zone.zone_netstack);
304bd670b35SErik Nordmark return (WALK_ERR);
305bd670b35SErik Nordmark }
306bd670b35SErik Nordmark
307bd670b35SErik Nordmark zi_cb->ipst = ns.netstack_ip;
308bd670b35SErik Nordmark return (WALK_DONE);
309bd670b35SErik Nordmark }
310bd670b35SErik Nordmark
311bd670b35SErik Nordmark static ip_stack_t *
zone_to_ips(const char * zone_name)312bd670b35SErik Nordmark zone_to_ips(const char *zone_name)
313bd670b35SErik Nordmark {
314bd670b35SErik Nordmark zi_cbdata_t zi_cb;
315bd670b35SErik Nordmark
316bd670b35SErik Nordmark if (zone_name == NULL)
317bd670b35SErik Nordmark return (NULL);
318bd670b35SErik Nordmark
319bd670b35SErik Nordmark zi_cb.zone_name = zone_name;
320bd670b35SErik Nordmark zi_cb.ipst = NULL;
321bd670b35SErik Nordmark zi_cb.shared_ip_zone = B_FALSE;
322bd670b35SErik Nordmark
323bd670b35SErik Nordmark if (mdb_walk("zone", (mdb_walk_cb_t)zone_to_ips_cb, &zi_cb) == -1) {
324bd670b35SErik Nordmark mdb_warn("failed to walk zone");
325bd670b35SErik Nordmark return (NULL);
326bd670b35SErik Nordmark }
327bd670b35SErik Nordmark
328bd670b35SErik Nordmark if (zi_cb.shared_ip_zone) {
329bd670b35SErik Nordmark mdb_warn("%s is a Shared-IP zone, try '-s global' instead\n",
330bd670b35SErik Nordmark zone_name);
331bd670b35SErik Nordmark return (NULL);
332bd670b35SErik Nordmark }
333bd670b35SErik Nordmark
334bd670b35SErik Nordmark if (zi_cb.ipst == NULL) {
335bd670b35SErik Nordmark mdb_warn("failed to find zone %s\n", zone_name);
336bd670b35SErik Nordmark return (NULL);
337bd670b35SErik Nordmark }
338bd670b35SErik Nordmark
339bd670b35SErik Nordmark return (zi_cb.ipst);
340bd670b35SErik Nordmark }
341bd670b35SErik Nordmark
342721fffe3SKacheong Poon /*
343721fffe3SKacheong Poon * Generic network stack walker initialization function. It is used by all
344721fffe3SKacheong Poon * other netwrok stack walkers.
345721fffe3SKacheong Poon */
3467c478bd9Sstevel@tonic-gate int
ns_walk_init(mdb_walk_state_t * wsp)347721fffe3SKacheong Poon ns_walk_init(mdb_walk_state_t *wsp)
348f4b3ec61Sdh155122 {
349f4b3ec61Sdh155122 if (mdb_layered_walk("netstack", wsp) == -1) {
350f4b3ec61Sdh155122 mdb_warn("can't walk 'netstack'");
351f4b3ec61Sdh155122 return (WALK_ERR);
352f4b3ec61Sdh155122 }
353f4b3ec61Sdh155122 return (WALK_NEXT);
354f4b3ec61Sdh155122 }
355f4b3ec61Sdh155122
356721fffe3SKacheong Poon /*
357721fffe3SKacheong Poon * Generic network stack walker stepping function. It is used by all other
358721fffe3SKacheong Poon * network stack walkers. The which parameter differentiates the different
359721fffe3SKacheong Poon * walkers.
360721fffe3SKacheong Poon */
361f4b3ec61Sdh155122 int
ns_walk_step(mdb_walk_state_t * wsp,int which)362721fffe3SKacheong Poon ns_walk_step(mdb_walk_state_t *wsp, int which)
363f4b3ec61Sdh155122 {
364f4b3ec61Sdh155122 uintptr_t kaddr;
365f4b3ec61Sdh155122 netstack_t nss;
366f4b3ec61Sdh155122
367f4b3ec61Sdh155122 if (mdb_vread(&nss, sizeof (nss), wsp->walk_addr) == -1) {
368f4b3ec61Sdh155122 mdb_warn("can't read netstack at %p", wsp->walk_addr);
369f4b3ec61Sdh155122 return (WALK_ERR);
370f4b3ec61Sdh155122 }
371721fffe3SKacheong Poon kaddr = (uintptr_t)nss.netstack_modules[which];
372f4b3ec61Sdh155122
373f4b3ec61Sdh155122 return (wsp->walk_callback(kaddr, wsp->walk_layer, wsp->walk_cbdata));
374f4b3ec61Sdh155122 }
375f4b3ec61Sdh155122
376721fffe3SKacheong Poon /*
377721fffe3SKacheong Poon * IP network stack walker stepping function.
378721fffe3SKacheong Poon */
379721fffe3SKacheong Poon int
ip_stacks_walk_step(mdb_walk_state_t * wsp)380721fffe3SKacheong Poon ip_stacks_walk_step(mdb_walk_state_t *wsp)
381721fffe3SKacheong Poon {
382721fffe3SKacheong Poon return (ns_walk_step(wsp, NS_IP));
383721fffe3SKacheong Poon }
384721fffe3SKacheong Poon
385721fffe3SKacheong Poon /*
386721fffe3SKacheong Poon * TCP network stack walker stepping function.
387721fffe3SKacheong Poon */
388721fffe3SKacheong Poon int
tcp_stacks_walk_step(mdb_walk_state_t * wsp)389721fffe3SKacheong Poon tcp_stacks_walk_step(mdb_walk_state_t *wsp)
390721fffe3SKacheong Poon {
391721fffe3SKacheong Poon return (ns_walk_step(wsp, NS_TCP));
392721fffe3SKacheong Poon }
393721fffe3SKacheong Poon
394721fffe3SKacheong Poon /*
395721fffe3SKacheong Poon * SCTP network stack walker stepping function.
396721fffe3SKacheong Poon */
397721fffe3SKacheong Poon int
sctp_stacks_walk_step(mdb_walk_state_t * wsp)398721fffe3SKacheong Poon sctp_stacks_walk_step(mdb_walk_state_t *wsp)
399721fffe3SKacheong Poon {
400721fffe3SKacheong Poon return (ns_walk_step(wsp, NS_SCTP));
401721fffe3SKacheong Poon }
402721fffe3SKacheong Poon
403721fffe3SKacheong Poon /*
404721fffe3SKacheong Poon * UDP network stack walker stepping function.
405721fffe3SKacheong Poon */
406721fffe3SKacheong Poon int
udp_stacks_walk_step(mdb_walk_state_t * wsp)407721fffe3SKacheong Poon udp_stacks_walk_step(mdb_walk_state_t *wsp)
408721fffe3SKacheong Poon {
409721fffe3SKacheong Poon return (ns_walk_step(wsp, NS_UDP));
410721fffe3SKacheong Poon }
411721fffe3SKacheong Poon
412721fffe3SKacheong Poon /*
413721fffe3SKacheong Poon * Initialization function for the per CPU TCP stats counter walker of a given
414721fffe3SKacheong Poon * TCP stack.
415721fffe3SKacheong Poon */
416721fffe3SKacheong Poon int
tcps_sc_walk_init(mdb_walk_state_t * wsp)417721fffe3SKacheong Poon tcps_sc_walk_init(mdb_walk_state_t *wsp)
418721fffe3SKacheong Poon {
419721fffe3SKacheong Poon tcp_stack_t tcps;
420721fffe3SKacheong Poon
421721fffe3SKacheong Poon if (wsp->walk_addr == NULL)
422721fffe3SKacheong Poon return (WALK_ERR);
423721fffe3SKacheong Poon
424721fffe3SKacheong Poon if (mdb_vread(&tcps, sizeof (tcps), wsp->walk_addr) == -1) {
425721fffe3SKacheong Poon mdb_warn("failed to read tcp_stack_t at %p", wsp->walk_addr);
426721fffe3SKacheong Poon return (WALK_ERR);
427721fffe3SKacheong Poon }
428721fffe3SKacheong Poon if (tcps.tcps_sc_cnt == 0)
429721fffe3SKacheong Poon return (WALK_DONE);
430721fffe3SKacheong Poon
431721fffe3SKacheong Poon /*
432721fffe3SKacheong Poon * Store the tcp_stack_t pointer in walk_data. The stepping function
433721fffe3SKacheong Poon * used it to calculate if the end of the counter has reached.
434721fffe3SKacheong Poon */
435721fffe3SKacheong Poon wsp->walk_data = (void *)wsp->walk_addr;
436721fffe3SKacheong Poon wsp->walk_addr = (uintptr_t)tcps.tcps_sc;
437721fffe3SKacheong Poon return (WALK_NEXT);
438721fffe3SKacheong Poon }
439721fffe3SKacheong Poon
440721fffe3SKacheong Poon /*
441721fffe3SKacheong Poon * Stepping function for the per CPU TCP stats counterwalker.
442721fffe3SKacheong Poon */
443721fffe3SKacheong Poon int
tcps_sc_walk_step(mdb_walk_state_t * wsp)444721fffe3SKacheong Poon tcps_sc_walk_step(mdb_walk_state_t *wsp)
445721fffe3SKacheong Poon {
446721fffe3SKacheong Poon int status;
447721fffe3SKacheong Poon tcp_stack_t tcps;
448721fffe3SKacheong Poon tcp_stats_cpu_t *stats;
449721fffe3SKacheong Poon char *next, *end;
450721fffe3SKacheong Poon
451721fffe3SKacheong Poon if (mdb_vread(&tcps, sizeof (tcps), (uintptr_t)wsp->walk_data) == -1) {
452721fffe3SKacheong Poon mdb_warn("failed to read tcp_stack_t at %p", wsp->walk_addr);
453721fffe3SKacheong Poon return (WALK_ERR);
454721fffe3SKacheong Poon }
455721fffe3SKacheong Poon if (mdb_vread(&stats, sizeof (stats), wsp->walk_addr) == -1) {
456721fffe3SKacheong Poon mdb_warn("failed ot read tcp_stats_cpu_t at %p",
457721fffe3SKacheong Poon wsp->walk_addr);
458721fffe3SKacheong Poon return (WALK_ERR);
459721fffe3SKacheong Poon }
460721fffe3SKacheong Poon status = wsp->walk_callback((uintptr_t)stats, &stats, wsp->walk_cbdata);
461721fffe3SKacheong Poon if (status != WALK_NEXT)
462721fffe3SKacheong Poon return (status);
463721fffe3SKacheong Poon
464721fffe3SKacheong Poon next = (char *)wsp->walk_addr + sizeof (tcp_stats_cpu_t *);
465721fffe3SKacheong Poon end = (char *)tcps.tcps_sc + tcps.tcps_sc_cnt *
466721fffe3SKacheong Poon sizeof (tcp_stats_cpu_t *);
467721fffe3SKacheong Poon if (next >= end)
468721fffe3SKacheong Poon return (WALK_DONE);
469721fffe3SKacheong Poon wsp->walk_addr = (uintptr_t)next;
470721fffe3SKacheong Poon return (WALK_NEXT);
471721fffe3SKacheong Poon }
472721fffe3SKacheong Poon
4736a8288c7Scarlsonj int
th_hash_walk_init(mdb_walk_state_t * wsp)4746a8288c7Scarlsonj th_hash_walk_init(mdb_walk_state_t *wsp)
4756a8288c7Scarlsonj {
4766a8288c7Scarlsonj GElf_Sym sym;
4776a8288c7Scarlsonj list_node_t *next;
4786a8288c7Scarlsonj
4796a8288c7Scarlsonj if (wsp->walk_addr == NULL) {
4806a8288c7Scarlsonj if (mdb_lookup_by_obj("ip", "ip_thread_list", &sym) == 0) {
4816a8288c7Scarlsonj wsp->walk_addr = sym.st_value;
4826a8288c7Scarlsonj } else {
4836a8288c7Scarlsonj mdb_warn("unable to locate ip_thread_list\n");
4846a8288c7Scarlsonj return (WALK_ERR);
4856a8288c7Scarlsonj }
4866a8288c7Scarlsonj }
4876a8288c7Scarlsonj
4886a8288c7Scarlsonj if (mdb_vread(&next, sizeof (next),
4896a8288c7Scarlsonj wsp->walk_addr + offsetof(list_t, list_head) +
4906a8288c7Scarlsonj offsetof(list_node_t, list_next)) == -1 ||
4916a8288c7Scarlsonj next == NULL) {
4926a8288c7Scarlsonj mdb_warn("non-DEBUG image; cannot walk th_hash list\n");
4936a8288c7Scarlsonj return (WALK_ERR);
4946a8288c7Scarlsonj }
4956a8288c7Scarlsonj
4966a8288c7Scarlsonj if (mdb_layered_walk("list", wsp) == -1) {
4976a8288c7Scarlsonj mdb_warn("can't walk 'list'");
4986a8288c7Scarlsonj return (WALK_ERR);
4996a8288c7Scarlsonj } else {
5006a8288c7Scarlsonj return (WALK_NEXT);
5016a8288c7Scarlsonj }
5026a8288c7Scarlsonj }
5036a8288c7Scarlsonj
5046a8288c7Scarlsonj int
th_hash_walk_step(mdb_walk_state_t * wsp)5056a8288c7Scarlsonj th_hash_walk_step(mdb_walk_state_t *wsp)
5066a8288c7Scarlsonj {
5076a8288c7Scarlsonj return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
5086a8288c7Scarlsonj wsp->walk_cbdata));
5096a8288c7Scarlsonj }
5106a8288c7Scarlsonj
511f4b3ec61Sdh155122 /*
512f4b3ec61Sdh155122 * Called with walk_addr being the address of ips_ill_g_heads
513f4b3ec61Sdh155122 */
514f4b3ec61Sdh155122 int
illif_stack_walk_init(mdb_walk_state_t * wsp)515f4b3ec61Sdh155122 illif_stack_walk_init(mdb_walk_state_t *wsp)
5167c478bd9Sstevel@tonic-gate {
5177c478bd9Sstevel@tonic-gate illif_walk_data_t *iw;
5187c478bd9Sstevel@tonic-gate
519f4b3ec61Sdh155122 if (wsp->walk_addr == NULL) {
520f4b3ec61Sdh155122 mdb_warn("illif_stack supports only local walks\n");
5217c478bd9Sstevel@tonic-gate return (WALK_ERR);
5227c478bd9Sstevel@tonic-gate }
5237c478bd9Sstevel@tonic-gate
5247c478bd9Sstevel@tonic-gate iw = mdb_alloc(sizeof (illif_walk_data_t), UM_SLEEP);
5257c478bd9Sstevel@tonic-gate
526f4b3ec61Sdh155122 if (mdb_vread(iw->ill_g_heads, MAX_G_HEADS * sizeof (ill_g_head_t),
527f4b3ec61Sdh155122 wsp->walk_addr) == -1) {
528f4b3ec61Sdh155122 mdb_warn("failed to read 'ips_ill_g_heads' at %p",
529f4b3ec61Sdh155122 wsp->walk_addr);
5307c478bd9Sstevel@tonic-gate mdb_free(iw, sizeof (illif_walk_data_t));
5317c478bd9Sstevel@tonic-gate return (WALK_ERR);
5327c478bd9Sstevel@tonic-gate }
5337c478bd9Sstevel@tonic-gate
5347c478bd9Sstevel@tonic-gate iw->ill_list = 0;
535f4b3ec61Sdh155122 wsp->walk_addr = (uintptr_t)iw->ill_g_heads[0].ill_g_list_head;
5367c478bd9Sstevel@tonic-gate wsp->walk_data = iw;
5377c478bd9Sstevel@tonic-gate
5387c478bd9Sstevel@tonic-gate return (WALK_NEXT);
5397c478bd9Sstevel@tonic-gate }
5407c478bd9Sstevel@tonic-gate
5417c478bd9Sstevel@tonic-gate int
illif_stack_walk_step(mdb_walk_state_t * wsp)542f4b3ec61Sdh155122 illif_stack_walk_step(mdb_walk_state_t *wsp)
5437c478bd9Sstevel@tonic-gate {
5447c478bd9Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr;
5457c478bd9Sstevel@tonic-gate illif_walk_data_t *iw = wsp->walk_data;
5467c478bd9Sstevel@tonic-gate int list = iw->ill_list;
5477c478bd9Sstevel@tonic-gate
5487c478bd9Sstevel@tonic-gate if (mdb_vread(&iw->ill_if, sizeof (ill_if_t), addr) == -1) {
5497c478bd9Sstevel@tonic-gate mdb_warn("failed to read ill_if_t at %p", addr);
5507c478bd9Sstevel@tonic-gate return (WALK_ERR);
5517c478bd9Sstevel@tonic-gate }
5527c478bd9Sstevel@tonic-gate
5537c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)iw->ill_if.illif_next;
5547c478bd9Sstevel@tonic-gate
555f4b3ec61Sdh155122 if (wsp->walk_addr ==
556f4b3ec61Sdh155122 (uintptr_t)iw->ill_g_heads[list].ill_g_list_head) {
5577c478bd9Sstevel@tonic-gate
5587c478bd9Sstevel@tonic-gate if (++list >= MAX_G_HEADS)
5597c478bd9Sstevel@tonic-gate return (WALK_DONE);
5607c478bd9Sstevel@tonic-gate
5617c478bd9Sstevel@tonic-gate iw->ill_list = list;
562f4b3ec61Sdh155122 wsp->walk_addr =
563f4b3ec61Sdh155122 (uintptr_t)iw->ill_g_heads[list].ill_g_list_head;
5647c478bd9Sstevel@tonic-gate return (WALK_NEXT);
5657c478bd9Sstevel@tonic-gate }
5667c478bd9Sstevel@tonic-gate
5677c478bd9Sstevel@tonic-gate return (wsp->walk_callback(addr, iw, wsp->walk_cbdata));
5687c478bd9Sstevel@tonic-gate }
5697c478bd9Sstevel@tonic-gate
5707c478bd9Sstevel@tonic-gate void
illif_stack_walk_fini(mdb_walk_state_t * wsp)571f4b3ec61Sdh155122 illif_stack_walk_fini(mdb_walk_state_t *wsp)
5727c478bd9Sstevel@tonic-gate {
5737c478bd9Sstevel@tonic-gate mdb_free(wsp->walk_data, sizeof (illif_walk_data_t));
5747c478bd9Sstevel@tonic-gate }
5757c478bd9Sstevel@tonic-gate
5767c478bd9Sstevel@tonic-gate typedef struct illif_cbdata {
5777c478bd9Sstevel@tonic-gate uint_t ill_flags;
5787c478bd9Sstevel@tonic-gate uintptr_t ill_addr;
5797c478bd9Sstevel@tonic-gate int ill_printlist; /* list to be printed (MAX_G_HEADS for all) */
5807c478bd9Sstevel@tonic-gate boolean_t ill_printed;
5817c478bd9Sstevel@tonic-gate } illif_cbdata_t;
5827c478bd9Sstevel@tonic-gate
5837c478bd9Sstevel@tonic-gate static int
illif_cb(uintptr_t addr,const illif_walk_data_t * iw,illif_cbdata_t * id)5847c478bd9Sstevel@tonic-gate illif_cb(uintptr_t addr, const illif_walk_data_t *iw, illif_cbdata_t *id)
5857c478bd9Sstevel@tonic-gate {
5867c478bd9Sstevel@tonic-gate const char *version;
5877c478bd9Sstevel@tonic-gate
5887c478bd9Sstevel@tonic-gate if (id->ill_printlist < MAX_G_HEADS &&
5897c478bd9Sstevel@tonic-gate id->ill_printlist != iw->ill_list)
5907c478bd9Sstevel@tonic-gate return (WALK_NEXT);
5917c478bd9Sstevel@tonic-gate
5927c478bd9Sstevel@tonic-gate if (id->ill_flags & DCMD_ADDRSPEC && id->ill_addr != addr)
5937c478bd9Sstevel@tonic-gate return (WALK_NEXT);
5947c478bd9Sstevel@tonic-gate
5957c478bd9Sstevel@tonic-gate if (id->ill_flags & DCMD_PIPE_OUT) {
5967c478bd9Sstevel@tonic-gate mdb_printf("%p\n", addr);
5977c478bd9Sstevel@tonic-gate return (WALK_NEXT);
5987c478bd9Sstevel@tonic-gate }
5997c478bd9Sstevel@tonic-gate
6007c478bd9Sstevel@tonic-gate switch (iw->ill_list) {
6017c478bd9Sstevel@tonic-gate case IP_V4_G_HEAD: version = "v4"; break;
6027c478bd9Sstevel@tonic-gate case IP_V6_G_HEAD: version = "v6"; break;
6037c478bd9Sstevel@tonic-gate default: version = "??"; break;
6047c478bd9Sstevel@tonic-gate }
6057c478bd9Sstevel@tonic-gate
6067c478bd9Sstevel@tonic-gate mdb_printf("%?p %2s %?p %10d %?p %s\n",
6077c478bd9Sstevel@tonic-gate addr, version, addr + offsetof(ill_if_t, illif_avl_by_ppa),
6087c478bd9Sstevel@tonic-gate iw->ill_if.illif_avl_by_ppa.avl_numnodes,
6097c478bd9Sstevel@tonic-gate iw->ill_if.illif_ppa_arena, iw->ill_if.illif_name);
6107c478bd9Sstevel@tonic-gate
6117c478bd9Sstevel@tonic-gate id->ill_printed = TRUE;
6127c478bd9Sstevel@tonic-gate
6137c478bd9Sstevel@tonic-gate return (WALK_NEXT);
6147c478bd9Sstevel@tonic-gate }
6157c478bd9Sstevel@tonic-gate
6167c478bd9Sstevel@tonic-gate int
ip_stacks_common_walk_init(mdb_walk_state_t * wsp)617ffaa671aSsowmini ip_stacks_common_walk_init(mdb_walk_state_t *wsp)
618f4b3ec61Sdh155122 {
619f4b3ec61Sdh155122 if (mdb_layered_walk("ip_stacks", wsp) == -1) {
620f4b3ec61Sdh155122 mdb_warn("can't walk 'ip_stacks'");
621f4b3ec61Sdh155122 return (WALK_ERR);
622f4b3ec61Sdh155122 }
623f4b3ec61Sdh155122
624f4b3ec61Sdh155122 return (WALK_NEXT);
625f4b3ec61Sdh155122 }
626f4b3ec61Sdh155122
627f4b3ec61Sdh155122 int
illif_walk_step(mdb_walk_state_t * wsp)628f4b3ec61Sdh155122 illif_walk_step(mdb_walk_state_t *wsp)
629f4b3ec61Sdh155122 {
630f4b3ec61Sdh155122 uintptr_t kaddr;
631f4b3ec61Sdh155122
632f4b3ec61Sdh155122 kaddr = wsp->walk_addr + OFFSETOF(ip_stack_t, ips_ill_g_heads);
633f4b3ec61Sdh155122
634f4b3ec61Sdh155122 if (mdb_vread(&kaddr, sizeof (kaddr), kaddr) == -1) {
635f4b3ec61Sdh155122 mdb_warn("can't read ips_ip_cache_table at %p", kaddr);
636f4b3ec61Sdh155122 return (WALK_ERR);
637f4b3ec61Sdh155122 }
638f4b3ec61Sdh155122
639f4b3ec61Sdh155122 if (mdb_pwalk("illif_stack", wsp->walk_callback,
640f4b3ec61Sdh155122 wsp->walk_cbdata, kaddr) == -1) {
641f4b3ec61Sdh155122 mdb_warn("couldn't walk 'illif_stack' for ips_ill_g_heads %p",
642f4b3ec61Sdh155122 kaddr);
643f4b3ec61Sdh155122 return (WALK_ERR);
644f4b3ec61Sdh155122 }
645f4b3ec61Sdh155122 return (WALK_NEXT);
646f4b3ec61Sdh155122 }
647f4b3ec61Sdh155122
648f4b3ec61Sdh155122 int
illif(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)6497c478bd9Sstevel@tonic-gate illif(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
6507c478bd9Sstevel@tonic-gate {
6517c478bd9Sstevel@tonic-gate illif_cbdata_t id;
6527c478bd9Sstevel@tonic-gate ill_if_t ill_if;
6537c478bd9Sstevel@tonic-gate const char *opt_P = NULL;
6547c478bd9Sstevel@tonic-gate int printlist = MAX_G_HEADS;
6557c478bd9Sstevel@tonic-gate
6567c478bd9Sstevel@tonic-gate if (mdb_getopts(argc, argv,
6577c478bd9Sstevel@tonic-gate 'P', MDB_OPT_STR, &opt_P, NULL) != argc)
6587c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
6597c478bd9Sstevel@tonic-gate
6607c478bd9Sstevel@tonic-gate if (opt_P != NULL) {
6617c478bd9Sstevel@tonic-gate if (strcmp("v4", opt_P) == 0) {
6627c478bd9Sstevel@tonic-gate printlist = IP_V4_G_HEAD;
6637c478bd9Sstevel@tonic-gate } else if (strcmp("v6", opt_P) == 0) {
6647c478bd9Sstevel@tonic-gate printlist = IP_V6_G_HEAD;
6657c478bd9Sstevel@tonic-gate } else {
6667c478bd9Sstevel@tonic-gate mdb_warn("invalid protocol '%s'\n", opt_P);
6677c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
6687c478bd9Sstevel@tonic-gate }
6697c478bd9Sstevel@tonic-gate }
6707c478bd9Sstevel@tonic-gate
6717c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags) && (flags & DCMD_PIPE_OUT) == 0) {
6727c478bd9Sstevel@tonic-gate mdb_printf("%<u>%?s %2s %?s %10s %?s %-10s%</u>\n",
6737c478bd9Sstevel@tonic-gate "ADDR", "IP", "AVLADDR", "NUMNODES", "ARENA", "NAME");
6747c478bd9Sstevel@tonic-gate }
6757c478bd9Sstevel@tonic-gate
6767c478bd9Sstevel@tonic-gate id.ill_flags = flags;
6777c478bd9Sstevel@tonic-gate id.ill_addr = addr;
6787c478bd9Sstevel@tonic-gate id.ill_printlist = printlist;
6797c478bd9Sstevel@tonic-gate id.ill_printed = FALSE;
6807c478bd9Sstevel@tonic-gate
6817c478bd9Sstevel@tonic-gate if (mdb_walk("illif", (mdb_walk_cb_t)illif_cb, &id) == -1) {
6827c478bd9Sstevel@tonic-gate mdb_warn("can't walk ill_if_t structures");
6837c478bd9Sstevel@tonic-gate return (DCMD_ERR);
6847c478bd9Sstevel@tonic-gate }
6857c478bd9Sstevel@tonic-gate
6867c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC) || opt_P != NULL || id.ill_printed)
6877c478bd9Sstevel@tonic-gate return (DCMD_OK);
6887c478bd9Sstevel@tonic-gate
6897c478bd9Sstevel@tonic-gate /*
6907c478bd9Sstevel@tonic-gate * If an address is specified and the walk doesn't find it,
6917c478bd9Sstevel@tonic-gate * print it anyway.
6927c478bd9Sstevel@tonic-gate */
6937c478bd9Sstevel@tonic-gate if (mdb_vread(&ill_if, sizeof (ill_if_t), addr) == -1) {
6947c478bd9Sstevel@tonic-gate mdb_warn("failed to read ill_if_t at %p", addr);
6957c478bd9Sstevel@tonic-gate return (DCMD_ERR);
6967c478bd9Sstevel@tonic-gate }
6977c478bd9Sstevel@tonic-gate
6987c478bd9Sstevel@tonic-gate mdb_printf("%?p %2s %?p %10d %?p %s\n",
6997c478bd9Sstevel@tonic-gate addr, "??", addr + offsetof(ill_if_t, illif_avl_by_ppa),
7007c478bd9Sstevel@tonic-gate ill_if.illif_avl_by_ppa.avl_numnodes,
7017c478bd9Sstevel@tonic-gate ill_if.illif_ppa_arena, ill_if.illif_name);
7027c478bd9Sstevel@tonic-gate
7037c478bd9Sstevel@tonic-gate return (DCMD_OK);
7047c478bd9Sstevel@tonic-gate }
7057c478bd9Sstevel@tonic-gate
7067c478bd9Sstevel@tonic-gate static void
illif_help(void)7077c478bd9Sstevel@tonic-gate illif_help(void)
7087c478bd9Sstevel@tonic-gate {
7097c478bd9Sstevel@tonic-gate mdb_printf("Options:\n");
7107c478bd9Sstevel@tonic-gate mdb_printf("\t-P v4 | v6"
7117c478bd9Sstevel@tonic-gate "\tfilter interface structures for the specified protocol\n");
7127c478bd9Sstevel@tonic-gate }
7137c478bd9Sstevel@tonic-gate
7147c478bd9Sstevel@tonic-gate int
nce_walk_init(mdb_walk_state_t * wsp)715bd670b35SErik Nordmark nce_walk_init(mdb_walk_state_t *wsp)
716bd670b35SErik Nordmark {
717bd670b35SErik Nordmark if (mdb_layered_walk("nce_cache", wsp) == -1) {
718bd670b35SErik Nordmark mdb_warn("can't walk 'nce_cache'");
719bd670b35SErik Nordmark return (WALK_ERR);
720bd670b35SErik Nordmark }
721bd670b35SErik Nordmark
722bd670b35SErik Nordmark return (WALK_NEXT);
723bd670b35SErik Nordmark }
724bd670b35SErik Nordmark
725bd670b35SErik Nordmark int
nce_walk_step(mdb_walk_state_t * wsp)726bd670b35SErik Nordmark nce_walk_step(mdb_walk_state_t *wsp)
727bd670b35SErik Nordmark {
728bd670b35SErik Nordmark nce_t nce;
729bd670b35SErik Nordmark
730bd670b35SErik Nordmark if (mdb_vread(&nce, sizeof (nce), wsp->walk_addr) == -1) {
731bd670b35SErik Nordmark mdb_warn("can't read nce at %p", wsp->walk_addr);
732bd670b35SErik Nordmark return (WALK_ERR);
733bd670b35SErik Nordmark }
734bd670b35SErik Nordmark
735bd670b35SErik Nordmark return (wsp->walk_callback(wsp->walk_addr, &nce, wsp->walk_cbdata));
736bd670b35SErik Nordmark }
737bd670b35SErik Nordmark
738bd670b35SErik Nordmark static int
nce_format(uintptr_t addr,const nce_t * ncep,void * nce_cb_arg)739bd670b35SErik Nordmark nce_format(uintptr_t addr, const nce_t *ncep, void *nce_cb_arg)
740bd670b35SErik Nordmark {
741bd670b35SErik Nordmark nce_cbdata_t *nce_cb = nce_cb_arg;
742bd670b35SErik Nordmark ill_t ill;
743bd670b35SErik Nordmark char ill_name[LIFNAMSIZ];
744bd670b35SErik Nordmark ncec_t ncec;
745bd670b35SErik Nordmark
746bd670b35SErik Nordmark if (mdb_vread(&ncec, sizeof (ncec),
747bd670b35SErik Nordmark (uintptr_t)ncep->nce_common) == -1) {
748bd670b35SErik Nordmark mdb_warn("can't read ncec at %p", ncep->nce_common);
749bd670b35SErik Nordmark return (WALK_NEXT);
750bd670b35SErik Nordmark }
751bd670b35SErik Nordmark if (nce_cb->nce_ipversion != 0 &&
752bd670b35SErik Nordmark ncec.ncec_ipversion != nce_cb->nce_ipversion)
753bd670b35SErik Nordmark return (WALK_NEXT);
754bd670b35SErik Nordmark
755bd670b35SErik Nordmark if (mdb_vread(&ill, sizeof (ill), (uintptr_t)ncep->nce_ill) == -1) {
756bd670b35SErik Nordmark mdb_snprintf(ill_name, sizeof (ill_name), "--");
757bd670b35SErik Nordmark } else {
758bd670b35SErik Nordmark (void) mdb_readstr(ill_name,
759bd670b35SErik Nordmark MIN(LIFNAMSIZ, ill.ill_name_length),
760bd670b35SErik Nordmark (uintptr_t)ill.ill_name);
761bd670b35SErik Nordmark }
762bd670b35SErik Nordmark
763bd670b35SErik Nordmark if (nce_cb->nce_ill_name[0] != '\0' &&
764bd670b35SErik Nordmark strncmp(nce_cb->nce_ill_name, ill_name, LIFNAMSIZ) != 0)
765bd670b35SErik Nordmark return (WALK_NEXT);
766bd670b35SErik Nordmark
767bd670b35SErik Nordmark if (ncec.ncec_ipversion == IPV6_VERSION) {
768bd670b35SErik Nordmark
769bd670b35SErik Nordmark mdb_printf("%?p %5s %-18s %?p %6d %N\n",
770bd670b35SErik Nordmark addr, ill_name,
771bd670b35SErik Nordmark nce_l2_addr(ncep, &ill),
772bd670b35SErik Nordmark ncep->nce_fp_mp,
773bd670b35SErik Nordmark ncep->nce_refcnt,
774bd670b35SErik Nordmark &ncep->nce_addr);
775bd670b35SErik Nordmark
776bd670b35SErik Nordmark } else {
777bd670b35SErik Nordmark struct in_addr nceaddr;
778bd670b35SErik Nordmark
779bd670b35SErik Nordmark IN6_V4MAPPED_TO_INADDR(&ncep->nce_addr, &nceaddr);
780bd670b35SErik Nordmark mdb_printf("%?p %5s %-18s %?p %6d %I\n",
781bd670b35SErik Nordmark addr, ill_name,
782bd670b35SErik Nordmark nce_l2_addr(ncep, &ill),
783bd670b35SErik Nordmark ncep->nce_fp_mp,
784bd670b35SErik Nordmark ncep->nce_refcnt,
785bd670b35SErik Nordmark nceaddr.s_addr);
786bd670b35SErik Nordmark }
787bd670b35SErik Nordmark
788bd670b35SErik Nordmark return (WALK_NEXT);
789bd670b35SErik Nordmark }
790bd670b35SErik Nordmark
791bd670b35SErik Nordmark int
dce_walk_init(mdb_walk_state_t * wsp)792bd670b35SErik Nordmark dce_walk_init(mdb_walk_state_t *wsp)
793bd670b35SErik Nordmark {
794bd670b35SErik Nordmark wsp->walk_data = (void *)wsp->walk_addr;
795bd670b35SErik Nordmark
796bd670b35SErik Nordmark if (mdb_layered_walk("dce_cache", wsp) == -1) {
797bd670b35SErik Nordmark mdb_warn("can't walk 'dce_cache'");
798bd670b35SErik Nordmark return (WALK_ERR);
799bd670b35SErik Nordmark }
800bd670b35SErik Nordmark
801bd670b35SErik Nordmark return (WALK_NEXT);
802bd670b35SErik Nordmark }
803bd670b35SErik Nordmark
804bd670b35SErik Nordmark int
dce_walk_step(mdb_walk_state_t * wsp)805bd670b35SErik Nordmark dce_walk_step(mdb_walk_state_t *wsp)
806bd670b35SErik Nordmark {
807bd670b35SErik Nordmark dce_t dce;
808bd670b35SErik Nordmark
809bd670b35SErik Nordmark if (mdb_vread(&dce, sizeof (dce), wsp->walk_addr) == -1) {
810bd670b35SErik Nordmark mdb_warn("can't read dce at %p", wsp->walk_addr);
811bd670b35SErik Nordmark return (WALK_ERR);
812bd670b35SErik Nordmark }
813bd670b35SErik Nordmark
814bd670b35SErik Nordmark /* If ip_stack_t is specified, skip DCEs that don't belong to it. */
815bd670b35SErik Nordmark if ((wsp->walk_data != NULL) && (wsp->walk_data != dce.dce_ipst))
816bd670b35SErik Nordmark return (WALK_NEXT);
817bd670b35SErik Nordmark
818bd670b35SErik Nordmark return (wsp->walk_callback(wsp->walk_addr, &dce, wsp->walk_cbdata));
819bd670b35SErik Nordmark }
820bd670b35SErik Nordmark
821bd670b35SErik Nordmark int
ire_walk_init(mdb_walk_state_t * wsp)8227c478bd9Sstevel@tonic-gate ire_walk_init(mdb_walk_state_t *wsp)
8237c478bd9Sstevel@tonic-gate {
824bd670b35SErik Nordmark wsp->walk_data = (void *)wsp->walk_addr;
825bd670b35SErik Nordmark
8267c478bd9Sstevel@tonic-gate if (mdb_layered_walk("ire_cache", wsp) == -1) {
8277c478bd9Sstevel@tonic-gate mdb_warn("can't walk 'ire_cache'");
8287c478bd9Sstevel@tonic-gate return (WALK_ERR);
8297c478bd9Sstevel@tonic-gate }
8307c478bd9Sstevel@tonic-gate
8317c478bd9Sstevel@tonic-gate return (WALK_NEXT);
8327c478bd9Sstevel@tonic-gate }
8337c478bd9Sstevel@tonic-gate
8347c478bd9Sstevel@tonic-gate int
ire_walk_step(mdb_walk_state_t * wsp)8357c478bd9Sstevel@tonic-gate ire_walk_step(mdb_walk_state_t *wsp)
8367c478bd9Sstevel@tonic-gate {
8377c478bd9Sstevel@tonic-gate ire_t ire;
8387c478bd9Sstevel@tonic-gate
8397c478bd9Sstevel@tonic-gate if (mdb_vread(&ire, sizeof (ire), wsp->walk_addr) == -1) {
8407c478bd9Sstevel@tonic-gate mdb_warn("can't read ire at %p", wsp->walk_addr);
8417c478bd9Sstevel@tonic-gate return (WALK_ERR);
8427c478bd9Sstevel@tonic-gate }
8437c478bd9Sstevel@tonic-gate
844bd670b35SErik Nordmark /* If ip_stack_t is specified, skip IREs that don't belong to it. */
845bd670b35SErik Nordmark if ((wsp->walk_data != NULL) && (wsp->walk_data != ire.ire_ipst))
846f4b3ec61Sdh155122 return (WALK_NEXT);
847bd670b35SErik Nordmark
848bd670b35SErik Nordmark return (wsp->walk_callback(wsp->walk_addr, &ire, wsp->walk_cbdata));
849f4b3ec61Sdh155122 }
850f4b3ec61Sdh155122
851f4b3ec61Sdh155122 /* ARGSUSED */
852f4b3ec61Sdh155122 int
ire_next_walk_init(mdb_walk_state_t * wsp)853f4b3ec61Sdh155122 ire_next_walk_init(mdb_walk_state_t *wsp)
854f4b3ec61Sdh155122 {
855f4b3ec61Sdh155122 return (WALK_NEXT);
856f4b3ec61Sdh155122 }
857f4b3ec61Sdh155122
858f4b3ec61Sdh155122 int
ire_next_walk_step(mdb_walk_state_t * wsp)859f4b3ec61Sdh155122 ire_next_walk_step(mdb_walk_state_t *wsp)
860f4b3ec61Sdh155122 {
861f4b3ec61Sdh155122 ire_t ire;
862f4b3ec61Sdh155122 int status;
863f4b3ec61Sdh155122
864f4b3ec61Sdh155122
865f4b3ec61Sdh155122 if (wsp->walk_addr == NULL)
866f4b3ec61Sdh155122 return (WALK_DONE);
867f4b3ec61Sdh155122
868f4b3ec61Sdh155122 if (mdb_vread(&ire, sizeof (ire), wsp->walk_addr) == -1) {
869f4b3ec61Sdh155122 mdb_warn("can't read ire at %p", wsp->walk_addr);
870f4b3ec61Sdh155122 return (WALK_ERR);
871f4b3ec61Sdh155122 }
872f4b3ec61Sdh155122 status = wsp->walk_callback(wsp->walk_addr, &ire,
873f4b3ec61Sdh155122 wsp->walk_cbdata);
874f4b3ec61Sdh155122
875f4b3ec61Sdh155122 if (status != WALK_NEXT)
876f4b3ec61Sdh155122 return (status);
877f4b3ec61Sdh155122
878f4b3ec61Sdh155122 wsp->walk_addr = (uintptr_t)ire.ire_next;
879f4b3ec61Sdh155122 return (status);
880f4b3ec61Sdh155122 }
881f4b3ec61Sdh155122
8827c478bd9Sstevel@tonic-gate static int
ire_format(uintptr_t addr,const void * ire_arg,void * ire_cb_arg)883ffaa671aSsowmini ire_format(uintptr_t addr, const void *ire_arg, void *ire_cb_arg)
8847c478bd9Sstevel@tonic-gate {
885ffaa671aSsowmini const ire_t *irep = ire_arg;
886ffaa671aSsowmini ire_cbdata_t *ire_cb = ire_cb_arg;
887ffaa671aSsowmini boolean_t verbose = ire_cb->verbose;
888bd670b35SErik Nordmark ill_t ill;
889bd670b35SErik Nordmark char ill_name[LIFNAMSIZ];
890bd670b35SErik Nordmark boolean_t condemned = irep->ire_generation == IRE_GENERATION_CONDEMNED;
891ffaa671aSsowmini
8927c478bd9Sstevel@tonic-gate static const mdb_bitmask_t tmasks[] = {
8937c478bd9Sstevel@tonic-gate { "BROADCAST", IRE_BROADCAST, IRE_BROADCAST },
8947c478bd9Sstevel@tonic-gate { "DEFAULT", IRE_DEFAULT, IRE_DEFAULT },
8957c478bd9Sstevel@tonic-gate { "LOCAL", IRE_LOCAL, IRE_LOCAL },
8967c478bd9Sstevel@tonic-gate { "LOOPBACK", IRE_LOOPBACK, IRE_LOOPBACK },
8977c478bd9Sstevel@tonic-gate { "PREFIX", IRE_PREFIX, IRE_PREFIX },
898bd670b35SErik Nordmark { "MULTICAST", IRE_MULTICAST, IRE_MULTICAST },
899bd670b35SErik Nordmark { "NOROUTE", IRE_NOROUTE, IRE_NOROUTE },
9007c478bd9Sstevel@tonic-gate { "IF_NORESOLVER", IRE_IF_NORESOLVER, IRE_IF_NORESOLVER },
9017c478bd9Sstevel@tonic-gate { "IF_RESOLVER", IRE_IF_RESOLVER, IRE_IF_RESOLVER },
902bd670b35SErik Nordmark { "IF_CLONE", IRE_IF_CLONE, IRE_IF_CLONE },
9037c478bd9Sstevel@tonic-gate { "HOST", IRE_HOST, IRE_HOST },
9047c478bd9Sstevel@tonic-gate { NULL, 0, 0 }
9057c478bd9Sstevel@tonic-gate };
9067c478bd9Sstevel@tonic-gate
9077c478bd9Sstevel@tonic-gate static const mdb_bitmask_t fmasks[] = {
9087c478bd9Sstevel@tonic-gate { "UP", RTF_UP, RTF_UP },
9097c478bd9Sstevel@tonic-gate { "GATEWAY", RTF_GATEWAY, RTF_GATEWAY },
9107c478bd9Sstevel@tonic-gate { "HOST", RTF_HOST, RTF_HOST },
9117c478bd9Sstevel@tonic-gate { "REJECT", RTF_REJECT, RTF_REJECT },
9127c478bd9Sstevel@tonic-gate { "DYNAMIC", RTF_DYNAMIC, RTF_DYNAMIC },
9137c478bd9Sstevel@tonic-gate { "MODIFIED", RTF_MODIFIED, RTF_MODIFIED },
9147c478bd9Sstevel@tonic-gate { "DONE", RTF_DONE, RTF_DONE },
9157c478bd9Sstevel@tonic-gate { "MASK", RTF_MASK, RTF_MASK },
9167c478bd9Sstevel@tonic-gate { "CLONING", RTF_CLONING, RTF_CLONING },
9177c478bd9Sstevel@tonic-gate { "XRESOLVE", RTF_XRESOLVE, RTF_XRESOLVE },
9187c478bd9Sstevel@tonic-gate { "LLINFO", RTF_LLINFO, RTF_LLINFO },
9197c478bd9Sstevel@tonic-gate { "STATIC", RTF_STATIC, RTF_STATIC },
9207c478bd9Sstevel@tonic-gate { "BLACKHOLE", RTF_BLACKHOLE, RTF_BLACKHOLE },
9217c478bd9Sstevel@tonic-gate { "PRIVATE", RTF_PRIVATE, RTF_PRIVATE },
9227c478bd9Sstevel@tonic-gate { "PROTO2", RTF_PROTO2, RTF_PROTO2 },
9237c478bd9Sstevel@tonic-gate { "PROTO1", RTF_PROTO1, RTF_PROTO1 },
9247c478bd9Sstevel@tonic-gate { "MULTIRT", RTF_MULTIRT, RTF_MULTIRT },
9257c478bd9Sstevel@tonic-gate { "SETSRC", RTF_SETSRC, RTF_SETSRC },
926bd670b35SErik Nordmark { "INDIRECT", RTF_INDIRECT, RTF_INDIRECT },
9277c478bd9Sstevel@tonic-gate { NULL, 0, 0 }
9287c478bd9Sstevel@tonic-gate };
9297c478bd9Sstevel@tonic-gate
930ffaa671aSsowmini if (ire_cb->ire_ipversion != 0 &&
931ffaa671aSsowmini irep->ire_ipversion != ire_cb->ire_ipversion)
932ffaa671aSsowmini return (WALK_NEXT);
933ffaa671aSsowmini
934bd670b35SErik Nordmark if (mdb_vread(&ill, sizeof (ill), (uintptr_t)irep->ire_ill) == -1) {
935bd670b35SErik Nordmark mdb_snprintf(ill_name, sizeof (ill_name), "--");
936bd670b35SErik Nordmark } else {
937bd670b35SErik Nordmark (void) mdb_readstr(ill_name,
938bd670b35SErik Nordmark MIN(LIFNAMSIZ, ill.ill_name_length),
939bd670b35SErik Nordmark (uintptr_t)ill.ill_name);
940bd670b35SErik Nordmark }
941bd670b35SErik Nordmark
942ffaa671aSsowmini if (irep->ire_ipversion == IPV6_VERSION && verbose) {
9437c478bd9Sstevel@tonic-gate
944bd670b35SErik Nordmark mdb_printf("%<b>%?p%</b>%3s %40N <%hb%s>\n"
945bd670b35SErik Nordmark "%?s %40N\n"
946bd670b35SErik Nordmark "%?s %40d %4d <%hb> %s\n",
947bd670b35SErik Nordmark addr, condemned ? "(C)" : "", &irep->ire_setsrc_addr_v6,
948bd670b35SErik Nordmark irep->ire_type, tmasks,
949bd670b35SErik Nordmark (irep->ire_testhidden ? ", HIDDEN" : ""),
950bd670b35SErik Nordmark "", &irep->ire_addr_v6,
951f4b3ec61Sdh155122 "", ips_to_stackid((uintptr_t)irep->ire_ipst),
952f4b3ec61Sdh155122 irep->ire_zoneid,
953bd670b35SErik Nordmark irep->ire_flags, fmasks, ill_name);
9547c478bd9Sstevel@tonic-gate
955ffaa671aSsowmini } else if (irep->ire_ipversion == IPV6_VERSION) {
9567c478bd9Sstevel@tonic-gate
957bd670b35SErik Nordmark mdb_printf("%?p%3s %30N %30N %5d %4d %s\n",
958bd670b35SErik Nordmark addr, condemned ? "(C)" : "", &irep->ire_setsrc_addr_v6,
959f4b3ec61Sdh155122 &irep->ire_addr_v6,
960f4b3ec61Sdh155122 ips_to_stackid((uintptr_t)irep->ire_ipst),
961bd670b35SErik Nordmark irep->ire_zoneid, ill_name);
9627c478bd9Sstevel@tonic-gate
963ffaa671aSsowmini } else if (verbose) {
9647c478bd9Sstevel@tonic-gate
965bd670b35SErik Nordmark mdb_printf("%<b>%?p%</b>%3s %40I <%hb%s>\n"
966bd670b35SErik Nordmark "%?s %40I\n"
967bd670b35SErik Nordmark "%?s %40d %4d <%hb> %s\n",
968bd670b35SErik Nordmark addr, condemned ? "(C)" : "", irep->ire_setsrc_addr,
969bd670b35SErik Nordmark irep->ire_type, tmasks,
970bd670b35SErik Nordmark (irep->ire_testhidden ? ", HIDDEN" : ""),
971bd670b35SErik Nordmark "", irep->ire_addr,
972f4b3ec61Sdh155122 "", ips_to_stackid((uintptr_t)irep->ire_ipst),
973bd670b35SErik Nordmark irep->ire_zoneid, irep->ire_flags, fmasks, ill_name);
9747c478bd9Sstevel@tonic-gate
9757c478bd9Sstevel@tonic-gate } else {
9767c478bd9Sstevel@tonic-gate
977bd670b35SErik Nordmark mdb_printf("%?p%3s %30I %30I %5d %4d %s\n", addr,
978bd670b35SErik Nordmark condemned ? "(C)" : "", irep->ire_setsrc_addr,
979f4b3ec61Sdh155122 irep->ire_addr, ips_to_stackid((uintptr_t)irep->ire_ipst),
980bd670b35SErik Nordmark irep->ire_zoneid, ill_name);
9817c478bd9Sstevel@tonic-gate }
9827c478bd9Sstevel@tonic-gate
9837c478bd9Sstevel@tonic-gate return (WALK_NEXT);
9847c478bd9Sstevel@tonic-gate }
9857c478bd9Sstevel@tonic-gate
9867c478bd9Sstevel@tonic-gate /*
9877c478bd9Sstevel@tonic-gate * There are faster ways to do this. Given the interactive nature of this
9887c478bd9Sstevel@tonic-gate * use I don't think its worth much effort.
9897c478bd9Sstevel@tonic-gate */
9907c478bd9Sstevel@tonic-gate static unsigned short
ipcksum(void * p,int len)9917c478bd9Sstevel@tonic-gate ipcksum(void *p, int len)
9927c478bd9Sstevel@tonic-gate {
9937c478bd9Sstevel@tonic-gate int32_t sum = 0;
9947c478bd9Sstevel@tonic-gate
9957c478bd9Sstevel@tonic-gate while (len > 1) {
9967c478bd9Sstevel@tonic-gate /* alignment */
9977c478bd9Sstevel@tonic-gate sum += *(uint16_t *)p;
9987c478bd9Sstevel@tonic-gate p = (char *)p + sizeof (uint16_t);
9997c478bd9Sstevel@tonic-gate if (sum & 0x80000000)
10007c478bd9Sstevel@tonic-gate sum = (sum & 0xFFFF) + (sum >> 16);
10017c478bd9Sstevel@tonic-gate len -= 2;
10027c478bd9Sstevel@tonic-gate }
10037c478bd9Sstevel@tonic-gate
10047c478bd9Sstevel@tonic-gate if (len)
10057c478bd9Sstevel@tonic-gate sum += (uint16_t)*(unsigned char *)p;
10067c478bd9Sstevel@tonic-gate
10077c478bd9Sstevel@tonic-gate while (sum >> 16)
10087c478bd9Sstevel@tonic-gate sum = (sum & 0xFFFF) + (sum >> 16);
10097c478bd9Sstevel@tonic-gate
10107c478bd9Sstevel@tonic-gate return (~sum);
10117c478bd9Sstevel@tonic-gate }
10127c478bd9Sstevel@tonic-gate
10137c478bd9Sstevel@tonic-gate static const mdb_bitmask_t tcp_flags[] = {
10147c478bd9Sstevel@tonic-gate { "SYN", TH_SYN, TH_SYN },
10157c478bd9Sstevel@tonic-gate { "ACK", TH_ACK, TH_ACK },
10167c478bd9Sstevel@tonic-gate { "FIN", TH_FIN, TH_FIN },
10177c478bd9Sstevel@tonic-gate { "RST", TH_RST, TH_RST },
10187c478bd9Sstevel@tonic-gate { "PSH", TH_PUSH, TH_PUSH },
10197c478bd9Sstevel@tonic-gate { "ECE", TH_ECE, TH_ECE },
10207c478bd9Sstevel@tonic-gate { "CWR", TH_CWR, TH_CWR },
10217c478bd9Sstevel@tonic-gate { NULL, 0, 0 }
10227c478bd9Sstevel@tonic-gate };
10237c478bd9Sstevel@tonic-gate
1024*0870f17bSKacheong Poon /* TCP option length */
1025*0870f17bSKacheong Poon #define TCPOPT_HEADER_LEN 2
1026*0870f17bSKacheong Poon #define TCPOPT_MAXSEG_LEN 4
1027*0870f17bSKacheong Poon #define TCPOPT_WS_LEN 3
1028*0870f17bSKacheong Poon #define TCPOPT_TSTAMP_LEN 10
1029*0870f17bSKacheong Poon #define TCPOPT_SACK_OK_LEN 2
1030*0870f17bSKacheong Poon
1031*0870f17bSKacheong Poon static void
tcphdr_print_options(uint8_t * opts,uint32_t opts_len)1032*0870f17bSKacheong Poon tcphdr_print_options(uint8_t *opts, uint32_t opts_len)
1033*0870f17bSKacheong Poon {
1034*0870f17bSKacheong Poon uint8_t *endp;
1035*0870f17bSKacheong Poon uint32_t len, val;
1036*0870f17bSKacheong Poon
1037*0870f17bSKacheong Poon mdb_printf("%<b>Options:%</b>");
1038*0870f17bSKacheong Poon endp = opts + opts_len;
1039*0870f17bSKacheong Poon while (opts < endp) {
1040*0870f17bSKacheong Poon len = endp - opts;
1041*0870f17bSKacheong Poon switch (*opts) {
1042*0870f17bSKacheong Poon case TCPOPT_EOL:
1043*0870f17bSKacheong Poon mdb_printf(" EOL");
1044*0870f17bSKacheong Poon opts++;
1045*0870f17bSKacheong Poon break;
1046*0870f17bSKacheong Poon
1047*0870f17bSKacheong Poon case TCPOPT_NOP:
1048*0870f17bSKacheong Poon mdb_printf(" NOP");
1049*0870f17bSKacheong Poon opts++;
1050*0870f17bSKacheong Poon break;
1051*0870f17bSKacheong Poon
1052*0870f17bSKacheong Poon case TCPOPT_MAXSEG: {
1053*0870f17bSKacheong Poon uint16_t mss;
1054*0870f17bSKacheong Poon
1055*0870f17bSKacheong Poon if (len < TCPOPT_MAXSEG_LEN ||
1056*0870f17bSKacheong Poon opts[1] != TCPOPT_MAXSEG_LEN) {
1057*0870f17bSKacheong Poon mdb_printf(" <Truncated MSS>\n");
1058*0870f17bSKacheong Poon return;
1059*0870f17bSKacheong Poon }
1060*0870f17bSKacheong Poon mdb_nhconvert(&mss, opts + TCPOPT_HEADER_LEN,
1061*0870f17bSKacheong Poon sizeof (mss));
1062*0870f17bSKacheong Poon mdb_printf(" MSS=%u", mss);
1063*0870f17bSKacheong Poon opts += TCPOPT_MAXSEG_LEN;
1064*0870f17bSKacheong Poon break;
1065*0870f17bSKacheong Poon }
1066*0870f17bSKacheong Poon
1067*0870f17bSKacheong Poon case TCPOPT_WSCALE:
1068*0870f17bSKacheong Poon if (len < TCPOPT_WS_LEN || opts[1] != TCPOPT_WS_LEN) {
1069*0870f17bSKacheong Poon mdb_printf(" <Truncated WS>\n");
1070*0870f17bSKacheong Poon return;
1071*0870f17bSKacheong Poon }
1072*0870f17bSKacheong Poon mdb_printf(" WS=%u", opts[2]);
1073*0870f17bSKacheong Poon opts += TCPOPT_WS_LEN;
1074*0870f17bSKacheong Poon break;
1075*0870f17bSKacheong Poon
1076*0870f17bSKacheong Poon case TCPOPT_TSTAMP: {
1077*0870f17bSKacheong Poon if (len < TCPOPT_TSTAMP_LEN ||
1078*0870f17bSKacheong Poon opts[1] != TCPOPT_TSTAMP_LEN) {
1079*0870f17bSKacheong Poon mdb_printf(" <Truncated TS>\n");
1080*0870f17bSKacheong Poon return;
1081*0870f17bSKacheong Poon }
1082*0870f17bSKacheong Poon
1083*0870f17bSKacheong Poon opts += TCPOPT_HEADER_LEN;
1084*0870f17bSKacheong Poon mdb_nhconvert(&val, opts, sizeof (val));
1085*0870f17bSKacheong Poon mdb_printf(" TS_VAL=%u,", val);
1086*0870f17bSKacheong Poon
1087*0870f17bSKacheong Poon opts += sizeof (val);
1088*0870f17bSKacheong Poon mdb_nhconvert(&val, opts, sizeof (val));
1089*0870f17bSKacheong Poon mdb_printf("TS_ECHO=%u", val);
1090*0870f17bSKacheong Poon
1091*0870f17bSKacheong Poon opts += sizeof (val);
1092*0870f17bSKacheong Poon break;
1093*0870f17bSKacheong Poon }
1094*0870f17bSKacheong Poon
1095*0870f17bSKacheong Poon case TCPOPT_SACK_PERMITTED:
1096*0870f17bSKacheong Poon if (len < TCPOPT_SACK_OK_LEN ||
1097*0870f17bSKacheong Poon opts[1] != TCPOPT_SACK_OK_LEN) {
1098*0870f17bSKacheong Poon mdb_printf(" <Truncated SACK_OK>\n");
1099*0870f17bSKacheong Poon return;
1100*0870f17bSKacheong Poon }
1101*0870f17bSKacheong Poon mdb_printf(" SACK_OK");
1102*0870f17bSKacheong Poon opts += TCPOPT_SACK_OK_LEN;
1103*0870f17bSKacheong Poon break;
1104*0870f17bSKacheong Poon
1105*0870f17bSKacheong Poon case TCPOPT_SACK: {
1106*0870f17bSKacheong Poon uint32_t sack_len;
1107*0870f17bSKacheong Poon
1108*0870f17bSKacheong Poon if (len <= TCPOPT_HEADER_LEN || len < opts[1] ||
1109*0870f17bSKacheong Poon opts[1] <= TCPOPT_HEADER_LEN) {
1110*0870f17bSKacheong Poon mdb_printf(" <Truncated SACK>\n");
1111*0870f17bSKacheong Poon return;
1112*0870f17bSKacheong Poon }
1113*0870f17bSKacheong Poon sack_len = opts[1] - TCPOPT_HEADER_LEN;
1114*0870f17bSKacheong Poon opts += TCPOPT_HEADER_LEN;
1115*0870f17bSKacheong Poon
1116*0870f17bSKacheong Poon mdb_printf(" SACK=");
1117*0870f17bSKacheong Poon while (sack_len > 0) {
1118*0870f17bSKacheong Poon if (opts + 2 * sizeof (val) > endp) {
1119*0870f17bSKacheong Poon mdb_printf("<Truncated SACK>\n");
1120*0870f17bSKacheong Poon opts = endp;
1121*0870f17bSKacheong Poon break;
1122*0870f17bSKacheong Poon }
1123*0870f17bSKacheong Poon
1124*0870f17bSKacheong Poon mdb_nhconvert(&val, opts, sizeof (val));
1125*0870f17bSKacheong Poon mdb_printf("<%u,", val);
1126*0870f17bSKacheong Poon opts += sizeof (val);
1127*0870f17bSKacheong Poon mdb_nhconvert(&val, opts, sizeof (val));
1128*0870f17bSKacheong Poon mdb_printf("%u>", val);
1129*0870f17bSKacheong Poon opts += sizeof (val);
1130*0870f17bSKacheong Poon
1131*0870f17bSKacheong Poon sack_len -= 2 * sizeof (val);
1132*0870f17bSKacheong Poon }
1133*0870f17bSKacheong Poon break;
1134*0870f17bSKacheong Poon }
1135*0870f17bSKacheong Poon
1136*0870f17bSKacheong Poon default:
1137*0870f17bSKacheong Poon mdb_printf(" Opts=<val=%u,len=%u>", *opts,
1138*0870f17bSKacheong Poon opts[1]);
1139*0870f17bSKacheong Poon opts += opts[1];
1140*0870f17bSKacheong Poon break;
1141*0870f17bSKacheong Poon }
1142*0870f17bSKacheong Poon }
1143*0870f17bSKacheong Poon mdb_printf("\n");
1144*0870f17bSKacheong Poon }
1145*0870f17bSKacheong Poon
11467c478bd9Sstevel@tonic-gate static void
tcphdr_print(struct tcphdr * tcph)11477c478bd9Sstevel@tonic-gate tcphdr_print(struct tcphdr *tcph)
11487c478bd9Sstevel@tonic-gate {
11497c478bd9Sstevel@tonic-gate in_port_t sport, dport;
11507c478bd9Sstevel@tonic-gate tcp_seq seq, ack;
11517c478bd9Sstevel@tonic-gate uint16_t win, urp;
11527c478bd9Sstevel@tonic-gate
11537c478bd9Sstevel@tonic-gate mdb_printf("%<b>TCP header%</b>\n");
11547c478bd9Sstevel@tonic-gate
11557c478bd9Sstevel@tonic-gate mdb_nhconvert(&sport, &tcph->th_sport, sizeof (sport));
11567c478bd9Sstevel@tonic-gate mdb_nhconvert(&dport, &tcph->th_dport, sizeof (dport));
11577c478bd9Sstevel@tonic-gate mdb_nhconvert(&seq, &tcph->th_seq, sizeof (seq));
11587c478bd9Sstevel@tonic-gate mdb_nhconvert(&ack, &tcph->th_ack, sizeof (ack));
11597c478bd9Sstevel@tonic-gate mdb_nhconvert(&win, &tcph->th_win, sizeof (win));
11607c478bd9Sstevel@tonic-gate mdb_nhconvert(&urp, &tcph->th_urp, sizeof (urp));
11617c478bd9Sstevel@tonic-gate
11627c478bd9Sstevel@tonic-gate mdb_printf("%<u>%6s %6s %10s %10s %4s %5s %5s %5s %-15s%</u>\n",
11637c478bd9Sstevel@tonic-gate "SPORT", "DPORT", "SEQ", "ACK", "HLEN", "WIN", "CSUM", "URP",
11647c478bd9Sstevel@tonic-gate "FLAGS");
11657c478bd9Sstevel@tonic-gate mdb_printf("%6hu %6hu %10u %10u %4d %5hu %5hu %5hu <%b>\n",
11667c478bd9Sstevel@tonic-gate sport, dport, seq, ack, tcph->th_off << 2, win,
11677c478bd9Sstevel@tonic-gate tcph->th_sum, urp, tcph->th_flags, tcp_flags);
11687c478bd9Sstevel@tonic-gate mdb_printf("0x%04x 0x%04x 0x%08x 0x%08x\n\n",
11697c478bd9Sstevel@tonic-gate sport, dport, seq, ack);
11707c478bd9Sstevel@tonic-gate }
11717c478bd9Sstevel@tonic-gate
11727c478bd9Sstevel@tonic-gate /* ARGSUSED */
11737c478bd9Sstevel@tonic-gate static int
tcphdr(uintptr_t addr,uint_t flags,int ac,const mdb_arg_t * av)11747c478bd9Sstevel@tonic-gate tcphdr(uintptr_t addr, uint_t flags, int ac, const mdb_arg_t *av)
11757c478bd9Sstevel@tonic-gate {
11767c478bd9Sstevel@tonic-gate struct tcphdr tcph;
1177*0870f17bSKacheong Poon uint32_t opt_len;
11787c478bd9Sstevel@tonic-gate
11797c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC))
11807c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
11817c478bd9Sstevel@tonic-gate
11827c478bd9Sstevel@tonic-gate if (mdb_vread(&tcph, sizeof (tcph), addr) == -1) {
11837c478bd9Sstevel@tonic-gate mdb_warn("failed to read TCP header at %p", addr);
11847c478bd9Sstevel@tonic-gate return (DCMD_ERR);
11857c478bd9Sstevel@tonic-gate }
11867c478bd9Sstevel@tonic-gate tcphdr_print(&tcph);
1187*0870f17bSKacheong Poon
1188*0870f17bSKacheong Poon /* If there are options, print them out also. */
1189*0870f17bSKacheong Poon opt_len = (tcph.th_off << 2) - TCP_MIN_HEADER_LENGTH;
1190*0870f17bSKacheong Poon if (opt_len > 0) {
1191*0870f17bSKacheong Poon uint8_t *opts, *opt_buf;
1192*0870f17bSKacheong Poon
1193*0870f17bSKacheong Poon opt_buf = mdb_alloc(opt_len, UM_SLEEP);
1194*0870f17bSKacheong Poon opts = (uint8_t *)addr + sizeof (tcph);
1195*0870f17bSKacheong Poon if (mdb_vread(opt_buf, opt_len, (uintptr_t)opts) == -1) {
1196*0870f17bSKacheong Poon mdb_warn("failed to read TCP options at %p", opts);
1197*0870f17bSKacheong Poon return (DCMD_ERR);
1198*0870f17bSKacheong Poon }
1199*0870f17bSKacheong Poon tcphdr_print_options(opt_buf, opt_len);
1200*0870f17bSKacheong Poon mdb_free(opt_buf, opt_len);
1201*0870f17bSKacheong Poon }
1202*0870f17bSKacheong Poon
12037c478bd9Sstevel@tonic-gate return (DCMD_OK);
12047c478bd9Sstevel@tonic-gate }
12057c478bd9Sstevel@tonic-gate
12067c478bd9Sstevel@tonic-gate static void
udphdr_print(struct udphdr * udph)12077c478bd9Sstevel@tonic-gate udphdr_print(struct udphdr *udph)
12087c478bd9Sstevel@tonic-gate {
12097c478bd9Sstevel@tonic-gate in_port_t sport, dport;
12107c478bd9Sstevel@tonic-gate uint16_t hlen;
12117c478bd9Sstevel@tonic-gate
12127c478bd9Sstevel@tonic-gate mdb_printf("%<b>UDP header%</b>\n");
12137c478bd9Sstevel@tonic-gate
12147c478bd9Sstevel@tonic-gate mdb_nhconvert(&sport, &udph->uh_sport, sizeof (sport));
12157c478bd9Sstevel@tonic-gate mdb_nhconvert(&dport, &udph->uh_dport, sizeof (dport));
12167c478bd9Sstevel@tonic-gate mdb_nhconvert(&hlen, &udph->uh_ulen, sizeof (hlen));
12177c478bd9Sstevel@tonic-gate
12187c478bd9Sstevel@tonic-gate mdb_printf("%<u>%14s %14s %5s %6s%</u>\n",
12197c478bd9Sstevel@tonic-gate "SPORT", "DPORT", "LEN", "CSUM");
12207c478bd9Sstevel@tonic-gate mdb_printf("%5hu (0x%04x) %5hu (0x%04x) %5hu 0x%04hx\n\n", sport, sport,
12217c478bd9Sstevel@tonic-gate dport, dport, hlen, udph->uh_sum);
12227c478bd9Sstevel@tonic-gate }
12237c478bd9Sstevel@tonic-gate
12247c478bd9Sstevel@tonic-gate /* ARGSUSED */
12257c478bd9Sstevel@tonic-gate static int
udphdr(uintptr_t addr,uint_t flags,int ac,const mdb_arg_t * av)12267c478bd9Sstevel@tonic-gate udphdr(uintptr_t addr, uint_t flags, int ac, const mdb_arg_t *av)
12277c478bd9Sstevel@tonic-gate {
12287c478bd9Sstevel@tonic-gate struct udphdr udph;
12297c478bd9Sstevel@tonic-gate
12307c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC))
12317c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
12327c478bd9Sstevel@tonic-gate
12337c478bd9Sstevel@tonic-gate if (mdb_vread(&udph, sizeof (udph), addr) == -1) {
12347c478bd9Sstevel@tonic-gate mdb_warn("failed to read UDP header at %p", addr);
12357c478bd9Sstevel@tonic-gate return (DCMD_ERR);
12367c478bd9Sstevel@tonic-gate }
12377c478bd9Sstevel@tonic-gate udphdr_print(&udph);
12387c478bd9Sstevel@tonic-gate return (DCMD_OK);
12397c478bd9Sstevel@tonic-gate }
12407c478bd9Sstevel@tonic-gate
12417c478bd9Sstevel@tonic-gate static void
sctphdr_print(sctp_hdr_t * sctph)12427c478bd9Sstevel@tonic-gate sctphdr_print(sctp_hdr_t *sctph)
12437c478bd9Sstevel@tonic-gate {
12447c478bd9Sstevel@tonic-gate in_port_t sport, dport;
12457c478bd9Sstevel@tonic-gate
12467c478bd9Sstevel@tonic-gate mdb_printf("%<b>SCTP header%</b>\n");
12477c478bd9Sstevel@tonic-gate mdb_nhconvert(&sport, &sctph->sh_sport, sizeof (sport));
12487c478bd9Sstevel@tonic-gate mdb_nhconvert(&dport, &sctph->sh_dport, sizeof (dport));
12497c478bd9Sstevel@tonic-gate
12507c478bd9Sstevel@tonic-gate mdb_printf("%<u>%14s %14s %10s %10s%</u>\n",
12517c478bd9Sstevel@tonic-gate "SPORT", "DPORT", "VTAG", "CHKSUM");
12527c478bd9Sstevel@tonic-gate mdb_printf("%5hu (0x%04x) %5hu (0x%04x) %10u 0x%08x\n\n", sport, sport,
12537c478bd9Sstevel@tonic-gate dport, dport, sctph->sh_verf, sctph->sh_chksum);
12547c478bd9Sstevel@tonic-gate }
12557c478bd9Sstevel@tonic-gate
12567c478bd9Sstevel@tonic-gate /* ARGSUSED */
12577c478bd9Sstevel@tonic-gate static int
sctphdr(uintptr_t addr,uint_t flags,int ac,const mdb_arg_t * av)12587c478bd9Sstevel@tonic-gate sctphdr(uintptr_t addr, uint_t flags, int ac, const mdb_arg_t *av)
12597c478bd9Sstevel@tonic-gate {
12607c478bd9Sstevel@tonic-gate sctp_hdr_t sctph;
12617c478bd9Sstevel@tonic-gate
12627c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC))
12637c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
12647c478bd9Sstevel@tonic-gate
12657c478bd9Sstevel@tonic-gate if (mdb_vread(&sctph, sizeof (sctph), addr) == -1) {
12667c478bd9Sstevel@tonic-gate mdb_warn("failed to read SCTP header at %p", addr);
12677c478bd9Sstevel@tonic-gate return (DCMD_ERR);
12687c478bd9Sstevel@tonic-gate }
12697c478bd9Sstevel@tonic-gate
12707c478bd9Sstevel@tonic-gate sctphdr_print(&sctph);
12717c478bd9Sstevel@tonic-gate return (DCMD_OK);
12727c478bd9Sstevel@tonic-gate }
12737c478bd9Sstevel@tonic-gate
12747c478bd9Sstevel@tonic-gate static int
transport_hdr(int proto,uintptr_t addr)12757c478bd9Sstevel@tonic-gate transport_hdr(int proto, uintptr_t addr)
12767c478bd9Sstevel@tonic-gate {
12777c478bd9Sstevel@tonic-gate mdb_printf("\n");
12787c478bd9Sstevel@tonic-gate switch (proto) {
12797c478bd9Sstevel@tonic-gate case IPPROTO_TCP: {
12807c478bd9Sstevel@tonic-gate struct tcphdr tcph;
12817c478bd9Sstevel@tonic-gate
12827c478bd9Sstevel@tonic-gate if (mdb_vread(&tcph, sizeof (tcph), addr) == -1) {
12837c478bd9Sstevel@tonic-gate mdb_warn("failed to read TCP header at %p", addr);
12847c478bd9Sstevel@tonic-gate return (DCMD_ERR);
12857c478bd9Sstevel@tonic-gate }
12867c478bd9Sstevel@tonic-gate tcphdr_print(&tcph);
12877c478bd9Sstevel@tonic-gate break;
12887c478bd9Sstevel@tonic-gate }
12897c478bd9Sstevel@tonic-gate case IPPROTO_UDP: {
12907c478bd9Sstevel@tonic-gate struct udphdr udph;
12917c478bd9Sstevel@tonic-gate
12927c478bd9Sstevel@tonic-gate if (mdb_vread(&udph, sizeof (udph), addr) == -1) {
12937c478bd9Sstevel@tonic-gate mdb_warn("failed to read UDP header at %p", addr);
12947c478bd9Sstevel@tonic-gate return (DCMD_ERR);
12957c478bd9Sstevel@tonic-gate }
12967c478bd9Sstevel@tonic-gate udphdr_print(&udph);
12977c478bd9Sstevel@tonic-gate break;
12987c478bd9Sstevel@tonic-gate }
12997c478bd9Sstevel@tonic-gate case IPPROTO_SCTP: {
13007c478bd9Sstevel@tonic-gate sctp_hdr_t sctph;
13017c478bd9Sstevel@tonic-gate
13027c478bd9Sstevel@tonic-gate if (mdb_vread(&sctph, sizeof (sctph), addr) == -1) {
13037c478bd9Sstevel@tonic-gate mdb_warn("failed to read SCTP header at %p", addr);
13047c478bd9Sstevel@tonic-gate return (DCMD_ERR);
13057c478bd9Sstevel@tonic-gate }
13067c478bd9Sstevel@tonic-gate sctphdr_print(&sctph);
13077c478bd9Sstevel@tonic-gate break;
13087c478bd9Sstevel@tonic-gate }
13097c478bd9Sstevel@tonic-gate default:
13107c478bd9Sstevel@tonic-gate break;
13117c478bd9Sstevel@tonic-gate }
13127c478bd9Sstevel@tonic-gate
13137c478bd9Sstevel@tonic-gate return (DCMD_OK);
13147c478bd9Sstevel@tonic-gate }
13157c478bd9Sstevel@tonic-gate
13167c478bd9Sstevel@tonic-gate static const mdb_bitmask_t ip_flags[] = {
13177c478bd9Sstevel@tonic-gate { "DF", IPH_DF, IPH_DF },
13187c478bd9Sstevel@tonic-gate { "MF", IPH_MF, IPH_MF },
13197c478bd9Sstevel@tonic-gate { NULL, 0, 0 }
13207c478bd9Sstevel@tonic-gate };
13217c478bd9Sstevel@tonic-gate
13227c478bd9Sstevel@tonic-gate /* ARGSUSED */
13237c478bd9Sstevel@tonic-gate static int
iphdr(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)13247c478bd9Sstevel@tonic-gate iphdr(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
13257c478bd9Sstevel@tonic-gate {
13267c478bd9Sstevel@tonic-gate uint_t verbose = FALSE, force = FALSE;
13277c478bd9Sstevel@tonic-gate ipha_t iph[1];
13287c478bd9Sstevel@tonic-gate uint16_t ver, totlen, hdrlen, ipid, off, csum;
13297c478bd9Sstevel@tonic-gate uintptr_t nxt_proto;
13307c478bd9Sstevel@tonic-gate char exp_csum[8];
13317c478bd9Sstevel@tonic-gate
13327c478bd9Sstevel@tonic-gate if (mdb_getopts(argc, argv,
13337c478bd9Sstevel@tonic-gate 'v', MDB_OPT_SETBITS, TRUE, &verbose,
13347c478bd9Sstevel@tonic-gate 'f', MDB_OPT_SETBITS, TRUE, &force, NULL) != argc)
13357c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
13367c478bd9Sstevel@tonic-gate
13377c478bd9Sstevel@tonic-gate if (mdb_vread(iph, sizeof (*iph), addr) == -1) {
13387c478bd9Sstevel@tonic-gate mdb_warn("failed to read IPv4 header at %p", addr);
13397c478bd9Sstevel@tonic-gate return (DCMD_ERR);
13407c478bd9Sstevel@tonic-gate }
13417c478bd9Sstevel@tonic-gate
13427c478bd9Sstevel@tonic-gate ver = (iph->ipha_version_and_hdr_length & 0xf0) >> 4;
13437c478bd9Sstevel@tonic-gate if (ver != IPV4_VERSION) {
13447c478bd9Sstevel@tonic-gate if (ver == IPV6_VERSION) {
13457c478bd9Sstevel@tonic-gate return (ip6hdr(addr, flags, argc, argv));
13467c478bd9Sstevel@tonic-gate } else if (!force) {
13477c478bd9Sstevel@tonic-gate mdb_warn("unknown IP version: %d\n", ver);
13487c478bd9Sstevel@tonic-gate return (DCMD_ERR);
13497c478bd9Sstevel@tonic-gate }
13507c478bd9Sstevel@tonic-gate }
13517c478bd9Sstevel@tonic-gate
13527c478bd9Sstevel@tonic-gate mdb_printf("%<b>IPv4 header%</b>\n");
13537c478bd9Sstevel@tonic-gate mdb_printf("%-34s %-34s\n"
13547c478bd9Sstevel@tonic-gate "%<u>%-4s %-4s %-5s %-5s %-6s %-5s %-5s %-6s %-8s %-6s%</u>\n",
13557c478bd9Sstevel@tonic-gate "SRC", "DST",
13567c478bd9Sstevel@tonic-gate "HLEN", "TOS", "LEN", "ID", "OFFSET", "TTL", "PROTO", "CHKSUM",
13577c478bd9Sstevel@tonic-gate "EXP-CSUM", "FLGS");
13587c478bd9Sstevel@tonic-gate
13597c478bd9Sstevel@tonic-gate hdrlen = (iph->ipha_version_and_hdr_length & 0x0f) << 2;
13607c478bd9Sstevel@tonic-gate mdb_nhconvert(&totlen, &iph->ipha_length, sizeof (totlen));
13617c478bd9Sstevel@tonic-gate mdb_nhconvert(&ipid, &iph->ipha_ident, sizeof (ipid));
13627c478bd9Sstevel@tonic-gate mdb_nhconvert(&off, &iph->ipha_fragment_offset_and_flags, sizeof (off));
13637c478bd9Sstevel@tonic-gate if (hdrlen == IP_SIMPLE_HDR_LENGTH) {
13647c478bd9Sstevel@tonic-gate if ((csum = ipcksum(iph, sizeof (*iph))) != 0)
13657c478bd9Sstevel@tonic-gate csum = ~(~csum + ~iph->ipha_hdr_checksum);
13667c478bd9Sstevel@tonic-gate else
13677c478bd9Sstevel@tonic-gate csum = iph->ipha_hdr_checksum;
13687c478bd9Sstevel@tonic-gate mdb_snprintf(exp_csum, 8, "%u", csum);
13697c478bd9Sstevel@tonic-gate } else {
13707c478bd9Sstevel@tonic-gate mdb_snprintf(exp_csum, 8, "<n/a>");
13717c478bd9Sstevel@tonic-gate }
13727c478bd9Sstevel@tonic-gate
13737c478bd9Sstevel@tonic-gate mdb_printf("%-34I %-34I%\n"
13747c478bd9Sstevel@tonic-gate "%-4d %-4d %-5hu %-5hu %-6hu %-5hu %-5hu %-6u %-8s <%5hb>\n",
13757c478bd9Sstevel@tonic-gate iph->ipha_src, iph->ipha_dst,
13767c478bd9Sstevel@tonic-gate hdrlen, iph->ipha_type_of_service, totlen, ipid,
13777c478bd9Sstevel@tonic-gate (off << 3) & 0xffff, iph->ipha_ttl, iph->ipha_protocol,
13787c478bd9Sstevel@tonic-gate iph->ipha_hdr_checksum, exp_csum, off, ip_flags);
13797c478bd9Sstevel@tonic-gate
13807c478bd9Sstevel@tonic-gate if (verbose) {
13817c478bd9Sstevel@tonic-gate nxt_proto = addr + hdrlen;
13827c478bd9Sstevel@tonic-gate return (transport_hdr(iph->ipha_protocol, nxt_proto));
13837c478bd9Sstevel@tonic-gate } else {
13847c478bd9Sstevel@tonic-gate return (DCMD_OK);
13857c478bd9Sstevel@tonic-gate }
13867c478bd9Sstevel@tonic-gate }
13877c478bd9Sstevel@tonic-gate
13887c478bd9Sstevel@tonic-gate /* ARGSUSED */
13897c478bd9Sstevel@tonic-gate static int
ip6hdr(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)13907c478bd9Sstevel@tonic-gate ip6hdr(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
13917c478bd9Sstevel@tonic-gate {
13927c478bd9Sstevel@tonic-gate uint_t verbose = FALSE, force = FALSE;
13937c478bd9Sstevel@tonic-gate ip6_t iph[1];
13947c478bd9Sstevel@tonic-gate int ver, class, flow;
13957c478bd9Sstevel@tonic-gate uint16_t plen;
13967c478bd9Sstevel@tonic-gate uintptr_t nxt_proto;
13977c478bd9Sstevel@tonic-gate
13987c478bd9Sstevel@tonic-gate if (mdb_getopts(argc, argv,
13997c478bd9Sstevel@tonic-gate 'v', MDB_OPT_SETBITS, TRUE, &verbose,
14007c478bd9Sstevel@tonic-gate 'f', MDB_OPT_SETBITS, TRUE, &force, NULL) != argc)
14017c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
14027c478bd9Sstevel@tonic-gate
14037c478bd9Sstevel@tonic-gate if (mdb_vread(iph, sizeof (*iph), addr) == -1) {
14047c478bd9Sstevel@tonic-gate mdb_warn("failed to read IPv6 header at %p", addr);
14057c478bd9Sstevel@tonic-gate return (DCMD_ERR);
14067c478bd9Sstevel@tonic-gate }
14077c478bd9Sstevel@tonic-gate
14087c478bd9Sstevel@tonic-gate ver = (iph->ip6_vfc & 0xf0) >> 4;
14097c478bd9Sstevel@tonic-gate if (ver != IPV6_VERSION) {
14107c478bd9Sstevel@tonic-gate if (ver == IPV4_VERSION) {
14117c478bd9Sstevel@tonic-gate return (iphdr(addr, flags, argc, argv));
14127c478bd9Sstevel@tonic-gate } else if (!force) {
14137c478bd9Sstevel@tonic-gate mdb_warn("unknown IP version: %d\n", ver);
14147c478bd9Sstevel@tonic-gate return (DCMD_ERR);
14157c478bd9Sstevel@tonic-gate }
14167c478bd9Sstevel@tonic-gate }
14177c478bd9Sstevel@tonic-gate
14187c478bd9Sstevel@tonic-gate mdb_printf("%<b>IPv6 header%</b>\n");
14197c478bd9Sstevel@tonic-gate mdb_printf("%<u>%-26s %-26s %4s %7s %5s %3s %3s%</u>\n",
14207c478bd9Sstevel@tonic-gate "SRC", "DST", "TCLS", "FLOW-ID", "PLEN", "NXT", "HOP");
14217c478bd9Sstevel@tonic-gate
14227c478bd9Sstevel@tonic-gate class = (iph->ip6_vcf & IPV6_FLOWINFO_TCLASS) >> 20;
14237c478bd9Sstevel@tonic-gate mdb_nhconvert(&class, &class, sizeof (class));
14247c478bd9Sstevel@tonic-gate flow = iph->ip6_vcf & IPV6_FLOWINFO_FLOWLABEL;
14257c478bd9Sstevel@tonic-gate mdb_nhconvert(&flow, &flow, sizeof (flow));
14267c478bd9Sstevel@tonic-gate mdb_nhconvert(&plen, &iph->ip6_plen, sizeof (plen));
14277c478bd9Sstevel@tonic-gate
14287c478bd9Sstevel@tonic-gate mdb_printf("%-26N %-26N %4d %7d %5hu %3d %3d\n",
14297c478bd9Sstevel@tonic-gate &iph->ip6_src, &iph->ip6_dst,
14307c478bd9Sstevel@tonic-gate class, flow, plen, iph->ip6_nxt, iph->ip6_hlim);
14317c478bd9Sstevel@tonic-gate
14327c478bd9Sstevel@tonic-gate if (verbose) {
14337c478bd9Sstevel@tonic-gate nxt_proto = addr + sizeof (ip6_t);
14347c478bd9Sstevel@tonic-gate return (transport_hdr(iph->ip6_nxt, nxt_proto));
14357c478bd9Sstevel@tonic-gate } else {
14367c478bd9Sstevel@tonic-gate return (DCMD_OK);
14377c478bd9Sstevel@tonic-gate }
14387c478bd9Sstevel@tonic-gate }
14397c478bd9Sstevel@tonic-gate
14407c478bd9Sstevel@tonic-gate int
nce(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1441bd670b35SErik Nordmark nce(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1442bd670b35SErik Nordmark {
1443bd670b35SErik Nordmark nce_t nce;
1444bd670b35SErik Nordmark nce_cbdata_t nce_cb;
1445bd670b35SErik Nordmark int ipversion = 0;
1446bd670b35SErik Nordmark const char *opt_P = NULL, *opt_ill;
1447bd670b35SErik Nordmark
1448bd670b35SErik Nordmark if (mdb_getopts(argc, argv,
1449bd670b35SErik Nordmark 'i', MDB_OPT_STR, &opt_ill,
1450bd670b35SErik Nordmark 'P', MDB_OPT_STR, &opt_P, NULL) != argc)
1451bd670b35SErik Nordmark return (DCMD_USAGE);
1452bd670b35SErik Nordmark
1453bd670b35SErik Nordmark if (opt_P != NULL) {
1454bd670b35SErik Nordmark if (strcmp("v4", opt_P) == 0) {
1455bd670b35SErik Nordmark ipversion = IPV4_VERSION;
1456bd670b35SErik Nordmark } else if (strcmp("v6", opt_P) == 0) {
1457bd670b35SErik Nordmark ipversion = IPV6_VERSION;
1458bd670b35SErik Nordmark } else {
1459bd670b35SErik Nordmark mdb_warn("invalid protocol '%s'\n", opt_P);
1460bd670b35SErik Nordmark return (DCMD_USAGE);
1461bd670b35SErik Nordmark }
1462bd670b35SErik Nordmark }
1463bd670b35SErik Nordmark
1464bd670b35SErik Nordmark if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) {
1465bd670b35SErik Nordmark mdb_printf("%<u>%?s %5s %18s %?s %s %s %</u>\n",
1466bd670b35SErik Nordmark "ADDR", "INTF", "LLADDR", "FP_MP", "REFCNT",
1467bd670b35SErik Nordmark "NCE_ADDR");
1468bd670b35SErik Nordmark }
1469bd670b35SErik Nordmark
1470bd670b35SErik Nordmark bzero(&nce_cb, sizeof (nce_cb));
1471bd670b35SErik Nordmark if (opt_ill != NULL) {
1472bd670b35SErik Nordmark strcpy(nce_cb.nce_ill_name, opt_ill);
1473bd670b35SErik Nordmark }
1474bd670b35SErik Nordmark nce_cb.nce_ipversion = ipversion;
1475bd670b35SErik Nordmark
1476bd670b35SErik Nordmark if (flags & DCMD_ADDRSPEC) {
1477bd670b35SErik Nordmark (void) mdb_vread(&nce, sizeof (nce_t), addr);
1478bd670b35SErik Nordmark (void) nce_format(addr, &nce, &nce_cb);
1479bd670b35SErik Nordmark } else if (mdb_walk("nce", (mdb_walk_cb_t)nce_format, &nce_cb) == -1) {
1480bd670b35SErik Nordmark mdb_warn("failed to walk ire table");
1481bd670b35SErik Nordmark return (DCMD_ERR);
1482bd670b35SErik Nordmark }
1483bd670b35SErik Nordmark
1484bd670b35SErik Nordmark return (DCMD_OK);
1485bd670b35SErik Nordmark }
1486bd670b35SErik Nordmark
1487bd670b35SErik Nordmark /* ARGSUSED */
1488bd670b35SErik Nordmark static int
dce_format(uintptr_t addr,const dce_t * dcep,void * dce_cb_arg)1489bd670b35SErik Nordmark dce_format(uintptr_t addr, const dce_t *dcep, void *dce_cb_arg)
1490bd670b35SErik Nordmark {
1491bd670b35SErik Nordmark static const mdb_bitmask_t dmasks[] = {
1492bd670b35SErik Nordmark { "D", DCEF_DEFAULT, DCEF_DEFAULT },
1493bd670b35SErik Nordmark { "P", DCEF_PMTU, DCEF_PMTU },
1494bd670b35SErik Nordmark { "U", DCEF_UINFO, DCEF_UINFO },
1495bd670b35SErik Nordmark { "S", DCEF_TOO_SMALL_PMTU, DCEF_TOO_SMALL_PMTU },
1496bd670b35SErik Nordmark { NULL, 0, 0 }
1497bd670b35SErik Nordmark };
1498bd670b35SErik Nordmark char flagsbuf[2 * A_CNT(dmasks)];
1499bd670b35SErik Nordmark int ipversion = *(int *)dce_cb_arg;
1500bd670b35SErik Nordmark boolean_t condemned = dcep->dce_generation == DCE_GENERATION_CONDEMNED;
1501bd670b35SErik Nordmark
1502bd670b35SErik Nordmark if (ipversion != 0 && ipversion != dcep->dce_ipversion)
1503bd670b35SErik Nordmark return (WALK_NEXT);
1504bd670b35SErik Nordmark
1505bd670b35SErik Nordmark mdb_snprintf(flagsbuf, sizeof (flagsbuf), "%b", dcep->dce_flags,
1506bd670b35SErik Nordmark dmasks);
1507bd670b35SErik Nordmark
1508bd670b35SErik Nordmark switch (dcep->dce_ipversion) {
1509bd670b35SErik Nordmark case IPV4_VERSION:
1510bd670b35SErik Nordmark mdb_printf("%<u>%?p%3s %8s %8d %30I %</u>\n", addr, condemned ?
1511bd670b35SErik Nordmark "(C)" : "", flagsbuf, dcep->dce_pmtu, &dcep->dce_v4addr);
1512bd670b35SErik Nordmark break;
1513bd670b35SErik Nordmark case IPV6_VERSION:
1514bd670b35SErik Nordmark mdb_printf("%<u>%?p%3s %8s %8d %30N %</u>\n", addr, condemned ?
1515bd670b35SErik Nordmark "(C)" : "", flagsbuf, dcep->dce_pmtu, &dcep->dce_v6addr);
1516bd670b35SErik Nordmark break;
1517bd670b35SErik Nordmark default:
1518bd670b35SErik Nordmark mdb_printf("%<u>%?p%3s %8s %8d %30s %</u>\n", addr, condemned ?
1519bd670b35SErik Nordmark "(C)" : "", flagsbuf, dcep->dce_pmtu, "");
1520bd670b35SErik Nordmark }
1521bd670b35SErik Nordmark
1522bd670b35SErik Nordmark return (WALK_NEXT);
1523bd670b35SErik Nordmark }
1524bd670b35SErik Nordmark
1525bd670b35SErik Nordmark int
dce(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1526bd670b35SErik Nordmark dce(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1527bd670b35SErik Nordmark {
1528bd670b35SErik Nordmark dce_t dce;
1529bd670b35SErik Nordmark const char *opt_P = NULL;
1530bd670b35SErik Nordmark const char *zone_name = NULL;
1531bd670b35SErik Nordmark ip_stack_t *ipst = NULL;
1532bd670b35SErik Nordmark int ipversion = 0;
1533bd670b35SErik Nordmark
1534bd670b35SErik Nordmark if (mdb_getopts(argc, argv,
1535bd670b35SErik Nordmark 's', MDB_OPT_STR, &zone_name,
1536bd670b35SErik Nordmark 'P', MDB_OPT_STR, &opt_P, NULL) != argc)
1537bd670b35SErik Nordmark return (DCMD_USAGE);
1538bd670b35SErik Nordmark
1539bd670b35SErik Nordmark /* Follow the specified zone name to find a ip_stack_t*. */
1540bd670b35SErik Nordmark if (zone_name != NULL) {
1541bd670b35SErik Nordmark ipst = zone_to_ips(zone_name);
1542bd670b35SErik Nordmark if (ipst == NULL)
1543bd670b35SErik Nordmark return (DCMD_USAGE);
1544bd670b35SErik Nordmark }
1545bd670b35SErik Nordmark
1546bd670b35SErik Nordmark if (opt_P != NULL) {
1547bd670b35SErik Nordmark if (strcmp("v4", opt_P) == 0) {
1548bd670b35SErik Nordmark ipversion = IPV4_VERSION;
1549bd670b35SErik Nordmark } else if (strcmp("v6", opt_P) == 0) {
1550bd670b35SErik Nordmark ipversion = IPV6_VERSION;
1551bd670b35SErik Nordmark } else {
1552bd670b35SErik Nordmark mdb_warn("invalid protocol '%s'\n", opt_P);
1553bd670b35SErik Nordmark return (DCMD_USAGE);
1554bd670b35SErik Nordmark }
1555bd670b35SErik Nordmark }
1556bd670b35SErik Nordmark
1557bd670b35SErik Nordmark if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) {
1558bd670b35SErik Nordmark mdb_printf("%<u>%?s%3s %8s %8s %30s %</u>\n",
1559bd670b35SErik Nordmark "ADDR", "", "FLAGS", "PMTU", "DST_ADDR");
1560bd670b35SErik Nordmark }
1561bd670b35SErik Nordmark
1562bd670b35SErik Nordmark if (flags & DCMD_ADDRSPEC) {
1563bd670b35SErik Nordmark (void) mdb_vread(&dce, sizeof (dce_t), addr);
1564bd670b35SErik Nordmark (void) dce_format(addr, &dce, &ipversion);
1565bd670b35SErik Nordmark } else if (mdb_pwalk("dce", (mdb_walk_cb_t)dce_format, &ipversion,
1566bd670b35SErik Nordmark (uintptr_t)ipst) == -1) {
1567bd670b35SErik Nordmark mdb_warn("failed to walk dce cache");
1568bd670b35SErik Nordmark return (DCMD_ERR);
1569bd670b35SErik Nordmark }
1570bd670b35SErik Nordmark
1571bd670b35SErik Nordmark return (DCMD_OK);
1572bd670b35SErik Nordmark }
1573bd670b35SErik Nordmark
1574bd670b35SErik Nordmark int
ire(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)15757c478bd9Sstevel@tonic-gate ire(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
15767c478bd9Sstevel@tonic-gate {
15777c478bd9Sstevel@tonic-gate uint_t verbose = FALSE;
15787c478bd9Sstevel@tonic-gate ire_t ire;
1579ffaa671aSsowmini ire_cbdata_t ire_cb;
1580ffaa671aSsowmini int ipversion = 0;
1581ffaa671aSsowmini const char *opt_P = NULL;
1582bd670b35SErik Nordmark const char *zone_name = NULL;
1583bd670b35SErik Nordmark ip_stack_t *ipst = NULL;
15847c478bd9Sstevel@tonic-gate
15857c478bd9Sstevel@tonic-gate if (mdb_getopts(argc, argv,
1586ffaa671aSsowmini 'v', MDB_OPT_SETBITS, TRUE, &verbose,
1587bd670b35SErik Nordmark 's', MDB_OPT_STR, &zone_name,
1588ffaa671aSsowmini 'P', MDB_OPT_STR, &opt_P, NULL) != argc)
15897c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
15907c478bd9Sstevel@tonic-gate
1591bd670b35SErik Nordmark /* Follow the specified zone name to find a ip_stack_t*. */
1592bd670b35SErik Nordmark if (zone_name != NULL) {
1593bd670b35SErik Nordmark ipst = zone_to_ips(zone_name);
1594bd670b35SErik Nordmark if (ipst == NULL)
1595bd670b35SErik Nordmark return (DCMD_USAGE);
1596bd670b35SErik Nordmark }
1597bd670b35SErik Nordmark
1598ffaa671aSsowmini if (opt_P != NULL) {
1599ffaa671aSsowmini if (strcmp("v4", opt_P) == 0) {
1600ffaa671aSsowmini ipversion = IPV4_VERSION;
1601ffaa671aSsowmini } else if (strcmp("v6", opt_P) == 0) {
1602ffaa671aSsowmini ipversion = IPV6_VERSION;
1603ffaa671aSsowmini } else {
1604ffaa671aSsowmini mdb_warn("invalid protocol '%s'\n", opt_P);
1605ffaa671aSsowmini return (DCMD_USAGE);
1606ffaa671aSsowmini }
1607ffaa671aSsowmini }
1608ffaa671aSsowmini
16097c478bd9Sstevel@tonic-gate if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) {
16107c478bd9Sstevel@tonic-gate
16117c478bd9Sstevel@tonic-gate if (verbose) {
16127c478bd9Sstevel@tonic-gate mdb_printf("%?s %40s %-20s%\n"
16137c478bd9Sstevel@tonic-gate "%?s %40s %-20s%\n"
1614bd670b35SErik Nordmark "%<u>%?s %40s %4s %-20s %s%</u>\n",
16157c478bd9Sstevel@tonic-gate "ADDR", "SRC", "TYPE",
16167c478bd9Sstevel@tonic-gate "", "DST", "MARKS",
1617bd670b35SErik Nordmark "", "STACK", "ZONE", "FLAGS", "INTF");
16187c478bd9Sstevel@tonic-gate } else {
1619bd670b35SErik Nordmark mdb_printf("%<u>%?s %30s %30s %5s %4s %s%</u>\n",
1620bd670b35SErik Nordmark "ADDR", "SRC", "DST", "STACK", "ZONE", "INTF");
16217c478bd9Sstevel@tonic-gate }
16227c478bd9Sstevel@tonic-gate }
16237c478bd9Sstevel@tonic-gate
1624ffaa671aSsowmini ire_cb.verbose = (verbose == TRUE);
1625ffaa671aSsowmini ire_cb.ire_ipversion = ipversion;
1626ffaa671aSsowmini
16277c478bd9Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC) {
16287c478bd9Sstevel@tonic-gate (void) mdb_vread(&ire, sizeof (ire_t), addr);
1629ffaa671aSsowmini (void) ire_format(addr, &ire, &ire_cb);
1630bd670b35SErik Nordmark } else if (mdb_pwalk("ire", (mdb_walk_cb_t)ire_format, &ire_cb,
1631bd670b35SErik Nordmark (uintptr_t)ipst) == -1) {
16327c478bd9Sstevel@tonic-gate mdb_warn("failed to walk ire table");
16337c478bd9Sstevel@tonic-gate return (DCMD_ERR);
16347c478bd9Sstevel@tonic-gate }
16357c478bd9Sstevel@tonic-gate
16367c478bd9Sstevel@tonic-gate return (DCMD_OK);
16377c478bd9Sstevel@tonic-gate }
16387c478bd9Sstevel@tonic-gate
16397c478bd9Sstevel@tonic-gate static size_t
mi_osize(const queue_t * q)16407c478bd9Sstevel@tonic-gate mi_osize(const queue_t *q)
16417c478bd9Sstevel@tonic-gate {
16427c478bd9Sstevel@tonic-gate /*
16437c478bd9Sstevel@tonic-gate * The code in common/inet/mi.c allocates an extra word to store the
16447c478bd9Sstevel@tonic-gate * size of the allocation. An mi_o_s is thus a size_t plus an mi_o_s.
16457c478bd9Sstevel@tonic-gate */
16467c478bd9Sstevel@tonic-gate struct mi_block {
16477c478bd9Sstevel@tonic-gate size_t mi_nbytes;
16487c478bd9Sstevel@tonic-gate struct mi_o_s mi_o;
16497c478bd9Sstevel@tonic-gate } m;
16507c478bd9Sstevel@tonic-gate
16517c478bd9Sstevel@tonic-gate if (mdb_vread(&m, sizeof (m), (uintptr_t)q->q_ptr -
16527c478bd9Sstevel@tonic-gate sizeof (m)) == sizeof (m))
16537c478bd9Sstevel@tonic-gate return (m.mi_nbytes - sizeof (m));
16547c478bd9Sstevel@tonic-gate
16557c478bd9Sstevel@tonic-gate return (0);
16567c478bd9Sstevel@tonic-gate }
16577c478bd9Sstevel@tonic-gate
16587c478bd9Sstevel@tonic-gate static void
ip_ill_qinfo(const queue_t * q,char * buf,size_t nbytes)16597c478bd9Sstevel@tonic-gate ip_ill_qinfo(const queue_t *q, char *buf, size_t nbytes)
16607c478bd9Sstevel@tonic-gate {
16617c478bd9Sstevel@tonic-gate char name[32];
16627c478bd9Sstevel@tonic-gate ill_t ill;
16637c478bd9Sstevel@tonic-gate
16647c478bd9Sstevel@tonic-gate if (mdb_vread(&ill, sizeof (ill),
16657c478bd9Sstevel@tonic-gate (uintptr_t)q->q_ptr) == sizeof (ill) &&
16667c478bd9Sstevel@tonic-gate mdb_readstr(name, sizeof (name), (uintptr_t)ill.ill_name) > 0)
16677c478bd9Sstevel@tonic-gate (void) mdb_snprintf(buf, nbytes, "if: %s", name);
16687c478bd9Sstevel@tonic-gate }
16697c478bd9Sstevel@tonic-gate
16707c478bd9Sstevel@tonic-gate void
ip_qinfo(const queue_t * q,char * buf,size_t nbytes)16717c478bd9Sstevel@tonic-gate ip_qinfo(const queue_t *q, char *buf, size_t nbytes)
16727c478bd9Sstevel@tonic-gate {
16737c478bd9Sstevel@tonic-gate size_t size = mi_osize(q);
16747c478bd9Sstevel@tonic-gate
16757c478bd9Sstevel@tonic-gate if (size == sizeof (ill_t))
16767c478bd9Sstevel@tonic-gate ip_ill_qinfo(q, buf, nbytes);
16777c478bd9Sstevel@tonic-gate }
16787c478bd9Sstevel@tonic-gate
16797c478bd9Sstevel@tonic-gate uintptr_t
ip_rnext(const queue_t * q)16807c478bd9Sstevel@tonic-gate ip_rnext(const queue_t *q)
16817c478bd9Sstevel@tonic-gate {
16827c478bd9Sstevel@tonic-gate size_t size = mi_osize(q);
16837c478bd9Sstevel@tonic-gate ill_t ill;
16847c478bd9Sstevel@tonic-gate
16857c478bd9Sstevel@tonic-gate if (size == sizeof (ill_t) && mdb_vread(&ill, sizeof (ill),
16867c478bd9Sstevel@tonic-gate (uintptr_t)q->q_ptr) == sizeof (ill))
16877c478bd9Sstevel@tonic-gate return ((uintptr_t)ill.ill_rq);
16887c478bd9Sstevel@tonic-gate
16897c478bd9Sstevel@tonic-gate return (NULL);
16907c478bd9Sstevel@tonic-gate }
16917c478bd9Sstevel@tonic-gate
16927c478bd9Sstevel@tonic-gate uintptr_t
ip_wnext(const queue_t * q)16937c478bd9Sstevel@tonic-gate ip_wnext(const queue_t *q)
16947c478bd9Sstevel@tonic-gate {
16957c478bd9Sstevel@tonic-gate size_t size = mi_osize(q);
16967c478bd9Sstevel@tonic-gate ill_t ill;
16977c478bd9Sstevel@tonic-gate
16987c478bd9Sstevel@tonic-gate if (size == sizeof (ill_t) && mdb_vread(&ill, sizeof (ill),
16997c478bd9Sstevel@tonic-gate (uintptr_t)q->q_ptr) == sizeof (ill))
17007c478bd9Sstevel@tonic-gate return ((uintptr_t)ill.ill_wq);
17017c478bd9Sstevel@tonic-gate
17027c478bd9Sstevel@tonic-gate return (NULL);
17037c478bd9Sstevel@tonic-gate }
17047c478bd9Sstevel@tonic-gate
17057c478bd9Sstevel@tonic-gate /*
17067c478bd9Sstevel@tonic-gate * Print the core fields in an squeue_t. With the "-v" argument,
17077c478bd9Sstevel@tonic-gate * provide more verbose output.
17087c478bd9Sstevel@tonic-gate */
17097c478bd9Sstevel@tonic-gate static int
squeue(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)17107c478bd9Sstevel@tonic-gate squeue(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
17117c478bd9Sstevel@tonic-gate {
17127c478bd9Sstevel@tonic-gate unsigned int i;
17137c478bd9Sstevel@tonic-gate unsigned int verbose = FALSE;
17147c478bd9Sstevel@tonic-gate const int SQUEUE_STATEDELT = (int)(sizeof (uintptr_t) + 9);
17157c478bd9Sstevel@tonic-gate boolean_t arm;
17167c478bd9Sstevel@tonic-gate squeue_t squeue;
17177c478bd9Sstevel@tonic-gate
17187c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) {
17197c478bd9Sstevel@tonic-gate if (mdb_walk_dcmd("genunix`squeue_cache", "ip`squeue",
17207c478bd9Sstevel@tonic-gate argc, argv) == -1) {
17217c478bd9Sstevel@tonic-gate mdb_warn("failed to walk squeue cache");
17227c478bd9Sstevel@tonic-gate return (DCMD_ERR);
17237c478bd9Sstevel@tonic-gate }
17247c478bd9Sstevel@tonic-gate return (DCMD_OK);
17257c478bd9Sstevel@tonic-gate }
17267c478bd9Sstevel@tonic-gate
17277c478bd9Sstevel@tonic-gate if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, TRUE, &verbose, NULL)
17287c478bd9Sstevel@tonic-gate != argc)
17297c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
17307c478bd9Sstevel@tonic-gate
17317c478bd9Sstevel@tonic-gate if (!DCMD_HDRSPEC(flags) && verbose)
17327c478bd9Sstevel@tonic-gate mdb_printf("\n\n");
17337c478bd9Sstevel@tonic-gate
17347c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags) || verbose) {
17357c478bd9Sstevel@tonic-gate mdb_printf("%?s %-5s %-3s %?s %?s %?s\n",
17367c478bd9Sstevel@tonic-gate "ADDR", "STATE", "CPU",
17377c478bd9Sstevel@tonic-gate "FIRST", "LAST", "WORKER");
17387c478bd9Sstevel@tonic-gate }
17397c478bd9Sstevel@tonic-gate
17407c478bd9Sstevel@tonic-gate if (mdb_vread(&squeue, sizeof (squeue_t), addr) == -1) {
17417c478bd9Sstevel@tonic-gate mdb_warn("cannot read squeue_t at %p", addr);
17427c478bd9Sstevel@tonic-gate return (DCMD_ERR);
17437c478bd9Sstevel@tonic-gate }
17447c478bd9Sstevel@tonic-gate
17457c478bd9Sstevel@tonic-gate mdb_printf("%0?p %05x %3d %0?p %0?p %0?p\n",
17467c478bd9Sstevel@tonic-gate addr, squeue.sq_state, squeue.sq_bind,
17477c478bd9Sstevel@tonic-gate squeue.sq_first, squeue.sq_last, squeue.sq_worker);
17487c478bd9Sstevel@tonic-gate
17497c478bd9Sstevel@tonic-gate if (!verbose)
17507c478bd9Sstevel@tonic-gate return (DCMD_OK);
17517c478bd9Sstevel@tonic-gate
17527c478bd9Sstevel@tonic-gate arm = B_TRUE;
17537c478bd9Sstevel@tonic-gate for (i = 0; squeue_states[i].bit_name != NULL; i++) {
17547c478bd9Sstevel@tonic-gate if (((squeue.sq_state) & (1 << i)) == 0)
17557c478bd9Sstevel@tonic-gate continue;
17567c478bd9Sstevel@tonic-gate
17577c478bd9Sstevel@tonic-gate if (arm) {
17587c478bd9Sstevel@tonic-gate mdb_printf("%*s|\n", SQUEUE_STATEDELT, "");
17597c478bd9Sstevel@tonic-gate mdb_printf("%*s+--> ", SQUEUE_STATEDELT, "");
17607c478bd9Sstevel@tonic-gate arm = B_FALSE;
17617c478bd9Sstevel@tonic-gate } else
17627c478bd9Sstevel@tonic-gate mdb_printf("%*s ", SQUEUE_STATEDELT, "");
17637c478bd9Sstevel@tonic-gate
17647c478bd9Sstevel@tonic-gate mdb_printf("%-12s %s\n", squeue_states[i].bit_name,
17657c478bd9Sstevel@tonic-gate squeue_states[i].bit_descr);
17667c478bd9Sstevel@tonic-gate }
17677c478bd9Sstevel@tonic-gate
17687c478bd9Sstevel@tonic-gate return (DCMD_OK);
17697c478bd9Sstevel@tonic-gate }
17707c478bd9Sstevel@tonic-gate
17717c478bd9Sstevel@tonic-gate static void
ip_squeue_help(void)17727c478bd9Sstevel@tonic-gate ip_squeue_help(void)
17737c478bd9Sstevel@tonic-gate {
17747c478bd9Sstevel@tonic-gate mdb_printf("Print the core information for a given NCA squeue_t.\n\n");
17757c478bd9Sstevel@tonic-gate mdb_printf("Options:\n");
17767c478bd9Sstevel@tonic-gate mdb_printf("\t-v\tbe verbose (more descriptive)\n");
17777c478bd9Sstevel@tonic-gate }
17787c478bd9Sstevel@tonic-gate
17796a8288c7Scarlsonj /*
17806a8288c7Scarlsonj * This is called by ::th_trace (via a callback) when walking the th_hash
17816a8288c7Scarlsonj * list. It calls modent to find the entries.
17826a8288c7Scarlsonj */
17836a8288c7Scarlsonj /* ARGSUSED */
17846a8288c7Scarlsonj static int
modent_summary(uintptr_t addr,const void * data,void * private)17856a8288c7Scarlsonj modent_summary(uintptr_t addr, const void *data, void *private)
17866a8288c7Scarlsonj {
17876a8288c7Scarlsonj th_walk_data_t *thw = private;
17886a8288c7Scarlsonj const struct mod_hash_entry *mhe = data;
17896a8288c7Scarlsonj th_trace_t th;
17906a8288c7Scarlsonj
17916a8288c7Scarlsonj if (mdb_vread(&th, sizeof (th), (uintptr_t)mhe->mhe_val) == -1) {
17926a8288c7Scarlsonj mdb_warn("failed to read th_trace_t %p", mhe->mhe_val);
17936a8288c7Scarlsonj return (WALK_ERR);
17946a8288c7Scarlsonj }
17956a8288c7Scarlsonj
17966a8288c7Scarlsonj if (th.th_refcnt == 0 && thw->thw_non_zero_only)
17976a8288c7Scarlsonj return (WALK_NEXT);
17986a8288c7Scarlsonj
17996a8288c7Scarlsonj if (!thw->thw_match) {
18006a8288c7Scarlsonj mdb_printf("%?p %?p %?p %8d %?p\n", thw->thw_ipst, mhe->mhe_key,
18016a8288c7Scarlsonj mhe->mhe_val, th.th_refcnt, th.th_id);
18026a8288c7Scarlsonj } else if (thw->thw_matchkey == (uintptr_t)mhe->mhe_key) {
18036a8288c7Scarlsonj int i, j, k;
18046a8288c7Scarlsonj tr_buf_t *tr;
18056a8288c7Scarlsonj
18066a8288c7Scarlsonj mdb_printf("Object %p in IP stack %p:\n", mhe->mhe_key,
18076a8288c7Scarlsonj thw->thw_ipst);
18086a8288c7Scarlsonj i = th.th_trace_lastref;
18096a8288c7Scarlsonj mdb_printf("\tThread %p refcnt %d:\n", th.th_id,
18106a8288c7Scarlsonj th.th_refcnt);
18116a8288c7Scarlsonj for (j = TR_BUF_MAX; j > 0; j--) {
18126a8288c7Scarlsonj tr = th.th_trbuf + i;
18136a8288c7Scarlsonj if (tr->tr_depth == 0 || tr->tr_depth > TR_STACK_DEPTH)
18146a8288c7Scarlsonj break;
18156a8288c7Scarlsonj mdb_printf("\t T%+ld:\n", tr->tr_time -
18166a8288c7Scarlsonj thw->thw_lbolt);
18176a8288c7Scarlsonj for (k = 0; k < tr->tr_depth; k++)
18186a8288c7Scarlsonj mdb_printf("\t\t%a\n", tr->tr_stack[k]);
18196a8288c7Scarlsonj if (--i < 0)
18206a8288c7Scarlsonj i = TR_BUF_MAX - 1;
18216a8288c7Scarlsonj }
18226a8288c7Scarlsonj }
18236a8288c7Scarlsonj return (WALK_NEXT);
18246a8288c7Scarlsonj }
18256a8288c7Scarlsonj
18266a8288c7Scarlsonj /*
18276a8288c7Scarlsonj * This is called by ::th_trace (via a callback) when walking the th_hash
18286a8288c7Scarlsonj * list. It calls modent to find the entries.
18296a8288c7Scarlsonj */
18306a8288c7Scarlsonj /* ARGSUSED */
18316a8288c7Scarlsonj static int
th_hash_summary(uintptr_t addr,const void * data,void * private)18326a8288c7Scarlsonj th_hash_summary(uintptr_t addr, const void *data, void *private)
18336a8288c7Scarlsonj {
18346a8288c7Scarlsonj const th_hash_t *thh = data;
18356a8288c7Scarlsonj th_walk_data_t *thw = private;
18366a8288c7Scarlsonj
18376a8288c7Scarlsonj thw->thw_ipst = (uintptr_t)thh->thh_ipst;
18386a8288c7Scarlsonj return (mdb_pwalk("modent", modent_summary, private,
18396a8288c7Scarlsonj (uintptr_t)thh->thh_hash));
18406a8288c7Scarlsonj }
18416a8288c7Scarlsonj
18426a8288c7Scarlsonj /*
18436a8288c7Scarlsonj * Print or summarize the th_trace_t structures.
18446a8288c7Scarlsonj */
18456a8288c7Scarlsonj static int
th_trace(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)18466a8288c7Scarlsonj th_trace(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
18476a8288c7Scarlsonj {
18486a8288c7Scarlsonj th_walk_data_t thw;
18496a8288c7Scarlsonj
18506a8288c7Scarlsonj (void) memset(&thw, 0, sizeof (thw));
18516a8288c7Scarlsonj
18526a8288c7Scarlsonj if (mdb_getopts(argc, argv,
18536a8288c7Scarlsonj 'n', MDB_OPT_SETBITS, TRUE, &thw.thw_non_zero_only,
18546a8288c7Scarlsonj NULL) != argc)
18556a8288c7Scarlsonj return (DCMD_USAGE);
18566a8288c7Scarlsonj
18576a8288c7Scarlsonj if (!(flags & DCMD_ADDRSPEC)) {
18586a8288c7Scarlsonj /*
18596a8288c7Scarlsonj * No address specified. Walk all of the th_hash_t in the
18606a8288c7Scarlsonj * system, and summarize the th_trace_t entries in each.
18616a8288c7Scarlsonj */
18626a8288c7Scarlsonj mdb_printf("%?s %?s %?s %8s %?s\n",
18636a8288c7Scarlsonj "IPSTACK", "OBJECT", "TRACE", "REFCNT", "THREAD");
18646a8288c7Scarlsonj thw.thw_match = B_FALSE;
18656a8288c7Scarlsonj } else {
18666a8288c7Scarlsonj thw.thw_match = B_TRUE;
18676a8288c7Scarlsonj thw.thw_matchkey = addr;
1868d3d50737SRafael Vanoni
1869d3d50737SRafael Vanoni if ((thw.thw_lbolt = (clock_t)mdb_get_lbolt()) == -1) {
18706a8288c7Scarlsonj mdb_warn("failed to read lbolt");
18716a8288c7Scarlsonj return (DCMD_ERR);
18726a8288c7Scarlsonj }
18736a8288c7Scarlsonj }
18746a8288c7Scarlsonj if (mdb_pwalk("th_hash", th_hash_summary, &thw, NULL) == -1) {
18756a8288c7Scarlsonj mdb_warn("can't walk th_hash entries");
18766a8288c7Scarlsonj return (DCMD_ERR);
18776a8288c7Scarlsonj }
18786a8288c7Scarlsonj return (DCMD_OK);
18796a8288c7Scarlsonj }
18806a8288c7Scarlsonj
18816a8288c7Scarlsonj static void
th_trace_help(void)18826a8288c7Scarlsonj th_trace_help(void)
18836a8288c7Scarlsonj {
1884bd670b35SErik Nordmark mdb_printf("If given an address of an ill_t, ipif_t, ire_t, or ncec_t, "
18856a8288c7Scarlsonj "print the\n"
18866a8288c7Scarlsonj "corresponding th_trace_t structure in detail. Otherwise, if no "
18876a8288c7Scarlsonj "address is\n"
18886a8288c7Scarlsonj "given, then summarize all th_trace_t structures.\n\n");
18896a8288c7Scarlsonj mdb_printf("Options:\n"
18906a8288c7Scarlsonj "\t-n\tdisplay only entries with non-zero th_refcnt\n");
18916a8288c7Scarlsonj }
18926a8288c7Scarlsonj
18937c478bd9Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = {
1894d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "conn_status", ":",
1895d5b6ed4bSVasumathi Sundaram - Sun Microsystems "display connection structures from ipcl hash tables",
1896d5b6ed4bSVasumathi Sundaram - Sun Microsystems conn_status, conn_status_help },
1897d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "srcid_status", ":",
1898d5b6ed4bSVasumathi Sundaram - Sun Microsystems "display connection structures from ipcl hash tables",
1899d5b6ed4bSVasumathi Sundaram - Sun Microsystems srcid_status },
1900bd670b35SErik Nordmark { "ill", "?[-v] [-P v4 | v6] [-s exclusive-ip-zone-name]",
1901bd670b35SErik Nordmark "display ill_t structures", ill, ill_help },
19027c478bd9Sstevel@tonic-gate { "illif", "?[-P v4 | v6]",
19037c478bd9Sstevel@tonic-gate "display or filter IP Lower Level InterFace structures", illif,
19047c478bd9Sstevel@tonic-gate illif_help },
19057c478bd9Sstevel@tonic-gate { "iphdr", ":[-vf]", "display an IPv4 header", iphdr },
19067c478bd9Sstevel@tonic-gate { "ip6hdr", ":[-vf]", "display an IPv6 header", ip6hdr },
1907d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "ipif", "?[-v] [-P v4 | v6]", "display ipif structures",
1908d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipif, ipif_help },
1909bd670b35SErik Nordmark { "ire", "?[-v] [-P v4|v6] [-s exclusive-ip-zone-name]",
1910ffaa671aSsowmini "display Internet Route Entry structures", ire },
1911bd670b35SErik Nordmark { "nce", "?[-P v4|v6] [-i <interface>]",
1912bd670b35SErik Nordmark "display interface-specific Neighbor Cache structures", nce },
1913bd670b35SErik Nordmark { "ncec", "?[-P v4 | v6]", "display Neighbor Cache Entry structures",
1914bd670b35SErik Nordmark ncec },
1915bd670b35SErik Nordmark { "dce", "?[-P v4|v6] [-s exclusive-ip-zone-name]",
1916bd670b35SErik Nordmark "display Destination Cache Entry structures", dce },
19177c478bd9Sstevel@tonic-gate { "squeue", ":[-v]", "print core squeue_t info", squeue,
19187c478bd9Sstevel@tonic-gate ip_squeue_help },
19197c478bd9Sstevel@tonic-gate { "tcphdr", ":", "display a TCP header", tcphdr },
19207c478bd9Sstevel@tonic-gate { "udphdr", ":", "display an UDP header", udphdr },
19217c478bd9Sstevel@tonic-gate { "sctphdr", ":", "display an SCTP header", sctphdr },
19226a8288c7Scarlsonj { "th_trace", "?[-n]", "display th_trace_t structures", th_trace,
19236a8288c7Scarlsonj th_trace_help },
19247c478bd9Sstevel@tonic-gate { NULL }
19257c478bd9Sstevel@tonic-gate };
19267c478bd9Sstevel@tonic-gate
19277c478bd9Sstevel@tonic-gate static const mdb_walker_t walkers[] = {
1928d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "conn_status", "walk list of conn_t structures",
1929d5b6ed4bSVasumathi Sundaram - Sun Microsystems ip_stacks_common_walk_init, conn_status_walk_step, NULL },
1930f4b3ec61Sdh155122 { "illif", "walk list of ill interface types for all stacks",
1931ffaa671aSsowmini ip_stacks_common_walk_init, illif_walk_step, NULL },
1932f4b3ec61Sdh155122 { "illif_stack", "walk list of ill interface types",
1933f4b3ec61Sdh155122 illif_stack_walk_init, illif_stack_walk_step,
1934f4b3ec61Sdh155122 illif_stack_walk_fini },
1935bd670b35SErik Nordmark { "ill", "walk active ill_t structures for all stacks",
1936d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill_walk_init, ill_walk_step, NULL },
1937d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "ipif", "walk list of ipif structures for all stacks",
1938d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipif_walk_init, ipif_walk_step, NULL },
1939d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "ipif_list", "walk the linked list of ipif structures "
1940d5b6ed4bSVasumathi Sundaram - Sun Microsystems "for a given ill",
1941d5b6ed4bSVasumathi Sundaram - Sun Microsystems ip_list_walk_init, ip_list_walk_step,
1942d5b6ed4bSVasumathi Sundaram - Sun Microsystems ip_list_walk_fini, &ipif_walk_arg },
1943d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "srcid", "walk list of srcid_map structures for all stacks",
1944d5b6ed4bSVasumathi Sundaram - Sun Microsystems ip_stacks_common_walk_init, srcid_walk_step, NULL },
1945d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "srcid_list", "walk list of srcid_map structures for a stack",
1946d5b6ed4bSVasumathi Sundaram - Sun Microsystems ip_list_walk_init, ip_list_walk_step, ip_list_walk_fini,
1947d5b6ed4bSVasumathi Sundaram - Sun Microsystems &srcid_walk_arg },
19487c478bd9Sstevel@tonic-gate { "ire", "walk active ire_t structures",
19497c478bd9Sstevel@tonic-gate ire_walk_init, ire_walk_step, NULL },
1950f4b3ec61Sdh155122 { "ire_next", "walk ire_t structures in the ctable",
1951f4b3ec61Sdh155122 ire_next_walk_init, ire_next_walk_step, NULL },
1952bd670b35SErik Nordmark { "nce", "walk active nce_t structures",
1953bd670b35SErik Nordmark nce_walk_init, nce_walk_step, NULL },
1954bd670b35SErik Nordmark { "dce", "walk active dce_t structures",
1955bd670b35SErik Nordmark dce_walk_init, dce_walk_step, NULL },
1956f4b3ec61Sdh155122 { "ip_stacks", "walk all the ip_stack_t",
1957721fffe3SKacheong Poon ns_walk_init, ip_stacks_walk_step, NULL },
1958721fffe3SKacheong Poon { "tcp_stacks", "walk all the tcp_stack_t",
1959721fffe3SKacheong Poon ns_walk_init, tcp_stacks_walk_step, NULL },
1960721fffe3SKacheong Poon { "sctp_stacks", "walk all the sctp_stack_t",
1961721fffe3SKacheong Poon ns_walk_init, sctp_stacks_walk_step, NULL },
1962721fffe3SKacheong Poon { "udp_stacks", "walk all the udp_stack_t",
1963721fffe3SKacheong Poon ns_walk_init, udp_stacks_walk_step, NULL },
19646a8288c7Scarlsonj { "th_hash", "walk all the th_hash_t entries",
19656a8288c7Scarlsonj th_hash_walk_init, th_hash_walk_step, NULL },
1966bd670b35SErik Nordmark { "ncec", "walk list of ncec structures for all stacks",
1967bd670b35SErik Nordmark ip_stacks_common_walk_init, ncec_walk_step, NULL },
1968bd670b35SErik Nordmark { "ncec_stack", "walk list of ncec structures",
1969bd670b35SErik Nordmark ncec_stack_walk_init, ncec_stack_walk_step,
1970bd670b35SErik Nordmark ncec_stack_walk_fini},
1971d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "udp_hash", "walk list of conn_t structures in ips_ipcl_udp_fanout",
1972d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipcl_hash_walk_init, ipcl_hash_walk_step,
1973d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipcl_hash_walk_fini, &udp_hash_arg},
1974d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "conn_hash", "walk list of conn_t structures in ips_ipcl_conn_fanout",
1975d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipcl_hash_walk_init, ipcl_hash_walk_step,
1976d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipcl_hash_walk_fini, &conn_hash_arg},
1977d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "bind_hash", "walk list of conn_t structures in ips_ipcl_bind_fanout",
1978d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipcl_hash_walk_init, ipcl_hash_walk_step,
1979d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipcl_hash_walk_fini, &bind_hash_arg},
1980d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "proto_hash", "walk list of conn_t structures in "
1981d5b6ed4bSVasumathi Sundaram - Sun Microsystems "ips_ipcl_proto_fanout",
1982d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipcl_hash_walk_init, ipcl_hash_walk_step,
1983d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipcl_hash_walk_fini, &proto_hash_arg},
1984d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "proto_v6_hash", "walk list of conn_t structures in "
1985d5b6ed4bSVasumathi Sundaram - Sun Microsystems "ips_ipcl_proto_fanout_v6",
1986d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipcl_hash_walk_init, ipcl_hash_walk_step,
1987d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipcl_hash_walk_fini, &proto_v6_hash_arg},
1988721fffe3SKacheong Poon { "ilb_stacks", "walk all ilb_stack_t",
1989721fffe3SKacheong Poon ns_walk_init, ilb_stacks_walk_step, NULL },
1990dbed73cbSSangeeta Misra { "ilb_rules", "walk ilb rules in a given ilb_stack_t",
1991dbed73cbSSangeeta Misra ilb_rules_walk_init, ilb_rules_walk_step, NULL },
1992dbed73cbSSangeeta Misra { "ilb_servers", "walk server in a given ilb_rule_t",
1993dbed73cbSSangeeta Misra ilb_servers_walk_init, ilb_servers_walk_step, NULL },
1994dbed73cbSSangeeta Misra { "ilb_nat_src", "walk NAT source table of a given ilb_stack_t",
1995dbed73cbSSangeeta Misra ilb_nat_src_walk_init, ilb_nat_src_walk_step,
1996dbed73cbSSangeeta Misra ilb_common_walk_fini },
1997dbed73cbSSangeeta Misra { "ilb_conns", "walk NAT table of a given ilb_stack_t",
1998dbed73cbSSangeeta Misra ilb_conn_walk_init, ilb_conn_walk_step, ilb_common_walk_fini },
1999dbed73cbSSangeeta Misra { "ilb_stickys", "walk sticky table of a given ilb_stack_t",
2000dbed73cbSSangeeta Misra ilb_sticky_walk_init, ilb_sticky_walk_step,
2001dbed73cbSSangeeta Misra ilb_common_walk_fini },
2002721fffe3SKacheong Poon { "tcps_sc", "walk all the per CPU stats counters of a tcp_stack_t",
2003721fffe3SKacheong Poon tcps_sc_walk_init, tcps_sc_walk_step, NULL },
20047c478bd9Sstevel@tonic-gate { NULL }
20057c478bd9Sstevel@tonic-gate };
20067c478bd9Sstevel@tonic-gate
20077c478bd9Sstevel@tonic-gate static const mdb_qops_t ip_qops = { ip_qinfo, ip_rnext, ip_wnext };
20087c478bd9Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers };
20097c478bd9Sstevel@tonic-gate
20107c478bd9Sstevel@tonic-gate const mdb_modinfo_t *
_mdb_init(void)20117c478bd9Sstevel@tonic-gate _mdb_init(void)
20127c478bd9Sstevel@tonic-gate {
20137c478bd9Sstevel@tonic-gate GElf_Sym sym;
20147c478bd9Sstevel@tonic-gate
201569bb4bb4Scarlsonj if (mdb_lookup_by_obj("ip", "ipwinit", &sym) == 0)
20167c478bd9Sstevel@tonic-gate mdb_qops_install(&ip_qops, (uintptr_t)sym.st_value);
20177c478bd9Sstevel@tonic-gate
20187c478bd9Sstevel@tonic-gate return (&modinfo);
20197c478bd9Sstevel@tonic-gate }
20207c478bd9Sstevel@tonic-gate
20217c478bd9Sstevel@tonic-gate void
_mdb_fini(void)20227c478bd9Sstevel@tonic-gate _mdb_fini(void)
20237c478bd9Sstevel@tonic-gate {
20247c478bd9Sstevel@tonic-gate GElf_Sym sym;
20257c478bd9Sstevel@tonic-gate
202669bb4bb4Scarlsonj if (mdb_lookup_by_obj("ip", "ipwinit", &sym) == 0)
20277c478bd9Sstevel@tonic-gate mdb_qops_remove(&ip_qops, (uintptr_t)sym.st_value);
20287c478bd9Sstevel@tonic-gate }
2029ffaa671aSsowmini
2030ffaa671aSsowmini static char *
ncec_state(int ncec_state)2031bd670b35SErik Nordmark ncec_state(int ncec_state)
2032ffaa671aSsowmini {
2033bd670b35SErik Nordmark switch (ncec_state) {
2034ffaa671aSsowmini case ND_UNCHANGED:
2035ffaa671aSsowmini return ("unchanged");
2036ffaa671aSsowmini case ND_INCOMPLETE:
2037ffaa671aSsowmini return ("incomplete");
2038ffaa671aSsowmini case ND_REACHABLE:
2039ffaa671aSsowmini return ("reachable");
2040ffaa671aSsowmini case ND_STALE:
2041ffaa671aSsowmini return ("stale");
2042ffaa671aSsowmini case ND_DELAY:
2043ffaa671aSsowmini return ("delay");
2044ffaa671aSsowmini case ND_PROBE:
2045ffaa671aSsowmini return ("probe");
2046ffaa671aSsowmini case ND_UNREACHABLE:
2047ffaa671aSsowmini return ("unreach");
2048ffaa671aSsowmini case ND_INITIAL:
2049ffaa671aSsowmini return ("initial");
2050ffaa671aSsowmini default:
2051ffaa671aSsowmini return ("??");
2052ffaa671aSsowmini }
2053ffaa671aSsowmini }
2054ffaa671aSsowmini
2055ffaa671aSsowmini static char *
ncec_l2_addr(const ncec_t * ncec,const ill_t * ill)2056bd670b35SErik Nordmark ncec_l2_addr(const ncec_t *ncec, const ill_t *ill)
2057bd670b35SErik Nordmark {
2058bd670b35SErik Nordmark uchar_t *h;
2059bd670b35SErik Nordmark static char addr_buf[L2MAXADDRSTRLEN];
2060bd670b35SErik Nordmark
2061bd670b35SErik Nordmark if (ncec->ncec_lladdr == NULL) {
2062bd670b35SErik Nordmark return ("None");
2063bd670b35SErik Nordmark }
2064bd670b35SErik Nordmark
2065bd670b35SErik Nordmark if (ill->ill_net_type == IRE_IF_RESOLVER) {
2066bd670b35SErik Nordmark
2067bd670b35SErik Nordmark if (ill->ill_phys_addr_length == 0)
2068bd670b35SErik Nordmark return ("None");
2069bd670b35SErik Nordmark h = mdb_zalloc(ill->ill_phys_addr_length, UM_SLEEP);
2070bd670b35SErik Nordmark if (mdb_vread(h, ill->ill_phys_addr_length,
2071bd670b35SErik Nordmark (uintptr_t)ncec->ncec_lladdr) == -1) {
2072bd670b35SErik Nordmark mdb_warn("failed to read hwaddr at %p",
2073bd670b35SErik Nordmark ncec->ncec_lladdr);
2074bd670b35SErik Nordmark return ("Unknown");
2075bd670b35SErik Nordmark }
2076bd670b35SErik Nordmark mdb_mac_addr(h, ill->ill_phys_addr_length,
2077bd670b35SErik Nordmark addr_buf, sizeof (addr_buf));
2078bd670b35SErik Nordmark } else {
2079bd670b35SErik Nordmark return ("None");
2080bd670b35SErik Nordmark }
2081bd670b35SErik Nordmark mdb_free(h, ill->ill_phys_addr_length);
2082bd670b35SErik Nordmark return (addr_buf);
2083bd670b35SErik Nordmark }
2084bd670b35SErik Nordmark
2085bd670b35SErik Nordmark static char *
nce_l2_addr(const nce_t * nce,const ill_t * ill)2086ffaa671aSsowmini nce_l2_addr(const nce_t *nce, const ill_t *ill)
2087ffaa671aSsowmini {
2088ffaa671aSsowmini uchar_t *h;
2089ffaa671aSsowmini static char addr_buf[L2MAXADDRSTRLEN];
2090ffaa671aSsowmini mblk_t mp;
2091ffaa671aSsowmini size_t mblen;
2092ffaa671aSsowmini
2093bd670b35SErik Nordmark if (nce->nce_dlur_mp == NULL)
2094ffaa671aSsowmini return ("None");
2095ffaa671aSsowmini
2096ffaa671aSsowmini if (ill->ill_net_type == IRE_IF_RESOLVER) {
2097ffaa671aSsowmini if (mdb_vread(&mp, sizeof (mblk_t),
2098bd670b35SErik Nordmark (uintptr_t)nce->nce_dlur_mp) == -1) {
2099bd670b35SErik Nordmark mdb_warn("failed to read nce_dlur_mp at %p",
2100bd670b35SErik Nordmark nce->nce_dlur_mp);
2101bd670b35SErik Nordmark return ("None");
2102ffaa671aSsowmini }
2103bd670b35SErik Nordmark if (ill->ill_phys_addr_length == 0)
2104ffaa671aSsowmini return ("None");
2105ffaa671aSsowmini mblen = mp.b_wptr - mp.b_rptr;
2106ffaa671aSsowmini if (mblen > (sizeof (dl_unitdata_req_t) + MAX_SAP_LEN) ||
2107bd670b35SErik Nordmark ill->ill_phys_addr_length > MAX_SAP_LEN ||
2108bd670b35SErik Nordmark (NCE_LL_ADDR_OFFSET(ill) +
2109bd670b35SErik Nordmark ill->ill_phys_addr_length) > mblen) {
2110bd670b35SErik Nordmark return ("Unknown");
2111ffaa671aSsowmini }
2112ffaa671aSsowmini h = mdb_zalloc(mblen, UM_SLEEP);
2113ffaa671aSsowmini if (mdb_vread(h, mblen, (uintptr_t)(mp.b_rptr)) == -1) {
2114ffaa671aSsowmini mdb_warn("failed to read hwaddr at %p",
2115ffaa671aSsowmini mp.b_rptr + NCE_LL_ADDR_OFFSET(ill));
2116ffaa671aSsowmini return ("Unknown");
2117ffaa671aSsowmini }
2118bd670b35SErik Nordmark mdb_mac_addr(h + NCE_LL_ADDR_OFFSET(ill),
2119bd670b35SErik Nordmark ill->ill_phys_addr_length, addr_buf, sizeof (addr_buf));
2120ffaa671aSsowmini } else {
2121ffaa671aSsowmini return ("None");
2122ffaa671aSsowmini }
2123ffaa671aSsowmini mdb_free(h, mblen);
2124ffaa671aSsowmini return (addr_buf);
2125ffaa671aSsowmini }
2126ffaa671aSsowmini
2127ffaa671aSsowmini static void
ncec_header(uint_t flags)2128bd670b35SErik Nordmark ncec_header(uint_t flags)
2129ffaa671aSsowmini {
2130ffaa671aSsowmini if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) {
2131ffaa671aSsowmini
2132ffaa671aSsowmini mdb_printf("%<u>%?s %-20s %-10s %-8s %-5s %s%</u>\n",
2133ffaa671aSsowmini "ADDR", "HW_ADDR", "STATE", "FLAGS", "ILL", "IP ADDR");
2134ffaa671aSsowmini }
2135ffaa671aSsowmini }
2136ffaa671aSsowmini
2137ffaa671aSsowmini int
ncec(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)2138bd670b35SErik Nordmark ncec(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2139ffaa671aSsowmini {
2140bd670b35SErik Nordmark ncec_t ncec;
2141bd670b35SErik Nordmark ncec_cbdata_t id;
2142ffaa671aSsowmini int ipversion = 0;
2143ffaa671aSsowmini const char *opt_P = NULL;
2144ffaa671aSsowmini
2145ffaa671aSsowmini if (mdb_getopts(argc, argv,
2146ffaa671aSsowmini 'P', MDB_OPT_STR, &opt_P, NULL) != argc)
2147ffaa671aSsowmini return (DCMD_USAGE);
2148ffaa671aSsowmini
2149ffaa671aSsowmini if (opt_P != NULL) {
2150ffaa671aSsowmini if (strcmp("v4", opt_P) == 0) {
2151ffaa671aSsowmini ipversion = IPV4_VERSION;
2152ffaa671aSsowmini } else if (strcmp("v6", opt_P) == 0) {
2153ffaa671aSsowmini ipversion = IPV6_VERSION;
2154ffaa671aSsowmini } else {
2155ffaa671aSsowmini mdb_warn("invalid protocol '%s'\n", opt_P);
2156ffaa671aSsowmini return (DCMD_USAGE);
2157ffaa671aSsowmini }
2158ffaa671aSsowmini }
2159ffaa671aSsowmini
2160ffaa671aSsowmini if (flags & DCMD_ADDRSPEC) {
2161ffaa671aSsowmini
2162bd670b35SErik Nordmark if (mdb_vread(&ncec, sizeof (ncec_t), addr) == -1) {
2163bd670b35SErik Nordmark mdb_warn("failed to read ncec at %p\n", addr);
2164ffaa671aSsowmini return (DCMD_ERR);
2165ffaa671aSsowmini }
2166bd670b35SErik Nordmark if (ipversion != 0 && ncec.ncec_ipversion != ipversion) {
2167ffaa671aSsowmini mdb_printf("IP Version mismatch\n");
2168ffaa671aSsowmini return (DCMD_ERR);
2169ffaa671aSsowmini }
2170bd670b35SErik Nordmark ncec_header(flags);
2171bd670b35SErik Nordmark return (ncec_format(addr, &ncec, ipversion));
2172ffaa671aSsowmini
2173ffaa671aSsowmini } else {
2174bd670b35SErik Nordmark id.ncec_addr = addr;
2175bd670b35SErik Nordmark id.ncec_ipversion = ipversion;
2176bd670b35SErik Nordmark ncec_header(flags);
2177bd670b35SErik Nordmark if (mdb_walk("ncec", (mdb_walk_cb_t)ncec_cb, &id) == -1) {
2178bd670b35SErik Nordmark mdb_warn("failed to walk ncec table\n");
2179ffaa671aSsowmini return (DCMD_ERR);
2180ffaa671aSsowmini }
2181ffaa671aSsowmini }
2182ffaa671aSsowmini return (DCMD_OK);
2183ffaa671aSsowmini }
2184ffaa671aSsowmini
2185ffaa671aSsowmini static int
ncec_format(uintptr_t addr,const ncec_t * ncec,int ipversion)2186bd670b35SErik Nordmark ncec_format(uintptr_t addr, const ncec_t *ncec, int ipversion)
2187ffaa671aSsowmini {
2188bd670b35SErik Nordmark static const mdb_bitmask_t ncec_flags[] = {
2189bd670b35SErik Nordmark { "P", NCE_F_NONUD, NCE_F_NONUD },
2190ffaa671aSsowmini { "R", NCE_F_ISROUTER, NCE_F_ISROUTER },
2191ffaa671aSsowmini { "N", NCE_F_NONUD, NCE_F_NONUD },
2192ffaa671aSsowmini { "A", NCE_F_ANYCAST, NCE_F_ANYCAST },
2193ffaa671aSsowmini { "C", NCE_F_CONDEMNED, NCE_F_CONDEMNED },
2194ffaa671aSsowmini { "U", NCE_F_UNSOL_ADV, NCE_F_UNSOL_ADV },
2195ffaa671aSsowmini { "B", NCE_F_BCAST, NCE_F_BCAST },
2196ffaa671aSsowmini { NULL, 0, 0 }
2197ffaa671aSsowmini };
2198bd670b35SErik Nordmark #define NCE_MAX_FLAGS (sizeof (ncec_flags) / sizeof (mdb_bitmask_t))
2199ffaa671aSsowmini struct in_addr nceaddr;
2200ffaa671aSsowmini ill_t ill;
2201ffaa671aSsowmini char ill_name[LIFNAMSIZ];
2202ffaa671aSsowmini char flagsbuf[NCE_MAX_FLAGS];
2203ffaa671aSsowmini
2204bd670b35SErik Nordmark if (mdb_vread(&ill, sizeof (ill), (uintptr_t)ncec->ncec_ill) == -1) {
2205bd670b35SErik Nordmark mdb_warn("failed to read ncec_ill at %p",
2206bd670b35SErik Nordmark ncec->ncec_ill);
2207ffaa671aSsowmini return (DCMD_ERR);
2208ffaa671aSsowmini }
2209ffaa671aSsowmini
2210ffaa671aSsowmini (void) mdb_readstr(ill_name, MIN(LIFNAMSIZ, ill.ill_name_length),
2211ffaa671aSsowmini (uintptr_t)ill.ill_name);
2212ffaa671aSsowmini
2213ffaa671aSsowmini mdb_snprintf(flagsbuf, sizeof (flagsbuf), "%hb",
2214bd670b35SErik Nordmark ncec->ncec_flags, ncec_flags);
2215ffaa671aSsowmini
2216bd670b35SErik Nordmark if (ipversion != 0 && ncec->ncec_ipversion != ipversion)
2217ffaa671aSsowmini return (DCMD_OK);
2218ffaa671aSsowmini
2219bd670b35SErik Nordmark if (ncec->ncec_ipversion == IPV4_VERSION) {
2220bd670b35SErik Nordmark IN6_V4MAPPED_TO_INADDR(&ncec->ncec_addr, &nceaddr);
2221ffaa671aSsowmini mdb_printf("%?p %-20s %-10s "
2222ffaa671aSsowmini "%-8s "
2223ffaa671aSsowmini "%-5s %I\n",
2224bd670b35SErik Nordmark addr, ncec_l2_addr(ncec, &ill),
2225bd670b35SErik Nordmark ncec_state(ncec->ncec_state),
2226ffaa671aSsowmini flagsbuf,
2227ffaa671aSsowmini ill_name, nceaddr.s_addr);
2228ffaa671aSsowmini } else {
2229ffaa671aSsowmini mdb_printf("%?p %-20s %-10s %-8s %-5s %N\n",
2230bd670b35SErik Nordmark addr, ncec_l2_addr(ncec, &ill),
2231bd670b35SErik Nordmark ncec_state(ncec->ncec_state),
2232ffaa671aSsowmini flagsbuf,
2233bd670b35SErik Nordmark ill_name, &ncec->ncec_addr);
2234ffaa671aSsowmini }
2235ffaa671aSsowmini
2236ffaa671aSsowmini return (DCMD_OK);
2237ffaa671aSsowmini }
2238ffaa671aSsowmini
2239ffaa671aSsowmini static uintptr_t
ncec_get_next_hash_tbl(uintptr_t start,int * index,struct ndp_g_s ndp)2240bd670b35SErik Nordmark ncec_get_next_hash_tbl(uintptr_t start, int *index, struct ndp_g_s ndp)
2241ffaa671aSsowmini {
2242ffaa671aSsowmini uintptr_t addr = start;
2243ffaa671aSsowmini int i = *index;
2244ffaa671aSsowmini
2245ffaa671aSsowmini while (addr == NULL) {
2246ffaa671aSsowmini
2247ffaa671aSsowmini if (++i >= NCE_TABLE_SIZE)
2248ffaa671aSsowmini break;
2249ffaa671aSsowmini addr = (uintptr_t)ndp.nce_hash_tbl[i];
2250ffaa671aSsowmini }
2251ffaa671aSsowmini *index = i;
2252ffaa671aSsowmini return (addr);
2253ffaa671aSsowmini }
2254ffaa671aSsowmini
2255ffaa671aSsowmini static int
ncec_walk_step(mdb_walk_state_t * wsp)2256bd670b35SErik Nordmark ncec_walk_step(mdb_walk_state_t *wsp)
2257ffaa671aSsowmini {
2258ffaa671aSsowmini uintptr_t kaddr4, kaddr6;
2259ffaa671aSsowmini
2260ffaa671aSsowmini kaddr4 = wsp->walk_addr + OFFSETOF(ip_stack_t, ips_ndp4);
2261ffaa671aSsowmini kaddr6 = wsp->walk_addr + OFFSETOF(ip_stack_t, ips_ndp6);
2262ffaa671aSsowmini
2263ffaa671aSsowmini if (mdb_vread(&kaddr4, sizeof (kaddr4), kaddr4) == -1) {
2264ffaa671aSsowmini mdb_warn("can't read ips_ip_cache_table at %p", kaddr4);
2265ffaa671aSsowmini return (WALK_ERR);
2266ffaa671aSsowmini }
2267ffaa671aSsowmini if (mdb_vread(&kaddr6, sizeof (kaddr6), kaddr6) == -1) {
2268ffaa671aSsowmini mdb_warn("can't read ips_ip_cache_table at %p", kaddr6);
2269ffaa671aSsowmini return (WALK_ERR);
2270ffaa671aSsowmini }
2271bd670b35SErik Nordmark if (mdb_pwalk("ncec_stack", wsp->walk_callback, wsp->walk_cbdata,
2272ffaa671aSsowmini kaddr4) == -1) {
2273bd670b35SErik Nordmark mdb_warn("couldn't walk 'ncec_stack' for ips_ndp4 %p",
2274ffaa671aSsowmini kaddr4);
2275ffaa671aSsowmini return (WALK_ERR);
2276ffaa671aSsowmini }
2277bd670b35SErik Nordmark if (mdb_pwalk("ncec_stack", wsp->walk_callback,
2278ffaa671aSsowmini wsp->walk_cbdata, kaddr6) == -1) {
2279bd670b35SErik Nordmark mdb_warn("couldn't walk 'ncec_stack' for ips_ndp6 %p",
2280ffaa671aSsowmini kaddr6);
2281ffaa671aSsowmini return (WALK_ERR);
2282ffaa671aSsowmini }
2283ffaa671aSsowmini return (WALK_NEXT);
2284ffaa671aSsowmini }
2285ffaa671aSsowmini
2286d5b6ed4bSVasumathi Sundaram - Sun Microsystems static uintptr_t
ipcl_hash_get_next_connf_tbl(ipcl_hash_walk_data_t * iw)2287d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipcl_hash_get_next_connf_tbl(ipcl_hash_walk_data_t *iw)
2288d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2289d5b6ed4bSVasumathi Sundaram - Sun Microsystems struct connf_s connf;
2290d5b6ed4bSVasumathi Sundaram - Sun Microsystems uintptr_t addr = NULL, next;
2291d5b6ed4bSVasumathi Sundaram - Sun Microsystems int index = iw->connf_tbl_index;
2292d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2293d5b6ed4bSVasumathi Sundaram - Sun Microsystems do {
2294d5b6ed4bSVasumathi Sundaram - Sun Microsystems next = iw->hash_tbl + index * sizeof (struct connf_s);
2295d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (++index >= iw->hash_tbl_size) {
2296d5b6ed4bSVasumathi Sundaram - Sun Microsystems addr = NULL;
2297d5b6ed4bSVasumathi Sundaram - Sun Microsystems break;
2298d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2299d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_vread(&connf, sizeof (struct connf_s), next) == -1) {
2300d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("failed to read conn_t at %p", next);
2301d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (NULL);
2302d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2303d5b6ed4bSVasumathi Sundaram - Sun Microsystems addr = (uintptr_t)connf.connf_head;
2304d5b6ed4bSVasumathi Sundaram - Sun Microsystems } while (addr == NULL);
2305d5b6ed4bSVasumathi Sundaram - Sun Microsystems iw->connf_tbl_index = index;
2306d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (addr);
2307d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2308d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2309d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
ipcl_hash_walk_init(mdb_walk_state_t * wsp)2310d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipcl_hash_walk_init(mdb_walk_state_t *wsp)
2311d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2312d5b6ed4bSVasumathi Sundaram - Sun Microsystems const hash_walk_arg_t *arg = wsp->walk_arg;
2313d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipcl_hash_walk_data_t *iw;
2314d5b6ed4bSVasumathi Sundaram - Sun Microsystems uintptr_t tbladdr;
2315d5b6ed4bSVasumathi Sundaram - Sun Microsystems uintptr_t sizeaddr;
2316d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2317d5b6ed4bSVasumathi Sundaram - Sun Microsystems iw = mdb_alloc(sizeof (ipcl_hash_walk_data_t), UM_SLEEP);
2318d5b6ed4bSVasumathi Sundaram - Sun Microsystems iw->conn = mdb_alloc(sizeof (conn_t), UM_SLEEP);
2319d5b6ed4bSVasumathi Sundaram - Sun Microsystems tbladdr = wsp->walk_addr + arg->tbl_off;
2320d5b6ed4bSVasumathi Sundaram - Sun Microsystems sizeaddr = wsp->walk_addr + arg->size_off;
2321d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2322d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_vread(&iw->hash_tbl, sizeof (uintptr_t), tbladdr) == -1) {
2323d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("can't read fanout table addr at %p", tbladdr);
2324d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_free(iw->conn, sizeof (conn_t));
2325d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_free(iw, sizeof (ipcl_hash_walk_data_t));
2326d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_ERR);
2327d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2328bd670b35SErik Nordmark if (arg->tbl_off == OFFSETOF(ip_stack_t, ips_ipcl_proto_fanout_v4) ||
2329d5b6ed4bSVasumathi Sundaram - Sun Microsystems arg->tbl_off == OFFSETOF(ip_stack_t, ips_ipcl_proto_fanout_v6)) {
2330d5b6ed4bSVasumathi Sundaram - Sun Microsystems iw->hash_tbl_size = IPPROTO_MAX;
2331d5b6ed4bSVasumathi Sundaram - Sun Microsystems } else {
2332d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_vread(&iw->hash_tbl_size, sizeof (int),
2333d5b6ed4bSVasumathi Sundaram - Sun Microsystems sizeaddr) == -1) {
2334d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("can't read fanout table size addr at %p",
2335d5b6ed4bSVasumathi Sundaram - Sun Microsystems sizeaddr);
2336d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_free(iw->conn, sizeof (conn_t));
2337d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_free(iw, sizeof (ipcl_hash_walk_data_t));
2338d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_ERR);
2339d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2340d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2341d5b6ed4bSVasumathi Sundaram - Sun Microsystems iw->connf_tbl_index = 0;
2342d5b6ed4bSVasumathi Sundaram - Sun Microsystems wsp->walk_addr = ipcl_hash_get_next_connf_tbl(iw);
2343d5b6ed4bSVasumathi Sundaram - Sun Microsystems wsp->walk_data = iw;
2344d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2345d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (wsp->walk_addr != NULL)
2346d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
2347d5b6ed4bSVasumathi Sundaram - Sun Microsystems else
2348d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_DONE);
2349d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2350d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2351d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
ipcl_hash_walk_step(mdb_walk_state_t * wsp)2352d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipcl_hash_walk_step(mdb_walk_state_t *wsp)
2353d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2354d5b6ed4bSVasumathi Sundaram - Sun Microsystems uintptr_t addr = wsp->walk_addr;
2355d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipcl_hash_walk_data_t *iw = wsp->walk_data;
2356d5b6ed4bSVasumathi Sundaram - Sun Microsystems conn_t *conn = iw->conn;
2357d5b6ed4bSVasumathi Sundaram - Sun Microsystems int ret = WALK_DONE;
2358d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2359d5b6ed4bSVasumathi Sundaram - Sun Microsystems while (addr != NULL) {
2360d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_vread(conn, sizeof (conn_t), addr) == -1) {
2361d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("failed to read conn_t at %p", addr);
2362d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_ERR);
2363d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2364d5b6ed4bSVasumathi Sundaram - Sun Microsystems ret = wsp->walk_callback(addr, iw, wsp->walk_cbdata);
2365d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (ret != WALK_NEXT)
2366d5b6ed4bSVasumathi Sundaram - Sun Microsystems break;
2367d5b6ed4bSVasumathi Sundaram - Sun Microsystems addr = (uintptr_t)conn->conn_next;
2368d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2369d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (ret == WALK_NEXT) {
2370d5b6ed4bSVasumathi Sundaram - Sun Microsystems wsp->walk_addr = ipcl_hash_get_next_connf_tbl(iw);
2371d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2372d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (wsp->walk_addr != NULL)
2373d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
2374d5b6ed4bSVasumathi Sundaram - Sun Microsystems else
2375d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_DONE);
2376d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2377d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2378d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (ret);
2379d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2380d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2381d5b6ed4bSVasumathi Sundaram - Sun Microsystems static void
ipcl_hash_walk_fini(mdb_walk_state_t * wsp)2382d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipcl_hash_walk_fini(mdb_walk_state_t *wsp)
2383d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2384d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipcl_hash_walk_data_t *iw = wsp->walk_data;
2385d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2386d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_free(iw->conn, sizeof (conn_t));
2387d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_free(iw, sizeof (ipcl_hash_walk_data_t));
2388d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2389d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2390ffaa671aSsowmini /*
2391ffaa671aSsowmini * Called with walk_addr being the address of ips_ndp{4,6}
2392ffaa671aSsowmini */
2393ffaa671aSsowmini static int
ncec_stack_walk_init(mdb_walk_state_t * wsp)2394bd670b35SErik Nordmark ncec_stack_walk_init(mdb_walk_state_t *wsp)
2395ffaa671aSsowmini {
2396bd670b35SErik Nordmark ncec_walk_data_t *nw;
2397ffaa671aSsowmini
2398ffaa671aSsowmini if (wsp->walk_addr == NULL) {
2399bd670b35SErik Nordmark mdb_warn("ncec_stack requires ndp_g_s address\n");
2400ffaa671aSsowmini return (WALK_ERR);
2401ffaa671aSsowmini }
2402ffaa671aSsowmini
2403bd670b35SErik Nordmark nw = mdb_alloc(sizeof (ncec_walk_data_t), UM_SLEEP);
2404ffaa671aSsowmini
2405bd670b35SErik Nordmark if (mdb_vread(&nw->ncec_ip_ndp, sizeof (struct ndp_g_s),
2406ffaa671aSsowmini wsp->walk_addr) == -1) {
2407ffaa671aSsowmini mdb_warn("failed to read 'ip_ndp' at %p",
2408ffaa671aSsowmini wsp->walk_addr);
2409bd670b35SErik Nordmark mdb_free(nw, sizeof (ncec_walk_data_t));
2410ffaa671aSsowmini return (WALK_ERR);
2411ffaa671aSsowmini }
2412ffaa671aSsowmini
2413bd670b35SErik Nordmark /*
2414bd670b35SErik Nordmark * ncec_get_next_hash_tbl() starts at ++i , so initialize index to -1
2415bd670b35SErik Nordmark */
2416bd670b35SErik Nordmark nw->ncec_hash_tbl_index = -1;
2417bd670b35SErik Nordmark wsp->walk_addr = ncec_get_next_hash_tbl(NULL,
2418bd670b35SErik Nordmark &nw->ncec_hash_tbl_index, nw->ncec_ip_ndp);
2419ffaa671aSsowmini wsp->walk_data = nw;
2420ffaa671aSsowmini
2421ffaa671aSsowmini return (WALK_NEXT);
2422ffaa671aSsowmini }
2423ffaa671aSsowmini
2424ffaa671aSsowmini static int
ncec_stack_walk_step(mdb_walk_state_t * wsp)2425bd670b35SErik Nordmark ncec_stack_walk_step(mdb_walk_state_t *wsp)
2426ffaa671aSsowmini {
2427ffaa671aSsowmini uintptr_t addr = wsp->walk_addr;
2428bd670b35SErik Nordmark ncec_walk_data_t *nw = wsp->walk_data;
2429ffaa671aSsowmini
2430ffaa671aSsowmini if (addr == NULL)
2431ffaa671aSsowmini return (WALK_DONE);
2432ffaa671aSsowmini
2433bd670b35SErik Nordmark if (mdb_vread(&nw->ncec, sizeof (ncec_t), addr) == -1) {
2434bd670b35SErik Nordmark mdb_warn("failed to read ncec_t at %p", addr);
2435ffaa671aSsowmini return (WALK_ERR);
2436ffaa671aSsowmini }
2437ffaa671aSsowmini
2438bd670b35SErik Nordmark wsp->walk_addr = (uintptr_t)nw->ncec.ncec_next;
2439ffaa671aSsowmini
2440bd670b35SErik Nordmark wsp->walk_addr = ncec_get_next_hash_tbl(wsp->walk_addr,
2441bd670b35SErik Nordmark &nw->ncec_hash_tbl_index, nw->ncec_ip_ndp);
2442ffaa671aSsowmini
2443ffaa671aSsowmini return (wsp->walk_callback(addr, nw, wsp->walk_cbdata));
2444ffaa671aSsowmini }
2445ffaa671aSsowmini
2446ffaa671aSsowmini static void
ncec_stack_walk_fini(mdb_walk_state_t * wsp)2447bd670b35SErik Nordmark ncec_stack_walk_fini(mdb_walk_state_t *wsp)
2448ffaa671aSsowmini {
2449bd670b35SErik Nordmark mdb_free(wsp->walk_data, sizeof (ncec_walk_data_t));
2450ffaa671aSsowmini }
2451ffaa671aSsowmini
2452ffaa671aSsowmini /* ARGSUSED */
2453ffaa671aSsowmini static int
ncec_cb(uintptr_t addr,const ncec_walk_data_t * iw,ncec_cbdata_t * id)2454bd670b35SErik Nordmark ncec_cb(uintptr_t addr, const ncec_walk_data_t *iw, ncec_cbdata_t *id)
2455ffaa671aSsowmini {
2456bd670b35SErik Nordmark ncec_t ncec;
2457ffaa671aSsowmini
2458bd670b35SErik Nordmark if (mdb_vread(&ncec, sizeof (ncec_t), addr) == -1) {
2459bd670b35SErik Nordmark mdb_warn("failed to read ncec at %p", addr);
2460ffaa671aSsowmini return (WALK_NEXT);
2461ffaa671aSsowmini }
2462bd670b35SErik Nordmark (void) ncec_format(addr, &ncec, id->ncec_ipversion);
2463ffaa671aSsowmini return (WALK_NEXT);
2464ffaa671aSsowmini }
2465d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2466d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
ill_walk_init(mdb_walk_state_t * wsp)2467d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill_walk_init(mdb_walk_state_t *wsp)
2468d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2469d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_layered_walk("illif", wsp) == -1) {
2470d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("can't walk 'illif'");
2471d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_ERR);
2472d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2473d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
2474d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2475d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2476d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
ill_walk_step(mdb_walk_state_t * wsp)2477d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill_walk_step(mdb_walk_state_t *wsp)
2478d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2479d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill_if_t ill_if;
2480d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2481d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_vread(&ill_if, sizeof (ill_if_t), wsp->walk_addr) == -1) {
2482d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("can't read ill_if_t at %p", wsp->walk_addr);
2483d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_ERR);
2484d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2485d5b6ed4bSVasumathi Sundaram - Sun Microsystems wsp->walk_addr = (uintptr_t)(wsp->walk_addr +
2486d5b6ed4bSVasumathi Sundaram - Sun Microsystems offsetof(ill_if_t, illif_avl_by_ppa));
2487d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_pwalk("avl", wsp->walk_callback, wsp->walk_cbdata,
2488d5b6ed4bSVasumathi Sundaram - Sun Microsystems wsp->walk_addr) == -1) {
2489d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("can't walk 'avl'");
2490d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_ERR);
2491d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2492d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2493d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
2494d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2495d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2496d5b6ed4bSVasumathi Sundaram - Sun Microsystems /* ARGSUSED */
2497d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
ill_cb(uintptr_t addr,const ill_walk_data_t * iw,ill_cbdata_t * id)2498d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill_cb(uintptr_t addr, const ill_walk_data_t *iw, ill_cbdata_t *id)
2499d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2500d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill_t ill;
2501d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2502d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_vread(&ill, sizeof (ill_t), (uintptr_t)addr) == -1) {
2503d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("failed to read ill at %p", addr);
2504d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
2505d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2506bd670b35SErik Nordmark
2507bd670b35SErik Nordmark /* If ip_stack_t is specified, skip ILLs that don't belong to it. */
2508bd670b35SErik Nordmark if (id->ill_ipst != NULL && ill.ill_ipst != id->ill_ipst)
2509bd670b35SErik Nordmark return (WALK_NEXT);
2510bd670b35SErik Nordmark
2511d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (ill_format((uintptr_t)addr, &ill, id));
2512d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2513d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2514d5b6ed4bSVasumathi Sundaram - Sun Microsystems static void
ill_header(boolean_t verbose)2515d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill_header(boolean_t verbose)
2516d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2517d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (verbose) {
2518d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%-?s %-8s %3s %-10s %-?s %-?s %-10s%</u>\n",
2519d5b6ed4bSVasumathi Sundaram - Sun Microsystems "ADDR", "NAME", "VER", "TYPE", "WQ", "IPST", "FLAGS");
2520d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%-?s %4s%4s %-?s\n",
2521d5b6ed4bSVasumathi Sundaram - Sun Microsystems "PHYINT", "CNT", "", "GROUP");
2522d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%<u>%80s%</u>\n", "");
2523d5b6ed4bSVasumathi Sundaram - Sun Microsystems } else {
2524d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%<u>%-?s %-8s %-3s %-10s %4s %-?s %-10s%</u>\n",
2525d5b6ed4bSVasumathi Sundaram - Sun Microsystems "ADDR", "NAME", "VER", "TYPE", "CNT", "WQ", "FLAGS");
2526d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2527d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2528d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2529d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
ill_format(uintptr_t addr,const void * illptr,void * ill_cb_arg)2530d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill_format(uintptr_t addr, const void *illptr, void *ill_cb_arg)
2531d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2532d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill_t *ill = (ill_t *)illptr;
2533d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill_cbdata_t *illcb = ill_cb_arg;
2534d5b6ed4bSVasumathi Sundaram - Sun Microsystems boolean_t verbose = illcb->verbose;
2535d5b6ed4bSVasumathi Sundaram - Sun Microsystems phyint_t phyi;
2536d5b6ed4bSVasumathi Sundaram - Sun Microsystems static const mdb_bitmask_t fmasks[] = {
2537d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "R", PHYI_RUNNING, PHYI_RUNNING },
2538d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "P", PHYI_PROMISC, PHYI_PROMISC },
2539d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "V", PHYI_VIRTUAL, PHYI_VIRTUAL },
2540d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "I", PHYI_IPMP, PHYI_IPMP },
2541d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "f", PHYI_FAILED, PHYI_FAILED },
2542d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "S", PHYI_STANDBY, PHYI_STANDBY },
2543d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "i", PHYI_INACTIVE, PHYI_INACTIVE },
2544d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "O", PHYI_OFFLINE, PHYI_OFFLINE },
2545d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "T", ILLF_NOTRAILERS, ILLF_NOTRAILERS },
2546d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "A", ILLF_NOARP, ILLF_NOARP },
2547d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "M", ILLF_MULTICAST, ILLF_MULTICAST },
2548d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "F", ILLF_ROUTER, ILLF_ROUTER },
2549d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "D", ILLF_NONUD, ILLF_NONUD },
2550d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "X", ILLF_NORTEXCH, ILLF_NORTEXCH },
2551d5b6ed4bSVasumathi Sundaram - Sun Microsystems { NULL, 0, 0 }
2552d5b6ed4bSVasumathi Sundaram - Sun Microsystems };
2553d5b6ed4bSVasumathi Sundaram - Sun Microsystems static const mdb_bitmask_t v_fmasks[] = {
2554d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "RUNNING", PHYI_RUNNING, PHYI_RUNNING },
2555d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "PROMISC", PHYI_PROMISC, PHYI_PROMISC },
2556d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "VIRTUAL", PHYI_VIRTUAL, PHYI_VIRTUAL },
2557d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "IPMP", PHYI_IPMP, PHYI_IPMP },
2558d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "FAILED", PHYI_FAILED, PHYI_FAILED },
2559d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "STANDBY", PHYI_STANDBY, PHYI_STANDBY },
2560d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "INACTIVE", PHYI_INACTIVE, PHYI_INACTIVE },
2561d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "OFFLINE", PHYI_OFFLINE, PHYI_OFFLINE },
2562d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "NOTRAILER", ILLF_NOTRAILERS, ILLF_NOTRAILERS },
2563d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "NOARP", ILLF_NOARP, ILLF_NOARP },
2564d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "MULTICAST", ILLF_MULTICAST, ILLF_MULTICAST },
2565d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "ROUTER", ILLF_ROUTER, ILLF_ROUTER },
2566d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "NONUD", ILLF_NONUD, ILLF_NONUD },
2567d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "NORTEXCH", ILLF_NORTEXCH, ILLF_NORTEXCH },
2568d5b6ed4bSVasumathi Sundaram - Sun Microsystems { NULL, 0, 0 }
2569d5b6ed4bSVasumathi Sundaram - Sun Microsystems };
2570d5b6ed4bSVasumathi Sundaram - Sun Microsystems char ill_name[LIFNAMSIZ];
2571d5b6ed4bSVasumathi Sundaram - Sun Microsystems int cnt;
2572d5b6ed4bSVasumathi Sundaram - Sun Microsystems char *typebuf;
2573d5b6ed4bSVasumathi Sundaram - Sun Microsystems char sbuf[DEFCOLS];
2574d5b6ed4bSVasumathi Sundaram - Sun Microsystems int ipver = illcb->ill_ipversion;
2575d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2576d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (ipver != 0) {
2577d5b6ed4bSVasumathi Sundaram - Sun Microsystems if ((ipver == IPV4_VERSION && ill->ill_isv6) ||
2578d5b6ed4bSVasumathi Sundaram - Sun Microsystems (ipver == IPV6_VERSION && !ill->ill_isv6)) {
2579d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
2580d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2581d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2582d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_vread(&phyi, sizeof (phyint_t),
2583d5b6ed4bSVasumathi Sundaram - Sun Microsystems (uintptr_t)ill->ill_phyint) == -1) {
2584d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("failed to read ill_phyint at %p",
2585d5b6ed4bSVasumathi Sundaram - Sun Microsystems (uintptr_t)ill->ill_phyint);
2586d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
2587d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2588d5b6ed4bSVasumathi Sundaram - Sun Microsystems (void) mdb_readstr(ill_name, MIN(LIFNAMSIZ, ill->ill_name_length),
2589d5b6ed4bSVasumathi Sundaram - Sun Microsystems (uintptr_t)ill->ill_name);
2590d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2591d5b6ed4bSVasumathi Sundaram - Sun Microsystems switch (ill->ill_type) {
2592d5b6ed4bSVasumathi Sundaram - Sun Microsystems case 0:
2593d5b6ed4bSVasumathi Sundaram - Sun Microsystems typebuf = "LOOPBACK";
2594d5b6ed4bSVasumathi Sundaram - Sun Microsystems break;
2595d5b6ed4bSVasumathi Sundaram - Sun Microsystems case IFT_ETHER:
2596d5b6ed4bSVasumathi Sundaram - Sun Microsystems typebuf = "ETHER";
2597d5b6ed4bSVasumathi Sundaram - Sun Microsystems break;
2598d5b6ed4bSVasumathi Sundaram - Sun Microsystems case IFT_OTHER:
2599d5b6ed4bSVasumathi Sundaram - Sun Microsystems typebuf = "OTHER";
2600d5b6ed4bSVasumathi Sundaram - Sun Microsystems break;
2601d5b6ed4bSVasumathi Sundaram - Sun Microsystems default:
2602d5b6ed4bSVasumathi Sundaram - Sun Microsystems typebuf = NULL;
2603d5b6ed4bSVasumathi Sundaram - Sun Microsystems break;
2604d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2605d5b6ed4bSVasumathi Sundaram - Sun Microsystems cnt = ill->ill_refcnt + ill->ill_ire_cnt + ill->ill_nce_cnt +
2606bd670b35SErik Nordmark ill->ill_ilm_cnt + ill->ill_ncec_cnt;
2607d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%-?p %-8s %-3s ",
2608d5b6ed4bSVasumathi Sundaram - Sun Microsystems addr, ill_name, ill->ill_isv6 ? "v6" : "v4");
2609d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (typebuf != NULL)
2610d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%-10s ", typebuf);
2611d5b6ed4bSVasumathi Sundaram - Sun Microsystems else
2612d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%-10x ", ill->ill_type);
2613d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (verbose) {
2614d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%-?p %-?p %-llb\n",
2615d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill->ill_wq, ill->ill_ipst,
2616d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill->ill_flags | phyi.phyint_flags, v_fmasks);
2617d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%-?p %4d%4s %-?p\n",
2618d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill->ill_phyint, cnt, "", ill->ill_grp);
2619d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_snprintf(sbuf, sizeof (sbuf), "%*s %3s",
2620d5b6ed4bSVasumathi Sundaram - Sun Microsystems sizeof (uintptr_t) * 2, "", "");
2621d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%s|\n%s+--> %3d %-18s "
2622d5b6ed4bSVasumathi Sundaram - Sun Microsystems "references from active threads\n",
2623d5b6ed4bSVasumathi Sundaram - Sun Microsystems sbuf, sbuf, ill->ill_refcnt, "ill_refcnt");
2624d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%*s %7d %-18s ires referencing this ill\n",
2625d5b6ed4bSVasumathi Sundaram - Sun Microsystems strlen(sbuf), "", ill->ill_ire_cnt, "ill_ire_cnt");
2626d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%*s %7d %-18s nces referencing this ill\n",
2627d5b6ed4bSVasumathi Sundaram - Sun Microsystems strlen(sbuf), "", ill->ill_nce_cnt, "ill_nce_cnt");
2628bd670b35SErik Nordmark mdb_printf("%*s %7d %-18s ncecs referencing this ill\n",
2629bd670b35SErik Nordmark strlen(sbuf), "", ill->ill_ncec_cnt, "ill_ncec_cnt");
2630d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%*s %7d %-18s ilms referencing this ill\n",
2631d5b6ed4bSVasumathi Sundaram - Sun Microsystems strlen(sbuf), "", ill->ill_ilm_cnt, "ill_ilm_cnt");
2632d5b6ed4bSVasumathi Sundaram - Sun Microsystems } else {
2633d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%4d %-?p %-llb\n",
2634d5b6ed4bSVasumathi Sundaram - Sun Microsystems cnt, ill->ill_wq,
2635d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill->ill_flags | phyi.phyint_flags, fmasks);
2636d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2637d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
2638d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2639d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2640d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
ill(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)2641d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2642d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2643d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill_t ill_data;
2644d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill_cbdata_t id;
2645d5b6ed4bSVasumathi Sundaram - Sun Microsystems int ipversion = 0;
2646bd670b35SErik Nordmark const char *zone_name = NULL;
2647d5b6ed4bSVasumathi Sundaram - Sun Microsystems const char *opt_P = NULL;
2648d5b6ed4bSVasumathi Sundaram - Sun Microsystems uint_t verbose = FALSE;
2649bd670b35SErik Nordmark ip_stack_t *ipst = NULL;
2650d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2651d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_getopts(argc, argv,
2652d5b6ed4bSVasumathi Sundaram - Sun Microsystems 'v', MDB_OPT_SETBITS, TRUE, &verbose,
2653bd670b35SErik Nordmark 's', MDB_OPT_STR, &zone_name,
2654d5b6ed4bSVasumathi Sundaram - Sun Microsystems 'P', MDB_OPT_STR, &opt_P, NULL) != argc)
2655d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (DCMD_USAGE);
2656d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2657bd670b35SErik Nordmark /* Follow the specified zone name to find a ip_stack_t*. */
2658bd670b35SErik Nordmark if (zone_name != NULL) {
2659bd670b35SErik Nordmark ipst = zone_to_ips(zone_name);
2660bd670b35SErik Nordmark if (ipst == NULL)
2661bd670b35SErik Nordmark return (DCMD_USAGE);
2662bd670b35SErik Nordmark }
2663bd670b35SErik Nordmark
2664d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (opt_P != NULL) {
2665d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (strcmp("v4", opt_P) == 0) {
2666d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipversion = IPV4_VERSION;
2667d5b6ed4bSVasumathi Sundaram - Sun Microsystems } else if (strcmp("v6", opt_P) == 0) {
2668d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipversion = IPV6_VERSION;
2669d5b6ed4bSVasumathi Sundaram - Sun Microsystems } else {
2670d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("invalid protocol '%s'\n", opt_P);
2671d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (DCMD_USAGE);
2672d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2673d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2674d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2675d5b6ed4bSVasumathi Sundaram - Sun Microsystems id.verbose = verbose;
2676d5b6ed4bSVasumathi Sundaram - Sun Microsystems id.ill_addr = addr;
2677d5b6ed4bSVasumathi Sundaram - Sun Microsystems id.ill_ipversion = ipversion;
2678bd670b35SErik Nordmark id.ill_ipst = ipst;
2679d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2680d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill_header(verbose);
2681d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (flags & DCMD_ADDRSPEC) {
2682d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_vread(&ill_data, sizeof (ill_t), addr) == -1) {
2683d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("failed to read ill at %p\n", addr);
2684d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (DCMD_ERR);
2685d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2686d5b6ed4bSVasumathi Sundaram - Sun Microsystems (void) ill_format(addr, &ill_data, &id);
2687d5b6ed4bSVasumathi Sundaram - Sun Microsystems } else {
2688d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_walk("ill", (mdb_walk_cb_t)ill_cb, &id) == -1) {
2689d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("failed to walk ills\n");
2690d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (DCMD_ERR);
2691d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2692d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2693d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (DCMD_OK);
2694d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2695d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2696d5b6ed4bSVasumathi Sundaram - Sun Microsystems static void
ill_help(void)2697d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill_help(void)
2698d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2699d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("Prints the following fields: ill ptr, name, "
2700d5b6ed4bSVasumathi Sundaram - Sun Microsystems "IP version, count, ill type and ill flags.\n"
2701d5b6ed4bSVasumathi Sundaram - Sun Microsystems "The count field is a sum of individual refcnts and is expanded "
2702d5b6ed4bSVasumathi Sundaram - Sun Microsystems "with the -v option.\n\n");
2703d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("Options:\n");
2704d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("\t-P v4 | v6"
2705d5b6ed4bSVasumathi Sundaram - Sun Microsystems "\tfilter ill structures for the specified protocol\n");
2706d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2707d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2708d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
ip_list_walk_init(mdb_walk_state_t * wsp)2709d5b6ed4bSVasumathi Sundaram - Sun Microsystems ip_list_walk_init(mdb_walk_state_t *wsp)
2710d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2711d5b6ed4bSVasumathi Sundaram - Sun Microsystems const ip_list_walk_arg_t *arg = wsp->walk_arg;
2712d5b6ed4bSVasumathi Sundaram - Sun Microsystems ip_list_walk_data_t *iw;
2713d5b6ed4bSVasumathi Sundaram - Sun Microsystems uintptr_t addr = (uintptr_t)(wsp->walk_addr + arg->off);
2714d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2715d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (wsp->walk_addr == NULL) {
2716d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("only local walks supported\n");
2717d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_ERR);
2718d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2719d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_vread(&wsp->walk_addr, sizeof (uintptr_t),
2720d5b6ed4bSVasumathi Sundaram - Sun Microsystems addr) == -1) {
2721d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("failed to read list head at %p", addr);
2722d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_ERR);
2723d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2724d5b6ed4bSVasumathi Sundaram - Sun Microsystems iw = mdb_alloc(sizeof (ip_list_walk_data_t), UM_SLEEP);
2725d5b6ed4bSVasumathi Sundaram - Sun Microsystems iw->nextoff = arg->nextp_off;
2726d5b6ed4bSVasumathi Sundaram - Sun Microsystems wsp->walk_data = iw;
2727d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2728d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
2729d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2730d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2731d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
ip_list_walk_step(mdb_walk_state_t * wsp)2732d5b6ed4bSVasumathi Sundaram - Sun Microsystems ip_list_walk_step(mdb_walk_state_t *wsp)
2733d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2734d5b6ed4bSVasumathi Sundaram - Sun Microsystems ip_list_walk_data_t *iw = wsp->walk_data;
2735d5b6ed4bSVasumathi Sundaram - Sun Microsystems uintptr_t addr = wsp->walk_addr;
2736d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2737d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (addr == NULL)
2738d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_DONE);
2739d5b6ed4bSVasumathi Sundaram - Sun Microsystems wsp->walk_addr = addr + iw->nextoff;
2740d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_vread(&wsp->walk_addr, sizeof (uintptr_t),
2741d5b6ed4bSVasumathi Sundaram - Sun Microsystems wsp->walk_addr) == -1) {
2742d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("failed to read list node at %p", addr);
2743d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_ERR);
2744d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2745d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (wsp->walk_callback(addr, iw, wsp->walk_cbdata));
2746d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2747d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2748d5b6ed4bSVasumathi Sundaram - Sun Microsystems static void
ip_list_walk_fini(mdb_walk_state_t * wsp)2749d5b6ed4bSVasumathi Sundaram - Sun Microsystems ip_list_walk_fini(mdb_walk_state_t *wsp)
2750d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2751d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_free(wsp->walk_data, sizeof (ip_list_walk_data_t));
2752d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2753d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2754d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
ipif_walk_init(mdb_walk_state_t * wsp)2755d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipif_walk_init(mdb_walk_state_t *wsp)
2756d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2757d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_layered_walk("ill", wsp) == -1) {
2758d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("can't walk 'ills'");
2759d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_ERR);
2760d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2761d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
2762d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2763d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2764d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
ipif_walk_step(mdb_walk_state_t * wsp)2765d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipif_walk_step(mdb_walk_state_t *wsp)
2766d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2767d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_pwalk("ipif_list", wsp->walk_callback, wsp->walk_cbdata,
2768d5b6ed4bSVasumathi Sundaram - Sun Microsystems wsp->walk_addr) == -1) {
2769d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("can't walk 'ipif_list'");
2770d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_ERR);
2771d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2772d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2773d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
2774d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2775d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2776d5b6ed4bSVasumathi Sundaram - Sun Microsystems /* ARGSUSED */
2777d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
ipif_cb(uintptr_t addr,const ipif_walk_data_t * iw,ipif_cbdata_t * id)2778d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipif_cb(uintptr_t addr, const ipif_walk_data_t *iw, ipif_cbdata_t *id)
2779d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2780d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipif_t ipif;
2781d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2782d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_vread(&ipif, sizeof (ipif_t), (uintptr_t)addr) == -1) {
2783d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("failed to read ipif at %p", addr);
2784d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
2785d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2786d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_vread(&id->ill, sizeof (ill_t),
2787d5b6ed4bSVasumathi Sundaram - Sun Microsystems (uintptr_t)ipif.ipif_ill) == -1) {
2788d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("failed to read ill at %p", ipif.ipif_ill);
2789d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
2790d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2791d5b6ed4bSVasumathi Sundaram - Sun Microsystems (void) ipif_format((uintptr_t)addr, &ipif, id);
2792d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
2793d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2794d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2795d5b6ed4bSVasumathi Sundaram - Sun Microsystems static void
ipif_header(boolean_t verbose)2796d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipif_header(boolean_t verbose)
2797d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2798d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (verbose) {
2799d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%-?s %-10s %-3s %-?s %-8s %-30s\n",
2800d5b6ed4bSVasumathi Sundaram - Sun Microsystems "ADDR", "NAME", "CNT", "ILL", "STFLAGS", "FLAGS");
2801d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%s\n%s\n",
2802d5b6ed4bSVasumathi Sundaram - Sun Microsystems "LCLADDR", "BROADCAST");
2803d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%<u>%80s%</u>\n", "");
2804d5b6ed4bSVasumathi Sundaram - Sun Microsystems } else {
2805d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%-?s %-10s %6s %-?s %-8s %-30s\n",
2806d5b6ed4bSVasumathi Sundaram - Sun Microsystems "ADDR", "NAME", "CNT", "ILL", "STFLAGS", "FLAGS");
2807d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%s\n%<u>%80s%</u>\n", "LCLADDR", "");
2808d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2809d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2810d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2811d5b6ed4bSVasumathi Sundaram - Sun Microsystems #ifdef _BIG_ENDIAN
2812d5b6ed4bSVasumathi Sundaram - Sun Microsystems #define ip_ntohl_32(x) ((x) & 0xffffffff)
2813d5b6ed4bSVasumathi Sundaram - Sun Microsystems #else
2814d5b6ed4bSVasumathi Sundaram - Sun Microsystems #define ip_ntohl_32(x) (((uint32_t)(x) << 24) | \
2815d5b6ed4bSVasumathi Sundaram - Sun Microsystems (((uint32_t)(x) << 8) & 0xff0000) | \
2816d5b6ed4bSVasumathi Sundaram - Sun Microsystems (((uint32_t)(x) >> 8) & 0xff00) | \
2817d5b6ed4bSVasumathi Sundaram - Sun Microsystems ((uint32_t)(x) >> 24))
2818d5b6ed4bSVasumathi Sundaram - Sun Microsystems #endif
2819d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2820d5b6ed4bSVasumathi Sundaram - Sun Microsystems int
mask_to_prefixlen(int af,const in6_addr_t * addr)2821d5b6ed4bSVasumathi Sundaram - Sun Microsystems mask_to_prefixlen(int af, const in6_addr_t *addr)
2822d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2823d5b6ed4bSVasumathi Sundaram - Sun Microsystems int len = 0;
2824d5b6ed4bSVasumathi Sundaram - Sun Microsystems int i;
2825d5b6ed4bSVasumathi Sundaram - Sun Microsystems uint_t mask = 0;
2826d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2827d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (af == AF_INET6) {
2828d5b6ed4bSVasumathi Sundaram - Sun Microsystems for (i = 0; i < 4; i++) {
2829d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (addr->s6_addr32[i] == 0xffffffff) {
2830d5b6ed4bSVasumathi Sundaram - Sun Microsystems len += 32;
2831d5b6ed4bSVasumathi Sundaram - Sun Microsystems } else {
2832d5b6ed4bSVasumathi Sundaram - Sun Microsystems mask = addr->s6_addr32[i];
2833d5b6ed4bSVasumathi Sundaram - Sun Microsystems break;
2834d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2835d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2836d5b6ed4bSVasumathi Sundaram - Sun Microsystems } else {
2837d5b6ed4bSVasumathi Sundaram - Sun Microsystems mask = V4_PART_OF_V6((*addr));
2838d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2839d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mask > 0)
2840d5b6ed4bSVasumathi Sundaram - Sun Microsystems len += (33 - mdb_ffs(ip_ntohl_32(mask)));
2841d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (len);
2842d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2843d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2844d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
ipif_format(uintptr_t addr,const void * ipifptr,void * ipif_cb_arg)2845d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipif_format(uintptr_t addr, const void *ipifptr, void *ipif_cb_arg)
2846d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2847d5b6ed4bSVasumathi Sundaram - Sun Microsystems const ipif_t *ipif = ipifptr;
2848d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipif_cbdata_t *ipifcb = ipif_cb_arg;
2849d5b6ed4bSVasumathi Sundaram - Sun Microsystems boolean_t verbose = ipifcb->verbose;
2850d5b6ed4bSVasumathi Sundaram - Sun Microsystems char ill_name[LIFNAMSIZ];
2851d5b6ed4bSVasumathi Sundaram - Sun Microsystems char buf[LIFNAMSIZ];
2852d5b6ed4bSVasumathi Sundaram - Sun Microsystems int cnt;
2853d5b6ed4bSVasumathi Sundaram - Sun Microsystems static const mdb_bitmask_t sfmasks[] = {
2854d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "CO", IPIF_CONDEMNED, IPIF_CONDEMNED},
2855d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "CH", IPIF_CHANGING, IPIF_CHANGING},
2856d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "SL", IPIF_SET_LINKLOCAL, IPIF_SET_LINKLOCAL},
2857d5b6ed4bSVasumathi Sundaram - Sun Microsystems { NULL, 0, 0 }
2858d5b6ed4bSVasumathi Sundaram - Sun Microsystems };
2859d5b6ed4bSVasumathi Sundaram - Sun Microsystems static const mdb_bitmask_t fmasks[] = {
2860d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "UP", IPIF_UP, IPIF_UP },
2861d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "UNN", IPIF_UNNUMBERED, IPIF_UNNUMBERED},
2862d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "DHCP", IPIF_DHCPRUNNING, IPIF_DHCPRUNNING},
2863d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "PRIV", IPIF_PRIVATE, IPIF_PRIVATE},
2864d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "NOXMT", IPIF_NOXMIT, IPIF_NOXMIT},
2865d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "NOLCL", IPIF_NOLOCAL, IPIF_NOLOCAL},
2866d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "DEPR", IPIF_DEPRECATED, IPIF_DEPRECATED},
2867d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "PREF", IPIF_PREFERRED, IPIF_PREFERRED},
2868d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "TEMP", IPIF_TEMPORARY, IPIF_TEMPORARY},
2869d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "ACONF", IPIF_ADDRCONF, IPIF_ADDRCONF},
2870d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "ANY", IPIF_ANYCAST, IPIF_ANYCAST},
2871d5b6ed4bSVasumathi Sundaram - Sun Microsystems { "NFAIL", IPIF_NOFAILOVER, IPIF_NOFAILOVER},
2872d5b6ed4bSVasumathi Sundaram - Sun Microsystems { NULL, 0, 0 }
2873d5b6ed4bSVasumathi Sundaram - Sun Microsystems };
2874d5b6ed4bSVasumathi Sundaram - Sun Microsystems char flagsbuf[2 * A_CNT(fmasks)];
2875d5b6ed4bSVasumathi Sundaram - Sun Microsystems char bitfields[A_CNT(fmasks)];
2876d5b6ed4bSVasumathi Sundaram - Sun Microsystems char sflagsbuf[A_CNT(sfmasks)];
2877d5b6ed4bSVasumathi Sundaram - Sun Microsystems char sbuf[DEFCOLS], addrstr[INET6_ADDRSTRLEN];
2878d5b6ed4bSVasumathi Sundaram - Sun Microsystems int ipver = ipifcb->ipif_ipversion;
2879d5b6ed4bSVasumathi Sundaram - Sun Microsystems int af;
2880d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2881d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (ipver != 0) {
2882d5b6ed4bSVasumathi Sundaram - Sun Microsystems if ((ipver == IPV4_VERSION && ipifcb->ill.ill_isv6) ||
2883d5b6ed4bSVasumathi Sundaram - Sun Microsystems (ipver == IPV6_VERSION && !ipifcb->ill.ill_isv6)) {
2884d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
2885d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2886d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2887d5b6ed4bSVasumathi Sundaram - Sun Microsystems if ((mdb_readstr(ill_name, MIN(LIFNAMSIZ,
2888d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipifcb->ill.ill_name_length),
2889d5b6ed4bSVasumathi Sundaram - Sun Microsystems (uintptr_t)ipifcb->ill.ill_name)) == -1) {
2890d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("failed to read ill_name of ill %p\n", ipifcb->ill);
2891d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
2892d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2893d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (ipif->ipif_id != 0) {
2894d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_snprintf(buf, LIFNAMSIZ, "%s:%d",
2895d5b6ed4bSVasumathi Sundaram - Sun Microsystems ill_name, ipif->ipif_id);
2896d5b6ed4bSVasumathi Sundaram - Sun Microsystems } else {
2897d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_snprintf(buf, LIFNAMSIZ, "%s", ill_name);
2898d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2899d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_snprintf(bitfields, sizeof (bitfields), "%s",
2900d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipif->ipif_addr_ready ? ",ADR" : "",
2901d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipif->ipif_was_up ? ",WU" : "",
2902bd670b35SErik Nordmark ipif->ipif_was_dup ? ",WD" : "");
2903d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_snprintf(flagsbuf, sizeof (flagsbuf), "%llb%s",
2904d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipif->ipif_flags, fmasks, bitfields);
2905d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_snprintf(sflagsbuf, sizeof (sflagsbuf), "%b",
2906d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipif->ipif_state_flags, sfmasks);
2907d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2908bd670b35SErik Nordmark cnt = ipif->ipif_refcnt;
2909d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2910d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (ipifcb->ill.ill_isv6) {
2911d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_snprintf(addrstr, sizeof (addrstr), "%N",
2912d5b6ed4bSVasumathi Sundaram - Sun Microsystems &ipif->ipif_v6lcl_addr);
2913d5b6ed4bSVasumathi Sundaram - Sun Microsystems af = AF_INET6;
2914d5b6ed4bSVasumathi Sundaram - Sun Microsystems } else {
2915d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_snprintf(addrstr, sizeof (addrstr), "%I",
2916d5b6ed4bSVasumathi Sundaram - Sun Microsystems V4_PART_OF_V6((ipif->ipif_v6lcl_addr)));
2917d5b6ed4bSVasumathi Sundaram - Sun Microsystems af = AF_INET;
2918d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2919d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2920d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (verbose) {
2921d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%-?p %-10s %3d %-?p %-8s %-30s\n",
2922d5b6ed4bSVasumathi Sundaram - Sun Microsystems addr, buf, cnt, ipif->ipif_ill,
2923d5b6ed4bSVasumathi Sundaram - Sun Microsystems sflagsbuf, flagsbuf);
2924d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_snprintf(sbuf, sizeof (sbuf), "%*s %12s",
2925d5b6ed4bSVasumathi Sundaram - Sun Microsystems sizeof (uintptr_t) * 2, "", "");
2926d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%s |\n%s +---> %4d %-15s "
2927d5b6ed4bSVasumathi Sundaram - Sun Microsystems "Active consistent reader cnt\n",
2928d5b6ed4bSVasumathi Sundaram - Sun Microsystems sbuf, sbuf, ipif->ipif_refcnt, "ipif_refcnt");
2929d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%-s/%d\n",
2930d5b6ed4bSVasumathi Sundaram - Sun Microsystems addrstr, mask_to_prefixlen(af, &ipif->ipif_v6net_mask));
2931d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (ipifcb->ill.ill_isv6) {
2932d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%-N\n", &ipif->ipif_v6brd_addr);
2933d5b6ed4bSVasumathi Sundaram - Sun Microsystems } else {
2934d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%-I\n",
2935d5b6ed4bSVasumathi Sundaram - Sun Microsystems V4_PART_OF_V6((ipif->ipif_v6brd_addr)));
2936d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2937d5b6ed4bSVasumathi Sundaram - Sun Microsystems } else {
2938d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%-?p %-10s %6d %-?p %-8s %-30s\n",
2939d5b6ed4bSVasumathi Sundaram - Sun Microsystems addr, buf, cnt, ipif->ipif_ill,
2940d5b6ed4bSVasumathi Sundaram - Sun Microsystems sflagsbuf, flagsbuf);
2941d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%-s/%d\n",
2942d5b6ed4bSVasumathi Sundaram - Sun Microsystems addrstr, mask_to_prefixlen(af, &ipif->ipif_v6net_mask));
2943d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2944d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2945d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
2946d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2947d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2948d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
ipif(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)2949d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipif(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2950d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
2951d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipif_t ipif;
2952d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipif_cbdata_t id;
2953d5b6ed4bSVasumathi Sundaram - Sun Microsystems int ipversion = 0;
2954d5b6ed4bSVasumathi Sundaram - Sun Microsystems const char *opt_P = NULL;
2955d5b6ed4bSVasumathi Sundaram - Sun Microsystems uint_t verbose = FALSE;
2956d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2957d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_getopts(argc, argv,
2958d5b6ed4bSVasumathi Sundaram - Sun Microsystems 'v', MDB_OPT_SETBITS, TRUE, &verbose,
2959d5b6ed4bSVasumathi Sundaram - Sun Microsystems 'P', MDB_OPT_STR, &opt_P, NULL) != argc)
2960d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (DCMD_USAGE);
2961d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2962d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (opt_P != NULL) {
2963d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (strcmp("v4", opt_P) == 0) {
2964d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipversion = IPV4_VERSION;
2965d5b6ed4bSVasumathi Sundaram - Sun Microsystems } else if (strcmp("v6", opt_P) == 0) {
2966d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipversion = IPV6_VERSION;
2967d5b6ed4bSVasumathi Sundaram - Sun Microsystems } else {
2968d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("invalid protocol '%s'\n", opt_P);
2969d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (DCMD_USAGE);
2970d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2971d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2972d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2973d5b6ed4bSVasumathi Sundaram - Sun Microsystems id.verbose = verbose;
2974d5b6ed4bSVasumathi Sundaram - Sun Microsystems id.ipif_ipversion = ipversion;
2975d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2976d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (flags & DCMD_ADDRSPEC) {
2977d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_vread(&ipif, sizeof (ipif_t), addr) == -1) {
2978d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("failed to read ipif at %p\n", addr);
2979d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (DCMD_ERR);
2980d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2981d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipif_header(verbose);
2982d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_vread(&id.ill, sizeof (ill_t),
2983d5b6ed4bSVasumathi Sundaram - Sun Microsystems (uintptr_t)ipif.ipif_ill) == -1) {
2984d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("failed to read ill at %p", ipif.ipif_ill);
2985d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
2986d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2987d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (ipif_format(addr, &ipif, &id));
2988d5b6ed4bSVasumathi Sundaram - Sun Microsystems } else {
2989d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipif_header(verbose);
2990d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_walk("ipif", (mdb_walk_cb_t)ipif_cb, &id) == -1) {
2991d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("failed to walk ipifs\n");
2992d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (DCMD_ERR);
2993d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2994d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2995d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (DCMD_OK);
2996d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
2997d5b6ed4bSVasumathi Sundaram - Sun Microsystems
2998d5b6ed4bSVasumathi Sundaram - Sun Microsystems static void
ipif_help(void)2999d5b6ed4bSVasumathi Sundaram - Sun Microsystems ipif_help(void)
3000d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
3001d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("Prints the following fields: ipif ptr, name, "
3002d5b6ed4bSVasumathi Sundaram - Sun Microsystems "count, ill ptr, state flags and ipif flags.\n"
3003d5b6ed4bSVasumathi Sundaram - Sun Microsystems "The count field is a sum of individual refcnts and is expanded "
3004d5b6ed4bSVasumathi Sundaram - Sun Microsystems "with the -v option.\n"
3005d5b6ed4bSVasumathi Sundaram - Sun Microsystems "The flags field shows the following:"
3006d5b6ed4bSVasumathi Sundaram - Sun Microsystems "\n\tUNN -> UNNUMBERED, DHCP -> DHCPRUNNING, PRIV -> PRIVATE, "
3007d5b6ed4bSVasumathi Sundaram - Sun Microsystems "\n\tNOXMT -> NOXMIT, NOLCL -> NOLOCAL, DEPR -> DEPRECATED, "
3008d5b6ed4bSVasumathi Sundaram - Sun Microsystems "\n\tPREF -> PREFERRED, TEMP -> TEMPORARY, ACONF -> ADDRCONF, "
3009d5b6ed4bSVasumathi Sundaram - Sun Microsystems "\n\tANY -> ANYCAST, NFAIL -> NOFAILOVER, "
3010d5b6ed4bSVasumathi Sundaram - Sun Microsystems "\n\tADR -> ipif_addr_ready, MU -> ipif_multicast_up, "
3011d5b6ed4bSVasumathi Sundaram - Sun Microsystems "\n\tWU -> ipif_was_up, WD -> ipif_was_dup, "
3012d5b6ed4bSVasumathi Sundaram - Sun Microsystems "JA -> ipif_joined_allhosts.\n\n");
3013d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("Options:\n");
3014d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("\t-P v4 | v6"
3015d5b6ed4bSVasumathi Sundaram - Sun Microsystems "\tfilter ipif structures on ills for the specified protocol\n");
3016d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3017d5b6ed4bSVasumathi Sundaram - Sun Microsystems
3018d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
conn_status_walk_fanout(uintptr_t addr,mdb_walk_state_t * wsp,const char * walkname)3019d5b6ed4bSVasumathi Sundaram - Sun Microsystems conn_status_walk_fanout(uintptr_t addr, mdb_walk_state_t *wsp,
3020d5b6ed4bSVasumathi Sundaram - Sun Microsystems const char *walkname)
3021d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
3022d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_pwalk(walkname, wsp->walk_callback, wsp->walk_cbdata,
3023d5b6ed4bSVasumathi Sundaram - Sun Microsystems addr) == -1) {
3024d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("couldn't walk '%s' at %p", walkname, addr);
3025d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_ERR);
3026d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3027d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
3028d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3029d5b6ed4bSVasumathi Sundaram - Sun Microsystems
3030d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
conn_status_walk_step(mdb_walk_state_t * wsp)3031d5b6ed4bSVasumathi Sundaram - Sun Microsystems conn_status_walk_step(mdb_walk_state_t *wsp)
3032d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
3033d5b6ed4bSVasumathi Sundaram - Sun Microsystems uintptr_t addr = wsp->walk_addr;
3034d5b6ed4bSVasumathi Sundaram - Sun Microsystems
3035d5b6ed4bSVasumathi Sundaram - Sun Microsystems (void) conn_status_walk_fanout(addr, wsp, "udp_hash");
3036d5b6ed4bSVasumathi Sundaram - Sun Microsystems (void) conn_status_walk_fanout(addr, wsp, "conn_hash");
3037d5b6ed4bSVasumathi Sundaram - Sun Microsystems (void) conn_status_walk_fanout(addr, wsp, "bind_hash");
3038d5b6ed4bSVasumathi Sundaram - Sun Microsystems (void) conn_status_walk_fanout(addr, wsp, "proto_hash");
3039d5b6ed4bSVasumathi Sundaram - Sun Microsystems (void) conn_status_walk_fanout(addr, wsp, "proto_v6_hash");
3040d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
3041d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3042d5b6ed4bSVasumathi Sundaram - Sun Microsystems
3043d5b6ed4bSVasumathi Sundaram - Sun Microsystems /* ARGSUSED */
3044d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
conn_status_cb(uintptr_t addr,const void * walk_data,void * private)3045d5b6ed4bSVasumathi Sundaram - Sun Microsystems conn_status_cb(uintptr_t addr, const void *walk_data,
3046d5b6ed4bSVasumathi Sundaram - Sun Microsystems void *private)
3047d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
3048d5b6ed4bSVasumathi Sundaram - Sun Microsystems netstack_t nss;
3049d5b6ed4bSVasumathi Sundaram - Sun Microsystems char src_addrstr[INET6_ADDRSTRLEN];
3050d5b6ed4bSVasumathi Sundaram - Sun Microsystems char rem_addrstr[INET6_ADDRSTRLEN];
3051d5b6ed4bSVasumathi Sundaram - Sun Microsystems const ipcl_hash_walk_data_t *iw = walk_data;
3052d5b6ed4bSVasumathi Sundaram - Sun Microsystems conn_t *conn = iw->conn;
3053d5b6ed4bSVasumathi Sundaram - Sun Microsystems
3054d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_vread(conn, sizeof (conn_t), addr) == -1) {
3055d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("failed to read conn_t at %p", addr);
3056d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_ERR);
3057d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3058d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_vread(&nss, sizeof (nss),
3059d5b6ed4bSVasumathi Sundaram - Sun Microsystems (uintptr_t)conn->conn_netstack) == -1) {
3060d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("failed to read netstack_t %p",
3061d5b6ed4bSVasumathi Sundaram - Sun Microsystems conn->conn_netstack);
3062d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_ERR);
3063d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3064d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%-?p %-?p %?d %?d\n", addr, conn->conn_wq,
3065d5b6ed4bSVasumathi Sundaram - Sun Microsystems nss.netstack_stackid, conn->conn_zoneid);
3066d5b6ed4bSVasumathi Sundaram - Sun Microsystems
3067bd670b35SErik Nordmark if (conn->conn_family == AF_INET6) {
3068d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_snprintf(src_addrstr, sizeof (rem_addrstr), "%N",
3069bd670b35SErik Nordmark &conn->conn_laddr_v6);
3070d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_snprintf(rem_addrstr, sizeof (rem_addrstr), "%N",
3071bd670b35SErik Nordmark &conn->conn_faddr_v6);
3072d5b6ed4bSVasumathi Sundaram - Sun Microsystems } else {
3073d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_snprintf(src_addrstr, sizeof (src_addrstr), "%I",
3074bd670b35SErik Nordmark V4_PART_OF_V6((conn->conn_laddr_v6)));
3075d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_snprintf(rem_addrstr, sizeof (rem_addrstr), "%I",
3076bd670b35SErik Nordmark V4_PART_OF_V6((conn->conn_faddr_v6)));
3077d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3078d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%s:%-5d\n%s:%-5d\n",
3079d5b6ed4bSVasumathi Sundaram - Sun Microsystems src_addrstr, conn->conn_lport, rem_addrstr, conn->conn_fport);
3080d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
3081d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3082d5b6ed4bSVasumathi Sundaram - Sun Microsystems
3083d5b6ed4bSVasumathi Sundaram - Sun Microsystems static void
conn_header(void)3084d5b6ed4bSVasumathi Sundaram - Sun Microsystems conn_header(void)
3085d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
3086d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%-?s %-?s %?s %?s\n%s\n%s\n",
3087d5b6ed4bSVasumathi Sundaram - Sun Microsystems "ADDR", "WQ", "STACK", "ZONE", "SRC:PORT", "DEST:PORT");
3088d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%<u>%80s%</u>\n", "");
3089d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3090d5b6ed4bSVasumathi Sundaram - Sun Microsystems
3091d5b6ed4bSVasumathi Sundaram - Sun Microsystems /*ARGSUSED*/
3092d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
conn_status(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)3093d5b6ed4bSVasumathi Sundaram - Sun Microsystems conn_status(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3094d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
3095d5b6ed4bSVasumathi Sundaram - Sun Microsystems conn_header();
3096d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (flags & DCMD_ADDRSPEC) {
3097d5b6ed4bSVasumathi Sundaram - Sun Microsystems (void) conn_status_cb(addr, NULL, NULL);
3098d5b6ed4bSVasumathi Sundaram - Sun Microsystems } else {
3099d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_walk("conn_status", (mdb_walk_cb_t)conn_status_cb,
3100d5b6ed4bSVasumathi Sundaram - Sun Microsystems NULL) == -1) {
3101d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("failed to walk conn_fanout");
3102d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (DCMD_ERR);
3103d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3104d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3105d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (DCMD_OK);
3106d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3107d5b6ed4bSVasumathi Sundaram - Sun Microsystems
3108d5b6ed4bSVasumathi Sundaram - Sun Microsystems static void
conn_status_help(void)3109d5b6ed4bSVasumathi Sundaram - Sun Microsystems conn_status_help(void)
3110d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
3111d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("Prints conn_t structures from the following hash tables: "
3112d5b6ed4bSVasumathi Sundaram - Sun Microsystems "\n\tips_ipcl_udp_fanout\n\tips_ipcl_bind_fanout"
3113bd670b35SErik Nordmark "\n\tips_ipcl_conn_fanout\n\tips_ipcl_proto_fanout_v4"
3114d5b6ed4bSVasumathi Sundaram - Sun Microsystems "\n\tips_ipcl_proto_fanout_v6\n");
3115d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3116d5b6ed4bSVasumathi Sundaram - Sun Microsystems
3117d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
srcid_walk_step(mdb_walk_state_t * wsp)3118d5b6ed4bSVasumathi Sundaram - Sun Microsystems srcid_walk_step(mdb_walk_state_t *wsp)
3119d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
3120d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_pwalk("srcid_list", wsp->walk_callback, wsp->walk_cbdata,
3121d5b6ed4bSVasumathi Sundaram - Sun Microsystems wsp->walk_addr) == -1) {
3122d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("can't walk 'srcid_list'");
3123d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_ERR);
3124d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3125d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
3126d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3127d5b6ed4bSVasumathi Sundaram - Sun Microsystems
3128d5b6ed4bSVasumathi Sundaram - Sun Microsystems /* ARGSUSED */
3129d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
srcid_status_cb(uintptr_t addr,const void * walk_data,void * private)3130d5b6ed4bSVasumathi Sundaram - Sun Microsystems srcid_status_cb(uintptr_t addr, const void *walk_data,
3131d5b6ed4bSVasumathi Sundaram - Sun Microsystems void *private)
3132d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
3133d5b6ed4bSVasumathi Sundaram - Sun Microsystems srcid_map_t smp;
3134d5b6ed4bSVasumathi Sundaram - Sun Microsystems
3135d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_vread(&smp, sizeof (srcid_map_t), addr) == -1) {
3136d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("failed to read srcid_map at %p", addr);
3137d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_ERR);
3138d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3139d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%-?p %3d %4d %6d %N\n",
3140d5b6ed4bSVasumathi Sundaram - Sun Microsystems addr, smp.sm_srcid, smp.sm_zoneid, smp.sm_refcnt,
3141d5b6ed4bSVasumathi Sundaram - Sun Microsystems &smp.sm_addr);
3142d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (WALK_NEXT);
3143d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3144d5b6ed4bSVasumathi Sundaram - Sun Microsystems
3145d5b6ed4bSVasumathi Sundaram - Sun Microsystems static void
srcid_header(void)3146d5b6ed4bSVasumathi Sundaram - Sun Microsystems srcid_header(void)
3147d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
3148d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%-?s %3s %4s %6s %s\n",
3149d5b6ed4bSVasumathi Sundaram - Sun Microsystems "ADDR", "ID", "ZONE", "REFCNT", "IPADDR");
3150d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_printf("%<u>%80s%</u>\n", "");
3151d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3152d5b6ed4bSVasumathi Sundaram - Sun Microsystems
3153d5b6ed4bSVasumathi Sundaram - Sun Microsystems /*ARGSUSED*/
3154d5b6ed4bSVasumathi Sundaram - Sun Microsystems static int
srcid_status(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)3155d5b6ed4bSVasumathi Sundaram - Sun Microsystems srcid_status(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3156d5b6ed4bSVasumathi Sundaram - Sun Microsystems {
3157d5b6ed4bSVasumathi Sundaram - Sun Microsystems srcid_header();
3158d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (flags & DCMD_ADDRSPEC) {
3159d5b6ed4bSVasumathi Sundaram - Sun Microsystems (void) srcid_status_cb(addr, NULL, NULL);
3160d5b6ed4bSVasumathi Sundaram - Sun Microsystems } else {
3161d5b6ed4bSVasumathi Sundaram - Sun Microsystems if (mdb_walk("srcid", (mdb_walk_cb_t)srcid_status_cb,
3162d5b6ed4bSVasumathi Sundaram - Sun Microsystems NULL) == -1) {
3163d5b6ed4bSVasumathi Sundaram - Sun Microsystems mdb_warn("failed to walk srcid_map");
3164d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (DCMD_ERR);
3165d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3166d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3167d5b6ed4bSVasumathi Sundaram - Sun Microsystems return (DCMD_OK);
3168d5b6ed4bSVasumathi Sundaram - Sun Microsystems }
3169dbed73cbSSangeeta Misra
3170dbed73cbSSangeeta Misra static int
ilb_stacks_walk_step(mdb_walk_state_t * wsp)3171dbed73cbSSangeeta Misra ilb_stacks_walk_step(mdb_walk_state_t *wsp)
3172dbed73cbSSangeeta Misra {
3173721fffe3SKacheong Poon return (ns_walk_step(wsp, NS_ILB));
3174dbed73cbSSangeeta Misra }
3175dbed73cbSSangeeta Misra
3176dbed73cbSSangeeta Misra static int
ilb_rules_walk_init(mdb_walk_state_t * wsp)3177dbed73cbSSangeeta Misra ilb_rules_walk_init(mdb_walk_state_t *wsp)
3178dbed73cbSSangeeta Misra {
3179dbed73cbSSangeeta Misra ilb_stack_t ilbs;
3180dbed73cbSSangeeta Misra
3181dbed73cbSSangeeta Misra if (wsp->walk_addr == NULL)
3182dbed73cbSSangeeta Misra return (WALK_ERR);
3183dbed73cbSSangeeta Misra
3184dbed73cbSSangeeta Misra if (mdb_vread(&ilbs, sizeof (ilbs), wsp->walk_addr) == -1) {
3185dbed73cbSSangeeta Misra mdb_warn("failed to read ilb_stack_t at %p", wsp->walk_addr);
3186dbed73cbSSangeeta Misra return (WALK_ERR);
3187dbed73cbSSangeeta Misra }
3188dbed73cbSSangeeta Misra if ((wsp->walk_addr = (uintptr_t)ilbs.ilbs_rule_head) != NULL)
3189dbed73cbSSangeeta Misra return (WALK_NEXT);
3190dbed73cbSSangeeta Misra else
3191dbed73cbSSangeeta Misra return (WALK_DONE);
3192dbed73cbSSangeeta Misra }
3193dbed73cbSSangeeta Misra
3194dbed73cbSSangeeta Misra static int
ilb_rules_walk_step(mdb_walk_state_t * wsp)3195dbed73cbSSangeeta Misra ilb_rules_walk_step(mdb_walk_state_t *wsp)
3196dbed73cbSSangeeta Misra {
3197dbed73cbSSangeeta Misra ilb_rule_t rule;
3198dbed73cbSSangeeta Misra int status;
3199dbed73cbSSangeeta Misra
3200dbed73cbSSangeeta Misra if (mdb_vread(&rule, sizeof (rule), wsp->walk_addr) == -1) {
3201dbed73cbSSangeeta Misra mdb_warn("failed to read ilb_rule_t at %p", wsp->walk_addr);
3202dbed73cbSSangeeta Misra return (WALK_ERR);
3203dbed73cbSSangeeta Misra }
3204dbed73cbSSangeeta Misra status = wsp->walk_callback(wsp->walk_addr, &rule, wsp->walk_cbdata);
3205dbed73cbSSangeeta Misra if (status != WALK_NEXT)
3206dbed73cbSSangeeta Misra return (status);
3207dbed73cbSSangeeta Misra if ((wsp->walk_addr = (uintptr_t)rule.ir_next) == NULL)
3208dbed73cbSSangeeta Misra return (WALK_DONE);
3209dbed73cbSSangeeta Misra else
3210dbed73cbSSangeeta Misra return (WALK_NEXT);
3211dbed73cbSSangeeta Misra }
3212dbed73cbSSangeeta Misra
3213dbed73cbSSangeeta Misra static int
ilb_servers_walk_init(mdb_walk_state_t * wsp)3214dbed73cbSSangeeta Misra ilb_servers_walk_init(mdb_walk_state_t *wsp)
3215dbed73cbSSangeeta Misra {
3216dbed73cbSSangeeta Misra ilb_rule_t rule;
3217dbed73cbSSangeeta Misra
3218dbed73cbSSangeeta Misra if (wsp->walk_addr == NULL)
3219dbed73cbSSangeeta Misra return (WALK_ERR);
3220dbed73cbSSangeeta Misra
3221dbed73cbSSangeeta Misra if (mdb_vread(&rule, sizeof (rule), wsp->walk_addr) == -1) {
3222dbed73cbSSangeeta Misra mdb_warn("failed to read ilb_rule_t at %p", wsp->walk_addr);
3223dbed73cbSSangeeta Misra return (WALK_ERR);
3224dbed73cbSSangeeta Misra }
3225dbed73cbSSangeeta Misra if ((wsp->walk_addr = (uintptr_t)rule.ir_servers) != NULL)
3226dbed73cbSSangeeta Misra return (WALK_NEXT);
3227dbed73cbSSangeeta Misra else
3228dbed73cbSSangeeta Misra return (WALK_DONE);
3229dbed73cbSSangeeta Misra }
3230dbed73cbSSangeeta Misra
3231dbed73cbSSangeeta Misra static int
ilb_servers_walk_step(mdb_walk_state_t * wsp)3232dbed73cbSSangeeta Misra ilb_servers_walk_step(mdb_walk_state_t *wsp)
3233dbed73cbSSangeeta Misra {
3234dbed73cbSSangeeta Misra ilb_server_t server;
3235dbed73cbSSangeeta Misra int status;
3236dbed73cbSSangeeta Misra
3237dbed73cbSSangeeta Misra if (mdb_vread(&server, sizeof (server), wsp->walk_addr) == -1) {
3238dbed73cbSSangeeta Misra mdb_warn("failed to read ilb_server_t at %p", wsp->walk_addr);
3239dbed73cbSSangeeta Misra return (WALK_ERR);
3240dbed73cbSSangeeta Misra }
3241dbed73cbSSangeeta Misra status = wsp->walk_callback(wsp->walk_addr, &server, wsp->walk_cbdata);
3242dbed73cbSSangeeta Misra if (status != WALK_NEXT)
3243dbed73cbSSangeeta Misra return (status);
3244dbed73cbSSangeeta Misra if ((wsp->walk_addr = (uintptr_t)server.iser_next) == NULL)
3245dbed73cbSSangeeta Misra return (WALK_DONE);
3246dbed73cbSSangeeta Misra else
3247dbed73cbSSangeeta Misra return (WALK_NEXT);
3248dbed73cbSSangeeta Misra }
3249dbed73cbSSangeeta Misra
3250dbed73cbSSangeeta Misra /*
3251dbed73cbSSangeeta Misra * Helper structure for ilb_nat_src walker. It stores the current index of the
3252dbed73cbSSangeeta Misra * nat src table.
3253dbed73cbSSangeeta Misra */
3254dbed73cbSSangeeta Misra typedef struct {
3255dbed73cbSSangeeta Misra ilb_stack_t ilbs;
3256dbed73cbSSangeeta Misra int idx;
3257dbed73cbSSangeeta Misra } ilb_walk_t;
3258dbed73cbSSangeeta Misra
3259dbed73cbSSangeeta Misra /* Copy from list.c */
3260dbed73cbSSangeeta Misra #define list_object(a, node) ((void *)(((char *)node) - (a)->list_offset))
3261dbed73cbSSangeeta Misra
3262dbed73cbSSangeeta Misra static int
ilb_nat_src_walk_init(mdb_walk_state_t * wsp)3263dbed73cbSSangeeta Misra ilb_nat_src_walk_init(mdb_walk_state_t *wsp)
3264dbed73cbSSangeeta Misra {
3265dbed73cbSSangeeta Misra int i;
3266dbed73cbSSangeeta Misra ilb_walk_t *ns_walk;
3267dbed73cbSSangeeta Misra ilb_nat_src_entry_t *entry = NULL;
3268dbed73cbSSangeeta Misra
3269dbed73cbSSangeeta Misra if (wsp->walk_addr == NULL)
3270dbed73cbSSangeeta Misra return (WALK_ERR);
3271dbed73cbSSangeeta Misra
3272dbed73cbSSangeeta Misra ns_walk = mdb_alloc(sizeof (ilb_walk_t), UM_SLEEP);
3273dbed73cbSSangeeta Misra if (mdb_vread(&ns_walk->ilbs, sizeof (ns_walk->ilbs),
3274dbed73cbSSangeeta Misra wsp->walk_addr) == -1) {
3275dbed73cbSSangeeta Misra mdb_warn("failed to read ilb_stack_t at %p", wsp->walk_addr);
3276dbed73cbSSangeeta Misra mdb_free(ns_walk, sizeof (ilb_walk_t));
3277dbed73cbSSangeeta Misra return (WALK_ERR);
3278dbed73cbSSangeeta Misra }
3279dbed73cbSSangeeta Misra
3280dbed73cbSSangeeta Misra if (ns_walk->ilbs.ilbs_nat_src == NULL) {
3281dbed73cbSSangeeta Misra mdb_free(ns_walk, sizeof (ilb_walk_t));
3282dbed73cbSSangeeta Misra return (WALK_DONE);
3283dbed73cbSSangeeta Misra }
3284dbed73cbSSangeeta Misra
3285dbed73cbSSangeeta Misra wsp->walk_data = ns_walk;
3286dbed73cbSSangeeta Misra for (i = 0; i < ns_walk->ilbs.ilbs_nat_src_hash_size; i++) {
3287dbed73cbSSangeeta Misra list_t head;
3288dbed73cbSSangeeta Misra char *khead;
3289dbed73cbSSangeeta Misra
3290dbed73cbSSangeeta Misra /* Read in the nsh_head in the i-th element of the array. */
3291dbed73cbSSangeeta Misra khead = (char *)ns_walk->ilbs.ilbs_nat_src + i *
3292dbed73cbSSangeeta Misra sizeof (ilb_nat_src_hash_t);
3293dbed73cbSSangeeta Misra if (mdb_vread(&head, sizeof (list_t), (uintptr_t)khead) == -1) {
3294dbed73cbSSangeeta Misra mdb_warn("failed to read ilbs_nat_src at %p\n", khead);
3295dbed73cbSSangeeta Misra return (WALK_ERR);
3296dbed73cbSSangeeta Misra }
3297dbed73cbSSangeeta Misra
3298dbed73cbSSangeeta Misra /*
3299dbed73cbSSangeeta Misra * Note that list_next points to a kernel address and we need
3300dbed73cbSSangeeta Misra * to compare list_next with the kernel address of the list
3301dbed73cbSSangeeta Misra * head. So we need to calculate the address manually.
3302dbed73cbSSangeeta Misra */
3303dbed73cbSSangeeta Misra if ((char *)head.list_head.list_next != khead +
3304dbed73cbSSangeeta Misra offsetof(list_t, list_head)) {
3305dbed73cbSSangeeta Misra entry = list_object(&head, head.list_head.list_next);
3306dbed73cbSSangeeta Misra break;
3307dbed73cbSSangeeta Misra }
3308dbed73cbSSangeeta Misra }
3309dbed73cbSSangeeta Misra
3310dbed73cbSSangeeta Misra if (entry == NULL)
3311dbed73cbSSangeeta Misra return (WALK_DONE);
3312dbed73cbSSangeeta Misra
3313dbed73cbSSangeeta Misra wsp->walk_addr = (uintptr_t)entry;
3314dbed73cbSSangeeta Misra ns_walk->idx = i;
3315dbed73cbSSangeeta Misra return (WALK_NEXT);
3316dbed73cbSSangeeta Misra }
3317dbed73cbSSangeeta Misra
3318dbed73cbSSangeeta Misra static int
ilb_nat_src_walk_step(mdb_walk_state_t * wsp)3319dbed73cbSSangeeta Misra ilb_nat_src_walk_step(mdb_walk_state_t *wsp)
3320dbed73cbSSangeeta Misra {
3321dbed73cbSSangeeta Misra int status;
3322dbed73cbSSangeeta Misra ilb_nat_src_entry_t entry, *next_entry;
3323dbed73cbSSangeeta Misra ilb_walk_t *ns_walk;
3324dbed73cbSSangeeta Misra ilb_stack_t *ilbs;
3325dbed73cbSSangeeta Misra list_t head;
3326dbed73cbSSangeeta Misra char *khead;
3327dbed73cbSSangeeta Misra int i;
3328dbed73cbSSangeeta Misra
3329dbed73cbSSangeeta Misra if (mdb_vread(&entry, sizeof (ilb_nat_src_entry_t),
3330dbed73cbSSangeeta Misra wsp->walk_addr) == -1) {
3331dbed73cbSSangeeta Misra mdb_warn("failed to read ilb_nat_src_entry_t at %p",
3332dbed73cbSSangeeta Misra wsp->walk_addr);
3333dbed73cbSSangeeta Misra return (WALK_ERR);
3334dbed73cbSSangeeta Misra }
3335dbed73cbSSangeeta Misra status = wsp->walk_callback(wsp->walk_addr, &entry, wsp->walk_cbdata);
3336dbed73cbSSangeeta Misra if (status != WALK_NEXT)
3337dbed73cbSSangeeta Misra return (status);
3338dbed73cbSSangeeta Misra
3339dbed73cbSSangeeta Misra ns_walk = (ilb_walk_t *)wsp->walk_data;
3340dbed73cbSSangeeta Misra ilbs = &ns_walk->ilbs;
3341dbed73cbSSangeeta Misra i = ns_walk->idx;
3342dbed73cbSSangeeta Misra
3343dbed73cbSSangeeta Misra /* Read in the nsh_head in the i-th element of the array. */
3344dbed73cbSSangeeta Misra khead = (char *)ilbs->ilbs_nat_src + i * sizeof (ilb_nat_src_hash_t);
3345dbed73cbSSangeeta Misra if (mdb_vread(&head, sizeof (list_t), (uintptr_t)khead) == -1) {
3346dbed73cbSSangeeta Misra mdb_warn("failed to read ilbs_nat_src at %p\n", khead);
3347dbed73cbSSangeeta Misra return (WALK_ERR);
3348dbed73cbSSangeeta Misra }
3349dbed73cbSSangeeta Misra
3350dbed73cbSSangeeta Misra /*
3351dbed73cbSSangeeta Misra * Check if there is still entry in the current list.
3352dbed73cbSSangeeta Misra *
3353dbed73cbSSangeeta Misra * Note that list_next points to a kernel address and we need to
3354dbed73cbSSangeeta Misra * compare list_next with the kernel address of the list head.
3355dbed73cbSSangeeta Misra * So we need to calculate the address manually.
3356dbed73cbSSangeeta Misra */
3357dbed73cbSSangeeta Misra if ((char *)entry.nse_link.list_next != khead + offsetof(list_t,
3358dbed73cbSSangeeta Misra list_head)) {
3359dbed73cbSSangeeta Misra wsp->walk_addr = (uintptr_t)list_object(&head,
3360dbed73cbSSangeeta Misra entry.nse_link.list_next);
3361dbed73cbSSangeeta Misra return (WALK_NEXT);
3362dbed73cbSSangeeta Misra }
3363dbed73cbSSangeeta Misra
3364dbed73cbSSangeeta Misra /* Start with the next bucket in the array. */
3365dbed73cbSSangeeta Misra next_entry = NULL;
3366dbed73cbSSangeeta Misra for (i++; i < ilbs->ilbs_nat_src_hash_size; i++) {
3367dbed73cbSSangeeta Misra khead = (char *)ilbs->ilbs_nat_src + i *
3368dbed73cbSSangeeta Misra sizeof (ilb_nat_src_hash_t);
3369dbed73cbSSangeeta Misra if (mdb_vread(&head, sizeof (list_t), (uintptr_t)khead) == -1) {
3370dbed73cbSSangeeta Misra mdb_warn("failed to read ilbs_nat_src at %p\n", khead);
3371dbed73cbSSangeeta Misra return (WALK_ERR);
3372dbed73cbSSangeeta Misra }
3373dbed73cbSSangeeta Misra
3374dbed73cbSSangeeta Misra if ((char *)head.list_head.list_next != khead +
3375dbed73cbSSangeeta Misra offsetof(list_t, list_head)) {
3376dbed73cbSSangeeta Misra next_entry = list_object(&head,
3377dbed73cbSSangeeta Misra head.list_head.list_next);
3378dbed73cbSSangeeta Misra break;
3379dbed73cbSSangeeta Misra }
3380dbed73cbSSangeeta Misra }
3381dbed73cbSSangeeta Misra
3382dbed73cbSSangeeta Misra if (next_entry == NULL)
3383dbed73cbSSangeeta Misra return (WALK_DONE);
3384dbed73cbSSangeeta Misra
3385dbed73cbSSangeeta Misra wsp->walk_addr = (uintptr_t)next_entry;
3386dbed73cbSSangeeta Misra ns_walk->idx = i;
3387dbed73cbSSangeeta Misra return (WALK_NEXT);
3388dbed73cbSSangeeta Misra }
3389dbed73cbSSangeeta Misra
3390dbed73cbSSangeeta Misra static void
ilb_common_walk_fini(mdb_walk_state_t * wsp)3391dbed73cbSSangeeta Misra ilb_common_walk_fini(mdb_walk_state_t *wsp)
3392dbed73cbSSangeeta Misra {
3393dbed73cbSSangeeta Misra ilb_walk_t *walk;
3394dbed73cbSSangeeta Misra
3395dbed73cbSSangeeta Misra walk = (ilb_walk_t *)wsp->walk_data;
3396dbed73cbSSangeeta Misra if (walk == NULL)
3397dbed73cbSSangeeta Misra return;
3398dbed73cbSSangeeta Misra mdb_free(walk, sizeof (ilb_walk_t *));
3399dbed73cbSSangeeta Misra }
3400dbed73cbSSangeeta Misra
3401dbed73cbSSangeeta Misra static int
ilb_conn_walk_init(mdb_walk_state_t * wsp)3402dbed73cbSSangeeta Misra ilb_conn_walk_init(mdb_walk_state_t *wsp)
3403dbed73cbSSangeeta Misra {
3404dbed73cbSSangeeta Misra int i;
3405dbed73cbSSangeeta Misra ilb_walk_t *conn_walk;
3406dbed73cbSSangeeta Misra ilb_conn_hash_t head;
3407dbed73cbSSangeeta Misra
3408dbed73cbSSangeeta Misra if (wsp->walk_addr == NULL)
3409dbed73cbSSangeeta Misra return (WALK_ERR);
3410dbed73cbSSangeeta Misra
3411dbed73cbSSangeeta Misra conn_walk = mdb_alloc(sizeof (ilb_walk_t), UM_SLEEP);
3412dbed73cbSSangeeta Misra if (mdb_vread(&conn_walk->ilbs, sizeof (conn_walk->ilbs),
3413dbed73cbSSangeeta Misra wsp->walk_addr) == -1) {
3414dbed73cbSSangeeta Misra mdb_warn("failed to read ilb_stack_t at %p", wsp->walk_addr);
3415dbed73cbSSangeeta Misra mdb_free(conn_walk, sizeof (ilb_walk_t));
3416dbed73cbSSangeeta Misra return (WALK_ERR);
3417dbed73cbSSangeeta Misra }
3418dbed73cbSSangeeta Misra
3419dbed73cbSSangeeta Misra if (conn_walk->ilbs.ilbs_c2s_conn_hash == NULL) {
3420dbed73cbSSangeeta Misra mdb_free(conn_walk, sizeof (ilb_walk_t));
3421dbed73cbSSangeeta Misra return (WALK_DONE);
3422dbed73cbSSangeeta Misra }
3423dbed73cbSSangeeta Misra
3424dbed73cbSSangeeta Misra wsp->walk_data = conn_walk;
3425dbed73cbSSangeeta Misra for (i = 0; i < conn_walk->ilbs.ilbs_conn_hash_size; i++) {
3426dbed73cbSSangeeta Misra char *khead;
3427dbed73cbSSangeeta Misra
3428dbed73cbSSangeeta Misra /* Read in the nsh_head in the i-th element of the array. */
3429dbed73cbSSangeeta Misra khead = (char *)conn_walk->ilbs.ilbs_c2s_conn_hash + i *
3430dbed73cbSSangeeta Misra sizeof (ilb_conn_hash_t);
3431dbed73cbSSangeeta Misra if (mdb_vread(&head, sizeof (ilb_conn_hash_t),
3432dbed73cbSSangeeta Misra (uintptr_t)khead) == -1) {
3433dbed73cbSSangeeta Misra mdb_warn("failed to read ilbs_c2s_conn_hash at %p\n",
3434dbed73cbSSangeeta Misra khead);
3435dbed73cbSSangeeta Misra return (WALK_ERR);
3436dbed73cbSSangeeta Misra }
3437dbed73cbSSangeeta Misra
3438dbed73cbSSangeeta Misra if (head.ilb_connp != NULL)
3439dbed73cbSSangeeta Misra break;
3440dbed73cbSSangeeta Misra }
3441dbed73cbSSangeeta Misra
3442dbed73cbSSangeeta Misra if (head.ilb_connp == NULL)
3443dbed73cbSSangeeta Misra return (WALK_DONE);
3444dbed73cbSSangeeta Misra
3445dbed73cbSSangeeta Misra wsp->walk_addr = (uintptr_t)head.ilb_connp;
3446dbed73cbSSangeeta Misra conn_walk->idx = i;
3447dbed73cbSSangeeta Misra return (WALK_NEXT);
3448dbed73cbSSangeeta Misra }
3449dbed73cbSSangeeta Misra
3450dbed73cbSSangeeta Misra static int
ilb_conn_walk_step(mdb_walk_state_t * wsp)3451dbed73cbSSangeeta Misra ilb_conn_walk_step(mdb_walk_state_t *wsp)
3452dbed73cbSSangeeta Misra {
3453dbed73cbSSangeeta Misra int status;
3454dbed73cbSSangeeta Misra ilb_conn_t conn;
3455dbed73cbSSangeeta Misra ilb_walk_t *conn_walk;
3456dbed73cbSSangeeta Misra ilb_stack_t *ilbs;
3457dbed73cbSSangeeta Misra ilb_conn_hash_t head;
3458dbed73cbSSangeeta Misra char *khead;
3459dbed73cbSSangeeta Misra int i;
3460dbed73cbSSangeeta Misra
3461dbed73cbSSangeeta Misra if (mdb_vread(&conn, sizeof (ilb_conn_t), wsp->walk_addr) == -1) {
3462dbed73cbSSangeeta Misra mdb_warn("failed to read ilb_conn_t at %p", wsp->walk_addr);
3463dbed73cbSSangeeta Misra return (WALK_ERR);
3464dbed73cbSSangeeta Misra }
3465dbed73cbSSangeeta Misra
3466dbed73cbSSangeeta Misra status = wsp->walk_callback(wsp->walk_addr, &conn, wsp->walk_cbdata);
3467dbed73cbSSangeeta Misra if (status != WALK_NEXT)
3468dbed73cbSSangeeta Misra return (status);
3469dbed73cbSSangeeta Misra
3470dbed73cbSSangeeta Misra conn_walk = (ilb_walk_t *)wsp->walk_data;
3471dbed73cbSSangeeta Misra ilbs = &conn_walk->ilbs;
3472dbed73cbSSangeeta Misra i = conn_walk->idx;
3473dbed73cbSSangeeta Misra
3474dbed73cbSSangeeta Misra /* Check if there is still entry in the current list. */
3475dbed73cbSSangeeta Misra if (conn.conn_c2s_next != NULL) {
3476dbed73cbSSangeeta Misra wsp->walk_addr = (uintptr_t)conn.conn_c2s_next;
3477dbed73cbSSangeeta Misra return (WALK_NEXT);
3478dbed73cbSSangeeta Misra }
3479dbed73cbSSangeeta Misra
3480dbed73cbSSangeeta Misra /* Start with the next bucket in the array. */
3481dbed73cbSSangeeta Misra for (i++; i < ilbs->ilbs_conn_hash_size; i++) {
3482dbed73cbSSangeeta Misra khead = (char *)ilbs->ilbs_c2s_conn_hash + i *
3483dbed73cbSSangeeta Misra sizeof (ilb_conn_hash_t);
3484dbed73cbSSangeeta Misra if (mdb_vread(&head, sizeof (ilb_conn_hash_t),
3485dbed73cbSSangeeta Misra (uintptr_t)khead) == -1) {
3486dbed73cbSSangeeta Misra mdb_warn("failed to read ilbs_c2s_conn_hash at %p\n",
3487dbed73cbSSangeeta Misra khead);
3488dbed73cbSSangeeta Misra return (WALK_ERR);
3489dbed73cbSSangeeta Misra }
3490dbed73cbSSangeeta Misra
3491dbed73cbSSangeeta Misra if (head.ilb_connp != NULL)
3492dbed73cbSSangeeta Misra break;
3493dbed73cbSSangeeta Misra }
3494dbed73cbSSangeeta Misra
3495dbed73cbSSangeeta Misra if (head.ilb_connp == NULL)
3496dbed73cbSSangeeta Misra return (WALK_DONE);
3497dbed73cbSSangeeta Misra
3498dbed73cbSSangeeta Misra wsp->walk_addr = (uintptr_t)head.ilb_connp;
3499dbed73cbSSangeeta Misra conn_walk->idx = i;
3500dbed73cbSSangeeta Misra return (WALK_NEXT);
3501dbed73cbSSangeeta Misra }
3502dbed73cbSSangeeta Misra
3503dbed73cbSSangeeta Misra static int
ilb_sticky_walk_init(mdb_walk_state_t * wsp)3504dbed73cbSSangeeta Misra ilb_sticky_walk_init(mdb_walk_state_t *wsp)
3505dbed73cbSSangeeta Misra {
3506dbed73cbSSangeeta Misra int i;
3507dbed73cbSSangeeta Misra ilb_walk_t *sticky_walk;
3508dbed73cbSSangeeta Misra ilb_sticky_t *st = NULL;
3509dbed73cbSSangeeta Misra
3510dbed73cbSSangeeta Misra if (wsp->walk_addr == NULL)
3511dbed73cbSSangeeta Misra return (WALK_ERR);
3512dbed73cbSSangeeta Misra
3513dbed73cbSSangeeta Misra sticky_walk = mdb_alloc(sizeof (ilb_walk_t), UM_SLEEP);
3514dbed73cbSSangeeta Misra if (mdb_vread(&sticky_walk->ilbs, sizeof (sticky_walk->ilbs),
3515dbed73cbSSangeeta Misra wsp->walk_addr) == -1) {
3516dbed73cbSSangeeta Misra mdb_warn("failed to read ilb_stack_t at %p", wsp->walk_addr);
3517dbed73cbSSangeeta Misra mdb_free(sticky_walk, sizeof (ilb_walk_t));
3518dbed73cbSSangeeta Misra return (WALK_ERR);
3519dbed73cbSSangeeta Misra }
3520dbed73cbSSangeeta Misra
3521dbed73cbSSangeeta Misra if (sticky_walk->ilbs.ilbs_sticky_hash == NULL) {
3522dbed73cbSSangeeta Misra mdb_free(sticky_walk, sizeof (ilb_walk_t));
3523dbed73cbSSangeeta Misra return (WALK_DONE);
3524dbed73cbSSangeeta Misra }
3525dbed73cbSSangeeta Misra
3526dbed73cbSSangeeta Misra wsp->walk_data = sticky_walk;
3527dbed73cbSSangeeta Misra for (i = 0; i < sticky_walk->ilbs.ilbs_sticky_hash_size; i++) {
3528dbed73cbSSangeeta Misra list_t head;
3529dbed73cbSSangeeta Misra char *khead;
3530dbed73cbSSangeeta Misra
3531dbed73cbSSangeeta Misra /* Read in the nsh_head in the i-th element of the array. */
3532dbed73cbSSangeeta Misra khead = (char *)sticky_walk->ilbs.ilbs_sticky_hash + i *
3533dbed73cbSSangeeta Misra sizeof (ilb_sticky_hash_t);
3534dbed73cbSSangeeta Misra if (mdb_vread(&head, sizeof (list_t), (uintptr_t)khead) == -1) {
3535dbed73cbSSangeeta Misra mdb_warn("failed to read ilbs_sticky_hash at %p\n",
3536dbed73cbSSangeeta Misra khead);
3537dbed73cbSSangeeta Misra return (WALK_ERR);
3538dbed73cbSSangeeta Misra }
3539dbed73cbSSangeeta Misra
3540dbed73cbSSangeeta Misra /*
3541dbed73cbSSangeeta Misra * Note that list_next points to a kernel address and we need
3542dbed73cbSSangeeta Misra * to compare list_next with the kernel address of the list
3543dbed73cbSSangeeta Misra * head. So we need to calculate the address manually.
3544dbed73cbSSangeeta Misra */
3545dbed73cbSSangeeta Misra if ((char *)head.list_head.list_next != khead +
3546dbed73cbSSangeeta Misra offsetof(list_t, list_head)) {
3547dbed73cbSSangeeta Misra st = list_object(&head, head.list_head.list_next);
3548dbed73cbSSangeeta Misra break;
3549dbed73cbSSangeeta Misra }
3550dbed73cbSSangeeta Misra }
3551dbed73cbSSangeeta Misra
3552dbed73cbSSangeeta Misra if (st == NULL)
3553dbed73cbSSangeeta Misra return (WALK_DONE);
3554dbed73cbSSangeeta Misra
3555dbed73cbSSangeeta Misra wsp->walk_addr = (uintptr_t)st;
3556dbed73cbSSangeeta Misra sticky_walk->idx = i;
3557dbed73cbSSangeeta Misra return (WALK_NEXT);
3558dbed73cbSSangeeta Misra }
3559dbed73cbSSangeeta Misra
3560dbed73cbSSangeeta Misra static int
ilb_sticky_walk_step(mdb_walk_state_t * wsp)3561dbed73cbSSangeeta Misra ilb_sticky_walk_step(mdb_walk_state_t *wsp)
3562dbed73cbSSangeeta Misra {
3563dbed73cbSSangeeta Misra int status;
3564dbed73cbSSangeeta Misra ilb_sticky_t st, *st_next;
3565dbed73cbSSangeeta Misra ilb_walk_t *sticky_walk;
3566dbed73cbSSangeeta Misra ilb_stack_t *ilbs;
3567dbed73cbSSangeeta Misra list_t head;
3568dbed73cbSSangeeta Misra char *khead;
3569dbed73cbSSangeeta Misra int i;
3570dbed73cbSSangeeta Misra
3571dbed73cbSSangeeta Misra if (mdb_vread(&st, sizeof (ilb_sticky_t), wsp->walk_addr) == -1) {
3572dbed73cbSSangeeta Misra mdb_warn("failed to read ilb_sticky_t at %p", wsp->walk_addr);
3573dbed73cbSSangeeta Misra return (WALK_ERR);
3574dbed73cbSSangeeta Misra }
3575dbed73cbSSangeeta Misra
3576dbed73cbSSangeeta Misra status = wsp->walk_callback(wsp->walk_addr, &st, wsp->walk_cbdata);
3577dbed73cbSSangeeta Misra if (status != WALK_NEXT)
3578dbed73cbSSangeeta Misra return (status);
3579dbed73cbSSangeeta Misra
3580dbed73cbSSangeeta Misra sticky_walk = (ilb_walk_t *)wsp->walk_data;
3581dbed73cbSSangeeta Misra ilbs = &sticky_walk->ilbs;
3582dbed73cbSSangeeta Misra i = sticky_walk->idx;
3583dbed73cbSSangeeta Misra
3584dbed73cbSSangeeta Misra /* Read in the nsh_head in the i-th element of the array. */
3585dbed73cbSSangeeta Misra khead = (char *)ilbs->ilbs_sticky_hash + i * sizeof (ilb_sticky_hash_t);
3586dbed73cbSSangeeta Misra if (mdb_vread(&head, sizeof (list_t), (uintptr_t)khead) == -1) {
3587dbed73cbSSangeeta Misra mdb_warn("failed to read ilbs_sticky_hash at %p\n", khead);
3588dbed73cbSSangeeta Misra return (WALK_ERR);
3589dbed73cbSSangeeta Misra }
3590dbed73cbSSangeeta Misra
3591dbed73cbSSangeeta Misra /*
3592dbed73cbSSangeeta Misra * Check if there is still entry in the current list.
3593dbed73cbSSangeeta Misra *
3594dbed73cbSSangeeta Misra * Note that list_next points to a kernel address and we need to
3595dbed73cbSSangeeta Misra * compare list_next with the kernel address of the list head.
3596dbed73cbSSangeeta Misra * So we need to calculate the address manually.
3597dbed73cbSSangeeta Misra */
3598dbed73cbSSangeeta Misra if ((char *)st.list.list_next != khead + offsetof(list_t,
3599dbed73cbSSangeeta Misra list_head)) {
3600dbed73cbSSangeeta Misra wsp->walk_addr = (uintptr_t)list_object(&head,
3601dbed73cbSSangeeta Misra st.list.list_next);
3602dbed73cbSSangeeta Misra return (WALK_NEXT);
3603dbed73cbSSangeeta Misra }
3604dbed73cbSSangeeta Misra
3605dbed73cbSSangeeta Misra /* Start with the next bucket in the array. */
3606dbed73cbSSangeeta Misra st_next = NULL;
3607dbed73cbSSangeeta Misra for (i++; i < ilbs->ilbs_nat_src_hash_size; i++) {
3608dbed73cbSSangeeta Misra khead = (char *)ilbs->ilbs_sticky_hash + i *
3609dbed73cbSSangeeta Misra sizeof (ilb_sticky_hash_t);
3610dbed73cbSSangeeta Misra if (mdb_vread(&head, sizeof (list_t), (uintptr_t)khead) == -1) {
3611dbed73cbSSangeeta Misra mdb_warn("failed to read ilbs_sticky_hash at %p\n",
3612dbed73cbSSangeeta Misra khead);
3613dbed73cbSSangeeta Misra return (WALK_ERR);
3614dbed73cbSSangeeta Misra }
3615dbed73cbSSangeeta Misra
3616dbed73cbSSangeeta Misra if ((char *)head.list_head.list_next != khead +
3617dbed73cbSSangeeta Misra offsetof(list_t, list_head)) {
3618dbed73cbSSangeeta Misra st_next = list_object(&head,
3619dbed73cbSSangeeta Misra head.list_head.list_next);
3620dbed73cbSSangeeta Misra break;
3621dbed73cbSSangeeta Misra }
3622dbed73cbSSangeeta Misra }
3623dbed73cbSSangeeta Misra
3624dbed73cbSSangeeta Misra if (st_next == NULL)
3625dbed73cbSSangeeta Misra return (WALK_DONE);
3626dbed73cbSSangeeta Misra
3627dbed73cbSSangeeta Misra wsp->walk_addr = (uintptr_t)st_next;
3628dbed73cbSSangeeta Misra sticky_walk->idx = i;
3629dbed73cbSSangeeta Misra return (WALK_NEXT);
3630dbed73cbSSangeeta Misra }
3631