1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/stream.h>
31*7c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
32*7c478bd9Sstevel@tonic-gate #define	_SUN_TPI_VERSION 2
33*7c478bd9Sstevel@tonic-gate #include <sys/tihdr.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #include <netinet/in.h>
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate #include <inet/common.h>
40*7c478bd9Sstevel@tonic-gate #include <inet/ip.h>
41*7c478bd9Sstevel@tonic-gate #include <inet/mib2.h>
42*7c478bd9Sstevel@tonic-gate #include <inet/snmpcom.h>
43*7c478bd9Sstevel@tonic-gate #include <inet/kstatcom.h>
44*7c478bd9Sstevel@tonic-gate #include <inet/ipclassifier.h>
45*7c478bd9Sstevel@tonic-gate #include "sctp_impl.h"
46*7c478bd9Sstevel@tonic-gate #include "sctp_addr.h"
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate mib2_sctp_t	sctp_mib;
49*7c478bd9Sstevel@tonic-gate kstat_t		*sctp_mibkp;	/* kstat exporting sctp_mib data */
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate static int sctp_snmp_state(sctp_t *sctp);
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate static int
54*7c478bd9Sstevel@tonic-gate sctp_kstat_update(kstat_t *kp, int rw)
55*7c478bd9Sstevel@tonic-gate {
56*7c478bd9Sstevel@tonic-gate 	sctp_named_kstat_t	*sctpkp;
57*7c478bd9Sstevel@tonic-gate 	sctp_t			*sctp, *sctp_prev;
58*7c478bd9Sstevel@tonic-gate 	zoneid_t		zoneid;
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate 	if (kp == NULL|| kp->ks_data == NULL)
61*7c478bd9Sstevel@tonic-gate 		return (EIO);
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate 	if (rw == KSTAT_WRITE)
64*7c478bd9Sstevel@tonic-gate 		return (EACCES);
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate 	zoneid = getzoneid();
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate 	/*
69*7c478bd9Sstevel@tonic-gate 	 * Get the number of current associations and gather their
70*7c478bd9Sstevel@tonic-gate 	 * individual set of statistics.
71*7c478bd9Sstevel@tonic-gate 	 */
72*7c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpCurrEstab, 0);
73*7c478bd9Sstevel@tonic-gate 	sctp = gsctp;
74*7c478bd9Sstevel@tonic-gate 	sctp_prev = NULL;
75*7c478bd9Sstevel@tonic-gate 	mutex_enter(&sctp_g_lock);
76*7c478bd9Sstevel@tonic-gate 	while (sctp != NULL) {
77*7c478bd9Sstevel@tonic-gate 		mutex_enter(&sctp->sctp_reflock);
78*7c478bd9Sstevel@tonic-gate 		if (sctp->sctp_condemned) {
79*7c478bd9Sstevel@tonic-gate 			mutex_exit(&sctp->sctp_reflock);
80*7c478bd9Sstevel@tonic-gate 			sctp = list_next(&sctp_g_list, sctp);
81*7c478bd9Sstevel@tonic-gate 			continue;
82*7c478bd9Sstevel@tonic-gate 		}
83*7c478bd9Sstevel@tonic-gate 		sctp->sctp_refcnt++;
84*7c478bd9Sstevel@tonic-gate 		mutex_exit(&sctp->sctp_reflock);
85*7c478bd9Sstevel@tonic-gate 		mutex_exit(&sctp_g_lock);
86*7c478bd9Sstevel@tonic-gate 		if (sctp_prev != NULL)
87*7c478bd9Sstevel@tonic-gate 			SCTP_REFRELE(sctp_prev);
88*7c478bd9Sstevel@tonic-gate 		if (sctp->sctp_connp->conn_zoneid != zoneid)
89*7c478bd9Sstevel@tonic-gate 			goto next_sctp;
90*7c478bd9Sstevel@tonic-gate 		if (sctp->sctp_state == SCTPS_ESTABLISHED ||
91*7c478bd9Sstevel@tonic-gate 		    sctp->sctp_state == SCTPS_SHUTDOWN_PENDING ||
92*7c478bd9Sstevel@tonic-gate 		    sctp->sctp_state == SCTPS_SHUTDOWN_RECEIVED) {
93*7c478bd9Sstevel@tonic-gate 			BUMP_MIB(&sctp_mib, sctpCurrEstab);
94*7c478bd9Sstevel@tonic-gate 		}
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate 		if (sctp->sctp_opkts) {
97*7c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpOutSCTPPkts,
98*7c478bd9Sstevel@tonic-gate 			    sctp->sctp_opkts);
99*7c478bd9Sstevel@tonic-gate 			sctp->sctp_opkts = 0;
100*7c478bd9Sstevel@tonic-gate 		}
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 		if (sctp->sctp_obchunks) {
103*7c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpOutCtrlChunks,
104*7c478bd9Sstevel@tonic-gate 			    sctp->sctp_obchunks);
105*7c478bd9Sstevel@tonic-gate 			sctp->sctp_obchunks = 0;
106*7c478bd9Sstevel@tonic-gate 		}
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate 		if (sctp->sctp_odchunks) {
109*7c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpOutOrderChunks,
110*7c478bd9Sstevel@tonic-gate 			    sctp->sctp_odchunks);
111*7c478bd9Sstevel@tonic-gate 			sctp->sctp_odchunks = 0;
112*7c478bd9Sstevel@tonic-gate 		}
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate 		if (sctp->sctp_oudchunks) {
115*7c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpOutUnorderChunks,
116*7c478bd9Sstevel@tonic-gate 			    sctp->sctp_oudchunks);
117*7c478bd9Sstevel@tonic-gate 			sctp->sctp_oudchunks = 0;
118*7c478bd9Sstevel@tonic-gate 		}
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate 		if (sctp->sctp_rxtchunks) {
121*7c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpRetransChunks,
122*7c478bd9Sstevel@tonic-gate 			    sctp->sctp_rxtchunks);
123*7c478bd9Sstevel@tonic-gate 			sctp->sctp_rxtchunks = 0;
124*7c478bd9Sstevel@tonic-gate 		}
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate 		if (sctp->sctp_ipkts) {
127*7c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpInSCTPPkts, sctp->sctp_ipkts);
128*7c478bd9Sstevel@tonic-gate 			sctp->sctp_ipkts = 0;
129*7c478bd9Sstevel@tonic-gate 		}
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate 		if (sctp->sctp_ibchunks) {
132*7c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpInCtrlChunks,
133*7c478bd9Sstevel@tonic-gate 			    sctp->sctp_ibchunks);
134*7c478bd9Sstevel@tonic-gate 			sctp->sctp_ibchunks = 0;
135*7c478bd9Sstevel@tonic-gate 		}
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate 		if (sctp->sctp_idchunks) {
138*7c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpInOrderChunks,
139*7c478bd9Sstevel@tonic-gate 			    sctp->sctp_idchunks);
140*7c478bd9Sstevel@tonic-gate 			sctp->sctp_idchunks = 0;
141*7c478bd9Sstevel@tonic-gate 		}
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate 		if (sctp->sctp_iudchunks) {
144*7c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpInUnorderChunks,
145*7c478bd9Sstevel@tonic-gate 			    sctp->sctp_iudchunks);
146*7c478bd9Sstevel@tonic-gate 			sctp->sctp_iudchunks = 0;
147*7c478bd9Sstevel@tonic-gate 		}
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate 		if (sctp->sctp_fragdmsgs) {
150*7c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpFragUsrMsgs,
151*7c478bd9Sstevel@tonic-gate 			    sctp->sctp_fragdmsgs);
152*7c478bd9Sstevel@tonic-gate 			sctp->sctp_fragdmsgs = 0;
153*7c478bd9Sstevel@tonic-gate 		}
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate 		if (sctp->sctp_reassmsgs) {
156*7c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpReasmUsrMsgs,
157*7c478bd9Sstevel@tonic-gate 			    sctp->sctp_reassmsgs);
158*7c478bd9Sstevel@tonic-gate 			sctp->sctp_reassmsgs = 0;
159*7c478bd9Sstevel@tonic-gate 		}
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate next_sctp:
162*7c478bd9Sstevel@tonic-gate 		sctp_prev = sctp;
163*7c478bd9Sstevel@tonic-gate 		mutex_enter(&sctp_g_lock);
164*7c478bd9Sstevel@tonic-gate 		sctp = list_next(&sctp_g_list, sctp);
165*7c478bd9Sstevel@tonic-gate 	}
166*7c478bd9Sstevel@tonic-gate 	mutex_exit(&sctp_g_lock);
167*7c478bd9Sstevel@tonic-gate 	if (sctp_prev != NULL)
168*7c478bd9Sstevel@tonic-gate 		SCTP_REFRELE(sctp_prev);
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate 	/* Copy data from the SCTP MIB */
171*7c478bd9Sstevel@tonic-gate 	sctpkp = (sctp_named_kstat_t *)kp->ks_data;
172*7c478bd9Sstevel@tonic-gate 
173*7c478bd9Sstevel@tonic-gate 	/* These are from global ndd params. */
174*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpRtoMin.value.ui32 = sctp_rto_ming;
175*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpRtoMax.value.ui32 = sctp_rto_maxg;
176*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpRtoInitial.value.ui32 = sctp_rto_initialg;
177*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpValCookieLife.value.ui32 = sctp_cookie_life;
178*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpMaxInitRetr.value.ui32 = sctp_max_init_retr;
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpCurrEstab.value.i32 = sctp_mib.sctpCurrEstab;
181*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpActiveEstab.value.i32 = sctp_mib.sctpActiveEstab;
182*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpPassiveEstab.value.i32 = sctp_mib.sctpPassiveEstab;
183*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpAborted.value.i32 = sctp_mib.sctpAborted;
184*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpShutdowns.value.i32 = sctp_mib.sctpShutdowns;
185*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpOutOfBlue.value.i32 = sctp_mib.sctpOutOfBlue;
186*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpChecksumError.value.i32 = sctp_mib.sctpChecksumError;
187*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpOutCtrlChunks.value.i64 = sctp_mib.sctpOutCtrlChunks;
188*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpOutOrderChunks.value.i64 = sctp_mib.sctpOutOrderChunks;
189*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpOutUnorderChunks.value.i64 = sctp_mib.sctpOutUnorderChunks;
190*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpRetransChunks.value.i64 = sctp_mib.sctpRetransChunks;
191*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpOutAck.value.i32 = sctp_mib.sctpOutAck;
192*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpOutAckDelayed.value.i32 = sctp_mib.sctpOutAckDelayed;
193*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpOutWinUpdate.value.i32 = sctp_mib.sctpOutWinUpdate;
194*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpOutFastRetrans.value.i32 = sctp_mib.sctpOutFastRetrans;
195*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpOutWinProbe.value.i32 = sctp_mib.sctpOutWinProbe;
196*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpInCtrlChunks.value.i64 = sctp_mib.sctpInCtrlChunks;
197*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpInOrderChunks.value.i64 = sctp_mib.sctpInOrderChunks;
198*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpInUnorderChunks.value.i64 = sctp_mib.sctpInUnorderChunks;
199*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpInAck.value.i32 = sctp_mib.sctpInAck;
200*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpInDupAck.value.i32 = sctp_mib.sctpInDupAck;
201*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpInAckUnsent.value.i32 = sctp_mib.sctpInAckUnsent;
202*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpFragUsrMsgs.value.i64 = sctp_mib.sctpFragUsrMsgs;
203*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpReasmUsrMsgs.value.i64 = sctp_mib.sctpReasmUsrMsgs;
204*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpOutSCTPPkts.value.i64 = sctp_mib.sctpOutSCTPPkts;
205*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpInSCTPPkts.value.i64 = sctp_mib.sctpInSCTPPkts;
206*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpInInvalidCookie.value.i32 = sctp_mib.sctpInInvalidCookie;
207*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpTimRetrans.value.i32 = sctp_mib.sctpTimRetrans;
208*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpTimRetransDrop.value.i32 = sctp_mib.sctpTimRetransDrop;
209*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpTimHeartBeatProbe.value.i32 =
210*7c478bd9Sstevel@tonic-gate 	    sctp_mib.sctpTimHeartBeatProbe;
211*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpTimHeartBeatDrop.value.i32 = sctp_mib.sctpTimHeartBeatDrop;
212*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpListenDrop.value.i32 = sctp_mib.sctpListenDrop;
213*7c478bd9Sstevel@tonic-gate 	sctpkp->sctpInClosed.value.i32 = sctp_mib.sctpInClosed;
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate 	return (0);
216*7c478bd9Sstevel@tonic-gate }
217*7c478bd9Sstevel@tonic-gate 
218*7c478bd9Sstevel@tonic-gate void
219*7c478bd9Sstevel@tonic-gate sctp_kstat_init(void)
220*7c478bd9Sstevel@tonic-gate {
221*7c478bd9Sstevel@tonic-gate 	sctp_named_kstat_t template = {
222*7c478bd9Sstevel@tonic-gate 		{ "sctpRtoAlgorithm",		KSTAT_DATA_INT32, 0 },
223*7c478bd9Sstevel@tonic-gate 		{ "sctpRtoMin",			KSTAT_DATA_UINT32, 0 },
224*7c478bd9Sstevel@tonic-gate 		{ "sctpRtoMax",			KSTAT_DATA_UINT32, 0 },
225*7c478bd9Sstevel@tonic-gate 		{ "sctpRtoInitial",		KSTAT_DATA_UINT32, 0 },
226*7c478bd9Sstevel@tonic-gate 		{ "sctpMaxAssocs",		KSTAT_DATA_INT32, 0 },
227*7c478bd9Sstevel@tonic-gate 		{ "sctpValCookieLife",		KSTAT_DATA_UINT32, 0 },
228*7c478bd9Sstevel@tonic-gate 		{ "sctpMaxInitRetr",		KSTAT_DATA_UINT32, 0 },
229*7c478bd9Sstevel@tonic-gate 		{ "sctpCurrEstab",		KSTAT_DATA_INT32, 0 },
230*7c478bd9Sstevel@tonic-gate 		{ "sctpActiveEstab",		KSTAT_DATA_INT32, 0 },
231*7c478bd9Sstevel@tonic-gate 		{ "sctpPassiveEstab",		KSTAT_DATA_INT32, 0 },
232*7c478bd9Sstevel@tonic-gate 		{ "sctpAborted",		KSTAT_DATA_INT32, 0 },
233*7c478bd9Sstevel@tonic-gate 		{ "sctpShutdowns",		KSTAT_DATA_INT32, 0 },
234*7c478bd9Sstevel@tonic-gate 		{ "sctpOutOfBlue",		KSTAT_DATA_INT32, 0 },
235*7c478bd9Sstevel@tonic-gate 		{ "sctpChecksumError",		KSTAT_DATA_INT32, 0 },
236*7c478bd9Sstevel@tonic-gate 		{ "sctpOutCtrlChunks",		KSTAT_DATA_INT64, 0 },
237*7c478bd9Sstevel@tonic-gate 		{ "sctpOutOrderChunks",		KSTAT_DATA_INT64, 0 },
238*7c478bd9Sstevel@tonic-gate 		{ "sctpOutUnorderChunks",	KSTAT_DATA_INT64, 0 },
239*7c478bd9Sstevel@tonic-gate 		{ "sctpRetransChunks",		KSTAT_DATA_INT64, 0 },
240*7c478bd9Sstevel@tonic-gate 		{ "sctpOutAck",			KSTAT_DATA_INT32, 0 },
241*7c478bd9Sstevel@tonic-gate 		{ "sctpOutAckDelayed",		KSTAT_DATA_INT32, 0 },
242*7c478bd9Sstevel@tonic-gate 		{ "sctpOutWinUpdate",		KSTAT_DATA_INT32, 0 },
243*7c478bd9Sstevel@tonic-gate 		{ "sctpOutFastRetrans",		KSTAT_DATA_INT32, 0 },
244*7c478bd9Sstevel@tonic-gate 		{ "sctpOutWinProbe",		KSTAT_DATA_INT32, 0 },
245*7c478bd9Sstevel@tonic-gate 		{ "sctpInCtrlChunks",		KSTAT_DATA_INT64, 0 },
246*7c478bd9Sstevel@tonic-gate 		{ "sctpInOrderChunks",		KSTAT_DATA_INT64, 0 },
247*7c478bd9Sstevel@tonic-gate 		{ "sctpInUnorderChunks",	KSTAT_DATA_INT64, 0 },
248*7c478bd9Sstevel@tonic-gate 		{ "sctpInAck",			KSTAT_DATA_INT32, 0 },
249*7c478bd9Sstevel@tonic-gate 		{ "sctpInDupAck",		KSTAT_DATA_INT32, 0 },
250*7c478bd9Sstevel@tonic-gate 		{ "sctpInAckUnsent",		KSTAT_DATA_INT32, 0 },
251*7c478bd9Sstevel@tonic-gate 		{ "sctpFragUsrMsgs",		KSTAT_DATA_INT64, 0 },
252*7c478bd9Sstevel@tonic-gate 		{ "sctpReasmUsrMsgs",		KSTAT_DATA_INT64, 0 },
253*7c478bd9Sstevel@tonic-gate 		{ "sctpOutSCTPPkts",		KSTAT_DATA_INT64, 0 },
254*7c478bd9Sstevel@tonic-gate 		{ "sctpInSCTPPkts",		KSTAT_DATA_INT64, 0 },
255*7c478bd9Sstevel@tonic-gate 		{ "sctpInInvalidCookie",	KSTAT_DATA_INT32, 0 },
256*7c478bd9Sstevel@tonic-gate 		{ "sctpTimRetrans",		KSTAT_DATA_INT32, 0 },
257*7c478bd9Sstevel@tonic-gate 		{ "sctpTimRetransDrop",		KSTAT_DATA_INT32, 0 },
258*7c478bd9Sstevel@tonic-gate 		{ "sctpTimHearBeatProbe",	KSTAT_DATA_INT32, 0 },
259*7c478bd9Sstevel@tonic-gate 		{ "sctpTimHearBeatDrop",	KSTAT_DATA_INT32, 0 },
260*7c478bd9Sstevel@tonic-gate 		{ "sctpListenDrop",		KSTAT_DATA_INT32, 0 },
261*7c478bd9Sstevel@tonic-gate 		{ "sctpInClosed",		KSTAT_DATA_INT32, 0 }
262*7c478bd9Sstevel@tonic-gate 	};
263*7c478bd9Sstevel@tonic-gate 
264*7c478bd9Sstevel@tonic-gate 	sctp_mibkp = kstat_create("sctp", 0, "sctp", "mib2", KSTAT_TYPE_NAMED,
265*7c478bd9Sstevel@tonic-gate 	    NUM_OF_FIELDS(sctp_named_kstat_t), 0);
266*7c478bd9Sstevel@tonic-gate 
267*7c478bd9Sstevel@tonic-gate 	if (sctp_mibkp == NULL)
268*7c478bd9Sstevel@tonic-gate 		return;
269*7c478bd9Sstevel@tonic-gate 
270*7c478bd9Sstevel@tonic-gate 	/* These won't change. */
271*7c478bd9Sstevel@tonic-gate 	template.sctpRtoAlgorithm.value.i32 = MIB2_SCTP_RTOALGO_VANJ;
272*7c478bd9Sstevel@tonic-gate 	template.sctpMaxAssocs.value.i32 = -1;
273*7c478bd9Sstevel@tonic-gate 
274*7c478bd9Sstevel@tonic-gate 	bcopy(&template, sctp_mibkp->ks_data, sizeof (template));
275*7c478bd9Sstevel@tonic-gate 
276*7c478bd9Sstevel@tonic-gate 	sctp_mibkp->ks_update = sctp_kstat_update;
277*7c478bd9Sstevel@tonic-gate 
278*7c478bd9Sstevel@tonic-gate 	kstat_install(sctp_mibkp);
279*7c478bd9Sstevel@tonic-gate }
280*7c478bd9Sstevel@tonic-gate 
281*7c478bd9Sstevel@tonic-gate void
282*7c478bd9Sstevel@tonic-gate sctp_kstat_fini(void)
283*7c478bd9Sstevel@tonic-gate {
284*7c478bd9Sstevel@tonic-gate 	if (sctp_mibkp != NULL) {
285*7c478bd9Sstevel@tonic-gate 		kstat_delete(sctp_mibkp);
286*7c478bd9Sstevel@tonic-gate 		sctp_mibkp = NULL;
287*7c478bd9Sstevel@tonic-gate 	}
288*7c478bd9Sstevel@tonic-gate }
289*7c478bd9Sstevel@tonic-gate 
290*7c478bd9Sstevel@tonic-gate /*
291*7c478bd9Sstevel@tonic-gate  * Return SNMP global stats in buffer in mpdata.
292*7c478bd9Sstevel@tonic-gate  * Return associatiation table in mp_conn_data,
293*7c478bd9Sstevel@tonic-gate  * local address table in mp_local_data, and
294*7c478bd9Sstevel@tonic-gate  * remote address table in mp_rem_data.
295*7c478bd9Sstevel@tonic-gate  */
296*7c478bd9Sstevel@tonic-gate mblk_t *
297*7c478bd9Sstevel@tonic-gate sctp_snmp_get_mib2(queue_t *q, mblk_t *mpctl)
298*7c478bd9Sstevel@tonic-gate {
299*7c478bd9Sstevel@tonic-gate 	mblk_t			*mpdata, *mp_ret;
300*7c478bd9Sstevel@tonic-gate 	mblk_t			*mp_conn_ctl = NULL;
301*7c478bd9Sstevel@tonic-gate 	mblk_t			*mp_conn_data;
302*7c478bd9Sstevel@tonic-gate 	mblk_t			*mp_conn_tail = NULL;
303*7c478bd9Sstevel@tonic-gate 	mblk_t			*mp_local_ctl = NULL;
304*7c478bd9Sstevel@tonic-gate 	mblk_t			*mp_local_data;
305*7c478bd9Sstevel@tonic-gate 	mblk_t			*mp_local_tail = NULL;
306*7c478bd9Sstevel@tonic-gate 	mblk_t			*mp_rem_ctl = NULL;
307*7c478bd9Sstevel@tonic-gate 	mblk_t			*mp_rem_data;
308*7c478bd9Sstevel@tonic-gate 	mblk_t			*mp_rem_tail = NULL;
309*7c478bd9Sstevel@tonic-gate 	struct opthdr		*optp;
310*7c478bd9Sstevel@tonic-gate 	sctp_t			*sctp, *sctp_prev = NULL;
311*7c478bd9Sstevel@tonic-gate 	sctp_faddr_t		*fp;
312*7c478bd9Sstevel@tonic-gate 	mib2_sctpConnEntry_t	sce;
313*7c478bd9Sstevel@tonic-gate 	mib2_sctpConnLocalEntry_t	scle;
314*7c478bd9Sstevel@tonic-gate 	mib2_sctpConnRemoteEntry_t	scre;
315*7c478bd9Sstevel@tonic-gate 	int			i;
316*7c478bd9Sstevel@tonic-gate 	int			l;
317*7c478bd9Sstevel@tonic-gate 	int			scanned = 0;
318*7c478bd9Sstevel@tonic-gate 	zoneid_t		zoneid = Q_TO_CONN(q)->conn_zoneid;
319*7c478bd9Sstevel@tonic-gate 
320*7c478bd9Sstevel@tonic-gate 	/*
321*7c478bd9Sstevel@tonic-gate 	 * Make copies of the original message.
322*7c478bd9Sstevel@tonic-gate 	 * mpctl will hold SCTP counters,
323*7c478bd9Sstevel@tonic-gate 	 * mp_conn_ctl will hold list of connections.
324*7c478bd9Sstevel@tonic-gate 	 */
325*7c478bd9Sstevel@tonic-gate 	mp_ret = copymsg(mpctl);
326*7c478bd9Sstevel@tonic-gate 	mp_conn_ctl = copymsg(mpctl);
327*7c478bd9Sstevel@tonic-gate 	mp_local_ctl = copymsg(mpctl);
328*7c478bd9Sstevel@tonic-gate 	mp_rem_ctl = copymsg(mpctl);
329*7c478bd9Sstevel@tonic-gate 
330*7c478bd9Sstevel@tonic-gate 	mpdata = mpctl->b_cont;
331*7c478bd9Sstevel@tonic-gate 
332*7c478bd9Sstevel@tonic-gate 	if (!mp_conn_ctl || !mp_local_ctl || !mp_rem_ctl || !mpdata) {
333*7c478bd9Sstevel@tonic-gate 		freemsg(mp_rem_ctl);
334*7c478bd9Sstevel@tonic-gate 		freemsg(mp_local_ctl);
335*7c478bd9Sstevel@tonic-gate 		freemsg(mp_conn_ctl);
336*7c478bd9Sstevel@tonic-gate 		freemsg(mp_ret);
337*7c478bd9Sstevel@tonic-gate 		freemsg(mpctl);
338*7c478bd9Sstevel@tonic-gate 		return (NULL);
339*7c478bd9Sstevel@tonic-gate 	}
340*7c478bd9Sstevel@tonic-gate 	mp_conn_data = mp_conn_ctl->b_cont;
341*7c478bd9Sstevel@tonic-gate 	mp_local_data = mp_local_ctl->b_cont;
342*7c478bd9Sstevel@tonic-gate 	mp_rem_data = mp_rem_ctl->b_cont;
343*7c478bd9Sstevel@tonic-gate 
344*7c478bd9Sstevel@tonic-gate 	/* hostname address parameters are not supported in Solaris */
345*7c478bd9Sstevel@tonic-gate 	sce.sctpAssocRemHostName.o_length = 0;
346*7c478bd9Sstevel@tonic-gate 	sce.sctpAssocRemHostName.o_bytes[0] = 0;
347*7c478bd9Sstevel@tonic-gate 
348*7c478bd9Sstevel@tonic-gate 	/* build table of connections -- need count in fixed part */
349*7c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpRtoAlgorithm, MIB2_SCTP_RTOALGO_VANJ);
350*7c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpRtoMin, sctp_rto_ming);
351*7c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpRtoMax, sctp_rto_maxg);
352*7c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpRtoInitial, sctp_rto_initialg);
353*7c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpMaxAssocs, -1);
354*7c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpValCookieLife, sctp_cookie_life);
355*7c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpMaxInitRetr, sctp_max_init_retr);
356*7c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpCurrEstab, 0);
357*7c478bd9Sstevel@tonic-gate 
358*7c478bd9Sstevel@tonic-gate 	sctp = gsctp;
359*7c478bd9Sstevel@tonic-gate 	mutex_enter(&sctp_g_lock);
360*7c478bd9Sstevel@tonic-gate 	while (sctp != NULL) {
361*7c478bd9Sstevel@tonic-gate 		mutex_enter(&sctp->sctp_reflock);
362*7c478bd9Sstevel@tonic-gate 		if (sctp->sctp_condemned) {
363*7c478bd9Sstevel@tonic-gate 			mutex_exit(&sctp->sctp_reflock);
364*7c478bd9Sstevel@tonic-gate 			sctp = list_next(&sctp_g_list, sctp);
365*7c478bd9Sstevel@tonic-gate 			continue;
366*7c478bd9Sstevel@tonic-gate 		}
367*7c478bd9Sstevel@tonic-gate 		sctp->sctp_refcnt++;
368*7c478bd9Sstevel@tonic-gate 		mutex_exit(&sctp->sctp_reflock);
369*7c478bd9Sstevel@tonic-gate 		mutex_exit(&sctp_g_lock);
370*7c478bd9Sstevel@tonic-gate 		if (sctp_prev != NULL)
371*7c478bd9Sstevel@tonic-gate 			SCTP_REFRELE(sctp_prev);
372*7c478bd9Sstevel@tonic-gate 		if (sctp->sctp_connp->conn_zoneid != zoneid)
373*7c478bd9Sstevel@tonic-gate 			goto next_sctp;
374*7c478bd9Sstevel@tonic-gate 		if (sctp->sctp_state == SCTPS_ESTABLISHED ||
375*7c478bd9Sstevel@tonic-gate 		    sctp->sctp_state == SCTPS_SHUTDOWN_PENDING ||
376*7c478bd9Sstevel@tonic-gate 		    sctp->sctp_state == SCTPS_SHUTDOWN_RECEIVED) {
377*7c478bd9Sstevel@tonic-gate 			BUMP_MIB(&sctp_mib, sctpCurrEstab);
378*7c478bd9Sstevel@tonic-gate 		}
379*7c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpOutSCTPPkts, sctp->sctp_opkts);
380*7c478bd9Sstevel@tonic-gate 		sctp->sctp_opkts = 0;
381*7c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpOutCtrlChunks, sctp->sctp_obchunks);
382*7c478bd9Sstevel@tonic-gate 		sctp->sctp_obchunks = 0;
383*7c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpOutOrderChunks, sctp->sctp_odchunks);
384*7c478bd9Sstevel@tonic-gate 		sctp->sctp_odchunks = 0;
385*7c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpOutUnorderChunks,
386*7c478bd9Sstevel@tonic-gate 		    sctp->sctp_oudchunks);
387*7c478bd9Sstevel@tonic-gate 		sctp->sctp_oudchunks = 0;
388*7c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpRetransChunks, sctp->sctp_rxtchunks);
389*7c478bd9Sstevel@tonic-gate 		sctp->sctp_rxtchunks = 0;
390*7c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpInSCTPPkts, sctp->sctp_ipkts);
391*7c478bd9Sstevel@tonic-gate 		sctp->sctp_ipkts = 0;
392*7c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpInCtrlChunks, sctp->sctp_ibchunks);
393*7c478bd9Sstevel@tonic-gate 		sctp->sctp_ibchunks = 0;
394*7c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpInOrderChunks, sctp->sctp_idchunks);
395*7c478bd9Sstevel@tonic-gate 		sctp->sctp_idchunks = 0;
396*7c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpInUnorderChunks,
397*7c478bd9Sstevel@tonic-gate 		    sctp->sctp_iudchunks);
398*7c478bd9Sstevel@tonic-gate 		sctp->sctp_iudchunks = 0;
399*7c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpFragUsrMsgs, sctp->sctp_fragdmsgs);
400*7c478bd9Sstevel@tonic-gate 		sctp->sctp_fragdmsgs = 0;
401*7c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpReasmUsrMsgs, sctp->sctp_reassmsgs);
402*7c478bd9Sstevel@tonic-gate 		sctp->sctp_reassmsgs = 0;
403*7c478bd9Sstevel@tonic-gate 
404*7c478bd9Sstevel@tonic-gate 		sce.sctpAssocId = ntohl(sctp->sctp_lvtag);
405*7c478bd9Sstevel@tonic-gate 		sce.sctpAssocLocalPort = ntohs(sctp->sctp_lport);
406*7c478bd9Sstevel@tonic-gate 		sce.sctpAssocRemPort = ntohs(sctp->sctp_fport);
407*7c478bd9Sstevel@tonic-gate 
408*7c478bd9Sstevel@tonic-gate 		RUN_SCTP(sctp);
409*7c478bd9Sstevel@tonic-gate 		if (sctp->sctp_primary != NULL) {
410*7c478bd9Sstevel@tonic-gate 			fp = sctp->sctp_primary;
411*7c478bd9Sstevel@tonic-gate 
412*7c478bd9Sstevel@tonic-gate 			if (IN6_IS_ADDR_V4MAPPED(&fp->faddr)) {
413*7c478bd9Sstevel@tonic-gate 				sce.sctpAssocRemPrimAddrType =
414*7c478bd9Sstevel@tonic-gate 				    MIB2_SCTP_ADDR_V4;
415*7c478bd9Sstevel@tonic-gate 			} else {
416*7c478bd9Sstevel@tonic-gate 				sce.sctpAssocRemPrimAddrType =
417*7c478bd9Sstevel@tonic-gate 				    MIB2_SCTP_ADDR_V6;
418*7c478bd9Sstevel@tonic-gate 			}
419*7c478bd9Sstevel@tonic-gate 			sce.sctpAssocRemPrimAddr = fp->faddr;
420*7c478bd9Sstevel@tonic-gate 			sce.sctpAssocLocPrimAddr = fp->saddr;
421*7c478bd9Sstevel@tonic-gate 			sce.sctpAssocHeartBeatInterval = TICK_TO_MSEC(
422*7c478bd9Sstevel@tonic-gate 			    fp->hb_interval);
423*7c478bd9Sstevel@tonic-gate 		} else {
424*7c478bd9Sstevel@tonic-gate 			sce.sctpAssocRemPrimAddrType = MIB2_SCTP_ADDR_V4;
425*7c478bd9Sstevel@tonic-gate 			bzero(&sce.sctpAssocRemPrimAddr,
426*7c478bd9Sstevel@tonic-gate 			    sizeof (sce.sctpAssocRemPrimAddr));
427*7c478bd9Sstevel@tonic-gate 			bzero(&sce.sctpAssocLocPrimAddr,
428*7c478bd9Sstevel@tonic-gate 			    sizeof (sce.sctpAssocLocPrimAddr));
429*7c478bd9Sstevel@tonic-gate 			sce.sctpAssocHeartBeatInterval =
430*7c478bd9Sstevel@tonic-gate 			    sctp_heartbeat_interval;
431*7c478bd9Sstevel@tonic-gate 		}
432*7c478bd9Sstevel@tonic-gate 
433*7c478bd9Sstevel@tonic-gate 		/*
434*7c478bd9Sstevel@tonic-gate 		 * Table for local addresses
435*7c478bd9Sstevel@tonic-gate 		 */
436*7c478bd9Sstevel@tonic-gate 		scanned = 0;
437*7c478bd9Sstevel@tonic-gate 		for (i = 0; i < SCTP_IPIF_HASH; i++) {
438*7c478bd9Sstevel@tonic-gate 			sctp_saddr_ipif_t	*obj;
439*7c478bd9Sstevel@tonic-gate 
440*7c478bd9Sstevel@tonic-gate 			if (sctp->sctp_saddrs[i].ipif_count == 0)
441*7c478bd9Sstevel@tonic-gate 				continue;
442*7c478bd9Sstevel@tonic-gate 			obj = list_head(&sctp->sctp_saddrs[i].sctp_ipif_list);
443*7c478bd9Sstevel@tonic-gate 			for (l = 0; l < sctp->sctp_saddrs[i].ipif_count; l++) {
444*7c478bd9Sstevel@tonic-gate 				sctp_ipif_t	*sctp_ipif;
445*7c478bd9Sstevel@tonic-gate 				in6_addr_t	addr;
446*7c478bd9Sstevel@tonic-gate 
447*7c478bd9Sstevel@tonic-gate 				sctp_ipif = obj->saddr_ipifp;
448*7c478bd9Sstevel@tonic-gate 				addr = sctp_ipif->sctp_ipif_saddr;
449*7c478bd9Sstevel@tonic-gate 				scanned++;
450*7c478bd9Sstevel@tonic-gate 				scle.sctpAssocId = ntohl(sctp->sctp_lvtag);
451*7c478bd9Sstevel@tonic-gate 				if (IN6_IS_ADDR_V4MAPPED(&addr)) {
452*7c478bd9Sstevel@tonic-gate 					scle.sctpAssocLocalAddrType =
453*7c478bd9Sstevel@tonic-gate 					    MIB2_SCTP_ADDR_V4;
454*7c478bd9Sstevel@tonic-gate 				} else {
455*7c478bd9Sstevel@tonic-gate 					scle.sctpAssocLocalAddrType =
456*7c478bd9Sstevel@tonic-gate 					    MIB2_SCTP_ADDR_V6;
457*7c478bd9Sstevel@tonic-gate 				}
458*7c478bd9Sstevel@tonic-gate 				scle.sctpAssocLocalAddr = addr;
459*7c478bd9Sstevel@tonic-gate 				(void) snmp_append_data2(mp_local_data,
460*7c478bd9Sstevel@tonic-gate 				    &mp_local_tail, (char *)&scle,
461*7c478bd9Sstevel@tonic-gate 				    sizeof (scle));
462*7c478bd9Sstevel@tonic-gate 				if (scanned >= sctp->sctp_nsaddrs)
463*7c478bd9Sstevel@tonic-gate 					goto done;
464*7c478bd9Sstevel@tonic-gate 				obj = list_next(&sctp->
465*7c478bd9Sstevel@tonic-gate 				    sctp_saddrs[i].sctp_ipif_list, obj);
466*7c478bd9Sstevel@tonic-gate 			}
467*7c478bd9Sstevel@tonic-gate 		}
468*7c478bd9Sstevel@tonic-gate done:
469*7c478bd9Sstevel@tonic-gate 		/*
470*7c478bd9Sstevel@tonic-gate 		 * Table for remote addresses
471*7c478bd9Sstevel@tonic-gate 		 */
472*7c478bd9Sstevel@tonic-gate 		for (fp = sctp->sctp_faddrs; fp; fp = fp->next) {
473*7c478bd9Sstevel@tonic-gate 			scre.sctpAssocId = ntohl(sctp->sctp_lvtag);
474*7c478bd9Sstevel@tonic-gate 			if (IN6_IS_ADDR_V4MAPPED(&fp->faddr)) {
475*7c478bd9Sstevel@tonic-gate 				scre.sctpAssocRemAddrType = MIB2_SCTP_ADDR_V4;
476*7c478bd9Sstevel@tonic-gate 			} else {
477*7c478bd9Sstevel@tonic-gate 				scre.sctpAssocRemAddrType = MIB2_SCTP_ADDR_V6;
478*7c478bd9Sstevel@tonic-gate 			}
479*7c478bd9Sstevel@tonic-gate 			scre.sctpAssocRemAddr = fp->faddr;
480*7c478bd9Sstevel@tonic-gate 			if (fp->state == SCTP_FADDRS_ALIVE) {
481*7c478bd9Sstevel@tonic-gate 				scre.sctpAssocRemAddrActive =
482*7c478bd9Sstevel@tonic-gate 				    scre.sctpAssocRemAddrHBActive =
483*7c478bd9Sstevel@tonic-gate 				    MIB2_SCTP_ACTIVE;
484*7c478bd9Sstevel@tonic-gate 			} else {
485*7c478bd9Sstevel@tonic-gate 				scre.sctpAssocRemAddrActive =
486*7c478bd9Sstevel@tonic-gate 				    scre.sctpAssocRemAddrHBActive =
487*7c478bd9Sstevel@tonic-gate 				    MIB2_SCTP_INACTIVE;
488*7c478bd9Sstevel@tonic-gate 			}
489*7c478bd9Sstevel@tonic-gate 			scre.sctpAssocRemAddrRTO = TICK_TO_MSEC(fp->rto);
490*7c478bd9Sstevel@tonic-gate 			scre.sctpAssocRemAddrMaxPathRtx = fp->max_retr;
491*7c478bd9Sstevel@tonic-gate 			scre.sctpAssocRemAddrRtx = fp->T3expire;
492*7c478bd9Sstevel@tonic-gate 			(void) snmp_append_data2(mp_rem_data, &mp_rem_tail,
493*7c478bd9Sstevel@tonic-gate 			    (char *)&scre, sizeof (scre));
494*7c478bd9Sstevel@tonic-gate 		}
495*7c478bd9Sstevel@tonic-gate 		WAKE_SCTP(sctp);
496*7c478bd9Sstevel@tonic-gate 		sce.sctpAssocState = sctp_snmp_state(sctp);
497*7c478bd9Sstevel@tonic-gate 		sce.sctpAssocInStreams = sctp->sctp_num_istr;
498*7c478bd9Sstevel@tonic-gate 		sce.sctpAssocOutStreams = sctp->sctp_num_ostr;
499*7c478bd9Sstevel@tonic-gate 		sce.sctpAssocMaxRetr = sctp->sctp_pa_max_rxt;
500*7c478bd9Sstevel@tonic-gate 		/* A 0 here indicates that no primary process is known */
501*7c478bd9Sstevel@tonic-gate 		sce.sctpAssocPrimProcess = 0;
502*7c478bd9Sstevel@tonic-gate 		sce.sctpAssocT1expired = sctp->sctp_T1expire;
503*7c478bd9Sstevel@tonic-gate 		sce.sctpAssocT2expired = sctp->sctp_T2expire;
504*7c478bd9Sstevel@tonic-gate 		sce.sctpAssocRtxChunks = sctp->sctp_T3expire;
505*7c478bd9Sstevel@tonic-gate 		sce.sctpAssocStartTime = sctp->sctp_assoc_start_time;
506*7c478bd9Sstevel@tonic-gate 		sce.sctpConnEntryInfo.ce_sendq = sctp->sctp_unacked +
507*7c478bd9Sstevel@tonic-gate 		    sctp->sctp_unsent;
508*7c478bd9Sstevel@tonic-gate 		sce.sctpConnEntryInfo.ce_recvq = sctp->sctp_rxqueued;
509*7c478bd9Sstevel@tonic-gate 		sce.sctpConnEntryInfo.ce_swnd = sctp->sctp_frwnd;
510*7c478bd9Sstevel@tonic-gate 		sce.sctpConnEntryInfo.ce_rwnd = sctp->sctp_rwnd;
511*7c478bd9Sstevel@tonic-gate 		sce.sctpConnEntryInfo.ce_mss = sctp->sctp_mss;
512*7c478bd9Sstevel@tonic-gate 		(void) snmp_append_data2(mp_conn_data, &mp_conn_tail,
513*7c478bd9Sstevel@tonic-gate 		    (char *)&sce, sizeof (sce));
514*7c478bd9Sstevel@tonic-gate next_sctp:
515*7c478bd9Sstevel@tonic-gate 		sctp_prev = sctp;
516*7c478bd9Sstevel@tonic-gate 		mutex_enter(&sctp_g_lock);
517*7c478bd9Sstevel@tonic-gate 		sctp = list_next(&sctp_g_list, sctp);
518*7c478bd9Sstevel@tonic-gate 	}
519*7c478bd9Sstevel@tonic-gate 	mutex_exit(&sctp_g_lock);
520*7c478bd9Sstevel@tonic-gate 	if (sctp_prev != NULL)
521*7c478bd9Sstevel@tonic-gate 		SCTP_REFRELE(sctp_prev);
522*7c478bd9Sstevel@tonic-gate 
523*7c478bd9Sstevel@tonic-gate 	/* fixed length structure for IPv4 and IPv6 counters */
524*7c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpEntrySize, sizeof (sce));
525*7c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpLocalEntrySize, sizeof (scle));
526*7c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpRemoteEntrySize, sizeof (scre));
527*7c478bd9Sstevel@tonic-gate 	optp = (struct opthdr *)&mpctl->b_rptr[sizeof (struct T_optmgmt_ack)];
528*7c478bd9Sstevel@tonic-gate 	optp->level = MIB2_SCTP;
529*7c478bd9Sstevel@tonic-gate 	optp->name = 0;
530*7c478bd9Sstevel@tonic-gate 	(void) snmp_append_data(mpdata, (char *)&sctp_mib, sizeof (sctp_mib));
531*7c478bd9Sstevel@tonic-gate 	optp->len = msgdsize(mpdata);
532*7c478bd9Sstevel@tonic-gate 	qreply(q, mpctl);
533*7c478bd9Sstevel@tonic-gate 
534*7c478bd9Sstevel@tonic-gate 	/* table of connections... */
535*7c478bd9Sstevel@tonic-gate 	optp = (struct opthdr *)&mp_conn_ctl->b_rptr[
536*7c478bd9Sstevel@tonic-gate 	    sizeof (struct T_optmgmt_ack)];
537*7c478bd9Sstevel@tonic-gate 	optp->level = MIB2_SCTP;
538*7c478bd9Sstevel@tonic-gate 	optp->name = MIB2_SCTP_CONN;
539*7c478bd9Sstevel@tonic-gate 	optp->len = msgdsize(mp_conn_data);
540*7c478bd9Sstevel@tonic-gate 	qreply(q, mp_conn_ctl);
541*7c478bd9Sstevel@tonic-gate 
542*7c478bd9Sstevel@tonic-gate 	/* assoc local address table */
543*7c478bd9Sstevel@tonic-gate 	optp = (struct opthdr *)&mp_local_ctl->b_rptr[
544*7c478bd9Sstevel@tonic-gate 	    sizeof (struct T_optmgmt_ack)];
545*7c478bd9Sstevel@tonic-gate 	optp->level = MIB2_SCTP;
546*7c478bd9Sstevel@tonic-gate 	optp->name = MIB2_SCTP_CONN_LOCAL;
547*7c478bd9Sstevel@tonic-gate 	optp->len = msgdsize(mp_local_data);
548*7c478bd9Sstevel@tonic-gate 	qreply(q, mp_local_ctl);
549*7c478bd9Sstevel@tonic-gate 
550*7c478bd9Sstevel@tonic-gate 	/* assoc remote address table */
551*7c478bd9Sstevel@tonic-gate 	optp = (struct opthdr *)&mp_rem_ctl->b_rptr[
552*7c478bd9Sstevel@tonic-gate 	    sizeof (struct T_optmgmt_ack)];
553*7c478bd9Sstevel@tonic-gate 	optp->level = MIB2_SCTP;
554*7c478bd9Sstevel@tonic-gate 	optp->name = MIB2_SCTP_CONN_REMOTE;
555*7c478bd9Sstevel@tonic-gate 	optp->len = msgdsize(mp_rem_data);
556*7c478bd9Sstevel@tonic-gate 	qreply(q, mp_rem_ctl);
557*7c478bd9Sstevel@tonic-gate 
558*7c478bd9Sstevel@tonic-gate 	return (mp_ret);
559*7c478bd9Sstevel@tonic-gate }
560*7c478bd9Sstevel@tonic-gate 
561*7c478bd9Sstevel@tonic-gate /* Translate SCTP state to MIB2 SCTP state. */
562*7c478bd9Sstevel@tonic-gate static int
563*7c478bd9Sstevel@tonic-gate sctp_snmp_state(sctp_t *sctp)
564*7c478bd9Sstevel@tonic-gate {
565*7c478bd9Sstevel@tonic-gate 	if (sctp == NULL)
566*7c478bd9Sstevel@tonic-gate 		return (0);
567*7c478bd9Sstevel@tonic-gate 
568*7c478bd9Sstevel@tonic-gate 	switch (sctp->sctp_state) {
569*7c478bd9Sstevel@tonic-gate 	case SCTPS_IDLE:
570*7c478bd9Sstevel@tonic-gate 	case SCTPS_BOUND:
571*7c478bd9Sstevel@tonic-gate 		return (MIB2_SCTP_closed);
572*7c478bd9Sstevel@tonic-gate 	case SCTPS_LISTEN:
573*7c478bd9Sstevel@tonic-gate 		return (MIB2_SCTP_listen);
574*7c478bd9Sstevel@tonic-gate 	case SCTPS_COOKIE_WAIT:
575*7c478bd9Sstevel@tonic-gate 		return (MIB2_SCTP_cookieWait);
576*7c478bd9Sstevel@tonic-gate 	case SCTPS_COOKIE_ECHOED:
577*7c478bd9Sstevel@tonic-gate 		return (MIB2_SCTP_cookieEchoed);
578*7c478bd9Sstevel@tonic-gate 	case SCTPS_ESTABLISHED:
579*7c478bd9Sstevel@tonic-gate 		return (MIB2_SCTP_established);
580*7c478bd9Sstevel@tonic-gate 	case SCTPS_SHUTDOWN_PENDING:
581*7c478bd9Sstevel@tonic-gate 		return (MIB2_SCTP_shutdownPending);
582*7c478bd9Sstevel@tonic-gate 	case SCTPS_SHUTDOWN_SENT:
583*7c478bd9Sstevel@tonic-gate 		return (MIB2_SCTP_shutdownSent);
584*7c478bd9Sstevel@tonic-gate 	case SCTPS_SHUTDOWN_RECEIVED:
585*7c478bd9Sstevel@tonic-gate 		return (MIB2_SCTP_shutdownReceived);
586*7c478bd9Sstevel@tonic-gate 	case SCTPS_SHUTDOWN_ACK_SENT:
587*7c478bd9Sstevel@tonic-gate 		return (MIB2_SCTP_shutdownAckSent);
588*7c478bd9Sstevel@tonic-gate 	default:
589*7c478bd9Sstevel@tonic-gate 		return (0);
590*7c478bd9Sstevel@tonic-gate 	}
591*7c478bd9Sstevel@tonic-gate }
592