xref: /onnv-gate/usr/src/cmd/mdb/common/modules/sctp/sctp.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <sys/types.h>
30*0Sstevel@tonic-gate #include <sys/stream.h>
31*0Sstevel@tonic-gate #include <sys/mdb_modapi.h>
32*0Sstevel@tonic-gate #include <sys/socket.h>
33*0Sstevel@tonic-gate #include <sys/list.h>
34*0Sstevel@tonic-gate #include <sys/strsun.h>
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate #include <mdb/mdb_stdlib.h>
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate #include <netinet/in.h>
39*0Sstevel@tonic-gate #include <netinet/ip6.h>
40*0Sstevel@tonic-gate #include <netinet/sctp.h>
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate #include <inet/common.h>
43*0Sstevel@tonic-gate #include <inet/ip.h>
44*0Sstevel@tonic-gate #include <inet/ip6.h>
45*0Sstevel@tonic-gate #include <inet/ipclassifier.h>
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate #include <sctp/sctp_impl.h>
48*0Sstevel@tonic-gate #include <sctp/sctp_addr.h>
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate #define	MDB_SCTP_SHOW_FLAGS	0x1
51*0Sstevel@tonic-gate #define	MDB_SCTP_DUMP_ADDRS	0x2
52*0Sstevel@tonic-gate #define	MDB_SCTP_SHOW_HASH	0x4
53*0Sstevel@tonic-gate #define	MDB_SCTP_SHOW_OUT	0x8
54*0Sstevel@tonic-gate #define	MDB_SCTP_SHOW_IN	0x10
55*0Sstevel@tonic-gate #define	MDB_SCTP_SHOW_MISC	0x20
56*0Sstevel@tonic-gate #define	MDB_SCTP_SHOW_RTT	0x40
57*0Sstevel@tonic-gate #define	MDB_SCTP_SHOW_STATS	0x80
58*0Sstevel@tonic-gate #define	MDB_SCTP_SHOW_FLOW	0x100
59*0Sstevel@tonic-gate #define	MDB_SCTP_SHOW_HDR	0x200
60*0Sstevel@tonic-gate #define	MDB_SCTP_SHOW_PMTUD	0x400
61*0Sstevel@tonic-gate #define	MDB_SCTP_SHOW_RXT	0x800
62*0Sstevel@tonic-gate #define	MDB_SCTP_SHOW_CONN	0x1000
63*0Sstevel@tonic-gate #define	MDB_SCTP_SHOW_CLOSE	0x2000
64*0Sstevel@tonic-gate #define	MDB_SCTP_SHOW_EXT	0x4000
65*0Sstevel@tonic-gate 
66*0Sstevel@tonic-gate #define	MDB_SCTP_SHOW_ALL	0xffffffff
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate uint_t sctp_conn_hash_size;
69*0Sstevel@tonic-gate static GElf_Sym sctp_list_sym;
70*0Sstevel@tonic-gate static list_t sctp_list;
71*0Sstevel@tonic-gate 
72*0Sstevel@tonic-gate /*
73*0Sstevel@tonic-gate  * Both the ill and ipif global arrays are small, so we just read
74*0Sstevel@tonic-gate  * in the whole arrays.
75*0Sstevel@tonic-gate  */
76*0Sstevel@tonic-gate static sctp_ill_hash_t local_g_ills[SCTP_ILL_HASH];
77*0Sstevel@tonic-gate static sctp_ipif_hash_t local_g_ipifs[SCTP_IPIF_HASH];
78*0Sstevel@tonic-gate 
79*0Sstevel@tonic-gate /*
80*0Sstevel@tonic-gate  * Copy from usr/src/uts/common/os/list.c.  Should we have a generic
81*0Sstevel@tonic-gate  * mdb list walker?
82*0Sstevel@tonic-gate  */
83*0Sstevel@tonic-gate #define	list_object(a, node) ((void *)(((char *)node) - (a)->list_offset))
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate /* ARGSUSED */
86*0Sstevel@tonic-gate static int
87*0Sstevel@tonic-gate sctp_faddr(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
88*0Sstevel@tonic-gate {
89*0Sstevel@tonic-gate 	sctp_faddr_t fa[1];
90*0Sstevel@tonic-gate 	char *statestr;
91*0Sstevel@tonic-gate 
92*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
93*0Sstevel@tonic-gate 		return (DCMD_USAGE);
94*0Sstevel@tonic-gate 
95*0Sstevel@tonic-gate 	if (mdb_vread(fa, sizeof (*fa), addr) == -1) {
96*0Sstevel@tonic-gate 		mdb_warn("cannot read fadder at %p", addr);
97*0Sstevel@tonic-gate 		return (DCMD_ERR);
98*0Sstevel@tonic-gate 	}
99*0Sstevel@tonic-gate 
100*0Sstevel@tonic-gate 	switch (fa->state) {
101*0Sstevel@tonic-gate 	case SCTP_FADDRS_UNREACH:
102*0Sstevel@tonic-gate 		statestr = "SCTP_FADDRS_UNREACH";
103*0Sstevel@tonic-gate 		break;
104*0Sstevel@tonic-gate 	case SCTP_FADDRS_DOWN:
105*0Sstevel@tonic-gate 		statestr = "SCTP_FADDRS_DOWN";
106*0Sstevel@tonic-gate 		break;
107*0Sstevel@tonic-gate 	case SCTP_FADDRS_ALIVE:
108*0Sstevel@tonic-gate 		statestr = "SCTP_FADDRS_ALIVE";
109*0Sstevel@tonic-gate 		break;
110*0Sstevel@tonic-gate 	case SCTP_FADDRS_UNCONFIRMED:
111*0Sstevel@tonic-gate 		statestr = "SCTP_FADDRS_UNCONFIRMED";
112*0Sstevel@tonic-gate 		break;
113*0Sstevel@tonic-gate 	default:
114*0Sstevel@tonic-gate 		statestr = "UNKNOWN STATE";
115*0Sstevel@tonic-gate 		break;
116*0Sstevel@tonic-gate 	}
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate 	mdb_printf("%<u>%p\t%<b>%N%</b>\t%s%</u>\n", addr, &fa->faddr,
119*0Sstevel@tonic-gate 	    statestr);
120*0Sstevel@tonic-gate 	mdb_printf("next\t\t%?p\tsaddr\t%N\n", fa->next, &fa->saddr);
121*0Sstevel@tonic-gate 	mdb_printf("rto\t\t%?d\tsrtt\t\t%?d\n", fa->rto, fa->srtt);
122*0Sstevel@tonic-gate 	mdb_printf("rttvar\t\t%?d\trtt_updates\t%?u\n", fa->rttvar,
123*0Sstevel@tonic-gate 	    fa->rtt_updates);
124*0Sstevel@tonic-gate 	mdb_printf("strikes\t\t%?d\tmax_retr\t%?d\n", fa->strikes,
125*0Sstevel@tonic-gate 	    fa->max_retr);
126*0Sstevel@tonic-gate 	mdb_printf("hb_expiry\t%?ld\thb_interval\t%?u\n", fa->hb_expiry,
127*0Sstevel@tonic-gate 	    fa->hb_interval);
128*0Sstevel@tonic-gate 	mdb_printf("pmss\t\t%?u\tcwnd\t\t%?u\n", fa->sfa_pmss, fa->cwnd);
129*0Sstevel@tonic-gate 	mdb_printf("ssthresh\t%?u\tsuna\t\t%?u\n", fa->ssthresh, fa->suna);
130*0Sstevel@tonic-gate 	mdb_printf("pba\t\t%?u\tacked\t\t%?u\n", fa->pba, fa->acked);
131*0Sstevel@tonic-gate 	mdb_printf("lastactive\t%?ld\thb_secret\t%?#lx\n", fa->lastactive,
132*0Sstevel@tonic-gate 	    fa->hb_secret);
133*0Sstevel@tonic-gate 	mdb_printf("timer_mp\t%?p\tire\t\t%?p\n", fa->timer_mp, fa->ire);
134*0Sstevel@tonic-gate 	mdb_printf("hb_pending\t%?d\ttimer_running\t%?d\n"
135*0Sstevel@tonic-gate 	    "df\t\t%?d\tpmtu_discovered\t%?d\n"
136*0Sstevel@tonic-gate 	    "isv4\t\t%?d\tretransmissions\t%?u\n",
137*0Sstevel@tonic-gate 	    fa->hb_pending, fa->timer_running, fa->df, fa->pmtu_discovered,
138*0Sstevel@tonic-gate 	    fa->isv4, fa->T3expire);
139*0Sstevel@tonic-gate 
140*0Sstevel@tonic-gate 	return (DCMD_OK);
141*0Sstevel@tonic-gate }
142*0Sstevel@tonic-gate 
143*0Sstevel@tonic-gate static void
144*0Sstevel@tonic-gate print_set(sctp_set_t *sp)
145*0Sstevel@tonic-gate {
146*0Sstevel@tonic-gate 	mdb_printf("\tbegin\t%<b>%?x%</b>\t\tend\t%<b>%?x%</b>\n",
147*0Sstevel@tonic-gate 	    sp->begin, sp->end);
148*0Sstevel@tonic-gate 	mdb_printf("\tnext\t%?p\tprev\t%?p\n", sp->next, sp->prev);
149*0Sstevel@tonic-gate }
150*0Sstevel@tonic-gate 
151*0Sstevel@tonic-gate /* ARGSUSED */
152*0Sstevel@tonic-gate static int
153*0Sstevel@tonic-gate sctp_set(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
154*0Sstevel@tonic-gate {
155*0Sstevel@tonic-gate 	sctp_set_t sp[1];
156*0Sstevel@tonic-gate 
157*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
158*0Sstevel@tonic-gate 		return (DCMD_USAGE);
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate 	if (mdb_vread(sp, sizeof (*sp), addr) == -1)
161*0Sstevel@tonic-gate 		return (DCMD_ERR);
162*0Sstevel@tonic-gate 
163*0Sstevel@tonic-gate 	print_set(sp);
164*0Sstevel@tonic-gate 
165*0Sstevel@tonic-gate 	return (DCMD_OK);
166*0Sstevel@tonic-gate }
167*0Sstevel@tonic-gate 
168*0Sstevel@tonic-gate static void
169*0Sstevel@tonic-gate dump_sack_info(uintptr_t addr)
170*0Sstevel@tonic-gate {
171*0Sstevel@tonic-gate 	sctp_set_t sp[1];
172*0Sstevel@tonic-gate 
173*0Sstevel@tonic-gate 	while (addr != 0) {
174*0Sstevel@tonic-gate 		if (mdb_vread(sp, sizeof (*sp), addr) == -1) {
175*0Sstevel@tonic-gate 			mdb_warn("failed to read sctp_set at %p", addr);
176*0Sstevel@tonic-gate 			return;
177*0Sstevel@tonic-gate 		}
178*0Sstevel@tonic-gate 
179*0Sstevel@tonic-gate 		addr = (uintptr_t)sp->next;
180*0Sstevel@tonic-gate 		print_set(sp);
181*0Sstevel@tonic-gate 	}
182*0Sstevel@tonic-gate }
183*0Sstevel@tonic-gate 
184*0Sstevel@tonic-gate static int
185*0Sstevel@tonic-gate dump_msghdr(mblk_t *meta)
186*0Sstevel@tonic-gate {
187*0Sstevel@tonic-gate 	sctp_msg_hdr_t smh;
188*0Sstevel@tonic-gate 
189*0Sstevel@tonic-gate 	if (mdb_vread(&smh, sizeof (smh), (uintptr_t)meta->b_rptr) == -1)
190*0Sstevel@tonic-gate 		return (-1);
191*0Sstevel@tonic-gate 
192*0Sstevel@tonic-gate 	mdb_printf("%<u>msg_hdr_t at \t%?p\tsentto\t%?p%</u>\n",
193*0Sstevel@tonic-gate 	    meta->b_rptr, SCTP_CHUNK_DEST(meta));
194*0Sstevel@tonic-gate 	mdb_printf("\tttl\t%?ld\ttob\t%?ld\n", smh.smh_ttl, smh.smh_tob);
195*0Sstevel@tonic-gate 	mdb_printf("\tsid\t%?u\tssn\t%?u\n", smh.smh_sid, smh.smh_ssn);
196*0Sstevel@tonic-gate 	mdb_printf("\tppid\t%?u\tflags\t%?s\n", smh.smh_ppid,
197*0Sstevel@tonic-gate 	    smh.smh_flags & MSG_UNORDERED ? "unordered" : " ");
198*0Sstevel@tonic-gate 	mdb_printf("\tcontext\t%?u\tmsglen\t%?d\n", smh.smh_context,
199*0Sstevel@tonic-gate 	    smh.smh_msglen);
200*0Sstevel@tonic-gate 
201*0Sstevel@tonic-gate 	return (0);
202*0Sstevel@tonic-gate }
203*0Sstevel@tonic-gate 
204*0Sstevel@tonic-gate static int
205*0Sstevel@tonic-gate dump_datahdr(mblk_t *mp)
206*0Sstevel@tonic-gate {
207*0Sstevel@tonic-gate 	sctp_data_hdr_t	sdc;
208*0Sstevel@tonic-gate 	uint16_t		sdh_int16;
209*0Sstevel@tonic-gate 	uint32_t		sdh_int32;
210*0Sstevel@tonic-gate 
211*0Sstevel@tonic-gate 	if (mdb_vread(&sdc, sizeof (sdc), (uintptr_t)mp->b_rptr) == -1)
212*0Sstevel@tonic-gate 		return (-1);
213*0Sstevel@tonic-gate 
214*0Sstevel@tonic-gate 	mdb_printf("%<u>data_chunk_t \t%?p\tsentto\t%?p%</u>\n",
215*0Sstevel@tonic-gate 	    mp->b_rptr, SCTP_CHUNK_DEST(mp));
216*0Sstevel@tonic-gate 	mdb_printf("\tsent\t%?d\t", SCTP_CHUNK_ISSENT(mp)?1:0);
217*0Sstevel@tonic-gate 	mdb_printf("retrans\t%?d\n", SCTP_CHUNK_WANT_REXMIT(mp)?1:0);
218*0Sstevel@tonic-gate 	mdb_printf("\tacked\t%?d\t", SCTP_CHUNK_ISACKED(mp)?1:0);
219*0Sstevel@tonic-gate 	mdb_printf("sackcnt\t%?u\n", SCTP_CHUNK_SACKCNT(mp));
220*0Sstevel@tonic-gate 
221*0Sstevel@tonic-gate 	mdb_nhconvert(&sdh_int16, &sdc.sdh_len, sizeof (sdc.sdh_len));
222*0Sstevel@tonic-gate 	mdb_printf("\tlen\t%?d\t", sdh_int16);
223*0Sstevel@tonic-gate 	mdb_printf("BBIT=%d", SCTP_DATA_GET_BBIT(&sdc) == 0 ? 0 : 1);
224*0Sstevel@tonic-gate 	mdb_printf("EBIT=%d", SCTP_DATA_GET_EBIT(&sdc) == 0 ? 0 : 1);
225*0Sstevel@tonic-gate 
226*0Sstevel@tonic-gate 	mdb_nhconvert(&sdh_int32, &sdc.sdh_tsn, sizeof (sdc.sdh_tsn));
227*0Sstevel@tonic-gate 	mdb_nhconvert(&sdh_int16, &sdc.sdh_sid, sizeof (sdc.sdh_sid));
228*0Sstevel@tonic-gate 	mdb_printf("\ttsn\t%?x\tsid\t%?hu\n", sdh_int32, sdh_int16);
229*0Sstevel@tonic-gate 
230*0Sstevel@tonic-gate 	mdb_nhconvert(&sdh_int16, &sdc.sdh_ssn, sizeof (sdc.sdh_ssn));
231*0Sstevel@tonic-gate 	mdb_nhconvert(&sdh_int32, &sdc.sdh_payload_id,
232*0Sstevel@tonic-gate 	    sizeof (sdc.sdh_payload_id));
233*0Sstevel@tonic-gate 	mdb_printf("\tssn\t%?hu\tppid\t%?d\n", sdh_int16, sdh_int32);
234*0Sstevel@tonic-gate 
235*0Sstevel@tonic-gate 	return (0);
236*0Sstevel@tonic-gate }
237*0Sstevel@tonic-gate 
238*0Sstevel@tonic-gate static int
239*0Sstevel@tonic-gate sctp_sent_list(mblk_t *addr)
240*0Sstevel@tonic-gate {
241*0Sstevel@tonic-gate 	mblk_t meta, mp;
242*0Sstevel@tonic-gate 
243*0Sstevel@tonic-gate 	if (!addr)
244*0Sstevel@tonic-gate 		return (0);
245*0Sstevel@tonic-gate 
246*0Sstevel@tonic-gate 	if (mdb_vread(&meta, sizeof (meta), (uintptr_t)addr) == -1)
247*0Sstevel@tonic-gate 		return (-1);
248*0Sstevel@tonic-gate 
249*0Sstevel@tonic-gate 	for (;;) {
250*0Sstevel@tonic-gate 		dump_msghdr(&meta);
251*0Sstevel@tonic-gate 
252*0Sstevel@tonic-gate 		if (meta.b_cont == NULL) {
253*0Sstevel@tonic-gate 			mdb_printf("No data chunks with message header!\n");
254*0Sstevel@tonic-gate 			return (-1);
255*0Sstevel@tonic-gate 		}
256*0Sstevel@tonic-gate 		if (mdb_vread(&mp, sizeof (mp),
257*0Sstevel@tonic-gate 			(uintptr_t)meta.b_cont) == -1) {
258*0Sstevel@tonic-gate 			return (-1);
259*0Sstevel@tonic-gate 		}
260*0Sstevel@tonic-gate 		for (;;) {
261*0Sstevel@tonic-gate 			dump_datahdr(&mp);
262*0Sstevel@tonic-gate 			if (!mp.b_next)
263*0Sstevel@tonic-gate 				break;
264*0Sstevel@tonic-gate 
265*0Sstevel@tonic-gate 			if (mdb_vread(&mp, sizeof (mp),
266*0Sstevel@tonic-gate 			    (uintptr_t)(mp.b_next)) == -1)
267*0Sstevel@tonic-gate 				return (-1);
268*0Sstevel@tonic-gate 		}
269*0Sstevel@tonic-gate 		if (meta.b_next == NULL)
270*0Sstevel@tonic-gate 			break;
271*0Sstevel@tonic-gate 		if (mdb_vread(&meta, sizeof (meta),
272*0Sstevel@tonic-gate 		    (uintptr_t)meta.b_next) == -1)
273*0Sstevel@tonic-gate 			return (-1);
274*0Sstevel@tonic-gate 	}
275*0Sstevel@tonic-gate 
276*0Sstevel@tonic-gate 	return (0);
277*0Sstevel@tonic-gate }
278*0Sstevel@tonic-gate 
279*0Sstevel@tonic-gate static int
280*0Sstevel@tonic-gate sctp_unsent_list(mblk_t *addr)
281*0Sstevel@tonic-gate {
282*0Sstevel@tonic-gate 	mblk_t meta;
283*0Sstevel@tonic-gate 
284*0Sstevel@tonic-gate 	if (!addr)
285*0Sstevel@tonic-gate 		return (0);
286*0Sstevel@tonic-gate 
287*0Sstevel@tonic-gate 	if (mdb_vread(&meta, sizeof (meta), (uintptr_t)addr) == -1)
288*0Sstevel@tonic-gate 		return (-1);
289*0Sstevel@tonic-gate 
290*0Sstevel@tonic-gate 	for (;;) {
291*0Sstevel@tonic-gate 		dump_msghdr(&meta);
292*0Sstevel@tonic-gate 
293*0Sstevel@tonic-gate 		if (meta.b_next == NULL)
294*0Sstevel@tonic-gate 			break;
295*0Sstevel@tonic-gate 
296*0Sstevel@tonic-gate 		if (mdb_vread(&meta, sizeof (meta),
297*0Sstevel@tonic-gate 		    (uintptr_t)meta.b_next) == -1)
298*0Sstevel@tonic-gate 			return (-1);
299*0Sstevel@tonic-gate 	}
300*0Sstevel@tonic-gate 
301*0Sstevel@tonic-gate 	return (0);
302*0Sstevel@tonic-gate }
303*0Sstevel@tonic-gate 
304*0Sstevel@tonic-gate /* ARGSUSED */
305*0Sstevel@tonic-gate static int
306*0Sstevel@tonic-gate sctp_xmit_list(uintptr_t addr, uint_t flags, int ac, const mdb_arg_t *av)
307*0Sstevel@tonic-gate {
308*0Sstevel@tonic-gate 	sctp_t sctp;
309*0Sstevel@tonic-gate 
310*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
311*0Sstevel@tonic-gate 		return (DCMD_USAGE);
312*0Sstevel@tonic-gate 
313*0Sstevel@tonic-gate 	if (mdb_vread(&sctp, sizeof (sctp), addr) == -1)
314*0Sstevel@tonic-gate 		return (DCMD_ERR);
315*0Sstevel@tonic-gate 
316*0Sstevel@tonic-gate 	mdb_printf("%<b>Chunkified TX list%</b>\n");
317*0Sstevel@tonic-gate 	if (sctp_sent_list(sctp.sctp_xmit_head) < 0)
318*0Sstevel@tonic-gate 		return (DCMD_ERR);
319*0Sstevel@tonic-gate 
320*0Sstevel@tonic-gate 	mdb_printf("%<b>Unchunkified TX list%</b>\n");
321*0Sstevel@tonic-gate 	if (sctp_unsent_list(sctp.sctp_xmit_unsent) < 0)
322*0Sstevel@tonic-gate 		return (DCMD_ERR);
323*0Sstevel@tonic-gate 
324*0Sstevel@tonic-gate 	return (DCMD_OK);
325*0Sstevel@tonic-gate }
326*0Sstevel@tonic-gate 
327*0Sstevel@tonic-gate /* ARGSUSED */
328*0Sstevel@tonic-gate static int
329*0Sstevel@tonic-gate sctp_mdata_chunk(uintptr_t addr, uint_t flags, int ac, const mdb_arg_t *av)
330*0Sstevel@tonic-gate {
331*0Sstevel@tonic-gate 	sctp_data_hdr_t dc;
332*0Sstevel@tonic-gate 	mblk_t mp;
333*0Sstevel@tonic-gate 
334*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
335*0Sstevel@tonic-gate 		return (DCMD_USAGE);
336*0Sstevel@tonic-gate 
337*0Sstevel@tonic-gate 	if (mdb_vread(&mp, sizeof (mp), addr) == -1)
338*0Sstevel@tonic-gate 		return (DCMD_ERR);
339*0Sstevel@tonic-gate 
340*0Sstevel@tonic-gate 	if (mdb_vread(&dc, sizeof (dc), (uintptr_t)mp.b_rptr) == -1)
341*0Sstevel@tonic-gate 		return (DCMD_ERR);
342*0Sstevel@tonic-gate 
343*0Sstevel@tonic-gate 	mdb_printf("%<b>%-?p%</b>tsn\t%?x\tsid\t%?hu\n", addr,
344*0Sstevel@tonic-gate 	    dc.sdh_tsn, dc.sdh_sid);
345*0Sstevel@tonic-gate 	mdb_printf("%-?sssn\t%?hu\tppid\t%?x\n", "", dc.sdh_ssn,
346*0Sstevel@tonic-gate 	    dc.sdh_payload_id);
347*0Sstevel@tonic-gate 
348*0Sstevel@tonic-gate 	return (DCMD_OK);
349*0Sstevel@tonic-gate }
350*0Sstevel@tonic-gate 
351*0Sstevel@tonic-gate /* ARGSUSED */
352*0Sstevel@tonic-gate static int
353*0Sstevel@tonic-gate sctp_istr_msgs(uintptr_t addr, uint_t flags, int ac, const mdb_arg_t *av)
354*0Sstevel@tonic-gate {
355*0Sstevel@tonic-gate 	mblk_t			istrmp;
356*0Sstevel@tonic-gate 	mblk_t			dmp;
357*0Sstevel@tonic-gate 	sctp_data_hdr_t 	dp;
358*0Sstevel@tonic-gate 	uintptr_t		daddr;
359*0Sstevel@tonic-gate 	uintptr_t		chaddr;
360*0Sstevel@tonic-gate 	boolean_t		bbit;
361*0Sstevel@tonic-gate 	boolean_t		ebit;
362*0Sstevel@tonic-gate 
363*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
364*0Sstevel@tonic-gate 		return (DCMD_USAGE);
365*0Sstevel@tonic-gate 
366*0Sstevel@tonic-gate 	do {
367*0Sstevel@tonic-gate 		if (mdb_vread(&istrmp, sizeof (istrmp), addr) == -1)
368*0Sstevel@tonic-gate 			return (DCMD_ERR);
369*0Sstevel@tonic-gate 
370*0Sstevel@tonic-gate 		mdb_printf("\tistr mblk at %p: next: %?p\n"
371*0Sstevel@tonic-gate 		    "\t\tprev: %?p\tcont: %?p\n", addr, istrmp.b_next,
372*0Sstevel@tonic-gate 		    istrmp.b_prev, istrmp.b_cont);
373*0Sstevel@tonic-gate 		daddr = (uintptr_t)&istrmp;
374*0Sstevel@tonic-gate 		do {
375*0Sstevel@tonic-gate 			if (mdb_vread(&dmp, sizeof (dmp), daddr) == -1)
376*0Sstevel@tonic-gate 				break;
377*0Sstevel@tonic-gate 			chaddr = (uintptr_t)dmp.b_rptr;
378*0Sstevel@tonic-gate 			if (mdb_vread(&dp, sizeof (dp), chaddr) == -1)
379*0Sstevel@tonic-gate 				break;
380*0Sstevel@tonic-gate 
381*0Sstevel@tonic-gate 			bbit = (SCTP_DATA_GET_BBIT(&dp) != 0);
382*0Sstevel@tonic-gate 			ebit = (SCTP_DATA_GET_EBIT(&dp) != 0);
383*0Sstevel@tonic-gate 
384*0Sstevel@tonic-gate 			mdb_printf("\t\t\ttsn: %x  bbit: %d  ebit: %d\n",
385*0Sstevel@tonic-gate 			    dp.sdh_tsn, bbit, ebit);
386*0Sstevel@tonic-gate 
387*0Sstevel@tonic-gate 
388*0Sstevel@tonic-gate 			daddr = (uintptr_t)dmp.b_cont;
389*0Sstevel@tonic-gate 		} while (daddr != NULL);
390*0Sstevel@tonic-gate 
391*0Sstevel@tonic-gate 		addr = (uintptr_t)istrmp.b_next;
392*0Sstevel@tonic-gate 	} while (addr != NULL);
393*0Sstevel@tonic-gate 
394*0Sstevel@tonic-gate 	return (DCMD_OK);
395*0Sstevel@tonic-gate }
396*0Sstevel@tonic-gate 
397*0Sstevel@tonic-gate /* ARGSUSED */
398*0Sstevel@tonic-gate static int
399*0Sstevel@tonic-gate sctp_reass_list(uintptr_t addr, uint_t flags, int ac, const mdb_arg_t *av)
400*0Sstevel@tonic-gate {
401*0Sstevel@tonic-gate 	sctp_reass_t srp;
402*0Sstevel@tonic-gate 	mblk_t srpmp;
403*0Sstevel@tonic-gate 	sctp_data_hdr_t dp;
404*0Sstevel@tonic-gate 	mblk_t dmp;
405*0Sstevel@tonic-gate 	uintptr_t daddr;
406*0Sstevel@tonic-gate 	uintptr_t chaddr;
407*0Sstevel@tonic-gate 	boolean_t bbit, ebit;
408*0Sstevel@tonic-gate 
409*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
410*0Sstevel@tonic-gate 		return (DCMD_USAGE);
411*0Sstevel@tonic-gate 
412*0Sstevel@tonic-gate 	do {
413*0Sstevel@tonic-gate 		if (mdb_vread(&srpmp, sizeof (srpmp), addr) == -1)
414*0Sstevel@tonic-gate 			return (DCMD_ERR);
415*0Sstevel@tonic-gate 
416*0Sstevel@tonic-gate 		if (mdb_vread(&srp, sizeof (srp),
417*0Sstevel@tonic-gate 		    (uintptr_t)srpmp.b_datap->db_base) == -1)
418*0Sstevel@tonic-gate 			return (DCMD_ERR);
419*0Sstevel@tonic-gate 
420*0Sstevel@tonic-gate 		mdb_printf("\treassembly mblk at %p: next: %?p\n"
421*0Sstevel@tonic-gate 		    "\t\tprev: %?p\tcont: %?p\n", addr, srpmp.b_next,
422*0Sstevel@tonic-gate 		    srpmp.b_prev, srpmp.b_cont);
423*0Sstevel@tonic-gate 		mdb_printf("\t\tssn: %hu\tneeded: %hu\tgot: %hu\ttail: %?p\n"
424*0Sstevel@tonic-gate 		    "\t\tpartial_delivered: %s\n", srp.ssn, srp.needed,
425*0Sstevel@tonic-gate 		    srp.got, srp.tail, srp.partial_delivered ? "TRUE" :
426*0Sstevel@tonic-gate 		    "FALSE");
427*0Sstevel@tonic-gate 
428*0Sstevel@tonic-gate 		/* display the contents of this ssn's reassemby list */
429*0Sstevel@tonic-gate 		daddr = DB_TYPE(&srpmp) == M_CTL ? (uintptr_t)srpmp.b_cont :
430*0Sstevel@tonic-gate 		    (uintptr_t)&srpmp;
431*0Sstevel@tonic-gate 		do {
432*0Sstevel@tonic-gate 			if (mdb_vread(&dmp, sizeof (dmp), daddr) == -1)
433*0Sstevel@tonic-gate 				break;
434*0Sstevel@tonic-gate 			chaddr = (uintptr_t)dmp.b_rptr;
435*0Sstevel@tonic-gate 			if (mdb_vread(&dp, sizeof (dp), chaddr) == -1)
436*0Sstevel@tonic-gate 				break;
437*0Sstevel@tonic-gate 
438*0Sstevel@tonic-gate 			bbit = (SCTP_DATA_GET_BBIT(&dp) != 0);
439*0Sstevel@tonic-gate 			ebit = (SCTP_DATA_GET_EBIT(&dp) != 0);
440*0Sstevel@tonic-gate 
441*0Sstevel@tonic-gate 			mdb_printf("\t\t\ttsn: %x  bbit: %d  ebit: %d\n",
442*0Sstevel@tonic-gate 			    dp.sdh_tsn, bbit, ebit);
443*0Sstevel@tonic-gate 
444*0Sstevel@tonic-gate 			daddr = (uintptr_t)dmp.b_cont;
445*0Sstevel@tonic-gate 		} while (daddr != NULL);
446*0Sstevel@tonic-gate 
447*0Sstevel@tonic-gate 		addr = (uintptr_t)srpmp.b_next;
448*0Sstevel@tonic-gate 	} while (addr != NULL);
449*0Sstevel@tonic-gate 
450*0Sstevel@tonic-gate 	return (DCMD_OK);
451*0Sstevel@tonic-gate }
452*0Sstevel@tonic-gate 
453*0Sstevel@tonic-gate /* ARGSUSED */
454*0Sstevel@tonic-gate static int
455*0Sstevel@tonic-gate sctp_uo_reass_list(uintptr_t addr, uint_t flags, int ac, const mdb_arg_t *av)
456*0Sstevel@tonic-gate {
457*0Sstevel@tonic-gate 	sctp_data_hdr_t	dp;
458*0Sstevel@tonic-gate 	mblk_t		dmp;
459*0Sstevel@tonic-gate 	uintptr_t	chaddr;
460*0Sstevel@tonic-gate 	boolean_t	bbit;
461*0Sstevel@tonic-gate 	boolean_t	ebit;
462*0Sstevel@tonic-gate 	boolean_t	ubit;
463*0Sstevel@tonic-gate 
464*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
465*0Sstevel@tonic-gate 		return (DCMD_USAGE);
466*0Sstevel@tonic-gate 
467*0Sstevel@tonic-gate 	do {
468*0Sstevel@tonic-gate 		if (mdb_vread(&dmp, sizeof (dmp), addr) == -1)
469*0Sstevel@tonic-gate 			return (DCMD_ERR);
470*0Sstevel@tonic-gate 
471*0Sstevel@tonic-gate 		mdb_printf("\treassembly mblk at %p: next: %?p\n"
472*0Sstevel@tonic-gate 		    "\t\tprev: %?p\n", addr, dmp.b_next, dmp.b_prev);
473*0Sstevel@tonic-gate 
474*0Sstevel@tonic-gate 		chaddr = (uintptr_t)dmp.b_rptr;
475*0Sstevel@tonic-gate 		if (mdb_vread(&dp, sizeof (dp), chaddr) == -1)
476*0Sstevel@tonic-gate 			break;
477*0Sstevel@tonic-gate 
478*0Sstevel@tonic-gate 		bbit = (SCTP_DATA_GET_BBIT(&dp) != 0);
479*0Sstevel@tonic-gate 		ebit = (SCTP_DATA_GET_EBIT(&dp) != 0);
480*0Sstevel@tonic-gate 		ubit = (SCTP_DATA_GET_UBIT(&dp) != 0);
481*0Sstevel@tonic-gate 
482*0Sstevel@tonic-gate 		mdb_printf("\t\t\tsid: %hu ssn: %hu tsn: %x "
483*0Sstevel@tonic-gate 		    "flags: %x (U=%d B=%d E=%d)\n", dp.sdh_sid, dp.sdh_ssn,
484*0Sstevel@tonic-gate 		    dp.sdh_tsn, dp.sdh_flags, ubit, bbit, ebit);
485*0Sstevel@tonic-gate 
486*0Sstevel@tonic-gate 		addr = (uintptr_t)dmp.b_next;
487*0Sstevel@tonic-gate 	} while (addr != NULL);
488*0Sstevel@tonic-gate 
489*0Sstevel@tonic-gate 	return (DCMD_OK);
490*0Sstevel@tonic-gate }
491*0Sstevel@tonic-gate 
492*0Sstevel@tonic-gate static int
493*0Sstevel@tonic-gate sctp_instr(uintptr_t addr, uint_t flags, int ac, const mdb_arg_t *av)
494*0Sstevel@tonic-gate {
495*0Sstevel@tonic-gate 	sctp_instr_t sip;
496*0Sstevel@tonic-gate 
497*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
498*0Sstevel@tonic-gate 		return (DCMD_USAGE);
499*0Sstevel@tonic-gate 
500*0Sstevel@tonic-gate 	if (mdb_vread(&sip, sizeof (sip), addr) == -1)
501*0Sstevel@tonic-gate 		return (DCMD_ERR);
502*0Sstevel@tonic-gate 
503*0Sstevel@tonic-gate 	mdb_printf("%<b>%-?p%</b>\n\tmsglist\t%?p\tnmsgs\t%?d\n"
504*0Sstevel@tonic-gate 	    "\tnextseq\t%?d\treass\t%?p\n", addr, sip.istr_msgs,
505*0Sstevel@tonic-gate 	    sip.istr_nmsgs, sip.nextseq, sip.istr_reass);
506*0Sstevel@tonic-gate 	mdb_set_dot(addr + sizeof (sip));
507*0Sstevel@tonic-gate 
508*0Sstevel@tonic-gate 	return (sctp_reass_list((uintptr_t)sip.istr_reass, flags, ac, av));
509*0Sstevel@tonic-gate }
510*0Sstevel@tonic-gate 
511*0Sstevel@tonic-gate static const char *
512*0Sstevel@tonic-gate state2str(sctp_t *sctp)
513*0Sstevel@tonic-gate {
514*0Sstevel@tonic-gate 	switch (sctp->sctp_state) {
515*0Sstevel@tonic-gate 	case SCTPS_IDLE:		return ("SCTPS_IDLE");
516*0Sstevel@tonic-gate 	case SCTPS_BOUND:		return ("SCTPS_BOUND");
517*0Sstevel@tonic-gate 	case SCTPS_LISTEN:		return ("SCTPS_LISTEN");
518*0Sstevel@tonic-gate 	case SCTPS_COOKIE_WAIT:		return ("SCTPS_COOKIE_WAIT");
519*0Sstevel@tonic-gate 	case SCTPS_COOKIE_ECHOED:	return ("SCTPS_COOKIE_ECHOED");
520*0Sstevel@tonic-gate 	case SCTPS_ESTABLISHED:		return ("SCTPS_ESTABLISHED");
521*0Sstevel@tonic-gate 	case SCTPS_SHUTDOWN_PENDING:	return ("SCTPS_SHUTDOWN_PENDING");
522*0Sstevel@tonic-gate 	case SCTPS_SHUTDOWN_SENT:	return ("SCTPS_SHUTDOWN_SENT");
523*0Sstevel@tonic-gate 	case SCTPS_SHUTDOWN_RECEIVED:	return ("SCTPS_SHUTDOWN_RECEIVED");
524*0Sstevel@tonic-gate 	case SCTPS_SHUTDOWN_ACK_SENT:	return ("SCTPS_SHUTDOWN_ACK_SENT");
525*0Sstevel@tonic-gate 	default:			return ("UNKNOWN STATE");
526*0Sstevel@tonic-gate 	}
527*0Sstevel@tonic-gate }
528*0Sstevel@tonic-gate 
529*0Sstevel@tonic-gate static void
530*0Sstevel@tonic-gate show_sctp_flags(sctp_t *sctp)
531*0Sstevel@tonic-gate {
532*0Sstevel@tonic-gate 	mdb_printf("\tunderstands_asconf\t%d\n",
533*0Sstevel@tonic-gate 	    sctp->sctp_understands_asconf);
534*0Sstevel@tonic-gate 	mdb_printf("\tdebug\t\t\t%d\n", sctp->sctp_debug);
535*0Sstevel@tonic-gate 	mdb_printf("\tdontroute\t\t%d\n", sctp->sctp_dontroute);
536*0Sstevel@tonic-gate 	mdb_printf("\tbroadcast\t\t%d\n", sctp->sctp_broadcast);
537*0Sstevel@tonic-gate 
538*0Sstevel@tonic-gate 	mdb_printf("\tuseloopback\t\t%d\n", sctp->sctp_useloopback);
539*0Sstevel@tonic-gate 	mdb_printf("\tcchunk_pend\t\t%d\n", sctp->sctp_cchunk_pend);
540*0Sstevel@tonic-gate 	mdb_printf("\tdgram_errind\t\t%d\n", sctp->sctp_dgram_errind);
541*0Sstevel@tonic-gate 	mdb_printf("\treuseaddr\t\t%d\n", sctp->sctp_reuseaddr);
542*0Sstevel@tonic-gate 
543*0Sstevel@tonic-gate 	mdb_printf("\tlinger\t\t\t%d\n", sctp->sctp_linger);
544*0Sstevel@tonic-gate 	if (sctp->sctp_lingering)
545*0Sstevel@tonic-gate 		return;
546*0Sstevel@tonic-gate 	mdb_printf("\tlingering\t\t%d\n", sctp->sctp_lingering);
547*0Sstevel@tonic-gate 	mdb_printf("\tloopback\t\t%d\n", sctp->sctp_loopback);
548*0Sstevel@tonic-gate 	mdb_printf("\tforce_sack\t\t%d\n", sctp->sctp_force_sack);
549*0Sstevel@tonic-gate 
550*0Sstevel@tonic-gate 	mdb_printf("\tack_timer_runing\t%d\n", sctp->sctp_ack_timer_running);
551*0Sstevel@tonic-gate 	mdb_printf("\trecvdstaddr\t\t%d\n", sctp->sctp_recvdstaddr);
552*0Sstevel@tonic-gate 	mdb_printf("\thwcksum\t\t\t%d\n", sctp->sctp_hwcksum);
553*0Sstevel@tonic-gate 	mdb_printf("\tunderstands_addip\t%d\n", sctp->sctp_understands_addip);
554*0Sstevel@tonic-gate 
555*0Sstevel@tonic-gate 	mdb_printf("\tbound_to_all\t\t%d\n", sctp->sctp_bound_to_all);
556*0Sstevel@tonic-gate 	mdb_printf("\tcansleep\t\t%d\n", sctp->sctp_cansleep);
557*0Sstevel@tonic-gate 	mdb_printf("\tdetached\t\t%d\n", sctp->sctp_detached);
558*0Sstevel@tonic-gate 	mdb_printf("\tsend_adaption\t\t%d\n", sctp->sctp_send_adaption);
559*0Sstevel@tonic-gate 
560*0Sstevel@tonic-gate 	mdb_printf("\trecv_adaption\t\t%d\n", sctp->sctp_recv_adaption);
561*0Sstevel@tonic-gate 	mdb_printf("\tndelay\t\t\t%d\n", sctp->sctp_ndelay);
562*0Sstevel@tonic-gate 	mdb_printf("\tcondemned\t\t%d\n", sctp->sctp_condemned);
563*0Sstevel@tonic-gate 	mdb_printf("\tchk_fast_rexmit\t\t%d\n", sctp->sctp_chk_fast_rexmit);
564*0Sstevel@tonic-gate 	mdb_printf("\tprsctp_aware\t\t%d\n", sctp->sctp_prsctp_aware);
565*0Sstevel@tonic-gate 
566*0Sstevel@tonic-gate 	mdb_printf("\trecvsndrcvinfo\t\t%d\n", sctp->sctp_recvsndrcvinfo);
567*0Sstevel@tonic-gate 	mdb_printf("\trecvassocevnt\t\t%d\n", sctp->sctp_recvassocevnt);
568*0Sstevel@tonic-gate 	mdb_printf("\trecvpathevnt\t\t%d\n", sctp->sctp_recvpathevnt);
569*0Sstevel@tonic-gate 	mdb_printf("\trecvsendfailevnt\t%d\n", sctp->sctp_recvsendfailevnt);
570*0Sstevel@tonic-gate 
571*0Sstevel@tonic-gate 	mdb_printf("\trecvpeerevnt\t\t%d\n", sctp->sctp_recvpeererr);
572*0Sstevel@tonic-gate 	mdb_printf("\trecvchutdownevnt\t%d\n", sctp->sctp_recvshutdownevnt);
573*0Sstevel@tonic-gate 	mdb_printf("\trecvcpdnevnt\t\t%d\n", sctp->sctp_recvpdevnt);
574*0Sstevel@tonic-gate 	mdb_printf("\trecvcalevnt\t\t%d\n\n", sctp->sctp_recvalevnt);
575*0Sstevel@tonic-gate }
576*0Sstevel@tonic-gate 
577*0Sstevel@tonic-gate /*
578*0Sstevel@tonic-gate  * Given a sctp_saddr_ipif_t, print out its address.  This assumes
579*0Sstevel@tonic-gate  * that addr contains the sctp_addr_ipif_t structure already and this
580*0Sstevel@tonic-gate  * function does not need to read it in.
581*0Sstevel@tonic-gate  */
582*0Sstevel@tonic-gate /* ARGSUSED */
583*0Sstevel@tonic-gate static int
584*0Sstevel@tonic-gate print_saddr(uintptr_t ptr, const void *addr, void *cbdata)
585*0Sstevel@tonic-gate {
586*0Sstevel@tonic-gate 	sctp_saddr_ipif_t *saddr = (sctp_saddr_ipif_t *)addr;
587*0Sstevel@tonic-gate 	sctp_ipif_t ipif;
588*0Sstevel@tonic-gate 	char *statestr;
589*0Sstevel@tonic-gate 
590*0Sstevel@tonic-gate 	/* Read in the sctp_ipif object */
591*0Sstevel@tonic-gate 	if (mdb_vread(&ipif, sizeof (ipif), (uintptr_t)saddr->saddr_ipifp) ==
592*0Sstevel@tonic-gate 	    -1) {
593*0Sstevel@tonic-gate 		mdb_warn("cannot read ipif at %p", saddr->saddr_ipifp);
594*0Sstevel@tonic-gate 		return (WALK_ERR);
595*0Sstevel@tonic-gate 	}
596*0Sstevel@tonic-gate 
597*0Sstevel@tonic-gate 	switch (ipif.sctp_ipif_state) {
598*0Sstevel@tonic-gate 	case SCTP_IPIFS_CONDEMNED:
599*0Sstevel@tonic-gate 		statestr = "SCTP_IPIFS_CONDEMNED";
600*0Sstevel@tonic-gate 		break;
601*0Sstevel@tonic-gate 	case SCTP_IPIFS_INVALID:
602*0Sstevel@tonic-gate 		statestr = "SCTP_IPIFS_INVALID";
603*0Sstevel@tonic-gate 		break;
604*0Sstevel@tonic-gate 	case SCTP_IPIFS_DOWN:
605*0Sstevel@tonic-gate 		statestr = "SCTP_IPIFS_DOWN";
606*0Sstevel@tonic-gate 		break;
607*0Sstevel@tonic-gate 	case SCTP_IPIFS_UP:
608*0Sstevel@tonic-gate 		statestr = "SCTP_IPIFS_UP";
609*0Sstevel@tonic-gate 		break;
610*0Sstevel@tonic-gate 	default:
611*0Sstevel@tonic-gate 		statestr = "Unknown state";
612*0Sstevel@tonic-gate 		break;
613*0Sstevel@tonic-gate 	}
614*0Sstevel@tonic-gate 	mdb_printf("\t%N\tmtu %d id %d %d %s\n", &ipif.sctp_ipif_saddr,
615*0Sstevel@tonic-gate 	    ipif.sctp_ipif_mtu, ipif.sctp_ipif_id,
616*0Sstevel@tonic-gate 	    ipif.sctp_ipif_zoneid, statestr);
617*0Sstevel@tonic-gate 
618*0Sstevel@tonic-gate 	return (WALK_NEXT);
619*0Sstevel@tonic-gate }
620*0Sstevel@tonic-gate 
621*0Sstevel@tonic-gate /*
622*0Sstevel@tonic-gate  * Given a sctp_faddr_t, print out its address.  This assumes that
623*0Sstevel@tonic-gate  * addr contains the sctp_faddr_t structure already and this function
624*0Sstevel@tonic-gate  * does not need to read it in.
625*0Sstevel@tonic-gate  */
626*0Sstevel@tonic-gate static int
627*0Sstevel@tonic-gate print_faddr(uintptr_t ptr, const void *addr, void *cbdata)
628*0Sstevel@tonic-gate {
629*0Sstevel@tonic-gate 	sctp_faddr_t *faddr = (sctp_faddr_t *)addr;
630*0Sstevel@tonic-gate 	int *i = cbdata;
631*0Sstevel@tonic-gate 
632*0Sstevel@tonic-gate 	mdb_printf("\t%d:\t%N\t%?p\n", (*i)++, &faddr->faddr, ptr);
633*0Sstevel@tonic-gate 	return (WALK_NEXT);
634*0Sstevel@tonic-gate }
635*0Sstevel@tonic-gate 
636*0Sstevel@tonic-gate int
637*0Sstevel@tonic-gate sctp(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
638*0Sstevel@tonic-gate {
639*0Sstevel@tonic-gate 	sctp_t sctp;
640*0Sstevel@tonic-gate 	conn_t connp;
641*0Sstevel@tonic-gate 	int i;
642*0Sstevel@tonic-gate 	uint_t opts = 0;
643*0Sstevel@tonic-gate 	uint_t paddr = 0;
644*0Sstevel@tonic-gate 	in_port_t lport, fport;
645*0Sstevel@tonic-gate 
646*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC))
647*0Sstevel@tonic-gate 		return (DCMD_USAGE);
648*0Sstevel@tonic-gate 
649*0Sstevel@tonic-gate 	if (mdb_vread(&sctp, sizeof (sctp), addr) == -1) {
650*0Sstevel@tonic-gate 		mdb_warn("failed to read sctp_t at: %p\n", addr);
651*0Sstevel@tonic-gate 		return (DCMD_ERR);
652*0Sstevel@tonic-gate 	}
653*0Sstevel@tonic-gate 	if (mdb_vread(&connp, sizeof (connp),
654*0Sstevel@tonic-gate 	    (uintptr_t)sctp.sctp_connp) == -1) {
655*0Sstevel@tonic-gate 		mdb_warn("failed to read conn_t at: %p\n", sctp.sctp_connp);
656*0Sstevel@tonic-gate 		return (DCMD_ERR);
657*0Sstevel@tonic-gate 	}
658*0Sstevel@tonic-gate 
659*0Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
660*0Sstevel@tonic-gate 		'a', MDB_OPT_SETBITS, MDB_SCTP_SHOW_ALL, &opts,
661*0Sstevel@tonic-gate 		'f', MDB_OPT_SETBITS, MDB_SCTP_SHOW_FLAGS, &opts,
662*0Sstevel@tonic-gate 		'h', MDB_OPT_SETBITS, MDB_SCTP_SHOW_HASH, &opts,
663*0Sstevel@tonic-gate 		'o', MDB_OPT_SETBITS, MDB_SCTP_SHOW_OUT, &opts,
664*0Sstevel@tonic-gate 		'i', MDB_OPT_SETBITS, MDB_SCTP_SHOW_IN, &opts,
665*0Sstevel@tonic-gate 		'm', MDB_OPT_SETBITS, MDB_SCTP_SHOW_MISC, &opts,
666*0Sstevel@tonic-gate 		'r', MDB_OPT_SETBITS, MDB_SCTP_SHOW_RTT, &opts,
667*0Sstevel@tonic-gate 		'S', MDB_OPT_SETBITS, MDB_SCTP_SHOW_STATS, &opts,
668*0Sstevel@tonic-gate 		'F', MDB_OPT_SETBITS, MDB_SCTP_SHOW_FLOW, &opts,
669*0Sstevel@tonic-gate 		'H', MDB_OPT_SETBITS, MDB_SCTP_SHOW_HDR, &opts,
670*0Sstevel@tonic-gate 		'p', MDB_OPT_SETBITS, MDB_SCTP_SHOW_PMTUD, &opts,
671*0Sstevel@tonic-gate 		'R', MDB_OPT_SETBITS, MDB_SCTP_SHOW_RXT, &opts,
672*0Sstevel@tonic-gate 		'C', MDB_OPT_SETBITS, MDB_SCTP_SHOW_CONN, &opts,
673*0Sstevel@tonic-gate 		'c', MDB_OPT_SETBITS, MDB_SCTP_SHOW_CLOSE, &opts,
674*0Sstevel@tonic-gate 		'e', MDB_OPT_SETBITS, MDB_SCTP_SHOW_EXT, &opts,
675*0Sstevel@tonic-gate 		'P', MDB_OPT_SETBITS, 1, &paddr,
676*0Sstevel@tonic-gate 		'd', MDB_OPT_SETBITS, MDB_SCTP_DUMP_ADDRS, &opts) != argc) {
677*0Sstevel@tonic-gate 		return (DCMD_USAGE);
678*0Sstevel@tonic-gate 	}
679*0Sstevel@tonic-gate 
680*0Sstevel@tonic-gate 	/* non-verbose faddrs, suitable for pipelines to sctp_faddr */
681*0Sstevel@tonic-gate 	if (paddr != 0) {
682*0Sstevel@tonic-gate 		sctp_faddr_t faddr, *fp;
683*0Sstevel@tonic-gate 		for (fp = sctp.sctp_faddrs; fp != NULL; fp = faddr.next) {
684*0Sstevel@tonic-gate 			if (mdb_vread(&faddr, sizeof (faddr), (uintptr_t)fp)
685*0Sstevel@tonic-gate 			    == -1) {
686*0Sstevel@tonic-gate 				mdb_warn("failed to read faddr at %p",
687*0Sstevel@tonic-gate 				    fp);
688*0Sstevel@tonic-gate 				return (DCMD_ERR);
689*0Sstevel@tonic-gate 			}
690*0Sstevel@tonic-gate 			mdb_printf("%p\n", fp);
691*0Sstevel@tonic-gate 		}
692*0Sstevel@tonic-gate 		return (DCMD_OK);
693*0Sstevel@tonic-gate 	}
694*0Sstevel@tonic-gate 
695*0Sstevel@tonic-gate 	mdb_nhconvert(&lport, &sctp.sctp_lport, sizeof (lport));
696*0Sstevel@tonic-gate 	mdb_nhconvert(&fport, &sctp.sctp_fport, sizeof (fport));
697*0Sstevel@tonic-gate 	mdb_printf("%<u>%p% %22s S=%-6hu D=%-6hu% ZONE=%d%</u>", addr,
698*0Sstevel@tonic-gate 	    state2str(&sctp), lport, fport, connp.conn_zoneid);
699*0Sstevel@tonic-gate 
700*0Sstevel@tonic-gate 	if (sctp.sctp_faddrs) {
701*0Sstevel@tonic-gate 		sctp_faddr_t faddr;
702*0Sstevel@tonic-gate 		if (mdb_vread(&faddr, sizeof (faddr),
703*0Sstevel@tonic-gate 		    (uintptr_t)sctp.sctp_faddrs) != -1)
704*0Sstevel@tonic-gate 			mdb_printf("%<u> %N%</u>", &faddr.faddr);
705*0Sstevel@tonic-gate 	}
706*0Sstevel@tonic-gate 	mdb_printf("\n");
707*0Sstevel@tonic-gate 
708*0Sstevel@tonic-gate 	if (opts & MDB_SCTP_DUMP_ADDRS) {
709*0Sstevel@tonic-gate 		mdb_printf("%<b>Local and Peer Addresses%</b>\n");
710*0Sstevel@tonic-gate 
711*0Sstevel@tonic-gate 		/* Display source addresses */
712*0Sstevel@tonic-gate 		mdb_printf("nsaddrs\t\t%?d\n", sctp.sctp_nsaddrs);
713*0Sstevel@tonic-gate 		(void) mdb_pwalk("sctp_walk_saddr", print_saddr, NULL, addr);
714*0Sstevel@tonic-gate 
715*0Sstevel@tonic-gate 		/* Display peer addresses */
716*0Sstevel@tonic-gate 		mdb_printf("faddrs\t\t%?p\n", sctp.sctp_faddrs);
717*0Sstevel@tonic-gate 		i = 1;
718*0Sstevel@tonic-gate 		(void) mdb_pwalk("sctp_walk_faddr", print_faddr, &i, addr);
719*0Sstevel@tonic-gate 
720*0Sstevel@tonic-gate 		mdb_printf("lastfaddr\t%?p\tprimary\t\t%?p\n",
721*0Sstevel@tonic-gate 		    sctp.sctp_lastfaddr, sctp.sctp_primary);
722*0Sstevel@tonic-gate 		mdb_printf("current\t\t%?p\tlastdata\t%?p\n",
723*0Sstevel@tonic-gate 		    sctp.sctp_current, sctp.sctp_lastdata);
724*0Sstevel@tonic-gate 	}
725*0Sstevel@tonic-gate 
726*0Sstevel@tonic-gate 	if (opts & MDB_SCTP_SHOW_OUT) {
727*0Sstevel@tonic-gate 		mdb_printf("%<b>Outbound Data%</b>\n");
728*0Sstevel@tonic-gate 		mdb_printf("xmit_head\t%?p\txmit_tail\t%?p\n",
729*0Sstevel@tonic-gate 		    sctp.sctp_xmit_head, sctp.sctp_xmit_tail);
730*0Sstevel@tonic-gate 		mdb_printf("xmit_unsent\t%?p\txmit_unsent_tail%?p\n",
731*0Sstevel@tonic-gate 		    sctp.sctp_xmit_unsent, sctp.sctp_xmit_unsent_tail);
732*0Sstevel@tonic-gate 		mdb_printf("xmit_unacked\t%?p\n", sctp.sctp_xmit_unacked);
733*0Sstevel@tonic-gate 		mdb_printf("unacked\t\t%?u\tunsent\t\t%?ld\n",
734*0Sstevel@tonic-gate 		    sctp.sctp_unacked, sctp.sctp_unsent);
735*0Sstevel@tonic-gate 		mdb_printf("ltsn\t\t%?x\tlastack_rxd\t%?x\n",
736*0Sstevel@tonic-gate 		    sctp.sctp_ltsn, sctp.sctp_lastack_rxd);
737*0Sstevel@tonic-gate 		mdb_printf("recovery_tsn\t%?x\tadv_pap\t\t%?x\n",
738*0Sstevel@tonic-gate 		    sctp.sctp_recovery_tsn, sctp.sctp_adv_pap);
739*0Sstevel@tonic-gate 		mdb_printf("num_ostr\t%?hu\tostrcntrs\t%?p\n",
740*0Sstevel@tonic-gate 		    sctp.sctp_num_ostr, sctp.sctp_ostrcntrs);
741*0Sstevel@tonic-gate 
742*0Sstevel@tonic-gate 		mdb_printf("%<b>Default Send Parameters%</b>\n");
743*0Sstevel@tonic-gate 		mdb_printf("def_stream\t%?u\tdef_flags\t%?x\n",
744*0Sstevel@tonic-gate 		    sctp.sctp_def_stream, sctp.sctp_def_flags);
745*0Sstevel@tonic-gate 		mdb_printf("def_ppid\t%?x\tdef_context\t%?x\n",
746*0Sstevel@tonic-gate 		    sctp.sctp_def_ppid, sctp.sctp_def_context);
747*0Sstevel@tonic-gate 		mdb_printf("def_timetolive\t%?u\n",
748*0Sstevel@tonic-gate 		    sctp.sctp_def_timetolive);
749*0Sstevel@tonic-gate 	}
750*0Sstevel@tonic-gate 
751*0Sstevel@tonic-gate 	if (opts & MDB_SCTP_SHOW_IN) {
752*0Sstevel@tonic-gate 		mdb_printf("%<b>Inbound Data%</b>\n");
753*0Sstevel@tonic-gate 		mdb_printf("sack_info\t%?p\tsack_gaps\t%?d\n",
754*0Sstevel@tonic-gate 		    sctp.sctp_sack_info, sctp.sctp_sack_gaps);
755*0Sstevel@tonic-gate 		dump_sack_info((uintptr_t)sctp.sctp_sack_info);
756*0Sstevel@tonic-gate 		mdb_printf("ftsn\t\t%?x\tlastacked\t%?x\n",
757*0Sstevel@tonic-gate 		    sctp.sctp_ftsn, sctp.sctp_lastacked);
758*0Sstevel@tonic-gate 		mdb_printf("istr_nmsgs\t%?d\tsack_toggle\t%?d\n",
759*0Sstevel@tonic-gate 		    sctp.sctp_istr_nmsgs, sctp.sctp_sack_toggle);
760*0Sstevel@tonic-gate 		mdb_printf("ack_mp\t\t%?p\n", sctp.sctp_ack_mp);
761*0Sstevel@tonic-gate 		mdb_printf("num_istr\t%?hu\tinstr\t\t%?p\n",
762*0Sstevel@tonic-gate 		    sctp.sctp_num_istr, sctp.sctp_instr);
763*0Sstevel@tonic-gate 		mdb_printf("unord_reass\t%?p\n", sctp.sctp_uo_frags);
764*0Sstevel@tonic-gate 	}
765*0Sstevel@tonic-gate 
766*0Sstevel@tonic-gate 	if (opts & MDB_SCTP_SHOW_RTT) {
767*0Sstevel@tonic-gate 		mdb_printf("%<b>RTT Tracking%</b>\n");
768*0Sstevel@tonic-gate 		mdb_printf("rtt_tsn\t\t%?x\tout_time\t%?ld\n",
769*0Sstevel@tonic-gate 		    sctp.sctp_rtt_tsn, sctp.sctp_out_time);
770*0Sstevel@tonic-gate 	}
771*0Sstevel@tonic-gate 
772*0Sstevel@tonic-gate 	if (opts & MDB_SCTP_SHOW_FLOW) {
773*0Sstevel@tonic-gate 		mdb_printf("%<b>Flow Control%</b>\n");
774*0Sstevel@tonic-gate 		mdb_printf("txmit_hiwater\t%?d\n"
775*0Sstevel@tonic-gate 		    "xmit_lowater\t%?d\tfrwnd\t\t%?u\n"
776*0Sstevel@tonic-gate 		    "rwnd\t\t%?u\trxqueued\t%?u\n"
777*0Sstevel@tonic-gate 		    "cwnd_max\t%?u\n", sctp.sctp_xmit_hiwater,
778*0Sstevel@tonic-gate 		    sctp.sctp_xmit_lowater, sctp.sctp_frwnd,
779*0Sstevel@tonic-gate 		    sctp.sctp_rwnd, sctp.sctp_rxqueued, sctp.sctp_cwnd_max);
780*0Sstevel@tonic-gate 	}
781*0Sstevel@tonic-gate 
782*0Sstevel@tonic-gate 	if (opts & MDB_SCTP_SHOW_HDR) {
783*0Sstevel@tonic-gate 		mdb_printf("%<b>Composite Headers%</b>\n");
784*0Sstevel@tonic-gate 		mdb_printf("iphc\t\t%?p\tiphc6\t\t%?p\n"
785*0Sstevel@tonic-gate 		    "iphc_len\t%?d\tiphc6_len\t%?d\n"
786*0Sstevel@tonic-gate 		    "hdr_len\t\t%?d\thdr6_len\t%?d\n"
787*0Sstevel@tonic-gate 		    "ipha\t\t%?p\tip6h\t\t%?p\n"
788*0Sstevel@tonic-gate 		    "ip_hdr_len\t%?d\tip_hdr6_len\t%?d\n"
789*0Sstevel@tonic-gate 		    "sctph\t\t%?p\tsctph6\t\t%?p\n"
790*0Sstevel@tonic-gate 		    "lvtag\t\t%?x\tfvtag\t\t%?x\n", sctp.sctp_iphc,
791*0Sstevel@tonic-gate 		    sctp.sctp_iphc6, sctp.sctp_iphc_len,
792*0Sstevel@tonic-gate 		    sctp.sctp_iphc6_len, sctp.sctp_hdr_len,
793*0Sstevel@tonic-gate 		    sctp.sctp_hdr6_len, sctp.sctp_ipha, sctp.sctp_ip6h,
794*0Sstevel@tonic-gate 		    sctp.sctp_ip_hdr_len, sctp.sctp_ip_hdr6_len,
795*0Sstevel@tonic-gate 		    sctp.sctp_sctph, sctp.sctp_sctph6, sctp.sctp_lvtag,
796*0Sstevel@tonic-gate 		    sctp.sctp_fvtag);
797*0Sstevel@tonic-gate 	}
798*0Sstevel@tonic-gate 
799*0Sstevel@tonic-gate 	if (opts & MDB_SCTP_SHOW_PMTUD) {
800*0Sstevel@tonic-gate 		mdb_printf("%<b>PMTUd%</b>\n");
801*0Sstevel@tonic-gate 		mdb_printf("last_mtu_probe\t%?ld\tmtu_probe_intvl\t%?ld\n"
802*0Sstevel@tonic-gate 		    "mss\t\t%?u\n",
803*0Sstevel@tonic-gate 		    sctp.sctp_last_mtu_probe, sctp.sctp_mtu_probe_intvl,
804*0Sstevel@tonic-gate 		    sctp.sctp_mss);
805*0Sstevel@tonic-gate 	}
806*0Sstevel@tonic-gate 
807*0Sstevel@tonic-gate 	if (opts & MDB_SCTP_SHOW_RXT) {
808*0Sstevel@tonic-gate 		mdb_printf("%<b>Retransmit Info%</b>\n");
809*0Sstevel@tonic-gate 		mdb_printf("cookie_mp\t%?p\tstrikes\t\t%?d\n"
810*0Sstevel@tonic-gate 		    "max_init_rxt\t%?d\tpa_max_rxt\t%?d\n"
811*0Sstevel@tonic-gate 		    "pp_max_rxt\t%?d\trto_max\t\t%?u\n"
812*0Sstevel@tonic-gate 		    "rto_min\t\t%?u\trto_initial\t%?u\n"
813*0Sstevel@tonic-gate 		    "init_rto_max\t%?u\n", sctp.sctp_cookie_mp,
814*0Sstevel@tonic-gate 		    sctp.sctp_strikes, sctp.sctp_max_init_rxt,
815*0Sstevel@tonic-gate 		    sctp.sctp_pa_max_rxt, sctp.sctp_pp_max_rxt,
816*0Sstevel@tonic-gate 		    sctp.sctp_rto_max, sctp.sctp_rto_min,
817*0Sstevel@tonic-gate 		    sctp.sctp_rto_initial, sctp.sctp_init_rto_max);
818*0Sstevel@tonic-gate 	}
819*0Sstevel@tonic-gate 
820*0Sstevel@tonic-gate 	if (opts & MDB_SCTP_SHOW_CONN) {
821*0Sstevel@tonic-gate 		mdb_printf("%<b>Connection State%</b>\n");
822*0Sstevel@tonic-gate 		mdb_printf("last_secret_update%?ld\n",
823*0Sstevel@tonic-gate 		    sctp.sctp_last_secret_update);
824*0Sstevel@tonic-gate 
825*0Sstevel@tonic-gate 		mdb_printf("secret\t\t");
826*0Sstevel@tonic-gate 		for (i = 0; i < SCTP_SECRET_LEN; i++) {
827*0Sstevel@tonic-gate 			if (i % 2 == 0)
828*0Sstevel@tonic-gate 				mdb_printf("0x%02x", sctp.sctp_secret[i]);
829*0Sstevel@tonic-gate 			else
830*0Sstevel@tonic-gate 				mdb_printf("%02x ", sctp.sctp_secret[i]);
831*0Sstevel@tonic-gate 		}
832*0Sstevel@tonic-gate 		mdb_printf("\n");
833*0Sstevel@tonic-gate 		mdb_printf("old_secret\t");
834*0Sstevel@tonic-gate 		for (i = 0; i < SCTP_SECRET_LEN; i++) {
835*0Sstevel@tonic-gate 			if (i % 2 == 0)
836*0Sstevel@tonic-gate 				mdb_printf("0x%02x", sctp.sctp_old_secret[i]);
837*0Sstevel@tonic-gate 			else
838*0Sstevel@tonic-gate 				mdb_printf("%02x ", sctp.sctp_old_secret[i]);
839*0Sstevel@tonic-gate 		}
840*0Sstevel@tonic-gate 		mdb_printf("\n");
841*0Sstevel@tonic-gate 	}
842*0Sstevel@tonic-gate 
843*0Sstevel@tonic-gate 	if (opts & MDB_SCTP_SHOW_STATS) {
844*0Sstevel@tonic-gate 		mdb_printf("%<b>Stats Counters%</b>\n");
845*0Sstevel@tonic-gate 		mdb_printf("opkts\t\t%?llu\tobchunks\t%?llu\n"
846*0Sstevel@tonic-gate 		    "odchunks\t%?llu\toudchunks\t%?llu\n"
847*0Sstevel@tonic-gate 		    "rxtchunks\t%?llu\tT1expire\t%?lu\n"
848*0Sstevel@tonic-gate 		    "T2expire\t%?lu\tT3expire\t%?lu\n"
849*0Sstevel@tonic-gate 		    "msgcount\t%?llu\tprsctpdrop\t%?llu\n"
850*0Sstevel@tonic-gate 		    "AssocStartTime\t%?lu\n",
851*0Sstevel@tonic-gate 		    sctp.sctp_opkts, sctp.sctp_obchunks,
852*0Sstevel@tonic-gate 		    sctp.sctp_odchunks, sctp.sctp_oudchunks,
853*0Sstevel@tonic-gate 		    sctp.sctp_rxtchunks, sctp.sctp_T1expire,
854*0Sstevel@tonic-gate 		    sctp.sctp_T2expire, sctp.sctp_T3expire,
855*0Sstevel@tonic-gate 		    sctp.sctp_msgcount, sctp.sctp_prsctpdrop,
856*0Sstevel@tonic-gate 		    sctp.sctp_assoc_start_time);
857*0Sstevel@tonic-gate 		mdb_printf("ipkts\t\t%?llu\tibchunks\t%?llu\n"
858*0Sstevel@tonic-gate 		    "idchunks\t%?llu\tiudchunks\t%?llu\n"
859*0Sstevel@tonic-gate 		    "fragdmsgs\t%?llu\treassmsgs\t%?llu\n",
860*0Sstevel@tonic-gate 		    sctp.sctp_ipkts, sctp.sctp_ibchunks,
861*0Sstevel@tonic-gate 		    sctp.sctp_idchunks, sctp.sctp_iudchunks,
862*0Sstevel@tonic-gate 		    sctp.sctp_fragdmsgs, sctp.sctp_reassmsgs);
863*0Sstevel@tonic-gate 	}
864*0Sstevel@tonic-gate 
865*0Sstevel@tonic-gate 	if (opts & MDB_SCTP_SHOW_HASH) {
866*0Sstevel@tonic-gate 		mdb_printf("%<b>Hash Tables%</b>\n");
867*0Sstevel@tonic-gate 		mdb_printf("conn_hash_next\t%?p\t", sctp.sctp_conn_hash_next);
868*0Sstevel@tonic-gate 		mdb_printf("conn_hash_prev\t%?p\n", sctp.sctp_conn_hash_prev);
869*0Sstevel@tonic-gate 		mdb_printf("[ conn_hash bucket\t%?d ]\n",
870*0Sstevel@tonic-gate 		    SCTP_CONN_HASH(sctp.sctp_ports));
871*0Sstevel@tonic-gate 
872*0Sstevel@tonic-gate 		mdb_printf("listen_hash_next%?p\t",
873*0Sstevel@tonic-gate 		    sctp.sctp_listen_hash_next);
874*0Sstevel@tonic-gate 		mdb_printf("listen_hash_prev%?p\n",
875*0Sstevel@tonic-gate 		    sctp.sctp_listen_hash_prev);
876*0Sstevel@tonic-gate 		mdb_nhconvert(&lport, &sctp.sctp_lport, sizeof (lport));
877*0Sstevel@tonic-gate 		mdb_printf("[ listen_hash bucket\t%?d ]\n",
878*0Sstevel@tonic-gate 		    SCTP_LISTEN_HASH(lport));
879*0Sstevel@tonic-gate 
880*0Sstevel@tonic-gate 		mdb_printf("conn_tfp\t%?p\t", sctp.sctp_conn_tfp);
881*0Sstevel@tonic-gate 		mdb_printf("listen_tfp\t%?p\n", sctp.sctp_listen_tfp);
882*0Sstevel@tonic-gate 
883*0Sstevel@tonic-gate 		mdb_printf("bind_hash\t%?p\tptpbhn\t\t%?p\n",
884*0Sstevel@tonic-gate 		    sctp.sctp_bind_hash, sctp.sctp_ptpbhn);
885*0Sstevel@tonic-gate 		mdb_printf("bind_lockp\t%?p\n",
886*0Sstevel@tonic-gate 		    sctp.sctp_bind_lockp);
887*0Sstevel@tonic-gate 		mdb_printf("[ bind_hash bucket\t%?d ]\n",
888*0Sstevel@tonic-gate 		    SCTP_BIND_HASH(lport));
889*0Sstevel@tonic-gate 	}
890*0Sstevel@tonic-gate 
891*0Sstevel@tonic-gate 	if (opts & MDB_SCTP_SHOW_CLOSE) {
892*0Sstevel@tonic-gate 		mdb_printf("%<b>Cleanup / Close%</b>\n");
893*0Sstevel@tonic-gate 		mdb_printf("shutdown_faddr\t%?p\tclient_errno\t%?d\n"
894*0Sstevel@tonic-gate 		    "lingertime\t%?d\trefcnt\t\t%?hu\n",
895*0Sstevel@tonic-gate 		    sctp.sctp_shutdown_faddr, sctp.sctp_client_errno,
896*0Sstevel@tonic-gate 		    sctp.sctp_lingertime, sctp.sctp_refcnt);
897*0Sstevel@tonic-gate 	}
898*0Sstevel@tonic-gate 
899*0Sstevel@tonic-gate 	if (opts & MDB_SCTP_SHOW_MISC) {
900*0Sstevel@tonic-gate 		mdb_printf("%<b>Miscellaneous%</b>\n");
901*0Sstevel@tonic-gate 		mdb_printf("bound_if\t%?u\theartbeat_mp\t%?p\n"
902*0Sstevel@tonic-gate 		    "family\t\t%?u\tipversion\t%?hu\n"
903*0Sstevel@tonic-gate 		    "hb_interval\t%?u\tautoclose\t%?d\n"
904*0Sstevel@tonic-gate 		    "active\t\t%?ld\ttx_adaption_code%?x\n"
905*0Sstevel@tonic-gate 		    "rx_adaption_code%?x\ttimer_mp\t%?p\n",
906*0Sstevel@tonic-gate 		    sctp.sctp_bound_if, sctp.sctp_heartbeat_mp,
907*0Sstevel@tonic-gate 		    sctp.sctp_family, sctp.sctp_ipversion,
908*0Sstevel@tonic-gate 		    sctp.sctp_hb_interval, sctp.sctp_autoclose,
909*0Sstevel@tonic-gate 		    sctp.sctp_active, sctp.sctp_tx_adaption_code,
910*0Sstevel@tonic-gate 		    sctp.sctp_rx_adaption_code, sctp.sctp_timer_mp);
911*0Sstevel@tonic-gate 	}
912*0Sstevel@tonic-gate 
913*0Sstevel@tonic-gate 	if (opts & MDB_SCTP_SHOW_EXT) {
914*0Sstevel@tonic-gate 		mdb_printf("%<b>Extensions and Reliable Ctl Chunks%</b>\n");
915*0Sstevel@tonic-gate 		mdb_printf("cxmit_list\t%?p\tlcsn\t\t%?x\n"
916*0Sstevel@tonic-gate 		    "fcsn\t\t%?x\n", sctp.sctp_cxmit_list, sctp.sctp_lcsn,
917*0Sstevel@tonic-gate 		    sctp.sctp_fcsn);
918*0Sstevel@tonic-gate 	}
919*0Sstevel@tonic-gate 
920*0Sstevel@tonic-gate 	if (opts & MDB_SCTP_SHOW_FLAGS) {
921*0Sstevel@tonic-gate 		mdb_printf("%<b>Flags%</b>\n");
922*0Sstevel@tonic-gate 		show_sctp_flags(&sctp);
923*0Sstevel@tonic-gate 	}
924*0Sstevel@tonic-gate 
925*0Sstevel@tonic-gate 	return (DCMD_OK);
926*0Sstevel@tonic-gate }
927*0Sstevel@tonic-gate 
928*0Sstevel@tonic-gate typedef struct fanout_walk_data {
929*0Sstevel@tonic-gate 	int index;
930*0Sstevel@tonic-gate 	int size;
931*0Sstevel@tonic-gate 	uintptr_t sctp;
932*0Sstevel@tonic-gate 	sctp_tf_t *fanout;
933*0Sstevel@tonic-gate 	uintptr_t (*getnext)(sctp_t *);
934*0Sstevel@tonic-gate } fanout_walk_data_t;
935*0Sstevel@tonic-gate 
936*0Sstevel@tonic-gate typedef struct fanout_init {
937*0Sstevel@tonic-gate 	const char *symname;
938*0Sstevel@tonic-gate 	int (*getsize)();
939*0Sstevel@tonic-gate 	uintptr_t (*getnext)(sctp_t *);
940*0Sstevel@tonic-gate } fanout_init_t;
941*0Sstevel@tonic-gate 
942*0Sstevel@tonic-gate static uintptr_t
943*0Sstevel@tonic-gate listen_next(sctp_t *sctp)
944*0Sstevel@tonic-gate {
945*0Sstevel@tonic-gate 	return ((uintptr_t)sctp->sctp_listen_hash_next);
946*0Sstevel@tonic-gate }
947*0Sstevel@tonic-gate 
948*0Sstevel@tonic-gate static int
949*0Sstevel@tonic-gate listen_size(void)
950*0Sstevel@tonic-gate {
951*0Sstevel@tonic-gate 	return (SCTP_LISTEN_FANOUT_SIZE);
952*0Sstevel@tonic-gate }
953*0Sstevel@tonic-gate 
954*0Sstevel@tonic-gate static uintptr_t
955*0Sstevel@tonic-gate conn_next(sctp_t *sctp)
956*0Sstevel@tonic-gate {
957*0Sstevel@tonic-gate 	return ((uintptr_t)sctp->sctp_conn_hash_next);
958*0Sstevel@tonic-gate }
959*0Sstevel@tonic-gate 
960*0Sstevel@tonic-gate static int
961*0Sstevel@tonic-gate conn_size(void)
962*0Sstevel@tonic-gate {
963*0Sstevel@tonic-gate 	GElf_Sym sym;
964*0Sstevel@tonic-gate 	int size;
965*0Sstevel@tonic-gate 
966*0Sstevel@tonic-gate 	if (mdb_lookup_by_name("sctp_conn_hash_size", &sym) == -1) {
967*0Sstevel@tonic-gate 		mdb_warn("can't read 'sctp_conn_hash_size'");
968*0Sstevel@tonic-gate 		return (1);
969*0Sstevel@tonic-gate 	}
970*0Sstevel@tonic-gate 	if (mdb_vread(&size, sizeof (size), sym.st_value) == -1) {
971*0Sstevel@tonic-gate 		mdb_warn("can't dereference 'sctp_conn_hash_size'");
972*0Sstevel@tonic-gate 		return (1);
973*0Sstevel@tonic-gate 	}
974*0Sstevel@tonic-gate 	return (size);
975*0Sstevel@tonic-gate }
976*0Sstevel@tonic-gate 
977*0Sstevel@tonic-gate static uintptr_t
978*0Sstevel@tonic-gate bind_next(sctp_t *sctp)
979*0Sstevel@tonic-gate {
980*0Sstevel@tonic-gate 	return ((uintptr_t)sctp->sctp_bind_hash);
981*0Sstevel@tonic-gate }
982*0Sstevel@tonic-gate 
983*0Sstevel@tonic-gate static int
984*0Sstevel@tonic-gate bind_size(void)
985*0Sstevel@tonic-gate {
986*0Sstevel@tonic-gate 	return (SCTP_BIND_FANOUT_SIZE);
987*0Sstevel@tonic-gate }
988*0Sstevel@tonic-gate 
989*0Sstevel@tonic-gate static intptr_t
990*0Sstevel@tonic-gate find_next_hash_item(fanout_walk_data_t *fw)
991*0Sstevel@tonic-gate {
992*0Sstevel@tonic-gate 	sctp_tf_t tf;
993*0Sstevel@tonic-gate 	sctp_t sctp;
994*0Sstevel@tonic-gate 
995*0Sstevel@tonic-gate 	/* first try to continue down the hash chain */
996*0Sstevel@tonic-gate 	if (fw->sctp != NULL) {
997*0Sstevel@tonic-gate 		/* try to get next in hash chain */
998*0Sstevel@tonic-gate 		if (mdb_vread(&sctp, sizeof (sctp), fw->sctp) == -1) {
999*0Sstevel@tonic-gate 			mdb_warn("failed to read sctp at %p", fw->sctp);
1000*0Sstevel@tonic-gate 			return (NULL);
1001*0Sstevel@tonic-gate 		}
1002*0Sstevel@tonic-gate 		fw->sctp = fw->getnext(&sctp);
1003*0Sstevel@tonic-gate 		if (fw->sctp != NULL)
1004*0Sstevel@tonic-gate 			return (fw->sctp);
1005*0Sstevel@tonic-gate 		else
1006*0Sstevel@tonic-gate 			/* end of chain; go to next bucket */
1007*0Sstevel@tonic-gate 			fw->index++;
1008*0Sstevel@tonic-gate 	}
1009*0Sstevel@tonic-gate 
1010*0Sstevel@tonic-gate 	/* find a new hash chain, traversing the buckets */
1011*0Sstevel@tonic-gate 	for (; fw->index < fw->size; fw->index++) {
1012*0Sstevel@tonic-gate 		/* read the current hash line for an sctp */
1013*0Sstevel@tonic-gate 		if (mdb_vread(&tf, sizeof (tf),
1014*0Sstevel@tonic-gate 			(uintptr_t)(fw->fanout + fw->index)) == -1) {
1015*0Sstevel@tonic-gate 			mdb_warn("failed to read tf at %p",
1016*0Sstevel@tonic-gate 			    fw->fanout + fw->index);
1017*0Sstevel@tonic-gate 			return (NULL);
1018*0Sstevel@tonic-gate 		}
1019*0Sstevel@tonic-gate 		if (tf.tf_sctp != NULL) {
1020*0Sstevel@tonic-gate 			/* start of a new chain */
1021*0Sstevel@tonic-gate 			fw->sctp = (uintptr_t)tf.tf_sctp;
1022*0Sstevel@tonic-gate 			return (fw->sctp);
1023*0Sstevel@tonic-gate 		}
1024*0Sstevel@tonic-gate 	}
1025*0Sstevel@tonic-gate 	return (NULL);
1026*0Sstevel@tonic-gate }
1027*0Sstevel@tonic-gate 
1028*0Sstevel@tonic-gate static int
1029*0Sstevel@tonic-gate fanout_walk_init(mdb_walk_state_t *wsp)
1030*0Sstevel@tonic-gate {
1031*0Sstevel@tonic-gate 	GElf_Sym sym;
1032*0Sstevel@tonic-gate 	fanout_walk_data_t *lw;
1033*0Sstevel@tonic-gate 	fanout_init_t *fi = wsp->walk_arg;
1034*0Sstevel@tonic-gate 
1035*0Sstevel@tonic-gate 	if (mdb_lookup_by_name(fi->symname, &sym) == -1) {
1036*0Sstevel@tonic-gate 		mdb_warn("failed to read '%s'", fi->symname);
1037*0Sstevel@tonic-gate 		return (WALK_ERR);
1038*0Sstevel@tonic-gate 	}
1039*0Sstevel@tonic-gate 
1040*0Sstevel@tonic-gate 	lw = mdb_alloc(sizeof (*lw), UM_SLEEP);
1041*0Sstevel@tonic-gate 	lw->index = 0;
1042*0Sstevel@tonic-gate 	lw->size = fi->getsize();
1043*0Sstevel@tonic-gate 	lw->sctp = NULL;
1044*0Sstevel@tonic-gate 	lw->fanout = (sctp_tf_t *)sym.st_value;
1045*0Sstevel@tonic-gate 	lw->getnext = fi->getnext;
1046*0Sstevel@tonic-gate 
1047*0Sstevel@tonic-gate 	if ((wsp->walk_addr = find_next_hash_item(lw)) == NULL) {
1048*0Sstevel@tonic-gate 		return (WALK_DONE);
1049*0Sstevel@tonic-gate 	}
1050*0Sstevel@tonic-gate 	wsp->walk_data = lw;
1051*0Sstevel@tonic-gate 	return (WALK_NEXT);
1052*0Sstevel@tonic-gate }
1053*0Sstevel@tonic-gate 
1054*0Sstevel@tonic-gate static int
1055*0Sstevel@tonic-gate fanout_walk_step(mdb_walk_state_t *wsp)
1056*0Sstevel@tonic-gate {
1057*0Sstevel@tonic-gate 	fanout_walk_data_t *fw = wsp->walk_data;
1058*0Sstevel@tonic-gate 	uintptr_t addr = wsp->walk_addr;
1059*0Sstevel@tonic-gate 	sctp_t sctp;
1060*0Sstevel@tonic-gate 	int status;
1061*0Sstevel@tonic-gate 
1062*0Sstevel@tonic-gate 	if (mdb_vread(&sctp, sizeof (sctp), addr) == -1) {
1063*0Sstevel@tonic-gate 		mdb_warn("failed to read sctp at %p", addr);
1064*0Sstevel@tonic-gate 		return (WALK_DONE);
1065*0Sstevel@tonic-gate 	}
1066*0Sstevel@tonic-gate 
1067*0Sstevel@tonic-gate 	status = wsp->walk_callback(addr, &sctp, wsp->walk_cbdata);
1068*0Sstevel@tonic-gate 	if (status != WALK_NEXT)
1069*0Sstevel@tonic-gate 		return (status);
1070*0Sstevel@tonic-gate 
1071*0Sstevel@tonic-gate 	if ((wsp->walk_addr = find_next_hash_item(fw)) == NULL)
1072*0Sstevel@tonic-gate 		return (WALK_DONE);
1073*0Sstevel@tonic-gate 
1074*0Sstevel@tonic-gate 	return (WALK_NEXT);
1075*0Sstevel@tonic-gate }
1076*0Sstevel@tonic-gate 
1077*0Sstevel@tonic-gate static void
1078*0Sstevel@tonic-gate fanout_walk_fini(mdb_walk_state_t *wsp)
1079*0Sstevel@tonic-gate {
1080*0Sstevel@tonic-gate 	fanout_walk_data_t *fw = wsp->walk_data;
1081*0Sstevel@tonic-gate 
1082*0Sstevel@tonic-gate 	mdb_free(fw, sizeof (*fw));
1083*0Sstevel@tonic-gate }
1084*0Sstevel@tonic-gate 
1085*0Sstevel@tonic-gate static int
1086*0Sstevel@tonic-gate sctp_walk_init(mdb_walk_state_t *wsp)
1087*0Sstevel@tonic-gate {
1088*0Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)list_object(&sctp_list,
1089*0Sstevel@tonic-gate 	    sctp_list.list_head.list_next);
1090*0Sstevel@tonic-gate 	return (WALK_NEXT);
1091*0Sstevel@tonic-gate }
1092*0Sstevel@tonic-gate 
1093*0Sstevel@tonic-gate static int
1094*0Sstevel@tonic-gate sctp_walk_step(mdb_walk_state_t *wsp)
1095*0Sstevel@tonic-gate {
1096*0Sstevel@tonic-gate 	uintptr_t psctp = wsp->walk_addr;
1097*0Sstevel@tonic-gate 	sctp_t sctp;
1098*0Sstevel@tonic-gate 	int status;
1099*0Sstevel@tonic-gate 
1100*0Sstevel@tonic-gate 	if (mdb_vread(&sctp, sizeof (sctp), psctp) == -1) {
1101*0Sstevel@tonic-gate 		mdb_warn("failed to read sctp at %p", psctp);
1102*0Sstevel@tonic-gate 		return (WALK_ERR);
1103*0Sstevel@tonic-gate 	}
1104*0Sstevel@tonic-gate 	status = wsp->walk_callback(psctp, &sctp, wsp->walk_cbdata);
1105*0Sstevel@tonic-gate 	if (status != WALK_NEXT)
1106*0Sstevel@tonic-gate 		return (status);
1107*0Sstevel@tonic-gate 
1108*0Sstevel@tonic-gate 	if ((psctp = (uintptr_t)sctp.sctp_list.list_next) ==
1109*0Sstevel@tonic-gate 	    sctp_list_sym.st_value + OFFSETOF(list_t, list_head)) {
1110*0Sstevel@tonic-gate 		return (WALK_DONE);
1111*0Sstevel@tonic-gate 	} else {
1112*0Sstevel@tonic-gate 		wsp->walk_addr = (uintptr_t)list_object(&sctp_list, psctp);
1113*0Sstevel@tonic-gate 		return (WALK_NEXT);
1114*0Sstevel@tonic-gate 	}
1115*0Sstevel@tonic-gate }
1116*0Sstevel@tonic-gate 
1117*0Sstevel@tonic-gate static int
1118*0Sstevel@tonic-gate sctp_walk_faddr_init(mdb_walk_state_t *wsp)
1119*0Sstevel@tonic-gate {
1120*0Sstevel@tonic-gate 	sctp_t sctp;
1121*0Sstevel@tonic-gate 
1122*0Sstevel@tonic-gate 	if (wsp->walk_addr == NULL)
1123*0Sstevel@tonic-gate 		return (WALK_ERR);
1124*0Sstevel@tonic-gate 
1125*0Sstevel@tonic-gate 	if (mdb_vread(&sctp, sizeof (sctp), wsp->walk_addr) == -1) {
1126*0Sstevel@tonic-gate 		mdb_warn("failed to read sctp at %p", wsp->walk_addr);
1127*0Sstevel@tonic-gate 		return (WALK_ERR);
1128*0Sstevel@tonic-gate 	}
1129*0Sstevel@tonic-gate 	if ((wsp->walk_addr = (uintptr_t)sctp.sctp_faddrs) != NULL)
1130*0Sstevel@tonic-gate 		return (WALK_NEXT);
1131*0Sstevel@tonic-gate 	else
1132*0Sstevel@tonic-gate 		return (WALK_DONE);
1133*0Sstevel@tonic-gate }
1134*0Sstevel@tonic-gate 
1135*0Sstevel@tonic-gate static int
1136*0Sstevel@tonic-gate sctp_walk_faddr_step(mdb_walk_state_t *wsp)
1137*0Sstevel@tonic-gate {
1138*0Sstevel@tonic-gate 	uintptr_t faddr_ptr = wsp->walk_addr;
1139*0Sstevel@tonic-gate 	sctp_faddr_t sctp_faddr;
1140*0Sstevel@tonic-gate 	int status;
1141*0Sstevel@tonic-gate 
1142*0Sstevel@tonic-gate 	if (mdb_vread(&sctp_faddr, sizeof (sctp_faddr_t), faddr_ptr) == -1) {
1143*0Sstevel@tonic-gate 		mdb_warn("failed to read sctp_faddr_t at %p", faddr_ptr);
1144*0Sstevel@tonic-gate 		return (WALK_ERR);
1145*0Sstevel@tonic-gate 	}
1146*0Sstevel@tonic-gate 	status = wsp->walk_callback(faddr_ptr, &sctp_faddr, wsp->walk_cbdata);
1147*0Sstevel@tonic-gate 	if (status != WALK_NEXT)
1148*0Sstevel@tonic-gate 		return (status);
1149*0Sstevel@tonic-gate 	if ((faddr_ptr = (uintptr_t)sctp_faddr.next) == NULL) {
1150*0Sstevel@tonic-gate 		return (WALK_DONE);
1151*0Sstevel@tonic-gate 	} else {
1152*0Sstevel@tonic-gate 		wsp->walk_addr = faddr_ptr;
1153*0Sstevel@tonic-gate 		return (WALK_NEXT);
1154*0Sstevel@tonic-gate 	}
1155*0Sstevel@tonic-gate }
1156*0Sstevel@tonic-gate 
1157*0Sstevel@tonic-gate /*
1158*0Sstevel@tonic-gate  * Helper structure for sctp_walk_saddr.  It stores the sctp_t being walked,
1159*0Sstevel@tonic-gate  * the current index to the sctp_saddrs[], and the current count of the
1160*0Sstevel@tonic-gate  * sctp_saddr_ipif_t list.
1161*0Sstevel@tonic-gate  */
1162*0Sstevel@tonic-gate typedef struct {
1163*0Sstevel@tonic-gate 	sctp_t	sctp;
1164*0Sstevel@tonic-gate 	int	hash_index;
1165*0Sstevel@tonic-gate 	int	cur_cnt;
1166*0Sstevel@tonic-gate } saddr_walk_t;
1167*0Sstevel@tonic-gate 
1168*0Sstevel@tonic-gate static int
1169*0Sstevel@tonic-gate sctp_walk_saddr_init(mdb_walk_state_t *wsp)
1170*0Sstevel@tonic-gate {
1171*0Sstevel@tonic-gate 	sctp_t *sctp;
1172*0Sstevel@tonic-gate 	int i;
1173*0Sstevel@tonic-gate 	saddr_walk_t *swalker;
1174*0Sstevel@tonic-gate 
1175*0Sstevel@tonic-gate 	if (wsp->walk_addr == NULL)
1176*0Sstevel@tonic-gate 		return (WALK_ERR);
1177*0Sstevel@tonic-gate 
1178*0Sstevel@tonic-gate 	swalker = mdb_alloc(sizeof (saddr_walk_t), UM_SLEEP);
1179*0Sstevel@tonic-gate 	sctp = &swalker->sctp;
1180*0Sstevel@tonic-gate 	if (mdb_vread(sctp, sizeof (sctp_t), wsp->walk_addr) == -1) {
1181*0Sstevel@tonic-gate 		mdb_warn("failed to read sctp at %p", wsp->walk_addr);
1182*0Sstevel@tonic-gate 		mdb_free(swalker, sizeof (saddr_walk_t));
1183*0Sstevel@tonic-gate 		return (WALK_ERR);
1184*0Sstevel@tonic-gate 	}
1185*0Sstevel@tonic-gate 
1186*0Sstevel@tonic-gate 	/* Find the first source address. */
1187*0Sstevel@tonic-gate 	for (i = 0; i < SCTP_IPIF_HASH; i++) {
1188*0Sstevel@tonic-gate 		if (sctp->sctp_saddrs[i].ipif_count > 0) {
1189*0Sstevel@tonic-gate 			list_t *addr_list;
1190*0Sstevel@tonic-gate 
1191*0Sstevel@tonic-gate 			addr_list = &sctp->sctp_saddrs[i].sctp_ipif_list;
1192*0Sstevel@tonic-gate 			wsp->walk_addr = (uintptr_t)list_object(addr_list,
1193*0Sstevel@tonic-gate 			    addr_list->list_head.list_next);
1194*0Sstevel@tonic-gate 
1195*0Sstevel@tonic-gate 			/* Recode the current info */
1196*0Sstevel@tonic-gate 			swalker->hash_index = i;
1197*0Sstevel@tonic-gate 			swalker->cur_cnt = 1;
1198*0Sstevel@tonic-gate 			wsp->walk_data = swalker;
1199*0Sstevel@tonic-gate 
1200*0Sstevel@tonic-gate 			return (WALK_NEXT);
1201*0Sstevel@tonic-gate 		}
1202*0Sstevel@tonic-gate 	}
1203*0Sstevel@tonic-gate 	return (WALK_DONE);
1204*0Sstevel@tonic-gate }
1205*0Sstevel@tonic-gate 
1206*0Sstevel@tonic-gate static int
1207*0Sstevel@tonic-gate sctp_walk_saddr_step(mdb_walk_state_t *wsp)
1208*0Sstevel@tonic-gate {
1209*0Sstevel@tonic-gate 	uintptr_t saddr_ptr = wsp->walk_addr;
1210*0Sstevel@tonic-gate 	sctp_saddr_ipif_t saddr;
1211*0Sstevel@tonic-gate 	saddr_walk_t *swalker;
1212*0Sstevel@tonic-gate 	sctp_t *sctp;
1213*0Sstevel@tonic-gate 	int status;
1214*0Sstevel@tonic-gate 	int i, j;
1215*0Sstevel@tonic-gate 
1216*0Sstevel@tonic-gate 	if (mdb_vread(&saddr, sizeof (sctp_saddr_ipif_t), saddr_ptr) == -1) {
1217*0Sstevel@tonic-gate 		mdb_warn("failed to read sctp_saddr_ipif_t at %p", saddr_ptr);
1218*0Sstevel@tonic-gate 		return (WALK_ERR);
1219*0Sstevel@tonic-gate 	}
1220*0Sstevel@tonic-gate 	status = wsp->walk_callback(saddr_ptr, &saddr, wsp->walk_cbdata);
1221*0Sstevel@tonic-gate 	if (status != WALK_NEXT)
1222*0Sstevel@tonic-gate 		return (status);
1223*0Sstevel@tonic-gate 
1224*0Sstevel@tonic-gate 	swalker = (saddr_walk_t *)wsp->walk_data;
1225*0Sstevel@tonic-gate 	sctp = &swalker->sctp;
1226*0Sstevel@tonic-gate 	i = swalker->hash_index;
1227*0Sstevel@tonic-gate 	j = swalker->cur_cnt;
1228*0Sstevel@tonic-gate 
1229*0Sstevel@tonic-gate 	/*
1230*0Sstevel@tonic-gate 	 * If there is still a source address in the current list, return it.
1231*0Sstevel@tonic-gate 	 * Otherwise, go to the next list in the sctp_saddrs[].
1232*0Sstevel@tonic-gate 	 */
1233*0Sstevel@tonic-gate 	if (j++ < sctp->sctp_saddrs[i].ipif_count) {
1234*0Sstevel@tonic-gate 		wsp->walk_addr = (uintptr_t)saddr.saddr_ipif.list_next;
1235*0Sstevel@tonic-gate 		swalker->cur_cnt = j;
1236*0Sstevel@tonic-gate 		return (WALK_NEXT);
1237*0Sstevel@tonic-gate 	} else {
1238*0Sstevel@tonic-gate 		list_t *lst;
1239*0Sstevel@tonic-gate 
1240*0Sstevel@tonic-gate 		for (i = i + 1; i < SCTP_IPIF_HASH; i++) {
1241*0Sstevel@tonic-gate 			if (sctp->sctp_saddrs[i].ipif_count > 0) {
1242*0Sstevel@tonic-gate 				lst = &sctp->sctp_saddrs[i].sctp_ipif_list;
1243*0Sstevel@tonic-gate 				wsp->walk_addr = (uintptr_t)list_object(
1244*0Sstevel@tonic-gate 				    lst, lst->list_head.list_next);
1245*0Sstevel@tonic-gate 				swalker->hash_index = i;
1246*0Sstevel@tonic-gate 				swalker->cur_cnt = 1;
1247*0Sstevel@tonic-gate 				return (WALK_NEXT);
1248*0Sstevel@tonic-gate 			}
1249*0Sstevel@tonic-gate 		}
1250*0Sstevel@tonic-gate 	}
1251*0Sstevel@tonic-gate 	return (WALK_DONE);
1252*0Sstevel@tonic-gate }
1253*0Sstevel@tonic-gate 
1254*0Sstevel@tonic-gate static void
1255*0Sstevel@tonic-gate sctp_walk_saddr_fini(mdb_walk_state_t *wsp)
1256*0Sstevel@tonic-gate {
1257*0Sstevel@tonic-gate 	saddr_walk_t *swalker = (saddr_walk_t *)wsp->walk_data;
1258*0Sstevel@tonic-gate 
1259*0Sstevel@tonic-gate 	mdb_free(swalker, sizeof (saddr_walk_t));
1260*0Sstevel@tonic-gate }
1261*0Sstevel@tonic-gate 
1262*0Sstevel@tonic-gate static int
1263*0Sstevel@tonic-gate sctp_walk_ill_init(mdb_walk_state_t *wsp)
1264*0Sstevel@tonic-gate {
1265*0Sstevel@tonic-gate 	intptr_t i;
1266*0Sstevel@tonic-gate 
1267*0Sstevel@tonic-gate 	/* Find the first ill. */
1268*0Sstevel@tonic-gate 	for (i = 0; i < SCTP_ILL_HASH; i++) {
1269*0Sstevel@tonic-gate 		if (local_g_ills[i].ill_count > 0) {
1270*0Sstevel@tonic-gate 			wsp->walk_addr = (uintptr_t)list_object(
1271*0Sstevel@tonic-gate 			    &local_g_ills[i].sctp_ill_list,
1272*0Sstevel@tonic-gate 			    local_g_ills[i].sctp_ill_list.list_head.list_next);
1273*0Sstevel@tonic-gate 			wsp->walk_data = (void *)i;
1274*0Sstevel@tonic-gate 			wsp->walk_arg = (void *)1;
1275*0Sstevel@tonic-gate 			return (WALK_NEXT);
1276*0Sstevel@tonic-gate 		}
1277*0Sstevel@tonic-gate 	}
1278*0Sstevel@tonic-gate 	return (WALK_DONE);
1279*0Sstevel@tonic-gate }
1280*0Sstevel@tonic-gate 
1281*0Sstevel@tonic-gate static int
1282*0Sstevel@tonic-gate sctp_walk_ill_step(mdb_walk_state_t *wsp)
1283*0Sstevel@tonic-gate {
1284*0Sstevel@tonic-gate 	uintptr_t ill_ptr = wsp->walk_addr;
1285*0Sstevel@tonic-gate 	sctp_ill_t ill;
1286*0Sstevel@tonic-gate 	int status;
1287*0Sstevel@tonic-gate 	intptr_t i, j;
1288*0Sstevel@tonic-gate 
1289*0Sstevel@tonic-gate 	if (mdb_vread(&ill, sizeof (sctp_ill_t), ill_ptr) == -1) {
1290*0Sstevel@tonic-gate 		mdb_warn("failed to read sctp_ill_t at %p", ill_ptr);
1291*0Sstevel@tonic-gate 		return (WALK_ERR);
1292*0Sstevel@tonic-gate 	}
1293*0Sstevel@tonic-gate 	status = wsp->walk_callback(ill_ptr, &ill, wsp->walk_cbdata);
1294*0Sstevel@tonic-gate 	if (status != WALK_NEXT)
1295*0Sstevel@tonic-gate 		return (status);
1296*0Sstevel@tonic-gate 
1297*0Sstevel@tonic-gate 	i = (intptr_t)wsp->walk_data;
1298*0Sstevel@tonic-gate 	j = (intptr_t)wsp->walk_arg;
1299*0Sstevel@tonic-gate 
1300*0Sstevel@tonic-gate 	/*
1301*0Sstevel@tonic-gate 	 * If there is still an ill in the current list, return it.
1302*0Sstevel@tonic-gate 	 * Otherwise, go to the next list and find another one.
1303*0Sstevel@tonic-gate 	 */
1304*0Sstevel@tonic-gate 	if (j++ < local_g_ills[i].ill_count) {
1305*0Sstevel@tonic-gate 		wsp->walk_addr = (uintptr_t)ill.sctp_ills.list_next;
1306*0Sstevel@tonic-gate 		wsp->walk_data = (void *)i;
1307*0Sstevel@tonic-gate 		wsp->walk_arg = (void *)j;
1308*0Sstevel@tonic-gate 		return (WALK_NEXT);
1309*0Sstevel@tonic-gate 	} else {
1310*0Sstevel@tonic-gate 		list_t *ill_list;
1311*0Sstevel@tonic-gate 
1312*0Sstevel@tonic-gate 		for (i = i + 1; i < SCTP_ILL_HASH; i++) {
1313*0Sstevel@tonic-gate 			if (local_g_ills[i].ill_count > 0) {
1314*0Sstevel@tonic-gate 				ill_list = &local_g_ills[i].sctp_ill_list;
1315*0Sstevel@tonic-gate 				wsp->walk_addr = (uintptr_t)list_object(
1316*0Sstevel@tonic-gate 				    ill_list, ill_list->list_head.list_next);
1317*0Sstevel@tonic-gate 
1318*0Sstevel@tonic-gate 				/* Record the current position. */
1319*0Sstevel@tonic-gate 				wsp->walk_data = (void *)i;
1320*0Sstevel@tonic-gate 				wsp->walk_arg = (void *)1;
1321*0Sstevel@tonic-gate 				return (WALK_NEXT);
1322*0Sstevel@tonic-gate 			}
1323*0Sstevel@tonic-gate 		}
1324*0Sstevel@tonic-gate 	}
1325*0Sstevel@tonic-gate 	return (WALK_DONE);
1326*0Sstevel@tonic-gate }
1327*0Sstevel@tonic-gate 
1328*0Sstevel@tonic-gate static int
1329*0Sstevel@tonic-gate sctp_walk_ipif_init(mdb_walk_state_t *wsp)
1330*0Sstevel@tonic-gate {
1331*0Sstevel@tonic-gate 	intptr_t i;
1332*0Sstevel@tonic-gate 	list_t *ipif_list;
1333*0Sstevel@tonic-gate 
1334*0Sstevel@tonic-gate 	for (i = 0; i < SCTP_IPIF_HASH; i++) {
1335*0Sstevel@tonic-gate 		if (local_g_ipifs[i].ipif_count > 0) {
1336*0Sstevel@tonic-gate 			ipif_list = &local_g_ipifs[i].sctp_ipif_list;
1337*0Sstevel@tonic-gate 
1338*0Sstevel@tonic-gate 			wsp->walk_addr = (uintptr_t)list_object(ipif_list,
1339*0Sstevel@tonic-gate 			    ipif_list->list_head.list_next);
1340*0Sstevel@tonic-gate 			wsp->walk_data = (void *)i;
1341*0Sstevel@tonic-gate 			wsp->walk_arg = (void *)1;
1342*0Sstevel@tonic-gate 			return (WALK_NEXT);
1343*0Sstevel@tonic-gate 		}
1344*0Sstevel@tonic-gate 	}
1345*0Sstevel@tonic-gate 	return (WALK_DONE);
1346*0Sstevel@tonic-gate }
1347*0Sstevel@tonic-gate 
1348*0Sstevel@tonic-gate static int
1349*0Sstevel@tonic-gate sctp_walk_ipif_step(mdb_walk_state_t *wsp)
1350*0Sstevel@tonic-gate {
1351*0Sstevel@tonic-gate 	uintptr_t ipif_ptr = wsp->walk_addr;
1352*0Sstevel@tonic-gate 	sctp_ipif_t ipif;
1353*0Sstevel@tonic-gate 	int status;
1354*0Sstevel@tonic-gate 	intptr_t i, j;
1355*0Sstevel@tonic-gate 
1356*0Sstevel@tonic-gate 	if (mdb_vread(&ipif, sizeof (sctp_ipif_t), ipif_ptr) == -1) {
1357*0Sstevel@tonic-gate 		mdb_warn("failed to read sctp_ipif_t at %p", ipif_ptr);
1358*0Sstevel@tonic-gate 		return (WALK_ERR);
1359*0Sstevel@tonic-gate 	}
1360*0Sstevel@tonic-gate 	status = wsp->walk_callback(ipif_ptr, &ipif, wsp->walk_cbdata);
1361*0Sstevel@tonic-gate 	if (status != WALK_NEXT)
1362*0Sstevel@tonic-gate 		return (status);
1363*0Sstevel@tonic-gate 
1364*0Sstevel@tonic-gate 	i = (intptr_t)wsp->walk_data;
1365*0Sstevel@tonic-gate 	j = (intptr_t)wsp->walk_arg;
1366*0Sstevel@tonic-gate 
1367*0Sstevel@tonic-gate 	/*
1368*0Sstevel@tonic-gate 	 * If there is still an ipif in the current list, return it.
1369*0Sstevel@tonic-gate 	 * Otherwise, go to the next list and find another one.
1370*0Sstevel@tonic-gate 	 */
1371*0Sstevel@tonic-gate 	if (j++ < local_g_ipifs[i].ipif_count) {
1372*0Sstevel@tonic-gate 		wsp->walk_addr = (uintptr_t)ipif.sctp_ipifs.list_next;
1373*0Sstevel@tonic-gate 		wsp->walk_data = (void *)i;
1374*0Sstevel@tonic-gate 		wsp->walk_arg = (void *)j;
1375*0Sstevel@tonic-gate 		return (WALK_NEXT);
1376*0Sstevel@tonic-gate 	} else {
1377*0Sstevel@tonic-gate 		list_t *ipif_list;
1378*0Sstevel@tonic-gate 
1379*0Sstevel@tonic-gate 		for (i = i + 1; i < SCTP_IPIF_HASH; i++) {
1380*0Sstevel@tonic-gate 			if (local_g_ipifs[i].ipif_count > 0) {
1381*0Sstevel@tonic-gate 				ipif_list = &local_g_ipifs[i].sctp_ipif_list;
1382*0Sstevel@tonic-gate 				wsp->walk_addr = (uintptr_t)list_object(
1383*0Sstevel@tonic-gate 				    ipif_list, ipif_list->list_head.list_next);
1384*0Sstevel@tonic-gate 
1385*0Sstevel@tonic-gate 				/* Record the current position */
1386*0Sstevel@tonic-gate 				wsp->walk_data = (void *)i;
1387*0Sstevel@tonic-gate 				wsp->walk_arg = (void *)1;
1388*0Sstevel@tonic-gate 				return (WALK_NEXT);
1389*0Sstevel@tonic-gate 			}
1390*0Sstevel@tonic-gate 		}
1391*0Sstevel@tonic-gate 	}
1392*0Sstevel@tonic-gate 	return (WALK_DONE);
1393*0Sstevel@tonic-gate }
1394*0Sstevel@tonic-gate 
1395*0Sstevel@tonic-gate static void
1396*0Sstevel@tonic-gate sctp_help(void)
1397*0Sstevel@tonic-gate {
1398*0Sstevel@tonic-gate 	mdb_printf("Print information for a given SCTP sctp_t\n\n");
1399*0Sstevel@tonic-gate 	mdb_printf("Options:\n");
1400*0Sstevel@tonic-gate 	mdb_printf("\t-a\t All the information\n");
1401*0Sstevel@tonic-gate 	mdb_printf("\t-f\t Flags\n");
1402*0Sstevel@tonic-gate 	mdb_printf("\t-h\t Hash Tables\n");
1403*0Sstevel@tonic-gate 	mdb_printf("\t-o\t Outbound Data\n");
1404*0Sstevel@tonic-gate 	mdb_printf("\t-i\t Inbound Data\n");
1405*0Sstevel@tonic-gate 	mdb_printf("\t-m\t Miscellaneous Information\n");
1406*0Sstevel@tonic-gate 	mdb_printf("\t-r\t RTT Tracking\n");
1407*0Sstevel@tonic-gate 	mdb_printf("\t-S\t Stats Counters\n");
1408*0Sstevel@tonic-gate 	mdb_printf("\t-F\t Flow Control\n");
1409*0Sstevel@tonic-gate 	mdb_printf("\t-H\t Composite Headers\n");
1410*0Sstevel@tonic-gate 	mdb_printf("\t-p\t PMTUD\n");
1411*0Sstevel@tonic-gate 	mdb_printf("\t-R\t Retransmit Information\n");
1412*0Sstevel@tonic-gate 	mdb_printf("\t-C\t Connection State\n");
1413*0Sstevel@tonic-gate 	mdb_printf("\t-c\t Cleanup / Close\n");
1414*0Sstevel@tonic-gate 	mdb_printf("\t-e\t Extensions and Reliable Control Chunks\n");
1415*0Sstevel@tonic-gate 	mdb_printf("\t-d\t Local and Peer addresses\n");
1416*0Sstevel@tonic-gate 	mdb_printf("\t-P\t Peer addresses\n");
1417*0Sstevel@tonic-gate }
1418*0Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = {
1419*0Sstevel@tonic-gate 	{ "sctp", ":[-afhoimrSFHpRCcedP]",
1420*0Sstevel@tonic-gate 	    "display sctp control structure", sctp, sctp_help },
1421*0Sstevel@tonic-gate 	{ "sctp_set", ":", "display a SCTP set", sctp_set },
1422*0Sstevel@tonic-gate 	{ "sctp_faddr", ":", "display a faddr", sctp_faddr },
1423*0Sstevel@tonic-gate 	{ "sctp_istr_msgs", ":", "display msg list on an instream",
1424*0Sstevel@tonic-gate 	    sctp_istr_msgs },
1425*0Sstevel@tonic-gate 	{ "sctp_mdata_chunk", ":", "display a data chunk in an mblk",
1426*0Sstevel@tonic-gate 	    sctp_mdata_chunk },
1427*0Sstevel@tonic-gate 	{ "sctp_xmit_list", ":", "display sctp xmit lists", sctp_xmit_list },
1428*0Sstevel@tonic-gate 	{ "sctp_instr", ":", "display instr", sctp_instr },
1429*0Sstevel@tonic-gate 	{ "sctp_reass_list", ":", "display reass list", sctp_reass_list },
1430*0Sstevel@tonic-gate 	{ "sctp_uo_reass_list", ":", "display un-ordered reass list",
1431*0Sstevel@tonic-gate 	    sctp_uo_reass_list },
1432*0Sstevel@tonic-gate 	{ NULL }
1433*0Sstevel@tonic-gate };
1434*0Sstevel@tonic-gate 
1435*0Sstevel@tonic-gate static const fanout_init_t listen_fanout_init = {
1436*0Sstevel@tonic-gate 	"sctp_listen_fanout", listen_size, listen_next
1437*0Sstevel@tonic-gate };
1438*0Sstevel@tonic-gate 
1439*0Sstevel@tonic-gate static const fanout_init_t conn_fanout_init = {
1440*0Sstevel@tonic-gate 	"sctp_conn_fanout", conn_size, conn_next
1441*0Sstevel@tonic-gate };
1442*0Sstevel@tonic-gate 
1443*0Sstevel@tonic-gate static const fanout_init_t bind_fanout_init = {
1444*0Sstevel@tonic-gate 	"sctp_bind_fanout", bind_size, bind_next
1445*0Sstevel@tonic-gate };
1446*0Sstevel@tonic-gate 
1447*0Sstevel@tonic-gate static const mdb_walker_t walkers[] = {
1448*0Sstevel@tonic-gate 	{ "sctps", "walk the full chain of sctps",
1449*0Sstevel@tonic-gate 	    sctp_walk_init, sctp_walk_step, NULL },
1450*0Sstevel@tonic-gate 	{ "sctp_listen_fanout", "walk the sctp listen fanout",
1451*0Sstevel@tonic-gate 	    fanout_walk_init, fanout_walk_step, fanout_walk_fini,
1452*0Sstevel@tonic-gate 	    (void *)&listen_fanout_init },
1453*0Sstevel@tonic-gate 	{ "sctp_conn_fanout", "walk the sctp conn fanout",
1454*0Sstevel@tonic-gate 	    fanout_walk_init, fanout_walk_step, fanout_walk_fini,
1455*0Sstevel@tonic-gate 	    (void *)&conn_fanout_init },
1456*0Sstevel@tonic-gate 	{ "sctp_bind_fanout", "walk the sctp bind fanout",
1457*0Sstevel@tonic-gate 	    fanout_walk_init, fanout_walk_step, fanout_walk_fini,
1458*0Sstevel@tonic-gate 	    (void *)&bind_fanout_init },
1459*0Sstevel@tonic-gate 	{ "sctp_walk_faddr", "walk the peer address list of a given sctp_t",
1460*0Sstevel@tonic-gate 	    sctp_walk_faddr_init, sctp_walk_faddr_step, NULL },
1461*0Sstevel@tonic-gate 	{ "sctp_walk_saddr", "walk the local address list of a given sctp_t",
1462*0Sstevel@tonic-gate 	    sctp_walk_saddr_init, sctp_walk_saddr_step, sctp_walk_saddr_fini },
1463*0Sstevel@tonic-gate 	{ "sctp_walk_ill", "walk the sctp_g_ills list",
1464*0Sstevel@tonic-gate 	    sctp_walk_ill_init, sctp_walk_ill_step, NULL },
1465*0Sstevel@tonic-gate 	{ "sctp_walk_ipif", "walk the sctp_g_ipif list",
1466*0Sstevel@tonic-gate 	    sctp_walk_ipif_init, sctp_walk_ipif_step, NULL },
1467*0Sstevel@tonic-gate 	{ NULL }
1468*0Sstevel@tonic-gate };
1469*0Sstevel@tonic-gate 
1470*0Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers };
1471*0Sstevel@tonic-gate 
1472*0Sstevel@tonic-gate const mdb_modinfo_t *
1473*0Sstevel@tonic-gate _mdb_init(void)
1474*0Sstevel@tonic-gate {
1475*0Sstevel@tonic-gate 	GElf_Sym sym;
1476*0Sstevel@tonic-gate 	GElf_Sym ills_sym;
1477*0Sstevel@tonic-gate 	GElf_Sym ipifs_sym;
1478*0Sstevel@tonic-gate 
1479*0Sstevel@tonic-gate 	if (mdb_lookup_by_name("sctp_g_list", &sctp_list_sym) == -1) {
1480*0Sstevel@tonic-gate 		mdb_warn("failed to find 'sctp_g_list'");
1481*0Sstevel@tonic-gate 		return (NULL);
1482*0Sstevel@tonic-gate 	}
1483*0Sstevel@tonic-gate 	if (mdb_vread(&sctp_list, sizeof (list_t),
1484*0Sstevel@tonic-gate 	    (uintptr_t)sctp_list_sym.st_value) == -1) {
1485*0Sstevel@tonic-gate 		mdb_warn("failed to read 'sctp_g_list'");
1486*0Sstevel@tonic-gate 		return (NULL);
1487*0Sstevel@tonic-gate 	}
1488*0Sstevel@tonic-gate 	if (mdb_lookup_by_name("sctp_conn_hash_size", &sym) != -1) {
1489*0Sstevel@tonic-gate 		if (mdb_vread(&sctp_conn_hash_size,
1490*0Sstevel@tonic-gate 		    sizeof (sctp_conn_hash_size), sym.st_value) == -1) {
1491*0Sstevel@tonic-gate 			mdb_warn("failed to read 'sctp_conn_hash_size'");
1492*0Sstevel@tonic-gate 			return (NULL);
1493*0Sstevel@tonic-gate 		}
1494*0Sstevel@tonic-gate 	}
1495*0Sstevel@tonic-gate 	if (mdb_lookup_by_name("sctp_g_ills", &ills_sym) == -1) {
1496*0Sstevel@tonic-gate 		mdb_warn("failed to find 'sctp_g_ills'");
1497*0Sstevel@tonic-gate 		return (NULL);
1498*0Sstevel@tonic-gate 	}
1499*0Sstevel@tonic-gate 	if (mdb_vread(&local_g_ills, sizeof (local_g_ills),
1500*0Sstevel@tonic-gate 	    (uintptr_t)ills_sym.st_value) == -1) {
1501*0Sstevel@tonic-gate 		mdb_warn("failed to read 'sctp_g_ills'");
1502*0Sstevel@tonic-gate 		return (NULL);
1503*0Sstevel@tonic-gate 	}
1504*0Sstevel@tonic-gate 	if (mdb_lookup_by_name("sctp_g_ipifs", &ipifs_sym) == -1) {
1505*0Sstevel@tonic-gate 		mdb_warn("failed to find 'sctp_g_ipifs'");
1506*0Sstevel@tonic-gate 		return (NULL);
1507*0Sstevel@tonic-gate 	}
1508*0Sstevel@tonic-gate 	if (mdb_vread(&local_g_ipifs, sizeof (local_g_ipifs),
1509*0Sstevel@tonic-gate 	    (uintptr_t)ipifs_sym.st_value) == -1) {
1510*0Sstevel@tonic-gate 		mdb_warn("failed to read 'sctp_g_ipifs'");
1511*0Sstevel@tonic-gate 		return (NULL);
1512*0Sstevel@tonic-gate 	}
1513*0Sstevel@tonic-gate 
1514*0Sstevel@tonic-gate 	return (&modinfo);
1515*0Sstevel@tonic-gate }
1516