17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*45916cd2Sjpk  * Common Development and Distribution License (the "License").
6*45916cd2Sjpk  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*45916cd2Sjpk  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <sys/types.h>
297c478bd9Sstevel@tonic-gate #include <sys/stream.h>
307c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
317c478bd9Sstevel@tonic-gate #define	_SUN_TPI_VERSION 2
327c478bd9Sstevel@tonic-gate #include <sys/tihdr.h>
337c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
347c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
35*45916cd2Sjpk #include <sys/tsol/tndb.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #include <netinet/in.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include <inet/common.h>
407c478bd9Sstevel@tonic-gate #include <inet/ip.h>
417c478bd9Sstevel@tonic-gate #include <inet/mib2.h>
427c478bd9Sstevel@tonic-gate #include <inet/snmpcom.h>
437c478bd9Sstevel@tonic-gate #include <inet/kstatcom.h>
447c478bd9Sstevel@tonic-gate #include <inet/ipclassifier.h>
457c478bd9Sstevel@tonic-gate #include "sctp_impl.h"
467c478bd9Sstevel@tonic-gate #include "sctp_addr.h"
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate mib2_sctp_t	sctp_mib;
497c478bd9Sstevel@tonic-gate kstat_t		*sctp_mibkp;	/* kstat exporting sctp_mib data */
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate static int sctp_snmp_state(sctp_t *sctp);
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate static int
547c478bd9Sstevel@tonic-gate sctp_kstat_update(kstat_t *kp, int rw)
557c478bd9Sstevel@tonic-gate {
567c478bd9Sstevel@tonic-gate 	sctp_named_kstat_t	*sctpkp;
577c478bd9Sstevel@tonic-gate 	sctp_t			*sctp, *sctp_prev;
587c478bd9Sstevel@tonic-gate 	zoneid_t		zoneid;
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate 	if (kp == NULL|| kp->ks_data == NULL)
617c478bd9Sstevel@tonic-gate 		return (EIO);
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate 	if (rw == KSTAT_WRITE)
647c478bd9Sstevel@tonic-gate 		return (EACCES);
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 	zoneid = getzoneid();
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate 	/*
697c478bd9Sstevel@tonic-gate 	 * Get the number of current associations and gather their
707c478bd9Sstevel@tonic-gate 	 * individual set of statistics.
717c478bd9Sstevel@tonic-gate 	 */
727c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpCurrEstab, 0);
737c478bd9Sstevel@tonic-gate 	sctp = gsctp;
747c478bd9Sstevel@tonic-gate 	sctp_prev = NULL;
757c478bd9Sstevel@tonic-gate 	mutex_enter(&sctp_g_lock);
767c478bd9Sstevel@tonic-gate 	while (sctp != NULL) {
777c478bd9Sstevel@tonic-gate 		mutex_enter(&sctp->sctp_reflock);
787c478bd9Sstevel@tonic-gate 		if (sctp->sctp_condemned) {
797c478bd9Sstevel@tonic-gate 			mutex_exit(&sctp->sctp_reflock);
807c478bd9Sstevel@tonic-gate 			sctp = list_next(&sctp_g_list, sctp);
817c478bd9Sstevel@tonic-gate 			continue;
827c478bd9Sstevel@tonic-gate 		}
837c478bd9Sstevel@tonic-gate 		sctp->sctp_refcnt++;
847c478bd9Sstevel@tonic-gate 		mutex_exit(&sctp->sctp_reflock);
857c478bd9Sstevel@tonic-gate 		mutex_exit(&sctp_g_lock);
867c478bd9Sstevel@tonic-gate 		if (sctp_prev != NULL)
877c478bd9Sstevel@tonic-gate 			SCTP_REFRELE(sctp_prev);
887c478bd9Sstevel@tonic-gate 		if (sctp->sctp_connp->conn_zoneid != zoneid)
897c478bd9Sstevel@tonic-gate 			goto next_sctp;
907c478bd9Sstevel@tonic-gate 		if (sctp->sctp_state == SCTPS_ESTABLISHED ||
917c478bd9Sstevel@tonic-gate 		    sctp->sctp_state == SCTPS_SHUTDOWN_PENDING ||
927c478bd9Sstevel@tonic-gate 		    sctp->sctp_state == SCTPS_SHUTDOWN_RECEIVED) {
937c478bd9Sstevel@tonic-gate 			BUMP_MIB(&sctp_mib, sctpCurrEstab);
947c478bd9Sstevel@tonic-gate 		}
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 		if (sctp->sctp_opkts) {
977c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpOutSCTPPkts,
987c478bd9Sstevel@tonic-gate 			    sctp->sctp_opkts);
997c478bd9Sstevel@tonic-gate 			sctp->sctp_opkts = 0;
1007c478bd9Sstevel@tonic-gate 		}
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 		if (sctp->sctp_obchunks) {
1037c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpOutCtrlChunks,
1047c478bd9Sstevel@tonic-gate 			    sctp->sctp_obchunks);
1057c478bd9Sstevel@tonic-gate 			sctp->sctp_obchunks = 0;
1067c478bd9Sstevel@tonic-gate 		}
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 		if (sctp->sctp_odchunks) {
1097c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpOutOrderChunks,
1107c478bd9Sstevel@tonic-gate 			    sctp->sctp_odchunks);
1117c478bd9Sstevel@tonic-gate 			sctp->sctp_odchunks = 0;
1127c478bd9Sstevel@tonic-gate 		}
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate 		if (sctp->sctp_oudchunks) {
1157c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpOutUnorderChunks,
1167c478bd9Sstevel@tonic-gate 			    sctp->sctp_oudchunks);
1177c478bd9Sstevel@tonic-gate 			sctp->sctp_oudchunks = 0;
1187c478bd9Sstevel@tonic-gate 		}
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 		if (sctp->sctp_rxtchunks) {
1217c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpRetransChunks,
1227c478bd9Sstevel@tonic-gate 			    sctp->sctp_rxtchunks);
1237c478bd9Sstevel@tonic-gate 			sctp->sctp_rxtchunks = 0;
1247c478bd9Sstevel@tonic-gate 		}
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate 		if (sctp->sctp_ipkts) {
1277c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpInSCTPPkts, sctp->sctp_ipkts);
1287c478bd9Sstevel@tonic-gate 			sctp->sctp_ipkts = 0;
1297c478bd9Sstevel@tonic-gate 		}
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate 		if (sctp->sctp_ibchunks) {
1327c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpInCtrlChunks,
1337c478bd9Sstevel@tonic-gate 			    sctp->sctp_ibchunks);
1347c478bd9Sstevel@tonic-gate 			sctp->sctp_ibchunks = 0;
1357c478bd9Sstevel@tonic-gate 		}
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate 		if (sctp->sctp_idchunks) {
1387c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpInOrderChunks,
1397c478bd9Sstevel@tonic-gate 			    sctp->sctp_idchunks);
1407c478bd9Sstevel@tonic-gate 			sctp->sctp_idchunks = 0;
1417c478bd9Sstevel@tonic-gate 		}
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 		if (sctp->sctp_iudchunks) {
1447c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpInUnorderChunks,
1457c478bd9Sstevel@tonic-gate 			    sctp->sctp_iudchunks);
1467c478bd9Sstevel@tonic-gate 			sctp->sctp_iudchunks = 0;
1477c478bd9Sstevel@tonic-gate 		}
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 		if (sctp->sctp_fragdmsgs) {
1507c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpFragUsrMsgs,
1517c478bd9Sstevel@tonic-gate 			    sctp->sctp_fragdmsgs);
1527c478bd9Sstevel@tonic-gate 			sctp->sctp_fragdmsgs = 0;
1537c478bd9Sstevel@tonic-gate 		}
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 		if (sctp->sctp_reassmsgs) {
1567c478bd9Sstevel@tonic-gate 			UPDATE_MIB(&sctp_mib, sctpReasmUsrMsgs,
1577c478bd9Sstevel@tonic-gate 			    sctp->sctp_reassmsgs);
1587c478bd9Sstevel@tonic-gate 			sctp->sctp_reassmsgs = 0;
1597c478bd9Sstevel@tonic-gate 		}
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate next_sctp:
1627c478bd9Sstevel@tonic-gate 		sctp_prev = sctp;
1637c478bd9Sstevel@tonic-gate 		mutex_enter(&sctp_g_lock);
1647c478bd9Sstevel@tonic-gate 		sctp = list_next(&sctp_g_list, sctp);
1657c478bd9Sstevel@tonic-gate 	}
1667c478bd9Sstevel@tonic-gate 	mutex_exit(&sctp_g_lock);
1677c478bd9Sstevel@tonic-gate 	if (sctp_prev != NULL)
1687c478bd9Sstevel@tonic-gate 		SCTP_REFRELE(sctp_prev);
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	/* Copy data from the SCTP MIB */
1717c478bd9Sstevel@tonic-gate 	sctpkp = (sctp_named_kstat_t *)kp->ks_data;
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate 	/* These are from global ndd params. */
1747c478bd9Sstevel@tonic-gate 	sctpkp->sctpRtoMin.value.ui32 = sctp_rto_ming;
1757c478bd9Sstevel@tonic-gate 	sctpkp->sctpRtoMax.value.ui32 = sctp_rto_maxg;
1767c478bd9Sstevel@tonic-gate 	sctpkp->sctpRtoInitial.value.ui32 = sctp_rto_initialg;
1777c478bd9Sstevel@tonic-gate 	sctpkp->sctpValCookieLife.value.ui32 = sctp_cookie_life;
1787c478bd9Sstevel@tonic-gate 	sctpkp->sctpMaxInitRetr.value.ui32 = sctp_max_init_retr;
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 	sctpkp->sctpCurrEstab.value.i32 = sctp_mib.sctpCurrEstab;
1817c478bd9Sstevel@tonic-gate 	sctpkp->sctpActiveEstab.value.i32 = sctp_mib.sctpActiveEstab;
1827c478bd9Sstevel@tonic-gate 	sctpkp->sctpPassiveEstab.value.i32 = sctp_mib.sctpPassiveEstab;
1837c478bd9Sstevel@tonic-gate 	sctpkp->sctpAborted.value.i32 = sctp_mib.sctpAborted;
1847c478bd9Sstevel@tonic-gate 	sctpkp->sctpShutdowns.value.i32 = sctp_mib.sctpShutdowns;
1857c478bd9Sstevel@tonic-gate 	sctpkp->sctpOutOfBlue.value.i32 = sctp_mib.sctpOutOfBlue;
1867c478bd9Sstevel@tonic-gate 	sctpkp->sctpChecksumError.value.i32 = sctp_mib.sctpChecksumError;
1877c478bd9Sstevel@tonic-gate 	sctpkp->sctpOutCtrlChunks.value.i64 = sctp_mib.sctpOutCtrlChunks;
1887c478bd9Sstevel@tonic-gate 	sctpkp->sctpOutOrderChunks.value.i64 = sctp_mib.sctpOutOrderChunks;
1897c478bd9Sstevel@tonic-gate 	sctpkp->sctpOutUnorderChunks.value.i64 = sctp_mib.sctpOutUnorderChunks;
1907c478bd9Sstevel@tonic-gate 	sctpkp->sctpRetransChunks.value.i64 = sctp_mib.sctpRetransChunks;
1917c478bd9Sstevel@tonic-gate 	sctpkp->sctpOutAck.value.i32 = sctp_mib.sctpOutAck;
1927c478bd9Sstevel@tonic-gate 	sctpkp->sctpOutAckDelayed.value.i32 = sctp_mib.sctpOutAckDelayed;
1937c478bd9Sstevel@tonic-gate 	sctpkp->sctpOutWinUpdate.value.i32 = sctp_mib.sctpOutWinUpdate;
1947c478bd9Sstevel@tonic-gate 	sctpkp->sctpOutFastRetrans.value.i32 = sctp_mib.sctpOutFastRetrans;
1957c478bd9Sstevel@tonic-gate 	sctpkp->sctpOutWinProbe.value.i32 = sctp_mib.sctpOutWinProbe;
1967c478bd9Sstevel@tonic-gate 	sctpkp->sctpInCtrlChunks.value.i64 = sctp_mib.sctpInCtrlChunks;
1977c478bd9Sstevel@tonic-gate 	sctpkp->sctpInOrderChunks.value.i64 = sctp_mib.sctpInOrderChunks;
1987c478bd9Sstevel@tonic-gate 	sctpkp->sctpInUnorderChunks.value.i64 = sctp_mib.sctpInUnorderChunks;
1997c478bd9Sstevel@tonic-gate 	sctpkp->sctpInAck.value.i32 = sctp_mib.sctpInAck;
2007c478bd9Sstevel@tonic-gate 	sctpkp->sctpInDupAck.value.i32 = sctp_mib.sctpInDupAck;
2017c478bd9Sstevel@tonic-gate 	sctpkp->sctpInAckUnsent.value.i32 = sctp_mib.sctpInAckUnsent;
2027c478bd9Sstevel@tonic-gate 	sctpkp->sctpFragUsrMsgs.value.i64 = sctp_mib.sctpFragUsrMsgs;
2037c478bd9Sstevel@tonic-gate 	sctpkp->sctpReasmUsrMsgs.value.i64 = sctp_mib.sctpReasmUsrMsgs;
2047c478bd9Sstevel@tonic-gate 	sctpkp->sctpOutSCTPPkts.value.i64 = sctp_mib.sctpOutSCTPPkts;
2057c478bd9Sstevel@tonic-gate 	sctpkp->sctpInSCTPPkts.value.i64 = sctp_mib.sctpInSCTPPkts;
2067c478bd9Sstevel@tonic-gate 	sctpkp->sctpInInvalidCookie.value.i32 = sctp_mib.sctpInInvalidCookie;
2077c478bd9Sstevel@tonic-gate 	sctpkp->sctpTimRetrans.value.i32 = sctp_mib.sctpTimRetrans;
2087c478bd9Sstevel@tonic-gate 	sctpkp->sctpTimRetransDrop.value.i32 = sctp_mib.sctpTimRetransDrop;
2097c478bd9Sstevel@tonic-gate 	sctpkp->sctpTimHeartBeatProbe.value.i32 =
2107c478bd9Sstevel@tonic-gate 	    sctp_mib.sctpTimHeartBeatProbe;
2117c478bd9Sstevel@tonic-gate 	sctpkp->sctpTimHeartBeatDrop.value.i32 = sctp_mib.sctpTimHeartBeatDrop;
2127c478bd9Sstevel@tonic-gate 	sctpkp->sctpListenDrop.value.i32 = sctp_mib.sctpListenDrop;
2137c478bd9Sstevel@tonic-gate 	sctpkp->sctpInClosed.value.i32 = sctp_mib.sctpInClosed;
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 	return (0);
2167c478bd9Sstevel@tonic-gate }
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate void
2197c478bd9Sstevel@tonic-gate sctp_kstat_init(void)
2207c478bd9Sstevel@tonic-gate {
2217c478bd9Sstevel@tonic-gate 	sctp_named_kstat_t template = {
2227c478bd9Sstevel@tonic-gate 		{ "sctpRtoAlgorithm",		KSTAT_DATA_INT32, 0 },
2237c478bd9Sstevel@tonic-gate 		{ "sctpRtoMin",			KSTAT_DATA_UINT32, 0 },
2247c478bd9Sstevel@tonic-gate 		{ "sctpRtoMax",			KSTAT_DATA_UINT32, 0 },
2257c478bd9Sstevel@tonic-gate 		{ "sctpRtoInitial",		KSTAT_DATA_UINT32, 0 },
2267c478bd9Sstevel@tonic-gate 		{ "sctpMaxAssocs",		KSTAT_DATA_INT32, 0 },
2277c478bd9Sstevel@tonic-gate 		{ "sctpValCookieLife",		KSTAT_DATA_UINT32, 0 },
2287c478bd9Sstevel@tonic-gate 		{ "sctpMaxInitRetr",		KSTAT_DATA_UINT32, 0 },
2297c478bd9Sstevel@tonic-gate 		{ "sctpCurrEstab",		KSTAT_DATA_INT32, 0 },
2307c478bd9Sstevel@tonic-gate 		{ "sctpActiveEstab",		KSTAT_DATA_INT32, 0 },
2317c478bd9Sstevel@tonic-gate 		{ "sctpPassiveEstab",		KSTAT_DATA_INT32, 0 },
2327c478bd9Sstevel@tonic-gate 		{ "sctpAborted",		KSTAT_DATA_INT32, 0 },
2337c478bd9Sstevel@tonic-gate 		{ "sctpShutdowns",		KSTAT_DATA_INT32, 0 },
2347c478bd9Sstevel@tonic-gate 		{ "sctpOutOfBlue",		KSTAT_DATA_INT32, 0 },
2357c478bd9Sstevel@tonic-gate 		{ "sctpChecksumError",		KSTAT_DATA_INT32, 0 },
2367c478bd9Sstevel@tonic-gate 		{ "sctpOutCtrlChunks",		KSTAT_DATA_INT64, 0 },
2377c478bd9Sstevel@tonic-gate 		{ "sctpOutOrderChunks",		KSTAT_DATA_INT64, 0 },
2387c478bd9Sstevel@tonic-gate 		{ "sctpOutUnorderChunks",	KSTAT_DATA_INT64, 0 },
2397c478bd9Sstevel@tonic-gate 		{ "sctpRetransChunks",		KSTAT_DATA_INT64, 0 },
2407c478bd9Sstevel@tonic-gate 		{ "sctpOutAck",			KSTAT_DATA_INT32, 0 },
2417c478bd9Sstevel@tonic-gate 		{ "sctpOutAckDelayed",		KSTAT_DATA_INT32, 0 },
2427c478bd9Sstevel@tonic-gate 		{ "sctpOutWinUpdate",		KSTAT_DATA_INT32, 0 },
2437c478bd9Sstevel@tonic-gate 		{ "sctpOutFastRetrans",		KSTAT_DATA_INT32, 0 },
2447c478bd9Sstevel@tonic-gate 		{ "sctpOutWinProbe",		KSTAT_DATA_INT32, 0 },
2457c478bd9Sstevel@tonic-gate 		{ "sctpInCtrlChunks",		KSTAT_DATA_INT64, 0 },
2467c478bd9Sstevel@tonic-gate 		{ "sctpInOrderChunks",		KSTAT_DATA_INT64, 0 },
2477c478bd9Sstevel@tonic-gate 		{ "sctpInUnorderChunks",	KSTAT_DATA_INT64, 0 },
2487c478bd9Sstevel@tonic-gate 		{ "sctpInAck",			KSTAT_DATA_INT32, 0 },
2497c478bd9Sstevel@tonic-gate 		{ "sctpInDupAck",		KSTAT_DATA_INT32, 0 },
2507c478bd9Sstevel@tonic-gate 		{ "sctpInAckUnsent",		KSTAT_DATA_INT32, 0 },
2517c478bd9Sstevel@tonic-gate 		{ "sctpFragUsrMsgs",		KSTAT_DATA_INT64, 0 },
2527c478bd9Sstevel@tonic-gate 		{ "sctpReasmUsrMsgs",		KSTAT_DATA_INT64, 0 },
2537c478bd9Sstevel@tonic-gate 		{ "sctpOutSCTPPkts",		KSTAT_DATA_INT64, 0 },
2547c478bd9Sstevel@tonic-gate 		{ "sctpInSCTPPkts",		KSTAT_DATA_INT64, 0 },
2557c478bd9Sstevel@tonic-gate 		{ "sctpInInvalidCookie",	KSTAT_DATA_INT32, 0 },
2567c478bd9Sstevel@tonic-gate 		{ "sctpTimRetrans",		KSTAT_DATA_INT32, 0 },
2577c478bd9Sstevel@tonic-gate 		{ "sctpTimRetransDrop",		KSTAT_DATA_INT32, 0 },
2587c478bd9Sstevel@tonic-gate 		{ "sctpTimHearBeatProbe",	KSTAT_DATA_INT32, 0 },
2597c478bd9Sstevel@tonic-gate 		{ "sctpTimHearBeatDrop",	KSTAT_DATA_INT32, 0 },
2607c478bd9Sstevel@tonic-gate 		{ "sctpListenDrop",		KSTAT_DATA_INT32, 0 },
2617c478bd9Sstevel@tonic-gate 		{ "sctpInClosed",		KSTAT_DATA_INT32, 0 }
2627c478bd9Sstevel@tonic-gate 	};
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 	sctp_mibkp = kstat_create("sctp", 0, "sctp", "mib2", KSTAT_TYPE_NAMED,
2657c478bd9Sstevel@tonic-gate 	    NUM_OF_FIELDS(sctp_named_kstat_t), 0);
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 	if (sctp_mibkp == NULL)
2687c478bd9Sstevel@tonic-gate 		return;
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate 	/* These won't change. */
2717c478bd9Sstevel@tonic-gate 	template.sctpRtoAlgorithm.value.i32 = MIB2_SCTP_RTOALGO_VANJ;
2727c478bd9Sstevel@tonic-gate 	template.sctpMaxAssocs.value.i32 = -1;
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	bcopy(&template, sctp_mibkp->ks_data, sizeof (template));
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate 	sctp_mibkp->ks_update = sctp_kstat_update;
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	kstat_install(sctp_mibkp);
2797c478bd9Sstevel@tonic-gate }
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate void
2827c478bd9Sstevel@tonic-gate sctp_kstat_fini(void)
2837c478bd9Sstevel@tonic-gate {
2847c478bd9Sstevel@tonic-gate 	if (sctp_mibkp != NULL) {
2857c478bd9Sstevel@tonic-gate 		kstat_delete(sctp_mibkp);
2867c478bd9Sstevel@tonic-gate 		sctp_mibkp = NULL;
2877c478bd9Sstevel@tonic-gate 	}
2887c478bd9Sstevel@tonic-gate }
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate /*
2917c478bd9Sstevel@tonic-gate  * Return SNMP global stats in buffer in mpdata.
2927c478bd9Sstevel@tonic-gate  * Return associatiation table in mp_conn_data,
2937c478bd9Sstevel@tonic-gate  * local address table in mp_local_data, and
2947c478bd9Sstevel@tonic-gate  * remote address table in mp_rem_data.
2957c478bd9Sstevel@tonic-gate  */
2967c478bd9Sstevel@tonic-gate mblk_t *
2977c478bd9Sstevel@tonic-gate sctp_snmp_get_mib2(queue_t *q, mblk_t *mpctl)
2987c478bd9Sstevel@tonic-gate {
2997c478bd9Sstevel@tonic-gate 	mblk_t			*mpdata, *mp_ret;
3007c478bd9Sstevel@tonic-gate 	mblk_t			*mp_conn_ctl = NULL;
3017c478bd9Sstevel@tonic-gate 	mblk_t			*mp_conn_data;
3027c478bd9Sstevel@tonic-gate 	mblk_t			*mp_conn_tail = NULL;
3037c478bd9Sstevel@tonic-gate 	mblk_t			*mp_local_ctl = NULL;
3047c478bd9Sstevel@tonic-gate 	mblk_t			*mp_local_data;
3057c478bd9Sstevel@tonic-gate 	mblk_t			*mp_local_tail = NULL;
3067c478bd9Sstevel@tonic-gate 	mblk_t			*mp_rem_ctl = NULL;
3077c478bd9Sstevel@tonic-gate 	mblk_t			*mp_rem_data;
3087c478bd9Sstevel@tonic-gate 	mblk_t			*mp_rem_tail = NULL;
309*45916cd2Sjpk 	mblk_t			*mp_attr_ctl = NULL;
310*45916cd2Sjpk 	mblk_t			*mp_attr_data;
311*45916cd2Sjpk 	mblk_t			*mp_attr_tail = NULL;
3127c478bd9Sstevel@tonic-gate 	struct opthdr		*optp;
3137c478bd9Sstevel@tonic-gate 	sctp_t			*sctp, *sctp_prev = NULL;
3147c478bd9Sstevel@tonic-gate 	sctp_faddr_t		*fp;
3157c478bd9Sstevel@tonic-gate 	mib2_sctpConnEntry_t	sce;
3167c478bd9Sstevel@tonic-gate 	mib2_sctpConnLocalEntry_t	scle;
3177c478bd9Sstevel@tonic-gate 	mib2_sctpConnRemoteEntry_t	scre;
318*45916cd2Sjpk 	mib2_transportMLPEntry_t	mlp;
3197c478bd9Sstevel@tonic-gate 	int			i;
3207c478bd9Sstevel@tonic-gate 	int			l;
3217c478bd9Sstevel@tonic-gate 	int			scanned = 0;
3227c478bd9Sstevel@tonic-gate 	zoneid_t		zoneid = Q_TO_CONN(q)->conn_zoneid;
323*45916cd2Sjpk 	conn_t			*connp;
324*45916cd2Sjpk 	boolean_t		needattr;
325*45916cd2Sjpk 	int			idx;
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate 	/*
3287c478bd9Sstevel@tonic-gate 	 * Make copies of the original message.
3297c478bd9Sstevel@tonic-gate 	 * mpctl will hold SCTP counters,
3307c478bd9Sstevel@tonic-gate 	 * mp_conn_ctl will hold list of connections.
3317c478bd9Sstevel@tonic-gate 	 */
3327c478bd9Sstevel@tonic-gate 	mp_ret = copymsg(mpctl);
3337c478bd9Sstevel@tonic-gate 	mp_conn_ctl = copymsg(mpctl);
3347c478bd9Sstevel@tonic-gate 	mp_local_ctl = copymsg(mpctl);
3357c478bd9Sstevel@tonic-gate 	mp_rem_ctl = copymsg(mpctl);
336*45916cd2Sjpk 	mp_attr_ctl = copymsg(mpctl);
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 	mpdata = mpctl->b_cont;
3397c478bd9Sstevel@tonic-gate 
340*45916cd2Sjpk 	if (mp_conn_ctl == NULL || mp_local_ctl == NULL ||
341*45916cd2Sjpk 	    mp_rem_ctl == NULL || mp_attr_ctl == NULL || mpdata == NULL) {
342*45916cd2Sjpk 		freemsg(mp_attr_ctl);
3437c478bd9Sstevel@tonic-gate 		freemsg(mp_rem_ctl);
3447c478bd9Sstevel@tonic-gate 		freemsg(mp_local_ctl);
3457c478bd9Sstevel@tonic-gate 		freemsg(mp_conn_ctl);
3467c478bd9Sstevel@tonic-gate 		freemsg(mp_ret);
3477c478bd9Sstevel@tonic-gate 		freemsg(mpctl);
3487c478bd9Sstevel@tonic-gate 		return (NULL);
3497c478bd9Sstevel@tonic-gate 	}
3507c478bd9Sstevel@tonic-gate 	mp_conn_data = mp_conn_ctl->b_cont;
3517c478bd9Sstevel@tonic-gate 	mp_local_data = mp_local_ctl->b_cont;
3527c478bd9Sstevel@tonic-gate 	mp_rem_data = mp_rem_ctl->b_cont;
353*45916cd2Sjpk 	mp_attr_data = mp_attr_ctl->b_cont;
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate 	/* hostname address parameters are not supported in Solaris */
3567c478bd9Sstevel@tonic-gate 	sce.sctpAssocRemHostName.o_length = 0;
3577c478bd9Sstevel@tonic-gate 	sce.sctpAssocRemHostName.o_bytes[0] = 0;
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate 	/* build table of connections -- need count in fixed part */
3607c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpRtoAlgorithm, MIB2_SCTP_RTOALGO_VANJ);
3617c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpRtoMin, sctp_rto_ming);
3627c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpRtoMax, sctp_rto_maxg);
3637c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpRtoInitial, sctp_rto_initialg);
3647c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpMaxAssocs, -1);
3657c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpValCookieLife, sctp_cookie_life);
3667c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpMaxInitRetr, sctp_max_init_retr);
3677c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpCurrEstab, 0);
3687c478bd9Sstevel@tonic-gate 
369*45916cd2Sjpk 	idx = 0;
3707c478bd9Sstevel@tonic-gate 	sctp = gsctp;
3717c478bd9Sstevel@tonic-gate 	mutex_enter(&sctp_g_lock);
3727c478bd9Sstevel@tonic-gate 	while (sctp != NULL) {
3737c478bd9Sstevel@tonic-gate 		mutex_enter(&sctp->sctp_reflock);
3747c478bd9Sstevel@tonic-gate 		if (sctp->sctp_condemned) {
3757c478bd9Sstevel@tonic-gate 			mutex_exit(&sctp->sctp_reflock);
3767c478bd9Sstevel@tonic-gate 			sctp = list_next(&sctp_g_list, sctp);
3777c478bd9Sstevel@tonic-gate 			continue;
3787c478bd9Sstevel@tonic-gate 		}
3797c478bd9Sstevel@tonic-gate 		sctp->sctp_refcnt++;
3807c478bd9Sstevel@tonic-gate 		mutex_exit(&sctp->sctp_reflock);
3817c478bd9Sstevel@tonic-gate 		mutex_exit(&sctp_g_lock);
3827c478bd9Sstevel@tonic-gate 		if (sctp_prev != NULL)
3837c478bd9Sstevel@tonic-gate 			SCTP_REFRELE(sctp_prev);
3847c478bd9Sstevel@tonic-gate 		if (sctp->sctp_connp->conn_zoneid != zoneid)
3857c478bd9Sstevel@tonic-gate 			goto next_sctp;
3867c478bd9Sstevel@tonic-gate 		if (sctp->sctp_state == SCTPS_ESTABLISHED ||
3877c478bd9Sstevel@tonic-gate 		    sctp->sctp_state == SCTPS_SHUTDOWN_PENDING ||
3887c478bd9Sstevel@tonic-gate 		    sctp->sctp_state == SCTPS_SHUTDOWN_RECEIVED) {
3897c478bd9Sstevel@tonic-gate 			BUMP_MIB(&sctp_mib, sctpCurrEstab);
3907c478bd9Sstevel@tonic-gate 		}
3917c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpOutSCTPPkts, sctp->sctp_opkts);
3927c478bd9Sstevel@tonic-gate 		sctp->sctp_opkts = 0;
3937c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpOutCtrlChunks, sctp->sctp_obchunks);
3947c478bd9Sstevel@tonic-gate 		sctp->sctp_obchunks = 0;
3957c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpOutOrderChunks, sctp->sctp_odchunks);
3967c478bd9Sstevel@tonic-gate 		sctp->sctp_odchunks = 0;
3977c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpOutUnorderChunks,
3987c478bd9Sstevel@tonic-gate 		    sctp->sctp_oudchunks);
3997c478bd9Sstevel@tonic-gate 		sctp->sctp_oudchunks = 0;
4007c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpRetransChunks, sctp->sctp_rxtchunks);
4017c478bd9Sstevel@tonic-gate 		sctp->sctp_rxtchunks = 0;
4027c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpInSCTPPkts, sctp->sctp_ipkts);
4037c478bd9Sstevel@tonic-gate 		sctp->sctp_ipkts = 0;
4047c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpInCtrlChunks, sctp->sctp_ibchunks);
4057c478bd9Sstevel@tonic-gate 		sctp->sctp_ibchunks = 0;
4067c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpInOrderChunks, sctp->sctp_idchunks);
4077c478bd9Sstevel@tonic-gate 		sctp->sctp_idchunks = 0;
4087c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpInUnorderChunks,
4097c478bd9Sstevel@tonic-gate 		    sctp->sctp_iudchunks);
4107c478bd9Sstevel@tonic-gate 		sctp->sctp_iudchunks = 0;
4117c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpFragUsrMsgs, sctp->sctp_fragdmsgs);
4127c478bd9Sstevel@tonic-gate 		sctp->sctp_fragdmsgs = 0;
4137c478bd9Sstevel@tonic-gate 		UPDATE_MIB(&sctp_mib, sctpReasmUsrMsgs, sctp->sctp_reassmsgs);
4147c478bd9Sstevel@tonic-gate 		sctp->sctp_reassmsgs = 0;
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate 		sce.sctpAssocId = ntohl(sctp->sctp_lvtag);
4177c478bd9Sstevel@tonic-gate 		sce.sctpAssocLocalPort = ntohs(sctp->sctp_lport);
4187c478bd9Sstevel@tonic-gate 		sce.sctpAssocRemPort = ntohs(sctp->sctp_fport);
4197c478bd9Sstevel@tonic-gate 
4207c478bd9Sstevel@tonic-gate 		RUN_SCTP(sctp);
4217c478bd9Sstevel@tonic-gate 		if (sctp->sctp_primary != NULL) {
4227c478bd9Sstevel@tonic-gate 			fp = sctp->sctp_primary;
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate 			if (IN6_IS_ADDR_V4MAPPED(&fp->faddr)) {
4257c478bd9Sstevel@tonic-gate 				sce.sctpAssocRemPrimAddrType =
4267c478bd9Sstevel@tonic-gate 				    MIB2_SCTP_ADDR_V4;
4277c478bd9Sstevel@tonic-gate 			} else {
4287c478bd9Sstevel@tonic-gate 				sce.sctpAssocRemPrimAddrType =
4297c478bd9Sstevel@tonic-gate 				    MIB2_SCTP_ADDR_V6;
4307c478bd9Sstevel@tonic-gate 			}
4317c478bd9Sstevel@tonic-gate 			sce.sctpAssocRemPrimAddr = fp->faddr;
4327c478bd9Sstevel@tonic-gate 			sce.sctpAssocLocPrimAddr = fp->saddr;
4337c478bd9Sstevel@tonic-gate 			sce.sctpAssocHeartBeatInterval = TICK_TO_MSEC(
4347c478bd9Sstevel@tonic-gate 			    fp->hb_interval);
4357c478bd9Sstevel@tonic-gate 		} else {
4367c478bd9Sstevel@tonic-gate 			sce.sctpAssocRemPrimAddrType = MIB2_SCTP_ADDR_V4;
4377c478bd9Sstevel@tonic-gate 			bzero(&sce.sctpAssocRemPrimAddr,
4387c478bd9Sstevel@tonic-gate 			    sizeof (sce.sctpAssocRemPrimAddr));
4397c478bd9Sstevel@tonic-gate 			bzero(&sce.sctpAssocLocPrimAddr,
4407c478bd9Sstevel@tonic-gate 			    sizeof (sce.sctpAssocLocPrimAddr));
4417c478bd9Sstevel@tonic-gate 			sce.sctpAssocHeartBeatInterval =
4427c478bd9Sstevel@tonic-gate 			    sctp_heartbeat_interval;
4437c478bd9Sstevel@tonic-gate 		}
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate 		/*
4467c478bd9Sstevel@tonic-gate 		 * Table for local addresses
4477c478bd9Sstevel@tonic-gate 		 */
4487c478bd9Sstevel@tonic-gate 		scanned = 0;
4497c478bd9Sstevel@tonic-gate 		for (i = 0; i < SCTP_IPIF_HASH; i++) {
4507c478bd9Sstevel@tonic-gate 			sctp_saddr_ipif_t	*obj;
4517c478bd9Sstevel@tonic-gate 
4527c478bd9Sstevel@tonic-gate 			if (sctp->sctp_saddrs[i].ipif_count == 0)
4537c478bd9Sstevel@tonic-gate 				continue;
4547c478bd9Sstevel@tonic-gate 			obj = list_head(&sctp->sctp_saddrs[i].sctp_ipif_list);
4557c478bd9Sstevel@tonic-gate 			for (l = 0; l < sctp->sctp_saddrs[i].ipif_count; l++) {
4567c478bd9Sstevel@tonic-gate 				sctp_ipif_t	*sctp_ipif;
4577c478bd9Sstevel@tonic-gate 				in6_addr_t	addr;
4587c478bd9Sstevel@tonic-gate 
4597c478bd9Sstevel@tonic-gate 				sctp_ipif = obj->saddr_ipifp;
4607c478bd9Sstevel@tonic-gate 				addr = sctp_ipif->sctp_ipif_saddr;
4617c478bd9Sstevel@tonic-gate 				scanned++;
4627c478bd9Sstevel@tonic-gate 				scle.sctpAssocId = ntohl(sctp->sctp_lvtag);
4637c478bd9Sstevel@tonic-gate 				if (IN6_IS_ADDR_V4MAPPED(&addr)) {
4647c478bd9Sstevel@tonic-gate 					scle.sctpAssocLocalAddrType =
4657c478bd9Sstevel@tonic-gate 					    MIB2_SCTP_ADDR_V4;
4667c478bd9Sstevel@tonic-gate 				} else {
4677c478bd9Sstevel@tonic-gate 					scle.sctpAssocLocalAddrType =
4687c478bd9Sstevel@tonic-gate 					    MIB2_SCTP_ADDR_V6;
4697c478bd9Sstevel@tonic-gate 				}
4707c478bd9Sstevel@tonic-gate 				scle.sctpAssocLocalAddr = addr;
4717c478bd9Sstevel@tonic-gate 				(void) snmp_append_data2(mp_local_data,
4727c478bd9Sstevel@tonic-gate 				    &mp_local_tail, (char *)&scle,
4737c478bd9Sstevel@tonic-gate 				    sizeof (scle));
4747c478bd9Sstevel@tonic-gate 				if (scanned >= sctp->sctp_nsaddrs)
4757c478bd9Sstevel@tonic-gate 					goto done;
4767c478bd9Sstevel@tonic-gate 				obj = list_next(&sctp->
4777c478bd9Sstevel@tonic-gate 				    sctp_saddrs[i].sctp_ipif_list, obj);
4787c478bd9Sstevel@tonic-gate 			}
4797c478bd9Sstevel@tonic-gate 		}
4807c478bd9Sstevel@tonic-gate done:
4817c478bd9Sstevel@tonic-gate 		/*
4827c478bd9Sstevel@tonic-gate 		 * Table for remote addresses
4837c478bd9Sstevel@tonic-gate 		 */
4847c478bd9Sstevel@tonic-gate 		for (fp = sctp->sctp_faddrs; fp; fp = fp->next) {
4857c478bd9Sstevel@tonic-gate 			scre.sctpAssocId = ntohl(sctp->sctp_lvtag);
4867c478bd9Sstevel@tonic-gate 			if (IN6_IS_ADDR_V4MAPPED(&fp->faddr)) {
4877c478bd9Sstevel@tonic-gate 				scre.sctpAssocRemAddrType = MIB2_SCTP_ADDR_V4;
4887c478bd9Sstevel@tonic-gate 			} else {
4897c478bd9Sstevel@tonic-gate 				scre.sctpAssocRemAddrType = MIB2_SCTP_ADDR_V6;
4907c478bd9Sstevel@tonic-gate 			}
4917c478bd9Sstevel@tonic-gate 			scre.sctpAssocRemAddr = fp->faddr;
4927c478bd9Sstevel@tonic-gate 			if (fp->state == SCTP_FADDRS_ALIVE) {
4937c478bd9Sstevel@tonic-gate 				scre.sctpAssocRemAddrActive =
4947c478bd9Sstevel@tonic-gate 				    scre.sctpAssocRemAddrHBActive =
4957c478bd9Sstevel@tonic-gate 				    MIB2_SCTP_ACTIVE;
4967c478bd9Sstevel@tonic-gate 			} else {
4977c478bd9Sstevel@tonic-gate 				scre.sctpAssocRemAddrActive =
4987c478bd9Sstevel@tonic-gate 				    scre.sctpAssocRemAddrHBActive =
4997c478bd9Sstevel@tonic-gate 				    MIB2_SCTP_INACTIVE;
5007c478bd9Sstevel@tonic-gate 			}
5017c478bd9Sstevel@tonic-gate 			scre.sctpAssocRemAddrRTO = TICK_TO_MSEC(fp->rto);
5027c478bd9Sstevel@tonic-gate 			scre.sctpAssocRemAddrMaxPathRtx = fp->max_retr;
5037c478bd9Sstevel@tonic-gate 			scre.sctpAssocRemAddrRtx = fp->T3expire;
5047c478bd9Sstevel@tonic-gate 			(void) snmp_append_data2(mp_rem_data, &mp_rem_tail,
5057c478bd9Sstevel@tonic-gate 			    (char *)&scre, sizeof (scre));
5067c478bd9Sstevel@tonic-gate 		}
507*45916cd2Sjpk 		connp = sctp->sctp_connp;
508*45916cd2Sjpk 		needattr = B_FALSE;
509*45916cd2Sjpk 		bzero(&mlp, sizeof (mlp));
510*45916cd2Sjpk 		if (connp->conn_mlp_type != mlptSingle) {
511*45916cd2Sjpk 			if (connp->conn_mlp_type == mlptShared ||
512*45916cd2Sjpk 			    connp->conn_mlp_type == mlptBoth)
513*45916cd2Sjpk 				mlp.tme_flags |= MIB2_TMEF_SHARED;
514*45916cd2Sjpk 			if (connp->conn_mlp_type == mlptPrivate ||
515*45916cd2Sjpk 			    connp->conn_mlp_type == mlptBoth)
516*45916cd2Sjpk 				mlp.tme_flags |= MIB2_TMEF_PRIVATE;
517*45916cd2Sjpk 			needattr = B_TRUE;
518*45916cd2Sjpk 		}
519*45916cd2Sjpk 		if (connp->conn_peercred != NULL) {
520*45916cd2Sjpk 			ts_label_t *tsl;
521*45916cd2Sjpk 
522*45916cd2Sjpk 			tsl = crgetlabel(connp->conn_peercred);
523*45916cd2Sjpk 			mlp.tme_doi = label2doi(tsl);
524*45916cd2Sjpk 			mlp.tme_label = *label2bslabel(tsl);
525*45916cd2Sjpk 			needattr = B_TRUE;
526*45916cd2Sjpk 		}
5277c478bd9Sstevel@tonic-gate 		WAKE_SCTP(sctp);
5287c478bd9Sstevel@tonic-gate 		sce.sctpAssocState = sctp_snmp_state(sctp);
5297c478bd9Sstevel@tonic-gate 		sce.sctpAssocInStreams = sctp->sctp_num_istr;
5307c478bd9Sstevel@tonic-gate 		sce.sctpAssocOutStreams = sctp->sctp_num_ostr;
5317c478bd9Sstevel@tonic-gate 		sce.sctpAssocMaxRetr = sctp->sctp_pa_max_rxt;
5327c478bd9Sstevel@tonic-gate 		/* A 0 here indicates that no primary process is known */
5337c478bd9Sstevel@tonic-gate 		sce.sctpAssocPrimProcess = 0;
5347c478bd9Sstevel@tonic-gate 		sce.sctpAssocT1expired = sctp->sctp_T1expire;
5357c478bd9Sstevel@tonic-gate 		sce.sctpAssocT2expired = sctp->sctp_T2expire;
5367c478bd9Sstevel@tonic-gate 		sce.sctpAssocRtxChunks = sctp->sctp_T3expire;
5377c478bd9Sstevel@tonic-gate 		sce.sctpAssocStartTime = sctp->sctp_assoc_start_time;
5387c478bd9Sstevel@tonic-gate 		sce.sctpConnEntryInfo.ce_sendq = sctp->sctp_unacked +
5397c478bd9Sstevel@tonic-gate 		    sctp->sctp_unsent;
5407c478bd9Sstevel@tonic-gate 		sce.sctpConnEntryInfo.ce_recvq = sctp->sctp_rxqueued;
5417c478bd9Sstevel@tonic-gate 		sce.sctpConnEntryInfo.ce_swnd = sctp->sctp_frwnd;
5427c478bd9Sstevel@tonic-gate 		sce.sctpConnEntryInfo.ce_rwnd = sctp->sctp_rwnd;
5437c478bd9Sstevel@tonic-gate 		sce.sctpConnEntryInfo.ce_mss = sctp->sctp_mss;
5447c478bd9Sstevel@tonic-gate 		(void) snmp_append_data2(mp_conn_data, &mp_conn_tail,
5457c478bd9Sstevel@tonic-gate 		    (char *)&sce, sizeof (sce));
546*45916cd2Sjpk 		mlp.tme_connidx = idx++;
547*45916cd2Sjpk 		if (needattr)
548*45916cd2Sjpk 			(void) snmp_append_data2(mp_attr_ctl->b_cont,
549*45916cd2Sjpk 			    &mp_attr_tail, (char *)&mlp, sizeof (mlp));
5507c478bd9Sstevel@tonic-gate next_sctp:
5517c478bd9Sstevel@tonic-gate 		sctp_prev = sctp;
5527c478bd9Sstevel@tonic-gate 		mutex_enter(&sctp_g_lock);
5537c478bd9Sstevel@tonic-gate 		sctp = list_next(&sctp_g_list, sctp);
5547c478bd9Sstevel@tonic-gate 	}
5557c478bd9Sstevel@tonic-gate 	mutex_exit(&sctp_g_lock);
5567c478bd9Sstevel@tonic-gate 	if (sctp_prev != NULL)
5577c478bd9Sstevel@tonic-gate 		SCTP_REFRELE(sctp_prev);
5587c478bd9Sstevel@tonic-gate 
5597c478bd9Sstevel@tonic-gate 	/* fixed length structure for IPv4 and IPv6 counters */
5607c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpEntrySize, sizeof (sce));
5617c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpLocalEntrySize, sizeof (scle));
5627c478bd9Sstevel@tonic-gate 	SET_MIB(sctp_mib.sctpRemoteEntrySize, sizeof (scre));
5637c478bd9Sstevel@tonic-gate 	optp = (struct opthdr *)&mpctl->b_rptr[sizeof (struct T_optmgmt_ack)];
5647c478bd9Sstevel@tonic-gate 	optp->level = MIB2_SCTP;
5657c478bd9Sstevel@tonic-gate 	optp->name = 0;
5667c478bd9Sstevel@tonic-gate 	(void) snmp_append_data(mpdata, (char *)&sctp_mib, sizeof (sctp_mib));
5677c478bd9Sstevel@tonic-gate 	optp->len = msgdsize(mpdata);
5687c478bd9Sstevel@tonic-gate 	qreply(q, mpctl);
5697c478bd9Sstevel@tonic-gate 
5707c478bd9Sstevel@tonic-gate 	/* table of connections... */
5717c478bd9Sstevel@tonic-gate 	optp = (struct opthdr *)&mp_conn_ctl->b_rptr[
5727c478bd9Sstevel@tonic-gate 	    sizeof (struct T_optmgmt_ack)];
5737c478bd9Sstevel@tonic-gate 	optp->level = MIB2_SCTP;
5747c478bd9Sstevel@tonic-gate 	optp->name = MIB2_SCTP_CONN;
5757c478bd9Sstevel@tonic-gate 	optp->len = msgdsize(mp_conn_data);
5767c478bd9Sstevel@tonic-gate 	qreply(q, mp_conn_ctl);
5777c478bd9Sstevel@tonic-gate 
5787c478bd9Sstevel@tonic-gate 	/* assoc local address table */
5797c478bd9Sstevel@tonic-gate 	optp = (struct opthdr *)&mp_local_ctl->b_rptr[
5807c478bd9Sstevel@tonic-gate 	    sizeof (struct T_optmgmt_ack)];
5817c478bd9Sstevel@tonic-gate 	optp->level = MIB2_SCTP;
5827c478bd9Sstevel@tonic-gate 	optp->name = MIB2_SCTP_CONN_LOCAL;
5837c478bd9Sstevel@tonic-gate 	optp->len = msgdsize(mp_local_data);
5847c478bd9Sstevel@tonic-gate 	qreply(q, mp_local_ctl);
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate 	/* assoc remote address table */
5877c478bd9Sstevel@tonic-gate 	optp = (struct opthdr *)&mp_rem_ctl->b_rptr[
5887c478bd9Sstevel@tonic-gate 	    sizeof (struct T_optmgmt_ack)];
5897c478bd9Sstevel@tonic-gate 	optp->level = MIB2_SCTP;
5907c478bd9Sstevel@tonic-gate 	optp->name = MIB2_SCTP_CONN_REMOTE;
5917c478bd9Sstevel@tonic-gate 	optp->len = msgdsize(mp_rem_data);
5927c478bd9Sstevel@tonic-gate 	qreply(q, mp_rem_ctl);
5937c478bd9Sstevel@tonic-gate 
594*45916cd2Sjpk 	/* table of MLP attributes */
595*45916cd2Sjpk 	optp = (struct opthdr *)&mp_attr_ctl->b_rptr[
596*45916cd2Sjpk 	    sizeof (struct T_optmgmt_ack)];
597*45916cd2Sjpk 	optp->level = MIB2_SCTP;
598*45916cd2Sjpk 	optp->name = EXPER_XPORT_MLP;
599*45916cd2Sjpk 	optp->len = msgdsize(mp_attr_data);
600*45916cd2Sjpk 	if (optp->len == 0)
601*45916cd2Sjpk 		freemsg(mp_attr_ctl);
602*45916cd2Sjpk 	else
603*45916cd2Sjpk 		qreply(q, mp_attr_ctl);
604*45916cd2Sjpk 
6057c478bd9Sstevel@tonic-gate 	return (mp_ret);
6067c478bd9Sstevel@tonic-gate }
6077c478bd9Sstevel@tonic-gate 
6087c478bd9Sstevel@tonic-gate /* Translate SCTP state to MIB2 SCTP state. */
6097c478bd9Sstevel@tonic-gate static int
6107c478bd9Sstevel@tonic-gate sctp_snmp_state(sctp_t *sctp)
6117c478bd9Sstevel@tonic-gate {
6127c478bd9Sstevel@tonic-gate 	if (sctp == NULL)
6137c478bd9Sstevel@tonic-gate 		return (0);
6147c478bd9Sstevel@tonic-gate 
6157c478bd9Sstevel@tonic-gate 	switch (sctp->sctp_state) {
6167c478bd9Sstevel@tonic-gate 	case SCTPS_IDLE:
6177c478bd9Sstevel@tonic-gate 	case SCTPS_BOUND:
6187c478bd9Sstevel@tonic-gate 		return (MIB2_SCTP_closed);
6197c478bd9Sstevel@tonic-gate 	case SCTPS_LISTEN:
6207c478bd9Sstevel@tonic-gate 		return (MIB2_SCTP_listen);
6217c478bd9Sstevel@tonic-gate 	case SCTPS_COOKIE_WAIT:
6227c478bd9Sstevel@tonic-gate 		return (MIB2_SCTP_cookieWait);
6237c478bd9Sstevel@tonic-gate 	case SCTPS_COOKIE_ECHOED:
6247c478bd9Sstevel@tonic-gate 		return (MIB2_SCTP_cookieEchoed);
6257c478bd9Sstevel@tonic-gate 	case SCTPS_ESTABLISHED:
6267c478bd9Sstevel@tonic-gate 		return (MIB2_SCTP_established);
6277c478bd9Sstevel@tonic-gate 	case SCTPS_SHUTDOWN_PENDING:
6287c478bd9Sstevel@tonic-gate 		return (MIB2_SCTP_shutdownPending);
6297c478bd9Sstevel@tonic-gate 	case SCTPS_SHUTDOWN_SENT:
6307c478bd9Sstevel@tonic-gate 		return (MIB2_SCTP_shutdownSent);
6317c478bd9Sstevel@tonic-gate 	case SCTPS_SHUTDOWN_RECEIVED:
6327c478bd9Sstevel@tonic-gate 		return (MIB2_SCTP_shutdownReceived);
6337c478bd9Sstevel@tonic-gate 	case SCTPS_SHUTDOWN_ACK_SENT:
6347c478bd9Sstevel@tonic-gate 		return (MIB2_SCTP_shutdownAckSent);
6357c478bd9Sstevel@tonic-gate 	default:
6367c478bd9Sstevel@tonic-gate 		return (0);
6377c478bd9Sstevel@tonic-gate 	}
6387c478bd9Sstevel@tonic-gate }
639